blob: 5836cd4aa1b785eacdca9a548f5da9bc843627ee [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
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +010022import subprocess
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +020023
24import osmopy.obscvty as obscvty
25import osmopy.osmoutil as osmoutil
26
Max3e676892016-11-16 14:55:21 +010027sys.path.append("../contrib")
28from ipa import IPA
29
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +020030confpath = '.'
31
32class TestVTYBase(unittest.TestCase):
33
34 def vty_command(self):
35 raise Exception("Needs to be implemented by a subclass")
36
37 def vty_app(self):
38 raise Exception("Needs to be implemented by a subclass")
39
40 def setUp(self):
41 osmo_vty_cmd = self.vty_command()[:]
42 config_index = osmo_vty_cmd.index('-c')
43 if config_index:
44 cfi = config_index + 1
45 osmo_vty_cmd[cfi] = os.path.join(confpath, osmo_vty_cmd[cfi])
46
47 try:
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +020048 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):
Neels Hofmeyr40a91b32017-02-24 17:54:22 +010059 if self.vty:
60 self.vty._close_socket()
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +020061 self.vty = None
62 osmoutil.end_proc(self.proc)
63
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +020064class TestVTYMGCP(TestVTYBase):
65 def vty_command(self):
66 return ["./src/osmo-bsc_mgcp/osmo-bsc_mgcp", "-c",
67 "doc/examples/osmo-bsc_mgcp/mgcp.cfg"]
68
69 def vty_app(self):
70 return (4243, "./src/osmo-bsc_mgcp/osmo-bsc_mgcp", "OpenBSC MGCP", "mgcp")
71
72 def testForcePtime(self):
Neels Hofmeyr0867b722016-09-28 23:28:06 +020073 self.vty.enable()
74 res = self.vty.command("show running-config")
75 self.assert_(res.find(' rtp force-ptime 20\r') > 0)
76 self.assertEquals(res.find(' no rtp force-ptime\r'), -1)
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +020077
Neels Hofmeyr0867b722016-09-28 23:28:06 +020078 self.vty.command("configure terminal")
79 self.vty.command("mgcp")
80 self.vty.command("no rtp force-ptime")
81 res = self.vty.command("show running-config")
82 self.assertEquals(res.find(' rtp force-ptime 20\r'), -1)
83 self.assertEquals(res.find(' no rtp force-ptime\r'), -1)
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +020084
Holger Hans Peter Freyther619b0142014-11-19 16:04:45 +010085 def testOmitAudio(self):
86 self.vty.enable()
Neels Hofmeyr0867b722016-09-28 23:28:06 +020087 res = self.vty.command("show running-config")
88 self.assert_(res.find(' sdp audio-payload send-name\r') > 0)
89 self.assertEquals(res.find(' no sdp audio-payload send-name\r'), -1)
Holger Hans Peter Freyther619b0142014-11-19 16:04:45 +010090
Neels Hofmeyr0867b722016-09-28 23:28:06 +020091 self.vty.command("configure terminal")
92 self.vty.command("mgcp")
93 self.vty.command("no sdp audio-payload send-name")
94 res = self.vty.command("show running-config")
95 self.assertEquals(res.find(' rtp sdp audio-payload send-name\r'), -1)
96 self.assert_(res.find(' no sdp audio-payload send-name\r') > 0)
Holger Hans Peter Freyther619b0142014-11-19 16:04:45 +010097
98 # TODO: test it for the trunk!
99
Holger Hans Peter Freytherc390ae82015-08-20 15:15:50 +0200100 def testBindAddr(self):
101 self.vty.enable()
102
Neels Hofmeyr0867b722016-09-28 23:28:06 +0200103 self.vty.command("configure terminal")
104 self.vty.command("mgcp")
Holger Hans Peter Freytherc390ae82015-08-20 15:15:50 +0200105
106 # enable.. disable bts-bind-ip
107 self.vty.command("rtp bts-bind-ip 254.253.252.250")
108 res = self.vty.command("show running-config")
109 self.assert_(res.find('rtp bts-bind-ip 254.253.252.250') > 0)
110 self.vty.command("no rtp bts-bind-ip")
111 res = self.vty.command("show running-config")
112 self.assertEquals(res.find(' rtp bts-bind-ip'), -1)
113
114 # enable.. disable net-bind-ip
115 self.vty.command("rtp net-bind-ip 254.253.252.250")
116 res = self.vty.command("show running-config")
117 self.assert_(res.find('rtp net-bind-ip 254.253.252.250') > 0)
118 self.vty.command("no rtp net-bind-ip")
119 res = self.vty.command("show running-config")
120 self.assertEquals(res.find(' rtp net-bind-ip'), -1)
121
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200122
123class TestVTYGenericBSC(TestVTYBase):
124
125 def checkForEndAndExit(self):
126 res = self.vty.command("list")
127 #print ('looking for "exit"\n')
128 self.assert_(res.find(' exit\r') > 0)
129 #print 'found "exit"\nlooking for "end"\n'
130 self.assert_(res.find(' end\r') > 0)
131 #print 'found "end"\n'
132
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200133 def _testConfigNetworkTree(self):
134 self.vty.enable()
135 self.assertTrue(self.vty.verify("configure terminal",['']))
136 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100137 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200138 self.assertTrue(self.vty.verify("network",['']))
139 self.assertEquals(self.vty.node(), 'config-net')
140 self.checkForEndAndExit()
141 self.assertTrue(self.vty.verify("bts 0",['']))
142 self.assertEquals(self.vty.node(), 'config-net-bts')
143 self.checkForEndAndExit()
144 self.assertTrue(self.vty.verify("trx 0",['']))
145 self.assertEquals(self.vty.node(), 'config-net-bts-trx')
146 self.checkForEndAndExit()
Jacob Erlbeck733bec82013-09-11 10:46:56 +0200147 self.vty.command("write terminal")
148 self.assertTrue(self.vty.verify("exit",['']))
149 self.assertEquals(self.vty.node(), 'config-net-bts')
150 self.assertTrue(self.vty.verify("exit",['']))
151 self.assertTrue(self.vty.verify("bts 1",['']))
152 self.assertEquals(self.vty.node(), 'config-net-bts')
153 self.checkForEndAndExit()
154 self.assertTrue(self.vty.verify("trx 1",['']))
155 self.assertEquals(self.vty.node(), 'config-net-bts-trx')
156 self.checkForEndAndExit()
157 self.vty.command("write terminal")
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200158 self.assertTrue(self.vty.verify("exit",['']))
159 self.assertEquals(self.vty.node(), 'config-net-bts')
160 self.assertTrue(self.vty.verify("exit",['']))
161 self.assertEquals(self.vty.node(), 'config-net')
162 self.assertTrue(self.vty.verify("exit",['']))
163 self.assertEquals(self.vty.node(), 'config')
164 self.assertTrue(self.vty.verify("exit",['']))
165 self.assertTrue(self.vty.node() is None)
166
167class TestVTYNITB(TestVTYGenericBSC):
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200168
169 def vty_command(self):
170 return ["./src/osmo-nitb/osmo-nitb", "-c",
171 "doc/examples/osmo-nitb/nanobts/openbsc.cfg"]
172
173 def vty_app(self):
174 return (4242, "./src/osmo-nitb/osmo-nitb", "OpenBSC", "nitb")
175
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200176 def testConfigNetworkTree(self):
Jacob Erlbeck75877272013-10-23 11:24:14 +0200177 self._testConfigNetworkTree()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200178
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200179 def checkForSmpp(self):
180 """SMPP is not always enabled, check if it is"""
181 res = self.vty.command("list")
182 return "smpp" in res
183
Holger Hans Peter Freyther42cf2e02015-07-06 16:41:30 +0200184 def testSmppFirst(self):
Holger Hans Peter Freyther42cf2e02015-07-06 16:41:30 +0200185 # enable the configuration
186 self.vty.enable()
187 self.vty.command("configure terminal")
Holger Hans Peter Freythera2c41c42015-07-13 11:23:53 +0200188
189 if not self.checkForSmpp():
190 return
191
Holger Hans Peter Freyther42cf2e02015-07-06 16:41:30 +0200192 self.vty.command("smpp")
193
194 # check the default
195 res = self.vty.command("write terminal")
196 self.assert_(res.find(' no smpp-first') > 0)
197
198 self.vty.verify("smpp-first", [''])
199 res = self.vty.command("write terminal")
200 self.assert_(res.find(' smpp-first') > 0)
201 self.assertEquals(res.find('no smpp-first'), -1)
202
203 self.vty.verify("no smpp-first", [''])
204 res = self.vty.command("write terminal")
205 self.assert_(res.find('no smpp-first') > 0)
206
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200207 def testVtyTree(self):
208 self.vty.enable()
209 self.assertTrue(self.vty.verify("configure terminal", ['']))
210 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100211 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200212 self.assertTrue(self.vty.verify('mncc-int', ['']))
213 self.assertEquals(self.vty.node(), 'config-mncc-int')
214 self.checkForEndAndExit()
215 self.assertTrue(self.vty.verify('exit', ['']))
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200216
217 if self.checkForSmpp():
218 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck75877272013-10-23 11:24:14 +0200219 self.assertTrue(self.vty.verify('smpp', ['']))
220 self.assertEquals(self.vty.node(), 'config-smpp')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100221 self.checkForEndAndExit()
Jacob Erlbeck75877272013-10-23 11:24:14 +0200222 self.assertTrue(self.vty.verify("exit", ['']))
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200223
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200224 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200225 self.assertTrue(self.vty.verify("exit", ['']))
226 self.assertTrue(self.vty.node() is None)
227
228 # Check searching for outer node's commands
229 self.vty.command("configure terminal")
230 self.vty.command('mncc-int')
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200231
232 if self.checkForSmpp():
233 self.vty.command('smpp')
234 self.assertEquals(self.vty.node(), 'config-smpp')
235 self.vty.command('mncc-int')
236
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200237 self.assertEquals(self.vty.node(), 'config-mncc-int')
238
Maxddee01f2016-05-24 14:23:27 +0200239 def testVtyAuthorization(self):
240 self.vty.enable()
241 self.vty.command("configure terminal")
242 self.vty.command("network")
243 self.assertTrue(self.vty.verify("auth policy closed", ['']))
244 self.assertTrue(self.vty.verify("auth policy regexp", ['']))
245 self.assertTrue(self.vty.verify("authorized-regexp ^001", ['']))
246 self.assertTrue(self.vty.verify("authorized-regexp 02$", ['']))
247 self.assertTrue(self.vty.verify("authorized-regexp *123.*", ['']))
248 self.vty.command("end")
249 self.vty.command("configure terminal")
250 self.vty.command("nitb")
251 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
Maxe6052c42016-06-30 10:25:49 +0200252 self.assertTrue(self.vty.verify("subscriber-create-on-demand no-extension", ['']))
Maxddee01f2016-05-24 14:23:27 +0200253 self.vty.command("end")
254
Max0c1bc262016-04-20 12:06:06 +0200255 def testSi2Q(self):
256 self.vty.enable()
257 self.vty.command("configure terminal")
258 self.vty.command("network")
259 self.vty.command("bts 0")
260 before = self.vty.command("show running-config")
261 self.vty.command("si2quater neighbor-list add earfcn 1911 threshold 11 2")
262 self.vty.command("si2quater neighbor-list add earfcn 1924 threshold 11 3")
263 self.vty.command("si2quater neighbor-list add earfcn 2111 threshold 11")
264 self.vty.command("si2quater neighbor-list del earfcn 1911")
265 self.vty.command("si2quater neighbor-list del earfcn 1924")
266 self.vty.command("si2quater neighbor-list del earfcn 2111")
267 self.assertEquals(before, self.vty.command("show running-config"))
Max26679e02016-04-20 15:57:13 +0200268 self.vty.command("si2quater neighbor-list add uarfcn 1976 13 1")
269 self.vty.command("si2quater neighbor-list add uarfcn 1976 38 1")
270 self.vty.command("si2quater neighbor-list add uarfcn 1976 44 1")
271 self.vty.command("si2quater neighbor-list add uarfcn 1976 120 1")
272 self.vty.command("si2quater neighbor-list add uarfcn 1976 140 1")
273 self.vty.command("si2quater neighbor-list add uarfcn 1976 163 1")
274 self.vty.command("si2quater neighbor-list add uarfcn 1976 166 1")
275 self.vty.command("si2quater neighbor-list add uarfcn 1976 217 1")
276 self.vty.command("si2quater neighbor-list add uarfcn 1976 224 1")
277 self.vty.command("si2quater neighbor-list add uarfcn 1976 225 1")
278 self.vty.command("si2quater neighbor-list add uarfcn 1976 226 1")
279 self.vty.command("si2quater neighbor-list del uarfcn 1976 13")
280 self.vty.command("si2quater neighbor-list del uarfcn 1976 38")
281 self.vty.command("si2quater neighbor-list del uarfcn 1976 44")
282 self.vty.command("si2quater neighbor-list del uarfcn 1976 120")
283 self.vty.command("si2quater neighbor-list del uarfcn 1976 140")
284 self.vty.command("si2quater neighbor-list del uarfcn 1976 163")
285 self.vty.command("si2quater neighbor-list del uarfcn 1976 166")
286 self.vty.command("si2quater neighbor-list del uarfcn 1976 217")
287 self.vty.command("si2quater neighbor-list del uarfcn 1976 224")
288 self.vty.command("si2quater neighbor-list del uarfcn 1976 225")
289 self.vty.command("si2quater neighbor-list del uarfcn 1976 226")
290 self.assertEquals(before, self.vty.command("show running-config"))
Max0c1bc262016-04-20 12:06:06 +0200291
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200292 def testEnableDisablePeriodicLU(self):
293 self.vty.enable()
294 self.vty.command("configure terminal")
295 self.vty.command("network")
296 self.vty.command("bts 0")
297
298 # Test invalid input
299 self.vty.verify("periodic location update 0", ['% Unknown command.'])
300 self.vty.verify("periodic location update 5", ['% Unknown command.'])
301 self.vty.verify("periodic location update 1531", ['% Unknown command.'])
302
303 # Enable periodic lu..
304 self.vty.verify("periodic location update 60", [''])
305 res = self.vty.command("write terminal")
Holger Hans Peter Freytherc0438e32013-07-27 22:23:25 +0200306 self.assert_(res.find('periodic location update 60') > 0)
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200307 self.assertEquals(res.find('no periodic location update'), -1)
308
309 # Now disable it..
310 self.vty.verify("no periodic location update", [''])
311 res = self.vty.command("write terminal")
312 self.assertEquals(res.find('periodic location update 60'), -1)
Holger Hans Peter Freytherc0438e32013-07-27 22:23:25 +0200313 self.assert_(res.find('no periodic location update') > 0)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200314
Jacob Erlbeck65d114f2014-01-16 11:02:14 +0100315 def testEnableDisableSiHacks(self):
316 self.vty.enable()
317 self.vty.command("configure terminal")
318 self.vty.command("network")
319 self.vty.command("bts 0")
320
321 # Enable periodic lu..
322 self.vty.verify("force-combined-si", [''])
323 res = self.vty.command("write terminal")
324 self.assert_(res.find(' force-combined-si') > 0)
325 self.assertEquals(res.find('no force-combined-si'), -1)
326
327 # Now disable it..
328 self.vty.verify("no force-combined-si", [''])
329 res = self.vty.command("write terminal")
330 self.assertEquals(res.find(' force-combined-si'), -1)
331 self.assert_(res.find('no force-combined-si') > 0)
332
Ivan Kluchnikov67920592013-09-16 13:13:04 +0400333 def testRachAccessControlClass(self):
334 self.vty.enable()
335 self.vty.command("configure terminal")
336 self.vty.command("network")
337 self.vty.command("bts 0")
338
339 # Test invalid input
340 self.vty.verify("rach access-control-class", ['% Command incomplete.'])
341 self.vty.verify("rach access-control-class 1", ['% Command incomplete.'])
342 self.vty.verify("rach access-control-class -1", ['% Unknown command.'])
343 self.vty.verify("rach access-control-class 10", ['% Unknown command.'])
344 self.vty.verify("rach access-control-class 16", ['% Unknown command.'])
345
346 # Barred rach access control classes
347 for classNum in range(16):
348 if classNum != 10:
349 self.vty.verify("rach access-control-class " + str(classNum) + " barred", [''])
350
351 # Verify settings
352 res = self.vty.command("write terminal")
353 for classNum in range(16):
354 if classNum != 10:
355 self.assert_(res.find("rach access-control-class " + str(classNum) + " barred") > 0)
356
357 # Allowed rach access control classes
358 for classNum in range(16):
359 if classNum != 10:
360 self.vty.verify("rach access-control-class " + str(classNum) + " allowed", [''])
361
362 # Verify settings
363 res = self.vty.command("write terminal")
364 for classNum in range(16):
365 if classNum != 10:
366 self.assertEquals(res.find("rach access-control-class " + str(classNum) + " barred"), -1)
367
Holger Hans Peter Freytherde392252016-04-01 19:44:00 +0200368 def testSubscriberCreateDeleteTwice(self):
369 """
370 OS#1657 indicates that there might be an issue creating the
371 same subscriber twice. This test will use the VTY command to
372 create a subscriber and then issue a second create command
373 with the same IMSI. The test passes if the VTY continues to
374 respond to VTY commands.
375 """
376 self.vty.enable()
377
378 imsi = "204300854013739"
379
380 # Initially we don't have this subscriber
381 self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi])
382
383 # Lets create one
384 res = self.vty.command('subscriber create imsi '+imsi)
385 self.assert_(res.find(" IMSI: "+imsi) > 0)
386 # And now create one again.
387 res2 = self.vty.command('subscriber create imsi '+imsi)
388 self.assert_(res2.find(" IMSI: "+imsi) > 0)
389 self.assertEqual(res, res2)
390
391 # Verify it has been created
392 res = self.vty.command('show subscriber imsi '+imsi)
393 self.assert_(res.find(" IMSI: "+imsi) > 0)
394
395 # Delete it
Max488902d2016-06-22 14:02:39 +0200396 res = self.vty.command('subscriber imsi ' + imsi + ' delete')
397 self.assert_("" == res)
Holger Hans Peter Freytherde392252016-04-01 19:44:00 +0200398
399 # Now it should not be there anymore
400 res = self.vty.command('show subscriber imsi '+imsi)
Max488902d2016-06-22 14:02:39 +0200401 self.assert_(('% No subscriber found for imsi ' + imsi) == res)
Holger Hans Peter Freytherde392252016-04-01 19:44:00 +0200402
403
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500404 def testSubscriberCreateDelete(self):
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200405 self.vty.enable()
406
407 imsi = "204300854013739"
Maxe6052c42016-06-30 10:25:49 +0200408 imsi2 = "222301824913762"
409 imsi3 = "333500854113763"
410 imsi4 = "444583744053764"
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200411
412 # Initially we don't have this subscriber
413 self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi])
414
415 # Lets create one
416 res = self.vty.command('subscriber create imsi '+imsi)
417 self.assert_(res.find(" IMSI: "+imsi) > 0)
Maxe6052c42016-06-30 10:25:49 +0200418 self.assert_(res.find("Extension") > 0)
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200419
420 # Now we have it
421 res = self.vty.command('show subscriber imsi '+imsi)
422 self.assert_(res.find(" IMSI: "+imsi) > 0)
423
Maxe6052c42016-06-30 10:25:49 +0200424 # With narrow random interval
425 self.vty.command("configure terminal")
426 self.vty.command("nitb")
427 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
428 # wrong interval
429 res = self.vty.command("subscriber-create-on-demand random 221 122")
430 # error string will contain arguments
431 self.assert_(res.find("122") > 0)
432 self.assert_(res.find("221") > 0)
433 # correct interval - silent ok
434 self.assertTrue(self.vty.verify("subscriber-create-on-demand random 221 222", ['']))
435 self.vty.command("end")
436
437 res = self.vty.command('subscriber create imsi ' + imsi2)
438 self.assert_(res.find(" IMSI: " + imsi2) > 0)
439 self.assert_(res.find("221") > 0 or res.find("222") > 0)
440 self.assert_(res.find(" Extension: ") > 0)
441
442 # Without extension
443 self.vty.command("configure terminal")
444 self.vty.command("nitb")
445 self.assertTrue(self.vty.verify("subscriber-create-on-demand no-extension", ['']))
446 self.vty.command("end")
447 res = self.vty.command('subscriber create imsi ' + imsi3)
448 self.assert_(res.find(" IMSI: " + imsi3) > 0)
449 self.assertEquals(res.find("Extension"), -1)
450
451 # With extension again
452 self.vty.command("configure terminal")
453 self.vty.command("nitb")
454 self.assertTrue(self.vty.verify("no subscriber-create-on-demand", ['']))
455 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
456 self.assertTrue(self.vty.verify("subscriber-create-on-demand random 221 666", ['']))
457 self.vty.command("end")
458
459 res = self.vty.command('subscriber create imsi ' + imsi4)
460 self.assert_(res.find(" IMSI: " + imsi4) > 0)
461 self.assert_(res.find(" Extension: ") > 0)
462
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500463 # Delete it
Max488902d2016-06-22 14:02:39 +0200464 res = self.vty.command('subscriber imsi ' + imsi + ' delete')
465 self.assert_("" == res)
Maxe6052c42016-06-30 10:25:49 +0200466 res = self.vty.command('subscriber imsi ' + imsi2 + ' delete')
467 self.assert_("" == res)
468 res = self.vty.command('subscriber imsi ' + imsi3 + ' delete')
469 self.assert_("" == res)
470 res = self.vty.command('subscriber imsi ' + imsi4 + ' delete')
471 self.assert_("" == res)
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500472
473 # Now it should not be there anymore
474 res = self.vty.command('show subscriber imsi '+imsi)
Max488902d2016-06-22 14:02:39 +0200475 self.assert_(('% No subscriber found for imsi ' + imsi) == res)
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500476
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200477 def testSubscriberSettings(self):
478 self.vty.enable()
479
480 imsi = "204300854013739"
Max0fcd2e22016-06-07 15:32:16 +0200481 imsi2 = "204301824913769"
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200482 wrong_imsi = "204300999999999"
483
484 # Lets create one
485 res = self.vty.command('subscriber create imsi '+imsi)
486 self.assert_(res.find(" IMSI: "+imsi) > 0)
Max0fcd2e22016-06-07 15:32:16 +0200487 self.assert_(res.find("Extension") > 0)
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200488
489 self.vty.verify('subscriber imsi '+wrong_imsi+' name wrong', ['% No subscriber found for imsi '+wrong_imsi])
490 res = self.vty.command('subscriber imsi '+imsi+' name '+('X' * 160))
491 self.assert_(res.find("NAME is too long") > 0)
492
493 self.vty.verify('subscriber imsi '+imsi+' name '+('G' * 159), [''])
494
495 self.vty.verify('subscriber imsi '+wrong_imsi+' extension 840', ['% No subscriber found for imsi '+wrong_imsi])
496 res = self.vty.command('subscriber imsi '+imsi+' extension '+('9' * 15))
497 self.assert_(res.find("EXTENSION is too long") > 0)
498
499 self.vty.verify('subscriber imsi '+imsi+' extension '+('1' * 14), [''])
500
Max0fcd2e22016-06-07 15:32:16 +0200501 # With narrow random interval
502 self.vty.command("configure terminal")
503 self.vty.command("nitb")
504 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
505 # wrong interval
506 res = self.vty.command("subscriber-create-on-demand random 221 122")
507 self.assert_(res.find("122") > 0)
508 self.assert_(res.find("221") > 0)
509 # correct interval
510 self.assertTrue(self.vty.verify("subscriber-create-on-demand random 221 222", ['']))
511 self.vty.command("end")
512
Max488902d2016-06-22 14:02:39 +0200513 # create subscriber with extension in a configured interval
Max0fcd2e22016-06-07 15:32:16 +0200514 res = self.vty.command('subscriber create imsi ' + imsi2)
515 self.assert_(res.find(" IMSI: " + imsi2) > 0)
516 self.assert_(res.find("221") > 0 or res.find("222") > 0)
517 self.assert_(res.find(" Extension: ") > 0)
518
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200519 # Delete it
Max488902d2016-06-22 14:02:39 +0200520 res = self.vty.command('subscriber imsi ' + imsi + ' delete')
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200521 self.assert_(res != "")
Max488902d2016-06-22 14:02:39 +0200522 # imsi2 is inactive so deletion should succeed
523 res = self.vty.command('subscriber imsi ' + imsi2 + ' delete')
524 self.assert_("" == res)
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200525
Holger Hans Peter Freytherec37bb22013-02-05 09:39:09 +0100526 def testShowPagingGroup(self):
527 res = self.vty.command("show paging-group 255 1234567")
528 self.assertEqual(res, "% can't find BTS 255")
529 res = self.vty.command("show paging-group 0 1234567")
530 self.assertEquals(res, "%Paging group for IMSI 1234567 on BTS #0 is 7")
531
Ciabyec6e4f82014-03-06 17:20:55 +0100532 def testShowNetwork(self):
533 res = self.vty.command("show network")
534 self.assert_(res.startswith('BSC is on Country Code') >= 0)
535
Holger Hans Peter Freyther86573262015-01-31 09:47:37 +0100536 def testMeasurementFeed(self):
537 self.vty.enable()
538 self.vty.command("configure terminal")
539 self.vty.command("mncc-int")
540
541 res = self.vty.command("write terminal")
542 self.assertEquals(res.find('meas-feed scenario'), -1)
543
544 self.vty.command("meas-feed scenario bla")
545 res = self.vty.command("write terminal")
546 self.assert_(res.find('meas-feed scenario bla') > 0)
547
Neels Hofmeyr0867b722016-09-28 23:28:06 +0200548 self.vty.command("meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890")
Holger Hans Peter Freyther86573262015-01-31 09:47:37 +0100549 res = self.vty.command("write terminal")
550 self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890'), -1)
551 self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz012345'), -1)
552 self.assert_(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234') > 0)
553
554
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200555class TestVTYBSC(TestVTYGenericBSC):
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200556
557 def vty_command(self):
558 return ["./src/osmo-bsc/osmo-bsc", "-c",
559 "doc/examples/osmo-bsc/osmo-bsc.cfg"]
560
561 def vty_app(self):
562 return (4242, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc")
563
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200564 def testConfigNetworkTree(self):
Jacob Erlbeck75877272013-10-23 11:24:14 +0200565 self._testConfigNetworkTree()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200566
567 def testVtyTree(self):
568 self.vty.enable()
569 self.assertTrue(self.vty.verify("configure terminal", ['']))
570 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100571 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200572 self.assertTrue(self.vty.verify("msc 0", ['']))
573 self.assertEquals(self.vty.node(), 'config-msc')
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("bsc", ['']))
578 self.assertEquals(self.vty.node(), 'config-bsc')
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200579 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200580 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200581 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200582 self.assertTrue(self.vty.verify("exit", ['']))
583 self.assertTrue(self.vty.node() is None)
584
585 # Check searching for outer node's commands
586 self.vty.command("configure terminal")
587 self.vty.command('msc 0')
588 self.vty.command("bsc")
589 self.assertEquals(self.vty.node(), 'config-bsc')
590 self.vty.command("msc 0")
591 self.assertEquals(self.vty.node(), 'config-msc')
592
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200593 def testUssdNotificationsMsc(self):
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200594 self.vty.enable()
595 self.vty.command("configure terminal")
596 self.vty.command("msc")
597
598 # Test invalid input
599 self.vty.verify("bsc-msc-lost-text", ['% Command incomplete.'])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200600 self.vty.verify("bsc-welcome-text", ['% Command incomplete.'])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200601 self.vty.verify("bsc-grace-text", ['% Command incomplete.'])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200602
603 # Enable USSD notifications
604 self.vty.verify("bsc-msc-lost-text MSC disconnected", [''])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200605 self.vty.verify("bsc-welcome-text Hello MS", [''])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200606 self.vty.verify("bsc-grace-text In grace period", [''])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200607
608 # Verify settings
609 res = self.vty.command("write terminal")
610 self.assert_(res.find('bsc-msc-lost-text MSC disconnected') > 0)
611 self.assertEquals(res.find('no bsc-msc-lost-text'), -1)
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200612 self.assert_(res.find('bsc-welcome-text Hello MS') > 0)
613 self.assertEquals(res.find('no bsc-welcome-text'), -1)
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200614 self.assert_(res.find('bsc-grace-text In grace period') > 0)
615 self.assertEquals(res.find('no bsc-grace-text'), -1)
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200616
617 # Now disable it..
618 self.vty.verify("no bsc-msc-lost-text", [''])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200619 self.vty.verify("no bsc-welcome-text", [''])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200620 self.vty.verify("no bsc-grace-text", [''])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200621
622 # Verify settings
623 res = self.vty.command("write terminal")
624 self.assertEquals(res.find('bsc-msc-lost-text MSC disconnected'), -1)
625 self.assert_(res.find('no bsc-msc-lost-text') > 0)
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200626 self.assertEquals(res.find('bsc-welcome-text Hello MS'), -1)
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200627 self.assert_(res.find('no bsc-welcome-text') > 0)
628 self.assertEquals(res.find('bsc-grace-text In grace period'), -1)
629 self.assert_(res.find('no bsc-grace-text') > 0)
630
631 def testUssdNotificationsBsc(self):
632 self.vty.enable()
633 self.vty.command("configure terminal")
634 self.vty.command("bsc")
635
636 # Test invalid input
637 self.vty.verify("missing-msc-text", ['% Command incomplete.'])
638
639 # Enable USSD notifications
640 self.vty.verify("missing-msc-text No MSC found", [''])
641
642 # Verify settings
643 res = self.vty.command("write terminal")
644 self.assert_(res.find('missing-msc-text No MSC found') > 0)
645 self.assertEquals(res.find('no missing-msc-text'), -1)
646
647 # Now disable it..
648 self.vty.verify("no missing-msc-text", [''])
649
650 # Verify settings
651 res = self.vty.command("write terminal")
652 self.assertEquals(res.find('missing-msc-text No MSC found'), -1)
653 self.assert_(res.find('no missing-msc-text') > 0)
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200654
Jacob Erlbeck946d1412013-09-17 13:59:29 +0200655 def testNetworkTimezone(self):
656 self.vty.enable()
657 self.vty.verify("configure terminal", [''])
658 self.vty.verify("network", [''])
Jacob Erlbeck946d1412013-09-17 13:59:29 +0200659
660 # Test invalid input
661 self.vty.verify("timezone", ['% Command incomplete.'])
662 self.vty.verify("timezone 20 0", ['% Unknown command.'])
663 self.vty.verify("timezone 0 11", ['% Unknown command.'])
664 self.vty.verify("timezone 0 0 99", ['% Unknown command.'])
665
666 # Set time zone without DST
667 self.vty.verify("timezone 2 30", [''])
668
669 # Verify settings
670 res = self.vty.command("write terminal")
671 self.assert_(res.find('timezone 2 30') > 0)
672 self.assertEquals(res.find('timezone 2 30 '), -1)
673
674 # Set time zone with DST
675 self.vty.verify("timezone 2 30 1", [''])
676
677 # Verify settings
678 res = self.vty.command("write terminal")
679 self.assert_(res.find('timezone 2 30 1') > 0)
680
681 # Now disable it..
682 self.vty.verify("no timezone", [''])
683
684 # Verify settings
685 res = self.vty.command("write terminal")
686 self.assertEquals(res.find(' timezone'), -1)
687
Ciabyec6e4f82014-03-06 17:20:55 +0100688 def testShowNetwork(self):
689 res = self.vty.command("show network")
690 self.assert_(res.startswith('BSC is on Country Code') >= 0)
691
Holger Hans Peter Freytherdb64f2e2014-10-29 10:06:15 +0100692 def testPingPongConfiguration(self):
693 self.vty.enable()
694 self.vty.verify("configure terminal", [''])
695 self.vty.verify("network", [''])
696 self.vty.verify("msc 0", [''])
697
698 self.vty.verify("timeout-ping 12", [''])
699 self.vty.verify("timeout-pong 14", [''])
700 res = self.vty.command("show running-config")
701 self.assert_(res.find(" timeout-ping 12") > 0)
702 self.assert_(res.find(" timeout-pong 14") > 0)
703 self.assert_(res.find(" no timeout-ping advanced") > 0)
704
705 self.vty.verify("timeout-ping advanced", [''])
706 res = self.vty.command("show running-config")
707 self.assert_(res.find(" timeout-ping 12") > 0)
708 self.assert_(res.find(" timeout-pong 14") > 0)
709 self.assert_(res.find(" timeout-ping advanced") > 0)
710
711 self.vty.verify("no timeout-ping advanced", [''])
712 res = self.vty.command("show running-config")
713 self.assert_(res.find(" timeout-ping 12") > 0)
714 self.assert_(res.find(" timeout-pong 14") > 0)
715 self.assert_(res.find(" no timeout-ping advanced") > 0)
716
717 self.vty.verify("no timeout-ping", [''])
718 res = self.vty.command("show running-config")
719 self.assertEquals(res.find(" timeout-ping 12"), -1)
720 self.assertEquals(res.find(" timeout-pong 14"), -1)
721 self.assertEquals(res.find(" no timeout-ping advanced"), -1)
722 self.assert_(res.find(" no timeout-ping") > 0)
723
724 self.vty.verify("timeout-ping advanced", ['%ping handling is disabled. Enable it first.'])
725
726 # And back to enabling it
727 self.vty.verify("timeout-ping 12", [''])
728 self.vty.verify("timeout-pong 14", [''])
729 res = self.vty.command("show running-config")
730 self.assert_(res.find(" timeout-ping 12") > 0)
731 self.assert_(res.find(" timeout-pong 14") > 0)
732 self.assert_(res.find(" timeout-ping advanced") > 0)
733
Holger Hans Peter Freyther32dd2f32015-04-01 18:15:48 +0200734 def testMscDataCoreLACCI(self):
735 self.vty.enable()
736 res = self.vty.command("show running-config")
737 self.assertEquals(res.find("core-location-area-code"), -1)
738 self.assertEquals(res.find("core-cell-identity"), -1)
739
Neels Hofmeyr0867b722016-09-28 23:28:06 +0200740 self.vty.command("configure terminal")
Holger Hans Peter Freyther32dd2f32015-04-01 18:15:48 +0200741 self.vty.command("msc 0")
742 self.vty.command("core-location-area-code 666")
743 self.vty.command("core-cell-identity 333")
744
745 res = self.vty.command("show running-config")
746 self.assert_(res.find("core-location-area-code 666") > 0)
747 self.assert_(res.find("core-cell-identity 333") > 0)
748
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200749class TestVTYNAT(TestVTYGenericBSC):
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200750
751 def vty_command(self):
Max49364482016-04-13 11:36:39 +0200752 return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-l", "127.0.0.1", "-c",
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200753 "doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"]
754
755 def vty_app(self):
756 return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat")
757
Max49364482016-04-13 11:36:39 +0200758 def testBSCreload(self):
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -0400759 # Use different port for the mock msc to avoid clashing with
760 # the osmo-bsc_nat itself
Holger Hans Peter Freytherf1a61bb2016-04-14 08:50:25 -0400761 ip = "127.0.0.1"
Holger Hans Peter Freythere98c9c72016-04-14 10:58:58 -0400762 port = 5522
Max49364482016-04-13 11:36:39 +0200763 self.vty.enable()
764 bscs1 = self.vty.command("show bscs-config")
765 nat_bsc_reload(self)
766 bscs2 = self.vty.command("show bscs-config")
767 # check that multiple calls to bscs-config-file give the same result
768 self.assertEquals(bscs1, bscs2)
769
770 # add new bsc
771 self.vty.command("configure terminal")
772 self.vty.command("nat")
773 self.vty.command("bsc 5")
774 self.vty.command("token key")
775 self.vty.command("location_area_code 666")
776 self.vty.command("end")
777
778 # update bsc token
779 self.vty.command("configure terminal")
780 self.vty.command("nat")
781 self.vty.command("bsc 1")
782 self.vty.command("token xyu")
783 self.vty.command("end")
784
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -0400785 nat_msc_ip(self, ip, port)
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +0100786 msc = nat_msc_test(self, ip, port, verbose=True)
787 b0 = nat_bsc_sock_test(0, "lol", verbose=True, proc=self.proc)
788 b1 = nat_bsc_sock_test(1, "xyu", verbose=True, proc=self.proc)
789 b2 = nat_bsc_sock_test(5, "key", verbose=True, proc=self.proc)
Max49364482016-04-13 11:36:39 +0200790
791 self.assertEquals("3 BSCs configured", self.vty.command("show nat num-bscs-configured"))
792 self.assertTrue(3 == nat_bsc_num_con(self))
793 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
794
795 nat_bsc_reload(self)
796 bscs2 = self.vty.command("show bscs-config")
797 # check that the reset to initial config succeeded
798 self.assertEquals(bscs1, bscs2)
799
800 self.assertEquals("2 BSCs configured", self.vty.command("show nat num-bscs-configured"))
801 self.assertTrue(1 == nat_bsc_num_con(self))
802 rem = self.vty.command("show bsc connections").split(' ')
803 # remaining connection is for BSC0
804 self.assertEquals('0', rem[2])
805 # remaining connection is authorized
806 self.assertEquals('1', rem[4])
807 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
808
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200809 def testVtyTree(self):
810 self.vty.enable()
811 self.assertTrue(self.vty.verify('configure terminal', ['']))
812 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100813 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200814 self.assertTrue(self.vty.verify('mgcp', ['']))
815 self.assertEquals(self.vty.node(), 'config-mgcp')
816 self.checkForEndAndExit()
817 self.assertTrue(self.vty.verify('exit', ['']))
818 self.assertEquals(self.vty.node(), 'config')
819 self.assertTrue(self.vty.verify('nat', ['']))
820 self.assertEquals(self.vty.node(), 'config-nat')
821 self.checkForEndAndExit()
822 self.assertTrue(self.vty.verify('bsc 0', ['']))
823 self.assertEquals(self.vty.node(), 'config-nat-bsc')
824 self.checkForEndAndExit()
825 self.assertTrue(self.vty.verify('exit', ['']))
826 self.assertEquals(self.vty.node(), 'config-nat')
827 self.assertTrue(self.vty.verify('exit', ['']))
828 self.assertEquals(self.vty.node(), 'config')
829 self.assertTrue(self.vty.verify('exit', ['']))
830 self.assertTrue(self.vty.node() is None)
831
832 # Check searching for outer node's commands
833 self.vty.command('configure terminal')
834 self.vty.command('mgcp')
835 self.vty.command('nat')
836 self.assertEquals(self.vty.node(), 'config-nat')
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 self.vty.command('nat')
840 self.assertEquals(self.vty.node(), 'config-nat')
841 self.vty.command('bsc 0')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200842 self.vty.command('mgcp')
843 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200844
Holger Hans Peter Freytherb718ad32013-06-25 09:08:02 +0200845 def testRewriteNoRewrite(self):
846 self.vty.enable()
847 res = self.vty.command("configure terminal")
848 res = self.vty.command("nat")
849 res = self.vty.command("number-rewrite rewrite.cfg")
850 res = self.vty.command("no number-rewrite")
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200851
Holger Hans Peter Freyther7f100c92015-04-23 20:25:17 -0400852 def testEnsureNoEnsureModeSet(self):
853 self.vty.enable()
854 res = self.vty.command("configure terminal")
855 res = self.vty.command("nat")
856
857 # Ensure the default
858 res = self.vty.command("show running-config")
859 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
860
861 self.vty.command("sdp-ensure-amr-mode-set")
862 res = self.vty.command("show running-config")
863 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
864
865 self.vty.command("no sdp-ensure-amr-mode-set")
866 res = self.vty.command("show running-config")
867 self.assert_(res.find('\n no sdp-ensure-amr-mode-set') > 0)
868
Holger Hans Peter Freyther67e423c2013-06-25 15:38:31 +0200869 def testRewritePostNoRewrite(self):
870 self.vty.enable()
871 self.vty.command("configure terminal")
872 self.vty.command("nat")
873 self.vty.verify("number-rewrite-post rewrite.cfg", [''])
874 self.vty.verify("no number-rewrite-post", [''])
875
876
Holger Hans Peter Freytherddf191e2013-06-25 11:44:01 +0200877 def testPrefixTreeLoading(self):
878 cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv")
879
880 self.vty.enable()
881 self.vty.command("configure terminal")
882 self.vty.command("nat")
883 res = self.vty.command("prefix-tree %s" % cfg)
884 self.assertEqual(res, "% prefix-tree loaded 17 rules.")
885 self.vty.command("end")
886
887 res = self.vty.command("show prefix-tree")
888 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')
889
890 self.vty.command("configure terminal")
891 self.vty.command("nat")
892 self.vty.command("no prefix-tree")
893 self.vty.command("end")
894
895 res = self.vty.command("show prefix-tree")
896 self.assertEqual(res, "% there is now prefix tree loaded.")
897
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200898 def testUssdSideChannelProvider(self):
899 self.vty.command("end")
900 self.vty.enable()
901 self.vty.command("configure terminal")
902 self.vty.command("nat")
903 self.vty.command("ussd-token key")
904 self.vty.command("end")
905
906 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
907 self.assertTrue(res)
908
909 ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
910 ussdSocket.connect(('127.0.0.1', 5001))
911 ussdSocket.settimeout(2.0)
912 print "Connected to %s:%d" % ussdSocket.getpeername()
913
914 print "Expecting ID_GET request"
915 data = ussdSocket.recv(4)
916 self.assertEqual(data, "\x00\x01\xfe\x04")
917
918 print "Going to send ID_RESP response"
Max3e676892016-11-16 14:55:21 +0100919 res = ussdSocket.send(IPA().id_resp(IPA().tag_name('key')))
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200920 self.assertEqual(res, 10)
921
922 # initiating PING/PONG cycle to know, that the ID_RESP message has been processed
923
924 print "Going to send PING request"
Max3e676892016-11-16 14:55:21 +0100925 res = ussdSocket.send(IPA().ping())
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200926 self.assertEqual(res, 4)
927
928 print "Expecting PONG response"
929 data = ussdSocket.recv(4)
930 self.assertEqual(data, "\x00\x01\xfe\x01")
931
932 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.'])
933 self.assertTrue(res)
934
935 print "Going to shut down connection"
936 ussdSocket.shutdown(socket.SHUT_WR)
937
938 print "Expecting EOF"
939 data = ussdSocket.recv(4)
940 self.assertEqual(data, "")
941
942 ussdSocket.close()
943
944 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
945 self.assertTrue(res)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200946
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100947 def testAccessList(self):
948 """
949 Verify that the imsi-deny can have a reject cause or no reject cause
950 """
951 self.vty.enable()
952 self.vty.command("configure terminal")
953 self.vty.command("nat")
954
955 # Old default
956 self.vty.command("access-list test-default imsi-deny ^123[0-9]*$")
957 res = self.vty.command("show running-config").split("\r\n")
958 asserted = False
959 for line in res:
Holger Hans Peter Freyther4ecc6872014-03-04 15:38:00 +0100960 if line.startswith(" access-list test-default"):
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100961 self.assertEqual(line, " access-list test-default imsi-deny ^123[0-9]*$ 11 11")
962 asserted = True
963 self.assert_(asserted)
964
965 # Check the optional CM Service Reject Cause
966 self.vty.command("access-list test-cm-deny imsi-deny ^123[0-9]*$ 42").split("\r\n")
967 res = self.vty.command("show running-config").split("\r\n")
968 asserted = False
969 for line in res:
970 if line.startswith(" access-list test-cm"):
971 self.assertEqual(line, " access-list test-cm-deny imsi-deny ^123[0-9]*$ 42 11")
972 asserted = True
973 self.assert_(asserted)
974
975 # Check the optional LU Reject Cause
976 self.vty.command("access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42").split("\r\n")
977 res = self.vty.command("show running-config").split("\r\n")
978 asserted = False
979 for line in res:
980 if line.startswith(" access-list test-lu"):
981 self.assertEqual(line, " access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42")
982 asserted = True
983 self.assert_(asserted)
984
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200985class TestVTYGbproxy(TestVTYGenericBSC):
986
987 def vty_command(self):
988 return ["./src/gprs/osmo-gbproxy", "-c",
989 "doc/examples/osmo-gbproxy/osmo-gbproxy.cfg"]
990
991 def vty_app(self):
992 return (4246, "./src/gprs/osmo-gbproxy", "OsmoGbProxy", "bsc")
993
994 def testVtyTree(self):
995 self.vty.enable()
996 self.assertTrue(self.vty.verify('configure terminal', ['']))
997 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100998 self.checkForEndAndExit()
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200999 self.assertTrue(self.vty.verify('ns', ['']))
1000 self.assertEquals(self.vty.node(), 'config-ns')
1001 self.checkForEndAndExit()
1002 self.assertTrue(self.vty.verify('exit', ['']))
1003 self.assertEquals(self.vty.node(), 'config')
1004 self.assertTrue(self.vty.verify('gbproxy', ['']))
1005 self.assertEquals(self.vty.node(), 'config-gbproxy')
1006 self.checkForEndAndExit()
1007 self.assertTrue(self.vty.verify('exit', ['']))
1008 self.assertEquals(self.vty.node(), 'config')
1009
1010 def testVtyShow(self):
1011 res = self.vty.command("show ns")
1012 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
1013
1014 res = self.vty.command("show gbproxy stats")
1015 self.assert_(res.find('GBProxy Global Statistics') >= 0)
1016
Jacob Erlbeck4211d792013-10-24 12:48:23 +02001017 def testVtyDeletePeer(self):
1018 self.vty.enable()
1019 self.assertTrue(self.vty.verify('delete-gbproxy-peer 9999 bvci 7777', ['BVC not found']))
1020 res = self.vty.command("delete-gbproxy-peer 9999 all dry-run")
1021 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
1022 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
1023 res = self.vty.command("delete-gbproxy-peer 9999 only-bvc dry-run")
1024 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
1025 self.assert_(res.find('Not Deleted 0 NS-VC') < 0)
1026 res = self.vty.command("delete-gbproxy-peer 9999 only-nsvc dry-run")
1027 self.assert_(res.find('Not Deleted 0 BVC') < 0)
1028 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
1029 res = self.vty.command("delete-gbproxy-peer 9999 all")
1030 self.assert_(res.find('Deleted 0 BVC') >= 0)
1031 self.assert_(res.find('Deleted 0 NS-VC') >= 0)
1032
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001033class TestVTYSGSN(TestVTYGenericBSC):
1034
1035 def vty_command(self):
1036 return ["./src/gprs/osmo-sgsn", "-c",
1037 "doc/examples/osmo-sgsn/osmo-sgsn.cfg"]
1038
1039 def vty_app(self):
1040 return (4245, "./src/gprs/osmo-sgsn", "OsmoSGSN", "sgsn")
1041
1042 def testVtyTree(self):
1043 self.vty.enable()
1044 self.assertTrue(self.vty.verify('configure terminal', ['']))
1045 self.assertEquals(self.vty.node(), 'config')
1046 self.checkForEndAndExit()
1047 self.assertTrue(self.vty.verify('ns', ['']))
1048 self.assertEquals(self.vty.node(), 'config-ns')
1049 self.checkForEndAndExit()
1050 self.assertTrue(self.vty.verify('exit', ['']))
1051 self.assertEquals(self.vty.node(), 'config')
1052 self.assertTrue(self.vty.verify('sgsn', ['']))
1053 self.assertEquals(self.vty.node(), 'config-sgsn')
1054 self.checkForEndAndExit()
1055 self.assertTrue(self.vty.verify('exit', ['']))
1056 self.assertEquals(self.vty.node(), 'config')
1057
1058 def testVtyShow(self):
1059 res = self.vty.command("show ns")
1060 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
1061 self.assertTrue(self.vty.verify('show bssgp', ['']))
1062 self.assertTrue(self.vty.verify('show bssgp stats', ['']))
1063 # TODO: uncomment when the command does not segfault anymore
1064 # self.assertTrue(self.vty.verify('show bssgp nsei 123', ['']))
1065 # self.assertTrue(self.vty.verify('show bssgp nsei 123 stats', ['']))
1066
1067 self.assertTrue(self.vty.verify('show sgsn', ['']))
1068 self.assertTrue(self.vty.verify('show mm-context all', ['']))
1069 self.assertTrue(self.vty.verify('show mm-context imsi 000001234567', ['No MM context for IMSI 000001234567']))
1070 self.assertTrue(self.vty.verify('show pdp-context all', ['']))
1071
1072 res = self.vty.command("show sndcp")
1073 self.assert_(res.find('State of SNDCP Entities') >= 0)
1074
1075 res = self.vty.command("show llc")
1076 self.assert_(res.find('State of LLC Entities') >= 0)
1077
Jacob Erlbeck106f5472014-11-04 10:08:37 +01001078 def testVtyAuth(self):
1079 self.vty.enable()
1080 self.assertTrue(self.vty.verify('configure terminal', ['']))
1081 self.assertEquals(self.vty.node(), 'config')
1082 self.assertTrue(self.vty.verify('sgsn', ['']))
1083 self.assertEquals(self.vty.node(), 'config-sgsn')
1084 self.assertTrue(self.vty.verify('auth-policy accept-all', ['']))
1085 res = self.vty.command("show running-config")
1086 self.assert_(res.find('auth-policy accept-all') > 0)
1087 self.assertTrue(self.vty.verify('auth-policy acl-only', ['']))
1088 res = self.vty.command("show running-config")
1089 self.assert_(res.find('auth-policy acl-only') > 0)
1090 self.assertTrue(self.vty.verify('auth-policy closed', ['']))
1091 res = self.vty.command("show running-config")
1092 self.assert_(res.find('auth-policy closed') > 0)
Max176b62a2016-07-04 11:09:07 +02001093 self.assertTrue(self.vty.verify('gsup remote-ip 127.0.0.4', ['']))
1094 self.assertTrue(self.vty.verify('gsup remote-port 2222', ['']))
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +01001095 self.assertTrue(self.vty.verify('auth-policy remote', ['']))
1096 res = self.vty.command("show running-config")
1097 self.assert_(res.find('auth-policy remote') > 0)
Jacob Erlbeck106f5472014-11-04 10:08:37 +01001098
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001099 def testVtySubscriber(self):
1100 self.vty.enable()
1101 res = self.vty.command('show subscriber cache')
1102 self.assert_(res.find('1234567890') < 0)
Jacob Erlbeckd9193432015-01-19 14:11:46 +01001103 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 create', ['']))
1104 res = self.vty.command('show subscriber cache')
1105 self.assert_(res.find('1234567890') >= 0)
1106 self.assert_(res.find('Authorized: 0') >= 0)
1107 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 update-location-result ok', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001108 res = self.vty.command('show subscriber cache')
1109 self.assert_(res.find('1234567890') >= 0)
1110 self.assert_(res.find('Authorized: 1') >= 0)
Jacob Erlbeck8000e0e2015-01-27 14:56:40 +01001111 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 cancel update-procedure', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001112 res = self.vty.command('show subscriber cache')
Jacob Erlbecke988ae42015-01-27 12:41:19 +01001113 self.assert_(res.find('1234567890') >= 0)
1114 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 destroy', ['']))
1115 res = self.vty.command('show subscriber cache')
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001116 self.assert_(res.find('1234567890') < 0)
1117
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +01001118 def testVtyGgsn(self):
1119 self.vty.enable()
1120 self.assertTrue(self.vty.verify('configure terminal', ['']))
1121 self.assertEquals(self.vty.node(), 'config')
1122 self.assertTrue(self.vty.verify('sgsn', ['']))
1123 self.assertEquals(self.vty.node(), 'config-sgsn')
1124 self.assertTrue(self.vty.verify('ggsn 0 remote-ip 127.99.99.99', ['']))
1125 self.assertTrue(self.vty.verify('ggsn 0 gtp-version 1', ['']))
1126 self.assertTrue(self.vty.verify('apn * ggsn 0', ['']))
1127 self.assertTrue(self.vty.verify('apn apn1.test ggsn 0', ['']))
1128 self.assertTrue(self.vty.verify('apn apn1.test ggsn 1', ['% a GGSN with id 1 has not been defined']))
1129 self.assertTrue(self.vty.verify('apn apn1.test imsi-prefix 123456 ggsn 0', ['']))
1130 self.assertTrue(self.vty.verify('apn apn2.test imsi-prefix 123456 ggsn 0', ['']))
1131 res = self.vty.command("show running-config")
1132 self.assert_(res.find('ggsn 0 remote-ip 127.99.99.99') >= 0)
1133 self.assert_(res.find('ggsn 0 gtp-version 1') >= 0)
1134 self.assert_(res.find('apn * ggsn 0') >= 0)
1135 self.assert_(res.find('apn apn1.test ggsn 0') >= 0)
1136 self.assert_(res.find('apn apn1.test imsi-prefix 123456 ggsn 0') >= 0)
1137 self.assert_(res.find('apn apn2.test imsi-prefix 123456 ggsn 0') >= 0)
1138
Holger Hans Peter Freyther9c20a5f2015-02-06 16:23:29 +01001139 def testVtyEasyAPN(self):
1140 self.vty.enable()
1141 self.assertTrue(self.vty.verify('configure terminal', ['']))
1142 self.assertEquals(self.vty.node(), 'config')
1143 self.assertTrue(self.vty.verify('sgsn', ['']))
1144 self.assertEquals(self.vty.node(), 'config-sgsn')
1145
1146 res = self.vty.command("show running-config")
1147 self.assertEquals(res.find("apn internet"), -1)
1148
1149 self.assertTrue(self.vty.verify("access-point-name internet.apn", ['']))
1150 res = self.vty.command("show running-config")
1151 self.assert_(res.find("apn internet.apn ggsn 0") >= 0)
1152
1153 self.assertTrue(self.vty.verify("no access-point-name internet.apn", ['']))
1154 res = self.vty.command("show running-config")
1155 self.assertEquals(res.find("apn internet"), -1)
1156
Holger Hans Peter Freytherc15c61c2015-05-06 17:46:08 +02001157 def testVtyCDR(self):
1158 self.vty.enable()
1159 self.assertTrue(self.vty.verify('configure terminal', ['']))
1160 self.assertEquals(self.vty.node(), 'config')
1161 self.assertTrue(self.vty.verify('sgsn', ['']))
1162 self.assertEquals(self.vty.node(), 'config-sgsn')
1163
1164 res = self.vty.command("show running-config")
1165 self.assert_(res.find("no cdr filename") > 0)
1166
1167 self.vty.command("cdr filename bla.cdr")
1168 res = self.vty.command("show running-config")
1169 self.assertEquals(res.find("no cdr filename"), -1)
1170 self.assert_(res.find(" cdr filename bla.cdr") > 0)
1171
1172 self.vty.command("no cdr filename")
1173 res = self.vty.command("show running-config")
1174 self.assert_(res.find("no cdr filename") > 0)
1175 self.assertEquals(res.find(" cdr filename bla.cdr"), -1)
1176
1177 res = self.vty.command("show running-config")
1178 self.assert_(res.find(" cdr interval 600") > 0)
1179
1180 self.vty.command("cdr interval 900")
1181 res = self.vty.command("show running-config")
1182 self.assert_(res.find(" cdr interval 900") > 0)
1183 self.assertEquals(res.find(" cdr interval 600"), -1)
1184
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001185def add_nat_test(suite, workdir):
1186 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
1187 print("Skipping the NAT test")
1188 return
1189 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT)
1190 suite.addTest(test)
1191
Max49364482016-04-13 11:36:39 +02001192def nat_bsc_reload(x):
1193 x.vty.command("configure terminal")
1194 x.vty.command("nat")
1195 x.vty.command("bscs-config-file bscs.config")
1196 x.vty.command("end")
1197
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001198def nat_msc_ip(x, ip, port):
Max49364482016-04-13 11:36:39 +02001199 x.vty.command("configure terminal")
1200 x.vty.command("nat")
1201 x.vty.command("msc ip " + ip)
Holger Hans Peter Freyther84ae27e2016-04-14 10:40:06 -04001202 x.vty.command("msc port " + str(port))
Max49364482016-04-13 11:36:39 +02001203 x.vty.command("end")
1204
1205def data2str(d):
Holger Hans Peter Freyther8bb62042016-04-14 21:40:04 -04001206 return d.encode('hex').lower()
Max49364482016-04-13 11:36:39 +02001207
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001208def nat_msc_test(x, ip, port, verbose = False):
Max49364482016-04-13 11:36:39 +02001209 msc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Neels Hofmeyr53403452017-02-28 02:38:43 +01001210 msc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
Neels Hofmeyrcaeb62d2016-09-28 23:38:45 +02001211 msc.settimeout(5)
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001212 msc.bind((ip, port))
Max49364482016-04-13 11:36:39 +02001213 msc.listen(5)
1214 if (verbose):
1215 print "MSC is ready at " + ip
Neels Hofmeyr89d20b62016-09-26 12:59:36 +02001216 conn = None
Neels Hofmeyrcaeb62d2016-09-28 23:38:45 +02001217 while True:
1218 vty_response = x.vty.command("show msc connection")
1219 print "'show msc connection' says: %r" % vty_response
1220 if vty_response == "MSC is connected: 1":
1221 # success
1222 break;
1223 if vty_response != "MSC is connected: 0":
1224 raise Exception("Unexpected response to 'show msc connection'"
1225 " vty command: %r" % vty_response)
1226
1227 timeout_retries = 6
1228 while timeout_retries > 0:
1229 try:
1230 conn, addr = msc.accept()
1231 print "MSC got connection from ", addr
1232 break
1233 except socket.timeout:
1234 print "socket timed out."
1235 timeout_retries -= 1
1236 continue
1237
Neels Hofmeyr89d20b62016-09-26 12:59:36 +02001238 if not conn:
Neels Hofmeyr0867b722016-09-28 23:28:06 +02001239 raise Exception("VTY reports MSC is connected, but I haven't"
1240 " connected yet: %r %r" % (ip, port))
Max49364482016-04-13 11:36:39 +02001241 return conn
1242
1243def ipa_handle_small(x, verbose = False):
1244 s = data2str(x.recv(4))
Neels Hofmeyrba1468e2017-02-03 04:23:46 +01001245 if len(s) != 4*2:
1246 raise Exception("expected to receive 4 bytes, but got %d (%r)" % (len(s)/2, s))
Max49364482016-04-13 11:36:39 +02001247 if "0001fe00" == s:
1248 if (verbose):
1249 print "\tBSC <- NAT: PING?"
Max3e676892016-11-16 14:55:21 +01001250 x.send(IPA().pong())
Max49364482016-04-13 11:36:39 +02001251 elif "0001fe06" == s:
1252 if (verbose):
1253 print "\tBSC <- NAT: IPA ID ACK"
Max3e676892016-11-16 14:55:21 +01001254 x.send(IPA().id_ack())
Max49364482016-04-13 11:36:39 +02001255 elif "0001fe00" == s:
1256 if (verbose):
1257 print "\tBSC <- NAT: PONG!"
1258 else:
1259 if (verbose):
1260 print "\tBSC <- NAT: ", s
1261
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001262def ipa_handle_resp(x, tk, verbose = False, proc=None):
Max49364482016-04-13 11:36:39 +02001263 s = data2str(x.recv(38))
1264 if "0023fe040108010701020103010401050101010011" in s:
Neels Hofmeyr7d17c3e2017-01-26 23:04:28 +01001265 retries = 3
1266 while True:
1267 print "\tsending IPA identity(%s) at %s" % (tk, time.strftime("%T"))
1268 try:
1269 x.send(IPA().id_resp(IPA().identity(name = tk.encode('utf-8'))))
1270 print "\tdone sending IPA identity(%s) at %s" % (tk,
1271 time.strftime("%T"))
1272 break
1273 except:
1274 print "\tfailed sending IPA identity at", time.strftime("%T")
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001275 if proc:
1276 print "\tproc.poll() = %r" % proc.poll()
Neels Hofmeyr7d17c3e2017-01-26 23:04:28 +01001277 if retries < 1:
1278 print "\tgiving up"
1279 raise
Neels Hofmeyre02e1e72017-02-03 05:55:26 +01001280 print "\tretrying (%d attempts left)" % retries
Neels Hofmeyr7d17c3e2017-01-26 23:04:28 +01001281 retries -= 1
Max49364482016-04-13 11:36:39 +02001282 else:
1283 if (verbose):
1284 print "\tBSC <- NAT: ", s
1285
1286def nat_bsc_num_con(x):
1287 return len(x.vty.command("show bsc connections").split('\n'))
1288
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001289def nat_bsc_sock_test(nr, tk, verbose = False, proc=None):
Max49364482016-04-13 11:36:39 +02001290 bsc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Holger Hans Peter Freyther2abf2b02016-04-14 21:13:51 -04001291 bsc.bind(('127.0.0.1', 0))
Max49364482016-04-13 11:36:39 +02001292 bsc.connect(('127.0.0.1', 5000))
1293 if (verbose):
1294 print "BSC%d " %nr
1295 print "\tconnected to %s:%d" % bsc.getpeername()
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001296 if proc:
1297 print "\tproc.poll() = %r" % proc.poll()
1298 print "\tproc.pid = %r" % proc.pid
Max49364482016-04-13 11:36:39 +02001299 ipa_handle_small(bsc, verbose)
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001300 ipa_handle_resp(bsc, tk, verbose, proc=proc)
1301 if proc:
1302 print "\tproc.poll() = %r" % proc.poll()
Max49364482016-04-13 11:36:39 +02001303 bsc.recv(27) # MGCP msg
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001304 if proc:
1305 print "\tproc.poll() = %r" % proc.poll()
Max49364482016-04-13 11:36:39 +02001306 ipa_handle_small(bsc, verbose)
1307 return bsc
1308
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001309def add_bsc_test(suite, workdir):
1310 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")):
1311 print("Skipping the BSC test")
1312 return
1313 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC)
1314 suite.addTest(test)
1315
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001316def add_gbproxy_test(suite, workdir):
1317 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-gbproxy")):
1318 print("Skipping the Gb-Proxy test")
1319 return
1320 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYGbproxy)
1321 suite.addTest(test)
1322
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001323def add_sgsn_test(suite, workdir):
1324 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-sgsn")):
1325 print("Skipping the SGSN test")
1326 return
1327 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYSGSN)
1328 suite.addTest(test)
1329
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001330if __name__ == '__main__':
1331 import argparse
1332 import sys
1333
1334 workdir = '.'
1335
1336 parser = argparse.ArgumentParser()
1337 parser.add_argument("-v", "--verbose", dest="verbose",
1338 action="store_true", help="verbose mode")
1339 parser.add_argument("-p", "--pythonconfpath", dest="p",
1340 help="searchpath for config")
1341 parser.add_argument("-w", "--workdir", dest="w",
1342 help="Working directory")
1343 args = parser.parse_args()
1344
1345 verbose_level = 1
1346 if args.verbose:
1347 verbose_level = 2
1348
1349 if args.w:
1350 workdir = args.w
1351
1352 if args.p:
1353 confpath = args.p
1354
1355 print "confpath %s, workdir %s" % (confpath, workdir)
1356 os.chdir(workdir)
1357 print "Running tests for specific VTY commands"
1358 suite = unittest.TestSuite()
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +02001359 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYMGCP))
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +02001360 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB))
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001361 add_bsc_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001362 add_nat_test(suite, workdir)
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001363 add_gbproxy_test(suite, workdir)
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001364 add_sgsn_test(suite, workdir)
Neels Hofmeyr0a45c1e2016-09-28 23:48:02 +02001365 res = unittest.TextTestRunner(verbosity=verbose_level, stream=sys.stdout).run(suite)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001366 sys.exit(len(res.errors) + len(res.failures))
Neels Hofmeyr23d37c92016-09-26 03:18:32 +02001367
Neels Hofmeyr0867b722016-09-28 23:28:06 +02001368# vim: shiftwidth=4 expandtab nocin ai