Harald Welte | 9fbcf4b | 2018-12-07 07:56:52 +0100 | [diff] [blame^] | 1 | module PCU_Tests_RAW { |
| 2 | |
| 3 | /* "RAW" PCU tests: Talk directly to the PCU socket of OsmoPCU on the one hand side (emulating |
| 4 | the BTS/BSC side PCU socket server) and the Gb interface on the other hand side. No NS/BSSGP |
| 5 | Emulation is used; rather, we simply use the NS_CodecPort to implement both standard and non- |
| 6 | standard procedures on the NS and BSSGP level. The goal of these tests is to test exactly |
| 7 | those NS and BSSGP implementations on the BSS (PCU) side. */ |
| 8 | |
| 9 | import from General_Types all; |
| 10 | import from Osmocom_Types all; |
| 11 | import from NS_Types all; |
| 12 | import from BSSGP_Types all; |
| 13 | import from Osmocom_Gb_Types all; |
| 14 | |
| 15 | import from BSSGP_Emulation all; /* BssgpConfig */ |
| 16 | import from NS_Emulation all; /* NSConfiguration */ |
| 17 | |
| 18 | import from UD_Types all; |
| 19 | import from PCUIF_Types all; |
| 20 | import from PCUIF_CodecPort all; |
| 21 | import from IPL4asp_Types all; |
| 22 | import from NS_CodecPort all; |
| 23 | import from NS_CodecPort_CtrlFunct all; |
| 24 | import from Native_Functions all; |
| 25 | import from PCU_Tests all; |
| 26 | |
| 27 | modulepar { |
| 28 | charstring mp_pcu_sock_path := PCU_SOCK_DEFAULT; |
| 29 | } |
| 30 | |
| 31 | type component RAW_NS_CT { |
| 32 | /* UDP port towards the bottom (IUT) */ |
| 33 | port NS_CODEC_PT NSCP; |
| 34 | var ConnectionId g_ns_conn_id := -1; |
| 35 | timer g_T_guard; |
| 36 | |
| 37 | /* PCUIF (we emulate the BTS part) */ |
| 38 | port PCUIF_CODEC_PT PCU; |
| 39 | var ConnectionId g_pcu_conn_id := -1; |
| 40 | } |
| 41 | |
| 42 | private altstep as_Tguard() runs on RAW_NS_CT { |
| 43 | [] g_T_guard.timeout { |
| 44 | setverdict(fail, "Timeout of T_guard"); |
| 45 | mtc.stop; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | function f_init_pcuif() runs on RAW_NS_CT { |
| 50 | map(self:PCU, system:PCU); |
| 51 | |
| 52 | /* Connect the Unix Domain Socket */ |
| 53 | g_pcu_conn_id := f_pcuif_listen(PCU, mp_pcu_sock_path); |
| 54 | PCU.receive(UD_connected:?); |
| 55 | |
| 56 | /* Wait for PCU_VERSION and return INFO_IND */ |
| 57 | PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TXT_IND(0, PCU_VERSION, ?))); |
| 58 | /* FIXME: make sure to use parameters from mp_gb_cfg.cell_id in the PCU INFO IND */ |
| 59 | var template PCUIF_Message info_ind := ts_PCUIF_INFO_IND(bts_nr := 0, |
| 60 | nsei := mp_nsconfig.nsei, |
| 61 | nsvci := mp_nsconfig.nsvci, |
| 62 | bvci := mp_gb_cfg.bvci, |
| 63 | local_port := mp_nsconfig.remote_udp_port, |
| 64 | remote_port := mp_nsconfig.local_udp_port, |
| 65 | remote_ip := f_inet_haddr(mp_nsconfig.local_ip) |
| 66 | ); |
| 67 | PCU.send(t_SD_PCUIF(g_pcu_conn_id, info_ind)); |
| 68 | } |
| 69 | |
| 70 | function f_init_ns_codec(float guard_secs := 60.0) runs on RAW_NS_CT { |
| 71 | var Result res; |
| 72 | map(self:NSCP, system:NSCP); |
| 73 | /* Connect the UDP socket */ |
| 74 | res := f_IPL4_connect(NSCP, mp_nsconfig.remote_ip, mp_nsconfig.remote_udp_port, |
| 75 | mp_nsconfig.local_ip, mp_nsconfig.local_udp_port, |
| 76 | 0, { udp := {}}); |
| 77 | if (not ispresent(res.connId)) { |
| 78 | setverdict(fail, "Could not connect NS UDP socket, check your configuration"); |
| 79 | mtc.stop; |
| 80 | } |
| 81 | g_ns_conn_id := res.connId; |
| 82 | g_T_guard.start(guard_secs); |
| 83 | activate(as_Tguard()); |
| 84 | } |
| 85 | |
| 86 | function f_ns_exp(template PDU_NS exp_rx) runs on RAW_NS_CT return PDU_NS { |
| 87 | var NS_RecvFrom nrf; |
| 88 | log("f_ns_exp() expecting ", exp_rx); |
| 89 | alt { |
| 90 | [] NSCP.receive(t_NS_RecvFrom(exp_rx)) -> value nrf { } |
| 91 | [] NSCP.receive { |
| 92 | setverdict(fail, "Received unexpected NS: ", nrf); |
| 93 | mtc.stop; |
| 94 | } |
| 95 | } |
| 96 | return nrf.msg; |
| 97 | } |
| 98 | |
| 99 | /* perform inbound SNS-SIZE procedure */ |
| 100 | function f_incoming_sns_size(template (omit) NsCause cause := omit) runs on RAW_NS_CT { |
| 101 | var PDU_NS rx; |
| 102 | /* expect one single SNS-SIZE with RESET flag; one remote v4 EP; no v6 EP */ |
| 103 | rx := f_ns_exp(tr_SNS_SIZE(mp_nsconfig.nsei, rst_flag := true, max_nsvcs := ?, |
| 104 | num_v4 := 1, num_v6 := omit)); |
| 105 | NSCP.send(t_NS_Send(g_ns_conn_id, ts_SNS_SIZE_ACK(mp_nsconfig.nsei, cause))); |
| 106 | } |
| 107 | |
| 108 | /* perform outbound SNS-SIZE procedure */ |
| 109 | function f_outgoing_sns_size(template (omit) NsCause cause := omit) runs on RAW_NS_CT { |
| 110 | var PDU_NS rx; |
| 111 | NSCP.send(t_NS_Send(g_ns_conn_id, ts_SNS_SIZE(mp_nsconfig.nsei, rst_flag := true, max_nsvcs := 1, |
| 112 | num_v4 := 1, num_v6 := omit) |
| 113 | )); |
| 114 | /* expect one single SNS-SIZE with RESET flag; one remote v4 EP; no v6 EP */ |
| 115 | rx := f_ns_exp(tr_SNS_SIZE_ACK(mp_nsconfig.nsei, cause)); |
| 116 | } |
| 117 | |
| 118 | /* perform inbound SNS-CONFIG procedure */ |
| 119 | function f_incoming_sns_config(template (omit) NsCause cause := omit) runs on RAW_NS_CT { |
| 120 | var PDU_NS rx; |
| 121 | rx := f_ns_exp(tr_SNS_CONFIG(mp_nsconfig.nsei, end_flag := true, v4 := ?)); |
| 122 | NSCP.send(t_NS_Send(g_ns_conn_id, ts_SNS_CONFIG_ACK(mp_nsconfig.nsei, cause))); |
| 123 | } |
| 124 | |
| 125 | /* perform outbound SNS-CONFIG procedure */ |
| 126 | function f_outgoing_sns_config(template (omit) NsCause cause := omit) runs on RAW_NS_CT { |
| 127 | var PDU_NS rx; |
| 128 | var template (omit) IP4_Elements v4 := { ts_SNS_IPv4(mp_nsconfig.local_ip, |
| 129 | mp_nsconfig.local_udp_port) } |
| 130 | NSCP.send(t_NS_Send(g_ns_conn_id, ts_SNS_CONFIG(mp_nsconfig.nsei, true, v4))); |
| 131 | rx := f_ns_exp(tr_SNS_CONFIG_ACK(mp_nsconfig.nsei, cause)); |
| 132 | } |
| 133 | |
| 134 | /* perform outbound NS-ALIVE procedure */ |
| 135 | function f_outgoing_ns_alive() runs on RAW_NS_CT { |
| 136 | NSCP.send(t_NS_Send(g_ns_conn_id, t_NS_ALIVE)); |
| 137 | alt { |
| 138 | [] NSCP.receive(t_NS_RecvFrom(t_NS_ALIVE_ACK)); |
| 139 | [] NSCP.receive { repeat; } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | /* perform outbound NS-BLOCK procedure */ |
| 144 | function f_outgoing_ns_block(NsCause cause) runs on RAW_NS_CT { |
| 145 | NSCP.send(t_NS_Send(g_ns_conn_id, ts_NS_BLOCK(cause, mp_nsconfig.nsvci))); |
| 146 | alt { |
| 147 | [] NSCP.receive(t_NS_RecvFrom(tr_NS_BLOCK_ACK(mp_nsconfig.nsvci))); |
| 148 | [] NSCP.receive { repeat; } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | /* receive NS-ALIVE and ACK it */ |
| 153 | altstep as_rx_alive_tx_ack(boolean oneshot := false) runs on RAW_NS_CT { |
| 154 | [] NSCP.receive(t_NS_RecvFrom(t_NS_ALIVE)) { |
| 155 | NSCP.send(t_NS_Send(g_ns_conn_id, t_NS_ALIVE_ACK)); |
| 156 | if (not oneshot) { repeat; } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | /* Receive a BSSGP RESET for given BVCI and ACK it */ |
| 161 | altstep as_rx_bvc_reset_tx_ack(BssgpBvci bvci, boolean oneshot := false) runs on RAW_NS_CT { |
| 162 | var NS_RecvFrom ns_rf; |
| 163 | /* FIXME: nail down received cell_id in match */ |
| 164 | [] NSCP.receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, 0, |
| 165 | decmatch tr_BVC_RESET(?, bvci, ?)))) |
| 166 | -> value ns_rf { |
| 167 | var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.msg.pDU_NS_Unitdata.nS_SDU); |
| 168 | var PDU_BSSGP bssgp_tx := valueof(ts_BVC_RESET_ACK(bvci, mp_gb_cfg.cell_id)); |
| 169 | NSCP.send(t_NS_Send(g_ns_conn_id, ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx)))); |
| 170 | if (not oneshot) { repeat; } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | |
| 175 | /* Receive a BSSGP UNBLOCK for given BVCI and ACK it */ |
| 176 | altstep as_rx_bvc_unblock_tx_ack(BssgpBvci bvci, boolean oneshot := false) runs on RAW_NS_CT { |
| 177 | var NS_RecvFrom ns_rf; |
| 178 | [] NSCP.receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, 0, |
| 179 | decmatch t_BVC_UNBLOCK(bvci)))) |
| 180 | -> value ns_rf { |
| 181 | var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.msg.pDU_NS_Unitdata.nS_SDU); |
| 182 | var PDU_BSSGP bssgp_tx := valueof(t_BVC_UNBLOCK_ACK(bvci)); |
| 183 | NSCP.send(t_NS_Send(g_ns_conn_id, ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx)))); |
| 184 | if (not oneshot) { repeat; } |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | /* Receive a BSSGP FLOW-CONTROL-BVC and ACK it */ |
| 189 | altstep as_rx_bvc_fc_tx_ack(BssgpBvci bvci, boolean oneshot := false) runs on RAW_NS_CT { |
| 190 | var NS_RecvFrom ns_rf; |
| 191 | [] NSCP.receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, bvci, |
| 192 | decmatch tr_BVC_FC_BVC))) |
| 193 | -> value ns_rf { |
| 194 | var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.msg.pDU_NS_Unitdata.nS_SDU); |
| 195 | var OCT1 tag := bssgp_rx.pDU_BSSGP_FLOW_CONTROL_BVC.tag.unstructured_Value; |
| 196 | var PDU_BSSGP bssgp_tx := valueof(t_BVC_FC_BVC_ACK(tag)); |
| 197 | NSCP.send(t_NS_Send(g_ns_conn_id, ts_NS_UNITDATA(t_SduCtrlB, bvci, enc_PDU_BSSGP(bssgp_tx)))); |
| 198 | if (not oneshot) { repeat; } |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | /********************************************************************************** |
| 203 | * Classic Gb/IP bring-up test cases using NS-{RESET,BLOCK,UNBLOCK} and no IP-SNS * |
| 204 | **********************************************************************************/ |
| 205 | |
| 206 | /* Receive a NS-RESET and ACK it */ |
| 207 | private altstep as_rx_ns_reset_ack(boolean oneshot := false) runs on RAW_NS_CT { |
| 208 | var NS_RecvFrom ns_rf; |
| 209 | [] NSCP.receive(t_NS_RecvFrom(tr_NS_RESET(NS_CAUSE_OM_INTERVENTION, mp_nsconfig.nsvci, |
| 210 | mp_nsconfig.nsei))) -> value ns_rf { |
| 211 | NSCP.send(t_NS_Send(g_ns_conn_id, ts_NS_RESET_ACK(mp_nsconfig.nsvci, mp_nsconfig.nsei))); |
| 212 | if (not oneshot) { repeat; } |
| 213 | } |
| 214 | } |
| 215 | /* Receive a NS-UNBLOCK and ACK it */ |
| 216 | private altstep as_rx_ns_unblock_ack(boolean oneshot := false) runs on RAW_NS_CT { |
| 217 | var NS_RecvFrom ns_rf; |
| 218 | [] NSCP.receive(t_NS_RecvFrom(t_NS_UNBLOCK)) -> value ns_rf { |
| 219 | NSCP.send(t_NS_Send(g_ns_conn_id, t_NS_UNBLOCK_ACK)); |
| 220 | if (not oneshot) { repeat; } |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | /* test the NS-RESET procedure */ |
| 225 | testcase TC_ns_reset() runs on RAW_NS_CT { |
| 226 | f_init_ns_codec(); |
| 227 | f_init_pcuif(); |
| 228 | |
| 229 | |
| 230 | /* Expect inbound NS-RESET procedure */ |
| 231 | as_rx_ns_reset_ack(oneshot := true); |
| 232 | setverdict(pass); |
| 233 | } |
| 234 | |
| 235 | /* ensure NS-RESET are re-transmitted */ |
| 236 | testcase TC_ns_reset_retrans() runs on RAW_NS_CT { |
| 237 | f_init_ns_codec(); |
| 238 | f_init_pcuif(); |
| 239 | |
| 240 | var integer i; |
| 241 | for (i := 0; i < 3; i := i+1) { |
| 242 | NSCP.receive(t_NS_RecvFrom(tr_NS_RESET(NS_CAUSE_OM_INTERVENTION, |
| 243 | mp_nsconfig.nsvci, mp_nsconfig.nsei))); |
| 244 | } |
| 245 | |
| 246 | /* Expect inbound NS-RESET procedure */ |
| 247 | as_rx_ns_reset_ack(oneshot := true); |
| 248 | setverdict(pass); |
| 249 | } |
| 250 | |
| 251 | /* test the inbound NS-ALIVE procedure after NS-RESET */ |
| 252 | testcase TC_ns_alive() runs on RAW_NS_CT { |
| 253 | f_init_ns_codec(); |
| 254 | f_init_pcuif(); |
| 255 | |
| 256 | /* Expect inbound NS-RESET procedure */ |
| 257 | as_rx_ns_reset_ack(oneshot := true); |
| 258 | |
| 259 | /* wait for one ALIVE cycle, then ACK any further ALIVE in the background */ |
| 260 | as_rx_alive_tx_ack(oneshot := true); |
| 261 | setverdict(pass); |
| 262 | } |
| 263 | |
| 264 | /* Test for NS-RESET after NS-ALIVE timeout */ |
| 265 | testcase TC_ns_alive_timeout_reset() runs on RAW_NS_CT { |
| 266 | f_init_ns_codec(100.0); |
| 267 | f_init_pcuif(); |
| 268 | |
| 269 | /* Expect inbound NS-RESET procedure */ |
| 270 | as_rx_ns_reset_ack(oneshot := true); |
| 271 | |
| 272 | /* wait for at least one NS-ALIVE */ |
| 273 | NSCP.receive(t_NS_RecvFrom(t_NS_ALIVE)); |
| 274 | |
| 275 | /* wait for NS-RESET to re-appear, ignoring any NS-ALIVE until then */ |
| 276 | alt { |
| 277 | [] as_rx_ns_reset_ack(oneshot := true) { setverdict(pass); } |
| 278 | [] NSCP.receive(t_NS_RecvFrom(t_NS_ALIVE)) { repeat; } |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | /* test for NS-RESET/NS-ALIVE/NS-UNBLOCK */ |
| 283 | testcase TC_ns_unblock() runs on RAW_NS_CT { |
| 284 | f_init_ns_codec(); |
| 285 | f_init_pcuif(); |
| 286 | |
| 287 | /* Expect inbound NS-RESET procedure */ |
| 288 | as_rx_ns_reset_ack(oneshot := true); |
| 289 | |
| 290 | /* wait for one ALIVE cycle, then ACK any further ALIVE in the background */ |
| 291 | as_rx_alive_tx_ack(oneshot := true); |
| 292 | activate(as_rx_alive_tx_ack()); |
| 293 | |
| 294 | as_rx_ns_unblock_ack(oneshot := true); |
| 295 | setverdict(pass); |
| 296 | } |
| 297 | |
| 298 | /* test for NS-UNBLOCK re-transmissions */ |
| 299 | testcase TC_ns_unblock_retrans() runs on RAW_NS_CT { |
| 300 | f_init_ns_codec(); |
| 301 | f_init_pcuif(); |
| 302 | |
| 303 | /* Expect inbound NS-RESET procedure */ |
| 304 | as_rx_ns_reset_ack(oneshot := true); |
| 305 | |
| 306 | /* wait for one ALIVE cycle, then ACK any further ALIVE in the background */ |
| 307 | as_rx_alive_tx_ack(oneshot := true); |
| 308 | activate(as_rx_alive_tx_ack()); |
| 309 | |
| 310 | /* wait for first NS-UNBLOCK, don't respond */ |
| 311 | NSCP.receive(t_NS_RecvFrom(t_NS_UNBLOCK)); |
| 312 | |
| 313 | /* wait for re-transmission of NS-UNBLOCK */ |
| 314 | as_rx_ns_unblock_ack(oneshot := true); |
| 315 | setverdict(pass); |
| 316 | } |
| 317 | |
| 318 | /* full bring-up of the Gb link for NS and BSSGP layer up to BVC-FC */ |
| 319 | testcase TC_ns_full_bringup() runs on RAW_NS_CT { |
| 320 | f_init_ns_codec(); |
| 321 | f_init_pcuif(); |
| 322 | |
| 323 | /* Expect inbound NS-RESET procedure */ |
| 324 | as_rx_ns_reset_ack(oneshot := true); |
| 325 | |
| 326 | /* wait for one ALIVE cycle, then ACK any further ALIVE in the background */ |
| 327 | as_rx_alive_tx_ack(oneshot := true); |
| 328 | activate(as_rx_alive_tx_ack()); |
| 329 | |
| 330 | as_rx_ns_unblock_ack(oneshot := true); |
| 331 | |
| 332 | f_outgoing_ns_alive(); |
| 333 | |
| 334 | /* Expect BVC-RESET for signaling (0) and ptp BVCI */ |
| 335 | as_rx_bvc_reset_tx_ack(0, oneshot := true); |
| 336 | as_rx_bvc_reset_tx_ack(mp_gb_cfg.bvci, oneshot := true); |
| 337 | as_rx_bvc_unblock_tx_ack(mp_gb_cfg.bvci, oneshot := true); |
| 338 | |
| 339 | /* wait for one FLOW-CONTROL BVC and then ACK any further in the future */ |
| 340 | as_rx_bvc_fc_tx_ack(mp_gb_cfg.bvci, oneshot := true); |
| 341 | activate(as_rx_bvc_fc_tx_ack(mp_gb_cfg.bvci)); |
| 342 | setverdict(pass); |
| 343 | } |
| 344 | |
| 345 | /* test outbound (SGSN-originated) NS-BLOCK procedure */ |
| 346 | testcase TC_ns_so_block() runs on RAW_NS_CT { |
| 347 | f_init_ns_codec(); |
| 348 | f_init_pcuif(); |
| 349 | |
| 350 | /* Expect inbound NS-RESET procedure */ |
| 351 | as_rx_ns_reset_ack(oneshot := true); |
| 352 | |
| 353 | /* wait for one ALIVE cycle, then ACK any further ALIVE in the background */ |
| 354 | as_rx_alive_tx_ack(oneshot := true); |
| 355 | activate(as_rx_alive_tx_ack()); |
| 356 | |
| 357 | as_rx_ns_unblock_ack(oneshot := true); |
| 358 | |
| 359 | f_outgoing_ns_alive(); |
| 360 | |
| 361 | f_outgoing_ns_block(NS_CAUSE_EQUIPMENT_FAILURE); |
| 362 | setverdict(pass); |
| 363 | } |
| 364 | |
| 365 | |
| 366 | control { |
| 367 | execute( TC_ns_reset() ); |
| 368 | execute( TC_ns_reset_retrans() ); |
| 369 | execute( TC_ns_alive() ); |
| 370 | execute( TC_ns_alive_timeout_reset() ); |
| 371 | execute( TC_ns_unblock() ); |
| 372 | execute( TC_ns_unblock_retrans() ); |
| 373 | execute( TC_ns_full_bringup() ); |
| 374 | execute( TC_ns_so_block() ); |
| 375 | } |
| 376 | |
| 377 | |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | } |