summaryrefslogtreecommitdiffstats
path: root/hlr/HLR_Tests.ttcn
blob: 51d45bac3cc223fadcd79a1fc9dab300129c8d83 (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
module HLR_Tests {

import from GSUP_Types all;
import from GSUP_Emulation all;
import from IPA_Emulation all;

import from General_Types all;
import from Osmocom_Types all;
import from Osmocom_CTRL_Adapter all;

import from Osmocom_VTY_Functions all;
import from TELNETasp_PortType all;

type component test_CT extends CTRL_Adapter_CT {
	var IPA_Emulation_CT vc_IPA;
	var IPA_CCM_Parameters ccm_pars;
	/* legacy tests without ConnHdlr */
	port IPA_GSUP_PT GSUP;
	/* new tests using ConnHdlr + GSUP_Emulation */
	var GSUP_Emulation_CT vc_GSUP;
	/* only to get events from IPA underneath GSUP */
	port IPA_CTRL_PT GSUP_IPA_EVENT;

	port TELNETasp_PT VTY;

	timer g_Tguard := 10.0;
};

modulepar {
	charstring mp_hlr_ip := "127.0.0.1";
	integer mp_hlr_gsup_port := 4222;
	integer mp_hlr_ctrl_port := 4259;
};

type record HlrSubscrAud2G {
	charstring algo,
	OCT16 ki
}

type record HlrSubscrAud3G {
	charstring algo,
	OCT16 k,
	OCT16 op,
	boolean op_is_opc
}

type record HlrSubscriber {
	hexstring imsi,
	hexstring msisdn,
	HlrSubscrAud2G aud2g optional,
	HlrSubscrAud3G aud3g optional
}

type record of HlrSubscriber HlrSubscriberList;

type component HLR_ConnHdlr extends GSUP_ConnHdlr {
	timer g_Tguard := 10.0;
	var HLR_ConnHdlrPars g_pars;
	port TELNETasp_PT VTY;
}

type record HLR_ConnHdlrPars {
	HlrSubscriber sub
}

template (value) HLR_ConnHdlrPars t_Pars(hexstring imsi, hexstring msisdn := ''H) := {
	sub := {
		imsi := imsi,
		msisdn := msisdn,
		aud2g := omit,
		aud3g := omit
	}
}

template (value) HLR_ConnHdlrPars t_Pars_sub(HlrSubscriber sub) := {
	sub := sub
}

type function void_fn() runs on HLR_ConnHdlr;

/***********************************************************************
 * Main Component
 ***********************************************************************/

function f_init_vty() runs on test_CT {
	map(self:VTY, system:VTY);
	f_vty_set_prompts(VTY);
	f_vty_transceive(VTY, "enable");
}

private altstep as_Tguard() runs on test_CT {
	[] g_Tguard.timeout {
		setverdict(fail, "g_Tguard timeout");
		self.stop;
	}
}

function f_init_gsup(charstring id, boolean legacy) runs on test_CT {
	id := id & "-GSUP";
	var GsupOps ops := {
		create_cb := refers(GSUP_Emulation.ExpectedCreateCallback)
	}

	ccm_pars := c_IPA_default_ccm_pars;
	ccm_pars.name := "Osmocom TTCN-3 GSUP Simulator";

	vc_IPA := IPA_Emulation_CT.create(id & "-IPA");
	log("legacy= ", legacy);
	if (not legacy) {
		log("in not legacy case 1");
		vc_GSUP := GSUP_Emulation_CT.create(id);
	}

	map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
	if (not legacy) {
		log("in not legacy case 2");
		connect(vc_GSUP:GSUP, vc_IPA:IPA_GSUP_PORT);
		connect(vc_IPA:IPA_CTRL_PORT, self:GSUP_IPA_EVENT);
		vc_GSUP.start(GSUP_Emulation.main(ops, id));
	} else {
		connect(vc_IPA:IPA_GSUP_PORT, self:GSUP);
	}

	vc_IPA.start(IPA_Emulation.main_client(mp_hlr_ip, mp_hlr_gsup_port, "", -1, ccm_pars));

	/* wait for incoming connection to GSUP port before proceeding */
	timer T := 10.0;
	T.start;
	alt {
		[not legacy] GSUP_IPA_EVENT.receive(t_ASP_IPA_EVT_UD(ASP_IPA_EVENT_UP)) { }
		[legacy] GSUP.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP}) { }
		[] T.timeout {
			setverdict(fail, "No connection to GSUP Port");
			self.stop;
		}
	}
}

