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;
 
diff --git a/mme/gen_links.sh b/mme/gen_links.sh
index e0a038b..f10a161 100755
--- a/mme/gen_links.sh
+++ b/mme/gen_links.sh
@@ -51,6 +51,14 @@
 FILES="BSSGP_EncDec.cc  BSSGP_Types.ttcn"
 gen_links $DIR $FILES
 
+DIR=$BASEDIR/titan.ProtocolModules.GTPv2_v13.7.0/src
+FILES="GTPv2_Types.ttcn"
+gen_links $DIR $FILES
+
+DIR=$BASEDIR/osmo-uecups/ttcn3
+FILES="UECUPS_CodecPort.ttcn  UECUPS_CodecPort_CtrlFunct.ttcn  UECUPS_CodecPort_CtrlFunctDef.cc UECUPS_Types.ttcn "
+gen_links $DIR $FILES
+
 DIR=$BASEDIR/titan.ProtocolModules.DIAMETER_ProtocolModule_Generator/src
 FILES="DIAMETER_EncDec.cc"
 gen_links $DIR $FILES
@@ -69,6 +77,8 @@
 FILES+="NAS_Templates.ttcn GTPv2_PrivateExtensions.ttcn GTPv2_Templates.ttcn "
 FILES+="DIAMETER_Types.ttcn DIAMETER_CodecPort.ttcn DIAMETER_CodecPort_CtrlFunct.ttcn DIAMETER_CodecPort_CtrlFunctDef.cc DIAMETER_Emulation.ttcn DIAMETER_Templates.ttcn "
 FILES+="GTP_CodecPort.ttcn GTP_CodecPort_CtrlFunct.ttcn GTP_CodecPort_CtrlFunctDef.cc GTP_Emulation.ttcn GTP_Templates.ttcn Osmocom_Gb_Types.ttcn "
+FILES+="GTPv2_PrivateExtensions.ttcn GTPv2_Templates.ttcn "
+FILES+="GTPv2_CodecPort.ttcn GTPv2_CodecPort_CtrlFunctDef.cc GTPv2_CodecPort_CtrlFunct.ttcn GTPv2_Emulation.ttcn "
 FILES+="BSSGP_Emulation.ttcnpp Osmocom_Gb_Types.ttcn "
 gen_links $DIR $FILES
 
diff --git a/mme/regen_makefile.sh b/mme/regen_makefile.sh
index df5151e..e153d35 100755
--- a/mme/regen_makefile.sh
+++ b/mme/regen_makefile.sh
@@ -12,6 +12,7 @@
 	GTPC_EncDec.cc
 	GTPU_EncDec.cc
 	GTP_CodecPort_CtrlFunctDef.cc
+	GTPv2_CodecPort_CtrlFunctDef.cc
 	IPL4asp_PT.cc
 	IPL4asp_discovery.cc
 	LTE_CryptoFunctionDefs.cc
@@ -23,6 +24,7 @@
 	TCCEncoding.cc
 	TCCInterface.cc
 	TELNETasp_PT.cc
+	UECUPS_CodecPort_CtrlFunctDef.cc
 "