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