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