blob: 9ea988d624a57bee71a66a57e7287bc01b7f7090 [file] [log] [blame]
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001#!/usr/bin/env python
2
3# (C) 2013 by Katerina Barone-Adesi <kat.obsc@gmail.com>
4# (C) 2013 by Holger Hans Peter Freyther
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18import os
19import time
20import unittest
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +020021import socket
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +020022
23import osmopy.obscvty as obscvty
24import osmopy.osmoutil as osmoutil
25
26confpath = '.'
27
28class TestVTYBase(unittest.TestCase):
29
30 def vty_command(self):
31 raise Exception("Needs to be implemented by a subclass")
32
33 def vty_app(self):
34 raise Exception("Needs to be implemented by a subclass")
35
36 def setUp(self):
37 osmo_vty_cmd = self.vty_command()[:]
38 config_index = osmo_vty_cmd.index('-c')
39 if config_index:
40 cfi = config_index + 1
41 osmo_vty_cmd[cfi] = os.path.join(confpath, osmo_vty_cmd[cfi])
42
43 try:
44 print "Launch: %s from %s" % (' '.join(osmo_vty_cmd), os.getcwd())
45 self.proc = osmoutil.popen_devnull(osmo_vty_cmd)
46 except OSError:
47 print >> sys.stderr, "Current directory: %s" % os.getcwd()
48 print >> sys.stderr, "Consider setting -b"
49 time.sleep(1)
50
51 appstring = self.vty_app()[2]
52 appport = self.vty_app()[0]
53 self.vty = obscvty.VTYInteract(appstring, "127.0.0.1", appport)
54
55 def tearDown(self):
56 self.vty = None
57 osmoutil.end_proc(self.proc)
58
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +020059class TestVTYMGCP(TestVTYBase):
60 def vty_command(self):
61 return ["./src/osmo-bsc_mgcp/osmo-bsc_mgcp", "-c",
62 "doc/examples/osmo-bsc_mgcp/mgcp.cfg"]
63
64 def vty_app(self):
65 return (4243, "./src/osmo-bsc_mgcp/osmo-bsc_mgcp", "OpenBSC MGCP", "mgcp")
66
67 def testForcePtime(self):
68 self.vty.enable()
69 res = self.vty.command("show running-config")
70 self.assert_(res.find(' rtp force-ptime 20\r') > 0)
71 self.assertEquals(res.find(' no rtp force-ptime\r'), -1)
72
73 self.vty.command("configure terminal")
74 self.vty.command("mgcp")
75 self.vty.command("no rtp force-ptime")
76 res = self.vty.command("show running-config")
77 self.assertEquals(res.find(' rtp force-ptime 20\r'), -1)
78 self.assertEquals(res.find(' no rtp force-ptime\r'), -1)
79
Holger Hans Peter Freyther619b0142014-11-19 16:04:45 +010080 def testOmitAudio(self):
81 self.vty.enable()
82 res = self.vty.command("show running-config")
83 self.assert_(res.find(' sdp audio-payload send-name\r') > 0)
84 self.assertEquals(res.find(' no sdp audio-payload send-name\r'), -1)
85
86 self.vty.command("configure terminal")
87 self.vty.command("mgcp")
88 self.vty.command("no sdp audio-payload send-name")
89 res = self.vty.command("show running-config")
90 self.assertEquals(res.find(' rtp sdp audio-payload send-name\r'), -1)
91 self.assert_(res.find(' no sdp audio-payload send-name\r') > 0)
92
93 # TODO: test it for the trunk!
94
Holger Hans Peter Freytherc390ae82015-08-20 15:15:50 +020095 def testBindAddr(self):
96 self.vty.enable()
97
98 self.vty.command("configure terminal")
99 self.vty.command("mgcp")
100
101 # enable.. disable bts-bind-ip
102 self.vty.command("rtp bts-bind-ip 254.253.252.250")
103 res = self.vty.command("show running-config")
104 self.assert_(res.find('rtp bts-bind-ip 254.253.252.250') > 0)
105 self.vty.command("no rtp bts-bind-ip")
106 res = self.vty.command("show running-config")
107 self.assertEquals(res.find(' rtp bts-bind-ip'), -1)
108
109 # enable.. disable net-bind-ip
110 self.vty.command("rtp net-bind-ip 254.253.252.250")
111 res = self.vty.command("show running-config")
112 self.assert_(res.find('rtp net-bind-ip 254.253.252.250') > 0)
113 self.vty.command("no rtp net-bind-ip")
114 res = self.vty.command("show running-config")
115 self.assertEquals(res.find(' rtp net-bind-ip'), -1)
116
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200117
118class TestVTYGenericBSC(TestVTYBase):
119
120 def checkForEndAndExit(self):
121 res = self.vty.command("list")
122 #print ('looking for "exit"\n')
123 self.assert_(res.find(' exit\r') > 0)
124 #print 'found "exit"\nlooking for "end"\n'
125 self.assert_(res.find(' end\r') > 0)
126 #print 'found "end"\n'
127
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200128 def _testConfigNetworkTree(self):
129 self.vty.enable()
130 self.assertTrue(self.vty.verify("configure terminal",['']))
131 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100132 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200133 self.assertTrue(self.vty.verify("network",['']))
134 self.assertEquals(self.vty.node(), 'config-net')
135 self.checkForEndAndExit()
136 self.assertTrue(self.vty.verify("bts 0",['']))
137 self.assertEquals(self.vty.node(), 'config-net-bts')
138 self.checkForEndAndExit()
139 self.assertTrue(self.vty.verify("trx 0",['']))
140 self.assertEquals(self.vty.node(), 'config-net-bts-trx')
141 self.checkForEndAndExit()
Jacob Erlbeck733bec82013-09-11 10:46:56 +0200142 self.vty.command("write terminal")
143 self.assertTrue(self.vty.verify("exit",['']))
144 self.assertEquals(self.vty.node(), 'config-net-bts')
145 self.assertTrue(self.vty.verify("exit",['']))
146 self.assertTrue(self.vty.verify("bts 1",['']))
147 self.assertEquals(self.vty.node(), 'config-net-bts')
148 self.checkForEndAndExit()
149 self.assertTrue(self.vty.verify("trx 1",['']))
150 self.assertEquals(self.vty.node(), 'config-net-bts-trx')
151 self.checkForEndAndExit()
152 self.vty.command("write terminal")
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200153 self.assertTrue(self.vty.verify("exit",['']))
154 self.assertEquals(self.vty.node(), 'config-net-bts')
155 self.assertTrue(self.vty.verify("exit",['']))
156 self.assertEquals(self.vty.node(), 'config-net')
157 self.assertTrue(self.vty.verify("exit",['']))
158 self.assertEquals(self.vty.node(), 'config')
159 self.assertTrue(self.vty.verify("exit",['']))
160 self.assertTrue(self.vty.node() is None)
161
162class TestVTYNITB(TestVTYGenericBSC):
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200163
164 def vty_command(self):
165 return ["./src/osmo-nitb/osmo-nitb", "-c",
166 "doc/examples/osmo-nitb/nanobts/openbsc.cfg"]
167
168 def vty_app(self):
169 return (4242, "./src/osmo-nitb/osmo-nitb", "OpenBSC", "nitb")
170
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200171 def testConfigNetworkTree(self):
Jacob Erlbeck75877272013-10-23 11:24:14 +0200172 self._testConfigNetworkTree()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200173
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200174 def checkForSmpp(self):
175 """SMPP is not always enabled, check if it is"""
176 res = self.vty.command("list")
177 return "smpp" in res
178
Holger Hans Peter Freyther42cf2e02015-07-06 16:41:30 +0200179 def testSmppFirst(self):
Holger Hans Peter Freyther42cf2e02015-07-06 16:41:30 +0200180 # enable the configuration
181 self.vty.enable()
182 self.vty.command("configure terminal")
Holger Hans Peter Freythera2c41c42015-07-13 11:23:53 +0200183
184 if not self.checkForSmpp():
185 return
186
Holger Hans Peter Freyther42cf2e02015-07-06 16:41:30 +0200187 self.vty.command("smpp")
188
189 # check the default
190 res = self.vty.command("write terminal")
191 self.assert_(res.find(' no smpp-first') > 0)
192
193 self.vty.verify("smpp-first", [''])
194 res = self.vty.command("write terminal")
195 self.assert_(res.find(' smpp-first') > 0)
196 self.assertEquals(res.find('no smpp-first'), -1)
197
198 self.vty.verify("no smpp-first", [''])
199 res = self.vty.command("write terminal")
200 self.assert_(res.find('no smpp-first') > 0)
201
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200202 def testVtyTree(self):
203 self.vty.enable()
204 self.assertTrue(self.vty.verify("configure terminal", ['']))
205 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100206 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200207 self.assertTrue(self.vty.verify('mncc-int', ['']))
208 self.assertEquals(self.vty.node(), 'config-mncc-int')
209 self.checkForEndAndExit()
210 self.assertTrue(self.vty.verify('exit', ['']))
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200211
212 if self.checkForSmpp():
213 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck75877272013-10-23 11:24:14 +0200214 self.assertTrue(self.vty.verify('smpp', ['']))
215 self.assertEquals(self.vty.node(), 'config-smpp')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100216 self.checkForEndAndExit()
Jacob Erlbeck75877272013-10-23 11:24:14 +0200217 self.assertTrue(self.vty.verify("exit", ['']))
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200218
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200219 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200220 self.assertTrue(self.vty.verify("exit", ['']))
221 self.assertTrue(self.vty.node() is None)
222
223 # Check searching for outer node's commands
224 self.vty.command("configure terminal")
225 self.vty.command('mncc-int')
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200226
227 if self.checkForSmpp():
228 self.vty.command('smpp')
229 self.assertEquals(self.vty.node(), 'config-smpp')
230 self.vty.command('mncc-int')
231
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200232 self.assertEquals(self.vty.node(), 'config-mncc-int')
233
Maxddee01f2016-05-24 14:23:27 +0200234 def testVtyAuthorization(self):
235 self.vty.enable()
236 self.vty.command("configure terminal")
237 self.vty.command("network")
238 self.assertTrue(self.vty.verify("auth policy closed", ['']))
239 self.assertTrue(self.vty.verify("auth policy regexp", ['']))
240 self.assertTrue(self.vty.verify("authorized-regexp ^001", ['']))
241 self.assertTrue(self.vty.verify("authorized-regexp 02$", ['']))
242 self.assertTrue(self.vty.verify("authorized-regexp *123.*", ['']))
243 self.vty.command("end")
244 self.vty.command("configure terminal")
245 self.vty.command("nitb")
246 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
247 self.assertTrue(self.vty.verify("subscriber-create-on-demand regexp", ['']))
248 self.vty.command("end")
249
Max0c1bc262016-04-20 12:06:06 +0200250 def testSi2Q(self):
251 self.vty.enable()
252 self.vty.command("configure terminal")
253 self.vty.command("network")
254 self.vty.command("bts 0")
255 before = self.vty.command("show running-config")
256 self.vty.command("si2quater neighbor-list add earfcn 1911 threshold 11 2")
257 self.vty.command("si2quater neighbor-list add earfcn 1924 threshold 11 3")
258 self.vty.command("si2quater neighbor-list add earfcn 2111 threshold 11")
259 self.vty.command("si2quater neighbor-list del earfcn 1911")
260 self.vty.command("si2quater neighbor-list del earfcn 1924")
261 self.vty.command("si2quater neighbor-list del earfcn 2111")
262 self.assertEquals(before, self.vty.command("show running-config"))
Max26679e02016-04-20 15:57:13 +0200263 self.vty.command("si2quater neighbor-list add uarfcn 1976 13 1")
264 self.vty.command("si2quater neighbor-list add uarfcn 1976 38 1")
265 self.vty.command("si2quater neighbor-list add uarfcn 1976 44 1")
266 self.vty.command("si2quater neighbor-list add uarfcn 1976 120 1")
267 self.vty.command("si2quater neighbor-list add uarfcn 1976 140 1")
268 self.vty.command("si2quater neighbor-list add uarfcn 1976 163 1")
269 self.vty.command("si2quater neighbor-list add uarfcn 1976 166 1")
270 self.vty.command("si2quater neighbor-list add uarfcn 1976 217 1")
271 self.vty.command("si2quater neighbor-list add uarfcn 1976 224 1")
272 self.vty.command("si2quater neighbor-list add uarfcn 1976 225 1")
273 self.vty.command("si2quater neighbor-list add uarfcn 1976 226 1")
274 self.vty.command("si2quater neighbor-list del uarfcn 1976 13")
275 self.vty.command("si2quater neighbor-list del uarfcn 1976 38")
276 self.vty.command("si2quater neighbor-list del uarfcn 1976 44")
277 self.vty.command("si2quater neighbor-list del uarfcn 1976 120")
278 self.vty.command("si2quater neighbor-list del uarfcn 1976 140")
279 self.vty.command("si2quater neighbor-list del uarfcn 1976 163")
280 self.vty.command("si2quater neighbor-list del uarfcn 1976 166")
281 self.vty.command("si2quater neighbor-list del uarfcn 1976 217")
282 self.vty.command("si2quater neighbor-list del uarfcn 1976 224")
283 self.vty.command("si2quater neighbor-list del uarfcn 1976 225")
284 self.vty.command("si2quater neighbor-list del uarfcn 1976 226")
285 self.assertEquals(before, self.vty.command("show running-config"))
Max0c1bc262016-04-20 12:06:06 +0200286
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200287 def testEnableDisablePeriodicLU(self):
288 self.vty.enable()
289 self.vty.command("configure terminal")
290 self.vty.command("network")
291 self.vty.command("bts 0")
292
293 # Test invalid input
294 self.vty.verify("periodic location update 0", ['% Unknown command.'])
295 self.vty.verify("periodic location update 5", ['% Unknown command.'])
296 self.vty.verify("periodic location update 1531", ['% Unknown command.'])
297
298 # Enable periodic lu..
299 self.vty.verify("periodic location update 60", [''])
300 res = self.vty.command("write terminal")
Holger Hans Peter Freytherc0438e32013-07-27 22:23:25 +0200301 self.assert_(res.find('periodic location update 60') > 0)
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200302 self.assertEquals(res.find('no periodic location update'), -1)
303
304 # Now disable it..
305 self.vty.verify("no periodic location update", [''])
306 res = self.vty.command("write terminal")
307 self.assertEquals(res.find('periodic location update 60'), -1)
Holger Hans Peter Freytherc0438e32013-07-27 22:23:25 +0200308 self.assert_(res.find('no periodic location update') > 0)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200309
Jacob Erlbeck65d114f2014-01-16 11:02:14 +0100310 def testEnableDisableSiHacks(self):
311 self.vty.enable()
312 self.vty.command("configure terminal")
313 self.vty.command("network")
314 self.vty.command("bts 0")
315
316 # Enable periodic lu..
317 self.vty.verify("force-combined-si", [''])
318 res = self.vty.command("write terminal")
319 self.assert_(res.find(' force-combined-si') > 0)
320 self.assertEquals(res.find('no force-combined-si'), -1)
321
322 # Now disable it..
323 self.vty.verify("no force-combined-si", [''])
324 res = self.vty.command("write terminal")
325 self.assertEquals(res.find(' force-combined-si'), -1)
326 self.assert_(res.find('no force-combined-si') > 0)
327
Ivan Kluchnikov67920592013-09-16 13:13:04 +0400328 def testRachAccessControlClass(self):
329 self.vty.enable()
330 self.vty.command("configure terminal")
331 self.vty.command("network")
332 self.vty.command("bts 0")
333
334 # Test invalid input
335 self.vty.verify("rach access-control-class", ['% Command incomplete.'])
336 self.vty.verify("rach access-control-class 1", ['% Command incomplete.'])
337 self.vty.verify("rach access-control-class -1", ['% Unknown command.'])
338 self.vty.verify("rach access-control-class 10", ['% Unknown command.'])
339 self.vty.verify("rach access-control-class 16", ['% Unknown command.'])
340
341 # Barred rach access control classes
342 for classNum in range(16):
343 if classNum != 10:
344 self.vty.verify("rach access-control-class " + str(classNum) + " barred", [''])
345
346 # Verify settings
347 res = self.vty.command("write terminal")
348 for classNum in range(16):
349 if classNum != 10:
350 self.assert_(res.find("rach access-control-class " + str(classNum) + " barred") > 0)
351
352 # Allowed rach access control classes
353 for classNum in range(16):
354 if classNum != 10:
355 self.vty.verify("rach access-control-class " + str(classNum) + " allowed", [''])
356
357 # Verify settings
358 res = self.vty.command("write terminal")
359 for classNum in range(16):
360 if classNum != 10:
361 self.assertEquals(res.find("rach access-control-class " + str(classNum) + " barred"), -1)
362
Holger Hans Peter Freytherde392252016-04-01 19:44:00 +0200363 def testSubscriberCreateDeleteTwice(self):
364 """
365 OS#1657 indicates that there might be an issue creating the
366 same subscriber twice. This test will use the VTY command to
367 create a subscriber and then issue a second create command
368 with the same IMSI. The test passes if the VTY continues to
369 respond to VTY commands.
370 """
371 self.vty.enable()
372
373 imsi = "204300854013739"
374
375 # Initially we don't have this subscriber
376 self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi])
377
378 # Lets create one
379 res = self.vty.command('subscriber create imsi '+imsi)
380 self.assert_(res.find(" IMSI: "+imsi) > 0)
381 # And now create one again.
382 res2 = self.vty.command('subscriber create imsi '+imsi)
383 self.assert_(res2.find(" IMSI: "+imsi) > 0)
384 self.assertEqual(res, res2)
385
386 # Verify it has been created
387 res = self.vty.command('show subscriber imsi '+imsi)
388 self.assert_(res.find(" IMSI: "+imsi) > 0)
389
390 # Delete it
391 res = self.vty.command('subscriber delete imsi '+imsi)
392 self.assert_(res != "")
393
394 # Now it should not be there anymore
395 res = self.vty.command('show subscriber imsi '+imsi)
396 self.assert_(res != '% No subscriber found for imsi '+imsi)
397
398
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500399 def testSubscriberCreateDelete(self):
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200400 self.vty.enable()
401
402 imsi = "204300854013739"
403
404 # Initially we don't have this subscriber
405 self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi])
406
407 # Lets create one
408 res = self.vty.command('subscriber create imsi '+imsi)
409 self.assert_(res.find(" IMSI: "+imsi) > 0)
410
411 # Now we have it
412 res = self.vty.command('show subscriber imsi '+imsi)
413 self.assert_(res.find(" IMSI: "+imsi) > 0)
414
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500415 # Delete it
416 res = self.vty.command('subscriber delete imsi '+imsi)
417 self.assert_(res != "")
418
419 # Now it should not be there anymore
420 res = self.vty.command('show subscriber imsi '+imsi)
421 self.assert_(res != '% No subscriber found for imsi '+imsi)
422
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200423 def testSubscriberSettings(self):
424 self.vty.enable()
425
426 imsi = "204300854013739"
Max0fcd2e22016-06-07 15:32:16 +0200427 imsi2 = "204301824913769"
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200428 wrong_imsi = "204300999999999"
429
430 # Lets create one
431 res = self.vty.command('subscriber create imsi '+imsi)
432 self.assert_(res.find(" IMSI: "+imsi) > 0)
Max0fcd2e22016-06-07 15:32:16 +0200433 self.assert_(res.find("Extension") > 0)
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200434
435 self.vty.verify('subscriber imsi '+wrong_imsi+' name wrong', ['% No subscriber found for imsi '+wrong_imsi])
436 res = self.vty.command('subscriber imsi '+imsi+' name '+('X' * 160))
437 self.assert_(res.find("NAME is too long") > 0)
438
439 self.vty.verify('subscriber imsi '+imsi+' name '+('G' * 159), [''])
440
441 self.vty.verify('subscriber imsi '+wrong_imsi+' extension 840', ['% No subscriber found for imsi '+wrong_imsi])
442 res = self.vty.command('subscriber imsi '+imsi+' extension '+('9' * 15))
443 self.assert_(res.find("EXTENSION is too long") > 0)
444
445 self.vty.verify('subscriber imsi '+imsi+' extension '+('1' * 14), [''])
446
Max0fcd2e22016-06-07 15:32:16 +0200447 # With narrow random interval
448 self.vty.command("configure terminal")
449 self.vty.command("nitb")
450 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
451 # wrong interval
452 res = self.vty.command("subscriber-create-on-demand random 221 122")
453 self.assert_(res.find("122") > 0)
454 self.assert_(res.find("221") > 0)
455 # correct interval
456 self.assertTrue(self.vty.verify("subscriber-create-on-demand random 221 222", ['']))
457 self.vty.command("end")
458
459 res = self.vty.command('subscriber create imsi ' + imsi2)
460 self.assert_(res.find(" IMSI: " + imsi2) > 0)
461 self.assert_(res.find("221") > 0 or res.find("222") > 0)
462 self.assert_(res.find(" Extension: ") > 0)
463
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200464 # Delete it
465 res = self.vty.command('subscriber delete imsi '+imsi)
466 self.assert_(res != "")
Max0fcd2e22016-06-07 15:32:16 +0200467 res = self.vty.command('subscriber delete imsi ' + imsi2)
468 self.assert_(res != "")
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200469
Holger Hans Peter Freytherec37bb22013-02-05 09:39:09 +0100470 def testShowPagingGroup(self):
471 res = self.vty.command("show paging-group 255 1234567")
472 self.assertEqual(res, "% can't find BTS 255")
473 res = self.vty.command("show paging-group 0 1234567")
474 self.assertEquals(res, "%Paging group for IMSI 1234567 on BTS #0 is 7")
475
Ciabyec6e4f82014-03-06 17:20:55 +0100476 def testShowNetwork(self):
477 res = self.vty.command("show network")
478 self.assert_(res.startswith('BSC is on Country Code') >= 0)
479
Holger Hans Peter Freyther86573262015-01-31 09:47:37 +0100480 def testMeasurementFeed(self):
481 self.vty.enable()
482 self.vty.command("configure terminal")
483 self.vty.command("mncc-int")
484
485 res = self.vty.command("write terminal")
486 self.assertEquals(res.find('meas-feed scenario'), -1)
487
488 self.vty.command("meas-feed scenario bla")
489 res = self.vty.command("write terminal")
490 self.assert_(res.find('meas-feed scenario bla') > 0)
491
492 self.vty.command("meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890")
493 res = self.vty.command("write terminal")
494 self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890'), -1)
495 self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz012345'), -1)
496 self.assert_(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234') > 0)
497
498
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200499class TestVTYBSC(TestVTYGenericBSC):
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200500
501 def vty_command(self):
502 return ["./src/osmo-bsc/osmo-bsc", "-c",
503 "doc/examples/osmo-bsc/osmo-bsc.cfg"]
504
505 def vty_app(self):
506 return (4242, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc")
507
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200508 def testConfigNetworkTree(self):
Jacob Erlbeck75877272013-10-23 11:24:14 +0200509 self._testConfigNetworkTree()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200510
511 def testVtyTree(self):
512 self.vty.enable()
513 self.assertTrue(self.vty.verify("configure terminal", ['']))
514 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100515 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200516 self.assertTrue(self.vty.verify("msc 0", ['']))
517 self.assertEquals(self.vty.node(), 'config-msc')
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200518 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200519 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200520 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200521 self.assertTrue(self.vty.verify("bsc", ['']))
522 self.assertEquals(self.vty.node(), 'config-bsc')
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200523 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200524 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200525 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200526 self.assertTrue(self.vty.verify("exit", ['']))
527 self.assertTrue(self.vty.node() is None)
528
529 # Check searching for outer node's commands
530 self.vty.command("configure terminal")
531 self.vty.command('msc 0')
532 self.vty.command("bsc")
533 self.assertEquals(self.vty.node(), 'config-bsc')
534 self.vty.command("msc 0")
535 self.assertEquals(self.vty.node(), 'config-msc')
536
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200537 def testUssdNotificationsMsc(self):
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200538 self.vty.enable()
539 self.vty.command("configure terminal")
540 self.vty.command("msc")
541
542 # Test invalid input
543 self.vty.verify("bsc-msc-lost-text", ['% Command incomplete.'])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200544 self.vty.verify("bsc-welcome-text", ['% Command incomplete.'])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200545 self.vty.verify("bsc-grace-text", ['% Command incomplete.'])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200546
547 # Enable USSD notifications
548 self.vty.verify("bsc-msc-lost-text MSC disconnected", [''])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200549 self.vty.verify("bsc-welcome-text Hello MS", [''])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200550 self.vty.verify("bsc-grace-text In grace period", [''])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200551
552 # Verify settings
553 res = self.vty.command("write terminal")
554 self.assert_(res.find('bsc-msc-lost-text MSC disconnected') > 0)
555 self.assertEquals(res.find('no bsc-msc-lost-text'), -1)
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200556 self.assert_(res.find('bsc-welcome-text Hello MS') > 0)
557 self.assertEquals(res.find('no bsc-welcome-text'), -1)
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200558 self.assert_(res.find('bsc-grace-text In grace period') > 0)
559 self.assertEquals(res.find('no bsc-grace-text'), -1)
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200560
561 # Now disable it..
562 self.vty.verify("no bsc-msc-lost-text", [''])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200563 self.vty.verify("no bsc-welcome-text", [''])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200564 self.vty.verify("no bsc-grace-text", [''])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200565
566 # Verify settings
567 res = self.vty.command("write terminal")
568 self.assertEquals(res.find('bsc-msc-lost-text MSC disconnected'), -1)
569 self.assert_(res.find('no bsc-msc-lost-text') > 0)
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200570 self.assertEquals(res.find('bsc-welcome-text Hello MS'), -1)
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200571 self.assert_(res.find('no bsc-welcome-text') > 0)
572 self.assertEquals(res.find('bsc-grace-text In grace period'), -1)
573 self.assert_(res.find('no bsc-grace-text') > 0)
574
575 def testUssdNotificationsBsc(self):
576 self.vty.enable()
577 self.vty.command("configure terminal")
578 self.vty.command("bsc")
579
580 # Test invalid input
581 self.vty.verify("missing-msc-text", ['% Command incomplete.'])
582
583 # Enable USSD notifications
584 self.vty.verify("missing-msc-text No MSC found", [''])
585
586 # Verify settings
587 res = self.vty.command("write terminal")
588 self.assert_(res.find('missing-msc-text No MSC found') > 0)
589 self.assertEquals(res.find('no missing-msc-text'), -1)
590
591 # Now disable it..
592 self.vty.verify("no missing-msc-text", [''])
593
594 # Verify settings
595 res = self.vty.command("write terminal")
596 self.assertEquals(res.find('missing-msc-text No MSC found'), -1)
597 self.assert_(res.find('no missing-msc-text') > 0)
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200598
Jacob Erlbeck946d1412013-09-17 13:59:29 +0200599 def testNetworkTimezone(self):
600 self.vty.enable()
601 self.vty.verify("configure terminal", [''])
602 self.vty.verify("network", [''])
603 self.vty.verify("bts 0", [''])
604
605 # Test invalid input
606 self.vty.verify("timezone", ['% Command incomplete.'])
607 self.vty.verify("timezone 20 0", ['% Unknown command.'])
608 self.vty.verify("timezone 0 11", ['% Unknown command.'])
609 self.vty.verify("timezone 0 0 99", ['% Unknown command.'])
610
611 # Set time zone without DST
612 self.vty.verify("timezone 2 30", [''])
613
614 # Verify settings
615 res = self.vty.command("write terminal")
616 self.assert_(res.find('timezone 2 30') > 0)
617 self.assertEquals(res.find('timezone 2 30 '), -1)
618
619 # Set time zone with DST
620 self.vty.verify("timezone 2 30 1", [''])
621
622 # Verify settings
623 res = self.vty.command("write terminal")
624 self.assert_(res.find('timezone 2 30 1') > 0)
625
626 # Now disable it..
627 self.vty.verify("no timezone", [''])
628
629 # Verify settings
630 res = self.vty.command("write terminal")
631 self.assertEquals(res.find(' timezone'), -1)
632
Ciabyec6e4f82014-03-06 17:20:55 +0100633 def testShowNetwork(self):
634 res = self.vty.command("show network")
635 self.assert_(res.startswith('BSC is on Country Code') >= 0)
636
Holger Hans Peter Freytherdb64f2e2014-10-29 10:06:15 +0100637 def testPingPongConfiguration(self):
638 self.vty.enable()
639 self.vty.verify("configure terminal", [''])
640 self.vty.verify("network", [''])
641 self.vty.verify("msc 0", [''])
642
643 self.vty.verify("timeout-ping 12", [''])
644 self.vty.verify("timeout-pong 14", [''])
645 res = self.vty.command("show running-config")
646 self.assert_(res.find(" timeout-ping 12") > 0)
647 self.assert_(res.find(" timeout-pong 14") > 0)
648 self.assert_(res.find(" no timeout-ping advanced") > 0)
649
650 self.vty.verify("timeout-ping advanced", [''])
651 res = self.vty.command("show running-config")
652 self.assert_(res.find(" timeout-ping 12") > 0)
653 self.assert_(res.find(" timeout-pong 14") > 0)
654 self.assert_(res.find(" timeout-ping advanced") > 0)
655
656 self.vty.verify("no timeout-ping advanced", [''])
657 res = self.vty.command("show running-config")
658 self.assert_(res.find(" timeout-ping 12") > 0)
659 self.assert_(res.find(" timeout-pong 14") > 0)
660 self.assert_(res.find(" no timeout-ping advanced") > 0)
661
662 self.vty.verify("no timeout-ping", [''])
663 res = self.vty.command("show running-config")
664 self.assertEquals(res.find(" timeout-ping 12"), -1)
665 self.assertEquals(res.find(" timeout-pong 14"), -1)
666 self.assertEquals(res.find(" no timeout-ping advanced"), -1)
667 self.assert_(res.find(" no timeout-ping") > 0)
668
669 self.vty.verify("timeout-ping advanced", ['%ping handling is disabled. Enable it first.'])
670
671 # And back to enabling it
672 self.vty.verify("timeout-ping 12", [''])
673 self.vty.verify("timeout-pong 14", [''])
674 res = self.vty.command("show running-config")
675 self.assert_(res.find(" timeout-ping 12") > 0)
676 self.assert_(res.find(" timeout-pong 14") > 0)
677 self.assert_(res.find(" timeout-ping advanced") > 0)
678
Holger Hans Peter Freyther32dd2f32015-04-01 18:15:48 +0200679 def testMscDataCoreLACCI(self):
680 self.vty.enable()
681 res = self.vty.command("show running-config")
682 self.assertEquals(res.find("core-location-area-code"), -1)
683 self.assertEquals(res.find("core-cell-identity"), -1)
684
685 self.vty.command("configure terminal")
686 self.vty.command("msc 0")
687 self.vty.command("core-location-area-code 666")
688 self.vty.command("core-cell-identity 333")
689
690 res = self.vty.command("show running-config")
691 self.assert_(res.find("core-location-area-code 666") > 0)
692 self.assert_(res.find("core-cell-identity 333") > 0)
693
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200694class TestVTYNAT(TestVTYGenericBSC):
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200695
696 def vty_command(self):
Max49364482016-04-13 11:36:39 +0200697 return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-l", "127.0.0.1", "-c",
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200698 "doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"]
699
700 def vty_app(self):
701 return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat")
702
Max49364482016-04-13 11:36:39 +0200703 def testBSCreload(self):
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -0400704 # Use different port for the mock msc to avoid clashing with
705 # the osmo-bsc_nat itself
Holger Hans Peter Freytherf1a61bb2016-04-14 08:50:25 -0400706 ip = "127.0.0.1"
Holger Hans Peter Freythere98c9c72016-04-14 10:58:58 -0400707 port = 5522
Max49364482016-04-13 11:36:39 +0200708 self.vty.enable()
709 bscs1 = self.vty.command("show bscs-config")
710 nat_bsc_reload(self)
711 bscs2 = self.vty.command("show bscs-config")
712 # check that multiple calls to bscs-config-file give the same result
713 self.assertEquals(bscs1, bscs2)
714
715 # add new bsc
716 self.vty.command("configure terminal")
717 self.vty.command("nat")
718 self.vty.command("bsc 5")
719 self.vty.command("token key")
720 self.vty.command("location_area_code 666")
721 self.vty.command("end")
722
723 # update bsc token
724 self.vty.command("configure terminal")
725 self.vty.command("nat")
726 self.vty.command("bsc 1")
727 self.vty.command("token xyu")
728 self.vty.command("end")
729
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -0400730 nat_msc_ip(self, ip, port)
731 msc = nat_msc_test(self, ip, port)
Max49364482016-04-13 11:36:39 +0200732 b0 = nat_bsc_sock_test(0, "lol")
733 b1 = nat_bsc_sock_test(1, "xyu")
734 b2 = nat_bsc_sock_test(5, "key")
735
736 self.assertEquals("3 BSCs configured", self.vty.command("show nat num-bscs-configured"))
737 self.assertTrue(3 == nat_bsc_num_con(self))
738 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
739
740 nat_bsc_reload(self)
741 bscs2 = self.vty.command("show bscs-config")
742 # check that the reset to initial config succeeded
743 self.assertEquals(bscs1, bscs2)
744
745 self.assertEquals("2 BSCs configured", self.vty.command("show nat num-bscs-configured"))
746 self.assertTrue(1 == nat_bsc_num_con(self))
747 rem = self.vty.command("show bsc connections").split(' ')
748 # remaining connection is for BSC0
749 self.assertEquals('0', rem[2])
750 # remaining connection is authorized
751 self.assertEquals('1', rem[4])
752 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
753
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200754 def testVtyTree(self):
755 self.vty.enable()
756 self.assertTrue(self.vty.verify('configure terminal', ['']))
757 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100758 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200759 self.assertTrue(self.vty.verify('mgcp', ['']))
760 self.assertEquals(self.vty.node(), 'config-mgcp')
761 self.checkForEndAndExit()
762 self.assertTrue(self.vty.verify('exit', ['']))
763 self.assertEquals(self.vty.node(), 'config')
764 self.assertTrue(self.vty.verify('nat', ['']))
765 self.assertEquals(self.vty.node(), 'config-nat')
766 self.checkForEndAndExit()
767 self.assertTrue(self.vty.verify('bsc 0', ['']))
768 self.assertEquals(self.vty.node(), 'config-nat-bsc')
769 self.checkForEndAndExit()
770 self.assertTrue(self.vty.verify('exit', ['']))
771 self.assertEquals(self.vty.node(), 'config-nat')
772 self.assertTrue(self.vty.verify('exit', ['']))
773 self.assertEquals(self.vty.node(), 'config')
774 self.assertTrue(self.vty.verify('exit', ['']))
775 self.assertTrue(self.vty.node() is None)
776
777 # Check searching for outer node's commands
778 self.vty.command('configure terminal')
779 self.vty.command('mgcp')
780 self.vty.command('nat')
781 self.assertEquals(self.vty.node(), 'config-nat')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200782 self.vty.command('mgcp')
783 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200784 self.vty.command('nat')
785 self.assertEquals(self.vty.node(), 'config-nat')
786 self.vty.command('bsc 0')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200787 self.vty.command('mgcp')
788 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200789
Holger Hans Peter Freytherb718ad32013-06-25 09:08:02 +0200790 def testRewriteNoRewrite(self):
791 self.vty.enable()
792 res = self.vty.command("configure terminal")
793 res = self.vty.command("nat")
794 res = self.vty.command("number-rewrite rewrite.cfg")
795 res = self.vty.command("no number-rewrite")
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200796
Holger Hans Peter Freyther7f100c92015-04-23 20:25:17 -0400797 def testEnsureNoEnsureModeSet(self):
798 self.vty.enable()
799 res = self.vty.command("configure terminal")
800 res = self.vty.command("nat")
801
802 # Ensure the default
803 res = self.vty.command("show running-config")
804 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
805
806 self.vty.command("sdp-ensure-amr-mode-set")
807 res = self.vty.command("show running-config")
808 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
809
810 self.vty.command("no sdp-ensure-amr-mode-set")
811 res = self.vty.command("show running-config")
812 self.assert_(res.find('\n no sdp-ensure-amr-mode-set') > 0)
813
Holger Hans Peter Freyther67e423c2013-06-25 15:38:31 +0200814 def testRewritePostNoRewrite(self):
815 self.vty.enable()
816 self.vty.command("configure terminal")
817 self.vty.command("nat")
818 self.vty.verify("number-rewrite-post rewrite.cfg", [''])
819 self.vty.verify("no number-rewrite-post", [''])
820
821
Holger Hans Peter Freytherddf191e2013-06-25 11:44:01 +0200822 def testPrefixTreeLoading(self):
823 cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv")
824
825 self.vty.enable()
826 self.vty.command("configure terminal")
827 self.vty.command("nat")
828 res = self.vty.command("prefix-tree %s" % cfg)
829 self.assertEqual(res, "% prefix-tree loaded 17 rules.")
830 self.vty.command("end")
831
832 res = self.vty.command("show prefix-tree")
833 self.assertEqual(res, '1,1\r\n12,2\r\n123,3\r\n1234,4\r\n12345,5\r\n123456,6\r\n1234567,7\r\n12345678,8\r\n123456789,9\r\n1234567890,10\r\n13,11\r\n14,12\r\n15,13\r\n16,14\r\n82,16\r\n823455,15\r\n+49123,17')
834
835 self.vty.command("configure terminal")
836 self.vty.command("nat")
837 self.vty.command("no prefix-tree")
838 self.vty.command("end")
839
840 res = self.vty.command("show prefix-tree")
841 self.assertEqual(res, "% there is now prefix tree loaded.")
842
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200843 def testUssdSideChannelProvider(self):
844 self.vty.command("end")
845 self.vty.enable()
846 self.vty.command("configure terminal")
847 self.vty.command("nat")
848 self.vty.command("ussd-token key")
849 self.vty.command("end")
850
851 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
852 self.assertTrue(res)
853
854 ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
855 ussdSocket.connect(('127.0.0.1', 5001))
856 ussdSocket.settimeout(2.0)
857 print "Connected to %s:%d" % ussdSocket.getpeername()
858
859 print "Expecting ID_GET request"
860 data = ussdSocket.recv(4)
861 self.assertEqual(data, "\x00\x01\xfe\x04")
862
863 print "Going to send ID_RESP response"
Max70cf7292016-04-13 11:36:38 +0200864 res = ipa_send_resp(ussdSocket, "\x6b\x65\x79")
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200865 self.assertEqual(res, 10)
866
867 # initiating PING/PONG cycle to know, that the ID_RESP message has been processed
868
869 print "Going to send PING request"
Max70cf7292016-04-13 11:36:38 +0200870 res = ipa_send_ping(ussdSocket)
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200871 self.assertEqual(res, 4)
872
873 print "Expecting PONG response"
874 data = ussdSocket.recv(4)
875 self.assertEqual(data, "\x00\x01\xfe\x01")
876
877 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.'])
878 self.assertTrue(res)
879
880 print "Going to shut down connection"
881 ussdSocket.shutdown(socket.SHUT_WR)
882
883 print "Expecting EOF"
884 data = ussdSocket.recv(4)
885 self.assertEqual(data, "")
886
887 ussdSocket.close()
888
889 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
890 self.assertTrue(res)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200891
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100892 def testAccessList(self):
893 """
894 Verify that the imsi-deny can have a reject cause or no reject cause
895 """
896 self.vty.enable()
897 self.vty.command("configure terminal")
898 self.vty.command("nat")
899
900 # Old default
901 self.vty.command("access-list test-default imsi-deny ^123[0-9]*$")
902 res = self.vty.command("show running-config").split("\r\n")
903 asserted = False
904 for line in res:
Holger Hans Peter Freyther4ecc6872014-03-04 15:38:00 +0100905 if line.startswith(" access-list test-default"):
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100906 self.assertEqual(line, " access-list test-default imsi-deny ^123[0-9]*$ 11 11")
907 asserted = True
908 self.assert_(asserted)
909
910 # Check the optional CM Service Reject Cause
911 self.vty.command("access-list test-cm-deny imsi-deny ^123[0-9]*$ 42").split("\r\n")
912 res = self.vty.command("show running-config").split("\r\n")
913 asserted = False
914 for line in res:
915 if line.startswith(" access-list test-cm"):
916 self.assertEqual(line, " access-list test-cm-deny imsi-deny ^123[0-9]*$ 42 11")
917 asserted = True
918 self.assert_(asserted)
919
920 # Check the optional LU Reject Cause
921 self.vty.command("access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42").split("\r\n")
922 res = self.vty.command("show running-config").split("\r\n")
923 asserted = False
924 for line in res:
925 if line.startswith(" access-list test-lu"):
926 self.assertEqual(line, " access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42")
927 asserted = True
928 self.assert_(asserted)
929
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200930class TestVTYGbproxy(TestVTYGenericBSC):
931
932 def vty_command(self):
933 return ["./src/gprs/osmo-gbproxy", "-c",
934 "doc/examples/osmo-gbproxy/osmo-gbproxy.cfg"]
935
936 def vty_app(self):
937 return (4246, "./src/gprs/osmo-gbproxy", "OsmoGbProxy", "bsc")
938
939 def testVtyTree(self):
940 self.vty.enable()
941 self.assertTrue(self.vty.verify('configure terminal', ['']))
942 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100943 self.checkForEndAndExit()
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200944 self.assertTrue(self.vty.verify('ns', ['']))
945 self.assertEquals(self.vty.node(), 'config-ns')
946 self.checkForEndAndExit()
947 self.assertTrue(self.vty.verify('exit', ['']))
948 self.assertEquals(self.vty.node(), 'config')
949 self.assertTrue(self.vty.verify('gbproxy', ['']))
950 self.assertEquals(self.vty.node(), 'config-gbproxy')
951 self.checkForEndAndExit()
952 self.assertTrue(self.vty.verify('exit', ['']))
953 self.assertEquals(self.vty.node(), 'config')
954
955 def testVtyShow(self):
956 res = self.vty.command("show ns")
957 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
958
959 res = self.vty.command("show gbproxy stats")
960 self.assert_(res.find('GBProxy Global Statistics') >= 0)
961
Jacob Erlbeck4211d792013-10-24 12:48:23 +0200962 def testVtyDeletePeer(self):
963 self.vty.enable()
964 self.assertTrue(self.vty.verify('delete-gbproxy-peer 9999 bvci 7777', ['BVC not found']))
965 res = self.vty.command("delete-gbproxy-peer 9999 all dry-run")
966 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
967 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
968 res = self.vty.command("delete-gbproxy-peer 9999 only-bvc dry-run")
969 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
970 self.assert_(res.find('Not Deleted 0 NS-VC') < 0)
971 res = self.vty.command("delete-gbproxy-peer 9999 only-nsvc dry-run")
972 self.assert_(res.find('Not Deleted 0 BVC') < 0)
973 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
974 res = self.vty.command("delete-gbproxy-peer 9999 all")
975 self.assert_(res.find('Deleted 0 BVC') >= 0)
976 self.assert_(res.find('Deleted 0 NS-VC') >= 0)
977
Jacob Erlbeck144b8b12014-11-04 11:15:01 +0100978class TestVTYSGSN(TestVTYGenericBSC):
979
980 def vty_command(self):
981 return ["./src/gprs/osmo-sgsn", "-c",
982 "doc/examples/osmo-sgsn/osmo-sgsn.cfg"]
983
984 def vty_app(self):
985 return (4245, "./src/gprs/osmo-sgsn", "OsmoSGSN", "sgsn")
986
987 def testVtyTree(self):
988 self.vty.enable()
989 self.assertTrue(self.vty.verify('configure terminal', ['']))
990 self.assertEquals(self.vty.node(), 'config')
991 self.checkForEndAndExit()
992 self.assertTrue(self.vty.verify('ns', ['']))
993 self.assertEquals(self.vty.node(), 'config-ns')
994 self.checkForEndAndExit()
995 self.assertTrue(self.vty.verify('exit', ['']))
996 self.assertEquals(self.vty.node(), 'config')
997 self.assertTrue(self.vty.verify('sgsn', ['']))
998 self.assertEquals(self.vty.node(), 'config-sgsn')
999 self.checkForEndAndExit()
1000 self.assertTrue(self.vty.verify('exit', ['']))
1001 self.assertEquals(self.vty.node(), 'config')
1002
1003 def testVtyShow(self):
1004 res = self.vty.command("show ns")
1005 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
1006 self.assertTrue(self.vty.verify('show bssgp', ['']))
1007 self.assertTrue(self.vty.verify('show bssgp stats', ['']))
1008 # TODO: uncomment when the command does not segfault anymore
1009 # self.assertTrue(self.vty.verify('show bssgp nsei 123', ['']))
1010 # self.assertTrue(self.vty.verify('show bssgp nsei 123 stats', ['']))
1011
1012 self.assertTrue(self.vty.verify('show sgsn', ['']))
1013 self.assertTrue(self.vty.verify('show mm-context all', ['']))
1014 self.assertTrue(self.vty.verify('show mm-context imsi 000001234567', ['No MM context for IMSI 000001234567']))
1015 self.assertTrue(self.vty.verify('show pdp-context all', ['']))
1016
1017 res = self.vty.command("show sndcp")
1018 self.assert_(res.find('State of SNDCP Entities') >= 0)
1019
1020 res = self.vty.command("show llc")
1021 self.assert_(res.find('State of LLC Entities') >= 0)
1022
Jacob Erlbeck106f5472014-11-04 10:08:37 +01001023 def testVtyAuth(self):
1024 self.vty.enable()
1025 self.assertTrue(self.vty.verify('configure terminal', ['']))
1026 self.assertEquals(self.vty.node(), 'config')
1027 self.assertTrue(self.vty.verify('sgsn', ['']))
1028 self.assertEquals(self.vty.node(), 'config-sgsn')
1029 self.assertTrue(self.vty.verify('auth-policy accept-all', ['']))
1030 res = self.vty.command("show running-config")
1031 self.assert_(res.find('auth-policy accept-all') > 0)
1032 self.assertTrue(self.vty.verify('auth-policy acl-only', ['']))
1033 res = self.vty.command("show running-config")
1034 self.assert_(res.find('auth-policy acl-only') > 0)
1035 self.assertTrue(self.vty.verify('auth-policy closed', ['']))
1036 res = self.vty.command("show running-config")
1037 self.assert_(res.find('auth-policy closed') > 0)
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +01001038 self.assertTrue(self.vty.verify('auth-policy remote', ['']))
1039 res = self.vty.command("show running-config")
1040 self.assert_(res.find('auth-policy remote') > 0)
Jacob Erlbeck106f5472014-11-04 10:08:37 +01001041
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001042 def testVtySubscriber(self):
1043 self.vty.enable()
1044 res = self.vty.command('show subscriber cache')
1045 self.assert_(res.find('1234567890') < 0)
Jacob Erlbeckd9193432015-01-19 14:11:46 +01001046 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 create', ['']))
1047 res = self.vty.command('show subscriber cache')
1048 self.assert_(res.find('1234567890') >= 0)
1049 self.assert_(res.find('Authorized: 0') >= 0)
1050 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 update-location-result ok', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001051 res = self.vty.command('show subscriber cache')
1052 self.assert_(res.find('1234567890') >= 0)
1053 self.assert_(res.find('Authorized: 1') >= 0)
Jacob Erlbeck8000e0e2015-01-27 14:56:40 +01001054 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 cancel update-procedure', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001055 res = self.vty.command('show subscriber cache')
Jacob Erlbecke988ae42015-01-27 12:41:19 +01001056 self.assert_(res.find('1234567890') >= 0)
1057 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 destroy', ['']))
1058 res = self.vty.command('show subscriber cache')
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001059 self.assert_(res.find('1234567890') < 0)
1060
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +01001061 def testVtyGgsn(self):
1062 self.vty.enable()
1063 self.assertTrue(self.vty.verify('configure terminal', ['']))
1064 self.assertEquals(self.vty.node(), 'config')
1065 self.assertTrue(self.vty.verify('sgsn', ['']))
1066 self.assertEquals(self.vty.node(), 'config-sgsn')
1067 self.assertTrue(self.vty.verify('ggsn 0 remote-ip 127.99.99.99', ['']))
1068 self.assertTrue(self.vty.verify('ggsn 0 gtp-version 1', ['']))
1069 self.assertTrue(self.vty.verify('apn * ggsn 0', ['']))
1070 self.assertTrue(self.vty.verify('apn apn1.test ggsn 0', ['']))
1071 self.assertTrue(self.vty.verify('apn apn1.test ggsn 1', ['% a GGSN with id 1 has not been defined']))
1072 self.assertTrue(self.vty.verify('apn apn1.test imsi-prefix 123456 ggsn 0', ['']))
1073 self.assertTrue(self.vty.verify('apn apn2.test imsi-prefix 123456 ggsn 0', ['']))
1074 res = self.vty.command("show running-config")
1075 self.assert_(res.find('ggsn 0 remote-ip 127.99.99.99') >= 0)
1076 self.assert_(res.find('ggsn 0 gtp-version 1') >= 0)
1077 self.assert_(res.find('apn * ggsn 0') >= 0)
1078 self.assert_(res.find('apn apn1.test ggsn 0') >= 0)
1079 self.assert_(res.find('apn apn1.test imsi-prefix 123456 ggsn 0') >= 0)
1080 self.assert_(res.find('apn apn2.test imsi-prefix 123456 ggsn 0') >= 0)
1081
Holger Hans Peter Freyther9c20a5f2015-02-06 16:23:29 +01001082 def testVtyEasyAPN(self):
1083 self.vty.enable()
1084 self.assertTrue(self.vty.verify('configure terminal', ['']))
1085 self.assertEquals(self.vty.node(), 'config')
1086 self.assertTrue(self.vty.verify('sgsn', ['']))
1087 self.assertEquals(self.vty.node(), 'config-sgsn')
1088
1089 res = self.vty.command("show running-config")
1090 self.assertEquals(res.find("apn internet"), -1)
1091
1092 self.assertTrue(self.vty.verify("access-point-name internet.apn", ['']))
1093 res = self.vty.command("show running-config")
1094 self.assert_(res.find("apn internet.apn ggsn 0") >= 0)
1095
1096 self.assertTrue(self.vty.verify("no access-point-name internet.apn", ['']))
1097 res = self.vty.command("show running-config")
1098 self.assertEquals(res.find("apn internet"), -1)
1099
Holger Hans Peter Freytherc15c61c2015-05-06 17:46:08 +02001100 def testVtyCDR(self):
1101 self.vty.enable()
1102 self.assertTrue(self.vty.verify('configure terminal', ['']))
1103 self.assertEquals(self.vty.node(), 'config')
1104 self.assertTrue(self.vty.verify('sgsn', ['']))
1105 self.assertEquals(self.vty.node(), 'config-sgsn')
1106
1107 res = self.vty.command("show running-config")
1108 self.assert_(res.find("no cdr filename") > 0)
1109
1110 self.vty.command("cdr filename bla.cdr")
1111 res = self.vty.command("show running-config")
1112 self.assertEquals(res.find("no cdr filename"), -1)
1113 self.assert_(res.find(" cdr filename bla.cdr") > 0)
1114
1115 self.vty.command("no cdr filename")
1116 res = self.vty.command("show running-config")
1117 self.assert_(res.find("no cdr filename") > 0)
1118 self.assertEquals(res.find(" cdr filename bla.cdr"), -1)
1119
1120 res = self.vty.command("show running-config")
1121 self.assert_(res.find(" cdr interval 600") > 0)
1122
1123 self.vty.command("cdr interval 900")
1124 res = self.vty.command("show running-config")
1125 self.assert_(res.find(" cdr interval 900") > 0)
1126 self.assertEquals(res.find(" cdr interval 600"), -1)
1127
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001128def add_nat_test(suite, workdir):
1129 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
1130 print("Skipping the NAT test")
1131 return
1132 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT)
1133 suite.addTest(test)
1134
Max70cf7292016-04-13 11:36:38 +02001135def ipa_send_pong(x, verbose = False):
1136 if (verbose):
1137 print "\tBSC -> NAT: PONG!"
1138 return x.send("\x00\x01\xfe\x01")
1139
1140def ipa_send_ping(x, verbose = False):
1141 if (verbose):
1142 print "\tBSC -> NAT: PING?"
1143 return x.send("\x00\x01\xfe\x00")
1144
1145def ipa_send_ack(x, verbose = False):
1146 if (verbose):
1147 print "\tBSC -> NAT: IPA ID ACK"
1148 return x.send("\x00\x01\xfe\x06")
1149
1150def ipa_send_reset(x, verbose = False):
1151 if (verbose):
1152 print "\tBSC -> NAT: RESET"
1153 return x.send("\x00\x12\xfd\x09\x00\x03\x05\x07\x02\x42\xfe\x02\x42\xfe\x06\x00\x04\x30\x04\x01\x20")
1154
1155def ipa_send_resp(x, tk, verbose = False):
1156 if (verbose):
1157 print "\tBSC -> NAT: IPA ID RESP"
1158 return x.send("\x00\x07\xfe\x05\x00\x04\x01" + tk)
1159
Max49364482016-04-13 11:36:39 +02001160def nat_bsc_reload(x):
1161 x.vty.command("configure terminal")
1162 x.vty.command("nat")
1163 x.vty.command("bscs-config-file bscs.config")
1164 x.vty.command("end")
1165
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001166def nat_msc_ip(x, ip, port):
Max49364482016-04-13 11:36:39 +02001167 x.vty.command("configure terminal")
1168 x.vty.command("nat")
1169 x.vty.command("msc ip " + ip)
Holger Hans Peter Freyther84ae27e2016-04-14 10:40:06 -04001170 x.vty.command("msc port " + str(port))
Max49364482016-04-13 11:36:39 +02001171 x.vty.command("end")
1172
1173def data2str(d):
Holger Hans Peter Freyther8bb62042016-04-14 21:40:04 -04001174 return d.encode('hex').lower()
Max49364482016-04-13 11:36:39 +02001175
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001176def nat_msc_test(x, ip, port, verbose = False):
Max49364482016-04-13 11:36:39 +02001177 msc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1178 msc.settimeout(32)
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001179 msc.bind((ip, port))
Max49364482016-04-13 11:36:39 +02001180 msc.listen(5)
1181 if (verbose):
1182 print "MSC is ready at " + ip
1183 while "MSC is connected: 0" == x.vty.command("show msc connection"):
1184 conn, addr = msc.accept()
1185 if (verbose):
1186 print "MSC got connection from ", addr
1187 return conn
1188
1189def ipa_handle_small(x, verbose = False):
1190 s = data2str(x.recv(4))
1191 if "0001fe00" == s:
1192 if (verbose):
1193 print "\tBSC <- NAT: PING?"
1194 ipa_send_pong(x, verbose)
1195 elif "0001fe06" == s:
1196 if (verbose):
1197 print "\tBSC <- NAT: IPA ID ACK"
1198 ipa_send_ack(x, verbose)
1199 elif "0001fe00" == s:
1200 if (verbose):
1201 print "\tBSC <- NAT: PONG!"
1202 else:
1203 if (verbose):
1204 print "\tBSC <- NAT: ", s
1205
1206def ipa_handle_resp(x, tk, verbose = False):
1207 s = data2str(x.recv(38))
1208 if "0023fe040108010701020103010401050101010011" in s:
1209 ipa_send_resp(x, tk, verbose)
1210 else:
1211 if (verbose):
1212 print "\tBSC <- NAT: ", s
1213
1214def nat_bsc_num_con(x):
1215 return len(x.vty.command("show bsc connections").split('\n'))
1216
1217def nat_bsc_sock_test(nr, tk, verbose = False):
1218 bsc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Holger Hans Peter Freyther2abf2b02016-04-14 21:13:51 -04001219 bsc.bind(('127.0.0.1', 0))
Max49364482016-04-13 11:36:39 +02001220 bsc.connect(('127.0.0.1', 5000))
1221 if (verbose):
1222 print "BSC%d " %nr
1223 print "\tconnected to %s:%d" % bsc.getpeername()
1224 ipa_handle_small(bsc, verbose)
1225 ipa_handle_resp(bsc, tk, verbose)
1226 bsc.recv(27) # MGCP msg
1227 ipa_handle_small(bsc, verbose)
1228 return bsc
1229
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001230def add_bsc_test(suite, workdir):
1231 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")):
1232 print("Skipping the BSC test")
1233 return
1234 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC)
1235 suite.addTest(test)
1236
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001237def add_gbproxy_test(suite, workdir):
1238 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-gbproxy")):
1239 print("Skipping the Gb-Proxy test")
1240 return
1241 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYGbproxy)
1242 suite.addTest(test)
1243
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001244def add_sgsn_test(suite, workdir):
1245 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-sgsn")):
1246 print("Skipping the SGSN test")
1247 return
1248 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYSGSN)
1249 suite.addTest(test)
1250
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001251if __name__ == '__main__':
1252 import argparse
1253 import sys
1254
1255 workdir = '.'
1256
1257 parser = argparse.ArgumentParser()
1258 parser.add_argument("-v", "--verbose", dest="verbose",
1259 action="store_true", help="verbose mode")
1260 parser.add_argument("-p", "--pythonconfpath", dest="p",
1261 help="searchpath for config")
1262 parser.add_argument("-w", "--workdir", dest="w",
1263 help="Working directory")
1264 args = parser.parse_args()
1265
1266 verbose_level = 1
1267 if args.verbose:
1268 verbose_level = 2
1269
1270 if args.w:
1271 workdir = args.w
1272
1273 if args.p:
1274 confpath = args.p
1275
1276 print "confpath %s, workdir %s" % (confpath, workdir)
1277 os.chdir(workdir)
1278 print "Running tests for specific VTY commands"
1279 suite = unittest.TestSuite()
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +02001280 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYMGCP))
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +02001281 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB))
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001282 add_bsc_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001283 add_nat_test(suite, workdir)
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001284 add_gbproxy_test(suite, workdir)
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001285 add_sgsn_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001286 res = unittest.TextTestRunner(verbosity=verbose_level).run(suite)
1287 sys.exit(len(res.errors) + len(res.failures))