blob: 6e772dc08af477abe872ac31e3b733a3c0377c98 [file] [log] [blame]
Harald Welte3a194402017-07-22 17:07:51 +02001module Test {
2
3 import from BSSGP_Helper_Functions all;
4 import from BSSGP_Types all;
Harald Welte6e594f22017-07-23 16:19:35 +02005 import from BSSGP_Emulation all;
Harald Welte6fff3642017-07-22 21:36:13 +02006 import from NS_Types all;
Harald Welte6e594f22017-07-23 16:19:35 +02007 import from NS_Emulation all;
Harald Welte3a194402017-07-22 17:07:51 +02008
9 type component dummy_CT {
Harald Welte6e594f22017-07-23 16:19:35 +020010 port BSSGP_PT BSSGP;
11 var NS_CT ns_component;
12 var BSSGP_CT bssgp_component;
13 }
14
15 function f_init() runs on dummy_CT {
16 /* create a new NS component */
17 ns_component := NS_CT.create;
18 bssgp_component := BSSGP_CT.create;
19 /* connect our BSSGP port to the BSSGP Emulation */
20 connect(self:BSSGP, bssgp_component:BSSGP_SP);
21 /* connect lower-end of BSSGP with BSSGP_CODEC_PORT (maps to NS_PT*/
22 connect(bssgp_component:BSCP, ns_component:NS_SP);
23 /* connect lower-end of NS emulation to NS_CODEC_PORT (on top of IPl4) */
24 map(ns_component:NSCP, system:NS_CODEC_PORT);
25 ns_component.start(NSStart());
26 bssgp_component.start(BssgpStart());
Harald Welte3a194402017-07-22 17:07:51 +020027 }
28
Harald Welte6fff3642017-07-22 21:36:13 +020029 function f_bssgp_assert_prepr(in octetstring a, in octetstring b) {
30 log("BSSGP Input: ", a);
31 log("BSSGP Expected: ", b);
Harald Weltef1fd0162017-07-22 20:34:05 +020032 var octetstring a_preprocessed := f_BSSGP_expand_len(a);
Harald Welte6fff3642017-07-22 21:36:13 +020033 log("BSSGP Preprocessed: ", a_preprocessed);
Harald Welte3a194402017-07-22 17:07:51 +020034
35 if (a_preprocessed != b) {
36 setverdict(fail);
37 } else {
38 setverdict(pass);
39 }
40 }
41
Harald Welte6fff3642017-07-22 21:36:13 +020042 function f_bssgp_dec_and_log(in octetstring inp) {
43 log("BSSGP Input: ", inp);
Harald Weltef1fd0162017-07-22 20:34:05 +020044 var octetstring inp_p := f_BSSGP_expand_len(inp);
Harald Welte6fff3642017-07-22 21:36:13 +020045 log("BSSGP Preprocessed: ", inp_p);
Harald Welte3a194402017-07-22 17:07:51 +020046 var BssgpPdu dec := dec_BssgpPdu(inp_p);
Harald Welte6fff3642017-07-22 21:36:13 +020047 log("BSSGP Decoded: ", dec);
Harald Welte3a194402017-07-22 17:07:51 +020048 }
49
Harald Welte6fff3642017-07-22 21:36:13 +020050 testcase TC_selftest_bssgp() runs on dummy_CT {
Harald Welte3a194402017-07-22 17:07:51 +020051 const octetstring c_bvc_reset_pcu := '2204820000078108088832f44000c80051e0'O;
52 const octetstring c_bvc_reset_q := '2204820000078100'O;
53 const octetstring c_status_pcu := '4107810515882204820000078103'O;
54 const octetstring c_reset_ack_q := '2304820000'O;
55 const octetstring c_reset_ack_pcu := '23048200c4'O;
56 const octetstring c_unblock_pcu := '24048200c4'O;
57 const octetstring c_unblock_ack_q := '25048200c4'O;
58 const octetstring c_fc_bvc_pcu := '261e8101058200fa038200c8018200fa1c8200c806820000'O;
59 const octetstring c_fc_bvc_ack_q := '271e8101'O;
60 const octetstring c_gmm_mo_att_req := '01bb146ddd000004088832f44000c80051e000800e003b01c001080103e5e000110a0005f4fb146ddd32f44000c8001d1b53432b37159ef9090070000dd9c6321200e00019b32c642401c0002017057bf0ec'O;
61 const octetstring c_gmm_mt_ac_req := '00bb146ddd0050001682ffff0a8204030e9c41c001081200102198c72477ea104895e8b959acc58b108182f4d045'O;
62 const octetstring c_gmm_mo_ac_resp := '01bb146ddd000004088832f44000c80051e000800e000e01c00508130122fa361f5fdd623d'O;
63 const octetstring c_gmm_mt_att_acc := '00bb146ddd0050001682ffff0a8204030e9841c005080201340432f44000c8001805f4fb146ddd0967d0'O;
64 const octetstring c_gmm_mt_det_req := '00bb146ddd0050001682ffff0a8204030e8941c00908050215f0b6'O;
65 const octetstring c_gmm_mo_att_cpl := '01fb146ddd000004088832f44000c80051e000800e000801c009080339d7bc'O;
66
67 /* single byte length to two byte length */
Harald Welte6fff3642017-07-22 21:36:13 +020068 f_bssgp_assert_prepr('04058101'O, '0405000101'O);
69 f_bssgp_assert_prepr('040589000102030405060708'O, '04050009000102030405060708'O);
Harald Welte3a194402017-07-22 17:07:51 +020070 /* two byte length to two byte length */
Harald Welte6fff3642017-07-22 21:36:13 +020071 f_bssgp_assert_prepr('0405000101'O, '0405000101'O);
Harald Welte3a194402017-07-22 17:07:51 +020072 /* special case: DL-UD + UL-UD */
Harald Welte6fff3642017-07-22 21:36:13 +020073 f_bssgp_assert_prepr('00aabbccddeeffaa29822342'O, '00aabbccddeeffaa2900022342'O);
74 f_bssgp_assert_prepr('01aabbccddeeffaa29822342'O, '01aabbccddeeffaa2900022342'O);
Harald Welte3a194402017-07-22 17:07:51 +020075 /* multiple TLVs */
Harald Welte6fff3642017-07-22 21:36:13 +020076 f_bssgp_assert_prepr('234281aa4382bbbb'O, '23420001aa430002bbbb'O);
77 f_bssgp_assert_prepr('230080'O, '23000000'O);
Harald Welte3a194402017-07-22 17:07:51 +020078
Harald Welte6fff3642017-07-22 21:36:13 +020079 f_bssgp_dec_and_log(c_bvc_reset_pcu);
80 f_bssgp_dec_and_log(c_bvc_reset_q);
81 f_bssgp_dec_and_log(c_status_pcu);
82 f_bssgp_dec_and_log(c_reset_ack_q);
83 f_bssgp_dec_and_log(c_reset_ack_pcu);
84 f_bssgp_dec_and_log(c_unblock_pcu);
85 f_bssgp_dec_and_log(c_unblock_ack_q);
86 f_bssgp_dec_and_log(c_fc_bvc_pcu);
87 f_bssgp_dec_and_log(c_fc_bvc_ack_q);
88 f_bssgp_dec_and_log(c_gmm_mo_att_req);
89 f_bssgp_dec_and_log(c_gmm_mt_ac_req);
90 f_bssgp_dec_and_log(c_gmm_mo_ac_resp);
91 f_bssgp_dec_and_log(c_gmm_mt_att_acc);
92 f_bssgp_dec_and_log(c_gmm_mt_det_req);
93 f_bssgp_dec_and_log(c_gmm_mo_att_cpl);
94 }
95
96 function f_ns_assert_prepr(in octetstring a, in octetstring b) {
97 log("NS Input: ", a);
98 log("NS Expected: ", b);
99 var octetstring a_preprocessed := f_NS_expand_len(a);
100 log("NS Preprocessed: ", a_preprocessed);
101
102 if (a_preprocessed != b) {
103 setverdict(fail);
104 } else {
105 setverdict(pass);
106 }
107 }
108
109 function f_ns_dec_and_log(in octetstring inp) {
110 log("NS Input: ", inp);
111 var octetstring inp_p := f_NS_expand_len(inp);
112 log("NS Preprocessed: ", inp_p);
113 var NsPdu dec := dec_NsPdu(inp_p);
114 log("NS Decoded: ", dec);
115 }
116
117 testcase TC_selftest_ns() runs on dummy_CT {
118 const octetstring c_ns_reset_pcu := '000000c4271e813d'O;
119
120 /* single byte length to two byte length */
121 f_ns_assert_prepr('04058101'O, '0405000101'O);
122 f_ns_assert_prepr('040589000102030405060708'O, '04050009000102030405060708'O);
123 /* two byte length to two byte length */
124 f_ns_assert_prepr('0405000101'O, '0405000101'O);
125 /* special case: NS-UNITDATA */
126 f_ns_assert_prepr('00aabbccddeeffaa29822342'O, '00aabbccddeeffaa2900022342'O);
127 /* multiple TLVs */
128 f_ns_assert_prepr('234281aa4382bbbb'O, '23420001aa430002bbbb'O);
129 /* zero-length */
130 f_ns_assert_prepr('230080'O, '23000000'O);
131
132 f_ns_dec_and_log(c_ns_reset_pcu);
Harald Welte3a194402017-07-22 17:07:51 +0200133 }
134
Harald Welte6e594f22017-07-23 16:19:35 +0200135 testcase TC_nsem() runs on dummy_CT {
Harald Welte13d391e2017-07-23 19:52:33 +0200136 timer T:= 60.0;
137
Harald Welte6e594f22017-07-23 16:19:35 +0200138 f_init();
Harald Welte13d391e2017-07-23 19:52:33 +0200139 T.start
140 alt {
141 [] BSSGP.receive(t_BssgpStsInd(?, ?, BVC_S_UNBLOCKED)) { }
142 [] BSSGP.receive { repeat; }
143 [] T.timeout { setverdict(fail); }
144 }
145 T.stop
146 log("BSSGP successfully initialized");
147
148 while (true) {
149 var BssgpPdu pdu;
150 alt {
151 [] BSSGP.receive(BssgpPdu:?) -> value pdu {
152 log("BSSGP Rx: ", pdu);
153 }
154 [] BSSGP.receive(t_BssgpStsInd(?, ?, BVC_S_UNBLOCKED)) { repeat; }
155 [] BSSGP.receive { repeat; }
156 }
157 }
Harald Welte6e594f22017-07-23 16:19:35 +0200158 }
159
Harald Welte3a194402017-07-22 17:07:51 +0200160 control {
Harald Welte6fff3642017-07-22 21:36:13 +0200161 execute(TC_selftest_bssgp());
162 execute(TC_selftest_ns());
Harald Welte6e594f22017-07-23 16:19:35 +0200163 execute(TC_nsem());
Harald Welte3a194402017-07-22 17:07:51 +0200164 }
165};