Daniel Willmann | fa870f5 | 2018-01-17 12:37:14 +0100 | [diff] [blame] | 1 | module MGCP_Emulation { |
| 2 | |
| 3 | import from MGCP_CodecPort all; |
| 4 | import from MGCP_CodecPort_CtrlFunct all; |
| 5 | import from MGCP_Types all; |
| 6 | import from MGCP_Templates all; |
| 7 | import from Osmocom_Types all; |
| 8 | import from IPL4asp_Types all; |
| 9 | |
| 10 | type component MGCP_ConnHdlr { |
| 11 | port MGCP_Conn_PT MGCP; |
| 12 | } |
| 13 | |
| 14 | /* port between individual per-connection components and this dispatcher */ |
| 15 | type port MGCP_Conn_PT message { |
| 16 | inout MgcpCommand, MgcpResponse; |
| 17 | } with { extension "internal" }; |
| 18 | |
| 19 | |
| 20 | type component MGCP_Emulation_CT { |
| 21 | /* Port facing to the UDP SUT */ |
| 22 | port MGCP_CODEC_PT MGCP; |
| 23 | /* All MGCP_ConnHdlr MGCP ports connect here |
| 24 | * MGCP_Emulation_CT.main needs to figure out what messages |
| 25 | * to send where with CLIENT.send() to vc_conn */ |
| 26 | port MGCP_Conn_PT CLIENT; |
| 27 | /* currently tracked connections */ |
| 28 | // var ConnectionData ConnectionTable[16]; |
| 29 | /* pending expected CRCX */ |
| 30 | var ExpectData ExpectTable[8]; |
| 31 | /* procedure based port to register for incoming connections */ |
| 32 | port MGCPEM_PROC_PT PROC; |
| 33 | |
| 34 | var charstring g_mgcp_id; |
| 35 | } |
| 36 | |
| 37 | type function MGCPCreateCallback(MgcpCommand cmd, charstring id) |
| 38 | runs on MGCP_Emulation_CT return MGCP_ConnHdlr; |
| 39 | |
| 40 | type record MGCPOps { |
| 41 | MGCPCreateCallback create_cb |
| 42 | } |
| 43 | |
| 44 | type record MGCP_conn_parameters { |
| 45 | charstring callagent_ip, |
| 46 | uint16_t callagent_udp_port, |
| 47 | charstring mgw_ip, |
| 48 | uint16_t mgw_udp_port |
| 49 | } |
| 50 | |
Daniel Willmann | 955627a | 2018-01-17 15:22:32 +0100 | [diff] [blame^] | 51 | function main(MGCPOps ops, MGCP_conn_parameters p, charstring id) runs on MGCP_Emulation_CT { |
Daniel Willmann | fa870f5 | 2018-01-17 12:37:14 +0100 | [diff] [blame] | 52 | var Result res; |
| 53 | g_mgcp_id := id; |
| 54 | //f_conn_table_init(); |
Daniel Willmann | 955627a | 2018-01-17 15:22:32 +0100 | [diff] [blame^] | 55 | f_expect_table_init(); |
Daniel Willmann | fa870f5 | 2018-01-17 12:37:14 +0100 | [diff] [blame] | 56 | |
| 57 | map(self:MGCP, system:MGCP_CODEC_PT); |
| 58 | res := MGCP_CodecPort_CtrlFunct.f_IPL4_connect(MGCP, p.mgw_ip, |
| 59 | p.mgw_udp_port, |
| 60 | p.callagent_ip, p.callagent_udp_port, 0, { udp:={} }); |
| 61 | |
| 62 | |
| 63 | while (true) { |
| 64 | alt { |
| 65 | [] CLIENT.receive(MgcpCommand:?) { |
| 66 | } |
| 67 | [] MGCP.receive(MGCP_RecvFrom:?) { |
| 68 | } |
Daniel Willmann | 955627a | 2018-01-17 15:22:32 +0100 | [diff] [blame^] | 69 | [] PROC.getcall(MGCPEM_register:{?,?}) -> param(crit, vc_conn) { |
| 70 | f_create_expect(crit, vc_conn); |
| 71 | PROC.reply(MGCPEM_register:{crit, vc_conn}); |
| 72 | } |
Daniel Willmann | fa870f5 | 2018-01-17 12:37:14 +0100 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | /* "Expect" Handling */ |
| 78 | |
| 79 | /* */ |
Daniel Willmann | 955627a | 2018-01-17 15:22:32 +0100 | [diff] [blame^] | 80 | type record ExpectCriteria { |
| 81 | MgcpConnectionId connid optional, |
| 82 | MgcpEndpoint endpoint optional, |
| 83 | MgcpTransId transid optional |
Daniel Willmann | fa870f5 | 2018-01-17 12:37:14 +0100 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | type record ExpectData { |
| 87 | ExpectCriteria crit optional, |
Daniel Willmann | 955627a | 2018-01-17 15:22:32 +0100 | [diff] [blame^] | 88 | MGCP_ConnHdlr vc_conn |
Daniel Willmann | fa870f5 | 2018-01-17 12:37:14 +0100 | [diff] [blame] | 89 | } |
| 90 | |
Daniel Willmann | 955627a | 2018-01-17 15:22:32 +0100 | [diff] [blame^] | 91 | signature MGCPEM_register(in ExpectCriteria cmd, in MGCP_ConnHdlr hdlr); |
Daniel Willmann | fa870f5 | 2018-01-17 12:37:14 +0100 | [diff] [blame] | 92 | |
| 93 | type port MGCPEM_PROC_PT procedure { |
| 94 | inout MGCPEM_register; |
| 95 | } with { extension "internal" }; |
| 96 | |
| 97 | function f_get_mgcp_by_crit(ExpectCriteria crit) |
| 98 | return template MgcpCommand { |
| 99 | template MgcpCommand ret := { |
| 100 | }; |
| 101 | |
| 102 | return ret; |
| 103 | } |
| 104 | |
| 105 | /* Function that can be used as create_cb and will usse the expect table */ |
| 106 | function ExpectedCreateCallback(MgcpCommand cmd, charstring id) |
| 107 | runs on MGCP_Emulation_CT return MGCP_ConnHdlr { |
| 108 | var MGCP_ConnHdlr ret := null; |
| 109 | var template MgcpCommand mgcpcmd; |
| 110 | var integer i; |
| 111 | |
| 112 | /* Ensure cmd is a CRCX? */ |
| 113 | |
| 114 | for (i := 0; i < sizeof(ExpectTable); i := i+1) { |
Daniel Willmann | 955627a | 2018-01-17 15:22:32 +0100 | [diff] [blame^] | 115 | if (not ispresent(ExpectTable[i].crit)) { |
Daniel Willmann | fa870f5 | 2018-01-17 12:37:14 +0100 | [diff] [blame] | 116 | continue; |
| 117 | } |
Daniel Willmann | 955627a | 2018-01-17 15:22:32 +0100 | [diff] [blame^] | 118 | /* FIXME: Ignore criteria for now */ |
| 119 | // mgcpcmd := f_get_mgcp_by_crit(ExpectTable[i].crit); |
| 120 | // if (match(cmd, mgcpcmd)) { |
Daniel Willmann | fa870f5 | 2018-01-17 12:37:14 +0100 | [diff] [blame] | 121 | ret := ExpectTable[i].vc_conn; |
| 122 | /* Release this entry */ |
| 123 | ExpectTable[i].crit := omit; |
| 124 | ExpectTable[i].vc_conn := null; |
| 125 | log("Found Expect[", i, "] for ", cmd, " handled at ", ret); |
| 126 | return ret; |
Daniel Willmann | 955627a | 2018-01-17 15:22:32 +0100 | [diff] [blame^] | 127 | // } |
Daniel Willmann | fa870f5 | 2018-01-17 12:37:14 +0100 | [diff] [blame] | 128 | } |
| 129 | setverdict(fail, "Couldn't find Expect for CRCX", cmd); |
| 130 | return ret; |
| 131 | } |
| 132 | |
| 133 | private function f_create_expect(ExpectCriteria crit, MGCP_ConnHdlr hdlr) |
| 134 | runs on MGCP_Emulation_CT { |
| 135 | var integer i; |
| 136 | |
| 137 | /* Check an entry like this is not already presnt */ |
| 138 | for (i := 0; i < sizeof(ExpectTable); i := i+1) { |
| 139 | if (crit == ExpectTable[i].crit) { |
| 140 | setverdict(fail, "Crit already present", crit); |
| 141 | self.stop; |
| 142 | } |
| 143 | } |
| 144 | for (i := 0; i < sizeof(ExpectTable); i := i+1) { |
| 145 | if (not ispresent(ExpectTable[i].crit)) { |
| 146 | ExpectTable[i].crit := crit; |
| 147 | ExpectTable[i].vc_conn := hdlr; |
| 148 | log("Created Expect[", i, "] for ", crit, " to be handled at ", hdlr); |
| 149 | return; |
| 150 | } |
| 151 | } |
| 152 | setverdict(fail, "No space left in ExpectTable") |
| 153 | } |
| 154 | |
Daniel Willmann | 955627a | 2018-01-17 15:22:32 +0100 | [diff] [blame^] | 155 | private function f_expect_table_init() |
| 156 | runs on MGCP_Emulation_CT { |
| 157 | var integer i; |
| 158 | for (i := 0; i < sizeof(ExpectTable); i := i + 1) { |
| 159 | ExpectTable[i].crit := omit; |
| 160 | } |
| 161 | } |
| 162 | |
Daniel Willmann | fa870f5 | 2018-01-17 12:37:14 +0100 | [diff] [blame] | 163 | } |