blob: 8540f38d7c1518957cc93d475dbeb33324d87918 [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
71function f_ns_exp(template PDU_NS exp_rx, integer idx := 0) runs on RAW_NS_CT return PDU_NS {
72 var NS_RecvFrom nrf;
73 log("f_ns_exp() expecting ", exp_rx);
74 alt {
75 [] NSCP[idx].receive(t_NS_RecvFrom(exp_rx)) -> value nrf { }
Alexander Couzensf57ff032020-09-11 14:27:57 +020076 [] NSCP[idx].receive(t_NS_RecvFrom(?)) -> value nrf {
Alexander Couzens3c268da2020-09-07 04:25:05 +020077 setverdict(fail, "Received unexpected NS: ", nrf);
78 mtc.stop;
79 }
80 }
81 return nrf.msg;
82}
83
84/* perform outbound NS-ALIVE procedure */
85function f_outgoing_ns_alive(integer idx := 0) runs on RAW_NS_CT {
86 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], t_NS_ALIVE));
87 alt {
88 [] NSCP[idx].receive(t_NS_RecvFrom(t_NS_ALIVE_ACK));
89 [] NSCP[idx].receive { repeat; }
90 }
91}
92
93/* perform outbound NS-ALIVE procedure */
94function f_outgoing_ns_alive_no_ack(integer idx := 0, float tout := 10.0) runs on RAW_NS_CT {
95 timer T := tout;
96 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], t_NS_ALIVE));
97 T.start;
98 alt {
99 [] NSCP[idx].receive(t_NS_RecvFrom(t_NS_ALIVE_ACK)) {
100 setverdict(fail, "Received unexpected NS-ALIVE ACK");
101 }
102 [] NSCP[idx].receive { repeat; }
103 [] T.timeout {
104 setverdict(pass);
105 }
106 }
107}
108
Alexander Couzens1220a242020-09-07 05:21:50 +0200109function f_outgoing_ns_reset(integer idx := 0, float tout := 10.0) runs on RAW_NS_CT {
110 timer T := tout;
Harald Welte90f19742020-11-06 19:34:40 +0100111 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 +0200112 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], reset));
113 T.start;
114 alt {
Harald Welte90f19742020-11-06 19:34:40 +0100115 [] 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 +0200116 setverdict(pass);
117 }
118 [] NSCP[idx].receive { repeat; }
119 [] T.timeout {
120 setverdict(fail, "Failed to receive a RESET ACK");
121 }
122 }
123}
124
Alexander Couzens3c268da2020-09-07 04:25:05 +0200125/* perform outbound NS-BLOCK procedure */
126function f_outgoing_ns_block(NsCause cause, integer idx := 0) runs on RAW_NS_CT {
Harald Welte90f19742020-11-06 19:34:40 +0100127 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 +0200128 alt {
Harald Welte90f19742020-11-06 19:34:40 +0100129 [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_BLOCK_ACK(g_nsconfig[idx].nsvc[0].nsvci)));
Alexander Couzens3c268da2020-09-07 04:25:05 +0200130 [] NSCP[idx].receive { repeat; }
131 }
132}
133
134/* receive NS-ALIVE and ACK it */
135altstep as_rx_alive_tx_ack(boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
136 [] NSCP[idx].receive(t_NS_RecvFrom(t_NS_ALIVE)) {
137 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], t_NS_ALIVE_ACK));
138 if (not oneshot) { repeat; }
139 }
140}
141
142/* Transmit BSSGP RESET for given BVCI and expect ACK */
Harald Weltee97e3af2020-10-09 14:56:54 +0200143function f_tx_bvc_reset_rx_ack(BssgpBvci bvci, template (omit) BssgpCellId tx_cell_id, template BssgpCellId rx_cell_id,
144 integer idx := 0, boolean exp_ack := true)
Alexander Couzens3c268da2020-09-07 04:25:05 +0200145runs on RAW_NS_CT {
146 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 +0200147 tx_cell_id));
Alexander Couzens3c268da2020-09-07 04:25:05 +0200148 timer T := 5.0;
149 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx))));
150 T.start;
151 alt {
152 [exp_ack] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, 0,
Harald Weltee97e3af2020-10-09 14:56:54 +0200153 decmatch tr_BVC_RESET_ACK(bvci, rx_cell_id)))) {
Alexander Couzens3c268da2020-09-07 04:25:05 +0200154 setverdict(pass);
155 }
156 [exp_ack] T.timeout {
157 setverdict(fail, "No response to BVC-RESET");
158 }
159 [not exp_ack] T.timeout {
160 setverdict(pass);
161 }
162 [] NSCP[idx].receive { repeat; }
163 }
164}
165
166/* Receive a BSSGP RESET for given BVCI and ACK it */
Harald Weltee97e3af2020-10-09 14:56:54 +0200167altstep as_rx_bvc_reset_tx_ack(BssgpBvci bvci, template BssgpCellId rx_cell_id, template (omit) BssgpCellId tx_cell_id,
168 boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
Alexander Couzens3c268da2020-09-07 04:25:05 +0200169 var NS_RecvFrom ns_rf;
Alexander Couzens3c268da2020-09-07 04:25:05 +0200170 [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, 0,
Harald Weltee97e3af2020-10-09 14:56:54 +0200171 decmatch tr_BVC_RESET(?, bvci, rx_cell_id))))
Alexander Couzens3c268da2020-09-07 04:25:05 +0200172 -> value ns_rf {
173 var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.msg.pDU_NS_Unitdata.nS_SDU);
Harald Weltee97e3af2020-10-09 14:56:54 +0200174 var PDU_BSSGP bssgp_tx := valueof(ts_BVC_RESET_ACK(bvci, tx_cell_id));
Alexander Couzens3c268da2020-09-07 04:25:05 +0200175 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx))));
176 if (not oneshot) { repeat; }
177 }
178}
179
180
181/* Receive a BSSGP UNBLOCK for given BVCI and ACK it */
182altstep as_rx_bvc_unblock_tx_ack(BssgpBvci bvci, boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
183 var NS_RecvFrom ns_rf;
184 [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, 0,
185 decmatch t_BVC_UNBLOCK(bvci))))
186 -> value ns_rf {
187 var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.msg.pDU_NS_Unitdata.nS_SDU);
188 var PDU_BSSGP bssgp_tx := valueof(t_BVC_UNBLOCK_ACK(bvci));
189 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx))));
190 if (not oneshot) { repeat; }
191 }
192}
193
194/* Receive a BSSGP FLOW-CONTROL-BVC and ACK it */
195altstep as_rx_bvc_fc_tx_ack(BssgpBvci bvci, boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
196 var NS_RecvFrom ns_rf;
197 [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, bvci,
198 decmatch tr_BVC_FC_BVC)))
199 -> value ns_rf {
200 var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.msg.pDU_NS_Unitdata.nS_SDU);
201 var OCT1 tag := bssgp_rx.pDU_BSSGP_FLOW_CONTROL_BVC.tag.unstructured_Value;
202 var PDU_BSSGP bssgp_tx := valueof(t_BVC_FC_BVC_ACK(tag));
203 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_UNITDATA(t_SduCtrlB, bvci, enc_PDU_BSSGP(bssgp_tx))));
204 if (not oneshot) { repeat; }
205 }
206}
207
208/**********************************************************************************
209 * Classic Gb/IP bring-up test cases using NS-{RESET,BLOCK,UNBLOCK} and no IP-SNS *
210 **********************************************************************************/
211
212/* Receive a NS-RESET and ACK it */
213public altstep as_rx_ns_reset_ack(boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
214 var NS_RecvFrom ns_rf;
Harald Welte90f19742020-11-06 19:34:40 +0100215 [] 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 +0200216 g_nsconfig[idx].nsei))) -> value ns_rf {
Harald Welte90f19742020-11-06 19:34:40 +0100217 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 +0200218 g_nsconfig[idx].nsei)));
219 if (not oneshot) { repeat; }
220 }
221}
222/* Receive a NS-UNBLOCK and ACK it */
223public altstep as_rx_ns_unblock_ack(boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
224 var NS_RecvFrom ns_rf;
225 [] NSCP[idx].receive(t_NS_RecvFrom(t_NS_UNBLOCK)) -> value ns_rf {
226 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], t_NS_UNBLOCK_ACK));
227 if (not oneshot) { repeat; }
228 }
229}
230
231}