function f_init(boolean legacy := true) runs on test_CT {

	/* activate default guard timer to ensure all tests eventually terminate */
	g_Tguard.start;
	activate(as_Tguard());

	f_init_gsup("HLR_Test", legacy);
	f_init_vty();

	f_ipa_ctrl_start(mp_hlr_ip, mp_hlr_ctrl_port);
}

function f_start_handler(void_fn fn, HLR_ConnHdlrPars pars) runs on test_CT return HLR_ConnHdlr {
	var HLR_ConnHdlr vc_conn;
	var charstring id := testcasename();

	vc_conn := HLR_ConnHdlr.create(id);
	connect(vc_conn:GSUP, vc_GSUP:GSUP_CLIENT);
	connect(vc_conn:GSUP_PROC, vc_GSUP:GSUP_PROC);

	vc_conn.start(f_handler_init(fn, id, pars));
	return vc_conn;
}

private function f_handler_init_vty() runs on HLR_ConnHdlr {
	map(self:VTY, system:VTY);
	f_vty_set_prompts(VTY);
	f_vty_transceive(VTY, "enable");
}

/* first function inside ConnHdlr component; sets g_pars + starts function */
function f_handler_init(void_fn fn, charstring id, template (omit) HLR_ConnHdlrPars pars := omit)
runs on HLR_ConnHdlr
{
	if (isvalue(pars)) {
		g_pars := valueof(pars);
		f_create_gsup_expect(hex2str(g_pars.sub.imsi));
	}
	f_handler_init_vty();
	fn.apply();
}

/***********************************************************************
 * Subscriber creation via VTY
 ***********************************************************************/

template (value) HlrSubscriber t_SubNoAuth(hexstring imsi, hexstring msisdn) := {
	imsi := imsi,
	msisdn := msisdn,
	aud2g := omit,
	aud3g := omit
}

const OCT16 c_KI_DEFAULT := '000102030405060708090a0b0c0d0e0f'O;
const OCT16 c_K_DEFAULT := '101112131415161718191a1b1c1d1e1f'O;
const OCT16 c_OP_DEFAULT := '202122232425262728292a2b2c2d2e2f'O;
//const OCT16 c_OPC_DEFAULT := '303132333435363738393a3b3c3d3f'O;

template (value) HlrSubscriber t_Sub2G(hexstring imsi, hexstring msisdn, charstring algo) := {
	imsi := imsi,
	msisdn := msisdn,
	aud2g := {
		algo := algo,
		ki := c_KI_DEFAULT
	},
	aud3g := omit
}

template (value) HlrSubscriber t_Sub3G(hexstring imsi, hexstring msisdn, charstring algo, boolean is_opc) := {
	imsi := imsi,
	msisdn := msisdn,
	aud2g := omit,
	aud3g := {
		algo := algo,
		k := c_K_DEFAULT,
		op := c_OP_DEFAULT,
		op_is_opc := is_opc
	}
}

template (value) HlrSubscriber t_Sub2G3G(hexstring imsi, hexstring msisdn, charstring algo2g, charstring algo3g, boolean is_opc) := {
	imsi := imsi,
	msisdn := msisdn,
	aud2g := {
		algo := algo2g,
		ki := c_KI_DEFAULT
	},
	aud3g := {
		algo := algo3g,
		k := c_K_DEFAULT,
		op := c_OP_DEFAULT,
		op_is_opc := is_opc
	}
}

