aboutsummaryrefslogtreecommitdiffstats
path: root/msc/MSC_Tests_ASCI.ttcn
blob: c8bf2dac6d997c3fc499e03cc3744ae60a4c026f (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
module MSC_Tests_ASCI {

/* Osmocom MSC test suite for ASCI support in TTCN-3
 * (C) 2023 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
 * All Rights Reserved
 *
 * Author: Andreas Eversberg
 *
 * 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 General_Types all;
import from Osmocom_Types all;

import from BSC_ConnectionHandler all;
import from MSC_Tests all;

import from Osmocom_VTY_Functions all;

import from GSUP_Emulation all;
import from RAN_Emulation all;
import from MGCP_Emulation all;

import from RANAP_Templates all;

import from BSSAP_Types all;
import from BSSMAP_Templates all;

import from L3_Templates all;

import from MobileL3_CommonIE_Types all;


/* Call control for VGCS and VBS
 *
 * There are 3 connection:
 * - "call" = voice group/broadcast call initiated by the calling subscriber
 * - "control" = VGCS/VBS call control connection
 * - "channel" = VGCS/VBS channel resource connection
 *
 * All 3 connections have their own handlers. They send their test results via
 * COORD messages to the main test function. There the result is collected and
 * the outcome of the test is checked.
 */

/* Test functions */
const charstring COORD_TEST_NO_CALLREF := "TEST_NO_CALLREF";
const charstring COORD_TEST_SETUP_REFUSE := "TEST_SETUP_REFUSE";
const charstring COORD_TEST_ASSIGN_FAIL := "TEST_ASSIGN_FAIL";
const charstring COORD_TEST_COMPLETE_VGCS := "TEST_COMPLETE_VGCS";
const charstring COORD_TEST_COMPLETE_VBS := "TEST_COMPLETE_VBS";

/* COORD pipes for each connection */
type component asci_CT extends MTC_CT {
	port BSC_ConnHdlr_Coord_PT COORD_call;
	port BSC_ConnHdlr_Coord_PT COORD_control;
	port BSC_ConnHdlr_Coord_PT COORD_channel;
}

/* COORD messages for test events */
const charstring COORD_SETUP := "SETUP";
const charstring COORD_VGCS_SETUP := "VGCS_SETUP";
const charstring COORD_VGCS_ASSIGN := "VGCS_ASSIGN";
const charstring COORD_UPLINK_SEIZED := "UPLINK_SEIZED";
const charstring COORD_GCC_CONNECT := "GCC_CONNECT";
const charstring COORD_BCC_CONNECT := "BCC_CONNECT";
const charstring COORD_GCC_SET_PARAM := "GCC_SET_PARAM";
const charstring COORD_BCC_SET_PARAM := "BCC_SET_PARAM";
const charstring COORD_UPLINK_REQ_ACK := "UPLINK_REQ_ACK";
const charstring COORD_GCC_TERMINATION := "GCC_TERMINATION";
const charstring COORD_BCC_TERMINATION := "BCC_TERMINATION";
const charstring COORD_GCC_TERMINATION_FAIL := "GCC_TERMINATION_FAIL";
const charstring COORD_BCC_TERMINATION_FAIL := "BCC_TERMINATION_FAIL";
const charstring COORD_ASSIGNMENT := "ASSIGNMENT";
const charstring COORD_CLEAR := "CLEAR";

template (value) DescriptiveGroupOrBroadcastCallReference_V
                        ts_BSSMAP_IE_GroupCallRef(integer cr,
                                                  BIT1 sf,
                                                  BIT1 af,
                                                  BIT3 prio,
                                                  BIT4 ci) := {
        binaryCodingOfGroupOrBroadcastCallReference := int2bit(cr, 27),
        sF := sf,
        aF := af,
        callPriority := prio,
        cipheringInformation := ci,
        spare := '0000'B
}

function f_gen_asci_ass_res(integer bssap_idx := 0,
			    template (value) BSSMAP_IE_ChannelType ch_type := ts_BSSMAP_IE_ChannelType,
			    template (value) BSSMAP_IE_CellIdentifier cell_id := ts_CellId_CI(0),
			    template (omit) BSSMAP_IE_AoIP_TransportLayerAddress aoip_tla := omit,
			    template (omit) BSSMAP_IE_SpeechCodec codec := omit,
			    template (omit) OCT4 call_id := omit)
runs on BSC_ConnHdlr return template (value) PDU_BSSAP {
        if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
                return ts_BSSMAP_VGCS_VBS_AssignmentRes(ch_type, cell_id, omit, omit, aoip_tla, codec, call_id);
        } else {
                var template (value) BSSMAP_IE_CircuitIdentityCode cic := ts_BSSMAP_IE_CIC(0,1);
                return ts_BSSMAP_VGCS_VBS_AssignmentRes(ch_type, cell_id, omit, cic, omit, omit, omit);
        }
}

/* "call" connection handling */
private function f_tc_vgcs_call(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr
{
	/* Receive test case from main function. */
	var charstring test;
	COORD.receive(charstring:?) -> value test;

	/* Initialize variables and templates. */
	var CallParameters cpars := valueof(t_CallParams('12345'H, 0));
	var template (value) DescriptiveGroupOrBroadcastCallReference_V callref :=
					ts_BSSMAP_IE_GroupCallRef(oct2int('190000'O), '1'B, '0'B, '000'B, '0000'B);
	if (test == COORD_TEST_COMPLETE_VBS) {
		callref := ts_BSSMAP_IE_GroupCallRef(oct2int('1a0000'O), '0'B, '0'B, '000'B, '0000'B);
	}
	var template BSSMAP_IE_ChannelType tr_ch_type := tr_BSSMAP_IE_ChannelType('0001'B, ChRate_TCHF, Spdi_TCHF_FR);
	var template PDU_BSSAP tr_assignment_req := tr_BSSMAP_AssignmentReq();
	tr_assignment_req.pdu.bssmap.assignmentRequest.channelType := tr_ch_type;
	tr_assignment_req.pdu.bssmap.assignmentRequest.groupCallReference :=
								tr_BSSMAP_IE_GroupCallRef(bit2oct(encvalue(callref)));
	/* Due to a bug in dec_PDU_BSSAP(), we do not get the callref IE, so we need to match it with omit. */
	tr_assignment_req.pdu.bssmap.assignmentRequest.groupCallReference := omit;
	var template (value) PDU_BSSAP ts_assignment_cpl := ts_BSSMAP_AssignmentComplete(omit, omit, omit, omit);
	var octetstring xcc_termination_21 := '340121'O;
	var octetstring xcc_termination_11 := '340111'O;
	var PDU_BSSAP rx_bssap;

	f_init_handler(pars);

	/* Location Update to make subscriber known. */
	f_perform_lu();

	/* MGW */
	f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
	var default crcx := activate(as_optional_mgcp_crcx(cpars));
	var default mdcx := activate(as_optional_mgcp_mdcx(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_port));
	var default dlcx := activate(as_optional_mgcp_dlcx(cpars));

	/* Establish connection using the service type, defined by the test. */
	if (test == COORD_TEST_COMPLETE_VBS) {
		f_establish_fully(EST_TYPE_VBS);
	} else {
		f_establish_fully(EST_TYPE_VGCS);
	}

	/* Send incorrect call reference, if selected by test. */
	log("Sending SETUP.");
	select (test) {
	case (COORD_TEST_NO_CALLREF) {
		BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_GCC(cpars.transaction_id, '3200002900'O)));
		}
	case (COORD_TEST_COMPLETE_VBS) {
		BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_BCC(cpars.transaction_id, '3200001a00'O)));
		}
	case else {
		BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_GCC(cpars.transaction_id, '3200001900'O)));
		}
	}
	COORD.send(COORD_SETUP);

	timer T := 10.0;
	T.start;
	alt {
	[] BSSAP.receive(tr_assignment_req) -> value rx_bssap {
		/* The MSC sends and Assignment Request to assign the calling subscriber to the VGCS/VBS channel. */
		log("Got Assignment Request: ", rx_bssap);
		COORD.send(COORD_ASSIGNMENT);
		log("Sending Assignment Complete: ", ts_assignment_cpl);
		BSSAP.send(ts_assignment_cpl);
		repeat;
		}
	[] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_GCC(cpars.transaction_id, xcc_termination_21))) {
		/* The MSC terminates the group call with cause 21 = requested service not subscribed. */
		log("Got GCC Termination with failure.");
		COORD.send(COORD_GCC_TERMINATION_FAIL);
		repeat;
		}
	[] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_BCC(cpars.transaction_id, xcc_termination_21))) {
		/* The MSC terminates the broadcast call with cause 21 = requested service not subscribed. */
		log("Got BCC Termination with failure.");
		COORD.send(COORD_BCC_TERMINATION_FAIL);
		repeat;
		}
	[] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_GCC(cpars.transaction_id, xcc_termination_11))) {
		/* The MSC terminates the group call with cause 11 = network failure. */
		log("Got GCC Termination with failure.");
		COORD.send(COORD_GCC_TERMINATION_FAIL);
		repeat;
		}
	[] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_BCC(cpars.transaction_id, xcc_termination_11))) {
		/* The MSC terminates the broadcast call with cause 11 = network failure. */
		log("Got BCC Termination with failure.");
		COORD.send(COORD_BCC_TERMINATION_FAIL);
		repeat;
		}
	[] BSSAP.receive(tr_BSSMAP_ClearCommand) {
		/* The SCCP connection is released. */
		log("Got Clear Command on initial connection.");
		COORD.send(COORD_CLEAR);
		repeat;
		}
	[] BSSAP.receive {
		setverdict(fail, "Got unexpected message on initial connection.");
		}
	[] COORD.receive(COORD_CLEAR) { }
	[] T.timeout {
		setverdict(fail, "Timeout waiting for Message");
		}
	}

	deactivate(crcx);
	deactivate(mdcx);
	deactivate(dlcx);
}

