blob: 608aef493c73e48a0c32ba59b071b921fefca72a [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
Max3e676892016-11-16 14:55:21 +010018import os, sys
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +020019import 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
Max3e676892016-11-16 14:55:21 +010026sys.path.append("../contrib")
27from ipa import IPA
28
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +020029confpath = '.'
30
31class TestVTYBase(unittest.TestCase):
32
33 def vty_command(self):
34 raise Exception("Needs to be implemented by a subclass")
35
36 def vty_app(self):
37 raise Exception("Needs to be implemented by a subclass")
38
39 def setUp(self):
40 osmo_vty_cmd = self.vty_command()[:]
41 config_index = osmo_vty_cmd.index('-c')
42 if config_index:
43 cfi = config_index + 1
44 osmo_vty_cmd[cfi] = os.path.join(confpath, osmo_vty_cmd[cfi])
45
46 try:
47 print "Launch: %s from %s" % (' '.join(osmo_vty_cmd), os.getcwd())
48 self.proc = osmoutil.popen_devnull(osmo_vty_cmd)
49 except OSError:
50 print >> sys.stderr, "Current directory: %s" % os.getcwd()
51 print >> sys.stderr, "Consider setting -b"
52 time.sleep(1)
53
54 appstring = self.vty_app()[2]
55 appport = self.vty_app()[0]
56 self.vty = obscvty.VTYInteract(appstring, "127.0.0.1", appport)
57
58 def tearDown(self):
59 self.vty = None
60 osmoutil.end_proc(self.proc)
61
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +020062class TestVTYMGCP(TestVTYBase):
63 def vty_command(self):
64 return ["./src/osmo-bsc_mgcp/osmo-bsc_mgcp", "-c",
65 "doc/examples/osmo-bsc_mgcp/mgcp.cfg"]
66
67 def vty_app(self):
68 return (4243, "./src/osmo-bsc_mgcp/osmo-bsc_mgcp", "OpenBSC MGCP", "mgcp")
69
70 def testForcePtime(self):
Neels Hofmeyr0867b722016-09-28 23:28:06 +020071 self.vty.enable()
72 res = self.vty.command("show running-config")
73 self.assert_(res.find(' rtp force-ptime 20\r') > 0)
74 self.assertEquals(res.find(' no rtp force-ptime\r'), -1)
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +020075
Neels Hofmeyr0867b722016-09-28 23:28:06 +020076 self.vty.command("configure terminal")
77 self.vty.command("mgcp")
78 self.vty.command("no rtp force-ptime")
79 res = self.vty.command("show running-config")
80 self.assertEquals(res.find(' rtp force-ptime 20\r'), -1)
81 self.assertEquals(res.find(' no rtp force-ptime\r'), -1)
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +020082
Holger Hans Peter Freyther619b0142014-11-19 16:04:45 +010083 def testOmitAudio(self):
84 self.vty.enable()
Neels Hofmeyr0867b722016-09-28 23:28:06 +020085 res = self.vty.command("show running-config")
86 self.assert_(res.find(' sdp audio-payload send-name\r') > 0)
87 self.assertEquals(res.find(' no sdp audio-payload send-name\r'), -1)
Holger Hans Peter Freyther619b0142014-11-19 16:04:45 +010088
Neels Hofmeyr0867b722016-09-28 23:28:06 +020089 self.vty.command("configure terminal")
90 self.vty.command("mgcp")
91 self.vty.command("no sdp audio-payload send-name")
92 res = self.vty.command("show running-config")
93 self.assertEquals(res.find(' rtp sdp audio-payload send-name\r'), -1)
94 self.assert_(res.find(' no sdp audio-payload send-name\r') > 0)
Holger Hans Peter Freyther619b0142014-11-19 16:04:45 +010095
96 # TODO: test it for the trunk!
97
Holger Hans Peter Freytherc390ae82015-08-20 15:15:50 +020098 def testBindAddr(self):
99 self.vty.enable()
100
Neels Hofmeyr0867b722016-09-28 23:28:06 +0200101 self.vty.command("configure terminal")
102 self.vty.command("mgcp")
Holger Hans Peter Freytherc390ae82015-08-20 15:15:50 +0200103
104 # enable.. disable bts-bind-ip
105 self.vty.command("rtp bts-bind-ip 254.253.252.250")
106 res = self.vty.command("show running-config")
107 self.assert_(res.find('rtp bts-bind-ip 254.253.252.250') > 0)
108 self.vty.command("no rtp bts-bind-ip")
109 res = self.vty.command("show running-config")
110 self.assertEquals(res.find(' rtp bts-bind-ip'), -1)
111
112 # enable.. disable net-bind-ip
113 self.vty.command("rtp net-bind-ip 254.253.252.250")
114 res = self.vty.command("show running-config")
115 self.assert_(res.find('rtp net-bind-ip 254.253.252.250') > 0)
116 self.vty.command("no rtp net-bind-ip")
117 res = self.vty.command("show running-config")
118 self.assertEquals(res.find(' rtp net-bind-ip'), -1)
119
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200120
121class TestVTYGenericBSC(TestVTYBase):
122
123 def checkForEndAndExit(self):
124 res = self.vty.command("list")
125 #print ('looking for "exit"\n')
126 self.assert_(res.find(' exit\r') > 0)
127 #print 'found "exit"\nlooking for "end"\n'
128 self.assert_(res.find(' end\r') > 0)
129 #print 'found "end"\n'
130
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200131 def _testConfigNetworkTree(self):
132 self.vty.enable()
133 self.assertTrue(self.vty.verify("configure terminal",['']))
134 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100135 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200136 self.assertTrue(self.vty.verify("network",['']))
137 self.assertEquals(self.vty.node(), 'config-net')
138 self.checkForEndAndExit()
139 self.assertTrue(self.vty.verify("bts 0",['']))
140 self.assertEquals(self.vty.node(), 'config-net-bts')
141 self.checkForEndAndExit()
142 self.assertTrue(self.vty.verify("trx 0",['']))
143 self.assertEquals(self.vty.node(), 'config-net-bts-trx')
144 self.checkForEndAndExit()
Jacob Erlbeck733bec82013-09-11 10:46:56 +0200145 self.vty.command("write terminal")
146 self.assertTrue(self.vty.verify("exit",['']))
147 self.assertEquals(self.vty.node(), 'config-net-bts')
148 self.assertTrue(self.vty.verify("exit",['']))
149 self.assertTrue(self.vty.verify("bts 1",['']))
150 self.assertEquals(self.vty.node(), 'config-net-bts')
151 self.checkForEndAndExit()
152 self.assertTrue(self.vty.verify("trx 1",['']))
153 self.assertEquals(self.vty.node(), 'config-net-bts-trx')
154 self.checkForEndAndExit()
155 self.vty.command("write terminal")
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200156 self.assertTrue(self.vty.verify("exit",['']))
157 self.assertEquals(self.vty.node(), 'config-net-bts')
158 self.assertTrue(self.vty.verify("exit",['']))
159 self.assertEquals(self.vty.node(), 'config-net')
160 self.assertTrue(self.vty.verify("exit",['']))
161 self.assertEquals(self.vty.node(), 'config')
162 self.assertTrue(self.vty.verify("exit",['']))
163 self.assertTrue(self.vty.node() is None)
164
165class TestVTYNITB(TestVTYGenericBSC):
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200166
167 def vty_command(self):
168 return ["./src/osmo-nitb/osmo-nitb", "-c",
169 "doc/examples/osmo-nitb/nanobts/openbsc.cfg"]
170
171 def vty_app(self):
172 return (4242, "./src/osmo-nitb/osmo-nitb", "OpenBSC", "nitb")
173
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200174 def testConfigNetworkTree(self):
Jacob Erlbeck75877272013-10-23 11:24:14 +0200175 self._testConfigNetworkTree()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200176
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200177 def checkForSmpp(self):
178 """SMPP is not always enabled, check if it is"""
179 res = self.vty.command("list")
180 return "smpp" in res
181
Holger Hans Peter Freyther42cf2e02015-07-06 16:41:30 +0200182 def testSmppFirst(self):
Holger Hans Peter Freyther42cf2e02015-07-06 16:41:30 +0200183 # enable the configuration
184 self.vty.enable()
185 self.vty.command("configure terminal")
Holger Hans Peter Freythera2c41c42015-07-13 11:23:53 +0200186
187 if not self.checkForSmpp():
188 return
189
Holger Hans Peter Freyther42cf2e02015-07-06 16:41:30 +0200190 self.vty.command("smpp")
191
192 # check the default
193 res = self.vty.command("write terminal")
194 self.assert_(res.find(' no smpp-first') > 0)
195
196 self.vty.verify("smpp-first", [''])
197 res = self.vty.command("write terminal")
198 self.assert_(res.find(' smpp-first') > 0)
199 self.assertEquals(res.find('no smpp-first'), -1)
200
201 self.vty.verify("no smpp-first", [''])
202 res = self.vty.command("write terminal")
203 self.assert_(res.find('no smpp-first') > 0)
204
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200205 def testVtyTree(self):
206 self.vty.enable()
207 self.assertTrue(self.vty.verify("configure terminal", ['']))
208 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100209 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200210 self.assertTrue(self.vty.verify('mncc-int', ['']))
211 self.assertEquals(self.vty.node(), 'config-mncc-int')
212 self.checkForEndAndExit()
213 self.assertTrue(self.vty.verify('exit', ['']))
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200214
215 if self.checkForSmpp():
216 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck75877272013-10-23 11:24:14 +0200217 self.assertTrue(self.vty.verify('smpp', ['']))
218 self.assertEquals(self.vty.node(), 'config-smpp')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100219 self.checkForEndAndExit()
Jacob Erlbeck75877272013-10-23 11:24:14 +0200220 self.assertTrue(self.vty.verify("exit", ['']))
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200221
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200222 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200223 self.assertTrue(self.vty.verify("exit", ['']))
224 self.assertTrue(self.vty.node() is None)
225
226 # Check searching for outer node's commands
227 self.vty.command("configure terminal")
228 self.vty.command('mncc-int')
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200229
230 if self.checkForSmpp():
231 self.vty.command('smpp')
232 self.assertEquals(self.vty.node(), 'config-smpp')
233 self.vty.command('mncc-int')
234
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200235 self.assertEquals(self.vty.node(), 'config-mncc-int')
236
Maxddee01f2016-05-24 14:23:27 +0200237 def testVtyAuthorization(self):
238 self.vty.enable()
239 self.vty.command("configure terminal")
240 self.vty.command("network")
241 self.assertTrue(self.vty.verify("auth policy closed", ['']))
242 self.assertTrue(self.vty.verify("auth policy regexp", ['']))
243 self.assertTrue(self.vty.verify("authorized-regexp ^001", ['']))
244 self.assertTrue(self.vty.verify("authorized-regexp 02$", ['']))
245 self.assertTrue(self.vty.verify("authorized-regexp *123.*", ['']))
246 self.vty.command("end")
247 self.vty.command("configure terminal")
248 self.vty.command("nitb")
249 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
Maxe6052c42016-06-30 10:25:49 +0200250 self.assertTrue(self.vty.verify("subscriber-create-on-demand no-extension", ['']))
Maxddee01f2016-05-24 14:23:27 +0200251 self.vty.command("end")
252
Max0c1bc262016-04-20 12:06:06 +0200253 def testSi2Q(self):
254 self.vty.enable()
255 self.vty.command("configure terminal")
256 self.vty.command("network")
257 self.vty.command("bts 0")
258 before = self.vty.command("show running-config")
259 self.vty.command("si2quater neighbor-list add earfcn 1911 threshold 11 2")
260 self.vty.command("si2quater neighbor-list add earfcn 1924 threshold 11 3")
261 self.vty.command("si2quater neighbor-list add earfcn 2111 threshold 11")
262 self.vty.command("si2quater neighbor-list del earfcn 1911")
263 self.vty.command("si2quater neighbor-list del earfcn 1924")
264 self.vty.command("si2quater neighbor-list del earfcn 2111")
265 self.assertEquals(before, self.vty.command("show running-config"))
Max26679e02016-04-20 15:57:13 +0200266 self.vty.command("si2quater neighbor-list add uarfcn 1976 13 1")
267 self.vty.command("si2quater neighbor-list add uarfcn 1976 38 1")
268 self.vty.command("si2quater neighbor-list add uarfcn 1976 44 1")
269 self.vty.command("si2quater neighbor-list add uarfcn 1976 120 1")
270 self.vty.command("si2quater neighbor-list add uarfcn 1976 140 1")
271 self.vty.command("si2quater neighbor-list add uarfcn 1976 163 1")
272 self.vty.command("si2quater neighbor-list add uarfcn 1976 166 1")
273 self.vty.command("si2quater neighbor-list add uarfcn 1976 217 1")
274 self.vty.command("si2quater neighbor-list add uarfcn 1976 224 1")
275 self.vty.command("si2quater neighbor-list add uarfcn 1976 225 1")
276 self.vty.command("si2quater neighbor-list add uarfcn 1976 226 1")
277 self.vty.command("si2quater neighbor-list del uarfcn 1976 13")
278 self.vty.command("si2quater neighbor-list del uarfcn 1976 38")
279 self.vty.command("si2quater neighbor-list del uarfcn 1976 44")
280 self.vty.command("si2quater neighbor-list del uarfcn 1976 120")
281 self.vty.command("si2quater neighbor-list del uarfcn 1976 140")
282 self.vty.command("si2quater neighbor-list del uarfcn 1976 163")
283 self.vty.command("si2quater neighbor-list del uarfcn 1976 166")
284 self.vty.command("si2quater neighbor-list del uarfcn 1976 217")
285 self.vty.command("si2quater neighbor-list del uarfcn 1976 224")
286 self.vty.command("si2quater neighbor-list del uarfcn 1976 225")
287 self.vty.command("si2quater neighbor-list del uarfcn 1976 226")
288 self.assertEquals(before, self.vty.command("show running-config"))
Max0c1bc262016-04-20 12:06:06 +0200289
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200290 def testEnableDisablePeriodicLU(self):
291 self.vty.enable()
292 self.vty.command("configure terminal")
293 self.vty.command("network")
294 self.vty.command("bts 0")
295
296 # Test invalid input
297 self.vty.verify("periodic location update 0", ['% Unknown command.'])
298 self.vty.verify("periodic location update 5", ['% Unknown command.'])
299 self.vty.verify("periodic location update 1531", ['% Unknown command.'])
300
301 # Enable periodic lu..
302 self.vty.verify("periodic location update 60", [''])
303 res = self.vty.command("write terminal")
Holger Hans Peter Freytherc0438e32013-07-27 22:23:25 +0200304 self.assert_(res.find('periodic location update 60') > 0)
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200305 self.assertEquals(res.find('no periodic location update'), -1)
306
307 # Now disable it..
308 self.vty.verify("no periodic location update", [''])
309 res = self.vty.command("write terminal")
310 self.assertEquals(res.find('periodic location update 60'), -1)
Holger Hans Peter Freytherc0438e32013-07-27 22:23:25 +0200311 self.assert_(res.find('no periodic location update') > 0)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200312
Jacob Erlbeck65d114f2014-01-16 11:02:14 +0100313 def testEnableDisableSiHacks(self):
314 self.vty.enable()
315 self.vty.command("configure terminal")
316 self.vty.command("network")
317 self.vty.command("bts 0")
318
319 # Enable periodic lu..
320 self.vty.verify("force-combined-si", [''])
321 res = self.vty.command("write terminal")
322 self.assert_(res.find(' force-combined-si') > 0)
323 self.assertEquals(res.find('no force-combined-si'), -1)
324
325 # Now disable it..
326 self.vty.verify("no force-combined-si", [''])
327 res = self.vty.command("write terminal")
328 self.assertEquals(res.find(' force-combined-si'), -1)
329 self.assert_(res.find('no force-combined-si') > 0)
330
Ivan Kluchnikov67920592013-09-16 13:13:04 +0400331 def testRachAccessControlClass(self):
332 self.vty.enable()
333 self.vty.command("configure terminal")
334 self.vty.command("network")
335 self.vty.command("bts 0")
336
337 # Test invalid input
338 self.vty.verify("rach access-control-class", ['% Command incomplete.'])
339 self.vty.verify("rach access-control-class 1", ['% Command incomplete.'])
340 self.vty.verify("rach access-control-class -1", ['% Unknown command.'])
341 self.vty.verify("rach access-control-class 10", ['% Unknown command.'])
342 self.vty.verify("rach access-control-class 16", ['% Unknown command.'])
343
344 # Barred rach access control classes
345 for classNum in range(16):
346 if classNum != 10:
347 self.vty.verify("rach access-control-class " + str(classNum) + " barred", [''])
348
349 # Verify settings
350 res = self.vty.command("write terminal")
351 for classNum in range(16):
352 if classNum != 10:
353 self.assert_(res.find("rach access-control-class " + str(classNum) + " barred") > 0)
354
355 # Allowed rach access control classes
356 for classNum in range(16):
357 if classNum != 10:
358 self.vty.verify("rach access-control-class " + str(classNum) + " allowed", [''])
359
360 # Verify settings
361 res = self.vty.command("write terminal")
362 for classNum in range(16):
363 if classNum != 10:
364 self.assertEquals(res.find("rach access-control-class " + str(classNum) + " barred"), -1)
365
Holger Hans Peter Freytherde392252016-04-01 19:44:00 +0200366 def testSubscriberCreateDeleteTwice(self):
367 """
368 OS#1657 indicates that there might be an issue creating the
369 same subscriber twice. This test will use the VTY command to
370 create a subscriber and then issue a second create command
371 with the same IMSI. The test passes if the VTY continues to
372 respond to VTY commands.
373 """
374 self.vty.enable()
375
376 imsi = "204300854013739"
377
378 # Initially we don't have this subscriber
379 self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi])
380
381 # Lets create one
382 res = self.vty.command('subscriber create imsi '+imsi)
383 self.assert_(res.find(" IMSI: "+imsi) > 0)
384 # And now create one again.
385 res2 = self.vty.command('subscriber create imsi '+imsi)
386 self.assert_(res2.find(" IMSI: "+imsi) > 0)
387 self.assertEqual(res, res2)
388
389 # Verify it has been created
390 res = self.vty.command('show subscriber imsi '+imsi)
391 self.assert_(res.find(" IMSI: "+imsi) > 0)
392
393 # Delete it
Max488902d2016-06-22 14:02:39 +0200394 res = self.vty.command('subscriber imsi ' + imsi + ' delete')
395 self.assert_("" == res)
Holger Hans Peter Freytherde392252016-04-01 19:44:00 +0200396
397 # Now it should not be there anymore
398 res = self.vty.command('show subscriber imsi '+imsi)
Max488902d2016-06-22 14:02:39 +0200399 self.assert_(('% No subscriber found for imsi ' + imsi) == res)
Holger Hans Peter Freytherde392252016-04-01 19:44:00 +0200400
401
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500402 def testSubscriberCreateDelete(self):
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200403 self.vty.enable()
404
405 imsi = "204300854013739"
Maxe6052c42016-06-30 10:25:49 +0200406 imsi2 = "222301824913762"
407 imsi3 = "333500854113763"
408 imsi4 = "444583744053764"
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200409
410 # Initially we don't have this subscriber
411 self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi])
412
413 # Lets create one
414 res = self.vty.command('subscriber create imsi '+imsi)
415 self.assert_(res.find(" IMSI: "+imsi) > 0)
Maxe6052c42016-06-30 10:25:49 +0200416 self.assert_(res.find("Extension") > 0)
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200417
418 # Now we have it
419 res = self.vty.command('show subscriber imsi '+imsi)
420 self.assert_(res.find(" IMSI: "+imsi) > 0)
421
Maxe6052c42016-06-30 10:25:49 +0200422 # With narrow random interval
423 self.vty.command("configure terminal")
424 self.vty.command("nitb")
425 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
426 # wrong interval
427 res = self.vty.command("subscriber-create-on-demand random 221 122")
428 # error string will contain arguments
429 self.assert_(res.find("122") > 0)
430 self.assert_(res.find("221") > 0)
431 # correct interval - silent ok
432 self.assertTrue(self.vty.verify("subscriber-create-on-demand random 221 222", ['']))
433 self.vty.command("end")
434
435 res = self.vty.command('subscriber create imsi ' + imsi2)
436 self.assert_(res.find(" IMSI: " + imsi2) > 0)
437 self.assert_(res.find("221") > 0 or res.find("222") > 0)
438 self.assert_(res.find(" Extension: ") > 0)
439
440 # Without extension
441 self.vty.command("configure terminal")
442 self.vty.command("nitb")
443 self.assertTrue(self.vty.verify("subscriber-create-on-demand no-extension", ['']))
444 self.vty.command("end")
445 res = self.vty.command('subscriber create imsi ' + imsi3)
446 self.assert_(res.find(" IMSI: " + imsi3) > 0)
447 self.assertEquals(res.find("Extension"), -1)
448
449 # With extension again
450 self.vty.command("configure terminal")
451 self.vty.command("nitb")
452 self.assertTrue(self.vty.verify("no subscriber-create-on-demand", ['']))
453 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
454 self.assertTrue(self.vty.verify("subscriber-create-on-demand random 221 666", ['']))
455 self.vty.command("end")
456
457 res = self.vty.command('subscriber create imsi ' + imsi4)
458 self.assert_(res.find(" IMSI: " + imsi4) > 0)
459 self.assert_(res.find(" Extension: ") > 0)
460
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500461 # Delete it
Max488902d2016-06-22 14:02:39 +0200462 res = self.vty.command('subscriber imsi ' + imsi + ' delete')
463 self.assert_("" == res)
Maxe6052c42016-06-30 10:25:49 +0200464 res = self.vty.command('subscriber imsi ' + imsi2 + ' delete')
465 self.assert_("" == res)
466 res = self.vty.command('subscriber imsi ' + imsi3 + ' delete')
467 self.assert_("" == res)
468 res = self.vty.command('subscriber imsi ' + imsi4 + ' delete')
469 self.assert_("" == res)
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500470
471 # Now it should not be there anymore
472 res = self.vty.command('show subscriber imsi '+imsi)
Max488902d2016-06-22 14:02:39 +0200473 self.assert_(('% No subscriber found for imsi ' + imsi) == res)
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500474
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200475 def testSubscriberSettings(self):
476 self.vty.enable()
477
478 imsi = "204300854013739"
Max0fcd2e22016-06-07 15:32:16 +0200479 imsi2 = "204301824913769"
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200480 wrong_imsi = "204300999999999"
481
482 # Lets create one
483 res = self.vty.command('subscriber create imsi '+imsi)
484 self.assert_(res.find(" IMSI: "+imsi) > 0)
Max0fcd2e22016-06-07 15:32:16 +0200485 self.assert_(res.find("Extension") > 0)
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200486
487 self.vty.verify('subscriber imsi '+wrong_imsi+' name wrong', ['% No subscriber found for imsi '+wrong_imsi])
488 res = self.vty.command('subscriber imsi '+imsi+' name '+('X' * 160))
489 self.assert_(res.find("NAME is too long") > 0)
490
491 self.vty.verify('subscriber imsi '+imsi+' name '+('G' * 159), [''])
492
493 self.vty.verify('subscriber imsi '+wrong_imsi+' extension 840', ['% No subscriber found for imsi '+wrong_imsi])
494 res = self.vty.command('subscriber imsi '+imsi+' extension '+('9' * 15))
495 self.assert_(res.find("EXTENSION is too long") > 0)
496
497 self.vty.verify('subscriber imsi '+imsi+' extension '+('1' * 14), [''])
498
Max0fcd2e22016-06-07 15:32:16 +0200499 # With narrow random interval
500 self.vty.command("configure terminal")
501 self.vty.command("nitb")
502 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
503 # wrong interval
504 res = self.vty.command("subscriber-create-on-demand random 221 122")
505 self.assert_(res.find("122") > 0)
506 self.assert_(res.find("221") > 0)
507 # correct interval
508 self.assertTrue(self.vty.verify("subscriber-create-on-demand random 221 222", ['']))
509 self.vty.command("end")
510
Max488902d2016-06-22 14:02:39 +0200511 # create subscriber with extension in a configured interval
Max0fcd2e22016-06-07 15:32:16 +0200512 res = self.vty.command('subscriber create imsi ' + imsi2)
513 self.assert_(res.find(" IMSI: " + imsi2) > 0)
514 self.assert_(res.find("221") > 0 or res.find("222") > 0)
515 self.assert_(res.find(" Extension: ") > 0)
516
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200517 # Delete it
Max488902d2016-06-22 14:02:39 +0200518 res = self.vty.command('subscriber imsi ' + imsi + ' delete')
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200519 self.assert_(res != "")
Max488902d2016-06-22 14:02:39 +0200520 # imsi2 is inactive so deletion should succeed
521 res = self.vty.command('subscriber imsi ' + imsi2 + ' delete')
522 self.assert_("" == res)
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200523
Holger Hans Peter Freytherec37bb22013-02-05 09:39:09 +0100524 def testShowPagingGroup(self):
525 res = self.vty.command("show paging-group 255 1234567")
526 self.assertEqual(res, "% can't find BTS 255")
527 res = self.vty.command("show paging-group 0 1234567")
528 self.assertEquals(res, "%Paging group for IMSI 1234567 on BTS #0 is 7")
529
Ciabyec6e4f82014-03-06 17:20:55 +0100530 def testShowNetwork(self):
531 res = self.vty.command("show network")
532 self.assert_(res.startswith('BSC is on Country Code') >= 0)
533
Holger Hans Peter Freyther86573262015-01-31 09:47:37 +0100534 def testMeasurementFeed(self):
535 self.vty.enable()
536 self.vty.command("configure terminal")
537 self.vty.command("mncc-int")
538
539 res = self.vty.command("write terminal")
540 self.assertEquals(res.find('meas-feed scenario'), -1)
541
542 self.vty.command("meas-feed scenario bla")
543 res = self.vty.command("write terminal")
544 self.assert_(res.find('meas-feed scenario bla') > 0)
545
Neels Hofmeyr0867b722016-09-28 23:28:06 +0200546 self.vty.command("meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890")
Holger Hans Peter Freyther86573262015-01-31 09:47:37 +0100547 res = self.vty.command("write terminal")
548 self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890'), -1)
549 self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz012345'), -1)
550 self.assert_(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234') > 0)
551
552
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200553class TestVTYBSC(TestVTYGenericBSC):
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200554
555 def vty_command(self):
556 return ["./src/osmo-bsc/osmo-bsc", "-c",
557 "doc/examples/osmo-bsc/osmo-bsc.cfg"]
558
559 def vty_app(self):
560 return (4242, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc")
561
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200562 def testConfigNetworkTree(self):
Jacob Erlbeck75877272013-10-23 11:24:14 +0200563 self._testConfigNetworkTree()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200564
565 def testVtyTree(self):
566 self.vty.enable()
567 self.assertTrue(self.vty.verify("configure terminal", ['']))
568 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100569 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200570 self.assertTrue(self.vty.verify("msc 0", ['']))
571 self.assertEquals(self.vty.node(), 'config-msc')
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200572 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200573 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200574 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200575 self.assertTrue(self.vty.verify("bsc", ['']))
576 self.assertEquals(self.vty.node(), 'config-bsc')
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200577 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200578 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200579 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200580 self.assertTrue(self.vty.verify("exit", ['']))
581 self.assertTrue(self.vty.node() is None)
582
583 # Check searching for outer node's commands
584 self.vty.command("configure terminal")
585 self.vty.command('msc 0')
586 self.vty.command("bsc")
587 self.assertEquals(self.vty.node(), 'config-bsc')
588 self.vty.command("msc 0")
589 self.assertEquals(self.vty.node(), 'config-msc')
590
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200591 def testUssdNotificationsMsc(self):
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200592 self.vty.enable()
593 self.vty.command("configure terminal")
594 self.vty.command("msc")
595
596 # Test invalid input
597 self.vty.verify("bsc-msc-lost-text", ['% Command incomplete.'])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200598 self.vty.verify("bsc-welcome-text", ['% Command incomplete.'])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200599 self.vty.verify("bsc-grace-text", ['% Command incomplete.'])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200600
601 # Enable USSD notifications
602 self.vty.verify("bsc-msc-lost-text MSC disconnected", [''])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200603 self.vty.verify("bsc-welcome-text Hello MS", [''])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200604 self.vty.verify("bsc-grace-text In grace period", [''])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200605
606 # Verify settings
607 res = self.vty.command("write terminal")
608 self.assert_(res.find('bsc-msc-lost-text MSC disconnected') > 0)
609 self.assertEquals(res.find('no bsc-msc-lost-text'), -1)
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200610 self.assert_(res.find('bsc-welcome-text Hello MS') > 0)
611 self.assertEquals(res.find('no bsc-welcome-text'), -1)
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200612 self.assert_(res.find('bsc-grace-text In grace period') > 0)
613 self.assertEquals(res.find('no bsc-grace-text'), -1)
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200614
615 # Now disable it..
616 self.vty.verify("no bsc-msc-lost-text", [''])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200617 self.vty.verify("no bsc-welcome-text", [''])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200618 self.vty.verify("no bsc-grace-text", [''])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200619
620 # Verify settings
621 res = self.vty.command("write terminal")
622 self.assertEquals(res.find('bsc-msc-lost-text MSC disconnected'), -1)
623 self.assert_(res.find('no bsc-msc-lost-text') > 0)
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200624 self.assertEquals(res.find('bsc-welcome-text Hello MS'), -1)
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200625 self.assert_(res.find('no bsc-welcome-text') > 0)
626 self.assertEquals(res.find('bsc-grace-text In grace period'), -1)
627 self.assert_(res.find('no bsc-grace-text') > 0)
628
629 def testUssdNotificationsBsc(self):
630 self.vty.enable()
631 self.vty.command("configure terminal")
632 self.vty.command("bsc")
633
634 # Test invalid input
635 self.vty.verify("missing-msc-text", ['% Command incomplete.'])
636
637 # Enable USSD notifications
638 self.vty.verify("missing-msc-text No MSC found", [''])
639
640 # Verify settings
641 res = self.vty.command("write terminal")
642 self.assert_(res.find('missing-msc-text No MSC found') > 0)
643 self.assertEquals(res.find('no missing-msc-text'), -1)
644
645 # Now disable it..
646 self.vty.verify("no missing-msc-text", [''])
647
648 # Verify settings
649 res = self.vty.command("write terminal")
650 self.assertEquals(res.find('missing-msc-text No MSC found'), -1)
651 self.assert_(res.find('no missing-msc-text') > 0)
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200652
Jacob Erlbeck946d1412013-09-17 13:59:29 +0200653 def testNetworkTimezone(self):
654 self.vty.enable()
655 self.vty.verify("configure terminal", [''])
656 self.vty.verify("network", [''])
Jacob Erlbeck946d1412013-09-17 13:59:29 +0200657
658 # Test invalid input
659 self.vty.verify("timezone", ['% Command incomplete.'])
660 self.vty.verify("timezone 20 0", ['% Unknown command.'])
661 self.vty.verify("timezone 0 11", ['% Unknown command.'])
662 self.vty.verify("timezone 0 0 99", ['% Unknown command.'])
663
664 # Set time zone without DST
665 self.vty.verify("timezone 2 30", [''])
666
667 # Verify settings
668 res = self.vty.command("write terminal")
669 self.assert_(res.find('timezone 2 30') > 0)
670 self.assertEquals(res.find('timezone 2 30 '), -1)
671
672 # Set time zone with DST
673 self.vty.verify("timezone 2 30 1", [''])
674
675 # Verify settings
676 res = self.vty.command("write terminal")
677 self.assert_(res.find('timezone 2 30 1') > 0)
678
679 # Now disable it..
680 self.vty.verify("no timezone", [''])
681
682 # Verify settings
683 res = self.vty.command("write terminal")
684 self.assertEquals(res.find(' timezone'), -1)
685
Ciabyec6e4f82014-03-06 17:20:55 +0100686 def testShowNetwork(self):
687 res = self.vty.command("show network")
688 self.assert_(res.startswith('BSC is on Country Code') >= 0)
689
Holger Hans Peter Freytherdb64f2e2014-10-29 10:06:15 +0100690 def testPingPongConfiguration(self):
691 self.vty.enable()
692 self.vty.verify("configure terminal", [''])
693 self.vty.verify("network", [''])
694 self.vty.verify("msc 0", [''])
695
696 self.vty.verify("timeout-ping 12", [''])
697 self.vty.verify("timeout-pong 14", [''])
698 res = self.vty.command("show running-config")
699 self.assert_(res.find(" timeout-ping 12") > 0)
700 self.assert_(res.find(" timeout-pong 14") > 0)
701 self.assert_(res.find(" no timeout-ping advanced") > 0)
702
703 self.vty.verify("timeout-ping advanced", [''])
704 res = self.vty.command("show running-config")
705 self.assert_(res.find(" timeout-ping 12") > 0)
706 self.assert_(res.find(" timeout-pong 14") > 0)
707 self.assert_(res.find(" timeout-ping advanced") > 0)
708
709 self.vty.verify("no timeout-ping advanced", [''])
710 res = self.vty.command("show running-config")
711 self.assert_(res.find(" timeout-ping 12") > 0)
712 self.assert_(res.find(" timeout-pong 14") > 0)
713 self.assert_(res.find(" no timeout-ping advanced") > 0)
714
715 self.vty.verify("no timeout-ping", [''])
716 res = self.vty.command("show running-config")
717 self.assertEquals(res.find(" timeout-ping 12"), -1)
718 self.assertEquals(res.find(" timeout-pong 14"), -1)
719 self.assertEquals(res.find(" no timeout-ping advanced"), -1)
720 self.assert_(res.find(" no timeout-ping") > 0)
721
722 self.vty.verify("timeout-ping advanced", ['%ping handling is disabled. Enable it first.'])
723
724 # And back to enabling it
725 self.vty.verify("timeout-ping 12", [''])
726 self.vty.verify("timeout-pong 14", [''])
727 res = self.vty.command("show running-config")
728 self.assert_(res.find(" timeout-ping 12") > 0)
729 self.assert_(res.find(" timeout-pong 14") > 0)
730 self.assert_(res.find(" timeout-ping advanced") > 0)
731
Holger Hans Peter Freyther32dd2f32015-04-01 18:15:48 +0200732 def testMscDataCoreLACCI(self):
733 self.vty.enable()
734 res = self.vty.command("show running-config")
735 self.assertEquals(res.find("core-location-area-code"), -1)
736 self.assertEquals(res.find("core-cell-identity"), -1)
737
Neels Hofmeyr0867b722016-09-28 23:28:06 +0200738 self.vty.command("configure terminal")
Holger Hans Peter Freyther32dd2f32015-04-01 18:15:48 +0200739 self.vty.command("msc 0")
740 self.vty.command("core-location-area-code 666")
741 self.vty.command("core-cell-identity 333")
742
743 res = self.vty.command("show running-config")
744 self.assert_(res.find("core-location-area-code 666") > 0)
745 self.assert_(res.find("core-cell-identity 333") > 0)
746
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200747class TestVTYNAT(TestVTYGenericBSC):
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200748
749 def vty_command(self):
Max49364482016-04-13 11:36:39 +0200750 return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-l", "127.0.0.1", "-c",
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200751 "doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"]
752
753 def vty_app(self):
754 return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat")
755
Max49364482016-04-13 11:36:39 +0200756 def testBSCreload(self):
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -0400757 # Use different port for the mock msc to avoid clashing with
758 # the osmo-bsc_nat itself
Holger Hans Peter Freytherf1a61bb2016-04-14 08:50:25 -0400759 ip = "127.0.0.1"
Holger Hans Peter Freythere98c9c72016-04-14 10:58:58 -0400760 port = 5522
Max49364482016-04-13 11:36:39 +0200761 self.vty.enable()
762 bscs1 = self.vty.command("show bscs-config")
763 nat_bsc_reload(self)
764 bscs2 = self.vty.command("show bscs-config")
765 # check that multiple calls to bscs-config-file give the same result
766 self.assertEquals(bscs1, bscs2)
767
768 # add new bsc
769 self.vty.command("configure terminal")
770 self.vty.command("nat")
771 self.vty.command("bsc 5")
772 self.vty.command("token key")
773 self.vty.command("location_area_code 666")
774 self.vty.command("end")
775
776 # update bsc token
777 self.vty.command("configure terminal")
778 self.vty.command("nat")
779 self.vty.command("bsc 1")
780 self.vty.command("token xyu")
781 self.vty.command("end")
782
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -0400783 nat_msc_ip(self, ip, port)
784 msc = nat_msc_test(self, ip, port)
Max49364482016-04-13 11:36:39 +0200785 b0 = nat_bsc_sock_test(0, "lol")
786 b1 = nat_bsc_sock_test(1, "xyu")
787 b2 = nat_bsc_sock_test(5, "key")
788
789 self.assertEquals("3 BSCs configured", self.vty.command("show nat num-bscs-configured"))
790 self.assertTrue(3 == nat_bsc_num_con(self))
791 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
792
793 nat_bsc_reload(self)
794 bscs2 = self.vty.command("show bscs-config")
795 # check that the reset to initial config succeeded
796 self.assertEquals(bscs1, bscs2)
797
798 self.assertEquals("2 BSCs configured", self.vty.command("show nat num-bscs-configured"))
799 self.assertTrue(1 == nat_bsc_num_con(self))
800 rem = self.vty.command("show bsc connections").split(' ')
801 # remaining connection is for BSC0
802 self.assertEquals('0', rem[2])
803 # remaining connection is authorized
804 self.assertEquals('1', rem[4])
805 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
806
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200807 def testVtyTree(self):
808 self.vty.enable()
809 self.assertTrue(self.vty.verify('configure terminal', ['']))
810 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100811 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200812 self.assertTrue(self.vty.verify('mgcp', ['']))
813 self.assertEquals(self.vty.node(), 'config-mgcp')
814 self.checkForEndAndExit()
815 self.assertTrue(self.vty.verify('exit', ['']))
816 self.assertEquals(self.vty.node(), 'config')
817 self.assertTrue(self.vty.verify('nat', ['']))
818 self.assertEquals(self.vty.node(), 'config-nat')
819 self.checkForEndAndExit()
820 self.assertTrue(self.vty.verify('bsc 0', ['']))
821 self.assertEquals(self.vty.node(), 'config-nat-bsc')
822 self.checkForEndAndExit()
823 self.assertTrue(self.vty.verify('exit', ['']))
824 self.assertEquals(self.vty.node(), 'config-nat')
825 self.assertTrue(self.vty.verify('exit', ['']))
826 self.assertEquals(self.vty.node(), 'config')
827 self.assertTrue(self.vty.verify('exit', ['']))
828 self.assertTrue(self.vty.node() is None)
829
830 # Check searching for outer node's commands
831 self.vty.command('configure terminal')
832 self.vty.command('mgcp')
833 self.vty.command('nat')
834 self.assertEquals(self.vty.node(), 'config-nat')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200835 self.vty.command('mgcp')
836 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200837 self.vty.command('nat')
838 self.assertEquals(self.vty.node(), 'config-nat')
839 self.vty.command('bsc 0')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200840 self.vty.command('mgcp')
841 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200842
Holger Hans Peter Freytherb718ad32013-06-25 09:08:02 +0200843 def testRewriteNoRewrite(self):
844 self.vty.enable()
845 res = self.vty.command("configure terminal")
846 res = self.vty.command("nat")
847 res = self.vty.command("number-rewrite rewrite.cfg")
848 res = self.vty.command("no number-rewrite")
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200849
Holger Hans Peter Freyther7f100c92015-04-23 20:25:17 -0400850 def testEnsureNoEnsureModeSet(self):
851 self.vty.enable()
852 res = self.vty.command("configure terminal")
853 res = self.vty.command("nat")
854
855 # Ensure the default
856 res = self.vty.command("show running-config")
857 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
858
859 self.vty.command("sdp-ensure-amr-mode-set")
860 res = self.vty.command("show running-config")
861 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
862
863 self.vty.command("no sdp-ensure-amr-mode-set")
864 res = self.vty.command("show running-config")
865 self.assert_(res.find('\n no sdp-ensure-amr-mode-set') > 0)
866
Holger Hans Peter Freyther67e423c2013-06-25 15:38:31 +0200867 def testRewritePostNoRewrite(self):
868 self.vty.enable()
869 self.vty.command("configure terminal")
870 self.vty.command("nat")
871 self.vty.verify("number-rewrite-post rewrite.cfg", [''])
872 self.vty.verify("no number-rewrite-post", [''])
873
874
Holger Hans Peter Freytherddf191e2013-06-25 11:44:01 +0200875 def testPrefixTreeLoading(self):
876 cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv")
877
878 self.vty.enable()
879 self.vty.command("configure terminal")
880 self.vty.command("nat")
881 res = self.vty.command("prefix-tree %s" % cfg)
882 self.assertEqual(res, "% prefix-tree loaded 17 rules.")
883 self.vty.command("end")
884
885 res = self.vty.command("show prefix-tree")
886 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')
887
888 self.vty.command("configure terminal")
889 self.vty.command("nat")
890 self.vty.command("no prefix-tree")
891 self.vty.command("end")
892
893 res = self.vty.command("show prefix-tree")
894 self.assertEqual(res, "% there is now prefix tree loaded.")
895
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200896 def testUssdSideChannelProvider(self):
897 self.vty.command("end")
898 self.vty.enable()
899 self.vty.command("configure terminal")
900 self.vty.command("nat")
901 self.vty.command("ussd-token key")
902 self.vty.command("end")
903
904 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
905 self.assertTrue(res)
906
907 ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
908 ussdSocket.connect(('127.0.0.1', 5001))
909 ussdSocket.settimeout(2.0)
910 print "Connected to %s:%d" % ussdSocket.getpeername()
911
912 print "Expecting ID_GET request"
913 data = ussdSocket.recv(4)
914 self.assertEqual(data, "\x00\x01\xfe\x04")
915
916 print "Going to send ID_RESP response"
Max3e676892016-11-16 14:55:21 +0100917 res = ussdSocket.send(IPA().id_resp(IPA().tag_name('key')))
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200918 self.assertEqual(res, 10)
919
920 # initiating PING/PONG cycle to know, that the ID_RESP message has been processed
921
922 print "Going to send PING request"
Max3e676892016-11-16 14:55:21 +0100923 res = ussdSocket.send(IPA().ping())
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200924 self.assertEqual(res, 4)
925
926 print "Expecting PONG response"
927 data = ussdSocket.recv(4)
928 self.assertEqual(data, "\x00\x01\xfe\x01")
929
930 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.'])
931 self.assertTrue(res)
932
933 print "Going to shut down connection"
934 ussdSocket.shutdown(socket.SHUT_WR)
935
936 print "Expecting EOF"
937 data = ussdSocket.recv(4)
938 self.assertEqual(data, "")
939
940 ussdSocket.close()
941
942 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
943 self.assertTrue(res)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200944
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100945 def testAccessList(self):
946 """
947 Verify that the imsi-deny can have a reject cause or no reject cause
948 """
949 self.vty.enable()
950 self.vty.command("configure terminal")
951 self.vty.command("nat")
952
953 # Old default
954 self.vty.command("access-list test-default imsi-deny ^123[0-9]*$")
955 res = self.vty.command("show running-config").split("\r\n")
956 asserted = False
957 for line in res:
Holger Hans Peter Freyther4ecc6872014-03-04 15:38:00 +0100958 if line.startswith(" access-list test-default"):
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100959 self.assertEqual(line, " access-list test-default imsi-deny ^123[0-9]*$ 11 11")
960 asserted = True
961 self.assert_(asserted)
962
963 # Check the optional CM Service Reject Cause
964 self.vty.command("access-list test-cm-deny imsi-deny ^123[0-9]*$ 42").split("\r\n")
965 res = self.vty.command("show running-config").split("\r\n")
966 asserted = False
967 for line in res:
968 if line.startswith(" access-list test-cm"):
969 self.assertEqual(line, " access-list test-cm-deny imsi-deny ^123[0-9]*$ 42 11")
970 asserted = True
971 self.assert_(asserted)
972
973 # Check the optional LU Reject Cause
974 self.vty.command("access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42").split("\r\n")
975 res = self.vty.command("show running-config").split("\r\n")
976 asserted = False
977 for line in res:
978 if line.startswith(" access-list test-lu"):
979 self.assertEqual(line, " access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42")
980 asserted = True
981 self.assert_(asserted)
982
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200983class TestVTYGbproxy(TestVTYGenericBSC):
984
985 def vty_command(self):
986 return ["./src/gprs/osmo-gbproxy", "-c",
987 "doc/examples/osmo-gbproxy/osmo-gbproxy.cfg"]
988
989 def vty_app(self):
990 return (4246, "./src/gprs/osmo-gbproxy", "OsmoGbProxy", "bsc")
991
992 def testVtyTree(self):
993 self.vty.enable()
994 self.assertTrue(self.vty.verify('configure terminal', ['']))
995 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100996 self.checkForEndAndExit()
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200997 self.assertTrue(self.vty.verify('ns', ['']))
998 self.assertEquals(self.vty.node(), 'config-ns')
999 self.checkForEndAndExit()
1000 self.assertTrue(self.vty.verify('exit', ['']))
1001 self.assertEquals(self.vty.node(), 'config')
1002 self.assertTrue(self.vty.verify('gbproxy', ['']))
1003 self.assertEquals(self.vty.node(), 'config-gbproxy')
1004 self.checkForEndAndExit()
1005 self.assertTrue(self.vty.verify('exit', ['']))
1006 self.assertEquals(self.vty.node(), 'config')
1007
1008 def testVtyShow(self):
1009 res = self.vty.command("show ns")
1010 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
1011
1012 res = self.vty.command("show gbproxy stats")
1013 self.assert_(res.find('GBProxy Global Statistics') >= 0)
1014
Jacob Erlbeck4211d792013-10-24 12:48:23 +02001015 def testVtyDeletePeer(self):
1016 self.vty.enable()
1017 self.assertTrue(self.vty.verify('delete-gbproxy-peer 9999 bvci 7777', ['BVC not found']))
1018 res = self.vty.command("delete-gbproxy-peer 9999 all 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-bvc 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 only-nsvc dry-run")
1025 self.assert_(res.find('Not Deleted 0 BVC') < 0)
1026 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
1027 res = self.vty.command("delete-gbproxy-peer 9999 all")
1028 self.assert_(res.find('Deleted 0 BVC') >= 0)
1029 self.assert_(res.find('Deleted 0 NS-VC') >= 0)
1030
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001031class TestVTYSGSN(TestVTYGenericBSC):
1032
1033 def vty_command(self):
1034 return ["./src/gprs/osmo-sgsn", "-c",
1035 "doc/examples/osmo-sgsn/osmo-sgsn.cfg"]
1036
1037 def vty_app(self):
1038 return (4245, "./src/gprs/osmo-sgsn", "OsmoSGSN", "sgsn")
1039
1040 def testVtyTree(self):
1041 self.vty.enable()
1042 self.assertTrue(self.vty.verify('configure terminal', ['']))
1043 self.assertEquals(self.vty.node(), 'config')
1044 self.checkForEndAndExit()
1045 self.assertTrue(self.vty.verify('ns', ['']))
1046 self.assertEquals(self.vty.node(), 'config-ns')
1047 self.checkForEndAndExit()
1048 self.assertTrue(self.vty.verify('exit', ['']))
1049 self.assertEquals(self.vty.node(), 'config')
1050 self.assertTrue(self.vty.verify('sgsn', ['']))
1051 self.assertEquals(self.vty.node(), 'config-sgsn')
1052 self.checkForEndAndExit()
1053 self.assertTrue(self.vty.verify('exit', ['']))
1054 self.assertEquals(self.vty.node(), 'config')
1055
1056 def testVtyShow(self):
1057 res = self.vty.command("show ns")
1058 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
1059 self.assertTrue(self.vty.verify('show bssgp', ['']))
1060 self.assertTrue(self.vty.verify('show bssgp stats', ['']))
1061 # TODO: uncomment when the command does not segfault anymore
1062 # self.assertTrue(self.vty.verify('show bssgp nsei 123', ['']))
1063 # self.assertTrue(self.vty.verify('show bssgp nsei 123 stats', ['']))
1064
1065 self.assertTrue(self.vty.verify('show sgsn', ['']))
1066 self.assertTrue(self.vty.verify('show mm-context all', ['']))
1067 self.assertTrue(self.vty.verify('show mm-context imsi 000001234567', ['No MM context for IMSI 000001234567']))
1068 self.assertTrue(self.vty.verify('show pdp-context all', ['']))
1069
1070 res = self.vty.command("show sndcp")
1071 self.assert_(res.find('State of SNDCP Entities') >= 0)
1072
1073 res = self.vty.command("show llc")
1074 self.assert_(res.find('State of LLC Entities') >= 0)
1075
Jacob Erlbeck106f5472014-11-04 10:08:37 +01001076 def testVtyAuth(self):
1077 self.vty.enable()
1078 self.assertTrue(self.vty.verify('configure terminal', ['']))
1079 self.assertEquals(self.vty.node(), 'config')
1080 self.assertTrue(self.vty.verify('sgsn', ['']))
1081 self.assertEquals(self.vty.node(), 'config-sgsn')
1082 self.assertTrue(self.vty.verify('auth-policy accept-all', ['']))
1083 res = self.vty.command("show running-config")
1084 self.assert_(res.find('auth-policy accept-all') > 0)
1085 self.assertTrue(self.vty.verify('auth-policy acl-only', ['']))
1086 res = self.vty.command("show running-config")
1087 self.assert_(res.find('auth-policy acl-only') > 0)
1088 self.assertTrue(self.vty.verify('auth-policy closed', ['']))
1089 res = self.vty.command("show running-config")
1090 self.assert_(res.find('auth-policy closed') > 0)
Max176b62a2016-07-04 11:09:07 +02001091 self.assertTrue(self.vty.verify('gsup remote-ip 127.0.0.4', ['']))
1092 self.assertTrue(self.vty.verify('gsup remote-port 2222', ['']))
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +01001093 self.assertTrue(self.vty.verify('auth-policy remote', ['']))
1094 res = self.vty.command("show running-config")
1095 self.assert_(res.find('auth-policy remote') > 0)
Jacob Erlbeck106f5472014-11-04 10:08:37 +01001096
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001097 def testVtySubscriber(self):
1098 self.vty.enable()
1099 res = self.vty.command('show subscriber cache')
1100 self.assert_(res.find('1234567890') < 0)
Jacob Erlbeckd9193432015-01-19 14:11:46 +01001101 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 create', ['']))
1102 res = self.vty.command('show subscriber cache')
1103 self.assert_(res.find('1234567890') >= 0)
1104 self.assert_(res.find('Authorized: 0') >= 0)
1105 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 update-location-result ok', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001106 res = self.vty.command('show subscriber cache')
1107 self.assert_(res.find('1234567890') >= 0)
1108 self.assert_(res.find('Authorized: 1') >= 0)
Jacob Erlbeck8000e0e2015-01-27 14:56:40 +01001109 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 cancel update-procedure', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001110 res = self.vty.command('show subscriber cache')
Jacob Erlbecke988ae42015-01-27 12:41:19 +01001111 self.assert_(res.find('1234567890') >= 0)
1112 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 destroy', ['']))
1113 res = self.vty.command('show subscriber cache')
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001114 self.assert_(res.find('1234567890') < 0)
1115
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +01001116 def testVtyGgsn(self):
1117 self.vty.enable()
1118 self.assertTrue(self.vty.verify('configure terminal', ['']))
1119 self.assertEquals(self.vty.node(), 'config')
1120 self.assertTrue(self.vty.verify('sgsn', ['']))
1121 self.assertEquals(self.vty.node(), 'config-sgsn')
1122 self.assertTrue(self.vty.verify('ggsn 0 remote-ip 127.99.99.99', ['']))
1123 self.assertTrue(self.vty.verify('ggsn 0 gtp-version 1', ['']))
1124 self.assertTrue(self.vty.verify('apn * ggsn 0', ['']))
1125 self.assertTrue(self.vty.verify('apn apn1.test ggsn 0', ['']))
1126 self.assertTrue(self.vty.verify('apn apn1.test ggsn 1', ['% a GGSN with id 1 has not been defined']))
1127 self.assertTrue(self.vty.verify('apn apn1.test imsi-prefix 123456 ggsn 0', ['']))
1128 self.assertTrue(self.vty.verify('apn apn2.test imsi-prefix 123456 ggsn 0', ['']))
1129 res = self.vty.command("show running-config")
1130 self.assert_(res.find('ggsn 0 remote-ip 127.99.99.99') >= 0)
1131 self.assert_(res.find('ggsn 0 gtp-version 1') >= 0)
1132 self.assert_(res.find('apn * ggsn 0') >= 0)
1133 self.assert_(res.find('apn apn1.test ggsn 0') >= 0)
1134 self.assert_(res.find('apn apn1.test imsi-prefix 123456 ggsn 0') >= 0)
1135 self.assert_(res.find('apn apn2.test imsi-prefix 123456 ggsn 0') >= 0)
1136
Holger Hans Peter Freyther9c20a5f2015-02-06 16:23:29 +01001137 def testVtyEasyAPN(self):
1138 self.vty.enable()
1139 self.assertTrue(self.vty.verify('configure terminal', ['']))
1140 self.assertEquals(self.vty.node(), 'config')
1141 self.assertTrue(self.vty.verify('sgsn', ['']))
1142 self.assertEquals(self.vty.node(), 'config-sgsn')
1143
1144 res = self.vty.command("show running-config")
1145 self.assertEquals(res.find("apn internet"), -1)
1146
1147 self.assertTrue(self.vty.verify("access-point-name internet.apn", ['']))
1148 res = self.vty.command("show running-config")
1149 self.assert_(res.find("apn internet.apn ggsn 0") >= 0)
1150
1151 self.assertTrue(self.vty.verify("no access-point-name internet.apn", ['']))
1152 res = self.vty.command("show running-config")
1153 self.assertEquals(res.find("apn internet"), -1)
1154
Holger Hans Peter Freytherc15c61c2015-05-06 17:46:08 +02001155 def testVtyCDR(self):
1156 self.vty.enable()
1157 self.assertTrue(self.vty.verify('configure terminal', ['']))
1158 self.assertEquals(self.vty.node(), 'config')
1159 self.assertTrue(self.vty.verify('sgsn', ['']))
1160 self.assertEquals(self.vty.node(), 'config-sgsn')
1161
1162 res = self.vty.command("show running-config")
1163 self.assert_(res.find("no cdr filename") > 0)
1164
1165 self.vty.command("cdr filename bla.cdr")
1166 res = self.vty.command("show running-config")
1167 self.assertEquals(res.find("no cdr filename"), -1)
1168 self.assert_(res.find(" cdr filename bla.cdr") > 0)
1169
1170 self.vty.command("no cdr filename")
1171 res = self.vty.command("show running-config")
1172 self.assert_(res.find("no cdr filename") > 0)
1173 self.assertEquals(res.find(" cdr filename bla.cdr"), -1)
1174
1175 res = self.vty.command("show running-config")
1176 self.assert_(res.find(" cdr interval 600") > 0)
1177
1178 self.vty.command("cdr interval 900")
1179 res = self.vty.command("show running-config")
1180 self.assert_(res.find(" cdr interval 900") > 0)
1181 self.assertEquals(res.find(" cdr interval 600"), -1)
1182
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001183def add_nat_test(suite, workdir):
1184 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
1185 print("Skipping the NAT test")
1186 return
1187 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT)
1188 suite.addTest(test)
1189
Max49364482016-04-13 11:36:39 +02001190def nat_bsc_reload(x):
1191 x.vty.command("configure terminal")
1192 x.vty.command("nat")
1193 x.vty.command("bscs-config-file bscs.config")
1194 x.vty.command("end")
1195
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001196def nat_msc_ip(x, ip, port):
Max49364482016-04-13 11:36:39 +02001197 x.vty.command("configure terminal")
1198 x.vty.command("nat")
1199 x.vty.command("msc ip " + ip)
Holger Hans Peter Freyther84ae27e2016-04-14 10:40:06 -04001200 x.vty.command("msc port " + str(port))
Max49364482016-04-13 11:36:39 +02001201 x.vty.command("end")
1202
1203def data2str(d):
Holger Hans Peter Freyther8bb62042016-04-14 21:40:04 -04001204 return d.encode('hex').lower()
Max49364482016-04-13 11:36:39 +02001205
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001206def nat_msc_test(x, ip, port, verbose = False):
Max49364482016-04-13 11:36:39 +02001207 msc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Neels Hofmeyrcaeb62d2016-09-28 23:38:45 +02001208 msc.settimeout(5)
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001209 msc.bind((ip, port))
Max49364482016-04-13 11:36:39 +02001210 msc.listen(5)
1211 if (verbose):
1212 print "MSC is ready at " + ip
Neels Hofmeyr89d20b62016-09-26 12:59:36 +02001213 conn = None
Neels Hofmeyrcaeb62d2016-09-28 23:38:45 +02001214 while True:
1215 vty_response = x.vty.command("show msc connection")
1216 print "'show msc connection' says: %r" % vty_response
1217 if vty_response == "MSC is connected: 1":
1218 # success
1219 break;
1220 if vty_response != "MSC is connected: 0":
1221 raise Exception("Unexpected response to 'show msc connection'"
1222 " vty command: %r" % vty_response)
1223
1224 timeout_retries = 6
1225 while timeout_retries > 0:
1226 try:
1227 conn, addr = msc.accept()
1228 print "MSC got connection from ", addr
1229 break
1230 except socket.timeout:
1231 print "socket timed out."
1232 timeout_retries -= 1
1233 continue
1234
Neels Hofmeyr89d20b62016-09-26 12:59:36 +02001235 if not conn:
Neels Hofmeyr0867b722016-09-28 23:28:06 +02001236 raise Exception("VTY reports MSC is connected, but I haven't"
1237 " connected yet: %r %r" % (ip, port))
Max49364482016-04-13 11:36:39 +02001238 return conn
1239
1240def ipa_handle_small(x, verbose = False):
1241 s = data2str(x.recv(4))
Neels Hofmeyrba1468e2017-02-03 04:23:46 +01001242 if len(s) != 4*2:
1243 raise Exception("expected to receive 4 bytes, but got %d (%r)" % (len(s)/2, s))
Max49364482016-04-13 11:36:39 +02001244 if "0001fe00" == s:
1245 if (verbose):
1246 print "\tBSC <- NAT: PING?"
Max3e676892016-11-16 14:55:21 +01001247 x.send(IPA().pong())
Max49364482016-04-13 11:36:39 +02001248 elif "0001fe06" == s:
1249 if (verbose):
1250 print "\tBSC <- NAT: IPA ID ACK"
Max3e676892016-11-16 14:55:21 +01001251 x.send(IPA().id_ack())
Max49364482016-04-13 11:36:39 +02001252 elif "0001fe00" == s:
1253 if (verbose):
1254 print "\tBSC <- NAT: PONG!"
1255 else:
1256 if (verbose):
1257 print "\tBSC <- NAT: ", s
1258
1259def ipa_handle_resp(x, tk, verbose = False):
1260 s = data2str(x.recv(38))
1261 if "0023fe040108010701020103010401050101010011" in s:
Neels Hofmeyr7d17c3e2017-01-26 23:04:28 +01001262 retries = 3
1263 while True:
1264 print "\tsending IPA identity(%s) at %s" % (tk, time.strftime("%T"))
1265 try:
1266 x.send(IPA().id_resp(IPA().identity(name = tk.encode('utf-8'))))
1267 print "\tdone sending IPA identity(%s) at %s" % (tk,
1268 time.strftime("%T"))
1269 break
1270 except:
1271 print "\tfailed sending IPA identity at", time.strftime("%T")
1272 if retries < 1:
1273 print "\tgiving up"
1274 raise
Neels Hofmeyre02e1e72017-02-03 05:55:26 +01001275 print "\tretrying (%d attempts left)" % retries
Neels Hofmeyr7d17c3e2017-01-26 23:04:28 +01001276 retries -= 1
Max49364482016-04-13 11:36:39 +02001277 else:
1278 if (verbose):
1279 print "\tBSC <- NAT: ", s
1280
1281def nat_bsc_num_con(x):
1282 return len(x.vty.command("show bsc connections").split('\n'))
1283
1284def nat_bsc_sock_test(nr, tk, verbose = False):
1285 bsc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Holger Hans Peter Freyther2abf2b02016-04-14 21:13:51 -04001286 bsc.bind(('127.0.0.1', 0))
Max49364482016-04-13 11:36:39 +02001287 bsc.connect(('127.0.0.1', 5000))
1288 if (verbose):
1289 print "BSC%d " %nr
1290 print "\tconnected to %s:%d" % bsc.getpeername()
1291 ipa_handle_small(bsc, verbose)
1292 ipa_handle_resp(bsc, tk, verbose)
1293 bsc.recv(27) # MGCP msg
1294 ipa_handle_small(bsc, verbose)
1295 return bsc
1296
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001297def add_bsc_test(suite, workdir):
1298 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")):
1299 print("Skipping the BSC test")
1300 return
1301 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC)
1302 suite.addTest(test)
1303
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001304def add_gbproxy_test(suite, workdir):
1305 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-gbproxy")):
1306 print("Skipping the Gb-Proxy test")
1307 return
1308 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYGbproxy)
1309 suite.addTest(test)
1310
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001311def add_sgsn_test(suite, workdir):
1312 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-sgsn")):
1313 print("Skipping the SGSN test")
1314 return
1315 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYSGSN)
1316 suite.addTest(test)
1317
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001318if __name__ == '__main__':
1319 import argparse
1320 import sys
1321
1322 workdir = '.'
1323
1324 parser = argparse.ArgumentParser()
1325 parser.add_argument("-v", "--verbose", dest="verbose",
1326 action="store_true", help="verbose mode")
1327 parser.add_argument("-p", "--pythonconfpath", dest="p",
1328 help="searchpath for config")
1329 parser.add_argument("-w", "--workdir", dest="w",
1330 help="Working directory")
1331 args = parser.parse_args()
1332
1333 verbose_level = 1
1334 if args.verbose:
1335 verbose_level = 2
1336
1337 if args.w:
1338 workdir = args.w
1339
1340 if args.p:
1341 confpath = args.p
1342
1343 print "confpath %s, workdir %s" % (confpath, workdir)
1344 os.chdir(workdir)
1345 print "Running tests for specific VTY commands"
1346 suite = unittest.TestSuite()
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +02001347 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYMGCP))
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +02001348 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB))
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001349 add_bsc_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001350 add_nat_test(suite, workdir)
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001351 add_gbproxy_test(suite, workdir)
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001352 add_sgsn_test(suite, workdir)
Neels Hofmeyr0a45c1e2016-09-28 23:48:02 +02001353 res = unittest.TextTestRunner(verbosity=verbose_level, stream=sys.stdout).run(suite)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001354 sys.exit(len(res.errors) + len(res.failures))
Neels Hofmeyr23d37c92016-09-26 03:18:32 +02001355
Neels Hofmeyr0867b722016-09-28 23:28:06 +02001356# vim: shiftwidth=4 expandtab nocin ai