blob: d01c7a21c22ac2779b6ccf7922f2bff875339499 [file] [log] [blame]
Harald Welte1733a382017-07-23 17:26:17 +02001module BSSGP_Emulation {
Harald Welte1733a382017-07-23 17:26:17 +02002
Harald Welte34b5a952019-05-27 11:54:11 +02003/* BSSGP Emulation in TTCN-3
Harald Weltef5365242021-01-17 13:46:57 +01004 * (C) 2018-2021 Harald Welte <laforge@gnumonks.org>
Harald Welte34b5a952019-05-27 11:54:11 +02005 * 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
Harald Welte5339b2e2020-10-04 22:52:56 +020011 *
12 * This code implements BSSGP asa hierarchy of components:
13 * - the main BSSGP_CT which runs on top of a NSE (NS Entity).
14 * - demultiplex based on BVCI. BVCI=0 is handled to a user port
15 * - a per-BVC BSSGP_BVC_CT which runs on top of BSSGP_CT, it handles
16 * one PTP BVCI (i.e. one cell)
17 * - demultiplex based on TLLI
18 * - a per-TLLI BSSGP_Client_CT which runs on top of BSSGP_BVC_CT
Harald Welte34b5a952019-05-27 11:54:11 +020019 */
20
Harald Welte5ac31492018-02-15 20:39:13 +010021import from General_Types all;
22import from Osmocom_Types all;
Harald Welte853c0ad2018-02-15 17:45:29 +010023import from NS_Types all;
24import from NS_Emulation all;
25import from BSSGP_Types all;
26import from Osmocom_Gb_Types all;
27import from IPL4asp_Types all;
Pau Espin Pedrol011e32f2021-02-05 12:07:04 +010028import from Misc_Helpers all;
Harald Welte1733a382017-07-23 17:26:17 +020029
Harald Welte93331e72020-09-12 20:51:05 +020030#ifdef BSSGP_EM_L3
Harald Welte5ac31492018-02-15 20:39:13 +010031import from MobileL3_GMM_SM_Types all;
32import from MobileL3_Types all;
Harald Welte93331e72020-09-12 20:51:05 +020033#endif
Harald Welte5ac31492018-02-15 20:39:13 +010034
35import from LLC_Types all;
36import from LLC_Templates all;
37
Harald Weltea2526a82018-02-18 19:03:36 +010038import from SNDCP_Types all;
39
Harald Welte5ac31492018-02-15 20:39:13 +010040/***********************************************************************
Harald Welte5339b2e2020-10-04 22:52:56 +020041 * Communication between Client Components and per-BVC component
Harald Welte5ac31492018-02-15 20:39:13 +010042 ***********************************************************************/
43
Harald Welte853c0ad2018-02-15 17:45:29 +010044type record BssgpStatusIndication {
Harald Welte5339b2e2020-10-04 22:52:56 +020045 Nsei nsei optional,
Harald Welte853c0ad2018-02-15 17:45:29 +010046 BssgpBvci bvci,
47 BvcState state
Harald Welte5339b2e2020-10-04 22:52:56 +020048};
49
50type record BssgpResetIndication {
51 BssgpBvci bvci
52};
53
54template (value) BssgpStatusIndication
55ts_BssgpStsInd(template (omit) Nsei nsei, template (value) BssgpBvci bvci,
56 template (value) BvcState state) := {
57 nsei := nsei,
58 bvci := bvci,
59 state := state
Harald Welte853c0ad2018-02-15 17:45:29 +010060}
61
Harald Welte5339b2e2020-10-04 22:52:56 +020062template (present) BssgpStatusIndication
63tr_BssgpStsInd(template Nsei nsei, template (present) BssgpBvci bvci,
64 template (present) BvcState state) := {
Harald Welte853c0ad2018-02-15 17:45:29 +010065 nsei := nsei,
66 bvci := bvci,
67 state := state
68}
69
70type enumerated BvcState {
Harald Welte5339b2e2020-10-04 22:52:56 +020071 /* SGSN role: waiting to be reset by the peer */
72 BVC_S_WAIT_RESET,
73 /* PCU role: waiting for NS_ALIVE_UNBLOCKED */
74 BVC_S_WAIT_NS_ALIVE_UNBLOCKED,
75 /* BVC-BLOCKED state */
Harald Welte853c0ad2018-02-15 17:45:29 +010076 BVC_S_BLOCKED,
Harald Welte5339b2e2020-10-04 22:52:56 +020077 /* BVC-UNBLOCKED state */
Harald Welte853c0ad2018-02-15 17:45:29 +010078 BVC_S_UNBLOCKED
79};
80
81/* port from our (internal) point of view */
82type port BSSGP_SP_PT message {
Harald Welte5ac31492018-02-15 20:39:13 +010083 in PDU_BSSGP,
Harald Welte93331e72020-09-12 20:51:05 +020084 PDU_LLC
85#ifdef BSSGP_EM_L3
86 ,
Harald Welte5ac31492018-02-15 20:39:13 +010087 PDU_L3_MS_SGSN,
Harald Welte93331e72020-09-12 20:51:05 +020088 PDU_L3_SGSN_MS
89#endif
90 ;
Harald Welte955aa942019-05-03 01:29:29 +020091 out PDU_BSSGP,
92 PDU_LLC,
93 PDU_SN,
Harald Welte853c0ad2018-02-15 17:45:29 +010094 NsStatusIndication,
95 BssgpStatusIndication,
Harald Welte93331e72020-09-12 20:51:05 +020096 ASP_Event
97#ifdef BSSGP_EM_L3
98 ,
Harald Welte5ac31492018-02-15 20:39:13 +010099 PDU_L3_MS_SGSN,
Harald Welte93331e72020-09-12 20:51:05 +0200100 PDU_L3_SGSN_MS
101#endif
102 ;
Harald Welte853c0ad2018-02-15 17:45:29 +0100103} with { extension "internal" };
104
105/* port from the user point of view */
106type port BSSGP_PT message {
107 in ASP_Event,
108 NsStatusIndication,
109 BssgpStatusIndication,
Harald Welte955aa942019-05-03 01:29:29 +0200110 PDU_BSSGP,
111 PDU_LLC,
Harald Welte93331e72020-09-12 20:51:05 +0200112 PDU_SN
113#ifdef BSSGP_EM_L3
114 ,
Harald Welte5ac31492018-02-15 20:39:13 +0100115 PDU_L3_MS_SGSN,
Harald Welte93331e72020-09-12 20:51:05 +0200116 PDU_L3_SGSN_MS
117#endif
118 ;
Harald Welte5ac31492018-02-15 20:39:13 +0100119 out PDU_BSSGP,
Harald Welte93331e72020-09-12 20:51:05 +0200120 PDU_LLC
121#ifdef BSSGP_EM_L3
122 ,
Harald Welte5ac31492018-02-15 20:39:13 +0100123 PDU_L3_SGSN_MS,
Harald Welte93331e72020-09-12 20:51:05 +0200124 PDU_L3_MS_SGSN
125#endif
126 ;
Harald Welte853c0ad2018-02-15 17:45:29 +0100127} with { extension "internal" };
128
Harald Welte5339b2e2020-10-04 22:52:56 +0200129signature BSSGP_register_client(hexstring imsi, OCT4 tlli);
Harald Welte5ac31492018-02-15 20:39:13 +0100130signature BSSGP_unregister_client(hexstring imsi);
Harald Weltef70997d2018-02-17 10:11:19 +0100131signature BSSGP_llgmm_assign(OCT4 tlli_old, OCT4 tlli);
Harald Welte5ac31492018-02-15 20:39:13 +0100132
133type port BSSGP_PROC_PT procedure {
Harald Weltef70997d2018-02-17 10:11:19 +0100134 inout BSSGP_register_client, BSSGP_unregister_client, BSSGP_llgmm_assign;
Harald Welte5ac31492018-02-15 20:39:13 +0100135} with { extension "internal" };
136
137
Harald Welte5339b2e2020-10-04 22:52:56 +0200138
Harald Welte5ac31492018-02-15 20:39:13 +0100139/***********************************************************************
140 * Client Component for a single MS/TLLI
Harald Welte5339b2e2020-10-04 22:52:56 +0200141 ***********************************************************************
142 * This is what most users will want to derive their test cases from. It
143 * provides a set of three different ports (PTP, signaling, procedure)
144 * for (currently up to 3) different Cells. Those ports are all connected
145 * to one or multiple different per-BVC compoennts, depending on whether
146 * they share the same BSS or not.
Harald Welte5ac31492018-02-15 20:39:13 +0100147 ***********************************************************************/
148
149type component BSSGP_Client_CT {
Harald Welte5339b2e2020-10-04 22:52:56 +0200150 /* one port array for each client; allows talking to up to 3 BVC/Cell (handover, ...) */
151 port BSSGP_PT BSSGP[3]; /* PTP-BVC */
152 port BSSGP_PT BSSGP_SIG[3]; /* Signaling BVC */
Harald Welte9b461a92020-12-10 23:41:14 +0100153 port BSSGP_PT BSSGP_GLOBAL[3]; /* Signaling BVC */
Harald Welte5339b2e2020-10-04 22:52:56 +0200154 port BSSGP_PROC_PT BSSGP_PROC[3]; /* registration / deregistration */
Harald Welte5ac31492018-02-15 20:39:13 +0100155};
156
Harald Welte5339b2e2020-10-04 22:52:56 +0200157function f_bssgp_client_register(hexstring imsi, OCT4 tlli, BSSGP_PROC_PT PT := BSSGP_PROC[0])
158runs on BSSGP_Client_CT {
159 PT.call(BSSGP_register_client:{imsi, tlli}) {
160 [] PT.getreply(BSSGP_register_client:{imsi, tlli}) {};
161 }
162}
163
164function f_bssgp_client_unregister(hexstring imsi, BSSGP_PROC_PT PT := BSSGP_PROC[0])
165runs on BSSGP_Client_CT {
166 PT.call(BSSGP_unregister_client:{imsi}) {
167 [] PT.getreply(BSSGP_unregister_client:{imsi}) {};
168 }
169}
170
171/* TS 44.064 7.2.1.1 LLGMM-ASSIGN */
172function f_bssgp_client_llgmm_assign(OCT4 tlli_old, OCT4 tlli_new, BSSGP_PROC_PT PT := BSSGP_PROC[0])
173runs on BSSGP_Client_CT {
174 PT.call(BSSGP_llgmm_assign:{tlli_old, tlli_new}) {
175 [] PT.getreply(BSSGP_llgmm_assign:{tlli_old, tlli_new}) {};
176 }
177}
178
Harald Welte5ac31492018-02-15 20:39:13 +0100179/***********************************************************************
180 * Main Component
Harald Welte5339b2e2020-10-04 22:52:56 +0200181 ***********************************************************************
182 * This component exists once, and it runs on to of the NS_Emulation.
183 * It handles the BVC-RESET for the signaling BVCI, and dispatches messages
184 * to the per-BVC components running above it. Messages are routed by:
185 * - PTP BVCI in NS header (if non-0)
186 * - BVCI IE in messages on BVCI=0 in NS header
187 * Messages for which no unique BVC can be identified (like paging without
188 * a BVCI IE set) are broadcast to all BVC components.
189 * We also broadcast state changes (BssgpStatusIndication) and reset events
190 * (BssgpResetIndication) of the signaling BVC to all per-BVC components.
Harald Welte5ac31492018-02-15 20:39:13 +0100191 ***********************************************************************/
192
Harald Welte5339b2e2020-10-04 22:52:56 +0200193function BssgpStart(BssgpConfig cfg, charstring id) runs on BSSGP_CT {
Harald Welte5ac31492018-02-15 20:39:13 +0100194 g_cfg := cfg;
Harald Welte5339b2e2020-10-04 22:52:56 +0200195
196 /* create the per-BVC components based on the configuration */
197 for (var integer i := 0; i < lengthof(g_cfg.bvc); i := i+1) {
198 var BssgpBvcConfig bvc_cfg := g_cfg.bvc[i];
199 var charstring bvc_id := id & "-BVCI" & int2str(bvc_cfg.bvci);
200 /* create, connect and start the BVC component */
Pau Espin Pedrolee57d1c2022-02-22 15:53:48 +0100201 var BSSGP_BVC_CT bvc_ct := BSSGP_BVC_CT.create(bvc_id) alive;
Harald Welte5339b2e2020-10-04 22:52:56 +0200202 connect(bvc_ct:BVC, self:BVC);
Harald Weltefba7afd2020-11-24 23:12:31 +0100203 bvc_ct.start(f_bssgp_bvc_main(bvc_cfg, g_cfg.sgsn_role, g_cfg.nsei, bvc_id));
Harald Welte5339b2e2020-10-04 22:52:56 +0200204 /* populate the BVC state table */
205 BvcTable[i] := {
206 bvci := bvc_cfg.bvci,
207 cell_id := bvc_cfg.cell_id,
208 comp_ref := bvc_ct
209 };
210 }
211
212 if (g_cfg.sgsn_role) {
213 /* The SGSN side waits for an inbound BVC-RESET on the signaling BVC */
214 f_sign_change_state(BVC_S_WAIT_RESET);
215 } else {
216 /* The BSS/PCU side waits for an inbound NsStatusIndication to Tx BVC-RESET */
217 f_sign_change_state(BVC_S_WAIT_NS_ALIVE_UNBLOCKED);
218 }
219
220 /* main loop */
221 f_bssgp_ScanEvents();
Harald Welte853c0ad2018-02-15 17:45:29 +0100222}
223
Harald Welte5339b2e2020-10-04 22:52:56 +0200224/* master component, exists once per BSSGP instance (NSE) */
Harald Welte853c0ad2018-02-15 17:45:29 +0100225type component BSSGP_CT {
Stefan Sperlingf82bbb62018-05-03 19:14:28 +0200226 /* UDP ports towards the bottom (IUT) */
Harald Welte853c0ad2018-02-15 17:45:29 +0100227 port NS_PT BSCP;
Harald Welte5339b2e2020-10-04 22:52:56 +0200228
229 /* control by the user */
230 port BSSGP_CT_PROC_PT PROC;
231
Harald Welte57de2202020-11-24 18:15:02 +0100232 /* global port for procedures without any relation to a BVC
233 * (currently only) SUSPEND/RESUME */
234 port BSSGP_SP_PT GLOBAL;
235
Harald Welte0083ea62020-12-02 21:30:44 +0100236 /* RAN INFORMATION MGMT */
237 port BSSGP_SP_PT RIM;
238
Harald Weltebdf96d82020-11-27 18:58:46 +0100239 /* port to a management instance */
240 port BSSGP_BVC_MGMT_SP_PT MGMT;
241
Harald Welte5339b2e2020-10-04 22:52:56 +0200242 var BssgpConfig g_cfg;
243
244 /* Signaling BVC (BVCI=0) */
245 var BvcState g_sign_bvc_state := BVC_S_WAIT_RESET;
246 timer g_T2 := 60.0;
247
248 /* port to per-BVC components */
249 port BSSGP_BVC_SP_PT BVC;
250 /* per-BVC state table */
Harald Welte633805b2021-02-03 17:47:18 +0100251 var BvcEntity BvcTable[64];
Harald Welte5339b2e2020-10-04 22:52:56 +0200252};
253
254/* one element in the per-BVC state table */
255type record BvcEntity {
256 /* PTP BVCI of this BVC/Cell */
257 BssgpBvci bvci,
258 /* Cell Identity of this cell */
259 BssgpCellId cell_id,
260 /* reference to the per-BVC/cell component */
261 BSSGP_BVC_CT comp_ref
262};
263
264/* find the per-BVC component for a given BVCI */
265private function f_comp_for_bvci(BssgpBvci bvci) runs on BSSGP_CT return BSSGP_BVC_CT {
266 var integer i;
267
268 for (i := 0; i < lengthof(BvcTable); i := i+1) {
269 if (BvcTable[i].bvci == bvci) {
270 return BvcTable[i].comp_ref;
271 }
272 }
273 return null;
274}
275
276/* We are in BVC_S_WAIT_RSET state (only happens in SGSN role) */
277altstep as_sig_wait_reset() runs on BSSGP_CT {
278 var NsUnitdataIndication udi;
279
280 /* Respond to RESET for signalling BVCI 0 */
281 [] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, 0, omit), 0)) -> value udi {
282 log("Rx BVC-RESET for Signaling BVCI=0");
Harald Welte5339b2e2020-10-04 22:52:56 +0200283 f_sign_change_state(BVC_S_UNBLOCKED);
Harald Weltebdf96d82020-11-27 18:58:46 +0100284 if (MGMT.checkstate("Connected")) {
285 MGMT.send(BssgpResetIndication:{0});
286 }
287 BSCP.send(f_BnsUdReq(ts_BVC_RESET_ACK(0, omit), 0, 0));
Harald Welte5339b2e2020-10-04 22:52:56 +0200288 }
Harald Welte5339b2e2020-10-04 22:52:56 +0200289}
290
Harald Welte27a70cc2020-12-09 11:57:41 +0100291private template PDU_BSSGP tr_GLOBAL_SIG := (
Harald Welte57de2202020-11-24 18:15:02 +0100292 {pDU_BSSGP_SUSPEND:=?}, {pDU_BSSGP_SUSPEND_ACK:=?}, {pDU_BSSGP_SUSPEND_NACK:=?},
Harald Weltef8e5c5d2020-11-27 22:37:23 +0100293 {pDU_BSSGP_RESUME:=?}, {pDU_BSSGP_RESUME_ACK:=?}, {pDU_BSSGP_RESUME_NACK:=?},
Harald Weltef5365242021-01-17 13:46:57 +0100294 {pDU_BSSGP_SGSN_INVOKE_TRACE:=?}, {pDU_BSSGP_OVERLOAD:=?}, {pDU_BSSGP_STATUS:=?}
Harald Welte57de2202020-11-24 18:15:02 +0100295);
296
Harald Welte0083ea62020-12-02 21:30:44 +0100297/* BSSGP messages that should arrive on the RIM port */
298private template PDU_BSSGP tr_RIM := (
299 {pDU_BSSGP_RAN_INFORMATION:=?}, {pDU_BSSGP_RAN_INFORMATION_REQUEST:=?},
300 {pDU_BSSGP_RAN_INFORMATION_ACK:=?}, {pDU_BSSGP_RAN_INFORMATION_ERROR:=?},
301 {pDU_BSSGP_RAN_INFORMATION_APPLICATION_ERROR:=?}
302);
303
Harald Welte5339b2e2020-10-04 22:52:56 +0200304/* We are in BVC_S_UNBLOCKED state */
305altstep as_sig_unblocked() runs on BSSGP_CT {
306 var BSSGP_BVC_CT bvc_comp_ref;
307 var BSSGP_Client_CT vc_conn;
308 var NsUnitdataIndication udi;
309 var NsUnitdataRequest udr;
Harald Welte57de2202020-11-24 18:15:02 +0100310 var PDU_BSSGP bssgp;
Harald Welte5339b2e2020-10-04 22:52:56 +0200311
312 /* Messages PTP BVCI in BVCI field of NS: dispatch by that */
313 [] BSCP.receive(f_BnsUdInd(?, (2..65535))) -> value udi {
314 bvc_comp_ref := f_comp_for_bvci(valueof(udi.bvci));
315 if (isbound(bvc_comp_ref) and bvc_comp_ref != null) {
316 /* dispatch to BVC component */
317 BVC.send(udi) to bvc_comp_ref;
318 } else {
319 setverdict(fail, "Rx BSSGP for unknown PTP BVCI ", udi.bvci, ": ", udi.bssgp);
Harald Weltec4505522020-11-11 18:55:09 +0100320 BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(udi.bvci, BSSGP_CAUSE_BVCI_UNKNOWN, udi.bssgp), udi.bvci, 0));
Harald Welte5339b2e2020-10-04 22:52:56 +0200321 }
322 }
323
324 /* Messages with BVCI = 0 (Signaling) in BVCI field of NS */
Harald Welte27a70cc2020-12-09 11:57:41 +0100325 [] BSCP.receive(f_BnsUdInd(tr_GLOBAL_SIG, 0)) -> value udi {
Daniel Willmannc5bbcc62021-09-24 13:17:20 +0200326 if (GLOBAL.checkstate("Connected")) {
327 GLOBAL.send(udi.bssgp);
328 }
Harald Welte57de2202020-11-24 18:15:02 +0100329 }
Harald Welte0083ea62020-12-02 21:30:44 +0100330 [] BSCP.receive(f_BnsUdInd(tr_RIM, 0)) -> value udi {
331 if (RIM.checkstate("Connected")) {
332 RIM.send(udi.bssgp);
333 }
334 }
Harald Welte5339b2e2020-10-04 22:52:56 +0200335
Daniel Willmannef8e50e2021-11-26 11:41:50 +0100336 /* Broadcast FLUSH_LL_ACK no matter the BVCI */
337 [] BSCP.receive(f_BnsUdInd(tr_BSSGP_FLUSH_LL_ACK(?, ?, ?), 0)) -> value udi {
338 log("Rx FLUSH_LL_ACK: broadcasting");
339 for (var integer i := 0; i < lengthof(BvcTable); i := i+1) {
340 if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) {
341 BVC.send(udi) to BvcTable[i].comp_ref;
342 }
343 }
344 }
345
Harald Welte5339b2e2020-10-04 22:52:56 +0200346 /* Route based on PTP BVCI in payload/IE of signaling PDU */
347 [] BSCP.receive(f_BnsUdInd(?, 0)) -> value udi {
348 var template (omit) BssgpBvci ptp_bvci := f_BSSGP_BVCI_get(udi.bssgp);
349 if (istemplatekind(ptp_bvci, "omit")) {
350 log("Rx on SIG BVCI without PTP BVCI: broadcasting");
351 for (var integer i := 0; i < lengthof(BvcTable); i := i+1) {
352 if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) {
353 BVC.send(udi) to BvcTable[i].comp_ref;
354 }
355 }
356 } else {
357 bvc_comp_ref := f_comp_for_bvci(valueof(ptp_bvci));
358 if (isbound(bvc_comp_ref) and bvc_comp_ref != null) {
359 /* dispatch to BVC component */
360 BVC.send(udi) to bvc_comp_ref;
361 } else {
362 setverdict(fail, "Rx SIG BSSGP for unknown PTP BVCI ", ptp_bvci, ": ", udi.bssgp);
Harald Weltec4505522020-11-11 18:55:09 +0100363 BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(udi.bvci, BSSGP_CAUSE_BVCI_UNKNOWN, udi.bssgp), 0, 0));
Pau Espin Pedrol847a1652021-02-05 12:08:04 +0100364 }
Harald Welte5339b2e2020-10-04 22:52:56 +0200365 }
366 }
367
368 /* Handle PS-PAGING on SIGN BVCI with no conditional BVCI IE */
369 [] BSCP.receive(f_BnsUdInd(PDU_BSSGP:{pDU_BSSGP_PAGING_PS:=?}, 0)) -> value udi {
370 /* FIXME: use LA, RA or BSS Area to dispatch instead of broadcast */
371 for (var integer i := 0; i < lengthof(BvcTable); i := i+1) {
372 if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) {
373 BVC.send(udi) to BvcTable[i].comp_ref;
374 }
375 }
376 }
377 /* Handle CS-PAGING on SIGN BVCI with no conditional BVCI IE */
378 [] BSCP.receive(f_BnsUdInd(PDU_BSSGP:{pDU_BSSGP_PAGING_CS:=?}, 0)) -> value udi {
379 /* FIXME: use LA, RA or BSS Area to dispatch instead of broadcast */
380 for (var integer i := 0; i < lengthof(BvcTable); i := i+1) {
381 if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) {
382 BVC.send(udi) to BvcTable[i].comp_ref;
383 }
384 }
385 }
386
387 /* per-BVC component sends us something; forward to NS without any validation */
388 [] BVC.receive(NsUnitdataRequest:?) -> value udr {
389 /* patch in the NSEI, as the per-BVC components have no idea about it */
390 udr.nsei := g_cfg.nsei;
391 BSCP.send(udr);
392 }
Harald Welte57de2202020-11-24 18:15:02 +0100393
Harald Welte27a70cc2020-12-09 11:57:41 +0100394 [] GLOBAL.receive(tr_GLOBAL_SIG) -> value bssgp {
Harald Welte57de2202020-11-24 18:15:02 +0100395 BSCP.send(f_BnsUdReq(bssgp, 0, 0));
396 }
Harald Welte0083ea62020-12-02 21:30:44 +0100397
398 [] RIM.receive(tr_RIM) -> value bssgp {
399 BSCP.send(f_BnsUdReq(bssgp, 0, 0));
400 }
401
Harald Welte5339b2e2020-10-04 22:52:56 +0200402}
403
404/* We are in BVC_S_WAIT_NS_ALIVE_UNBLOCKED (only happens in BSS role) */
405altstep as_sig_wait_ns_alive_unblocked() runs on BSSGP_CT {
406 var NsStatusIndication nsi;
Harald Weltedc0a0902020-11-10 21:03:29 +0100407 [] BSCP.receive(NsStatusIndication:{g_cfg.nsei,?, complement (NSVC_S_ALIVE_UNBLOCKED), NSVC_S_ALIVE_UNBLOCKED, true}) -> value nsi {
Harald Welte5339b2e2020-10-04 22:52:56 +0200408 /* if we just became NS-unblocked, send a BCC-RESET */
409 if (g_cfg.sgsn_role == false) {
Harald Weltec4505522020-11-11 18:55:09 +0100410 BSCP.send(f_BnsUdReq(ts_BVC_RESET(BSSGP_CAUSE_OM_INTERVENTION, 0, omit), 0, 0));
Harald Welte5339b2e2020-10-04 22:52:56 +0200411 g_T2.start;
412 /* The BVC_RESET_ACK is handled in the as_sig_allstate() below */
413 }
414 /* Idea: We could send BVC-UNBLOCK here like some SGSN do */
415 }
416
417}
418
Harald Weltee5887922020-11-27 19:04:46 +0100419/* handling of events irrespective of BVC state (before state-specific handling) */
420altstep as_sig_allstate_pre() runs on BSSGP_CT {
421 var NsUnitdataIndication udi;
422
423 /* Respond to RESET for signalling BVCI 0 */
424 [] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, 0, omit), 0)) -> value udi {
425 log("Rx BVC-RESET for Signaling BVCI=0");
426 if (MGMT.checkstate("Connected")) {
427 MGMT.send(BssgpResetIndication:{0});
428 }
429 BSCP.send(f_BnsUdReq(ts_BVC_RESET_ACK(0, omit), 0, 0));
430 for (var integer i := 0; i < sizeof(BvcTable); i := i+1) {
431 if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) {
432 BVC.send(BssgpResetIndication:{0}) to BvcTable[i].comp_ref;
433 }
434 }
435 }
436
437 /* any BLOCK or UNBLOCK for the SIGNALING BVCI are illegal */
Pau Espin Pedrol6ee01262021-02-05 13:05:06 +0100438 [] BSCP.receive(f_BnsUdInd(tr_BVC_BLOCK(0, ?), 0)) -> value udi {
Harald Weltee5887922020-11-27 19:04:46 +0100439 setverdict(fail, "Rx BVC-BLOCK illegal for BVCI=0: ", udi);
440 }
Pau Espin Pedrol6ee01262021-02-05 13:05:06 +0100441 [] BSCP.receive(f_BnsUdInd(tr_BVC_UNBLOCK(0), 0)) -> value udi {
Harald Weltee5887922020-11-27 19:04:46 +0100442 setverdict(fail, "Rx BVC-UNBLOCK illegal for BVCI=0: ", udi);
443 }
Pau Espin Pedrol6ee01262021-02-05 13:05:06 +0100444 [] BSCP.receive(f_BnsUdInd(tr_BVC_BLOCK_ACK(0), 0)) -> value udi {
Harald Weltee5887922020-11-27 19:04:46 +0100445 setverdict(fail, "Rx BVC-BLOCK-ACK illegal for BVCI=0: ", udi);
446 }
Pau Espin Pedrol6ee01262021-02-05 13:05:06 +0100447 [] BSCP.receive(f_BnsUdInd(tr_BVC_UNBLOCK_ACK(0), 0)) -> value udi {
Harald Weltee5887922020-11-27 19:04:46 +0100448 setverdict(fail, "Rx BVC-UNBLOCK-ACK illegal for BVCI=0: ", udi);
449 }
450
451 /* BVC-RESET-ACK for BVCI=0 while T2 is running: Answer to a BVC-RESET we sent earlier */
452 [g_T2.running] BSCP.receive(f_BnsUdInd(tr_BVC_RESET_ACK(0, omit), 0)) -> value udi {
453 log("BVCI(0) Rx BVC-RESET-ACK");
454 g_T2.stop;
455 f_sign_change_state(BVC_S_UNBLOCKED);
456 for (var integer i := 0; i < sizeof(BvcTable); i := i+1) {
457 if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) {
458 BVC.send(BssgpResetIndication:{0}) to BvcTable[i].comp_ref;
459 }
460 }
461 }
Pau Espin Pedrol8afdee12022-02-22 15:30:26 +0100462 [g_T2.running] g_T2.timeout {
Harald Weltee5887922020-11-27 19:04:46 +0100463 setverdict(fail, "Timeout waiting for BVC-RESET-ACK on BVCI=0");
464 BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(udi.bvci, BSSGP_CAUSE_BVCI_UNKNOWN, udi.bssgp), 0, 0));
465 g_T2.start;
466 }
467}
468
469/* handling of events irrespective of BVC state (after state-specific handling) */
470altstep as_sig_allstate_post() runs on BSSGP_CT {
Harald Welte5339b2e2020-10-04 22:52:56 +0200471 var BSSGP_Client_CT vc_conn;
472 var NsUnitdataIndication udi;
473 var NsStatusIndication nsi;
474 var ASP_Event evt;
475 var BSSGP_BVC_CT bvc_comp_ref;
476 var BssgpBvci bvci;
Harald Weltee5887922020-11-27 19:04:46 +0100477 var BssgpResetRequest brr;
Harald Welte5339b2e2020-10-04 22:52:56 +0200478
479 /* Respond to RESET for signalling BVCI 0 */
480 [] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, 0, omit), 0)) -> value udi {
481 log("Rx BVC-RESET for Signaling BVCI=0");
Harald Weltebdf96d82020-11-27 18:58:46 +0100482 if (MGMT.checkstate("Connected")) {
483 MGMT.send(BssgpResetIndication:{0});
484 }
Harald Weltec4505522020-11-11 18:55:09 +0100485 BSCP.send(f_BnsUdReq(ts_BVC_RESET_ACK(0, omit), 0, 0));
Harald Welte5339b2e2020-10-04 22:52:56 +0200486 for (var integer i := 0; i < sizeof(BvcTable); i := i+1) {
487 if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) {
488 BVC.send(BssgpResetIndication:{0}) to BvcTable[i].comp_ref;
489 }
490 }
491 }
492
493 /* any BLOCK or UNBLOCK for the SIGNALING BVCI are illegal */
Pau Espin Pedrol6ee01262021-02-05 13:05:06 +0100494 [] BSCP.receive(f_BnsUdInd(tr_BVC_BLOCK(0, ?), 0)) -> value udi {
Harald Welte5339b2e2020-10-04 22:52:56 +0200495 setverdict(fail, "Rx BVC-BLOCK illegal for BVCI=0: ", udi);
496 }
Pau Espin Pedrol6ee01262021-02-05 13:05:06 +0100497 [] BSCP.receive(f_BnsUdInd(tr_BVC_UNBLOCK(0), 0)) -> value udi {
Harald Welte5339b2e2020-10-04 22:52:56 +0200498 setverdict(fail, "Rx BVC-UNBLOCK illegal for BVCI=0: ", udi);
499 }
Pau Espin Pedrol6ee01262021-02-05 13:05:06 +0100500 [] BSCP.receive(f_BnsUdInd(tr_BVC_BLOCK_ACK(0), 0)) -> value udi {
Harald Welte5339b2e2020-10-04 22:52:56 +0200501 setverdict(fail, "Rx BVC-BLOCK-ACK illegal for BVCI=0: ", udi);
502 }
Pau Espin Pedrol6ee01262021-02-05 13:05:06 +0100503 [] BSCP.receive(f_BnsUdInd(tr_BVC_UNBLOCK_ACK(0), 0)) -> value udi {
Harald Welte5339b2e2020-10-04 22:52:56 +0200504 setverdict(fail, "Rx BVC-UNBLOCK-ACK illegal for BVCI=0: ", udi);
505 }
506
507 /* Respond to BLOCK for wrong BVCI */
Pau Espin Pedrol6ee01262021-02-05 13:05:06 +0100508 [] BSCP.receive(f_BnsUdInd(tr_BVC_BLOCK(?, ?), 0)) -> value udi {
Harald Welte5339b2e2020-10-04 22:52:56 +0200509 setverdict(fail, "Rx BVC-BLOCK for unknown BVCI");
Harald Weltec4505522020-11-11 18:55:09 +0100510 BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(0, BSSGP_CAUSE_BVCI_UNKNOWN, udi.bssgp), 0, 0));
Harald Welte5339b2e2020-10-04 22:52:56 +0200511 }
512
513 /* Respond to RESET with wrong BVCI */
514 [] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, ?, ?), 0)) -> value udi {
515 var BssgpBvci ptp_bvci := oct2int(udi.bssgp.pDU_BSSGP_BVC_RESET.bVCI.unstructured_value);
516 setverdict(fail, "Rx BVC-RESET for unknown BVCI ", ptp_bvci);
Harald Weltec4505522020-11-11 18:55:09 +0100517 BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(ptp_bvci, BSSGP_CAUSE_BVCI_UNKNOWN, udi.bssgp), 0, 0));
Harald Welte5339b2e2020-10-04 22:52:56 +0200518 }
519
Harald Welte5339b2e2020-10-04 22:52:56 +0200520 /* Forwarding of ASP_Event to per-BVC components */
521 [] BSCP.receive(ASP_Event:?) -> value evt {
522 for (var integer i := 0; i < sizeof(BvcTable); i := i+1) {
523 if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) {
524 BVC.send(evt) to BvcTable[i].comp_ref;
525 }
526 }
527 }
528 /* Keep NS Status Indicaitons to us; no need to inform per-BVC components [for now?] */
Harald Weltedc0a0902020-11-10 21:03:29 +0100529 [] BSCP.receive(tr_NsStsInd(g_cfg.nsei)) -> value nsi { }
Harald Welte445fc612020-11-10 19:15:30 +0100530 /* We should never see any different NSEI: There's one BSSGP_CT per NSE */
Harald Weltedc0a0902020-11-10 21:03:29 +0100531 [] BSCP.receive(tr_NsStsInd(?)) -> value nsi {
Harald Welte445fc612020-11-10 19:15:30 +0100532 setverdict(fail, "Rx NsStatusInd for wrong NSEI ", nsi);
533 }
Harald Welte5339b2e2020-10-04 22:52:56 +0200534
535 /* Procedure port request to resolve the per-BVC component for a given ptp BVCI */
536 [] PROC.getcall(BSSGP_get_bvci_ct:{?}) -> param(bvci) sender vc_conn {
537 for (var integer i := 0; i < sizeof(BvcTable); i := i+1) {
538 if (BvcTable[i].bvci == bvci) {
539 PROC.reply(BSSGP_get_bvci_ct:{bvci} value BvcTable[i].comp_ref) to vc_conn;
540 return;
541 }
542 }
543 }
Harald Weltee5887922020-11-27 19:04:46 +0100544
545 /* default case of handling unknown PDUs */
546 [] BSCP.receive(f_BnsUdInd(?, ?)) -> value udi {
547 setverdict(fail, "Rx Unexpected BSSGP PDU ", udi.bssgp," in state ", g_sign_bvc_state);
548 BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(0, BSSGP_CAUSE_PDU_NOT_COMPATIBLE_WITH_PROTOCOL_STATE, udi.bssgp), 0, 0));
549 }
550
551 [] MGMT.receive(BssgpResetRequest:?) -> value brr {
552 BSCP.send(f_BnsUdReq(ts_BVC_RESET(brr.cause, 0, omit), 0, 0));
553 g_T2.start;
554 }
Harald Welte5339b2e2020-10-04 22:52:56 +0200555}
556
557/* send the highest decoded layer of the message through given port */
558private function f_send_bssgp_dec(BssgpDecoded dec, BSSGP_Client_CT vc_conn, BSSGP_SP_PT pt) {
559#ifdef BSSGP_EM_L3
560 if (ispresent(dec.l3_mt)) {
561 pt.send(dec.l3_mt) to vc_conn;
562 } else if (ispresent(dec.l3_mo)) {
563 pt.send(dec.l3_mo) to vc_conn;
564 } else
565#endif
566 if (ispresent(dec.sndcp)) {
567 pt.send(dec.sndcp) to vc_conn;
568 } else if (ispresent(dec.llc)) {
569 pt.send(dec.llc) to vc_conn;
570 } else {
571 pt.send(dec.bssgp) to vc_conn;
572 }
573}
574
575
576function f_llc_get_n_u_tx(inout LLC_Entity llc) return uint9_t {
577 var uint9_t ret := llc.n_u_tx_next;
578 llc.n_u_tx_next := llc.n_u_tx_next + 1;
579 return ret;
580}
581
582#ifdef BSSGP_EM_L3
583function f_llc_sapi_by_l3_mo(PDU_L3_MS_SGSN l3_mo) return BIT4 {
584 if (ischosen(l3_mo.msgs.gprs_mm)) {
585 return c_LLC_SAPI_LLGMM;
586 } else if (ischosen(l3_mo.msgs.gprs_sm)) {
587 return c_LLC_SAPI_LLGMM;
588 } else if (ischosen(l3_mo.msgs.sms)) {
589 return c_LLC_SAPI_LLSMS;
590 }
Pau Espin Pedrol011e32f2021-02-05 12:07:04 +0100591 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No LLC SAPI for ", l3_mo));
592 return '0000'B;
Harald Welte5339b2e2020-10-04 22:52:56 +0200593}
594
595private function f_llc_sapi_by_l3_mt(PDU_L3_SGSN_MS l3_mt) return BIT4 {
596 if (ischosen(l3_mt.msgs.gprs_mm)) {
597 return c_LLC_SAPI_LLGMM;
598 } else if (ischosen(l3_mt.msgs.gprs_sm)) {
599 return c_LLC_SAPI_LLGMM;
600 } else if (ischosen(l3_mt.msgs.sms)) {
601 return c_LLC_SAPI_LLSMS;
602 }
Pau Espin Pedrol011e32f2021-02-05 12:07:04 +0100603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No LLC SAPI for ", l3_mt));
604 return '0000'B;
Harald Welte5339b2e2020-10-04 22:52:56 +0200605}
606#endif
607
608/* main loop of BSSGP_CT */
609private function f_bssgp_ScanEvents() runs on BSSGP_CT {
610 while (true) {
611 alt {
612 [g_sign_bvc_state == BVC_S_WAIT_RESET] as_sig_wait_reset();
Harald Weltee5887922020-11-27 19:04:46 +0100613 [] as_sig_allstate_pre();
Harald Welte5339b2e2020-10-04 22:52:56 +0200614 [g_sign_bvc_state == BVC_S_WAIT_NS_ALIVE_UNBLOCKED] as_sig_wait_ns_alive_unblocked();
615 [g_sign_bvc_state == BVC_S_UNBLOCKED] as_sig_unblocked();
Harald Weltee5887922020-11-27 19:04:46 +0100616 [g_sign_bvc_state == BVC_S_WAIT_RESET] as_sig_wait_reset();
617 [] as_sig_allstate_post();
Harald Welte5339b2e2020-10-04 22:52:56 +0200618 }
619 } /* while */
620}
621
622/* generate a send template. Cannot be a real template as we want to use g_cfg.nsei */
Harald Weltec4505522020-11-11 18:55:09 +0100623private function f_BnsUdReq(template PDU_BSSGP pdu, BssgpBvci bvci, integer lsp)
Harald Welte5339b2e2020-10-04 22:52:56 +0200624runs on BSSGP_CT return NsUnitdataRequest {
625 var NsUnitdataRequest udr := {
626 bvci := bvci,
627 nsei := g_cfg.nsei,
Harald Weltec4505522020-11-11 18:55:09 +0100628 lsp := lsp,
Harald Welte5339b2e2020-10-04 22:52:56 +0200629 /* for some weird reason we get "Dynamic test case error: Text encoder: Encoding an
630 * unbound integer value." when trying to send the reocrd rather than the octetstring */
631 //sdu := omit,
632 //bssgp := valueof(pdu)
633 sdu := enc_PDU_BSSGP(valueof(pdu)),
634 bssgp := omit
635 }
636 return udr;
637}
638
639/* generate a receive template. Cannot be a real template as we want to use g_cfg.nsei */
640private function f_BnsUdInd(template PDU_BSSGP pdu, template BssgpBvci bvci)
641runs on BSSGP_CT return template (present) NsUnitdataIndication {
642 var template (present) NsUnitdataIndication udi := {
643 bvci := bvci,
644 nsei := g_cfg.nsei,
Harald Welte80a249a2020-11-17 19:57:40 +0100645 nsvci := ?,
Harald Welte5339b2e2020-10-04 22:52:56 +0200646 sdu := *,
647 bssgp := pdu
648 }
649 return udi;
650}
651
652/* change state of signaling BVCI; notify per-BVC components */
653private function f_sign_change_state(BvcState new_state) runs on BSSGP_CT {
654 if (new_state == g_sign_bvc_state) {
655 return;
656 }
657 log("BVCI(0) State Transition: ", g_sign_bvc_state, " -> ", new_state);
658 g_sign_bvc_state := new_state;
659 for (var integer i := 0; i < sizeof(BvcTable); i := i+1) {
660 if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) {
661 BVC.send(ts_BssgpStsInd(g_cfg.nsei, 0, g_sign_bvc_state)) to BvcTable[i].comp_ref;
662 }
663 }
664}
665
666/* User wants to get per-BVC component reference from BSSGP_CT */
667signature BSSGP_get_bvci_ct(BssgpBvci bvci) return BSSGP_BVC_CT;
668
669type port BSSGP_CT_PROC_PT procedure {
670 inout BSSGP_get_bvci_ct
671} with { extension "internal" };
672
673/* convenience wrapper function for user */
674function f_bssgp_get_bvci_ct(BssgpBvci bvci, BSSGP_CT_PROC_PT PT) return BSSGP_BVC_CT {
675 var BSSGP_BVC_CT res;
676 PT.call(BSSGP_get_bvci_ct:{bvci}) {
677 [] PT.getreply(BSSGP_get_bvci_ct:{bvci})-> value res {
678 return res;
679 }
680 }
681}
682
683/***********************************************************************
684 * per-BVC (Cell) Component
685 ***********************************************************************
686 * Any number of these components runs on top of the BSSGP_CT, each
687 * representing one PTP BVC within this NSE. Users (test cases) can
688 * register with TLLI and/or IMSI via the procedure port.
689 ***********************************************************************/
690
691/* per-BVC component. Exists once per cell within a BSSGP_CT */
692type component BSSGP_BVC_CT {
693 /* port towards the underlying BSSGP_CT */
694 port BSSGP_BVC_PT BVC;
695
Harald Welte199f3862020-11-15 22:37:45 +0100696 /* port to a management instance */
697 port BSSGP_BVC_MGMT_SP_PT MGMT;
698
Harald Welte71449b02020-12-09 11:58:23 +0100699 /* per-BVC global port for e.g. BVC Flow Control */
700 port BSSGP_SP_PT GLOBAL;
701
702 /* BSSGP-User SAP towards the user (per-TLLI, Client) */
Harald Welte853c0ad2018-02-15 17:45:29 +0100703 port BSSGP_SP_PT BSSGP_SP;
Stefan Sperlingf82bbb62018-05-03 19:14:28 +0200704 port BSSGP_SP_PT BSSGP_SP_SIG;
Harald Welte5ac31492018-02-15 20:39:13 +0100705 port BSSGP_PROC_PT BSSGP_PROC;
Harald Welte853c0ad2018-02-15 17:45:29 +0100706
Harald Welte5339b2e2020-10-04 22:52:56 +0200707 var BssgpBvcConfig g_cfg;
708 var boolean g_sgsn_role;
Harald Weltefba7afd2020-11-24 23:12:31 +0100709 var Nsei g_nsei;
Harald Welte5ac31492018-02-15 20:39:13 +0100710
Harald Weltec4505522020-11-11 18:55:09 +0100711 /* default Link Selector Parameter for this BVC (for traffic unrelated to a TLLI) */
712 var integer g_bvc_lsp;
713
Harald Welte853c0ad2018-02-15 17:45:29 +0100714 var BvcState g_ptp_bvc_state := BVC_S_BLOCKED;
715 timer g_T1 := 15.0;
716 timer g_T2 := 60.0;
Harald Welte5339b2e2020-10-04 22:52:56 +0200717 var boolean g_t1_waits_for_block_ack := false;
Harald Welte199f3862020-11-15 22:37:45 +0100718 /* for re-transmissions */
719 var BssgpCause g_last_block_cause;
720 var BssgpCause g_last_reset_cause;
Harald Welte5ac31492018-02-15 20:39:13 +0100721
Harald Welte633805b2021-02-03 17:47:18 +0100722 var ClientEntity ClientTable[64];
Harald Welte5339b2e2020-10-04 22:52:56 +0200723};
Harald Welte853c0ad2018-02-15 17:45:29 +0100724
Harald Welte5339b2e2020-10-04 22:52:56 +0200725/* port between global BSSGP_CT and per-BVC BSSGP_BVC_CT */
726type port BSSGP_BVC_SP_PT message {
727 in NsUnitdataRequest;
728 out ASP_Event,
729 BssgpStatusIndication,
730 BssgpResetIndication,
731 NsUnitdataIndication;
732} with { extension "internal" };
733type port BSSGP_BVC_PT message {
734 in ASP_Event,
735 BssgpStatusIndication,
736 BssgpResetIndication,
737 NsUnitdataIndication;
738 out NsUnitdataRequest;
739} with { extension "internal" };
Alexander Couzens6b449fb2018-07-31 14:19:36 +0200740
Harald Welte199f3862020-11-15 22:37:45 +0100741/* port between BSSGP_BVC_CT and a management instance */
742type port BSSGP_BVC_MGMT_SP_PT message {
743 in BssgpResetRequest,
744 BssgpBlockRequest,
745 BssgpUnblockRequest;
746 out BssgpStatusIndication,
747 BssgpResetIndication;
748} with { extension "internal" };
749type port BSSGP_BVC_MGMT_PT message {
750 in BssgpStatusIndication,
751 BssgpResetIndication;
752 out BssgpResetRequest,
753 BssgpBlockRequest,
754 BssgpUnblockRequest;
755} with { extension "internal" };
756
757type record BssgpResetRequest {
758 BssgpCause cause
759};
760type record BssgpBlockRequest {
761 BssgpCause cause
762};
763type record BssgpUnblockRequest {
764};
Harald Welte5339b2e2020-10-04 22:52:56 +0200765
766/* one element in the per-TLLI state table */
Harald Welte5ac31492018-02-15 20:39:13 +0100767type record ClientEntity {
768 OCT4 tlli,
769 OCT4 tlli_old optional,
770 hexstring imsi,
Harald Welte5ac31492018-02-15 20:39:13 +0100771 BSSGP_Client_CT comp_ref,
772 /* LLC entities, one for each SAPI */
773 LLC_Entity llc[16]
Harald Welte853c0ad2018-02-15 17:45:29 +0100774};
Harald Welte5ac31492018-02-15 20:39:13 +0100775type record LLC_Entity {
776 boolean sgsn_role,
777 /* N(U) on transmit side for next PDU */
778 uint9_t n_u_tx_next,
779 /* N(U) on receive side, last PDU */
780 uint9_t n_u_rx_last optional
781};
Harald Welte5339b2e2020-10-04 22:52:56 +0200782type record length(16) of LLC_Entity LLC_Entities;
Harald Welte5ac31492018-02-15 20:39:13 +0100783
Harald Weltef5365242021-01-17 13:46:57 +0100784private template PDU_BSSGP tr_GLOBAL_PTP := (
785 {pDU_BSSGP_STATUS:=?}
786);
787
Alexander Couzenscdfb7512018-07-31 15:37:14 +0200788function f_llc_create(boolean sgsn_role := false) return LLC_Entities {
789 var LLC_Entities llc;
790 for (var integer i := 0; i < 16; i := i+1) {
791 llc[i] := valueof(t_LLC_init(sgsn_role));
792 }
793 return llc;
794}
795
Harald Welte5ac31492018-02-15 20:39:13 +0100796private template LLC_Entity t_LLC_init(boolean sgsn_role := false) := {
797 sgsn_role := sgsn_role,
798 n_u_tx_next := 0,
799 n_u_rx_last := -
800}
801
Harald Welte5339b2e2020-10-04 22:52:56 +0200802/* configuration of BSSGP_CT */
803type record BssgpConfig {
804 Nsvci nsei,
805 boolean sgsn_role,
806 BssgpBvcConfigs bvc
807};
808/* Configuration of one BVC (Cell) BSSGP_BVC_CT */
809type record BssgpBvcConfig {
810 BssgpBvci bvci,
811 BssgpCellId cell_id,
Harald Welte4d112c92020-11-12 19:48:31 +0100812 BssgpDecodeDepth depth,
813 BssgpCreateCallback create_cb
Harald Welte5339b2e2020-10-04 22:52:56 +0200814};
815type record of BssgpBvcConfig BssgpBvcConfigs;
Oliver Smithaac9b9c2019-09-02 08:36:36 +0200816type enumerated BssgpDecodeDepth {
817 BSSGP_DECODE_DEPTH_BSSGP,
818 BSSGP_DECODE_DEPTH_LLC,
Harald Welte93331e72020-09-12 20:51:05 +0200819 BSSGP_DECODE_DEPTH_SNDCP
820#ifdef BSSGP_EM_L3
821 ,
Oliver Smithaac9b9c2019-09-02 08:36:36 +0200822 BSSGP_DECODE_DEPTH_L3
Harald Welte93331e72020-09-12 20:51:05 +0200823#endif
Oliver Smithaac9b9c2019-09-02 08:36:36 +0200824};
Harald Welte4d112c92020-11-12 19:48:31 +0100825/* call-back function type: Called for inbound BSSGP for unknown TLLIs; could create BSSGP_ClienT_CT */
826type function BssgpCreateCallback(BssgpBvci bvci, BssgpCellId cell_id, OCT4 tlli, BssgpDecoded dec) runs on BSSGP_BVC_CT;
827
828/* Default Create Callback function: Fail and terminate */
829function DefaultCreateCallback(BssgpBvci bvci, BssgpCellId cell_id, OCT4 tlli, BssgpDecoded dec) runs on BSSGP_BVC_CT {
Pau Espin Pedrol011e32f2021-02-05 12:07:04 +0100830 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Couldn't find Component for TLLI ", tlli));
Harald Welte4d112c92020-11-12 19:48:31 +0100831}
Oliver Smithaac9b9c2019-09-02 08:36:36 +0200832
Harald Welte5339b2e2020-10-04 22:52:56 +0200833/*
834private function f_tbl_init() runs on BSSGP_BVC_CT {
835 var integer i;
836 for (i := 0; i < sizeof(ImsiTable); i := i+1) {
837 ImsiTable[i] := -;
Harald Welte853c0ad2018-02-15 17:45:29 +0100838 }
Harald Welte853c0ad2018-02-15 17:45:29 +0100839
Harald Welte5339b2e2020-10-04 22:52:56 +0200840 for (i := 0; i < sizeof(TlliTable); i := i+1) {
841 TlliTable[i] := -;
Harald Welte853c0ad2018-02-15 17:45:29 +0100842 }
Harald Welte853c0ad2018-02-15 17:45:29 +0100843}
Harald Welte5339b2e2020-10-04 22:52:56 +0200844*/
Harald Welte853c0ad2018-02-15 17:45:29 +0100845
Harald Welte5339b2e2020-10-04 22:52:56 +0200846private function f_tbl_client_add(hexstring imsi, OCT4 tlli, BSSGP_Client_CT vc_conn)
847runs on BSSGP_BVC_CT {
848 var integer i;
849 for (i := 0; i < sizeof(ClientTable); i := i+1) {
850 if (not isvalue(ClientTable[i].comp_ref)) {
851 log("Adding Client=", vc_conn, ", IMSI=", imsi, ", TLLI=", tlli, ", index=", i);
852 ClientTable[i] := {
853 tlli := tlli,
854 tlli_old := omit,
855 imsi := imsi,
856 comp_ref := vc_conn,
857 llc := -
858 };
859 for (var integer j := 0; j < sizeof(ClientTable[i].llc); j := j+1) {
860 ClientTable[i].llc[j] := valueof(t_LLC_init(g_sgsn_role));
861 }
862 return;
Harald Welte5ac31492018-02-15 20:39:13 +0100863 }
864 }
Harald Welte5339b2e2020-10-04 22:52:56 +0200865 testcase.stop("Client Table full");
Harald Welte853c0ad2018-02-15 17:45:29 +0100866}
867
Harald Welte5339b2e2020-10-04 22:52:56 +0200868private function f_tbl_client_del(hexstring imsi, BSSGP_Client_CT vc_conn) runs on BSSGP_BVC_CT {
869 var integer i;
870 for (i := 0; i < sizeof(ClientTable); i := i+1) {
871 if (isvalue(ClientTable[i].imsi) and ClientTable[i].imsi == imsi) {
872 if (ClientTable[i].comp_ref != vc_conn) {
Pau Espin Pedrol011e32f2021-02-05 12:07:04 +0100873 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
874 log2str("Cannot unregister index=", i, " IMSI ",
875 imsi, " registred to ", ClientTable[i].comp_ref,
876 " from ", vc_conn));
Harald Welte5339b2e2020-10-04 22:52:56 +0200877 }
878 log("Removing Client IMSI=", imsi, ", index=", i);
879 ClientTable[i] := {
880 tlli := -,
881 tlli_old := omit,
882 imsi := ''H,
883 comp_ref := null,
884 llc := - };
885 return;
886 }
887 }
888 log("Warning: Could not find client for IMSI ", imsi);
889 return;
890}
891
892/* TS 44.064 7.2.1.1 LLGMM-ASSIGN */
893private function f_tbl_client_llgmm_assign(OCT4 tlli_old, OCT4 tlli_new, BSSGP_Client_CT vc_conn)
894runs on BSSGP_BVC_CT {
895 var integer i := f_tbl_idx_by_comp(vc_conn);
896
897 if (tlli_old == 'FFFFFFFF'O and tlli_new != 'FFFFFFFF'O) {
898 /* TLLI assignment */
899 ClientTable[i].tlli := tlli_new;
900 ClientTable[i].tlli_old := omit;
901 } else if (tlli_old != 'FFFFFFFF'O and tlli_new != 'FFFFFFFF'O) {
902 /* TLLI change: both active */
903 ClientTable[i].tlli := tlli_new;
904 ClientTable[i].tlli_old := tlli_old;
905 } else if (tlli_old != 'FFFFFFFF'O and tlli_new == 'FFFFFFFF'O) {
906 /* TLLI unassignment: old shall be unassigned; new stays */
907 ClientTable[i].tlli_old := omit;
908 }
909}
910
911private function f_tbl_comp_by_imsi(hexstring imsi) runs on BSSGP_BVC_CT return BSSGP_Client_CT {
912 var integer i;
913 for (i := 0; i < sizeof(ClientTable); i := i+1) {
914 if (isvalue(ClientTable[i].imsi) and isvalue(ClientTable[i].comp_ref)
915 and ClientTable[i].imsi == imsi) {
916 return ClientTable[i].comp_ref;
917 }
918 }
Pau Espin Pedrol011e32f2021-02-05 12:07:04 +0100919 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Couldn't find Component for IMSI ", imsi));
920 return ClientTable[0].comp_ref;
Harald Welte5339b2e2020-10-04 22:52:56 +0200921}
922
923private function f_tbl_comp_by_tlli(OCT4 tlli) runs on BSSGP_BVC_CT return BSSGP_Client_CT {
924 var integer i;
925 for (i := 0; i < sizeof(ClientTable); i := i+1) {
926 if (isvalue(ClientTable[i].comp_ref) and
927 (isvalue(ClientTable[i].tlli) and (ClientTable[i].tlli == tlli or
928 isvalue(ClientTable[i].tlli_old) and ClientTable[i].tlli_old == tlli) )) {
929 return ClientTable[i].comp_ref;
930 }
931 }
Harald Welte4d112c92020-11-12 19:48:31 +0100932 return null;
Harald Welte5339b2e2020-10-04 22:52:56 +0200933}
934
935private function f_tbl_idx_by_comp(BSSGP_Client_CT comp_ref) runs on BSSGP_BVC_CT return integer {
936 var integer i;
937 for (i := 0; i < sizeof(ClientTable); i := i+1) {
938 if (isvalue(ClientTable[i].comp_ref) and ClientTable[i].comp_ref == comp_ref) {
939 return i;
940 }
941 }
Pau Espin Pedrol011e32f2021-02-05 12:07:04 +0100942 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Couldn't find Client for Component ", comp_ref));
943 return 1;
Harald Welte5339b2e2020-10-04 22:52:56 +0200944}
945
946private function f_tbl_tlli_by_comp(BSSGP_Client_CT comp_ref) runs on BSSGP_BVC_CT return OCT4 {
947 var integer i;
948 for (i := 0; i < sizeof(ClientTable); i := i+1) {
949 if (isvalue(ClientTable[i].tlli) and isvalue(ClientTable[i].comp_ref)
950 and ClientTable[i].comp_ref == comp_ref) {
951 return ClientTable[i].tlli;
952 }
953 }
Pau Espin Pedrol011e32f2021-02-05 12:07:04 +0100954 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Couldn't find TLLI for Component ", comp_ref));
955 return '00000000'O;
Harald Welte5339b2e2020-10-04 22:52:56 +0200956}
957
958/* PDU_BSSGP enhanced with LLC and possibly L3 decoded payloads */
959type record BssgpDecoded {
960 PDU_BSSGP bssgp,
961 PDU_LLC llc optional,
962#ifdef BSSGP_EM_L3
963 PDU_L3_MS_SGSN l3_mo optional,
964 PDU_L3_SGSN_MS l3_mt optional,
965#endif
966 PDU_SN sndcp optional
967}
968
969/* Decode a PDU_BSSGP into a BssgpDecoded (i.e. with LLC/L3 decoded, as applicable) */
970private function f_dec_bssgp(PDU_BSSGP bssgp) runs on BSSGP_BVC_CT return BssgpDecoded {
971 var BssgpDecoded dec := {
972 bssgp := bssgp,
973 llc := omit,
974#ifdef BSSGP_EM_L3
975 l3_mo := omit,
976 l3_mt := omit,
977#endif
978 sndcp := omit
979 };
980
981 /* Decode LLC, if it is a PDU that contains LLC */
982 if (g_cfg.depth >= BSSGP_DECODE_DEPTH_LLC) {
983 if (ischosen(bssgp.pDU_BSSGP_DL_UNITDATA)) {
984 dec.llc := dec_PDU_LLC(bssgp.pDU_BSSGP_DL_UNITDATA.lLC_PDU.lLC_PDU);
985 } else if (ischosen(bssgp.pDU_BSSGP_UL_UNITDATA)) {
986 dec.llc := dec_PDU_LLC(bssgp.pDU_BSSGP_UL_UNITDATA.lLC_PDU.lLC_PDU);
987 }
988 }
989
990 /* Decode SNDCP, if it is a LLC PDU containing user plane data */
991 if (g_cfg.depth >= BSSGP_DECODE_DEPTH_SNDCP) {
992 if (isvalue(dec.llc) and match(dec.llc, tr_LLC_UI_USER)) {
993 dec.sndcp := dec_PDU_SN(dec.llc.pDU_LLC_UI.information_field_UI);
994 }
995 }
996
997#ifdef BSSGP_EM_L3
998 /* Decode L3, if it is a LLC PDU containing L3 */
999 if (g_cfg.depth >= BSSGP_DECODE_DEPTH_L3) {
1000 if (isvalue(dec.llc) and match(dec.llc, tr_LLC_UI_L3)) {
1001 if (g_sgsn_role) {
1002 dec.l3_mo := dec_PDU_L3_MS_SGSN(dec.llc.pDU_LLC_UI.information_field_UI);
1003 } else {
1004 dec.l3_mt := dec_PDU_L3_SGSN_MS(dec.llc.pDU_LLC_UI.information_field_UI);
1005 }
1006 }
1007 }
1008#endif
1009
1010 return dec;
1011}
1012
1013private function f_ptp_sendUnblock() runs on BSSGP_BVC_CT {
Pau Espin Pedrol6ee01262021-02-05 13:05:06 +01001014 BVC.send(ts_ptp_BnsUdReq(ts_BVC_UNBLOCK(g_cfg.bvci), 0, g_bvc_lsp));
Harald Welte5339b2e2020-10-04 22:52:56 +02001015 g_t1_waits_for_block_ack := false;
1016 g_T1.start;
1017}
1018
1019private function f_ptp_sendBlock(BssgpCause cause) runs on BSSGP_BVC_CT {
Pau Espin Pedrol6ee01262021-02-05 13:05:06 +01001020 BVC.send(ts_ptp_BnsUdReq(ts_BVC_BLOCK(g_cfg.bvci, cause), 0, g_bvc_lsp));
Harald Welte5339b2e2020-10-04 22:52:56 +02001021 g_t1_waits_for_block_ack := true;
1022 g_T1.start;
Harald Welte199f3862020-11-15 22:37:45 +01001023 g_last_block_cause := cause;
Harald Welte5339b2e2020-10-04 22:52:56 +02001024}
1025
1026private function f_ptp_sendStatus(BssgpCause cause, PDU_BSSGP pdu) runs on BSSGP_BVC_CT {
1027 /* FIXME: Make sure correct Signaling or PTP BVCI is used! */
Harald Weltec4505522020-11-11 18:55:09 +01001028 BVC.send(ts_ptp_BnsUdReq(ts_BSSGP_STATUS(g_cfg.bvci, cause, pdu), g_cfg.bvci, g_bvc_lsp));
Harald Welte5339b2e2020-10-04 22:52:56 +02001029}
1030
Harald Welte199f3862020-11-15 22:37:45 +01001031private function f_ptp_sendReset(BssgpCause cause := BSSGP_CAUSE_OM_INTERVENTION) runs on BSSGP_BVC_CT {
Harald Weltec967d0e2020-09-14 16:07:26 +02001032 var PDU_BSSGP pdu;
1033
1034 /* The Cell Identifier IE is mandatory in the BVC-RESET PDU sent from BSS to
1035 * SGSN in order to reset a BVC corresponding to a PTP functional entity. The
1036 * Cell Identifier IE shall not be used in any other BVC-RESET PDU. */
Harald Welte5339b2e2020-10-04 22:52:56 +02001037 if (g_sgsn_role) {
Harald Welte199f3862020-11-15 22:37:45 +01001038 pdu := valueof(ts_BVC_RESET(cause, g_cfg.bvci, omit));
Harald Weltec967d0e2020-09-14 16:07:26 +02001039 } else {
Harald Welte199f3862020-11-15 22:37:45 +01001040 pdu := valueof(ts_BVC_RESET(cause, g_cfg.bvci, g_cfg.cell_id));
Harald Weltec967d0e2020-09-14 16:07:26 +02001041 }
Harald Welte853c0ad2018-02-15 17:45:29 +01001042
1043 /* BVC-RESET is always sent via the SIGNALLING BVCI, see Table 5.4.1 */
Harald Weltec4505522020-11-11 18:55:09 +01001044 BVC.send(ts_ptp_BnsUdReq(pdu, 0, g_bvc_lsp));
Harald Welte853c0ad2018-02-15 17:45:29 +01001045 g_T2.start;
1046 //f_change_state(BVC_S_WAIT_RESET);
Harald Welte199f3862020-11-15 22:37:45 +01001047 g_last_reset_cause := cause;
Harald Welte853c0ad2018-02-15 17:45:29 +01001048}
1049
Harald Welte5339b2e2020-10-04 22:52:56 +02001050/* PTP-BVC is in BVC_S_BLOCKED state */
1051private altstep as_ptp_blocked() runs on BSSGP_BVC_CT {
1052 var NsUnitdataIndication udi;
1053
Pau Espin Pedrol6ee01262021-02-05 13:05:06 +01001054 [g_T1.running and not g_t1_waits_for_block_ack] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_UNBLOCK_ACK(g_cfg.bvci), 0)) {
Harald Welte5339b2e2020-10-04 22:52:56 +02001055 g_T1.stop;
1056 f_ptp_change_state(BVC_S_UNBLOCKED);
1057 }
1058
Harald Welteddfc6672020-11-24 23:13:01 +01001059 /* Inbound BVC-UNBLOCK from peer */
Pau Espin Pedrol6ee01262021-02-05 13:05:06 +01001060 [g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_UNBLOCK(g_cfg.bvci), 0)) {
1061 BVC.send(ts_ptp_BnsUdReq(ts_BVC_UNBLOCK_ACK(g_cfg.bvci), 0, g_bvc_lsp));
Harald Welteddfc6672020-11-24 23:13:01 +01001062 f_ptp_change_state(BVC_S_UNBLOCKED);
1063 }
1064
Harald Welte5339b2e2020-10-04 22:52:56 +02001065 /* RESET-ACK before T2 timeout: reset successful. In SGSN role, CellID must be present */
1066 [g_T2.running and g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_RESET_ACK(g_cfg.bvci, g_cfg.cell_id), 0)) -> value udi {
1067 g_T2.stop;
1068 f_ptp_change_state(BVC_S_UNBLOCKED);
1069 }
1070 /* RESET-ACK before T2 timeout: reset successful. In BSS role, CellID must be absent */
1071 [g_T2.running and not g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_RESET_ACK(g_cfg.bvci, omit), 0)) -> value udi {
1072 g_T2.stop;
1073 f_ptp_change_state(BVC_S_UNBLOCKED);
1074 }
1075
Harald Welteab50cc22020-11-25 17:11:08 +01001076 [] as_ptp_handle_inbound_reset();
1077
Harald Welte5339b2e2020-10-04 22:52:56 +02001078 [] g_T2.timeout {
1079 /* BVC-RESET-ACK PDU was not received within T2: retransmit */
Harald Welte199f3862020-11-15 22:37:45 +01001080 f_ptp_sendReset(g_last_reset_cause);
Harald Welte5339b2e2020-10-04 22:52:56 +02001081 }
Harald Welte199f3862020-11-15 22:37:45 +01001082
1083 [] MGMT.receive(BssgpUnblockRequest:?) {
1084 f_ptp_sendUnblock();
1085 }
Harald Welte853c0ad2018-02-15 17:45:29 +01001086}
1087
Harald Welte5339b2e2020-10-04 22:52:56 +02001088/* PTP-BVC is in UNBLOCKED state */
1089private altstep as_ptp_unblocked() runs on BSSGP_BVC_CT {
1090 var NsUnitdataIndication udi;
1091 var NsStatusIndication nsi;
Harald Welte199f3862020-11-15 22:37:45 +01001092 var BssgpBlockRequest bbr;
Harald Welte5339b2e2020-10-04 22:52:56 +02001093 var BSSGP_Client_CT vc_conn;
1094 var ASP_Event evt;
1095 var PDU_BSSGP bs_pdu;
1096 var PDU_LLC llc;
1097#ifdef BSSGP_EM_L3
1098 var PDU_L3_MS_SGSN l3_mo;
1099 var PDU_L3_SGSN_MS l3_mt;
1100#endif
1101
1102 /* bogus unblock, just respond with ACK */
Pau Espin Pedrol6ee01262021-02-05 13:05:06 +01001103 [] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_UNBLOCK(g_cfg.bvci), 0)) -> value udi {
1104 BVC.send(ts_ptp_BnsUdReq(ts_BVC_UNBLOCK_ACK(g_cfg.bvci), 0, g_bvc_lsp));
Harald Welte5339b2e2020-10-04 22:52:56 +02001105 }
1106 /* Respond to BLOCK with BLOCK-ACK + change state */
Pau Espin Pedrol6ee01262021-02-05 13:05:06 +01001107 [] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_BLOCK(g_cfg.bvci, ?), 0)) -> value udi {
1108 BVC.send(ts_ptp_BnsUdReq(ts_BVC_BLOCK_ACK(g_cfg.bvci), 0, g_bvc_lsp));
Harald Welte5339b2e2020-10-04 22:52:56 +02001109 g_T1.stop;
1110 f_ptp_change_state(BVC_S_BLOCKED);
1111 }
1112 /* BLOCK-ACK before T1 timeout: mark as blocked */
Pau Espin Pedrol6ee01262021-02-05 13:05:06 +01001113 [g_T1.running and g_t1_waits_for_block_ack] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_BLOCK_ACK(g_cfg.bvci), 0)) -> value udi {
Harald Welte5339b2e2020-10-04 22:52:56 +02001114 g_T1.stop;
1115 f_ptp_change_state(BVC_S_BLOCKED);
1116 }
1117 /* Re-transmit BLOCK / UNBLOCK on T1 timeout */
Pau Espin Pedrolf7926c02024-01-30 11:12:45 +01001118 [g_T1.running and not g_t1_waits_for_block_ack] g_T1.timeout {
Harald Welte5339b2e2020-10-04 22:52:56 +02001119 f_ptp_sendUnblock();
1120 }
Pau Espin Pedrolf7926c02024-01-30 11:12:45 +01001121 [g_T1.running and g_t1_waits_for_block_ack] g_T1.timeout {
Harald Welte199f3862020-11-15 22:37:45 +01001122 f_ptp_sendBlock(g_last_block_cause);
Harald Welte5339b2e2020-10-04 22:52:56 +02001123 }
1124
Harald Welteab50cc22020-11-25 17:11:08 +01001125 [] as_ptp_handle_inbound_reset();
1126
Harald Welte5339b2e2020-10-04 22:52:56 +02001127 [g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_FC_BVC, g_cfg.bvci)) -> value udi {
Harald Welte71449b02020-12-09 11:58:23 +01001128 if (GLOBAL.checkstate("Connected")) {
1129 GLOBAL.send(udi.bssgp);
1130 } else {
1131 /* simply acknowledge all per-BVC Flow Control Messages */
1132 var OCT1 tag := udi.bssgp.pDU_BSSGP_FLOW_CONTROL_BVC.tag.unstructured_Value;
Pau Espin Pedrol6ee01262021-02-05 13:05:06 +01001133 BVC.send(ts_ptp_BnsUdReq(ts_BVC_FC_BVC_ACK(tag), g_cfg.bvci, g_bvc_lsp));
Harald Welte71449b02020-12-09 11:58:23 +01001134 }
Harald Welte5339b2e2020-10-04 22:52:56 +02001135 }
Harald Welte71449b02020-12-09 11:58:23 +01001136
Pau Espin Pedrol6ee01262021-02-05 13:05:06 +01001137 [not g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_FC_BVC_ACK(?), g_cfg.bvci)) -> value udi {
Harald Welte71449b02020-12-09 11:58:23 +01001138 if (GLOBAL.checkstate("Connected")) {
1139 GLOBAL.send(udi.bssgp);
1140 } else {
1141 /* ignore any incoming flow control ACK */
1142 }
Harald Welte5339b2e2020-10-04 22:52:56 +02001143 }
Harald Welte71449b02020-12-09 11:58:23 +01001144
Harald Weltef5365242021-01-17 13:46:57 +01001145 [] BVC.receive(tr_ptp_BnsUdInd(tr_GLOBAL_PTP, g_cfg.bvci)) -> value udi {
1146 if (GLOBAL.checkstate("Connected")) {
1147 GLOBAL.send(udi.bssgp);
1148 } else {
1149 setverdict(fail, "Received BSSGP STATUS ", udi.bssgp);
1150 }
1151 }
1152
Harald Welte5339b2e2020-10-04 22:52:56 +02001153 /* Any other PTP BSSGP message: If it has TLLI, route to component; otherwise broadcast */
1154 [] BVC.receive(tr_ptp_BnsUdInd(?, g_cfg.bvci)) -> value udi {
1155 var BssgpDecoded dec := f_dec_bssgp(udi.bssgp);
1156 var template OCT4 tlli := f_bssgp_get_tlli(udi.bssgp);
1157 if (isvalue(tlli)) {
1158 vc_conn := f_tbl_comp_by_tlli(valueof(tlli));
Harald Welte4d112c92020-11-12 19:48:31 +01001159 if (vc_conn == null) {
1160 g_cfg.create_cb.apply(g_cfg.bvci, g_cfg.cell_id, valueof(tlli), dec);
1161 } else {
1162 f_send_bssgp_dec(dec, vc_conn, BSSGP_SP);
1163 }
Harald Welte5339b2e2020-10-04 22:52:56 +02001164 } else {
1165 log("No TLLI: Broadcasting ", dec);
1166 /* broadcast this message to all components */
1167 // TITAN DOESN'T DO THIS, *SIGH*: "BSSGP_SP.send(dec) to all component;"
1168 for (var integer i := 0; i < sizeof(ClientTable); i := i+1) {
1169 if (isbound(ClientTable[i].comp_ref) and ClientTable[i].comp_ref != null) {
1170 f_send_bssgp_dec(dec, ClientTable[i].comp_ref, BSSGP_SP);
1171 }
1172 }
1173 }
1174 }
1175
Daniel Willmannef8e50e2021-11-26 11:41:50 +01001176 [] BVC.receive(tr_ptp_BnsUdInd(tr_BSSGP_FLUSH_LL_ACK(?, ?, ?), 0)) -> value udi {
1177 var BssgpDecoded dec := f_dec_bssgp(udi.bssgp);
1178
1179 log("Broadcasting FLUSH_LL_ACK ", dec);
1180 /* broadcast this message to all components */
1181 // TITAN DOESN'T DO THIS, *SIGH*: "BSSGP_SP.send(dec) to all component;"
1182 for (var integer i := 0; i < sizeof(ClientTable); i := i+1) {
1183 if (isbound(ClientTable[i].comp_ref) and ClientTable[i].comp_ref != null) {
1184 f_send_bssgp_dec(dec, ClientTable[i].comp_ref, BSSGP_SP_SIG);
1185 }
1186 }
1187 }
1188
Harald Welte5339b2e2020-10-04 22:52:56 +02001189 /* Any other SIG BSSGP message: If it has TLLI, route to component; otherwise broadcast */
1190 [] BVC.receive(tr_ptp_BnsUdInd(?, 0)) -> value udi {
1191 var BssgpDecoded dec := f_dec_bssgp(udi.bssgp);
1192 var template OCT4 tlli := f_bssgp_get_tlli(udi.bssgp);
1193 if (isvalue(tlli)) {
1194 vc_conn := f_tbl_comp_by_tlli(valueof(tlli));
Harald Welte4d112c92020-11-12 19:48:31 +01001195 if (vc_conn == null) {
1196 g_cfg.create_cb.apply(g_cfg.bvci, g_cfg.cell_id, valueof(tlli), dec);
1197 } else {
1198 f_send_bssgp_dec(dec, vc_conn, BSSGP_SP_SIG);
1199 }
Harald Welte5339b2e2020-10-04 22:52:56 +02001200 } else {
1201 log("No TLLI: Broadcasting ", dec);
1202 /* broadcast this message to all components */
1203 // TITAN DOESN'T DO THIS, *SIGH*: "BSSGP_SP.send(dec) to all component;"
1204 for (var integer i := 0; i < sizeof(ClientTable); i := i+1) {
1205 if (isbound(ClientTable[i].comp_ref) and ClientTable[i].comp_ref != null) {
1206 f_send_bssgp_dec(dec, ClientTable[i].comp_ref, BSSGP_SP_SIG);
1207 }
1208 }
1209 }
1210 }
1211
1212 /* ConnHdlr sends BSSGP on BVCI=0 port: forward it to BSSGP_CT */
1213 [] BSSGP_SP_SIG.receive(PDU_BSSGP:?)-> value bs_pdu sender vc_conn {
Harald Weltec4505522020-11-11 18:55:09 +01001214 BVC.send(ts_ptp_BnsUdReq(bs_pdu, 0, g_bvc_lsp));
Harald Welte5339b2e2020-10-04 22:52:56 +02001215 }
1216
1217 /* ConnHdlr sends BSSGP on BVCI=PTP port: forward it to BSSGP_CT */
1218 [] BSSGP_SP.receive(PDU_BSSGP:?)-> value bs_pdu sender vc_conn {
Harald Weltec4505522020-11-11 18:55:09 +01001219 BVC.send(ts_ptp_BnsUdReq(bs_pdu, g_cfg.bvci, g_bvc_lsp));
Harald Welte5339b2e2020-10-04 22:52:56 +02001220 }
1221
1222#ifdef BSSGP_EM_L3
1223 /* ConnHdlr sends L3: Encode and send as UL_UD / DL_UD */
1224 [g_sgsn_role] BSSGP_SP.receive(PDU_L3_SGSN_MS:?) -> value l3_mt sender vc_conn {
1225 var integer idx := f_tbl_idx_by_comp(vc_conn);
Harald Weltec4505522020-11-11 18:55:09 +01001226 var OCT4 tlli := ClientTable[idx].tlli;
Harald Welte5339b2e2020-10-04 22:52:56 +02001227 var octetstring l3_enc := enc_PDU_L3_SGSN_MS(l3_mt);
1228 var BIT4 sapi := f_llc_sapi_by_l3_mt(l3_mt);
1229 var integer n_u := f_llc_get_n_u_tx(ClientTable[idx].llc[bit2int(sapi)]);
1230 var octetstring llc_enc := enc_PDU_LLC(valueof(ts_LLC_UI(l3_enc, sapi, '1'B, n_u)));
Harald Weltec4505522020-11-11 18:55:09 +01001231 BVC.send(ts_ptp_BnsUdReq(ts_BSSGP_DL_UD(tlli, llc_enc), g_cfg.bvci, oct2int(tlli)));
Harald Welte5339b2e2020-10-04 22:52:56 +02001232 }
1233 [not g_sgsn_role] BSSGP_SP.receive(PDU_L3_MS_SGSN:?) -> value l3_mo sender vc_conn {
1234 var integer idx := f_tbl_idx_by_comp(vc_conn);
Harald Weltec4505522020-11-11 18:55:09 +01001235 var OCT4 tlli := ClientTable[idx].tlli;
Harald Welte5339b2e2020-10-04 22:52:56 +02001236 var octetstring l3_enc := enc_PDU_L3_MS_SGSN(l3_mo);
1237 var BIT4 sapi := f_llc_sapi_by_l3_mo(l3_mo);
1238 var integer n_u := f_llc_get_n_u_tx(ClientTable[idx].llc[bit2int(sapi)]);
1239 var octetstring llc_enc := enc_PDU_LLC(valueof(ts_LLC_UI(l3_enc, sapi, '1'B, n_u)));
Harald Weltec4505522020-11-11 18:55:09 +01001240 BVC.send(ts_ptp_BnsUdReq(ts_BSSGP_UL_UD(tlli, g_cfg.cell_id, llc_enc), g_cfg.bvci, oct2int(tlli)));
Harald Welte5339b2e2020-10-04 22:52:56 +02001241 }
1242#endif
1243
1244 /* ConnHdlr sends raw LLC: Encode and send as UL_UD / DL_UD */
1245 [not g_sgsn_role] BSSGP_SP.receive(PDU_LLC:?) -> value llc sender vc_conn {
1246 var integer idx := f_tbl_idx_by_comp(vc_conn);
Harald Weltec4505522020-11-11 18:55:09 +01001247 var OCT4 tlli := ClientTable[idx].tlli;
Harald Welte5339b2e2020-10-04 22:52:56 +02001248 var octetstring llc_enc := enc_PDU_LLC(llc);
Harald Weltec4505522020-11-11 18:55:09 +01001249 BVC.send(ts_ptp_BnsUdReq(ts_BSSGP_UL_UD(tlli, g_cfg.cell_id, llc_enc), g_cfg.bvci, oct2int(tlli)));
Harald Welte5339b2e2020-10-04 22:52:56 +02001250 }
1251 [g_sgsn_role] BSSGP_SP.receive(PDU_LLC:?) -> value llc sender vc_conn {
1252 var integer idx := f_tbl_idx_by_comp(vc_conn);
Harald Weltec4505522020-11-11 18:55:09 +01001253 var OCT4 tlli := ClientTable[idx].tlli;
Harald Welte5339b2e2020-10-04 22:52:56 +02001254 var octetstring llc_enc := enc_PDU_LLC(llc);
Harald Weltec4505522020-11-11 18:55:09 +01001255 BVC.send(ts_ptp_BnsUdReq(ts_BSSGP_DL_UD(tlli, llc_enc), g_cfg.bvci, oct2int(tlli)));
Harald Welte5339b2e2020-10-04 22:52:56 +02001256 }
Harald Welte199f3862020-11-15 22:37:45 +01001257
Harald Welte71449b02020-12-09 11:58:23 +01001258 /* Testcase sends us BSSGP on global port */
1259 [] GLOBAL.receive(PDU_BSSGP:?)-> value bs_pdu sender vc_conn {
1260 BVC.send(ts_ptp_BnsUdReq(bs_pdu, g_cfg.bvci, g_bvc_lsp));
1261 }
1262
Harald Welte199f3862020-11-15 22:37:45 +01001263 [] MGMT.receive(BssgpBlockRequest:?) -> value bbr {
1264 f_ptp_sendBlock(bbr.cause);
1265 }
Harald Welte853c0ad2018-02-15 17:45:29 +01001266}
1267
Harald Welteab50cc22020-11-25 17:11:08 +01001268private altstep as_ptp_handle_inbound_reset() runs on BSSGP_BVC_CT {
1269 var NsUnitdataIndication udi;
1270 /* we are a SGSN: BSS/PCU-originated RESET must have a cell ID */
1271 [g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_RESET(?, g_cfg.bvci, g_cfg.cell_id), 0)) -> value udi {
1272 log("Rx BVC-RESET from BVCI=", g_cfg.bvci);
Harald Welte3c905152020-11-26 20:56:09 +01001273 if (MGMT.checkstate("Connected")) {
1274 MGMT.send(BssgpResetIndication:{g_cfg.bvci});
1275 }
Harald Welteab50cc22020-11-25 17:11:08 +01001276 /* Respond to RESET with correct BVCI but without CellID */
1277 BVC.send(ts_ptp_BnsUdReq(ts_BVC_RESET_ACK(g_cfg.bvci, omit), 0, g_bvc_lsp));
1278 /* FIXME: reset all state? What about clients? */
1279 f_ptp_change_state(BVC_S_UNBLOCKED);
1280 }
1281 /* we are a BSS/PCU: SGSN-originated RESET must not have a cell ID */
1282 [not g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_RESET(?, g_cfg.bvci, omit), 0)) -> value udi {
1283 log("Rx BVC-RESET from BVCI=", g_cfg.bvci);
Harald Welte3c905152020-11-26 20:56:09 +01001284 if (MGMT.checkstate("Connected")) {
1285 MGMT.send(BssgpResetIndication:{g_cfg.bvci});
1286 }
Harald Welteab50cc22020-11-25 17:11:08 +01001287 /* Respond to RESET with correct BVCI with CellID */
1288 BVC.send(ts_ptp_BnsUdReq(ts_BVC_RESET_ACK(g_cfg.bvci, g_cfg.cell_id), 0, g_bvc_lsp));
1289 /* FIXME: reset all state? What about clients? */
1290 f_ptp_change_state(BVC_S_UNBLOCKED);
1291 }
1292}
1293
Harald Welte5339b2e2020-10-04 22:52:56 +02001294/* Events permitted in all states */
1295private altstep as_ptp_allstate() runs on BSSGP_BVC_CT {
1296 var NsUnitdataIndication udi;
Harald Welte199f3862020-11-15 22:37:45 +01001297 var BssgpResetRequest brr;
Harald Welte5339b2e2020-10-04 22:52:56 +02001298 var BSSGP_Client_CT vc_conn;
1299 var OCT4 tlli, tlli_old;
1300 var hexstring imsi;
1301
1302 /* Signaling BVC was reset */
1303 [] BVC.receive(BssgpResetIndication:{0}) {
Harald Welte199f3862020-11-15 22:37:45 +01001304 if (MGMT.checkstate("Connected")) {
1305 MGMT.send(BssgpResetIndication:{0});
1306 }
Harald Welte5339b2e2020-10-04 22:52:56 +02001307 if (not g_sgsn_role) {
1308 f_ptp_change_state(BVC_S_BLOCKED);
1309 /* when the BSS side signaling PTP is RESET, all PTP BVC must start the
1310 * reset procedure */
1311 f_ptp_sendReset();
1312 } else {
1313 f_ptp_change_state(BVC_S_UNBLOCKED);
1314 }
1315 }
1316
Harald Welte5339b2e2020-10-04 22:52:56 +02001317 /* Ignore those for now */
1318 [] BVC.receive(ASP_Event:?) { }
1319 [] BVC.receive(BssgpStatusIndication:?) { }
1320
1321 /* catch-all */
1322 [] BVC.receive(tr_ptp_BnsUdInd(?, 0)) -> value udi {
1323 setverdict(fail, "Received unexpected NS (SIG): ", udi);
1324 }
1325 [] BVC.receive(tr_ptp_BnsUdInd(?, ?)) -> value udi {
1326 setverdict(fail, "Received unexpected NS (PTP): ", udi);
1327 }
1328 [] BVC.receive {
1329 setverdict(fail, "Received unexpected message from BSSGP_CT");
1330 }
1331
1332 /* registration/deregistration of Clients (per-TLLI components) */
1333 [] BSSGP_PROC.getcall(BSSGP_register_client:{?,?}) -> param(imsi, tlli) sender vc_conn {
1334 f_tbl_client_add(imsi, tlli, vc_conn);
1335 BSSGP_PROC.reply(BSSGP_register_client:{imsi, tlli}) to vc_conn;
1336 }
1337 [] BSSGP_PROC.getcall(BSSGP_unregister_client:{?}) -> param(imsi) sender vc_conn {
1338 f_tbl_client_del(imsi, vc_conn);
1339 BSSGP_PROC.reply(BSSGP_unregister_client:{imsi}) to vc_conn;
1340 }
1341 [] BSSGP_PROC.getcall(BSSGP_llgmm_assign:{?,?}) -> param(tlli_old, tlli) sender vc_conn {
1342 f_tbl_client_llgmm_assign(tlli_old, tlli, vc_conn);
1343 BSSGP_PROC.reply(BSSGP_llgmm_assign:{tlli_old, tlli}) to vc_conn;
1344 }
Harald Welte199f3862020-11-15 22:37:45 +01001345
1346 [] MGMT.receive(BssgpResetRequest:?) -> value brr {
Harald Welte52cecbb2020-11-25 21:57:31 +01001347 f_ptp_change_state(BVC_S_BLOCKED);
Harald Welte199f3862020-11-15 22:37:45 +01001348 f_ptp_sendReset(brr.cause);
1349 }
Harald Welte5339b2e2020-10-04 22:52:56 +02001350}
1351
1352/* main loop for per-BVC component */
1353private function f_bssgp_bvc_ScanEvents() runs on BSSGP_BVC_CT {
1354 while (true) {
1355 alt {
1356 [g_ptp_bvc_state == BVC_S_BLOCKED] as_ptp_blocked();
1357 [g_ptp_bvc_state == BVC_S_UNBLOCKED] as_ptp_unblocked();
1358 [] as_ptp_allstate();
1359 }
1360 }
1361}
1362
1363/* main function for per-BVC Component */
Harald Weltefba7afd2020-11-24 23:12:31 +01001364private function f_bssgp_bvc_main(BssgpBvcConfig cfg, boolean sgsn_role, Nsei nsei, charstring id) runs on BSSGP_BVC_CT {
Harald Welte5339b2e2020-10-04 22:52:56 +02001365 g_cfg := cfg;
Harald Weltefba7afd2020-11-24 23:12:31 +01001366 g_nsei := nsei;
Harald Weltec4505522020-11-11 18:55:09 +01001367 g_bvc_lsp := cfg.bvci;
Harald Welte5339b2e2020-10-04 22:52:56 +02001368 g_sgsn_role := sgsn_role;
1369 f_bssgp_bvc_ScanEvents();
1370}
1371
Harald Weltec4505522020-11-11 18:55:09 +01001372template (value) NsUnitdataRequest ts_ptp_BnsUdReq(template (value) PDU_BSSGP pdu, template (value) BssgpBvci bvci,
1373 template (value) integer lsp) := {
Harald Welte5339b2e2020-10-04 22:52:56 +02001374 bvci := bvci,
1375 nsei := 0, // overwritten in BSSGP_CT
Harald Weltec4505522020-11-11 18:55:09 +01001376 lsp := lsp,
Harald Welte5339b2e2020-10-04 22:52:56 +02001377 /* for some weird reason we get "Dynamic test case error: Text encoder: Encoding an
1378 * unbound integer value." when trying to send the reocrd rather than the octetstring */
1379 //sdu := omit,
1380 //bssgp := valueof(pdu)
1381 sdu := enc_PDU_BSSGP(valueof(pdu)),
1382 bssgp := omit
1383}
1384
1385template (present) NsUnitdataIndication tr_ptp_BnsUdInd(template (present) PDU_BSSGP pdu, template (present) BssgpBvci bvci) := {
1386 bvci := bvci,
1387 nsei := ?,
Harald Welte80a249a2020-11-17 19:57:40 +01001388 nsvci := ?,
Harald Welte5339b2e2020-10-04 22:52:56 +02001389 sdu := *,
1390 bssgp := pdu
1391}
1392
1393/* change state of PTP BVC; broadcast state change to clients */
1394private function f_ptp_change_state(BvcState new_state) runs on BSSGP_BVC_CT {
1395 if (new_state == g_ptp_bvc_state) {
1396 return;
1397 }
1398 log("BVCI(", g_cfg.bvci, ") State Transition: ", g_ptp_bvc_state, " -> ", new_state);
1399 g_ptp_bvc_state := new_state;
Harald Welte199f3862020-11-15 22:37:45 +01001400 if (MGMT.checkstate("Connected")) {
Harald Weltefba7afd2020-11-24 23:12:31 +01001401 MGMT.send(ts_BssgpStsInd(g_nsei, g_cfg.bvci, g_ptp_bvc_state));
Harald Welte199f3862020-11-15 22:37:45 +01001402 }
Harald Welte5339b2e2020-10-04 22:52:56 +02001403 for (var integer i := 0; i < sizeof(ClientTable); i := i+1) {
1404 if (isbound(ClientTable[i].comp_ref) and ClientTable[i].comp_ref != null) {
Harald Weltefba7afd2020-11-24 23:12:31 +01001405 BSSGP_SP.send(ts_BssgpStsInd(g_nsei, g_cfg.bvci, g_ptp_bvc_state)) to ClientTable[i].comp_ref;
Harald Welte5339b2e2020-10-04 22:52:56 +02001406 }
1407 }
Harald Welte5ac31492018-02-15 20:39:13 +01001408}
1409
1410/* attempt to extract the TLLI from a BSSGP PDU */
1411function f_bssgp_get_tlli(PDU_BSSGP bssgp) return template OCT4 {
1412 if (ischosen(bssgp.pDU_BSSGP_DL_UNITDATA)) {
1413 return bssgp.pDU_BSSGP_DL_UNITDATA.tLLI_current;
1414 } else if (ischosen(bssgp.pDU_BSSGP_UL_UNITDATA)) {
1415 return bssgp.pDU_BSSGP_UL_UNITDATA.tLLI;
1416 } else if (ischosen(bssgp.pDU_BSSGP_RA_CAPABILITY)) {
1417 return bssgp.pDU_BSSGP_RA_CAPABILITY.tLLI.tLLI_Value;
1418 } else if (ischosen(bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE)) {
1419 return bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE.tLLI.tLLI_Value;
1420 } else if (ischosen(bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE_ACK)) {
1421 return bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE_ACK.tLLI.tLLI_Value;
Harald Welte650bd722021-01-17 10:58:56 +01001422 } else if (ischosen(bssgp.pDU_BSSGP_RADIO_STATUS) and
1423 ispresent(bssgp.pDU_BSSGP_RADIO_STATUS.tLLI)) {
Harald Welte5ac31492018-02-15 20:39:13 +01001424 return bssgp.pDU_BSSGP_RADIO_STATUS.tLLI.tLLI_Value;
1425 } else if (ischosen(bssgp.pDU_BSSGP_SUSPEND)) {
1426 return bssgp.pDU_BSSGP_SUSPEND.tLLI.tLLI_Value;
1427 } else if (ischosen(bssgp.pDU_BSSGP_SUSPEND_ACK)) {
1428 return bssgp.pDU_BSSGP_SUSPEND_ACK.tLLI.tLLI_Value;
1429 } else if (ischosen(bssgp.pDU_BSSGP_SUSPEND_NACK)) {
1430 return bssgp.pDU_BSSGP_SUSPEND_NACK.tLLI.tLLI_Value;
1431 } else if (ischosen(bssgp.pDU_BSSGP_RESUME)) {
1432 return bssgp.pDU_BSSGP_RESUME.tLLI.tLLI_Value;
1433 } else if (ischosen(bssgp.pDU_BSSGP_RESUME_ACK)) {
1434 return bssgp.pDU_BSSGP_RESUME_ACK.tLLI.tLLI_Value;
1435 } else if (ischosen(bssgp.pDU_BSSGP_RESUME_NACK)) {
1436 return bssgp.pDU_BSSGP_RESUME_NACK.tLLI.tLLI_Value;
1437 } else if (ischosen(bssgp.pDU_BSSGP_FLUSH_LL)) {
1438 return bssgp.pDU_BSSGP_FLUSH_LL.tLLI.tLLI_Value;
1439 } else if (ischosen(bssgp.pDU_BSSGP_FLUSH_LL_ACK)) {
1440 return bssgp.pDU_BSSGP_FLUSH_LL_ACK.tLLI.tLLI_Value;
1441 } else if (ischosen(bssgp.pDU_BSSGP_LLC_DISCARDED)) {
1442 return bssgp.pDU_BSSGP_LLC_DISCARDED.tLLI.tLLI_Value;
1443 } else if (ischosen(bssgp.pDU_BSSGP_LLC_DISCARDED)) {
1444 return bssgp.pDU_BSSGP_LLC_DISCARDED.tLLI.tLLI_Value;
1445 } else if (ischosen(bssgp.pDU_BSSGP_PAGING_CS) and
1446 isvalue(bssgp.pDU_BSSGP_PAGING_CS.tLLI)) {
1447 return bssgp.pDU_BSSGP_PAGING_CS.tLLI.tLLI_Value;
1448 } else if (ischosen(bssgp.pDU_BSSGP_FLOW_CONTROL_MS)) {
1449 return bssgp.pDU_BSSGP_FLOW_CONTROL_MS.tLLI.tLLI_Value;
1450 } else if (ischosen(bssgp.pDU_BSSGP_FLOW_CONTROL_MS_ACK)) {
1451 return bssgp.pDU_BSSGP_FLOW_CONTROL_MS_ACK.tLLI.tLLI_Value;
1452 }
1453 /* TODO: Handover, PFC, LCS */
1454 return omit;
1455}
1456
Harald Weltef70997d2018-02-17 10:11:19 +01001457
Harald Welte5ac31492018-02-15 20:39:13 +01001458
Harald Welte1733a382017-07-23 17:26:17 +02001459}