Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [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 Misc_Helpers all; |
| 14 | import from General_Types all; |
| 15 | import from Osmocom_Types all; |
| 16 | import from Osmocom_Gb_Types all; |
| 17 | import from NS_Emulation all; |
| 18 | import from NS_Types all; |
| 19 | import from BSSGP_Types all; |
| 20 | import from NS_Emulation all; |
| 21 | import from Native_Functions all; |
| 22 | import from IPL4asp_Types all; |
| 23 | import from NS_Provider_IPL4 all; |
| 24 | #ifdef NS_EMULATION_FR |
| 25 | import from NS_Provider_FR all; |
| 26 | #endif |
| 27 | |
| 28 | public type component RAW_NS_CT { |
| 29 | /* UDP port towards the bottom (IUT) */ |
| 30 | port NS_PROVIDER_PT NSCP[4]; |
| 31 | var NS_Provider_IPL4_CT vc_NSP_IP[4]; |
| 32 | #ifdef NS_EMULATION_FR |
| 33 | var NS_Provider_FR_CT vc_NSP_FR[4]; |
| 34 | #endif |
| 35 | var NSConfiguration g_nsconfig; |
| 36 | timer g_T_guard; |
| 37 | } |
| 38 | |
| 39 | public altstep as_Tguard() runs on RAW_NS_CT { |
| 40 | [] g_T_guard.timeout { |
| 41 | setverdict(fail, "Timeout of T_guard"); |
| 42 | mtc.stop; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | function f_init_ns_codec(NSConfiguration ns_config, integer idx := 0, float guard_secs := 60.0, charstring id := testcasename()) runs on RAW_NS_CT { |
| 47 | var Result res; |
| 48 | |
| 49 | if (not g_T_guard.running) { |
| 50 | g_T_guard.start(guard_secs); |
| 51 | activate(as_Tguard()); |
| 52 | } |
| 53 | |
| 54 | if (not isbound(g_nsconfig)) { |
| 55 | g_nsconfig := ns_config; |
| 56 | } |
| 57 | |
| 58 | if (ischosen(ns_config.nsvc[idx].provider.ip)) { |
| 59 | /* Connect the UDP socket */ |
| 60 | vc_NSP_IP[idx] := NS_Provider_IPL4_CT.create(id & "-provIP"); |
| 61 | connect(self:NSCP[idx], vc_NSP_IP[idx]:NSE); |
| 62 | vc_NSP_IP[idx].start(NS_Provider_IPL4.main(ns_config.nsvc[idx], ns_config, id)); |
| 63 | #ifdef NS_EMULATION_FR |
| 64 | } else if (ischosen(ns_config.nsvc[idx].provider.fr)) { |
| 65 | vc_NSP_FR[idx] := NS_Provider_FR_CT.create(id & "-provFR"); |
| 66 | connect(self:NSCP[idx], vc_NSP_FR[idx]:NSE); |
| 67 | vc_NSP_FR[idx].start(NS_Provider_FR.main(ns_config.nsvc[idx], ns_config, id)); |
| 68 | #endif |
| 69 | } else { |
| 70 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported NS provider"); |
| 71 | } |
| 72 | |
| 73 | NSCP[idx].receive(NS_Provider_Evt:{link_status:=NS_PROV_LINK_STATUS_UP}); |
| 74 | } |
| 75 | |
| 76 | function f_clean_ns_codec() runs on RAW_NS_CT { |
| 77 | for (var integer i := 0; i < lengthof(vc_NSP_IP); i := i + 1) { |
| 78 | vc_NSP_IP[i].stop; |
| 79 | } |
| 80 | #ifdef NS_EMULATION_FR |
| 81 | for (var integer i := 0; i < lengthof(vc_NSP_FR); i := i + 1) { |
| 82 | vc_NSP_FR[i].stop; |
| 83 | } |
| 84 | #endif NS_EMULATION_FR |
| 85 | } |
| 86 | |
| 87 | public altstep ax_rx_fail_on_any_ns(integer idx := 0) runs on RAW_NS_CT { |
| 88 | var PDU_NS nrf; |
| 89 | [] NSCP[idx].receive(PDU_NS: ?) -> value nrf { |
| 90 | setverdict(fail, "Received unexpected NS: ", nrf); |
| 91 | mtc.stop; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | function f_ns_exp(template PDU_NS exp_rx, integer idx := 0) runs on RAW_NS_CT return PDU_NS { |
| 96 | var PDU_NS nrf; |
| 97 | log("f_ns_exp() expecting ", exp_rx); |
| 98 | /* last activated altstep has the lowest priority */ |
| 99 | var default d := activate(ax_rx_fail_on_any_ns()); |
| 100 | alt { |
| 101 | [] NSCP[idx].receive(PDU_NS: exp_rx) -> value nrf { } |
| 102 | } |
| 103 | deactivate(d); |
| 104 | return nrf; |
| 105 | } |
| 106 | |
| 107 | /* perform outbound NS-ALIVE procedure */ |
| 108 | function f_outgoing_ns_alive(integer idx := 0) runs on RAW_NS_CT { |
| 109 | NSCP[idx].send(t_NS_ALIVE); |
| 110 | alt { |
| 111 | [] NSCP[idx].receive(t_NS_ALIVE_ACK); |
| 112 | [] NSCP[idx].receive { repeat; } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | /* perform outbound NS-ALIVE procedure */ |
| 117 | function f_outgoing_ns_alive_no_ack(integer idx := 0, float tout := 10.0) runs on RAW_NS_CT { |
| 118 | timer T := tout; |
| 119 | NSCP[idx].send(t_NS_ALIVE); |
| 120 | T.start; |
| 121 | alt { |
| 122 | [] NSCP[idx].receive(t_NS_ALIVE_ACK) { |
| 123 | setverdict(fail, "Received unexpected NS-ALIVE ACK"); |
| 124 | } |
| 125 | [] NSCP[idx].receive { repeat; } |
| 126 | [] T.timeout { |
| 127 | setverdict(pass); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | function f_outgoing_ns_reset(integer idx := 0, float tout := 10.0) runs on RAW_NS_CT { |
| 133 | timer T := tout; |
| 134 | var template PDU_NS reset := ts_NS_RESET(NS_CAUSE_EQUIPMENT_FAILURE, g_nsconfig.nsvc[idx].nsvci, g_nsconfig.nsei) |
| 135 | NSCP[idx].send(reset); |
| 136 | T.start; |
| 137 | alt { |
| 138 | [] NSCP[idx].receive(ts_NS_RESET_ACK(g_nsconfig.nsvc[idx].nsvci, g_nsconfig.nsei)) { |
| 139 | setverdict(pass); |
| 140 | } |
| 141 | [] NSCP[idx].receive { repeat; } |
| 142 | [] T.timeout { |
| 143 | setverdict(fail, "Failed to receive a RESET ACK"); |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | /* perform outbound NS-BLOCK procedure */ |
| 149 | function f_outgoing_ns_block(NsCause cause, integer idx := 0) runs on RAW_NS_CT { |
| 150 | NSCP[idx].send(ts_NS_BLOCK(cause, g_nsconfig.nsvc[idx].nsvci)); |
| 151 | alt { |
| 152 | [] NSCP[idx].receive(tr_NS_BLOCK_ACK(g_nsconfig.nsvc[idx].nsvci)); |
| 153 | [] NSCP[idx].receive { repeat; } |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | /* perform outbound NS-UNBLOCK procedure */ |
| 158 | function f_outgoing_ns_unblock(integer idx := 0) runs on RAW_NS_CT { |
| 159 | NSCP[idx].send(t_NS_UNBLOCK); |
| 160 | alt { |
| 161 | [] NSCP[idx].receive(t_NS_UNBLOCK_ACK); |
| 162 | [] NSCP[idx].receive { repeat; } |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | /* receive NS-ALIVE and ACK it */ |
| 167 | altstep as_rx_alive_tx_ack(boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT { |
| 168 | [] NSCP[idx].receive(t_NS_ALIVE) { |
| 169 | NSCP[idx].send(t_NS_ALIVE_ACK); |
| 170 | if (not oneshot) { repeat; } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | /* Transmit BSSGP RESET for given BVCI and expect ACK */ |
| 175 | function f_tx_bvc_reset_rx_ack(BssgpBvci bvci, template (omit) BssgpCellId tx_cell_id, template BssgpCellId rx_cell_id, |
| 176 | integer idx := 0, boolean exp_ack := true) |
| 177 | runs on RAW_NS_CT { |
| 178 | var PDU_BSSGP bssgp_tx := valueof(ts_BVC_RESET(BSSGP_CAUSE_NET_SV_CAP_MOD_GT_ZERO_KBPS, bvci, |
| 179 | tx_cell_id)); |
| 180 | timer T := 5.0; |
| 181 | NSCP[idx].send(ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx))); |
| 182 | T.start; |
| 183 | alt { |
| 184 | [exp_ack] NSCP[idx].receive(tr_NS_UNITDATA(t_SduCtrlB, 0, |
| 185 | decmatch tr_BVC_RESET_ACK(bvci, rx_cell_id))) { |
| 186 | setverdict(pass); |
| 187 | } |
| 188 | [exp_ack] T.timeout { |
| 189 | setverdict(fail, "No response to BVC-RESET"); |
| 190 | } |
| 191 | [not exp_ack] T.timeout { |
| 192 | setverdict(pass); |
| 193 | } |
| 194 | [] NSCP[idx].receive { repeat; } |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | /* Receive a BSSGP RESET for given BVCI and ACK it */ |
| 199 | altstep as_rx_bvc_reset_tx_ack(BssgpBvci bvci, template BssgpCellId rx_cell_id, template (omit) BssgpCellId tx_cell_id, |
| 200 | boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT { |
| 201 | var PDU_NS ns_rf; |
| 202 | [] NSCP[idx].receive(tr_NS_UNITDATA(t_SduCtrlB, 0, |
| 203 | decmatch tr_BVC_RESET(?, bvci, rx_cell_id))) |
| 204 | -> value ns_rf { |
| 205 | var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.pDU_NS_Unitdata.nS_SDU); |
| 206 | var PDU_BSSGP bssgp_tx := valueof(ts_BVC_RESET_ACK(bvci, tx_cell_id)); |
| 207 | NSCP[idx].send(ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx))); |
| 208 | if (not oneshot) { repeat; } |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | |
| 213 | /* Receive a BSSGP UNBLOCK for given BVCI and ACK it */ |
| 214 | altstep as_rx_bvc_unblock_tx_ack(BssgpBvci bvci, boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT { |
| 215 | var PDU_NS ns_rf; |
Pau Espin Pedrol | 6ee0126 | 2021-02-05 13:05:06 +0100 | [diff] [blame] | 216 | [] NSCP[idx].receive(tr_NS_UNITDATA(t_SduCtrlB, 0, decmatch tr_BVC_UNBLOCK(bvci))) -> value ns_rf { |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 217 | var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.pDU_NS_Unitdata.nS_SDU); |
Pau Espin Pedrol | 6ee0126 | 2021-02-05 13:05:06 +0100 | [diff] [blame] | 218 | var PDU_BSSGP bssgp_tx := valueof(ts_BVC_UNBLOCK_ACK(bvci)); |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 219 | NSCP[idx].send(ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx))); |
| 220 | if (not oneshot) { repeat; } |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | /* Receive a BSSGP FLOW-CONTROL-BVC and ACK it */ |
| 225 | altstep as_rx_bvc_fc_tx_ack(BssgpBvci bvci, boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT { |
| 226 | var PDU_NS ns_rf; |
| 227 | [] NSCP[idx].receive(tr_NS_UNITDATA(t_SduCtrlB, bvci, |
| 228 | decmatch tr_BVC_FC_BVC)) |
| 229 | -> value ns_rf { |
| 230 | var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.pDU_NS_Unitdata.nS_SDU); |
| 231 | var OCT1 tag := bssgp_rx.pDU_BSSGP_FLOW_CONTROL_BVC.tag.unstructured_Value; |
Pau Espin Pedrol | 6ee0126 | 2021-02-05 13:05:06 +0100 | [diff] [blame] | 232 | var PDU_BSSGP bssgp_tx := valueof(ts_BVC_FC_BVC_ACK(tag)); |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 233 | NSCP[idx].send(ts_NS_UNITDATA(t_SduCtrlB, bvci, enc_PDU_BSSGP(bssgp_tx))); |
| 234 | if (not oneshot) { repeat; } |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | /********************************************************************************** |
| 239 | * Classic Gb/IP bring-up test cases using NS-{RESET,BLOCK,UNBLOCK} and no IP-SNS * |
| 240 | **********************************************************************************/ |
| 241 | |
| 242 | /* Receive a NS-RESET and ACK it */ |
| 243 | public altstep as_rx_ns_reset_ack(boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT { |
| 244 | var PDU_NS ns_rf; |
| 245 | [] NSCP[idx].receive(tr_NS_RESET(NS_CAUSE_OM_INTERVENTION, g_nsconfig.nsvc[idx].nsvci, |
| 246 | g_nsconfig.nsei)) -> value ns_rf { |
| 247 | NSCP[idx].send(ts_NS_RESET_ACK(g_nsconfig.nsvc[idx].nsvci, g_nsconfig.nsei)); |
| 248 | if (not oneshot) { repeat; } |
| 249 | } |
| 250 | } |
| 251 | /* Receive a NS-UNBLOCK and ACK it */ |
| 252 | public altstep as_rx_ns_unblock_ack(boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT { |
| 253 | var PDU_NS ns_rf; |
| 254 | [] NSCP[idx].receive(t_NS_UNBLOCK) -> value ns_rf { |
| 255 | NSCP[idx].send(t_NS_UNBLOCK_ACK); |
| 256 | if (not oneshot) { repeat; } |
| 257 | } |
| 258 | } |
| 259 | |
Alexander Couzens | 20cd41e | 2021-01-11 02:56:03 +0100 | [diff] [blame] | 260 | /* Receive a NS-BLOCK and ACK it */ |
| 261 | public altstep as_rx_ns_block_ack(boolean oneshot := false, integer idx := 0, template NsCause cause := *, template Nsvci nsvci := *) runs on RAW_NS_CT { |
| 262 | var PDU_NS ns_rf; |
| 263 | [] NSCP[idx].receive(tr_NS_BLOCK(cause, nsvci)) -> value ns_rf { |
| 264 | NSCP[idx].send(ts_NS_BLOCK_ACK(oct2int(ns_rf.pDU_NS_Block.nS_VCI.nS_VCI))); |
| 265 | if (not oneshot) { repeat; } |
| 266 | } |
| 267 | } |
| 268 | |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 269 | } |