blob: 5fa89fa27da0e316a5500f8d824955bacc8e22ee [file] [log] [blame]
Harald Welte56db5fd2017-07-14 18:25:59 +02001module Test {
2 import from GSM_SystemInformation all;
Harald Welteb622a3d2017-07-14 22:26:33 +02003 import from GSMTAP_Types all;
4 import from GSMTAP_PortType all;
5 import from IPL4_GSMTAP_CtrlFunct all;
Harald Welte9a907b32017-07-15 10:34:27 +02006 import from TELNETasp_PortType all;
Harald Welte56db5fd2017-07-14 18:25:59 +02007
8 const octetstring si1 := '5506198fb38000000000000000000000000000e504002b'O;
9 const octetstring si2 := '59061a00000000000000000000000000000000ffe50400'O;
10 const octetstring si3 := '49061b000062f22404d2490301275d40e50400392b2b2b'O;
11 const octetstring si4 := '31061c62f22404d25d40e504002b2b2b2b2b2b2b2b2b2b'O;
12
13 type component dummy_CT {
Harald Welteb622a3d2017-07-14 22:26:33 +020014 port GSMTAP_PT GSMTAP;
Harald Welte9a907b32017-07-15 10:34:27 +020015 port TELNETasp_PT BSCVTY;
Harald Welte56db5fd2017-07-14 18:25:59 +020016 };
17
18 testcase TC_si1() runs on dummy_CT {
19 var SystemInformationHeader hdr := {
20 l2_plen := valueof(t_L2Pseudolength(21)),
21 skip_indicator := 0,
22 rr_protocol_discriminator := 6,
23 message_type := '19'O
24 };
25 log("SI: ", dec_SystemInformation(si1));
26 log("SI: ", dec_SystemInformation(si2));
27 log("SI: ", dec_SystemInformation(si3));
28 log("SI: ", dec_SystemInformation(si4));
29 }
30
Harald Welteb622a3d2017-07-14 22:26:33 +020031 template GsmtapHeader t_GsmtapHeader := {
32 version := GSMTAP_VERSION,
33 hdr_len := 4,
34 msg_type := ?,
35 timeslot := ?,
36 arfcn := ?,
37 signal_dbm := ?,
38 snr_db := ?,
39 frame_number := ?,
40 sub_type := ?,
41 antenna_nr := ?,
42 sub_slot := ?,
43 res := ?
44 }
45
46 template GsmtapHeader t_GsmtapHeaderUm(template GsmtapChannel ch) modifies t_GsmtapHeader := {
47 msg_type := GSMTAP_TYPE_UM,
48 sub_type := ch
49 }
50
51
52 template GsmtapMessage t_bcch := {
53 header := t_GsmtapHeaderUm(GSMTAP_CHANNEL_BCCH),
54 payload := ?
55 }
56
57 template GSMTAP_RecvFrom t_recvfrom(template GsmtapChannel ch) := {
58 connId := ?,
59 remName := ?,
60 remPort := ?,
61 locName := ?,
62 locPort := GSMTAP_PORT,
63 proto := {udp:={}},
64 userData := ?,
65 msg := { header := t_GsmtapHeaderUm(ch), payload := ?}
66 }
67
68 testcase TC_gsmtap() runs on dummy_CT {
69 map(self:GSMTAP, system:GSMTAP);
70 IPL4_GSMTAP_CtrlFunct.f_IPL4_listen(GSMTAP, "0.0.0.0", GSMTAP_PORT, {udp := {}});
71
72 var GSMTAP_RecvFrom rf;
73 GSMTAP.receive(t_recvfrom(GSMTAP_CHANNEL_BCCH)) -> value rf;
74 log("UDP Rx:", rf);
75 log("SI: ", dec_SystemInformation(rf.msg.payload));
76 }
77
Harald Welte9a907b32017-07-15 10:34:27 +020078
79
80 /* permitted prompts on VTY */
81 const charstring NORMAL_PROMPT := "OpenBSC> ";
82 const charstring ENABLE_PROMPT := "OpenBSC# ";
83 const charstring CONFIG_PROMPT := "OpenBSC(*)\#";
84
85 const ASP_TelnetDynamicConfig vty_prompt[3] := {
86 {
87 prompt := {
88 id := 1,
89 prompt := NORMAL_PROMPT,
90 has_wildcards := false
91 }
92 }, {
93 prompt := {
94 id := 2,
95 prompt := ENABLE_PROMPT,
96 has_wildcards := false
97 }
98 }, {
99 prompt := {
100 id := 3,
101 prompt := CONFIG_PROMPT,
102 has_wildcards := true
103 }
104 }
105 };
106
107 /* configure prompts in TELNETasp module */
108 function f_vty_set_prompts(TELNETasp_PT pt) {
109 /* set some configuration that isn't possible to express
110 * in the config file due to syntactic restrictions (Who invents config
111 * files that don't permit regular expressions? */
112 for (var integer i := 0; i < sizeof(vty_prompt); i:= i + 1) {
113 pt.send(vty_prompt[i])
114 }
115 }
116
117 /* wait for any of the permitted prompts; buffer + return all intermediate output */
118 function f_vty_wait_for_prompt(TELNETasp_PT pt) return charstring {
119 template charstring config_pattern := pattern CONFIG_PROMPT;
120 var charstring rx, buf := "";
121 timer T := 2.0;
122
123 T.start;
124 alt {
125 [] pt.receive(NORMAL_PROMPT) { };
126 [] pt.receive(ENABLE_PROMPT) { };
127 [] pt.receive(config_pattern) { };
128 [] pt.receive(charstring:?) -> value rx { buf := buf & rx; repeat };
129 [] T.timeout { setverdict(fail); return ""};
130 }
131 T.stop;
132 return buf;
133 }
134
135 /* send a VTY command and obtain response until prompt is received */
136 function f_vty_transceive(TELNETasp_PT pt, charstring tx) return charstring {
137 pt.send(tx);
138 return f_vty_wait_for_prompt(pt);
139 }
140
141 /* enter the'confiugration' mode of the VTY */
142 function f_vty_enter_config(TELNETasp_PT pt) {
143 f_vty_transceive(pt, "enable");
144 f_vty_transceive(pt, "configure terminal")
145 }
146
147 testcase TC_telnet() runs on dummy_CT {
148
149 map(self:BSCVTY, system:BSCVTY);
150 f_vty_set_prompts(BSCVTY)
151
152 f_vty_transceive(BSCVTY, "show network")
153 f_vty_enter_config(BSCVTY)
154 f_vty_transceive(BSCVTY, "network")
155 f_vty_transceive(BSCVTY, "bts 0")
156 }
157
Harald Welte56db5fd2017-07-14 18:25:59 +0200158 control {
159 execute(TC_si1());
Harald Welteb622a3d2017-07-14 22:26:33 +0200160 execute(TC_gsmtap());
Harald Welte9a907b32017-07-15 10:34:27 +0200161 execute(TC_telnet());
Harald Welte56db5fd2017-07-14 18:25:59 +0200162 }
163}