/* generate a variety of subscribers with different parameters */
function f_gen_subs() runs on test_CT return HlrSubscriberList {
	var HlrSubscriber sub;
	var HlrSubscriberList sl := {};

	sub := valueof(t_Sub2G(f_rnd_imsi('26242'H), '49161'H & f_rnd_hexstring(7, 9), "comp128v1"));
	sl := sl & { sub };

	sub := valueof(t_Sub2G(f_rnd_imsi('26242'H), '49161'H & f_rnd_hexstring(7, 9), "comp128v2"));
	sl := sl & { sub };

	sub := valueof(t_Sub2G(f_rnd_imsi('26242'H), '49161'H & f_rnd_hexstring(7, 9), "comp128v3"));
	sl := sl & { sub };

	sub := valueof(t_Sub3G(f_rnd_imsi('26242'H), '49161'H & f_rnd_hexstring(7, 9), "milenage", false));
	sl := sl & { sub };

	sub := valueof(t_Sub3G(f_rnd_imsi('26242'H), '49161'H & f_rnd_hexstring(7, 9), "milenage", true));
	sl := sl & { sub };

	sub := valueof(t_Sub2G3G(f_rnd_imsi('26242'H), '49161'H & f_rnd_hexstring(7, 9),
				 "comp128v1", "milenage", false));
	sl := sl & { sub };

	sub := valueof(t_Sub2G3G(f_rnd_imsi('26242'H), '49161'H & f_rnd_hexstring(7, 9),
				 "comp128v2", "milenage", false));
	sl := sl & { sub };

	sub := valueof(t_Sub2G3G(f_rnd_imsi('26242'H), '49161'H & f_rnd_hexstring(7, 9),
				 "comp128v3", "milenage", false));
	sl := sl & { sub };

	return sl;
}

function f_vty_transceive_match(TELNETasp_PT pt, charstring cmd, template charstring exp_ret) {
	var charstring ret := f_vty_transceive_ret(pt, cmd);
	if (not match(ret, exp_ret)) {
		setverdict(fail, "Non-matching VTY response: ", ret);
		self.stop;
	}
}

private template (value) charstring t_subscr_prefix(hexstring imsi) :=
	"subscriber imsi " & hex2str(imsi) & " ";

/* create a given subscriber using the VTY */
function f_vty_subscr_create(TELNETasp_PT VTY, HlrSubscriber sub) {
	var charstring prefix := valueof(t_subscr_prefix(sub.imsi));
	f_vty_transceive_match(VTY, prefix & "create", pattern "% Created subscriber *");
	f_vty_transceive_match(VTY, prefix & "update msisdn " & hex2str(sub.msisdn),
				pattern "% Updated subscriber *");
	if (ispresent(sub.aud2g)) {
		f_vty_transceive_match(VTY, prefix & "update aud2g " & sub.aud2g.algo &
					" ki " & oct2str(sub.aud2g.ki),
					pattern "");
	} else {
		f_vty_transceive_match(VTY, prefix & "update aud2g none", pattern "");
	}

	if (ispresent(sub.aud3g)) {
		var charstring op_mode := "op";
		if (sub.aud3g.op_is_opc) {
			op_mode := "opc";
		}
		f_vty_transceive_match(VTY, prefix & "update aud3g " & sub.aud3g.algo &
					" k " & oct2str(sub.aud3g.k) & " " & op_mode & " " &
					oct2str(sub.aud3g.op), pattern "");
	} else {
		f_vty_transceive_match(VTY, prefix & "update aud3g none", pattern "");
	}
}

function f_vty_subscr_update_msisdn(TELNETasp_PT VTY, HlrSubscriber sub, hexstring new_msisdn) {
	var charstring prefix := valueof(t_subscr_prefix(sub.imsi));
	f_vty_transceive_match(VTY, prefix & "update msisdn " & hex2str(new_msisdn),
				pattern "% Updated subscriber *");
}

/* perform 'delete' on subscriber */
function f_vty_subscr_delete(TELNETasp_PT VTY, HlrSubscriber sub) {
	var charstring prefix := valueof(t_subscr_prefix(sub.imsi));
	f_vty_transceive_match(VTY, prefix & "delete",
				pattern "% Deleted subscriber for IMSI *");
}

