blob: c0888559e8d276105a681bbf755eb965e7d2f2b3 [file] [log] [blame]
Holger Hans Peter Freyther65397522013-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 Erlbeck4684eb62013-08-14 11:10:34 +020021import socket
Holger Hans Peter Freyther65397522013-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 Freytherb30b3aa2014-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 Freyther60e09922014-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 Freythere5899382015-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 Erlbeck768a7c32013-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 Erlbeck768a7c32013-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 Erlbecka4235912013-10-29 09:30:31 +0100132 self.checkForEndAndExit()
Jacob Erlbeck768a7c32013-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 Erlbeck5e229112013-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 Erlbeck768a7c32013-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 Freyther2fb8ebf2013-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 Erlbeck768a7c32013-09-02 13:17:14 +0200171 def testConfigNetworkTree(self):
Jacob Erlbeck5c46e932013-10-23 11:24:14 +0200172 self._testConfigNetworkTree()
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200173
Holger Hans Peter Freytherabb54ae2013-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 Freyther3c64e2d2015-07-06 16:41:30 +0200179 def testSmppFirst(self):
Holger Hans Peter Freyther3c64e2d2015-07-06 16:41:30 +0200180 # enable the configuration
181 self.vty.enable()
182 self.vty.command("configure terminal")
Holger Hans Peter Freyther9c700ee2015-07-13 11:23:53 +0200183
184 if not self.checkForSmpp():
185 return
186
Holger Hans Peter Freyther3c64e2d2015-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 Erlbeck768a7c32013-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 Erlbecka4235912013-10-29 09:30:31 +0100206 self.checkForEndAndExit()
Jacob Erlbeck768a7c32013-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 Freytherabb54ae2013-09-02 20:58:38 +0200211
212 if self.checkForSmpp():
213 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck5c46e932013-10-23 11:24:14 +0200214 self.assertTrue(self.vty.verify('smpp', ['']))
215 self.assertEquals(self.vty.node(), 'config-smpp')
Jacob Erlbecka4235912013-10-29 09:30:31 +0100216 self.checkForEndAndExit()
Jacob Erlbeck5c46e932013-10-23 11:24:14 +0200217 self.assertTrue(self.vty.verify("exit", ['']))
Holger Hans Peter Freytherabb54ae2013-09-02 20:58:38 +0200218
Jacob Erlbeckbf8eec72013-09-02 13:17:16 +0200219 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck768a7c32013-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 Freytherabb54ae2013-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 Erlbeck768a7c32013-09-02 13:17:14 +0200232 self.assertEquals(self.vty.node(), 'config-mncc-int')
233
Max2befab12016-04-20 12:06:06 +0200234 def testSi2Q(self):
235 self.vty.enable()
236 self.vty.command("configure terminal")
237 self.vty.command("network")
238 self.vty.command("bts 0")
239 before = self.vty.command("show running-config")
240 self.vty.command("si2quater neighbor-list add earfcn 1911 threshold 11 2")
241 self.vty.command("si2quater neighbor-list add earfcn 1924 threshold 11 3")
242 self.vty.command("si2quater neighbor-list add earfcn 2111 threshold 11")
243 self.vty.command("si2quater neighbor-list del earfcn 1911")
244 self.vty.command("si2quater neighbor-list del earfcn 1924")
245 self.vty.command("si2quater neighbor-list del earfcn 2111")
246 self.assertEquals(before, self.vty.command("show running-config"))
Maxeaf196c2016-04-20 15:57:13 +0200247 self.vty.command("si2quater neighbor-list add uarfcn 1976 13 1")
248 self.vty.command("si2quater neighbor-list add uarfcn 1976 38 1")
249 self.vty.command("si2quater neighbor-list add uarfcn 1976 44 1")
250 self.vty.command("si2quater neighbor-list add uarfcn 1976 120 1")
251 self.vty.command("si2quater neighbor-list add uarfcn 1976 140 1")
252 self.vty.command("si2quater neighbor-list add uarfcn 1976 163 1")
253 self.vty.command("si2quater neighbor-list add uarfcn 1976 166 1")
254 self.vty.command("si2quater neighbor-list add uarfcn 1976 217 1")
255 self.vty.command("si2quater neighbor-list add uarfcn 1976 224 1")
256 self.vty.command("si2quater neighbor-list add uarfcn 1976 225 1")
257 self.vty.command("si2quater neighbor-list add uarfcn 1976 226 1")
258 self.vty.command("si2quater neighbor-list del uarfcn 1976 13")
259 self.vty.command("si2quater neighbor-list del uarfcn 1976 38")
260 self.vty.command("si2quater neighbor-list del uarfcn 1976 44")
261 self.vty.command("si2quater neighbor-list del uarfcn 1976 120")
262 self.vty.command("si2quater neighbor-list del uarfcn 1976 140")
263 self.vty.command("si2quater neighbor-list del uarfcn 1976 163")
264 self.vty.command("si2quater neighbor-list del uarfcn 1976 166")
265 self.vty.command("si2quater neighbor-list del uarfcn 1976 217")
266 self.vty.command("si2quater neighbor-list del uarfcn 1976 224")
267 self.vty.command("si2quater neighbor-list del uarfcn 1976 225")
268 self.vty.command("si2quater neighbor-list del uarfcn 1976 226")
269 self.assertEquals(before, self.vty.command("show running-config"))
Max2befab12016-04-20 12:06:06 +0200270
Holger Hans Peter Freyther2fb8ebf2013-07-27 21:07:57 +0200271 def testEnableDisablePeriodicLU(self):
272 self.vty.enable()
273 self.vty.command("configure terminal")
274 self.vty.command("network")
275 self.vty.command("bts 0")
276
277 # Test invalid input
278 self.vty.verify("periodic location update 0", ['% Unknown command.'])
279 self.vty.verify("periodic location update 5", ['% Unknown command.'])
280 self.vty.verify("periodic location update 1531", ['% Unknown command.'])
281
282 # Enable periodic lu..
283 self.vty.verify("periodic location update 60", [''])
284 res = self.vty.command("write terminal")
Holger Hans Peter Freythereda08672013-07-27 22:23:25 +0200285 self.assert_(res.find('periodic location update 60') > 0)
Holger Hans Peter Freyther2fb8ebf2013-07-27 21:07:57 +0200286 self.assertEquals(res.find('no periodic location update'), -1)
287
288 # Now disable it..
289 self.vty.verify("no periodic location update", [''])
290 res = self.vty.command("write terminal")
291 self.assertEquals(res.find('periodic location update 60'), -1)
Holger Hans Peter Freythereda08672013-07-27 22:23:25 +0200292 self.assert_(res.find('no periodic location update') > 0)
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +0200293
Jacob Erlbeck8f8e5bf2014-01-16 11:02:14 +0100294 def testEnableDisableSiHacks(self):
295 self.vty.enable()
296 self.vty.command("configure terminal")
297 self.vty.command("network")
298 self.vty.command("bts 0")
299
300 # Enable periodic lu..
301 self.vty.verify("force-combined-si", [''])
302 res = self.vty.command("write terminal")
303 self.assert_(res.find(' force-combined-si') > 0)
304 self.assertEquals(res.find('no force-combined-si'), -1)
305
306 # Now disable it..
307 self.vty.verify("no force-combined-si", [''])
308 res = self.vty.command("write terminal")
309 self.assertEquals(res.find(' force-combined-si'), -1)
310 self.assert_(res.find('no force-combined-si') > 0)
311
Ivan Kluchnikov80d58432013-09-16 13:13:04 +0400312 def testRachAccessControlClass(self):
313 self.vty.enable()
314 self.vty.command("configure terminal")
315 self.vty.command("network")
316 self.vty.command("bts 0")
317
318 # Test invalid input
319 self.vty.verify("rach access-control-class", ['% Command incomplete.'])
320 self.vty.verify("rach access-control-class 1", ['% Command incomplete.'])
321 self.vty.verify("rach access-control-class -1", ['% Unknown command.'])
322 self.vty.verify("rach access-control-class 10", ['% Unknown command.'])
323 self.vty.verify("rach access-control-class 16", ['% Unknown command.'])
324
325 # Barred rach access control classes
326 for classNum in range(16):
327 if classNum != 10:
328 self.vty.verify("rach access-control-class " + str(classNum) + " barred", [''])
329
330 # Verify settings
331 res = self.vty.command("write terminal")
332 for classNum in range(16):
333 if classNum != 10:
334 self.assert_(res.find("rach access-control-class " + str(classNum) + " barred") > 0)
335
336 # Allowed rach access control classes
337 for classNum in range(16):
338 if classNum != 10:
339 self.vty.verify("rach access-control-class " + str(classNum) + " allowed", [''])
340
341 # Verify settings
342 res = self.vty.command("write terminal")
343 for classNum in range(16):
344 if classNum != 10:
345 self.assertEquals(res.find("rach access-control-class " + str(classNum) + " barred"), -1)
346
Holger Hans Peter Freyther75543292016-04-01 19:44:00 +0200347 def testSubscriberCreateDeleteTwice(self):
348 """
349 OS#1657 indicates that there might be an issue creating the
350 same subscriber twice. This test will use the VTY command to
351 create a subscriber and then issue a second create command
352 with the same IMSI. The test passes if the VTY continues to
353 respond to VTY commands.
354 """
355 self.vty.enable()
356
357 imsi = "204300854013739"
358
359 # Initially we don't have this subscriber
360 self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi])
361
362 # Lets create one
363 res = self.vty.command('subscriber create imsi '+imsi)
364 self.assert_(res.find(" IMSI: "+imsi) > 0)
365 # And now create one again.
366 res2 = self.vty.command('subscriber create imsi '+imsi)
367 self.assert_(res2.find(" IMSI: "+imsi) > 0)
368 self.assertEqual(res, res2)
369
370 # Verify it has been created
371 res = self.vty.command('show subscriber imsi '+imsi)
372 self.assert_(res.find(" IMSI: "+imsi) > 0)
373
374 # Delete it
375 res = self.vty.command('subscriber delete imsi '+imsi)
376 self.assert_(res != "")
377
378 # Now it should not be there anymore
379 res = self.vty.command('show subscriber imsi '+imsi)
380 self.assert_(res != '% No subscriber found for imsi '+imsi)
381
382
Ruben Pollan6af2b402014-09-24 20:50:13 -0500383 def testSubscriberCreateDelete(self):
Alexander Chemerise092dec2013-10-04 23:54:17 +0200384 self.vty.enable()
385
386 imsi = "204300854013739"
387
388 # Initially we don't have this subscriber
389 self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi])
390
391 # Lets create one
392 res = self.vty.command('subscriber create imsi '+imsi)
393 self.assert_(res.find(" IMSI: "+imsi) > 0)
394
395 # Now we have it
396 res = self.vty.command('show subscriber imsi '+imsi)
397 self.assert_(res.find(" IMSI: "+imsi) > 0)
398
Ruben Pollan6af2b402014-09-24 20:50:13 -0500399 # Delete it
400 res = self.vty.command('subscriber delete imsi '+imsi)
401 self.assert_(res != "")
402
403 # Now it should not be there anymore
404 res = self.vty.command('show subscriber imsi '+imsi)
405 self.assert_(res != '% No subscriber found for imsi '+imsi)
406
Jacob Erlbeck508c3102015-04-07 17:49:49 +0200407 def testSubscriberSettings(self):
408 self.vty.enable()
409
410 imsi = "204300854013739"
411 wrong_imsi = "204300999999999"
412
413 # Lets create one
414 res = self.vty.command('subscriber create imsi '+imsi)
415 self.assert_(res.find(" IMSI: "+imsi) > 0)
416
417 self.vty.verify('subscriber imsi '+wrong_imsi+' name wrong', ['% No subscriber found for imsi '+wrong_imsi])
418 res = self.vty.command('subscriber imsi '+imsi+' name '+('X' * 160))
419 self.assert_(res.find("NAME is too long") > 0)
420
421 self.vty.verify('subscriber imsi '+imsi+' name '+('G' * 159), [''])
422
423 self.vty.verify('subscriber imsi '+wrong_imsi+' extension 840', ['% No subscriber found for imsi '+wrong_imsi])
424 res = self.vty.command('subscriber imsi '+imsi+' extension '+('9' * 15))
425 self.assert_(res.find("EXTENSION is too long") > 0)
426
427 self.vty.verify('subscriber imsi '+imsi+' extension '+('1' * 14), [''])
428
429 # Delete it
430 res = self.vty.command('subscriber delete imsi '+imsi)
431 self.assert_(res != "")
432
Holger Hans Peter Freyther35e6fbb2013-02-05 09:39:09 +0100433 def testShowPagingGroup(self):
434 res = self.vty.command("show paging-group 255 1234567")
435 self.assertEqual(res, "% can't find BTS 255")
436 res = self.vty.command("show paging-group 0 1234567")
437 self.assertEquals(res, "%Paging group for IMSI 1234567 on BTS #0 is 7")
438
Ciaby38abd7b2014-03-06 17:20:55 +0100439 def testShowNetwork(self):
440 res = self.vty.command("show network")
441 self.assert_(res.startswith('BSC is on Country Code') >= 0)
442
Holger Hans Peter Freyther65b89922015-01-31 09:47:37 +0100443 def testMeasurementFeed(self):
444 self.vty.enable()
445 self.vty.command("configure terminal")
446 self.vty.command("mncc-int")
447
448 res = self.vty.command("write terminal")
449 self.assertEquals(res.find('meas-feed scenario'), -1)
450
451 self.vty.command("meas-feed scenario bla")
452 res = self.vty.command("write terminal")
453 self.assert_(res.find('meas-feed scenario bla') > 0)
454
455 self.vty.command("meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890")
456 res = self.vty.command("write terminal")
457 self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890'), -1)
458 self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz012345'), -1)
459 self.assert_(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234') > 0)
460
461
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200462class TestVTYBSC(TestVTYGenericBSC):
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200463
464 def vty_command(self):
465 return ["./src/osmo-bsc/osmo-bsc", "-c",
466 "doc/examples/osmo-bsc/osmo-bsc.cfg"]
467
468 def vty_app(self):
469 return (4242, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc")
470
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200471 def testConfigNetworkTree(self):
Jacob Erlbeck5c46e932013-10-23 11:24:14 +0200472 self._testConfigNetworkTree()
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200473
474 def testVtyTree(self):
475 self.vty.enable()
476 self.assertTrue(self.vty.verify("configure terminal", ['']))
477 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbecka4235912013-10-29 09:30:31 +0100478 self.checkForEndAndExit()
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200479 self.assertTrue(self.vty.verify("msc 0", ['']))
480 self.assertEquals(self.vty.node(), 'config-msc')
Jacob Erlbeckbf8eec72013-09-02 13:17:16 +0200481 self.checkForEndAndExit()
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200482 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeckbf8eec72013-09-02 13:17:16 +0200483 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200484 self.assertTrue(self.vty.verify("bsc", ['']))
485 self.assertEquals(self.vty.node(), 'config-bsc')
Jacob Erlbeckbf8eec72013-09-02 13:17:16 +0200486 self.checkForEndAndExit()
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200487 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeckbf8eec72013-09-02 13:17:16 +0200488 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200489 self.assertTrue(self.vty.verify("exit", ['']))
490 self.assertTrue(self.vty.node() is None)
491
492 # Check searching for outer node's commands
493 self.vty.command("configure terminal")
494 self.vty.command('msc 0')
495 self.vty.command("bsc")
496 self.assertEquals(self.vty.node(), 'config-bsc')
497 self.vty.command("msc 0")
498 self.assertEquals(self.vty.node(), 'config-msc')
499
Jacob Erlbeck3ccb86b2013-09-11 10:46:55 +0200500 def testUssdNotificationsMsc(self):
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200501 self.vty.enable()
502 self.vty.command("configure terminal")
503 self.vty.command("msc")
504
505 # Test invalid input
506 self.vty.verify("bsc-msc-lost-text", ['% Command incomplete.'])
Jacob Erlbeckb62092a2013-08-28 10:16:55 +0200507 self.vty.verify("bsc-welcome-text", ['% Command incomplete.'])
Jacob Erlbeck3ccb86b2013-09-11 10:46:55 +0200508 self.vty.verify("bsc-grace-text", ['% Command incomplete.'])
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200509
510 # Enable USSD notifications
511 self.vty.verify("bsc-msc-lost-text MSC disconnected", [''])
Jacob Erlbeckb62092a2013-08-28 10:16:55 +0200512 self.vty.verify("bsc-welcome-text Hello MS", [''])
Jacob Erlbeck3ccb86b2013-09-11 10:46:55 +0200513 self.vty.verify("bsc-grace-text In grace period", [''])
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200514
515 # Verify settings
516 res = self.vty.command("write terminal")
517 self.assert_(res.find('bsc-msc-lost-text MSC disconnected') > 0)
518 self.assertEquals(res.find('no bsc-msc-lost-text'), -1)
Jacob Erlbeckb62092a2013-08-28 10:16:55 +0200519 self.assert_(res.find('bsc-welcome-text Hello MS') > 0)
520 self.assertEquals(res.find('no bsc-welcome-text'), -1)
Jacob Erlbeck3ccb86b2013-09-11 10:46:55 +0200521 self.assert_(res.find('bsc-grace-text In grace period') > 0)
522 self.assertEquals(res.find('no bsc-grace-text'), -1)
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200523
524 # Now disable it..
525 self.vty.verify("no bsc-msc-lost-text", [''])
Jacob Erlbeckb62092a2013-08-28 10:16:55 +0200526 self.vty.verify("no bsc-welcome-text", [''])
Jacob Erlbeck3ccb86b2013-09-11 10:46:55 +0200527 self.vty.verify("no bsc-grace-text", [''])
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200528
529 # Verify settings
530 res = self.vty.command("write terminal")
531 self.assertEquals(res.find('bsc-msc-lost-text MSC disconnected'), -1)
532 self.assert_(res.find('no bsc-msc-lost-text') > 0)
Jacob Erlbeckb62092a2013-08-28 10:16:55 +0200533 self.assertEquals(res.find('bsc-welcome-text Hello MS'), -1)
Jacob Erlbeck3ccb86b2013-09-11 10:46:55 +0200534 self.assert_(res.find('no bsc-welcome-text') > 0)
535 self.assertEquals(res.find('bsc-grace-text In grace period'), -1)
536 self.assert_(res.find('no bsc-grace-text') > 0)
537
538 def testUssdNotificationsBsc(self):
539 self.vty.enable()
540 self.vty.command("configure terminal")
541 self.vty.command("bsc")
542
543 # Test invalid input
544 self.vty.verify("missing-msc-text", ['% Command incomplete.'])
545
546 # Enable USSD notifications
547 self.vty.verify("missing-msc-text No MSC found", [''])
548
549 # Verify settings
550 res = self.vty.command("write terminal")
551 self.assert_(res.find('missing-msc-text No MSC found') > 0)
552 self.assertEquals(res.find('no missing-msc-text'), -1)
553
554 # Now disable it..
555 self.vty.verify("no missing-msc-text", [''])
556
557 # Verify settings
558 res = self.vty.command("write terminal")
559 self.assertEquals(res.find('missing-msc-text No MSC found'), -1)
560 self.assert_(res.find('no missing-msc-text') > 0)
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200561
Jacob Erlbeckcc0d8842013-09-17 13:59:29 +0200562 def testNetworkTimezone(self):
563 self.vty.enable()
564 self.vty.verify("configure terminal", [''])
565 self.vty.verify("network", [''])
566 self.vty.verify("bts 0", [''])
567
568 # Test invalid input
569 self.vty.verify("timezone", ['% Command incomplete.'])
570 self.vty.verify("timezone 20 0", ['% Unknown command.'])
571 self.vty.verify("timezone 0 11", ['% Unknown command.'])
572 self.vty.verify("timezone 0 0 99", ['% Unknown command.'])
573
574 # Set time zone without DST
575 self.vty.verify("timezone 2 30", [''])
576
577 # Verify settings
578 res = self.vty.command("write terminal")
579 self.assert_(res.find('timezone 2 30') > 0)
580 self.assertEquals(res.find('timezone 2 30 '), -1)
581
582 # Set time zone with DST
583 self.vty.verify("timezone 2 30 1", [''])
584
585 # Verify settings
586 res = self.vty.command("write terminal")
587 self.assert_(res.find('timezone 2 30 1') > 0)
588
589 # Now disable it..
590 self.vty.verify("no timezone", [''])
591
592 # Verify settings
593 res = self.vty.command("write terminal")
594 self.assertEquals(res.find(' timezone'), -1)
595
Ciaby38abd7b2014-03-06 17:20:55 +0100596 def testShowNetwork(self):
597 res = self.vty.command("show network")
598 self.assert_(res.startswith('BSC is on Country Code') >= 0)
599
Holger Hans Peter Freytherd2b37c52014-10-29 10:06:15 +0100600 def testPingPongConfiguration(self):
601 self.vty.enable()
602 self.vty.verify("configure terminal", [''])
603 self.vty.verify("network", [''])
604 self.vty.verify("msc 0", [''])
605
606 self.vty.verify("timeout-ping 12", [''])
607 self.vty.verify("timeout-pong 14", [''])
608 res = self.vty.command("show running-config")
609 self.assert_(res.find(" timeout-ping 12") > 0)
610 self.assert_(res.find(" timeout-pong 14") > 0)
611 self.assert_(res.find(" no timeout-ping advanced") > 0)
612
613 self.vty.verify("timeout-ping advanced", [''])
614 res = self.vty.command("show running-config")
615 self.assert_(res.find(" timeout-ping 12") > 0)
616 self.assert_(res.find(" timeout-pong 14") > 0)
617 self.assert_(res.find(" timeout-ping advanced") > 0)
618
619 self.vty.verify("no timeout-ping advanced", [''])
620 res = self.vty.command("show running-config")
621 self.assert_(res.find(" timeout-ping 12") > 0)
622 self.assert_(res.find(" timeout-pong 14") > 0)
623 self.assert_(res.find(" no timeout-ping advanced") > 0)
624
625 self.vty.verify("no timeout-ping", [''])
626 res = self.vty.command("show running-config")
627 self.assertEquals(res.find(" timeout-ping 12"), -1)
628 self.assertEquals(res.find(" timeout-pong 14"), -1)
629 self.assertEquals(res.find(" no timeout-ping advanced"), -1)
630 self.assert_(res.find(" no timeout-ping") > 0)
631
632 self.vty.verify("timeout-ping advanced", ['%ping handling is disabled. Enable it first.'])
633
634 # And back to enabling it
635 self.vty.verify("timeout-ping 12", [''])
636 self.vty.verify("timeout-pong 14", [''])
637 res = self.vty.command("show running-config")
638 self.assert_(res.find(" timeout-ping 12") > 0)
639 self.assert_(res.find(" timeout-pong 14") > 0)
640 self.assert_(res.find(" timeout-ping advanced") > 0)
641
Holger Hans Peter Freyther05e27702015-04-01 18:15:48 +0200642 def testMscDataCoreLACCI(self):
643 self.vty.enable()
644 res = self.vty.command("show running-config")
645 self.assertEquals(res.find("core-location-area-code"), -1)
646 self.assertEquals(res.find("core-cell-identity"), -1)
647
648 self.vty.command("configure terminal")
649 self.vty.command("msc 0")
650 self.vty.command("core-location-area-code 666")
651 self.vty.command("core-cell-identity 333")
652
653 res = self.vty.command("show running-config")
654 self.assert_(res.find("core-location-area-code 666") > 0)
655 self.assert_(res.find("core-cell-identity 333") > 0)
656
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200657class TestVTYNAT(TestVTYGenericBSC):
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +0200658
659 def vty_command(self):
Max884b4da2016-04-13 11:36:39 +0200660 return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-l", "127.0.0.1", "-c",
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +0200661 "doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"]
662
663 def vty_app(self):
664 return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat")
665
Max884b4da2016-04-13 11:36:39 +0200666 def testBSCreload(self):
Holger Hans Peter Freyther4ad2e142016-04-14 10:05:13 -0400667 # Use different port for the mock msc to avoid clashing with
668 # the osmo-bsc_nat itself
Holger Hans Peter Freyther09f1afc2016-04-14 08:50:25 -0400669 ip = "127.0.0.1"
Holger Hans Peter Freyther46ba2ea2016-04-14 10:58:58 -0400670 port = 5522
Max884b4da2016-04-13 11:36:39 +0200671 self.vty.enable()
672 bscs1 = self.vty.command("show bscs-config")
673 nat_bsc_reload(self)
674 bscs2 = self.vty.command("show bscs-config")
675 # check that multiple calls to bscs-config-file give the same result
676 self.assertEquals(bscs1, bscs2)
677
678 # add new bsc
679 self.vty.command("configure terminal")
680 self.vty.command("nat")
681 self.vty.command("bsc 5")
682 self.vty.command("token key")
683 self.vty.command("location_area_code 666")
684 self.vty.command("end")
685
686 # update bsc token
687 self.vty.command("configure terminal")
688 self.vty.command("nat")
689 self.vty.command("bsc 1")
690 self.vty.command("token xyu")
691 self.vty.command("end")
692
Holger Hans Peter Freyther4ad2e142016-04-14 10:05:13 -0400693 nat_msc_ip(self, ip, port)
694 msc = nat_msc_test(self, ip, port)
Max884b4da2016-04-13 11:36:39 +0200695 b0 = nat_bsc_sock_test(0, "lol")
696 b1 = nat_bsc_sock_test(1, "xyu")
697 b2 = nat_bsc_sock_test(5, "key")
698
699 self.assertEquals("3 BSCs configured", self.vty.command("show nat num-bscs-configured"))
700 self.assertTrue(3 == nat_bsc_num_con(self))
701 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
702
703 nat_bsc_reload(self)
704 bscs2 = self.vty.command("show bscs-config")
705 # check that the reset to initial config succeeded
706 self.assertEquals(bscs1, bscs2)
707
708 self.assertEquals("2 BSCs configured", self.vty.command("show nat num-bscs-configured"))
709 self.assertTrue(1 == nat_bsc_num_con(self))
710 rem = self.vty.command("show bsc connections").split(' ')
711 # remaining connection is for BSC0
712 self.assertEquals('0', rem[2])
713 # remaining connection is authorized
714 self.assertEquals('1', rem[4])
715 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
716
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200717 def testVtyTree(self):
718 self.vty.enable()
719 self.assertTrue(self.vty.verify('configure terminal', ['']))
720 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbecka4235912013-10-29 09:30:31 +0100721 self.checkForEndAndExit()
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200722 self.assertTrue(self.vty.verify('mgcp', ['']))
723 self.assertEquals(self.vty.node(), 'config-mgcp')
724 self.checkForEndAndExit()
725 self.assertTrue(self.vty.verify('exit', ['']))
726 self.assertEquals(self.vty.node(), 'config')
727 self.assertTrue(self.vty.verify('nat', ['']))
728 self.assertEquals(self.vty.node(), 'config-nat')
729 self.checkForEndAndExit()
730 self.assertTrue(self.vty.verify('bsc 0', ['']))
731 self.assertEquals(self.vty.node(), 'config-nat-bsc')
732 self.checkForEndAndExit()
733 self.assertTrue(self.vty.verify('exit', ['']))
734 self.assertEquals(self.vty.node(), 'config-nat')
735 self.assertTrue(self.vty.verify('exit', ['']))
736 self.assertEquals(self.vty.node(), 'config')
737 self.assertTrue(self.vty.verify('exit', ['']))
738 self.assertTrue(self.vty.node() is None)
739
740 # Check searching for outer node's commands
741 self.vty.command('configure terminal')
742 self.vty.command('mgcp')
743 self.vty.command('nat')
744 self.assertEquals(self.vty.node(), 'config-nat')
Jacob Erlbeckcdf18572013-09-02 13:17:17 +0200745 self.vty.command('mgcp')
746 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200747 self.vty.command('nat')
748 self.assertEquals(self.vty.node(), 'config-nat')
749 self.vty.command('bsc 0')
Jacob Erlbeckcdf18572013-09-02 13:17:17 +0200750 self.vty.command('mgcp')
751 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200752
Holger Hans Peter Freytherbf123a12013-06-25 09:08:02 +0200753 def testRewriteNoRewrite(self):
754 self.vty.enable()
755 res = self.vty.command("configure terminal")
756 res = self.vty.command("nat")
757 res = self.vty.command("number-rewrite rewrite.cfg")
758 res = self.vty.command("no number-rewrite")
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +0200759
Holger Hans Peter Freytherf85852b2015-04-23 20:25:17 -0400760 def testEnsureNoEnsureModeSet(self):
761 self.vty.enable()
762 res = self.vty.command("configure terminal")
763 res = self.vty.command("nat")
764
765 # Ensure the default
766 res = self.vty.command("show running-config")
767 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
768
769 self.vty.command("sdp-ensure-amr-mode-set")
770 res = self.vty.command("show running-config")
771 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
772
773 self.vty.command("no sdp-ensure-amr-mode-set")
774 res = self.vty.command("show running-config")
775 self.assert_(res.find('\n no sdp-ensure-amr-mode-set') > 0)
776
Holger Hans Peter Freythere9c7e272013-06-25 15:38:31 +0200777 def testRewritePostNoRewrite(self):
778 self.vty.enable()
779 self.vty.command("configure terminal")
780 self.vty.command("nat")
781 self.vty.verify("number-rewrite-post rewrite.cfg", [''])
782 self.vty.verify("no number-rewrite-post", [''])
783
784
Holger Hans Peter Freyther367390b2013-06-25 11:44:01 +0200785 def testPrefixTreeLoading(self):
786 cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv")
787
788 self.vty.enable()
789 self.vty.command("configure terminal")
790 self.vty.command("nat")
791 res = self.vty.command("prefix-tree %s" % cfg)
792 self.assertEqual(res, "% prefix-tree loaded 17 rules.")
793 self.vty.command("end")
794
795 res = self.vty.command("show prefix-tree")
796 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')
797
798 self.vty.command("configure terminal")
799 self.vty.command("nat")
800 self.vty.command("no prefix-tree")
801 self.vty.command("end")
802
803 res = self.vty.command("show prefix-tree")
804 self.assertEqual(res, "% there is now prefix tree loaded.")
805
Jacob Erlbeck4684eb62013-08-14 11:10:34 +0200806 def testUssdSideChannelProvider(self):
807 self.vty.command("end")
808 self.vty.enable()
809 self.vty.command("configure terminal")
810 self.vty.command("nat")
811 self.vty.command("ussd-token key")
812 self.vty.command("end")
813
814 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
815 self.assertTrue(res)
816
817 ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
818 ussdSocket.connect(('127.0.0.1', 5001))
819 ussdSocket.settimeout(2.0)
820 print "Connected to %s:%d" % ussdSocket.getpeername()
821
822 print "Expecting ID_GET request"
823 data = ussdSocket.recv(4)
824 self.assertEqual(data, "\x00\x01\xfe\x04")
825
826 print "Going to send ID_RESP response"
Maxfb092392016-04-13 11:36:38 +0200827 res = ipa_send_resp(ussdSocket, "\x6b\x65\x79")
Jacob Erlbeck4684eb62013-08-14 11:10:34 +0200828 self.assertEqual(res, 10)
829
830 # initiating PING/PONG cycle to know, that the ID_RESP message has been processed
831
832 print "Going to send PING request"
Maxfb092392016-04-13 11:36:38 +0200833 res = ipa_send_ping(ussdSocket)
Jacob Erlbeck4684eb62013-08-14 11:10:34 +0200834 self.assertEqual(res, 4)
835
836 print "Expecting PONG response"
837 data = ussdSocket.recv(4)
838 self.assertEqual(data, "\x00\x01\xfe\x01")
839
840 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.'])
841 self.assertTrue(res)
842
843 print "Going to shut down connection"
844 ussdSocket.shutdown(socket.SHUT_WR)
845
846 print "Expecting EOF"
847 data = ussdSocket.recv(4)
848 self.assertEqual(data, "")
849
850 ussdSocket.close()
851
852 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
853 self.assertTrue(res)
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +0200854
Holger Hans Peter Freytherd8afce92014-01-20 10:14:05 +0100855 def testAccessList(self):
856 """
857 Verify that the imsi-deny can have a reject cause or no reject cause
858 """
859 self.vty.enable()
860 self.vty.command("configure terminal")
861 self.vty.command("nat")
862
863 # Old default
864 self.vty.command("access-list test-default imsi-deny ^123[0-9]*$")
865 res = self.vty.command("show running-config").split("\r\n")
866 asserted = False
867 for line in res:
Holger Hans Peter Freyther842137a2014-03-04 15:38:00 +0100868 if line.startswith(" access-list test-default"):
Holger Hans Peter Freytherd8afce92014-01-20 10:14:05 +0100869 self.assertEqual(line, " access-list test-default imsi-deny ^123[0-9]*$ 11 11")
870 asserted = True
871 self.assert_(asserted)
872
873 # Check the optional CM Service Reject Cause
874 self.vty.command("access-list test-cm-deny imsi-deny ^123[0-9]*$ 42").split("\r\n")
875 res = self.vty.command("show running-config").split("\r\n")
876 asserted = False
877 for line in res:
878 if line.startswith(" access-list test-cm"):
879 self.assertEqual(line, " access-list test-cm-deny imsi-deny ^123[0-9]*$ 42 11")
880 asserted = True
881 self.assert_(asserted)
882
883 # Check the optional LU Reject Cause
884 self.vty.command("access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42").split("\r\n")
885 res = self.vty.command("show running-config").split("\r\n")
886 asserted = False
887 for line in res:
888 if line.startswith(" access-list test-lu"):
889 self.assertEqual(line, " access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42")
890 asserted = True
891 self.assert_(asserted)
892
Jacob Erlbeck7553d1c2013-10-23 11:24:15 +0200893class TestVTYGbproxy(TestVTYGenericBSC):
894
895 def vty_command(self):
896 return ["./src/gprs/osmo-gbproxy", "-c",
897 "doc/examples/osmo-gbproxy/osmo-gbproxy.cfg"]
898
899 def vty_app(self):
900 return (4246, "./src/gprs/osmo-gbproxy", "OsmoGbProxy", "bsc")
901
902 def testVtyTree(self):
903 self.vty.enable()
904 self.assertTrue(self.vty.verify('configure terminal', ['']))
905 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbecka4235912013-10-29 09:30:31 +0100906 self.checkForEndAndExit()
Jacob Erlbeck7553d1c2013-10-23 11:24:15 +0200907 self.assertTrue(self.vty.verify('ns', ['']))
908 self.assertEquals(self.vty.node(), 'config-ns')
909 self.checkForEndAndExit()
910 self.assertTrue(self.vty.verify('exit', ['']))
911 self.assertEquals(self.vty.node(), 'config')
912 self.assertTrue(self.vty.verify('gbproxy', ['']))
913 self.assertEquals(self.vty.node(), 'config-gbproxy')
914 self.checkForEndAndExit()
915 self.assertTrue(self.vty.verify('exit', ['']))
916 self.assertEquals(self.vty.node(), 'config')
917
918 def testVtyShow(self):
919 res = self.vty.command("show ns")
920 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
921
922 res = self.vty.command("show gbproxy stats")
923 self.assert_(res.find('GBProxy Global Statistics') >= 0)
924
Jacob Erlbeck7fee9722013-10-24 12:48:23 +0200925 def testVtyDeletePeer(self):
926 self.vty.enable()
927 self.assertTrue(self.vty.verify('delete-gbproxy-peer 9999 bvci 7777', ['BVC not found']))
928 res = self.vty.command("delete-gbproxy-peer 9999 all dry-run")
929 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
930 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
931 res = self.vty.command("delete-gbproxy-peer 9999 only-bvc dry-run")
932 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
933 self.assert_(res.find('Not Deleted 0 NS-VC') < 0)
934 res = self.vty.command("delete-gbproxy-peer 9999 only-nsvc dry-run")
935 self.assert_(res.find('Not Deleted 0 BVC') < 0)
936 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
937 res = self.vty.command("delete-gbproxy-peer 9999 all")
938 self.assert_(res.find('Deleted 0 BVC') >= 0)
939 self.assert_(res.find('Deleted 0 NS-VC') >= 0)
940
Jacob Erlbeckca1c7aa2014-11-04 11:15:01 +0100941class TestVTYSGSN(TestVTYGenericBSC):
942
943 def vty_command(self):
944 return ["./src/gprs/osmo-sgsn", "-c",
945 "doc/examples/osmo-sgsn/osmo-sgsn.cfg"]
946
947 def vty_app(self):
948 return (4245, "./src/gprs/osmo-sgsn", "OsmoSGSN", "sgsn")
949
950 def testVtyTree(self):
951 self.vty.enable()
952 self.assertTrue(self.vty.verify('configure terminal', ['']))
953 self.assertEquals(self.vty.node(), 'config')
954 self.checkForEndAndExit()
955 self.assertTrue(self.vty.verify('ns', ['']))
956 self.assertEquals(self.vty.node(), 'config-ns')
957 self.checkForEndAndExit()
958 self.assertTrue(self.vty.verify('exit', ['']))
959 self.assertEquals(self.vty.node(), 'config')
960 self.assertTrue(self.vty.verify('sgsn', ['']))
961 self.assertEquals(self.vty.node(), 'config-sgsn')
962 self.checkForEndAndExit()
963 self.assertTrue(self.vty.verify('exit', ['']))
964 self.assertEquals(self.vty.node(), 'config')
965
966 def testVtyShow(self):
967 res = self.vty.command("show ns")
968 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
969 self.assertTrue(self.vty.verify('show bssgp', ['']))
970 self.assertTrue(self.vty.verify('show bssgp stats', ['']))
971 # TODO: uncomment when the command does not segfault anymore
972 # self.assertTrue(self.vty.verify('show bssgp nsei 123', ['']))
973 # self.assertTrue(self.vty.verify('show bssgp nsei 123 stats', ['']))
974
975 self.assertTrue(self.vty.verify('show sgsn', ['']))
976 self.assertTrue(self.vty.verify('show mm-context all', ['']))
977 self.assertTrue(self.vty.verify('show mm-context imsi 000001234567', ['No MM context for IMSI 000001234567']))
978 self.assertTrue(self.vty.verify('show pdp-context all', ['']))
979
980 res = self.vty.command("show sndcp")
981 self.assert_(res.find('State of SNDCP Entities') >= 0)
982
983 res = self.vty.command("show llc")
984 self.assert_(res.find('State of LLC Entities') >= 0)
985
Jacob Erlbeckd7b77732014-11-04 10:08:37 +0100986 def testVtyAuth(self):
987 self.vty.enable()
988 self.assertTrue(self.vty.verify('configure terminal', ['']))
989 self.assertEquals(self.vty.node(), 'config')
990 self.assertTrue(self.vty.verify('sgsn', ['']))
991 self.assertEquals(self.vty.node(), 'config-sgsn')
992 self.assertTrue(self.vty.verify('auth-policy accept-all', ['']))
993 res = self.vty.command("show running-config")
994 self.assert_(res.find('auth-policy accept-all') > 0)
995 self.assertTrue(self.vty.verify('auth-policy acl-only', ['']))
996 res = self.vty.command("show running-config")
997 self.assert_(res.find('auth-policy acl-only') > 0)
998 self.assertTrue(self.vty.verify('auth-policy closed', ['']))
999 res = self.vty.command("show running-config")
1000 self.assert_(res.find('auth-policy closed') > 0)
Jacob Erlbeckd04f7cc2014-11-12 10:18:09 +01001001 self.assertTrue(self.vty.verify('auth-policy remote', ['']))
1002 res = self.vty.command("show running-config")
1003 self.assert_(res.find('auth-policy remote') > 0)
Jacob Erlbeckd7b77732014-11-04 10:08:37 +01001004
Jacob Erlbeckc16c3502014-11-11 14:01:48 +01001005 def testVtySubscriber(self):
1006 self.vty.enable()
1007 res = self.vty.command('show subscriber cache')
1008 self.assert_(res.find('1234567890') < 0)
Jacob Erlbeck90e3ead2015-01-19 14:11:46 +01001009 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 create', ['']))
1010 res = self.vty.command('show subscriber cache')
1011 self.assert_(res.find('1234567890') >= 0)
1012 self.assert_(res.find('Authorized: 0') >= 0)
1013 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 update-location-result ok', ['']))
Jacob Erlbeckc16c3502014-11-11 14:01:48 +01001014 res = self.vty.command('show subscriber cache')
1015 self.assert_(res.find('1234567890') >= 0)
1016 self.assert_(res.find('Authorized: 1') >= 0)
Jacob Erlbeck3b0d0c02015-01-27 14:56:40 +01001017 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 cancel update-procedure', ['']))
Jacob Erlbeckc16c3502014-11-11 14:01:48 +01001018 res = self.vty.command('show subscriber cache')
Jacob Erlbeckeafb8492015-01-27 12:41:19 +01001019 self.assert_(res.find('1234567890') >= 0)
1020 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 destroy', ['']))
1021 res = self.vty.command('show subscriber cache')
Jacob Erlbeckc16c3502014-11-11 14:01:48 +01001022 self.assert_(res.find('1234567890') < 0)
1023
Jacob Erlbeck9b3ca642015-02-03 13:47:53 +01001024 def testVtyGgsn(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 self.assertTrue(self.vty.verify('ggsn 0 remote-ip 127.99.99.99', ['']))
1031 self.assertTrue(self.vty.verify('ggsn 0 gtp-version 1', ['']))
1032 self.assertTrue(self.vty.verify('apn * ggsn 0', ['']))
1033 self.assertTrue(self.vty.verify('apn apn1.test ggsn 0', ['']))
1034 self.assertTrue(self.vty.verify('apn apn1.test ggsn 1', ['% a GGSN with id 1 has not been defined']))
1035 self.assertTrue(self.vty.verify('apn apn1.test imsi-prefix 123456 ggsn 0', ['']))
1036 self.assertTrue(self.vty.verify('apn apn2.test imsi-prefix 123456 ggsn 0', ['']))
1037 res = self.vty.command("show running-config")
1038 self.assert_(res.find('ggsn 0 remote-ip 127.99.99.99') >= 0)
1039 self.assert_(res.find('ggsn 0 gtp-version 1') >= 0)
1040 self.assert_(res.find('apn * ggsn 0') >= 0)
1041 self.assert_(res.find('apn apn1.test ggsn 0') >= 0)
1042 self.assert_(res.find('apn apn1.test imsi-prefix 123456 ggsn 0') >= 0)
1043 self.assert_(res.find('apn apn2.test imsi-prefix 123456 ggsn 0') >= 0)
1044
Holger Hans Peter Freyther37391482015-02-06 16:23:29 +01001045 def testVtyEasyAPN(self):
1046 self.vty.enable()
1047 self.assertTrue(self.vty.verify('configure terminal', ['']))
1048 self.assertEquals(self.vty.node(), 'config')
1049 self.assertTrue(self.vty.verify('sgsn', ['']))
1050 self.assertEquals(self.vty.node(), 'config-sgsn')
1051
1052 res = self.vty.command("show running-config")
1053 self.assertEquals(res.find("apn internet"), -1)
1054
1055 self.assertTrue(self.vty.verify("access-point-name internet.apn", ['']))
1056 res = self.vty.command("show running-config")
1057 self.assert_(res.find("apn internet.apn ggsn 0") >= 0)
1058
1059 self.assertTrue(self.vty.verify("no access-point-name internet.apn", ['']))
1060 res = self.vty.command("show running-config")
1061 self.assertEquals(res.find("apn internet"), -1)
1062
Holger Hans Peter Freyther81283872015-05-06 17:46:08 +02001063 def testVtyCDR(self):
1064 self.vty.enable()
1065 self.assertTrue(self.vty.verify('configure terminal', ['']))
1066 self.assertEquals(self.vty.node(), 'config')
1067 self.assertTrue(self.vty.verify('sgsn', ['']))
1068 self.assertEquals(self.vty.node(), 'config-sgsn')
1069
1070 res = self.vty.command("show running-config")
1071 self.assert_(res.find("no cdr filename") > 0)
1072
1073 self.vty.command("cdr filename bla.cdr")
1074 res = self.vty.command("show running-config")
1075 self.assertEquals(res.find("no cdr filename"), -1)
1076 self.assert_(res.find(" cdr filename bla.cdr") > 0)
1077
1078 self.vty.command("no cdr filename")
1079 res = self.vty.command("show running-config")
1080 self.assert_(res.find("no cdr filename") > 0)
1081 self.assertEquals(res.find(" cdr filename bla.cdr"), -1)
1082
1083 res = self.vty.command("show running-config")
1084 self.assert_(res.find(" cdr interval 600") > 0)
1085
1086 self.vty.command("cdr interval 900")
1087 res = self.vty.command("show running-config")
1088 self.assert_(res.find(" cdr interval 900") > 0)
1089 self.assertEquals(res.find(" cdr interval 600"), -1)
1090
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +02001091def add_nat_test(suite, workdir):
1092 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
1093 print("Skipping the NAT test")
1094 return
1095 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT)
1096 suite.addTest(test)
1097
Maxfb092392016-04-13 11:36:38 +02001098def ipa_send_pong(x, verbose = False):
1099 if (verbose):
1100 print "\tBSC -> NAT: PONG!"
1101 return x.send("\x00\x01\xfe\x01")
1102
1103def ipa_send_ping(x, verbose = False):
1104 if (verbose):
1105 print "\tBSC -> NAT: PING?"
1106 return x.send("\x00\x01\xfe\x00")
1107
1108def ipa_send_ack(x, verbose = False):
1109 if (verbose):
1110 print "\tBSC -> NAT: IPA ID ACK"
1111 return x.send("\x00\x01\xfe\x06")
1112
1113def ipa_send_reset(x, verbose = False):
1114 if (verbose):
1115 print "\tBSC -> NAT: RESET"
1116 return x.send("\x00\x12\xfd\x09\x00\x03\x05\x07\x02\x42\xfe\x02\x42\xfe\x06\x00\x04\x30\x04\x01\x20")
1117
1118def ipa_send_resp(x, tk, verbose = False):
1119 if (verbose):
1120 print "\tBSC -> NAT: IPA ID RESP"
1121 return x.send("\x00\x07\xfe\x05\x00\x04\x01" + tk)
1122
Max884b4da2016-04-13 11:36:39 +02001123def nat_bsc_reload(x):
1124 x.vty.command("configure terminal")
1125 x.vty.command("nat")
1126 x.vty.command("bscs-config-file bscs.config")
1127 x.vty.command("end")
1128
Holger Hans Peter Freyther4ad2e142016-04-14 10:05:13 -04001129def nat_msc_ip(x, ip, port):
Max884b4da2016-04-13 11:36:39 +02001130 x.vty.command("configure terminal")
1131 x.vty.command("nat")
1132 x.vty.command("msc ip " + ip)
Holger Hans Peter Freyther6d795892016-04-14 10:40:06 -04001133 x.vty.command("msc port " + str(port))
Max884b4da2016-04-13 11:36:39 +02001134 x.vty.command("end")
1135
1136def data2str(d):
Holger Hans Peter Freyther7db1ff62016-04-14 21:40:04 -04001137 return d.encode('hex').lower()
Max884b4da2016-04-13 11:36:39 +02001138
Holger Hans Peter Freyther4ad2e142016-04-14 10:05:13 -04001139def nat_msc_test(x, ip, port, verbose = False):
Max884b4da2016-04-13 11:36:39 +02001140 msc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1141 msc.settimeout(32)
Holger Hans Peter Freyther4ad2e142016-04-14 10:05:13 -04001142 msc.bind((ip, port))
Max884b4da2016-04-13 11:36:39 +02001143 msc.listen(5)
1144 if (verbose):
1145 print "MSC is ready at " + ip
1146 while "MSC is connected: 0" == x.vty.command("show msc connection"):
1147 conn, addr = msc.accept()
1148 if (verbose):
1149 print "MSC got connection from ", addr
1150 return conn
1151
1152def ipa_handle_small(x, verbose = False):
1153 s = data2str(x.recv(4))
1154 if "0001fe00" == s:
1155 if (verbose):
1156 print "\tBSC <- NAT: PING?"
1157 ipa_send_pong(x, verbose)
1158 elif "0001fe06" == s:
1159 if (verbose):
1160 print "\tBSC <- NAT: IPA ID ACK"
1161 ipa_send_ack(x, verbose)
1162 elif "0001fe00" == s:
1163 if (verbose):
1164 print "\tBSC <- NAT: PONG!"
1165 else:
1166 if (verbose):
1167 print "\tBSC <- NAT: ", s
1168
1169def ipa_handle_resp(x, tk, verbose = False):
1170 s = data2str(x.recv(38))
1171 if "0023fe040108010701020103010401050101010011" in s:
1172 ipa_send_resp(x, tk, verbose)
1173 else:
1174 if (verbose):
1175 print "\tBSC <- NAT: ", s
1176
1177def nat_bsc_num_con(x):
1178 return len(x.vty.command("show bsc connections").split('\n'))
1179
1180def nat_bsc_sock_test(nr, tk, verbose = False):
1181 bsc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Holger Hans Peter Freyther50445972016-04-14 21:13:51 -04001182 bsc.bind(('127.0.0.1', 0))
Max884b4da2016-04-13 11:36:39 +02001183 bsc.connect(('127.0.0.1', 5000))
1184 if (verbose):
1185 print "BSC%d " %nr
1186 print "\tconnected to %s:%d" % bsc.getpeername()
1187 ipa_handle_small(bsc, verbose)
1188 ipa_handle_resp(bsc, tk, verbose)
1189 bsc.recv(27) # MGCP msg
1190 ipa_handle_small(bsc, verbose)
1191 return bsc
1192
Jacob Erlbeck058b1e52013-08-28 10:16:54 +02001193def add_bsc_test(suite, workdir):
1194 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")):
1195 print("Skipping the BSC test")
1196 return
1197 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC)
1198 suite.addTest(test)
1199
Jacob Erlbeck7553d1c2013-10-23 11:24:15 +02001200def add_gbproxy_test(suite, workdir):
1201 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-gbproxy")):
1202 print("Skipping the Gb-Proxy test")
1203 return
1204 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYGbproxy)
1205 suite.addTest(test)
1206
Jacob Erlbeckca1c7aa2014-11-04 11:15:01 +01001207def add_sgsn_test(suite, workdir):
1208 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-sgsn")):
1209 print("Skipping the SGSN test")
1210 return
1211 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYSGSN)
1212 suite.addTest(test)
1213
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +02001214if __name__ == '__main__':
1215 import argparse
1216 import sys
1217
1218 workdir = '.'
1219
1220 parser = argparse.ArgumentParser()
1221 parser.add_argument("-v", "--verbose", dest="verbose",
1222 action="store_true", help="verbose mode")
1223 parser.add_argument("-p", "--pythonconfpath", dest="p",
1224 help="searchpath for config")
1225 parser.add_argument("-w", "--workdir", dest="w",
1226 help="Working directory")
1227 args = parser.parse_args()
1228
1229 verbose_level = 1
1230 if args.verbose:
1231 verbose_level = 2
1232
1233 if args.w:
1234 workdir = args.w
1235
1236 if args.p:
1237 confpath = args.p
1238
1239 print "confpath %s, workdir %s" % (confpath, workdir)
1240 os.chdir(workdir)
1241 print "Running tests for specific VTY commands"
1242 suite = unittest.TestSuite()
Holger Hans Peter Freytherb30b3aa2014-07-04 20:23:56 +02001243 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYMGCP))
Holger Hans Peter Freyther2fb8ebf2013-07-27 21:07:57 +02001244 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB))
Jacob Erlbeck058b1e52013-08-28 10:16:54 +02001245 add_bsc_test(suite, workdir)
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +02001246 add_nat_test(suite, workdir)
Jacob Erlbeck7553d1c2013-10-23 11:24:15 +02001247 add_gbproxy_test(suite, workdir)
Jacob Erlbeckca1c7aa2014-11-04 11:15:01 +01001248 add_sgsn_test(suite, workdir)
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +02001249 res = unittest.TextTestRunner(verbosity=verbose_level).run(suite)
1250 sys.exit(len(res.errors) + len(res.failures))