Change in osmo-e1d[master]: vpair: fix writing config file with vpairs configured

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.org
Thu Dec 17 19:03:00 UTC 2020


laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-e1d/+/21781 )


Change subject: vpair: fix writing config file with vpairs configured
......................................................................

vpair: fix writing config file with vpairs configured

prior to this patch, the configured vpair interfaces would not
be saved to the config file on 'write file'.

Change-Id: Iff6551318534a3717c374060082147f17b925a21
---
M doc/examples/osmo-e1d-vpair.cfg
M src/e1d.h
M src/vpair.c
M src/vty.c
4 files changed, 77 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-e1d refs/changes/81/21781/1

diff --git a/doc/examples/osmo-e1d-vpair.cfg b/doc/examples/osmo-e1d-vpair.cfg
index 32742de..04bdb72 100644
--- a/doc/examples/osmo-e1d-vpair.cfg
+++ b/doc/examples/osmo-e1d-vpair.cfg
@@ -1,2 +1,2 @@
-
-virtual-e1-pair 1
+e1d
+ virtual-e1-pair 1
diff --git a/src/e1d.h b/src/e1d.h
index c35f4a8..a7ba005 100644
--- a/src/e1d.h
+++ b/src/e1d.h
@@ -146,3 +146,6 @@
 
 int
 e1d_vpair_create(struct e1_daemon *e1d, unsigned int num_lines);
+
+struct e1_intf *
+e1d_vpair_intf_peer(struct e1_intf *intf);
diff --git a/src/vpair.c b/src/vpair.c
index 12452fe..df14026 100644
--- a/src/vpair.c
+++ b/src/vpair.c
@@ -88,6 +88,15 @@
 	talloc_free(intf->drv_data);
 }
 
+/* resolve the peer of a given interface */
+struct e1_intf *
+e1d_vpair_intf_peer(struct e1_intf *intf)
+{
+	struct ve1_intf_data *intf_data = intf->drv_data;
+	OSMO_ASSERT(intf->drv == E1_DRIVER_VPAIR);
+	return intf_data->peer;
+}
+
 static int
 ve1_timerfd_cb(struct osmo_fd *ofd, unsigned int what)
 {
diff --git a/src/vty.c b/src/vty.c
index 0690177..1caa54f 100644
--- a/src/vty.c
+++ b/src/vty.c
@@ -41,6 +41,16 @@
 
 static struct e1_daemon *vty_e1d;
 
+enum e1d_vty_node {
+	E1D_NODE = _LAST_OSMOVTY_NODE + 1,
+};
+
+static struct cmd_node e1d_node = {
+	(enum node_type) E1D_NODE,
+	"%s(config-e1d)# ",
+	1,
+};
+
 #if 0
 static void vty_dump_ts(struct vty *vty, const struct e1_ts *ts)
 {
@@ -142,6 +152,14 @@
 	return CMD_SUCCESS;
 }
 
+DEFUN(cfg_e1d, cfg_e1d_cmd, "e1d",
+	"E1 Daemon sspecific configuration\n")
+{
+	vty->node = E1D_NODE;
+
+	return CMD_SUCCESS;
+}
+
 DEFUN(cfg_vpair, cfg_vpair_cmd, "virtual-e1-pair <1-255>",
 	"Create a virtual E1 interface pair\n"
 	"Number of E1 lines in virtual E1 interface pair\n")
@@ -158,11 +176,55 @@
 	return CMD_SUCCESS;
 }
 
+static bool intf_arr_contains(struct e1_intf **arr, unsigned int arr_cnt, struct e1_intf *intf)
+{
+	unsigned int i;
+	for (i = 0; i < arr_cnt; i++) {
+		if (arr[i] == intf)
+			return true;
+	}
+	return false;
+}
+
+static int config_write_e1d(struct vty *vty)
+{
+	struct e1_intf *intf;
+	struct e1_intf *intf_b[256];
+	unsigned int num_intf_b = 0;
+
+	vty_out(vty, "pcu%s", VTY_NEWLINE);
+
+	/* find all vpair interfaces */
+	llist_for_each_entry(intf, &vty_e1d->interfaces, list) {
+		unsigned int line_count = 0;
+		struct e1_line *line;
+
+		if (intf->drv != E1_DRIVER_VPAIR)
+			continue;
+		/* skip the 'mirror' interfaces */
+		if (intf_arr_contains(intf_b, ARRAY_SIZE(intf_b), intf))
+			continue;
+
+		llist_for_each_entry(line, &intf->lines, list)
+			line_count++;
+
+		vty_out(vty, " virtual-e1-pair %u%s", line_count, VTY_NEWLINE);
+
+		/* memorize the peer so we don't save it twice */
+		intf_b[num_intf_b++] = e1d_vpair_intf_peer(intf);
+		if (num_intf_b >= ARRAY_SIZE(intf_b))
+			break;
+	}
+	return 0;
+}
+
 void e1d_vty_init(struct e1_daemon *e1d)
 {
 	vty_e1d = e1d;
 	install_element_ve(&show_intf_cmd);
 	install_element_ve(&show_line_cmd);
 
-	install_element(CONFIG_NODE, &cfg_vpair_cmd);
+	install_node(&e1d_node, config_write_e1d);
+	install_element(CONFIG_NODE, &cfg_e1d_cmd);
+	install_element(E1D_NODE, &cfg_vpair_cmd);
 }

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

Gerrit-Project: osmo-e1d
Gerrit-Branch: master
Gerrit-Change-Id: Iff6551318534a3717c374060082147f17b925a21
Gerrit-Change-Number: 21781
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/20201217/753c357c/attachment.htm>


More information about the gerrit-log mailing list