/* "control" connection handling */
private function f_tc_vgcs_control(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr
{
	/* Receive test case from main function. */
	var charstring test;
	COORD.receive(charstring:?) -> value test;

	/* Initialize variables and templates. */
	var CallParameters cpars := valueof(t_CallParams('12345'H, 0));
	var template (value) DescriptiveGroupOrBroadcastCallReference_V callref :=
					ts_BSSMAP_IE_GroupCallRef(oct2int('190000'O), '1'B, '0'B, '000'B, '0000'B);
	if (test == COORD_TEST_COMPLETE_VBS) {
		callref := ts_BSSMAP_IE_GroupCallRef(oct2int('1a0000'O), '0'B, '0'B, '000'B, '0000'B);
	}
	var template PDU_BSSAP tr_vgcs_vbs_setup := tr_BSSMAP_VGCS_VBS_Setup(bit2oct(encvalue(callref)));
	var template (value) PDU_BSSAP ts_vgcs_vbs_setup_ack := ts_BSSMAP_VGCS_VBS_SetupAck(omit);
	var myBSSMAP_Cause cause_fail := GSM0808_CAUSE_EQUIPMENT_FAILURE;
	var template (value) PDU_BSSAP ts_vgcs_vbs_setup_refuse := ts_BSSMAP_VGCS_VBS_SetupRefuse(enum2int(cause_fail));
	var octetstring gcc_connect := '330000190001'O;
	var octetstring bcc_connect := '3300001a0001'O;
	var octetstring xcc_set_param := '3A07'O;
	var octetstring gcc_term_req := '3500001900'O;
	var octetstring bcc_term_req := '3500001a00'O;
	var octetstring xcc_termination := '340110'O;
	/* L3 info carries the mobile identity of the talker requesting the uplink. */
	var octetstring uplink_req_conf := '061103505902082926240000000033'O;
	var myBSSMAP_Cause cause_success := GSM0808_CAUSE_CALL_CONTROL;
	var template (value) PDU_BSSAP ts_uplink_rel_ind := ts_BSSMAP_UplinkRelInd(enum2int(cause_success), omit);
	var template (value) PDU_BSSAP ts_uplink_req := ts_BSSMAP_UplinkReq;
	var template (value) PDU_BSSAP ts_uplink_req_conf := ts_BSSMAP_UplinkReqConf(ts_CellId_CI(42), omit, uplink_req_conf);
	var PDU_BSSAP rx_bssap;

	f_init_handler(pars);

	f_create_bssmap_exp_n_connect(193);

	timer T := 7.0;
	T.start;
	alt {
	[] BSSAP.receive(tr_vgcs_vbs_setup) -> value rx_bssap {
		/* The MSC sets up call control on the BSC. The test case will send an ack or a refuse. */
		log("Got VGCS/VBS Setup: ", rx_bssap);
		COORD.send(COORD_VGCS_SETUP);
		if (test == COORD_TEST_SETUP_REFUSE) {
			log("Sending VGCS/VBS Setup Refuse: ", ts_vgcs_vbs_setup_refuse);
			BSSAP.send(ts_vgcs_vbs_setup_refuse);
		} else {
			log("Sending VGCS/VBS Setup Ack: ", ts_vgcs_vbs_setup_ack);
			BSSAP.send(ts_vgcs_vbs_setup_ack);
		}
		repeat;
		}
	[] BSSAP.receive(tr_BSSMAP_UplinkSeizedCmd(GSM0808_CAUSE_CALL_CONTROL)) -> value rx_bssap {
		/* After setting up the call, the MSC marks the call as busy. */
		log("Got Uplink Seized Cmd: ", rx_bssap);
		COORD.send(COORD_UPLINK_SEIZED);
		repeat;
		}
	[] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_GCC(cpars.transaction_id, gcc_connect))) {
		/* The GCC CONNECT message is sent to the calling MS. */
		log("Got GCC Connect.");
		COORD.send(COORD_GCC_CONNECT);
		repeat;
		}
	[] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_BCC(cpars.transaction_id, bcc_connect))) {
		/* The BCC CONNECT message is sent to the calling MS. */
		log("Got BCC Connect.");
		COORD.send(COORD_BCC_CONNECT);
		repeat;
		}
	[] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_GCC(cpars.transaction_id, xcc_set_param))) {
		/* The GCC SET PARAMETER message is sent to the calling MS. */
		log("Got GCC Set Parameter.");
		COORD.send(COORD_GCC_SET_PARAM);
		f_sleep(0.2);
		/* The MS releases the uplink. */
		log("Sending Uplink Release Ind: ", ts_uplink_rel_ind);
		BSSAP.send(ts_uplink_rel_ind);
		f_sleep(0.2);
		/* The MS requests the uplink again. */
		log("Sending Uplink Req: ", ts_uplink_req);
		BSSAP.send(ts_uplink_req);
		repeat;
		}
	[] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_BCC(cpars.transaction_id, xcc_set_param))) {
		/* The BCC SET PARAMETER message is sent to the calling MS. */
		log("Got BCC Set Parameter");
		COORD.send(COORD_BCC_SET_PARAM);
		f_sleep(0.2);
		/* The MS requests termination of the call. */
		log("Sending BCC Termination Request: ", bcc_term_req);
		BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_BCC(cpars.transaction_id, bcc_term_req)));
		repeat;
		}
	[] BSSAP.receive(tr_BSSMAP_UplinkReqAck(*)) -> value rx_bssap {
		/* The uplink was granted by the MSC. */
		log("Got Uplink Request Acknowledge: ", rx_bssap);
		COORD.send(COORD_UPLINK_REQ_ACK);
		f_sleep(0.2);
		/* The BSC confirms the uplink and provides mobile identity to identify originator. */
		log("Sending Uplink Req Confirm: ", ts_uplink_req_conf);
		BSSAP.send(ts_uplink_req_conf);
		/* The MS requests termination of the call. */
		log("Sending GCC Termination Request: ", gcc_term_req);
		BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_GCC(cpars.transaction_id, gcc_term_req)));
		repeat;
		}
	[] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_GCC(cpars.transaction_id, xcc_termination))) {
		/* The MSC terminates the call towards the MS. */
		log("Got GCC Termination.");
		COORD.send(COORD_GCC_TERMINATION);
		repeat;
		}
	[] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_BCC(cpars.transaction_id, xcc_termination))) {
		/* The MSC terminates the call towards the MS. */
		log("Got BCC Termination.");
		COORD.send(COORD_BCC_TERMINATION);
		repeat;
		}
	[] BSSAP.receive(tr_BSSMAP_ClearCommand) {
		/* The SCCP connection is released. */
		log("Got Clear Command on control connection.");
		COORD.send(COORD_CLEAR);
		repeat;
		}
	[] BSSAP.receive(PDU_BSSAP:?) -> value rx_bssap {
		setverdict(fail, "Got unexpected BSSAP message on control connection: ", rx_bssap);
		}
	[] BSSAP.receive {
		setverdict(fail, "Got unexpected message on control connection.");
		}
	[] COORD.receive(COORD_CLEAR) { }
	[] T.timeout {
		setverdict(fail, "Timeout on control connection.");
		}
	}
}

