blob: 7f7b6c4e9c55b41f65637bd62876e54b47418d0b [file] [log] [blame]
Alexander Couzens3c268da2020-09-07 04:25:05 +02001module RAW_NS {
2
3/* Osmocom NS test suite for NS in TTCN-3
4 * (C) 2018-2019 Harald Welte <laforge@gnumonks.org>
5 * All rights reserved.
6 *
7 * Released under the terms of GNU General Public License, Version 2 or
8 * (at your option) any later version.
9 *
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 */
12
13import from General_Types all;
14import from Osmocom_Types all;
Alexander Couzens3c268da2020-09-07 04:25:05 +020015import from Osmocom_Gb_Types all;
16import from NS_CodecPort all;
17import from NS_Types all;
18import from BSSGP_Types all;
19import from NS_CodecPort all;
20import from NS_CodecPort_CtrlFunct all;
21import from NS_Emulation all;
22import from Native_Functions all;
23import from IPL4asp_Types all;
24
25public type component RAW_NS_CT {
26 /* UDP port towards the bottom (IUT) */
27 port NS_CODEC_PT NSCP[4];
28 var ConnectionId g_ns_conn_id[4] := {-1, -1, -1, -1};
29 var NSConfiguration g_nsconfig[4];
30 timer g_T_guard;
31}
32
33public altstep as_Tguard() runs on RAW_NS_CT {
34 [] g_T_guard.timeout {
35 setverdict(fail, "Timeout of T_guard");
36 mtc.stop;
37 }
38}
39
Alexander Couzens2beaa202020-09-11 20:08:41 +020040function f_init_ns_codec(NSConfiguration ns_config, integer idx := 0, float guard_secs := 60.0, integer tc_offset := 0) runs on RAW_NS_CT {
Alexander Couzens3c268da2020-09-07 04:25:05 +020041 var Result res;
42
43 if (not g_T_guard.running) {
44 g_T_guard.start(guard_secs);
45 activate(as_Tguard());
46 }
47
48 if (not isbound(g_nsconfig) or not isbound(g_nsconfig[idx])) {
49 /* copy most parts from mp_nsconfig */
Alexander Couzens2beaa202020-09-11 20:08:41 +020050 g_nsconfig[idx] := ns_config;
Alexander Couzens3c268da2020-09-07 04:25:05 +020051 /* adjust those parts different for each NS-VC */
Harald Welte90f19742020-11-06 19:34:40 +010052 g_nsconfig[idx].nsvc[0].nsvci := ns_config.nsvc[0].nsvci + idx;
53 g_nsconfig[idx].nsvc[0].provider.ip.local_udp_port := ns_config.nsvc[0].provider.ip.local_udp_port + idx + tc_offset;
Alexander Couzens3c268da2020-09-07 04:25:05 +020054 }
55
56 map(self:NSCP[idx], system:NSCP);
57 /* Connect the UDP socket */
Harald Welte5e8573e2020-09-13 15:32:56 +020058 var NSConfiguration nscfg := g_nsconfig[idx];
Harald Welte90f19742020-11-06 19:34:40 +010059 var NSVCConfiguration nsvc_cfg := nscfg.nsvc[0];
Harald Welte5e8573e2020-09-13 15:32:56 +020060 log("connecting NSCP[", idx, "] to ", nscfg);
Harald Welte90f19742020-11-06 19:34:40 +010061 res := f_IPL4_connect(NSCP[idx], nsvc_cfg.provider.ip.remote_ip, nsvc_cfg.provider.ip.remote_udp_port,
62 nsvc_cfg.provider.ip.local_ip, nsvc_cfg.provider.ip.local_udp_port, 0, { udp := {}});
Alexander Couzens3c268da2020-09-07 04:25:05 +020063 if (not ispresent(res.connId)) {
64 setverdict(fail, "Could not connect NS UDP socket, check your configuration ", g_nsconfig[idx]);
65 mtc.stop;
66 }
67 g_ns_conn_id[idx] := res.connId;
68
69}
70
Alexander Couzens195c9e72020-10-26 23:09:16 +010071public altstep ax_rx_fail_on_any_ns(integer idx := 0) runs on RAW_NS_CT {
Alexander Couzens3c268da2020-09-07 04:25:05 +020072 var NS_RecvFrom nrf;
Alexander Couzensf57ff032020-09-11 14:27:57 +020073 [] NSCP[idx].receive(t_NS_RecvFrom(?)) -> value nrf {
Alexander Couzens3c268da2020-09-07 04:25:05 +020074 setverdict(fail, "Received unexpected NS: ", nrf);
75 mtc.stop;
76 }
Alexander Couzens195c9e72020-10-26 23:09:16 +010077}
78
79function f_ns_exp(template PDU_NS exp_rx, integer idx := 0) runs on RAW_NS_CT return PDU_NS {
80 var NS_RecvFrom nrf;
81 log("f_ns_exp() expecting ", exp_rx);
82 /* last activated altstep has the lowest priority */
83 var default d := activate(ax_rx_fail_on_any_ns());
84 alt {
85 [] NSCP[idx].receive(t_NS_RecvFrom(exp_rx)) -> value nrf { }
Alexander Couzens3c268da2020-09-07 04:25:05 +020086 }
Alexander Couzens195c9e72020-10-26 23:09:16 +010087 deactivate(d);
Alexander Couzens3c268da2020-09-07 04:25:05 +020088 return nrf.msg;
89}
90
91/* perform outbound NS-ALIVE procedure */
92function f_outgoing_ns_alive(integer idx := 0) runs on RAW_NS_CT {
93 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], t_NS_ALIVE));
94 alt {
95 [] NSCP[idx].receive(t_NS_RecvFrom(t_NS_ALIVE_ACK));
96 [] NSCP[idx].receive { repeat; }
97 }
98}
99
100/* perform outbound NS-ALIVE procedure */
101function f_outgoing_ns_alive_no_ack(integer idx := 0, float tout := 10.0) runs on RAW_NS_CT {
102 timer T := tout;
103 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], t_NS_ALIVE));
104 T.start;
105 alt {
106 [] NSCP[idx].receive(t_NS_RecvFrom(t_NS_ALIVE_ACK)) {
107 setverdict(fail, "Received unexpected NS-ALIVE ACK");
108 }
109 [] NSCP[idx].receive { repeat; }
110 [] T.timeout {
111 setverdict(pass);
112 }
113 }
114}
115
Alexander Couzens1220a242020-09-07 05:21:50 +0200116function f_outgoing_ns_reset(integer idx := 0, float tout := 10.0) runs on RAW_NS_CT {
117 timer T := tout;
Harald Welte90f19742020-11-06 19:34:40 +0100118 var template PDU_NS reset := ts_NS_RESET(NS_CAUSE_EQUIPMENT_FAILURE, g_nsconfig[idx].nsvc[0].nsvci, g_nsconfig[idx].nsei)
Alexander Couzens1220a242020-09-07 05:21:50 +0200119 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], reset));
120 T.start;
121 alt {
Harald Welte90f19742020-11-06 19:34:40 +0100122 [] NSCP[idx].receive(t_NS_RecvFrom(ts_NS_RESET_ACK(g_nsconfig[idx].nsvc[0].nsvci, g_nsconfig[idx].nsei))) {
Alexander Couzens1220a242020-09-07 05:21:50 +0200123 setverdict(pass);
124 }
125 [] NSCP[idx].receive { repeat; }
126 [] T.timeout {
127 setverdict(fail, "Failed to receive a RESET ACK");
128 }
129 }
130}
131
Alexander Couzens3c268da2020-09-07 04:25:05 +0200132/* perform outbound NS-BLOCK procedure */
133function f_outgoing_ns_block(NsCause cause, integer idx := 0) runs on RAW_NS_CT {
Harald Welte90f19742020-11-06 19:34:40 +0100134 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_BLOCK(cause, g_nsconfig[idx].nsvc[0].nsvci)));
Alexander Couzens3c268da2020-09-07 04:25:05 +0200135 alt {
Harald Welte90f19742020-11-06 19:34:40 +0100136 [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_BLOCK_ACK(g_nsconfig[idx].nsvc[0].nsvci)));
Alexander Couzens3c268da2020-09-07 04:25:05 +0200137 [] NSCP[idx].receive { repeat; }
138 }
139}
140
141/* receive NS-ALIVE and ACK it */
142altstep as_rx_alive_tx_ack(boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
143 [] NSCP[idx].receive(t_NS_RecvFrom(t_NS_ALIVE)) {
144 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], t_NS_ALIVE_ACK));
145 if (not oneshot) { repeat; }
146 }
147}
148
149/* Transmit BSSGP RESET for given BVCI and expect ACK */
Harald Weltee97e3af2020-10-09 14:56:54 +0200150function f_tx_bvc_reset_rx_ack(BssgpBvci bvci, template (omit) BssgpCellId tx_cell_id, template BssgpCellId rx_cell_id,
151 integer idx := 0, boolean exp_ack := true)
Alexander Couzens3c268da2020-09-07 04:25:05 +0200152runs on RAW_NS_CT {
153 var PDU_BSSGP bssgp_tx := valueof(ts_BVC_RESET(BSSGP_CAUSE_NET_SV_CAP_MOD_GT_ZERO_KBPS, bvci,
Harald Weltee97e3af2020-10-09 14:56:54 +0200154 tx_cell_id));
Alexander Couzens3c268da2020-09-07 04:25:05 +0200155 timer T := 5.0;
156 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx))));
157 T.start;
158 alt {
159 [exp_ack] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, 0,
Harald Weltee97e3af2020-10-09 14:56:54 +0200160 decmatch tr_BVC_RESET_ACK(bvci, rx_cell_id)))) {
Alexander Couzens3c268da2020-09-07 04:25:05 +0200161 setverdict(pass);
162 }
163 [exp_ack] T.timeout {
164 setverdict(fail, "No response to BVC-RESET");
165 }
166 [not exp_ack] T.timeout {
167 setverdict(pass);
168 }
169 [] NSCP[idx].receive { repeat; }
170 }
171}
172
173/* Receive a BSSGP RESET for given BVCI and ACK it */
Harald Weltee97e3af2020-10-09 14:56:54 +0200174altstep as_rx_bvc_reset_tx_ack(BssgpBvci bvci, template BssgpCellId rx_cell_id, template (omit) BssgpCellId tx_cell_id,
175 boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
Alexander Couzens3c268da2020-09-07 04:25:05 +0200176 var NS_RecvFrom ns_rf;
Alexander Couzens3c268da2020-09-07 04:25:05 +0200177 [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, 0,
Harald Weltee97e3af2020-10-09 14:56:54 +0200178 decmatch tr_BVC_RESET(?, bvci, rx_cell_id))))
Alexander Couzens3c268da2020-09-07 04:25:05 +0200179 -> value ns_rf {
180 var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.msg.pDU_NS_Unitdata.nS_SDU);
Harald Weltee97e3af2020-10-09 14:56:54 +0200181 var PDU_BSSGP bssgp_tx := valueof(ts_BVC_RESET_ACK(bvci, tx_cell_id));
Alexander Couzens3c268da2020-09-07 04:25:05 +0200182 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx))));
183 if (not oneshot) { repeat; }
184 }
185}
186
187
188/* Receive a BSSGP UNBLOCK for given BVCI and ACK it */
189altstep as_rx_bvc_unblock_tx_ack(BssgpBvci bvci, boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
190 var NS_RecvFrom ns_rf;
191 [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, 0,
192 decmatch t_BVC_UNBLOCK(bvci))))
193 -> value ns_rf {
194 var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.msg.pDU_NS_Unitdata.nS_SDU);
195 var PDU_BSSGP bssgp_tx := valueof(t_BVC_UNBLOCK_ACK(bvci));
196 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx))));
197 if (not oneshot) { repeat; }
198 }
199}
200
201/* Receive a BSSGP FLOW-CONTROL-BVC and ACK it */
202altstep as_rx_bvc_fc_tx_ack(BssgpBvci bvci, boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
203 var NS_RecvFrom ns_rf;
204 [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, bvci,
205 decmatch tr_BVC_FC_BVC)))
206 -> value ns_rf {
207 var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.msg.pDU_NS_Unitdata.nS_SDU);
208 var OCT1 tag := bssgp_rx.pDU_BSSGP_FLOW_CONTROL_BVC.tag.unstructured_Value;
209 var PDU_BSSGP bssgp_tx := valueof(t_BVC_FC_BVC_ACK(tag));
210 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_UNITDATA(t_SduCtrlB, bvci, enc_PDU_BSSGP(bssgp_tx))));
211 if (not oneshot) { repeat; }
212 }
213}
214
215/**********************************************************************************
216 * Classic Gb/IP bring-up test cases using NS-{RESET,BLOCK,UNBLOCK} and no IP-SNS *
217 **********************************************************************************/
218
219/* Receive a NS-RESET and ACK it */
220public altstep as_rx_ns_reset_ack(boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
221 var NS_RecvFrom ns_rf;
Harald Welte90f19742020-11-06 19:34:40 +0100222 [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_RESET(NS_CAUSE_OM_INTERVENTION, g_nsconfig[idx].nsvc[0].nsvci,
Alexander Couzens3c268da2020-09-07 04:25:05 +0200223 g_nsconfig[idx].nsei))) -> value ns_rf {
Harald Welte90f19742020-11-06 19:34:40 +0100224 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_RESET_ACK(g_nsconfig[idx].nsvc[0].nsvci,
Alexander Couzens3c268da2020-09-07 04:25:05 +0200225 g_nsconfig[idx].nsei)));
226 if (not oneshot) { repeat; }
227 }
228}
229/* Receive a NS-UNBLOCK and ACK it */
230public altstep as_rx_ns_unblock_ack(boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
231 var NS_RecvFrom ns_rf;
232 [] NSCP[idx].receive(t_NS_RecvFrom(t_NS_UNBLOCK)) -> value ns_rf {
233 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], t_NS_UNBLOCK_ACK));
234 if (not oneshot) { repeat; }
235 }
236}
237
238}