From af39c7a78a37058ec4a2f2dc0d4e588aad46b3a1 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Wed, 26 Sep 2018 17:12:23 +0200 Subject: vty: SCCP timers: add optional units Add VTY UI to optionally configure SCCP timers in millisecond unit, allowing for less-than-a-second resolution, and in minute unit, allowing for convenience to cut short the factor-of-60 calculations when thinking in minutes. Also write back the config in the largest possible unit that doesn't lose timer value precision. Change-Id: I020d5dab19bc67e8444ed548db15b2a4d8871a9c --- src/sccp_vty.c | 47 +++++++++++++++++++++---- tests/vty/ss7_asp_test.vty | 87 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 109 insertions(+), 25 deletions(-) diff --git a/src/sccp_vty.c b/src/sccp_vty.c index 46afb49..b251f58 100644 --- a/src/sccp_vty.c +++ b/src/sccp_vty.c @@ -142,19 +142,32 @@ DEFUN(show_sccp_connections, show_sccp_connections_cmd, } /* sccp-timer <1-999999> - * (cmdstr and doc are dynamically generated from osmo_sccp_timer_names.) */ + * (cmdstr and doc are dynamically generated from osmo_sccp_timer_names.) + * The VTY API does not allow passing optional choice args like [(a|b|c)], so there is a separate command + * for adding optional unit indicators. */ DEFUN(sccp_timer, sccp_timer_cmd, NULL, NULL) { struct osmo_ss7_instance *ss7 = vty->index; enum osmo_sccp_timer timer = get_string_value(osmo_sccp_timer_names, argv[0]); - struct osmo_sccp_timer_val set_val = { .s = atoi(argv[1]) }; + struct osmo_sccp_timer_val set_val = {}; + int val = atoi(argv[1]); + const char *unit = argc > 2? argv[2] : "s"; if (timer < 0 || timer >= OSMO_SCCP_TIMERS_COUNT) { vty_out(vty, "%% Invalid timer: %s%s", argv[0], VTY_NEWLINE); return CMD_WARNING; } + if (!strcmp(unit, "m")) + set_val.s = val * 60; + else if (!strcmp(unit, "s")) + set_val.s = val; + else if (!strcmp(unit, "ms")) { + set_val.s = val / 1000; + set_val.us = (val % 1000) * 1000; + } + osmo_ss7_ensure_sccp(ss7); if (!ss7->sccp) { vty_out(vty, "%% Error: cannot instantiate SCCP instance%s", VTY_NEWLINE); @@ -165,15 +178,25 @@ DEFUN(sccp_timer, sccp_timer_cmd, return CMD_SUCCESS; } +/* sccp-timer <1-999999> (m|s|ms) + * (cmdstr and doc are dynamically generated from osmo_sccp_timer_names.) */ +ALIAS(sccp_timer, sccp_timer_unit_cmd, NULL, NULL) + static const char *osmo_sccp_timer_val_name(const struct osmo_sccp_timer_val *val) { static char buf[16]; - snprintf(buf, sizeof(buf), "%u", val->s); + if (val->us) { + uint32_t ms = val->us / 1000 + val->s * 1000; + snprintf(buf, sizeof(buf), "%u ms", ms); + } else if (val->s % 60) + snprintf(buf, sizeof(buf), "%u", val->s); + else + snprintf(buf, sizeof(buf), "%u m", val->s / 60); return buf; } -static void gen_sccp_timer_cmd_strs(struct cmd_element *cmd) +static void gen_sccp_timer_cmd_strs(struct cmd_element *cmd, bool with_units) { int i; char *cmd_str = NULL; @@ -200,11 +223,21 @@ static void gen_sccp_timer_cmd_strs(struct cmd_element *cmd) osmo_talloc_asprintf(tall_vty_ctx, doc_str, "%s (default: %s)\n", osmo_sccp_timer_description(timer), osmo_sccp_timer_val_name(def)); + + } osmo_talloc_asprintf(tall_vty_ctx, cmd_str, ") <1-999999>"); osmo_talloc_asprintf(tall_vty_ctx, doc_str, - "Timer value, in seconds\n"); + "Timer value, in seconds unless a different unit keyword follows\n"); + + if (with_units) { + osmo_talloc_asprintf(tall_vty_ctx, cmd_str, " (m|s|ms)"); + osmo_talloc_asprintf(tall_vty_ctx, doc_str, + "Timer value unit: supply value in minutes instead of seconds\n" + "Timer value unit: supply value in seconds, which is also the default unit\n" + "Timer value unit: supply value in milliseconds instead of seconds\n"); + } cmd->string = cmd_str; cmd->doc = doc_str; @@ -260,6 +293,8 @@ void osmo_sccp_vty_init(void) install_element_ve(&show_sccp_connections_cmd); install_element_ve(&show_sccp_timers_cmd); - gen_sccp_timer_cmd_strs(&sccp_timer_cmd); + gen_sccp_timer_cmd_strs(&sccp_timer_cmd, false); + gen_sccp_timer_cmd_strs(&sccp_timer_unit_cmd, true); install_element(L_CS7_NODE, &sccp_timer_cmd); + install_element(L_CS7_NODE, &sccp_timer_unit_cmd); } diff --git a/tests/vty/ss7_asp_test.vty b/tests/vty/ss7_asp_test.vty index a7fe492..5cd4389 100644 --- a/tests/vty/ss7_asp_test.vty +++ b/tests/vty/ss7_asp_test.vty @@ -83,6 +83,7 @@ ss7_asp_vty_test(config-cs7)# list sccp-address NAME no sccp-address NAME sccp-timer (conn_est|ias|iar|rel|repeat_rel|int|guard|reset|reassembly) <1-999999> + sccp-timer (conn_est|ias|iar|rel|repeat_rel|int|guard|reset|reassembly) <1-999999> (m|s|ms) ss7_asp_vty_test(config-cs7)# ? ... @@ -371,31 +372,31 @@ SS7 instance 0 has no SCCP initialized ss7_asp_vty_test(config-cs7)# show running-config ... !sccp-timer -ss7_asp_vty_test(config-cs7)# sccp-timer ias 5 +ss7_asp_vty_test(config-cs7)# sccp-timer ias 5 ms ss7_asp_vty_test(config-cs7)# do show cs7 instance 0 sccp timers -sccp-timer conn_est 60 -sccp-timer ias 5 -sccp-timer iar 900 +sccp-timer conn_est 1 m +sccp-timer ias 5 ms +sccp-timer iar 15 m sccp-timer rel 10 sccp-timer repeat_rel 10 -sccp-timer int 60 -sccp-timer guard 1380 +sccp-timer int 1 m +sccp-timer guard 23 m sccp-timer reset 10 sccp-timer reassembly 10 ss7_asp_vty_test(config-cs7)# show running-config ... !sccp-timer - sccp-timer ias 5 + sccp-timer ias 5 ms ... !sccp-timer -ss7_asp_vty_test(config-cs7)# sccp-timer ias 420 +ss7_asp_vty_test(config-cs7)# sccp-timer ias 7 m ss7_asp_vty_test(config-cs7)# do show cs7 instance 0 sccp timers -sccp-timer conn_est 60 -sccp-timer ias 420 -sccp-timer iar 900 +sccp-timer conn_est 1 m +sccp-timer ias 7 m +sccp-timer iar 15 m sccp-timer rel 10 sccp-timer repeat_rel 10 -sccp-timer int 60 -sccp-timer guard 1380 +sccp-timer int 1 m +sccp-timer guard 23 m sccp-timer reset 10 sccp-timer reassembly 10 ss7_asp_vty_test(config-cs7)# show running-config @@ -405,15 +406,63 @@ ss7_asp_vty_test(config-cs7)# sccp-timer? sccp-timer Configure SCCP timer values, see ITU-T Q.714 ss7_asp_vty_test(config-cs7)# sccp-timer ? - conn_est Waiting for connection confirm message, 1 to 2 minutes (default: 60) - ias Send keep-alive: on an idle connection, delay before sending an Idle Timer message, 5 to 10 minutes (default: 420) - iar Receive keep-alive: on an idle connection, delay until considering a connection as stale, 11 to 21 minutes (default: 900) + conn_est Waiting for connection confirm message, 1 to 2 minutes (default: 1 m) + ias Send keep-alive: on an idle connection, delay before sending an Idle Timer message, 5 to 10 minutes (default: 7 m) + iar Receive keep-alive: on an idle connection, delay until considering a connection as stale, 11 to 21 minutes (default: 15 m) rel Waiting for release complete message, 10 to 20 seconds (default: 10) repeat_rel Waiting for release complete message; or to repeat sending released message after the initial expiry, 10 to 20 seconds (default: 10) - int Waiting for release complete message; or to release connection resources, freeze the LRN and alert a maintenance function after the initial expiry, extending to 1 minute (default: 60) - guard Waiting to resume normal procedure for temporary connection sections during the restart procedure, 23 to 25 minutes (default: 1380) + int Waiting for release complete message; or to release connection resources, freeze the LRN and alert a maintenance function after the initial expiry, extending to 1 minute (default: 1 m) + guard Waiting to resume normal procedure for temporary connection sections during the restart procedure, 23 to 25 minutes (default: 23 m) reset Waiting to release temporary connection section or alert maintenance function after reset request message is sent, 10 to 20 seconds (default: 10) reassembly Waiting to receive all the segments of the remaining segments, single segmented message after receiving the first segment, 10 to 20 seconds (default: 10) ss7_asp_vty_test(config-cs7)# sccp-timer conn_est ? - <1-999999> Timer value, in seconds + <1-999999> Timer value, in seconds unless a different unit keyword follows + +ss7_asp_vty_test(config-cs7)# sccp-timer conn_est 1 ? + m Timer value unit: supply value in minutes instead of seconds + s Timer value unit: supply value in seconds, which is also the default unit + ms Timer value unit: supply value in milliseconds instead of seconds + + +ss7_asp_vty_test(config-cs7)# sccp-timer iar 1 ms +ss7_asp_vty_test(config-cs7)# do show cs7 instance 0 sccp timers +... +sccp-timer iar 1 ms +... + +ss7_asp_vty_test(config-cs7)# sccp-timer iar 1000 ms +ss7_asp_vty_test(config-cs7)# do show cs7 instance 0 sccp timers +... +sccp-timer iar 1 +... + +ss7_asp_vty_test(config-cs7)# sccp-timer iar 60000 ms +ss7_asp_vty_test(config-cs7)# do show cs7 instance 0 sccp timers +... +sccp-timer iar 1 m +... + +ss7_asp_vty_test(config-cs7)# sccp-timer iar 60500 ms +ss7_asp_vty_test(config-cs7)# do show cs7 instance 0 sccp timers +... +sccp-timer iar 60500 ms +... + +ss7_asp_vty_test(config-cs7)# sccp-timer iar 65000 ms +ss7_asp_vty_test(config-cs7)# do show cs7 instance 0 sccp timers +... +sccp-timer iar 65 +... + +ss7_asp_vty_test(config-cs7)# sccp-timer iar 65 +ss7_asp_vty_test(config-cs7)# do show cs7 instance 0 sccp timers +... +sccp-timer iar 65 +... + +ss7_asp_vty_test(config-cs7)# sccp-timer iar 180 +ss7_asp_vty_test(config-cs7)# do show cs7 instance 0 sccp timers +... +sccp-timer iar 3 m +... -- cgit v1.2.3