Alexander Couzens | 3c268da | 2020-09-07 04:25:05 +0200 | [diff] [blame] | 1 | module 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 | |
| 13 | import from General_Types all; |
| 14 | import from Osmocom_Types all; |
Alexander Couzens | 3c268da | 2020-09-07 04:25:05 +0200 | [diff] [blame] | 15 | import from Osmocom_Gb_Types all; |
| 16 | import from NS_CodecPort all; |
| 17 | import from NS_Types all; |
| 18 | import from BSSGP_Types all; |
| 19 | import from NS_CodecPort all; |
| 20 | import from NS_CodecPort_CtrlFunct all; |
| 21 | import from NS_Emulation all; |
| 22 | import from Native_Functions all; |
| 23 | import from IPL4asp_Types all; |
| 24 | |
| 25 | public 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 | |
| 33 | public 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 Couzens | 2beaa20 | 2020-09-11 20:08:41 +0200 | [diff] [blame] | 40 | function 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 Couzens | 3c268da | 2020-09-07 04:25:05 +0200 | [diff] [blame] | 41 | 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 Couzens | 2beaa20 | 2020-09-11 20:08:41 +0200 | [diff] [blame] | 50 | g_nsconfig[idx] := ns_config; |
Alexander Couzens | 3c268da | 2020-09-07 04:25:05 +0200 | [diff] [blame] | 51 | /* adjust those parts different for each NS-VC */ |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 52 | 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 Couzens | 3c268da | 2020-09-07 04:25:05 +0200 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | map(self:NSCP[idx], system:NSCP); |
| 57 | /* Connect the UDP socket */ |
Harald Welte | 5e8573e | 2020-09-13 15:32:56 +0200 | [diff] [blame] | 58 | var NSConfiguration nscfg := g_nsconfig[idx]; |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 59 | var NSVCConfiguration nsvc_cfg := nscfg.nsvc[0]; |
Harald Welte | 5e8573e | 2020-09-13 15:32:56 +0200 | [diff] [blame] | 60 | log("connecting NSCP[", idx, "] to ", nscfg); |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 61 | 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 Couzens | 3c268da | 2020-09-07 04:25:05 +0200 | [diff] [blame] | 63 | 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 | |
| 71 | function 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 Couzens | f57ff03 | 2020-09-11 14:27:57 +0200 | [diff] [blame] | 76 | [] NSCP[idx].receive(t_NS_RecvFrom(?)) -> value nrf { |
Alexander Couzens | 3c268da | 2020-09-07 04:25:05 +0200 | [diff] [blame] | 77 | setverdict(fail, "Received unexpected NS: ", nrf); |
| 78 | mtc.stop; |
| 79 | } |
| 80 | } |
| 81 | return nrf.msg; |
| 82 | } |
| 83 | |
| 84 | /* perform outbound NS-ALIVE procedure */ |
| 85 | function 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 */ |
| 94 | function 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 Couzens | 1220a24 | 2020-09-07 05:21:50 +0200 | [diff] [blame] | 109 | function f_outgoing_ns_reset(integer idx := 0, float tout := 10.0) runs on RAW_NS_CT { |
| 110 | timer T := tout; |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 111 | var template PDU_NS reset := ts_NS_RESET(NS_CAUSE_EQUIPMENT_FAILURE, g_nsconfig[idx].nsvc[0].nsvci, g_nsconfig[idx].nsei) |
Alexander Couzens | 1220a24 | 2020-09-07 05:21:50 +0200 | [diff] [blame] | 112 | NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], reset)); |
| 113 | T.start; |
| 114 | alt { |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 115 | [] NSCP[idx].receive(t_NS_RecvFrom(ts_NS_RESET_ACK(g_nsconfig[idx].nsvc[0].nsvci, g_nsconfig[idx].nsei))) { |
Alexander Couzens | 1220a24 | 2020-09-07 05:21:50 +0200 | [diff] [blame] | 116 | 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 Couzens | 3c268da | 2020-09-07 04:25:05 +0200 | [diff] [blame] | 125 | /* perform outbound NS-BLOCK procedure */ |
| 126 | function f_outgoing_ns_block(NsCause cause, integer idx := 0) runs on RAW_NS_CT { |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 127 | NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_BLOCK(cause, g_nsconfig[idx].nsvc[0].nsvci))); |
Alexander Couzens | 3c268da | 2020-09-07 04:25:05 +0200 | [diff] [blame] | 128 | alt { |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 129 | [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_BLOCK_ACK(g_nsconfig[idx].nsvc[0].nsvci))); |
Alexander Couzens | 3c268da | 2020-09-07 04:25:05 +0200 | [diff] [blame] | 130 | [] NSCP[idx].receive { repeat; } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /* receive NS-ALIVE and ACK it */ |
| 135 | altstep 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 Welte | e97e3af | 2020-10-09 14:56:54 +0200 | [diff] [blame] | 143 | function 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 Couzens | 3c268da | 2020-09-07 04:25:05 +0200 | [diff] [blame] | 145 | runs 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 Welte | e97e3af | 2020-10-09 14:56:54 +0200 | [diff] [blame] | 147 | tx_cell_id)); |
Alexander Couzens | 3c268da | 2020-09-07 04:25:05 +0200 | [diff] [blame] | 148 | 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 Welte | e97e3af | 2020-10-09 14:56:54 +0200 | [diff] [blame] | 153 | decmatch tr_BVC_RESET_ACK(bvci, rx_cell_id)))) { |
Alexander Couzens | 3c268da | 2020-09-07 04:25:05 +0200 | [diff] [blame] | 154 | 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 Welte | e97e3af | 2020-10-09 14:56:54 +0200 | [diff] [blame] | 167 | altstep 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 Couzens | 3c268da | 2020-09-07 04:25:05 +0200 | [diff] [blame] | 169 | var NS_RecvFrom ns_rf; |
Alexander Couzens | 3c268da | 2020-09-07 04:25:05 +0200 | [diff] [blame] | 170 | [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, 0, |
Harald Welte | e97e3af | 2020-10-09 14:56:54 +0200 | [diff] [blame] | 171 | decmatch tr_BVC_RESET(?, bvci, rx_cell_id)))) |
Alexander Couzens | 3c268da | 2020-09-07 04:25:05 +0200 | [diff] [blame] | 172 | -> value ns_rf { |
| 173 | var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.msg.pDU_NS_Unitdata.nS_SDU); |
Harald Welte | e97e3af | 2020-10-09 14:56:54 +0200 | [diff] [blame] | 174 | var PDU_BSSGP bssgp_tx := valueof(ts_BVC_RESET_ACK(bvci, tx_cell_id)); |
Alexander Couzens | 3c268da | 2020-09-07 04:25:05 +0200 | [diff] [blame] | 175 | 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 */ |
| 182 | altstep 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 */ |
| 195 | altstep 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 */ |
| 213 | public altstep as_rx_ns_reset_ack(boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT { |
| 214 | var NS_RecvFrom ns_rf; |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 215 | [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_RESET(NS_CAUSE_OM_INTERVENTION, g_nsconfig[idx].nsvc[0].nsvci, |
Alexander Couzens | 3c268da | 2020-09-07 04:25:05 +0200 | [diff] [blame] | 216 | g_nsconfig[idx].nsei))) -> value ns_rf { |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 217 | NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_RESET_ACK(g_nsconfig[idx].nsvc[0].nsvci, |
Alexander Couzens | 3c268da | 2020-09-07 04:25:05 +0200 | [diff] [blame] | 218 | g_nsconfig[idx].nsei))); |
| 219 | if (not oneshot) { repeat; } |
| 220 | } |
| 221 | } |
| 222 | /* Receive a NS-UNBLOCK and ACK it */ |
| 223 | public 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 | } |