aboutsummaryrefslogtreecommitdiffstats
path: root/library/GTP_Emulation.ttcn
diff options
context:
space:
mode:
Diffstat (limited to 'library/GTP_Emulation.ttcn')
-rw-r--r--library/GTP_Emulation.ttcn56
1 files changed, 38 insertions, 18 deletions
diff --git a/library/GTP_Emulation.ttcn b/library/GTP_Emulation.ttcn
index 43c034b8..f7c54a19 100644
--- a/library/GTP_Emulation.ttcn
+++ b/library/GTP_Emulation.ttcn
@@ -16,8 +16,10 @@ import from General_Types all;
import from Osmocom_Types all;
import from GTPC_Types all;
import from GTPU_Types all;
-import from GTP_CodecPort all;
-import from GTP_CodecPort_CtrlFunct all;
+import from GTPv1C_CodecPort all;
+import from GTPv1U_CodecPort all;
+import from GTPv1C_CodecPort_CtrlFunct all;
+import from GTPv1U_CodecPort_CtrlFunct all;
/***********************************************************************
* Main Emulation Component
@@ -30,8 +32,8 @@ const integer GTP1U_PORT := 2152;
type record GtpEmulationCfg {
HostName gtpc_bind_ip,
PortNumber gtpc_bind_port,
- HostName gtpu_bind_ip,
- PortNumber gtpu_bind_port,
+ HostName gtpu_bind_ip optional,
+ PortNumber gtpu_bind_port optional,
boolean sgsn_role
};
@@ -43,6 +45,7 @@ type component GTP_Emulation_CT {
/* Communication with Clients */
port GTPEM_PT CLIENT;
port GTPEM_PROC_PT CLIENT_PROC;
+ port GTPEM_PT CLIENT_DEFAULT;
/* Configuration by the user */
var GtpEmulationCfg g_gtp_cfg;
@@ -133,9 +136,17 @@ function f_gtpc_extract_imsi(PDU_GTPC gtp) return template (omit) hexstring {
} else if (ischosen(gtp.gtpc_pdu.identificationResponse) ){
return gtp.gtpc_pdu.identificationResponse.imsi.digits;
} else if (ischosen(gtp.gtpc_pdu.sgsn_ContextRequest)) {
- return gtp.gtpc_pdu.sgsn_ContextRequest.imsi.digits;
+ if (ispresent(gtp.gtpc_pdu.sgsn_ContextRequest.imsi.digits)) {
+ return gtp.gtpc_pdu.sgsn_ContextRequest.imsi.digits;
+ } else {
+ return omit;
+ }
} else if (ischosen(gtp.gtpc_pdu.sgsn_ContextResponse)) {
- return gtp.gtpc_pdu.sgsn_ContextResponse.imsi.digits;
+ if (ispresent(gtp.gtpc_pdu.sgsn_ContextResponse.imsi.digits)) {
+ return gtp.gtpc_pdu.sgsn_ContextResponse.imsi.digits;
+ } else {
+ return omit;
+ }
} else if (ischosen(gtp.gtpc_pdu.forwardRelocationRequest)) {
return gtp.gtpc_pdu.forwardRelocationRequest.imsi.digits;
} else if (ischosen(gtp.gtpc_pdu.relocationCancelRequest)) {
@@ -163,14 +174,16 @@ private function f_init(GtpEmulationCfg cfg) runs on GTP_Emulation_CT {
var Result res;
map(self:GTPC, system:GTPC);
- res := GTP_CodecPort_CtrlFunct.f_IPL4_listen(GTPC, cfg.gtpc_bind_ip,
+ res := GTPv1C_CodecPort_CtrlFunct.f_IPL4_listen(GTPC, cfg.gtpc_bind_ip,
cfg.gtpc_bind_port, {udp:={}});
g_gtpc_id := res.connId;
- map(self:GTPU, system:GTPU);
- res := GTP_CodecPort_CtrlFunct.f_GTPU_listen(GTPU, cfg.gtpu_bind_ip,
- cfg.gtpu_bind_port, {udp:={}});
- g_gtpu_id := res.connId;
+ if (isvalue(cfg.gtpu_bind_ip) and isvalue(cfg.gtpu_bind_port)) {
+ map(self:GTPU, system:GTPU);
+ res := GTPv1U_CodecPort_CtrlFunct.f_GTPU_listen(GTPU, cfg.gtpu_bind_ip,
+ cfg.gtpu_bind_port, {udp:={}});
+ g_gtpu_id := res.connId;
+ }
g_restart_ctr := f_rnd_octstring(1);
g_c_seq_nr := f_rnd_int(65535);
@@ -199,11 +212,16 @@ function main(GtpEmulationCfg cfg) runs on GTP_Emulation_CT {
vc_conn := f_comp_by_teid(g1c_ud.gtpc.teid);
CLIENT.send(g1c_ud) to vc_conn;
} else {
- /* Send to all clients */
- var integer i;
- for (i := 0; i < sizeof(TidTable); i := i+1) {
- if (isbound(TidTable[i].teid) and TidTable[i].teid == teid) {
- CLIENT.send(g1c_ud) to TidTable[i].vc_conn;
+ /* Check if a default port is set: */
+ if (CLIENT_DEFAULT.checkstate("Connected")) {
+ CLIENT_DEFAULT.send(g1c_ud);
+ } else {
+ /* Send to all clients */
+ var integer i;
+ for (i := 0; i < sizeof(TidTable); i := i+1) {
+ if (isbound(TidTable[i].teid) and TidTable[i].teid == teid) {
+ CLIENT.send(g1c_ud) to TidTable[i].vc_conn;
+ }
}
}
}
@@ -220,7 +238,9 @@ function main(GtpEmulationCfg cfg) runs on GTP_Emulation_CT {
[] CLIENT.receive(Gtp1uUnitdata:?) -> value g1u_ud sender vc_conn {
GTPU.send(g1u_ud);
}
-
+ [] CLIENT_DEFAULT.receive(Gtp1cUnitdata:?) -> value g1c_ud sender vc_conn {
+ GTPC.send(g1c_ud);
+ }
[] CLIENT_PROC.getcall(GTPEM_register_imsi:{?}) -> param(imsi) sender vc_conn {
f_imsi_tbl_add(imsi, vc_conn);
@@ -252,7 +272,7 @@ type port GTPEM_PROC_PT procedure {
} with { extension "internal" };
/***********************************************************************
- * Client Compoennt
+ * Client Component
***********************************************************************/
type component GTP_ConnHdlr {