blob: dca352f2c89f2a354659ef9a4ba5cf2307d389c9 [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 */
Alexander Couzens2beaa202020-09-11 20:08:41 +020052 g_nsconfig[idx].nsvci := ns_config.nsvci + idx;
Harald Welte5e8573e2020-09-13 15:32:56 +020053 g_nsconfig[idx].provider.ip.local_udp_port := ns_config.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];
59 log("connecting NSCP[", idx, "] to ", nscfg);
60 res := f_IPL4_connect(NSCP[idx], nscfg.provider.ip.remote_ip, nscfg.provider.ip.remote_udp_port,
61 nscfg.provider.ip.local_ip, nscfg.provider.ip.local_udp_port, 0, { udp := {}});
Alexander Couzens3c268da2020-09-07 04:25:05 +020062 if (not ispresent(res.connId)) {
63 setverdict(fail, "Could not connect NS UDP socket, check your configuration ", g_nsconfig[idx]);
64 mtc.stop;
65 }
66 g_ns_conn_id[idx] := res.connId;
67
68}
69
70function f_ns_exp(template PDU_NS exp_rx, integer idx := 0) runs on RAW_NS_CT return PDU_NS {
71 var NS_RecvFrom nrf;
72 log("f_ns_exp() expecting ", exp_rx);
73 alt {
74 [] NSCP[idx].receive(t_NS_RecvFrom(exp_rx)) -> value nrf { }
Alexander Couzensf57ff032020-09-11 14:27:57 +020075 [] NSCP[idx].receive(t_NS_RecvFrom(?)) -> value nrf {
Alexander Couzens3c268da2020-09-07 04:25:05 +020076 setverdict(fail, "Received unexpected NS: ", nrf);
77 mtc.stop;
78 }
79 }
80 return nrf.msg;
81}
82
83/* perform outbound NS-ALIVE procedure */
84function f_outgoing_ns_alive(integer idx := 0) runs on RAW_NS_CT {
85 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], t_NS_ALIVE));
86 alt {
87 [] NSCP[idx].receive(t_NS_RecvFrom(t_NS_ALIVE_ACK));
88 [] NSCP[idx].receive { repeat; }
89 }
90}
91
92/* perform outbound NS-ALIVE procedure */
93function f_outgoing_ns_alive_no_ack(integer idx := 0, float tout := 10.0) runs on RAW_NS_CT {
94 timer T := tout;
95 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], t_NS_ALIVE));
96 T.start;
97 alt {
98 [] NSCP[idx].receive(t_NS_RecvFrom(t_NS_ALIVE_ACK)) {
99 setverdict(fail, "Received unexpected NS-ALIVE ACK");
100 }
101 [] NSCP[idx].receive { repeat; }
102 [] T.timeout {
103 setverdict(pass);
104 }
105 }
106}
107
Alexander Couzens1220a242020-09-07 05:21:50 +0200108function f_outgoing_ns_reset(integer idx := 0, float tout := 10.0) runs on RAW_NS_CT {
109 timer T := tout;
110 var template PDU_NS reset := ts_NS_RESET(NS_CAUSE_EQUIPMENT_FAILURE, g_nsconfig[idx].nsvci, g_nsconfig[idx].nsei)
111 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], reset));
112 T.start;
113 alt {
114 [] NSCP[idx].receive(t_NS_RecvFrom(ts_NS_RESET_ACK(g_nsconfig[idx].nsvci, g_nsconfig[idx].nsei))) {
115 setverdict(pass);
116 }
117 [] NSCP[idx].receive { repeat; }
118 [] T.timeout {
119 setverdict(fail, "Failed to receive a RESET ACK");
120 }
121 }
122}
123
Alexander Couzens3c268da2020-09-07 04:25:05 +0200124/* perform outbound NS-BLOCK procedure */
125function f_outgoing_ns_block(NsCause cause, integer idx := 0) runs on RAW_NS_CT {
126 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_BLOCK(cause, g_nsconfig[idx].nsvci)));
127 alt {
128 [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_BLOCK_ACK(g_nsconfig[idx].nsvci)));
129 [] NSCP[idx].receive { repeat; }
130 }
131}
132
133/* receive NS-ALIVE and ACK it */
134altstep as_rx_alive_tx_ack(boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
135 [] NSCP[idx].receive(t_NS_RecvFrom(t_NS_ALIVE)) {
136 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], t_NS_ALIVE_ACK));
137 if (not oneshot) { repeat; }
138 }
139}
140
141/* Transmit BSSGP RESET for given BVCI and expect ACK */
Alexander Couzensad709912020-09-11 20:21:29 +0200142function f_tx_bvc_reset_rx_ack(BssgpBvci bvci, BssgpCellId cell_id, integer idx := 0, boolean exp_ack := true)
Alexander Couzens3c268da2020-09-07 04:25:05 +0200143runs on RAW_NS_CT {
144 var PDU_BSSGP bssgp_tx := valueof(ts_BVC_RESET(BSSGP_CAUSE_NET_SV_CAP_MOD_GT_ZERO_KBPS, bvci,
Alexander Couzensad709912020-09-11 20:21:29 +0200145 cell_id));
Alexander Couzens3c268da2020-09-07 04:25:05 +0200146 timer T := 5.0;
147 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx))));
148 T.start;
149 alt {
150 [exp_ack] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, 0,
151 decmatch tr_BVC_RESET_ACK(bvci, ?)))) {
152 setverdict(pass);
153 }
154 [exp_ack] T.timeout {
155 setverdict(fail, "No response to BVC-RESET");
156 }
157 [not exp_ack] T.timeout {
158 setverdict(pass);
159 }
160 [] NSCP[idx].receive { repeat; }
161 }
162}
163
164/* Receive a BSSGP RESET for given BVCI and ACK it */
Alexander Couzensad709912020-09-11 20:21:29 +0200165altstep as_rx_bvc_reset_tx_ack(BssgpBvci bvci, BssgpCellId cell_id, boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
Alexander Couzens3c268da2020-09-07 04:25:05 +0200166 var NS_RecvFrom ns_rf;
167 /* FIXME: nail down received cell_id in match */
168 [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, 0,
169 decmatch tr_BVC_RESET(?, bvci, ?))))
170 -> value ns_rf {
171 var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.msg.pDU_NS_Unitdata.nS_SDU);
Alexander Couzensad709912020-09-11 20:21:29 +0200172 var PDU_BSSGP bssgp_tx := valueof(ts_BVC_RESET_ACK(bvci, cell_id));
Alexander Couzens3c268da2020-09-07 04:25:05 +0200173 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx))));
174 if (not oneshot) { repeat; }
175 }
176}
177
178
179/* Receive a BSSGP UNBLOCK for given BVCI and ACK it */
180altstep as_rx_bvc_unblock_tx_ack(BssgpBvci bvci, boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
181 var NS_RecvFrom ns_rf;
182 [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, 0,
183 decmatch t_BVC_UNBLOCK(bvci))))
184 -> value ns_rf {
185 var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.msg.pDU_NS_Unitdata.nS_SDU);
186 var PDU_BSSGP bssgp_tx := valueof(t_BVC_UNBLOCK_ACK(bvci));
187 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx))));
188 if (not oneshot) { repeat; }
189 }
190}
191
192/* Receive a BSSGP FLOW-CONTROL-BVC and ACK it */
193altstep as_rx_bvc_fc_tx_ack(BssgpBvci bvci, boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
194 var NS_RecvFrom ns_rf;
195 [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, bvci,
196 decmatch tr_BVC_FC_BVC)))
197 -> value ns_rf {
198 var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.msg.pDU_NS_Unitdata.nS_SDU);
199 var OCT1 tag := bssgp_rx.pDU_BSSGP_FLOW_CONTROL_BVC.tag.unstructured_Value;
200 var PDU_BSSGP bssgp_tx := valueof(t_BVC_FC_BVC_ACK(tag));
201 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_UNITDATA(t_SduCtrlB, bvci, enc_PDU_BSSGP(bssgp_tx))));
202 if (not oneshot) { repeat; }
203 }
204}
205
206/**********************************************************************************
207 * Classic Gb/IP bring-up test cases using NS-{RESET,BLOCK,UNBLOCK} and no IP-SNS *
208 **********************************************************************************/
209
210/* Receive a NS-RESET and ACK it */
211public altstep as_rx_ns_reset_ack(boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
212 var NS_RecvFrom ns_rf;
213 [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_RESET(NS_CAUSE_OM_INTERVENTION, g_nsconfig[idx].nsvci,
214 g_nsconfig[idx].nsei))) -> value ns_rf {
215 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_RESET_ACK(g_nsconfig[idx].nsvci,
216 g_nsconfig[idx].nsei)));
217 if (not oneshot) { repeat; }
218 }
219}
220/* Receive a NS-UNBLOCK and ACK it */
221public altstep as_rx_ns_unblock_ack(boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
222 var NS_RecvFrom ns_rf;
223 [] NSCP[idx].receive(t_NS_RecvFrom(t_NS_UNBLOCK)) -> value ns_rf {
224 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], t_NS_UNBLOCK_ACK));
225 if (not oneshot) { repeat; }
226 }
227}
228
229}