Change in osmo-ttcn3-hacks[master]: RAW_NS/NS_Provider_IPL4: allow to use the new NSVC interface

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

lynxis lazus gerrit-no-reply at lists.osmocom.org
Tue May 25 15:48:49 UTC 2021


lynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/24401 )


Change subject: RAW_NS/NS_Provider_IPL4: allow to use the new NSVC interface
......................................................................

RAW_NS/NS_Provider_IPL4: allow to use the new NSVC interface

RAW_NS used previous a single TTCN3 port for a single UDP port
(source/listen side).
This has the limitation that only a single NSVC could be tested for a
local UDP port. However SNS tests require multiple NSVCs over a single UDP port.
NS_Provider_IPL4 already supports multiple NSVCs for the NS_Emulation.
Extend the support in NS_Provider_IPL4 to also allow RAW_NS to use
multiple NSVCs.

Change-Id: Iafd9310e04066958914201da0cbdcd563bd5c976
---
M library/NS_Provider_IPL4.ttcn
M library/RAW_NS.ttcnpp
2 files changed, 92 insertions(+), 19 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/01/24401/1

diff --git a/library/NS_Provider_IPL4.ttcn b/library/NS_Provider_IPL4.ttcn
index 774c08a..31ad351 100644
--- a/library/NS_Provider_IPL4.ttcn
+++ b/library/NS_Provider_IPL4.ttcn
@@ -28,6 +28,7 @@
 import from Misc_Helpers all;
 import from NS_Emulation all;
 import from NS_Types all;
+import from RAW_NS all;
 
 import from IPL4asp_Types all;
 import from IPL4asp_PortType all;
@@ -51,10 +52,12 @@
 type record PerNsvcState {
 	charstring remote_ip,
 	PortNumber remote_port,
-	NSVC_CT	vc_nsvc
+	NSVC_CT	vc_nsvc,
+	RAW_NS_CT vc_raw,
+	integer vc_raw_idx
 };
 
