diff --git a/fr-net/gen_links.sh b/fr-net/gen_links.sh index 29f4399f8..413676c37 100755 --- a/fr-net/gen_links.sh +++ b/fr-net/gen_links.sh @@ -47,7 +47,7 @@ gen_links $DIR $FILES DIR=../library FILES="Misc_Helpers.ttcn General_Types.ttcn Osmocom_VTY_Functions.ttcn Native_Functions.ttcn Native_FunctionDefs.cc GSM_Types.ttcn Osmocom_Types.ttcn " -FILES+="NS_Provider_IPL4.ttcn NS_Provider_FR.ttcn NS_Emulation.ttcnpp " +FILES+="RAW_NS.ttcnpp NS_Provider_IPL4.ttcn NS_Provider_FR.ttcn NS_Emulation.ttcnpp " FILES+="BSSGP_Emulation.ttcnpp Osmocom_Gb_Types.ttcn " FILES+="LLC_Templates.ttcn " gen_links $DIR $FILES diff --git a/fr/gen_links.sh b/fr/gen_links.sh index 29f4399f8..413676c37 100755 --- a/fr/gen_links.sh +++ b/fr/gen_links.sh @@ -47,7 +47,7 @@ gen_links $DIR $FILES DIR=../library FILES="Misc_Helpers.ttcn General_Types.ttcn Osmocom_VTY_Functions.ttcn Native_Functions.ttcn Native_FunctionDefs.cc GSM_Types.ttcn Osmocom_Types.ttcn " -FILES+="NS_Provider_IPL4.ttcn NS_Provider_FR.ttcn NS_Emulation.ttcnpp " +FILES+="RAW_NS.ttcnpp NS_Provider_IPL4.ttcn NS_Provider_FR.ttcn NS_Emulation.ttcnpp " FILES+="BSSGP_Emulation.ttcnpp Osmocom_Gb_Types.ttcn " FILES+="LLC_Templates.ttcn " gen_links $DIR $FILES diff --git a/gbproxy/gen_links.sh b/gbproxy/gen_links.sh index d6bf22e0a..6d4ab81d9 100755 --- a/gbproxy/gen_links.sh +++ b/gbproxy/gen_links.sh @@ -84,7 +84,7 @@ gen_links $DIR $FILES DIR=../library FILES="Misc_Helpers.ttcn General_Types.ttcn GSM_Types.ttcn GSM_RR_Types.ttcn Osmocom_Types.ttcn RLCMAC_Templates.ttcn RLCMAC_Types.ttcn RLCMAC_CSN1_Templates.ttcn RLCMAC_CSN1_Types.ttcn RLCMAC_EncDec.cc " -FILES+="NS_Provider_IPL4.ttcn NS_Provider_FR.ttcn NS_Emulation.ttcnpp " +FILES+="RAW_NS.ttcnpp NS_Provider_IPL4.ttcn NS_Provider_FR.ttcn NS_Emulation.ttcnpp " FILES+="BSSGP_Emulation.ttcnpp Osmocom_Gb_Types.ttcn " FILES+="PCUIF_Types.ttcn " FILES+="Osmocom_CTRL_Types.ttcn Osmocom_CTRL_Functions.ttcn Osmocom_CTRL_Adapter.ttcn " diff --git a/library/NS_Provider_IPL4.ttcn b/library/NS_Provider_IPL4.ttcn index 774c08a8b..09e7dc0e2 100644 --- a/library/NS_Provider_IPL4.ttcn +++ b/library/NS_Provider_IPL4.ttcn @@ -27,6 +27,7 @@ module NS_Provider_IPL4 { import from Misc_Helpers all; import from NS_Emulation all; +import from RAW_NS all; import from NS_Types all; import from IPL4asp_Types all; @@ -42,6 +43,7 @@ type component NS_Provider_IPL4_CT extends NS_Provider_CT { /* per-NSVC ports and state */ port NS_PROVIDER_PT NSVC[NUM_MAX_NSVC]; + var boolean g_nsvc_bound[NUM_MAX_NSVC]; var PerNsvcState g_nsvc[NUM_MAX_NSVC]; /* management port via which */ @@ -54,31 +56,35 @@ type record PerNsvcState { NSVC_CT vc_nsvc }; -signature NSPIP_add_nsvc(charstring remote_ip, PortNumber remote_port, NSVC_CT vc_nsvc); -signature NSPIP_del_nsvc(charstring remote_ip, PortNumber remote_port); +signature NSPIP_add_nsvc(charstring remote_ip, PortNumber remote_port, NSVC_CT vc_nsvc) return integer; +signature NSPIP_del_nsvc(charstring remote_ip, PortNumber remote_port) return integer; type port NSPIP_PROC_PT procedure { inout NSPIP_add_nsvc, NSPIP_del_nsvc; } with { extension "internal" }; /* add a new NSVC to the provider */ -private function f_nsvc_add(PerNsvcState nsvc) runs on NS_Provider_IPL4_CT +private function f_nsvc_add(PerNsvcState nsvc) 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) { + if (g_nsvc_bound[i] == false) { g_nsvc[i] := nsvc; - connect(self:NSVC[i], nsvc.vc_nsvc:NSCP); - NSVC[i].send(NS_Provider_Evt:{link_status := NS_PROV_LINK_STATUS_UP}); - return; + g_nsvc_bound[i] := true; + if (isbound(nsvc.vc_nsvc) and nsvc.vc_nsvc != null) { + connect(self:NSVC[i], nsvc.vc_nsvc:NSCP); + NSVC[i].send(NS_Provider_Evt:{link_status := NS_PROV_LINK_STATUS_UP}); + } + return i; } } Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Overflow of g_nsvc array")); + return -1; } -private function f_nsvc_del(PerNsvcState nsvc) runs on NS_Provider_IPL4_CT +private function f_nsvc_del(PerNsvcState nsvc) 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_bound[i] and g_nsvc[i].remote_ip == nsvc.remote_ip and g_nsvc[i].remote_port == nsvc.remote_port) { g_nsvc[i] := { @@ -86,19 +92,23 @@ private function f_nsvc_del(PerNsvcState nsvc) runs on NS_Provider_IPL4_CT remote_port := -, vc_nsvc := null } + g_nsvc_bound[i] := false; NSVC[i].send(NS_Provider_Evt:{link_status := NS_PROV_LINK_STATUS_DOWN}); - disconnect(self:NSVC[i], nsvc.vc_nsvc:NSCP); - return; + if (isbound(g_nsvc[i].vc_nsvc) and g_nsvc[i].vc_nsvc != null) { + disconnect(self:NSVC[i], nsvc.vc_nsvc:NSCP); + } + return i; } } Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("attempt to delete unknown NSVC")); + return -1; } private function f_get_nsvc_idx(charstring remote_ip, PortNumber remote_port) 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_bound[i] and g_nsvc[i].remote_ip == remote_ip and g_nsvc[i].remote_port == remote_port) { return i; } @@ -109,6 +119,7 @@ runs on NS_Provider_IPL4_CT return integer 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_bound[i] := false; } /* in order to support any number of NSVC on this endpoiint, we only bind the socket @@ -182,12 +193,14 @@ function main(NSVCConfiguration config, NSConfiguration nsconfig, charstring id) /* 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; + var integer idx; + idx := f_nsvc_add(PerNsvcState:{remote_ip, remote_port, vc_nsvc}); + PROC.reply(NSPIP_add_nsvc:{remote_ip, remote_port, vc_nsvc} value 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}); - PROC.reply(NSPIP_del_nsvc:{remote_ip, remote_port}) to vc_caller; + var integer idx; + idx := f_nsvc_del(PerNsvcState:{remote_ip, remote_port}); + PROC.reply(NSPIP_del_nsvc:{remote_ip, remote_port} value idx) to vc_caller; } } /* alt */ @@ -197,9 +210,20 @@ function main(NSVCConfiguration config, NSConfiguration nsconfig, charstring id) 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 { + var integer idx := -1; NSPIP_PROC.call(NSPIP_add_nsvc:{remote_ip, remote_port, vc_nsvc}) to vc_ipep { - [] NSPIP_PROC.getreply(NSPIP_add_nsvc:{?,?,?}); + [] NSPIP_PROC.getreply(NSPIP_add_nsvc:{?,?,?}) -> value idx; } } +function f_nspip_add_nsvc2(NS_Provider_IPL4_CT vc_ipep, charstring remote_ip, PortNumber remote_port) +runs on RAW_NS_CT return integer { + var integer idx := -1; + NSPIP_PROC.call(NSPIP_add_nsvc:{remote_ip, remote_port, null}) to vc_ipep { + [] NSPIP_PROC.getreply(NSPIP_add_nsvc:{?,?,?}) -> value idx; + } + + return idx; +} + } /* module */ diff --git a/library/RAW_NS.ttcnpp b/library/RAW_NS.ttcnpp index 42efb7d56..6930a727b 100644 --- a/library/RAW_NS.ttcnpp +++ b/library/RAW_NS.ttcnpp @@ -25,16 +25,24 @@ import from NS_Provider_IPL4 all; 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 rawns_initialized := false; } public altstep as_Tguard() runs on RAW_NS_CT { @@ -44,6 +52,21 @@ public altstep as_Tguard() runs on RAW_NS_CT { } } +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,31 +75,58 @@ function f_init_ns_codec(NSConfiguration ns_config, integer idx := 0, float guar activate(as_Tguard()); } + if (not rawns_initialized) { + for (var integer i := 0; i < sizeof(ip_prov); i := i+1) { + ip_prov[i].vc_NSP_IP := null; + } + rawns_initialized := true; + } + if (not isbound(g_nsconfig)) { g_nsconfig := ns_config; } if (ischosen(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)); + var integer prov_idx := f_find_ip_provider(ns_config.nsvc[idx].provider.ip); + /* Connect the UDP socket + * 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)); + } + var integer port_idx := f_nspip_add_nsvc2(ip_prov[prov_idx].vc_NSP_IP, ns_config.nsvc[idx].provider.ip.remote_ip, ns_config.nsvc[idx].provider.ip.remote_udp_port); + connect(self:NSCP[idx], ip_prov[prov_idx].vc_NSP_IP:NSVC[port_idx]); + /* the NS_PROV_LINK_STATUS_UP is not sent by the NS_Provider_IPL4 because we connect the port manual */ #ifdef NS_EMULATION_FR } else if (ischosen(ns_config.nsvc[idx].provider.fr)) { vc_NSP_FR[idx] := NS_Provider_FR_CT.create(id & "-provFR"); connect(self:NSCP[idx], vc_NSP_FR[idx]:NSE); vc_NSP_FR[idx].start(NS_Provider_FR.main(ns_config.nsvc[idx], ns_config, id)); + NSCP[idx].receive(NS_Provider_Evt:{link_status:=NS_PROV_LINK_STATUS_UP}); #endif } else { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported NS provider"); } - - NSCP[idx].receive(NS_Provider_Evt:{link_status:=NS_PROV_LINK_STATUS_UP}); } 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) { diff --git a/ns/gen_links.sh b/ns/gen_links.sh index 6ebee9d18..42e5547d8 100755 --- a/ns/gen_links.sh +++ b/ns/gen_links.sh @@ -52,7 +52,7 @@ gen_links $DIR $FILES DIR=../library FILES="Misc_Helpers.ttcn General_Types.ttcn Osmocom_VTY_Functions.ttcn Native_Functions.ttcn Native_FunctionDefs.cc GSM_Types.ttcn GSM_RR_Types.ttcn Osmocom_Types.ttcn RLCMAC_Templates.ttcn RLCMAC_Types.ttcn RLCMAC_CSN1_Templates.ttcn RLCMAC_CSN1_Types.ttcn RLCMAC_EncDec.cc " FILES+="StatsD_Types.ttcn StatsD_CodecPort.ttcn StatsD_CodecPort_CtrlFunct.ttcn StatsD_CodecPort_CtrlFunctdef.cc StatsD_Checker.ttcn " -FILES+="NS_Provider_IPL4.ttcn NS_Provider_FR.ttcn NS_Emulation.ttcnpp " +FILES+="RAW_NS.ttcnpp NS_Provider_IPL4.ttcn NS_Provider_FR.ttcn NS_Emulation.ttcnpp " FILES+="BSSGP_Emulation.ttcnpp Osmocom_Gb_Types.ttcn " FILES+="LLC_Templates.ttcn L3_Templates.ttcn L3_Common.ttcn " FILES+="PCUIF_Types.ttcn PCUIF_CodecPort.ttcn RAW_NS.ttcnpp " diff --git a/pcu/gen_links.sh b/pcu/gen_links.sh index 98a9ff36a..d0f3acecf 100755 --- a/pcu/gen_links.sh +++ b/pcu/gen_links.sh @@ -51,7 +51,7 @@ gen_links $DIR $FILES DIR=../library FILES="Misc_Helpers.ttcn General_Types.ttcn Osmocom_VTY_Functions.ttcn Native_Functions.ttcn Native_FunctionDefs.cc GSM_Types.ttcn GSM_RR_Types.ttcn Osmocom_Types.ttcn RLCMAC_Templates.ttcn RLCMAC_Types.ttcn RLCMAC_CSN1_Templates.ttcn RLCMAC_CSN1_Types.ttcn RLCMAC_EncDec.cc " FILES+="StatsD_Types.ttcn StatsD_CodecPort.ttcn StatsD_CodecPort_CtrlFunct.ttcn StatsD_CodecPort_CtrlFunctdef.cc StatsD_Checker.ttcn " -FILES+="NS_Provider_IPL4.ttcn NS_Emulation.ttcnpp " +FILES+="RAW_NS.ttcnpp NS_Provider_IPL4.ttcn NS_Emulation.ttcnpp " FILES+="BSSGP_Emulation.ttcnpp Osmocom_Gb_Types.ttcn " FILES+="LLC_Templates.ttcn L3_Templates.ttcn L3_Common.ttcn " FILES+="PCUIF_Types.ttcn PCUIF_CodecPort.ttcn RAW_NS.ttcnpp " diff --git a/sgsn/gen_links.sh b/sgsn/gen_links.sh index 8cffa1725..510b449e9 100755 --- a/sgsn/gen_links.sh +++ b/sgsn/gen_links.sh @@ -84,7 +84,7 @@ gen_links $DIR $FILES DIR=../library FILES="Misc_Helpers.ttcn General_Types.ttcn GSM_Types.ttcn GSM_RR_Types.ttcn Osmocom_Types.ttcn RLCMAC_Templates.ttcn RLCMAC_Types.ttcn RLCMAC_CSN1_Templates.ttcn RLCMAC_CSN1_Types.ttcn RLCMAC_EncDec.cc " -FILES+="NS_Provider_IPL4.ttcn NS_Emulation.ttcnpp PCUIF_Types.ttcn " +FILES+="RAW_NS.ttcnpp NS_Provider_IPL4.ttcn NS_Emulation.ttcnpp PCUIF_Types.ttcn " FILES+="BSSGP_Emulation.ttcnpp Osmocom_Gb_Types.ttcn " FILES+="Osmocom_CTRL_Types.ttcn Osmocom_CTRL_Functions.ttcn Osmocom_CTRL_Adapter.ttcn " FILES+="Osmocom_VTY_Functions.ttcn "