blob: d5741298927ce539020319f43f4828d5e58d7731 [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):
623 return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-c",
624 "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
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200629 def testVtyTree(self):
630 self.vty.enable()
631 self.assertTrue(self.vty.verify('configure terminal', ['']))
632 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100633 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200634 self.assertTrue(self.vty.verify('mgcp', ['']))
635 self.assertEquals(self.vty.node(), 'config-mgcp')
636 self.checkForEndAndExit()
637 self.assertTrue(self.vty.verify('exit', ['']))
638 self.assertEquals(self.vty.node(), 'config')
639 self.assertTrue(self.vty.verify('nat', ['']))
640 self.assertEquals(self.vty.node(), 'config-nat')
641 self.checkForEndAndExit()
642 self.assertTrue(self.vty.verify('bsc 0', ['']))
643 self.assertEquals(self.vty.node(), 'config-nat-bsc')
644 self.checkForEndAndExit()
645 self.assertTrue(self.vty.verify('exit', ['']))
646 self.assertEquals(self.vty.node(), 'config-nat')
647 self.assertTrue(self.vty.verify('exit', ['']))
648 self.assertEquals(self.vty.node(), 'config')
649 self.assertTrue(self.vty.verify('exit', ['']))
650 self.assertTrue(self.vty.node() is None)
651
652 # Check searching for outer node's commands
653 self.vty.command('configure terminal')
654 self.vty.command('mgcp')
655 self.vty.command('nat')
656 self.assertEquals(self.vty.node(), 'config-nat')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200657 self.vty.command('mgcp')
658 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200659 self.vty.command('nat')
660 self.assertEquals(self.vty.node(), 'config-nat')
661 self.vty.command('bsc 0')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200662 self.vty.command('mgcp')
663 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200664
Holger Hans Peter Freytherb718ad32013-06-25 09:08:02 +0200665 def testRewriteNoRewrite(self):
666 self.vty.enable()
667 res = self.vty.command("configure terminal")
668 res = self.vty.command("nat")
669 res = self.vty.command("number-rewrite rewrite.cfg")
670 res = self.vty.command("no number-rewrite")
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200671
Holger Hans Peter Freyther7f100c92015-04-23 20:25:17 -0400672 def testEnsureNoEnsureModeSet(self):
673 self.vty.enable()
674 res = self.vty.command("configure terminal")
675 res = self.vty.command("nat")
676
677 # Ensure the default
678 res = self.vty.command("show running-config")
679 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
680
681 self.vty.command("sdp-ensure-amr-mode-set")
682 res = self.vty.command("show running-config")
683 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
684
685 self.vty.command("no sdp-ensure-amr-mode-set")
686 res = self.vty.command("show running-config")
687 self.assert_(res.find('\n no sdp-ensure-amr-mode-set') > 0)
688
Holger Hans Peter Freyther67e423c2013-06-25 15:38:31 +0200689 def testRewritePostNoRewrite(self):
690 self.vty.enable()
691 self.vty.command("configure terminal")
692 self.vty.command("nat")
693 self.vty.verify("number-rewrite-post rewrite.cfg", [''])
694 self.vty.verify("no number-rewrite-post", [''])
695
696
Holger Hans Peter Freytherddf191e2013-06-25 11:44:01 +0200697 def testPrefixTreeLoading(self):
698 cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv")
699
700 self.vty.enable()
701 self.vty.command("configure terminal")
702 self.vty.command("nat")
703 res = self.vty.command("prefix-tree %s" % cfg)
704 self.assertEqual(res, "% prefix-tree loaded 17 rules.")
705 self.vty.command("end")
706
707 res = self.vty.command("show prefix-tree")
708 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')
709
710 self.vty.command("configure terminal")
711 self.vty.command("nat")
712 self.vty.command("no prefix-tree")
713 self.vty.command("end")
714
715 res = self.vty.command("show prefix-tree")
716 self.assertEqual(res, "% there is now prefix tree loaded.")
717
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200718 def testUssdSideChannelProvider(self):
719 self.vty.command("end")
720 self.vty.enable()
721 self.vty.command("configure terminal")
722 self.vty.command("nat")
723 self.vty.command("ussd-token key")
724 self.vty.command("end")
725
726 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
727 self.assertTrue(res)
728
729 ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
730 ussdSocket.connect(('127.0.0.1', 5001))
731 ussdSocket.settimeout(2.0)
732 print "Connected to %s:%d" % ussdSocket.getpeername()
733
734 print "Expecting ID_GET request"
735 data = ussdSocket.recv(4)
736 self.assertEqual(data, "\x00\x01\xfe\x04")
737
738 print "Going to send ID_RESP response"
Max70cf7292016-04-13 11:36:38 +0200739 res = ipa_send_resp(ussdSocket, "\x6b\x65\x79")
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200740 self.assertEqual(res, 10)
741
742 # initiating PING/PONG cycle to know, that the ID_RESP message has been processed
743
744 print "Going to send PING request"
Max70cf7292016-04-13 11:36:38 +0200745 res = ipa_send_ping(ussdSocket)
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200746 self.assertEqual(res, 4)
747
748 print "Expecting PONG response"
749 data = ussdSocket.recv(4)
750 self.assertEqual(data, "\x00\x01\xfe\x01")
751
752 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.'])
753 self.assertTrue(res)
754
755 print "Going to shut down connection"
756 ussdSocket.shutdown(socket.SHUT_WR)
757
758 print "Expecting EOF"
759 data = ussdSocket.recv(4)
760 self.assertEqual(data, "")
761
762 ussdSocket.close()
763
764 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
765 self.assertTrue(res)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200766
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100767 def testAccessList(self):
768 """
769 Verify that the imsi-deny can have a reject cause or no reject cause
770 """
771 self.vty.enable()
772 self.vty.command("configure terminal")
773 self.vty.command("nat")
774
775 # Old default
776 self.vty.command("access-list test-default imsi-deny ^123[0-9]*$")
777 res = self.vty.command("show running-config").split("\r\n")
778 asserted = False
779 for line in res:
Holger Hans Peter Freyther4ecc6872014-03-04 15:38:00 +0100780 if line.startswith(" access-list test-default"):
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100781 self.assertEqual(line, " access-list test-default imsi-deny ^123[0-9]*$ 11 11")
782 asserted = True
783 self.assert_(asserted)
784
785 # Check the optional CM Service Reject Cause
786 self.vty.command("access-list test-cm-deny imsi-deny ^123[0-9]*$ 42").split("\r\n")
787 res = self.vty.command("show running-config").split("\r\n")
788 asserted = False
789 for line in res:
790 if line.startswith(" access-list test-cm"):
791 self.assertEqual(line, " access-list test-cm-deny imsi-deny ^123[0-9]*$ 42 11")
792 asserted = True
793 self.assert_(asserted)
794
795 # Check the optional LU Reject Cause
796 self.vty.command("access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42").split("\r\n")
797 res = self.vty.command("show running-config").split("\r\n")
798 asserted = False
799 for line in res:
800 if line.startswith(" access-list test-lu"):
801 self.assertEqual(line, " access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42")
802 asserted = True
803 self.assert_(asserted)
804
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200805class TestVTYGbproxy(TestVTYGenericBSC):
806
807 def vty_command(self):
808 return ["./src/gprs/osmo-gbproxy", "-c",
809 "doc/examples/osmo-gbproxy/osmo-gbproxy.cfg"]
810
811 def vty_app(self):
812 return (4246, "./src/gprs/osmo-gbproxy", "OsmoGbProxy", "bsc")
813
814 def testVtyTree(self):
815 self.vty.enable()
816 self.assertTrue(self.vty.verify('configure terminal', ['']))
817 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100818 self.checkForEndAndExit()
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200819 self.assertTrue(self.vty.verify('ns', ['']))
820 self.assertEquals(self.vty.node(), 'config-ns')
821 self.checkForEndAndExit()
822 self.assertTrue(self.vty.verify('exit', ['']))
823 self.assertEquals(self.vty.node(), 'config')
824 self.assertTrue(self.vty.verify('gbproxy', ['']))
825 self.assertEquals(self.vty.node(), 'config-gbproxy')
826 self.checkForEndAndExit()
827 self.assertTrue(self.vty.verify('exit', ['']))
828 self.assertEquals(self.vty.node(), 'config')
829
830 def testVtyShow(self):
831 res = self.vty.command("show ns")
832 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
833
834 res = self.vty.command("show gbproxy stats")
835 self.assert_(res.find('GBProxy Global Statistics') >= 0)
836
Jacob Erlbeck4211d792013-10-24 12:48:23 +0200837 def testVtyDeletePeer(self):
838 self.vty.enable()
839 self.assertTrue(self.vty.verify('delete-gbproxy-peer 9999 bvci 7777', ['BVC not found']))
840 res = self.vty.command("delete-gbproxy-peer 9999 all dry-run")
841 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
842 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
843 res = self.vty.command("delete-gbproxy-peer 9999 only-bvc dry-run")
844 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
845 self.assert_(res.find('Not Deleted 0 NS-VC') < 0)
846 res = self.vty.command("delete-gbproxy-peer 9999 only-nsvc dry-run")
847 self.assert_(res.find('Not Deleted 0 BVC') < 0)
848 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
849 res = self.vty.command("delete-gbproxy-peer 9999 all")
850 self.assert_(res.find('Deleted 0 BVC') >= 0)
851 self.assert_(res.find('Deleted 0 NS-VC') >= 0)
852
Jacob Erlbeck144b8b12014-11-04 11:15:01 +0100853class TestVTYSGSN(TestVTYGenericBSC):
854
855 def vty_command(self):
856 return ["./src/gprs/osmo-sgsn", "-c",
857 "doc/examples/osmo-sgsn/osmo-sgsn.cfg"]
858
859 def vty_app(self):
860 return (4245, "./src/gprs/osmo-sgsn", "OsmoSGSN", "sgsn")
861
862 def testVtyTree(self):
863 self.vty.enable()
864 self.assertTrue(self.vty.verify('configure terminal', ['']))
865 self.assertEquals(self.vty.node(), 'config')
866 self.checkForEndAndExit()
867 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('sgsn', ['']))
873 self.assertEquals(self.vty.node(), 'config-sgsn')
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 self.assertTrue(self.vty.verify('show bssgp', ['']))
882 self.assertTrue(self.vty.verify('show bssgp stats', ['']))
883 # TODO: uncomment when the command does not segfault anymore
884 # self.assertTrue(self.vty.verify('show bssgp nsei 123', ['']))
885 # self.assertTrue(self.vty.verify('show bssgp nsei 123 stats', ['']))
886
887 self.assertTrue(self.vty.verify('show sgsn', ['']))
888 self.assertTrue(self.vty.verify('show mm-context all', ['']))
889 self.assertTrue(self.vty.verify('show mm-context imsi 000001234567', ['No MM context for IMSI 000001234567']))
890 self.assertTrue(self.vty.verify('show pdp-context all', ['']))
891
892 res = self.vty.command("show sndcp")
893 self.assert_(res.find('State of SNDCP Entities') >= 0)
894
895 res = self.vty.command("show llc")
896 self.assert_(res.find('State of LLC Entities') >= 0)
897
Jacob Erlbeck106f5472014-11-04 10:08:37 +0100898 def testVtyAuth(self):
899 self.vty.enable()
900 self.assertTrue(self.vty.verify('configure terminal', ['']))
901 self.assertEquals(self.vty.node(), 'config')
902 self.assertTrue(self.vty.verify('sgsn', ['']))
903 self.assertEquals(self.vty.node(), 'config-sgsn')
904 self.assertTrue(self.vty.verify('auth-policy accept-all', ['']))
905 res = self.vty.command("show running-config")
906 self.assert_(res.find('auth-policy accept-all') > 0)
907 self.assertTrue(self.vty.verify('auth-policy acl-only', ['']))
908 res = self.vty.command("show running-config")
909 self.assert_(res.find('auth-policy acl-only') > 0)
910 self.assertTrue(self.vty.verify('auth-policy closed', ['']))
911 res = self.vty.command("show running-config")
912 self.assert_(res.find('auth-policy closed') > 0)
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +0100913 self.assertTrue(self.vty.verify('auth-policy remote', ['']))
914 res = self.vty.command("show running-config")
915 self.assert_(res.find('auth-policy remote') > 0)
Jacob Erlbeck106f5472014-11-04 10:08:37 +0100916
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100917 def testVtySubscriber(self):
918 self.vty.enable()
919 res = self.vty.command('show subscriber cache')
920 self.assert_(res.find('1234567890') < 0)
Jacob Erlbeckd9193432015-01-19 14:11:46 +0100921 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 create', ['']))
922 res = self.vty.command('show subscriber cache')
923 self.assert_(res.find('1234567890') >= 0)
924 self.assert_(res.find('Authorized: 0') >= 0)
925 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 update-location-result ok', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100926 res = self.vty.command('show subscriber cache')
927 self.assert_(res.find('1234567890') >= 0)
928 self.assert_(res.find('Authorized: 1') >= 0)
Jacob Erlbeck8000e0e2015-01-27 14:56:40 +0100929 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 cancel update-procedure', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100930 res = self.vty.command('show subscriber cache')
Jacob Erlbecke988ae42015-01-27 12:41:19 +0100931 self.assert_(res.find('1234567890') >= 0)
932 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 destroy', ['']))
933 res = self.vty.command('show subscriber cache')
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100934 self.assert_(res.find('1234567890') < 0)
935
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +0100936 def testVtyGgsn(self):
937 self.vty.enable()
938 self.assertTrue(self.vty.verify('configure terminal', ['']))
939 self.assertEquals(self.vty.node(), 'config')
940 self.assertTrue(self.vty.verify('sgsn', ['']))
941 self.assertEquals(self.vty.node(), 'config-sgsn')
942 self.assertTrue(self.vty.verify('ggsn 0 remote-ip 127.99.99.99', ['']))
943 self.assertTrue(self.vty.verify('ggsn 0 gtp-version 1', ['']))
944 self.assertTrue(self.vty.verify('apn * ggsn 0', ['']))
945 self.assertTrue(self.vty.verify('apn apn1.test ggsn 0', ['']))
946 self.assertTrue(self.vty.verify('apn apn1.test ggsn 1', ['% a GGSN with id 1 has not been defined']))
947 self.assertTrue(self.vty.verify('apn apn1.test imsi-prefix 123456 ggsn 0', ['']))
948 self.assertTrue(self.vty.verify('apn apn2.test imsi-prefix 123456 ggsn 0', ['']))
949 res = self.vty.command("show running-config")
950 self.assert_(res.find('ggsn 0 remote-ip 127.99.99.99') >= 0)
951 self.assert_(res.find('ggsn 0 gtp-version 1') >= 0)
952 self.assert_(res.find('apn * ggsn 0') >= 0)
953 self.assert_(res.find('apn apn1.test ggsn 0') >= 0)
954 self.assert_(res.find('apn apn1.test imsi-prefix 123456 ggsn 0') >= 0)
955 self.assert_(res.find('apn apn2.test imsi-prefix 123456 ggsn 0') >= 0)
956
Holger Hans Peter Freyther9c20a5f2015-02-06 16:23:29 +0100957 def testVtyEasyAPN(self):
958 self.vty.enable()
959 self.assertTrue(self.vty.verify('configure terminal', ['']))
960 self.assertEquals(self.vty.node(), 'config')
961 self.assertTrue(self.vty.verify('sgsn', ['']))
962 self.assertEquals(self.vty.node(), 'config-sgsn')
963
964 res = self.vty.command("show running-config")
965 self.assertEquals(res.find("apn internet"), -1)
966
967 self.assertTrue(self.vty.verify("access-point-name internet.apn", ['']))
968 res = self.vty.command("show running-config")
969 self.assert_(res.find("apn internet.apn ggsn 0") >= 0)
970
971 self.assertTrue(self.vty.verify("no access-point-name internet.apn", ['']))
972 res = self.vty.command("show running-config")
973 self.assertEquals(res.find("apn internet"), -1)
974
Holger Hans Peter Freytherc15c61c2015-05-06 17:46:08 +0200975 def testVtyCDR(self):
976 self.vty.enable()
977 self.assertTrue(self.vty.verify('configure terminal', ['']))
978 self.assertEquals(self.vty.node(), 'config')
979 self.assertTrue(self.vty.verify('sgsn', ['']))
980 self.assertEquals(self.vty.node(), 'config-sgsn')
981
982 res = self.vty.command("show running-config")
983 self.assert_(res.find("no cdr filename") > 0)
984
985 self.vty.command("cdr filename bla.cdr")
986 res = self.vty.command("show running-config")
987 self.assertEquals(res.find("no cdr filename"), -1)
988 self.assert_(res.find(" cdr filename bla.cdr") > 0)
989
990 self.vty.command("no cdr filename")
991 res = self.vty.command("show running-config")
992 self.assert_(res.find("no cdr filename") > 0)
993 self.assertEquals(res.find(" cdr filename bla.cdr"), -1)
994
995 res = self.vty.command("show running-config")
996 self.assert_(res.find(" cdr interval 600") > 0)
997
998 self.vty.command("cdr interval 900")
999 res = self.vty.command("show running-config")
1000 self.assert_(res.find(" cdr interval 900") > 0)
1001 self.assertEquals(res.find(" cdr interval 600"), -1)
1002
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001003def add_nat_test(suite, workdir):
1004 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
1005 print("Skipping the NAT test")
1006 return
1007 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT)
1008 suite.addTest(test)
1009
Max70cf7292016-04-13 11:36:38 +02001010def ipa_send_pong(x, verbose = False):
1011 if (verbose):
1012 print "\tBSC -> NAT: PONG!"
1013 return x.send("\x00\x01\xfe\x01")
1014
1015def ipa_send_ping(x, verbose = False):
1016 if (verbose):
1017 print "\tBSC -> NAT: PING?"
1018 return x.send("\x00\x01\xfe\x00")
1019
1020def ipa_send_ack(x, verbose = False):
1021 if (verbose):
1022 print "\tBSC -> NAT: IPA ID ACK"
1023 return x.send("\x00\x01\xfe\x06")
1024
1025def ipa_send_reset(x, verbose = False):
1026 if (verbose):
1027 print "\tBSC -> NAT: RESET"
1028 return x.send("\x00\x12\xfd\x09\x00\x03\x05\x07\x02\x42\xfe\x02\x42\xfe\x06\x00\x04\x30\x04\x01\x20")
1029
1030def ipa_send_resp(x, tk, verbose = False):
1031 if (verbose):
1032 print "\tBSC -> NAT: IPA ID RESP"
1033 return x.send("\x00\x07\xfe\x05\x00\x04\x01" + tk)
1034
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001035def add_bsc_test(suite, workdir):
1036 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")):
1037 print("Skipping the BSC test")
1038 return
1039 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC)
1040 suite.addTest(test)
1041
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001042def add_gbproxy_test(suite, workdir):
1043 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-gbproxy")):
1044 print("Skipping the Gb-Proxy test")
1045 return
1046 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYGbproxy)
1047 suite.addTest(test)
1048
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001049def add_sgsn_test(suite, workdir):
1050 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-sgsn")):
1051 print("Skipping the SGSN test")
1052 return
1053 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYSGSN)
1054 suite.addTest(test)
1055
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001056if __name__ == '__main__':
1057 import argparse
1058 import sys
1059
1060 workdir = '.'
1061
1062 parser = argparse.ArgumentParser()
1063 parser.add_argument("-v", "--verbose", dest="verbose",
1064 action="store_true", help="verbose mode")
1065 parser.add_argument("-p", "--pythonconfpath", dest="p",
1066 help="searchpath for config")
1067 parser.add_argument("-w", "--workdir", dest="w",
1068 help="Working directory")
1069 args = parser.parse_args()
1070
1071 verbose_level = 1
1072 if args.verbose:
1073 verbose_level = 2
1074
1075 if args.w:
1076 workdir = args.w
1077
1078 if args.p:
1079 confpath = args.p
1080
1081 print "confpath %s, workdir %s" % (confpath, workdir)
1082 os.chdir(workdir)
1083 print "Running tests for specific VTY commands"
1084 suite = unittest.TestSuite()
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +02001085 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYMGCP))
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +02001086 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB))
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001087 add_bsc_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001088 add_nat_test(suite, workdir)
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001089 add_gbproxy_test(suite, workdir)
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001090 add_sgsn_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001091 res = unittest.TextTestRunner(verbosity=verbose_level).run(suite)
1092 sys.exit(len(res.errors) + len(res.failures))