-signature NSPIP_add_nsvc(charstring remote_ip, PortNumber remote_port, NSVC_CT vc_nsvc);
+signature NSPIP_add_nsvc(charstring remote_ip, PortNumber remote_port, NSVC_CT vc_nsvc, RAW_NS_CT vc_raw, integer vc_raw_idx);
 signature NSPIP_del_nsvc(charstring remote_ip, PortNumber remote_port);
 
 type port NSPIP_PROC_PT procedure {
@@ -65,9 +68,13 @@
 private function f_nsvc_add(PerNsvcState nsvc) runs on NS_Provider_IPL4_CT
 {
 	for (var integer i := 0; i < sizeof(g_nsvc); i := i+1) {
-		if (g_nsvc[i].vc_nsvc == null) {
+		if (g_nsvc[i].vc_nsvc == null and g_nsvc[i].vc_raw == null) {
 			g_nsvc[i] := nsvc;
-			connect(self:NSVC[i], nsvc.vc_nsvc:NSCP);
+			if (g_nsvc[i].vc_nsvc != null) {
+				connect(self:NSVC[i], nsvc.vc_nsvc:NSCP);
+			} else {
+				connect(self:NSVC[i], nsvc.vc_raw:NSCP[nsvc.vc_raw_idx]);
+			}
 			NSVC[i].send(NS_Provider_Evt:{link_status := NS_PROV_LINK_STATUS_UP});
 			return;
 		}
@@ -78,16 +85,22 @@
 private function f_nsvc_del(PerNsvcState nsvc) runs on NS_Provider_IPL4_CT
 {
 	for (var integer i := 0; i < sizeof(g_nsvc); i := i+1) {
-		if (g_nsvc[i].vc_nsvc != null and
+		if ((g_nsvc[i].vc_nsvc != null or g_nsvc[i].vc_raw != null) and
 		    g_nsvc[i].remote_ip == nsvc.remote_ip and
 		    g_nsvc[i].remote_port == nsvc.remote_port) {
 			g_nsvc[i] := {
 				remote_ip := -,
 				remote_port := -,
-				vc_nsvc := null
+				vc_nsvc := null,
+				vc_raw := null,
+				vc_raw_idx := -1
 			}
 			NSVC[i].send(NS_Provider_Evt:{link_status := NS_PROV_LINK_STATUS_DOWN});
-			disconnect(self:NSVC[i], nsvc.vc_nsvc:NSCP);
+			if (nsvc.vc_nsvc != null) {
+				disconnect(self:NSVC[i], nsvc.vc_nsvc:NSCP);
+			} else {
+				disconnect(self:NSVC[i], nsvc.vc_raw:NSCP[nsvc.vc_raw_idx]);
+			}
 			return;
 		}
 	}
@@ -98,7 +111,7 @@
 runs on NS_Provider_IPL4_CT return integer
 {
 	for (var integer i := 0; i < sizeof(g_nsvc); i := i+1) {
-		if (g_nsvc[i].vc_nsvc != null and
+		if ((g_nsvc[i].vc_nsvc != null or g_nsvc[i].vc_raw != null) and
 		    g_nsvc[i].remote_ip == remote_ip and g_nsvc[i].remote_port == remote_port) {
 			return i;
 		}
@@ -109,6 +122,7 @@
 function main(NSVCConfiguration config, NSConfiguration nsconfig, charstring id) runs on NS_Provider_IPL4_CT {
 	for (var integer i := 0; i < sizeof(g_nsvc); i := i+1) {
 		g_nsvc[i].vc_nsvc := null;
+		g_nsvc[i].vc_raw := null;
 	}
 
 	/* in order to support any number of NSVC on this endpoiint, we only bind the socket
@@ -134,6 +148,8 @@
 	var charstring remote_ip;
 	var PortNumber remote_port;
 	var NSVC_CT vc_nsvc;
+	var RAW_NS_CT vc_raw;
+	var integer vc_raw_idx;
 	var NS_CT vc_caller;
 	alt {
 
@@ -181,9 +197,9 @@
 		}
 
 	/* procedure port to add/remove NSVCs from this provider */
-	[] PROC.getcall(NSPIP_add_nsvc:{?,?,?}) -> param (remote_ip, remote_port, vc_nsvc) sender vc_caller {
-		f_nsvc_add(PerNsvcState:{remote_ip, remote_port, vc_nsvc});
-		PROC.reply(NSPIP_add_nsvc:{remote_ip, remote_port, vc_nsvc}) to vc_caller;
+	[] PROC.getcall(NSPIP_add_nsvc:{?,?,?,?,?}) -> param (remote_ip, remote_port, vc_nsvc, vc_raw, vc_raw_idx) sender vc_caller {
+		f_nsvc_add(PerNsvcState:{remote_ip, remote_port, vc_nsvc, vc_raw, vc_raw_idx});
+		PROC.reply(NSPIP_add_nsvc:{remote_ip, remote_port, vc_nsvc, vc_raw, vc_raw_idx}) to vc_caller;
 		}
 	[] PROC.getcall(NSPIP_del_nsvc:{?,?}) -> param (remote_ip, remote_port) sender vc_caller {
 		f_nsvc_del(PerNsvcState:{remote_ip, remote_port});
@@ -197,9 +213,17 @@
 
 function f_nspip_add_nsvc(NS_Provider_IPL4_CT vc_ipep, charstring remote_ip, PortNumber remote_port, NSVC_CT vc_nsvc)
 runs on NS_CT {
-	NSPIP_PROC.call(NSPIP_add_nsvc:{remote_ip, remote_port, vc_nsvc}) to vc_ipep {
-		[] NSPIP_PROC.getreply(NSPIP_add_nsvc:{?,?,?});
+	NSPIP_PROC.call(NSPIP_add_nsvc:{remote_ip, remote_port, vc_nsvc, null, -1}) to vc_ipep {
+		[] NSPIP_PROC.getreply(NSPIP_add_nsvc:{?,?,?,?,?});
 	}
 }
 
+function f_rawip_add_nsvc(NS_Provider_IPL4_CT vc_ipep, charstring remote_ip, PortNumber remote_port, integer idx)
+runs on RAW_NS_CT {
+	NSPIP_PROC.call(NSPIP_add_nsvc:{remote_ip, remote_port, null, self, idx}) to vc_ipep {
+		[] NSPIP_PROC.getreply(NSPIP_add_nsvc:{?,?,?,?,?});
+	}
+}
+
+
 } /* module */
diff --git a/library/RAW_NS.ttcnpp b/library/RAW_NS.ttcnpp
index 8f986e4..b459eb3 100644
--- a/library/RAW_NS.ttcnpp
+++ b/library/RAW_NS.ttcnpp
@@ -25,16 +25,24 @@
 import from NS_Provider_FR all;
 #endif
 
+type record PerIPProvider {
+	NS_Provider_IPL4_CT vc_NSP_IP,
+	charstring local_ip,
+	PortNumber local_udp_port
+}
+
 public type component RAW_NS_CT {
 	/* UDP port towards the bottom (IUT) */
 	port NS_PROVIDER_PT NSCP[4];
-	var NS_Provider_IPL4_CT vc_NSP_IP[4];
+	var PerIPProvider ip_prov[4];
+	port NSPIP_PROC_PT NSPIP_PROC;
 #ifdef NS_EMULATION_FR
 	var NS_Provider_FR_CT vc_NSP_FR[4];
 #endif
 	var NSConfiguration g_nsconfig;
 	timer g_T_guard;
 	var boolean g_handle_rx_alive := false;
+	var boolean g_initialized := false;
 }
 
 public altstep as_Tguard() runs on RAW_NS_CT {
@@ -44,6 +52,21 @@
 		}
 }
 
+function f_find_ip_provider(NSVCConfigurationIP nsip_config)
+runs on RAW_NS_CT return integer {
+	for (var integer idx := 0; idx < sizeof(ip_prov); idx := idx+1) {
+		if (ip_prov[idx].vc_NSP_IP == null) {
+			continue;
+		}
+
+		if (ip_prov[idx].local_ip == nsip_config.local_ip and
+			ip_prov[idx].local_udp_port == nsip_config.local_udp_port) {
+			return idx;
+		}
+	}
+	return -1;
+}
+
 function f_init_ns_codec(NSConfiguration ns_config, integer idx := 0, float guard_secs := 60.0, charstring id := testcasename()) runs on RAW_NS_CT {
 	var Result res;
 
@@ -52,15 +75,39 @@
 		activate(as_Tguard());
 	}
 
+	if (not g_initialized) {
+		for (var integer i := 0; i < sizeof(ip_prov); i := i+1) {
+			ip_prov[i].vc_NSP_IP := null;
+		}
+		g_initialized := true;
+	}
+
 	if (not isbound(g_nsconfig)) {
 		g_nsconfig := ns_config;
 	}
 
 	if (ischosen(ns_config.nsvc[idx].provider.ip)) {
+		var integer prov_idx := f_find_ip_provider(ns_config.nsvc[idx].provider.ip);
 		/* Connect the UDP socket */
-		vc_NSP_IP[idx] := NS_Provider_IPL4_CT.create(id & "-provIP");
-		connect(self:NSCP[idx], vc_NSP_IP[idx]:NSE);
-		vc_NSP_IP[idx].start(NS_Provider_IPL4.main(ns_config.nsvc[idx], ns_config, id));
+		// check if NS_Provider_IPL4_CT is already created
+		// add list of vc_NSP_IP with entries of source ip/port
+		// add a NSVC to it
+		if (prov_idx == -1) {
+			for (prov_idx := 0; prov_idx < sizeof(ip_prov); prov_idx := prov_idx+1) {
+				if (ip_prov[prov_idx].vc_NSP_IP == null) {
+					break;
+				}
+			}
+			if (prov_idx > sizeof(ip_prov)) {
+				/* TODO: error !! */
+			}
+			ip_prov[prov_idx].local_ip := ns_config.nsvc[idx].provider.ip.local_ip;
+			ip_prov[prov_idx].local_udp_port := ns_config.nsvc[idx].provider.ip.local_udp_port;
+			ip_prov[prov_idx].vc_NSP_IP := NS_Provider_IPL4_CT.create(id & "-provIP" & int2str(prov_idx));
+			connect(self:NSPIP_PROC, ip_prov[prov_idx].vc_NSP_IP:PROC);
+			ip_prov[prov_idx].vc_NSP_IP.start(NS_Provider_IPL4.main(ns_config.nsvc[idx], ns_config, id));
+		}
+		f_rawip_add_nsvc(ip_prov[prov_idx].vc_NSP_IP, ns_config.nsvc[idx].provider.ip.remote_ip, ns_config.nsvc[idx].provider.ip.remote_udp_port, idx);
 #ifdef NS_EMULATION_FR
 	} else if (ischosen(ns_config.nsvc[idx].provider.fr)) {
 		vc_NSP_FR[idx] := NS_Provider_FR_CT.create(id & "-provFR");
@@ -75,8 +122,10 @@
 }
 
 function f_clean_ns_codec() runs on RAW_NS_CT {
-	for (var integer i := 0; i < lengthof(vc_NSP_IP); i := i + 1) {
-		vc_NSP_IP[i].stop;
+	for (var integer i := 0; i < lengthof(ip_prov); i := i + 1) {
+		if (ip_prov[i].vc_NSP_IP != null) {
+			ip_prov[i].vc_NSP_IP.stop;
+		}
 	}
 #ifdef NS_EMULATION_FR
 	for (var integer i := 0; i < lengthof(vc_NSP_FR); i := i + 1) {

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/24401
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: Iafd9310e04066958914201da0cbdcd563bd5c976
Gerrit-Change-Number: 24401
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus <lynxis at fe80.eu>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210525/f276778c/attachment.htm>


More information about the gerrit-log mailing list