/* perform 'show' on subscriber; match result with pattern 'exp' */
function f_vty_subscr_show(TELNETasp_PT VTY, HlrSubscriber sub, template charstring exp) {
	var charstring prefix := valueof(t_subscr_prefix(sub.imsi));
	f_vty_transceive_match(VTY, prefix & "show", exp);
}


/***********************************************************************
 * Helper functions for ConnHdlr
 ***********************************************************************/

/* perform SendAuthInfo for given imsi, return the GSUP response/error */
function f_perform_SAI(hexstring imsi, template (omit) integer exp_err_cause := omit)
runs on HLR_ConnHdlr return GSUP_PDU {
	var GSUP_PDU ret;
	timer T := 3.0;
	var boolean exp_fail := false;
	if (not istemplatekind(exp_err_cause, "omit")) {
		exp_fail := true;
	}

	GSUP.send(valueof(ts_GSUP_SAI_REQ(imsi)));
	T.start;
	alt {
	[exp_fail] GSUP.receive(tr_GSUP_SAI_ERR(imsi, exp_err_cause)) -> value ret {
		setverdict(pass);
		}
	[exp_fail] GSUP.receive(tr_GSUP_SAI_ERR(imsi, ?)) -> value ret {
		setverdict(fail, "Unexpected SAI ERROR Cause");
		}
	[exp_fail] GSUP.receive(tr_GSUP_SAI_RES(imsi)) -> value ret {
		setverdict(fail, "Unexpected SAI.res for unknown IMSI");
		}
	[not exp_fail] GSUP.receive(tr_GSUP_SAI_ERR(imsi, ?)) -> value ret {
		setverdict(fail, "Unexpected SAI ERROR");
		}
	[not exp_fail] GSUP.receive(tr_GSUP_SAI_RES(imsi)) -> value ret {
		setverdict(pass);
		}
	[] GSUP.receive { repeat; }
	[] T.timeout {
		setverdict(fail, "Timeout waiting for SAI response");
		self.stop;
		}
	}
	return ret;
}

function f_perform_UL(hexstring imsi, template hexstring msisdn,
			template (omit) integer exp_err_cause := omit)
runs on HLR_ConnHdlr return GSUP_PDU {
	var GSUP_PDU ret;
	timer T := 3.0;
	var boolean exp_fail := false;
	var boolean isd_done := false;
	if (not istemplatekind(exp_err_cause, "omit")) {
		exp_fail := true;
	}

	GSUP.send(valueof(ts_GSUP_UL_REQ(imsi)));
	T.start;
	alt {
	[exp_fail] GSUP.receive(tr_GSUP_UL_ERR(imsi, exp_err_cause)) -> value ret {
		setverdict(pass);
		}
	[exp_fail] GSUP.receive(tr_GSUP_UL_ERR(imsi, ?)) -> value ret {
		setverdict(fail, "Unexpected UL ERROR Cause");
		}
	[exp_fail] GSUP.receive(tr_GSUP_UL_RES(imsi)) -> value ret {
		setverdict(fail, "Unexpected UL.res for unknown IMSI");
		}
	[exp_fail] GSUP.receive(tr_GSUP_ISD_REQ(imsi)) -> value ret {
		setverdict(fail, "Unexpected ISD.req in error case");
		}
	[not exp_fail] GSUP.receive(tr_GSUP_UL_ERR(imsi, ?)) -> value ret {
		setverdict(fail, "Unexpected UL ERROR");
		}
	[not exp_fail and not isd_done] GSUP.receive(tr_GSUP_ISD_REQ(imsi, msisdn)) -> value ret {
		GSUP.send(ts_GSUP_ISD_RES(imsi));
		isd_done := true;
		repeat;
		}
	[not exp_fail and isd_done] GSUP.receive(tr_GSUP_UL_RES(imsi)) -> value ret {
		setverdict(pass);
		}
	[] GSUP.receive { repeat; }
	[] T.timeout {
		setverdict(fail, "Timeout waiting for UL response");
		self.stop;
		}
	}
	return ret;
}

