blob: 11b788bccfdffb3cdb4243e226ae23e703449b36 [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 Freytherf1a61bb2016-04-14 08:50:25 -0400630 ip = "127.0.0.1"
Max49364482016-04-13 11:36:39 +0200631 self.vty.enable()
632 bscs1 = self.vty.command("show bscs-config")
633 nat_bsc_reload(self)
634 bscs2 = self.vty.command("show bscs-config")
635 # check that multiple calls to bscs-config-file give the same result
636 self.assertEquals(bscs1, bscs2)
637
638 # add new bsc
639 self.vty.command("configure terminal")
640 self.vty.command("nat")
641 self.vty.command("bsc 5")
642 self.vty.command("token key")
643 self.vty.command("location_area_code 666")
644 self.vty.command("end")
645
646 # update bsc token
647 self.vty.command("configure terminal")
648 self.vty.command("nat")
649 self.vty.command("bsc 1")
650 self.vty.command("token xyu")
651 self.vty.command("end")
652
653 nat_msc_ip(self, ip)
654 msc = nat_msc_test(self, ip)
655 b0 = nat_bsc_sock_test(0, "lol")
656 b1 = nat_bsc_sock_test(1, "xyu")
657 b2 = nat_bsc_sock_test(5, "key")
658
659 self.assertEquals("3 BSCs configured", self.vty.command("show nat num-bscs-configured"))
660 self.assertTrue(3 == nat_bsc_num_con(self))
661 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
662
663 nat_bsc_reload(self)
664 bscs2 = self.vty.command("show bscs-config")
665 # check that the reset to initial config succeeded
666 self.assertEquals(bscs1, bscs2)
667
668 self.assertEquals("2 BSCs configured", self.vty.command("show nat num-bscs-configured"))
669 self.assertTrue(1 == nat_bsc_num_con(self))
670 rem = self.vty.command("show bsc connections").split(' ')
671 # remaining connection is for BSC0
672 self.assertEquals('0', rem[2])
673 # remaining connection is authorized
674 self.assertEquals('1', rem[4])
675 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
676
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200677 def testVtyTree(self):
678 self.vty.enable()
679 self.assertTrue(self.vty.verify('configure terminal', ['']))
680 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100681 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200682 self.assertTrue(self.vty.verify('mgcp', ['']))
683 self.assertEquals(self.vty.node(), 'config-mgcp')
684 self.checkForEndAndExit()
685 self.assertTrue(self.vty.verify('exit', ['']))
686 self.assertEquals(self.vty.node(), 'config')
687 self.assertTrue(self.vty.verify('nat', ['']))
688 self.assertEquals(self.vty.node(), 'config-nat')
689 self.checkForEndAndExit()
690 self.assertTrue(self.vty.verify('bsc 0', ['']))
691 self.assertEquals(self.vty.node(), 'config-nat-bsc')
692 self.checkForEndAndExit()
693 self.assertTrue(self.vty.verify('exit', ['']))
694 self.assertEquals(self.vty.node(), 'config-nat')
695 self.assertTrue(self.vty.verify('exit', ['']))
696 self.assertEquals(self.vty.node(), 'config')
697 self.assertTrue(self.vty.verify('exit', ['']))
698 self.assertTrue(self.vty.node() is None)
699
700 # Check searching for outer node's commands
701 self.vty.command('configure terminal')
702 self.vty.command('mgcp')
703 self.vty.command('nat')
704 self.assertEquals(self.vty.node(), 'config-nat')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200705 self.vty.command('mgcp')
706 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200707 self.vty.command('nat')
708 self.assertEquals(self.vty.node(), 'config-nat')
709 self.vty.command('bsc 0')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200710 self.vty.command('mgcp')
711 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200712
Holger Hans Peter Freytherb718ad32013-06-25 09:08:02 +0200713 def testRewriteNoRewrite(self):
714 self.vty.enable()
715 res = self.vty.command("configure terminal")
716 res = self.vty.command("nat")
717 res = self.vty.command("number-rewrite rewrite.cfg")
718 res = self.vty.command("no number-rewrite")
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200719
Holger Hans Peter Freyther7f100c92015-04-23 20:25:17 -0400720 def testEnsureNoEnsureModeSet(self):
721 self.vty.enable()
722 res = self.vty.command("configure terminal")
723 res = self.vty.command("nat")
724
725 # Ensure the default
726 res = self.vty.command("show running-config")
727 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
728
729 self.vty.command("sdp-ensure-amr-mode-set")
730 res = self.vty.command("show running-config")
731 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
732
733 self.vty.command("no sdp-ensure-amr-mode-set")
734 res = self.vty.command("show running-config")
735 self.assert_(res.find('\n no sdp-ensure-amr-mode-set') > 0)
736
Holger Hans Peter Freyther67e423c2013-06-25 15:38:31 +0200737 def testRewritePostNoRewrite(self):
738 self.vty.enable()
739 self.vty.command("configure terminal")
740 self.vty.command("nat")
741 self.vty.verify("number-rewrite-post rewrite.cfg", [''])
742 self.vty.verify("no number-rewrite-post", [''])
743
744
Holger Hans Peter Freytherddf191e2013-06-25 11:44:01 +0200745 def testPrefixTreeLoading(self):
746 cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv")
747
748 self.vty.enable()
749 self.vty.command("configure terminal")
750 self.vty.command("nat")
751 res = self.vty.command("prefix-tree %s" % cfg)
752 self.assertEqual(res, "% prefix-tree loaded 17 rules.")
753 self.vty.command("end")
754
755 res = self.vty.command("show prefix-tree")
756 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')
757
758 self.vty.command("configure terminal")
759 self.vty.command("nat")
760 self.vty.command("no prefix-tree")
761 self.vty.command("end")
762
763 res = self.vty.command("show prefix-tree")
764 self.assertEqual(res, "% there is now prefix tree loaded.")
765
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200766 def testUssdSideChannelProvider(self):
767 self.vty.command("end")
768 self.vty.enable()
769 self.vty.command("configure terminal")
770 self.vty.command("nat")
771 self.vty.command("ussd-token key")
772 self.vty.command("end")
773
774 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
775 self.assertTrue(res)
776
777 ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
778 ussdSocket.connect(('127.0.0.1', 5001))
779 ussdSocket.settimeout(2.0)
780 print "Connected to %s:%d" % ussdSocket.getpeername()
781
782 print "Expecting ID_GET request"
783 data = ussdSocket.recv(4)
784 self.assertEqual(data, "\x00\x01\xfe\x04")
785
786 print "Going to send ID_RESP response"
Max70cf7292016-04-13 11:36:38 +0200787 res = ipa_send_resp(ussdSocket, "\x6b\x65\x79")
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200788 self.assertEqual(res, 10)
789
790 # initiating PING/PONG cycle to know, that the ID_RESP message has been processed
791
792 print "Going to send PING request"
Max70cf7292016-04-13 11:36:38 +0200793 res = ipa_send_ping(ussdSocket)
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200794 self.assertEqual(res, 4)
795
796 print "Expecting PONG response"
797 data = ussdSocket.recv(4)
798 self.assertEqual(data, "\x00\x01\xfe\x01")
799
800 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.'])
801 self.assertTrue(res)
802
803 print "Going to shut down connection"
804 ussdSocket.shutdown(socket.SHUT_WR)
805
806 print "Expecting EOF"
807 data = ussdSocket.recv(4)
808 self.assertEqual(data, "")
809
810 ussdSocket.close()
811
812 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
813 self.assertTrue(res)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200814
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100815 def testAccessList(self):
816 """
817 Verify that the imsi-deny can have a reject cause or no reject cause
818 """
819 self.vty.enable()
820 self.vty.command("configure terminal")
821 self.vty.command("nat")
822
823 # Old default
824 self.vty.command("access-list test-default imsi-deny ^123[0-9]*$")
825 res = self.vty.command("show running-config").split("\r\n")
826 asserted = False
827 for line in res:
Holger Hans Peter Freyther4ecc6872014-03-04 15:38:00 +0100828 if line.startswith(" access-list test-default"):
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100829 self.assertEqual(line, " access-list test-default imsi-deny ^123[0-9]*$ 11 11")
830 asserted = True
831 self.assert_(asserted)
832
833 # Check the optional CM Service Reject Cause
834 self.vty.command("access-list test-cm-deny imsi-deny ^123[0-9]*$ 42").split("\r\n")
835 res = self.vty.command("show running-config").split("\r\n")
836 asserted = False
837 for line in res:
838 if line.startswith(" access-list test-cm"):
839 self.assertEqual(line, " access-list test-cm-deny imsi-deny ^123[0-9]*$ 42 11")
840 asserted = True
841 self.assert_(asserted)
842
843 # Check the optional LU Reject Cause
844 self.vty.command("access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42").split("\r\n")
845 res = self.vty.command("show running-config").split("\r\n")
846 asserted = False
847 for line in res:
848 if line.startswith(" access-list test-lu"):
849 self.assertEqual(line, " access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42")
850 asserted = True
851 self.assert_(asserted)
852
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200853class TestVTYGbproxy(TestVTYGenericBSC):
854
855 def vty_command(self):
856 return ["./src/gprs/osmo-gbproxy", "-c",
857 "doc/examples/osmo-gbproxy/osmo-gbproxy.cfg"]
858
859 def vty_app(self):
860 return (4246, "./src/gprs/osmo-gbproxy", "OsmoGbProxy", "bsc")
861
862 def testVtyTree(self):
863 self.vty.enable()
864 self.assertTrue(self.vty.verify('configure terminal', ['']))
865 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100866 self.checkForEndAndExit()
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200867 self.assertTrue(self.vty.verify('ns', ['']))
868 self.assertEquals(self.vty.node(), 'config-ns')
869 self.checkForEndAndExit()
870 self.assertTrue(self.vty.verify('exit', ['']))
871 self.assertEquals(self.vty.node(), 'config')
872 self.assertTrue(self.vty.verify('gbproxy', ['']))
873 self.assertEquals(self.vty.node(), 'config-gbproxy')
874 self.checkForEndAndExit()
875 self.assertTrue(self.vty.verify('exit', ['']))
876 self.assertEquals(self.vty.node(), 'config')
877
878 def testVtyShow(self):
879 res = self.vty.command("show ns")
880 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
881
882 res = self.vty.command("show gbproxy stats")
883 self.assert_(res.find('GBProxy Global Statistics') >= 0)
884
Jacob Erlbeck4211d792013-10-24 12:48:23 +0200885 def testVtyDeletePeer(self):
886 self.vty.enable()
887 self.assertTrue(self.vty.verify('delete-gbproxy-peer 9999 bvci 7777', ['BVC not found']))
888 res = self.vty.command("delete-gbproxy-peer 9999 all dry-run")
889 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
890 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
891 res = self.vty.command("delete-gbproxy-peer 9999 only-bvc 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-nsvc 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 all")
898 self.assert_(res.find('Deleted 0 BVC') >= 0)
899 self.assert_(res.find('Deleted 0 NS-VC') >= 0)
900
Jacob Erlbeck144b8b12014-11-04 11:15:01 +0100901class TestVTYSGSN(TestVTYGenericBSC):
902
903 def vty_command(self):
904 return ["./src/gprs/osmo-sgsn", "-c",
905 "doc/examples/osmo-sgsn/osmo-sgsn.cfg"]
906
907 def vty_app(self):
908 return (4245, "./src/gprs/osmo-sgsn", "OsmoSGSN", "sgsn")
909
910 def testVtyTree(self):
911 self.vty.enable()
912 self.assertTrue(self.vty.verify('configure terminal', ['']))
913 self.assertEquals(self.vty.node(), 'config')
914 self.checkForEndAndExit()
915 self.assertTrue(self.vty.verify('ns', ['']))
916 self.assertEquals(self.vty.node(), 'config-ns')
917 self.checkForEndAndExit()
918 self.assertTrue(self.vty.verify('exit', ['']))
919 self.assertEquals(self.vty.node(), 'config')
920 self.assertTrue(self.vty.verify('sgsn', ['']))
921 self.assertEquals(self.vty.node(), 'config-sgsn')
922 self.checkForEndAndExit()
923 self.assertTrue(self.vty.verify('exit', ['']))
924 self.assertEquals(self.vty.node(), 'config')
925
926 def testVtyShow(self):
927 res = self.vty.command("show ns")
928 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
929 self.assertTrue(self.vty.verify('show bssgp', ['']))
930 self.assertTrue(self.vty.verify('show bssgp stats', ['']))
931 # TODO: uncomment when the command does not segfault anymore
932 # self.assertTrue(self.vty.verify('show bssgp nsei 123', ['']))
933 # self.assertTrue(self.vty.verify('show bssgp nsei 123 stats', ['']))
934
935 self.assertTrue(self.vty.verify('show sgsn', ['']))
936 self.assertTrue(self.vty.verify('show mm-context all', ['']))
937 self.assertTrue(self.vty.verify('show mm-context imsi 000001234567', ['No MM context for IMSI 000001234567']))
938 self.assertTrue(self.vty.verify('show pdp-context all', ['']))
939
940 res = self.vty.command("show sndcp")
941 self.assert_(res.find('State of SNDCP Entities') >= 0)
942
943 res = self.vty.command("show llc")
944 self.assert_(res.find('State of LLC Entities') >= 0)
945
Jacob Erlbeck106f5472014-11-04 10:08:37 +0100946 def testVtyAuth(self):
947 self.vty.enable()
948 self.assertTrue(self.vty.verify('configure terminal', ['']))
949 self.assertEquals(self.vty.node(), 'config')
950 self.assertTrue(self.vty.verify('sgsn', ['']))
951 self.assertEquals(self.vty.node(), 'config-sgsn')
952 self.assertTrue(self.vty.verify('auth-policy accept-all', ['']))
953 res = self.vty.command("show running-config")
954 self.assert_(res.find('auth-policy accept-all') > 0)
955 self.assertTrue(self.vty.verify('auth-policy acl-only', ['']))
956 res = self.vty.command("show running-config")
957 self.assert_(res.find('auth-policy acl-only') > 0)
958 self.assertTrue(self.vty.verify('auth-policy closed', ['']))
959 res = self.vty.command("show running-config")
960 self.assert_(res.find('auth-policy closed') > 0)
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +0100961 self.assertTrue(self.vty.verify('auth-policy remote', ['']))
962 res = self.vty.command("show running-config")
963 self.assert_(res.find('auth-policy remote') > 0)
Jacob Erlbeck106f5472014-11-04 10:08:37 +0100964
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100965 def testVtySubscriber(self):
966 self.vty.enable()
967 res = self.vty.command('show subscriber cache')
968 self.assert_(res.find('1234567890') < 0)
Jacob Erlbeckd9193432015-01-19 14:11:46 +0100969 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 create', ['']))
970 res = self.vty.command('show subscriber cache')
971 self.assert_(res.find('1234567890') >= 0)
972 self.assert_(res.find('Authorized: 0') >= 0)
973 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 update-location-result ok', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100974 res = self.vty.command('show subscriber cache')
975 self.assert_(res.find('1234567890') >= 0)
976 self.assert_(res.find('Authorized: 1') >= 0)
Jacob Erlbeck8000e0e2015-01-27 14:56:40 +0100977 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 cancel update-procedure', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100978 res = self.vty.command('show subscriber cache')
Jacob Erlbecke988ae42015-01-27 12:41:19 +0100979 self.assert_(res.find('1234567890') >= 0)
980 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 destroy', ['']))
981 res = self.vty.command('show subscriber cache')
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100982 self.assert_(res.find('1234567890') < 0)
983
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +0100984 def testVtyGgsn(self):
985 self.vty.enable()
986 self.assertTrue(self.vty.verify('configure terminal', ['']))
987 self.assertEquals(self.vty.node(), 'config')
988 self.assertTrue(self.vty.verify('sgsn', ['']))
989 self.assertEquals(self.vty.node(), 'config-sgsn')
990 self.assertTrue(self.vty.verify('ggsn 0 remote-ip 127.99.99.99', ['']))
991 self.assertTrue(self.vty.verify('ggsn 0 gtp-version 1', ['']))
992 self.assertTrue(self.vty.verify('apn * ggsn 0', ['']))
993 self.assertTrue(self.vty.verify('apn apn1.test ggsn 0', ['']))
994 self.assertTrue(self.vty.verify('apn apn1.test ggsn 1', ['% a GGSN with id 1 has not been defined']))
995 self.assertTrue(self.vty.verify('apn apn1.test imsi-prefix 123456 ggsn 0', ['']))
996 self.assertTrue(self.vty.verify('apn apn2.test imsi-prefix 123456 ggsn 0', ['']))
997 res = self.vty.command("show running-config")
998 self.assert_(res.find('ggsn 0 remote-ip 127.99.99.99') >= 0)
999 self.assert_(res.find('ggsn 0 gtp-version 1') >= 0)
1000 self.assert_(res.find('apn * ggsn 0') >= 0)
1001 self.assert_(res.find('apn apn1.test ggsn 0') >= 0)
1002 self.assert_(res.find('apn apn1.test imsi-prefix 123456 ggsn 0') >= 0)
1003 self.assert_(res.find('apn apn2.test imsi-prefix 123456 ggsn 0') >= 0)
1004
Holger Hans Peter Freyther9c20a5f2015-02-06 16:23:29 +01001005 def testVtyEasyAPN(self):
1006 self.vty.enable()
1007 self.assertTrue(self.vty.verify('configure terminal', ['']))
1008 self.assertEquals(self.vty.node(), 'config')
1009 self.assertTrue(self.vty.verify('sgsn', ['']))
1010 self.assertEquals(self.vty.node(), 'config-sgsn')
1011
1012 res = self.vty.command("show running-config")
1013 self.assertEquals(res.find("apn internet"), -1)
1014
1015 self.assertTrue(self.vty.verify("access-point-name internet.apn", ['']))
1016 res = self.vty.command("show running-config")
1017 self.assert_(res.find("apn internet.apn ggsn 0") >= 0)
1018
1019 self.assertTrue(self.vty.verify("no access-point-name internet.apn", ['']))
1020 res = self.vty.command("show running-config")
1021 self.assertEquals(res.find("apn internet"), -1)
1022
Holger Hans Peter Freytherc15c61c2015-05-06 17:46:08 +02001023 def testVtyCDR(self):
1024 self.vty.enable()
1025 self.assertTrue(self.vty.verify('configure terminal', ['']))
1026 self.assertEquals(self.vty.node(), 'config')
1027 self.assertTrue(self.vty.verify('sgsn', ['']))
1028 self.assertEquals(self.vty.node(), 'config-sgsn')
1029
1030 res = self.vty.command("show running-config")
1031 self.assert_(res.find("no cdr filename") > 0)
1032
1033 self.vty.command("cdr filename bla.cdr")
1034 res = self.vty.command("show running-config")
1035 self.assertEquals(res.find("no cdr filename"), -1)
1036 self.assert_(res.find(" cdr filename bla.cdr") > 0)
1037
1038 self.vty.command("no cdr filename")
1039 res = self.vty.command("show running-config")
1040 self.assert_(res.find("no cdr filename") > 0)
1041 self.assertEquals(res.find(" cdr filename bla.cdr"), -1)
1042
1043 res = self.vty.command("show running-config")
1044 self.assert_(res.find(" cdr interval 600") > 0)
1045
1046 self.vty.command("cdr interval 900")
1047 res = self.vty.command("show running-config")
1048 self.assert_(res.find(" cdr interval 900") > 0)
1049 self.assertEquals(res.find(" cdr interval 600"), -1)
1050
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001051def add_nat_test(suite, workdir):
1052 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
1053 print("Skipping the NAT test")
1054 return
1055 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT)
1056 suite.addTest(test)
1057
Max70cf7292016-04-13 11:36:38 +02001058def ipa_send_pong(x, verbose = False):
1059 if (verbose):
1060 print "\tBSC -> NAT: PONG!"
1061 return x.send("\x00\x01\xfe\x01")
1062
1063def ipa_send_ping(x, verbose = False):
1064 if (verbose):
1065 print "\tBSC -> NAT: PING?"
1066 return x.send("\x00\x01\xfe\x00")
1067
1068def ipa_send_ack(x, verbose = False):
1069 if (verbose):
1070 print "\tBSC -> NAT: IPA ID ACK"
1071 return x.send("\x00\x01\xfe\x06")
1072
1073def ipa_send_reset(x, verbose = False):
1074 if (verbose):
1075 print "\tBSC -> NAT: RESET"
1076 return x.send("\x00\x12\xfd\x09\x00\x03\x05\x07\x02\x42\xfe\x02\x42\xfe\x06\x00\x04\x30\x04\x01\x20")
1077
1078def ipa_send_resp(x, tk, verbose = False):
1079 if (verbose):
1080 print "\tBSC -> NAT: IPA ID RESP"
1081 return x.send("\x00\x07\xfe\x05\x00\x04\x01" + tk)
1082
Max49364482016-04-13 11:36:39 +02001083def nat_bsc_reload(x):
1084 x.vty.command("configure terminal")
1085 x.vty.command("nat")
1086 x.vty.command("bscs-config-file bscs.config")
1087 x.vty.command("end")
1088
1089def nat_msc_ip(x, ip):
1090 x.vty.command("configure terminal")
1091 x.vty.command("nat")
1092 x.vty.command("msc ip " + ip)
1093 x.vty.command("end")
1094
1095def data2str(d):
1096 return "".join("{:02x}".format(ord(c)) for c in d)
1097
1098def nat_msc_test(x, ip, verbose = False):
1099 msc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1100 msc.settimeout(32)
1101 msc.bind((ip, 5000))
1102 msc.listen(5)
1103 if (verbose):
1104 print "MSC is ready at " + ip
1105 while "MSC is connected: 0" == x.vty.command("show msc connection"):
1106 conn, addr = msc.accept()
1107 if (verbose):
1108 print "MSC got connection from ", addr
1109 return conn
1110
1111def ipa_handle_small(x, verbose = False):
1112 s = data2str(x.recv(4))
1113 if "0001fe00" == s:
1114 if (verbose):
1115 print "\tBSC <- NAT: PING?"
1116 ipa_send_pong(x, verbose)
1117 elif "0001fe06" == s:
1118 if (verbose):
1119 print "\tBSC <- NAT: IPA ID ACK"
1120 ipa_send_ack(x, verbose)
1121 elif "0001fe00" == s:
1122 if (verbose):
1123 print "\tBSC <- NAT: PONG!"
1124 else:
1125 if (verbose):
1126 print "\tBSC <- NAT: ", s
1127
1128def ipa_handle_resp(x, tk, verbose = False):
1129 s = data2str(x.recv(38))
1130 if "0023fe040108010701020103010401050101010011" in s:
1131 ipa_send_resp(x, tk, verbose)
1132 else:
1133 if (verbose):
1134 print "\tBSC <- NAT: ", s
1135
1136def nat_bsc_num_con(x):
1137 return len(x.vty.command("show bsc connections").split('\n'))
1138
1139def nat_bsc_sock_test(nr, tk, verbose = False):
1140 bsc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1141 bsc.bind(('127.0.0.1' + str(nr), 0))
1142 bsc.connect(('127.0.0.1', 5000))
1143 if (verbose):
1144 print "BSC%d " %nr
1145 print "\tconnected to %s:%d" % bsc.getpeername()
1146 ipa_handle_small(bsc, verbose)
1147 ipa_handle_resp(bsc, tk, verbose)
1148 bsc.recv(27) # MGCP msg
1149 ipa_handle_small(bsc, verbose)
1150 return bsc
1151
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001152def add_bsc_test(suite, workdir):
1153 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")):
1154 print("Skipping the BSC test")
1155 return
1156 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC)
1157 suite.addTest(test)
1158
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001159def add_gbproxy_test(suite, workdir):
1160 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-gbproxy")):
1161 print("Skipping the Gb-Proxy test")
1162 return
1163 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYGbproxy)
1164 suite.addTest(test)
1165
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001166def add_sgsn_test(suite, workdir):
1167 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-sgsn")):
1168 print("Skipping the SGSN test")
1169 return
1170 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYSGSN)
1171 suite.addTest(test)
1172
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001173if __name__ == '__main__':
1174 import argparse
1175 import sys
1176
1177 workdir = '.'
1178
1179 parser = argparse.ArgumentParser()
1180 parser.add_argument("-v", "--verbose", dest="verbose",
1181 action="store_true", help="verbose mode")
1182 parser.add_argument("-p", "--pythonconfpath", dest="p",
1183 help="searchpath for config")
1184 parser.add_argument("-w", "--workdir", dest="w",
1185 help="Working directory")
1186 args = parser.parse_args()
1187
1188 verbose_level = 1
1189 if args.verbose:
1190 verbose_level = 2
1191
1192 if args.w:
1193 workdir = args.w
1194
1195 if args.p:
1196 confpath = args.p
1197
1198 print "confpath %s, workdir %s" % (confpath, workdir)
1199 os.chdir(workdir)
1200 print "Running tests for specific VTY commands"
1201 suite = unittest.TestSuite()
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +02001202 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYMGCP))
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +02001203 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB))
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001204 add_bsc_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001205 add_nat_test(suite, workdir)
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001206 add_gbproxy_test(suite, workdir)
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001207 add_sgsn_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001208 res = unittest.TextTestRunner(verbosity=verbose_level).run(suite)
1209 sys.exit(len(res.errors) + len(res.failures))