Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 1 | /* MME (Mobility Management Engine) test suite in TTCN-3 |
| 2 | * (C) 2019 Harald Welte <laforge@gnumonks.org> |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Released under the terms of GNU General Public License, Version 2 or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 9 | */ |
| 10 | |
| 11 | module MME_Tests { |
| 12 | |
| 13 | import from SGsAP_Types all; |
| 14 | import from SGsAP_Templates all; |
| 15 | import from SGsAP_Emulation all; |
| 16 | |
| 17 | import from L3_Templates all; |
| 18 | import from DNS_Helpers all; |
| 19 | |
| 20 | friend module MME_Tests_SGsAP; |
| 21 | |
| 22 | type component MTC_CT { |
| 23 | var SGsAP_Emulation_CT vc_SGsAP; |
| 24 | port SGsAP_PT SGsAP_UNIT; |
| 25 | port SGsAPEM_PROC_PT SGsAP_PROC; |
| 26 | } |
| 27 | |
| 28 | type component ConnHdlr extends SGsAP_ConnHdlr { |
| 29 | var ConnHdlrPars g_pars; |
| 30 | timer g_Tguard := 30.0; |
| 31 | } |
| 32 | |
| 33 | type record ConnHdlrPars { |
| 34 | hexstring imsi |
| 35 | } |
| 36 | |
| 37 | modulepar { |
| 38 | charstring mp_sgs_local_ip := "127.0.0.1"; |
| 39 | integer mp_sgs_local_port := 29118; |
| 40 | charstring mp_vlr_name := "vlr.example.net"; |
| 41 | charstring mp_mme_name := "mmec01.mmegi0001.mme.epc.mnc070.mcc901.3gppnetwork.org"; |
| 42 | } |
| 43 | |
| 44 | /* send incoming unit data messages (like reset) to global SGsAP_UNIT port */ |
| 45 | friend function ForwardUnitdataCallback(PDU_SGsAP msg) |
| 46 | runs on SGsAP_Emulation_CT return template PDU_SGsAP { |
| 47 | SGsAP_UNIT.send(msg); |
| 48 | return omit; |
| 49 | } |
| 50 | |
| 51 | friend function f_init_sgsap(charstring id) runs on MTC_CT { |
| 52 | id := id & "-SGsAP"; |
| 53 | var SGsAPOps ops := { |
| 54 | create_cb := refers(SGsAP_Emulation.ExpectedCreateCallback), |
| 55 | unitdata_cb := refers(ForwardUnitdataCallback) |
| 56 | } |
| 57 | var SGsAP_conn_parameters pars := { |
| 58 | remote_ip := "", |
| 59 | remote_sctp_port := -1, |
| 60 | local_ip := mp_sgs_local_ip, |
| 61 | local_sctp_port := mp_sgs_local_port |
| 62 | } |
| 63 | |
| 64 | vc_SGsAP := SGsAP_Emulation_CT.create(id); |
| 65 | map(vc_SGsAP:SGsAP, system:SGsAP_CODEC_PT); |
| 66 | connect(vc_SGsAP:SGsAP_PROC, self:SGsAP_PROC); |
| 67 | connect(vc_SGsAP:SGsAP_UNIT, self:SGsAP_UNIT); |
| 68 | vc_SGsAP.start(SGsAP_Emulation.main(ops, pars, id)); |
| 69 | } |
| 70 | |
| 71 | /* generate parameters for a connection handler */ |
| 72 | friend function f_init_pars(integer imsi_suffix) |
| 73 | runs on MTC_CT return ConnHdlrPars { |
| 74 | var ConnHdlrPars pars := { |
| 75 | imsi := f_gen_imsi(imsi_suffix) |
| 76 | }; |
| 77 | return pars; |
| 78 | } |
| 79 | |
| 80 | type function void_fn(ConnHdlrPars pars) runs on ConnHdlr; |
| 81 | |
| 82 | /* start a connection handler with given parameters */ |
| 83 | friend function f_start_handler_with_pars(void_fn fn, ConnHdlrPars pars, integer s1ap_idx := 0) |
| 84 | runs on MTC_CT return ConnHdlr { |
| 85 | var ConnHdlr vc_conn; |
| 86 | var charstring id := testcasename() & int2str(s1ap_idx); |
| 87 | |
| 88 | vc_conn := ConnHdlr.create(id); |
| 89 | /* SGsAP part */ |
| 90 | connect(vc_conn:SGsAP, vc_SGsAP:SGsAP_CLIENT); |
| 91 | connect(vc_conn:SGsAP_PROC, vc_SGsAP:SGsAP_PROC); |
| 92 | |
| 93 | /* We cannot use vc_conn.start(f_init_handler(fn, id, pars)); as we cannot have |
| 94 | * a stand-alone 'derefers()' call, see https://www.eclipse.org/forums/index.php/t/1091364/ */ |
| 95 | vc_conn.start(derefers(fn)(pars)); |
| 96 | return vc_conn; |
| 97 | } |
| 98 | |
| 99 | /* altstep for the global guard timer */ |
| 100 | private altstep as_Tguard()runs on ConnHdlr { |
| 101 | [] g_Tguard.timeout { |
| 102 | setverdict(fail, "Tguard timeout"); |
| 103 | mtc.stop; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | friend function f_init_handler(ConnHdlrPars pars, float t_guard := 30.0) runs on ConnHdlr { |
| 108 | /* make parameters available via component variable */ |
| 109 | g_pars := pars; |
| 110 | /* start guard timre and activate it as default */ |
| 111 | g_Tguard.start(t_guard); |
| 112 | activate(as_Tguard()); |
| 113 | /* Route all SGsAP mesages for our IMSIto us */ |
| 114 | f_create_sgsap_expect(pars.imsi); |
| 115 | } |
| 116 | |
| 117 | |
| 118 | } |