Change in libosmocore[master]: osmo-ns-dummy: Add simple NS traffic generator

2021-02-01 Thread laforge
laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/22553 )

Change subject: osmo-ns-dummy: Add simple NS traffic generator
..

osmo-ns-dummy: Add simple NS traffic generator

This adds a simple NS traffic generator that can be used to perform
load testing on NS links, particularly those with limited bandwidth
such as frame-relay E1 lines.

Related: OS#4995
Change-Id: Iad3b694c85962dbbc6b4a27a0ed5bc841add464f
---
M utils/Makefile.am
A utils/osmo-ns-dummy-vty.c
M utils/osmo-ns-dummy.c
3 files changed, 312 insertions(+), 1 deletion(-)

Approvals:
  Jenkins Builder: Verified
  lynxis lazus: Looks good to me, but someone else must approve
  laforge: Looks good to me, approved



diff --git a/utils/Makefile.am b/utils/Makefile.am
index 4fac477..4e54a78 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -29,7 +29,7 @@
 if ENABLE_EXT_TESTS
 if ENABLE_GB
 noinst_PROGRAMS += osmo-ns-dummy
-osmo_ns_dummy_SOURCES = osmo-ns-dummy.c
+osmo_ns_dummy_SOURCES = osmo-ns-dummy.c osmo-ns-dummy-vty.c
 osmo_ns_dummy_LDADD = $(LDADD) $(TALLOC_LIBS) \
$(top_builddir)/src/gb/libosmogb.la \
$(top_builddir)/src/vty/libosmovty.la \
diff --git a/utils/osmo-ns-dummy-vty.c b/utils/osmo-ns-dummy-vty.c
new file mode 100644
index 000..1b7ce1c
--- /dev/null
+++ b/utils/osmo-ns-dummy-vty.c
@@ -0,0 +1,309 @@
+/* VTY for osmo-ns-dummy */
+
+/* (C) 2021 Harald Welte 
+ *
+ * All Rights Reserved
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static struct gprs_ns2_inst *g_nsi;
+static struct llist_head g_ns_traf_gens = LLIST_HEAD_INIT(g_ns_traf_gens);
+
+/* one NS traffic generator instance.  You can have as many of these as you 
want,
+ * just as long as they have unique names */
+struct ns_traf_gen {
+   struct llist_head list;
+   const char *name;
+   struct {
+   uint16_t nsei;
+   uint16_t bvci;
+   /* size of each packet */
+   uint16_t pkt_size;
+   /* interval between packets in us */
+   uint32_t interval_us;
+   /* fixed (false) or random (true) LSP */
+   bool lsp_randomize;
+   /* (fixeD) Link Selector Parameter */
+   uint32_t lsp;
+   } cfg;
+   struct osmo_fd timerfd;
+   bool running;
+};
+
+#define LOGNTG(ntg, lvl, fmt, args ...) \
+   LOGP(DLGLOBAL, lvl, "traf-gen(%s): " fmt, (ntg)->name, ## args)
+
+/* allocate and transmit one NS message */
+static int ntg_tx_one(struct ns_traf_gen *ntg)
+{
+   struct osmo_gprs_ns2_prim nsp = {};
+   struct msgb *msg = msgb_alloc_headroom(3072, 20, "NS traffic gen");
+
+   if (!msg)
+   return -ENOMEM;
+   msgb_put(msg, ntg->cfg.pkt_size);
+   nsp.bvci = ntg->cfg.bvci;
+   nsp.nsei = ntg->cfg.nsei;
+   if (ntg->cfg.lsp_randomize)
+   nsp.u.unitdata.link_selector = rand();
+   else
+   nsp.u.unitdata.link_selector = ntg->cfg.lsp;
+   osmo_prim_init(, SAP_NS, GPRS_NS2_PRIM_UNIT_DATA, 
PRIM_OP_REQUEST, msg);
+   return gprs_ns2_recv_prim(g_nsi, );
+}
+
+/* call-back from transmit timer-fd */
+static int ntg_timerfd_cb(struct osmo_fd *ofd, unsigned int what)
+{
+   uint64_t expire_count;
+   struct ns_traf_gen *ntg = ofd->data;
+   unsigned int i;
+   int rc;
+
+   OSMO_ASSERT(what & OSMO_FD_READ);
+
+   rc = read(ofd->fd, (void *) _count, sizeof(expire_count));
+   if (rc < 0 && errno == EAGAIN)
+   return 0;
+   OSMO_ASSERT(rc == sizeof(expire_count));
+
+   for (i = 0; i < expire_count; i++)
+   ntg_tx_one(ntg);
+
+   return 0;
+}
+
+static struct ns_traf_gen *ns_traf_gen_find(const char *name)
+{
+   struct ns_traf_gen *ntg;
+
+   llist_for_each_entry(ntg, _ns_traf_gens, list) {
+   if (!strcmp(ntg->name, name))
+   return ntg;
+   }
+   return NULL;
+}
+
+static struct ns_traf_gen *ns_traf_gen_find_or_alloc(const char *name)

Change in libosmocore[master]: osmo-ns-dummy: Add simple NS traffic generator

2021-02-01 Thread laforge
laforge has posted comments on this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/22553 )

