gprs_ns2_vty: add optional argument signalling and data weights to `nsvc udp`

A static configured UDP NSVC can have signalling and data weights

Related: SYS#5354
Change-Id: Id363937c64e786c55e3136401ebdb44052415e0f
diff --git a/src/gb/gprs_ns2_vty.c b/src/gb/gprs_ns2_vty.c
index 01409bb..4bd7cde 100644
--- a/src/gb/gprs_ns2_vty.c
+++ b/src/gb/gprs_ns2_vty.c
@@ -1038,14 +1038,8 @@
 	return CMD_SUCCESS;
 }
 
-DEFUN(cfg_ns_nse_nsvc_udp, cfg_ns_nse_nsvc_udp_cmd,
-      "nsvc udp BIND " VTY_IPV46_CMD " <1-65535>",
-      "NS Virtual Connection\n"
-      "NS over UDP\n"
-      "A unique bind identifier created by ns bind\n"
-      "Remote IPv4 Address\n" "Remote IPv6 Address\n"
-      "Remote UDP Port\n"
-      )
+static int ns_nse_nsvc_udp_cmds(struct vty *vty, const char *bind_name, const char *remote_char, uint16_t port,
+				uint16_t sig_weight, uint16_t data_weight)
 {
 	struct gprs_ns2_vc_bind *bind;
 	struct gprs_ns2_vc *nsvc;
@@ -1053,10 +1047,8 @@
 	bool dialect_modified = false;
 	bool ll_modified = false;
 
-	const char *bind_name = argv[0];
 	struct osmo_sockaddr_str remote_str;
 	struct osmo_sockaddr remote;
-	uint16_t port = atoi(argv[2]);
 
 	if (nse->ll == GPRS_NS2_LL_UNDEF) {
 		nse->ll = GPRS_NS2_LL_UDP;
@@ -1078,7 +1070,7 @@
 		goto err;
 	}
 
-	if (osmo_sockaddr_str_from_str(&remote_str, argv[1], port)) {
+	if (osmo_sockaddr_str_from_str(&remote_str, remote_char, port)) {
 		vty_out(vty, "Can not parse IPv4/IPv6 or port.%s", VTY_NEWLINE);
 		goto err;
 	}
@@ -1106,6 +1098,8 @@
 		vty_out(vty, "Can not create NS-VC.%s", VTY_NEWLINE);
 		goto err;
 	}
+	nsvc->sig_weight = sig_weight;
+	nsvc->data_weight = data_weight;
 	nsvc->persistent = true;
 
 	return CMD_SUCCESS;
@@ -1118,6 +1112,45 @@
 	return CMD_WARNING;
 }
 
+DEFUN(cfg_ns_nse_nsvc_udp, cfg_ns_nse_nsvc_udp_cmd,
+      "nsvc udp BIND " VTY_IPV46_CMD " <1-65535>",
+      "NS Virtual Connection\n"
+      "NS over UDP\n"
+      "A unique bind identifier created by ns bind\n"
+      "Remote IPv4 Address\n" "Remote IPv6 Address\n"
+      "Remote UDP Port\n")
+{
+	const char *bind_name = argv[0];
+	const char *remote = argv[1];
+	uint16_t port = atoi(argv[2]);
+	uint16_t sig_weight = 1;
+	uint16_t data_weight = 1;
+
+	return ns_nse_nsvc_udp_cmds(vty, bind_name, remote, port, sig_weight, data_weight);
+}
+
+DEFUN(cfg_ns_nse_nsvc_udp_weights, cfg_ns_nse_nsvc_udp_weights_cmd,
+      "nsvc udp BIND " VTY_IPV46_CMD " <1-65535> signalling-weight <0-254> data-weight <0-254>",
+      "NS Virtual Connection\n"
+      "NS over UDP\n"
+      "A unique bind identifier created by ns bind\n"
+      "Remote IPv4 Address\n" "Remote IPv6 Address\n"
+      "Remote UDP Port\n"
+      "Signalling weight of the NSVC (default = 1)\n"
+      "Signalling weight of the NSVC (default = 1)\n"
+      "Data weight of the NSVC (default = 1)\n"
+      "Data weight of the NSVC (default = 1)\n"
+      )
+{
+	const char *bind_name = argv[0];
+	const char *remote = argv[1];
+	uint16_t port = atoi(argv[2]);
+	uint16_t sig_weight = atoi(argv[3]);
+	uint16_t data_weight = atoi(argv[4]);
+
+	return ns_nse_nsvc_udp_cmds(vty, bind_name, remote, port, sig_weight, data_weight);
+}
+
 DEFUN(cfg_no_ns_nse_nsvc_udp, cfg_no_ns_nse_nsvc_udp_cmd,
       "no nsvc udp BIND " VTY_IPV46_CMD " <1-65535>",
       NO_STR
@@ -2033,6 +2066,7 @@
 	install_lib_element(L_NS_NSE_NODE, &cfg_no_ns_nse_nsvci_cmd);
 	install_lib_element(L_NS_NSE_NODE, &cfg_no_ns_nse_nsvc_fr_dlci_cmd);
 	install_lib_element(L_NS_NSE_NODE, &cfg_ns_nse_nsvc_udp_cmd);
+	install_lib_element(L_NS_NSE_NODE, &cfg_ns_nse_nsvc_udp_weights_cmd);
 	install_lib_element(L_NS_NSE_NODE, &cfg_no_ns_nse_nsvc_udp_cmd);
 	install_lib_element(L_NS_NSE_NODE, &cfg_ns_nse_nsvc_ipa_cmd);
 	install_lib_element(L_NS_NSE_NODE, &cfg_no_ns_nse_nsvc_ipa_cmd);