blob: 8b173977cda45c8bd6f1d3f9e1314406dddc8d4c [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:
48 print "Launch: %s from %s" % (' '.join(osmo_vty_cmd), os.getcwd())
49 self.proc = osmoutil.popen_devnull(osmo_vty_cmd)
50 except OSError:
51 print >> sys.stderr, "Current directory: %s" % os.getcwd()
52 print >> sys.stderr, "Consider setting -b"
53 time.sleep(1)
54
55 appstring = self.vty_app()[2]
56 appport = self.vty_app()[0]
57 self.vty = obscvty.VTYInteract(appstring, "127.0.0.1", appport)
58
59 def tearDown(self):
Neels Hofmeyr40a91b32017-02-24 17:54:22 +010060 if self.vty:
61 self.vty._close_socket()
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +020062 self.vty = None
63 osmoutil.end_proc(self.proc)
64
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +020065class TestVTYMGCP(TestVTYBase):
66 def vty_command(self):
67 return ["./src/osmo-bsc_mgcp/osmo-bsc_mgcp", "-c",
68 "doc/examples/osmo-bsc_mgcp/mgcp.cfg"]
69
70 def vty_app(self):
71 return (4243, "./src/osmo-bsc_mgcp/osmo-bsc_mgcp", "OpenBSC MGCP", "mgcp")
72
73 def testForcePtime(self):
Neels Hofmeyr0867b722016-09-28 23:28:06 +020074 self.vty.enable()
75 res = self.vty.command("show running-config")
76 self.assert_(res.find(' rtp force-ptime 20\r') > 0)
77 self.assertEquals(res.find(' no rtp force-ptime\r'), -1)
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +020078
Neels Hofmeyr0867b722016-09-28 23:28:06 +020079 self.vty.command("configure terminal")
80 self.vty.command("mgcp")
81 self.vty.command("no rtp force-ptime")
82 res = self.vty.command("show running-config")
83 self.assertEquals(res.find(' rtp force-ptime 20\r'), -1)
84 self.assertEquals(res.find(' no rtp force-ptime\r'), -1)
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +020085
Holger Hans Peter Freyther619b0142014-11-19 16:04:45 +010086 def testOmitAudio(self):
87 self.vty.enable()
Neels Hofmeyr0867b722016-09-28 23:28:06 +020088 res = self.vty.command("show running-config")
89 self.assert_(res.find(' sdp audio-payload send-name\r') > 0)
90 self.assertEquals(res.find(' no sdp audio-payload send-name\r'), -1)
Holger Hans Peter Freyther619b0142014-11-19 16:04:45 +010091
Neels Hofmeyr0867b722016-09-28 23:28:06 +020092 self.vty.command("configure terminal")
93 self.vty.command("mgcp")
94 self.vty.command("no sdp audio-payload send-name")
95 res = self.vty.command("show running-config")
96 self.assertEquals(res.find(' rtp sdp audio-payload send-name\r'), -1)
97 self.assert_(res.find(' no sdp audio-payload send-name\r') > 0)
Holger Hans Peter Freyther619b0142014-11-19 16:04:45 +010098
99 # TODO: test it for the trunk!
100
Holger Hans Peter Freytherc390ae82015-08-20 15:15:50 +0200101 def testBindAddr(self):
102 self.vty.enable()
103
Neels Hofmeyr0867b722016-09-28 23:28:06 +0200104 self.vty.command("configure terminal")
105 self.vty.command("mgcp")
Holger Hans Peter Freytherc390ae82015-08-20 15:15:50 +0200106
107 # enable.. disable bts-bind-ip
108 self.vty.command("rtp bts-bind-ip 254.253.252.250")
109 res = self.vty.command("show running-config")
110 self.assert_(res.find('rtp bts-bind-ip 254.253.252.250') > 0)
111 self.vty.command("no rtp bts-bind-ip")
112 res = self.vty.command("show running-config")
113 self.assertEquals(res.find(' rtp bts-bind-ip'), -1)
114
115 # enable.. disable net-bind-ip
116 self.vty.command("rtp net-bind-ip 254.253.252.250")
117 res = self.vty.command("show running-config")
118 self.assert_(res.find('rtp net-bind-ip 254.253.252.250') > 0)
119 self.vty.command("no rtp net-bind-ip")
120 res = self.vty.command("show running-config")
121 self.assertEquals(res.find(' rtp net-bind-ip'), -1)
122
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200123
124class TestVTYGenericBSC(TestVTYBase):
125
126 def checkForEndAndExit(self):
127 res = self.vty.command("list")
128 #print ('looking for "exit"\n')
129 self.assert_(res.find(' exit\r') > 0)
130 #print 'found "exit"\nlooking for "end"\n'
131 self.assert_(res.find(' end\r') > 0)
132 #print 'found "end"\n'
133
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200134 def _testConfigNetworkTree(self):
135 self.vty.enable()
136 self.assertTrue(self.vty.verify("configure terminal",['']))
137 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100138 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200139 self.assertTrue(self.vty.verify("network",['']))
140 self.assertEquals(self.vty.node(), 'config-net')
141 self.checkForEndAndExit()
142 self.assertTrue(self.vty.verify("bts 0",['']))
143 self.assertEquals(self.vty.node(), 'config-net-bts')
144 self.checkForEndAndExit()
145 self.assertTrue(self.vty.verify("trx 0",['']))
146 self.assertEquals(self.vty.node(), 'config-net-bts-trx')
147 self.checkForEndAndExit()
Jacob Erlbeck733bec82013-09-11 10:46:56 +0200148 self.vty.command("write terminal")
149 self.assertTrue(self.vty.verify("exit",['']))
150 self.assertEquals(self.vty.node(), 'config-net-bts')
151 self.assertTrue(self.vty.verify("exit",['']))
152 self.assertTrue(self.vty.verify("bts 1",['']))
153 self.assertEquals(self.vty.node(), 'config-net-bts')
154 self.checkForEndAndExit()
155 self.assertTrue(self.vty.verify("trx 1",['']))
156 self.assertEquals(self.vty.node(), 'config-net-bts-trx')
157 self.checkForEndAndExit()
158 self.vty.command("write terminal")
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200159 self.assertTrue(self.vty.verify("exit",['']))
160 self.assertEquals(self.vty.node(), 'config-net-bts')
161 self.assertTrue(self.vty.verify("exit",['']))
162 self.assertEquals(self.vty.node(), 'config-net')
163 self.assertTrue(self.vty.verify("exit",['']))
164 self.assertEquals(self.vty.node(), 'config')
165 self.assertTrue(self.vty.verify("exit",['']))
166 self.assertTrue(self.vty.node() is None)
167
168class TestVTYNITB(TestVTYGenericBSC):
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200169
170 def vty_command(self):
171 return ["./src/osmo-nitb/osmo-nitb", "-c",
172 "doc/examples/osmo-nitb/nanobts/openbsc.cfg"]
173
174 def vty_app(self):
175 return (4242, "./src/osmo-nitb/osmo-nitb", "OpenBSC", "nitb")
176
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200177 def testConfigNetworkTree(self):
Jacob Erlbeck75877272013-10-23 11:24:14 +0200178 self._testConfigNetworkTree()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200179
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200180 def checkForSmpp(self):
181 """SMPP is not always enabled, check if it is"""
182 res = self.vty.command("list")
183 return "smpp" in res
184
Holger Hans Peter Freyther42cf2e02015-07-06 16:41:30 +0200185 def testSmppFirst(self):
Holger Hans Peter Freyther42cf2e02015-07-06 16:41:30 +0200186 # enable the configuration
187 self.vty.enable()
188 self.vty.command("configure terminal")
Holger Hans Peter Freythera2c41c42015-07-13 11:23:53 +0200189
190 if not self.checkForSmpp():
191 return
192
Holger Hans Peter Freyther42cf2e02015-07-06 16:41:30 +0200193 self.vty.command("smpp")
194
195 # check the default
196 res = self.vty.command("write terminal")
197 self.assert_(res.find(' no smpp-first') > 0)
198
199 self.vty.verify("smpp-first", [''])
200 res = self.vty.command("write terminal")
201 self.assert_(res.find(' smpp-first') > 0)
202 self.assertEquals(res.find('no smpp-first'), -1)
203
204 self.vty.verify("no smpp-first", [''])
205 res = self.vty.command("write terminal")
206 self.assert_(res.find('no smpp-first') > 0)
207
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200208 def testVtyTree(self):
209 self.vty.enable()
210 self.assertTrue(self.vty.verify("configure terminal", ['']))
211 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100212 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200213 self.assertTrue(self.vty.verify('mncc-int', ['']))
214 self.assertEquals(self.vty.node(), 'config-mncc-int')
215 self.checkForEndAndExit()
216 self.assertTrue(self.vty.verify('exit', ['']))
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200217
218 if self.checkForSmpp():
219 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck75877272013-10-23 11:24:14 +0200220 self.assertTrue(self.vty.verify('smpp', ['']))
221 self.assertEquals(self.vty.node(), 'config-smpp')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100222 self.checkForEndAndExit()
Jacob Erlbeck75877272013-10-23 11:24:14 +0200223 self.assertTrue(self.vty.verify("exit", ['']))
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200224
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200225 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200226 self.assertTrue(self.vty.verify("exit", ['']))
227 self.assertTrue(self.vty.node() is None)
228
229 # Check searching for outer node's commands
230 self.vty.command("configure terminal")
231 self.vty.command('mncc-int')
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200232
233 if self.checkForSmpp():
234 self.vty.command('smpp')
235 self.assertEquals(self.vty.node(), 'config-smpp')
236 self.vty.command('mncc-int')
237
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200238 self.assertEquals(self.vty.node(), 'config-mncc-int')
239
Maxddee01f2016-05-24 14:23:27 +0200240 def testVtyAuthorization(self):
241 self.vty.enable()
242 self.vty.command("configure terminal")
243 self.vty.command("network")
244 self.assertTrue(self.vty.verify("auth policy closed", ['']))
245 self.assertTrue(self.vty.verify("auth policy regexp", ['']))
246 self.assertTrue(self.vty.verify("authorized-regexp ^001", ['']))
247 self.assertTrue(self.vty.verify("authorized-regexp 02$", ['']))
248 self.assertTrue(self.vty.verify("authorized-regexp *123.*", ['']))
249 self.vty.command("end")
250 self.vty.command("configure terminal")
251 self.vty.command("nitb")
252 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
Maxe6052c42016-06-30 10:25:49 +0200253 self.assertTrue(self.vty.verify("subscriber-create-on-demand no-extension", ['']))
Maxddee01f2016-05-24 14:23:27 +0200254 self.vty.command("end")
255
Max0c1bc262016-04-20 12:06:06 +0200256 def testSi2Q(self):
257 self.vty.enable()
258 self.vty.command("configure terminal")
259 self.vty.command("network")
260 self.vty.command("bts 0")
261 before = self.vty.command("show running-config")
262 self.vty.command("si2quater neighbor-list add earfcn 1911 threshold 11 2")
263 self.vty.command("si2quater neighbor-list add earfcn 1924 threshold 11 3")
264 self.vty.command("si2quater neighbor-list add earfcn 2111 threshold 11")
265 self.vty.command("si2quater neighbor-list del earfcn 1911")
266 self.vty.command("si2quater neighbor-list del earfcn 1924")
267 self.vty.command("si2quater neighbor-list del earfcn 2111")
268 self.assertEquals(before, self.vty.command("show running-config"))
Max26679e02016-04-20 15:57:13 +0200269 self.vty.command("si2quater neighbor-list add uarfcn 1976 13 1")
270 self.vty.command("si2quater neighbor-list add uarfcn 1976 38 1")
271 self.vty.command("si2quater neighbor-list add uarfcn 1976 44 1")
272 self.vty.command("si2quater neighbor-list add uarfcn 1976 120 1")
273 self.vty.command("si2quater neighbor-list add uarfcn 1976 140 1")
274 self.vty.command("si2quater neighbor-list add uarfcn 1976 163 1")
275 self.vty.command("si2quater neighbor-list add uarfcn 1976 166 1")
276 self.vty.command("si2quater neighbor-list add uarfcn 1976 217 1")
277 self.vty.command("si2quater neighbor-list add uarfcn 1976 224 1")
278 self.vty.command("si2quater neighbor-list add uarfcn 1976 225 1")
279 self.vty.command("si2quater neighbor-list add uarfcn 1976 226 1")
280 self.vty.command("si2quater neighbor-list del uarfcn 1976 13")
281 self.vty.command("si2quater neighbor-list del uarfcn 1976 38")
282 self.vty.command("si2quater neighbor-list del uarfcn 1976 44")
283 self.vty.command("si2quater neighbor-list del uarfcn 1976 120")
284 self.vty.command("si2quater neighbor-list del uarfcn 1976 140")
285 self.vty.command("si2quater neighbor-list del uarfcn 1976 163")
286 self.vty.command("si2quater neighbor-list del uarfcn 1976 166")
287 self.vty.command("si2quater neighbor-list del uarfcn 1976 217")
288 self.vty.command("si2quater neighbor-list del uarfcn 1976 224")
289 self.vty.command("si2quater neighbor-list del uarfcn 1976 225")
290 self.vty.command("si2quater neighbor-list del uarfcn 1976 226")
291 self.assertEquals(before, self.vty.command("show running-config"))
Max0c1bc262016-04-20 12:06:06 +0200292
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200293 def testEnableDisablePeriodicLU(self):
294 self.vty.enable()
295 self.vty.command("configure terminal")
296 self.vty.command("network")
297 self.vty.command("bts 0")
298
299 # Test invalid input
300 self.vty.verify("periodic location update 0", ['% Unknown command.'])
301 self.vty.verify("periodic location update 5", ['% Unknown command.'])
302 self.vty.verify("periodic location update 1531", ['% Unknown command.'])
303
304 # Enable periodic lu..
305 self.vty.verify("periodic location update 60", [''])
306 res = self.vty.command("write terminal")
Holger Hans Peter Freytherc0438e32013-07-27 22:23:25 +0200307 self.assert_(res.find('periodic location update 60') > 0)
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200308 self.assertEquals(res.find('no periodic location update'), -1)
309
310 # Now disable it..
311 self.vty.verify("no periodic location update", [''])
312 res = self.vty.command("write terminal")
313 self.assertEquals(res.find('periodic location update 60'), -1)
Holger Hans Peter Freytherc0438e32013-07-27 22:23:25 +0200314 self.assert_(res.find('no periodic location update') > 0)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200315
Jacob Erlbeck65d114f2014-01-16 11:02:14 +0100316 def testEnableDisableSiHacks(self):
317 self.vty.enable()
318 self.vty.command("configure terminal")
319 self.vty.command("network")
320 self.vty.command("bts 0")
321
322 # Enable periodic lu..
323 self.vty.verify("force-combined-si", [''])
324 res = self.vty.command("write terminal")
325 self.assert_(res.find(' force-combined-si') > 0)
326 self.assertEquals(res.find('no force-combined-si'), -1)
327
328 # Now disable it..
329 self.vty.verify("no force-combined-si", [''])
330 res = self.vty.command("write terminal")
331 self.assertEquals(res.find(' force-combined-si'), -1)
332 self.assert_(res.find('no force-combined-si') > 0)
333
Ivan Kluchnikov67920592013-09-16 13:13:04 +0400334 def testRachAccessControlClass(self):
335 self.vty.enable()
336 self.vty.command("configure terminal")
337 self.vty.command("network")
338 self.vty.command("bts 0")
339
340 # Test invalid input
341 self.vty.verify("rach access-control-class", ['% Command incomplete.'])
342 self.vty.verify("rach access-control-class 1", ['% Command incomplete.'])
343 self.vty.verify("rach access-control-class -1", ['% Unknown command.'])
344 self.vty.verify("rach access-control-class 10", ['% Unknown command.'])
345 self.vty.verify("rach access-control-class 16", ['% Unknown command.'])
346
347 # Barred rach access control classes
348 for classNum in range(16):
349 if classNum != 10:
350 self.vty.verify("rach access-control-class " + str(classNum) + " barred", [''])
351
352 # Verify settings
353 res = self.vty.command("write terminal")
354 for classNum in range(16):
355 if classNum != 10:
356 self.assert_(res.find("rach access-control-class " + str(classNum) + " barred") > 0)
357
358 # Allowed rach access control classes
359 for classNum in range(16):
360 if classNum != 10:
361 self.vty.verify("rach access-control-class " + str(classNum) + " allowed", [''])
362
363 # Verify settings
364 res = self.vty.command("write terminal")
365 for classNum in range(16):
366 if classNum != 10:
367 self.assertEquals(res.find("rach access-control-class " + str(classNum) + " barred"), -1)
368
Holger Hans Peter Freytherde392252016-04-01 19:44:00 +0200369 def testSubscriberCreateDeleteTwice(self):
370 """
371 OS#1657 indicates that there might be an issue creating the
372 same subscriber twice. This test will use the VTY command to
373 create a subscriber and then issue a second create command
374 with the same IMSI. The test passes if the VTY continues to
375 respond to VTY commands.
376 """
377 self.vty.enable()
378
379 imsi = "204300854013739"
380
381 # Initially we don't have this subscriber
382 self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi])
383
384 # Lets create one
385 res = self.vty.command('subscriber create imsi '+imsi)
386 self.assert_(res.find(" IMSI: "+imsi) > 0)
387 # And now create one again.
388 res2 = self.vty.command('subscriber create imsi '+imsi)
389 self.assert_(res2.find(" IMSI: "+imsi) > 0)
390 self.assertEqual(res, res2)
391
392 # Verify it has been created
393 res = self.vty.command('show subscriber imsi '+imsi)
394 self.assert_(res.find(" IMSI: "+imsi) > 0)
395
396 # Delete it
Max488902d2016-06-22 14:02:39 +0200397 res = self.vty.command('subscriber imsi ' + imsi + ' delete')
398 self.assert_("" == res)
Holger Hans Peter Freytherde392252016-04-01 19:44:00 +0200399
400 # Now it should not be there anymore
401 res = self.vty.command('show subscriber imsi '+imsi)
Max488902d2016-06-22 14:02:39 +0200402 self.assert_(('% No subscriber found for imsi ' + imsi) == res)
Holger Hans Peter Freytherde392252016-04-01 19:44:00 +0200403
404
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500405 def testSubscriberCreateDelete(self):
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200406 self.vty.enable()
407
408 imsi = "204300854013739"
Maxe6052c42016-06-30 10:25:49 +0200409 imsi2 = "222301824913762"
410 imsi3 = "333500854113763"
411 imsi4 = "444583744053764"
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200412
413 # Initially we don't have this subscriber
414 self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi])
415
416 # Lets create one
417 res = self.vty.command('subscriber create imsi '+imsi)
418 self.assert_(res.find(" IMSI: "+imsi) > 0)
Maxe6052c42016-06-30 10:25:49 +0200419 self.assert_(res.find("Extension") > 0)
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200420
421 # Now we have it
422 res = self.vty.command('show subscriber imsi '+imsi)
423 self.assert_(res.find(" IMSI: "+imsi) > 0)
424
Maxe6052c42016-06-30 10:25:49 +0200425 # With narrow random interval
426 self.vty.command("configure terminal")
427 self.vty.command("nitb")
428 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
429 # wrong interval
430 res = self.vty.command("subscriber-create-on-demand random 221 122")
431 # error string will contain arguments
432 self.assert_(res.find("122") > 0)
433 self.assert_(res.find("221") > 0)
434 # correct interval - silent ok
435 self.assertTrue(self.vty.verify("subscriber-create-on-demand random 221 222", ['']))
436 self.vty.command("end")
437
438 res = self.vty.command('subscriber create imsi ' + imsi2)
439 self.assert_(res.find(" IMSI: " + imsi2) > 0)
440 self.assert_(res.find("221") > 0 or res.find("222") > 0)
441 self.assert_(res.find(" Extension: ") > 0)
442
443 # Without extension
444 self.vty.command("configure terminal")
445 self.vty.command("nitb")
446 self.assertTrue(self.vty.verify("subscriber-create-on-demand no-extension", ['']))
447 self.vty.command("end")
448 res = self.vty.command('subscriber create imsi ' + imsi3)
449 self.assert_(res.find(" IMSI: " + imsi3) > 0)
450 self.assertEquals(res.find("Extension"), -1)
451
452 # With extension again
453 self.vty.command("configure terminal")
454 self.vty.command("nitb")
455 self.assertTrue(self.vty.verify("no subscriber-create-on-demand", ['']))
456 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
457 self.assertTrue(self.vty.verify("subscriber-create-on-demand random 221 666", ['']))
458 self.vty.command("end")
459
460 res = self.vty.command('subscriber create imsi ' + imsi4)
461 self.assert_(res.find(" IMSI: " + imsi4) > 0)
462 self.assert_(res.find(" Extension: ") > 0)
463
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500464 # Delete it
Max488902d2016-06-22 14:02:39 +0200465 res = self.vty.command('subscriber imsi ' + imsi + ' delete')
466 self.assert_("" == res)
Maxe6052c42016-06-30 10:25:49 +0200467 res = self.vty.command('subscriber imsi ' + imsi2 + ' delete')
468 self.assert_("" == res)
469 res = self.vty.command('subscriber imsi ' + imsi3 + ' delete')
470 self.assert_("" == res)
471 res = self.vty.command('subscriber imsi ' + imsi4 + ' delete')
472 self.assert_("" == res)
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500473
474 # Now it should not be there anymore
475 res = self.vty.command('show subscriber imsi '+imsi)
Max488902d2016-06-22 14:02:39 +0200476 self.assert_(('% No subscriber found for imsi ' + imsi) == res)
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500477
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200478 def testSubscriberSettings(self):
479 self.vty.enable()
480
481 imsi = "204300854013739"
Max0fcd2e22016-06-07 15:32:16 +0200482 imsi2 = "204301824913769"
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200483 wrong_imsi = "204300999999999"
484
485 # Lets create one
486 res = self.vty.command('subscriber create imsi '+imsi)
487 self.assert_(res.find(" IMSI: "+imsi) > 0)
Max0fcd2e22016-06-07 15:32:16 +0200488 self.assert_(res.find("Extension") > 0)
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200489
490 self.vty.verify('subscriber imsi '+wrong_imsi+' name wrong', ['% No subscriber found for imsi '+wrong_imsi])
491 res = self.vty.command('subscriber imsi '+imsi+' name '+('X' * 160))
492 self.assert_(res.find("NAME is too long") > 0)
493
494 self.vty.verify('subscriber imsi '+imsi+' name '+('G' * 159), [''])
495
496 self.vty.verify('subscriber imsi '+wrong_imsi+' extension 840', ['% No subscriber found for imsi '+wrong_imsi])
497 res = self.vty.command('subscriber imsi '+imsi+' extension '+('9' * 15))
498 self.assert_(res.find("EXTENSION is too long") > 0)
499
500 self.vty.verify('subscriber imsi '+imsi+' extension '+('1' * 14), [''])
501
Max0fcd2e22016-06-07 15:32:16 +0200502 # With narrow random interval
503 self.vty.command("configure terminal")
504 self.vty.command("nitb")
505 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
506 # wrong interval
507 res = self.vty.command("subscriber-create-on-demand random 221 122")
508 self.assert_(res.find("122") > 0)
509 self.assert_(res.find("221") > 0)
510 # correct interval
511 self.assertTrue(self.vty.verify("subscriber-create-on-demand random 221 222", ['']))
512 self.vty.command("end")
513
Max488902d2016-06-22 14:02:39 +0200514 # create subscriber with extension in a configured interval
Max0fcd2e22016-06-07 15:32:16 +0200515 res = self.vty.command('subscriber create imsi ' + imsi2)
516 self.assert_(res.find(" IMSI: " + imsi2) > 0)
517 self.assert_(res.find("221") > 0 or res.find("222") > 0)
518 self.assert_(res.find(" Extension: ") > 0)
519
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200520 # Delete it
Max488902d2016-06-22 14:02:39 +0200521 res = self.vty.command('subscriber imsi ' + imsi + ' delete')
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200522 self.assert_(res != "")
Max488902d2016-06-22 14:02:39 +0200523 # imsi2 is inactive so deletion should succeed
524 res = self.vty.command('subscriber imsi ' + imsi2 + ' delete')
525 self.assert_("" == res)
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200526
Holger Hans Peter Freytherec37bb22013-02-05 09:39:09 +0100527 def testShowPagingGroup(self):
528 res = self.vty.command("show paging-group 255 1234567")
529 self.assertEqual(res, "% can't find BTS 255")
530 res = self.vty.command("show paging-group 0 1234567")
531 self.assertEquals(res, "%Paging group for IMSI 1234567 on BTS #0 is 7")
532
Ciabyec6e4f82014-03-06 17:20:55 +0100533 def testShowNetwork(self):
534 res = self.vty.command("show network")
535 self.assert_(res.startswith('BSC is on Country Code') >= 0)
536
Holger Hans Peter Freyther86573262015-01-31 09:47:37 +0100537 def testMeasurementFeed(self):
538 self.vty.enable()
539 self.vty.command("configure terminal")
540 self.vty.command("mncc-int")
541
542 res = self.vty.command("write terminal")
543 self.assertEquals(res.find('meas-feed scenario'), -1)
544
545 self.vty.command("meas-feed scenario bla")
546 res = self.vty.command("write terminal")
547 self.assert_(res.find('meas-feed scenario bla') > 0)
548
Neels Hofmeyr0867b722016-09-28 23:28:06 +0200549 self.vty.command("meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890")
Holger Hans Peter Freyther86573262015-01-31 09:47:37 +0100550 res = self.vty.command("write terminal")
551 self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890'), -1)
552 self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz012345'), -1)
553 self.assert_(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234') > 0)
554
555
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200556class TestVTYBSC(TestVTYGenericBSC):
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200557
558 def vty_command(self):
559 return ["./src/osmo-bsc/osmo-bsc", "-c",
560 "doc/examples/osmo-bsc/osmo-bsc.cfg"]
561
562 def vty_app(self):
563 return (4242, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc")
564
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200565 def testConfigNetworkTree(self):
Jacob Erlbeck75877272013-10-23 11:24:14 +0200566 self._testConfigNetworkTree()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200567
568 def testVtyTree(self):
569 self.vty.enable()
570 self.assertTrue(self.vty.verify("configure terminal", ['']))
571 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100572 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200573 self.assertTrue(self.vty.verify("msc 0", ['']))
574 self.assertEquals(self.vty.node(), 'config-msc')
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200575 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200576 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200577 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200578 self.assertTrue(self.vty.verify("bsc", ['']))
579 self.assertEquals(self.vty.node(), 'config-bsc')
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200580 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200581 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200582 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200583 self.assertTrue(self.vty.verify("exit", ['']))
584 self.assertTrue(self.vty.node() is None)
585
586 # Check searching for outer node's commands
587 self.vty.command("configure terminal")
588 self.vty.command('msc 0')
589 self.vty.command("bsc")
590 self.assertEquals(self.vty.node(), 'config-bsc')
591 self.vty.command("msc 0")
592 self.assertEquals(self.vty.node(), 'config-msc')
593
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200594 def testUssdNotificationsMsc(self):
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200595 self.vty.enable()
596 self.vty.command("configure terminal")
597 self.vty.command("msc")
598
599 # Test invalid input
600 self.vty.verify("bsc-msc-lost-text", ['% Command incomplete.'])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200601 self.vty.verify("bsc-welcome-text", ['% Command incomplete.'])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200602 self.vty.verify("bsc-grace-text", ['% Command incomplete.'])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200603
604 # Enable USSD notifications
605 self.vty.verify("bsc-msc-lost-text MSC disconnected", [''])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200606 self.vty.verify("bsc-welcome-text Hello MS", [''])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200607 self.vty.verify("bsc-grace-text In grace period", [''])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200608
609 # Verify settings
610 res = self.vty.command("write terminal")
611 self.assert_(res.find('bsc-msc-lost-text MSC disconnected') > 0)
612 self.assertEquals(res.find('no bsc-msc-lost-text'), -1)
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200613 self.assert_(res.find('bsc-welcome-text Hello MS') > 0)
614 self.assertEquals(res.find('no bsc-welcome-text'), -1)
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200615 self.assert_(res.find('bsc-grace-text In grace period') > 0)
616 self.assertEquals(res.find('no bsc-grace-text'), -1)
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200617
618 # Now disable it..
619 self.vty.verify("no bsc-msc-lost-text", [''])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200620 self.vty.verify("no bsc-welcome-text", [''])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200621 self.vty.verify("no bsc-grace-text", [''])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200622
623 # Verify settings
624 res = self.vty.command("write terminal")
625 self.assertEquals(res.find('bsc-msc-lost-text MSC disconnected'), -1)
626 self.assert_(res.find('no bsc-msc-lost-text') > 0)
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200627 self.assertEquals(res.find('bsc-welcome-text Hello MS'), -1)
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200628 self.assert_(res.find('no bsc-welcome-text') > 0)
629 self.assertEquals(res.find('bsc-grace-text In grace period'), -1)
630 self.assert_(res.find('no bsc-grace-text') > 0)
631
632 def testUssdNotificationsBsc(self):
633 self.vty.enable()
634 self.vty.command("configure terminal")
635 self.vty.command("bsc")
636
637 # Test invalid input
638 self.vty.verify("missing-msc-text", ['% Command incomplete.'])
639
640 # Enable USSD notifications
641 self.vty.verify("missing-msc-text No MSC found", [''])
642
643 # Verify settings
644 res = self.vty.command("write terminal")
645 self.assert_(res.find('missing-msc-text No MSC found') > 0)
646 self.assertEquals(res.find('no missing-msc-text'), -1)
647
648 # Now disable it..
649 self.vty.verify("no missing-msc-text", [''])
650
651 # Verify settings
652 res = self.vty.command("write terminal")
653 self.assertEquals(res.find('missing-msc-text No MSC found'), -1)
654 self.assert_(res.find('no missing-msc-text') > 0)
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200655
Jacob Erlbeck946d1412013-09-17 13:59:29 +0200656 def testNetworkTimezone(self):
657 self.vty.enable()
658 self.vty.verify("configure terminal", [''])
659 self.vty.verify("network", [''])
Jacob Erlbeck946d1412013-09-17 13:59:29 +0200660
661 # Test invalid input
662 self.vty.verify("timezone", ['% Command incomplete.'])
663 self.vty.verify("timezone 20 0", ['% Unknown command.'])
664 self.vty.verify("timezone 0 11", ['% Unknown command.'])
665 self.vty.verify("timezone 0 0 99", ['% Unknown command.'])
666
667 # Set time zone without DST
668 self.vty.verify("timezone 2 30", [''])
669
670 # Verify settings
671 res = self.vty.command("write terminal")
672 self.assert_(res.find('timezone 2 30') > 0)
673 self.assertEquals(res.find('timezone 2 30 '), -1)
674
675 # Set time zone with DST
676 self.vty.verify("timezone 2 30 1", [''])
677
678 # Verify settings
679 res = self.vty.command("write terminal")
680 self.assert_(res.find('timezone 2 30 1') > 0)
681
682 # Now disable it..
683 self.vty.verify("no timezone", [''])
684
685 # Verify settings
686 res = self.vty.command("write terminal")
687 self.assertEquals(res.find(' timezone'), -1)
688
Ciabyec6e4f82014-03-06 17:20:55 +0100689 def testShowNetwork(self):
690 res = self.vty.command("show network")
691 self.assert_(res.startswith('BSC is on Country Code') >= 0)
692
Holger Hans Peter Freytherdb64f2e2014-10-29 10:06:15 +0100693 def testPingPongConfiguration(self):
694 self.vty.enable()
695 self.vty.verify("configure terminal", [''])
696 self.vty.verify("network", [''])
697 self.vty.verify("msc 0", [''])
698
699 self.vty.verify("timeout-ping 12", [''])
700 self.vty.verify("timeout-pong 14", [''])
701 res = self.vty.command("show running-config")
702 self.assert_(res.find(" timeout-ping 12") > 0)
703 self.assert_(res.find(" timeout-pong 14") > 0)
704 self.assert_(res.find(" no timeout-ping advanced") > 0)
705
706 self.vty.verify("timeout-ping advanced", [''])
707 res = self.vty.command("show running-config")
708 self.assert_(res.find(" timeout-ping 12") > 0)
709 self.assert_(res.find(" timeout-pong 14") > 0)
710 self.assert_(res.find(" timeout-ping advanced") > 0)
711
712 self.vty.verify("no timeout-ping advanced", [''])
713 res = self.vty.command("show running-config")
714 self.assert_(res.find(" timeout-ping 12") > 0)
715 self.assert_(res.find(" timeout-pong 14") > 0)
716 self.assert_(res.find(" no timeout-ping advanced") > 0)
717
718 self.vty.verify("no timeout-ping", [''])
719 res = self.vty.command("show running-config")
720 self.assertEquals(res.find(" timeout-ping 12"), -1)
721 self.assertEquals(res.find(" timeout-pong 14"), -1)
722 self.assertEquals(res.find(" no timeout-ping advanced"), -1)
723 self.assert_(res.find(" no timeout-ping") > 0)
724
725 self.vty.verify("timeout-ping advanced", ['%ping handling is disabled. Enable it first.'])
726
727 # And back to enabling it
728 self.vty.verify("timeout-ping 12", [''])
729 self.vty.verify("timeout-pong 14", [''])
730 res = self.vty.command("show running-config")
731 self.assert_(res.find(" timeout-ping 12") > 0)
732 self.assert_(res.find(" timeout-pong 14") > 0)
733 self.assert_(res.find(" timeout-ping advanced") > 0)
734
Holger Hans Peter Freyther32dd2f32015-04-01 18:15:48 +0200735 def testMscDataCoreLACCI(self):
736 self.vty.enable()
737 res = self.vty.command("show running-config")
738 self.assertEquals(res.find("core-location-area-code"), -1)
739 self.assertEquals(res.find("core-cell-identity"), -1)
740
Neels Hofmeyr0867b722016-09-28 23:28:06 +0200741 self.vty.command("configure terminal")
Holger Hans Peter Freyther32dd2f32015-04-01 18:15:48 +0200742 self.vty.command("msc 0")
743 self.vty.command("core-location-area-code 666")
744 self.vty.command("core-cell-identity 333")
745
746 res = self.vty.command("show running-config")
747 self.assert_(res.find("core-location-area-code 666") > 0)
748 self.assert_(res.find("core-cell-identity 333") > 0)
749
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200750class TestVTYNAT(TestVTYGenericBSC):
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200751
752 def vty_command(self):
Max49364482016-04-13 11:36:39 +0200753 return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-l", "127.0.0.1", "-c",
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200754 "doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"]
755
756 def vty_app(self):
757 return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat")
758
Max49364482016-04-13 11:36:39 +0200759 def testBSCreload(self):
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -0400760 # Use different port for the mock msc to avoid clashing with
761 # the osmo-bsc_nat itself
Holger Hans Peter Freytherf1a61bb2016-04-14 08:50:25 -0400762 ip = "127.0.0.1"
Holger Hans Peter Freythere98c9c72016-04-14 10:58:58 -0400763 port = 5522
Max49364482016-04-13 11:36:39 +0200764 self.vty.enable()
765 bscs1 = self.vty.command("show bscs-config")
766 nat_bsc_reload(self)
767 bscs2 = self.vty.command("show bscs-config")
768 # check that multiple calls to bscs-config-file give the same result
769 self.assertEquals(bscs1, bscs2)
770
771 # add new bsc
772 self.vty.command("configure terminal")
773 self.vty.command("nat")
774 self.vty.command("bsc 5")
775 self.vty.command("token key")
776 self.vty.command("location_area_code 666")
777 self.vty.command("end")
778
779 # update bsc token
780 self.vty.command("configure terminal")
781 self.vty.command("nat")
782 self.vty.command("bsc 1")
783 self.vty.command("token xyu")
784 self.vty.command("end")
785
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -0400786 nat_msc_ip(self, ip, port)
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +0100787 msc = nat_msc_test(self, ip, port, verbose=True)
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
792 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"))
795
796 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)
800
801 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
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200810 def testVtyTree(self):
811 self.vty.enable()
812 self.assertTrue(self.vty.verify('configure terminal', ['']))
813 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100814 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200815 self.assertTrue(self.vty.verify('mgcp', ['']))
816 self.assertEquals(self.vty.node(), 'config-mgcp')
817 self.checkForEndAndExit()
818 self.assertTrue(self.vty.verify('exit', ['']))
819 self.assertEquals(self.vty.node(), 'config')
820 self.assertTrue(self.vty.verify('nat', ['']))
821 self.assertEquals(self.vty.node(), 'config-nat')
822 self.checkForEndAndExit()
823 self.assertTrue(self.vty.verify('bsc 0', ['']))
824 self.assertEquals(self.vty.node(), 'config-nat-bsc')
825 self.checkForEndAndExit()
826 self.assertTrue(self.vty.verify('exit', ['']))
827 self.assertEquals(self.vty.node(), 'config-nat')
828 self.assertTrue(self.vty.verify('exit', ['']))
829 self.assertEquals(self.vty.node(), 'config')
830 self.assertTrue(self.vty.verify('exit', ['']))
831 self.assertTrue(self.vty.node() is None)
832
833 # Check searching for outer node's commands
834 self.vty.command('configure terminal')
835 self.vty.command('mgcp')
836 self.vty.command('nat')
837 self.assertEquals(self.vty.node(), 'config-nat')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200838 self.vty.command('mgcp')
839 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200840 self.vty.command('nat')
841 self.assertEquals(self.vty.node(), 'config-nat')
842 self.vty.command('bsc 0')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200843 self.vty.command('mgcp')
844 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200845
Holger Hans Peter Freytherb718ad32013-06-25 09:08:02 +0200846 def testRewriteNoRewrite(self):
847 self.vty.enable()
848 res = self.vty.command("configure terminal")
849 res = self.vty.command("nat")
850 res = self.vty.command("number-rewrite rewrite.cfg")
851 res = self.vty.command("no number-rewrite")
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200852
Holger Hans Peter Freyther7f100c92015-04-23 20:25:17 -0400853 def testEnsureNoEnsureModeSet(self):
854 self.vty.enable()
855 res = self.vty.command("configure terminal")
856 res = self.vty.command("nat")
857
858 # Ensure the default
859 res = self.vty.command("show running-config")
860 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
861
862 self.vty.command("sdp-ensure-amr-mode-set")
863 res = self.vty.command("show running-config")
864 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
865
866 self.vty.command("no sdp-ensure-amr-mode-set")
867 res = self.vty.command("show running-config")
868 self.assert_(res.find('\n no sdp-ensure-amr-mode-set') > 0)
869
Holger Hans Peter Freyther67e423c2013-06-25 15:38:31 +0200870 def testRewritePostNoRewrite(self):
871 self.vty.enable()
872 self.vty.command("configure terminal")
873 self.vty.command("nat")
874 self.vty.verify("number-rewrite-post rewrite.cfg", [''])
875 self.vty.verify("no number-rewrite-post", [''])
876
877
Holger Hans Peter Freytherddf191e2013-06-25 11:44:01 +0200878 def testPrefixTreeLoading(self):
879 cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv")
880
881 self.vty.enable()
882 self.vty.command("configure terminal")
883 self.vty.command("nat")
884 res = self.vty.command("prefix-tree %s" % cfg)
885 self.assertEqual(res, "% prefix-tree loaded 17 rules.")
886 self.vty.command("end")
887
888 res = self.vty.command("show prefix-tree")
889 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')
890
891 self.vty.command("configure terminal")
892 self.vty.command("nat")
893 self.vty.command("no prefix-tree")
894 self.vty.command("end")
895
896 res = self.vty.command("show prefix-tree")
897 self.assertEqual(res, "% there is now prefix tree loaded.")
898
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200899 def testUssdSideChannelProvider(self):
900 self.vty.command("end")
901 self.vty.enable()
902 self.vty.command("configure terminal")
903 self.vty.command("nat")
904 self.vty.command("ussd-token key")
905 self.vty.command("end")
906
907 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
908 self.assertTrue(res)
909
910 ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
911 ussdSocket.connect(('127.0.0.1', 5001))
912 ussdSocket.settimeout(2.0)
913 print "Connected to %s:%d" % ussdSocket.getpeername()
914
915 print "Expecting ID_GET request"
916 data = ussdSocket.recv(4)
917 self.assertEqual(data, "\x00\x01\xfe\x04")
918
919 print "Going to send ID_RESP response"
Max3e676892016-11-16 14:55:21 +0100920 res = ussdSocket.send(IPA().id_resp(IPA().tag_name('key')))
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200921 self.assertEqual(res, 10)
922
923 # initiating PING/PONG cycle to know, that the ID_RESP message has been processed
924
925 print "Going to send PING request"
Max3e676892016-11-16 14:55:21 +0100926 res = ussdSocket.send(IPA().ping())
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200927 self.assertEqual(res, 4)
928
929 print "Expecting PONG response"
930 data = ussdSocket.recv(4)
931 self.assertEqual(data, "\x00\x01\xfe\x01")
932
933 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.'])
934 self.assertTrue(res)
935
936 print "Going to shut down connection"
937 ussdSocket.shutdown(socket.SHUT_WR)
938
939 print "Expecting EOF"
940 data = ussdSocket.recv(4)
941 self.assertEqual(data, "")
942
943 ussdSocket.close()
944
945 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
946 self.assertTrue(res)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200947
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100948 def testAccessList(self):
949 """
950 Verify that the imsi-deny can have a reject cause or no reject cause
951 """
952 self.vty.enable()
953 self.vty.command("configure terminal")
954 self.vty.command("nat")
955
956 # Old default
957 self.vty.command("access-list test-default imsi-deny ^123[0-9]*$")
958 res = self.vty.command("show running-config").split("\r\n")
959 asserted = False
960 for line in res:
Holger Hans Peter Freyther4ecc6872014-03-04 15:38:00 +0100961 if line.startswith(" access-list test-default"):
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100962 self.assertEqual(line, " access-list test-default imsi-deny ^123[0-9]*$ 11 11")
963 asserted = True
964 self.assert_(asserted)
965
966 # Check the optional CM Service Reject Cause
967 self.vty.command("access-list test-cm-deny imsi-deny ^123[0-9]*$ 42").split("\r\n")
968 res = self.vty.command("show running-config").split("\r\n")
969 asserted = False
970 for line in res:
971 if line.startswith(" access-list test-cm"):
972 self.assertEqual(line, " access-list test-cm-deny imsi-deny ^123[0-9]*$ 42 11")
973 asserted = True
974 self.assert_(asserted)
975
976 # Check the optional LU Reject Cause
977 self.vty.command("access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42").split("\r\n")
978 res = self.vty.command("show running-config").split("\r\n")
979 asserted = False
980 for line in res:
981 if line.startswith(" access-list test-lu"):
982 self.assertEqual(line, " access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42")
983 asserted = True
984 self.assert_(asserted)
985
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200986class TestVTYGbproxy(TestVTYGenericBSC):
987
988 def vty_command(self):
989 return ["./src/gprs/osmo-gbproxy", "-c",
990 "doc/examples/osmo-gbproxy/osmo-gbproxy.cfg"]
991
992 def vty_app(self):
993 return (4246, "./src/gprs/osmo-gbproxy", "OsmoGbProxy", "bsc")
994
995 def testVtyTree(self):
996 self.vty.enable()
997 self.assertTrue(self.vty.verify('configure terminal', ['']))
998 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100999 self.checkForEndAndExit()
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001000 self.assertTrue(self.vty.verify('ns', ['']))
1001 self.assertEquals(self.vty.node(), 'config-ns')
1002 self.checkForEndAndExit()
1003 self.assertTrue(self.vty.verify('exit', ['']))
1004 self.assertEquals(self.vty.node(), 'config')
1005 self.assertTrue(self.vty.verify('gbproxy', ['']))
1006 self.assertEquals(self.vty.node(), 'config-gbproxy')
1007 self.checkForEndAndExit()
1008 self.assertTrue(self.vty.verify('exit', ['']))
1009 self.assertEquals(self.vty.node(), 'config')
1010
1011 def testVtyShow(self):
1012 res = self.vty.command("show ns")
1013 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
1014
1015 res = self.vty.command("show gbproxy stats")
1016 self.assert_(res.find('GBProxy Global Statistics') >= 0)
1017
Jacob Erlbeck4211d792013-10-24 12:48:23 +02001018 def testVtyDeletePeer(self):
1019 self.vty.enable()
1020 self.assertTrue(self.vty.verify('delete-gbproxy-peer 9999 bvci 7777', ['BVC not found']))
1021 res = self.vty.command("delete-gbproxy-peer 9999 all dry-run")
1022 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
1023 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
1024 res = self.vty.command("delete-gbproxy-peer 9999 only-bvc 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-nsvc 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 all")
1031 self.assert_(res.find('Deleted 0 BVC') >= 0)
1032 self.assert_(res.find('Deleted 0 NS-VC') >= 0)
1033
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001034class TestVTYSGSN(TestVTYGenericBSC):
1035
1036 def vty_command(self):
1037 return ["./src/gprs/osmo-sgsn", "-c",
1038 "doc/examples/osmo-sgsn/osmo-sgsn.cfg"]
1039
1040 def vty_app(self):
1041 return (4245, "./src/gprs/osmo-sgsn", "OsmoSGSN", "sgsn")
1042
1043 def testVtyTree(self):
1044 self.vty.enable()
1045 self.assertTrue(self.vty.verify('configure terminal', ['']))
1046 self.assertEquals(self.vty.node(), 'config')
1047 self.checkForEndAndExit()
1048 self.assertTrue(self.vty.verify('ns', ['']))
1049 self.assertEquals(self.vty.node(), 'config-ns')
1050 self.checkForEndAndExit()
1051 self.assertTrue(self.vty.verify('exit', ['']))
1052 self.assertEquals(self.vty.node(), 'config')
1053 self.assertTrue(self.vty.verify('sgsn', ['']))
1054 self.assertEquals(self.vty.node(), 'config-sgsn')
1055 self.checkForEndAndExit()
1056 self.assertTrue(self.vty.verify('exit', ['']))
1057 self.assertEquals(self.vty.node(), 'config')
1058
1059 def testVtyShow(self):
1060 res = self.vty.command("show ns")
1061 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
1062 self.assertTrue(self.vty.verify('show bssgp', ['']))
1063 self.assertTrue(self.vty.verify('show bssgp stats', ['']))
1064 # TODO: uncomment when the command does not segfault anymore
1065 # self.assertTrue(self.vty.verify('show bssgp nsei 123', ['']))
1066 # self.assertTrue(self.vty.verify('show bssgp nsei 123 stats', ['']))
1067
1068 self.assertTrue(self.vty.verify('show sgsn', ['']))
1069 self.assertTrue(self.vty.verify('show mm-context all', ['']))
1070 self.assertTrue(self.vty.verify('show mm-context imsi 000001234567', ['No MM context for IMSI 000001234567']))
1071 self.assertTrue(self.vty.verify('show pdp-context all', ['']))
1072
1073 res = self.vty.command("show sndcp")
1074 self.assert_(res.find('State of SNDCP Entities') >= 0)
1075
1076 res = self.vty.command("show llc")
1077 self.assert_(res.find('State of LLC Entities') >= 0)
1078
Jacob Erlbeck106f5472014-11-04 10:08:37 +01001079 def testVtyAuth(self):
1080 self.vty.enable()
1081 self.assertTrue(self.vty.verify('configure terminal', ['']))
1082 self.assertEquals(self.vty.node(), 'config')
1083 self.assertTrue(self.vty.verify('sgsn', ['']))
1084 self.assertEquals(self.vty.node(), 'config-sgsn')
1085 self.assertTrue(self.vty.verify('auth-policy accept-all', ['']))
1086 res = self.vty.command("show running-config")
1087 self.assert_(res.find('auth-policy accept-all') > 0)
1088 self.assertTrue(self.vty.verify('auth-policy acl-only', ['']))
1089 res = self.vty.command("show running-config")
1090 self.assert_(res.find('auth-policy acl-only') > 0)
1091 self.assertTrue(self.vty.verify('auth-policy closed', ['']))
1092 res = self.vty.command("show running-config")
1093 self.assert_(res.find('auth-policy closed') > 0)
Max176b62a2016-07-04 11:09:07 +02001094 self.assertTrue(self.vty.verify('gsup remote-ip 127.0.0.4', ['']))
1095 self.assertTrue(self.vty.verify('gsup remote-port 2222', ['']))
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +01001096 self.assertTrue(self.vty.verify('auth-policy remote', ['']))
1097 res = self.vty.command("show running-config")
1098 self.assert_(res.find('auth-policy remote') > 0)
Jacob Erlbeck106f5472014-11-04 10:08:37 +01001099
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001100 def testVtySubscriber(self):
1101 self.vty.enable()
1102 res = self.vty.command('show subscriber cache')
1103 self.assert_(res.find('1234567890') < 0)
Jacob Erlbeckd9193432015-01-19 14:11:46 +01001104 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 create', ['']))
1105 res = self.vty.command('show subscriber cache')
1106 self.assert_(res.find('1234567890') >= 0)
1107 self.assert_(res.find('Authorized: 0') >= 0)
1108 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 update-location-result ok', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001109 res = self.vty.command('show subscriber cache')
1110 self.assert_(res.find('1234567890') >= 0)
1111 self.assert_(res.find('Authorized: 1') >= 0)
Jacob Erlbeck8000e0e2015-01-27 14:56:40 +01001112 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 cancel update-procedure', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001113 res = self.vty.command('show subscriber cache')
Jacob Erlbecke988ae42015-01-27 12:41:19 +01001114 self.assert_(res.find('1234567890') >= 0)
1115 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 destroy', ['']))
1116 res = self.vty.command('show subscriber cache')
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001117 self.assert_(res.find('1234567890') < 0)
1118
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +01001119 def testVtyGgsn(self):
1120 self.vty.enable()
1121 self.assertTrue(self.vty.verify('configure terminal', ['']))
1122 self.assertEquals(self.vty.node(), 'config')
1123 self.assertTrue(self.vty.verify('sgsn', ['']))
1124 self.assertEquals(self.vty.node(), 'config-sgsn')
1125 self.assertTrue(self.vty.verify('ggsn 0 remote-ip 127.99.99.99', ['']))
1126 self.assertTrue(self.vty.verify('ggsn 0 gtp-version 1', ['']))
1127 self.assertTrue(self.vty.verify('apn * ggsn 0', ['']))
1128 self.assertTrue(self.vty.verify('apn apn1.test ggsn 0', ['']))
1129 self.assertTrue(self.vty.verify('apn apn1.test ggsn 1', ['% a GGSN with id 1 has not been defined']))
1130 self.assertTrue(self.vty.verify('apn apn1.test imsi-prefix 123456 ggsn 0', ['']))
1131 self.assertTrue(self.vty.verify('apn apn2.test imsi-prefix 123456 ggsn 0', ['']))
1132 res = self.vty.command("show running-config")
1133 self.assert_(res.find('ggsn 0 remote-ip 127.99.99.99') >= 0)
1134 self.assert_(res.find('ggsn 0 gtp-version 1') >= 0)
1135 self.assert_(res.find('apn * ggsn 0') >= 0)
1136 self.assert_(res.find('apn apn1.test ggsn 0') >= 0)
1137 self.assert_(res.find('apn apn1.test imsi-prefix 123456 ggsn 0') >= 0)
1138 self.assert_(res.find('apn apn2.test imsi-prefix 123456 ggsn 0') >= 0)
1139
Holger Hans Peter Freyther9c20a5f2015-02-06 16:23:29 +01001140 def testVtyEasyAPN(self):
1141 self.vty.enable()
1142 self.assertTrue(self.vty.verify('configure terminal', ['']))
1143 self.assertEquals(self.vty.node(), 'config')
1144 self.assertTrue(self.vty.verify('sgsn', ['']))
1145 self.assertEquals(self.vty.node(), 'config-sgsn')
1146
1147 res = self.vty.command("show running-config")
1148 self.assertEquals(res.find("apn internet"), -1)
1149
1150 self.assertTrue(self.vty.verify("access-point-name internet.apn", ['']))
1151 res = self.vty.command("show running-config")
1152 self.assert_(res.find("apn internet.apn ggsn 0") >= 0)
1153
1154 self.assertTrue(self.vty.verify("no access-point-name internet.apn", ['']))
1155 res = self.vty.command("show running-config")
1156 self.assertEquals(res.find("apn internet"), -1)
1157
Holger Hans Peter Freytherc15c61c2015-05-06 17:46:08 +02001158 def testVtyCDR(self):
1159 self.vty.enable()
1160 self.assertTrue(self.vty.verify('configure terminal', ['']))
1161 self.assertEquals(self.vty.node(), 'config')
1162 self.assertTrue(self.vty.verify('sgsn', ['']))
1163 self.assertEquals(self.vty.node(), 'config-sgsn')
1164
1165 res = self.vty.command("show running-config")
1166 self.assert_(res.find("no cdr filename") > 0)
1167
1168 self.vty.command("cdr filename bla.cdr")
1169 res = self.vty.command("show running-config")
1170 self.assertEquals(res.find("no cdr filename"), -1)
1171 self.assert_(res.find(" cdr filename bla.cdr") > 0)
1172
1173 self.vty.command("no cdr filename")
1174 res = self.vty.command("show running-config")
1175 self.assert_(res.find("no cdr filename") > 0)
1176 self.assertEquals(res.find(" cdr filename bla.cdr"), -1)
1177
1178 res = self.vty.command("show running-config")
1179 self.assert_(res.find(" cdr interval 600") > 0)
1180
1181 self.vty.command("cdr interval 900")
1182 res = self.vty.command("show running-config")
1183 self.assert_(res.find(" cdr interval 900") > 0)
1184 self.assertEquals(res.find(" cdr interval 600"), -1)
1185
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001186def add_nat_test(suite, workdir):
1187 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
1188 print("Skipping the NAT test")
1189 return
1190 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT)
1191 suite.addTest(test)
1192
Max49364482016-04-13 11:36:39 +02001193def nat_bsc_reload(x):
1194 x.vty.command("configure terminal")
1195 x.vty.command("nat")
1196 x.vty.command("bscs-config-file bscs.config")
1197 x.vty.command("end")
1198
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001199def nat_msc_ip(x, ip, port):
Max49364482016-04-13 11:36:39 +02001200 x.vty.command("configure terminal")
1201 x.vty.command("nat")
1202 x.vty.command("msc ip " + ip)
Holger Hans Peter Freyther84ae27e2016-04-14 10:40:06 -04001203 x.vty.command("msc port " + str(port))
Max49364482016-04-13 11:36:39 +02001204 x.vty.command("end")
1205
1206def data2str(d):
Holger Hans Peter Freyther8bb62042016-04-14 21:40:04 -04001207 return d.encode('hex').lower()
Max49364482016-04-13 11:36:39 +02001208
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001209def nat_msc_test(x, ip, port, verbose = False):
Max49364482016-04-13 11:36:39 +02001210 msc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
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
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001243def cmd(what):
1244 print '\n> %s' % what
1245 sys.stdout.flush()
1246 subprocess.call(what, shell=True)
1247 sys.stdout.flush()
1248 sys.stderr.flush()
1249 print ''
1250 sys.stdout.flush()
1251
1252def checkxxx():
1253 cmd('cat /proc/net/tcp');
1254 cmd('ps xua | grep osmo');
1255
Max49364482016-04-13 11:36:39 +02001256def ipa_handle_small(x, verbose = False):
1257 s = data2str(x.recv(4))
Neels Hofmeyrba1468e2017-02-03 04:23:46 +01001258 if len(s) != 4*2:
1259 raise Exception("expected to receive 4 bytes, but got %d (%r)" % (len(s)/2, s))
Max49364482016-04-13 11:36:39 +02001260 if "0001fe00" == s:
1261 if (verbose):
1262 print "\tBSC <- NAT: PING?"
Max3e676892016-11-16 14:55:21 +01001263 x.send(IPA().pong())
Max49364482016-04-13 11:36:39 +02001264 elif "0001fe06" == s:
1265 if (verbose):
1266 print "\tBSC <- NAT: IPA ID ACK"
Max3e676892016-11-16 14:55:21 +01001267 x.send(IPA().id_ack())
Max49364482016-04-13 11:36:39 +02001268 elif "0001fe00" == s:
1269 if (verbose):
1270 print "\tBSC <- NAT: PONG!"
1271 else:
1272 if (verbose):
1273 print "\tBSC <- NAT: ", s
1274
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001275def ipa_handle_resp(x, tk, verbose = False, proc=None):
Max49364482016-04-13 11:36:39 +02001276 s = data2str(x.recv(38))
1277 if "0023fe040108010701020103010401050101010011" in s:
Neels Hofmeyr7d17c3e2017-01-26 23:04:28 +01001278 retries = 3
1279 while True:
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001280 if proc:
1281 print "\tproc.poll() = %r" % proc.poll()
1282 print "\tproc.pid = %r" % proc.pid
1283 checkxxx()
Neels Hofmeyr7d17c3e2017-01-26 23:04:28 +01001284 print "\tsending IPA identity(%s) at %s" % (tk, time.strftime("%T"))
1285 try:
1286 x.send(IPA().id_resp(IPA().identity(name = tk.encode('utf-8'))))
1287 print "\tdone sending IPA identity(%s) at %s" % (tk,
1288 time.strftime("%T"))
1289 break
1290 except:
1291 print "\tfailed sending IPA identity at", time.strftime("%T")
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001292 if proc:
1293 print "\tproc.poll() = %r" % proc.poll()
Neels Hofmeyr7d17c3e2017-01-26 23:04:28 +01001294 if retries < 1:
1295 print "\tgiving up"
1296 raise
Neels Hofmeyre02e1e72017-02-03 05:55:26 +01001297 print "\tretrying (%d attempts left)" % retries
Neels Hofmeyr7d17c3e2017-01-26 23:04:28 +01001298 retries -= 1
Max49364482016-04-13 11:36:39 +02001299 else:
1300 if (verbose):
1301 print "\tBSC <- NAT: ", s
1302
1303def nat_bsc_num_con(x):
1304 return len(x.vty.command("show bsc connections").split('\n'))
1305
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001306def nat_bsc_sock_test(nr, tk, verbose = False, proc=None):
Max49364482016-04-13 11:36:39 +02001307 bsc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Holger Hans Peter Freyther2abf2b02016-04-14 21:13:51 -04001308 bsc.bind(('127.0.0.1', 0))
Max49364482016-04-13 11:36:39 +02001309 bsc.connect(('127.0.0.1', 5000))
1310 if (verbose):
1311 print "BSC%d " %nr
1312 print "\tconnected to %s:%d" % bsc.getpeername()
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001313 if proc:
1314 print "\tproc.poll() = %r" % proc.poll()
1315 print "\tproc.pid = %r" % proc.pid
1316 checkxxx()
Max49364482016-04-13 11:36:39 +02001317 ipa_handle_small(bsc, verbose)
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001318 checkxxx()
1319 ipa_handle_resp(bsc, tk, verbose, proc=proc)
1320 if proc:
1321 print "\tproc.poll() = %r" % proc.poll()
1322 checkxxx()
Max49364482016-04-13 11:36:39 +02001323 bsc.recv(27) # MGCP msg
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001324 if proc:
1325 print "\tproc.poll() = %r" % proc.poll()
1326 checkxxx()
Max49364482016-04-13 11:36:39 +02001327 ipa_handle_small(bsc, verbose)
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001328 checkxxx()
Max49364482016-04-13 11:36:39 +02001329 return bsc
1330
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001331def add_bsc_test(suite, workdir):
1332 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")):
1333 print("Skipping the BSC test")
1334 return
1335 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC)
1336 suite.addTest(test)
1337
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001338def add_gbproxy_test(suite, workdir):
1339 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-gbproxy")):
1340 print("Skipping the Gb-Proxy test")
1341 return
1342 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYGbproxy)
1343 suite.addTest(test)
1344
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001345def add_sgsn_test(suite, workdir):
1346 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-sgsn")):
1347 print("Skipping the SGSN test")
1348 return
1349 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYSGSN)
1350 suite.addTest(test)
1351
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001352if __name__ == '__main__':
1353 import argparse
1354 import sys
1355
1356 workdir = '.'
1357
1358 parser = argparse.ArgumentParser()
1359 parser.add_argument("-v", "--verbose", dest="verbose",
1360 action="store_true", help="verbose mode")
1361 parser.add_argument("-p", "--pythonconfpath", dest="p",
1362 help="searchpath for config")
1363 parser.add_argument("-w", "--workdir", dest="w",
1364 help="Working directory")
1365 args = parser.parse_args()
1366
1367 verbose_level = 1
1368 if args.verbose:
1369 verbose_level = 2
1370
1371 if args.w:
1372 workdir = args.w
1373
1374 if args.p:
1375 confpath = args.p
1376
1377 print "confpath %s, workdir %s" % (confpath, workdir)
1378 os.chdir(workdir)
1379 print "Running tests for specific VTY commands"
1380 suite = unittest.TestSuite()
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +02001381 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYMGCP))
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +02001382 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB))
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001383 add_bsc_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001384 add_nat_test(suite, workdir)
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001385 add_gbproxy_test(suite, workdir)
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001386 add_sgsn_test(suite, workdir)
Neels Hofmeyr0a45c1e2016-09-28 23:48:02 +02001387 res = unittest.TextTestRunner(verbosity=verbose_level, stream=sys.stdout).run(suite)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001388 sys.exit(len(res.errors) + len(res.failures))
Neels Hofmeyr23d37c92016-09-26 03:18:32 +02001389
Neels Hofmeyr0867b722016-09-28 23:28:06 +02001390# vim: shiftwidth=4 expandtab nocin ai