Change subject: osmo-ns-dummy: Add simple NS traffic generator
..


Patch Set 2: Code-Review+2

(1 comment)

https://gerrit.osmocom.org/c/libosmocore/+/22553/2/utils/osmo-ns-dummy-vty.c
File utils/osmo-ns-dummy-vty.c:

https://gerrit.osmocom.org/c/libosmocore/+/22553/2/utils/osmo-ns-dummy-vty.c@189
PS2, Line 189:  if (ntg->running) {
> I would have used osmo_timer_pending() instead of running
will try to get this merged first and then submit a patch to get rid of 
'running'



--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/22553
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Iad3b694c85962dbbc6b4a27a0ed5bc841add464f
Gerrit-Change-Number: 22553
Gerrit-PatchSet: 2
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel 
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: lynxis lazus 
Gerrit-Comment-Date: Mon, 01 Feb 2021 08:30:41 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: lynxis lazus 
Gerrit-MessageType: comment


Change in libosmocore[master]: osmo-ns-dummy: Add simple NS traffic generator

2021-01-31 Thread lynxis lazus
lynxis lazus has posted comments on this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/22553 )

Change subject: osmo-ns-dummy: Add simple NS traffic generator
..


Patch Set 2: Code-Review+1

(1 comment)

https://gerrit.osmocom.org/c/libosmocore/+/22553/2/utils/osmo-ns-dummy-vty.c
File utils/osmo-ns-dummy-vty.c:

