Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 1 | /* GPRS-NS Emulation in TTCN-3 |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 2 | * (C) 2018-2020 Harald Welte <laforge@gnumonks.org> |
Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 3 | * contributions by sysmocom - s.f.m.c. GmbH |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * Released under the terms of GNU General Public License, Version 2 or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 10 | */ |
| 11 | |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 12 | module NS_Emulation { |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 13 | import from Misc_Helpers all; |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 14 | import from NS_Types all; |
| 15 | import from BSSGP_Types all; |
Harald Welte | 867243a | 2020-09-13 18:32:32 +0200 | [diff] [blame] | 16 | import from Osmocom_Types all; |
Harald Welte | e0abc47 | 2018-02-05 09:13:31 +0100 | [diff] [blame] | 17 | import from Osmocom_Gb_Types all; |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 18 | import from NS_Provider_IPL4 all; |
Harald Welte | 867243a | 2020-09-13 18:32:32 +0200 | [diff] [blame] | 19 | #ifdef NS_EMULATION_FR |
| 20 | import from NS_Provider_FR all; |
| 21 | #endif |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 22 | import from IPL4asp_Types all; |
| 23 | |
| 24 | type record NsUnitdataRequest { |
| 25 | BssgpBvci bvci, |
| 26 | Nsei nsei, |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 27 | integer lsp, |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 28 | octetstring sdu optional, |
Harald Welte | e0abc47 | 2018-02-05 09:13:31 +0100 | [diff] [blame] | 29 | PDU_BSSGP bssgp optional |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 30 | } |
| 31 | |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 32 | template NsUnitdataRequest tr_NsUdReq(template Nsei nsei, template BssgpBvci bvci, template integer lsp, |
| 33 | template octetstring sdu, template PDU_BSSGP bssgp) := { |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 34 | bvci := bvci, |
| 35 | nsei := nsei, |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 36 | lsp := lsp, |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 37 | sdu := sdu, |
| 38 | bssgp := bssgp |
| 39 | } |
| 40 | |
| 41 | template (value) NsUnitdataRequest ts_NsUdReq(template (value) Nsei nsei, |
| 42 | template (value) BssgpBvci bvci, |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 43 | template (value) integer lsp, |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 44 | template (omit) octetstring sdu, |
| 45 | template (omit) PDU_BSSGP bssgp) := { |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 46 | bvci := bvci, |
| 47 | nsei := nsei, |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 48 | lsp := lsp, |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 49 | sdu := sdu, |
| 50 | bssgp := bssgp |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | type record NsUnitdataIndication { |
| 54 | BssgpBvci bvci, |
| 55 | Nsei nsei, |
Harald Welte | 80a249a | 2020-11-17 19:57:40 +0100 | [diff] [blame] | 56 | Nsvci nsvci, |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 57 | octetstring sdu optional, |
Harald Welte | e0abc47 | 2018-02-05 09:13:31 +0100 | [diff] [blame] | 58 | PDU_BSSGP bssgp optional |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 59 | } |
| 60 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 61 | template (present) NsUnitdataIndication tr_NsUdInd(template (present) Nsei nsei, |
| 62 | template (present) BssgpBvci bvci, |
| 63 | template octetstring sdu) := { |
| 64 | bvci := bvci, |
| 65 | nsei := nsei, |
Harald Welte | 80a249a | 2020-11-17 19:57:40 +0100 | [diff] [blame] | 66 | nsvci := ?, |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 67 | sdu := sdu, |
| 68 | bssgp := ? |
| 69 | } |
| 70 | |
Harald Welte | 80a249a | 2020-11-17 19:57:40 +0100 | [diff] [blame] | 71 | template (value) NsUnitdataIndication ts_NsUdInd(Nsei nsei, Nsvci nsvci, BssgpBvci bvci, octetstring sdu) := { |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 72 | bvci := bvci, |
| 73 | nsei := nsei, |
Harald Welte | 80a249a | 2020-11-17 19:57:40 +0100 | [diff] [blame] | 74 | nsvci := nsvci, |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 75 | sdu := sdu, |
Harald Welte | e0abc47 | 2018-02-05 09:13:31 +0100 | [diff] [blame] | 76 | bssgp := dec_PDU_BSSGP(sdu) |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | type record NsStatusIndication { |
| 80 | Nsei nsei, |
| 81 | Nsvci nsvci, |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 82 | NsvcState old_state, |
Harald Welte | dc0a090 | 2020-11-10 21:03:29 +0100 | [diff] [blame] | 83 | NsvcState new_state, |
| 84 | boolean first_or_last |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 85 | } |
| 86 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 87 | template (present) NsStatusIndication tr_NsStsInd(template (present) Nsei nsei := ?, |
| 88 | template (present) Nsvci nsvci := ?, |
| 89 | template (present) NsvcState old_state := ?, |
Harald Welte | dc0a090 | 2020-11-10 21:03:29 +0100 | [diff] [blame] | 90 | template (present) NsvcState state := ?, |
| 91 | template (present) boolean first_or_last := ?) := { |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 92 | nsei := nsei, |
| 93 | nsvci := nsvci, |
| 94 | old_state := old_state, |
Harald Welte | dc0a090 | 2020-11-10 21:03:29 +0100 | [diff] [blame] | 95 | new_state := state, |
| 96 | first_or_last := first_or_last |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 97 | } |
| 98 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 99 | |
Harald Welte | dc0a090 | 2020-11-10 21:03:29 +0100 | [diff] [blame] | 100 | template (value) NsStatusIndication ts_NsStsInd(Nsei nsei, Nsvci nsvci, NsvcState old_state, NsvcState state, |
| 101 | boolean first_or_last := false) := { |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 102 | nsei := nsei, |
| 103 | nsvci := nsvci, |
| 104 | old_state := old_state, |
Harald Welte | dc0a090 | 2020-11-10 21:03:29 +0100 | [diff] [blame] | 105 | new_state := state, |
| 106 | first_or_last := first_or_last |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | type enumerated NsvcState { |
| 110 | NSVC_S_DEAD_BLOCKED, |
| 111 | NSVC_S_WAIT_RESET, |
| 112 | NSVC_S_ALIVE_BLOCKED, |
| 113 | NSVC_S_ALIVE_UNBLOCKED |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 114 | } |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 115 | |
| 116 | /* port from our (internal) point of view */ |
| 117 | type port NS_SP_PT message { |
| 118 | in NsUnitdataRequest; |
| 119 | out NsUnitdataIndication, |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 120 | NsStatusIndication; |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 121 | } with { extension "internal" }; |
| 122 | |
| 123 | /* port from the user point of view */ |
| 124 | type port NS_PT message { |
| 125 | in ASP_Event, |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 126 | NsStatusIndication, |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 127 | NsUnitdataIndication; |
| 128 | out NsUnitdataRequest; |
| 129 | } with { extension "internal" }; |
| 130 | |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 131 | type component NS_Provider_CT { |
| 132 | /* upper port, facing to NS_Emulation:NSCP */ |
| 133 | port NS_PROVIDER_PT NSE; |
| 134 | /* lower layer ports (UDP/IP, Frame Relay) are added in derived components */ |
| 135 | }; |
| 136 | |
Harald Welte | bd612cd | 2020-09-14 09:42:28 +0200 | [diff] [blame] | 137 | type enumerated NS_Provider_LinkStatus { |
| 138 | NS_PROV_LINK_STATUS_UP, |
| 139 | NS_PROV_LINK_STATUS_DOWN |
| 140 | }; |
| 141 | type union NS_Provider_Evt { |
| 142 | NS_Provider_LinkStatus link_status |
| 143 | }; |
| 144 | |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 145 | /* port between NS_Provider and NS_CT */ |
| 146 | type port NS_PROVIDER_PT message { |
Harald Welte | bd612cd | 2020-09-14 09:42:28 +0200 | [diff] [blame] | 147 | inout PDU_NS, NS_Provider_Evt; |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 148 | } with { extension "internal" }; |
| 149 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 150 | type record NSVCConfigurationIP { |
| 151 | AddressFamily address_family, |
| 152 | PortNumber local_udp_port, |
| 153 | charstring local_ip, |
| 154 | PortNumber remote_udp_port, |
| 155 | charstring remote_ip |
| 156 | }; |
| 157 | type record NSVCConfigurationFR { |
| 158 | charstring netdev, /* HDLC net-device for AF_PACKET socket */ |
| 159 | integer dlci |
| 160 | }; |
| 161 | type union NSVCConfigurationP { |
| 162 | NSVCConfigurationIP ip, |
| 163 | NSVCConfigurationFR fr |
| 164 | }; |
| 165 | type record NSVCConfiguration { |
| 166 | NSVCConfigurationP provider, |
| 167 | Nsvci nsvci |
| 168 | }; |
| 169 | type record of NSVCConfiguration NSVCConfigurations; |
| 170 | type record NSConfiguration { |
| 171 | Nsvci nsei, |
| 172 | boolean role_sgsn, |
| 173 | boolean handle_sns, |
| 174 | NSVCConfigurations nsvc |
| 175 | } |
| 176 | |
| 177 | /*********************************************************************** |
| 178 | * per NS-VCG component. Exists once per [peer of] NSE |
| 179 | ***********************************************************************/ |
| 180 | |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 181 | type component NS_CT { |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 182 | /* NS-User SAP towards the user */ |
| 183 | port NS_SP_PT NS_SP; |
| 184 | |
| 185 | /* port towards the per-NSVC components */ |
Harald Welte | 1308dbb | 2021-01-18 18:19:38 +0100 | [diff] [blame] | 186 | port NSint_PT NSVC; |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 187 | |
| 188 | /* all of the NS configuration a user passes to us */ |
| 189 | var NSConfiguration g_config; |
| 190 | var charstring g_id; |
| 191 | |
| 192 | /* references to the per-NSVC components */ |
| 193 | var NsvcTable g_nsvcs := {}; |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 194 | /* list of indexes to g_nsvcs[] of currently unblocked NSVCs */ |
| 195 | var ro_integer g_unblocked_nsvcs := {}; |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 196 | }; |
| 197 | type record NsvcTableEntry { |
| 198 | Nsvci nsvci, |
| 199 | NSVC_CT vc_conn, |
| 200 | NsvcState state |
| 201 | }; |
| 202 | type record of NsvcTableEntry NsvcTable; |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 203 | type record of integer ro_integer; |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 204 | |
Harald Welte | 1308dbb | 2021-01-18 18:19:38 +0100 | [diff] [blame] | 205 | /* internal port from the NS-VC point of view */ |
| 206 | type port NSint_SP_PT message { |
| 207 | in NsUnitdataRequest, |
| 208 | SnsRequest, |
| 209 | NsCtrlRequest; |
| 210 | out NsUnitdataIndication, |
| 211 | SnsIndication, |
| 212 | NsStatusIndication; |
| 213 | } with { extension "internal" }; |
| 214 | |
| 215 | /* internal port from the NS-VCG point of view */ |
| 216 | type port NSint_PT message { |
| 217 | in ASP_Event, |
| 218 | NsStatusIndication, |
| 219 | SnsIndication, |
| 220 | NsUnitdataIndication; |
| 221 | out NsUnitdataRequest, |
| 222 | SnsRequest, |
| 223 | NsCtrlRequest; |
| 224 | } with { extension "internal" }; |
| 225 | |
| 226 | /* Used by NS-VC to report reception of a SNS PDU to NS-VCG */ |
| 227 | type record SnsIndication { |
| 228 | Nsvci nsvci, |
| 229 | PDU_NS ns |
| 230 | }; |
| 231 | |
| 232 | /* Used by NS-VCG to request transmission of a SNS PDU via a NS-VC */ |
| 233 | type record SnsRequest { |
| 234 | Nsvci nsvci, |
| 235 | PDU_NS ns |
| 236 | }; |
| 237 | |
| 238 | type enumerated NsCtrlRequest { |
| 239 | StartAliveProcedure (0) |
| 240 | }; |
| 241 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 242 | /* add one NSVC (component and table entry */ |
| 243 | function f_nsvc_add(NSVCConfiguration nsvc_cfg) runs on NS_CT { |
| 244 | var charstring nsvc_id := g_id & "-NSVCI" & int2str(nsvc_cfg.nsvci); |
| 245 | var NsvcTableEntry te; |
| 246 | |
| 247 | te.nsvci := nsvc_cfg.nsvci; |
| 248 | te.vc_conn := NSVC_CT.create(nsvc_id); |
| 249 | te.state := NSVC_S_DEAD_BLOCKED; |
| 250 | |
| 251 | connect(self:NSVC, te.vc_conn:NS_SP); |
| 252 | te.vc_conn.start(NSVCStart(nsvc_cfg, g_config, nsvc_id)); |
| 253 | |
| 254 | g_nsvcs := g_nsvcs & { te }; |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 255 | /* no need to add to g_unblocked_nsvcs, as state is always DEAD_BLOCKED above */ |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | function f_nsvc_find_idx(Nsvci nsvci) runs on NS_CT return integer { |
| 259 | var integer i; |
| 260 | for (i := 0; i < lengthof(g_nsvcs); i := i+1) { |
| 261 | if (g_nsvcs[i].nsvci == nsvci) { |
| 262 | return i; |
| 263 | } |
| 264 | } |
| 265 | return -1; |
| 266 | } |
| 267 | |
| 268 | function f_nsvc_find(Nsvci nsvci) runs on NS_CT return NSVC_CT { |
| 269 | var integer i := f_nsvc_find_idx(nsvci); |
| 270 | if (i < 0) { |
| 271 | return null; |
| 272 | } else { |
| 273 | return g_nsvcs[i].vc_conn; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | function f_nsvc_update_state(Nsvci nsvci, NsvcState state) runs on NS_CT { |
| 278 | var integer i := f_nsvc_find_idx(nsvci); |
| 279 | if (i < 0) { |
| 280 | return; |
| 281 | } |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 282 | if (g_nsvcs[i].state != NSVC_S_ALIVE_UNBLOCKED and state == NSVC_S_ALIVE_UNBLOCKED) { |
| 283 | /* add index to list of unblocked NSVCs */ |
| 284 | g_unblocked_nsvcs := g_unblocked_nsvcs & {i}; |
| 285 | } else if (g_nsvcs[i].state == NSVC_S_ALIVE_UNBLOCKED and state != NSVC_S_ALIVE_UNBLOCKED) { |
| 286 | /* remove index to list of unblocked NSVCs */ |
| 287 | var ro_integer new_unblocked_nsvcs := {}; |
| 288 | for (var integer j := 0; j < lengthof(g_unblocked_nsvcs); j := j+1) { |
| 289 | if (g_unblocked_nsvcs[j] != i) { |
| 290 | new_unblocked_nsvcs := new_unblocked_nsvcs & {j}; |
| 291 | } |
| 292 | } |
| 293 | g_unblocked_nsvcs := new_unblocked_nsvcs; |
| 294 | } |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 295 | g_nsvcs[i].state := state; |
| 296 | } |
| 297 | |
| 298 | function NSStart(NSConfiguration init_config, charstring id := testcasename()) runs on NS_CT { |
| 299 | g_config := init_config; |
| 300 | g_id := id; |
| 301 | |
| 302 | /* iterate over list of NS-VCs and start per-NSVC components */ |
| 303 | for (var integer i := 0; i < lengthof(g_config.nsvc); i := i+1) { |
| 304 | var NSVCConfiguration nsvc_cfg := g_config.nsvc[i]; |
| 305 | f_nsvc_add(nsvc_cfg); |
| 306 | } |
| 307 | |
| 308 | while (true) { |
| 309 | alt { |
| 310 | [] as_ns_common() {} |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | |
Harald Welte | dc0a090 | 2020-11-10 21:03:29 +0100 | [diff] [blame] | 315 | function f_count_nsvcs_in_state(template NsvcState state := ?) runs on NS_CT return integer { |
| 316 | var integer i; |
| 317 | var integer res := 0; |
| 318 | for (i := 0; i < lengthof(g_nsvcs); i := i+1) { |
| 319 | if (match(g_nsvcs[i].state, state)) { |
| 320 | res := res + 1; |
| 321 | } |
| 322 | } |
| 323 | return res; |
| 324 | } |
| 325 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 326 | private altstep as_ns_common() runs on NS_CT { |
| 327 | var NsStatusIndication rx_nssi; |
| 328 | var NsUnitdataIndication rx_nsudi; |
| 329 | var NsUnitdataRequest rx_nsudr; |
| 330 | /* pass from NS-VCs up to user */ |
Harald Welte | dc0a090 | 2020-11-10 21:03:29 +0100 | [diff] [blame] | 331 | [] NSVC.receive(tr_NsStsInd(g_config.nsei, ?, ?, NSVC_S_ALIVE_UNBLOCKED)) -> value rx_nssi { |
| 332 | /* check if this one is the first to be unblocked */ |
| 333 | var integer num_nsvc_unblocked := f_count_nsvcs_in_state(NSVC_S_ALIVE_UNBLOCKED); |
| 334 | f_nsvc_update_state(rx_nssi.nsvci, rx_nssi.new_state); |
| 335 | if (num_nsvc_unblocked == 0) { |
| 336 | rx_nssi.first_or_last := true; |
| 337 | } |
| 338 | NS_SP.send(rx_nssi); |
| 339 | } |
| 340 | [] NSVC.receive(tr_NsStsInd(g_config.nsei, ?, ?, NSVC_S_DEAD_BLOCKED)) -> value rx_nssi { |
| 341 | f_nsvc_update_state(rx_nssi.nsvci, rx_nssi.new_state); |
| 342 | /* check if this one is the last to be blocked */ |
| 343 | var integer num_nsvc_unblocked := f_count_nsvcs_in_state(NSVC_S_ALIVE_UNBLOCKED); |
| 344 | if (num_nsvc_unblocked == 0) { |
| 345 | rx_nssi.first_or_last := true; |
| 346 | } |
| 347 | NS_SP.send(rx_nssi); |
| 348 | } |
| 349 | [] NSVC.receive(tr_NsStsInd(g_config.nsei, ?, ?, ?)) -> value rx_nssi { |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 350 | f_nsvc_update_state(rx_nssi.nsvci, rx_nssi.new_state); |
| 351 | NS_SP.send(rx_nssi); |
| 352 | } |
| 353 | [] NSVC.receive(tr_NsStsInd) -> value rx_nssi { |
| 354 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 355 | log2str("Received NsStatusInd for invalid NSEI: ", rx_nssi)); |
| 356 | } |
| 357 | [] NSVC.receive(tr_NsUdInd(g_config.nsei, ?, ?)) -> value rx_nsudi { |
| 358 | NS_SP.send(rx_nsudi); |
| 359 | } |
Harald Welte | 1308dbb | 2021-01-18 18:19:38 +0100 | [diff] [blame] | 360 | |
| 361 | [g_config.handle_sns and g_config.role_sgsn] as_vcg_sns_sgsn(); |
| 362 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 363 | [] NSVC.receive(tr_NsUdInd(?, ?, ?)) -> value rx_nsudi { |
| 364 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 365 | log2str("Received UnitDataInd for invalid NSEI: ", rx_nsudi)); |
| 366 | } |
| 367 | /* from user down to NS-VC */ |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 368 | [] NS_SP.receive(tr_NsUdReq(g_config.nsei, ?, ?, ?, *)) -> value rx_nsudr { |
| 369 | /* load distribution function */ |
| 370 | var integer nsvc_idx := g_unblocked_nsvcs[rx_nsudr.lsp mod lengthof(g_unblocked_nsvcs)]; |
| 371 | NSVC.send(rx_nsudr) to g_nsvcs[nsvc_idx].vc_conn; |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 372 | } |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 373 | [] NS_SP.receive(tr_NsUdReq(?, ?, ?, ?, *)) -> value rx_nsudr { |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 374 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 375 | log2str("Received NsUnitdataReq for invalid NSEI: ", rx_nsudr)); |
| 376 | } |
| 377 | } |
| 378 | |
Harald Welte | 1308dbb | 2021-01-18 18:19:38 +0100 | [diff] [blame] | 379 | /* generate a list of v4 + v6 endpoints based on the NSVConfigurations. This is not strictly |
| 380 | * accurate, as we should create a list of _endpoints_, while we actually create a list of |
| 381 | * NSVCs. Those are only identical as long as our peer only implements one endpoint */ |
| 382 | private function gen_sns_ip_elems(out template (omit) IP4_Elements v4_out, |
| 383 | out template (omit) IP6_Elements v6_out) runs on NS_CT { |
| 384 | var integer i; |
| 385 | var IP4_Elements v4 := {}; |
| 386 | var IP6_Elements v6 := {}; |
| 387 | |
| 388 | for (i := 0; i < lengthof(g_config.nsvc); i := i + 1) { |
| 389 | var NSVCConfiguration nsvc_cfg := g_config.nsvc[i]; |
| 390 | if (not ischosen(nsvc_cfg.provider.ip)) { |
| 391 | continue; |
| 392 | } |
| 393 | if (nsvc_cfg.provider.ip.address_family == AF_INET) { |
| 394 | v4 := v4 & { valueof(ts_SNS_IPv4(nsvc_cfg.provider.ip.local_ip, |
| 395 | nsvc_cfg.provider.ip.local_udp_port)) }; |
| 396 | } else if (nsvc_cfg.provider.ip.address_family == AF_INET6) { |
| 397 | v6 := v6 & { valueof(ts_SNS_IPv6(nsvc_cfg.provider.ip.local_ip, |
| 398 | nsvc_cfg.provider.ip.local_udp_port)) }; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | /* we must not return empty lists, but 'omit' as otherwise we get wrong SNS IEs */ |
| 403 | if (lengthof(v4) == 0) { |
| 404 | v4_out := omit; |
| 405 | } else { |
| 406 | v4_out := v4; |
| 407 | } |
| 408 | if (lengthof(v6) == 0) { |
| 409 | v6_out := omit; |
| 410 | } else { |
| 411 | v6_out := v6; |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | /* simple IP Sub-Network Service responder for the SGSN side. This is not a full implementation |
| 416 | * of the protocol, merely sufficient to make the PCU/BSS side happy to proceed */ |
| 417 | private altstep as_vcg_sns_sgsn() runs on NS_CT { |
| 418 | var SnsIndication sind; |
| 419 | var NSVC_CT vc; |
| 420 | [] NSVC.receive(SnsIndication:{?, tr_SNS_SIZE(g_config.nsei)}) -> value sind sender vc { |
| 421 | /* blindly acknowledge whatever the PCU sends */ |
| 422 | NSVC.send(SnsRequest:{sind.nsvci, ts_SNS_SIZE_ACK(g_config.nsei, omit)}) to vc; |
| 423 | } |
| 424 | /* FIXME: We assume our peer has only one endpoint */ |
| 425 | [] NSVC.receive(SnsIndication:{?, tr_SNS_CONFIG(g_config.nsei, true, |
| 426 | {tr_SNS_IPv4(g_config.nsvc[0].provider.ip.remote_ip, |
| 427 | g_config.nsvc[0].provider.ip.remote_udp_port)})}) |
| 428 | -> value sind sender vc { |
| 429 | /* blindly acknowledge whatever the PCU sends */ |
| 430 | NSVC.send(SnsRequest:{sind.nsvci, ts_SNS_CONFIG_ACK(g_config.nsei, omit)}) to vc; |
| 431 | /* send a SNS-CONFIG in response and expect a SNS-CONFIG-ACK */ |
| 432 | var template (omit) IP4_Elements v4; |
| 433 | var template (omit) IP6_Elements v6; |
| 434 | gen_sns_ip_elems(v4, v6); |
| 435 | NSVC.send(SnsRequest:{sind.nsvci, |
| 436 | ts_SNS_CONFIG(g_config.nsei, true, v4, v6)}) to vc; |
| 437 | alt { |
| 438 | [] NSVC.receive(SnsIndication:{sind.nsvci, |
| 439 | tr_SNS_CONFIG_ACK(g_config.nsei, omit)}) from vc { |
| 440 | /* success */ |
| 441 | log("SNS Config succeeded. Sending Alive"); |
| 442 | /* inform all NS-VC that they are now considered alive */ |
| 443 | for (var integer i := 0; i < lengthof(g_nsvcs); i := i+1) { |
| 444 | NSVC.send(NsCtrlRequest:StartAliveProcedure) to g_nsvcs[i].vc_conn; |
| 445 | } |
| 446 | } |
| 447 | [] NSVC.receive(SnsIndication:{sind.nsvci, |
| 448 | tr_SNS_CONFIG_ACK(g_config.nsei, ?)}) from vc { |
| 449 | setverdict(fail, "Unexpected SNS-CONFIG-NACK"); |
| 450 | self.stop; |
| 451 | } |
| 452 | } |
| 453 | } |
| 454 | [] NSVC.receive(SnsIndication:{?, tr_SNS_CONFIG(g_config.nsei, false, ?)}) { /* ignore */} |
| 455 | [] NSVC.receive(SnsIndication:{?, tr_SNS_CONFIG(g_config.nsei, true, ?)}) { |
| 456 | setverdict(fail, "Unexpected SNS-CONFIG content"); |
| 457 | self.stop; |
| 458 | } |
| 459 | [] NSVC.receive(SnsIndication:{?, tr_SNS_CONFIG(?, ?, ?)}) { |
| 460 | setverdict(fail, "SNS-CONFIG from unexpected NSEI"); |
| 461 | self.stop; |
| 462 | } |
| 463 | } |
| 464 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 465 | /*********************************************************************** |
| 466 | per-NSVC component. Exists once for each NS-VC in the NS-VCG |
| 467 | ***********************************************************************/ |
| 468 | |
| 469 | type component NSVC_CT { |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 470 | /* UDP port towards the bottom (IUT) */ |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 471 | port NS_PROVIDER_PT NSCP; |
| 472 | var NS_Provider_IPL4_CT vc_NSP_IP; |
Harald Welte | 867243a | 2020-09-13 18:32:32 +0200 | [diff] [blame] | 473 | #ifdef NS_EMULATION_FR |
| 474 | var NS_Provider_FR_CT vc_NSP_FR; |
| 475 | #endif |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 476 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 477 | /* port towards the NS_CT */ |
Harald Welte | 1308dbb | 2021-01-18 18:19:38 +0100 | [diff] [blame] | 478 | port NSint_SP_PT NS_SP; |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 479 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 480 | /* configuration passed by the user */ |
| 481 | var NSVCConfiguration g_nsvc_config; |
| 482 | /* we cannot access the NS_CT.config and hence need to copy those */ |
| 483 | var NSConfiguration g_config; |
Alexander Couzens | 2c12b24 | 2018-07-31 00:30:11 +0200 | [diff] [blame] | 484 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 485 | var NsvcState vc_state := NSVC_S_DEAD_BLOCKED; |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 486 | |
| 487 | timer Tns_alive := 3.0; |
| 488 | timer Tns_test := 10.0; |
| 489 | timer Tns_block := 10.0; |
Harald Welte | 3dd8355 | 2020-09-14 11:38:01 +0200 | [diff] [blame] | 490 | timer Tns_reset := 10.0; |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 491 | } |
| 492 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 493 | function NSVCStart(NSVCConfiguration init_config, NSConfiguration init_g_config, charstring id := testcasename()) runs on NSVC_CT { |
| 494 | g_nsvc_config := init_config; |
| 495 | g_config := init_g_config; |
| 496 | f_init(id & "-NSVCemu" & int2str(g_nsvc_config.nsvci)); |
| 497 | f_ScanEvents(); |
Alexander Couzens | 2c12b24 | 2018-07-31 00:30:11 +0200 | [diff] [blame] | 498 | } |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 499 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 500 | private function f_init(charstring id) runs on NSVC_CT { |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 501 | if (ischosen(g_nsvc_config.provider.ip)) { |
| 502 | /* Connect the UDP socket */ |
| 503 | vc_NSP_IP := NS_Provider_IPL4_CT.create(id & "-provIP"); |
| 504 | connect(self:NSCP, vc_NSP_IP:NSE); |
| 505 | vc_NSP_IP.start(NS_Provider_IPL4.main(g_nsvc_config, g_config, id)); |
| 506 | #ifdef NS_EMULATION_FR |
| 507 | } else if (ischosen(g_nsvc_config.provider.fr)) { |
| 508 | vc_NSP_FR := NS_Provider_FR_CT.create(id & "-provFR"); |
| 509 | connect(self:NSCP, vc_NSP_FR:NSE); |
| 510 | vc_NSP_FR.start(NS_Provider_FR.main(g_nsvc_config, g_config, id)); |
| 511 | #endif |
Harald Welte | e15299a | 2020-11-17 17:30:09 +0100 | [diff] [blame] | 512 | } else { |
| 513 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported NS provider"); |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | f_change_state(NSVC_S_DEAD_BLOCKED); |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 517 | } |
| 518 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 519 | private function f_change_state(NsvcState new_state) runs on NSVC_CT { |
| 520 | var NsvcState old_state := vc_state; |
| 521 | vc_state := new_state; |
| 522 | log("NSVC ", g_nsvc_config.nsvci, " State Transition: ", old_state, " -> ", new_state); |
| 523 | NS_SP.send(ts_NsStsInd(g_config.nsei, g_nsvc_config.nsvci, old_state, new_state)); |
| 524 | } |
| 525 | |
| 526 | private function f_sendReset() runs on NSVC_CT { |
| 527 | NSCP.send(ts_NS_RESET(NS_CAUSE_OM_INTERVENTION, g_nsvc_config.nsvci, g_config.nsei)); |
Harald Welte | 3dd8355 | 2020-09-14 11:38:01 +0200 | [diff] [blame] | 528 | Tns_reset.start; |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 529 | vc_state := NSVC_S_WAIT_RESET; |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 530 | } |
| 531 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 532 | private function f_sendAlive() runs on NSVC_CT { |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 533 | NSCP.send(t_NS_ALIVE); |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 534 | Tns_alive.start; |
| 535 | } |
| 536 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 537 | private function f_sendUnblock() runs on NSVC_CT { |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 538 | NSCP.send(t_NS_UNBLOCK); |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 539 | Tns_block.start; |
| 540 | } |
| 541 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 542 | private function f_sendBlock(NsCause cause) runs on NSVC_CT { |
| 543 | NSCP.send(ts_NS_BLOCK(cause, g_nsvc_config.nsvci)); |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 544 | Tns_block.start; |
| 545 | } |
| 546 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 547 | private altstep as_allstate() runs on NSVC_CT { |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 548 | var PDU_NS rf; |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 549 | var ASP_Event evt; |
| 550 | |
| 551 | /* transition to DEAD if t_alive times out */ |
Harald Welte | 9a7c512 | 2020-09-14 11:35:57 +0200 | [diff] [blame] | 552 | [] Tns_alive.timeout { |
| 553 | log("Tns-alive expired: changing to DEAD_BLOCKED + starting Tns-test"); |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 554 | f_change_state(NSVC_S_DEAD_BLOCKED); |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 555 | Tns_test.start; |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 556 | } |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 557 | |
Harald Welte | 9a7c512 | 2020-09-14 11:35:57 +0200 | [diff] [blame] | 558 | [] Tns_test.timeout { |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 559 | log("Tns-test expired: sending NS-ALIVE"); |
| 560 | f_sendAlive(); |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 561 | } |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 562 | |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 563 | /* Stop t_alive when receiving ALIVE-ACK */ |
Harald Welte | 9a7c512 | 2020-09-14 11:35:57 +0200 | [diff] [blame] | 564 | [Tns_alive.running] NSCP.receive(t_NS_ALIVE_ACK) { |
Daniel Willmann | 654f85e | 2020-10-12 18:10:06 +0200 | [diff] [blame] | 565 | log("Rx NS-ALIVE-ACK: stopping Tns-alive; starting Tns-test"); |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 566 | Tns_alive.stop; |
| 567 | Tns_test.start; |
| 568 | } |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 569 | |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 570 | /* respond to NS-ALIVE with NS-ALIVE-ACK */ |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 571 | [] NSCP.receive(t_NS_ALIVE) { |
| 572 | NSCP.send(t_NS_ALIVE_ACK); |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | /* Respond to BLOCK for wrong NSVCI */ |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 576 | [] NSCP.receive(tr_NS_BLOCK(?, ?)) -> value rf { |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 577 | log("Rx NS-BLOCK for unknown NSVCI"); |
| 578 | /* FIXME */ |
| 579 | } |
| 580 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 581 | [not g_config.handle_sns] as_handle_reset(); |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 582 | |
Harald Welte | 1308dbb | 2021-01-18 18:19:38 +0100 | [diff] [blame] | 583 | [g_config.handle_sns and ischosen(g_nsvc_config.provider.ip)] as_nsvc_sns(); |
Harald Welte | 5e514fa | 2018-07-05 00:01:45 +0200 | [diff] [blame] | 584 | |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 585 | /* default case of handling unknown PDUs */ |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 586 | [] NSCP.receive(PDU_NS: ?) -> value rf { |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 587 | log("Rx Unexpected NS PDU ", rf," in state ", vc_state); |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 588 | NSCP.send(ts_NS_STATUS(NS_CAUSE_PDU_NOT_COMPATIBLE_WITH_PROTOCOL_STATE, rf)); |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 589 | } |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 590 | } |
| 591 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 592 | private altstep as_handle_reset() runs on NSVC_CT { |
Daniel Willmann | 654f85e | 2020-10-12 18:10:06 +0200 | [diff] [blame] | 593 | var PDU_NS rf; |
| 594 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 595 | [g_config.role_sgsn] NSCP.receive(NS_Provider_Evt:{link_status:=NS_PROV_LINK_STATUS_UP}) { |
Daniel Willmann | 654f85e | 2020-10-12 18:10:06 +0200 | [diff] [blame] | 596 | log("Provider Link came up: waiting for NS-RESET"); |
| 597 | } |
| 598 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 599 | [not g_config.role_sgsn] NSCP.receive(NS_Provider_Evt:{link_status:=NS_PROV_LINK_STATUS_UP}) { |
Daniel Willmann | 654f85e | 2020-10-12 18:10:06 +0200 | [diff] [blame] | 600 | log("Provider Link came up: sending NS-RESET"); |
| 601 | f_sendReset(); |
| 602 | } |
| 603 | |
| 604 | /* Respond to RESET with correct NSEI/NSVCI */ |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 605 | [] NSCP.receive(tr_NS_RESET(?, g_nsvc_config.nsvci, g_config.nsei)) -> value rf { |
| 606 | f_change_state(NSVC_S_ALIVE_BLOCKED); |
| 607 | NSCP.send(ts_NS_RESET_ACK(g_nsvc_config.nsvci, g_config.nsei)); |
Daniel Willmann | 654f85e | 2020-10-12 18:10:06 +0200 | [diff] [blame] | 608 | log("Rx NS-RESET: Sending NS-ALIVE"); |
| 609 | f_sendAlive(); |
| 610 | Tns_test.start; |
| 611 | } |
| 612 | |
| 613 | /* Respond to RESET with wrong NSEI/NSVCI */ |
| 614 | [] NSCP.receive(tr_NS_RESET(?, ?, ?)) -> value rf { |
| 615 | log("Rx NS-RESET for unknown NSEI/NSVCI"); |
| 616 | /* FIXME */ |
| 617 | } |
| 618 | } |
| 619 | |
Harald Welte | 1308dbb | 2021-01-18 18:19:38 +0100 | [diff] [blame] | 620 | private altstep as_nsvc_sns() runs on NSVC_CT { |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 621 | var PDU_NS rf; |
Harald Welte | 1308dbb | 2021-01-18 18:19:38 +0100 | [diff] [blame] | 622 | var SnsRequest sreq; |
Alexander Couzens | d533890 | 2020-12-21 18:41:21 +0100 | [diff] [blame] | 623 | [] NSCP.receive(NS_Provider_Evt:{link_status:=NS_PROV_LINK_STATUS_UP}) { |
| 624 | log("Provider Link came up. Waiting for SNS Size"); |
Harald Welte | 1308dbb | 2021-01-18 18:19:38 +0100 | [diff] [blame] | 625 | } |
Daniel Willmann | 654f85e | 2020-10-12 18:10:06 +0200 | [diff] [blame] | 626 | |
Harald Welte | 1308dbb | 2021-01-18 18:19:38 +0100 | [diff] [blame] | 627 | /* pass up to NS-VCG */ |
| 628 | [] NSCP.receive(tr_SNS(g_config.nsei)) -> value rf { |
| 629 | NS_SP.send(SnsIndication:{g_nsvc_config.nsvci, rf}); |
Harald Welte | 5e514fa | 2018-07-05 00:01:45 +0200 | [diff] [blame] | 630 | } |
Harald Welte | 1308dbb | 2021-01-18 18:19:38 +0100 | [diff] [blame] | 631 | [] NSCP.receive(tr_SNS(?)) -> value rf { |
| 632 | setverdict(fail, "SNS from unexpected NSEI: ", rf); |
Harald Welte | 5e514fa | 2018-07-05 00:01:45 +0200 | [diff] [blame] | 633 | self.stop; |
| 634 | } |
Harald Welte | 1308dbb | 2021-01-18 18:19:38 +0100 | [diff] [blame] | 635 | [] NS_SP.receive(SnsRequest:{g_nsvc_config.nsvci, ?}) -> value sreq { |
| 636 | NSCP.send(sreq.ns); |
Harald Welte | 5e514fa | 2018-07-05 00:01:45 +0200 | [diff] [blame] | 637 | } |
Harald Welte | 1308dbb | 2021-01-18 18:19:38 +0100 | [diff] [blame] | 638 | [] NS_SP.receive(SnsRequest:?) -> value sreq { |
| 639 | setverdict(fail, "Unexpected SNS from NSVC: ", sreq); |
Harald Welte | 5e514fa | 2018-07-05 00:01:45 +0200 | [diff] [blame] | 640 | self.stop; |
| 641 | } |
Harald Welte | 1308dbb | 2021-01-18 18:19:38 +0100 | [diff] [blame] | 642 | [] NS_SP.receive(NsCtrlRequest:StartAliveProcedure) { |
| 643 | f_change_state(NSVC_S_ALIVE_UNBLOCKED); |
| 644 | f_sendAlive(); |
| 645 | Tns_test.start; |
Harald Welte | 5e514fa | 2018-07-05 00:01:45 +0200 | [diff] [blame] | 646 | } |
| 647 | } |
| 648 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 649 | private altstep as_alive_blocked() runs on NSVC_CT { |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 650 | var PDU_NS rf; |
| 651 | /* bogus block, just respond with ACK */ |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 652 | [] NSCP.receive(tr_NS_BLOCK(?, g_nsvc_config.nsvci)) -> value rf { |
| 653 | NSCP.send(ts_NS_BLOCK_ACK(g_nsvc_config.nsvci)); |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 654 | } |
| 655 | /* Respond to UNBLOCK with UNBLOCK-ACK + change state */ |
| 656 | [] NSCP.receive(t_NS_UNBLOCK) -> value rf { |
| 657 | NSCP.send(t_NS_UNBLOCK_ACK); |
| 658 | Tns_block.stop; |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 659 | f_change_state(NSVC_S_ALIVE_UNBLOCKED); |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 660 | } |
| 661 | [] NSCP.receive(t_NS_UNBLOCK_ACK) -> value rf { |
| 662 | Tns_block.stop; |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 663 | f_change_state(NSVC_S_ALIVE_UNBLOCKED); |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 664 | } |
Harald Welte | da9d938 | 2020-12-07 15:53:57 +0100 | [diff] [blame] | 665 | /* tolerate a late NS-BLOCK-ACK from peer */ |
| 666 | [] NSCP.receive(tr_NS_BLOCK_ACK(g_nsvc_config.nsvci)) -> value rf { |
| 667 | } |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 668 | [] Tns_block.timeout { |
| 669 | /* repeat unblock transmission */ |
| 670 | f_sendUnblock(); |
| 671 | } |
| 672 | } |
| 673 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 674 | private altstep as_alive_unblocked() runs on NSVC_CT { |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 675 | var NsUnitdataRequest ud_req; |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 676 | var PDU_NS rf; |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 677 | /* bogus unblock, just respond with ACK */ |
| 678 | [] NSCP.receive(t_NS_UNBLOCK) -> value rf { |
| 679 | NSCP.send(t_NS_UNBLOCK_ACK); |
| 680 | } |
| 681 | /* Respond to BLOCK with BLOCK-ACK + change state */ |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 682 | [] NSCP.receive(tr_NS_BLOCK(?, g_nsvc_config.nsvci)) -> value rf { |
| 683 | NSCP.send(ts_NS_BLOCK_ACK(g_nsvc_config.nsvci)); |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 684 | Tns_block.stop; |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 685 | f_change_state(NSVC_S_ALIVE_BLOCKED); |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 686 | } |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 687 | [] NSCP.receive(tr_NS_BLOCK_ACK(g_nsvc_config.nsvci)) -> value rf { |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 688 | Tns_block.stop; |
| 689 | } |
Harald Welte | da9d938 | 2020-12-07 15:53:57 +0100 | [diff] [blame] | 690 | /* tolerate a late NS-UNBLOCK-ACK from peer */ |
| 691 | [] NSCP.receive(t_NS_UNBLOCK_ACK) -> value rf { |
| 692 | } |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 693 | /* NS-UNITDATA PDU from network to NS-UNITDATA.ind to user */ |
| 694 | [] NSCP.receive(tr_NS_UNITDATA(?, ?, ?)) -> value rf { |
Harald Welte | 80a249a | 2020-11-17 19:57:40 +0100 | [diff] [blame] | 695 | NS_SP.send(ts_NsUdInd(g_config.nsei, g_nsvc_config.nsvci, |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 696 | oct2int(rf.pDU_NS_Unitdata.bVCI), |
| 697 | rf.pDU_NS_Unitdata.nS_SDU)); |
| 698 | } |
| 699 | /* NS-UNITDATA.req from user to NS-UNITDATA PDU on network */ |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 700 | [] NS_SP.receive(tr_NsUdReq(g_config.nsei, ?, ?, ?, omit)) -> value ud_req { |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 701 | /* using raw octetstring PDU */ |
| 702 | NSCP.send(ts_NS_UNITDATA(t_SduCtrlB, ud_req.bvci, ud_req.sdu)); |
| 703 | } |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 704 | [] NS_SP.receive(tr_NsUdReq(g_config.nsei, ?, ?, omit, ?)) -> value ud_req { |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 705 | /* using decoded BSSGP PDU that we need to encode first */ |
| 706 | var octetstring enc := enc_PDU_BSSGP(ud_req.bssgp); |
| 707 | NSCP.send(ts_NS_UNITDATA(t_SduCtrlB, ud_req.bvci, enc)); |
| 708 | } |
| 709 | } |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 710 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 711 | private altstep as_wait_reset() runs on NSVC_CT { |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 712 | var PDU_NS rf; |
Harald Welte | 3dd8355 | 2020-09-14 11:38:01 +0200 | [diff] [blame] | 713 | [] Tns_reset.timeout { |
| 714 | /* If the sending entity of an NS-RESET PDU receives no NS-RESET-ACK PDU before timer |
| 715 | * Tns-reset expires the corresponding NS-VCs shall remain blocked and dead and the |
| 716 | * entire reset procedure shall be repeated */ |
| 717 | f_sendReset(); |
| 718 | } |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 719 | [] NSCP.receive(tr_NS_RESET_ACK(g_nsvc_config.nsvci, g_config.nsei)) -> value rf { |
Harald Welte | 3dd8355 | 2020-09-14 11:38:01 +0200 | [diff] [blame] | 720 | Tns_reset.stop; |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 721 | f_change_state(NSVC_S_ALIVE_BLOCKED); |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 722 | f_sendAlive(); |
| 723 | f_sendUnblock(); |
| 724 | } |
| 725 | } |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 726 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 727 | private function f_ScanEvents() runs on NSVC_CT { |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 728 | var PDU_NS rf; |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 729 | while (true) { |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 730 | alt { |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 731 | [vc_state == NSVC_S_WAIT_RESET] as_wait_reset(); |
| 732 | [vc_state == NSVC_S_ALIVE_BLOCKED] as_alive_blocked(); |
| 733 | [vc_state == NSVC_S_ALIVE_UNBLOCKED] as_alive_unblocked(); |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 734 | [] as_allstate(); |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 735 | } |
| 736 | } |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 737 | } |
| 738 | } |