/* "channel" connection handling */
private function f_tc_vgcs_channel(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr
{
	/* Receive test case from main function. */
	var charstring test;
	COORD.receive(charstring:?) -> value test;

	/* Initialize variables and templates. */
	var template (value) DescriptiveGroupOrBroadcastCallReference_V callref :=
					ts_BSSMAP_IE_GroupCallRef(oct2int('190000'O), '1'B, '0'B, '000'B, '0000'B);
	if (test == COORD_TEST_COMPLETE_VBS) {
		callref := ts_BSSMAP_IE_GroupCallRef(oct2int('1a0000'O), '0'B, '0'B, '000'B, '0000'B);
	}
	var template (present) BSSMAP_IE_ChannelType tr_ch_type :=
							tr_BSSMAP_IE_ChannelType('0001'B, ChRate_TCHF, Spdi_TCHF_FR);
	var template (value) BSSMAP_IE_ChannelType ts_ch_type := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
	var template (present) BSSMAP_IE_CellIdentifier tr_cell_id := tr_CellId_CI(42);
	var template (value) BSSMAP_IE_CellIdentifier ts_cell_id := ts_CellId_CI(42);
	var template (value) BSSMAP_IE_AoIP_TransportLayerAddress ts_tla := f_ts_BSSMAP_IE_AoIP_TLA("1.2.3.4", 2342);
	var template (value) BSSMAP_IE_SpeechCodec ts_codec := ts_BSSMAP_IE_SpeechCodec({ts_CodecFR});
	var template PDU_BSSAP tr_vgcs_vbs_ass_req :=
		tr_BSSMAP_VGCS_VBS_AssignmentReq(tr_ch_type, '01'O, tr_cell_id, bit2oct(encvalue(callref)), *, *, *);
	var template (value) PDU_BSSAP ts_vgcs_vbs_ass_res :=
					f_gen_asci_ass_res(0, ts_ch_type, ts_cell_id, ts_tla, ts_codec, '01000000'O);
	var myBSSMAP_Cause cause_fail := GSM0808_CAUSE_EQUIPMENT_FAILURE;
	var template (value) PDU_BSSAP ts_vgcs_vbs_ass_fail := ts_BSSMAP_VGCS_VBS_AssignmentFail(enum2int(cause_fail));
	var PDU_BSSAP rx_bssap;

	f_init_handler(pars);

	/* Wait some time before registering, because this has to be the second connection to be registered. */
	f_sleep(0.5);
	f_create_bssmap_exp_n_connect(193);

	timer T := 7.0;
	T.start;
	alt {
	[] BSSAP.receive(tr_vgcs_vbs_ass_req) -> value rx_bssap {
		/* The MSC allocates channel on the given BTS. The test case will send a result or a failure. */
		log("Got VGCS/VBS Assignment Request: ", rx_bssap);
		COORD.send(COORD_VGCS_ASSIGN);
		if (test == COORD_TEST_ASSIGN_FAIL) {
			log("Sending VGCS/VBS Assignment Failure: ", ts_vgcs_vbs_ass_fail);
			BSSAP.send(ts_vgcs_vbs_ass_fail);
		} else {
			log("Sending VGCS/VBS Assignment Result: ", ts_vgcs_vbs_ass_res);
			BSSAP.send(ts_vgcs_vbs_ass_res);
		}
		repeat;
		}
	[] BSSAP.receive(tr_BSSMAP_ClearCommand) {
		/* The SCCP connection is released. */
		log("Got Clear Command on channel connection.");
		COORD.send(COORD_CLEAR);
		repeat;
		}
	[] BSSAP.receive(PDU_BSSAP:?) -> value rx_bssap {
		setverdict(fail, "Got unexpected BSSAP message on channel connection: ", rx_bssap);
		}
	[] BSSAP.receive {
		setverdict(fail, "Got unexpected message on channel connection.");
		}
	[] COORD.receive(COORD_CLEAR) { }
	[] T.timeout {
		setverdict(fail, "Timeout on channel connection.");
		}
	}
}

/* Main function for call test */
private function f_TC_asci_call(charstring test) runs on asci_CT
{
        var BSC_ConnHdlr vc_conn_call, vc_conn_control, vc_conn_channel;
	var boolean got_vgcs_setup := false;
	var boolean got_vgcs_assign := false;
	var boolean got_uplink_seized := false;
	var boolean got_gcc_connect := false;
	var boolean got_bcc_connect := false;
	var boolean got_gcc_set_param := false;
	var boolean got_bcc_set_param := false;
	var boolean got_uplink_req_ack := false;
	var boolean got_gcc_termination := false;
	var boolean got_bcc_termination := false;
	var boolean got_gcc_termination_fail := false;
	var boolean got_bcc_termination_fail := false;
	var boolean got_assignment := false;
	var boolean connection_call := false;
	var boolean connection_control := false;
	var boolean connection_channel := false;
	var charstring event;

        f_init();

	/* Enable ASCI in VTY and setup a VGC and a VBS. */
        f_vty_config(MSCVTY, "asci", "enable");
	f_vty_config2(MSCVTY, { "asci", "gcr", "vgc 200"}, "cell 0.24.1 42");
	f_vty_config2(MSCVTY, { "asci", "gcr", "vbc 208"}, "cell 0.24.1 42");

        vc_conn_call := f_start_handler(refers(f_tc_vgcs_call), 33);
        vc_conn_control := f_start_handler(refers(f_tc_vgcs_control), 34);
        vc_conn_channel := f_start_handler(refers(f_tc_vgcs_channel), 35);

	connect(self:COORD_call, vc_conn_call:COORD);
	connect(self:COORD_control, vc_conn_control:COORD);
	connect(self:COORD_channel, vc_conn_channel:COORD);

	COORD_call.send(test);
	COORD_control.send(test);
	COORD_channel.send(test);

	/* Receive the test events until all three connections are released or not established. */
	timer T := 7.0, Texit := 0.5;
	T.start;
	alt {
	[] COORD_call.receive(COORD_SETUP) -> value event {
		log("Got test event: ", event);
		connection_call := true;
		repeat;
		}
	[] COORD_control.receive(COORD_VGCS_SETUP) -> value event {
		log("Got test event: ", event);
		got_vgcs_setup := true;
		connection_control := true;
		repeat;
		}
	[] COORD_channel.receive(COORD_VGCS_ASSIGN) -> value event {
		log("Got test event: ", event);
		got_vgcs_assign := true;
		connection_channel := true;
		repeat;
		}
	[] COORD_control.receive(COORD_UPLINK_REQ_ACK) -> value event {
		log("Got test event: ", event);
		got_uplink_req_ack := true;
		repeat;
		}
	[] COORD_control.receive(COORD_GCC_CONNECT) -> value event {
		log("Got test event: ", event);
		got_gcc_connect := true;
		repeat;
		}
	[] COORD_control.receive(COORD_BCC_CONNECT) -> value event {
		log("Got test event: ", event);
		got_bcc_connect := true;
		repeat;
		}
	[] COORD_control.receive(COORD_GCC_SET_PARAM) -> value event {
		log("Got test event: ", event);
		got_gcc_set_param := true;
		repeat;
		}
	[] COORD_control.receive(COORD_BCC_SET_PARAM) -> value event {
		log("Got test event: ", event);
		got_bcc_set_param := true;
		repeat;
		}
	[] COORD_control.receive(COORD_UPLINK_SEIZED) -> value event {
		log("Got test event: ", event);
		got_uplink_seized := true;
		repeat;
		}
	[] COORD_call.receive(COORD_GCC_TERMINATION_FAIL) -> value event {
		log("Got test event: ", event);
		got_gcc_termination_fail := true;
		repeat;
		}
	[] COORD_call.receive(COORD_BCC_TERMINATION_FAIL) -> value event {
		log("Got test event: ", event);
		got_bcc_termination_fail := true;
		repeat;
		}
	[] COORD_control.receive(COORD_GCC_TERMINATION) -> value event {
		log("Got test event: ", event);
		got_gcc_termination := true;
		repeat;
		}
	[] COORD_control.receive(COORD_BCC_TERMINATION) -> value event {
		log("Got test event: ", event);
		got_bcc_termination := true;
		repeat;
		}
	[] COORD_call.receive(COORD_ASSIGNMENT) -> value event {
		log("Got test event: ", event);
		got_assignment := true;
		repeat;
		}
	[not connection_call] COORD_call.receive(COORD_CLEAR) -> value event {
		setverdict(fail, "Received CLEAR COMMAND of initial call twice.");
		}
	[] COORD_call.receive(COORD_CLEAR) -> value event {
		log("Got test event: ", event);
		connection_call := false;
		if (connection_call or connection_control or connection_channel) {
			repeat;
		}
		Texit.start;
		repeat;
		}
	[not connection_control] COORD_control.receive(COORD_CLEAR) -> value event {
		setverdict(fail, "Received CLEAR COMMAND control connection twice.");
		}
	[] COORD_control.receive(COORD_CLEAR) -> value event {
		log("Got test event: ", event);
		connection_control := false;
		if (connection_call or connection_control or connection_channel) {
			repeat;
		}
		Texit.start;
		repeat;
		}
	[not connection_channel] COORD_channel.receive(COORD_CLEAR) -> value event {
		setverdict(fail, "Received CLEAR COMMAND of channel connection twice.");
		}
	[] COORD_channel.receive(COORD_CLEAR) -> value event {
		log("Got test event: ", event);
		connection_channel := false;
		if (connection_call or connection_control or connection_channel) {
			repeat;
		}
		Texit.start;
		repeat;
		}
	[] COORD_call.receive {
		setverdict(fail, "Unhandled COORD_call, please fix!");
		}
	[] COORD_control.receive {
		setverdict(fail, "Unhandled COORD_control, please fix!");
		}
	[] COORD_channel.receive {
		setverdict(fail, "Unhandled COORD_channel, please fix!");
		}
	[] T.timeout {
		setverdict(fail, "Timeout waiting for Test result");
		}
	[] Texit.timeout {
		log("All connection are cleared now.");
		}
	}

	/* Tell the connection handlers to exit. */
	COORD_call.send(COORD_CLEAR);
	COORD_control.send(COORD_CLEAR);
	COORD_channel.send(COORD_CLEAR);

        vc_conn_call.done;
        vc_conn_control.done;
        vc_conn_channel.done;

	if (getverdict == fail) {
		return;
	}

	/* Check if the outcome of each test is as expected. */
	select (test) {
	case (COORD_TEST_NO_CALLREF) {
		if (not got_vgcs_setup and
		    not got_vgcs_assign and
		    got_gcc_termination_fail) {
			setverdict(pass);
		}
		}
	case (COORD_TEST_SETUP_REFUSE) {
		if (got_vgcs_setup and
		    not got_vgcs_assign and
		    got_gcc_termination_fail) {
			setverdict(pass);
		}
		}
	case (COORD_TEST_ASSIGN_FAIL) {
		if (got_vgcs_setup and
		    got_vgcs_assign and
		    got_gcc_termination_fail) {
			setverdict(pass);
		}
		}
	case (COORD_TEST_COMPLETE_VGCS) {
		if (got_vgcs_setup and
		    got_vgcs_assign and
		    got_uplink_req_ack and
		    got_gcc_connect and
		    got_gcc_set_param and
		    got_uplink_seized and
		    got_gcc_termination and
		    got_assignment) {
			setverdict(pass);
		}
		}
	case (COORD_TEST_COMPLETE_VBS) {
		if (got_vgcs_setup and
		    got_vgcs_assign and
		    not got_uplink_req_ack and
		    got_bcc_connect and
		    got_bcc_set_param and
		    got_uplink_seized and
		    got_bcc_termination and
		    got_assignment) {
			setverdict(pass);
		}
		}
	case else {
		setverdict(fail, "Test case has no check for the outcome, please fix! Test was: ", test);
		}
	}

	if (getverdict == pass) {
		log("All expected events have been received. The test passed.");
	} else {
		setverdict(fail, "Not all expected event received.");
	}
}

/* A call is tried, but the given call reference does not exit. */
testcase TC_no_callref() runs on asci_CT
{
	f_TC_asci_call(COORD_TEST_NO_CALLREF);
}

/* The VGCS/VBS is refused by the BSC. */
testcase TC_setup_refuse() runs on asci_CT
{
	f_TC_asci_call(COORD_TEST_SETUP_REFUSE);
}

/* The VGCS/VBS channel is refused by the BSC. */
testcase TC_assign_fail() runs on asci_CT
{
	f_TC_asci_call(COORD_TEST_ASSIGN_FAIL);
}

/* The VGCS call is completed and the MS releases and requests the uplink again. Then it terminates the call. */
testcase TC_complete_vgcs() runs on asci_CT
{
	f_TC_asci_call(COORD_TEST_COMPLETE_VGCS);
}

/* The VBS call is completed and the MS terminates the call. */
testcase TC_complete_vbs() runs on asci_CT
{
	f_TC_asci_call(COORD_TEST_COMPLETE_VBS);
}

control {
	execute( TC_no_callref() );
	execute( TC_setup_refuse() );
	execute( TC_assign_fail() );
	execute( TC_complete_vgcs() );
	execute( TC_complete_vbs() );
}

}