https://gerrit.osmocom.org/c/libosmocore/+/22553/2/utils/osmo-ns-dummy-vty.c@189
PS2, Line 189:  if (ntg->running) {
I would have used osmo_timer_pending() instead of running



--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/22553
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Iad3b694c85962dbbc6b4a27a0ed5bc841add464f
Gerrit-Change-Number: 22553
Gerrit-PatchSet: 2
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel 
Gerrit-Reviewer: lynxis lazus 
Gerrit-Comment-Date: Mon, 01 Feb 2021 00:29:47 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


Change in libosmocore[master]: osmo-ns-dummy: Add simple NS traffic generator

2021-01-30 Thread laforge
Hello Jenkins Builder,

I'd like you to reexamine a change. Please visit

https://gerrit.osmocom.org/c/libosmocore/+/22553

to look at the new patch set (#2).

Change subject: osmo-ns-dummy: Add simple NS traffic generator
..

osmo-ns-dummy: Add simple NS traffic generator

This adds a simple NS traffic generator that can be used to perform
load testing on NS links, particularly those with limited bandwidth
such as frame-relay E1 lines.

Related: OS#4995
Change-Id: Iad3b694c85962dbbc6b4a27a0ed5bc841add464f
---
M utils/Makefile.am
A utils/osmo-ns-dummy-vty.c
M utils/osmo-ns-dummy.c
3 files changed, 312 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/53/22553/2
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/22553
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Iad3b694c85962dbbc6b4a27a0ed5bc841add464f
Gerrit-Change-Number: 22553
Gerrit-PatchSet: 2
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-MessageType: newpatchset


Change in libosmocore[master]: osmo-ns-dummy: Add simple NS traffic generator

2021-01-30 Thread laforge
laforge has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmocore/+/22553 )


Change subject: osmo-ns-dummy: Add simple NS traffic generator
..

osmo-ns-dummy: Add simple NS traffic generator

This adds a simple NS traffic generator that can be used to perform
load testing on NS links, particularly those with limited bandwidth
such as frame-relay E1 lines.

Related: OS#4995
Change-Id: Iad3b694c85962dbbc6b4a27a0ed5bc841add464f
---
M utils/Makefile.am
A utils/osmo-ns-dummy-vty.c
M utils/osmo-ns-dummy.c
3 files changed, 317 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/53/22553/1

diff --git a/utils/Makefile.am b/utils/Makefile.am
index 4fac477..4e54a78 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -29,7 +29,7 @@
 if ENABLE_EXT_TESTS
 if ENABLE_GB
 noinst_PROGRAMS += osmo-ns-dummy
-osmo_ns_dummy_SOURCES = osmo-ns-dummy.c
+osmo_ns_dummy_SOURCES = osmo-ns-dummy.c osmo-ns-dummy-vty.c
 osmo_ns_dummy_LDADD = $(LDADD) $(TALLOC_LIBS) \
$(top_builddir)/src/gb/libosmogb.la \
$(top_builddir)/src/vty/libosmovty.la \
diff --git a/utils/osmo-ns-dummy-vty.c b/utils/osmo-ns-dummy-vty.c
new file mode 100644
index 000..c88add7
--- /dev/null
+++ b/utils/osmo-ns-dummy-vty.c
@@ -0,0 +1,314 @@
+/* VTY for osmo-ns-dummy */
+
+/* (C) 2021 Harald Welte 
+ *
+ * All Rights Reserved
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static struct gprs_ns2_inst *g_nsi;
+static struct llist_head g_ns_traf_gens = LLIST_HEAD_INIT(g_ns_traf_gens);
+
+/* one NS traffic generator instance.  You can have as many of these as you 
want,
+ * just as long as they have unique names */
+struct ns_traf_gen {
+   struct llist_head list;
+   const char *name;
+   struct {
+   uint16_t nsei;
+   uint16_t bvci;
+   /* size of each packet */
+   uint16_t pkt_size;
+   /* interval between packets in us */
+   uint32_t interval_us;
+   /* fixed (false) or random (true) LSP */
+   bool lsp_randomize;
+   /* (fixeD) Link Selector Parameter */
+   uint32_t lsp;
+   } cfg;
+   struct osmo_fd timerfd;
+   bool running;
+};
+
+#define LOGNTG(ntg, lvl, fmt, args ...) \
+   LOGP(DLGLOBAL, lvl, "traf-gen(%s): " fmt, (ntg)->name, ## args)
+
+/* allocate and transmit one NS message */
+static int ntg_tx_one(struct ns_traf_gen *ntg)
+{
+   struct osmo_gprs_ns2_prim nsp = {};
+   struct msgb *msg = msgb_alloc_headroom(3072, 20, "NS traffic gen");
+   int rc;
+
+   if (!msg)
+   return -ENOMEM;
+   msgb_put(msg, ntg->cfg.pkt_size);
+   nsp.bvci = ntg->cfg.bvci;
+   nsp.nsei = ntg->cfg.nsei;
+   if (ntg->cfg.lsp_randomize)
+   nsp.u.unitdata.link_selector = rand();
+   else
+   nsp.u.unitdata.link_selector = ntg->cfg.lsp;
+   osmo_prim_init(, SAP_NS, GPRS_NS2_PRIM_UNIT_DATA, 
PRIM_OP_REQUEST, msg);
+   rc = gprs_ns2_recv_prim(g_nsi, );
+   if (rc < 0)
+   LOGNTG(ntg, LOGL_ERROR, "error transmitting: %d\n", rc);
+
+   return rc;
+}
+
+/* call-back from transmit timer-fd */
+static int ntg_timerfd_cb(struct osmo_fd *ofd, unsigned int what)
+{
+   uint64_t expire_count;
+   struct ns_traf_gen *ntg = ofd->data;
+   unsigned int i;
+   int rc;
+
+   OSMO_ASSERT(what & OSMO_FD_READ);
+
+   rc = read(ofd->fd, (void *) _count, sizeof(expire_count));
+   if (rc < 0 && errno == EAGAIN)
+   return 0;
+   OSMO_ASSERT(rc == sizeof(expire_count));
+
+   for (i = 0; i < expire_count; i++)
+   ntg_tx_one(ntg);
+
+   return 0;
+}
+
+static struct ns_traf_gen *ns_traf_gen_find(const char *name)
+{
+   struct ns_traf_gen *ntg;
+
+   llist_for_each_entry(ntg, _ns_traf_gens, list) {
+   if (!strcmp(ntg->name, name))
+   return ntg;
+   }
+   return NULL;