Change in osmo-e1d[master]: vpair: fix writing config file with vpairs configured
laforge has submitted this change. ( 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, 61 insertions(+), 3 deletions(-) Approvals: Jenkins Builder: Verified tnt: Looks good to me, but someone else must approve laforge: Looks good to me, approved 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..d4d26ef 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 specific 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,39 @@ return CMD_SUCCESS; } +static int config_write_e1d(struct vty *vty) +{ + struct e1_intf *intf; + + vty_out(vty, "e1d%s", VTY_NEWLINE); + + /* find all vpair interfaces */ + llist_for_each_entry(intf, _e1d->interfaces, list) { + struct e1_intf *peer = e1d_vpair_intf_peer(intf); + unsigned int line_count = 0; + struct e1_line *line; + + if (intf->drv != E1_DRIVER_VPAIR) + continue; + /* skip the 'mirror' interfaces */ + if (intf->id > peer->id) + continue; + + llist_for_each_entry(line, >lines, list) + line_count++; + + vty_out(vty, " virtual-e1-pair %u%s", line_count, VTY_NEWLINE); + } + return 0; +} + void e1d_vty_init(struct e1_daemon *e1d) { vty_e1d = e1d; install_element_ve(_intf_cmd); install_element_ve(_line_cmd); - install_element(CONFIG_NODE, _vpair_cmd); + install_node(_node, config_write_e1d); + install_element(CONFIG_NODE, _e1d_cmd); + install_element(E1D_NODE, _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: 3 Gerrit-Owner: laforge Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge Gerrit-Reviewer: tnt Gerrit-CC: pespin Gerrit-MessageType: merged
Change in osmo-e1d[master]: vpair: fix writing config file with vpairs configured
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-e1d/+/21781 ) Change subject: vpair: fix writing config file with vpairs configured .. Patch Set 3: Code-Review+2 -- 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: 3 Gerrit-Owner: laforge Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge Gerrit-Reviewer: tnt Gerrit-CC: pespin Gerrit-Comment-Date: Sun, 20 Dec 2020 10:26:13 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
Change in osmo-e1d[master]: vpair: fix writing config file with vpairs configured
tnt has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-e1d/+/21781 ) Change subject: vpair: fix writing config file with vpairs configured .. Patch Set 3: Code-Review+1 -- 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: 3 Gerrit-Owner: laforge Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: tnt Gerrit-CC: pespin Gerrit-Comment-Date: Sat, 19 Dec 2020 17:29:13 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
Change in osmo-e1d[master]: vpair: fix writing config file with vpairs configured
Hello Jenkins Builder, tnt, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/osmo-e1d/+/21781 to look at the new patch set (#3). 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, 61 insertions(+), 3 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-e1d refs/changes/81/21781/3 -- 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: 3 Gerrit-Owner: laforge Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: tnt Gerrit-CC: pespin Gerrit-MessageType: newpatchset
Change in osmo-e1d[master]: vpair: fix writing config file with vpairs configured
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-e1d/+/21781 ) Change subject: vpair: fix writing config file with vpairs configured .. Patch Set 2: (2 comments) https://gerrit.osmocom.org/c/osmo-e1d/+/21781/1/src/vty.c File src/vty.c: https://gerrit.osmocom.org/c/osmo-e1d/+/21781/1/src/vty.c@195 PS1, Line 195: vty_out(vty, "pcu%s", VTY_NEWLINE); > shouldn't this be e1d? Ack https://gerrit.osmocom.org/c/osmo-e1d/+/21781/2/src/vty.c File src/vty.c: https://gerrit.osmocom.org/c/osmo-e1d/+/21781/2/src/vty.c@192 PS2, Line 192: struct e1_intf *intf_b[256]; > 2k on the stack isn't great. […] I wouldn't really have worried about that kind of stack usage outside of a embedded device. But sure, it's not elegant, no doubt. Will change it. -- 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: 2 Gerrit-Owner: laforge Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: tnt Gerrit-CC: pespin Gerrit-Comment-Date: Sat, 19 Dec 2020 17:24:01 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: tnt Comment-In-Reply-To: pespin Gerrit-MessageType: comment
Change in osmo-e1d[master]: vpair: fix writing config file with vpairs configured
tnt has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-e1d/+/21781 ) Change subject: vpair: fix writing config file with vpairs configured .. Patch Set 2: (2 comments) https://gerrit.osmocom.org/c/osmo-e1d/+/21781/2/src/vty.c File src/vty.c: https://gerrit.osmocom.org/c/osmo-e1d/+/21781/2/src/vty.c@156 PS2, Line 156: "E1 Daemon sspecific configuration\n") Typo https://gerrit.osmocom.org/c/osmo-e1d/+/21781/2/src/vty.c@192 PS2, Line 192: struct e1_intf *intf_b[256]; 2k on the stack isn't great. Another approach to avoid duplicate would be to compare the pointers and only print if intf->id < intf_peer->id for instance. No memory needed. Also brings it to O(n) rather than O(n * log(n)) not that it matters for 256 max intf -- 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: 2 Gerrit-Owner: laforge Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: tnt Gerrit-CC: pespin Gerrit-Comment-Date: Sat, 19 Dec 2020 17:09:21 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Gerrit-MessageType: comment
Change in osmo-e1d[master]: vpair: fix writing config file with vpairs configured
Hello Jenkins Builder, tnt, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/osmo-e1d/+/21781 to look at the new patch set (#2). 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/2 -- 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: 2 Gerrit-Owner: laforge Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: tnt Gerrit-CC: pespin Gerrit-MessageType: newpatchset
Change in osmo-e1d[master]: vpair: fix writing config file with vpairs configured
pespin has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-e1d/+/21781 ) Change subject: vpair: fix writing config file with vpairs configured .. Patch Set 1: (1 comment) https://gerrit.osmocom.org/c/osmo-e1d/+/21781/1/src/vty.c File src/vty.c: https://gerrit.osmocom.org/c/osmo-e1d/+/21781/1/src/vty.c@195 PS1, Line 195: vty_out(vty, "pcu%s", VTY_NEWLINE); shouldn't this be e1d? -- 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 Gerrit-Reviewer: Jenkins Builder Gerrit-CC: pespin Gerrit-Comment-Date: Thu, 17 Dec 2020 19:44:53 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Gerrit-MessageType: comment
Change in osmo-e1d[master]: vpair: fix writing config file with vpairs configured
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, _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, >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(_intf_cmd); install_element_ve(_line_cmd); - install_element(CONFIG_NODE, _vpair_cmd); + install_node(_node, config_write_e1d); + install_element(CONFIG_NODE, _e1d_cmd); + install_element(E1D_NODE, _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 Gerrit-MessageType: newchange