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 | |
Harald Welte | 9fbcf4b | 2018-12-07 07:56:52 +0100 | [diff] [blame] | 99 | /* perform outbound NS-ALIVE procedure */ |
| 100 | function f_outgoing_ns_alive() runs on RAW_NS_CT { |
| 101 | NSCP.send(t_NS_Send(g_ns_conn_id, t_NS_ALIVE)); |
| 102 | alt { |
| 103 | [] NSCP.receive(t_NS_RecvFrom(t_NS_ALIVE_ACK)); |
| 104 | [] NSCP.receive { repeat; } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /* perform outbound NS-BLOCK procedure */ |
| 109 | function f_outgoing_ns_block(NsCause cause) runs on RAW_NS_CT { |
| 110 | NSCP.send(t_NS_Send(g_ns_conn_id, ts_NS_BLOCK(cause, mp_nsconfig.nsvci))); |
| 111 | alt { |
| 112 | [] NSCP.receive(t_NS_RecvFrom(tr_NS_BLOCK_ACK(mp_nsconfig.nsvci))); |
| 113 | [] NSCP.receive { repeat; } |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | /* receive NS-ALIVE and ACK it */ |
| 118 | altstep as_rx_alive_tx_ack(boolean oneshot := false) runs on RAW_NS_CT { |
| 119 | [] NSCP.receive(t_NS_RecvFrom(t_NS_ALIVE)) { |
| 120 | NSCP.send(t_NS_Send(g_ns_conn_id, t_NS_ALIVE_ACK)); |
| 121 | if (not oneshot) { repeat; } |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /* Receive a BSSGP RESET for given BVCI and ACK it */ |
| 126 | altstep as_rx_bvc_reset_tx_ack(BssgpBvci bvci, boolean oneshot := false) runs on RAW_NS_CT { |
| 127 | var NS_RecvFrom ns_rf; |
| 128 | /* FIXME: nail down received cell_id in match */ |
| 129 | [] NSCP.receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, 0, |
| 130 | decmatch tr_BVC_RESET(?, bvci, ?)))) |
| 131 | -> value ns_rf { |
| 132 | var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.msg.pDU_NS_Unitdata.nS_SDU); |
| 133 | var PDU_BSSGP bssgp_tx := valueof(ts_BVC_RESET_ACK(bvci, mp_gb_cfg.cell_id)); |
| 134 | NSCP.send(t_NS_Send(g_ns_conn_id, ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx)))); |
| 135 | if (not oneshot) { repeat; } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | |
| 140 | /* Receive a BSSGP UNBLOCK for given BVCI and ACK it */ |
| 141 | altstep as_rx_bvc_unblock_tx_ack(BssgpBvci bvci, boolean oneshot := false) runs on RAW_NS_CT { |
| 142 | var NS_RecvFrom ns_rf; |
| 143 | [] NSCP.receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, 0, |
| 144 | decmatch t_BVC_UNBLOCK(bvci)))) |
| 145 | -> value ns_rf { |
| 146 | var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.msg.pDU_NS_Unitdata.nS_SDU); |
| 147 | var PDU_BSSGP bssgp_tx := valueof(t_BVC_UNBLOCK_ACK(bvci)); |
| 148 | NSCP.send(t_NS_Send(g_ns_conn_id, ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx)))); |
| 149 | if (not oneshot) { repeat; } |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | /* Receive a BSSGP FLOW-CONTROL-BVC and ACK it */ |
| 154 | altstep as_rx_bvc_fc_tx_ack(BssgpBvci bvci, boolean oneshot := false) runs on RAW_NS_CT { |
| 155 | var NS_RecvFrom ns_rf; |
| 156 | [] NSCP.receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, bvci, |
| 157 | decmatch tr_BVC_FC_BVC))) |
| 158 | -> value ns_rf { |
| 159 | var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.msg.pDU_NS_Unitdata.nS_SDU); |
| 160 | var OCT1 tag := bssgp_rx.pDU_BSSGP_FLOW_CONTROL_BVC.tag.unstructured_Value; |
| 161 | var PDU_BSSGP bssgp_tx := valueof(t_BVC_FC_BVC_ACK(tag)); |
| 162 | NSCP.send(t_NS_Send(g_ns_conn_id, ts_NS_UNITDATA(t_SduCtrlB, bvci, enc_PDU_BSSGP(bssgp_tx)))); |
| 163 | if (not oneshot) { repeat; } |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | /********************************************************************************** |
| 168 | * Classic Gb/IP bring-up test cases using NS-{RESET,BLOCK,UNBLOCK} and no IP-SNS * |
| 169 | **********************************************************************************/ |
| 170 | |
| 171 | /* Receive a NS-RESET and ACK it */ |
| 172 | private altstep as_rx_ns_reset_ack(boolean oneshot := false) runs on RAW_NS_CT { |
| 173 | var NS_RecvFrom ns_rf; |
| 174 | [] NSCP.receive(t_NS_RecvFrom(tr_NS_RESET(NS_CAUSE_OM_INTERVENTION, mp_nsconfig.nsvci, |
| 175 | mp_nsconfig.nsei))) -> value ns_rf { |
| 176 | NSCP.send(t_NS_Send(g_ns_conn_id, ts_NS_RESET_ACK(mp_nsconfig.nsvci, mp_nsconfig.nsei))); |
| 177 | if (not oneshot) { repeat; } |
| 178 | } |
| 179 | } |
| 180 | /* Receive a NS-UNBLOCK and ACK it */ |
| 181 | private altstep as_rx_ns_unblock_ack(boolean oneshot := false) runs on RAW_NS_CT { |
| 182 | var NS_RecvFrom ns_rf; |
| 183 | [] NSCP.receive(t_NS_RecvFrom(t_NS_UNBLOCK)) -> value ns_rf { |
| 184 | NSCP.send(t_NS_Send(g_ns_conn_id, t_NS_UNBLOCK_ACK)); |
| 185 | if (not oneshot) { repeat; } |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | /* test the NS-RESET procedure */ |
| 190 | testcase TC_ns_reset() runs on RAW_NS_CT { |
| 191 | f_init_ns_codec(); |
| 192 | f_init_pcuif(); |
| 193 | |
| 194 | |
| 195 | /* Expect inbound NS-RESET procedure */ |
| 196 | as_rx_ns_reset_ack(oneshot := true); |
| 197 | setverdict(pass); |
| 198 | } |
| 199 | |
| 200 | /* ensure NS-RESET are re-transmitted */ |
| 201 | testcase TC_ns_reset_retrans() runs on RAW_NS_CT { |
| 202 | f_init_ns_codec(); |
| 203 | f_init_pcuif(); |
| 204 | |
| 205 | var integer i; |
| 206 | for (i := 0; i < 3; i := i+1) { |
| 207 | NSCP.receive(t_NS_RecvFrom(tr_NS_RESET(NS_CAUSE_OM_INTERVENTION, |
| 208 | mp_nsconfig.nsvci, mp_nsconfig.nsei))); |
| 209 | } |
| 210 | |
| 211 | /* Expect inbound NS-RESET procedure */ |
| 212 | as_rx_ns_reset_ack(oneshot := true); |
| 213 | setverdict(pass); |
| 214 | } |
| 215 | |
| 216 | /* test the inbound NS-ALIVE procedure after NS-RESET */ |
| 217 | testcase TC_ns_alive() runs on RAW_NS_CT { |
| 218 | f_init_ns_codec(); |
| 219 | f_init_pcuif(); |
| 220 | |
| 221 | /* Expect inbound NS-RESET procedure */ |
| 222 | as_rx_ns_reset_ack(oneshot := true); |
| 223 | |
| 224 | /* wait for one ALIVE cycle, then ACK any further ALIVE in the background */ |
| 225 | as_rx_alive_tx_ack(oneshot := true); |
| 226 | setverdict(pass); |
| 227 | } |
| 228 | |
| 229 | /* Test for NS-RESET after NS-ALIVE timeout */ |
| 230 | testcase TC_ns_alive_timeout_reset() runs on RAW_NS_CT { |
| 231 | f_init_ns_codec(100.0); |
| 232 | f_init_pcuif(); |
| 233 | |
| 234 | /* Expect inbound NS-RESET procedure */ |
| 235 | as_rx_ns_reset_ack(oneshot := true); |
| 236 | |
| 237 | /* wait for at least one NS-ALIVE */ |
| 238 | NSCP.receive(t_NS_RecvFrom(t_NS_ALIVE)); |
| 239 | |
| 240 | /* wait for NS-RESET to re-appear, ignoring any NS-ALIVE until then */ |
| 241 | alt { |
| 242 | [] as_rx_ns_reset_ack(oneshot := true) { setverdict(pass); } |
| 243 | [] NSCP.receive(t_NS_RecvFrom(t_NS_ALIVE)) { repeat; } |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /* test for NS-RESET/NS-ALIVE/NS-UNBLOCK */ |
| 248 | testcase TC_ns_unblock() runs on RAW_NS_CT { |
| 249 | f_init_ns_codec(); |
| 250 | f_init_pcuif(); |
| 251 | |
| 252 | /* Expect inbound NS-RESET procedure */ |
| 253 | as_rx_ns_reset_ack(oneshot := true); |
| 254 | |
| 255 | /* wait for one ALIVE cycle, then ACK any further ALIVE in the background */ |
| 256 | as_rx_alive_tx_ack(oneshot := true); |
| 257 | activate(as_rx_alive_tx_ack()); |
| 258 | |
| 259 | as_rx_ns_unblock_ack(oneshot := true); |
| 260 | setverdict(pass); |
| 261 | } |
| 262 | |
| 263 | /* test for NS-UNBLOCK re-transmissions */ |
| 264 | testcase TC_ns_unblock_retrans() runs on RAW_NS_CT { |
| 265 | f_init_ns_codec(); |
| 266 | f_init_pcuif(); |
| 267 | |
| 268 | /* Expect inbound NS-RESET procedure */ |
| 269 | as_rx_ns_reset_ack(oneshot := true); |
| 270 | |
| 271 | /* wait for one ALIVE cycle, then ACK any further ALIVE in the background */ |
| 272 | as_rx_alive_tx_ack(oneshot := true); |
| 273 | activate(as_rx_alive_tx_ack()); |
| 274 | |
| 275 | /* wait for first NS-UNBLOCK, don't respond */ |
| 276 | NSCP.receive(t_NS_RecvFrom(t_NS_UNBLOCK)); |
| 277 | |
| 278 | /* wait for re-transmission of NS-UNBLOCK */ |
| 279 | as_rx_ns_unblock_ack(oneshot := true); |
| 280 | setverdict(pass); |
| 281 | } |
| 282 | |
| 283 | /* full bring-up of the Gb link for NS and BSSGP layer up to BVC-FC */ |
| 284 | testcase TC_ns_full_bringup() runs on RAW_NS_CT { |
| 285 | f_init_ns_codec(); |
| 286 | f_init_pcuif(); |
| 287 | |
| 288 | /* Expect inbound NS-RESET procedure */ |
| 289 | as_rx_ns_reset_ack(oneshot := true); |
| 290 | |
| 291 | /* wait for one ALIVE cycle, then ACK any further ALIVE in the background */ |
| 292 | as_rx_alive_tx_ack(oneshot := true); |
| 293 | activate(as_rx_alive_tx_ack()); |
| 294 | |
| 295 | as_rx_ns_unblock_ack(oneshot := true); |
| 296 | |
| 297 | f_outgoing_ns_alive(); |
| 298 | |
| 299 | /* Expect BVC-RESET for signaling (0) and ptp BVCI */ |
| 300 | as_rx_bvc_reset_tx_ack(0, oneshot := true); |
| 301 | as_rx_bvc_reset_tx_ack(mp_gb_cfg.bvci, oneshot := true); |
| 302 | as_rx_bvc_unblock_tx_ack(mp_gb_cfg.bvci, oneshot := true); |
| 303 | |
| 304 | /* wait for one FLOW-CONTROL BVC and then ACK any further in the future */ |
| 305 | as_rx_bvc_fc_tx_ack(mp_gb_cfg.bvci, oneshot := true); |
| 306 | activate(as_rx_bvc_fc_tx_ack(mp_gb_cfg.bvci)); |
| 307 | setverdict(pass); |
| 308 | } |
| 309 | |
| 310 | /* test outbound (SGSN-originated) NS-BLOCK procedure */ |
| 311 | testcase TC_ns_so_block() runs on RAW_NS_CT { |
| 312 | f_init_ns_codec(); |
| 313 | f_init_pcuif(); |
| 314 | |
| 315 | /* Expect inbound NS-RESET procedure */ |
| 316 | as_rx_ns_reset_ack(oneshot := true); |
| 317 | |
| 318 | /* wait for one ALIVE cycle, then ACK any further ALIVE in the background */ |
| 319 | as_rx_alive_tx_ack(oneshot := true); |
| 320 | activate(as_rx_alive_tx_ack()); |
| 321 | |
| 322 | as_rx_ns_unblock_ack(oneshot := true); |
| 323 | |
| 324 | f_outgoing_ns_alive(); |
| 325 | |
| 326 | f_outgoing_ns_block(NS_CAUSE_EQUIPMENT_FAILURE); |
| 327 | setverdict(pass); |
| 328 | } |
| 329 | |
| 330 | |
| 331 | control { |
| 332 | execute( TC_ns_reset() ); |
| 333 | execute( TC_ns_reset_retrans() ); |
| 334 | execute( TC_ns_alive() ); |
| 335 | execute( TC_ns_alive_timeout_reset() ); |
| 336 | execute( TC_ns_unblock() ); |
| 337 | execute( TC_ns_unblock_retrans() ); |
| 338 | execute( TC_ns_full_bringup() ); |
| 339 | execute( TC_ns_so_block() ); |
| 340 | } |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | } |