blob: a4cfb607f3e3ace350f8cf0d6a32fa5b5220133b [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
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200234 def testEnableDisablePeriodicLU(self):
235 self.vty.enable()
236 self.vty.command("configure terminal")
237 self.vty.command("network")
238 self.vty.command("bts 0")
239
240 # Test invalid input
241 self.vty.verify("periodic location update 0", ['% Unknown command.'])
242 self.vty.verify("periodic location update 5", ['% Unknown command.'])
243 self.vty.verify("periodic location update 1531", ['% Unknown command.'])
244
245 # Enable periodic lu..
246 self.vty.verify("periodic location update 60", [''])
247 res = self.vty.command("write terminal")
Holger Hans Peter Freytherc0438e32013-07-27 22:23:25 +0200248 self.assert_(res.find('periodic location update 60') > 0)
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200249 self.assertEquals(res.find('no periodic location update'), -1)
250
251 # Now disable it..
252 self.vty.verify("no periodic location update", [''])
253 res = self.vty.command("write terminal")
254 self.assertEquals(res.find('periodic location update 60'), -1)
Holger Hans Peter Freytherc0438e32013-07-27 22:23:25 +0200255 self.assert_(res.find('no periodic location update') > 0)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200256
Jacob Erlbeck65d114f2014-01-16 11:02:14 +0100257 def testEnableDisableSiHacks(self):
258 self.vty.enable()
259 self.vty.command("configure terminal")
260 self.vty.command("network")
261 self.vty.command("bts 0")
262
263 # Enable periodic lu..
264 self.vty.verify("force-combined-si", [''])
265 res = self.vty.command("write terminal")
266 self.assert_(res.find(' force-combined-si') > 0)
267 self.assertEquals(res.find('no force-combined-si'), -1)
268
269 # Now disable it..
270 self.vty.verify("no force-combined-si", [''])
271 res = self.vty.command("write terminal")
272 self.assertEquals(res.find(' force-combined-si'), -1)
273 self.assert_(res.find('no force-combined-si') > 0)
274
Ivan Kluchnikov67920592013-09-16 13:13:04 +0400275 def testRachAccessControlClass(self):
276 self.vty.enable()
277 self.vty.command("configure terminal")
278 self.vty.command("network")
279 self.vty.command("bts 0")
280
281 # Test invalid input
282 self.vty.verify("rach access-control-class", ['% Command incomplete.'])
283 self.vty.verify("rach access-control-class 1", ['% Command incomplete.'])
284 self.vty.verify("rach access-control-class -1", ['% Unknown command.'])
285 self.vty.verify("rach access-control-class 10", ['% Unknown command.'])
286 self.vty.verify("rach access-control-class 16", ['% Unknown command.'])
287
288 # Barred rach access control classes
289 for classNum in range(16):
290 if classNum != 10:
291 self.vty.verify("rach access-control-class " + str(classNum) + " barred", [''])
292
293 # Verify settings
294 res = self.vty.command("write terminal")
295 for classNum in range(16):
296 if classNum != 10:
297 self.assert_(res.find("rach access-control-class " + str(classNum) + " barred") > 0)
298
299 # Allowed rach access control classes
300 for classNum in range(16):
301 if classNum != 10:
302 self.vty.verify("rach access-control-class " + str(classNum) + " allowed", [''])
303
304 # Verify settings
305 res = self.vty.command("write terminal")
306 for classNum in range(16):
307 if classNum != 10:
308 self.assertEquals(res.find("rach access-control-class " + str(classNum) + " barred"), -1)
309
Holger Hans Peter Freytherde392252016-04-01 19:44:00 +0200310 def testSubscriberCreateDeleteTwice(self):
311 """
312 OS#1657 indicates that there might be an issue creating the
313 same subscriber twice. This test will use the VTY command to
314 create a subscriber and then issue a second create command
315 with the same IMSI. The test passes if the VTY continues to
316 respond to VTY commands.
317 """
318 self.vty.enable()
319
320 imsi = "204300854013739"
321
322 # Initially we don't have this subscriber
323 self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi])
324
325 # Lets create one
326 res = self.vty.command('subscriber create imsi '+imsi)
327 self.assert_(res.find(" IMSI: "+imsi) > 0)
328 # And now create one again.
329 res2 = self.vty.command('subscriber create imsi '+imsi)
330 self.assert_(res2.find(" IMSI: "+imsi) > 0)
331 self.assertEqual(res, res2)
332
333 # Verify it has been created
334 res = self.vty.command('show subscriber imsi '+imsi)
335 self.assert_(res.find(" IMSI: "+imsi) > 0)
336
337 # Delete it
338 res = self.vty.command('subscriber delete imsi '+imsi)
339 self.assert_(res != "")
340
341 # Now it should not be there anymore
342 res = self.vty.command('show subscriber imsi '+imsi)
343 self.assert_(res != '% No subscriber found for imsi '+imsi)
344
345
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500346 def testSubscriberCreateDelete(self):
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200347 self.vty.enable()
348
349 imsi = "204300854013739"
350
351 # Initially we don't have this subscriber
352 self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi])
353
354 # Lets create one
355 res = self.vty.command('subscriber create imsi '+imsi)
356 self.assert_(res.find(" IMSI: "+imsi) > 0)
357
358 # Now we have it
359 res = self.vty.command('show subscriber imsi '+imsi)
360 self.assert_(res.find(" IMSI: "+imsi) > 0)
361
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500362 # Delete it
363 res = self.vty.command('subscriber delete imsi '+imsi)
364 self.assert_(res != "")
365
366 # Now it should not be there anymore
367 res = self.vty.command('show subscriber imsi '+imsi)
368 self.assert_(res != '% No subscriber found for imsi '+imsi)
369
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200370 def testSubscriberSettings(self):
371 self.vty.enable()
372
373 imsi = "204300854013739"
374 wrong_imsi = "204300999999999"
375
376 # Lets create one
377 res = self.vty.command('subscriber create imsi '+imsi)
378 self.assert_(res.find(" IMSI: "+imsi) > 0)
379
380 self.vty.verify('subscriber imsi '+wrong_imsi+' name wrong', ['% No subscriber found for imsi '+wrong_imsi])
381 res = self.vty.command('subscriber imsi '+imsi+' name '+('X' * 160))
382 self.assert_(res.find("NAME is too long") > 0)
383
384 self.vty.verify('subscriber imsi '+imsi+' name '+('G' * 159), [''])
385
386 self.vty.verify('subscriber imsi '+wrong_imsi+' extension 840', ['% No subscriber found for imsi '+wrong_imsi])
387 res = self.vty.command('subscriber imsi '+imsi+' extension '+('9' * 15))
388 self.assert_(res.find("EXTENSION is too long") > 0)
389
390 self.vty.verify('subscriber imsi '+imsi+' extension '+('1' * 14), [''])
391
392 # Delete it
393 res = self.vty.command('subscriber delete imsi '+imsi)
394 self.assert_(res != "")
395
Holger Hans Peter Freytherec37bb22013-02-05 09:39:09 +0100396 def testShowPagingGroup(self):
397 res = self.vty.command("show paging-group 255 1234567")
398 self.assertEqual(res, "% can't find BTS 255")
399 res = self.vty.command("show paging-group 0 1234567")
400 self.assertEquals(res, "%Paging group for IMSI 1234567 on BTS #0 is 7")
401
Ciabyec6e4f82014-03-06 17:20:55 +0100402 def testShowNetwork(self):
403 res = self.vty.command("show network")
404 self.assert_(res.startswith('BSC is on Country Code') >= 0)
405
Holger Hans Peter Freyther86573262015-01-31 09:47:37 +0100406 def testMeasurementFeed(self):
407 self.vty.enable()
408 self.vty.command("configure terminal")
409 self.vty.command("mncc-int")
410
411 res = self.vty.command("write terminal")
412 self.assertEquals(res.find('meas-feed scenario'), -1)
413
414 self.vty.command("meas-feed scenario bla")
415 res = self.vty.command("write terminal")
416 self.assert_(res.find('meas-feed scenario bla') > 0)
417
418 self.vty.command("meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890")
419 res = self.vty.command("write terminal")
420 self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890'), -1)
421 self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz012345'), -1)
422 self.assert_(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234') > 0)
423
424
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200425class TestVTYBSC(TestVTYGenericBSC):
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200426
427 def vty_command(self):
428 return ["./src/osmo-bsc/osmo-bsc", "-c",
429 "doc/examples/osmo-bsc/osmo-bsc.cfg"]
430
431 def vty_app(self):
432 return (4242, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc")
433
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200434 def testConfigNetworkTree(self):
Jacob Erlbeck75877272013-10-23 11:24:14 +0200435 self._testConfigNetworkTree()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200436
437 def testVtyTree(self):
438 self.vty.enable()
439 self.assertTrue(self.vty.verify("configure terminal", ['']))
440 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100441 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200442 self.assertTrue(self.vty.verify("msc 0", ['']))
443 self.assertEquals(self.vty.node(), 'config-msc')
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200444 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200445 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200446 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200447 self.assertTrue(self.vty.verify("bsc", ['']))
448 self.assertEquals(self.vty.node(), 'config-bsc')
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200449 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200450 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200451 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200452 self.assertTrue(self.vty.verify("exit", ['']))
453 self.assertTrue(self.vty.node() is None)
454
455 # Check searching for outer node's commands
456 self.vty.command("configure terminal")
457 self.vty.command('msc 0')
458 self.vty.command("bsc")
459 self.assertEquals(self.vty.node(), 'config-bsc')
460 self.vty.command("msc 0")
461 self.assertEquals(self.vty.node(), 'config-msc')
462
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200463 def testUssdNotificationsMsc(self):
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200464 self.vty.enable()
465 self.vty.command("configure terminal")
466 self.vty.command("msc")
467
468 # Test invalid input
469 self.vty.verify("bsc-msc-lost-text", ['% Command incomplete.'])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200470 self.vty.verify("bsc-welcome-text", ['% Command incomplete.'])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200471 self.vty.verify("bsc-grace-text", ['% Command incomplete.'])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200472
473 # Enable USSD notifications
474 self.vty.verify("bsc-msc-lost-text MSC disconnected", [''])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200475 self.vty.verify("bsc-welcome-text Hello MS", [''])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200476 self.vty.verify("bsc-grace-text In grace period", [''])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200477
478 # Verify settings
479 res = self.vty.command("write terminal")
480 self.assert_(res.find('bsc-msc-lost-text MSC disconnected') > 0)
481 self.assertEquals(res.find('no bsc-msc-lost-text'), -1)
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200482 self.assert_(res.find('bsc-welcome-text Hello MS') > 0)
483 self.assertEquals(res.find('no bsc-welcome-text'), -1)
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200484 self.assert_(res.find('bsc-grace-text In grace period') > 0)
485 self.assertEquals(res.find('no bsc-grace-text'), -1)
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200486
487 # Now disable it..
488 self.vty.verify("no bsc-msc-lost-text", [''])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200489 self.vty.verify("no bsc-welcome-text", [''])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200490 self.vty.verify("no bsc-grace-text", [''])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200491
492 # Verify settings
493 res = self.vty.command("write terminal")
494 self.assertEquals(res.find('bsc-msc-lost-text MSC disconnected'), -1)
495 self.assert_(res.find('no bsc-msc-lost-text') > 0)
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200496 self.assertEquals(res.find('bsc-welcome-text Hello MS'), -1)
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200497 self.assert_(res.find('no bsc-welcome-text') > 0)
498 self.assertEquals(res.find('bsc-grace-text In grace period'), -1)
499 self.assert_(res.find('no bsc-grace-text') > 0)
500
501 def testUssdNotificationsBsc(self):
502 self.vty.enable()
503 self.vty.command("configure terminal")
504 self.vty.command("bsc")
505
506 # Test invalid input
507 self.vty.verify("missing-msc-text", ['% Command incomplete.'])
508
509 # Enable USSD notifications
510 self.vty.verify("missing-msc-text No MSC found", [''])
511
512 # Verify settings
513 res = self.vty.command("write terminal")
514 self.assert_(res.find('missing-msc-text No MSC found') > 0)
515 self.assertEquals(res.find('no missing-msc-text'), -1)
516
517 # Now disable it..
518 self.vty.verify("no missing-msc-text", [''])
519
520 # Verify settings
521 res = self.vty.command("write terminal")
522 self.assertEquals(res.find('missing-msc-text No MSC found'), -1)
523 self.assert_(res.find('no missing-msc-text') > 0)
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200524
Jacob Erlbeck946d1412013-09-17 13:59:29 +0200525 def testNetworkTimezone(self):
526 self.vty.enable()
527 self.vty.verify("configure terminal", [''])
528 self.vty.verify("network", [''])
529 self.vty.verify("bts 0", [''])
530
531 # Test invalid input
532 self.vty.verify("timezone", ['% Command incomplete.'])
533 self.vty.verify("timezone 20 0", ['% Unknown command.'])
534 self.vty.verify("timezone 0 11", ['% Unknown command.'])
535 self.vty.verify("timezone 0 0 99", ['% Unknown command.'])
536
537 # Set time zone without DST
538 self.vty.verify("timezone 2 30", [''])
539
540 # Verify settings
541 res = self.vty.command("write terminal")
542 self.assert_(res.find('timezone 2 30') > 0)
543 self.assertEquals(res.find('timezone 2 30 '), -1)
544
545 # Set time zone with DST
546 self.vty.verify("timezone 2 30 1", [''])
547
548 # Verify settings
549 res = self.vty.command("write terminal")
550 self.assert_(res.find('timezone 2 30 1') > 0)
551
552 # Now disable it..
553 self.vty.verify("no timezone", [''])
554
555 # Verify settings
556 res = self.vty.command("write terminal")
557 self.assertEquals(res.find(' timezone'), -1)
558
Ciabyec6e4f82014-03-06 17:20:55 +0100559 def testShowNetwork(self):
560 res = self.vty.command("show network")
561 self.assert_(res.startswith('BSC is on Country Code') >= 0)
562
Holger Hans Peter Freytherdb64f2e2014-10-29 10:06:15 +0100563 def testPingPongConfiguration(self):
564 self.vty.enable()
565 self.vty.verify("configure terminal", [''])
566 self.vty.verify("network", [''])
567 self.vty.verify("msc 0", [''])
568
569 self.vty.verify("timeout-ping 12", [''])
570 self.vty.verify("timeout-pong 14", [''])
571 res = self.vty.command("show running-config")
572 self.assert_(res.find(" timeout-ping 12") > 0)
573 self.assert_(res.find(" timeout-pong 14") > 0)
574 self.assert_(res.find(" no timeout-ping advanced") > 0)
575
576 self.vty.verify("timeout-ping advanced", [''])
577 res = self.vty.command("show running-config")
578 self.assert_(res.find(" timeout-ping 12") > 0)
579 self.assert_(res.find(" timeout-pong 14") > 0)
580 self.assert_(res.find(" timeout-ping advanced") > 0)
581
582 self.vty.verify("no timeout-ping advanced", [''])
583 res = self.vty.command("show running-config")
584 self.assert_(res.find(" timeout-ping 12") > 0)
585 self.assert_(res.find(" timeout-pong 14") > 0)
586 self.assert_(res.find(" no timeout-ping advanced") > 0)
587
588 self.vty.verify("no timeout-ping", [''])
589 res = self.vty.command("show running-config")
590 self.assertEquals(res.find(" timeout-ping 12"), -1)
591 self.assertEquals(res.find(" timeout-pong 14"), -1)
592 self.assertEquals(res.find(" no timeout-ping advanced"), -1)
593 self.assert_(res.find(" no timeout-ping") > 0)
594
595 self.vty.verify("timeout-ping advanced", ['%ping handling is disabled. Enable it first.'])
596
597 # And back to enabling it
598 self.vty.verify("timeout-ping 12", [''])
599 self.vty.verify("timeout-pong 14", [''])
600 res = self.vty.command("show running-config")
601 self.assert_(res.find(" timeout-ping 12") > 0)
602 self.assert_(res.find(" timeout-pong 14") > 0)
603 self.assert_(res.find(" timeout-ping advanced") > 0)
604
Holger Hans Peter Freyther32dd2f32015-04-01 18:15:48 +0200605 def testMscDataCoreLACCI(self):
606 self.vty.enable()
607 res = self.vty.command("show running-config")
608 self.assertEquals(res.find("core-location-area-code"), -1)
609 self.assertEquals(res.find("core-cell-identity"), -1)
610
611 self.vty.command("configure terminal")
612 self.vty.command("msc 0")
613 self.vty.command("core-location-area-code 666")
614 self.vty.command("core-cell-identity 333")
615
616 res = self.vty.command("show running-config")
617 self.assert_(res.find("core-location-area-code 666") > 0)
618 self.assert_(res.find("core-cell-identity 333") > 0)
619
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200620class TestVTYNAT(TestVTYGenericBSC):
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200621
622 def vty_command(self):
Max49364482016-04-13 11:36:39 +0200623 return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-l", "127.0.0.1", "-c",
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200624 "doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"]
625
626 def vty_app(self):
627 return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat")
628
Max49364482016-04-13 11:36:39 +0200629 def testBSCreload(self):
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -0400630 # Use different port for the mock msc to avoid clashing with
631 # the osmo-bsc_nat itself
Holger Hans Peter Freytherf1a61bb2016-04-14 08:50:25 -0400632 ip = "127.0.0.1"
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -0400633 port = 5001
Max49364482016-04-13 11:36:39 +0200634 self.vty.enable()
635 bscs1 = self.vty.command("show bscs-config")
636 nat_bsc_reload(self)
637 bscs2 = self.vty.command("show bscs-config")
638 # check that multiple calls to bscs-config-file give the same result
639 self.assertEquals(bscs1, bscs2)
640
641 # add new bsc
642 self.vty.command("configure terminal")
643 self.vty.command("nat")
644 self.vty.command("bsc 5")
645 self.vty.command("token key")
646 self.vty.command("location_area_code 666")
647 self.vty.command("end")
648
649 # update bsc token
650 self.vty.command("configure terminal")
651 self.vty.command("nat")
652 self.vty.command("bsc 1")
653 self.vty.command("token xyu")
654 self.vty.command("end")
655
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -0400656 nat_msc_ip(self, ip, port)
657 msc = nat_msc_test(self, ip, port)
Max49364482016-04-13 11:36:39 +0200658 b0 = nat_bsc_sock_test(0, "lol")
659 b1 = nat_bsc_sock_test(1, "xyu")
660 b2 = nat_bsc_sock_test(5, "key")
661
662 self.assertEquals("3 BSCs configured", self.vty.command("show nat num-bscs-configured"))
663 self.assertTrue(3 == nat_bsc_num_con(self))
664 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
665
666 nat_bsc_reload(self)
667 bscs2 = self.vty.command("show bscs-config")
668 # check that the reset to initial config succeeded
669 self.assertEquals(bscs1, bscs2)
670
671 self.assertEquals("2 BSCs configured", self.vty.command("show nat num-bscs-configured"))
672 self.assertTrue(1 == nat_bsc_num_con(self))
673 rem = self.vty.command("show bsc connections").split(' ')
674 # remaining connection is for BSC0
675 self.assertEquals('0', rem[2])
676 # remaining connection is authorized
677 self.assertEquals('1', rem[4])
678 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
679
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200680 def testVtyTree(self):
681 self.vty.enable()
682 self.assertTrue(self.vty.verify('configure terminal', ['']))
683 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100684 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200685 self.assertTrue(self.vty.verify('mgcp', ['']))
686 self.assertEquals(self.vty.node(), 'config-mgcp')
687 self.checkForEndAndExit()
688 self.assertTrue(self.vty.verify('exit', ['']))
689 self.assertEquals(self.vty.node(), 'config')
690 self.assertTrue(self.vty.verify('nat', ['']))
691 self.assertEquals(self.vty.node(), 'config-nat')
692 self.checkForEndAndExit()
693 self.assertTrue(self.vty.verify('bsc 0', ['']))
694 self.assertEquals(self.vty.node(), 'config-nat-bsc')
695 self.checkForEndAndExit()
696 self.assertTrue(self.vty.verify('exit', ['']))
697 self.assertEquals(self.vty.node(), 'config-nat')
698 self.assertTrue(self.vty.verify('exit', ['']))
699 self.assertEquals(self.vty.node(), 'config')
700 self.assertTrue(self.vty.verify('exit', ['']))
701 self.assertTrue(self.vty.node() is None)
702
703 # Check searching for outer node's commands
704 self.vty.command('configure terminal')
705 self.vty.command('mgcp')
706 self.vty.command('nat')
707 self.assertEquals(self.vty.node(), 'config-nat')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200708 self.vty.command('mgcp')
709 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200710 self.vty.command('nat')
711 self.assertEquals(self.vty.node(), 'config-nat')
712 self.vty.command('bsc 0')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200713 self.vty.command('mgcp')
714 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200715
Holger Hans Peter Freytherb718ad32013-06-25 09:08:02 +0200716 def testRewriteNoRewrite(self):
717 self.vty.enable()
718 res = self.vty.command("configure terminal")
719 res = self.vty.command("nat")
720 res = self.vty.command("number-rewrite rewrite.cfg")
721 res = self.vty.command("no number-rewrite")
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200722
Holger Hans Peter Freyther7f100c92015-04-23 20:25:17 -0400723 def testEnsureNoEnsureModeSet(self):
724 self.vty.enable()
725 res = self.vty.command("configure terminal")
726 res = self.vty.command("nat")
727
728 # Ensure the default
729 res = self.vty.command("show running-config")
730 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
731
732 self.vty.command("sdp-ensure-amr-mode-set")
733 res = self.vty.command("show running-config")
734 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
735
736 self.vty.command("no sdp-ensure-amr-mode-set")
737 res = self.vty.command("show running-config")
738 self.assert_(res.find('\n no sdp-ensure-amr-mode-set') > 0)
739
Holger Hans Peter Freyther67e423c2013-06-25 15:38:31 +0200740 def testRewritePostNoRewrite(self):
741 self.vty.enable()
742 self.vty.command("configure terminal")
743 self.vty.command("nat")
744 self.vty.verify("number-rewrite-post rewrite.cfg", [''])
745 self.vty.verify("no number-rewrite-post", [''])
746
747
Holger Hans Peter Freytherddf191e2013-06-25 11:44:01 +0200748 def testPrefixTreeLoading(self):
749 cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv")
750
751 self.vty.enable()
752 self.vty.command("configure terminal")
753 self.vty.command("nat")
754 res = self.vty.command("prefix-tree %s" % cfg)
755 self.assertEqual(res, "% prefix-tree loaded 17 rules.")
756 self.vty.command("end")
757
758 res = self.vty.command("show prefix-tree")
759 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')
760
761 self.vty.command("configure terminal")
762 self.vty.command("nat")
763 self.vty.command("no prefix-tree")
764 self.vty.command("end")
765
766 res = self.vty.command("show prefix-tree")
767 self.assertEqual(res, "% there is now prefix tree loaded.")
768
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200769 def testUssdSideChannelProvider(self):
770 self.vty.command("end")
771 self.vty.enable()
772 self.vty.command("configure terminal")
773 self.vty.command("nat")
774 self.vty.command("ussd-token key")
775 self.vty.command("end")
776
777 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
778 self.assertTrue(res)
779
780 ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
781 ussdSocket.connect(('127.0.0.1', 5001))
782 ussdSocket.settimeout(2.0)
783 print "Connected to %s:%d" % ussdSocket.getpeername()
784
785 print "Expecting ID_GET request"
786 data = ussdSocket.recv(4)
787 self.assertEqual(data, "\x00\x01\xfe\x04")
788
789 print "Going to send ID_RESP response"
Max70cf7292016-04-13 11:36:38 +0200790 res = ipa_send_resp(ussdSocket, "\x6b\x65\x79")
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200791 self.assertEqual(res, 10)
792
793 # initiating PING/PONG cycle to know, that the ID_RESP message has been processed
794
795 print "Going to send PING request"
Max70cf7292016-04-13 11:36:38 +0200796 res = ipa_send_ping(ussdSocket)
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200797 self.assertEqual(res, 4)
798
799 print "Expecting PONG response"
800 data = ussdSocket.recv(4)
801 self.assertEqual(data, "\x00\x01\xfe\x01")
802
803 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.'])
804 self.assertTrue(res)
805
806 print "Going to shut down connection"
807 ussdSocket.shutdown(socket.SHUT_WR)
808
809 print "Expecting EOF"
810 data = ussdSocket.recv(4)
811 self.assertEqual(data, "")
812
813 ussdSocket.close()
814
815 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
816 self.assertTrue(res)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200817
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100818 def testAccessList(self):
819 """
820 Verify that the imsi-deny can have a reject cause or no reject cause
821 """
822 self.vty.enable()
823 self.vty.command("configure terminal")
824 self.vty.command("nat")
825
826 # Old default
827 self.vty.command("access-list test-default imsi-deny ^123[0-9]*$")
828 res = self.vty.command("show running-config").split("\r\n")
829 asserted = False
830 for line in res:
Holger Hans Peter Freyther4ecc6872014-03-04 15:38:00 +0100831 if line.startswith(" access-list test-default"):
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100832 self.assertEqual(line, " access-list test-default imsi-deny ^123[0-9]*$ 11 11")
833 asserted = True
834 self.assert_(asserted)
835
836 # Check the optional CM Service Reject Cause
837 self.vty.command("access-list test-cm-deny imsi-deny ^123[0-9]*$ 42").split("\r\n")
838 res = self.vty.command("show running-config").split("\r\n")
839 asserted = False
840 for line in res:
841 if line.startswith(" access-list test-cm"):
842 self.assertEqual(line, " access-list test-cm-deny imsi-deny ^123[0-9]*$ 42 11")
843 asserted = True
844 self.assert_(asserted)
845
846 # Check the optional LU Reject Cause
847 self.vty.command("access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42").split("\r\n")
848 res = self.vty.command("show running-config").split("\r\n")
849 asserted = False
850 for line in res:
851 if line.startswith(" access-list test-lu"):
852 self.assertEqual(line, " access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42")
853 asserted = True
854 self.assert_(asserted)
855
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200856class TestVTYGbproxy(TestVTYGenericBSC):
857
858 def vty_command(self):
859 return ["./src/gprs/osmo-gbproxy", "-c",
860 "doc/examples/osmo-gbproxy/osmo-gbproxy.cfg"]
861
862 def vty_app(self):
863 return (4246, "./src/gprs/osmo-gbproxy", "OsmoGbProxy", "bsc")
864
865 def testVtyTree(self):
866 self.vty.enable()
867 self.assertTrue(self.vty.verify('configure terminal', ['']))
868 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100869 self.checkForEndAndExit()
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200870 self.assertTrue(self.vty.verify('ns', ['']))
871 self.assertEquals(self.vty.node(), 'config-ns')
872 self.checkForEndAndExit()
873 self.assertTrue(self.vty.verify('exit', ['']))
874 self.assertEquals(self.vty.node(), 'config')
875 self.assertTrue(self.vty.verify('gbproxy', ['']))
876 self.assertEquals(self.vty.node(), 'config-gbproxy')
877 self.checkForEndAndExit()
878 self.assertTrue(self.vty.verify('exit', ['']))
879 self.assertEquals(self.vty.node(), 'config')
880
881 def testVtyShow(self):
882 res = self.vty.command("show ns")
883 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
884
885 res = self.vty.command("show gbproxy stats")
886 self.assert_(res.find('GBProxy Global Statistics') >= 0)
887
Jacob Erlbeck4211d792013-10-24 12:48:23 +0200888 def testVtyDeletePeer(self):
889 self.vty.enable()
890 self.assertTrue(self.vty.verify('delete-gbproxy-peer 9999 bvci 7777', ['BVC not found']))
891 res = self.vty.command("delete-gbproxy-peer 9999 all dry-run")
892 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
893 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
894 res = self.vty.command("delete-gbproxy-peer 9999 only-bvc dry-run")
895 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
896 self.assert_(res.find('Not Deleted 0 NS-VC') < 0)
897 res = self.vty.command("delete-gbproxy-peer 9999 only-nsvc dry-run")
898 self.assert_(res.find('Not Deleted 0 BVC') < 0)
899 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
900 res = self.vty.command("delete-gbproxy-peer 9999 all")
901 self.assert_(res.find('Deleted 0 BVC') >= 0)
902 self.assert_(res.find('Deleted 0 NS-VC') >= 0)
903
Jacob Erlbeck144b8b12014-11-04 11:15:01 +0100904class TestVTYSGSN(TestVTYGenericBSC):
905
906 def vty_command(self):
907 return ["./src/gprs/osmo-sgsn", "-c",
908 "doc/examples/osmo-sgsn/osmo-sgsn.cfg"]
909
910 def vty_app(self):
911 return (4245, "./src/gprs/osmo-sgsn", "OsmoSGSN", "sgsn")
912
913 def testVtyTree(self):
914 self.vty.enable()
915 self.assertTrue(self.vty.verify('configure terminal', ['']))
916 self.assertEquals(self.vty.node(), 'config')
917 self.checkForEndAndExit()
918 self.assertTrue(self.vty.verify('ns', ['']))
919 self.assertEquals(self.vty.node(), 'config-ns')
920 self.checkForEndAndExit()
921 self.assertTrue(self.vty.verify('exit', ['']))
922 self.assertEquals(self.vty.node(), 'config')
923 self.assertTrue(self.vty.verify('sgsn', ['']))
924 self.assertEquals(self.vty.node(), 'config-sgsn')
925 self.checkForEndAndExit()
926 self.assertTrue(self.vty.verify('exit', ['']))
927 self.assertEquals(self.vty.node(), 'config')
928
929 def testVtyShow(self):
930 res = self.vty.command("show ns")
931 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
932 self.assertTrue(self.vty.verify('show bssgp', ['']))
933 self.assertTrue(self.vty.verify('show bssgp stats', ['']))
934 # TODO: uncomment when the command does not segfault anymore
935 # self.assertTrue(self.vty.verify('show bssgp nsei 123', ['']))
936 # self.assertTrue(self.vty.verify('show bssgp nsei 123 stats', ['']))
937
938 self.assertTrue(self.vty.verify('show sgsn', ['']))
939 self.assertTrue(self.vty.verify('show mm-context all', ['']))
940 self.assertTrue(self.vty.verify('show mm-context imsi 000001234567', ['No MM context for IMSI 000001234567']))
941 self.assertTrue(self.vty.verify('show pdp-context all', ['']))
942
943 res = self.vty.command("show sndcp")
944 self.assert_(res.find('State of SNDCP Entities') >= 0)
945
946 res = self.vty.command("show llc")
947 self.assert_(res.find('State of LLC Entities') >= 0)
948
Jacob Erlbeck106f5472014-11-04 10:08:37 +0100949 def testVtyAuth(self):
950 self.vty.enable()
951 self.assertTrue(self.vty.verify('configure terminal', ['']))
952 self.assertEquals(self.vty.node(), 'config')
953 self.assertTrue(self.vty.verify('sgsn', ['']))
954 self.assertEquals(self.vty.node(), 'config-sgsn')
955 self.assertTrue(self.vty.verify('auth-policy accept-all', ['']))
956 res = self.vty.command("show running-config")
957 self.assert_(res.find('auth-policy accept-all') > 0)
958 self.assertTrue(self.vty.verify('auth-policy acl-only', ['']))
959 res = self.vty.command("show running-config")
960 self.assert_(res.find('auth-policy acl-only') > 0)
961 self.assertTrue(self.vty.verify('auth-policy closed', ['']))
962 res = self.vty.command("show running-config")
963 self.assert_(res.find('auth-policy closed') > 0)
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +0100964 self.assertTrue(self.vty.verify('auth-policy remote', ['']))
965 res = self.vty.command("show running-config")
966 self.assert_(res.find('auth-policy remote') > 0)
Jacob Erlbeck106f5472014-11-04 10:08:37 +0100967
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100968 def testVtySubscriber(self):
969 self.vty.enable()
970 res = self.vty.command('show subscriber cache')
971 self.assert_(res.find('1234567890') < 0)
Jacob Erlbeckd9193432015-01-19 14:11:46 +0100972 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 create', ['']))
973 res = self.vty.command('show subscriber cache')
974 self.assert_(res.find('1234567890') >= 0)
975 self.assert_(res.find('Authorized: 0') >= 0)
976 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 update-location-result ok', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100977 res = self.vty.command('show subscriber cache')
978 self.assert_(res.find('1234567890') >= 0)
979 self.assert_(res.find('Authorized: 1') >= 0)
Jacob Erlbeck8000e0e2015-01-27 14:56:40 +0100980 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 cancel update-procedure', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100981 res = self.vty.command('show subscriber cache')
Jacob Erlbecke988ae42015-01-27 12:41:19 +0100982 self.assert_(res.find('1234567890') >= 0)
983 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 destroy', ['']))
984 res = self.vty.command('show subscriber cache')
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100985 self.assert_(res.find('1234567890') < 0)
986
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +0100987 def testVtyGgsn(self):
988 self.vty.enable()
989 self.assertTrue(self.vty.verify('configure terminal', ['']))
990 self.assertEquals(self.vty.node(), 'config')
991 self.assertTrue(self.vty.verify('sgsn', ['']))
992 self.assertEquals(self.vty.node(), 'config-sgsn')
993 self.assertTrue(self.vty.verify('ggsn 0 remote-ip 127.99.99.99', ['']))
994 self.assertTrue(self.vty.verify('ggsn 0 gtp-version 1', ['']))
995 self.assertTrue(self.vty.verify('apn * ggsn 0', ['']))
996 self.assertTrue(self.vty.verify('apn apn1.test ggsn 0', ['']))
997 self.assertTrue(self.vty.verify('apn apn1.test ggsn 1', ['% a GGSN with id 1 has not been defined']))
998 self.assertTrue(self.vty.verify('apn apn1.test imsi-prefix 123456 ggsn 0', ['']))
999 self.assertTrue(self.vty.verify('apn apn2.test imsi-prefix 123456 ggsn 0', ['']))
1000 res = self.vty.command("show running-config")
1001 self.assert_(res.find('ggsn 0 remote-ip 127.99.99.99') >= 0)
1002 self.assert_(res.find('ggsn 0 gtp-version 1') >= 0)
1003 self.assert_(res.find('apn * ggsn 0') >= 0)
1004 self.assert_(res.find('apn apn1.test ggsn 0') >= 0)
1005 self.assert_(res.find('apn apn1.test imsi-prefix 123456 ggsn 0') >= 0)
1006 self.assert_(res.find('apn apn2.test imsi-prefix 123456 ggsn 0') >= 0)
1007
Holger Hans Peter Freyther9c20a5f2015-02-06 16:23:29 +01001008 def testVtyEasyAPN(self):
1009 self.vty.enable()
1010 self.assertTrue(self.vty.verify('configure terminal', ['']))
1011 self.assertEquals(self.vty.node(), 'config')
1012 self.assertTrue(self.vty.verify('sgsn', ['']))
1013 self.assertEquals(self.vty.node(), 'config-sgsn')
1014
1015 res = self.vty.command("show running-config")
1016 self.assertEquals(res.find("apn internet"), -1)
1017
1018 self.assertTrue(self.vty.verify("access-point-name internet.apn", ['']))
1019 res = self.vty.command("show running-config")
1020 self.assert_(res.find("apn internet.apn ggsn 0") >= 0)
1021
1022 self.assertTrue(self.vty.verify("no access-point-name internet.apn", ['']))
1023 res = self.vty.command("show running-config")
1024 self.assertEquals(res.find("apn internet"), -1)
1025
Holger Hans Peter Freytherc15c61c2015-05-06 17:46:08 +02001026 def testVtyCDR(self):
1027 self.vty.enable()
1028 self.assertTrue(self.vty.verify('configure terminal', ['']))
1029 self.assertEquals(self.vty.node(), 'config')
1030 self.assertTrue(self.vty.verify('sgsn', ['']))
1031 self.assertEquals(self.vty.node(), 'config-sgsn')
1032
1033 res = self.vty.command("show running-config")
1034 self.assert_(res.find("no cdr filename") > 0)
1035
1036 self.vty.command("cdr filename bla.cdr")
1037 res = self.vty.command("show running-config")
1038 self.assertEquals(res.find("no cdr filename"), -1)
1039 self.assert_(res.find(" cdr filename bla.cdr") > 0)
1040
1041 self.vty.command("no cdr filename")
1042 res = self.vty.command("show running-config")
1043 self.assert_(res.find("no cdr filename") > 0)
1044 self.assertEquals(res.find(" cdr filename bla.cdr"), -1)
1045
1046 res = self.vty.command("show running-config")
1047 self.assert_(res.find(" cdr interval 600") > 0)
1048
1049 self.vty.command("cdr interval 900")
1050 res = self.vty.command("show running-config")
1051 self.assert_(res.find(" cdr interval 900") > 0)
1052 self.assertEquals(res.find(" cdr interval 600"), -1)
1053
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001054def add_nat_test(suite, workdir):
1055 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
1056 print("Skipping the NAT test")
1057 return
1058 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT)
1059 suite.addTest(test)
1060
Max70cf7292016-04-13 11:36:38 +02001061def ipa_send_pong(x, verbose = False):
1062 if (verbose):
1063 print "\tBSC -> NAT: PONG!"
1064 return x.send("\x00\x01\xfe\x01")
1065
1066def ipa_send_ping(x, verbose = False):
1067 if (verbose):
1068 print "\tBSC -> NAT: PING?"
1069 return x.send("\x00\x01\xfe\x00")
1070
1071def ipa_send_ack(x, verbose = False):
1072 if (verbose):
1073 print "\tBSC -> NAT: IPA ID ACK"
1074 return x.send("\x00\x01\xfe\x06")
1075
1076def ipa_send_reset(x, verbose = False):
1077 if (verbose):
1078 print "\tBSC -> NAT: RESET"
1079 return x.send("\x00\x12\xfd\x09\x00\x03\x05\x07\x02\x42\xfe\x02\x42\xfe\x06\x00\x04\x30\x04\x01\x20")
1080
1081def ipa_send_resp(x, tk, verbose = False):
1082 if (verbose):
1083 print "\tBSC -> NAT: IPA ID RESP"
1084 return x.send("\x00\x07\xfe\x05\x00\x04\x01" + tk)
1085
Max49364482016-04-13 11:36:39 +02001086def nat_bsc_reload(x):
1087 x.vty.command("configure terminal")
1088 x.vty.command("nat")
1089 x.vty.command("bscs-config-file bscs.config")
1090 x.vty.command("end")
1091
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001092def nat_msc_ip(x, ip, port):
Max49364482016-04-13 11:36:39 +02001093 x.vty.command("configure terminal")
1094 x.vty.command("nat")
1095 x.vty.command("msc ip " + ip)
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001096 x.vty.command("msc port " + port)
Max49364482016-04-13 11:36:39 +02001097 x.vty.command("end")
1098
1099def data2str(d):
1100 return "".join("{:02x}".format(ord(c)) for c in d)
1101
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001102def nat_msc_test(x, ip, port, verbose = False):
Max49364482016-04-13 11:36:39 +02001103 msc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1104 msc.settimeout(32)
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001105 msc.bind((ip, port))
Max49364482016-04-13 11:36:39 +02001106 msc.listen(5)
1107 if (verbose):
1108 print "MSC is ready at " + ip
1109 while "MSC is connected: 0" == x.vty.command("show msc connection"):
1110 conn, addr = msc.accept()
1111 if (verbose):
1112 print "MSC got connection from ", addr
1113 return conn
1114
1115def ipa_handle_small(x, verbose = False):
1116 s = data2str(x.recv(4))
1117 if "0001fe00" == s:
1118 if (verbose):
1119 print "\tBSC <- NAT: PING?"
1120 ipa_send_pong(x, verbose)
1121 elif "0001fe06" == s:
1122 if (verbose):
1123 print "\tBSC <- NAT: IPA ID ACK"
1124 ipa_send_ack(x, verbose)
1125 elif "0001fe00" == s:
1126 if (verbose):
1127 print "\tBSC <- NAT: PONG!"
1128 else:
1129 if (verbose):
1130 print "\tBSC <- NAT: ", s
1131
1132def ipa_handle_resp(x, tk, verbose = False):
1133 s = data2str(x.recv(38))
1134 if "0023fe040108010701020103010401050101010011" in s:
1135 ipa_send_resp(x, tk, verbose)
1136 else:
1137 if (verbose):
1138 print "\tBSC <- NAT: ", s
1139
1140def nat_bsc_num_con(x):
1141 return len(x.vty.command("show bsc connections").split('\n'))
1142
1143def nat_bsc_sock_test(nr, tk, verbose = False):
1144 bsc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1145 bsc.bind(('127.0.0.1' + str(nr), 0))
1146 bsc.connect(('127.0.0.1', 5000))
1147 if (verbose):
1148 print "BSC%d " %nr
1149 print "\tconnected to %s:%d" % bsc.getpeername()
1150 ipa_handle_small(bsc, verbose)
1151 ipa_handle_resp(bsc, tk, verbose)
1152 bsc.recv(27) # MGCP msg
1153 ipa_handle_small(bsc, verbose)
1154 return bsc
1155
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001156def add_bsc_test(suite, workdir):
1157 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")):
1158 print("Skipping the BSC test")
1159 return
1160 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC)
1161 suite.addTest(test)
1162
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001163def add_gbproxy_test(suite, workdir):
1164 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-gbproxy")):
1165 print("Skipping the Gb-Proxy test")
1166 return
1167 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYGbproxy)
1168 suite.addTest(test)
1169
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001170def add_sgsn_test(suite, workdir):
1171 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-sgsn")):
1172 print("Skipping the SGSN test")
1173 return
1174 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYSGSN)
1175 suite.addTest(test)
1176
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001177if __name__ == '__main__':
1178 import argparse
1179 import sys
1180
1181 workdir = '.'
1182
1183 parser = argparse.ArgumentParser()
1184 parser.add_argument("-v", "--verbose", dest="verbose",
1185 action="store_true", help="verbose mode")
1186 parser.add_argument("-p", "--pythonconfpath", dest="p",
1187 help="searchpath for config")
1188 parser.add_argument("-w", "--workdir", dest="w",
1189 help="Working directory")
1190 args = parser.parse_args()
1191
1192 verbose_level = 1
1193 if args.verbose:
1194 verbose_level = 2
1195
1196 if args.w:
1197 workdir = args.w
1198
1199 if args.p:
1200 confpath = args.p
1201
1202 print "confpath %s, workdir %s" % (confpath, workdir)
1203 os.chdir(workdir)
1204 print "Running tests for specific VTY commands"
1205 suite = unittest.TestSuite()
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +02001206 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYMGCP))
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +02001207 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB))
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001208 add_bsc_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001209 add_nat_test(suite, workdir)
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001210 add_gbproxy_test(suite, workdir)
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001211 add_sgsn_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001212 res = unittest.TextTestRunner(verbosity=verbose_level).run(suite)
1213 sys.exit(len(res.errors) + len(res.failures))