blob: b16474876764bd3481db6951d22c1b34401612b3 [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;
12}
13
14/* port between individual per-connection components and this dispatcher */
15type port MGCP_Conn_PT message {
16 inout MgcpCommand, MgcpResponse;
17} with { extension "internal" };
18
19
20type 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
37type function MGCPCreateCallback(MgcpCommand cmd, charstring id)
38runs on MGCP_Emulation_CT return MGCP_ConnHdlr;
39
40type record MGCPOps {
41 MGCPCreateCallback create_cb
42}
43
44type 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 Willmann955627a2018-01-17 15:22:32 +010051function main(MGCPOps ops, MGCP_conn_parameters p, charstring id) runs on MGCP_Emulation_CT {
Daniel Willmannfa870f52018-01-17 12:37:14 +010052 var Result res;
53 g_mgcp_id := id;
54 //f_conn_table_init();
Daniel Willmann955627a2018-01-17 15:22:32 +010055 f_expect_table_init();
Daniel Willmannfa870f52018-01-17 12:37:14 +010056
57 map(self:MGCP, system:MGCP_CODEC_PT);
58 res := MGCP_CodecPort_CtrlFunct.f_IPL4_connect(MGCP, p.mgw_ip,
59p.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 Willmann955627a2018-01-17 15:22:32 +010069 [] 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 Willmannfa870f52018-01-17 12:37:14 +010073 }
74 }
75}
76
77/* "Expect" Handling */
78
79/* */
Daniel Willmann955627a2018-01-17 15:22:32 +010080type record ExpectCriteria {
81 MgcpConnectionId connid optional,
82 MgcpEndpoint endpoint optional,
83 MgcpTransId transid optional
Daniel Willmannfa870f52018-01-17 12:37:14 +010084}
85
86type record ExpectData {
87 ExpectCriteria crit optional,
Daniel Willmann955627a2018-01-17 15:22:32 +010088 MGCP_ConnHdlr vc_conn
Daniel Willmannfa870f52018-01-17 12:37:14 +010089}
90
Daniel Willmann955627a2018-01-17 15:22:32 +010091signature MGCPEM_register(in ExpectCriteria cmd, in MGCP_ConnHdlr hdlr);
Daniel Willmannfa870f52018-01-17 12:37:14 +010092
93type port MGCPEM_PROC_PT procedure {
94 inout MGCPEM_register;
95} with { extension "internal" };
96
97function f_get_mgcp_by_crit(ExpectCriteria crit)
98return 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 */
106function ExpectedCreateCallback(MgcpCommand cmd, charstring id)
107runs 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 Willmann955627a2018-01-17 15:22:32 +0100115 if (not ispresent(ExpectTable[i].crit)) {
Daniel Willmannfa870f52018-01-17 12:37:14 +0100116 continue;
117 }
Daniel Willmann955627a2018-01-17 15:22:32 +0100118 /* FIXME: Ignore criteria for now */
119// mgcpcmd := f_get_mgcp_by_crit(ExpectTable[i].crit);
120// if (match(cmd, mgcpcmd)) {
Daniel Willmannfa870f52018-01-17 12:37:14 +0100121 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 Willmann955627a2018-01-17 15:22:32 +0100127// }
Daniel Willmannfa870f52018-01-17 12:37:14 +0100128 }
129 setverdict(fail, "Couldn't find Expect for CRCX", cmd);
130 return ret;
131}
132
133private function f_create_expect(ExpectCriteria crit, MGCP_ConnHdlr hdlr)
134runs 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 Willmann955627a2018-01-17 15:22:32 +0100155private function f_expect_table_init()
156runs 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 Willmannfa870f52018-01-17 12:37:14 +0100163}