gprs_ns2: add signalling & data weights for UDP binds

Allow to assign a signalling and data weight to UDP binds.
Those weights will be used when doing dynamic configuration over
IP-SNS.
This is only the first part which only uses the assigned weights
when doing a new SNS configuration.
The outgoing change weight procedure will be supported in a later patch
when the SNS fsm supports outgoing procedures.

Related: SYS#5354
Change-Id: I5133e4229377d44772a9af28628a2bc420fea34b
diff --git a/src/gb/gprs_ns2_vty.c b/src/gb/gprs_ns2_vty.c
index 3646080..55f88b1 100644
--- a/src/gb/gprs_ns2_vty.c
+++ b/src/gb/gprs_ns2_vty.c
@@ -66,6 +66,8 @@
 	int dscp;
 	bool accept_ipaccess;
 	bool accept_sns;
+	uint8_t ip_sns_sig_weight;
+	uint8_t ip_sns_data_weight;
 };
 
 /* TODO: this should into osmo timer */
@@ -118,6 +120,8 @@
 		return NULL;
 	}
 
+	vbind->ip_sns_sig_weight = 1;
+	vbind->ip_sns_data_weight = 1;
 	llist_add(&vbind->list, &binds);
 	return vbind;
 }
@@ -328,6 +332,8 @@
 			vty_out(vty, "  accept-ipaccess%s", VTY_NEWLINE);
 		if (vbind->dscp)
 			vty_out(vty, "  dscp %u%s", vbind->dscp, VTY_NEWLINE);
+		vty_out(vty, "   ip-sns signalling-weight %u data-weight %u%s",
+			vbind->ip_sns_sig_weight, vbind->ip_sns_data_weight, VTY_NEWLINE);
 		break;
 	default:
 		return;
@@ -611,6 +617,34 @@
 	return CMD_SUCCESS;
 }
 
+DEFUN(cfg_ns_bind_ip_sns_weight, cfg_ns_bind_ip_sns_weight_cmd,
+      "ip-sns signalling-weight <0-254> data-weight <0-254>",
+      "IP SNS\n"
+      "signalling weight used by IP-SNS dynamic configuration\n"
+      "signalling weight used by IP-SNS dynamic configuration\n"
+      "data weight used by IP-SNS dynamic configuration\n"
+      "data weight used by IP-SNS dynamic configuration\n")
+{
+	struct vty_bind *vbind = vty->index;
+	struct gprs_ns2_vc_bind *bind;
+
+	int signalling = atoi(argv[0]);
+	int data = atoi(argv[1]);
+
+	if (vbind->ll != GPRS_NS2_LL_UDP) {
+		vty_out(vty, "ip-sns signalling-weight <0-254> data-weight <0-254> can be only used with UDP bind%s",
+			VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
+	vbind->ip_sns_data_weight = data;
+	vbind->ip_sns_sig_weight = signalling;
+	bind = gprs_ns2_bind_by_name(vty_nsi, vbind->name);
+	if (bind)
+		gprs_ns2_ip_bind_set_sns_weight(bind, signalling, data);
+
+	return CMD_SUCCESS;
+}
 
 DEFUN(cfg_ns_bind_fr, cfg_ns_bind_fr_cmd,
       "fr NETIF (fr|frnet)",
@@ -1686,6 +1720,7 @@
 	install_lib_element(L_NS_BIND_NODE, &cfg_no_ns_bind_listen_cmd);
 	install_lib_element(L_NS_BIND_NODE, &cfg_ns_bind_dscp_cmd);
 	install_lib_element(L_NS_BIND_NODE, &cfg_no_ns_bind_dscp_cmd);
+	install_lib_element(L_NS_BIND_NODE, &cfg_ns_bind_ip_sns_weight_cmd);
 	install_lib_element(L_NS_BIND_NODE, &cfg_ns_bind_ipaccess_cmd);
 	install_lib_element(L_NS_BIND_NODE, &cfg_no_ns_bind_ipaccess_cmd);
 	install_lib_element(L_NS_BIND_NODE, &cfg_ns_bind_fr_cmd);