MME_Tests: Add S11/GTPv2 interface

The S11 interface is used by the MME to talk to the SGW-C. At the moment
we do not simulate the S11 interface in our testcases. This is in particular
a problem for TC_s1ap_attach, which needs to answer the Create Session
Request, comming from the MME in order to continue.

As a first step, lets add evrything that is required to run an S11
interface in the testsuite.

Change-Id: I545dd6cef3cef7283f2e04c2406a2703c2fdd01a
Related: OS#5760
diff --git a/mme/MME_Tests.ttcn b/mme/MME_Tests.ttcn
index cc75377..55cb021 100644
--- a/mme/MME_Tests.ttcn
+++ b/mme/MME_Tests.ttcn
@@ -44,6 +44,10 @@
 import from Osmocom_Types all;
 import from Osmocom_Gb_Types all;
 
+import from GTPv2_Types all;
+import from GTPv2_Templates all;
+import from GTPv2_Emulation all;
+
 friend module MME_Tests_SGsAP;
 
 /* (maximum) number of emulated eNBs */
@@ -84,6 +88,10 @@
 	/* Gn interface (GTPv1C) of emulated SGSN (Rel. 7) */
 	var GTP_Emulation_CT vc_GTP;
 
+	/* S11 interface (GTPv2C) of emulated SGW-C */
+	var GTPv2_Emulation_CT vc_GTP2;
+	port GTP2EM_PT TEID0;
+
 	var UeParams g_ue_pars[NUM_UE];
 }
 
@@ -116,7 +124,7 @@
 	return substr(encoded, 11, global_enb_id_len);
 }
 
-type component ConnHdlr extends S1AP_ConnHdlr, SGsAP_ConnHdlr, DIAMETER_ConnHdlr, GTP_ConnHdlr {
+type component ConnHdlr extends S1AP_ConnHdlr, SGsAP_ConnHdlr, DIAMETER_ConnHdlr, GTP_ConnHdlr, GTP2_ConnHdlr {
 	var ConnHdlrPars g_pars;
 	timer g_Tguard := 30.0;
 
@@ -153,6 +161,12 @@
 	charstring mp_gn_local_ip := "127.0.0.22";
 	integer mp_gn_local_port := 2123;
 	charstring mp_gn_remote_ip := "127.0.0.2";
+
+	/* S11 interface (GTPv2C, interface between MME and SGW) */
+	charstring mp_s11_local_ip := "127.0.0.3";
+	integer mp_s11_local_port := 2123;
+	charstring mp_s11_remote_ip := "127.0.0.2";
+	integer mp_s11_remote_port := 2123;
 }
 
 /* send incoming unit data messages (like reset) to global SGsAP_UNIT port */
@@ -290,7 +304,25 @@
 	vc_GTP.start(GTP_Emulation.main(gtp_cfg));
 }
 
-friend template (value) TAI ts_enb_S1AP_TAI(EnbParams enb) := {
+friend function f_init_gtpv2_s11(charstring id) runs on MTC_CT {
+	id := id & "-GTPV2";
+
+	var Gtp2EmulationCfg cfg := {
+		gtpc_bind_ip := mp_s11_local_ip,
+		gtpc_bind_port := mp_s11_local_port,
+		gtpc_remote_ip := mp_s11_remote_ip,
+		gtpc_remote_port := mp_s11_remote_port,
+		sgw_role := true,
+		use_gtpu_daemon := false
+	};
+
+	vc_GTP2 := GTPv2_Emulation_CT.create(id);
+	map(vc_GTP2:GTP2C, system:GTP2C);
+	connect(vc_GTP2:TEID0, self:TEID0);
+	vc_GTP2.start(GTPv2_Emulation.main(cfg));
+}
+
+friend template (value) S1AP_IEs.TAI ts_enb_S1AP_TAI(EnbParams enb) := {
 	pLMNidentity := enb.global_enb_id.pLMNidentity,
 	tAC := enb.supported_tas[0].tAC,
 	iE_Extensions := omit
@@ -339,6 +371,10 @@
 		connect(vc_conn:GTP, vc_GTP:CLIENT);
 		connect(vc_conn:GTP_PROC, vc_GTP:CLIENT_PROC);
 	}
+	if (isbound(vc_GTP2)) {
+		connect(vc_conn:GTP2, vc_GTP2:CLIENT);
+		connect(vc_conn:GTP2_PROC, vc_GTP2:CLIENT_PROC);
+	}
 
 	/* We cannot use vc_conn.start(f_init_handler(fn, id, pars)); as we cannot have
 	 * a stand-alone 'derefers()' call, see https://www.eclipse.org/forums/index.php/t/1091364/ */
@@ -371,8 +407,8 @@
 
 
 
-friend function f_s1ap_setup(integer idx := 0, template Cause cause := omit) runs on MTC_CT {
-	var template (present) Cause exp_cause;
+friend function f_s1ap_setup(integer idx := 0, template S1AP_IEs.Cause cause := omit) runs on MTC_CT {
+	var template (present) S1AP_IEs.Cause exp_cause;
 	var boolean exp_fail := false;
 	timer T := 5.0;
 	if (not istemplatekind(cause, "omit")) {
@@ -911,7 +947,7 @@
 	f_init_s1ap(id, 3);
 	f_s1ap_setup(0);
 
-	var template (value) Cause reset_cause := {misc := om_intervention};
+	var template (value) S1AP_IEs.Cause reset_cause := {misc := om_intervention};
 	var template (value) ResetType reset_type := {s1_Interface := reset_all};
 	timer T := 5.0;