blob: 2ab5669578fe1deaecf5bfb0e97af259305ff858 [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
51function main(MGCP_conn_parameters p, charstring id) runs on MGCP_Emulation_CT {
52 var Result res;
53 g_mgcp_id := id;
54 //f_conn_table_init();
55
56 map(self:MGCP, system:MGCP_CODEC_PT);
57 res := MGCP_CodecPort_CtrlFunct.f_IPL4_connect(MGCP, p.mgw_ip,
58p.mgw_udp_port,
59 p.callagent_ip, p.callagent_udp_port, 0, { udp:={} });
60
61
62 while (true) {
63 alt {
64 [] CLIENT.receive(MgcpCommand:?) {
65 }
66 [] MGCP.receive(MGCP_RecvFrom:?) {
67 }
68 }
69 }
70}
71
72/* "Expect" Handling */
73
74/* */
75type union ExpectCriteria {
76 MgcpConnectionId connid,
77 MgcpEndpoint endpoint,
78 MgcpTransId transid
79}
80
81type record ExpectData {
82 ExpectCriteria crit optional,
83 MGCP_ConnHdlr vc_conn optional
84}
85
86signature MGCPEM_register(in MgcpCommand cmd, in MGCP_ConnHdlr hdlr);
87
88type port MGCPEM_PROC_PT procedure {
89 inout MGCPEM_register;
90} with { extension "internal" };
91
92function f_get_mgcp_by_crit(ExpectCriteria crit)
93return template MgcpCommand {
94 template MgcpCommand ret := {
95 };
96
97 return ret;
98}
99
100/* Function that can be used as create_cb and will usse the expect table */
101function ExpectedCreateCallback(MgcpCommand cmd, charstring id)
102runs on MGCP_Emulation_CT return MGCP_ConnHdlr {
103 var MGCP_ConnHdlr ret := null;
104 var template MgcpCommand mgcpcmd;
105 var integer i;
106
107 /* Ensure cmd is a CRCX? */
108
109 for (i := 0; i < sizeof(ExpectTable); i := i+1) {
110 if (not ispresent(ExpectTable[i].vc_conn)) {
111 continue;
112 }
113 mgcpcmd := f_get_mgcp_by_crit(ExpectTable[i].crit);
114 if (match(cmd, mgcpcmd)) {
115 ret := ExpectTable[i].vc_conn;
116 /* Release this entry */
117 ExpectTable[i].crit := omit;
118 ExpectTable[i].vc_conn := null;
119 log("Found Expect[", i, "] for ", cmd, " handled at ", ret);
120 return ret;
121 }
122 }
123 setverdict(fail, "Couldn't find Expect for CRCX", cmd);
124 return ret;
125}
126
127private function f_create_expect(ExpectCriteria crit, MGCP_ConnHdlr hdlr)
128runs on MGCP_Emulation_CT {
129 var integer i;
130
131 /* Check an entry like this is not already presnt */
132 for (i := 0; i < sizeof(ExpectTable); i := i+1) {
133 if (crit == ExpectTable[i].crit) {
134 setverdict(fail, "Crit already present", crit);
135 self.stop;
136 }
137 }
138 for (i := 0; i < sizeof(ExpectTable); i := i+1) {
139 if (not ispresent(ExpectTable[i].crit)) {
140 ExpectTable[i].crit := crit;
141 ExpectTable[i].vc_conn := hdlr;
142 log("Created Expect[", i, "] for ", crit, " to be handled at ", hdlr);
143 return;
144 }
145 }
146 setverdict(fail, "No space left in ExpectTable")
147}
148
149}