Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/6406

to look at the new patch set (#3).

Add tests for OS#2714, "close RSL connections from unknown Unit ID".

This adds two new tests: One for RSL, and a second one which performs
the same test on the OML port. Both tests open an IPA connection and
send a unit ID which is unknown to the BSC. The tests expect the BSC
to close the connection immediately.

We need to add handling for a socket error in IPA_Emulation because
otherwise these tests do not pass reliably as some closed connections
are not properly detected.

Change-Id: I6a947d7411a016e4d7650031396cae3575756453
---
M bsc/BSC_Tests.ttcn
M library/IPA_Emulation.ttcn
2 files changed, 104 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks 
refs/changes/06/6406/3

diff --git a/bsc/BSC_Tests.ttcn b/bsc/BSC_Tests.ttcn
index 086830a..a18b17f 100644
--- a/bsc/BSC_Tests.ttcn
+++ b/bsc/BSC_Tests.ttcn
@@ -28,6 +28,7 @@
 import from BSSAP_CodecPort all;
 import from BSSMAP_Templates all;
 import from IPA_Emulation all;
+import from IPA_CodecPort all;
 import from IPA_Types all;
 import from RSL_Types all;
 import from RSL_Emulation all;
@@ -61,6 +62,7 @@
        var BTS_State bts[NUM_BTS];
        /* array of per-BTS RSL test ports */
        port IPA_RSL_PT IPA_RSL[NUM_BTS];
+       port IPA_CODEC_PT IPA; /* Required for compilation of 
TC_rsl_unknown_unit_id() */
 
        var MGCP_Emulation_CT vc_MGCP;
 
@@ -75,6 +77,8 @@
 modulepar {
        /* IP address at which the BSC can be reached */
        charstring mp_bsc_ip := "127.0.0.1";
+       /* port number to which to establish the IPA OML connections */
+       integer mp_bsc_oml_port := 3002;
        /* port number to which to establish the IPA RSL connections */
        integer mp_bsc_rsl_port := 3003;
        /* port number to which to establish the IPA CTRL connection */
@@ -1236,6 +1240,83 @@
 
 /* TODO: Test OML link drop causes counter increment */
 
+/* BSC should close an RSL connection from a BTS with unknown unit ID 
(OS#2714). */
+testcase TC_rsl_unknown_unit_id() runs on test_CT {
+       timer T := 10.0;
+
+       bts[0].rsl.id := "IPA-0-RSL";
+       bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA");
+       bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
+       bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
+       bts[0].rsl.ccm_pars.unit_id := "0/0/0"; /* value which is unknown at 
BTS */
+
+       /* Call a function of our 'parent component' BSSAP_Adapter_CT to start 
the
+        * MSC-side BSSAP emulation */
+       f_bssap_init("VirtMSC", omit);
+
+       f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
+
+       f_init_mgcp("VirtMSC");
+
+       /* start RSL connection */
+       map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
+       connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
+       bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, 
mp_bsc_rsl_port, "", 10000, bts[0].rsl.ccm_pars));
+
+       /* wait for IPA RSL link to connect and then disconnect */
+       T.start;
+       alt {
+       [] IPA_RSL[0].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_DOWN}) {
+               T.stop;
+               setverdict(pass);
+       }
+       [] IPA_RSL[0].receive { repeat }
+       [] T.timeout {
+               setverdict(fail, "Timeout RSL waiting for connection to close");
+               self.stop;
+               }
+       }
+}
+
+/* BSC should close an RSL connection from a BTS with unknown unit ID 
(OS#2714). */
+testcase TC_oml_unknown_unit_id() runs on test_CT {
+       timer T := 10.0;
+
+       bts[0].rsl.id := "IPA-0-RSL";
+       bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA");
+       bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
+       bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
+       bts[0].rsl.ccm_pars.unit_id := "0/0/0"; /* value which is unknown at 
BTS */
+
+       /* Call a function of our 'parent component' BSSAP_Adapter_CT to start 
the
+        * MSC-side BSSAP emulation */
+       f_bssap_init("VirtMSC", omit);
+
+       f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
+
+       f_init_mgcp("VirtMSC");
+
+       /* start OML connection (XXX re-uses RSL port/protocol definitions) */
+       map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
+       connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
+       bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, 
mp_bsc_oml_port, "", 10000, bts[0].rsl.ccm_pars));
+
+       /* wait for IPA OML link to connect and then disconnect */
+       T.start;
+       alt {
+       [] IPA_RSL[0].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_DOWN}) {
+               T.stop;
+               setverdict(pass);
+       }
+       [] IPA_RSL[0].receive { repeat }
+       [] T.timeout {
+               setverdict(fail, "Timeout OML waiting for connection to close");
+               self.stop;
+               }
+       }
+}
+
+
 /***********************************************************************
  * "New world" test cases using RSL_Emulation + BSSMAP_Emulation
  ***********************************************************************/
@@ -1594,6 +1675,9 @@
        execute( TC_paging_imsi_load() );
 
        execute( TC_rsl_drop_counter() );
+       execute( TC_rsl_unknown_unit_id() );
+
+       execute( TC_oml_unknown_unit_id() );
 
        execute( TC_classmark() );
        execute( TC_unsol_ass_fail() );
diff --git a/library/IPA_Emulation.ttcn b/library/IPA_Emulation.ttcn
index b3e28e9..53a86ec 100644
--- a/library/IPA_Emulation.ttcn
+++ b/library/IPA_Emulation.ttcn
@@ -23,6 +23,7 @@
 import from MTP3asp_Types all;
 import from MTP3asp_PortType all;
 import from RSL_Types all;