/* perform PurgeMS for given imsi, return the GSUP response/error */
function f_perform_PURGE(hexstring imsi, GSUP_CnDomain cn_dom,
			 template (omit) integer exp_err_cause := omit)
runs on HLR_ConnHdlr return GSUP_PDU {
	var GSUP_PDU ret;
	timer T := 3.0;
	var boolean exp_fail := false;
	if (not istemplatekind(exp_err_cause, "omit")) {
		exp_fail := true;
	}

	GSUP.send(valueof(ts_GSUP_PURGE_MS_REQ(imsi, cn_dom)));
	T.start;
	alt {
	[exp_fail] GSUP.receive(tr_GSUP_PURGE_MS_ERR(imsi, exp_err_cause)) -> value ret {
		setverdict(pass);
		}
	[exp_fail] GSUP.receive(tr_GSUP_PURGE_MS_ERR(imsi, ?)) -> value ret {
		setverdict(fail, "Unexpected PURGE ERROR Cause");
		}
	[exp_fail] GSUP.receive(tr_GSUP_PURGE_MS_RES(imsi)) -> value ret {
		setverdict(fail, "Unexpected PURGE.res for unknown IMSI");
		}
	[not exp_fail] GSUP.receive(tr_GSUP_PURGE_MS_ERR(imsi, ?)) -> value ret {
		setverdict(fail, "Unexpected PURGE ERROR");
		}
	[not exp_fail] GSUP.receive(tr_GSUP_PURGE_MS_RES(imsi)) -> value ret {
		setverdict(pass);
		}
	[] GSUP.receive { repeat; }
	[] T.timeout {
		setverdict(fail, "Timeout waiting for PURGE response");
		self.stop;
		}
	}
	return ret;
}


/***********************************************************************
 * Testcases
 ***********************************************************************/

/* 23.003 Section 2.2 clearly states that an IMSI with less
 * than 5 digits is impossible. Even 5 digits is still questionable */
private function f_TC_gsup_sai_err_invalid_imsi() runs on HLR_ConnHdlr {
	var GSUP_PDU res;
	res := f_perform_SAI(g_pars.sub.imsi, 96); /* Invalid Mandatory information */
	setverdict(pass);
}
testcase TC_gsup_sai_err_invalid_imsi() runs on test_CT {
	var HLR_ConnHdlr vc_conn;
	var HLR_ConnHdlrPars pars := valueof(t_Pars('0123'H));
	f_init(false);
	vc_conn := f_start_handler(refers(f_TC_gsup_sai_err_invalid_imsi), pars);
	vc_conn.done;
}


private function f_TC_gsup_sai_err_unknown_imsi() runs on HLR_ConnHdlr {
	var GSUP_PDU res;
	res := f_perform_SAI(g_pars.sub.imsi, 2);
	setverdict(pass);
}

testcase TC_gsup_sai_err_unknown_imsi() runs on test_CT {
	var HLR_ConnHdlr vc_conn;
	var HLR_ConnHdlrPars pars := valueof(t_Pars(f_rnd_imsi('26242'H)));
	f_init(false);
	vc_conn := f_start_handler(refers(f_TC_gsup_sai_err_unknown_imsi), pars);
	vc_conn.done;
}

function f_start_handler_per_sub(void_fn fn, HlrSubscriberList sl) runs on test_CT {
	for (var integer i := 0; i < sizeof(sl); i := i+1) {
		var HlrSubscriber sub := sl[i];
		var HLR_ConnHdlrPars pars := valueof(t_Pars_sub(sub));
		var HLR_ConnHdlr vc_conn;

		f_vty_subscr_create(VTY, sub);
		vc_conn := f_start_handler(fn, pars);
		vc_conn.done;
		f_vty_subscr_delete(VTY, sub);
	}
}

/* test SAI for a number of different subscriber cases (algo, 2g/3g, ...) */
private function f_TC_gsup_sai() runs on HLR_ConnHdlr {
	var GSUP_PDU res;
	res := f_perform_SAI(g_pars.sub.imsi);
	/* TODO: match if tuple[s] matches expectation */
	setverdict(pass);
}
testcase TC_gsup_sai() runs on test_CT {
	var HlrSubscriberList sl;
	var GSUP_PDU res;

	f_init(false);

	sl := f_gen_subs();
	f_start_handler_per_sub(refers(f_TC_gsup_sai), sl);

	setverdict(pass);
}

/* test UL for unknown IMSI */
private function f_TC_ul_unknown_imsi() runs on HLR_ConnHdlr {
	var GSUP_PDU res;
	res := f_perform_UL(g_pars.sub.imsi, ?, 2);
	setverdict(pass);
}
testcase TC_gsup_ul_unknown_imsi() runs on test_CT {
	var hexstring imsi := f_rnd_imsi('26242'H);
	var HLR_ConnHdlrPars pars := valueof(t_Pars(imsi));
	var HLR_ConnHdlr vc_conn;

	f_init(false);
	vc_conn := f_start_handler(refers(f_TC_ul_unknown_imsi), pars);
	vc_conn.done;
}

/* test UL for a number of different subscriber cases (algo, 2g/3g, ...) */
private function f_TC_gsup_ul() runs on HLR_ConnHdlr {
	var GSUP_PDU res;
	res := f_perform_UL(g_pars.sub.imsi, g_pars.sub.msisdn);
	setverdict(pass);
}
testcase TC_gsup_ul() runs on test_CT {
	var HlrSubscriberList sl;
	var GSUP_PDU res;

	f_init(false);
	sl := f_gen_subs();
	f_start_handler_per_sub(refers(f_TC_gsup_ul), sl);

	setverdict(pass);
}

/* Test only the VTY commands */
testcase TC_vty() runs on test_CT {
	var HlrSubscriber sub;

	f_init();

	/* we're not using f_gen_subs() here as the expect pattern for the 'show' are different
	 * from case to case */
	sub := valueof(t_Sub2G(f_rnd_imsi('26242'H), '49161'H & f_rnd_hexstring(7, 9), "comp128v1"));
	f_vty_subscr_create(VTY, sub);
	f_vty_subscr_show(VTY, sub, pattern "*IMSI: *2G auth: COMP128v1*");
	f_vty_subscr_delete(VTY, sub);

	sub := valueof(t_Sub3G(f_rnd_imsi('26242'H), '49161'H & f_rnd_hexstring(7, 9),
				"milenage", false));
	f_vty_subscr_create(VTY, sub);
	f_vty_subscr_show(VTY, sub, pattern "*IMSI: *3G auth: MILENAGE*");
	f_vty_subscr_delete(VTY, sub);

	sub := valueof(t_Sub2G3G(f_rnd_imsi('26242'H), '49161'H & f_rnd_hexstring(7, 9),
				 "comp128v1", "milenage", false));
	f_vty_subscr_create(VTY, sub);
	f_vty_subscr_show(VTY, sub, pattern "*IMSI: *2G auth: COMP128v1*3G auth: MILENAGE*");
	f_vty_subscr_delete(VTY, sub);

	setverdict(pass);
}

/* VTY changes to MSISDN should result in ISD to current VLR */
private function f_TC_vty_msisdn_isd() runs on HLR_ConnHdlr {
	var hexstring new_msisdn;
	var GSUP_PDU res;
	timer T := 5.0;

	/* Create Subscriber */
	f_vty_subscr_create(VTY, g_pars.sub);

	/* Perform UpdateLocation (VLR now known to HLR) */
	res := f_perform_UL(g_pars.sub.imsi, g_pars.sub.msisdn);

	/* Then change IMSI via VTY */
	new_msisdn := '49161'H & f_rnd_hexstring(7, 9);
	f_vty_subscr_update_msisdn(VTY, g_pars.sub, new_msisdn);
	/* And expect InsertSubscriberData as result */
	T.start;
	alt {
	[] GSUP.receive(tr_GSUP_ISD_REQ(g_pars.sub.imsi, new_msisdn)) {
		GSUP.send(ts_GSUP_ISD_RES(g_pars.sub.imsi));
		g_pars.sub.msisdn := new_msisdn;
		setverdict(pass);
		}
	[] GSUP.receive(tr_GSUP_ISD_REQ(g_pars.sub.imsi, g_pars.sub.msisdn)) {
		log("received ISD req with old MSISDN");
		setverdict(fail);
		}
	[] GSUP.receive { repeat; }
	[] T.timeout {
		setverdict(fail, "Timeout waiting for ISD.req");
		}
	}
}
testcase TC_vty_msisdn_isd() runs on test_CT {
	var HlrSubscriber sub;
	var HLR_ConnHdlr vc_conn;

	f_init(false);

	/* Create Subscriber */
	sub := valueof(t_Sub2G(f_rnd_imsi('26242'H), '49161'H & f_rnd_hexstring(7, 9), "comp128v1"));

	vc_conn := f_start_handler(refers(f_TC_vty_msisdn_isd), valueof(t_Pars_sub(sub)));
	vc_conn.done;
}

/* Test PURGE MS for CS services */
private function f_TC_gsup_purge_cs() runs on HLR_ConnHdlr {
	var GSUP_PDU res;
	res := f_perform_UL(g_pars.sub.imsi, g_pars.sub.msisdn);
	res := f_perform_PURGE(g_pars.sub.imsi, OSMO_GSUP_CN_DOMAIN_CS);
}
testcase TC_gsup_purge_cs() runs on test_CT {
	var HlrSubscriberList sl;
	var GSUP_PDU res;

	f_init(false);
	sl := f_gen_subs();
	f_start_handler_per_sub(refers(f_TC_gsup_purge_cs), sl);

	setverdict(pass);
}

/* Test PURGE MS for PS services */
private function f_TC_gsup_purge_ps() runs on HLR_ConnHdlr {
	var GSUP_PDU res;
	res := f_perform_UL(g_pars.sub.imsi, g_pars.sub.msisdn);
	res := f_perform_PURGE(g_pars.sub.imsi, OSMO_GSUP_CN_DOMAIN_PS);
}
testcase TC_gsup_purge_ps() runs on test_CT {
	var HlrSubscriberList sl;

	f_init(false);
	sl := f_gen_subs();
	f_start_handler_per_sub(refers(f_TC_gsup_purge_ps), sl);

	setverdict(pass);
}

/* Test PURGEG MS procedure for unknown IMSI */

private function f_TC_gsup_purge_unknown() runs on HLR_ConnHdlr {
	var GSUP_PDU res;
	res := f_perform_PURGE(g_pars.sub.imsi, OSMO_GSUP_CN_DOMAIN_CS, 2);
}
testcase TC_gsup_purge_unknown() runs on test_CT {
	var hexstring imsi := '2345743413463'H;
	var HLR_ConnHdlrPars pars := valueof(t_Pars(imsi));
	var HLR_ConnHdlr vc_conn;

	f_init(false);
	vc_conn := f_start_handler(refers(f_TC_ul_unknown_imsi), pars);
	vc_conn.done;

	setverdict(pass);
}

/* TODO:
  * UL with ISD error
  * UL with ISD timeout
  * LOCATION CANCEL
  * AUTH FAIL REP
  * DELETE DATA after hlr_subscr_nam() change
  * correctness
  ** wrong message type
  ** wrong length of PDU
  ** too short message
  ** missing IMSI IE

 */

control {
	execute( TC_gsup_sai_err_invalid_imsi() );
	execute( TC_gsup_sai() );
	execute( TC_gsup_ul_unknown_imsi() );
	execute( TC_gsup_sai_err_unknown_imsi() );
	execute( TC_gsup_ul() );
	execute( TC_vty() );
	execute( TC_vty_msisdn_isd() );
	execute( TC_gsup_purge_cs() );
	execute( TC_gsup_purge_ps() );
	execute( TC_gsup_purge_unknown() );
};

};