blob: 3f4909cb5e11e10621550d6f4575a460acee515d [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 Hofmeyr0b619322017-02-28 02:37:39 +0100786 msc_socket, msc = nat_msc_test(self, ip, port, verbose=True)
787 try:
788 b0 = nat_bsc_sock_test(0, "lol", verbose=True, proc=self.proc)
789 b1 = nat_bsc_sock_test(1, "xyu", verbose=True, proc=self.proc)
790 b2 = nat_bsc_sock_test(5, "key", verbose=True, proc=self.proc)
Max49364482016-04-13 11:36:39 +0200791
Neels Hofmeyr0b619322017-02-28 02:37:39 +0100792 self.assertEquals("3 BSCs configured", self.vty.command("show nat num-bscs-configured"))
793 self.assertTrue(3 == nat_bsc_num_con(self))
794 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
Max49364482016-04-13 11:36:39 +0200795
Neels Hofmeyr0b619322017-02-28 02:37:39 +0100796 nat_bsc_reload(self)
797 bscs2 = self.vty.command("show bscs-config")
798 # check that the reset to initial config succeeded
799 self.assertEquals(bscs1, bscs2)
Max49364482016-04-13 11:36:39 +0200800
Neels Hofmeyr0b619322017-02-28 02:37:39 +0100801 self.assertEquals("2 BSCs configured", self.vty.command("show nat num-bscs-configured"))
802 self.assertTrue(1 == nat_bsc_num_con(self))
803 rem = self.vty.command("show bsc connections").split(' ')
804 # remaining connection is for BSC0
805 self.assertEquals('0', rem[2])
806 # remaining connection is authorized
807 self.assertEquals('1', rem[4])
808 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
809 finally:
810 msc.close()
811 msc_socket.close()
Max49364482016-04-13 11:36:39 +0200812
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200813 def testVtyTree(self):
814 self.vty.enable()
815 self.assertTrue(self.vty.verify('configure terminal', ['']))
816 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100817 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200818 self.assertTrue(self.vty.verify('mgcp', ['']))
819 self.assertEquals(self.vty.node(), 'config-mgcp')
820 self.checkForEndAndExit()
821 self.assertTrue(self.vty.verify('exit', ['']))
822 self.assertEquals(self.vty.node(), 'config')
823 self.assertTrue(self.vty.verify('nat', ['']))
824 self.assertEquals(self.vty.node(), 'config-nat')
825 self.checkForEndAndExit()
826 self.assertTrue(self.vty.verify('bsc 0', ['']))
827 self.assertEquals(self.vty.node(), 'config-nat-bsc')
828 self.checkForEndAndExit()
829 self.assertTrue(self.vty.verify('exit', ['']))
830 self.assertEquals(self.vty.node(), 'config-nat')
831 self.assertTrue(self.vty.verify('exit', ['']))
832 self.assertEquals(self.vty.node(), 'config')
833 self.assertTrue(self.vty.verify('exit', ['']))
834 self.assertTrue(self.vty.node() is None)
835
836 # Check searching for outer node's commands
837 self.vty.command('configure terminal')
838 self.vty.command('mgcp')
839 self.vty.command('nat')
840 self.assertEquals(self.vty.node(), 'config-nat')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200841 self.vty.command('mgcp')
842 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200843 self.vty.command('nat')
844 self.assertEquals(self.vty.node(), 'config-nat')
845 self.vty.command('bsc 0')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200846 self.vty.command('mgcp')
847 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200848
Holger Hans Peter Freytherb718ad32013-06-25 09:08:02 +0200849 def testRewriteNoRewrite(self):
850 self.vty.enable()
851 res = self.vty.command("configure terminal")
852 res = self.vty.command("nat")
853 res = self.vty.command("number-rewrite rewrite.cfg")
854 res = self.vty.command("no number-rewrite")
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200855
Holger Hans Peter Freyther7f100c92015-04-23 20:25:17 -0400856 def testEnsureNoEnsureModeSet(self):
857 self.vty.enable()
858 res = self.vty.command("configure terminal")
859 res = self.vty.command("nat")
860
861 # Ensure the default
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("sdp-ensure-amr-mode-set")
866 res = self.vty.command("show running-config")
867 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
868
869 self.vty.command("no sdp-ensure-amr-mode-set")
870 res = self.vty.command("show running-config")
871 self.assert_(res.find('\n no sdp-ensure-amr-mode-set') > 0)
872
Holger Hans Peter Freyther67e423c2013-06-25 15:38:31 +0200873 def testRewritePostNoRewrite(self):
874 self.vty.enable()
875 self.vty.command("configure terminal")
876 self.vty.command("nat")
877 self.vty.verify("number-rewrite-post rewrite.cfg", [''])
878 self.vty.verify("no number-rewrite-post", [''])
879
880
Holger Hans Peter Freytherddf191e2013-06-25 11:44:01 +0200881 def testPrefixTreeLoading(self):
882 cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv")
883
884 self.vty.enable()
885 self.vty.command("configure terminal")
886 self.vty.command("nat")
887 res = self.vty.command("prefix-tree %s" % cfg)
888 self.assertEqual(res, "% prefix-tree loaded 17 rules.")
889 self.vty.command("end")
890
891 res = self.vty.command("show prefix-tree")
892 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')
893
894 self.vty.command("configure terminal")
895 self.vty.command("nat")
896 self.vty.command("no prefix-tree")
897 self.vty.command("end")
898
899 res = self.vty.command("show prefix-tree")
900 self.assertEqual(res, "% there is now prefix tree loaded.")
901
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200902 def testUssdSideChannelProvider(self):
903 self.vty.command("end")
904 self.vty.enable()
905 self.vty.command("configure terminal")
906 self.vty.command("nat")
907 self.vty.command("ussd-token key")
908 self.vty.command("end")
909
910 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
911 self.assertTrue(res)
912
913 ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
914 ussdSocket.connect(('127.0.0.1', 5001))
915 ussdSocket.settimeout(2.0)
916 print "Connected to %s:%d" % ussdSocket.getpeername()
917
918 print "Expecting ID_GET request"
919 data = ussdSocket.recv(4)
920 self.assertEqual(data, "\x00\x01\xfe\x04")
921
922 print "Going to send ID_RESP response"
Max3e676892016-11-16 14:55:21 +0100923 res = ussdSocket.send(IPA().id_resp(IPA().tag_name('key')))
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200924 self.assertEqual(res, 10)
925
926 # initiating PING/PONG cycle to know, that the ID_RESP message has been processed
927
928 print "Going to send PING request"
Max3e676892016-11-16 14:55:21 +0100929 res = ussdSocket.send(IPA().ping())
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200930 self.assertEqual(res, 4)
931
932 print "Expecting PONG response"
933 data = ussdSocket.recv(4)
934 self.assertEqual(data, "\x00\x01\xfe\x01")
935
936 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.'])
937 self.assertTrue(res)
938
939 print "Going to shut down connection"
940 ussdSocket.shutdown(socket.SHUT_WR)
941
942 print "Expecting EOF"
943 data = ussdSocket.recv(4)
944 self.assertEqual(data, "")
945
946 ussdSocket.close()
947
948 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
949 self.assertTrue(res)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200950
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100951 def testAccessList(self):
952 """
953 Verify that the imsi-deny can have a reject cause or no reject cause
954 """
955 self.vty.enable()
956 self.vty.command("configure terminal")
957 self.vty.command("nat")
958
959 # Old default
960 self.vty.command("access-list test-default imsi-deny ^123[0-9]*$")
961 res = self.vty.command("show running-config").split("\r\n")
962 asserted = False
963 for line in res:
Holger Hans Peter Freyther4ecc6872014-03-04 15:38:00 +0100964 if line.startswith(" access-list test-default"):
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100965 self.assertEqual(line, " access-list test-default imsi-deny ^123[0-9]*$ 11 11")
966 asserted = True
967 self.assert_(asserted)
968
969 # Check the optional CM Service Reject Cause
970 self.vty.command("access-list test-cm-deny imsi-deny ^123[0-9]*$ 42").split("\r\n")
971 res = self.vty.command("show running-config").split("\r\n")
972 asserted = False
973 for line in res:
974 if line.startswith(" access-list test-cm"):
975 self.assertEqual(line, " access-list test-cm-deny imsi-deny ^123[0-9]*$ 42 11")
976 asserted = True
977 self.assert_(asserted)
978
979 # Check the optional LU Reject Cause
980 self.vty.command("access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42").split("\r\n")
981 res = self.vty.command("show running-config").split("\r\n")
982 asserted = False
983 for line in res:
984 if line.startswith(" access-list test-lu"):
985 self.assertEqual(line, " access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42")
986 asserted = True
987 self.assert_(asserted)
988
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200989class TestVTYGbproxy(TestVTYGenericBSC):
990
991 def vty_command(self):
992 return ["./src/gprs/osmo-gbproxy", "-c",
993 "doc/examples/osmo-gbproxy/osmo-gbproxy.cfg"]
994
995 def vty_app(self):
996 return (4246, "./src/gprs/osmo-gbproxy", "OsmoGbProxy", "bsc")
997
998 def testVtyTree(self):
999 self.vty.enable()
1000 self.assertTrue(self.vty.verify('configure terminal', ['']))
1001 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +01001002 self.checkForEndAndExit()
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001003 self.assertTrue(self.vty.verify('ns', ['']))
1004 self.assertEquals(self.vty.node(), 'config-ns')
1005 self.checkForEndAndExit()
1006 self.assertTrue(self.vty.verify('exit', ['']))
1007 self.assertEquals(self.vty.node(), 'config')
1008 self.assertTrue(self.vty.verify('gbproxy', ['']))
1009 self.assertEquals(self.vty.node(), 'config-gbproxy')
1010 self.checkForEndAndExit()
1011 self.assertTrue(self.vty.verify('exit', ['']))
1012 self.assertEquals(self.vty.node(), 'config')
1013
1014 def testVtyShow(self):
1015 res = self.vty.command("show ns")
1016 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
1017
1018 res = self.vty.command("show gbproxy stats")
1019 self.assert_(res.find('GBProxy Global Statistics') >= 0)
1020
Jacob Erlbeck4211d792013-10-24 12:48:23 +02001021 def testVtyDeletePeer(self):
1022 self.vty.enable()
1023 self.assertTrue(self.vty.verify('delete-gbproxy-peer 9999 bvci 7777', ['BVC not found']))
1024 res = self.vty.command("delete-gbproxy-peer 9999 all 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 only-bvc dry-run")
1028 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
1029 self.assert_(res.find('Not Deleted 0 NS-VC') < 0)
1030 res = self.vty.command("delete-gbproxy-peer 9999 only-nsvc dry-run")
1031 self.assert_(res.find('Not Deleted 0 BVC') < 0)
1032 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
1033 res = self.vty.command("delete-gbproxy-peer 9999 all")
1034 self.assert_(res.find('Deleted 0 BVC') >= 0)
1035 self.assert_(res.find('Deleted 0 NS-VC') >= 0)
1036
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001037class TestVTYSGSN(TestVTYGenericBSC):
1038
1039 def vty_command(self):
1040 return ["./src/gprs/osmo-sgsn", "-c",
1041 "doc/examples/osmo-sgsn/osmo-sgsn.cfg"]
1042
1043 def vty_app(self):
1044 return (4245, "./src/gprs/osmo-sgsn", "OsmoSGSN", "sgsn")
1045
1046 def testVtyTree(self):
1047 self.vty.enable()
1048 self.assertTrue(self.vty.verify('configure terminal', ['']))
1049 self.assertEquals(self.vty.node(), 'config')
1050 self.checkForEndAndExit()
1051 self.assertTrue(self.vty.verify('ns', ['']))
1052 self.assertEquals(self.vty.node(), 'config-ns')
1053 self.checkForEndAndExit()
1054 self.assertTrue(self.vty.verify('exit', ['']))
1055 self.assertEquals(self.vty.node(), 'config')
1056 self.assertTrue(self.vty.verify('sgsn', ['']))
1057 self.assertEquals(self.vty.node(), 'config-sgsn')
1058 self.checkForEndAndExit()
1059 self.assertTrue(self.vty.verify('exit', ['']))
1060 self.assertEquals(self.vty.node(), 'config')
1061
1062 def testVtyShow(self):
1063 res = self.vty.command("show ns")
1064 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
1065 self.assertTrue(self.vty.verify('show bssgp', ['']))
1066 self.assertTrue(self.vty.verify('show bssgp stats', ['']))
1067 # TODO: uncomment when the command does not segfault anymore
1068 # self.assertTrue(self.vty.verify('show bssgp nsei 123', ['']))
1069 # self.assertTrue(self.vty.verify('show bssgp nsei 123 stats', ['']))
1070
1071 self.assertTrue(self.vty.verify('show sgsn', ['']))
1072 self.assertTrue(self.vty.verify('show mm-context all', ['']))
1073 self.assertTrue(self.vty.verify('show mm-context imsi 000001234567', ['No MM context for IMSI 000001234567']))
1074 self.assertTrue(self.vty.verify('show pdp-context all', ['']))
1075
1076 res = self.vty.command("show sndcp")
1077 self.assert_(res.find('State of SNDCP Entities') >= 0)
1078
1079 res = self.vty.command("show llc")
1080 self.assert_(res.find('State of LLC Entities') >= 0)
1081
Jacob Erlbeck106f5472014-11-04 10:08:37 +01001082 def testVtyAuth(self):
1083 self.vty.enable()
1084 self.assertTrue(self.vty.verify('configure terminal', ['']))
1085 self.assertEquals(self.vty.node(), 'config')
1086 self.assertTrue(self.vty.verify('sgsn', ['']))
1087 self.assertEquals(self.vty.node(), 'config-sgsn')
1088 self.assertTrue(self.vty.verify('auth-policy accept-all', ['']))
1089 res = self.vty.command("show running-config")
1090 self.assert_(res.find('auth-policy accept-all') > 0)
1091 self.assertTrue(self.vty.verify('auth-policy acl-only', ['']))
1092 res = self.vty.command("show running-config")
1093 self.assert_(res.find('auth-policy acl-only') > 0)
1094 self.assertTrue(self.vty.verify('auth-policy closed', ['']))
1095 res = self.vty.command("show running-config")
1096 self.assert_(res.find('auth-policy closed') > 0)
Max176b62a2016-07-04 11:09:07 +02001097 self.assertTrue(self.vty.verify('gsup remote-ip 127.0.0.4', ['']))
1098 self.assertTrue(self.vty.verify('gsup remote-port 2222', ['']))
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +01001099 self.assertTrue(self.vty.verify('auth-policy remote', ['']))
1100 res = self.vty.command("show running-config")
1101 self.assert_(res.find('auth-policy remote') > 0)
Jacob Erlbeck106f5472014-11-04 10:08:37 +01001102
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001103 def testVtySubscriber(self):
1104 self.vty.enable()
1105 res = self.vty.command('show subscriber cache')
1106 self.assert_(res.find('1234567890') < 0)
Jacob Erlbeckd9193432015-01-19 14:11:46 +01001107 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 create', ['']))
1108 res = self.vty.command('show subscriber cache')
1109 self.assert_(res.find('1234567890') >= 0)
1110 self.assert_(res.find('Authorized: 0') >= 0)
1111 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 update-location-result ok', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001112 res = self.vty.command('show subscriber cache')
1113 self.assert_(res.find('1234567890') >= 0)
1114 self.assert_(res.find('Authorized: 1') >= 0)
Jacob Erlbeck8000e0e2015-01-27 14:56:40 +01001115 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 cancel update-procedure', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001116 res = self.vty.command('show subscriber cache')
Jacob Erlbecke988ae42015-01-27 12:41:19 +01001117 self.assert_(res.find('1234567890') >= 0)
1118 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 destroy', ['']))
1119 res = self.vty.command('show subscriber cache')
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001120 self.assert_(res.find('1234567890') < 0)
1121
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +01001122 def testVtyGgsn(self):
1123 self.vty.enable()
1124 self.assertTrue(self.vty.verify('configure terminal', ['']))
1125 self.assertEquals(self.vty.node(), 'config')
1126 self.assertTrue(self.vty.verify('sgsn', ['']))
1127 self.assertEquals(self.vty.node(), 'config-sgsn')
1128 self.assertTrue(self.vty.verify('ggsn 0 remote-ip 127.99.99.99', ['']))
1129 self.assertTrue(self.vty.verify('ggsn 0 gtp-version 1', ['']))
1130 self.assertTrue(self.vty.verify('apn * ggsn 0', ['']))
1131 self.assertTrue(self.vty.verify('apn apn1.test ggsn 0', ['']))
1132 self.assertTrue(self.vty.verify('apn apn1.test ggsn 1', ['% a GGSN with id 1 has not been defined']))
1133 self.assertTrue(self.vty.verify('apn apn1.test imsi-prefix 123456 ggsn 0', ['']))
1134 self.assertTrue(self.vty.verify('apn apn2.test imsi-prefix 123456 ggsn 0', ['']))
1135 res = self.vty.command("show running-config")
1136 self.assert_(res.find('ggsn 0 remote-ip 127.99.99.99') >= 0)
1137 self.assert_(res.find('ggsn 0 gtp-version 1') >= 0)
1138 self.assert_(res.find('apn * ggsn 0') >= 0)
1139 self.assert_(res.find('apn apn1.test ggsn 0') >= 0)
1140 self.assert_(res.find('apn apn1.test imsi-prefix 123456 ggsn 0') >= 0)
1141 self.assert_(res.find('apn apn2.test imsi-prefix 123456 ggsn 0') >= 0)
1142
Holger Hans Peter Freyther9c20a5f2015-02-06 16:23:29 +01001143 def testVtyEasyAPN(self):
1144 self.vty.enable()
1145 self.assertTrue(self.vty.verify('configure terminal', ['']))
1146 self.assertEquals(self.vty.node(), 'config')
1147 self.assertTrue(self.vty.verify('sgsn', ['']))
1148 self.assertEquals(self.vty.node(), 'config-sgsn')
1149
1150 res = self.vty.command("show running-config")
1151 self.assertEquals(res.find("apn internet"), -1)
1152
1153 self.assertTrue(self.vty.verify("access-point-name internet.apn", ['']))
1154 res = self.vty.command("show running-config")
1155 self.assert_(res.find("apn internet.apn ggsn 0") >= 0)
1156
1157 self.assertTrue(self.vty.verify("no access-point-name internet.apn", ['']))
1158 res = self.vty.command("show running-config")
1159 self.assertEquals(res.find("apn internet"), -1)
1160
Holger Hans Peter Freytherc15c61c2015-05-06 17:46:08 +02001161 def testVtyCDR(self):
1162 self.vty.enable()
1163 self.assertTrue(self.vty.verify('configure terminal', ['']))
1164 self.assertEquals(self.vty.node(), 'config')
1165 self.assertTrue(self.vty.verify('sgsn', ['']))
1166 self.assertEquals(self.vty.node(), 'config-sgsn')
1167
1168 res = self.vty.command("show running-config")
1169 self.assert_(res.find("no cdr filename") > 0)
1170
1171 self.vty.command("cdr filename bla.cdr")
1172 res = self.vty.command("show running-config")
1173 self.assertEquals(res.find("no cdr filename"), -1)
1174 self.assert_(res.find(" cdr filename bla.cdr") > 0)
1175
1176 self.vty.command("no cdr filename")
1177 res = self.vty.command("show running-config")
1178 self.assert_(res.find("no cdr filename") > 0)
1179 self.assertEquals(res.find(" cdr filename bla.cdr"), -1)
1180
1181 res = self.vty.command("show running-config")
1182 self.assert_(res.find(" cdr interval 600") > 0)
1183
1184 self.vty.command("cdr interval 900")
1185 res = self.vty.command("show running-config")
1186 self.assert_(res.find(" cdr interval 900") > 0)
1187 self.assertEquals(res.find(" cdr interval 600"), -1)
1188
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001189def add_nat_test(suite, workdir):
1190 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
1191 print("Skipping the NAT test")
1192 return
1193 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT)
1194 suite.addTest(test)
1195
Max49364482016-04-13 11:36:39 +02001196def nat_bsc_reload(x):
1197 x.vty.command("configure terminal")
1198 x.vty.command("nat")
1199 x.vty.command("bscs-config-file bscs.config")
1200 x.vty.command("end")
1201
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001202def nat_msc_ip(x, ip, port):
Max49364482016-04-13 11:36:39 +02001203 x.vty.command("configure terminal")
1204 x.vty.command("nat")
1205 x.vty.command("msc ip " + ip)
Holger Hans Peter Freyther84ae27e2016-04-14 10:40:06 -04001206 x.vty.command("msc port " + str(port))
Max49364482016-04-13 11:36:39 +02001207 x.vty.command("end")
1208
1209def data2str(d):
Holger Hans Peter Freyther8bb62042016-04-14 21:40:04 -04001210 return d.encode('hex').lower()
Max49364482016-04-13 11:36:39 +02001211
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001212def nat_msc_test(x, ip, port, verbose = False):
Max49364482016-04-13 11:36:39 +02001213 msc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Neels Hofmeyr53403452017-02-28 02:38:43 +01001214 msc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
Neels Hofmeyrcaeb62d2016-09-28 23:38:45 +02001215 msc.settimeout(5)
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001216 msc.bind((ip, port))
Max49364482016-04-13 11:36:39 +02001217 msc.listen(5)
1218 if (verbose):
1219 print "MSC is ready at " + ip
Neels Hofmeyr89d20b62016-09-26 12:59:36 +02001220 conn = None
Neels Hofmeyrcaeb62d2016-09-28 23:38:45 +02001221 while True:
1222 vty_response = x.vty.command("show msc connection")
1223 print "'show msc connection' says: %r" % vty_response
1224 if vty_response == "MSC is connected: 1":
1225 # success
1226 break;
1227 if vty_response != "MSC is connected: 0":
1228 raise Exception("Unexpected response to 'show msc connection'"
1229 " vty command: %r" % vty_response)
1230
1231 timeout_retries = 6
1232 while timeout_retries > 0:
1233 try:
1234 conn, addr = msc.accept()
1235 print "MSC got connection from ", addr
1236 break
1237 except socket.timeout:
1238 print "socket timed out."
1239 timeout_retries -= 1
1240 continue
1241
Neels Hofmeyr89d20b62016-09-26 12:59:36 +02001242 if not conn:
Neels Hofmeyr0867b722016-09-28 23:28:06 +02001243 raise Exception("VTY reports MSC is connected, but I haven't"
1244 " connected yet: %r %r" % (ip, port))
Neels Hofmeyr0b619322017-02-28 02:37:39 +01001245 return msc, conn
Max49364482016-04-13 11:36:39 +02001246
1247def ipa_handle_small(x, verbose = False):
1248 s = data2str(x.recv(4))
Neels Hofmeyrba1468e2017-02-03 04:23:46 +01001249 if len(s) != 4*2:
1250 raise Exception("expected to receive 4 bytes, but got %d (%r)" % (len(s)/2, s))
Max49364482016-04-13 11:36:39 +02001251 if "0001fe00" == s:
1252 if (verbose):
1253 print "\tBSC <- NAT: PING?"
Max3e676892016-11-16 14:55:21 +01001254 x.send(IPA().pong())
Max49364482016-04-13 11:36:39 +02001255 elif "0001fe06" == s:
1256 if (verbose):
1257 print "\tBSC <- NAT: IPA ID ACK"
Max3e676892016-11-16 14:55:21 +01001258 x.send(IPA().id_ack())
Max49364482016-04-13 11:36:39 +02001259 elif "0001fe00" == s:
1260 if (verbose):
1261 print "\tBSC <- NAT: PONG!"
1262 else:
1263 if (verbose):
1264 print "\tBSC <- NAT: ", s
1265
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001266def ipa_handle_resp(x, tk, verbose = False, proc=None):
Max49364482016-04-13 11:36:39 +02001267 s = data2str(x.recv(38))
1268 if "0023fe040108010701020103010401050101010011" in s:
Neels Hofmeyr7d17c3e2017-01-26 23:04:28 +01001269 retries = 3
1270 while True:
1271 print "\tsending IPA identity(%s) at %s" % (tk, time.strftime("%T"))
1272 try:
1273 x.send(IPA().id_resp(IPA().identity(name = tk.encode('utf-8'))))
1274 print "\tdone sending IPA identity(%s) at %s" % (tk,
1275 time.strftime("%T"))
1276 break
1277 except:
1278 print "\tfailed sending IPA identity at", time.strftime("%T")
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001279 if proc:
1280 print "\tproc.poll() = %r" % proc.poll()
Neels Hofmeyr7d17c3e2017-01-26 23:04:28 +01001281 if retries < 1:
1282 print "\tgiving up"
1283 raise
Neels Hofmeyre02e1e72017-02-03 05:55:26 +01001284 print "\tretrying (%d attempts left)" % retries
Neels Hofmeyr7d17c3e2017-01-26 23:04:28 +01001285 retries -= 1
Max49364482016-04-13 11:36:39 +02001286 else:
1287 if (verbose):
1288 print "\tBSC <- NAT: ", s
1289
1290def nat_bsc_num_con(x):
1291 return len(x.vty.command("show bsc connections").split('\n'))
1292
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001293def nat_bsc_sock_test(nr, tk, verbose = False, proc=None):
Max49364482016-04-13 11:36:39 +02001294 bsc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Holger Hans Peter Freyther2abf2b02016-04-14 21:13:51 -04001295 bsc.bind(('127.0.0.1', 0))
Max49364482016-04-13 11:36:39 +02001296 bsc.connect(('127.0.0.1', 5000))
1297 if (verbose):
1298 print "BSC%d " %nr
1299 print "\tconnected to %s:%d" % bsc.getpeername()
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001300 if proc:
1301 print "\tproc.poll() = %r" % proc.poll()
1302 print "\tproc.pid = %r" % proc.pid
Max49364482016-04-13 11:36:39 +02001303 ipa_handle_small(bsc, verbose)
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001304 ipa_handle_resp(bsc, tk, verbose, proc=proc)
1305 if proc:
1306 print "\tproc.poll() = %r" % proc.poll()
Max49364482016-04-13 11:36:39 +02001307 bsc.recv(27) # MGCP msg
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001308 if proc:
1309 print "\tproc.poll() = %r" % proc.poll()
Max49364482016-04-13 11:36:39 +02001310 ipa_handle_small(bsc, verbose)
1311 return bsc
1312
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001313def add_bsc_test(suite, workdir):
1314 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")):
1315 print("Skipping the BSC test")
1316 return
1317 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC)
1318 suite.addTest(test)
1319
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001320def add_gbproxy_test(suite, workdir):
1321 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-gbproxy")):
1322 print("Skipping the Gb-Proxy test")
1323 return
1324 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYGbproxy)
1325 suite.addTest(test)
1326
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001327def add_sgsn_test(suite, workdir):
1328 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-sgsn")):
1329 print("Skipping the SGSN test")
1330 return
1331 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYSGSN)
1332 suite.addTest(test)
1333
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001334if __name__ == '__main__':
1335 import argparse
1336 import sys
1337
1338 workdir = '.'
1339
1340 parser = argparse.ArgumentParser()
1341 parser.add_argument("-v", "--verbose", dest="verbose",
1342 action="store_true", help="verbose mode")
1343 parser.add_argument("-p", "--pythonconfpath", dest="p",
1344 help="searchpath for config")
1345 parser.add_argument("-w", "--workdir", dest="w",
1346 help="Working directory")
Neels Hofmeyr3f8a8f72017-02-28 02:43:29 +01001347 parser.add_argument("test_name", nargs="*", help="(parts of) test names to run, case-insensitive")
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001348 args = parser.parse_args()
1349
1350 verbose_level = 1
1351 if args.verbose:
1352 verbose_level = 2
1353
1354 if args.w:
1355 workdir = args.w
1356
1357 if args.p:
1358 confpath = args.p
1359
1360 print "confpath %s, workdir %s" % (confpath, workdir)
1361 os.chdir(workdir)
1362 print "Running tests for specific VTY commands"
1363 suite = unittest.TestSuite()
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +02001364 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYMGCP))
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +02001365 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB))
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001366 add_bsc_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001367 add_nat_test(suite, workdir)
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001368 add_gbproxy_test(suite, workdir)
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001369 add_sgsn_test(suite, workdir)
Neels Hofmeyr3f8a8f72017-02-28 02:43:29 +01001370
1371 if args.test_name:
1372 osmoutil.pick_tests(suite, *args.test_name)
1373
Neels Hofmeyr0a45c1e2016-09-28 23:48:02 +02001374 res = unittest.TextTestRunner(verbosity=verbose_level, stream=sys.stdout).run(suite)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001375 sys.exit(len(res.errors) + len(res.failures))
Neels Hofmeyr23d37c92016-09-26 03:18:32 +02001376
Neels Hofmeyr0867b722016-09-28 23:28:06 +02001377# vim: shiftwidth=4 expandtab nocin ai