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; |
| 15 | import from SGSN_Components all; |
| 16 | import from Osmocom_Gb_Types all; |
| 17 | import from NS_CodecPort all; |
| 18 | import from NS_Types all; |
| 19 | import from BSSGP_Types all; |
| 20 | import from NS_CodecPort all; |
| 21 | import from NS_CodecPort_CtrlFunct all; |
| 22 | import from NS_Emulation all; |
| 23 | import from Native_Functions all; |
| 24 | import from IPL4asp_Types all; |
| 25 | |
| 26 | public type component RAW_NS_CT { |
| 27 | /* UDP port towards the bottom (IUT) */ |
| 28 | port NS_CODEC_PT NSCP[4]; |
| 29 | var ConnectionId g_ns_conn_id[4] := {-1, -1, -1, -1}; |
| 30 | var NSConfiguration g_nsconfig[4]; |
| 31 | timer g_T_guard; |
| 32 | } |
| 33 | |
| 34 | public altstep as_Tguard() runs on RAW_NS_CT { |
| 35 | [] g_T_guard.timeout { |
| 36 | setverdict(fail, "Timeout of T_guard"); |
| 37 | mtc.stop; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | function f_init_ns_codec(integer idx := 0, float guard_secs := 60.0) runs on RAW_NS_CT { |
| 42 | var Result res; |
| 43 | |
| 44 | if (not g_T_guard.running) { |
| 45 | g_T_guard.start(guard_secs); |
| 46 | activate(as_Tguard()); |
| 47 | } |
| 48 | |
| 49 | if (not isbound(g_nsconfig) or not isbound(g_nsconfig[idx])) { |
| 50 | /* copy most parts from mp_nsconfig */ |
| 51 | g_nsconfig[idx] := mp_nsconfig; |
| 52 | /* adjust those parts different for each NS-VC */ |
| 53 | g_nsconfig[idx].nsvci := mp_nsconfig.nsvci + idx; |
| 54 | g_nsconfig[idx].local_udp_port := mp_nsconfig.local_udp_port + idx; |
| 55 | } |
| 56 | |
| 57 | map(self:NSCP[idx], system:NSCP); |
| 58 | /* Connect the UDP socket */ |
| 59 | log("connecting NSCP[", idx, "] to ", g_nsconfig[idx]); |
| 60 | res := f_IPL4_connect(NSCP[idx], g_nsconfig[idx].remote_ip, g_nsconfig[idx].remote_udp_port, |
| 61 | g_nsconfig[idx].local_ip, g_nsconfig[idx].local_udp_port, 0, { udp := {}}); |
| 62 | 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 | |
| 70 | function 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 { } |
| 75 | [] NSCP[idx].receive { |
| 76 | setverdict(fail, "Received unexpected NS: ", nrf); |
| 77 | mtc.stop; |
| 78 | } |
| 79 | } |
| 80 | return nrf.msg; |
| 81 | } |
| 82 | |
| 83 | /* perform outbound NS-ALIVE procedure */ |
| 84 | function 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 */ |
| 93 | function 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 | |
| 108 | /* perform outbound NS-BLOCK procedure */ |
| 109 | function f_outgoing_ns_block(NsCause cause, integer idx := 0) runs on RAW_NS_CT { |
| 110 | NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_BLOCK(cause, g_nsconfig[idx].nsvci))); |
| 111 | alt { |
| 112 | [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_BLOCK_ACK(g_nsconfig[idx].nsvci))); |
| 113 | [] NSCP[idx].receive { repeat; } |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | /* receive NS-ALIVE and ACK it */ |
| 118 | altstep as_rx_alive_tx_ack(boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT { |
| 119 | [] NSCP[idx].receive(t_NS_RecvFrom(t_NS_ALIVE)) { |
| 120 | NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], t_NS_ALIVE_ACK)); |
| 121 | if (not oneshot) { repeat; } |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /* Transmit BSSGP RESET for given BVCI and expect ACK */ |
| 126 | function f_tx_bvc_reset_rx_ack(BssgpBvci bvci, integer idx := 0, boolean exp_ack := true) |
| 127 | runs on RAW_NS_CT { |
| 128 | var PDU_BSSGP bssgp_tx := valueof(ts_BVC_RESET(BSSGP_CAUSE_NET_SV_CAP_MOD_GT_ZERO_KBPS, bvci, |
| 129 | mp_gb_cfg.cell_id)); |
| 130 | timer T := 5.0; |
| 131 | NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx)))); |
| 132 | T.start; |
| 133 | alt { |
| 134 | [exp_ack] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, 0, |
| 135 | decmatch tr_BVC_RESET_ACK(bvci, ?)))) { |
| 136 | setverdict(pass); |
| 137 | } |
| 138 | [exp_ack] T.timeout { |
| 139 | setverdict(fail, "No response to BVC-RESET"); |
| 140 | } |
| 141 | [not exp_ack] T.timeout { |
| 142 | setverdict(pass); |
| 143 | } |
| 144 | [] NSCP[idx].receive { repeat; } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | /* Receive a BSSGP RESET for given BVCI and ACK it */ |
| 149 | altstep as_rx_bvc_reset_tx_ack(BssgpBvci bvci, boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT { |
| 150 | var NS_RecvFrom ns_rf; |
| 151 | /* FIXME: nail down received cell_id in match */ |
| 152 | [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, 0, |
| 153 | decmatch tr_BVC_RESET(?, bvci, ?)))) |
| 154 | -> value ns_rf { |
| 155 | var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.msg.pDU_NS_Unitdata.nS_SDU); |
| 156 | var PDU_BSSGP bssgp_tx := valueof(ts_BVC_RESET_ACK(bvci, mp_gb_cfg.cell_id)); |
| 157 | NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx)))); |
| 158 | if (not oneshot) { repeat; } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | |
| 163 | /* Receive a BSSGP UNBLOCK for given BVCI and ACK it */ |
| 164 | altstep as_rx_bvc_unblock_tx_ack(BssgpBvci bvci, boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT { |
| 165 | var NS_RecvFrom ns_rf; |
| 166 | [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, 0, |
| 167 | decmatch t_BVC_UNBLOCK(bvci)))) |
| 168 | -> value ns_rf { |
| 169 | var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.msg.pDU_NS_Unitdata.nS_SDU); |
| 170 | var PDU_BSSGP bssgp_tx := valueof(t_BVC_UNBLOCK_ACK(bvci)); |
| 171 | NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx)))); |
| 172 | if (not oneshot) { repeat; } |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | /* Receive a BSSGP FLOW-CONTROL-BVC and ACK it */ |
| 177 | altstep as_rx_bvc_fc_tx_ack(BssgpBvci bvci, boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT { |
| 178 | var NS_RecvFrom ns_rf; |
| 179 | [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, bvci, |
| 180 | decmatch tr_BVC_FC_BVC))) |
| 181 | -> value ns_rf { |
| 182 | var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.msg.pDU_NS_Unitdata.nS_SDU); |
| 183 | var OCT1 tag := bssgp_rx.pDU_BSSGP_FLOW_CONTROL_BVC.tag.unstructured_Value; |
| 184 | var PDU_BSSGP bssgp_tx := valueof(t_BVC_FC_BVC_ACK(tag)); |
| 185 | NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_UNITDATA(t_SduCtrlB, bvci, enc_PDU_BSSGP(bssgp_tx)))); |
| 186 | if (not oneshot) { repeat; } |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | /********************************************************************************** |
| 191 | * Classic Gb/IP bring-up test cases using NS-{RESET,BLOCK,UNBLOCK} and no IP-SNS * |
| 192 | **********************************************************************************/ |
| 193 | |
| 194 | /* Receive a NS-RESET and ACK it */ |
| 195 | public altstep as_rx_ns_reset_ack(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_RESET(NS_CAUSE_OM_INTERVENTION, g_nsconfig[idx].nsvci, |
| 198 | g_nsconfig[idx].nsei))) -> value ns_rf { |
| 199 | NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_RESET_ACK(g_nsconfig[idx].nsvci, |
| 200 | g_nsconfig[idx].nsei))); |
| 201 | if (not oneshot) { repeat; } |
| 202 | } |
| 203 | } |
| 204 | /* Receive a NS-UNBLOCK and ACK it */ |
| 205 | public altstep as_rx_ns_unblock_ack(boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT { |
| 206 | var NS_RecvFrom ns_rf; |
| 207 | [] NSCP[idx].receive(t_NS_RecvFrom(t_NS_UNBLOCK)) -> value ns_rf { |
| 208 | NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], t_NS_UNBLOCK_ACK)); |
| 209 | if (not oneshot) { repeat; } |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | } |