blob: a6bdbb5c4837e7bbaf1c0e61ebb1c53183e34301 [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 Welte5339b2e2020-10-04 22:52:56 +02004 * (C) 2018-2020 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;
Harald Welte1733a382017-07-23 17:26:17 +020028
Harald Welte93331e72020-09-12 20:51:05 +020029#ifdef BSSGP_EM_L3
Harald Welte5ac31492018-02-15 20:39:13 +010030import from MobileL3_GMM_SM_Types all;
31import from MobileL3_Types all;
Harald Welte93331e72020-09-12 20:51:05 +020032#endif
Harald Welte5ac31492018-02-15 20:39:13 +010033
34import from LLC_Types all;
35import from LLC_Templates all;
36
Harald Weltea2526a82018-02-18 19:03:36 +010037import from SNDCP_Types all;
38
Harald Welte12d19b82020-10-09 11:41:06 +020039
40modulepar {
41 /* tolerate CellID absence/presence in BVC-RESET in violation to spec */
42 boolean mp_tolerate_bvc_reset_cellid := false;
43}
44
Harald Welte5ac31492018-02-15 20:39:13 +010045/***********************************************************************
Harald Welte5339b2e2020-10-04 22:52:56 +020046 * Communication between Client Components and per-BVC component
Harald Welte5ac31492018-02-15 20:39:13 +010047 ***********************************************************************/
48
Harald Welte853c0ad2018-02-15 17:45:29 +010049type record BssgpStatusIndication {
Harald Welte5339b2e2020-10-04 22:52:56 +020050 Nsei nsei optional,
Harald Welte853c0ad2018-02-15 17:45:29 +010051 BssgpBvci bvci,
52 BvcState state
Harald Welte5339b2e2020-10-04 22:52:56 +020053};
54
55type record BssgpResetIndication {
56 BssgpBvci bvci
57};
58
59template (value) BssgpStatusIndication
60ts_BssgpStsInd(template (omit) Nsei nsei, template (value) BssgpBvci bvci,
61 template (value) BvcState state) := {
62 nsei := nsei,
63 bvci := bvci,
64 state := state
Harald Welte853c0ad2018-02-15 17:45:29 +010065}
66
Harald Welte5339b2e2020-10-04 22:52:56 +020067template (present) BssgpStatusIndication
68tr_BssgpStsInd(template Nsei nsei, template (present) BssgpBvci bvci,
69 template (present) BvcState state) := {
Harald Welte853c0ad2018-02-15 17:45:29 +010070 nsei := nsei,
71 bvci := bvci,
72 state := state
73}
74
75type enumerated BvcState {
Harald Welte5339b2e2020-10-04 22:52:56 +020076 /* SGSN role: waiting to be reset by the peer */
77 BVC_S_WAIT_RESET,
78 /* PCU role: waiting for NS_ALIVE_UNBLOCKED */
79 BVC_S_WAIT_NS_ALIVE_UNBLOCKED,
80 /* BVC-BLOCKED state */
Harald Welte853c0ad2018-02-15 17:45:29 +010081 BVC_S_BLOCKED,
Harald Welte5339b2e2020-10-04 22:52:56 +020082 /* BVC-UNBLOCKED state */
Harald Welte853c0ad2018-02-15 17:45:29 +010083 BVC_S_UNBLOCKED
84};
85
86/* port from our (internal) point of view */
87type port BSSGP_SP_PT message {
Harald Welte5ac31492018-02-15 20:39:13 +010088 in PDU_BSSGP,
Harald Welte93331e72020-09-12 20:51:05 +020089 PDU_LLC
90#ifdef BSSGP_EM_L3
91 ,
Harald Welte5ac31492018-02-15 20:39:13 +010092 PDU_L3_MS_SGSN,
Harald Welte93331e72020-09-12 20:51:05 +020093 PDU_L3_SGSN_MS
94#endif
95 ;
Harald Welte955aa942019-05-03 01:29:29 +020096 out PDU_BSSGP,
97 PDU_LLC,
98 PDU_SN,
Harald Welte853c0ad2018-02-15 17:45:29 +010099 NsStatusIndication,
100 BssgpStatusIndication,
Harald Welte93331e72020-09-12 20:51:05 +0200101 ASP_Event
102#ifdef BSSGP_EM_L3
103 ,
Harald Welte5ac31492018-02-15 20:39:13 +0100104 PDU_L3_MS_SGSN,
Harald Welte93331e72020-09-12 20:51:05 +0200105 PDU_L3_SGSN_MS
106#endif
107 ;
Harald Welte853c0ad2018-02-15 17:45:29 +0100108} with { extension "internal" };
109
110/* port from the user point of view */
111type port BSSGP_PT message {
112 in ASP_Event,
113 NsStatusIndication,
114 BssgpStatusIndication,
Harald Welte955aa942019-05-03 01:29:29 +0200115 PDU_BSSGP,
116 PDU_LLC,
Harald Welte93331e72020-09-12 20:51:05 +0200117 PDU_SN
118#ifdef BSSGP_EM_L3
119 ,
Harald Welte5ac31492018-02-15 20:39:13 +0100120 PDU_L3_MS_SGSN,
Harald Welte93331e72020-09-12 20:51:05 +0200121 PDU_L3_SGSN_MS
122#endif
123 ;
Harald Welte5ac31492018-02-15 20:39:13 +0100124 out PDU_BSSGP,
Harald Welte93331e72020-09-12 20:51:05 +0200125 PDU_LLC
126#ifdef BSSGP_EM_L3
127 ,
Harald Welte5ac31492018-02-15 20:39:13 +0100128 PDU_L3_SGSN_MS,
Harald Welte93331e72020-09-12 20:51:05 +0200129 PDU_L3_MS_SGSN
130#endif
131 ;
Harald Welte853c0ad2018-02-15 17:45:29 +0100132} with { extension "internal" };
133
Harald Welte5339b2e2020-10-04 22:52:56 +0200134signature BSSGP_register_client(hexstring imsi, OCT4 tlli);
Harald Welte5ac31492018-02-15 20:39:13 +0100135signature BSSGP_unregister_client(hexstring imsi);
Harald Weltef70997d2018-02-17 10:11:19 +0100136signature BSSGP_llgmm_assign(OCT4 tlli_old, OCT4 tlli);
Harald Welte5ac31492018-02-15 20:39:13 +0100137
138type port BSSGP_PROC_PT procedure {
Harald Weltef70997d2018-02-17 10:11:19 +0100139 inout BSSGP_register_client, BSSGP_unregister_client, BSSGP_llgmm_assign;
Harald Welte5ac31492018-02-15 20:39:13 +0100140} with { extension "internal" };
141
142
Harald Welte5339b2e2020-10-04 22:52:56 +0200143
Harald Welte5ac31492018-02-15 20:39:13 +0100144/***********************************************************************
145 * Client Component for a single MS/TLLI
Harald Welte5339b2e2020-10-04 22:52:56 +0200146 ***********************************************************************
147 * This is what most users will want to derive their test cases from. It
148 * provides a set of three different ports (PTP, signaling, procedure)
149 * for (currently up to 3) different Cells. Those ports are all connected
150 * to one or multiple different per-BVC compoennts, depending on whether
151 * they share the same BSS or not.
Harald Welte5ac31492018-02-15 20:39:13 +0100152 ***********************************************************************/
153
154type component BSSGP_Client_CT {
Harald Welte5339b2e2020-10-04 22:52:56 +0200155 /* one port array for each client; allows talking to up to 3 BVC/Cell (handover, ...) */
156 port BSSGP_PT BSSGP[3]; /* PTP-BVC */
157 port BSSGP_PT BSSGP_SIG[3]; /* Signaling BVC */
158 port BSSGP_PROC_PT BSSGP_PROC[3]; /* registration / deregistration */
Harald Welte5ac31492018-02-15 20:39:13 +0100159};
160
Harald Welte5339b2e2020-10-04 22:52:56 +0200161function f_bssgp_client_register(hexstring imsi, OCT4 tlli, BSSGP_PROC_PT PT := BSSGP_PROC[0])
162runs on BSSGP_Client_CT {
163 PT.call(BSSGP_register_client:{imsi, tlli}) {
164 [] PT.getreply(BSSGP_register_client:{imsi, tlli}) {};
165 }
166}
167
168function f_bssgp_client_unregister(hexstring imsi, BSSGP_PROC_PT PT := BSSGP_PROC[0])
169runs on BSSGP_Client_CT {
170 PT.call(BSSGP_unregister_client:{imsi}) {
171 [] PT.getreply(BSSGP_unregister_client:{imsi}) {};
172 }
173}
174
175/* TS 44.064 7.2.1.1 LLGMM-ASSIGN */
176function f_bssgp_client_llgmm_assign(OCT4 tlli_old, OCT4 tlli_new, BSSGP_PROC_PT PT := BSSGP_PROC[0])
177runs on BSSGP_Client_CT {
178 PT.call(BSSGP_llgmm_assign:{tlli_old, tlli_new}) {
179 [] PT.getreply(BSSGP_llgmm_assign:{tlli_old, tlli_new}) {};
180 }
181}
182
Harald Welte5ac31492018-02-15 20:39:13 +0100183/***********************************************************************
184 * Main Component
Harald Welte5339b2e2020-10-04 22:52:56 +0200185 ***********************************************************************
186 * This component exists once, and it runs on to of the NS_Emulation.
187 * It handles the BVC-RESET for the signaling BVCI, and dispatches messages
188 * to the per-BVC components running above it. Messages are routed by:
189 * - PTP BVCI in NS header (if non-0)
190 * - BVCI IE in messages on BVCI=0 in NS header
191 * Messages for which no unique BVC can be identified (like paging without
192 * a BVCI IE set) are broadcast to all BVC components.
193 * We also broadcast state changes (BssgpStatusIndication) and reset events
194 * (BssgpResetIndication) of the signaling BVC to all per-BVC components.
Harald Welte5ac31492018-02-15 20:39:13 +0100195 ***********************************************************************/
196
Harald Welte5339b2e2020-10-04 22:52:56 +0200197function BssgpStart(BssgpConfig cfg, charstring id) runs on BSSGP_CT {
Harald Welte5ac31492018-02-15 20:39:13 +0100198 g_cfg := cfg;
Harald Welte5339b2e2020-10-04 22:52:56 +0200199
200 /* create the per-BVC components based on the configuration */
201 for (var integer i := 0; i < lengthof(g_cfg.bvc); i := i+1) {
202 var BssgpBvcConfig bvc_cfg := g_cfg.bvc[i];
203 var charstring bvc_id := id & "-BVCI" & int2str(bvc_cfg.bvci);
204 /* create, connect and start the BVC component */
205 var BSSGP_BVC_CT bvc_ct := BSSGP_BVC_CT.create(bvc_id);
206 connect(bvc_ct:BVC, self:BVC);
Harald Weltefba7afd2020-11-24 23:12:31 +0100207 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 +0200208 /* populate the BVC state table */
209 BvcTable[i] := {
210 bvci := bvc_cfg.bvci,
211 cell_id := bvc_cfg.cell_id,
212 comp_ref := bvc_ct
213 };
214 }
215
216 if (g_cfg.sgsn_role) {
217 /* The SGSN side waits for an inbound BVC-RESET on the signaling BVC */
218 f_sign_change_state(BVC_S_WAIT_RESET);
219 } else {
220 /* The BSS/PCU side waits for an inbound NsStatusIndication to Tx BVC-RESET */
221 f_sign_change_state(BVC_S_WAIT_NS_ALIVE_UNBLOCKED);
222 }
223
224 /* main loop */
225 f_bssgp_ScanEvents();
Harald Welte853c0ad2018-02-15 17:45:29 +0100226}
227
Harald Welte5339b2e2020-10-04 22:52:56 +0200228/* master component, exists once per BSSGP instance (NSE) */
Harald Welte853c0ad2018-02-15 17:45:29 +0100229type component BSSGP_CT {
Stefan Sperlingf82bbb62018-05-03 19:14:28 +0200230 /* UDP ports towards the bottom (IUT) */
Harald Welte853c0ad2018-02-15 17:45:29 +0100231 port NS_PT BSCP;
Harald Welte5339b2e2020-10-04 22:52:56 +0200232
233 /* control by the user */
234 port BSSGP_CT_PROC_PT PROC;
235
Harald Welte57de2202020-11-24 18:15:02 +0100236 /* global port for procedures without any relation to a BVC
237 * (currently only) SUSPEND/RESUME */
238 port BSSGP_SP_PT GLOBAL;
239
Harald Weltebdf96d82020-11-27 18:58:46 +0100240 /* port to a management instance */
241 port BSSGP_BVC_MGMT_SP_PT MGMT;
242
Harald Welte5339b2e2020-10-04 22:52:56 +0200243 var BssgpConfig g_cfg;
244
245 /* Signaling BVC (BVCI=0) */
246 var BvcState g_sign_bvc_state := BVC_S_WAIT_RESET;
247 timer g_T2 := 60.0;
248
249 /* port to per-BVC components */
250 port BSSGP_BVC_SP_PT BVC;
251 /* per-BVC state table */
252 var BvcEntity BvcTable[16];
253};
254
255/* one element in the per-BVC state table */
256type record BvcEntity {
257 /* PTP BVCI of this BVC/Cell */
258 BssgpBvci bvci,
259 /* Cell Identity of this cell */
260 BssgpCellId cell_id,
261 /* reference to the per-BVC/cell component */
262 BSSGP_BVC_CT comp_ref
263};
264
265/* find the per-BVC component for a given BVCI */
266private function f_comp_for_bvci(BssgpBvci bvci) runs on BSSGP_CT return BSSGP_BVC_CT {
267 var integer i;
268
269 for (i := 0; i < lengthof(BvcTable); i := i+1) {
270 if (BvcTable[i].bvci == bvci) {
271 return BvcTable[i].comp_ref;
272 }
273 }
274 return null;
275}
276
277/* We are in BVC_S_WAIT_RSET state (only happens in SGSN role) */
278altstep as_sig_wait_reset() runs on BSSGP_CT {
279 var NsUnitdataIndication udi;
280
281 /* Respond to RESET for signalling BVCI 0 */
282 [] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, 0, omit), 0)) -> value udi {
283 log("Rx BVC-RESET for Signaling BVCI=0");
Harald Welte5339b2e2020-10-04 22:52:56 +0200284 f_sign_change_state(BVC_S_UNBLOCKED);
Harald Weltebdf96d82020-11-27 18:58:46 +0100285 if (MGMT.checkstate("Connected")) {
286 MGMT.send(BssgpResetIndication:{0});
287 }
288 BSCP.send(f_BnsUdReq(ts_BVC_RESET_ACK(0, omit), 0, 0));
Harald Welte5339b2e2020-10-04 22:52:56 +0200289 }
290
291 /* work-around for old, buggy libosmogb before Change-Id Ie87820537d6d616da4fd4bbf73eab06e28fda5e1 */
292 [mp_tolerate_bvc_reset_cellid] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, 0, g_cfg.bvc[0].cell_id), 0)) -> value udi {
293 log("Rx BVC-RESET for Signaling BVCI=0");
Harald Welte5339b2e2020-10-04 22:52:56 +0200294 f_sign_change_state(BVC_S_UNBLOCKED);
Harald Weltebdf96d82020-11-27 18:58:46 +0100295 if (MGMT.checkstate("Connected")) {
296 MGMT.send(BssgpResetIndication:{0});
297 }
298 BSCP.send(f_BnsUdReq(ts_BVC_RESET_ACK(0, omit), 0, 0));
Harald Welte5339b2e2020-10-04 22:52:56 +0200299 }
300}
301
Harald Welte57de2202020-11-24 18:15:02 +0100302private template PDU_BSSGP tr_GLOBAL := (
303 {pDU_BSSGP_SUSPEND:=?}, {pDU_BSSGP_SUSPEND_ACK:=?}, {pDU_BSSGP_SUSPEND_NACK:=?},
304 {pDU_BSSGP_RESUME:=?}, {pDU_BSSGP_RESUME_ACK:=?}, {pDU_BSSGP_RESUME_NACK:=?}
305);
306
Harald Welte5339b2e2020-10-04 22:52:56 +0200307/* We are in BVC_S_UNBLOCKED state */
308altstep as_sig_unblocked() runs on BSSGP_CT {
309 var BSSGP_BVC_CT bvc_comp_ref;
310 var BSSGP_Client_CT vc_conn;
311 var NsUnitdataIndication udi;
312 var NsUnitdataRequest udr;
Harald Welte57de2202020-11-24 18:15:02 +0100313 var PDU_BSSGP bssgp;
Harald Welte5339b2e2020-10-04 22:52:56 +0200314
315 /* Messages PTP BVCI in BVCI field of NS: dispatch by that */
316 [] BSCP.receive(f_BnsUdInd(?, (2..65535))) -> value udi {
317 bvc_comp_ref := f_comp_for_bvci(valueof(udi.bvci));
318 if (isbound(bvc_comp_ref) and bvc_comp_ref != null) {
319 /* dispatch to BVC component */
320 BVC.send(udi) to bvc_comp_ref;
321 } else {
322 setverdict(fail, "Rx BSSGP for unknown PTP BVCI ", udi.bvci, ": ", udi.bssgp);
Harald Weltec4505522020-11-11 18:55:09 +0100323 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 +0200324 }
325 }
326
327 /* Messages with BVCI = 0 (Signaling) in BVCI field of NS */
Harald Welte57de2202020-11-24 18:15:02 +0100328 [] BSCP.receive(f_BnsUdInd(tr_GLOBAL, 0)) -> value udi {
329 GLOBAL.send(udi.bssgp);
330 }
Harald Welte5339b2e2020-10-04 22:52:56 +0200331
332 /* Route based on PTP BVCI in payload/IE of signaling PDU */
333 [] BSCP.receive(f_BnsUdInd(?, 0)) -> value udi {
334 var template (omit) BssgpBvci ptp_bvci := f_BSSGP_BVCI_get(udi.bssgp);
335 if (istemplatekind(ptp_bvci, "omit")) {
336 log("Rx on SIG BVCI without PTP BVCI: broadcasting");
337 for (var integer i := 0; i < lengthof(BvcTable); i := i+1) {
338 if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) {
339 BVC.send(udi) to BvcTable[i].comp_ref;
340 }
341 }
342 } else {
343 bvc_comp_ref := f_comp_for_bvci(valueof(ptp_bvci));
344 if (isbound(bvc_comp_ref) and bvc_comp_ref != null) {
345 /* dispatch to BVC component */
346 BVC.send(udi) to bvc_comp_ref;
347 } else {
348 setverdict(fail, "Rx SIG BSSGP for unknown PTP BVCI ", ptp_bvci, ": ", udi.bssgp);
Harald Weltec4505522020-11-11 18:55:09 +0100349 BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(udi.bvci, BSSGP_CAUSE_BVCI_UNKNOWN, udi.bssgp), 0, 0));
Harald Welte5339b2e2020-10-04 22:52:56 +0200350 }
351 }
352 }
353
354 /* Handle PS-PAGING on SIGN BVCI with no conditional BVCI IE */
355 [] BSCP.receive(f_BnsUdInd(PDU_BSSGP:{pDU_BSSGP_PAGING_PS:=?}, 0)) -> value udi {
356 /* FIXME: use LA, RA or BSS Area to dispatch instead of broadcast */
357 for (var integer i := 0; i < lengthof(BvcTable); i := i+1) {
358 if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) {
359 BVC.send(udi) to BvcTable[i].comp_ref;
360 }
361 }
362 }
363 /* Handle CS-PAGING on SIGN BVCI with no conditional BVCI IE */
364 [] BSCP.receive(f_BnsUdInd(PDU_BSSGP:{pDU_BSSGP_PAGING_CS:=?}, 0)) -> value udi {
365 /* FIXME: use LA, RA or BSS Area to dispatch instead of broadcast */
366 for (var integer i := 0; i < lengthof(BvcTable); i := i+1) {
367 if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) {
368 BVC.send(udi) to BvcTable[i].comp_ref;
369 }
370 }
371 }
372
373 /* per-BVC component sends us something; forward to NS without any validation */
374 [] BVC.receive(NsUnitdataRequest:?) -> value udr {
375 /* patch in the NSEI, as the per-BVC components have no idea about it */
376 udr.nsei := g_cfg.nsei;
377 BSCP.send(udr);
378 }
Harald Welte57de2202020-11-24 18:15:02 +0100379
380 [] GLOBAL.receive(tr_GLOBAL) -> value bssgp {
381 BSCP.send(f_BnsUdReq(bssgp, 0, 0));
382 }
Harald Welte5339b2e2020-10-04 22:52:56 +0200383}
384
385/* We are in BVC_S_WAIT_NS_ALIVE_UNBLOCKED (only happens in BSS role) */
386altstep as_sig_wait_ns_alive_unblocked() runs on BSSGP_CT {
387 var NsStatusIndication nsi;
Harald Weltedc0a0902020-11-10 21:03:29 +0100388 [] 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 +0200389 /* if we just became NS-unblocked, send a BCC-RESET */
390 if (g_cfg.sgsn_role == false) {
Harald Weltec4505522020-11-11 18:55:09 +0100391 BSCP.send(f_BnsUdReq(ts_BVC_RESET(BSSGP_CAUSE_OM_INTERVENTION, 0, omit), 0, 0));
Harald Welte5339b2e2020-10-04 22:52:56 +0200392 g_T2.start;
393 /* The BVC_RESET_ACK is handled in the as_sig_allstate() below */
394 }
395 /* Idea: We could send BVC-UNBLOCK here like some SGSN do */
396 }
397
398}
399
400/* handling of events irrespective of BVC state */
401altstep as_sig_allstate() runs on BSSGP_CT {
402 var BSSGP_Client_CT vc_conn;
403 var NsUnitdataIndication udi;
404 var NsStatusIndication nsi;
405 var ASP_Event evt;
406 var BSSGP_BVC_CT bvc_comp_ref;
407 var BssgpBvci bvci;
408
409 /* Respond to RESET for signalling BVCI 0 */
410 [] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, 0, omit), 0)) -> value udi {
411 log("Rx BVC-RESET for Signaling BVCI=0");
Harald Weltebdf96d82020-11-27 18:58:46 +0100412 if (MGMT.checkstate("Connected")) {
413 MGMT.send(BssgpResetIndication:{0});
414 }
Harald Weltec4505522020-11-11 18:55:09 +0100415 BSCP.send(f_BnsUdReq(ts_BVC_RESET_ACK(0, omit), 0, 0));
Harald Welte5339b2e2020-10-04 22:52:56 +0200416 for (var integer i := 0; i < sizeof(BvcTable); i := i+1) {
417 if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) {
418 BVC.send(BssgpResetIndication:{0}) to BvcTable[i].comp_ref;
419 }
420 }
421 }
422
423 /* any BLOCK or UNBLOCK for the SIGNALING BVCI are illegal */
424 [] BSCP.receive(f_BnsUdInd(t_BVC_BLOCK(0, ?), 0)) -> value udi {
425 setverdict(fail, "Rx BVC-BLOCK illegal for BVCI=0: ", udi);
426 }
427 [] BSCP.receive(f_BnsUdInd(t_BVC_UNBLOCK(0), 0)) -> value udi {
428 setverdict(fail, "Rx BVC-UNBLOCK illegal for BVCI=0: ", udi);
429 }
430 [] BSCP.receive(f_BnsUdInd(t_BVC_BLOCK_ACK(0), 0)) -> value udi {
431 setverdict(fail, "Rx BVC-BLOCK-ACK illegal for BVCI=0: ", udi);
432 }
433 [] BSCP.receive(f_BnsUdInd(t_BVC_UNBLOCK_ACK(0), 0)) -> value udi {
434 setverdict(fail, "Rx BVC-UNBLOCK-ACK illegal for BVCI=0: ", udi);
435 }
436
437 /* Respond to BLOCK for wrong BVCI */
438 [] BSCP.receive(f_BnsUdInd(t_BVC_BLOCK(?, ?), 0)) -> value udi {
439 setverdict(fail, "Rx BVC-BLOCK for unknown BVCI");
Harald Weltec4505522020-11-11 18:55:09 +0100440 BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(0, BSSGP_CAUSE_BVCI_UNKNOWN, udi.bssgp), 0, 0));
Harald Welte5339b2e2020-10-04 22:52:56 +0200441 }
442
443 /* Respond to RESET with wrong BVCI */
444 [] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, ?, ?), 0)) -> value udi {
445 var BssgpBvci ptp_bvci := oct2int(udi.bssgp.pDU_BSSGP_BVC_RESET.bVCI.unstructured_value);
446 setverdict(fail, "Rx BVC-RESET for unknown BVCI ", ptp_bvci);
Harald Weltec4505522020-11-11 18:55:09 +0100447 BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(ptp_bvci, BSSGP_CAUSE_BVCI_UNKNOWN, udi.bssgp), 0, 0));
Harald Welte5339b2e2020-10-04 22:52:56 +0200448 }
449
450 /* BVC-RESET-ACK for BVCI=0 while T2 is running: Answer to a BVC-RESET we sent earlier */
451 [g_T2.running] BSCP.receive(f_BnsUdInd(tr_BVC_RESET_ACK(0, omit), 0)) -> value udi {
452 log("BVCI(0) Rx BVC-RESET-ACK");
453 g_T2.stop;
454 f_sign_change_state(BVC_S_UNBLOCKED);
455 for (var integer i := 0; i < sizeof(BvcTable); i := i+1) {
456 if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) {
457 BVC.send(BssgpResetIndication:{0}) to BvcTable[i].comp_ref;
458 }
459 }
460 }
461 [] g_T2.timeout {
462 setverdict(fail, "Timeout waiting for BVC-RESET-ACK on BVCI=0");
Harald Weltec4505522020-11-11 18:55:09 +0100463 BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(udi.bvci, BSSGP_CAUSE_BVCI_UNKNOWN, udi.bssgp), 0, 0));
Harald Welte5339b2e2020-10-04 22:52:56 +0200464 g_T2.start;
465 }
466
467 /* default case of handling unknown PDUs */
468 [] BSCP.receive(f_BnsUdInd(?, ?)) -> value udi {
469 setverdict(fail, "Rx Unexpected BSSGP PDU ", udi.bssgp," in state ", g_sign_bvc_state);
Harald Weltec4505522020-11-11 18:55:09 +0100470 BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(0, BSSGP_CAUSE_PDU_NOT_COMPATIBLE_WITH_PROTOCOL_STATE, udi.bssgp), 0, 0));
Harald Welte5339b2e2020-10-04 22:52:56 +0200471 }
472
473 /* Forwarding of ASP_Event to per-BVC components */
474 [] BSCP.receive(ASP_Event:?) -> value evt {
475 for (var integer i := 0; i < sizeof(BvcTable); i := i+1) {
476 if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) {
477 BVC.send(evt) to BvcTable[i].comp_ref;
478 }
479 }
480 }
481 /* Keep NS Status Indicaitons to us; no need to inform per-BVC components [for now?] */
Harald Weltedc0a0902020-11-10 21:03:29 +0100482 [] BSCP.receive(tr_NsStsInd(g_cfg.nsei)) -> value nsi { }
Harald Welte445fc612020-11-10 19:15:30 +0100483 /* We should never see any different NSEI: There's one BSSGP_CT per NSE */
Harald Weltedc0a0902020-11-10 21:03:29 +0100484 [] BSCP.receive(tr_NsStsInd(?)) -> value nsi {
Harald Welte445fc612020-11-10 19:15:30 +0100485 setverdict(fail, "Rx NsStatusInd for wrong NSEI ", nsi);
486 }
Harald Welte5339b2e2020-10-04 22:52:56 +0200487
488 /* Procedure port request to resolve the per-BVC component for a given ptp BVCI */
489 [] PROC.getcall(BSSGP_get_bvci_ct:{?}) -> param(bvci) sender vc_conn {
490 for (var integer i := 0; i < sizeof(BvcTable); i := i+1) {
491 if (BvcTable[i].bvci == bvci) {
492 PROC.reply(BSSGP_get_bvci_ct:{bvci} value BvcTable[i].comp_ref) to vc_conn;
493 return;
494 }
495 }
496 }
497}
498
499/* send the highest decoded layer of the message through given port */
500private function f_send_bssgp_dec(BssgpDecoded dec, BSSGP_Client_CT vc_conn, BSSGP_SP_PT pt) {
501#ifdef BSSGP_EM_L3
502 if (ispresent(dec.l3_mt)) {
503 pt.send(dec.l3_mt) to vc_conn;
504 } else if (ispresent(dec.l3_mo)) {
505 pt.send(dec.l3_mo) to vc_conn;
506 } else
507#endif
508 if (ispresent(dec.sndcp)) {
509 pt.send(dec.sndcp) to vc_conn;
510 } else if (ispresent(dec.llc)) {
511 pt.send(dec.llc) to vc_conn;
512 } else {
513 pt.send(dec.bssgp) to vc_conn;
514 }
515}
516
517
518function f_llc_get_n_u_tx(inout LLC_Entity llc) return uint9_t {
519 var uint9_t ret := llc.n_u_tx_next;
520 llc.n_u_tx_next := llc.n_u_tx_next + 1;
521 return ret;
522}
523
524#ifdef BSSGP_EM_L3
525function f_llc_sapi_by_l3_mo(PDU_L3_MS_SGSN l3_mo) return BIT4 {
526 if (ischosen(l3_mo.msgs.gprs_mm)) {
527 return c_LLC_SAPI_LLGMM;
528 } else if (ischosen(l3_mo.msgs.gprs_sm)) {
529 return c_LLC_SAPI_LLGMM;
530 } else if (ischosen(l3_mo.msgs.sms)) {
531 return c_LLC_SAPI_LLSMS;
532 }
533 setverdict(fail, "No LLC SAPI for ", l3_mo);
534 mtc.stop;
535}
536
537private function f_llc_sapi_by_l3_mt(PDU_L3_SGSN_MS l3_mt) return BIT4 {
538 if (ischosen(l3_mt.msgs.gprs_mm)) {
539 return c_LLC_SAPI_LLGMM;
540 } else if (ischosen(l3_mt.msgs.gprs_sm)) {
541 return c_LLC_SAPI_LLGMM;
542 } else if (ischosen(l3_mt.msgs.sms)) {
543 return c_LLC_SAPI_LLSMS;
544 }
545 setverdict(fail, "No LLC SAPI for ", l3_mt);
546 mtc.stop;
547}
548#endif
549
550/* main loop of BSSGP_CT */
551private function f_bssgp_ScanEvents() runs on BSSGP_CT {
552 while (true) {
553 alt {
554 [g_sign_bvc_state == BVC_S_WAIT_RESET] as_sig_wait_reset();
555 [g_sign_bvc_state == BVC_S_WAIT_NS_ALIVE_UNBLOCKED] as_sig_wait_ns_alive_unblocked();
556 [g_sign_bvc_state == BVC_S_UNBLOCKED] as_sig_unblocked();
557 [] as_sig_allstate();
558 }
559 } /* while */
560}
561
562/* generate a send template. Cannot be a real template as we want to use g_cfg.nsei */
Harald Weltec4505522020-11-11 18:55:09 +0100563private function f_BnsUdReq(template PDU_BSSGP pdu, BssgpBvci bvci, integer lsp)
Harald Welte5339b2e2020-10-04 22:52:56 +0200564runs on BSSGP_CT return NsUnitdataRequest {
565 var NsUnitdataRequest udr := {
566 bvci := bvci,
567 nsei := g_cfg.nsei,
Harald Weltec4505522020-11-11 18:55:09 +0100568 lsp := lsp,
Harald Welte5339b2e2020-10-04 22:52:56 +0200569 /* for some weird reason we get "Dynamic test case error: Text encoder: Encoding an
570 * unbound integer value." when trying to send the reocrd rather than the octetstring */
571 //sdu := omit,
572 //bssgp := valueof(pdu)
573 sdu := enc_PDU_BSSGP(valueof(pdu)),
574 bssgp := omit
575 }
576 return udr;
577}
578
579/* generate a receive template. Cannot be a real template as we want to use g_cfg.nsei */
580private function f_BnsUdInd(template PDU_BSSGP pdu, template BssgpBvci bvci)
581runs on BSSGP_CT return template (present) NsUnitdataIndication {
582 var template (present) NsUnitdataIndication udi := {
583 bvci := bvci,
584 nsei := g_cfg.nsei,
Harald Welte80a249a2020-11-17 19:57:40 +0100585 nsvci := ?,
Harald Welte5339b2e2020-10-04 22:52:56 +0200586 sdu := *,
587 bssgp := pdu
588 }
589 return udi;
590}
591
592/* change state of signaling BVCI; notify per-BVC components */
593private function f_sign_change_state(BvcState new_state) runs on BSSGP_CT {
594 if (new_state == g_sign_bvc_state) {
595 return;
596 }
597 log("BVCI(0) State Transition: ", g_sign_bvc_state, " -> ", new_state);
598 g_sign_bvc_state := new_state;
599 for (var integer i := 0; i < sizeof(BvcTable); i := i+1) {
600 if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) {
601 BVC.send(ts_BssgpStsInd(g_cfg.nsei, 0, g_sign_bvc_state)) to BvcTable[i].comp_ref;
602 }
603 }
604}
605
606/* User wants to get per-BVC component reference from BSSGP_CT */
607signature BSSGP_get_bvci_ct(BssgpBvci bvci) return BSSGP_BVC_CT;
608
609type port BSSGP_CT_PROC_PT procedure {
610 inout BSSGP_get_bvci_ct
611} with { extension "internal" };
612
613/* convenience wrapper function for user */
614function f_bssgp_get_bvci_ct(BssgpBvci bvci, BSSGP_CT_PROC_PT PT) return BSSGP_BVC_CT {
615 var BSSGP_BVC_CT res;
616 PT.call(BSSGP_get_bvci_ct:{bvci}) {
617 [] PT.getreply(BSSGP_get_bvci_ct:{bvci})-> value res {
618 return res;
619 }
620 }
621}
622
623/***********************************************************************
624 * per-BVC (Cell) Component
625 ***********************************************************************
626 * Any number of these components runs on top of the BSSGP_CT, each
627 * representing one PTP BVC within this NSE. Users (test cases) can
628 * register with TLLI and/or IMSI via the procedure port.
629 ***********************************************************************/
630
631/* per-BVC component. Exists once per cell within a BSSGP_CT */
632type component BSSGP_BVC_CT {
633 /* port towards the underlying BSSGP_CT */
634 port BSSGP_BVC_PT BVC;
635
Harald Welte199f3862020-11-15 22:37:45 +0100636 /* port to a management instance */
637 port BSSGP_BVC_MGMT_SP_PT MGMT;
638
Harald Welte5339b2e2020-10-04 22:52:56 +0200639 /* BSSGP-User SAP towards the user (Client) */
Harald Welte853c0ad2018-02-15 17:45:29 +0100640 port BSSGP_SP_PT BSSGP_SP;
Stefan Sperlingf82bbb62018-05-03 19:14:28 +0200641 port BSSGP_SP_PT BSSGP_SP_SIG;
Harald Welte5ac31492018-02-15 20:39:13 +0100642 port BSSGP_PROC_PT BSSGP_PROC;
Harald Welte853c0ad2018-02-15 17:45:29 +0100643
Harald Welte5339b2e2020-10-04 22:52:56 +0200644 var BssgpBvcConfig g_cfg;
645 var boolean g_sgsn_role;
Harald Weltefba7afd2020-11-24 23:12:31 +0100646 var Nsei g_nsei;
Harald Welte5ac31492018-02-15 20:39:13 +0100647
Harald Weltec4505522020-11-11 18:55:09 +0100648 /* default Link Selector Parameter for this BVC (for traffic unrelated to a TLLI) */
649 var integer g_bvc_lsp;
650
Harald Welte853c0ad2018-02-15 17:45:29 +0100651 var BvcState g_ptp_bvc_state := BVC_S_BLOCKED;
652 timer g_T1 := 15.0;
653 timer g_T2 := 60.0;
Harald Welte5339b2e2020-10-04 22:52:56 +0200654 var boolean g_t1_waits_for_block_ack := false;
Harald Welte199f3862020-11-15 22:37:45 +0100655 /* for re-transmissions */
656 var BssgpCause g_last_block_cause;
657 var BssgpCause g_last_reset_cause;
Harald Welte5ac31492018-02-15 20:39:13 +0100658
659 var ClientEntity ClientTable[16];
Harald Welte5339b2e2020-10-04 22:52:56 +0200660};
Harald Welte853c0ad2018-02-15 17:45:29 +0100661
Harald Welte5339b2e2020-10-04 22:52:56 +0200662/* port between global BSSGP_CT and per-BVC BSSGP_BVC_CT */
663type port BSSGP_BVC_SP_PT message {
664 in NsUnitdataRequest;
665 out ASP_Event,
666 BssgpStatusIndication,
667 BssgpResetIndication,
668 NsUnitdataIndication;
669} with { extension "internal" };
670type port BSSGP_BVC_PT message {
671 in ASP_Event,
672 BssgpStatusIndication,
673 BssgpResetIndication,
674 NsUnitdataIndication;
675 out NsUnitdataRequest;
676} with { extension "internal" };
Alexander Couzens6b449fb2018-07-31 14:19:36 +0200677
Harald Welte199f3862020-11-15 22:37:45 +0100678/* port between BSSGP_BVC_CT and a management instance */
679type port BSSGP_BVC_MGMT_SP_PT message {
680 in BssgpResetRequest,
681 BssgpBlockRequest,
682 BssgpUnblockRequest;
683 out BssgpStatusIndication,
684 BssgpResetIndication;
685} with { extension "internal" };
686type port BSSGP_BVC_MGMT_PT message {
687 in BssgpStatusIndication,
688 BssgpResetIndication;
689 out BssgpResetRequest,
690 BssgpBlockRequest,
691 BssgpUnblockRequest;
692} with { extension "internal" };
693
694type record BssgpResetRequest {
695 BssgpCause cause
696};
697type record BssgpBlockRequest {
698 BssgpCause cause
699};
700type record BssgpUnblockRequest {
701};
Harald Welte5339b2e2020-10-04 22:52:56 +0200702
703/* one element in the per-TLLI state table */
Harald Welte5ac31492018-02-15 20:39:13 +0100704type record ClientEntity {
705 OCT4 tlli,
706 OCT4 tlli_old optional,
707 hexstring imsi,
Harald Welte5ac31492018-02-15 20:39:13 +0100708 BSSGP_Client_CT comp_ref,
709 /* LLC entities, one for each SAPI */
710 LLC_Entity llc[16]
Harald Welte853c0ad2018-02-15 17:45:29 +0100711};
Harald Welte5ac31492018-02-15 20:39:13 +0100712type record LLC_Entity {
713 boolean sgsn_role,
714 /* N(U) on transmit side for next PDU */
715 uint9_t n_u_tx_next,
716 /* N(U) on receive side, last PDU */
717 uint9_t n_u_rx_last optional
718};
Harald Welte5339b2e2020-10-04 22:52:56 +0200719type record length(16) of LLC_Entity LLC_Entities;
Harald Welte5ac31492018-02-15 20:39:13 +0100720
Alexander Couzenscdfb7512018-07-31 15:37:14 +0200721function f_llc_create(boolean sgsn_role := false) return LLC_Entities {
722 var LLC_Entities llc;
723 for (var integer i := 0; i < 16; i := i+1) {
724 llc[i] := valueof(t_LLC_init(sgsn_role));
725 }
726 return llc;
727}
728
Harald Welte5ac31492018-02-15 20:39:13 +0100729private template LLC_Entity t_LLC_init(boolean sgsn_role := false) := {
730 sgsn_role := sgsn_role,
731 n_u_tx_next := 0,
732 n_u_rx_last := -
733}
734
Harald Welte5339b2e2020-10-04 22:52:56 +0200735/* configuration of BSSGP_CT */
736type record BssgpConfig {
737 Nsvci nsei,
738 boolean sgsn_role,
739 BssgpBvcConfigs bvc
740};
741/* Configuration of one BVC (Cell) BSSGP_BVC_CT */
742type record BssgpBvcConfig {
743 BssgpBvci bvci,
744 BssgpCellId cell_id,
Harald Welte4d112c92020-11-12 19:48:31 +0100745 BssgpDecodeDepth depth,
746 BssgpCreateCallback create_cb
Harald Welte5339b2e2020-10-04 22:52:56 +0200747};
748type record of BssgpBvcConfig BssgpBvcConfigs;
Oliver Smithaac9b9c2019-09-02 08:36:36 +0200749type enumerated BssgpDecodeDepth {
750 BSSGP_DECODE_DEPTH_BSSGP,
751 BSSGP_DECODE_DEPTH_LLC,
Harald Welte93331e72020-09-12 20:51:05 +0200752 BSSGP_DECODE_DEPTH_SNDCP
753#ifdef BSSGP_EM_L3
754 ,
Oliver Smithaac9b9c2019-09-02 08:36:36 +0200755 BSSGP_DECODE_DEPTH_L3
Harald Welte93331e72020-09-12 20:51:05 +0200756#endif
Oliver Smithaac9b9c2019-09-02 08:36:36 +0200757};
Harald Welte4d112c92020-11-12 19:48:31 +0100758/* call-back function type: Called for inbound BSSGP for unknown TLLIs; could create BSSGP_ClienT_CT */
759type function BssgpCreateCallback(BssgpBvci bvci, BssgpCellId cell_id, OCT4 tlli, BssgpDecoded dec) runs on BSSGP_BVC_CT;
760
761/* Default Create Callback function: Fail and terminate */
762function DefaultCreateCallback(BssgpBvci bvci, BssgpCellId cell_id, OCT4 tlli, BssgpDecoded dec) runs on BSSGP_BVC_CT {
763 setverdict(fail, "Couldn't find Component for TLLI ", tlli);
764 mtc.stop;
765}
Oliver Smithaac9b9c2019-09-02 08:36:36 +0200766
Harald Welte5339b2e2020-10-04 22:52:56 +0200767/*
768private function f_tbl_init() runs on BSSGP_BVC_CT {
769 var integer i;
770 for (i := 0; i < sizeof(ImsiTable); i := i+1) {
771 ImsiTable[i] := -;
Harald Welte853c0ad2018-02-15 17:45:29 +0100772 }
Harald Welte853c0ad2018-02-15 17:45:29 +0100773
Harald Welte5339b2e2020-10-04 22:52:56 +0200774 for (i := 0; i < sizeof(TlliTable); i := i+1) {
775 TlliTable[i] := -;
Harald Welte853c0ad2018-02-15 17:45:29 +0100776 }
Harald Welte853c0ad2018-02-15 17:45:29 +0100777}
Harald Welte5339b2e2020-10-04 22:52:56 +0200778*/
Harald Welte853c0ad2018-02-15 17:45:29 +0100779
Harald Welte5339b2e2020-10-04 22:52:56 +0200780private function f_tbl_client_add(hexstring imsi, OCT4 tlli, BSSGP_Client_CT vc_conn)
781runs on BSSGP_BVC_CT {
782 var integer i;
783 for (i := 0; i < sizeof(ClientTable); i := i+1) {
784 if (not isvalue(ClientTable[i].comp_ref)) {
785 log("Adding Client=", vc_conn, ", IMSI=", imsi, ", TLLI=", tlli, ", index=", i);
786 ClientTable[i] := {
787 tlli := tlli,
788 tlli_old := omit,
789 imsi := imsi,
790 comp_ref := vc_conn,
791 llc := -
792 };
793 for (var integer j := 0; j < sizeof(ClientTable[i].llc); j := j+1) {
794 ClientTable[i].llc[j] := valueof(t_LLC_init(g_sgsn_role));
795 }
796 return;
Harald Welte5ac31492018-02-15 20:39:13 +0100797 }
798 }
Harald Welte5339b2e2020-10-04 22:52:56 +0200799 testcase.stop("Client Table full");
Harald Welte853c0ad2018-02-15 17:45:29 +0100800}
801
Harald Welte5339b2e2020-10-04 22:52:56 +0200802private function f_tbl_client_del(hexstring imsi, BSSGP_Client_CT vc_conn) runs on BSSGP_BVC_CT {
803 var integer i;
804 for (i := 0; i < sizeof(ClientTable); i := i+1) {
805 if (isvalue(ClientTable[i].imsi) and ClientTable[i].imsi == imsi) {
806 if (ClientTable[i].comp_ref != vc_conn) {
807 setverdict(fail, "Cannot unregister index=", i, " IMSI ", imsi, " registred to ",
808 ClientTable[i].comp_ref, " from ", vc_conn);
809 mtc.stop;
810 }
811 log("Removing Client IMSI=", imsi, ", index=", i);
812 ClientTable[i] := {
813 tlli := -,
814 tlli_old := omit,
815 imsi := ''H,
816 comp_ref := null,
817 llc := - };
818 return;
819 }
820 }
821 log("Warning: Could not find client for IMSI ", imsi);
822 return;
823}
824
825/* TS 44.064 7.2.1.1 LLGMM-ASSIGN */
826private function f_tbl_client_llgmm_assign(OCT4 tlli_old, OCT4 tlli_new, BSSGP_Client_CT vc_conn)
827runs on BSSGP_BVC_CT {
828 var integer i := f_tbl_idx_by_comp(vc_conn);
829
830 if (tlli_old == 'FFFFFFFF'O and tlli_new != 'FFFFFFFF'O) {
831 /* TLLI assignment */
832 ClientTable[i].tlli := tlli_new;
833 ClientTable[i].tlli_old := omit;
834 } else if (tlli_old != 'FFFFFFFF'O and tlli_new != 'FFFFFFFF'O) {
835 /* TLLI change: both active */
836 ClientTable[i].tlli := tlli_new;
837 ClientTable[i].tlli_old := tlli_old;
838 } else if (tlli_old != 'FFFFFFFF'O and tlli_new == 'FFFFFFFF'O) {
839 /* TLLI unassignment: old shall be unassigned; new stays */
840 ClientTable[i].tlli_old := omit;
841 }
842}
843
844private function f_tbl_comp_by_imsi(hexstring imsi) runs on BSSGP_BVC_CT return BSSGP_Client_CT {
845 var integer i;
846 for (i := 0; i < sizeof(ClientTable); i := i+1) {
847 if (isvalue(ClientTable[i].imsi) and isvalue(ClientTable[i].comp_ref)
848 and ClientTable[i].imsi == imsi) {
849 return ClientTable[i].comp_ref;
850 }
851 }
852 setverdict(fail, "Couldn't find Component for IMSI ", imsi);
853 mtc.stop;
854}
855
856private function f_tbl_comp_by_tlli(OCT4 tlli) runs on BSSGP_BVC_CT return BSSGP_Client_CT {
857 var integer i;
858 for (i := 0; i < sizeof(ClientTable); i := i+1) {
859 if (isvalue(ClientTable[i].comp_ref) and
860 (isvalue(ClientTable[i].tlli) and (ClientTable[i].tlli == tlli or
861 isvalue(ClientTable[i].tlli_old) and ClientTable[i].tlli_old == tlli) )) {
862 return ClientTable[i].comp_ref;
863 }
864 }
Harald Welte4d112c92020-11-12 19:48:31 +0100865 return null;
Harald Welte5339b2e2020-10-04 22:52:56 +0200866}
867
868private function f_tbl_idx_by_comp(BSSGP_Client_CT comp_ref) runs on BSSGP_BVC_CT return integer {
869 var integer i;
870 for (i := 0; i < sizeof(ClientTable); i := i+1) {
871 if (isvalue(ClientTable[i].comp_ref) and ClientTable[i].comp_ref == comp_ref) {
872 return i;
873 }
874 }
875 setverdict(fail, "Couldn't find Client for Component ", comp_ref);
876 mtc.stop;
877}
878
879private function f_tbl_tlli_by_comp(BSSGP_Client_CT comp_ref) runs on BSSGP_BVC_CT return OCT4 {
880 var integer i;
881 for (i := 0; i < sizeof(ClientTable); i := i+1) {
882 if (isvalue(ClientTable[i].tlli) and isvalue(ClientTable[i].comp_ref)
883 and ClientTable[i].comp_ref == comp_ref) {
884 return ClientTable[i].tlli;
885 }
886 }
887 setverdict(fail, "Couldn't find TLLI for Component ", comp_ref);
888 mtc.stop;
889}
890
891/* PDU_BSSGP enhanced with LLC and possibly L3 decoded payloads */
892type record BssgpDecoded {
893 PDU_BSSGP bssgp,
894 PDU_LLC llc optional,
895#ifdef BSSGP_EM_L3
896 PDU_L3_MS_SGSN l3_mo optional,
897 PDU_L3_SGSN_MS l3_mt optional,
898#endif
899 PDU_SN sndcp optional
900}
901
902/* Decode a PDU_BSSGP into a BssgpDecoded (i.e. with LLC/L3 decoded, as applicable) */
903private function f_dec_bssgp(PDU_BSSGP bssgp) runs on BSSGP_BVC_CT return BssgpDecoded {
904 var BssgpDecoded dec := {
905 bssgp := bssgp,
906 llc := omit,
907#ifdef BSSGP_EM_L3
908 l3_mo := omit,
909 l3_mt := omit,
910#endif
911 sndcp := omit
912 };
913
914 /* Decode LLC, if it is a PDU that contains LLC */
915 if (g_cfg.depth >= BSSGP_DECODE_DEPTH_LLC) {
916 if (ischosen(bssgp.pDU_BSSGP_DL_UNITDATA)) {
917 dec.llc := dec_PDU_LLC(bssgp.pDU_BSSGP_DL_UNITDATA.lLC_PDU.lLC_PDU);
918 } else if (ischosen(bssgp.pDU_BSSGP_UL_UNITDATA)) {
919 dec.llc := dec_PDU_LLC(bssgp.pDU_BSSGP_UL_UNITDATA.lLC_PDU.lLC_PDU);
920 }
921 }
922
923 /* Decode SNDCP, if it is a LLC PDU containing user plane data */
924 if (g_cfg.depth >= BSSGP_DECODE_DEPTH_SNDCP) {
925 if (isvalue(dec.llc) and match(dec.llc, tr_LLC_UI_USER)) {
926 dec.sndcp := dec_PDU_SN(dec.llc.pDU_LLC_UI.information_field_UI);
927 }
928 }
929
930#ifdef BSSGP_EM_L3
931 /* Decode L3, if it is a LLC PDU containing L3 */
932 if (g_cfg.depth >= BSSGP_DECODE_DEPTH_L3) {
933 if (isvalue(dec.llc) and match(dec.llc, tr_LLC_UI_L3)) {
934 if (g_sgsn_role) {
935 dec.l3_mo := dec_PDU_L3_MS_SGSN(dec.llc.pDU_LLC_UI.information_field_UI);
936 } else {
937 dec.l3_mt := dec_PDU_L3_SGSN_MS(dec.llc.pDU_LLC_UI.information_field_UI);
938 }
939 }
940 }
941#endif
942
943 return dec;
944}
945
946private function f_ptp_sendUnblock() runs on BSSGP_BVC_CT {
Harald Weltec4505522020-11-11 18:55:09 +0100947 BVC.send(ts_ptp_BnsUdReq(t_BVC_UNBLOCK(g_cfg.bvci), 0, g_bvc_lsp));
Harald Welte5339b2e2020-10-04 22:52:56 +0200948 g_t1_waits_for_block_ack := false;
949 g_T1.start;
950}
951
952private function f_ptp_sendBlock(BssgpCause cause) runs on BSSGP_BVC_CT {
Harald Weltec4505522020-11-11 18:55:09 +0100953 BVC.send(ts_ptp_BnsUdReq(t_BVC_BLOCK(g_cfg.bvci, cause), 0, g_bvc_lsp));
Harald Welte5339b2e2020-10-04 22:52:56 +0200954 g_t1_waits_for_block_ack := true;
955 g_T1.start;
Harald Welte199f3862020-11-15 22:37:45 +0100956 g_last_block_cause := cause;
Harald Welte5339b2e2020-10-04 22:52:56 +0200957}
958
959private function f_ptp_sendStatus(BssgpCause cause, PDU_BSSGP pdu) runs on BSSGP_BVC_CT {
960 /* FIXME: Make sure correct Signaling or PTP BVCI is used! */
Harald Weltec4505522020-11-11 18:55:09 +0100961 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 +0200962}
963
Harald Welte199f3862020-11-15 22:37:45 +0100964private function f_ptp_sendReset(BssgpCause cause := BSSGP_CAUSE_OM_INTERVENTION) runs on BSSGP_BVC_CT {
Harald Weltec967d0e2020-09-14 16:07:26 +0200965 var PDU_BSSGP pdu;
966
967 /* The Cell Identifier IE is mandatory in the BVC-RESET PDU sent from BSS to
968 * SGSN in order to reset a BVC corresponding to a PTP functional entity. The
969 * Cell Identifier IE shall not be used in any other BVC-RESET PDU. */
Harald Welte5339b2e2020-10-04 22:52:56 +0200970 if (g_sgsn_role) {
Harald Welte199f3862020-11-15 22:37:45 +0100971 pdu := valueof(ts_BVC_RESET(cause, g_cfg.bvci, omit));
Harald Weltec967d0e2020-09-14 16:07:26 +0200972 } else {
Harald Welte199f3862020-11-15 22:37:45 +0100973 pdu := valueof(ts_BVC_RESET(cause, g_cfg.bvci, g_cfg.cell_id));
Harald Weltec967d0e2020-09-14 16:07:26 +0200974 }
Harald Welte853c0ad2018-02-15 17:45:29 +0100975
976 /* BVC-RESET is always sent via the SIGNALLING BVCI, see Table 5.4.1 */
Harald Weltec4505522020-11-11 18:55:09 +0100977 BVC.send(ts_ptp_BnsUdReq(pdu, 0, g_bvc_lsp));
Harald Welte853c0ad2018-02-15 17:45:29 +0100978 g_T2.start;
979 //f_change_state(BVC_S_WAIT_RESET);
Harald Welte199f3862020-11-15 22:37:45 +0100980 g_last_reset_cause := cause;
Harald Welte853c0ad2018-02-15 17:45:29 +0100981}
982
Harald Welte5339b2e2020-10-04 22:52:56 +0200983/* PTP-BVC is in BVC_S_BLOCKED state */
984private altstep as_ptp_blocked() runs on BSSGP_BVC_CT {
985 var NsUnitdataIndication udi;
986
987 [g_T1.running and not g_t1_waits_for_block_ack] BVC.receive(tr_ptp_BnsUdInd(t_BVC_UNBLOCK_ACK(g_cfg.bvci), 0)) {
988 g_T1.stop;
989 f_ptp_change_state(BVC_S_UNBLOCKED);
990 }
991
Harald Welteddfc6672020-11-24 23:13:01 +0100992 /* Inbound BVC-UNBLOCK from peer */
993 [g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(t_BVC_UNBLOCK(g_cfg.bvci), 0)) {
994 BVC.send(ts_ptp_BnsUdReq(t_BVC_UNBLOCK_ACK(g_cfg.bvci), 0, g_bvc_lsp));
995 f_ptp_change_state(BVC_S_UNBLOCKED);
996 }
997
Harald Welte5339b2e2020-10-04 22:52:56 +0200998 /* RESET-ACK before T2 timeout: reset successful. In SGSN role, CellID must be present */
999 [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 {
1000 g_T2.stop;
1001 f_ptp_change_state(BVC_S_UNBLOCKED);
1002 }
1003 /* RESET-ACK before T2 timeout: reset successful. In BSS role, CellID must be absent */
1004 [g_T2.running and not g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_RESET_ACK(g_cfg.bvci, omit), 0)) -> value udi {
1005 g_T2.stop;
1006 f_ptp_change_state(BVC_S_UNBLOCKED);
1007 }
1008
Harald Welteab50cc22020-11-25 17:11:08 +01001009 [] as_ptp_handle_inbound_reset();
1010
Harald Welte5339b2e2020-10-04 22:52:56 +02001011 [] g_T2.timeout {
1012 /* BVC-RESET-ACK PDU was not received within T2: retransmit */
Harald Welte199f3862020-11-15 22:37:45 +01001013 f_ptp_sendReset(g_last_reset_cause);
Harald Welte5339b2e2020-10-04 22:52:56 +02001014 }
Harald Welte199f3862020-11-15 22:37:45 +01001015
1016 [] MGMT.receive(BssgpUnblockRequest:?) {
1017 f_ptp_sendUnblock();
1018 }
Harald Welte853c0ad2018-02-15 17:45:29 +01001019}
1020
Harald Welte5339b2e2020-10-04 22:52:56 +02001021/* PTP-BVC is in UNBLOCKED state */
1022private altstep as_ptp_unblocked() runs on BSSGP_BVC_CT {
1023 var NsUnitdataIndication udi;
1024 var NsStatusIndication nsi;
Harald Welte199f3862020-11-15 22:37:45 +01001025 var BssgpBlockRequest bbr;
Harald Welte5339b2e2020-10-04 22:52:56 +02001026 var BSSGP_Client_CT vc_conn;
1027 var ASP_Event evt;
1028 var PDU_BSSGP bs_pdu;
1029 var PDU_LLC llc;
1030#ifdef BSSGP_EM_L3
1031 var PDU_L3_MS_SGSN l3_mo;
1032 var PDU_L3_SGSN_MS l3_mt;
1033#endif
1034
1035 /* bogus unblock, just respond with ACK */
1036 [] BVC.receive(tr_ptp_BnsUdInd(t_BVC_UNBLOCK(g_cfg.bvci), 0)) -> value udi {
Harald Weltec4505522020-11-11 18:55:09 +01001037 BVC.send(ts_ptp_BnsUdReq(t_BVC_UNBLOCK_ACK(g_cfg.bvci), 0, g_bvc_lsp));
Harald Welte5339b2e2020-10-04 22:52:56 +02001038 }
1039 /* Respond to BLOCK with BLOCK-ACK + change state */
1040 [] BVC.receive(tr_ptp_BnsUdInd(t_BVC_BLOCK(g_cfg.bvci, ?), 0)) -> value udi {
Harald Weltec4505522020-11-11 18:55:09 +01001041 BVC.send(ts_ptp_BnsUdReq(t_BVC_BLOCK_ACK(g_cfg.bvci), 0, g_bvc_lsp));
Harald Welte5339b2e2020-10-04 22:52:56 +02001042 g_T1.stop;
1043 f_ptp_change_state(BVC_S_BLOCKED);
1044 }
1045 /* BLOCK-ACK before T1 timeout: mark as blocked */
1046 [g_T1.running and g_t1_waits_for_block_ack] BVC.receive(tr_ptp_BnsUdInd(t_BVC_BLOCK_ACK(g_cfg.bvci), 0)) -> value udi {
1047 g_T1.stop;
1048 f_ptp_change_state(BVC_S_BLOCKED);
1049 }
1050 /* Re-transmit BLOCK / UNBLOCK on T1 timeout */
1051 [not g_t1_waits_for_block_ack] g_T1.timeout {
1052 f_ptp_sendUnblock();
1053 }
1054 [g_t1_waits_for_block_ack] g_T1.timeout {
Harald Welte199f3862020-11-15 22:37:45 +01001055 f_ptp_sendBlock(g_last_block_cause);
Harald Welte5339b2e2020-10-04 22:52:56 +02001056 }
1057
Harald Welteab50cc22020-11-25 17:11:08 +01001058 [] as_ptp_handle_inbound_reset();
1059
Harald Welte5339b2e2020-10-04 22:52:56 +02001060 /* simply acknowledge all per-BVC Flow Control Messages */
1061 [g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_FC_BVC, g_cfg.bvci)) -> value udi {
1062 var OCT1 tag := udi.bssgp.pDU_BSSGP_FLOW_CONTROL_BVC.tag.unstructured_Value;
Harald Weltec4505522020-11-11 18:55:09 +01001063 BVC.send(ts_ptp_BnsUdReq(t_BVC_FC_BVC_ACK(tag), g_cfg.bvci, g_bvc_lsp));
Harald Welte5339b2e2020-10-04 22:52:56 +02001064 }
1065/*
1066 [g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(t_BVC_FC_MS, g_cfg.bvci)) {
1067 BVC.send(ts_ptp_BnsUdReq(t_BVC_FC_MS_ACK, g_cfg.bvci));
1068 }
1069*/
1070 /* Any other PTP BSSGP message: If it has TLLI, route to component; otherwise broadcast */
1071 [] BVC.receive(tr_ptp_BnsUdInd(?, g_cfg.bvci)) -> value udi {
1072 var BssgpDecoded dec := f_dec_bssgp(udi.bssgp);
1073 var template OCT4 tlli := f_bssgp_get_tlli(udi.bssgp);
1074 if (isvalue(tlli)) {
1075 vc_conn := f_tbl_comp_by_tlli(valueof(tlli));
Harald Welte4d112c92020-11-12 19:48:31 +01001076 if (vc_conn == null) {
1077 g_cfg.create_cb.apply(g_cfg.bvci, g_cfg.cell_id, valueof(tlli), dec);
1078 } else {
1079 f_send_bssgp_dec(dec, vc_conn, BSSGP_SP);
1080 }
Harald Welte5339b2e2020-10-04 22:52:56 +02001081 } else {
1082 log("No TLLI: Broadcasting ", dec);
1083 /* broadcast this message to all components */
1084 // TITAN DOESN'T DO THIS, *SIGH*: "BSSGP_SP.send(dec) to all component;"
1085 for (var integer i := 0; i < sizeof(ClientTable); i := i+1) {
1086 if (isbound(ClientTable[i].comp_ref) and ClientTable[i].comp_ref != null) {
1087 f_send_bssgp_dec(dec, ClientTable[i].comp_ref, BSSGP_SP);
1088 }
1089 }
1090 }
1091 }
1092
1093 /* Any other SIG BSSGP message: If it has TLLI, route to component; otherwise broadcast */
1094 [] BVC.receive(tr_ptp_BnsUdInd(?, 0)) -> value udi {
1095 var BssgpDecoded dec := f_dec_bssgp(udi.bssgp);
1096 var template OCT4 tlli := f_bssgp_get_tlli(udi.bssgp);
1097 if (isvalue(tlli)) {
1098 vc_conn := f_tbl_comp_by_tlli(valueof(tlli));
Harald Welte4d112c92020-11-12 19:48:31 +01001099 if (vc_conn == null) {
1100 g_cfg.create_cb.apply(g_cfg.bvci, g_cfg.cell_id, valueof(tlli), dec);
1101 } else {
1102 f_send_bssgp_dec(dec, vc_conn, BSSGP_SP_SIG);
1103 }
Harald Welte5339b2e2020-10-04 22:52:56 +02001104 } else {
1105 log("No TLLI: Broadcasting ", dec);
1106 /* broadcast this message to all components */
1107 // TITAN DOESN'T DO THIS, *SIGH*: "BSSGP_SP.send(dec) to all component;"
1108 for (var integer i := 0; i < sizeof(ClientTable); i := i+1) {
1109 if (isbound(ClientTable[i].comp_ref) and ClientTable[i].comp_ref != null) {
1110 f_send_bssgp_dec(dec, ClientTable[i].comp_ref, BSSGP_SP_SIG);
1111 }
1112 }
1113 }
1114 }
1115
1116 /* ConnHdlr sends BSSGP on BVCI=0 port: forward it to BSSGP_CT */
1117 [] BSSGP_SP_SIG.receive(PDU_BSSGP:?)-> value bs_pdu sender vc_conn {
Harald Weltec4505522020-11-11 18:55:09 +01001118 BVC.send(ts_ptp_BnsUdReq(bs_pdu, 0, g_bvc_lsp));
Harald Welte5339b2e2020-10-04 22:52:56 +02001119 }
1120
1121 /* ConnHdlr sends BSSGP on BVCI=PTP port: forward it to BSSGP_CT */
1122 [] BSSGP_SP.receive(PDU_BSSGP:?)-> value bs_pdu sender vc_conn {
Harald Weltec4505522020-11-11 18:55:09 +01001123 BVC.send(ts_ptp_BnsUdReq(bs_pdu, g_cfg.bvci, g_bvc_lsp));
Harald Welte5339b2e2020-10-04 22:52:56 +02001124 }
1125
1126#ifdef BSSGP_EM_L3
1127 /* ConnHdlr sends L3: Encode and send as UL_UD / DL_UD */
1128 [g_sgsn_role] BSSGP_SP.receive(PDU_L3_SGSN_MS:?) -> value l3_mt sender vc_conn {
1129 var integer idx := f_tbl_idx_by_comp(vc_conn);
Harald Weltec4505522020-11-11 18:55:09 +01001130 var OCT4 tlli := ClientTable[idx].tlli;
Harald Welte5339b2e2020-10-04 22:52:56 +02001131 var octetstring l3_enc := enc_PDU_L3_SGSN_MS(l3_mt);
1132 var BIT4 sapi := f_llc_sapi_by_l3_mt(l3_mt);
1133 var integer n_u := f_llc_get_n_u_tx(ClientTable[idx].llc[bit2int(sapi)]);
1134 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 +01001135 BVC.send(ts_ptp_BnsUdReq(ts_BSSGP_DL_UD(tlli, llc_enc), g_cfg.bvci, oct2int(tlli)));
Harald Welte5339b2e2020-10-04 22:52:56 +02001136 }
1137 [not g_sgsn_role] BSSGP_SP.receive(PDU_L3_MS_SGSN:?) -> value l3_mo sender vc_conn {
1138 var integer idx := f_tbl_idx_by_comp(vc_conn);
Harald Weltec4505522020-11-11 18:55:09 +01001139 var OCT4 tlli := ClientTable[idx].tlli;
Harald Welte5339b2e2020-10-04 22:52:56 +02001140 var octetstring l3_enc := enc_PDU_L3_MS_SGSN(l3_mo);
1141 var BIT4 sapi := f_llc_sapi_by_l3_mo(l3_mo);
1142 var integer n_u := f_llc_get_n_u_tx(ClientTable[idx].llc[bit2int(sapi)]);
1143 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 +01001144 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 +02001145 }
1146#endif
1147
1148 /* ConnHdlr sends raw LLC: Encode and send as UL_UD / DL_UD */
1149 [not g_sgsn_role] BSSGP_SP.receive(PDU_LLC:?) -> value llc sender vc_conn {
1150 var integer idx := f_tbl_idx_by_comp(vc_conn);
Harald Weltec4505522020-11-11 18:55:09 +01001151 var OCT4 tlli := ClientTable[idx].tlli;
Harald Welte5339b2e2020-10-04 22:52:56 +02001152 var octetstring llc_enc := enc_PDU_LLC(llc);
Harald Weltec4505522020-11-11 18:55:09 +01001153 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 +02001154 }
1155 [g_sgsn_role] BSSGP_SP.receive(PDU_LLC:?) -> value llc sender vc_conn {
1156 var integer idx := f_tbl_idx_by_comp(vc_conn);
Harald Weltec4505522020-11-11 18:55:09 +01001157 var OCT4 tlli := ClientTable[idx].tlli;
Harald Welte5339b2e2020-10-04 22:52:56 +02001158 var octetstring llc_enc := enc_PDU_LLC(llc);
Harald Weltec4505522020-11-11 18:55:09 +01001159 BVC.send(ts_ptp_BnsUdReq(ts_BSSGP_DL_UD(tlli, llc_enc), g_cfg.bvci, oct2int(tlli)));
Harald Welte5339b2e2020-10-04 22:52:56 +02001160 }
Harald Welte199f3862020-11-15 22:37:45 +01001161
1162 [] MGMT.receive(BssgpBlockRequest:?) -> value bbr {
1163 f_ptp_sendBlock(bbr.cause);
1164 }
Harald Welte853c0ad2018-02-15 17:45:29 +01001165}
1166
Harald Welteab50cc22020-11-25 17:11:08 +01001167private altstep as_ptp_handle_inbound_reset() runs on BSSGP_BVC_CT {
1168 var NsUnitdataIndication udi;
1169 /* we are a SGSN: BSS/PCU-originated RESET must have a cell ID */
1170 [g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_RESET(?, g_cfg.bvci, g_cfg.cell_id), 0)) -> value udi {
1171 log("Rx BVC-RESET from BVCI=", g_cfg.bvci);
Harald Welte3c905152020-11-26 20:56:09 +01001172 if (MGMT.checkstate("Connected")) {
1173 MGMT.send(BssgpResetIndication:{g_cfg.bvci});
1174 }
Harald Welteab50cc22020-11-25 17:11:08 +01001175 /* Respond to RESET with correct BVCI but without CellID */
1176 BVC.send(ts_ptp_BnsUdReq(ts_BVC_RESET_ACK(g_cfg.bvci, omit), 0, g_bvc_lsp));
1177 /* FIXME: reset all state? What about clients? */
1178 f_ptp_change_state(BVC_S_UNBLOCKED);
1179 }
1180 /* we are a BSS/PCU: SGSN-originated RESET must not have a cell ID */
1181 [not g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_RESET(?, g_cfg.bvci, omit), 0)) -> value udi {
1182 log("Rx BVC-RESET from BVCI=", g_cfg.bvci);
Harald Welte3c905152020-11-26 20:56:09 +01001183 if (MGMT.checkstate("Connected")) {
1184 MGMT.send(BssgpResetIndication:{g_cfg.bvci});
1185 }
Harald Welteab50cc22020-11-25 17:11:08 +01001186 /* Respond to RESET with correct BVCI with CellID */
1187 BVC.send(ts_ptp_BnsUdReq(ts_BVC_RESET_ACK(g_cfg.bvci, g_cfg.cell_id), 0, g_bvc_lsp));
1188 /* FIXME: reset all state? What about clients? */
1189 f_ptp_change_state(BVC_S_UNBLOCKED);
1190 }
1191}
1192
Harald Welte5339b2e2020-10-04 22:52:56 +02001193/* Events permitted in all states */
1194private altstep as_ptp_allstate() runs on BSSGP_BVC_CT {
1195 var NsUnitdataIndication udi;
Harald Welte199f3862020-11-15 22:37:45 +01001196 var BssgpResetRequest brr;
Harald Welte5339b2e2020-10-04 22:52:56 +02001197 var BSSGP_Client_CT vc_conn;
1198 var OCT4 tlli, tlli_old;
1199 var hexstring imsi;
1200
1201 /* Signaling BVC was reset */
1202 [] BVC.receive(BssgpResetIndication:{0}) {
Harald Welte199f3862020-11-15 22:37:45 +01001203 if (MGMT.checkstate("Connected")) {
1204 MGMT.send(BssgpResetIndication:{0});
1205 }
Harald Welte5339b2e2020-10-04 22:52:56 +02001206 if (not g_sgsn_role) {
1207 f_ptp_change_state(BVC_S_BLOCKED);
1208 /* when the BSS side signaling PTP is RESET, all PTP BVC must start the
1209 * reset procedure */
1210 f_ptp_sendReset();
1211 } else {
1212 f_ptp_change_state(BVC_S_UNBLOCKED);
1213 }
1214 }
1215
Harald Welte5339b2e2020-10-04 22:52:56 +02001216 /* Ignore those for now */
1217 [] BVC.receive(ASP_Event:?) { }
1218 [] BVC.receive(BssgpStatusIndication:?) { }
1219
1220 /* catch-all */
1221 [] BVC.receive(tr_ptp_BnsUdInd(?, 0)) -> value udi {
1222 setverdict(fail, "Received unexpected NS (SIG): ", udi);
1223 }
1224 [] BVC.receive(tr_ptp_BnsUdInd(?, ?)) -> value udi {
1225 setverdict(fail, "Received unexpected NS (PTP): ", udi);
1226 }
1227 [] BVC.receive {
1228 setverdict(fail, "Received unexpected message from BSSGP_CT");
1229 }
1230
1231 /* registration/deregistration of Clients (per-TLLI components) */
1232 [] BSSGP_PROC.getcall(BSSGP_register_client:{?,?}) -> param(imsi, tlli) sender vc_conn {
1233 f_tbl_client_add(imsi, tlli, vc_conn);
1234 BSSGP_PROC.reply(BSSGP_register_client:{imsi, tlli}) to vc_conn;
1235 }
1236 [] BSSGP_PROC.getcall(BSSGP_unregister_client:{?}) -> param(imsi) sender vc_conn {
1237 f_tbl_client_del(imsi, vc_conn);
1238 BSSGP_PROC.reply(BSSGP_unregister_client:{imsi}) to vc_conn;
1239 }
1240 [] BSSGP_PROC.getcall(BSSGP_llgmm_assign:{?,?}) -> param(tlli_old, tlli) sender vc_conn {
1241 f_tbl_client_llgmm_assign(tlli_old, tlli, vc_conn);
1242 BSSGP_PROC.reply(BSSGP_llgmm_assign:{tlli_old, tlli}) to vc_conn;
1243 }
Harald Welte199f3862020-11-15 22:37:45 +01001244
1245 [] MGMT.receive(BssgpResetRequest:?) -> value brr {
Harald Welte52cecbb2020-11-25 21:57:31 +01001246 f_ptp_change_state(BVC_S_BLOCKED);
Harald Welte199f3862020-11-15 22:37:45 +01001247 f_ptp_sendReset(brr.cause);
1248 }
Harald Welte5339b2e2020-10-04 22:52:56 +02001249}
1250
1251/* main loop for per-BVC component */
1252private function f_bssgp_bvc_ScanEvents() runs on BSSGP_BVC_CT {
1253 while (true) {
1254 alt {
1255 [g_ptp_bvc_state == BVC_S_BLOCKED] as_ptp_blocked();
1256 [g_ptp_bvc_state == BVC_S_UNBLOCKED] as_ptp_unblocked();
1257 [] as_ptp_allstate();
1258 }
1259 }
1260}
1261
1262/* main function for per-BVC Component */
Harald Weltefba7afd2020-11-24 23:12:31 +01001263private 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 +02001264 g_cfg := cfg;
Harald Weltefba7afd2020-11-24 23:12:31 +01001265 g_nsei := nsei;
Harald Weltec4505522020-11-11 18:55:09 +01001266 g_bvc_lsp := cfg.bvci;
Harald Welte5339b2e2020-10-04 22:52:56 +02001267 g_sgsn_role := sgsn_role;
1268 f_bssgp_bvc_ScanEvents();
1269}
1270
Harald Weltec4505522020-11-11 18:55:09 +01001271template (value) NsUnitdataRequest ts_ptp_BnsUdReq(template (value) PDU_BSSGP pdu, template (value) BssgpBvci bvci,
1272 template (value) integer lsp) := {
Harald Welte5339b2e2020-10-04 22:52:56 +02001273 bvci := bvci,
1274 nsei := 0, // overwritten in BSSGP_CT
Harald Weltec4505522020-11-11 18:55:09 +01001275 lsp := lsp,
Harald Welte5339b2e2020-10-04 22:52:56 +02001276 /* for some weird reason we get "Dynamic test case error: Text encoder: Encoding an
1277 * unbound integer value." when trying to send the reocrd rather than the octetstring */
1278 //sdu := omit,
1279 //bssgp := valueof(pdu)
1280 sdu := enc_PDU_BSSGP(valueof(pdu)),
1281 bssgp := omit
1282}
1283
1284template (present) NsUnitdataIndication tr_ptp_BnsUdInd(template (present) PDU_BSSGP pdu, template (present) BssgpBvci bvci) := {
1285 bvci := bvci,
1286 nsei := ?,
Harald Welte80a249a2020-11-17 19:57:40 +01001287 nsvci := ?,
Harald Welte5339b2e2020-10-04 22:52:56 +02001288 sdu := *,
1289 bssgp := pdu
1290}
1291
1292/* change state of PTP BVC; broadcast state change to clients */
1293private function f_ptp_change_state(BvcState new_state) runs on BSSGP_BVC_CT {
1294 if (new_state == g_ptp_bvc_state) {
1295 return;
1296 }
1297 log("BVCI(", g_cfg.bvci, ") State Transition: ", g_ptp_bvc_state, " -> ", new_state);
1298 g_ptp_bvc_state := new_state;
Harald Welte199f3862020-11-15 22:37:45 +01001299 if (MGMT.checkstate("Connected")) {
Harald Weltefba7afd2020-11-24 23:12:31 +01001300 MGMT.send(ts_BssgpStsInd(g_nsei, g_cfg.bvci, g_ptp_bvc_state));
Harald Welte199f3862020-11-15 22:37:45 +01001301 }
Harald Welte5339b2e2020-10-04 22:52:56 +02001302 for (var integer i := 0; i < sizeof(ClientTable); i := i+1) {
1303 if (isbound(ClientTable[i].comp_ref) and ClientTable[i].comp_ref != null) {
Harald Weltefba7afd2020-11-24 23:12:31 +01001304 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 +02001305 }
1306 }
Harald Welte5ac31492018-02-15 20:39:13 +01001307}
1308
1309/* attempt to extract the TLLI from a BSSGP PDU */
1310function f_bssgp_get_tlli(PDU_BSSGP bssgp) return template OCT4 {
1311 if (ischosen(bssgp.pDU_BSSGP_DL_UNITDATA)) {
1312 return bssgp.pDU_BSSGP_DL_UNITDATA.tLLI_current;
1313 } else if (ischosen(bssgp.pDU_BSSGP_UL_UNITDATA)) {
1314 return bssgp.pDU_BSSGP_UL_UNITDATA.tLLI;
1315 } else if (ischosen(bssgp.pDU_BSSGP_RA_CAPABILITY)) {
1316 return bssgp.pDU_BSSGP_RA_CAPABILITY.tLLI.tLLI_Value;
1317 } else if (ischosen(bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE)) {
1318 return bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE.tLLI.tLLI_Value;
1319 } else if (ischosen(bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE_ACK)) {
1320 return bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE_ACK.tLLI.tLLI_Value;
1321 } else if (ischosen(bssgp.pDU_BSSGP_RADIO_STATUS)) {
1322 return bssgp.pDU_BSSGP_RADIO_STATUS.tLLI.tLLI_Value;
1323 } else if (ischosen(bssgp.pDU_BSSGP_SUSPEND)) {
1324 return bssgp.pDU_BSSGP_SUSPEND.tLLI.tLLI_Value;
1325 } else if (ischosen(bssgp.pDU_BSSGP_SUSPEND_ACK)) {
1326 return bssgp.pDU_BSSGP_SUSPEND_ACK.tLLI.tLLI_Value;
1327 } else if (ischosen(bssgp.pDU_BSSGP_SUSPEND_NACK)) {
1328 return bssgp.pDU_BSSGP_SUSPEND_NACK.tLLI.tLLI_Value;
1329 } else if (ischosen(bssgp.pDU_BSSGP_RESUME)) {
1330 return bssgp.pDU_BSSGP_RESUME.tLLI.tLLI_Value;
1331 } else if (ischosen(bssgp.pDU_BSSGP_RESUME_ACK)) {
1332 return bssgp.pDU_BSSGP_RESUME_ACK.tLLI.tLLI_Value;
1333 } else if (ischosen(bssgp.pDU_BSSGP_RESUME_NACK)) {
1334 return bssgp.pDU_BSSGP_RESUME_NACK.tLLI.tLLI_Value;
1335 } else if (ischosen(bssgp.pDU_BSSGP_FLUSH_LL)) {
1336 return bssgp.pDU_BSSGP_FLUSH_LL.tLLI.tLLI_Value;
1337 } else if (ischosen(bssgp.pDU_BSSGP_FLUSH_LL_ACK)) {
1338 return bssgp.pDU_BSSGP_FLUSH_LL_ACK.tLLI.tLLI_Value;
1339 } else if (ischosen(bssgp.pDU_BSSGP_LLC_DISCARDED)) {
1340 return bssgp.pDU_BSSGP_LLC_DISCARDED.tLLI.tLLI_Value;
1341 } else if (ischosen(bssgp.pDU_BSSGP_LLC_DISCARDED)) {
1342 return bssgp.pDU_BSSGP_LLC_DISCARDED.tLLI.tLLI_Value;
1343 } else if (ischosen(bssgp.pDU_BSSGP_PAGING_CS) and
1344 isvalue(bssgp.pDU_BSSGP_PAGING_CS.tLLI)) {
1345 return bssgp.pDU_BSSGP_PAGING_CS.tLLI.tLLI_Value;
1346 } else if (ischosen(bssgp.pDU_BSSGP_FLOW_CONTROL_MS)) {
1347 return bssgp.pDU_BSSGP_FLOW_CONTROL_MS.tLLI.tLLI_Value;
1348 } else if (ischosen(bssgp.pDU_BSSGP_FLOW_CONTROL_MS_ACK)) {
1349 return bssgp.pDU_BSSGP_FLOW_CONTROL_MS_ACK.tLLI.tLLI_Value;
1350 }
1351 /* TODO: Handover, PFC, LCS */
1352 return omit;
1353}
1354
Harald Weltef70997d2018-02-17 10:11:19 +01001355
Harald Welte5ac31492018-02-15 20:39:13 +01001356
Harald Welte1733a382017-07-23 17:26:17 +02001357}