bsc: Fix TC_rsl_drop_counter due to IPA_Emulation component being alive-type

IPA_Emulation component was marked with the "alive" type recently, in
order to avoid race conditions leading to errors during tear down of the
test.

It turns out, the way "alive" keeps the component alive is by means of
not closing the sockets when the component is stopped. As a result,
TC_rsl_drop_counter test stopped working properly because it was
specting a TCP FIN to be sent to osmo-bsc when the component was
stopped.

In order to fix it, add a new CFG port to the IPA_Emulation component on
which one can operate. Add a a new method to tell the component to close
the socket.

Then, put that in BSC_Tests into a function which was actually unsued
until now, and use it in the test in order to have the specific logic
enclosed in a function helper.

Fixes: 7138913d664c33b2404e3d293ab820fb3516ff73
Change-Id: I68163b053313d9907ba8e40954a5933d14cb7db6
diff --git a/library/IPA_Emulation.ttcnpp b/library/IPA_Emulation.ttcnpp
index 5cdf324..0cd7314 100644
--- a/library/IPA_Emulation.ttcnpp
+++ b/library/IPA_Emulation.ttcnpp
@@ -206,6 +206,9 @@
 type component IPA_Emulation_CT {
 	/* down-facing port to IPA codec port */
 	port IPA_CODEC_PT IPA_PORT;
+	/* Down facing port to configure the component */
+	port IPA_CFG_PT CFG_PORT;
+
 #ifdef IPA_EMULATION_SCCP
 	/* up-facing port to SCCP */
 	port MTP3asp_SP_PT MTP3_SP_PORT;
@@ -286,6 +289,17 @@
 	osmo_rand := ""
 };
 
+signature IPA_CFG_disconnect(inout IPL4asp_Types.Result res);
+type port IPA_CFG_PT procedure {
+	inout IPA_CFG_disconnect;
+} with { extension "internal" };
+
+function f_ipa_cfg_disconnect(IPA_CFG_PT pt, inout IPL4asp_Types.Result res) {
+	pt.call(IPA_CFG_disconnect:{res}) {
+		[] pt.getreply(IPA_CFG_disconnect:{?}) -> param (res) {};
+	}
+}
+
 /* Function to use to connect as client to a remote IPA Server */
 function f_connect(charstring remote_host, IPL4asp_Types.PortNumber remote_port,
 		   charstring local_host, IPL4asp_Types.PortNumber local_port,
@@ -318,6 +332,25 @@
 	g_is_bsc_mgw := false;
 }
 
+private function f_close() runs on IPA_Emulation_CT return IPL4asp_Types.Result {
+	var IPL4asp_Types.Result res;
+	select (g_mode) {
+	case (IPA_MODE_CLIENT) {
+		res := IPA_CodecPort_CtrlFunct.f_IPL4_close(IPA_PORT, g_self_conn_id, {tcp := {}});
+		g_self_conn_id := -1;
+	}
+	case (IPA_MODE_SERVER) {
+		res := IPA_CodecPort_CtrlFunct.f_IPL4_close(IPA_PORT, g_last_conn_id, {tcp := {}});
+		g_last_conn_id := -1;
+	}
+	case else {
+		setverdict(fail, "Unknown mode");
+		mtc.stop;
+		}
+	}
+	return res;
+}
+
 #ifdef IPA_EMULATION_SCCP
 template ASP_MTP3_TRANSFERind ts_MTP3_XFER_ind(integer opc, octetstring data) := {
 	sio := { '10'B, '00'B, '0011'B },
@@ -661,6 +694,7 @@
 	var Socket_API_Definitions.PortEvent port_evt;
 	var octetstring payload;
 	var ASP_IPA_Unitdata ipa_ud;
+	var IPL4asp_Types.Result res;
 #ifdef IPA_EMULATION_CTRL
 	var CtrlMessage ctrl_msg;
 #endif
@@ -888,6 +922,11 @@
 			IPA_PORT.send(f_from_asp(f_ipa_conn_id(), ipa_ud));
 		}
 
+		/* Received call to configure/operate the component */
+		[] CFG_PORT.getcall(IPA_CFG_disconnect:{?}) {
+			res := f_close();
+			CFG_PORT.reply(IPA_CFG_disconnect:{res});
+		}
 
 		}
 	}