blob: cf2cf180f03a07b7bc7df017c58e8de4a04c4f0d [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):
Neels Hofmeyr0867b722016-09-28 23:28:06 +020068 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)
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +020072
Neels Hofmeyr0867b722016-09-28 23:28:06 +020073 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)
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +020079
Holger Hans Peter Freyther619b0142014-11-19 16:04:45 +010080 def testOmitAudio(self):
81 self.vty.enable()
Neels Hofmeyr0867b722016-09-28 23:28:06 +020082 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)
Holger Hans Peter Freyther619b0142014-11-19 16:04:45 +010085
Neels Hofmeyr0867b722016-09-28 23:28:06 +020086 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)
Holger Hans Peter Freyther619b0142014-11-19 16:04:45 +010092
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
Neels Hofmeyr0867b722016-09-28 23:28:06 +020098 self.vty.command("configure terminal")
99 self.vty.command("mgcp")
Holger Hans Peter Freytherc390ae82015-08-20 15:15:50 +0200100
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
Maxddee01f2016-05-24 14:23:27 +0200234 def testVtyAuthorization(self):
235 self.vty.enable()
236 self.vty.command("configure terminal")
237 self.vty.command("network")
238 self.assertTrue(self.vty.verify("auth policy closed", ['']))
239 self.assertTrue(self.vty.verify("auth policy regexp", ['']))
240 self.assertTrue(self.vty.verify("authorized-regexp ^001", ['']))
241 self.assertTrue(self.vty.verify("authorized-regexp 02$", ['']))
242 self.assertTrue(self.vty.verify("authorized-regexp *123.*", ['']))
243 self.vty.command("end")
244 self.vty.command("configure terminal")
245 self.vty.command("nitb")
246 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
Maxe6052c42016-06-30 10:25:49 +0200247 self.assertTrue(self.vty.verify("subscriber-create-on-demand no-extension", ['']))
Maxddee01f2016-05-24 14:23:27 +0200248 self.vty.command("end")
249
Max0c1bc262016-04-20 12:06:06 +0200250 def testSi2Q(self):
251 self.vty.enable()
252 self.vty.command("configure terminal")
253 self.vty.command("network")
254 self.vty.command("bts 0")
255 before = self.vty.command("show running-config")
256 self.vty.command("si2quater neighbor-list add earfcn 1911 threshold 11 2")
257 self.vty.command("si2quater neighbor-list add earfcn 1924 threshold 11 3")
258 self.vty.command("si2quater neighbor-list add earfcn 2111 threshold 11")
259 self.vty.command("si2quater neighbor-list del earfcn 1911")
260 self.vty.command("si2quater neighbor-list del earfcn 1924")
261 self.vty.command("si2quater neighbor-list del earfcn 2111")
262 self.assertEquals(before, self.vty.command("show running-config"))
Max26679e02016-04-20 15:57:13 +0200263 self.vty.command("si2quater neighbor-list add uarfcn 1976 13 1")
264 self.vty.command("si2quater neighbor-list add uarfcn 1976 38 1")
265 self.vty.command("si2quater neighbor-list add uarfcn 1976 44 1")
266 self.vty.command("si2quater neighbor-list add uarfcn 1976 120 1")
267 self.vty.command("si2quater neighbor-list add uarfcn 1976 140 1")
268 self.vty.command("si2quater neighbor-list add uarfcn 1976 163 1")
269 self.vty.command("si2quater neighbor-list add uarfcn 1976 166 1")
270 self.vty.command("si2quater neighbor-list add uarfcn 1976 217 1")
271 self.vty.command("si2quater neighbor-list add uarfcn 1976 224 1")
272 self.vty.command("si2quater neighbor-list add uarfcn 1976 225 1")
273 self.vty.command("si2quater neighbor-list add uarfcn 1976 226 1")
274 self.vty.command("si2quater neighbor-list del uarfcn 1976 13")
275 self.vty.command("si2quater neighbor-list del uarfcn 1976 38")
276 self.vty.command("si2quater neighbor-list del uarfcn 1976 44")
277 self.vty.command("si2quater neighbor-list del uarfcn 1976 120")
278 self.vty.command("si2quater neighbor-list del uarfcn 1976 140")
279 self.vty.command("si2quater neighbor-list del uarfcn 1976 163")
280 self.vty.command("si2quater neighbor-list del uarfcn 1976 166")
281 self.vty.command("si2quater neighbor-list del uarfcn 1976 217")
282 self.vty.command("si2quater neighbor-list del uarfcn 1976 224")
283 self.vty.command("si2quater neighbor-list del uarfcn 1976 225")
284 self.vty.command("si2quater neighbor-list del uarfcn 1976 226")
285 self.assertEquals(before, self.vty.command("show running-config"))
Max0c1bc262016-04-20 12:06:06 +0200286
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200287 def testEnableDisablePeriodicLU(self):
288 self.vty.enable()
289 self.vty.command("configure terminal")
290 self.vty.command("network")
291 self.vty.command("bts 0")
292
293 # Test invalid input
294 self.vty.verify("periodic location update 0", ['% Unknown command.'])
295 self.vty.verify("periodic location update 5", ['% Unknown command.'])
296 self.vty.verify("periodic location update 1531", ['% Unknown command.'])
297
298 # Enable periodic lu..
299 self.vty.verify("periodic location update 60", [''])
300 res = self.vty.command("write terminal")
Holger Hans Peter Freytherc0438e32013-07-27 22:23:25 +0200301 self.assert_(res.find('periodic location update 60') > 0)
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200302 self.assertEquals(res.find('no periodic location update'), -1)
303
304 # Now disable it..
305 self.vty.verify("no periodic location update", [''])
306 res = self.vty.command("write terminal")
307 self.assertEquals(res.find('periodic location update 60'), -1)
Holger Hans Peter Freytherc0438e32013-07-27 22:23:25 +0200308 self.assert_(res.find('no periodic location update') > 0)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200309
Jacob Erlbeck65d114f2014-01-16 11:02:14 +0100310 def testEnableDisableSiHacks(self):
311 self.vty.enable()
312 self.vty.command("configure terminal")
313 self.vty.command("network")
314 self.vty.command("bts 0")
315
316 # Enable periodic lu..
317 self.vty.verify("force-combined-si", [''])
318 res = self.vty.command("write terminal")
319 self.assert_(res.find(' force-combined-si') > 0)
320 self.assertEquals(res.find('no force-combined-si'), -1)
321
322 # Now disable it..
323 self.vty.verify("no force-combined-si", [''])
324 res = self.vty.command("write terminal")
325 self.assertEquals(res.find(' force-combined-si'), -1)
326 self.assert_(res.find('no force-combined-si') > 0)
327
Ivan Kluchnikov67920592013-09-16 13:13:04 +0400328 def testRachAccessControlClass(self):
329 self.vty.enable()
330 self.vty.command("configure terminal")
331 self.vty.command("network")
332 self.vty.command("bts 0")
333
334 # Test invalid input
335 self.vty.verify("rach access-control-class", ['% Command incomplete.'])
336 self.vty.verify("rach access-control-class 1", ['% Command incomplete.'])
337 self.vty.verify("rach access-control-class -1", ['% Unknown command.'])
338 self.vty.verify("rach access-control-class 10", ['% Unknown command.'])
339 self.vty.verify("rach access-control-class 16", ['% Unknown command.'])
340
341 # Barred rach access control classes
342 for classNum in range(16):
343 if classNum != 10:
344 self.vty.verify("rach access-control-class " + str(classNum) + " barred", [''])
345
346 # Verify settings
347 res = self.vty.command("write terminal")
348 for classNum in range(16):
349 if classNum != 10:
350 self.assert_(res.find("rach access-control-class " + str(classNum) + " barred") > 0)
351
352 # Allowed rach access control classes
353 for classNum in range(16):
354 if classNum != 10:
355 self.vty.verify("rach access-control-class " + str(classNum) + " allowed", [''])
356
357 # Verify settings
358 res = self.vty.command("write terminal")
359 for classNum in range(16):
360 if classNum != 10:
361 self.assertEquals(res.find("rach access-control-class " + str(classNum) + " barred"), -1)
362
Holger Hans Peter Freytherde392252016-04-01 19:44:00 +0200363 def testSubscriberCreateDeleteTwice(self):
364 """
365 OS#1657 indicates that there might be an issue creating the
366 same subscriber twice. This test will use the VTY command to
367 create a subscriber and then issue a second create command
368 with the same IMSI. The test passes if the VTY continues to
369 respond to VTY commands.
370 """
371 self.vty.enable()
372
373 imsi = "204300854013739"
374
375 # Initially we don't have this subscriber
376 self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi])
377
378 # Lets create one
379 res = self.vty.command('subscriber create imsi '+imsi)
380 self.assert_(res.find(" IMSI: "+imsi) > 0)
381 # And now create one again.
382 res2 = self.vty.command('subscriber create imsi '+imsi)
383 self.assert_(res2.find(" IMSI: "+imsi) > 0)
384 self.assertEqual(res, res2)
385
386 # Verify it has been created
387 res = self.vty.command('show subscriber imsi '+imsi)
388 self.assert_(res.find(" IMSI: "+imsi) > 0)
389
390 # Delete it
Max488902d2016-06-22 14:02:39 +0200391 res = self.vty.command('subscriber imsi ' + imsi + ' delete')
392 self.assert_("" == res)
Holger Hans Peter Freytherde392252016-04-01 19:44:00 +0200393
394 # Now it should not be there anymore
395 res = self.vty.command('show subscriber imsi '+imsi)
Max488902d2016-06-22 14:02:39 +0200396 self.assert_(('% No subscriber found for imsi ' + imsi) == res)
Holger Hans Peter Freytherde392252016-04-01 19:44:00 +0200397
398
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500399 def testSubscriberCreateDelete(self):
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200400 self.vty.enable()
401
402 imsi = "204300854013739"
Maxe6052c42016-06-30 10:25:49 +0200403 imsi2 = "222301824913762"
404 imsi3 = "333500854113763"
405 imsi4 = "444583744053764"
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200406
407 # Initially we don't have this subscriber
408 self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi])
409
410 # Lets create one
411 res = self.vty.command('subscriber create imsi '+imsi)
412 self.assert_(res.find(" IMSI: "+imsi) > 0)
Maxe6052c42016-06-30 10:25:49 +0200413 self.assert_(res.find("Extension") > 0)
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200414
415 # Now we have it
416 res = self.vty.command('show subscriber imsi '+imsi)
417 self.assert_(res.find(" IMSI: "+imsi) > 0)
418
Maxe6052c42016-06-30 10:25:49 +0200419 # With narrow random interval
420 self.vty.command("configure terminal")
421 self.vty.command("nitb")
422 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
423 # wrong interval
424 res = self.vty.command("subscriber-create-on-demand random 221 122")
425 # error string will contain arguments
426 self.assert_(res.find("122") > 0)
427 self.assert_(res.find("221") > 0)
428 # correct interval - silent ok
429 self.assertTrue(self.vty.verify("subscriber-create-on-demand random 221 222", ['']))
430 self.vty.command("end")
431
432 res = self.vty.command('subscriber create imsi ' + imsi2)
433 self.assert_(res.find(" IMSI: " + imsi2) > 0)
434 self.assert_(res.find("221") > 0 or res.find("222") > 0)
435 self.assert_(res.find(" Extension: ") > 0)
436
437 # Without extension
438 self.vty.command("configure terminal")
439 self.vty.command("nitb")
440 self.assertTrue(self.vty.verify("subscriber-create-on-demand no-extension", ['']))
441 self.vty.command("end")
442 res = self.vty.command('subscriber create imsi ' + imsi3)
443 self.assert_(res.find(" IMSI: " + imsi3) > 0)
444 self.assertEquals(res.find("Extension"), -1)
445
446 # With extension again
447 self.vty.command("configure terminal")
448 self.vty.command("nitb")
449 self.assertTrue(self.vty.verify("no subscriber-create-on-demand", ['']))
450 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
451 self.assertTrue(self.vty.verify("subscriber-create-on-demand random 221 666", ['']))
452 self.vty.command("end")
453
454 res = self.vty.command('subscriber create imsi ' + imsi4)
455 self.assert_(res.find(" IMSI: " + imsi4) > 0)
456 self.assert_(res.find(" Extension: ") > 0)
457
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500458 # Delete it
Max488902d2016-06-22 14:02:39 +0200459 res = self.vty.command('subscriber imsi ' + imsi + ' delete')
460 self.assert_("" == res)
Maxe6052c42016-06-30 10:25:49 +0200461 res = self.vty.command('subscriber imsi ' + imsi2 + ' delete')
462 self.assert_("" == res)
463 res = self.vty.command('subscriber imsi ' + imsi3 + ' delete')
464 self.assert_("" == res)
465 res = self.vty.command('subscriber imsi ' + imsi4 + ' delete')
466 self.assert_("" == res)
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500467
468 # Now it should not be there anymore
469 res = self.vty.command('show subscriber imsi '+imsi)
Max488902d2016-06-22 14:02:39 +0200470 self.assert_(('% No subscriber found for imsi ' + imsi) == res)
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500471
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200472 def testSubscriberSettings(self):
473 self.vty.enable()
474
475 imsi = "204300854013739"
Max0fcd2e22016-06-07 15:32:16 +0200476 imsi2 = "204301824913769"
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200477 wrong_imsi = "204300999999999"
478
479 # Lets create one
480 res = self.vty.command('subscriber create imsi '+imsi)
481 self.assert_(res.find(" IMSI: "+imsi) > 0)
Max0fcd2e22016-06-07 15:32:16 +0200482 self.assert_(res.find("Extension") > 0)
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200483
484 self.vty.verify('subscriber imsi '+wrong_imsi+' name wrong', ['% No subscriber found for imsi '+wrong_imsi])
485 res = self.vty.command('subscriber imsi '+imsi+' name '+('X' * 160))
486 self.assert_(res.find("NAME is too long") > 0)
487
488 self.vty.verify('subscriber imsi '+imsi+' name '+('G' * 159), [''])
489
490 self.vty.verify('subscriber imsi '+wrong_imsi+' extension 840', ['% No subscriber found for imsi '+wrong_imsi])
491 res = self.vty.command('subscriber imsi '+imsi+' extension '+('9' * 15))
492 self.assert_(res.find("EXTENSION is too long") > 0)
493
494 self.vty.verify('subscriber imsi '+imsi+' extension '+('1' * 14), [''])
495
Max0fcd2e22016-06-07 15:32:16 +0200496 # With narrow random interval
497 self.vty.command("configure terminal")
498 self.vty.command("nitb")
499 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
500 # wrong interval
501 res = self.vty.command("subscriber-create-on-demand random 221 122")
502 self.assert_(res.find("122") > 0)
503 self.assert_(res.find("221") > 0)
504 # correct interval
505 self.assertTrue(self.vty.verify("subscriber-create-on-demand random 221 222", ['']))
506 self.vty.command("end")
507
Max488902d2016-06-22 14:02:39 +0200508 # create subscriber with extension in a configured interval
Max0fcd2e22016-06-07 15:32:16 +0200509 res = self.vty.command('subscriber create imsi ' + imsi2)
510 self.assert_(res.find(" IMSI: " + imsi2) > 0)
511 self.assert_(res.find("221") > 0 or res.find("222") > 0)
512 self.assert_(res.find(" Extension: ") > 0)
513
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200514 # Delete it
Max488902d2016-06-22 14:02:39 +0200515 res = self.vty.command('subscriber imsi ' + imsi + ' delete')
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200516 self.assert_(res != "")
Max488902d2016-06-22 14:02:39 +0200517 # imsi2 is inactive so deletion should succeed
518 res = self.vty.command('subscriber imsi ' + imsi2 + ' delete')
519 self.assert_("" == res)
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200520
Holger Hans Peter Freytherec37bb22013-02-05 09:39:09 +0100521 def testShowPagingGroup(self):
522 res = self.vty.command("show paging-group 255 1234567")
523 self.assertEqual(res, "% can't find BTS 255")
524 res = self.vty.command("show paging-group 0 1234567")
525 self.assertEquals(res, "%Paging group for IMSI 1234567 on BTS #0 is 7")
526
Ciabyec6e4f82014-03-06 17:20:55 +0100527 def testShowNetwork(self):
528 res = self.vty.command("show network")
529 self.assert_(res.startswith('BSC is on Country Code') >= 0)
530
Holger Hans Peter Freyther86573262015-01-31 09:47:37 +0100531 def testMeasurementFeed(self):
532 self.vty.enable()
533 self.vty.command("configure terminal")
534 self.vty.command("mncc-int")
535
536 res = self.vty.command("write terminal")
537 self.assertEquals(res.find('meas-feed scenario'), -1)
538
539 self.vty.command("meas-feed scenario bla")
540 res = self.vty.command("write terminal")
541 self.assert_(res.find('meas-feed scenario bla') > 0)
542
Neels Hofmeyr0867b722016-09-28 23:28:06 +0200543 self.vty.command("meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890")
Holger Hans Peter Freyther86573262015-01-31 09:47:37 +0100544 res = self.vty.command("write terminal")
545 self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890'), -1)
546 self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz012345'), -1)
547 self.assert_(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234') > 0)
548
549
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200550class TestVTYBSC(TestVTYGenericBSC):
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200551
552 def vty_command(self):
553 return ["./src/osmo-bsc/osmo-bsc", "-c",
554 "doc/examples/osmo-bsc/osmo-bsc.cfg"]
555
556 def vty_app(self):
557 return (4242, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc")
558
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200559 def testConfigNetworkTree(self):
Jacob Erlbeck75877272013-10-23 11:24:14 +0200560 self._testConfigNetworkTree()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200561
562 def testVtyTree(self):
563 self.vty.enable()
564 self.assertTrue(self.vty.verify("configure terminal", ['']))
565 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100566 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200567 self.assertTrue(self.vty.verify("msc 0", ['']))
568 self.assertEquals(self.vty.node(), 'config-msc')
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200569 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200570 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200571 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200572 self.assertTrue(self.vty.verify("bsc", ['']))
573 self.assertEquals(self.vty.node(), 'config-bsc')
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200574 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200575 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200576 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200577 self.assertTrue(self.vty.verify("exit", ['']))
578 self.assertTrue(self.vty.node() is None)
579
580 # Check searching for outer node's commands
581 self.vty.command("configure terminal")
582 self.vty.command('msc 0')
583 self.vty.command("bsc")
584 self.assertEquals(self.vty.node(), 'config-bsc')
585 self.vty.command("msc 0")
586 self.assertEquals(self.vty.node(), 'config-msc')
587
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200588 def testUssdNotificationsMsc(self):
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200589 self.vty.enable()
590 self.vty.command("configure terminal")
591 self.vty.command("msc")
592
593 # Test invalid input
594 self.vty.verify("bsc-msc-lost-text", ['% Command incomplete.'])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200595 self.vty.verify("bsc-welcome-text", ['% Command incomplete.'])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200596 self.vty.verify("bsc-grace-text", ['% Command incomplete.'])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200597
598 # Enable USSD notifications
599 self.vty.verify("bsc-msc-lost-text MSC disconnected", [''])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200600 self.vty.verify("bsc-welcome-text Hello MS", [''])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200601 self.vty.verify("bsc-grace-text In grace period", [''])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200602
603 # Verify settings
604 res = self.vty.command("write terminal")
605 self.assert_(res.find('bsc-msc-lost-text MSC disconnected') > 0)
606 self.assertEquals(res.find('no bsc-msc-lost-text'), -1)
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200607 self.assert_(res.find('bsc-welcome-text Hello MS') > 0)
608 self.assertEquals(res.find('no bsc-welcome-text'), -1)
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200609 self.assert_(res.find('bsc-grace-text In grace period') > 0)
610 self.assertEquals(res.find('no bsc-grace-text'), -1)
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200611
612 # Now disable it..
613 self.vty.verify("no bsc-msc-lost-text", [''])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200614 self.vty.verify("no bsc-welcome-text", [''])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200615 self.vty.verify("no bsc-grace-text", [''])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200616
617 # Verify settings
618 res = self.vty.command("write terminal")
619 self.assertEquals(res.find('bsc-msc-lost-text MSC disconnected'), -1)
620 self.assert_(res.find('no bsc-msc-lost-text') > 0)
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200621 self.assertEquals(res.find('bsc-welcome-text Hello MS'), -1)
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200622 self.assert_(res.find('no bsc-welcome-text') > 0)
623 self.assertEquals(res.find('bsc-grace-text In grace period'), -1)
624 self.assert_(res.find('no bsc-grace-text') > 0)
625
626 def testUssdNotificationsBsc(self):
627 self.vty.enable()
628 self.vty.command("configure terminal")
629 self.vty.command("bsc")
630
631 # Test invalid input
632 self.vty.verify("missing-msc-text", ['% Command incomplete.'])
633
634 # Enable USSD notifications
635 self.vty.verify("missing-msc-text No MSC found", [''])
636
637 # Verify settings
638 res = self.vty.command("write terminal")
639 self.assert_(res.find('missing-msc-text No MSC found') > 0)
640 self.assertEquals(res.find('no missing-msc-text'), -1)
641
642 # Now disable it..
643 self.vty.verify("no missing-msc-text", [''])
644
645 # Verify settings
646 res = self.vty.command("write terminal")
647 self.assertEquals(res.find('missing-msc-text No MSC found'), -1)
648 self.assert_(res.find('no missing-msc-text') > 0)
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200649
Jacob Erlbeck946d1412013-09-17 13:59:29 +0200650 def testNetworkTimezone(self):
651 self.vty.enable()
652 self.vty.verify("configure terminal", [''])
653 self.vty.verify("network", [''])
Jacob Erlbeck946d1412013-09-17 13:59:29 +0200654
655 # Test invalid input
656 self.vty.verify("timezone", ['% Command incomplete.'])
657 self.vty.verify("timezone 20 0", ['% Unknown command.'])
658 self.vty.verify("timezone 0 11", ['% Unknown command.'])
659 self.vty.verify("timezone 0 0 99", ['% Unknown command.'])
660
661 # Set time zone without DST
662 self.vty.verify("timezone 2 30", [''])
663
664 # Verify settings
665 res = self.vty.command("write terminal")
666 self.assert_(res.find('timezone 2 30') > 0)
667 self.assertEquals(res.find('timezone 2 30 '), -1)
668
669 # Set time zone with DST
670 self.vty.verify("timezone 2 30 1", [''])
671
672 # Verify settings
673 res = self.vty.command("write terminal")
674 self.assert_(res.find('timezone 2 30 1') > 0)
675
676 # Now disable it..
677 self.vty.verify("no timezone", [''])
678
679 # Verify settings
680 res = self.vty.command("write terminal")
681 self.assertEquals(res.find(' timezone'), -1)
682
Ciabyec6e4f82014-03-06 17:20:55 +0100683 def testShowNetwork(self):
684 res = self.vty.command("show network")
685 self.assert_(res.startswith('BSC is on Country Code') >= 0)
686
Holger Hans Peter Freytherdb64f2e2014-10-29 10:06:15 +0100687 def testPingPongConfiguration(self):
688 self.vty.enable()
689 self.vty.verify("configure terminal", [''])
690 self.vty.verify("network", [''])
691 self.vty.verify("msc 0", [''])
692
693 self.vty.verify("timeout-ping 12", [''])
694 self.vty.verify("timeout-pong 14", [''])
695 res = self.vty.command("show running-config")
696 self.assert_(res.find(" timeout-ping 12") > 0)
697 self.assert_(res.find(" timeout-pong 14") > 0)
698 self.assert_(res.find(" no timeout-ping advanced") > 0)
699
700 self.vty.verify("timeout-ping advanced", [''])
701 res = self.vty.command("show running-config")
702 self.assert_(res.find(" timeout-ping 12") > 0)
703 self.assert_(res.find(" timeout-pong 14") > 0)
704 self.assert_(res.find(" timeout-ping advanced") > 0)
705
706 self.vty.verify("no timeout-ping advanced", [''])
707 res = self.vty.command("show running-config")
708 self.assert_(res.find(" timeout-ping 12") > 0)
709 self.assert_(res.find(" timeout-pong 14") > 0)
710 self.assert_(res.find(" no timeout-ping advanced") > 0)
711
712 self.vty.verify("no timeout-ping", [''])
713 res = self.vty.command("show running-config")
714 self.assertEquals(res.find(" timeout-ping 12"), -1)
715 self.assertEquals(res.find(" timeout-pong 14"), -1)
716 self.assertEquals(res.find(" no timeout-ping advanced"), -1)
717 self.assert_(res.find(" no timeout-ping") > 0)
718
719 self.vty.verify("timeout-ping advanced", ['%ping handling is disabled. Enable it first.'])
720
721 # And back to enabling it
722 self.vty.verify("timeout-ping 12", [''])
723 self.vty.verify("timeout-pong 14", [''])
724 res = self.vty.command("show running-config")
725 self.assert_(res.find(" timeout-ping 12") > 0)
726 self.assert_(res.find(" timeout-pong 14") > 0)
727 self.assert_(res.find(" timeout-ping advanced") > 0)
728
Holger Hans Peter Freyther32dd2f32015-04-01 18:15:48 +0200729 def testMscDataCoreLACCI(self):
730 self.vty.enable()
731 res = self.vty.command("show running-config")
732 self.assertEquals(res.find("core-location-area-code"), -1)
733 self.assertEquals(res.find("core-cell-identity"), -1)
734
Neels Hofmeyr0867b722016-09-28 23:28:06 +0200735 self.vty.command("configure terminal")
Holger Hans Peter Freyther32dd2f32015-04-01 18:15:48 +0200736 self.vty.command("msc 0")
737 self.vty.command("core-location-area-code 666")
738 self.vty.command("core-cell-identity 333")
739
740 res = self.vty.command("show running-config")
741 self.assert_(res.find("core-location-area-code 666") > 0)
742 self.assert_(res.find("core-cell-identity 333") > 0)
743
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200744class TestVTYNAT(TestVTYGenericBSC):
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200745
746 def vty_command(self):
Max49364482016-04-13 11:36:39 +0200747 return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-l", "127.0.0.1", "-c",
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200748 "doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"]
749
750 def vty_app(self):
751 return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat")
752
Max49364482016-04-13 11:36:39 +0200753 def testBSCreload(self):
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -0400754 # Use different port for the mock msc to avoid clashing with
755 # the osmo-bsc_nat itself
Holger Hans Peter Freytherf1a61bb2016-04-14 08:50:25 -0400756 ip = "127.0.0.1"
Holger Hans Peter Freythere98c9c72016-04-14 10:58:58 -0400757 port = 5522
Max49364482016-04-13 11:36:39 +0200758 self.vty.enable()
759 bscs1 = self.vty.command("show bscs-config")
760 nat_bsc_reload(self)
761 bscs2 = self.vty.command("show bscs-config")
762 # check that multiple calls to bscs-config-file give the same result
763 self.assertEquals(bscs1, bscs2)
764
765 # add new bsc
766 self.vty.command("configure terminal")
767 self.vty.command("nat")
768 self.vty.command("bsc 5")
769 self.vty.command("token key")
770 self.vty.command("location_area_code 666")
771 self.vty.command("end")
772
773 # update bsc token
774 self.vty.command("configure terminal")
775 self.vty.command("nat")
776 self.vty.command("bsc 1")
777 self.vty.command("token xyu")
778 self.vty.command("end")
779
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -0400780 nat_msc_ip(self, ip, port)
781 msc = nat_msc_test(self, ip, port)
Max49364482016-04-13 11:36:39 +0200782 b0 = nat_bsc_sock_test(0, "lol")
783 b1 = nat_bsc_sock_test(1, "xyu")
784 b2 = nat_bsc_sock_test(5, "key")
785
786 self.assertEquals("3 BSCs configured", self.vty.command("show nat num-bscs-configured"))
787 self.assertTrue(3 == nat_bsc_num_con(self))
788 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
789
790 nat_bsc_reload(self)
791 bscs2 = self.vty.command("show bscs-config")
792 # check that the reset to initial config succeeded
793 self.assertEquals(bscs1, bscs2)
794
795 self.assertEquals("2 BSCs configured", self.vty.command("show nat num-bscs-configured"))
796 self.assertTrue(1 == nat_bsc_num_con(self))
797 rem = self.vty.command("show bsc connections").split(' ')
798 # remaining connection is for BSC0
799 self.assertEquals('0', rem[2])
800 # remaining connection is authorized
801 self.assertEquals('1', rem[4])
802 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
803
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200804 def testVtyTree(self):
805 self.vty.enable()
806 self.assertTrue(self.vty.verify('configure terminal', ['']))
807 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100808 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200809 self.assertTrue(self.vty.verify('mgcp', ['']))
810 self.assertEquals(self.vty.node(), 'config-mgcp')
811 self.checkForEndAndExit()
812 self.assertTrue(self.vty.verify('exit', ['']))
813 self.assertEquals(self.vty.node(), 'config')
814 self.assertTrue(self.vty.verify('nat', ['']))
815 self.assertEquals(self.vty.node(), 'config-nat')
816 self.checkForEndAndExit()
817 self.assertTrue(self.vty.verify('bsc 0', ['']))
818 self.assertEquals(self.vty.node(), 'config-nat-bsc')
819 self.checkForEndAndExit()
820 self.assertTrue(self.vty.verify('exit', ['']))
821 self.assertEquals(self.vty.node(), 'config-nat')
822 self.assertTrue(self.vty.verify('exit', ['']))
823 self.assertEquals(self.vty.node(), 'config')
824 self.assertTrue(self.vty.verify('exit', ['']))
825 self.assertTrue(self.vty.node() is None)
826
827 # Check searching for outer node's commands
828 self.vty.command('configure terminal')
829 self.vty.command('mgcp')
830 self.vty.command('nat')
831 self.assertEquals(self.vty.node(), 'config-nat')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200832 self.vty.command('mgcp')
833 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200834 self.vty.command('nat')
835 self.assertEquals(self.vty.node(), 'config-nat')
836 self.vty.command('bsc 0')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200837 self.vty.command('mgcp')
838 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200839
Holger Hans Peter Freytherb718ad32013-06-25 09:08:02 +0200840 def testRewriteNoRewrite(self):
841 self.vty.enable()
842 res = self.vty.command("configure terminal")
843 res = self.vty.command("nat")
844 res = self.vty.command("number-rewrite rewrite.cfg")
845 res = self.vty.command("no number-rewrite")
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200846
Holger Hans Peter Freyther7f100c92015-04-23 20:25:17 -0400847 def testEnsureNoEnsureModeSet(self):
848 self.vty.enable()
849 res = self.vty.command("configure terminal")
850 res = self.vty.command("nat")
851
852 # Ensure the default
853 res = self.vty.command("show running-config")
854 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
855
856 self.vty.command("sdp-ensure-amr-mode-set")
857 res = self.vty.command("show running-config")
858 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
859
860 self.vty.command("no sdp-ensure-amr-mode-set")
861 res = self.vty.command("show running-config")
862 self.assert_(res.find('\n no sdp-ensure-amr-mode-set') > 0)
863
Holger Hans Peter Freyther67e423c2013-06-25 15:38:31 +0200864 def testRewritePostNoRewrite(self):
865 self.vty.enable()
866 self.vty.command("configure terminal")
867 self.vty.command("nat")
868 self.vty.verify("number-rewrite-post rewrite.cfg", [''])
869 self.vty.verify("no number-rewrite-post", [''])
870
871
Holger Hans Peter Freytherddf191e2013-06-25 11:44:01 +0200872 def testPrefixTreeLoading(self):
873 cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv")
874
875 self.vty.enable()
876 self.vty.command("configure terminal")
877 self.vty.command("nat")
878 res = self.vty.command("prefix-tree %s" % cfg)
879 self.assertEqual(res, "% prefix-tree loaded 17 rules.")
880 self.vty.command("end")
881
882 res = self.vty.command("show prefix-tree")
883 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')
884
885 self.vty.command("configure terminal")
886 self.vty.command("nat")
887 self.vty.command("no prefix-tree")
888 self.vty.command("end")
889
890 res = self.vty.command("show prefix-tree")
891 self.assertEqual(res, "% there is now prefix tree loaded.")
892
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200893 def testUssdSideChannelProvider(self):
894 self.vty.command("end")
895 self.vty.enable()
896 self.vty.command("configure terminal")
897 self.vty.command("nat")
898 self.vty.command("ussd-token key")
899 self.vty.command("end")
900
901 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
902 self.assertTrue(res)
903
904 ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
905 ussdSocket.connect(('127.0.0.1', 5001))
906 ussdSocket.settimeout(2.0)
907 print "Connected to %s:%d" % ussdSocket.getpeername()
908
909 print "Expecting ID_GET request"
910 data = ussdSocket.recv(4)
911 self.assertEqual(data, "\x00\x01\xfe\x04")
912
913 print "Going to send ID_RESP response"
Max70cf7292016-04-13 11:36:38 +0200914 res = ipa_send_resp(ussdSocket, "\x6b\x65\x79")
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200915 self.assertEqual(res, 10)
916
917 # initiating PING/PONG cycle to know, that the ID_RESP message has been processed
918
919 print "Going to send PING request"
Max70cf7292016-04-13 11:36:38 +0200920 res = ipa_send_ping(ussdSocket)
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200921 self.assertEqual(res, 4)
922
923 print "Expecting PONG response"
924 data = ussdSocket.recv(4)
925 self.assertEqual(data, "\x00\x01\xfe\x01")
926
927 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.'])
928 self.assertTrue(res)
929
930 print "Going to shut down connection"
931 ussdSocket.shutdown(socket.SHUT_WR)
932
933 print "Expecting EOF"
934 data = ussdSocket.recv(4)
935 self.assertEqual(data, "")
936
937 ussdSocket.close()
938
939 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
940 self.assertTrue(res)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200941
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100942 def testAccessList(self):
943 """
944 Verify that the imsi-deny can have a reject cause or no reject cause
945 """
946 self.vty.enable()
947 self.vty.command("configure terminal")
948 self.vty.command("nat")
949
950 # Old default
951 self.vty.command("access-list test-default imsi-deny ^123[0-9]*$")
952 res = self.vty.command("show running-config").split("\r\n")
953 asserted = False
954 for line in res:
Holger Hans Peter Freyther4ecc6872014-03-04 15:38:00 +0100955 if line.startswith(" access-list test-default"):
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100956 self.assertEqual(line, " access-list test-default imsi-deny ^123[0-9]*$ 11 11")
957 asserted = True
958 self.assert_(asserted)
959
960 # Check the optional CM Service Reject Cause
961 self.vty.command("access-list test-cm-deny imsi-deny ^123[0-9]*$ 42").split("\r\n")
962 res = self.vty.command("show running-config").split("\r\n")
963 asserted = False
964 for line in res:
965 if line.startswith(" access-list test-cm"):
966 self.assertEqual(line, " access-list test-cm-deny imsi-deny ^123[0-9]*$ 42 11")
967 asserted = True
968 self.assert_(asserted)
969
970 # Check the optional LU Reject Cause
971 self.vty.command("access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42").split("\r\n")
972 res = self.vty.command("show running-config").split("\r\n")
973 asserted = False
974 for line in res:
975 if line.startswith(" access-list test-lu"):
976 self.assertEqual(line, " access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42")
977 asserted = True
978 self.assert_(asserted)
979
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200980class TestVTYGbproxy(TestVTYGenericBSC):
981
982 def vty_command(self):
983 return ["./src/gprs/osmo-gbproxy", "-c",
984 "doc/examples/osmo-gbproxy/osmo-gbproxy.cfg"]
985
986 def vty_app(self):
987 return (4246, "./src/gprs/osmo-gbproxy", "OsmoGbProxy", "bsc")
988
989 def testVtyTree(self):
990 self.vty.enable()
991 self.assertTrue(self.vty.verify('configure terminal', ['']))
992 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100993 self.checkForEndAndExit()
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200994 self.assertTrue(self.vty.verify('ns', ['']))
995 self.assertEquals(self.vty.node(), 'config-ns')
996 self.checkForEndAndExit()
997 self.assertTrue(self.vty.verify('exit', ['']))
998 self.assertEquals(self.vty.node(), 'config')
999 self.assertTrue(self.vty.verify('gbproxy', ['']))
1000 self.assertEquals(self.vty.node(), 'config-gbproxy')
1001 self.checkForEndAndExit()
1002 self.assertTrue(self.vty.verify('exit', ['']))
1003 self.assertEquals(self.vty.node(), 'config')
1004
1005 def testVtyShow(self):
1006 res = self.vty.command("show ns")
1007 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
1008
1009 res = self.vty.command("show gbproxy stats")
1010 self.assert_(res.find('GBProxy Global Statistics') >= 0)
1011
Jacob Erlbeck4211d792013-10-24 12:48:23 +02001012 def testVtyDeletePeer(self):
1013 self.vty.enable()
1014 self.assertTrue(self.vty.verify('delete-gbproxy-peer 9999 bvci 7777', ['BVC not found']))
1015 res = self.vty.command("delete-gbproxy-peer 9999 all dry-run")
1016 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
1017 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
1018 res = self.vty.command("delete-gbproxy-peer 9999 only-bvc dry-run")
1019 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
1020 self.assert_(res.find('Not Deleted 0 NS-VC') < 0)
1021 res = self.vty.command("delete-gbproxy-peer 9999 only-nsvc dry-run")
1022 self.assert_(res.find('Not Deleted 0 BVC') < 0)
1023 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
1024 res = self.vty.command("delete-gbproxy-peer 9999 all")
1025 self.assert_(res.find('Deleted 0 BVC') >= 0)
1026 self.assert_(res.find('Deleted 0 NS-VC') >= 0)
1027
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001028class TestVTYSGSN(TestVTYGenericBSC):
1029
1030 def vty_command(self):
1031 return ["./src/gprs/osmo-sgsn", "-c",
1032 "doc/examples/osmo-sgsn/osmo-sgsn.cfg"]
1033
1034 def vty_app(self):
1035 return (4245, "./src/gprs/osmo-sgsn", "OsmoSGSN", "sgsn")
1036
1037 def testVtyTree(self):
1038 self.vty.enable()
1039 self.assertTrue(self.vty.verify('configure terminal', ['']))
1040 self.assertEquals(self.vty.node(), 'config')
1041 self.checkForEndAndExit()
1042 self.assertTrue(self.vty.verify('ns', ['']))
1043 self.assertEquals(self.vty.node(), 'config-ns')
1044 self.checkForEndAndExit()
1045 self.assertTrue(self.vty.verify('exit', ['']))
1046 self.assertEquals(self.vty.node(), 'config')
1047 self.assertTrue(self.vty.verify('sgsn', ['']))
1048 self.assertEquals(self.vty.node(), 'config-sgsn')
1049 self.checkForEndAndExit()
1050 self.assertTrue(self.vty.verify('exit', ['']))
1051 self.assertEquals(self.vty.node(), 'config')
1052
1053 def testVtyShow(self):
1054 res = self.vty.command("show ns")
1055 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
1056 self.assertTrue(self.vty.verify('show bssgp', ['']))
1057 self.assertTrue(self.vty.verify('show bssgp stats', ['']))
1058 # TODO: uncomment when the command does not segfault anymore
1059 # self.assertTrue(self.vty.verify('show bssgp nsei 123', ['']))
1060 # self.assertTrue(self.vty.verify('show bssgp nsei 123 stats', ['']))
1061
1062 self.assertTrue(self.vty.verify('show sgsn', ['']))
1063 self.assertTrue(self.vty.verify('show mm-context all', ['']))
1064 self.assertTrue(self.vty.verify('show mm-context imsi 000001234567', ['No MM context for IMSI 000001234567']))
1065 self.assertTrue(self.vty.verify('show pdp-context all', ['']))
1066
1067 res = self.vty.command("show sndcp")
1068 self.assert_(res.find('State of SNDCP Entities') >= 0)
1069
1070 res = self.vty.command("show llc")
1071 self.assert_(res.find('State of LLC Entities') >= 0)
1072
Jacob Erlbeck106f5472014-11-04 10:08:37 +01001073 def testVtyAuth(self):
1074 self.vty.enable()
1075 self.assertTrue(self.vty.verify('configure terminal', ['']))
1076 self.assertEquals(self.vty.node(), 'config')
1077 self.assertTrue(self.vty.verify('sgsn', ['']))
1078 self.assertEquals(self.vty.node(), 'config-sgsn')
1079 self.assertTrue(self.vty.verify('auth-policy accept-all', ['']))
1080 res = self.vty.command("show running-config")
1081 self.assert_(res.find('auth-policy accept-all') > 0)
1082 self.assertTrue(self.vty.verify('auth-policy acl-only', ['']))
1083 res = self.vty.command("show running-config")
1084 self.assert_(res.find('auth-policy acl-only') > 0)
1085 self.assertTrue(self.vty.verify('auth-policy closed', ['']))
1086 res = self.vty.command("show running-config")
1087 self.assert_(res.find('auth-policy closed') > 0)
Max176b62a2016-07-04 11:09:07 +02001088 self.assertTrue(self.vty.verify('gsup remote-ip 127.0.0.4', ['']))
1089 self.assertTrue(self.vty.verify('gsup remote-port 2222', ['']))
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +01001090 self.assertTrue(self.vty.verify('auth-policy remote', ['']))
1091 res = self.vty.command("show running-config")
1092 self.assert_(res.find('auth-policy remote') > 0)
Jacob Erlbeck106f5472014-11-04 10:08:37 +01001093
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001094 def testVtySubscriber(self):
1095 self.vty.enable()
1096 res = self.vty.command('show subscriber cache')
1097 self.assert_(res.find('1234567890') < 0)
Jacob Erlbeckd9193432015-01-19 14:11:46 +01001098 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 create', ['']))
1099 res = self.vty.command('show subscriber cache')
1100 self.assert_(res.find('1234567890') >= 0)
1101 self.assert_(res.find('Authorized: 0') >= 0)
1102 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 update-location-result ok', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001103 res = self.vty.command('show subscriber cache')
1104 self.assert_(res.find('1234567890') >= 0)
1105 self.assert_(res.find('Authorized: 1') >= 0)
Jacob Erlbeck8000e0e2015-01-27 14:56:40 +01001106 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 cancel update-procedure', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001107 res = self.vty.command('show subscriber cache')
Jacob Erlbecke988ae42015-01-27 12:41:19 +01001108 self.assert_(res.find('1234567890') >= 0)
1109 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 destroy', ['']))
1110 res = self.vty.command('show subscriber cache')
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001111 self.assert_(res.find('1234567890') < 0)
1112
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +01001113 def testVtyGgsn(self):
1114 self.vty.enable()
1115 self.assertTrue(self.vty.verify('configure terminal', ['']))
1116 self.assertEquals(self.vty.node(), 'config')
1117 self.assertTrue(self.vty.verify('sgsn', ['']))
1118 self.assertEquals(self.vty.node(), 'config-sgsn')
1119 self.assertTrue(self.vty.verify('ggsn 0 remote-ip 127.99.99.99', ['']))
1120 self.assertTrue(self.vty.verify('ggsn 0 gtp-version 1', ['']))
1121 self.assertTrue(self.vty.verify('apn * ggsn 0', ['']))
1122 self.assertTrue(self.vty.verify('apn apn1.test ggsn 0', ['']))
1123 self.assertTrue(self.vty.verify('apn apn1.test ggsn 1', ['% a GGSN with id 1 has not been defined']))
1124 self.assertTrue(self.vty.verify('apn apn1.test imsi-prefix 123456 ggsn 0', ['']))
1125 self.assertTrue(self.vty.verify('apn apn2.test imsi-prefix 123456 ggsn 0', ['']))
1126 res = self.vty.command("show running-config")
1127 self.assert_(res.find('ggsn 0 remote-ip 127.99.99.99') >= 0)
1128 self.assert_(res.find('ggsn 0 gtp-version 1') >= 0)
1129 self.assert_(res.find('apn * ggsn 0') >= 0)
1130 self.assert_(res.find('apn apn1.test ggsn 0') >= 0)
1131 self.assert_(res.find('apn apn1.test imsi-prefix 123456 ggsn 0') >= 0)
1132 self.assert_(res.find('apn apn2.test imsi-prefix 123456 ggsn 0') >= 0)
1133
Holger Hans Peter Freyther9c20a5f2015-02-06 16:23:29 +01001134 def testVtyEasyAPN(self):
1135 self.vty.enable()
1136 self.assertTrue(self.vty.verify('configure terminal', ['']))
1137 self.assertEquals(self.vty.node(), 'config')
1138 self.assertTrue(self.vty.verify('sgsn', ['']))
1139 self.assertEquals(self.vty.node(), 'config-sgsn')
1140
1141 res = self.vty.command("show running-config")
1142 self.assertEquals(res.find("apn internet"), -1)
1143
1144 self.assertTrue(self.vty.verify("access-point-name internet.apn", ['']))
1145 res = self.vty.command("show running-config")
1146 self.assert_(res.find("apn internet.apn ggsn 0") >= 0)
1147
1148 self.assertTrue(self.vty.verify("no access-point-name internet.apn", ['']))
1149 res = self.vty.command("show running-config")
1150 self.assertEquals(res.find("apn internet"), -1)
1151
Holger Hans Peter Freytherc15c61c2015-05-06 17:46:08 +02001152 def testVtyCDR(self):
1153 self.vty.enable()
1154 self.assertTrue(self.vty.verify('configure terminal', ['']))
1155 self.assertEquals(self.vty.node(), 'config')
1156 self.assertTrue(self.vty.verify('sgsn', ['']))
1157 self.assertEquals(self.vty.node(), 'config-sgsn')
1158
1159 res = self.vty.command("show running-config")
1160 self.assert_(res.find("no cdr filename") > 0)
1161
1162 self.vty.command("cdr filename bla.cdr")
1163 res = self.vty.command("show running-config")
1164 self.assertEquals(res.find("no cdr filename"), -1)
1165 self.assert_(res.find(" cdr filename bla.cdr") > 0)
1166
1167 self.vty.command("no cdr filename")
1168 res = self.vty.command("show running-config")
1169 self.assert_(res.find("no cdr filename") > 0)
1170 self.assertEquals(res.find(" cdr filename bla.cdr"), -1)
1171
1172 res = self.vty.command("show running-config")
1173 self.assert_(res.find(" cdr interval 600") > 0)
1174
1175 self.vty.command("cdr interval 900")
1176 res = self.vty.command("show running-config")
1177 self.assert_(res.find(" cdr interval 900") > 0)
1178 self.assertEquals(res.find(" cdr interval 600"), -1)
1179
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001180def add_nat_test(suite, workdir):
1181 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
1182 print("Skipping the NAT test")
1183 return
1184 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT)
1185 suite.addTest(test)
1186
Max70cf7292016-04-13 11:36:38 +02001187def ipa_send_pong(x, verbose = False):
1188 if (verbose):
1189 print "\tBSC -> NAT: PONG!"
1190 return x.send("\x00\x01\xfe\x01")
1191
1192def ipa_send_ping(x, verbose = False):
1193 if (verbose):
1194 print "\tBSC -> NAT: PING?"
1195 return x.send("\x00\x01\xfe\x00")
1196
1197def ipa_send_ack(x, verbose = False):
1198 if (verbose):
1199 print "\tBSC -> NAT: IPA ID ACK"
1200 return x.send("\x00\x01\xfe\x06")
1201
1202def ipa_send_reset(x, verbose = False):
1203 if (verbose):
1204 print "\tBSC -> NAT: RESET"
1205 return x.send("\x00\x12\xfd\x09\x00\x03\x05\x07\x02\x42\xfe\x02\x42\xfe\x06\x00\x04\x30\x04\x01\x20")
1206
1207def ipa_send_resp(x, tk, verbose = False):
1208 if (verbose):
1209 print "\tBSC -> NAT: IPA ID RESP"
1210 return x.send("\x00\x07\xfe\x05\x00\x04\x01" + tk)
1211
Max49364482016-04-13 11:36:39 +02001212def nat_bsc_reload(x):
1213 x.vty.command("configure terminal")
1214 x.vty.command("nat")
1215 x.vty.command("bscs-config-file bscs.config")
1216 x.vty.command("end")
1217
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001218def nat_msc_ip(x, ip, port):
Max49364482016-04-13 11:36:39 +02001219 x.vty.command("configure terminal")
1220 x.vty.command("nat")
1221 x.vty.command("msc ip " + ip)
Holger Hans Peter Freyther84ae27e2016-04-14 10:40:06 -04001222 x.vty.command("msc port " + str(port))
Max49364482016-04-13 11:36:39 +02001223 x.vty.command("end")
1224
1225def data2str(d):
Holger Hans Peter Freyther8bb62042016-04-14 21:40:04 -04001226 return d.encode('hex').lower()
Max49364482016-04-13 11:36:39 +02001227
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001228def nat_msc_test(x, ip, port, verbose = False):
Max49364482016-04-13 11:36:39 +02001229 msc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Neels Hofmeyrcaeb62d2016-09-28 23:38:45 +02001230 msc.settimeout(5)
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001231 msc.bind((ip, port))
Max49364482016-04-13 11:36:39 +02001232 msc.listen(5)
1233 if (verbose):
1234 print "MSC is ready at " + ip
Neels Hofmeyr89d20b62016-09-26 12:59:36 +02001235 conn = None
Neels Hofmeyrcaeb62d2016-09-28 23:38:45 +02001236 while True:
1237 vty_response = x.vty.command("show msc connection")
1238 print "'show msc connection' says: %r" % vty_response
1239 if vty_response == "MSC is connected: 1":
1240 # success
1241 break;
1242 if vty_response != "MSC is connected: 0":
1243 raise Exception("Unexpected response to 'show msc connection'"
1244 " vty command: %r" % vty_response)
1245
1246 timeout_retries = 6
1247 while timeout_retries > 0:
1248 try:
1249 conn, addr = msc.accept()
1250 print "MSC got connection from ", addr
1251 break
1252 except socket.timeout:
1253 print "socket timed out."
1254 timeout_retries -= 1
1255 continue
1256
Neels Hofmeyr89d20b62016-09-26 12:59:36 +02001257 if not conn:
Neels Hofmeyr0867b722016-09-28 23:28:06 +02001258 raise Exception("VTY reports MSC is connected, but I haven't"
1259 " connected yet: %r %r" % (ip, port))
Max49364482016-04-13 11:36:39 +02001260 return conn
1261
1262def ipa_handle_small(x, verbose = False):
1263 s = data2str(x.recv(4))
1264 if "0001fe00" == s:
1265 if (verbose):
1266 print "\tBSC <- NAT: PING?"
1267 ipa_send_pong(x, verbose)
1268 elif "0001fe06" == s:
1269 if (verbose):
1270 print "\tBSC <- NAT: IPA ID ACK"
1271 ipa_send_ack(x, verbose)
1272 elif "0001fe00" == s:
1273 if (verbose):
1274 print "\tBSC <- NAT: PONG!"
1275 else:
1276 if (verbose):
1277 print "\tBSC <- NAT: ", s
1278
1279def ipa_handle_resp(x, tk, verbose = False):
1280 s = data2str(x.recv(38))
1281 if "0023fe040108010701020103010401050101010011" in s:
1282 ipa_send_resp(x, tk, verbose)
1283 else:
1284 if (verbose):
1285 print "\tBSC <- NAT: ", s
1286
1287def nat_bsc_num_con(x):
1288 return len(x.vty.command("show bsc connections").split('\n'))
1289
1290def nat_bsc_sock_test(nr, tk, verbose = False):
1291 bsc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Holger Hans Peter Freyther2abf2b02016-04-14 21:13:51 -04001292 bsc.bind(('127.0.0.1', 0))
Max49364482016-04-13 11:36:39 +02001293 bsc.connect(('127.0.0.1', 5000))
1294 if (verbose):
1295 print "BSC%d " %nr
1296 print "\tconnected to %s:%d" % bsc.getpeername()
1297 ipa_handle_small(bsc, verbose)
1298 ipa_handle_resp(bsc, tk, verbose)
1299 bsc.recv(27) # MGCP msg
1300 ipa_handle_small(bsc, verbose)
1301 return bsc
1302
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001303def add_bsc_test(suite, workdir):
1304 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")):
1305 print("Skipping the BSC test")
1306 return
1307 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC)
1308 suite.addTest(test)
1309
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001310def add_gbproxy_test(suite, workdir):
1311 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-gbproxy")):
1312 print("Skipping the Gb-Proxy test")
1313 return
1314 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYGbproxy)
1315 suite.addTest(test)
1316
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001317def add_sgsn_test(suite, workdir):
1318 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-sgsn")):
1319 print("Skipping the SGSN test")
1320 return
1321 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYSGSN)
1322 suite.addTest(test)
1323
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001324if __name__ == '__main__':
1325 import argparse
1326 import sys
1327
1328 workdir = '.'
1329
1330 parser = argparse.ArgumentParser()
1331 parser.add_argument("-v", "--verbose", dest="verbose",
1332 action="store_true", help="verbose mode")
1333 parser.add_argument("-p", "--pythonconfpath", dest="p",
1334 help="searchpath for config")
1335 parser.add_argument("-w", "--workdir", dest="w",
1336 help="Working directory")
1337 args = parser.parse_args()
1338
1339 verbose_level = 1
1340 if args.verbose:
1341 verbose_level = 2
1342
1343 if args.w:
1344 workdir = args.w
1345
1346 if args.p:
1347 confpath = args.p
1348
1349 print "confpath %s, workdir %s" % (confpath, workdir)
1350 os.chdir(workdir)
1351 print "Running tests for specific VTY commands"
1352 suite = unittest.TestSuite()
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +02001353 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYMGCP))
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +02001354 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB))
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001355 add_bsc_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001356 add_nat_test(suite, workdir)
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001357 add_gbproxy_test(suite, workdir)
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001358 add_sgsn_test(suite, workdir)
Neels Hofmeyr0a45c1e2016-09-28 23:48:02 +02001359 res = unittest.TextTestRunner(verbosity=verbose_level, stream=sys.stdout).run(suite)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001360 sys.exit(len(res.errors) + len(res.failures))
Neels Hofmeyr23d37c92016-09-26 03:18:32 +02001361
Neels Hofmeyr0867b722016-09-28 23:28:06 +02001362# vim: shiftwidth=4 expandtab nocin ai