Change in libosmo-sccp[master]: vty: SCCP timers: add optional units

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/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Thu Sep 27 15:52:52 UTC 2018


Neels Hofmeyr has uploaded this change for review. ( https://gerrit.osmocom.org/11130


Change subject: vty: SCCP timers: add optional units
......................................................................

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
---
M src/sccp_vty.c
M tests/vty/ss7_asp_test.vty
2 files changed, 109 insertions(+), 25 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmo-sccp refs/changes/30/11130/1

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 @@
 }
 
 /* sccp-timer <name> <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 @@
 	return CMD_SUCCESS;
 }
 
+/* sccp-timer <name> <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 @@
 		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 @@
 	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 cb8dc85..d9b1d97 100644
--- a/tests/vty/ss7_asp_test.vty
+++ b/tests/vty/ss7_asp_test.vty
@@ -83,6 +83,7 @@
   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)# ?
 ...
@@ -367,31 +368,31 @@
 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
@@ -401,15 +402,63 @@
   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
+  <cr>  
+
+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
+...

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

Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I020d5dab19bc67e8444ed548db15b2a4d8871a9c
Gerrit-Change-Number: 11130
Gerrit-PatchSet: 1
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180927/d494a494/attachment.htm>


More information about the gerrit-log mailing list