blob: c264328a9dbcf09acfacd4065eb1673cebaac41b [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"
427 wrong_imsi = "204300999999999"
428
429 # Lets create one
430 res = self.vty.command('subscriber create imsi '+imsi)
431 self.assert_(res.find(" IMSI: "+imsi) > 0)
432
433 self.vty.verify('subscriber imsi '+wrong_imsi+' name wrong', ['% No subscriber found for imsi '+wrong_imsi])
434 res = self.vty.command('subscriber imsi '+imsi+' name '+('X' * 160))
435 self.assert_(res.find("NAME is too long") > 0)
436
437 self.vty.verify('subscriber imsi '+imsi+' name '+('G' * 159), [''])
438
439 self.vty.verify('subscriber imsi '+wrong_imsi+' extension 840', ['% No subscriber found for imsi '+wrong_imsi])
440 res = self.vty.command('subscriber imsi '+imsi+' extension '+('9' * 15))
441 self.assert_(res.find("EXTENSION is too long") > 0)
442
443 self.vty.verify('subscriber imsi '+imsi+' extension '+('1' * 14), [''])
444
445 # Delete it
446 res = self.vty.command('subscriber delete imsi '+imsi)
447 self.assert_(res != "")
448
Holger Hans Peter Freytherec37bb22013-02-05 09:39:09 +0100449 def testShowPagingGroup(self):
450 res = self.vty.command("show paging-group 255 1234567")
451 self.assertEqual(res, "% can't find BTS 255")
452 res = self.vty.command("show paging-group 0 1234567")
453 self.assertEquals(res, "%Paging group for IMSI 1234567 on BTS #0 is 7")
454
Ciabyec6e4f82014-03-06 17:20:55 +0100455 def testShowNetwork(self):
456 res = self.vty.command("show network")
457 self.assert_(res.startswith('BSC is on Country Code') >= 0)
458
Holger Hans Peter Freyther86573262015-01-31 09:47:37 +0100459 def testMeasurementFeed(self):
460 self.vty.enable()
461 self.vty.command("configure terminal")
462 self.vty.command("mncc-int")
463
464 res = self.vty.command("write terminal")
465 self.assertEquals(res.find('meas-feed scenario'), -1)
466
467 self.vty.command("meas-feed scenario bla")
468 res = self.vty.command("write terminal")
469 self.assert_(res.find('meas-feed scenario bla') > 0)
470
471 self.vty.command("meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890")
472 res = self.vty.command("write terminal")
473 self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890'), -1)
474 self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz012345'), -1)
475 self.assert_(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234') > 0)
476
477
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200478class TestVTYBSC(TestVTYGenericBSC):
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200479
480 def vty_command(self):
481 return ["./src/osmo-bsc/osmo-bsc", "-c",
482 "doc/examples/osmo-bsc/osmo-bsc.cfg"]
483
484 def vty_app(self):
485 return (4242, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc")
486
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200487 def testConfigNetworkTree(self):
Jacob Erlbeck75877272013-10-23 11:24:14 +0200488 self._testConfigNetworkTree()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200489
490 def testVtyTree(self):
491 self.vty.enable()
492 self.assertTrue(self.vty.verify("configure terminal", ['']))
493 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100494 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200495 self.assertTrue(self.vty.verify("msc 0", ['']))
496 self.assertEquals(self.vty.node(), 'config-msc')
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200497 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200498 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200499 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200500 self.assertTrue(self.vty.verify("bsc", ['']))
501 self.assertEquals(self.vty.node(), 'config-bsc')
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200502 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200503 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200504 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200505 self.assertTrue(self.vty.verify("exit", ['']))
506 self.assertTrue(self.vty.node() is None)
507
508 # Check searching for outer node's commands
509 self.vty.command("configure terminal")
510 self.vty.command('msc 0')
511 self.vty.command("bsc")
512 self.assertEquals(self.vty.node(), 'config-bsc')
513 self.vty.command("msc 0")
514 self.assertEquals(self.vty.node(), 'config-msc')
515
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200516 def testUssdNotificationsMsc(self):
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200517 self.vty.enable()
518 self.vty.command("configure terminal")
519 self.vty.command("msc")
520
521 # Test invalid input
522 self.vty.verify("bsc-msc-lost-text", ['% Command incomplete.'])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200523 self.vty.verify("bsc-welcome-text", ['% Command incomplete.'])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200524 self.vty.verify("bsc-grace-text", ['% Command incomplete.'])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200525
526 # Enable USSD notifications
527 self.vty.verify("bsc-msc-lost-text MSC disconnected", [''])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200528 self.vty.verify("bsc-welcome-text Hello MS", [''])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200529 self.vty.verify("bsc-grace-text In grace period", [''])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200530
531 # Verify settings
532 res = self.vty.command("write terminal")
533 self.assert_(res.find('bsc-msc-lost-text MSC disconnected') > 0)
534 self.assertEquals(res.find('no bsc-msc-lost-text'), -1)
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200535 self.assert_(res.find('bsc-welcome-text Hello MS') > 0)
536 self.assertEquals(res.find('no bsc-welcome-text'), -1)
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200537 self.assert_(res.find('bsc-grace-text In grace period') > 0)
538 self.assertEquals(res.find('no bsc-grace-text'), -1)
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200539
540 # Now disable it..
541 self.vty.verify("no bsc-msc-lost-text", [''])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200542 self.vty.verify("no bsc-welcome-text", [''])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200543 self.vty.verify("no bsc-grace-text", [''])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200544
545 # Verify settings
546 res = self.vty.command("write terminal")
547 self.assertEquals(res.find('bsc-msc-lost-text MSC disconnected'), -1)
548 self.assert_(res.find('no bsc-msc-lost-text') > 0)
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200549 self.assertEquals(res.find('bsc-welcome-text Hello MS'), -1)
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200550 self.assert_(res.find('no bsc-welcome-text') > 0)
551 self.assertEquals(res.find('bsc-grace-text In grace period'), -1)
552 self.assert_(res.find('no bsc-grace-text') > 0)
553
554 def testUssdNotificationsBsc(self):
555 self.vty.enable()
556 self.vty.command("configure terminal")
557 self.vty.command("bsc")
558
559 # Test invalid input
560 self.vty.verify("missing-msc-text", ['% Command incomplete.'])
561
562 # Enable USSD notifications
563 self.vty.verify("missing-msc-text No MSC found", [''])
564
565 # Verify settings
566 res = self.vty.command("write terminal")
567 self.assert_(res.find('missing-msc-text No MSC found') > 0)
568 self.assertEquals(res.find('no missing-msc-text'), -1)
569
570 # Now disable it..
571 self.vty.verify("no missing-msc-text", [''])
572
573 # Verify settings
574 res = self.vty.command("write terminal")
575 self.assertEquals(res.find('missing-msc-text No MSC found'), -1)
576 self.assert_(res.find('no missing-msc-text') > 0)
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200577
Jacob Erlbeck946d1412013-09-17 13:59:29 +0200578 def testNetworkTimezone(self):
579 self.vty.enable()
580 self.vty.verify("configure terminal", [''])
581 self.vty.verify("network", [''])
582 self.vty.verify("bts 0", [''])
583
584 # Test invalid input
585 self.vty.verify("timezone", ['% Command incomplete.'])
586 self.vty.verify("timezone 20 0", ['% Unknown command.'])
587 self.vty.verify("timezone 0 11", ['% Unknown command.'])
588 self.vty.verify("timezone 0 0 99", ['% Unknown command.'])
589
590 # Set time zone without DST
591 self.vty.verify("timezone 2 30", [''])
592
593 # Verify settings
594 res = self.vty.command("write terminal")
595 self.assert_(res.find('timezone 2 30') > 0)
596 self.assertEquals(res.find('timezone 2 30 '), -1)
597
598 # Set time zone with DST
599 self.vty.verify("timezone 2 30 1", [''])
600
601 # Verify settings
602 res = self.vty.command("write terminal")
603 self.assert_(res.find('timezone 2 30 1') > 0)
604
605 # Now disable it..
606 self.vty.verify("no timezone", [''])
607
608 # Verify settings
609 res = self.vty.command("write terminal")
610 self.assertEquals(res.find(' timezone'), -1)
611
Ciabyec6e4f82014-03-06 17:20:55 +0100612 def testShowNetwork(self):
613 res = self.vty.command("show network")
614 self.assert_(res.startswith('BSC is on Country Code') >= 0)
615
Holger Hans Peter Freytherdb64f2e2014-10-29 10:06:15 +0100616 def testPingPongConfiguration(self):
617 self.vty.enable()
618 self.vty.verify("configure terminal", [''])
619 self.vty.verify("network", [''])
620 self.vty.verify("msc 0", [''])
621
622 self.vty.verify("timeout-ping 12", [''])
623 self.vty.verify("timeout-pong 14", [''])
624 res = self.vty.command("show running-config")
625 self.assert_(res.find(" timeout-ping 12") > 0)
626 self.assert_(res.find(" timeout-pong 14") > 0)
627 self.assert_(res.find(" no timeout-ping advanced") > 0)
628
629 self.vty.verify("timeout-ping advanced", [''])
630 res = self.vty.command("show running-config")
631 self.assert_(res.find(" timeout-ping 12") > 0)
632 self.assert_(res.find(" timeout-pong 14") > 0)
633 self.assert_(res.find(" timeout-ping advanced") > 0)
634
635 self.vty.verify("no timeout-ping advanced", [''])
636 res = self.vty.command("show running-config")
637 self.assert_(res.find(" timeout-ping 12") > 0)
638 self.assert_(res.find(" timeout-pong 14") > 0)
639 self.assert_(res.find(" no timeout-ping advanced") > 0)
640
641 self.vty.verify("no timeout-ping", [''])
642 res = self.vty.command("show running-config")
643 self.assertEquals(res.find(" timeout-ping 12"), -1)
644 self.assertEquals(res.find(" timeout-pong 14"), -1)
645 self.assertEquals(res.find(" no timeout-ping advanced"), -1)
646 self.assert_(res.find(" no timeout-ping") > 0)
647
648 self.vty.verify("timeout-ping advanced", ['%ping handling is disabled. Enable it first.'])
649
650 # And back to enabling it
651 self.vty.verify("timeout-ping 12", [''])
652 self.vty.verify("timeout-pong 14", [''])
653 res = self.vty.command("show running-config")
654 self.assert_(res.find(" timeout-ping 12") > 0)
655 self.assert_(res.find(" timeout-pong 14") > 0)
656 self.assert_(res.find(" timeout-ping advanced") > 0)
657
Holger Hans Peter Freyther32dd2f32015-04-01 18:15:48 +0200658 def testMscDataCoreLACCI(self):
659 self.vty.enable()
660 res = self.vty.command("show running-config")
661 self.assertEquals(res.find("core-location-area-code"), -1)
662 self.assertEquals(res.find("core-cell-identity"), -1)
663
664 self.vty.command("configure terminal")
665 self.vty.command("msc 0")
666 self.vty.command("core-location-area-code 666")
667 self.vty.command("core-cell-identity 333")
668
669 res = self.vty.command("show running-config")
670 self.assert_(res.find("core-location-area-code 666") > 0)
671 self.assert_(res.find("core-cell-identity 333") > 0)
672
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200673class TestVTYNAT(TestVTYGenericBSC):
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200674
675 def vty_command(self):
Max49364482016-04-13 11:36:39 +0200676 return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-l", "127.0.0.1", "-c",
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200677 "doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"]
678
679 def vty_app(self):
680 return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat")
681
Max49364482016-04-13 11:36:39 +0200682 def testBSCreload(self):
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -0400683 # Use different port for the mock msc to avoid clashing with
684 # the osmo-bsc_nat itself
Holger Hans Peter Freytherf1a61bb2016-04-14 08:50:25 -0400685 ip = "127.0.0.1"
Holger Hans Peter Freythere98c9c72016-04-14 10:58:58 -0400686 port = 5522
Max49364482016-04-13 11:36:39 +0200687 self.vty.enable()
688 bscs1 = self.vty.command("show bscs-config")
689 nat_bsc_reload(self)
690 bscs2 = self.vty.command("show bscs-config")
691 # check that multiple calls to bscs-config-file give the same result
692 self.assertEquals(bscs1, bscs2)
693
694 # add new bsc
695 self.vty.command("configure terminal")
696 self.vty.command("nat")
697 self.vty.command("bsc 5")
698 self.vty.command("token key")
699 self.vty.command("location_area_code 666")
700 self.vty.command("end")
701
702 # update bsc token
703 self.vty.command("configure terminal")
704 self.vty.command("nat")
705 self.vty.command("bsc 1")
706 self.vty.command("token xyu")
707 self.vty.command("end")
708
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -0400709 nat_msc_ip(self, ip, port)
710 msc = nat_msc_test(self, ip, port)
Max49364482016-04-13 11:36:39 +0200711 b0 = nat_bsc_sock_test(0, "lol")
712 b1 = nat_bsc_sock_test(1, "xyu")
713 b2 = nat_bsc_sock_test(5, "key")
714
715 self.assertEquals("3 BSCs configured", self.vty.command("show nat num-bscs-configured"))
716 self.assertTrue(3 == nat_bsc_num_con(self))
717 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
718
719 nat_bsc_reload(self)
720 bscs2 = self.vty.command("show bscs-config")
721 # check that the reset to initial config succeeded
722 self.assertEquals(bscs1, bscs2)
723
724 self.assertEquals("2 BSCs configured", self.vty.command("show nat num-bscs-configured"))
725 self.assertTrue(1 == nat_bsc_num_con(self))
726 rem = self.vty.command("show bsc connections").split(' ')
727 # remaining connection is for BSC0
728 self.assertEquals('0', rem[2])
729 # remaining connection is authorized
730 self.assertEquals('1', rem[4])
731 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
732
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200733 def testVtyTree(self):
734 self.vty.enable()
735 self.assertTrue(self.vty.verify('configure terminal', ['']))
736 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100737 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200738 self.assertTrue(self.vty.verify('mgcp', ['']))
739 self.assertEquals(self.vty.node(), 'config-mgcp')
740 self.checkForEndAndExit()
741 self.assertTrue(self.vty.verify('exit', ['']))
742 self.assertEquals(self.vty.node(), 'config')
743 self.assertTrue(self.vty.verify('nat', ['']))
744 self.assertEquals(self.vty.node(), 'config-nat')
745 self.checkForEndAndExit()
746 self.assertTrue(self.vty.verify('bsc 0', ['']))
747 self.assertEquals(self.vty.node(), 'config-nat-bsc')
748 self.checkForEndAndExit()
749 self.assertTrue(self.vty.verify('exit', ['']))
750 self.assertEquals(self.vty.node(), 'config-nat')
751 self.assertTrue(self.vty.verify('exit', ['']))
752 self.assertEquals(self.vty.node(), 'config')
753 self.assertTrue(self.vty.verify('exit', ['']))
754 self.assertTrue(self.vty.node() is None)
755
756 # Check searching for outer node's commands
757 self.vty.command('configure terminal')
758 self.vty.command('mgcp')
759 self.vty.command('nat')
760 self.assertEquals(self.vty.node(), 'config-nat')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200761 self.vty.command('mgcp')
762 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200763 self.vty.command('nat')
764 self.assertEquals(self.vty.node(), 'config-nat')
765 self.vty.command('bsc 0')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200766 self.vty.command('mgcp')
767 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200768
Holger Hans Peter Freytherb718ad32013-06-25 09:08:02 +0200769 def testRewriteNoRewrite(self):
770 self.vty.enable()
771 res = self.vty.command("configure terminal")
772 res = self.vty.command("nat")
773 res = self.vty.command("number-rewrite rewrite.cfg")
774 res = self.vty.command("no number-rewrite")
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200775
Holger Hans Peter Freyther7f100c92015-04-23 20:25:17 -0400776 def testEnsureNoEnsureModeSet(self):
777 self.vty.enable()
778 res = self.vty.command("configure terminal")
779 res = self.vty.command("nat")
780
781 # Ensure the default
782 res = self.vty.command("show running-config")
783 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
784
785 self.vty.command("sdp-ensure-amr-mode-set")
786 res = self.vty.command("show running-config")
787 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
788
789 self.vty.command("no sdp-ensure-amr-mode-set")
790 res = self.vty.command("show running-config")
791 self.assert_(res.find('\n no sdp-ensure-amr-mode-set') > 0)
792
Holger Hans Peter Freyther67e423c2013-06-25 15:38:31 +0200793 def testRewritePostNoRewrite(self):
794 self.vty.enable()
795 self.vty.command("configure terminal")
796 self.vty.command("nat")
797 self.vty.verify("number-rewrite-post rewrite.cfg", [''])
798 self.vty.verify("no number-rewrite-post", [''])
799
800
Holger Hans Peter Freytherddf191e2013-06-25 11:44:01 +0200801 def testPrefixTreeLoading(self):
802 cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv")
803
804 self.vty.enable()
805 self.vty.command("configure terminal")
806 self.vty.command("nat")
807 res = self.vty.command("prefix-tree %s" % cfg)
808 self.assertEqual(res, "% prefix-tree loaded 17 rules.")
809 self.vty.command("end")
810
811 res = self.vty.command("show prefix-tree")
812 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')
813
814 self.vty.command("configure terminal")
815 self.vty.command("nat")
816 self.vty.command("no prefix-tree")
817 self.vty.command("end")
818
819 res = self.vty.command("show prefix-tree")
820 self.assertEqual(res, "% there is now prefix tree loaded.")
821
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200822 def testUssdSideChannelProvider(self):
823 self.vty.command("end")
824 self.vty.enable()
825 self.vty.command("configure terminal")
826 self.vty.command("nat")
827 self.vty.command("ussd-token key")
828 self.vty.command("end")
829
830 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
831 self.assertTrue(res)
832
833 ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
834 ussdSocket.connect(('127.0.0.1', 5001))
835 ussdSocket.settimeout(2.0)
836 print "Connected to %s:%d" % ussdSocket.getpeername()
837
838 print "Expecting ID_GET request"
839 data = ussdSocket.recv(4)
840 self.assertEqual(data, "\x00\x01\xfe\x04")
841
842 print "Going to send ID_RESP response"
Max70cf7292016-04-13 11:36:38 +0200843 res = ipa_send_resp(ussdSocket, "\x6b\x65\x79")
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200844 self.assertEqual(res, 10)
845
846 # initiating PING/PONG cycle to know, that the ID_RESP message has been processed
847
848 print "Going to send PING request"
Max70cf7292016-04-13 11:36:38 +0200849 res = ipa_send_ping(ussdSocket)
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200850 self.assertEqual(res, 4)
851
852 print "Expecting PONG response"
853 data = ussdSocket.recv(4)
854 self.assertEqual(data, "\x00\x01\xfe\x01")
855
856 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.'])
857 self.assertTrue(res)
858
859 print "Going to shut down connection"
860 ussdSocket.shutdown(socket.SHUT_WR)
861
862 print "Expecting EOF"
863 data = ussdSocket.recv(4)
864 self.assertEqual(data, "")
865
866 ussdSocket.close()
867
868 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
869 self.assertTrue(res)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200870
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100871 def testAccessList(self):
872 """
873 Verify that the imsi-deny can have a reject cause or no reject cause
874 """
875 self.vty.enable()
876 self.vty.command("configure terminal")
877 self.vty.command("nat")
878
879 # Old default
880 self.vty.command("access-list test-default imsi-deny ^123[0-9]*$")
881 res = self.vty.command("show running-config").split("\r\n")
882 asserted = False
883 for line in res:
Holger Hans Peter Freyther4ecc6872014-03-04 15:38:00 +0100884 if line.startswith(" access-list test-default"):
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100885 self.assertEqual(line, " access-list test-default imsi-deny ^123[0-9]*$ 11 11")
886 asserted = True
887 self.assert_(asserted)
888
889 # Check the optional CM Service Reject Cause
890 self.vty.command("access-list test-cm-deny imsi-deny ^123[0-9]*$ 42").split("\r\n")
891 res = self.vty.command("show running-config").split("\r\n")
892 asserted = False
893 for line in res:
894 if line.startswith(" access-list test-cm"):
895 self.assertEqual(line, " access-list test-cm-deny imsi-deny ^123[0-9]*$ 42 11")
896 asserted = True
897 self.assert_(asserted)
898
899 # Check the optional LU Reject Cause
900 self.vty.command("access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42").split("\r\n")
901 res = self.vty.command("show running-config").split("\r\n")
902 asserted = False
903 for line in res:
904 if line.startswith(" access-list test-lu"):
905 self.assertEqual(line, " access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42")
906 asserted = True
907 self.assert_(asserted)
908
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200909class TestVTYGbproxy(TestVTYGenericBSC):
910
911 def vty_command(self):
912 return ["./src/gprs/osmo-gbproxy", "-c",
913 "doc/examples/osmo-gbproxy/osmo-gbproxy.cfg"]
914
915 def vty_app(self):
916 return (4246, "./src/gprs/osmo-gbproxy", "OsmoGbProxy", "bsc")
917
918 def testVtyTree(self):
919 self.vty.enable()
920 self.assertTrue(self.vty.verify('configure terminal', ['']))
921 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100922 self.checkForEndAndExit()
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200923 self.assertTrue(self.vty.verify('ns', ['']))
924 self.assertEquals(self.vty.node(), 'config-ns')
925 self.checkForEndAndExit()
926 self.assertTrue(self.vty.verify('exit', ['']))
927 self.assertEquals(self.vty.node(), 'config')
928 self.assertTrue(self.vty.verify('gbproxy', ['']))
929 self.assertEquals(self.vty.node(), 'config-gbproxy')
930 self.checkForEndAndExit()
931 self.assertTrue(self.vty.verify('exit', ['']))
932 self.assertEquals(self.vty.node(), 'config')
933
934 def testVtyShow(self):
935 res = self.vty.command("show ns")
936 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
937
938 res = self.vty.command("show gbproxy stats")
939 self.assert_(res.find('GBProxy Global Statistics') >= 0)
940
Jacob Erlbeck4211d792013-10-24 12:48:23 +0200941 def testVtyDeletePeer(self):
942 self.vty.enable()
943 self.assertTrue(self.vty.verify('delete-gbproxy-peer 9999 bvci 7777', ['BVC not found']))
944 res = self.vty.command("delete-gbproxy-peer 9999 all dry-run")
945 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
946 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
947 res = self.vty.command("delete-gbproxy-peer 9999 only-bvc dry-run")
948 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
949 self.assert_(res.find('Not Deleted 0 NS-VC') < 0)
950 res = self.vty.command("delete-gbproxy-peer 9999 only-nsvc dry-run")
951 self.assert_(res.find('Not Deleted 0 BVC') < 0)
952 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
953 res = self.vty.command("delete-gbproxy-peer 9999 all")
954 self.assert_(res.find('Deleted 0 BVC') >= 0)
955 self.assert_(res.find('Deleted 0 NS-VC') >= 0)
956
Jacob Erlbeck144b8b12014-11-04 11:15:01 +0100957class TestVTYSGSN(TestVTYGenericBSC):
958
959 def vty_command(self):
960 return ["./src/gprs/osmo-sgsn", "-c",
961 "doc/examples/osmo-sgsn/osmo-sgsn.cfg"]
962
963 def vty_app(self):
964 return (4245, "./src/gprs/osmo-sgsn", "OsmoSGSN", "sgsn")
965
966 def testVtyTree(self):
967 self.vty.enable()
968 self.assertTrue(self.vty.verify('configure terminal', ['']))
969 self.assertEquals(self.vty.node(), 'config')
970 self.checkForEndAndExit()
971 self.assertTrue(self.vty.verify('ns', ['']))
972 self.assertEquals(self.vty.node(), 'config-ns')
973 self.checkForEndAndExit()
974 self.assertTrue(self.vty.verify('exit', ['']))
975 self.assertEquals(self.vty.node(), 'config')
976 self.assertTrue(self.vty.verify('sgsn', ['']))
977 self.assertEquals(self.vty.node(), 'config-sgsn')
978 self.checkForEndAndExit()
979 self.assertTrue(self.vty.verify('exit', ['']))
980 self.assertEquals(self.vty.node(), 'config')
981
982 def testVtyShow(self):
983 res = self.vty.command("show ns")
984 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
985 self.assertTrue(self.vty.verify('show bssgp', ['']))
986 self.assertTrue(self.vty.verify('show bssgp stats', ['']))
987 # TODO: uncomment when the command does not segfault anymore
988 # self.assertTrue(self.vty.verify('show bssgp nsei 123', ['']))
989 # self.assertTrue(self.vty.verify('show bssgp nsei 123 stats', ['']))
990
991 self.assertTrue(self.vty.verify('show sgsn', ['']))
992 self.assertTrue(self.vty.verify('show mm-context all', ['']))
993 self.assertTrue(self.vty.verify('show mm-context imsi 000001234567', ['No MM context for IMSI 000001234567']))
994 self.assertTrue(self.vty.verify('show pdp-context all', ['']))
995
996 res = self.vty.command("show sndcp")
997 self.assert_(res.find('State of SNDCP Entities') >= 0)
998
999 res = self.vty.command("show llc")
1000 self.assert_(res.find('State of LLC Entities') >= 0)
1001
Jacob Erlbeck106f5472014-11-04 10:08:37 +01001002 def testVtyAuth(self):
1003 self.vty.enable()
1004 self.assertTrue(self.vty.verify('configure terminal', ['']))
1005 self.assertEquals(self.vty.node(), 'config')
1006 self.assertTrue(self.vty.verify('sgsn', ['']))
1007 self.assertEquals(self.vty.node(), 'config-sgsn')
1008 self.assertTrue(self.vty.verify('auth-policy accept-all', ['']))
1009 res = self.vty.command("show running-config")
1010 self.assert_(res.find('auth-policy accept-all') > 0)
1011 self.assertTrue(self.vty.verify('auth-policy acl-only', ['']))
1012 res = self.vty.command("show running-config")
1013 self.assert_(res.find('auth-policy acl-only') > 0)
1014 self.assertTrue(self.vty.verify('auth-policy closed', ['']))
1015 res = self.vty.command("show running-config")
1016 self.assert_(res.find('auth-policy closed') > 0)
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +01001017 self.assertTrue(self.vty.verify('auth-policy remote', ['']))
1018 res = self.vty.command("show running-config")
1019 self.assert_(res.find('auth-policy remote') > 0)
Jacob Erlbeck106f5472014-11-04 10:08:37 +01001020
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001021 def testVtySubscriber(self):
1022 self.vty.enable()
1023 res = self.vty.command('show subscriber cache')
1024 self.assert_(res.find('1234567890') < 0)
Jacob Erlbeckd9193432015-01-19 14:11:46 +01001025 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 create', ['']))
1026 res = self.vty.command('show subscriber cache')
1027 self.assert_(res.find('1234567890') >= 0)
1028 self.assert_(res.find('Authorized: 0') >= 0)
1029 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 update-location-result ok', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001030 res = self.vty.command('show subscriber cache')
1031 self.assert_(res.find('1234567890') >= 0)
1032 self.assert_(res.find('Authorized: 1') >= 0)
Jacob Erlbeck8000e0e2015-01-27 14:56:40 +01001033 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 cancel update-procedure', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001034 res = self.vty.command('show subscriber cache')
Jacob Erlbecke988ae42015-01-27 12:41:19 +01001035 self.assert_(res.find('1234567890') >= 0)
1036 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 destroy', ['']))
1037 res = self.vty.command('show subscriber cache')
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001038 self.assert_(res.find('1234567890') < 0)
1039
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +01001040 def testVtyGgsn(self):
1041 self.vty.enable()
1042 self.assertTrue(self.vty.verify('configure terminal', ['']))
1043 self.assertEquals(self.vty.node(), 'config')
1044 self.assertTrue(self.vty.verify('sgsn', ['']))
1045 self.assertEquals(self.vty.node(), 'config-sgsn')
1046 self.assertTrue(self.vty.verify('ggsn 0 remote-ip 127.99.99.99', ['']))
1047 self.assertTrue(self.vty.verify('ggsn 0 gtp-version 1', ['']))
1048 self.assertTrue(self.vty.verify('apn * ggsn 0', ['']))
1049 self.assertTrue(self.vty.verify('apn apn1.test ggsn 0', ['']))
1050 self.assertTrue(self.vty.verify('apn apn1.test ggsn 1', ['% a GGSN with id 1 has not been defined']))
1051 self.assertTrue(self.vty.verify('apn apn1.test imsi-prefix 123456 ggsn 0', ['']))
1052 self.assertTrue(self.vty.verify('apn apn2.test imsi-prefix 123456 ggsn 0', ['']))
1053 res = self.vty.command("show running-config")
1054 self.assert_(res.find('ggsn 0 remote-ip 127.99.99.99') >= 0)
1055 self.assert_(res.find('ggsn 0 gtp-version 1') >= 0)
1056 self.assert_(res.find('apn * ggsn 0') >= 0)
1057 self.assert_(res.find('apn apn1.test ggsn 0') >= 0)
1058 self.assert_(res.find('apn apn1.test imsi-prefix 123456 ggsn 0') >= 0)
1059 self.assert_(res.find('apn apn2.test imsi-prefix 123456 ggsn 0') >= 0)
1060
Holger Hans Peter Freyther9c20a5f2015-02-06 16:23:29 +01001061 def testVtyEasyAPN(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
1068 res = self.vty.command("show running-config")
1069 self.assertEquals(res.find("apn internet"), -1)
1070
1071 self.assertTrue(self.vty.verify("access-point-name internet.apn", ['']))
1072 res = self.vty.command("show running-config")
1073 self.assert_(res.find("apn internet.apn ggsn 0") >= 0)
1074
1075 self.assertTrue(self.vty.verify("no access-point-name internet.apn", ['']))
1076 res = self.vty.command("show running-config")
1077 self.assertEquals(res.find("apn internet"), -1)
1078
Holger Hans Peter Freytherc15c61c2015-05-06 17:46:08 +02001079 def testVtyCDR(self):
1080 self.vty.enable()
1081 self.assertTrue(self.vty.verify('configure terminal', ['']))
1082 self.assertEquals(self.vty.node(), 'config')
1083 self.assertTrue(self.vty.verify('sgsn', ['']))
1084 self.assertEquals(self.vty.node(), 'config-sgsn')
1085
1086 res = self.vty.command("show running-config")
1087 self.assert_(res.find("no cdr filename") > 0)
1088
1089 self.vty.command("cdr filename bla.cdr")
1090 res = self.vty.command("show running-config")
1091 self.assertEquals(res.find("no cdr filename"), -1)
1092 self.assert_(res.find(" cdr filename bla.cdr") > 0)
1093
1094 self.vty.command("no cdr filename")
1095 res = self.vty.command("show running-config")
1096 self.assert_(res.find("no cdr filename") > 0)
1097 self.assertEquals(res.find(" cdr filename bla.cdr"), -1)
1098
1099 res = self.vty.command("show running-config")
1100 self.assert_(res.find(" cdr interval 600") > 0)
1101
1102 self.vty.command("cdr interval 900")
1103 res = self.vty.command("show running-config")
1104 self.assert_(res.find(" cdr interval 900") > 0)
1105 self.assertEquals(res.find(" cdr interval 600"), -1)
1106
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001107def add_nat_test(suite, workdir):
1108 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
1109 print("Skipping the NAT test")
1110 return
1111 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT)
1112 suite.addTest(test)
1113
Max70cf7292016-04-13 11:36:38 +02001114def ipa_send_pong(x, verbose = False):
1115 if (verbose):
1116 print "\tBSC -> NAT: PONG!"
1117 return x.send("\x00\x01\xfe\x01")
1118
1119def ipa_send_ping(x, verbose = False):
1120 if (verbose):
1121 print "\tBSC -> NAT: PING?"
1122 return x.send("\x00\x01\xfe\x00")
1123
1124def ipa_send_ack(x, verbose = False):
1125 if (verbose):
1126 print "\tBSC -> NAT: IPA ID ACK"
1127 return x.send("\x00\x01\xfe\x06")
1128
1129def ipa_send_reset(x, verbose = False):
1130 if (verbose):
1131 print "\tBSC -> NAT: RESET"
1132 return x.send("\x00\x12\xfd\x09\x00\x03\x05\x07\x02\x42\xfe\x02\x42\xfe\x06\x00\x04\x30\x04\x01\x20")
1133
1134def ipa_send_resp(x, tk, verbose = False):
1135 if (verbose):
1136 print "\tBSC -> NAT: IPA ID RESP"
1137 return x.send("\x00\x07\xfe\x05\x00\x04\x01" + tk)
1138
Max49364482016-04-13 11:36:39 +02001139def nat_bsc_reload(x):
1140 x.vty.command("configure terminal")
1141 x.vty.command("nat")
1142 x.vty.command("bscs-config-file bscs.config")
1143 x.vty.command("end")
1144
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001145def nat_msc_ip(x, ip, port):
Max49364482016-04-13 11:36:39 +02001146 x.vty.command("configure terminal")
1147 x.vty.command("nat")
1148 x.vty.command("msc ip " + ip)
Holger Hans Peter Freyther84ae27e2016-04-14 10:40:06 -04001149 x.vty.command("msc port " + str(port))
Max49364482016-04-13 11:36:39 +02001150 x.vty.command("end")
1151
1152def data2str(d):
Holger Hans Peter Freyther8bb62042016-04-14 21:40:04 -04001153 return d.encode('hex').lower()
Max49364482016-04-13 11:36:39 +02001154
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001155def nat_msc_test(x, ip, port, verbose = False):
Max49364482016-04-13 11:36:39 +02001156 msc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1157 msc.settimeout(32)
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001158 msc.bind((ip, port))
Max49364482016-04-13 11:36:39 +02001159 msc.listen(5)
1160 if (verbose):
1161 print "MSC is ready at " + ip
1162 while "MSC is connected: 0" == x.vty.command("show msc connection"):
1163 conn, addr = msc.accept()
1164 if (verbose):
1165 print "MSC got connection from ", addr
1166 return conn
1167
1168def ipa_handle_small(x, verbose = False):
1169 s = data2str(x.recv(4))
1170 if "0001fe00" == s:
1171 if (verbose):
1172 print "\tBSC <- NAT: PING?"
1173 ipa_send_pong(x, verbose)
1174 elif "0001fe06" == s:
1175 if (verbose):
1176 print "\tBSC <- NAT: IPA ID ACK"
1177 ipa_send_ack(x, verbose)
1178 elif "0001fe00" == s:
1179 if (verbose):
1180 print "\tBSC <- NAT: PONG!"
1181 else:
1182 if (verbose):
1183 print "\tBSC <- NAT: ", s
1184
1185def ipa_handle_resp(x, tk, verbose = False):
1186 s = data2str(x.recv(38))
1187 if "0023fe040108010701020103010401050101010011" in s:
1188 ipa_send_resp(x, tk, verbose)
1189 else:
1190 if (verbose):
1191 print "\tBSC <- NAT: ", s
1192
1193def nat_bsc_num_con(x):
1194 return len(x.vty.command("show bsc connections").split('\n'))
1195
1196def nat_bsc_sock_test(nr, tk, verbose = False):
1197 bsc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Holger Hans Peter Freyther2abf2b02016-04-14 21:13:51 -04001198 bsc.bind(('127.0.0.1', 0))
Max49364482016-04-13 11:36:39 +02001199 bsc.connect(('127.0.0.1', 5000))
1200 if (verbose):
1201 print "BSC%d " %nr
1202 print "\tconnected to %s:%d" % bsc.getpeername()
1203 ipa_handle_small(bsc, verbose)
1204 ipa_handle_resp(bsc, tk, verbose)
1205 bsc.recv(27) # MGCP msg
1206 ipa_handle_small(bsc, verbose)
1207 return bsc
1208
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001209def add_bsc_test(suite, workdir):
1210 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")):
1211 print("Skipping the BSC test")
1212 return
1213 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC)
1214 suite.addTest(test)
1215
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001216def add_gbproxy_test(suite, workdir):
1217 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-gbproxy")):
1218 print("Skipping the Gb-Proxy test")
1219 return
1220 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYGbproxy)
1221 suite.addTest(test)
1222
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001223def add_sgsn_test(suite, workdir):
1224 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-sgsn")):
1225 print("Skipping the SGSN test")
1226 return
1227 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYSGSN)
1228 suite.addTest(test)
1229
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001230if __name__ == '__main__':
1231 import argparse
1232 import sys
1233
1234 workdir = '.'
1235
1236 parser = argparse.ArgumentParser()
1237 parser.add_argument("-v", "--verbose", dest="verbose",
1238 action="store_true", help="verbose mode")
1239 parser.add_argument("-p", "--pythonconfpath", dest="p",
1240 help="searchpath for config")
1241 parser.add_argument("-w", "--workdir", dest="w",
1242 help="Working directory")
1243 args = parser.parse_args()
1244
1245 verbose_level = 1
1246 if args.verbose:
1247 verbose_level = 2
1248
1249 if args.w:
1250 workdir = args.w
1251
1252 if args.p:
1253 confpath = args.p
1254
1255 print "confpath %s, workdir %s" % (confpath, workdir)
1256 os.chdir(workdir)
1257 print "Running tests for specific VTY commands"
1258 suite = unittest.TestSuite()
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +02001259 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYMGCP))
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +02001260 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB))
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001261 add_bsc_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001262 add_nat_test(suite, workdir)
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001263 add_gbproxy_test(suite, workdir)
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001264 add_sgsn_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001265 res = unittest.TextTestRunner(verbosity=verbose_level).run(suite)
1266 sys.exit(len(res.errors) + len(res.failures))