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 | |
Alexander Couzens | bd6e9a1 | 2021-06-07 00:45:15 +0200 | [diff] [blame] | 28 | type record PerIPProvider { |
| 29 | NS_Provider_IPL4_CT vc_NSP_IP, |
| 30 | charstring local_ip, |
| 31 | PortNumber local_udp_port |
| 32 | } |
| 33 | |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 34 | public type component RAW_NS_CT { |
| 35 | /* UDP port towards the bottom (IUT) */ |
| 36 | port NS_PROVIDER_PT NSCP[4]; |
Alexander Couzens | bd6e9a1 | 2021-06-07 00:45:15 +0200 | [diff] [blame] | 37 | var PerIPProvider ip_prov[4]; |
| 38 | port NSPIP_PROC_PT NSPIP_PROC; |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 39 | #ifdef NS_EMULATION_FR |
| 40 | var NS_Provider_FR_CT vc_NSP_FR[4]; |
| 41 | #endif |
| 42 | var NSConfiguration g_nsconfig; |
| 43 | timer g_T_guard; |
Harald Welte | 424ec52 | 2021-03-23 18:20:12 +0100 | [diff] [blame] | 44 | var boolean g_handle_rx_alive := false; |
Alexander Couzens | bd6e9a1 | 2021-06-07 00:45:15 +0200 | [diff] [blame] | 45 | var boolean rawns_initialized := false; |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | public altstep as_Tguard() runs on RAW_NS_CT { |
| 49 | [] g_T_guard.timeout { |
| 50 | setverdict(fail, "Timeout of T_guard"); |
| 51 | mtc.stop; |
| 52 | } |
| 53 | } |
| 54 | |
Alexander Couzens | bd6e9a1 | 2021-06-07 00:45:15 +0200 | [diff] [blame] | 55 | function f_find_ip_provider(NSVCConfigurationIP nsip_config) |
| 56 | runs on RAW_NS_CT return integer { |
| 57 | for (var integer idx := 0; idx < sizeof(ip_prov); idx := idx+1) { |
| 58 | if (ip_prov[idx].vc_NSP_IP == null) { |
| 59 | continue; |
| 60 | } |
| 61 | |
| 62 | if (ip_prov[idx].local_ip == nsip_config.local_ip and |
| 63 | ip_prov[idx].local_udp_port == nsip_config.local_udp_port) { |
| 64 | return idx; |
| 65 | } |
| 66 | } |
| 67 | return -1; |
| 68 | } |
| 69 | |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 70 | function f_init_ns_codec(NSConfiguration ns_config, integer idx := 0, float guard_secs := 60.0, charstring id := testcasename()) runs on RAW_NS_CT { |
| 71 | var Result res; |
| 72 | |
| 73 | if (not g_T_guard.running) { |
| 74 | g_T_guard.start(guard_secs); |
| 75 | activate(as_Tguard()); |
| 76 | } |
| 77 | |
Alexander Couzens | bd6e9a1 | 2021-06-07 00:45:15 +0200 | [diff] [blame] | 78 | if (not rawns_initialized) { |
| 79 | for (var integer i := 0; i < sizeof(ip_prov); i := i+1) { |
| 80 | ip_prov[i].vc_NSP_IP := null; |
| 81 | } |
| 82 | rawns_initialized := true; |
| 83 | } |
| 84 | |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 85 | if (not isbound(g_nsconfig)) { |
| 86 | g_nsconfig := ns_config; |
| 87 | } |
| 88 | |
| 89 | if (ischosen(ns_config.nsvc[idx].provider.ip)) { |
Alexander Couzens | bd6e9a1 | 2021-06-07 00:45:15 +0200 | [diff] [blame] | 90 | var integer prov_idx := f_find_ip_provider(ns_config.nsvc[idx].provider.ip); |
| 91 | /* Connect the UDP socket |
| 92 | * check if NS_Provider_IPL4_CT is already created |
| 93 | * add list of vc_NSP_IP with entries of source ip/port |
| 94 | * add a NSVC to it */ |
| 95 | if (prov_idx == -1) { |
| 96 | for (prov_idx := 0; prov_idx < sizeof(ip_prov); prov_idx := prov_idx+1) { |
| 97 | if (ip_prov[prov_idx].vc_NSP_IP == null) { |
| 98 | break; |
| 99 | } |
| 100 | } |
| 101 | if (prov_idx > sizeof(ip_prov)) { |
| 102 | /* TODO: error !! */ |
| 103 | } |
| 104 | ip_prov[prov_idx].local_ip := ns_config.nsvc[idx].provider.ip.local_ip; |
| 105 | ip_prov[prov_idx].local_udp_port := ns_config.nsvc[idx].provider.ip.local_udp_port; |
| 106 | ip_prov[prov_idx].vc_NSP_IP := NS_Provider_IPL4_CT.create(id & "-provIP" & int2str(prov_idx)); |
| 107 | connect(self:NSPIP_PROC, ip_prov[prov_idx].vc_NSP_IP:PROC); |
| 108 | ip_prov[prov_idx].vc_NSP_IP.start(NS_Provider_IPL4.main(ns_config.nsvc[idx], ns_config, id)); |
| 109 | } |
| 110 | var integer port_idx := f_nspip_add_nsvc2(ip_prov[prov_idx].vc_NSP_IP, ns_config.nsvc[idx].provider.ip.remote_ip, ns_config.nsvc[idx].provider.ip.remote_udp_port); |
| 111 | connect(self:NSCP[idx], ip_prov[prov_idx].vc_NSP_IP:NSVC[port_idx]); |
| 112 | /* the NS_PROV_LINK_STATUS_UP is not sent by the NS_Provider_IPL4 because we connect the port manual */ |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 113 | #ifdef NS_EMULATION_FR |
| 114 | } else if (ischosen(ns_config.nsvc[idx].provider.fr)) { |
| 115 | vc_NSP_FR[idx] := NS_Provider_FR_CT.create(id & "-provFR"); |
| 116 | connect(self:NSCP[idx], vc_NSP_FR[idx]:NSE); |
| 117 | vc_NSP_FR[idx].start(NS_Provider_FR.main(ns_config.nsvc[idx], ns_config, id)); |
Alexander Couzens | bd6e9a1 | 2021-06-07 00:45:15 +0200 | [diff] [blame] | 118 | NSCP[idx].receive(NS_Provider_Evt:{link_status:=NS_PROV_LINK_STATUS_UP}); |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 119 | #endif |
| 120 | } else { |
| 121 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported NS provider"); |
| 122 | } |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | function f_clean_ns_codec() runs on RAW_NS_CT { |
Alexander Couzens | bd6e9a1 | 2021-06-07 00:45:15 +0200 | [diff] [blame] | 126 | for (var integer i := 0; i < lengthof(ip_prov); i := i + 1) { |
| 127 | if (ip_prov[i].vc_NSP_IP != null) { |
| 128 | ip_prov[i].vc_NSP_IP.stop; |
| 129 | } |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 130 | } |
| 131 | #ifdef NS_EMULATION_FR |
| 132 | for (var integer i := 0; i < lengthof(vc_NSP_FR); i := i + 1) { |
| 133 | vc_NSP_FR[i].stop; |
| 134 | } |
| 135 | #endif NS_EMULATION_FR |
| 136 | } |
| 137 | |
| 138 | public altstep ax_rx_fail_on_any_ns(integer idx := 0) runs on RAW_NS_CT { |
| 139 | var PDU_NS nrf; |
| 140 | [] NSCP[idx].receive(PDU_NS: ?) -> value nrf { |
| 141 | setverdict(fail, "Received unexpected NS: ", nrf); |
| 142 | mtc.stop; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | function f_ns_exp(template PDU_NS exp_rx, integer idx := 0) runs on RAW_NS_CT return PDU_NS { |
| 147 | var PDU_NS nrf; |
| 148 | log("f_ns_exp() expecting ", exp_rx); |
| 149 | /* last activated altstep has the lowest priority */ |
| 150 | var default d := activate(ax_rx_fail_on_any_ns()); |
| 151 | alt { |
| 152 | [] NSCP[idx].receive(PDU_NS: exp_rx) -> value nrf { } |
Alexander Couzens | 3f1d661 | 2021-04-19 02:57:14 +0200 | [diff] [blame] | 153 | [g_handle_rx_alive] as_rx_alive_tx_ack(idx := idx); |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 154 | } |
| 155 | deactivate(d); |
| 156 | return nrf; |
| 157 | } |
| 158 | |
| 159 | /* perform outbound NS-ALIVE procedure */ |
| 160 | function f_outgoing_ns_alive(integer idx := 0) runs on RAW_NS_CT { |
| 161 | NSCP[idx].send(t_NS_ALIVE); |
| 162 | alt { |
| 163 | [] NSCP[idx].receive(t_NS_ALIVE_ACK); |
Alexander Couzens | 3f1d661 | 2021-04-19 02:57:14 +0200 | [diff] [blame] | 164 | [g_handle_rx_alive] as_rx_alive_tx_ack(idx := idx); |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 165 | [] NSCP[idx].receive { repeat; } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | /* perform outbound NS-ALIVE procedure */ |
| 170 | function f_outgoing_ns_alive_no_ack(integer idx := 0, float tout := 10.0) runs on RAW_NS_CT { |
| 171 | timer T := tout; |
| 172 | NSCP[idx].send(t_NS_ALIVE); |
| 173 | T.start; |
| 174 | alt { |
| 175 | [] NSCP[idx].receive(t_NS_ALIVE_ACK) { |
| 176 | setverdict(fail, "Received unexpected NS-ALIVE ACK"); |
| 177 | } |
Alexander Couzens | 3f1d661 | 2021-04-19 02:57:14 +0200 | [diff] [blame] | 178 | [g_handle_rx_alive] as_rx_alive_tx_ack(idx := idx); |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 179 | [] NSCP[idx].receive { repeat; } |
| 180 | [] T.timeout { |
| 181 | setverdict(pass); |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | function f_outgoing_ns_reset(integer idx := 0, float tout := 10.0) runs on RAW_NS_CT { |
| 187 | timer T := tout; |
| 188 | var template PDU_NS reset := ts_NS_RESET(NS_CAUSE_EQUIPMENT_FAILURE, g_nsconfig.nsvc[idx].nsvci, g_nsconfig.nsei) |
| 189 | NSCP[idx].send(reset); |
| 190 | T.start; |
| 191 | alt { |
| 192 | [] NSCP[idx].receive(ts_NS_RESET_ACK(g_nsconfig.nsvc[idx].nsvci, g_nsconfig.nsei)) { |
| 193 | setverdict(pass); |
| 194 | } |
Alexander Couzens | 3f1d661 | 2021-04-19 02:57:14 +0200 | [diff] [blame] | 195 | [g_handle_rx_alive] as_rx_alive_tx_ack(idx := idx); |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 196 | [] NSCP[idx].receive { repeat; } |
| 197 | [] T.timeout { |
| 198 | setverdict(fail, "Failed to receive a RESET ACK"); |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | /* perform outbound NS-BLOCK procedure */ |
| 204 | function f_outgoing_ns_block(NsCause cause, integer idx := 0) runs on RAW_NS_CT { |
| 205 | NSCP[idx].send(ts_NS_BLOCK(cause, g_nsconfig.nsvc[idx].nsvci)); |
| 206 | alt { |
| 207 | [] NSCP[idx].receive(tr_NS_BLOCK_ACK(g_nsconfig.nsvc[idx].nsvci)); |
Alexander Couzens | 3f1d661 | 2021-04-19 02:57:14 +0200 | [diff] [blame] | 208 | [g_handle_rx_alive] as_rx_alive_tx_ack(idx := idx); |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 209 | [] NSCP[idx].receive { repeat; } |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | /* perform outbound NS-UNBLOCK procedure */ |
| 214 | function f_outgoing_ns_unblock(integer idx := 0) runs on RAW_NS_CT { |
| 215 | NSCP[idx].send(t_NS_UNBLOCK); |
| 216 | alt { |
| 217 | [] NSCP[idx].receive(t_NS_UNBLOCK_ACK); |
Alexander Couzens | 3f1d661 | 2021-04-19 02:57:14 +0200 | [diff] [blame] | 218 | [g_handle_rx_alive] as_rx_alive_tx_ack(idx := idx); |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 219 | [] NSCP[idx].receive { repeat; } |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | /* receive NS-ALIVE and ACK it */ |
| 224 | altstep as_rx_alive_tx_ack(boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT { |
| 225 | [] NSCP[idx].receive(t_NS_ALIVE) { |
| 226 | NSCP[idx].send(t_NS_ALIVE_ACK); |
| 227 | if (not oneshot) { repeat; } |
| 228 | } |
Harald Welte | 6a414c8 | 2021-03-24 00:56:44 +0100 | [diff] [blame] | 229 | /* in oneshot mode, ignore any NS-UNITDATA we receive meanwhile. This is |
| 230 | * particularly useful when waiting for the first NS-ALIVE after SNS-CONFIG, |
| 231 | * where there is a high chance of UNITDATA during the first Tns-test cycle |
| 232 | * before the peer sends its first NS-ALIVE after Tns-test expiration */ |
| 233 | [oneshot] NSCP[idx].receive(tr_NS_UNITDATA(?,?,?)) { |
| 234 | repeat; |
| 235 | } |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | /* Transmit BSSGP RESET for given BVCI and expect ACK */ |
| 239 | function f_tx_bvc_reset_rx_ack(BssgpBvci bvci, template (omit) BssgpCellId tx_cell_id, template BssgpCellId rx_cell_id, |
| 240 | integer idx := 0, boolean exp_ack := true) |
| 241 | runs on RAW_NS_CT { |
| 242 | var PDU_BSSGP bssgp_tx := valueof(ts_BVC_RESET(BSSGP_CAUSE_NET_SV_CAP_MOD_GT_ZERO_KBPS, bvci, |
| 243 | tx_cell_id)); |
| 244 | timer T := 5.0; |
| 245 | NSCP[idx].send(ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx))); |
| 246 | T.start; |
| 247 | alt { |
| 248 | [exp_ack] NSCP[idx].receive(tr_NS_UNITDATA(t_SduCtrlB, 0, |
| 249 | decmatch tr_BVC_RESET_ACK(bvci, rx_cell_id))) { |
| 250 | setverdict(pass); |
| 251 | } |
| 252 | [exp_ack] T.timeout { |
| 253 | setverdict(fail, "No response to BVC-RESET"); |
| 254 | } |
| 255 | [not exp_ack] T.timeout { |
| 256 | setverdict(pass); |
| 257 | } |
Alexander Couzens | 3f1d661 | 2021-04-19 02:57:14 +0200 | [diff] [blame] | 258 | [g_handle_rx_alive] as_rx_alive_tx_ack(idx := idx); |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 259 | [] NSCP[idx].receive { repeat; } |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | /* Receive a BSSGP RESET for given BVCI and ACK it */ |
| 264 | altstep as_rx_bvc_reset_tx_ack(BssgpBvci bvci, template BssgpCellId rx_cell_id, template (omit) BssgpCellId tx_cell_id, |
| 265 | boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT { |
| 266 | var PDU_NS ns_rf; |
| 267 | [] NSCP[idx].receive(tr_NS_UNITDATA(t_SduCtrlB, 0, |
| 268 | decmatch tr_BVC_RESET(?, bvci, rx_cell_id))) |
| 269 | -> value ns_rf { |
| 270 | var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.pDU_NS_Unitdata.nS_SDU); |
| 271 | var PDU_BSSGP bssgp_tx := valueof(ts_BVC_RESET_ACK(bvci, tx_cell_id)); |
| 272 | NSCP[idx].send(ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx))); |
| 273 | if (not oneshot) { repeat; } |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | |
| 278 | /* Receive a BSSGP UNBLOCK for given BVCI and ACK it */ |
| 279 | altstep as_rx_bvc_unblock_tx_ack(BssgpBvci bvci, boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT { |
| 280 | var PDU_NS ns_rf; |
Pau Espin Pedrol | 6ee0126 | 2021-02-05 13:05:06 +0100 | [diff] [blame] | 281 | [] 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] | 282 | 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] | 283 | var PDU_BSSGP bssgp_tx := valueof(ts_BVC_UNBLOCK_ACK(bvci)); |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 284 | NSCP[idx].send(ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx))); |
| 285 | if (not oneshot) { repeat; } |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | /* Receive a BSSGP FLOW-CONTROL-BVC and ACK it */ |
| 290 | altstep as_rx_bvc_fc_tx_ack(BssgpBvci bvci, boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT { |
| 291 | var PDU_NS ns_rf; |
| 292 | [] NSCP[idx].receive(tr_NS_UNITDATA(t_SduCtrlB, bvci, |
| 293 | decmatch tr_BVC_FC_BVC)) |
| 294 | -> value ns_rf { |
| 295 | var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.pDU_NS_Unitdata.nS_SDU); |
| 296 | 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] | 297 | var PDU_BSSGP bssgp_tx := valueof(ts_BVC_FC_BVC_ACK(tag)); |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 298 | NSCP[idx].send(ts_NS_UNITDATA(t_SduCtrlB, bvci, enc_PDU_BSSGP(bssgp_tx))); |
| 299 | if (not oneshot) { repeat; } |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | /********************************************************************************** |
| 304 | * Classic Gb/IP bring-up test cases using NS-{RESET,BLOCK,UNBLOCK} and no IP-SNS * |
| 305 | **********************************************************************************/ |
| 306 | |
| 307 | /* Receive a NS-RESET and ACK it */ |
| 308 | public altstep as_rx_ns_reset_ack(boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT { |
| 309 | var PDU_NS ns_rf; |
| 310 | [] NSCP[idx].receive(tr_NS_RESET(NS_CAUSE_OM_INTERVENTION, g_nsconfig.nsvc[idx].nsvci, |
| 311 | g_nsconfig.nsei)) -> value ns_rf { |
| 312 | NSCP[idx].send(ts_NS_RESET_ACK(g_nsconfig.nsvc[idx].nsvci, g_nsconfig.nsei)); |
| 313 | if (not oneshot) { repeat; } |
| 314 | } |
| 315 | } |
| 316 | /* Receive a NS-UNBLOCK and ACK it */ |
| 317 | public altstep as_rx_ns_unblock_ack(boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT { |
| 318 | var PDU_NS ns_rf; |
| 319 | [] NSCP[idx].receive(t_NS_UNBLOCK) -> value ns_rf { |
| 320 | NSCP[idx].send(t_NS_UNBLOCK_ACK); |
| 321 | if (not oneshot) { repeat; } |
| 322 | } |
| 323 | } |
| 324 | |
Alexander Couzens | 20cd41e | 2021-01-11 02:56:03 +0100 | [diff] [blame] | 325 | /* Receive a NS-BLOCK and ACK it */ |
| 326 | public altstep as_rx_ns_block_ack(boolean oneshot := false, integer idx := 0, template NsCause cause := *, template Nsvci nsvci := *) runs on RAW_NS_CT { |
| 327 | var PDU_NS ns_rf; |
| 328 | [] NSCP[idx].receive(tr_NS_BLOCK(cause, nsvci)) -> value ns_rf { |
| 329 | NSCP[idx].send(ts_NS_BLOCK_ACK(oct2int(ns_rf.pDU_NS_Block.nS_VCI.nS_VCI))); |
| 330 | if (not oneshot) { repeat; } |
| 331 | } |
| 332 | } |
| 333 | |
Alexander Couzens | 98ee6f6 | 2021-02-03 16:17:08 +0100 | [diff] [blame] | 334 | /********************************************************************************** |
| 335 | * IP Sub-Network Service (SNS) |
| 336 | **********************************************************************************/ |
| 337 | |
| 338 | /* perform inbound SNS-SIZE procedure */ |
Harald Welte | 22deecc | 2021-03-23 13:13:52 +0100 | [diff] [blame] | 339 | function f_incoming_sns_size(template (omit) NsCause cause := omit, integer idx := 0, |
| 340 | template integer num_max_nsvcs := ?, template integer num_ep := ?) |
Alexander Couzens | 98ee6f6 | 2021-02-03 16:17:08 +0100 | [diff] [blame] | 341 | runs on RAW_NS_CT { |
| 342 | log("f_incoming_sns_size(idx=", idx, ")"); |
| 343 | var PDU_NS rx; |
| 344 | var NSVCConfiguration nsvc_cfg := g_nsconfig.nsvc[idx]; |
| 345 | |
| 346 | if (nsvc_cfg.provider.ip.address_family == AF_INET) { |
| 347 | /* expect one single SNS-SIZE with RESET flag; 4x v4 EP; no v6 EP */ |
Harald Welte | 22deecc | 2021-03-23 13:13:52 +0100 | [diff] [blame] | 348 | rx := f_ns_exp(tr_SNS_SIZE(g_nsconfig.nsei, rst_flag := true, max_nsvcs := num_max_nsvcs, |
| 349 | num_v4 := num_ep, num_v6 := omit), idx); |
Alexander Couzens | 98ee6f6 | 2021-02-03 16:17:08 +0100 | [diff] [blame] | 350 | } else { |
| 351 | /* expect one single SNS-SIZE with RESET flag; no v4 EP; 4x v6 EP */ |
Harald Welte | 22deecc | 2021-03-23 13:13:52 +0100 | [diff] [blame] | 352 | rx := f_ns_exp(tr_SNS_SIZE(g_nsconfig.nsei, rst_flag := true, max_nsvcs := num_max_nsvcs, |
| 353 | num_v4 := omit, num_v6 := num_ep), idx); |
Alexander Couzens | 98ee6f6 | 2021-02-03 16:17:08 +0100 | [diff] [blame] | 354 | } |
| 355 | NSCP[idx].send(ts_SNS_SIZE_ACK(g_nsconfig.nsei, cause)); |
| 356 | } |
| 357 | |
| 358 | /* perform outbound SNS-SIZE procedure */ |
Harald Welte | 424ec52 | 2021-03-23 18:20:12 +0100 | [diff] [blame] | 359 | function f_outgoing_sns_size(template (omit) NsCause cause := omit, integer max_nsvcs := 1, |
| 360 | integer num_ip := 1, integer idx:= 0) |
Alexander Couzens | 98ee6f6 | 2021-02-03 16:17:08 +0100 | [diff] [blame] | 361 | runs on RAW_NS_CT { |
| 362 | log("f_outgoing_sns_size(idx=", idx, ")"); |
| 363 | var PDU_NS rx; |
| 364 | var NSVCConfiguration nsvc_cfg := g_nsconfig.nsvc[idx]; |
| 365 | |
| 366 | if (nsvc_cfg.provider.ip.address_family == AF_INET) { |
Harald Welte | 424ec52 | 2021-03-23 18:20:12 +0100 | [diff] [blame] | 367 | NSCP[idx].send(ts_SNS_SIZE(g_nsconfig.nsei, rst_flag := true, max_nsvcs := max_nsvcs, |
| 368 | num_v4 := num_ip, num_v6 := omit) |
Alexander Couzens | 98ee6f6 | 2021-02-03 16:17:08 +0100 | [diff] [blame] | 369 | ); |
| 370 | } else { |
Harald Welte | 424ec52 | 2021-03-23 18:20:12 +0100 | [diff] [blame] | 371 | NSCP[idx].send(ts_SNS_SIZE(g_nsconfig.nsei, rst_flag := true, max_nsvcs := max_nsvcs, |
| 372 | num_v4 := omit, num_v6 := num_ip) |
Alexander Couzens | 98ee6f6 | 2021-02-03 16:17:08 +0100 | [diff] [blame] | 373 | ); |
| 374 | } |
Harald Welte | 424ec52 | 2021-03-23 18:20:12 +0100 | [diff] [blame] | 375 | /* expect one single SNS-SIZE */ |
Alexander Couzens | 98ee6f6 | 2021-02-03 16:17:08 +0100 | [diff] [blame] | 376 | rx := f_ns_exp(tr_SNS_SIZE_ACK(g_nsconfig.nsei, cause), idx); |
| 377 | } |
| 378 | |
| 379 | /* perform inbound SNS-CONFIG procedure */ |
| 380 | function f_incoming_sns_config(template (omit) NsCause cause := omit, integer idx := 0) |
| 381 | runs on RAW_NS_CT { |
| 382 | log("f_incoming_sns_config(idx=", idx, ")"); |
| 383 | var PDU_NS rx; |
| 384 | var NSVCConfiguration nsvc_cfg := g_nsconfig.nsvc[idx]; |
| 385 | |
| 386 | if (nsvc_cfg.provider.ip.address_family == AF_INET) { |
| 387 | var template IP4_Elements v4_elem := { tr_SNS_IPv4(nsvc_cfg.provider.ip.remote_ip, |
| 388 | nsvc_cfg.provider.ip.remote_udp_port) }; |
| 389 | rx := f_ns_exp(tr_SNS_CONFIG(g_nsconfig.nsei, end_flag := true, v4 := v4_elem), idx); |
| 390 | } else { |
| 391 | var template IP6_Elements v6_elem := { tr_SNS_IPv6(nsvc_cfg.provider.ip.remote_ip, |
| 392 | nsvc_cfg.provider.ip.remote_udp_port) }; |
| 393 | rx := f_ns_exp(tr_SNS_CONFIG(g_nsconfig.nsei, end_flag := true, v6 := v6_elem), idx); |
| 394 | } |
| 395 | NSCP[idx].send(ts_SNS_CONFIG_ACK(g_nsconfig.nsei, cause)); |
| 396 | } |
| 397 | |
| 398 | /* perform outbound SNS-CONFIG procedure */ |
| 399 | function f_outgoing_sns_config(template (omit) NsCause cause := omit, integer idx := 0) |
| 400 | runs on RAW_NS_CT { |
| 401 | log("f_outgoing_sns_config(idx=", idx, ")"); |
| 402 | var PDU_NS rx; |
| 403 | var NSVCConfiguration nsvc_cfg := g_nsconfig.nsvc[idx]; |
| 404 | |
| 405 | if (nsvc_cfg.provider.ip.address_family == AF_INET) { |
| 406 | var template (omit) IP4_Elements v4 := { ts_SNS_IPv4(nsvc_cfg.provider.ip.local_ip, |
| 407 | nsvc_cfg.provider.ip.local_udp_port) } |
| 408 | NSCP[idx].send(ts_SNS_CONFIG(g_nsconfig.nsei, true, v4)); |
| 409 | } else { |
| 410 | var template (omit) IP6_Elements v6 := { ts_SNS_IPv6(nsvc_cfg.provider.ip.local_ip, |
| 411 | nsvc_cfg.provider.ip.local_udp_port) } |
| 412 | NSCP[idx].send(ts_SNS_CONFIG(g_nsconfig.nsei, true, omit, v6)); |
| 413 | } |
| 414 | rx := f_ns_exp(tr_SNS_CONFIG_ACK(g_nsconfig.nsei, cause), idx); |
| 415 | } |
| 416 | |
| 417 | /* perform outbound SNS-CONFIG procedure (separate endpoints: 1 for control, 1 for user */ |
| 418 | function f_outgoing_sns_config_1c1u(template (omit) NsCause cause := omit, integer idx := 0) |
| 419 | runs on RAW_NS_CT { |
| 420 | log("f_outgoing_sns_config_1c1u(idx=", idx, ")"); |
| 421 | var PDU_NS rx; |
| 422 | |
| 423 | if (g_nsconfig.nsvc[0].provider.ip.address_family == AF_INET) { |
| 424 | var template (omit) IP4_Elements v4 := { ts_SNS_IPv4(g_nsconfig.nsvc[0].provider.ip.local_ip, |
| 425 | g_nsconfig.nsvc[0].provider.ip.local_udp_port, 1, 0), |
| 426 | ts_SNS_IPv4(g_nsconfig.nsvc[1].provider.ip.local_ip, |
| 427 | g_nsconfig.nsvc[1].provider.ip.local_udp_port, 0, 1) }; |
| 428 | NSCP[idx].send(ts_SNS_CONFIG(g_nsconfig.nsei, true, v4)); |
| 429 | } else { |
| 430 | var template (omit) IP6_Elements v6 := { ts_SNS_IPv6(g_nsconfig.nsvc[0].provider.ip.local_ip, |
| 431 | g_nsconfig.nsvc[0].provider.ip.local_udp_port, 1, 0), |
| 432 | ts_SNS_IPv6(g_nsconfig.nsvc[1].provider.ip.local_ip, |
| 433 | g_nsconfig.nsvc[1].provider.ip.local_udp_port, 0, 1) }; |
| 434 | NSCP[idx].send(ts_SNS_CONFIG(g_nsconfig.nsei, true, omit, v6)); |
| 435 | } |
| 436 | rx := f_ns_exp(tr_SNS_CONFIG_ACK(g_nsconfig.nsei, cause), idx); |
| 437 | } |
| 438 | |
| 439 | /* perform outbound SNS-CONFIG procedure (separate endpoints: 1 for control, 1 for user */ |
| 440 | function f_outgoing_sns_config_1c1u_separate(template (omit) NsCause cause := omit, integer idx := 0) |
| 441 | runs on RAW_NS_CT { |
| 442 | log("f_outgoing_sns_config_1c1u_separate(idx=", idx, ")"); |
| 443 | var PDU_NS rx; |
| 444 | if (g_nsconfig.nsvc[0].provider.ip.address_family == AF_INET) { |
| 445 | var template (omit) IP4_Elements v4 := { ts_SNS_IPv4(g_nsconfig.nsvc[1].provider.ip.local_ip, |
| 446 | g_nsconfig.nsvc[1].provider.ip.local_udp_port, 1, 0), |
| 447 | ts_SNS_IPv4(g_nsconfig.nsvc[2].provider.ip.local_ip, |
| 448 | g_nsconfig.nsvc[2].provider.ip.local_udp_port, 0, 1) }; |
| 449 | NSCP[idx].send(ts_SNS_CONFIG(g_nsconfig.nsei, true, v4)); |
| 450 | } else { |
| 451 | var template (omit) IP6_Elements v6 := { ts_SNS_IPv6(g_nsconfig.nsvc[1].provider.ip.local_ip, |
| 452 | g_nsconfig.nsvc[1].provider.ip.local_udp_port, 1, 0), |
| 453 | ts_SNS_IPv6(g_nsconfig.nsvc[2].provider.ip.local_ip, |
| 454 | g_nsconfig.nsvc[2].provider.ip.local_udp_port, 0, 1) }; |
| 455 | NSCP[idx].send(ts_SNS_CONFIG(g_nsconfig.nsei, true, omit, v6)); |
| 456 | } |
| 457 | rx := f_ns_exp(tr_SNS_CONFIG_ACK(g_nsconfig.nsei, cause), idx); |
| 458 | } |
| 459 | |
Alexander Couzens | d5ac510 | 2021-02-27 20:53:37 +0100 | [diff] [blame] | 460 | /* perform inbound SNS-CHANGE-WEIGHT procedure */ |
Alexander Couzens | 2d10ee6 | 2021-06-06 23:14:03 +0200 | [diff] [blame] | 461 | function f_incoming_sns_chg_weight(integer idx_chg := 0, template (omit) NsCause cause := omit, integer idx := 0) |
Alexander Couzens | d5ac510 | 2021-02-27 20:53:37 +0100 | [diff] [blame] | 462 | runs on RAW_NS_CT { |
| 463 | log("f_incoming_sns_chg_weight(idx=", idx, ")"); |
| 464 | var PDU_NS rx; |
Alexander Couzens | 2d10ee6 | 2021-06-06 23:14:03 +0200 | [diff] [blame] | 465 | var NSVCConfiguration nsvc_cfg := g_nsconfig.nsvc[idx_chg]; |
Alexander Couzens | d5ac510 | 2021-02-27 20:53:37 +0100 | [diff] [blame] | 466 | |
| 467 | if (nsvc_cfg.provider.ip.address_family == AF_INET) { |
| 468 | var template IP4_Elements v4_elem := { tr_SNS_IPv4(nsvc_cfg.provider.ip.remote_ip, |
| 469 | nsvc_cfg.provider.ip.remote_udp_port) }; |
| 470 | rx := f_ns_exp(tr_SNS_CHG_WEIGHT(g_nsconfig.nsei, ?, v4 := v4_elem), idx); |
| 471 | } else { |
| 472 | var template IP6_Elements v6_elem := { tr_SNS_IPv6(nsvc_cfg.provider.ip.remote_ip, |
| 473 | nsvc_cfg.provider.ip.remote_udp_port) }; |
| 474 | rx := f_ns_exp(tr_SNS_CHG_WEIGHT(g_nsconfig.nsei, ?, v4 := omit, v6 := v6_elem), idx); |
| 475 | } |
| 476 | NSCP[idx].send(ts_SNS_ACK(g_nsconfig.nsei, rx.pDU_SNS_ChangeWeight.transactionID)); |
| 477 | } |
| 478 | |
| 479 | |
Alexander Couzens | c56a3b2 | 2021-04-19 02:57:26 +0200 | [diff] [blame] | 480 | /* perform inbound SNS-ADD procedure */ |
| 481 | function f_incoming_sns_add(integer idx_add, uint8_t w_sig := 1, uint8_t w_user := 1, integer idx := 0, template (omit) NsCause cause := omit) |
| 482 | runs on RAW_NS_CT { |
| 483 | log("f_incoming_sns_add(idx=", idx, ")"); |
| 484 | var PDU_NS rx; |
| 485 | var NSVCConfiguration nsvc_cfg := g_nsconfig.nsvc[idx_add]; |
| 486 | |
| 487 | if (nsvc_cfg.provider.ip.address_family == AF_INET) { |
| 488 | var template (omit) IP4_Elements v4_elem := { ts_SNS_IPv4(nsvc_cfg.provider.ip.remote_ip, |
| 489 | nsvc_cfg.provider.ip.remote_udp_port, |
| 490 | w_sig, w_user) }; |
| 491 | rx := f_ns_exp(tr_SNS_ADD(g_nsconfig.nsei, ?, v4 := v4_elem), idx); |
| 492 | } else { |
| 493 | var template (omit) IP6_Elements v6_elem := { ts_SNS_IPv6(nsvc_cfg.provider.ip.remote_ip, |
| 494 | nsvc_cfg.provider.ip.remote_udp_port, |
| 495 | w_sig, w_user) }; |
| 496 | rx := f_ns_exp(tr_SNS_ADD(g_nsconfig.nsei, ?, omit, v6_elem), idx); |
| 497 | } |
| 498 | NSCP[idx].send(ts_SNS_ACK(g_nsconfig.nsei, rx.pDU_SNS_Add.transactionID)); |
| 499 | } |
| 500 | |
Alexander Couzens | 98ee6f6 | 2021-02-03 16:17:08 +0100 | [diff] [blame] | 501 | function f_outgoing_sns_add(integer idx_add, uint8_t w_sig := 1, uint8_t w_user := 1, integer idx := 0, template (omit) NsCause cause := omit) |
| 502 | runs on RAW_NS_CT { |
| 503 | log("f_outgoing_sns_add(idx_add=", idx_add, ")"); |
| 504 | var PDU_NS rx; |
| 505 | var NSVCConfiguration nsvc_cfg := g_nsconfig.nsvc[idx_add]; |
| 506 | if (nsvc_cfg.provider.ip.address_family == AF_INET) { |
| 507 | var template (omit) IP4_Elements v4 := { ts_SNS_IPv4(nsvc_cfg.provider.ip.local_ip, |
| 508 | nsvc_cfg.provider.ip.local_udp_port, |
| 509 | w_sig, w_user) }; |
| 510 | NSCP[idx].send(ts_SNS_ADD(g_nsconfig.nsei, 23, v4)); |
| 511 | rx := f_ns_exp(tr_SNS_ACK(g_nsconfig.nsei, 23, cause, v4)); |
| 512 | } else { |
| 513 | var template (omit) IP6_Elements v6 := { ts_SNS_IPv6(nsvc_cfg.provider.ip.local_ip, |
| 514 | nsvc_cfg.provider.ip.local_udp_port, |
| 515 | w_sig, w_user) }; |
| 516 | NSCP[idx].send(ts_SNS_ADD(g_nsconfig.nsei, 23, omit, v6)); |
| 517 | rx := f_ns_exp(tr_SNS_ACK(g_nsconfig.nsei, 23, cause, omit, v6)); |
| 518 | } |
| 519 | } |
| 520 | |
Alexander Couzens | 54ebb4a | 2021-04-19 03:14:44 +0200 | [diff] [blame] | 521 | /* perform inbound SNS-DELETE procedure */ |
| 522 | function f_incoming_sns_del(integer idx_del, uint8_t w_sig := 1, uint8_t w_user := 1, integer idx := 0, template (omit) NsCause cause := omit) |
| 523 | runs on RAW_NS_CT { |
| 524 | log("f_incoming_sns_del(idx=", idx, ")"); |
| 525 | var PDU_NS rx; |
| 526 | var NSVCConfiguration nsvc_cfg := g_nsconfig.nsvc[idx_del]; |
| 527 | |
| 528 | if (nsvc_cfg.provider.ip.address_family == AF_INET) { |
| 529 | var template (omit) IP4_Elements v4_elem := { ts_SNS_IPv4(nsvc_cfg.provider.ip.remote_ip, |
| 530 | nsvc_cfg.provider.ip.remote_udp_port, |
| 531 | w_sig, w_user) }; |
| 532 | rx := f_ns_exp(tr_SNS_DEL(g_nsconfig.nsei, ?, omit, v4 := v4_elem), idx); |
| 533 | } else { |
| 534 | var template (omit) IP6_Elements v6_elem := { ts_SNS_IPv6(nsvc_cfg.provider.ip.remote_ip, |
| 535 | nsvc_cfg.provider.ip.remote_udp_port, |
| 536 | w_sig, w_user) }; |
| 537 | rx := f_ns_exp(tr_SNS_DEL(g_nsconfig.nsei, ?, omit, omit, v6_elem), idx); |
| 538 | } |
| 539 | NSCP[idx].send(ts_SNS_ACK(g_nsconfig.nsei, rx.pDU_SNS_Delete.transactionID)); |
| 540 | } |
| 541 | |
| 542 | |
Alexander Couzens | 98ee6f6 | 2021-02-03 16:17:08 +0100 | [diff] [blame] | 543 | function f_outgoing_sns_del(integer idx_del, uint8_t w_sig := 1, uint8_t w_user := 1, integer idx := 0) |
| 544 | runs on RAW_NS_CT { |
| 545 | log("f_outgoing_sns_del(idx_del=", idx_del, ")"); |
| 546 | var PDU_NS rx; |
| 547 | var NSVCConfiguration nsvc_cfg := g_nsconfig.nsvc[idx_del]; |
| 548 | if (nsvc_cfg.provider.ip.address_family == AF_INET) { |
| 549 | var template (omit) IP4_Elements v4 := { ts_SNS_IPv4(nsvc_cfg.provider.ip.local_ip, |
| 550 | nsvc_cfg.provider.ip.local_udp_port, |
| 551 | w_sig, w_user) }; |
| 552 | NSCP[idx].send(ts_SNS_DEL(g_nsconfig.nsei, 24, omit, v4)); |
| 553 | rx := f_ns_exp(tr_SNS_ACK(g_nsconfig.nsei, 24, omit, v4)); |
| 554 | } else { |
| 555 | var template (omit) IP6_Elements v6 := { ts_SNS_IPv6(nsvc_cfg.provider.ip.local_ip, |
| 556 | nsvc_cfg.provider.ip.local_udp_port, |
| 557 | w_sig, w_user) }; |
| 558 | NSCP[idx].send(ts_SNS_DEL(g_nsconfig.nsei, 24, omit, omit, v6)); |
| 559 | rx := f_ns_exp(tr_SNS_ACK(g_nsconfig.nsei, 24, omit, omit, v6)); |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | function f_outgoing_sns_chg_weight(integer idx_chg, uint8_t w_sig, uint8_t w_user, integer idx := 0) |
| 564 | runs on RAW_NS_CT { |
| 565 | log("f_outgoing_sns_chg_weight(idx_chg=", idx_chg, ")"); |
| 566 | var PDU_NS rx; |
| 567 | var NSVCConfiguration nsvc_cfg := g_nsconfig.nsvc[idx_chg]; |
| 568 | if (nsvc_cfg.provider.ip.address_family == AF_INET) { |
| 569 | var template (omit) IP4_Elements v4 := { ts_SNS_IPv4(nsvc_cfg.provider.ip.local_ip, |
| 570 | nsvc_cfg.provider.ip.local_udp_port, |
| 571 | w_sig, w_user) }; |
| 572 | NSCP[idx].send(ts_SNS_CHG_WEIGHT(g_nsconfig.nsei, 25, v4)); |
| 573 | rx := f_ns_exp(tr_SNS_ACK(g_nsconfig.nsei, 25, omit, v4)); |
| 574 | } else { |
| 575 | var template (omit) IP6_Elements v6 := { ts_SNS_IPv6(nsvc_cfg.provider.ip.local_ip, |
| 576 | nsvc_cfg.provider.ip.local_udp_port, |
| 577 | w_sig, w_user) }; |
| 578 | NSCP[idx].send(ts_SNS_CHG_WEIGHT(g_nsconfig.nsei, 25, omit, v6)); |
| 579 | rx := f_ns_exp(tr_SNS_ACK(g_nsconfig.nsei, 25, omit, omit, v6)); |
| 580 | } |
| 581 | } |
| 582 | |
Alexander Couzens | c316572 | 2021-01-11 02:51:45 +0100 | [diff] [blame] | 583 | } |