+import from Socket_API_Definitions all;
 
 import from MGCP_Types all;
 import from GSUP_Types all;
@@ -132,7 +133,7 @@
        port IPA_SP_PT IPA_SP_PORT;
 
        var boolean g_initialized := false;
-       var ConnectionId g_ipa_conn_id := -1;
+       var IPL4asp_Types.ConnectionId g_ipa_conn_id := -1;
        /* Are we a BSC/MGW (truel) or MSC (false) */
        var boolean g_is_bsc_mgw;
 
@@ -167,10 +168,10 @@
 };
 
 /* Function to use to connect as client to a remote IPA Server */
-function f_connect(charstring remote_host, PortNumber remote_port,
-                  charstring local_host, PortNumber local_port,
+function f_connect(charstring remote_host, IPL4asp_Types.PortNumber 
remote_port,
+                  charstring local_host, IPL4asp_Types.PortNumber local_port,
                   IPA_CCM_Parameters ccm_pars := c_IPA_default_ccm_pars) runs 
on IPA_Emulation_CT {
-       var Result res;
+       var IPL4asp_Types.Result res;
        res := IPA_CodecPort_CtrlFunct.f_IPL4_connect(IPA_PORT, remote_host, 
remote_port,
                                                local_host, local_port, 0, { 
tcp:={} });
        g_ipa_conn_id := res.connId;
@@ -179,9 +180,9 @@
 }
 
 /* Function to use to bind to a local port as IPA server, accepting remote 
clients */
-function f_bind(charstring local_host, PortNumber local_port,
+function f_bind(charstring local_host, IPL4asp_Types.PortNumber local_port,
                IPA_CCM_Parameters ccm_pars := c_IPA_default_ccm_pars) runs on 
IPA_Emulation_CT {
-       var Result res;
+       var IPL4asp_Types.Result res;
        res := IPA_CodecPort_CtrlFunct.f_IPL4_listen(IPA_PORT, 
                                                local_host, local_port, { 
tcp:={} });
        g_ipa_conn_id := res.connId;
@@ -324,21 +325,21 @@
        return ret;
 }
 
-private function f_from_asp(ConnectionId connId, ASP_IPA_Unitdata ipa_tx) 
return IPA_Send {
+private function f_from_asp(IPL4asp_Types.ConnectionId connId, 
ASP_IPA_Unitdata ipa_tx) return IPA_Send {
        var IPA_Send ret := valueof(t_IPA_Send(connId, ipa_tx.streamId, 
ipa_tx.payload,
                                                ipa_tx.streamIdExt));
        return ret;
 }
 
-private function f_from_rsl(ConnectionId connId, ASP_RSL_Unitdata rsl_tx) 
return IPA_Send {
+private function f_from_rsl(IPL4asp_Types.ConnectionId connId, 
ASP_RSL_Unitdata rsl_tx) return IPA_Send {
        var octetstring payload := enc_RSL_Message(rsl_tx.rsl);
        var IPA_Send ret := valueof(t_IPA_Send(connId, rsl_tx.streamId, 
payload));
        return ret;
 }
 
 /* main function to use for a client-side IPA implementation */
-function main_client(charstring remote_host, PortNumber remote_port,
-                    charstring local_host, PortNumber local_port,
+function main_client(charstring remote_host, IPL4asp_Types.PortNumber 
remote_port,
+                    charstring local_host, IPL4asp_Types.PortNumber local_port,
                     IPA_CCM_Parameters ccm_pars := c_IPA_default_ccm_pars) 
runs on IPA_Emulation_CT {
        g_mode := IPA_MODE_CLIENT;
        f_connect(remote_host, remote_port, local_host, local_port, ccm_pars);
@@ -347,7 +348,7 @@
 }
 
 /* main function to use for a server-side IPA implementation */
-function main_server(charstring local_host, PortNumber local_port) runs on 
IPA_Emulation_CT {
+function main_server(charstring local_host, IPL4asp_Types.PortNumber 
local_port) runs on IPA_Emulation_CT {
        g_mode := IPA_MODE_SERVER;
        f_bind(local_host, local_port);
        ScanEvents();
@@ -389,6 +390,7 @@
        var ASP_IPA_Unitdata ipa_ud;
        var ASP_MTP3_TRANSFERreq mtp_req;
        var ASP_Event asp_evt;
+       var Socket_API_Definitions.PortEvent port_evt;
        var MgcpCommand mgcp_cmd;
        var MgcpResponse mgcp_rsp;
        var CtrlMessage ctrl_msg;
@@ -456,6 +458,13 @@
                        self.stop;
                }
 
+               [] 
IPA_PORT.receive(Socket_API_Definitions.PortEvent:{result:={errorCode:=ERROR_SOCKET,
 connId:=?, os_error_code:=?, os_error_text:=?}}) -> value port_evt {
+                       log("PortEvent: ERROR_SOCKET: ", port_evt);
+                       g_ipa_conn_id := -1;
+                       f_send_IPA_EVT(t_ASP_IPA_EVT_UD(ASP_IPA_EVENT_DOWN));
+                       self.stop;
+               }
+
                /* Received SCCP -> down into IPA */
                [] MTP3_SP_PORT.receive(ASP_MTP3_TRANSFERreq: ?) -> value 
mtp_req {
                        var IPA_Send ipa_tx := 
valueof(t_IPA_Send(g_ipa_conn_id, IPAC_PROTO_SCCP,

-- 
To view, visit https://gerrit.osmocom.org/6406
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I6a947d7411a016e4d7650031396cae3575756453
Gerrit-PatchSet: 3
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Owner: Stefan Sperling <ssperl...@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder

Reply via email to