aboutsummaryrefslogtreecommitdiffstats
path: root/pcu/SGSN_Components.ttcn
blob: 4bbd18caefb066b488d8bdfee53cd3765cd9aaaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
module SGSN_Components {
/*
 * Osmocom PCU test suite in TTCN-3, components for BSSGP handlng
 * (C) 2018-2019 Harald Welte <laforge@gnumonks.org>
 * (C) 2020 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
 * All rights reserved.
 *
 * Released under the terms of GNU General Public License, Version 2 or
 * (at your option) any later version.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

import from BSSGP_Types all;
import from BSSGP_Emulation all;
import from NS_Types all;
import from NS_Emulation all;
import from GPRS_Context all;

modulepar {
	BssgpConfig mp_gb_cfg := {
		nsei := 1234,
		bvci := 1234,
		cell_id := {
			ra_id := {
				lai := {
					mcc_mnc := '262F42'H, lac := 13135
				},
				rac := 0
			},
			cell_id := 20960
		},
		sgsn_role := true,
		depth := BSSGP_DECODE_DEPTH_BSSGP
	};

	NSConfiguration mp_nsconfig := {
		local_udp_port := 23000,
		local_ip := "127.0.0.1",
		remote_udp_port := 21000,
		remote_ip := "127.0.0.1",
		nsvci := 0,
		nsei := 2342,
		role_sgsn := true,
		handle_sns := true
	};
}

/* FIXME: merge this into BSSGP_Client_CT ? */
type component bssgp_CT extends BSSGP_Client_CT {
	var NS_CT ns_component;
	var BSSGP_CT bssgp_component;
	var boolean g_initialized := false;
}

/* FIXME: merge this into BSSGP_Client_CT ? */
function f_init_bssgp() runs on bssgp_CT {
	var MmContext mmctx := {
		imsi := '262420000000001'H,
		tlli := 'FFFFFFFF'O,
		n_u := 0
	};


	if (g_initialized == true) {
		return;
	}
	g_initialized := true;

	/* create a new NS component */
	ns_component := NS_CT.create;
	bssgp_component := BSSGP_CT.create;
	/* connect our BSSGP port to the BSSGP Emulation */
	connect(self:BSSGP[0], bssgp_component:BSSGP_SP);
	connect(self:BSSGP_SIG[0], bssgp_component:BSSGP_SP_SIG);
	connect(self:BSSGP_PROC[0], bssgp_component:BSSGP_PROC);
	/* connect lower-end of BSSGP with BSSGP_CODEC_PORT (maps to NS_PT*/
	connect(bssgp_component:BSCP, ns_component:NS_SP);
	/* connect lower-end of NS emulation to NS_CODEC_PORT (on top of IPl4) */
	map(ns_component:NSCP, system:NS_CODEC_PORT);
	ns_component.start(NSStart(mp_nsconfig));
	bssgp_component.start(BssgpStart(mp_gb_cfg));

	f_bssgp_client_register(mmctx.imsi, mmctx.tlli, mp_gb_cfg.cell_id);
}

/* Establish BSSGP connection to PCU */
function f_bssgp_establish() runs on BSSGP_Client_CT {
	timer T:= 10.0;

	T.start
	alt {
	[] BSSGP[0].receive(t_BssgpStsInd(?, ?, BVC_S_UNBLOCKED)) { }
	[] BSSGP[0].receive { repeat; }
	[] T.timeout {
		setverdict(fail, "Timeout establishing BSSGP connection");
		mtc.stop;
		}
	}
	T.stop
	log("BSSGP successfully initialized");
}

}