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