Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 1 | module STP_Tests_M3UA { |
| 2 | |
| 3 | /* Osmocom STP test suite in in TTCN-3 |
| 4 | * (C) 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 | friend module STP_Tests; |
| 14 | |
| 15 | import from General_Types all; |
| 16 | import from Osmocom_Types all; |
| 17 | import from IPL4asp_Types all; |
| 18 | |
| 19 | import from Osmocom_VTY_Functions all; |
| 20 | |
| 21 | import from M3UA_Types all; |
| 22 | import from M3UA_Templates all; |
| 23 | import from M3UA_CodecPort all; |
| 24 | import from M3UA_CodecPort_CtrlFunct all; |
| 25 | |
| 26 | import from M3UA_Emulation all; |
| 27 | import from MTP3asp_Types all; |
| 28 | import from MTP3asp_PortType all; |
| 29 | |
| 30 | import from SCCP_Types all; |
| 31 | import from SCCP_Templates all; |
| 32 | import from SCCPasp_Types all; |
| 33 | import from SCCP_Emulation all; |
| 34 | |
| 35 | import from STP_Tests_Common all; |
| 36 | |
| 37 | modulepar { |
| 38 | integer mp_stp_m3ua_port := 2905; |
Harald Welte | 829dac4 | 2019-11-05 16:55:30 +0100 | [diff] [blame] | 39 | integer mp_stp_m3ua_clnt_port := 2906; |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 40 | integer mp_local_m3ua_port := 9999; |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 41 | integer mp_recovery_timeout_msec := 2000; |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 42 | } |
| 43 | |
Harald Welte | 829dac4 | 2019-11-05 16:55:30 +0100 | [diff] [blame] | 44 | private const integer NR_M3UA := 3; /* number of M3UA clients in ATS */ |
| 45 | private const integer NR_M3UA_SRV := 1; /* number of M3UA servres in ATS */ |
| 46 | |
| 47 | private function M3UA_SRV(integer idx) return integer { |
| 48 | return NR_M3UA+idx; |
| 49 | } |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 50 | |
| 51 | type component RAW_M3UA_CT extends Test_CT { |
Harald Welte | 829dac4 | 2019-11-05 16:55:30 +0100 | [diff] [blame] | 52 | port M3UA_CODEC_PT M3UA[NR_M3UA+NR_M3UA_SRV]; |
| 53 | var integer g_m3ua_conn_id[NR_M3UA+NR_M3UA_SRV]; |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | private template PortEvent tr_SctpAssocChange := { |
| 57 | sctpEvent := { |
| 58 | sctpAssocChange := ? |
| 59 | } |
| 60 | } |
| 61 | private template PortEvent tr_SctpPeerAddrChange := { |
| 62 | sctpEvent := { |
| 63 | sctpPeerAddrChange := ? |
| 64 | } |
| 65 | } |
Harald Welte | 829dac4 | 2019-11-05 16:55:30 +0100 | [diff] [blame] | 66 | private template PortEvent tr_SctpConnOpened := { |
| 67 | connOpened := ? |
| 68 | } |
| 69 | |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 70 | |
| 71 | private altstep as_m3ua_sctp() runs on RAW_M3UA_CT { |
| 72 | [] any from M3UA.receive(tr_SctpAssocChange) { repeat; } |
| 73 | [] any from M3UA.receive(tr_SctpPeerAddrChange) { repeat; } |
| 74 | } |
| 75 | |
| 76 | friend function f_M3UA_send(integer idx, template (present) PDU_M3UA msg, template integer stream := 0) |
| 77 | runs on RAW_M3UA_CT { |
| 78 | M3UA[idx].send(t_M3UA_Send(g_m3ua_conn_id[idx], msg, stream)); |
| 79 | } |
| 80 | |
| 81 | friend function f_M3UA_exp(integer idx, template (present) PDU_M3UA msg) runs on RAW_M3UA_CT { |
| 82 | var M3UA_RecvFrom rx; |
| 83 | alt { |
| 84 | [] M3UA[idx].receive(t_M3UA_RecvFrom(msg)) { |
| 85 | setverdict(pass); |
| 86 | } |
| 87 | [] M3UA[idx].receive(t_M3UA_RecvFrom(?)) -> value rx { |
| 88 | setverdict(fail, "Received unexpected M3UA[", idx, "] ", rx, |
| 89 | "while waiting for ", msg); |
| 90 | mtc.stop; |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | friend function f_M3UA_connect(integer i) runs on RAW_M3UA_CT { |
| 96 | var Result res; |
| 97 | res := M3UA_CodecPort_CtrlFunct.f_IPL4_connect(M3UA[i], mp_stp_ip, mp_stp_m3ua_port, |
| 98 | mp_local_ip, mp_local_m3ua_port+i, -1, |
| 99 | {sctp:=valueof(ts_SCTP)}); |
| 100 | if (not ispresent(res.connId)) { |
| 101 | setverdict(fail, "Could not connect M3UA socket, check your configuration"); |
| 102 | mtc.stop; |
| 103 | } |
| 104 | g_m3ua_conn_id[i] := res.connId; |
| 105 | } |
| 106 | |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 107 | friend function f_M3UA_close(integer i) runs on RAW_M3UA_CT { |
| 108 | var Result res; |
| 109 | res := M3UA_CodecPort_CtrlFunct.f_IPL4_close(M3UA[i], g_m3ua_conn_id[i], {sctp:=valueof(ts_SCTP)}); |
| 110 | g_m3ua_conn_id[i] := 0; |
| 111 | } |
| 112 | |
Harald Welte | 829dac4 | 2019-11-05 16:55:30 +0100 | [diff] [blame] | 113 | friend function f_M3UA_listen(integer i) runs on RAW_M3UA_CT { |
| 114 | var Result res; |
| 115 | res := M3UA_CodecPort_CtrlFunct.f_IPL4_listen(M3UA[i], mp_local_ip, mp_local_m3ua_port+i, |
| 116 | {sctp:=valueof(ts_SCTP)}); |
| 117 | if (not ispresent(res.connId)) { |
| 118 | setverdict(fail, "Could not bind M3UA socket, check your configuration"); |
| 119 | mtc.stop; |
| 120 | } |
| 121 | } |
| 122 | |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 123 | friend function f_init_m3ua() runs on RAW_M3UA_CT { |
| 124 | var integer i; |
| 125 | |
| 126 | f_init_common(); |
| 127 | |
| 128 | activate(as_m3ua_sctp()); |
| 129 | |
| 130 | for (i := 0; i < NR_M3UA; i:=i+1) { |
| 131 | map(self:M3UA[i], system:M3UA_CODEC_PT); |
| 132 | f_M3UA_connect(i); |
| 133 | } |
| 134 | } |
| 135 | |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 136 | friend function f_clear_m3ua() runs on RAW_M3UA_CT { |
| 137 | var integer i; |
| 138 | |
| 139 | log("Clearing M3UA..."); |
| 140 | |
| 141 | for (i := 0; i < NR_M3UA; i:=i+1) { |
| 142 | f_M3UA_close(i); |
| 143 | } |
| 144 | /* Wait for recovery timer to trigger and shutdown all AS: */ |
| 145 | f_sleep(int2float(mp_recovery_timeout_msec)/1000.0 + 0.5); |
| 146 | setverdict(pass, "M3UA cleared"); |
| 147 | } |
| 148 | |
Harald Welte | 829dac4 | 2019-11-05 16:55:30 +0100 | [diff] [blame] | 149 | friend function f_init_m3ua_srv() runs on RAW_M3UA_CT { |
| 150 | var integer i; |
| 151 | var PortEvent sctp_evt; |
| 152 | |
| 153 | for (i := NR_M3UA; i < NR_M3UA+NR_M3UA_SRV; i:=i+1) { |
| 154 | map(self:M3UA[i], system:M3UA_CODEC_PT); |
| 155 | /* bind+ listen */ |
| 156 | f_M3UA_listen(i); |
| 157 | /* wait for accept() */ |
| 158 | M3UA[i].receive(tr_SctpConnOpened) -> value sctp_evt { |
| 159 | g_m3ua_conn_id[i] := sctp_evt.connOpened.connId; |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | |
| 165 | /*********************************************************************** |
| 166 | * Test the STP in M3UA SG role (we are ASP) |
| 167 | ***********************************************************************/ |
| 168 | |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 169 | /* perform an outbound ASP-UP procedure */ |
| 170 | friend function f_M3UA_asp_up(integer idx, template (omit) OCT4 aspid := omit) runs on RAW_M3UA_CT { |
| 171 | f_M3UA_send(idx, ts_M3UA_ASPUP(aspid)); |
| 172 | f_M3UA_exp(idx, tr_M3UA_ASPUP_ACK); |
| 173 | } |
| 174 | |
| 175 | /* perform an outbound BEAT procedure */ |
| 176 | friend function f_M3UA_beat(integer idx, template (omit) octetstring hbd) runs on RAW_M3UA_CT { |
| 177 | if (istemplatekind(hbd, "omit")) { |
| 178 | f_M3UA_send(idx, ts_M3UA_BEAT(omit)); |
| 179 | f_M3UA_exp(idx, tr_M3UA_BEAT_ACK(omit)); |
| 180 | } else { |
| 181 | f_M3UA_send(idx, ts_M3UA_BEAT(ts_M3UA_hb_data(hbd))); |
| 182 | f_M3UA_exp(idx, tr_M3UA_BEAT_ACK(tr_M3UA_hb_data(hbd))); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | /* perform an outbound ASP-ACTIVATE procedure */ |
| 187 | friend function f_M3UA_asp_act(integer idx, template (omit) M3UA_Traffic_Mode_Type tmt := omit, |
| 188 | template (omit) OCT4 rctx := omit) runs on RAW_M3UA_CT { |
| 189 | f_M3UA_send(idx, ts_M3UA_ASPAC(tmt, rctx)); |
| 190 | f_M3UA_exp(idx, tr_M3UA_ASPAC_ACK(tmt, rctx)); |
| 191 | } |
| 192 | |
| 193 | /* perform outbound ASP-UP and ASP-ACT, optionally expect interemittent NOTIFY */ |
| 194 | friend function f_M3UA_asp_up_act(integer idx, template (omit) M3UA_Traffic_Mode_Type tmt := omit, |
| 195 | template (omit) OCT4 rctx := omit, |
| 196 | template (omit) OCT2 ntfy_after_up := c_M3UA_ST_I_AS_INACTIVE, |
| 197 | template (omit) OCT2 ntfy_after_act := c_M3UA_ST_I_AS_ACTIVE) |
| 198 | runs on RAW_M3UA_CT { |
| 199 | f_M3UA_asp_up(idx, omit); |
| 200 | if (not istemplatekind(ntfy_after_up, "omit")) { |
| 201 | f_M3UA_exp(idx, tr_M3UA_NOTIFY(c_M3UA_ST_T_STATE_CHG, ntfy_after_up, *)); |
| 202 | } |
| 203 | f_M3UA_asp_act(idx, tmt, rctx); |
| 204 | if (not istemplatekind(ntfy_after_act, "omit")) { |
| 205 | f_M3UA_exp(idx, tr_M3UA_NOTIFY(c_M3UA_ST_T_STATE_CHG, ntfy_after_act, *)); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | |
| 210 | /* Test the ASP-UP procedure */ |
| 211 | testcase TC_connect_asp_up() runs on RAW_M3UA_CT { |
| 212 | f_init_m3ua(); |
| 213 | f_M3UA_asp_up(0); |
| 214 | f_M3UA_exp(0, tr_M3UA_NOTIFY(c_M3UA_ST_T_STATE_CHG, c_M3UA_ST_I_AS_INACTIVE, *)); |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 215 | f_clear_m3ua(); |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | /* Test the heartbeat procedure without optional heartbeat data payload */ |
| 219 | testcase TC_beat() runs on RAW_M3UA_CT { |
| 220 | f_init_m3ua(); |
| 221 | f_M3UA_asp_up(0); |
| 222 | f_M3UA_exp(0, tr_M3UA_NOTIFY(c_M3UA_ST_T_STATE_CHG, c_M3UA_ST_I_AS_INACTIVE, *)); |
| 223 | f_M3UA_beat(0, omit); |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 224 | f_clear_m3ua(); |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | /* Test the heartbeat procedure with optional heartbeat data payload */ |
| 228 | testcase TC_beat_payload() runs on RAW_M3UA_CT { |
| 229 | f_init_m3ua(); |
| 230 | f_M3UA_asp_up(0); |
| 231 | f_M3UA_exp(0, tr_M3UA_NOTIFY(c_M3UA_ST_T_STATE_CHG, c_M3UA_ST_I_AS_INACTIVE, *)); |
| 232 | f_M3UA_beat(0, 'a1a2a3a4a5'O); |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 233 | f_clear_m3ua(); |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | /* Test the ASP-ACTIVATE procedure (without traffic-mode or routing ctx) */ |
| 237 | testcase TC_asp_act() runs on RAW_M3UA_CT { |
| 238 | f_init_m3ua(); |
| 239 | f_M3UA_asp_up_act(0); |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 240 | f_clear_m3ua(); |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | /* Test the ASP-ACTIVATE procedure with traffic-mode override */ |
| 244 | testcase TC_asp_act_override() runs on RAW_M3UA_CT { |
| 245 | f_init_m3ua(); |
| 246 | f_M3UA_asp_up_act(0, c_M3UA_TMT_override, omit); |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 247 | f_clear_m3ua(); |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | /* Test the ASP-ACTIVATE procedure with traffic-mode override */ |
| 251 | testcase TC_asp_act_loadshare() runs on RAW_M3UA_CT { |
| 252 | f_init_m3ua(); |
| 253 | f_M3UA_asp_up_act(0, c_M3UA_TMT_loadshare, omit); |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 254 | f_clear_m3ua(); |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | /* Test the ASP-ACTIVATE procedure with traffic-mode broadcast */ |
| 258 | testcase TC_asp_act_broadcast() runs on RAW_M3UA_CT { |
| 259 | f_init_m3ua(); |
| 260 | f_M3UA_asp_up_act(0, c_M3UA_TMT_broadcast, omit); |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 261 | f_clear_m3ua(); |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 262 | } |
| 263 | |
Harald Welte | 15a8501 | 2020-06-13 16:35:45 +0200 | [diff] [blame] | 264 | /* test whether the STP accepts M3UA DATA without Routing Context IE */ |
| 265 | testcase TC_act_rctx_data_no_rctx() runs on RAW_M3UA_CT { |
| 266 | var OCT4 rctx_sender := int2oct(1023, 4); |
| 267 | var OCT4 pc_sender := int2oct(23, 4); |
| 268 | var OCT4 rctx_receiver := int2oct(1042, 4); |
| 269 | var OCT4 pc_receiver := int2oct(42, 4); |
| 270 | |
| 271 | f_init_m3ua(); |
| 272 | /* bring up the sender specifying a routing context */ |
| 273 | |
| 274 | f_M3UA_asp_up_act(0, rctx := rctx_sender); |
| 275 | f_M3UA_asp_up_act(1); |
| 276 | |
| 277 | /* check if DATA is accepted without Routing Context IE */ |
| 278 | f_test_traffic(0, omit, pc_sender, 1, rctx_receiver, pc_receiver); |
| 279 | |
| 280 | f_clear_m3ua(); |
| 281 | } |
| 282 | |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 283 | /* Test if traffic is routed from idx_tx/pc_tx to idx_rx/pc_rx */ |
| 284 | private function f_test_traffic(integer idx_tx, template (omit) OCT4 rctx_sender, OCT4 pc_tx, |
| 285 | integer idx_rx, template (omit) OCT4 rctx_receiver, OCT4 pc_rx, |
| 286 | OCT1 si := '23'O, OCT1 ni := '00'O, OCT1 mp := '00'O, OCT1 sls := '00'O) |
| 287 | runs on RAW_M3UA_CT { |
| 288 | var octetstring data := f_rnd_octstring(f_rnd_int(100)); |
| 289 | f_M3UA_send(idx_tx, ts_M3UA_DATA(rctx_sender, |
| 290 | ts_M3UA_protocol_data(pc_tx, pc_rx, si, ni, mp, sls, data)), 1); |
| 291 | f_M3UA_exp(idx_rx, tr_M3UA_DATA(rctx_receiver, |
| 292 | tr_M3UA_protocol_data(pc_tx, pc_rx, si, ni, mp, sls, data))); |
| 293 | } |
| 294 | |
| 295 | |
| 296 | /* test "traffic-mode override" behavior */ |
| 297 | testcase TC_tmt_override() runs on RAW_M3UA_CT { |
| 298 | var OCT4 rctx_sender := int2oct(1023, 4); |
| 299 | var OCT4 pc_sender := int2oct(23, 4); |
| 300 | var OCT4 rctx_receiver := int2oct(1042, 4); |
| 301 | var OCT4 pc_receiver := int2oct(42, 4); |
| 302 | |
| 303 | f_init_m3ua(); |
| 304 | |
| 305 | /* bring up the 'sender' side (single ASP in AS) */ |
| 306 | f_M3UA_asp_up_act(0, omit, omit); |
| 307 | |
| 308 | /* activate the first 'receiver' side ASP */ |
| 309 | f_M3UA_asp_up_act(1, c_M3UA_TMT_override, rctx_receiver); |
| 310 | |
| 311 | /* verify traffic is routed from sender to [sole] receiver */ |
| 312 | f_test_traffic(0, rctx_sender, pc_sender, 1, rctx_receiver, pc_receiver); |
| 313 | |
| 314 | /* activate the second 'receiver' side ASP (no NOTIFY as AS state doesn't change) */ |
| 315 | f_M3UA_asp_up_act(2, c_M3UA_TMT_override, rctx_receiver, omit, omit); |
| 316 | |
| 317 | /* we expect a NOTIFY to the *other* ASP Other/Alternat-ASP-Active */ |
| 318 | f_M3UA_exp(1, tr_M3UA_NOTIFY(c_M3UA_ST_T_OTHER, c_M3UA_ST_I_ALTERNATE_ASP, *)); |
| 319 | |
| 320 | /* verify traffic is routed from sender to new receiver */ |
| 321 | f_test_traffic(0, rctx_sender, pc_sender, 2, rctx_receiver, pc_receiver); |
| 322 | |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 323 | f_clear_m3ua(); |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | private altstep as_count_rx(integer idx, template (present) PDU_M3UA exp, inout integer counter) |
| 327 | runs on RAW_M3UA_CT { |
| 328 | [] M3UA[idx].receive(t_M3UA_RecvFrom(exp)) { |
| 329 | counter := counter + 1; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | /* test "traffic-mode load-share" behavior */ |
| 334 | testcase TC_tmt_loadshare() runs on RAW_M3UA_CT { |
| 335 | var OCT4 rctx_sender := int2oct(1023, 4); |
| 336 | var OCT4 pc_sender := int2oct(23, 4); |
| 337 | var OCT4 rctx_receiver := int2oct(1042, 4); |
| 338 | var OCT4 pc_receiver := int2oct(42, 4); |
| 339 | var integer i; |
| 340 | |
| 341 | f_init_m3ua(); |
| 342 | |
| 343 | /* FIXME: configure the STP via VTY to set traffic-mode */ |
| 344 | |
| 345 | /* bring up the 'sender' side (single ASP in AS) */ |
| 346 | f_M3UA_asp_up_act(0, omit, rctx_sender); |
| 347 | |
| 348 | /* activate the first 'receiver' side ASP */ |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 349 | f_M3UA_asp_up_act(1, c_M3UA_TMT_loadshare, omit); // TODO: rctx |
| 350 | |
| 351 | /* verify traffic is routed from sender to [sole] receiver */ |
| 352 | for (i := 0; i < 10; i := i+1) { |
| 353 | f_test_traffic(0, rctx_sender, pc_sender, 1, rctx_receiver, pc_receiver); |
| 354 | } |
| 355 | |
| 356 | /* activate the second 'receiver' side ASP (no NOTIFY) */ |
| 357 | f_M3UA_asp_up_act(2, c_M3UA_TMT_loadshare, omit, omit, omit); // TODO: rctx |
| 358 | |
| 359 | /* verify traffic is routed from sender to new receiver */ |
| 360 | const integer iter_per_asp := 5; |
| 361 | var integer num_rx[NR_M3UA] := { 0, 0, 0 }; |
| 362 | for (i := 0; i < 2*iter_per_asp; i := i+1) { |
| 363 | var octetstring data := f_rnd_octstring(f_rnd_int(100)); |
| 364 | var template (value) M3UA_Protocol_Data tx_pd; |
| 365 | var template (present) M3UA_Protocol_Data rx_pd; |
| 366 | tx_pd := ts_M3UA_protocol_data(pc_sender, pc_receiver, '23'O, '00'O, '00'O, '00'O, data); |
| 367 | rx_pd := tr_M3UA_protocol_data(pc_sender, pc_receiver, '23'O, '00'O, '00'O, '00'O, data); |
| 368 | f_M3UA_send(0, ts_M3UA_DATA(rctx_sender, tx_pd), 1); |
| 369 | alt { |
| 370 | [] as_count_rx(1, tr_M3UA_DATA(rctx_receiver, rx_pd), num_rx[1]) |
| 371 | [] as_count_rx(2, tr_M3UA_DATA(rctx_receiver, rx_pd), num_rx[2]) |
| 372 | } |
| 373 | } |
| 374 | /* FIXME: check for extraneous messages? */ |
| 375 | for (i := 1; i <= 2; i := i+1) { |
| 376 | if (num_rx[i] != iter_per_asp) { |
Harald Welte | b9f7bbb | 2019-10-29 09:07:11 +0100 | [diff] [blame] | 377 | setverdict(fail, "Received ", num_rx[i], " out of expected ", iter_per_asp, |
| 378 | "M3UA DATA messages at M3UA port ", i); |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | setverdict(pass); |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 382 | |
| 383 | f_clear_m3ua(); |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | /* test "traffic-mode broadcast" behavior */ |
| 387 | testcase TC_tmt_broadcast() runs on RAW_M3UA_CT { |
| 388 | var OCT4 rctx_sender := int2oct(1023, 4); |
| 389 | var OCT4 pc_sender := int2oct(23, 4); |
| 390 | var OCT4 rctx_receiver := int2oct(1042, 4); |
| 391 | var OCT4 pc_receiver := int2oct(42, 4); |
| 392 | var integer i; |
| 393 | |
| 394 | f_init_m3ua(); |
| 395 | |
| 396 | /* FIXME: configure the STP via VTY to set traffic-mode */ |
| 397 | |
| 398 | /* bring up the 'sender' side (single ASP in AS) */ |
| 399 | f_M3UA_asp_up_act(0, omit, omit); // TODO: rctx |
| 400 | |
| 401 | /* activate the first 'receiver' side ASP */ |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 402 | f_M3UA_asp_up_act(1, c_M3UA_TMT_broadcast, omit); // TODO: rctx |
| 403 | |
| 404 | /* verify traffic is routed from sender to [sole] receiver */ |
| 405 | for (i := 0; i < 10; i := i+1) { |
| 406 | f_test_traffic(0, rctx_sender, pc_sender, 1, rctx_receiver, pc_receiver); |
| 407 | } |
| 408 | |
| 409 | /* activate the second 'receiver' side ASP */ |
| 410 | f_M3UA_asp_up_act(2, c_M3UA_TMT_broadcast, omit, omit, omit); // TODO: rctx |
| 411 | |
| 412 | /* verify traffic is routed from sender to new receiver */ |
| 413 | for (i := 0; i < 10; i := i+1) { |
| 414 | var octetstring data := f_rnd_octstring(f_rnd_int(100)); |
| 415 | var template (value) M3UA_Protocol_Data tx_pd; |
| 416 | var template (present) M3UA_Protocol_Data rx_pd; |
| 417 | tx_pd := ts_M3UA_protocol_data(pc_sender, pc_receiver, '23'O, '00'O, '00'O, '00'O, data); |
| 418 | rx_pd := tr_M3UA_protocol_data(pc_sender, pc_receiver, '23'O, '00'O, '00'O, '00'O, data); |
| 419 | f_M3UA_send(0, ts_M3UA_DATA(rctx_sender, tx_pd), 1); |
| 420 | /* each message must be received both on 1 and 2 */ |
| 421 | f_M3UA_exp(1, tr_M3UA_DATA(rctx_receiver, rx_pd)); |
| 422 | f_M3UA_exp(2, tr_M3UA_DATA(rctx_receiver, rx_pd)); |
| 423 | } |
| 424 | setverdict(pass); |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 425 | |
| 426 | f_clear_m3ua(); |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | private function f_M3UA_rkm_register(OCT4 id, OCT3 dpc, OCT4 rctx, |
| 430 | template (present) OCT4 exp_status := c_M3UA_REGSTS_SUCCESS) |
| 431 | runs on RAW_M3UA_CT |
| 432 | { |
| 433 | f_M3UA_send(0, ts_M3UA_REG_REQ({ts_M3UA_rkey(id:=id, dpc:=dpc, rctx:=rctx)})); |
| 434 | f_M3UA_exp(0, tr_M3UA_REG_RSP({tr_M3UA_reg_res(id:=id, status:=exp_status, rctx:=rctx)})); |
| 435 | } |
| 436 | |
| 437 | /* Send RKM registration; expect -EPERM as RCTX doesn't match config and dynamic not permitted */ |
| 438 | testcase TC_rkm_reg_static_notpermitted() runs on RAW_M3UA_CT { |
| 439 | f_init_m3ua(); |
| 440 | |
| 441 | f_M3UA_send(0, ts_M3UA_REG_REQ({ts_M3UA_rkey(id:='00000099'O, dpc:='aabbcc'O)})); |
| 442 | f_M3UA_exp(0, tr_M3UA_REG_RSP({tr_M3UA_reg_res(id:='00000099'O, status:=c_M3UA_REGSTS_ERR_EPERM, |
| 443 | rctx:=?)})); |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 444 | |
| 445 | f_clear_m3ua(); |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | /* Send RKM registration; expect OK as RCTX does match config */ |
| 449 | testcase TC_rkm_reg_static_permitted() runs on RAW_M3UA_CT { |
| 450 | var OCT3 dpc := int2oct(23, 3); // must match config |
| 451 | var OCT4 rctx := int2oct(1023, 4); // must match config |
| 452 | |
| 453 | f_init_m3ua(); |
| 454 | |
| 455 | f_M3UA_send(0, ts_M3UA_REG_REQ({ts_M3UA_rkey(id:='10000099'O, dpc:=dpc, rctx:=rctx)})); |
| 456 | f_M3UA_exp(0, tr_M3UA_REG_RSP({tr_M3UA_reg_res(id:='10000099'O, status:=c_M3UA_REGSTS_SUCCESS, |
| 457 | rctx:=rctx)})); |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 458 | |
| 459 | f_clear_m3ua(); |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | /* Send RKM registration; expect OK as dynamic not permitted */ |
| 463 | testcase TC_rkm_reg_dynamic_permitted() runs on RAW_M3UA_CT { |
| 464 | f_init_common(); |
| 465 | f_vty_config2(VTY, {"cs7 instance 0"}, "xua rkm routing-key-allocation dynamic-permitted"); |
| 466 | f_init_m3ua(); |
| 467 | |
| 468 | f_M3UA_send(0, ts_M3UA_REG_REQ({ts_M3UA_rkey(id:='20000099'O, dpc:='aabbcc'O)})); |
| 469 | f_M3UA_exp(0, tr_M3UA_REG_RSP({tr_M3UA_reg_res(id:='20000099'O, status:=c_M3UA_REGSTS_SUCCESS, |
| 470 | rctx:=?)})); |
| 471 | |
| 472 | f_vty_config2(VTY, {"cs7 instance 0"}, "xua rkm routing-key-allocation static-only"); |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 473 | |
| 474 | f_clear_m3ua(); |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | /* try to de-register a routing key that was never registered -> error */ |
| 478 | testcase TC_rkm_unreg_never_registered() runs on RAW_M3UA_CT { |
| 479 | f_init_m3ua(); |
| 480 | f_M3UA_send(0, ts_M3UA_DEREG_REQ(ts_M3UA_routing_ctx(int2oct(1023,4)))); |
| 481 | f_M3UA_exp(0, tr_M3UA_DEREG_RSP({tr_M3UA_dereg_res(?,c_m3UA_DEREGSTS_ERR_NOT_REG)})); |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 482 | f_clear_m3ua(); |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | /* try to de-register a routing key that is invalid (non-existant) -> error */ |
| 486 | testcase TC_rkm_unreg_invalid() runs on RAW_M3UA_CT { |
| 487 | f_init_m3ua(); |
| 488 | f_M3UA_send(0, ts_M3UA_DEREG_REQ(ts_M3UA_routing_ctx(int2oct(1234,4)))); |
| 489 | f_M3UA_exp(0, tr_M3UA_DEREG_RSP({tr_M3UA_dereg_res(?,c_m3UA_DEREGSTS_ERR_INVAL_RCTX)})); |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 490 | f_clear_m3ua(); |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | /* try to de-register a routing key that was registered -> OK*/ |
| 494 | testcase TC_rkm_unreg_registered() runs on RAW_M3UA_CT { |
| 495 | f_init_m3ua(); |
| 496 | f_M3UA_send(0, ts_M3UA_DEREG_REQ(ts_M3UA_routing_ctx(int2oct(1023,4)))); |
| 497 | f_M3UA_exp(0, tr_M3UA_DEREG_RSP({tr_M3UA_dereg_res(?,c_m3UA_DEREGSTS_SUCCESS)})); |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 498 | f_clear_m3ua(); |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | /* try to de-register a routing key for an active ASP -> ERROR */ |
| 502 | testcase TC_rkm_unreg_active() runs on RAW_M3UA_CT { |
| 503 | var OCT3 dpc := int2oct(23, 3); // must match config |
| 504 | var OCT4 rctx := int2oct(1023, 4); // must match config |
| 505 | |
| 506 | f_init_m3ua(); |
| 507 | |
| 508 | /* first register the routing key */ |
| 509 | f_M3UA_rkm_register(id:='30000099'O, dpc:=dpc, rctx:=rctx); |
| 510 | |
| 511 | /* then activate the ASP */ |
| 512 | f_M3UA_asp_up_act(0); |
| 513 | |
| 514 | /* then try to de-regsiter */ |
| 515 | f_M3UA_send(0, ts_M3UA_DEREG_REQ(ts_M3UA_routing_ctx(rctx))); |
| 516 | f_M3UA_exp(0, tr_M3UA_DEREG_RSP({tr_M3UA_dereg_res(?,c_m3UA_DEREGSTS_ERR_ASP_ACTIVE)})); |
| 517 | /* FIXME: we now may have changed the state on the STP side! */ |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 518 | |
| 519 | f_clear_m3ua(); |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 520 | } |
| 521 | |
Harald Welte | 829dac4 | 2019-11-05 16:55:30 +0100 | [diff] [blame] | 522 | /*********************************************************************** |
| 523 | * Test the STP in M3UA ASP role (we are SG) |
| 524 | ***********************************************************************/ |
| 525 | |
| 526 | /* expect/perform an inbound ASP-UP procedure */ |
| 527 | friend function f_M3UA_CLNT_asp_up(integer idx, template OCT4 aspid := omit) runs on RAW_M3UA_CT { |
| 528 | f_M3UA_exp(idx, tr_M3UA_ASPUP(aspid)); |
| 529 | f_M3UA_send(idx, ts_M3UA_ASPUP_ACK); |
| 530 | } |
| 531 | |
| 532 | /* expect/perform an inbound ASP-ACTIVATE procedure */ |
| 533 | friend function f_M3UA_CLNT_asp_act(integer idx, template M3UA_Traffic_Mode_Type tmt := omit, |
| 534 | template (omit) OCT4 rctx := omit) runs on RAW_M3UA_CT { |
| 535 | f_M3UA_exp(idx, tr_M3UA_ASPAC(tmt, rctx)); |
| 536 | f_M3UA_send(idx, ts_M3UA_ASPAC_ACK(tmt, rctx)); |
| 537 | } |
| 538 | |
| 539 | /* expect/perform inbound ASP-UP and ASP-ACT, optionally send interemittent NOTIFY */ |
| 540 | friend function f_M3UA_CLNT_asp_up_act(integer idx, template M3UA_Traffic_Mode_Type tmt := omit, |
| 541 | template OCT4 rctx := omit, |
| 542 | template (omit) OCT2 ntfy_after_up := c_M3UA_ST_I_AS_INACTIVE, |
| 543 | template (omit) OCT2 ntfy_after_act := c_M3UA_ST_I_AS_ACTIVE) |
| 544 | runs on RAW_M3UA_CT { |
| 545 | f_M3UA_CLNT_asp_up(idx, omit); |
| 546 | if (not istemplatekind(ntfy_after_up, "omit")) { |
| 547 | f_M3UA_send(idx, ts_M3UA_NOTIFY(c_M3UA_ST_T_STATE_CHG, ntfy_after_up, rctx)); |
| 548 | } |
| 549 | f_M3UA_CLNT_asp_act(idx, tmt, rctx); |
| 550 | if (not istemplatekind(ntfy_after_act, "omit")) { |
| 551 | f_M3UA_send(idx, ts_M3UA_NOTIFY(c_M3UA_ST_T_STATE_CHG, ntfy_after_act, rctx)); |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | |
| 556 | /* Expect inbound connection from ASP/SCTP-client, followed by ASP-UP */ |
| 557 | testcase TC_clnt_connect_asp_up() runs on RAW_M3UA_CT { |
| 558 | f_init_m3ua(); |
| 559 | f_init_m3ua_srv(); |
| 560 | |
| 561 | f_M3UA_CLNT_asp_up(M3UA_SRV(0)); |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 562 | |
| 563 | f_clear_m3ua(); |
Harald Welte | 829dac4 | 2019-11-05 16:55:30 +0100 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | /* Expect inbound connection from ASP/SCTP-client, followed by ASP-UP + ASP-ACT */ |
| 567 | testcase TC_clnt_asp_act() runs on RAW_M3UA_CT { |
| 568 | f_init_m3ua(); |
| 569 | f_init_m3ua_srv(); |
| 570 | |
Harald Welte | dfbca11 | 2019-12-01 18:00:48 +0100 | [diff] [blame] | 571 | f_M3UA_CLNT_asp_up_act(M3UA_SRV(0), rctx := int2oct(1055, 4)); |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 572 | |
| 573 | f_clear_m3ua(); |
Harald Welte | 829dac4 | 2019-11-05 16:55:30 +0100 | [diff] [blame] | 574 | } |
| 575 | |
Harald Welte | 53050cd | 2019-12-01 20:49:01 +0100 | [diff] [blame] | 576 | /* Expect inbound connection from ASP/SCTP-client, followed by ASP-UP + ASP-ACT */ |
| 577 | testcase TC_clnt_asp_act_tmt_loadshare() runs on RAW_M3UA_CT { |
| 578 | f_init_common(); |
| 579 | f_vty_config2(VTY, {"cs7 instance 0", "as as-client m3ua"}, "traffic-mode loadshare"); |
| 580 | f_init_m3ua(); |
| 581 | f_init_m3ua_srv(); |
| 582 | |
| 583 | f_M3UA_CLNT_asp_up_act(M3UA_SRV(0), tmt := c_M3UA_TMT_loadshare, rctx := int2oct(1055, 4)); |
| 584 | |
| 585 | f_clear_m3ua(); |
| 586 | } |
| 587 | |
Harald Welte | 829dac4 | 2019-11-05 16:55:30 +0100 | [diff] [blame] | 588 | /* Test traffic being routed through "server" side STP (M3UA SG), coming back in "client" |
| 589 | * side STP (M3UA ASP) */ |
| 590 | testcase TC_clnt_sg_to_asp() runs on RAW_M3UA_CT { |
| 591 | var OCT4 rctx_sender := int2oct(1023, 4); |
| 592 | var OCT4 pc_sender := int2oct(23, 4); |
| 593 | var OCT4 rctx_receiver := int2oct(1055, 4); |
| 594 | var OCT4 pc_receiver := int2oct(55, 4); |
| 595 | |
| 596 | f_init_m3ua(); |
| 597 | f_M3UA_asp_up_act(0); |
| 598 | |
| 599 | f_init_m3ua_srv(); |
Harald Welte | dfbca11 | 2019-12-01 18:00:48 +0100 | [diff] [blame] | 600 | f_M3UA_CLNT_asp_up_act(M3UA_SRV(0), rctx := int2oct(1055, 4)); |
Harald Welte | 829dac4 | 2019-11-05 16:55:30 +0100 | [diff] [blame] | 601 | |
| 602 | f_sleep(1.0); |
| 603 | |
| 604 | /* verify traffic is routed from sender to [sole] receiver */ |
| 605 | f_test_traffic(0, rctx_sender, pc_sender, M3UA_SRV(0), rctx_receiver, pc_receiver); |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 606 | |
| 607 | f_clear_m3ua(); |
Harald Welte | 829dac4 | 2019-11-05 16:55:30 +0100 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | /* Test traffic being routed through "client" side STP (M3UA ASP), coming back in "server" |
| 611 | * side STP (M3UA SG) */ |
| 612 | testcase TC_clnt_asp_to_sg() runs on RAW_M3UA_CT { |
| 613 | var OCT4 rctx_sender := int2oct(1055, 4); |
| 614 | var OCT4 pc_sender := int2oct(55, 4); |
| 615 | var OCT4 rctx_receiver := int2oct(1023, 4); |
| 616 | var OCT4 pc_receiver := int2oct(23, 4); |
| 617 | |
| 618 | f_init_m3ua(); |
| 619 | f_M3UA_asp_up_act(0); |
| 620 | |
| 621 | f_init_m3ua_srv(); |
Harald Welte | dfbca11 | 2019-12-01 18:00:48 +0100 | [diff] [blame] | 622 | f_M3UA_CLNT_asp_up_act(M3UA_SRV(0), rctx := int2oct(1055, 4)); |
Harald Welte | 829dac4 | 2019-11-05 16:55:30 +0100 | [diff] [blame] | 623 | |
| 624 | f_sleep(1.0); |
| 625 | |
| 626 | /* verify traffic is routed from sender to [sole] receiver */ |
| 627 | f_test_traffic(M3UA_SRV(0), rctx_sender, pc_sender, 0, rctx_receiver, pc_receiver); |
Pau Espin Pedrol | 05726dd | 2019-11-06 15:55:57 +0100 | [diff] [blame] | 628 | f_clear_m3ua(); |
Harald Welte | 829dac4 | 2019-11-05 16:55:30 +0100 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 632 | |
| 633 | control { |
| 634 | /* M3UA Tests */ |
| 635 | execute( TC_connect_asp_up() ); |
| 636 | execute( TC_beat() ); |
| 637 | execute( TC_beat_payload() ); |
| 638 | execute( TC_asp_act() ); |
| 639 | execute( TC_asp_act_override() ); |
| 640 | execute( TC_asp_act_loadshare() ); |
| 641 | execute( TC_asp_act_broadcast() ); |
| 642 | execute( TC_tmt_override() ); |
| 643 | execute( TC_tmt_loadshare() ); |
| 644 | execute( TC_tmt_broadcast() ); |
Harald Welte | 15a8501 | 2020-06-13 16:35:45 +0200 | [diff] [blame] | 645 | execute( TC_act_rctx_data_no_rctx() ); |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 646 | |
| 647 | /* M3UA RKM tests */ |
| 648 | execute( TC_rkm_reg_static_notpermitted() ); |
| 649 | execute( TC_rkm_reg_static_permitted() ); |
| 650 | execute( TC_rkm_reg_dynamic_permitted() ); |
| 651 | execute( TC_rkm_unreg_never_registered() ); |
| 652 | execute( TC_rkm_unreg_invalid() ); |
| 653 | execute( TC_rkm_unreg_registered() ); |
| 654 | execute( TC_rkm_unreg_active() ); |
| 655 | /* TODO: test RKM with unsupported routing keys: NA, SI, OPC */ |
| 656 | /* TODO: register/unregister multiple routing contexts in one message; including mixed |
| 657 | success/failure situations */ |
Harald Welte | 829dac4 | 2019-11-05 16:55:30 +0100 | [diff] [blame] | 658 | |
| 659 | /* Test STP as SCTP client + M3UA ASP role */ |
| 660 | execute( TC_clnt_connect_asp_up() ); |
| 661 | execute( TC_clnt_asp_act() ); |
| 662 | execute( TC_clnt_sg_to_asp() ); |
| 663 | execute( TC_clnt_asp_to_sg() ); |
Harald Welte | 53050cd | 2019-12-01 20:49:01 +0100 | [diff] [blame] | 664 | |
| 665 | /* put this one last as it changes the stp side config */ |
| 666 | execute( TC_clnt_asp_act_tmt_loadshare() ); |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | |
| 670 | |
| 671 | } |