This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
laforge gerrit-no-reply at lists.osmocom.orglaforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/22572 )
Change subject: osmo-ns-dummy: Add "mirror-mode" to mirror back any received packets
......................................................................
osmo-ns-dummy: Add "mirror-mode" to mirror back any received packets
Change-Id: If57bfdeb390d88d1ea058f7a9ce0403e64a5beda
---
M utils/osmo-ns-dummy-vty.c
M utils/osmo-ns-dummy.c
2 files changed, 43 insertions(+), 9 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/72/22572/1
diff --git a/utils/osmo-ns-dummy-vty.c b/utils/osmo-ns-dummy-vty.c
index 1b7ce1c..f4a270c 100644
--- a/utils/osmo-ns-dummy-vty.c
+++ b/utils/osmo-ns-dummy-vty.c
@@ -46,8 +46,9 @@
#include <osmocom/vty/stats.h>
#include <osmocom/vty/misc.h>
-static struct gprs_ns2_inst *g_nsi;
+extern struct gprs_ns2_inst *g_nsi;
static struct llist_head g_ns_traf_gens = LLIST_HEAD_INIT(g_ns_traf_gens);
+int g_mirror_mode;
/* one NS traffic generator instance. You can have as many of these as you want,
* just as long as they have unique names */
@@ -167,6 +168,7 @@
vty_out(vty, " lsp %u%s", ntg->cfg.lsp, VTY_NEWLINE);
vty_out(vty, " lsp-mode %s%s", ntg->cfg.lsp_randomize ? "randomized" : "fixed", VTY_NEWLINE);
}
+ vty_out(vty, "mirror-mode %s%s", g_mirror_mode ? "enable" : "disable", VTY_NEWLINE);
return 0;
}
@@ -288,12 +290,26 @@
return CMD_SUCCESS;
}
-int nsdummy_vty_init(struct gprs_ns2_inst *nsi)
+DEFUN(mirror_mode, mirror_mode_cmd,
+ "mirror-mode (enable|disable)",
+ "Configure mirroring of incoming NS-UNITDATA\n"
+ "Enable mirroring of incoming NS-UNITDATA\n"
+ "Disable mirroring of incoming NS-UNITDATA\n")
{
- g_nsi = nsi;
+ if (!strcmp(argv[0], "enable"))
+ g_mirror_mode = true;
+ else
+ g_mirror_mode = false;
+ return CMD_SUCCESS;
+}
+
+
+int nsdummy_vty_init(void)
+{
/* configuration of traffic generators via CONFIG / NTG node */
install_element(CONFIG_NODE, &gen_traffic_cmd);
+ install_element(CONFIG_NODE, &mirror_mode_cmd);
install_node(&ntg_node, config_write_ntg);
install_element(NTG_NODE, &ntg_nsei_cmd);
install_element(NTG_NODE, &ntg_bvci_cmd);
diff --git a/utils/osmo-ns-dummy.c b/utils/osmo-ns-dummy.c
index 4b93788..3520145 100644
--- a/utils/osmo-ns-dummy.c
+++ b/utils/osmo-ns-dummy.c
@@ -28,6 +28,7 @@
static bool daemonize = false;
static int vty_port = 0;
static char *config_file = NULL;
+struct gprs_ns2_inst *g_nsi;
static const char vty_copyright[] =
"Copyright (C) 2020 by by sysmocom - s.f.m.c. GmbH\r\n"
@@ -185,9 +186,27 @@
}
}
+extern int g_mirror_mode;
+
/* called by the ns layer */
int gprs_ns_prim_cb(struct osmo_prim_hdr *oph, void *ctx)
{
+ struct osmo_gprs_ns2_prim *nsp = container_of(oph, struct osmo_gprs_ns2_prim, oph);
+
+ switch (oph->primitive) {
+ case GPRS_NS2_PRIM_UNIT_DATA:
+ if (g_mirror_mode) {
+ /* simply switch indication->request and resubmit */
+ oph->operation = PRIM_OP_REQUEST;
+ msgb_pull_to_l3(oph->msg);
+ nsp->u.unitdata.link_selector = rand(); /* ensure random distribution */
+ return gprs_ns2_recv_prim(g_nsi, oph);
+ }
+ break;
+ default:
+ break;
+ }
+
if (oph->msg)
msgb_free(oph->msg);
@@ -204,7 +223,6 @@
int main (int argc, char *argv[])
{
void *ctx = tall_nsdummy_ctx = talloc_named_const(NULL, 0, "osmo-ns-dummy");
- struct gprs_ns2_inst *nsi;
int rc = 0;
osmo_init_logging2(ctx, &log_info);
@@ -224,14 +242,14 @@
handle_options(argc, argv);
- nsi = gprs_ns2_instantiate(ctx, gprs_ns_prim_cb, NULL);
- if (!nsi) {
+ g_nsi = gprs_ns2_instantiate(ctx, gprs_ns_prim_cb, NULL);
+ if (!g_nsi) {
LOGP(DLNS, LOGL_ERROR, "Failed to create NS instance\n");
exit(1);
}
- gprs_ns2_vty_init(nsi);
- nsdummy_vty_init(nsi);
+ gprs_ns2_vty_init(g_nsi);
+ nsdummy_vty_init(g_nsi);
rc = vty_read_config_file(config_file, NULL);
if (rc < 0 && config_given) {
fprintf(stderr, "Failed to parse the config file: '%s'\n",
@@ -270,7 +288,7 @@
}
telnet_exit();
- gprs_ns2_free(nsi);
+ gprs_ns2_free(g_nsi);
talloc_report_full(tall_nsdummy_ctx, stderr);
talloc_free(tall_nsdummy_ctx);
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/22572
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: If57bfdeb390d88d1ea058f7a9ce0403e64a5beda
Gerrit-Change-Number: 22572
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210131/3a9728dc/attachment.htm>