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 */ |
| 186 | port NS_PT NSVC; |
| 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 | |
| 205 | /* add one NSVC (component and table entry */ |
| 206 | function f_nsvc_add(NSVCConfiguration nsvc_cfg) runs on NS_CT { |
| 207 | var charstring nsvc_id := g_id & "-NSVCI" & int2str(nsvc_cfg.nsvci); |
| 208 | var NsvcTableEntry te; |
| 209 | |
| 210 | te.nsvci := nsvc_cfg.nsvci; |
| 211 | te.vc_conn := NSVC_CT.create(nsvc_id); |
| 212 | te.state := NSVC_S_DEAD_BLOCKED; |
| 213 | |
| 214 | connect(self:NSVC, te.vc_conn:NS_SP); |
| 215 | te.vc_conn.start(NSVCStart(nsvc_cfg, g_config, nsvc_id)); |
| 216 | |
| 217 | g_nsvcs := g_nsvcs & { te }; |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 218 | /* 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] | 219 | } |
| 220 | |
| 221 | function f_nsvc_find_idx(Nsvci nsvci) runs on NS_CT return integer { |
| 222 | var integer i; |
| 223 | for (i := 0; i < lengthof(g_nsvcs); i := i+1) { |
| 224 | if (g_nsvcs[i].nsvci == nsvci) { |
| 225 | return i; |
| 226 | } |
| 227 | } |
| 228 | return -1; |
| 229 | } |
| 230 | |
| 231 | function f_nsvc_find(Nsvci nsvci) runs on NS_CT return NSVC_CT { |
| 232 | var integer i := f_nsvc_find_idx(nsvci); |
| 233 | if (i < 0) { |
| 234 | return null; |
| 235 | } else { |
| 236 | return g_nsvcs[i].vc_conn; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | function f_nsvc_update_state(Nsvci nsvci, NsvcState state) runs on NS_CT { |
| 241 | var integer i := f_nsvc_find_idx(nsvci); |
| 242 | if (i < 0) { |
| 243 | return; |
| 244 | } |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 245 | if (g_nsvcs[i].state != NSVC_S_ALIVE_UNBLOCKED and state == NSVC_S_ALIVE_UNBLOCKED) { |
| 246 | /* add index to list of unblocked NSVCs */ |
| 247 | g_unblocked_nsvcs := g_unblocked_nsvcs & {i}; |
| 248 | } else if (g_nsvcs[i].state == NSVC_S_ALIVE_UNBLOCKED and state != NSVC_S_ALIVE_UNBLOCKED) { |
| 249 | /* remove index to list of unblocked NSVCs */ |
| 250 | var ro_integer new_unblocked_nsvcs := {}; |
| 251 | for (var integer j := 0; j < lengthof(g_unblocked_nsvcs); j := j+1) { |
| 252 | if (g_unblocked_nsvcs[j] != i) { |
| 253 | new_unblocked_nsvcs := new_unblocked_nsvcs & {j}; |
| 254 | } |
| 255 | } |
| 256 | g_unblocked_nsvcs := new_unblocked_nsvcs; |
| 257 | } |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 258 | g_nsvcs[i].state := state; |
| 259 | } |
| 260 | |
| 261 | function NSStart(NSConfiguration init_config, charstring id := testcasename()) runs on NS_CT { |
| 262 | g_config := init_config; |
| 263 | g_id := id; |
| 264 | |
| 265 | /* iterate over list of NS-VCs and start per-NSVC components */ |
| 266 | for (var integer i := 0; i < lengthof(g_config.nsvc); i := i+1) { |
| 267 | var NSVCConfiguration nsvc_cfg := g_config.nsvc[i]; |
| 268 | f_nsvc_add(nsvc_cfg); |
| 269 | } |
| 270 | |
| 271 | while (true) { |
| 272 | alt { |
| 273 | [] as_ns_common() {} |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | |
Harald Welte | dc0a090 | 2020-11-10 21:03:29 +0100 | [diff] [blame] | 278 | function f_count_nsvcs_in_state(template NsvcState state := ?) runs on NS_CT return integer { |
| 279 | var integer i; |
| 280 | var integer res := 0; |
| 281 | for (i := 0; i < lengthof(g_nsvcs); i := i+1) { |
| 282 | if (match(g_nsvcs[i].state, state)) { |
| 283 | res := res + 1; |
| 284 | } |
| 285 | } |
| 286 | return res; |
| 287 | } |
| 288 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 289 | private altstep as_ns_common() runs on NS_CT { |
| 290 | var NsStatusIndication rx_nssi; |
| 291 | var NsUnitdataIndication rx_nsudi; |
| 292 | var NsUnitdataRequest rx_nsudr; |
| 293 | /* pass from NS-VCs up to user */ |
Harald Welte | dc0a090 | 2020-11-10 21:03:29 +0100 | [diff] [blame] | 294 | [] NSVC.receive(tr_NsStsInd(g_config.nsei, ?, ?, NSVC_S_ALIVE_UNBLOCKED)) -> value rx_nssi { |
| 295 | /* check if this one is the first to be unblocked */ |
| 296 | var integer num_nsvc_unblocked := f_count_nsvcs_in_state(NSVC_S_ALIVE_UNBLOCKED); |
| 297 | f_nsvc_update_state(rx_nssi.nsvci, rx_nssi.new_state); |
| 298 | if (num_nsvc_unblocked == 0) { |
| 299 | rx_nssi.first_or_last := true; |
| 300 | } |
| 301 | NS_SP.send(rx_nssi); |
| 302 | } |
| 303 | [] NSVC.receive(tr_NsStsInd(g_config.nsei, ?, ?, NSVC_S_DEAD_BLOCKED)) -> value rx_nssi { |
| 304 | f_nsvc_update_state(rx_nssi.nsvci, rx_nssi.new_state); |
| 305 | /* check if this one is the last to be blocked */ |
| 306 | var integer num_nsvc_unblocked := f_count_nsvcs_in_state(NSVC_S_ALIVE_UNBLOCKED); |
| 307 | if (num_nsvc_unblocked == 0) { |
| 308 | rx_nssi.first_or_last := true; |
| 309 | } |
| 310 | NS_SP.send(rx_nssi); |
| 311 | } |
| 312 | [] NSVC.receive(tr_NsStsInd(g_config.nsei, ?, ?, ?)) -> value rx_nssi { |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 313 | f_nsvc_update_state(rx_nssi.nsvci, rx_nssi.new_state); |
| 314 | NS_SP.send(rx_nssi); |
| 315 | } |
| 316 | [] NSVC.receive(tr_NsStsInd) -> value rx_nssi { |
| 317 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 318 | log2str("Received NsStatusInd for invalid NSEI: ", rx_nssi)); |
| 319 | } |
| 320 | [] NSVC.receive(tr_NsUdInd(g_config.nsei, ?, ?)) -> value rx_nsudi { |
| 321 | NS_SP.send(rx_nsudi); |
| 322 | } |
| 323 | [] NSVC.receive(tr_NsUdInd(?, ?, ?)) -> value rx_nsudi { |
| 324 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 325 | log2str("Received UnitDataInd for invalid NSEI: ", rx_nsudi)); |
| 326 | } |
| 327 | /* from user down to NS-VC */ |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 328 | [] NS_SP.receive(tr_NsUdReq(g_config.nsei, ?, ?, ?, *)) -> value rx_nsudr { |
| 329 | /* load distribution function */ |
| 330 | var integer nsvc_idx := g_unblocked_nsvcs[rx_nsudr.lsp mod lengthof(g_unblocked_nsvcs)]; |
| 331 | NSVC.send(rx_nsudr) to g_nsvcs[nsvc_idx].vc_conn; |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 332 | } |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 333 | [] NS_SP.receive(tr_NsUdReq(?, ?, ?, ?, *)) -> value rx_nsudr { |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 334 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 335 | log2str("Received NsUnitdataReq for invalid NSEI: ", rx_nsudr)); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | /*********************************************************************** |
| 340 | per-NSVC component. Exists once for each NS-VC in the NS-VCG |
| 341 | ***********************************************************************/ |
| 342 | |
| 343 | type component NSVC_CT { |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 344 | /* UDP port towards the bottom (IUT) */ |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 345 | port NS_PROVIDER_PT NSCP; |
| 346 | var NS_Provider_IPL4_CT vc_NSP_IP; |
Harald Welte | 867243a | 2020-09-13 18:32:32 +0200 | [diff] [blame] | 347 | #ifdef NS_EMULATION_FR |
| 348 | var NS_Provider_FR_CT vc_NSP_FR; |
| 349 | #endif |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 350 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 351 | /* port towards the NS_CT */ |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 352 | port NS_SP_PT NS_SP; |
| 353 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 354 | /* configuration passed by the user */ |
| 355 | var NSVCConfiguration g_nsvc_config; |
| 356 | /* we cannot access the NS_CT.config and hence need to copy those */ |
| 357 | var NSConfiguration g_config; |
Alexander Couzens | 2c12b24 | 2018-07-31 00:30:11 +0200 | [diff] [blame] | 358 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 359 | var NsvcState vc_state := NSVC_S_DEAD_BLOCKED; |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 360 | |
| 361 | timer Tns_alive := 3.0; |
| 362 | timer Tns_test := 10.0; |
| 363 | timer Tns_block := 10.0; |
Harald Welte | 3dd8355 | 2020-09-14 11:38:01 +0200 | [diff] [blame] | 364 | timer Tns_reset := 10.0; |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 365 | } |
| 366 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 367 | function NSVCStart(NSVCConfiguration init_config, NSConfiguration init_g_config, charstring id := testcasename()) runs on NSVC_CT { |
| 368 | g_nsvc_config := init_config; |
| 369 | g_config := init_g_config; |
| 370 | f_init(id & "-NSVCemu" & int2str(g_nsvc_config.nsvci)); |
| 371 | f_ScanEvents(); |
Alexander Couzens | 2c12b24 | 2018-07-31 00:30:11 +0200 | [diff] [blame] | 372 | } |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 373 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 374 | private function f_init(charstring id) runs on NSVC_CT { |
| 375 | var Result res; |
| 376 | |
| 377 | if (ischosen(g_nsvc_config.provider.ip)) { |
| 378 | /* Connect the UDP socket */ |
| 379 | vc_NSP_IP := NS_Provider_IPL4_CT.create(id & "-provIP"); |
| 380 | connect(self:NSCP, vc_NSP_IP:NSE); |
| 381 | vc_NSP_IP.start(NS_Provider_IPL4.main(g_nsvc_config, g_config, id)); |
| 382 | #ifdef NS_EMULATION_FR |
| 383 | } else if (ischosen(g_nsvc_config.provider.fr)) { |
| 384 | vc_NSP_FR := NS_Provider_FR_CT.create(id & "-provFR"); |
| 385 | connect(self:NSCP, vc_NSP_FR:NSE); |
| 386 | vc_NSP_FR.start(NS_Provider_FR.main(g_nsvc_config, g_config, id)); |
| 387 | #endif |
Harald Welte | e15299a | 2020-11-17 17:30:09 +0100 | [diff] [blame] | 388 | } else { |
| 389 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported NS provider"); |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | f_change_state(NSVC_S_DEAD_BLOCKED); |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 393 | } |
| 394 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 395 | private function f_change_state(NsvcState new_state) runs on NSVC_CT { |
| 396 | var NsvcState old_state := vc_state; |
| 397 | vc_state := new_state; |
| 398 | log("NSVC ", g_nsvc_config.nsvci, " State Transition: ", old_state, " -> ", new_state); |
| 399 | NS_SP.send(ts_NsStsInd(g_config.nsei, g_nsvc_config.nsvci, old_state, new_state)); |
| 400 | } |
| 401 | |
| 402 | private function f_sendReset() runs on NSVC_CT { |
| 403 | 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] | 404 | Tns_reset.start; |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 405 | vc_state := NSVC_S_WAIT_RESET; |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 406 | } |
| 407 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 408 | private function f_sendAlive() runs on NSVC_CT { |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 409 | NSCP.send(t_NS_ALIVE); |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 410 | Tns_alive.start; |
| 411 | } |
| 412 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 413 | private function f_sendUnblock() runs on NSVC_CT { |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 414 | NSCP.send(t_NS_UNBLOCK); |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 415 | Tns_block.start; |
| 416 | } |
| 417 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 418 | private function f_sendBlock(NsCause cause) runs on NSVC_CT { |
| 419 | NSCP.send(ts_NS_BLOCK(cause, g_nsvc_config.nsvci)); |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 420 | Tns_block.start; |
| 421 | } |
| 422 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 423 | private altstep as_allstate() runs on NSVC_CT { |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 424 | var PDU_NS rf; |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 425 | var ASP_Event evt; |
| 426 | |
| 427 | /* transition to DEAD if t_alive times out */ |
Harald Welte | 9a7c512 | 2020-09-14 11:35:57 +0200 | [diff] [blame] | 428 | [] Tns_alive.timeout { |
| 429 | log("Tns-alive expired: changing to DEAD_BLOCKED + starting Tns-test"); |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 430 | f_change_state(NSVC_S_DEAD_BLOCKED); |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 431 | Tns_test.start; |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 432 | } |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 433 | |
Harald Welte | 9a7c512 | 2020-09-14 11:35:57 +0200 | [diff] [blame] | 434 | [] Tns_test.timeout { |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 435 | log("Tns-test expired: sending NS-ALIVE"); |
| 436 | f_sendAlive(); |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 437 | } |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 438 | |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 439 | /* Stop t_alive when receiving ALIVE-ACK */ |
Harald Welte | 9a7c512 | 2020-09-14 11:35:57 +0200 | [diff] [blame] | 440 | [Tns_alive.running] NSCP.receive(t_NS_ALIVE_ACK) { |
Daniel Willmann | 654f85e | 2020-10-12 18:10:06 +0200 | [diff] [blame] | 441 | log("Rx NS-ALIVE-ACK: stopping Tns-alive; starting Tns-test"); |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 442 | Tns_alive.stop; |
| 443 | Tns_test.start; |
| 444 | } |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 445 | |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 446 | /* respond to NS-ALIVE with NS-ALIVE-ACK */ |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 447 | [] NSCP.receive(t_NS_ALIVE) { |
| 448 | NSCP.send(t_NS_ALIVE_ACK); |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | /* Respond to BLOCK for wrong NSVCI */ |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 452 | [] NSCP.receive(tr_NS_BLOCK(?, ?)) -> value rf { |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 453 | log("Rx NS-BLOCK for unknown NSVCI"); |
| 454 | /* FIXME */ |
| 455 | } |
| 456 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 457 | [not g_config.handle_sns] as_handle_reset(); |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 458 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 459 | [g_config.role_sgsn and g_config.handle_sns and ischosen(g_nsvc_config.provider.ip)] as_sns_sgsn(); |
Harald Welte | 5e514fa | 2018-07-05 00:01:45 +0200 | [diff] [blame] | 460 | |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 461 | /* default case of handling unknown PDUs */ |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 462 | [] NSCP.receive(PDU_NS: ?) -> value rf { |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 463 | log("Rx Unexpected NS PDU ", rf," in state ", vc_state); |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 464 | 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] | 465 | } |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 466 | } |
| 467 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 468 | private altstep as_handle_reset() runs on NSVC_CT { |
Daniel Willmann | 654f85e | 2020-10-12 18:10:06 +0200 | [diff] [blame] | 469 | var PDU_NS rf; |
| 470 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 471 | [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] | 472 | log("Provider Link came up: waiting for NS-RESET"); |
| 473 | } |
| 474 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 475 | [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] | 476 | log("Provider Link came up: sending NS-RESET"); |
| 477 | f_sendReset(); |
| 478 | } |
| 479 | |
| 480 | /* Respond to RESET with correct NSEI/NSVCI */ |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 481 | [] NSCP.receive(tr_NS_RESET(?, g_nsvc_config.nsvci, g_config.nsei)) -> value rf { |
| 482 | f_change_state(NSVC_S_ALIVE_BLOCKED); |
| 483 | 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] | 484 | log("Rx NS-RESET: Sending NS-ALIVE"); |
| 485 | f_sendAlive(); |
| 486 | Tns_test.start; |
| 487 | } |
| 488 | |
| 489 | /* Respond to RESET with wrong NSEI/NSVCI */ |
| 490 | [] NSCP.receive(tr_NS_RESET(?, ?, ?)) -> value rf { |
| 491 | log("Rx NS-RESET for unknown NSEI/NSVCI"); |
| 492 | /* FIXME */ |
| 493 | } |
| 494 | } |
| 495 | |
Harald Welte | 5e514fa | 2018-07-05 00:01:45 +0200 | [diff] [blame] | 496 | /* simple IP Sub-Network Service responder for the SGSN side. This is not a full implementation |
| 497 | * of the protocol, merely sufficient to make the PCU/BSS side happy to proceed */ |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 498 | private altstep as_sns_sgsn() runs on NSVC_CT { |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 499 | var PDU_NS rf; |
Alexander Couzens | d533890 | 2020-12-21 18:41:21 +0100 | [diff] [blame] | 500 | [] NSCP.receive(NS_Provider_Evt:{link_status:=NS_PROV_LINK_STATUS_UP}) { |
| 501 | log("Provider Link came up. Waiting for SNS Size"); |
Daniel Willmann | 654f85e | 2020-10-12 18:10:06 +0200 | [diff] [blame] | 502 | } |
| 503 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 504 | [] NSCP.receive(tr_SNS_SIZE(g_config.nsei)) -> value rf { |
Harald Welte | 5e514fa | 2018-07-05 00:01:45 +0200 | [diff] [blame] | 505 | /* blindly acknowledge whatever the PCU sends */ |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 506 | NSCP.send(ts_SNS_SIZE_ACK(g_config.nsei, omit)); |
Harald Welte | 5e514fa | 2018-07-05 00:01:45 +0200 | [diff] [blame] | 507 | } |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 508 | [] NSCP.receive(tr_SNS_SIZE(?)) { |
Harald Welte | 5e514fa | 2018-07-05 00:01:45 +0200 | [diff] [blame] | 509 | setverdict(fail, "SNS-SIZE from unexpected NSEI"); |
| 510 | self.stop; |
| 511 | } |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 512 | [] NSCP.receive(tr_SNS_CONFIG(g_config.nsei, true, |
| 513 | {tr_SNS_IPv4(g_nsvc_config.provider.ip.remote_ip, |
| 514 | g_nsvc_config.provider.ip.remote_udp_port)})) -> value rf { |
Harald Welte | 5e514fa | 2018-07-05 00:01:45 +0200 | [diff] [blame] | 515 | /* blindly acknowledge whatever the PCU sends */ |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 516 | NSCP.send(ts_SNS_CONFIG_ACK(g_config.nsei, omit)); |
Harald Welte | 5e514fa | 2018-07-05 00:01:45 +0200 | [diff] [blame] | 517 | /* send a SNS-CONFIG in response and expect a SNS-CONFIG-ACK */ |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 518 | var IP4_Elements v4 := { valueof(ts_SNS_IPv4(g_nsvc_config.provider.ip.local_ip, |
| 519 | g_nsvc_config.provider.ip.local_udp_port)) }; |
| 520 | NSCP.send(ts_SNS_CONFIG(g_config.nsei, true, v4)); |
Harald Welte | 5e514fa | 2018-07-05 00:01:45 +0200 | [diff] [blame] | 521 | alt { |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 522 | [] NSCP.receive(tr_SNS_CONFIG_ACK(g_config.nsei, omit)) { |
Harald Welte | 5e514fa | 2018-07-05 00:01:45 +0200 | [diff] [blame] | 523 | /* success */ |
Alexander Couzens | d533890 | 2020-12-21 18:41:21 +0100 | [diff] [blame] | 524 | log("SNS Config succeeded. Sending Alive"); |
| 525 | f_change_state(NSVC_S_ALIVE_UNBLOCKED); |
| 526 | f_sendAlive(); |
| 527 | Tns_test.start; |
Harald Welte | 5e514fa | 2018-07-05 00:01:45 +0200 | [diff] [blame] | 528 | } |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 529 | [] NSCP.receive(tr_SNS_CONFIG_ACK(g_config.nsei, ?)) { |
Harald Welte | 5e514fa | 2018-07-05 00:01:45 +0200 | [diff] [blame] | 530 | setverdict(fail, "Unexpected SNS-CONFIG-NACK"); |
| 531 | self.stop; |
| 532 | } |
| 533 | } |
| 534 | } |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 535 | [] NSCP.receive(tr_SNS_CONFIG(g_config.nsei, false, ?)) { /* ignore */} |
| 536 | [] NSCP.receive(tr_SNS_CONFIG(g_config.nsei, true, ?)) { |
Harald Welte | 5e514fa | 2018-07-05 00:01:45 +0200 | [diff] [blame] | 537 | setverdict(fail, "Unexpected SNS-CONFIG content"); |
| 538 | self.stop; |
| 539 | } |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 540 | [] NSCP.receive(tr_SNS_CONFIG(?, ?, ?)) { |
Harald Welte | 5e514fa | 2018-07-05 00:01:45 +0200 | [diff] [blame] | 541 | setverdict(fail, "SNS-CONFIG from unexpected NSEI"); |
| 542 | self.stop; |
| 543 | } |
| 544 | } |
| 545 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 546 | private altstep as_alive_blocked() runs on NSVC_CT { |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 547 | var PDU_NS rf; |
| 548 | /* bogus block, just respond with ACK */ |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 549 | [] NSCP.receive(tr_NS_BLOCK(?, g_nsvc_config.nsvci)) -> value rf { |
| 550 | NSCP.send(ts_NS_BLOCK_ACK(g_nsvc_config.nsvci)); |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 551 | } |
| 552 | /* Respond to UNBLOCK with UNBLOCK-ACK + change state */ |
| 553 | [] NSCP.receive(t_NS_UNBLOCK) -> value rf { |
| 554 | NSCP.send(t_NS_UNBLOCK_ACK); |
| 555 | Tns_block.stop; |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 556 | f_change_state(NSVC_S_ALIVE_UNBLOCKED); |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 557 | } |
| 558 | [] NSCP.receive(t_NS_UNBLOCK_ACK) -> value rf { |
| 559 | Tns_block.stop; |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 560 | f_change_state(NSVC_S_ALIVE_UNBLOCKED); |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 561 | } |
Harald Welte | da9d938 | 2020-12-07 15:53:57 +0100 | [diff] [blame] | 562 | /* tolerate a late NS-BLOCK-ACK from peer */ |
| 563 | [] NSCP.receive(tr_NS_BLOCK_ACK(g_nsvc_config.nsvci)) -> value rf { |
| 564 | } |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 565 | [] Tns_block.timeout { |
| 566 | /* repeat unblock transmission */ |
| 567 | f_sendUnblock(); |
| 568 | } |
| 569 | } |
| 570 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 571 | private altstep as_alive_unblocked() runs on NSVC_CT { |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 572 | var NsUnitdataRequest ud_req; |
Harald Welte | 013d65a | 2020-09-13 14:41:31 +0200 | [diff] [blame] | 573 | var PDU_NS rf; |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 574 | /* bogus unblock, just respond with ACK */ |
| 575 | [] NSCP.receive(t_NS_UNBLOCK) -> value rf { |
| 576 | NSCP.send(t_NS_UNBLOCK_ACK); |
| 577 | } |
| 578 | /* Respond to BLOCK with BLOCK-ACK + change state */ |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 579 | [] NSCP.receive(tr_NS_BLOCK(?, g_nsvc_config.nsvci)) -> value rf { |
| 580 | NSCP.send(ts_NS_BLOCK_ACK(g_nsvc_config.nsvci)); |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 581 | Tns_block.stop; |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 582 | f_change_state(NSVC_S_ALIVE_BLOCKED); |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 583 | } |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 584 | [] NSCP.receive(tr_NS_BLOCK_ACK(g_nsvc_config.nsvci)) -> value rf { |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 585 | Tns_block.stop; |
| 586 | } |
Harald Welte | da9d938 | 2020-12-07 15:53:57 +0100 | [diff] [blame] | 587 | /* tolerate a late NS-UNBLOCK-ACK from peer */ |
| 588 | [] NSCP.receive(t_NS_UNBLOCK_ACK) -> value rf { |
| 589 | } |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 590 | /* NS-UNITDATA PDU from network to NS-UNITDATA.ind to user */ |
| 591 | [] NSCP.receive(tr_NS_UNITDATA(?, ?, ?)) -> value rf { |
Harald Welte | 80a249a | 2020-11-17 19:57:40 +0100 | [diff] [blame] | 592 | NS_SP.send(ts_NsUdInd(g_config.nsei, g_nsvc_config.nsvci, |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 593 | oct2int(rf.pDU_NS_Unitdata.bVCI), |
| 594 | rf.pDU_NS_Unitdata.nS_SDU)); |
| 595 | } |
| 596 | /* NS-UNITDATA.req from user to NS-UNITDATA PDU on network */ |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 597 | [] NS_SP.receive(tr_NsUdReq(g_config.nsei, ?, ?, ?, omit)) -> value ud_req { |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 598 | /* using raw octetstring PDU */ |
| 599 | NSCP.send(ts_NS_UNITDATA(t_SduCtrlB, ud_req.bvci, ud_req.sdu)); |
| 600 | } |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 601 | [] NS_SP.receive(tr_NsUdReq(g_config.nsei, ?, ?, omit, ?)) -> value ud_req { |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 602 | /* using decoded BSSGP PDU that we need to encode first */ |
| 603 | var octetstring enc := enc_PDU_BSSGP(ud_req.bssgp); |
| 604 | NSCP.send(ts_NS_UNITDATA(t_SduCtrlB, ud_req.bvci, enc)); |
| 605 | } |
| 606 | } |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 607 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 608 | private altstep as_wait_reset() runs on NSVC_CT { |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 609 | var PDU_NS rf; |
Harald Welte | 3dd8355 | 2020-09-14 11:38:01 +0200 | [diff] [blame] | 610 | [] Tns_reset.timeout { |
| 611 | /* If the sending entity of an NS-RESET PDU receives no NS-RESET-ACK PDU before timer |
| 612 | * Tns-reset expires the corresponding NS-VCs shall remain blocked and dead and the |
| 613 | * entire reset procedure shall be repeated */ |
| 614 | f_sendReset(); |
| 615 | } |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 616 | [] 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] | 617 | Tns_reset.stop; |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 618 | f_change_state(NSVC_S_ALIVE_BLOCKED); |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 619 | f_sendAlive(); |
| 620 | f_sendUnblock(); |
| 621 | } |
| 622 | } |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 623 | |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 624 | private function f_ScanEvents() runs on NSVC_CT { |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 625 | var PDU_NS rf; |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 626 | while (true) { |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 627 | alt { |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 628 | [vc_state == NSVC_S_WAIT_RESET] as_wait_reset(); |
| 629 | [vc_state == NSVC_S_ALIVE_BLOCKED] as_alive_blocked(); |
| 630 | [vc_state == NSVC_S_ALIVE_UNBLOCKED] as_alive_unblocked(); |
Harald Welte | 4a6a663 | 2020-09-14 09:58:53 +0200 | [diff] [blame] | 631 | [] as_allstate(); |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 632 | } |
| 633 | } |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 634 | } |
| 635 | } |