blob: f434360822e720c1154d5bc63f3c64544e1cdacf [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):
60 self.vty = None
61 osmoutil.end_proc(self.proc)
62
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +020063class TestVTYMGCP(TestVTYBase):
64 def vty_command(self):
65 return ["./src/osmo-bsc_mgcp/osmo-bsc_mgcp", "-c",
66 "doc/examples/osmo-bsc_mgcp/mgcp.cfg"]
67
68 def vty_app(self):
69 return (4243, "./src/osmo-bsc_mgcp/osmo-bsc_mgcp", "OpenBSC MGCP", "mgcp")
70
71 def testForcePtime(self):
Neels Hofmeyr0867b722016-09-28 23:28:06 +020072 self.vty.enable()
73 res = self.vty.command("show running-config")
74 self.assert_(res.find(' rtp force-ptime 20\r') > 0)
75 self.assertEquals(res.find(' no rtp force-ptime\r'), -1)
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +020076
Neels Hofmeyr0867b722016-09-28 23:28:06 +020077 self.vty.command("configure terminal")
78 self.vty.command("mgcp")
79 self.vty.command("no rtp force-ptime")
80 res = self.vty.command("show running-config")
81 self.assertEquals(res.find(' rtp force-ptime 20\r'), -1)
82 self.assertEquals(res.find(' no rtp force-ptime\r'), -1)
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +020083
Holger Hans Peter Freyther619b0142014-11-19 16:04:45 +010084 def testOmitAudio(self):
85 self.vty.enable()
Neels Hofmeyr0867b722016-09-28 23:28:06 +020086 res = self.vty.command("show running-config")
87 self.assert_(res.find(' sdp audio-payload send-name\r') > 0)
88 self.assertEquals(res.find(' no sdp audio-payload send-name\r'), -1)
Holger Hans Peter Freyther619b0142014-11-19 16:04:45 +010089
Neels Hofmeyr0867b722016-09-28 23:28:06 +020090 self.vty.command("configure terminal")
91 self.vty.command("mgcp")
92 self.vty.command("no sdp audio-payload send-name")
93 res = self.vty.command("show running-config")
94 self.assertEquals(res.find(' rtp sdp audio-payload send-name\r'), -1)
95 self.assert_(res.find(' no sdp audio-payload send-name\r') > 0)
Holger Hans Peter Freyther619b0142014-11-19 16:04:45 +010096
97 # TODO: test it for the trunk!
98
Holger Hans Peter Freytherc390ae82015-08-20 15:15:50 +020099 def testBindAddr(self):
100 self.vty.enable()
101
Neels Hofmeyr0867b722016-09-28 23:28:06 +0200102 self.vty.command("configure terminal")
103 self.vty.command("mgcp")
Holger Hans Peter Freytherc390ae82015-08-20 15:15:50 +0200104
105 # enable.. disable bts-bind-ip
106 self.vty.command("rtp bts-bind-ip 254.253.252.250")
107 res = self.vty.command("show running-config")
108 self.assert_(res.find('rtp bts-bind-ip 254.253.252.250') > 0)
109 self.vty.command("no rtp bts-bind-ip")
110 res = self.vty.command("show running-config")
111 self.assertEquals(res.find(' rtp bts-bind-ip'), -1)
112
113 # enable.. disable net-bind-ip
114 self.vty.command("rtp net-bind-ip 254.253.252.250")
115 res = self.vty.command("show running-config")
116 self.assert_(res.find('rtp net-bind-ip 254.253.252.250') > 0)
117 self.vty.command("no rtp net-bind-ip")
118 res = self.vty.command("show running-config")
119 self.assertEquals(res.find(' rtp net-bind-ip'), -1)
120
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200121
122class TestVTYGenericBSC(TestVTYBase):
123
124 def checkForEndAndExit(self):
125 res = self.vty.command("list")
126 #print ('looking for "exit"\n')
127 self.assert_(res.find(' exit\r') > 0)
128 #print 'found "exit"\nlooking for "end"\n'
129 self.assert_(res.find(' end\r') > 0)
130 #print 'found "end"\n'
131
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200132 def _testConfigNetworkTree(self):
133 self.vty.enable()
134 self.assertTrue(self.vty.verify("configure terminal",['']))
135 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100136 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200137 self.assertTrue(self.vty.verify("network",['']))
138 self.assertEquals(self.vty.node(), 'config-net')
139 self.checkForEndAndExit()
140 self.assertTrue(self.vty.verify("bts 0",['']))
141 self.assertEquals(self.vty.node(), 'config-net-bts')
142 self.checkForEndAndExit()
143 self.assertTrue(self.vty.verify("trx 0",['']))
144 self.assertEquals(self.vty.node(), 'config-net-bts-trx')
145 self.checkForEndAndExit()
Jacob Erlbeck733bec82013-09-11 10:46:56 +0200146 self.vty.command("write terminal")
147 self.assertTrue(self.vty.verify("exit",['']))
148 self.assertEquals(self.vty.node(), 'config-net-bts')
149 self.assertTrue(self.vty.verify("exit",['']))
150 self.assertTrue(self.vty.verify("bts 1",['']))
151 self.assertEquals(self.vty.node(), 'config-net-bts')
152 self.checkForEndAndExit()
153 self.assertTrue(self.vty.verify("trx 1",['']))
154 self.assertEquals(self.vty.node(), 'config-net-bts-trx')
155 self.checkForEndAndExit()
156 self.vty.command("write terminal")
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200157 self.assertTrue(self.vty.verify("exit",['']))
158 self.assertEquals(self.vty.node(), 'config-net-bts')
159 self.assertTrue(self.vty.verify("exit",['']))
160 self.assertEquals(self.vty.node(), 'config-net')
161 self.assertTrue(self.vty.verify("exit",['']))
162 self.assertEquals(self.vty.node(), 'config')
163 self.assertTrue(self.vty.verify("exit",['']))
164 self.assertTrue(self.vty.node() is None)
165
166class TestVTYNITB(TestVTYGenericBSC):
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200167
168 def vty_command(self):
169 return ["./src/osmo-nitb/osmo-nitb", "-c",
170 "doc/examples/osmo-nitb/nanobts/openbsc.cfg"]
171
172 def vty_app(self):
173 return (4242, "./src/osmo-nitb/osmo-nitb", "OpenBSC", "nitb")
174
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200175 def testConfigNetworkTree(self):
Jacob Erlbeck75877272013-10-23 11:24:14 +0200176 self._testConfigNetworkTree()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200177
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200178 def checkForSmpp(self):
179 """SMPP is not always enabled, check if it is"""
180 res = self.vty.command("list")
181 return "smpp" in res
182
Holger Hans Peter Freyther42cf2e02015-07-06 16:41:30 +0200183 def testSmppFirst(self):
Holger Hans Peter Freyther42cf2e02015-07-06 16:41:30 +0200184 # enable the configuration
185 self.vty.enable()
186 self.vty.command("configure terminal")
Holger Hans Peter Freythera2c41c42015-07-13 11:23:53 +0200187
188 if not self.checkForSmpp():
189 return
190
Holger Hans Peter Freyther42cf2e02015-07-06 16:41:30 +0200191 self.vty.command("smpp")
192
193 # check the default
194 res = self.vty.command("write terminal")
195 self.assert_(res.find(' no smpp-first') > 0)
196
197 self.vty.verify("smpp-first", [''])
198 res = self.vty.command("write terminal")
199 self.assert_(res.find(' smpp-first') > 0)
200 self.assertEquals(res.find('no smpp-first'), -1)
201
202 self.vty.verify("no smpp-first", [''])
203 res = self.vty.command("write terminal")
204 self.assert_(res.find('no smpp-first') > 0)
205
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200206 def testVtyTree(self):
207 self.vty.enable()
208 self.assertTrue(self.vty.verify("configure terminal", ['']))
209 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100210 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200211 self.assertTrue(self.vty.verify('mncc-int', ['']))
212 self.assertEquals(self.vty.node(), 'config-mncc-int')
213 self.checkForEndAndExit()
214 self.assertTrue(self.vty.verify('exit', ['']))
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200215
216 if self.checkForSmpp():
217 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck75877272013-10-23 11:24:14 +0200218 self.assertTrue(self.vty.verify('smpp', ['']))
219 self.assertEquals(self.vty.node(), 'config-smpp')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100220 self.checkForEndAndExit()
Jacob Erlbeck75877272013-10-23 11:24:14 +0200221 self.assertTrue(self.vty.verify("exit", ['']))
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200222
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200223 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200224 self.assertTrue(self.vty.verify("exit", ['']))
225 self.assertTrue(self.vty.node() is None)
226
227 # Check searching for outer node's commands
228 self.vty.command("configure terminal")
229 self.vty.command('mncc-int')
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200230
231 if self.checkForSmpp():
232 self.vty.command('smpp')
233 self.assertEquals(self.vty.node(), 'config-smpp')
234 self.vty.command('mncc-int')
235
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200236 self.assertEquals(self.vty.node(), 'config-mncc-int')
237
Maxddee01f2016-05-24 14:23:27 +0200238 def testVtyAuthorization(self):
239 self.vty.enable()
240 self.vty.command("configure terminal")
241 self.vty.command("network")
242 self.assertTrue(self.vty.verify("auth policy closed", ['']))
243 self.assertTrue(self.vty.verify("auth policy regexp", ['']))
244 self.assertTrue(self.vty.verify("authorized-regexp ^001", ['']))
245 self.assertTrue(self.vty.verify("authorized-regexp 02$", ['']))
246 self.assertTrue(self.vty.verify("authorized-regexp *123.*", ['']))
247 self.vty.command("end")
248 self.vty.command("configure terminal")
249 self.vty.command("nitb")
250 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
Maxe6052c42016-06-30 10:25:49 +0200251 self.assertTrue(self.vty.verify("subscriber-create-on-demand no-extension", ['']))
Maxddee01f2016-05-24 14:23:27 +0200252 self.vty.command("end")
253
Max0c1bc262016-04-20 12:06:06 +0200254 def testSi2Q(self):
255 self.vty.enable()
256 self.vty.command("configure terminal")
257 self.vty.command("network")
258 self.vty.command("bts 0")
259 before = self.vty.command("show running-config")
260 self.vty.command("si2quater neighbor-list add earfcn 1911 threshold 11 2")
261 self.vty.command("si2quater neighbor-list add earfcn 1924 threshold 11 3")
262 self.vty.command("si2quater neighbor-list add earfcn 2111 threshold 11")
263 self.vty.command("si2quater neighbor-list del earfcn 1911")
264 self.vty.command("si2quater neighbor-list del earfcn 1924")
265 self.vty.command("si2quater neighbor-list del earfcn 2111")
266 self.assertEquals(before, self.vty.command("show running-config"))
Max26679e02016-04-20 15:57:13 +0200267 self.vty.command("si2quater neighbor-list add uarfcn 1976 13 1")
268 self.vty.command("si2quater neighbor-list add uarfcn 1976 38 1")
269 self.vty.command("si2quater neighbor-list add uarfcn 1976 44 1")
270 self.vty.command("si2quater neighbor-list add uarfcn 1976 120 1")
271 self.vty.command("si2quater neighbor-list add uarfcn 1976 140 1")
272 self.vty.command("si2quater neighbor-list add uarfcn 1976 163 1")
273 self.vty.command("si2quater neighbor-list add uarfcn 1976 166 1")
274 self.vty.command("si2quater neighbor-list add uarfcn 1976 217 1")
275 self.vty.command("si2quater neighbor-list add uarfcn 1976 224 1")
276 self.vty.command("si2quater neighbor-list add uarfcn 1976 225 1")
277 self.vty.command("si2quater neighbor-list add uarfcn 1976 226 1")
278 self.vty.command("si2quater neighbor-list del uarfcn 1976 13")
279 self.vty.command("si2quater neighbor-list del uarfcn 1976 38")
280 self.vty.command("si2quater neighbor-list del uarfcn 1976 44")
281 self.vty.command("si2quater neighbor-list del uarfcn 1976 120")
282 self.vty.command("si2quater neighbor-list del uarfcn 1976 140")
283 self.vty.command("si2quater neighbor-list del uarfcn 1976 163")
284 self.vty.command("si2quater neighbor-list del uarfcn 1976 166")
285 self.vty.command("si2quater neighbor-list del uarfcn 1976 217")
286 self.vty.command("si2quater neighbor-list del uarfcn 1976 224")
287 self.vty.command("si2quater neighbor-list del uarfcn 1976 225")
288 self.vty.command("si2quater neighbor-list del uarfcn 1976 226")
289 self.assertEquals(before, self.vty.command("show running-config"))
Max0c1bc262016-04-20 12:06:06 +0200290
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200291 def testEnableDisablePeriodicLU(self):
292 self.vty.enable()
293 self.vty.command("configure terminal")
294 self.vty.command("network")
295 self.vty.command("bts 0")
296
297 # Test invalid input
298 self.vty.verify("periodic location update 0", ['% Unknown command.'])
299 self.vty.verify("periodic location update 5", ['% Unknown command.'])
300 self.vty.verify("periodic location update 1531", ['% Unknown command.'])
301
302 # Enable periodic lu..
303 self.vty.verify("periodic location update 60", [''])
304 res = self.vty.command("write terminal")
Holger Hans Peter Freytherc0438e32013-07-27 22:23:25 +0200305 self.assert_(res.find('periodic location update 60') > 0)
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200306 self.assertEquals(res.find('no periodic location update'), -1)
307
308 # Now disable it..
309 self.vty.verify("no periodic location update", [''])
310 res = self.vty.command("write terminal")
311 self.assertEquals(res.find('periodic location update 60'), -1)
Holger Hans Peter Freytherc0438e32013-07-27 22:23:25 +0200312 self.assert_(res.find('no periodic location update') > 0)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200313
Jacob Erlbeck65d114f2014-01-16 11:02:14 +0100314 def testEnableDisableSiHacks(self):
315 self.vty.enable()
316 self.vty.command("configure terminal")
317 self.vty.command("network")
318 self.vty.command("bts 0")
319
320 # Enable periodic lu..
321 self.vty.verify("force-combined-si", [''])
322 res = self.vty.command("write terminal")
323 self.assert_(res.find(' force-combined-si') > 0)
324 self.assertEquals(res.find('no force-combined-si'), -1)
325
326 # Now disable it..
327 self.vty.verify("no force-combined-si", [''])
328 res = self.vty.command("write terminal")
329 self.assertEquals(res.find(' force-combined-si'), -1)
330 self.assert_(res.find('no force-combined-si') > 0)
331
Ivan Kluchnikov67920592013-09-16 13:13:04 +0400332 def testRachAccessControlClass(self):
333 self.vty.enable()
334 self.vty.command("configure terminal")
335 self.vty.command("network")
336 self.vty.command("bts 0")
337
338 # Test invalid input
339 self.vty.verify("rach access-control-class", ['% Command incomplete.'])
340 self.vty.verify("rach access-control-class 1", ['% Command incomplete.'])
341 self.vty.verify("rach access-control-class -1", ['% Unknown command.'])
342 self.vty.verify("rach access-control-class 10", ['% Unknown command.'])
343 self.vty.verify("rach access-control-class 16", ['% Unknown command.'])
344
345 # Barred rach access control classes
346 for classNum in range(16):
347 if classNum != 10:
348 self.vty.verify("rach access-control-class " + str(classNum) + " barred", [''])
349
350 # Verify settings
351 res = self.vty.command("write terminal")
352 for classNum in range(16):
353 if classNum != 10:
354 self.assert_(res.find("rach access-control-class " + str(classNum) + " barred") > 0)
355
356 # Allowed rach access control classes
357 for classNum in range(16):
358 if classNum != 10:
359 self.vty.verify("rach access-control-class " + str(classNum) + " allowed", [''])
360
361 # Verify settings
362 res = self.vty.command("write terminal")
363 for classNum in range(16):
364 if classNum != 10:
365 self.assertEquals(res.find("rach access-control-class " + str(classNum) + " barred"), -1)
366
Holger Hans Peter Freytherde392252016-04-01 19:44:00 +0200367 def testSubscriberCreateDeleteTwice(self):
368 """
369 OS#1657 indicates that there might be an issue creating the
370 same subscriber twice. This test will use the VTY command to
371 create a subscriber and then issue a second create command
372 with the same IMSI. The test passes if the VTY continues to
373 respond to VTY commands.
374 """
375 self.vty.enable()
376
377 imsi = "204300854013739"
378
379 # Initially we don't have this subscriber
380 self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi])
381
382 # Lets create one
383 res = self.vty.command('subscriber create imsi '+imsi)
384 self.assert_(res.find(" IMSI: "+imsi) > 0)
385 # And now create one again.
386 res2 = self.vty.command('subscriber create imsi '+imsi)
387 self.assert_(res2.find(" IMSI: "+imsi) > 0)
388 self.assertEqual(res, res2)
389
390 # Verify it has been created
391 res = self.vty.command('show subscriber imsi '+imsi)
392 self.assert_(res.find(" IMSI: "+imsi) > 0)
393
394 # Delete it
Max488902d2016-06-22 14:02:39 +0200395 res = self.vty.command('subscriber imsi ' + imsi + ' delete')
396 self.assert_("" == res)
Holger Hans Peter Freytherde392252016-04-01 19:44:00 +0200397
398 # Now it should not be there anymore
399 res = self.vty.command('show subscriber imsi '+imsi)
Max488902d2016-06-22 14:02:39 +0200400 self.assert_(('% No subscriber found for imsi ' + imsi) == res)
Holger Hans Peter Freytherde392252016-04-01 19:44:00 +0200401
402
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500403 def testSubscriberCreateDelete(self):
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200404 self.vty.enable()
405
406 imsi = "204300854013739"
Maxe6052c42016-06-30 10:25:49 +0200407 imsi2 = "222301824913762"
408 imsi3 = "333500854113763"
409 imsi4 = "444583744053764"
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200410
411 # Initially we don't have this subscriber
412 self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi])
413
414 # Lets create one
415 res = self.vty.command('subscriber create imsi '+imsi)
416 self.assert_(res.find(" IMSI: "+imsi) > 0)
Maxe6052c42016-06-30 10:25:49 +0200417 self.assert_(res.find("Extension") > 0)
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200418
419 # Now we have it
420 res = self.vty.command('show subscriber imsi '+imsi)
421 self.assert_(res.find(" IMSI: "+imsi) > 0)
422
Maxe6052c42016-06-30 10:25:49 +0200423 # With narrow random interval
424 self.vty.command("configure terminal")
425 self.vty.command("nitb")
426 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
427 # wrong interval
428 res = self.vty.command("subscriber-create-on-demand random 221 122")
429 # error string will contain arguments
430 self.assert_(res.find("122") > 0)
431 self.assert_(res.find("221") > 0)
432 # correct interval - silent ok
433 self.assertTrue(self.vty.verify("subscriber-create-on-demand random 221 222", ['']))
434 self.vty.command("end")
435
436 res = self.vty.command('subscriber create imsi ' + imsi2)
437 self.assert_(res.find(" IMSI: " + imsi2) > 0)
438 self.assert_(res.find("221") > 0 or res.find("222") > 0)
439 self.assert_(res.find(" Extension: ") > 0)
440
441 # Without extension
442 self.vty.command("configure terminal")
443 self.vty.command("nitb")
444 self.assertTrue(self.vty.verify("subscriber-create-on-demand no-extension", ['']))
445 self.vty.command("end")
446 res = self.vty.command('subscriber create imsi ' + imsi3)
447 self.assert_(res.find(" IMSI: " + imsi3) > 0)
448 self.assertEquals(res.find("Extension"), -1)
449
450 # With extension again
451 self.vty.command("configure terminal")
452 self.vty.command("nitb")
453 self.assertTrue(self.vty.verify("no subscriber-create-on-demand", ['']))
454 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
455 self.assertTrue(self.vty.verify("subscriber-create-on-demand random 221 666", ['']))
456 self.vty.command("end")
457
458 res = self.vty.command('subscriber create imsi ' + imsi4)
459 self.assert_(res.find(" IMSI: " + imsi4) > 0)
460 self.assert_(res.find(" Extension: ") > 0)
461
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500462 # Delete it
Max488902d2016-06-22 14:02:39 +0200463 res = self.vty.command('subscriber imsi ' + imsi + ' delete')
464 self.assert_("" == res)
Maxe6052c42016-06-30 10:25:49 +0200465 res = self.vty.command('subscriber imsi ' + imsi2 + ' delete')
466 self.assert_("" == res)
467 res = self.vty.command('subscriber imsi ' + imsi3 + ' delete')
468 self.assert_("" == res)
469 res = self.vty.command('subscriber imsi ' + imsi4 + ' delete')
470 self.assert_("" == res)
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500471
472 # Now it should not be there anymore
473 res = self.vty.command('show subscriber imsi '+imsi)
Max488902d2016-06-22 14:02:39 +0200474 self.assert_(('% No subscriber found for imsi ' + imsi) == res)
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500475
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200476 def testSubscriberSettings(self):
477 self.vty.enable()
478
479 imsi = "204300854013739"
Max0fcd2e22016-06-07 15:32:16 +0200480 imsi2 = "204301824913769"
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200481 wrong_imsi = "204300999999999"
482
483 # Lets create one
484 res = self.vty.command('subscriber create imsi '+imsi)
485 self.assert_(res.find(" IMSI: "+imsi) > 0)
Max0fcd2e22016-06-07 15:32:16 +0200486 self.assert_(res.find("Extension") > 0)
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200487
488 self.vty.verify('subscriber imsi '+wrong_imsi+' name wrong', ['% No subscriber found for imsi '+wrong_imsi])
489 res = self.vty.command('subscriber imsi '+imsi+' name '+('X' * 160))
490 self.assert_(res.find("NAME is too long") > 0)
491
492 self.vty.verify('subscriber imsi '+imsi+' name '+('G' * 159), [''])
493
494 self.vty.verify('subscriber imsi '+wrong_imsi+' extension 840', ['% No subscriber found for imsi '+wrong_imsi])
495 res = self.vty.command('subscriber imsi '+imsi+' extension '+('9' * 15))
496 self.assert_(res.find("EXTENSION is too long") > 0)
497
498 self.vty.verify('subscriber imsi '+imsi+' extension '+('1' * 14), [''])
499
Max0fcd2e22016-06-07 15:32:16 +0200500 # With narrow random interval
501 self.vty.command("configure terminal")
502 self.vty.command("nitb")
503 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
504 # wrong interval
505 res = self.vty.command("subscriber-create-on-demand random 221 122")
506 self.assert_(res.find("122") > 0)
507 self.assert_(res.find("221") > 0)
508 # correct interval
509 self.assertTrue(self.vty.verify("subscriber-create-on-demand random 221 222", ['']))
510 self.vty.command("end")
511
Max488902d2016-06-22 14:02:39 +0200512 # create subscriber with extension in a configured interval
Max0fcd2e22016-06-07 15:32:16 +0200513 res = self.vty.command('subscriber create imsi ' + imsi2)
514 self.assert_(res.find(" IMSI: " + imsi2) > 0)
515 self.assert_(res.find("221") > 0 or res.find("222") > 0)
516 self.assert_(res.find(" Extension: ") > 0)
517
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200518 # Delete it
Max488902d2016-06-22 14:02:39 +0200519 res = self.vty.command('subscriber imsi ' + imsi + ' delete')
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200520 self.assert_(res != "")
Max488902d2016-06-22 14:02:39 +0200521 # imsi2 is inactive so deletion should succeed
522 res = self.vty.command('subscriber imsi ' + imsi2 + ' delete')
523 self.assert_("" == res)
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200524
Holger Hans Peter Freytherec37bb22013-02-05 09:39:09 +0100525 def testShowPagingGroup(self):
526 res = self.vty.command("show paging-group 255 1234567")
527 self.assertEqual(res, "% can't find BTS 255")
528 res = self.vty.command("show paging-group 0 1234567")
529 self.assertEquals(res, "%Paging group for IMSI 1234567 on BTS #0 is 7")
530
Ciabyec6e4f82014-03-06 17:20:55 +0100531 def testShowNetwork(self):
532 res = self.vty.command("show network")
533 self.assert_(res.startswith('BSC is on Country Code') >= 0)
534
Holger Hans Peter Freyther86573262015-01-31 09:47:37 +0100535 def testMeasurementFeed(self):
536 self.vty.enable()
537 self.vty.command("configure terminal")
538 self.vty.command("mncc-int")
539
540 res = self.vty.command("write terminal")
541 self.assertEquals(res.find('meas-feed scenario'), -1)
542
543 self.vty.command("meas-feed scenario bla")
544 res = self.vty.command("write terminal")
545 self.assert_(res.find('meas-feed scenario bla') > 0)
546
Neels Hofmeyr0867b722016-09-28 23:28:06 +0200547 self.vty.command("meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890")
Holger Hans Peter Freyther86573262015-01-31 09:47:37 +0100548 res = self.vty.command("write terminal")
549 self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890'), -1)
550 self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz012345'), -1)
551 self.assert_(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234') > 0)
552
553
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200554class TestVTYBSC(TestVTYGenericBSC):
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200555
556 def vty_command(self):
557 return ["./src/osmo-bsc/osmo-bsc", "-c",
558 "doc/examples/osmo-bsc/osmo-bsc.cfg"]
559
560 def vty_app(self):
561 return (4242, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc")
562
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200563 def testConfigNetworkTree(self):
Jacob Erlbeck75877272013-10-23 11:24:14 +0200564 self._testConfigNetworkTree()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200565
566 def testVtyTree(self):
567 self.vty.enable()
568 self.assertTrue(self.vty.verify("configure terminal", ['']))
569 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100570 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200571 self.assertTrue(self.vty.verify("msc 0", ['']))
572 self.assertEquals(self.vty.node(), 'config-msc')
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200573 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200574 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200575 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200576 self.assertTrue(self.vty.verify("bsc", ['']))
577 self.assertEquals(self.vty.node(), 'config-bsc')
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200578 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200579 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200580 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200581 self.assertTrue(self.vty.verify("exit", ['']))
582 self.assertTrue(self.vty.node() is None)
583
584 # Check searching for outer node's commands
585 self.vty.command("configure terminal")
586 self.vty.command('msc 0')
587 self.vty.command("bsc")
588 self.assertEquals(self.vty.node(), 'config-bsc')
589 self.vty.command("msc 0")
590 self.assertEquals(self.vty.node(), 'config-msc')
591
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200592 def testUssdNotificationsMsc(self):
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200593 self.vty.enable()
594 self.vty.command("configure terminal")
595 self.vty.command("msc")
596
597 # Test invalid input
598 self.vty.verify("bsc-msc-lost-text", ['% Command incomplete.'])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200599 self.vty.verify("bsc-welcome-text", ['% Command incomplete.'])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200600 self.vty.verify("bsc-grace-text", ['% Command incomplete.'])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200601
602 # Enable USSD notifications
603 self.vty.verify("bsc-msc-lost-text MSC disconnected", [''])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200604 self.vty.verify("bsc-welcome-text Hello MS", [''])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200605 self.vty.verify("bsc-grace-text In grace period", [''])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200606
607 # Verify settings
608 res = self.vty.command("write terminal")
609 self.assert_(res.find('bsc-msc-lost-text MSC disconnected') > 0)
610 self.assertEquals(res.find('no bsc-msc-lost-text'), -1)
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200611 self.assert_(res.find('bsc-welcome-text Hello MS') > 0)
612 self.assertEquals(res.find('no bsc-welcome-text'), -1)
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200613 self.assert_(res.find('bsc-grace-text In grace period') > 0)
614 self.assertEquals(res.find('no bsc-grace-text'), -1)
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200615
616 # Now disable it..
617 self.vty.verify("no bsc-msc-lost-text", [''])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200618 self.vty.verify("no bsc-welcome-text", [''])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200619 self.vty.verify("no bsc-grace-text", [''])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200620
621 # Verify settings
622 res = self.vty.command("write terminal")
623 self.assertEquals(res.find('bsc-msc-lost-text MSC disconnected'), -1)
624 self.assert_(res.find('no bsc-msc-lost-text') > 0)
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200625 self.assertEquals(res.find('bsc-welcome-text Hello MS'), -1)
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200626 self.assert_(res.find('no bsc-welcome-text') > 0)
627 self.assertEquals(res.find('bsc-grace-text In grace period'), -1)
628 self.assert_(res.find('no bsc-grace-text') > 0)
629
630 def testUssdNotificationsBsc(self):
631 self.vty.enable()
632 self.vty.command("configure terminal")
633 self.vty.command("bsc")
634
635 # Test invalid input
636 self.vty.verify("missing-msc-text", ['% Command incomplete.'])
637
638 # Enable USSD notifications
639 self.vty.verify("missing-msc-text No MSC found", [''])
640
641 # Verify settings
642 res = self.vty.command("write terminal")
643 self.assert_(res.find('missing-msc-text No MSC found') > 0)
644 self.assertEquals(res.find('no missing-msc-text'), -1)
645
646 # Now disable it..
647 self.vty.verify("no missing-msc-text", [''])
648
649 # Verify settings
650 res = self.vty.command("write terminal")
651 self.assertEquals(res.find('missing-msc-text No MSC found'), -1)
652 self.assert_(res.find('no missing-msc-text') > 0)
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200653
Jacob Erlbeck946d1412013-09-17 13:59:29 +0200654 def testNetworkTimezone(self):
655 self.vty.enable()
656 self.vty.verify("configure terminal", [''])
657 self.vty.verify("network", [''])
Jacob Erlbeck946d1412013-09-17 13:59:29 +0200658
659 # Test invalid input
660 self.vty.verify("timezone", ['% Command incomplete.'])
661 self.vty.verify("timezone 20 0", ['% Unknown command.'])
662 self.vty.verify("timezone 0 11", ['% Unknown command.'])
663 self.vty.verify("timezone 0 0 99", ['% Unknown command.'])
664
665 # Set time zone without DST
666 self.vty.verify("timezone 2 30", [''])
667
668 # Verify settings
669 res = self.vty.command("write terminal")
670 self.assert_(res.find('timezone 2 30') > 0)
671 self.assertEquals(res.find('timezone 2 30 '), -1)
672
673 # Set time zone with DST
674 self.vty.verify("timezone 2 30 1", [''])
675
676 # Verify settings
677 res = self.vty.command("write terminal")
678 self.assert_(res.find('timezone 2 30 1') > 0)
679
680 # Now disable it..
681 self.vty.verify("no timezone", [''])
682
683 # Verify settings
684 res = self.vty.command("write terminal")
685 self.assertEquals(res.find(' timezone'), -1)
686
Ciabyec6e4f82014-03-06 17:20:55 +0100687 def testShowNetwork(self):
688 res = self.vty.command("show network")
689 self.assert_(res.startswith('BSC is on Country Code') >= 0)
690
Holger Hans Peter Freytherdb64f2e2014-10-29 10:06:15 +0100691 def testPingPongConfiguration(self):
692 self.vty.enable()
693 self.vty.verify("configure terminal", [''])
694 self.vty.verify("network", [''])
695 self.vty.verify("msc 0", [''])
696
697 self.vty.verify("timeout-ping 12", [''])
698 self.vty.verify("timeout-pong 14", [''])
699 res = self.vty.command("show running-config")
700 self.assert_(res.find(" timeout-ping 12") > 0)
701 self.assert_(res.find(" timeout-pong 14") > 0)
702 self.assert_(res.find(" no timeout-ping advanced") > 0)
703
704 self.vty.verify("timeout-ping advanced", [''])
705 res = self.vty.command("show running-config")
706 self.assert_(res.find(" timeout-ping 12") > 0)
707 self.assert_(res.find(" timeout-pong 14") > 0)
708 self.assert_(res.find(" timeout-ping advanced") > 0)
709
710 self.vty.verify("no timeout-ping advanced", [''])
711 res = self.vty.command("show running-config")
712 self.assert_(res.find(" timeout-ping 12") > 0)
713 self.assert_(res.find(" timeout-pong 14") > 0)
714 self.assert_(res.find(" no timeout-ping advanced") > 0)
715
716 self.vty.verify("no timeout-ping", [''])
717 res = self.vty.command("show running-config")
718 self.assertEquals(res.find(" timeout-ping 12"), -1)
719 self.assertEquals(res.find(" timeout-pong 14"), -1)
720 self.assertEquals(res.find(" no timeout-ping advanced"), -1)
721 self.assert_(res.find(" no timeout-ping") > 0)
722
723 self.vty.verify("timeout-ping advanced", ['%ping handling is disabled. Enable it first.'])
724
725 # And back to enabling it
726 self.vty.verify("timeout-ping 12", [''])
727 self.vty.verify("timeout-pong 14", [''])
728 res = self.vty.command("show running-config")
729 self.assert_(res.find(" timeout-ping 12") > 0)
730 self.assert_(res.find(" timeout-pong 14") > 0)
731 self.assert_(res.find(" timeout-ping advanced") > 0)
732
Holger Hans Peter Freyther32dd2f32015-04-01 18:15:48 +0200733 def testMscDataCoreLACCI(self):
734 self.vty.enable()
735 res = self.vty.command("show running-config")
736 self.assertEquals(res.find("core-location-area-code"), -1)
737 self.assertEquals(res.find("core-cell-identity"), -1)
738
Neels Hofmeyr0867b722016-09-28 23:28:06 +0200739 self.vty.command("configure terminal")
Holger Hans Peter Freyther32dd2f32015-04-01 18:15:48 +0200740 self.vty.command("msc 0")
741 self.vty.command("core-location-area-code 666")
742 self.vty.command("core-cell-identity 333")
743
744 res = self.vty.command("show running-config")
745 self.assert_(res.find("core-location-area-code 666") > 0)
746 self.assert_(res.find("core-cell-identity 333") > 0)
747
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200748class TestVTYNAT(TestVTYGenericBSC):
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200749
750 def vty_command(self):
Max49364482016-04-13 11:36:39 +0200751 return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-l", "127.0.0.1", "-c",
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200752 "doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"]
753
754 def vty_app(self):
755 return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat")
756
Max49364482016-04-13 11:36:39 +0200757 def testBSCreload(self):
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -0400758 # Use different port for the mock msc to avoid clashing with
759 # the osmo-bsc_nat itself
Holger Hans Peter Freytherf1a61bb2016-04-14 08:50:25 -0400760 ip = "127.0.0.1"
Holger Hans Peter Freythere98c9c72016-04-14 10:58:58 -0400761 port = 5522
Max49364482016-04-13 11:36:39 +0200762 self.vty.enable()
763 bscs1 = self.vty.command("show bscs-config")
764 nat_bsc_reload(self)
765 bscs2 = self.vty.command("show bscs-config")
766 # check that multiple calls to bscs-config-file give the same result
767 self.assertEquals(bscs1, bscs2)
768
769 # add new bsc
770 self.vty.command("configure terminal")
771 self.vty.command("nat")
772 self.vty.command("bsc 5")
773 self.vty.command("token key")
774 self.vty.command("location_area_code 666")
775 self.vty.command("end")
776
777 # update bsc token
778 self.vty.command("configure terminal")
779 self.vty.command("nat")
780 self.vty.command("bsc 1")
781 self.vty.command("token xyu")
782 self.vty.command("end")
783
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -0400784 nat_msc_ip(self, ip, port)
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +0100785 msc = nat_msc_test(self, ip, port, verbose=True)
786 b0 = nat_bsc_sock_test(0, "lol", verbose=True, proc=self.proc)
787 b1 = nat_bsc_sock_test(1, "xyu", verbose=True, proc=self.proc)
788 b2 = nat_bsc_sock_test(5, "key", verbose=True, proc=self.proc)
Max49364482016-04-13 11:36:39 +0200789
790 self.assertEquals("3 BSCs configured", self.vty.command("show nat num-bscs-configured"))
791 self.assertTrue(3 == nat_bsc_num_con(self))
792 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
793
794 nat_bsc_reload(self)
795 bscs2 = self.vty.command("show bscs-config")
796 # check that the reset to initial config succeeded
797 self.assertEquals(bscs1, bscs2)
798
799 self.assertEquals("2 BSCs configured", self.vty.command("show nat num-bscs-configured"))
800 self.assertTrue(1 == nat_bsc_num_con(self))
801 rem = self.vty.command("show bsc connections").split(' ')
802 # remaining connection is for BSC0
803 self.assertEquals('0', rem[2])
804 # remaining connection is authorized
805 self.assertEquals('1', rem[4])
806 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
807
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200808 def testVtyTree(self):
809 self.vty.enable()
810 self.assertTrue(self.vty.verify('configure terminal', ['']))
811 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100812 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200813 self.assertTrue(self.vty.verify('mgcp', ['']))
814 self.assertEquals(self.vty.node(), 'config-mgcp')
815 self.checkForEndAndExit()
816 self.assertTrue(self.vty.verify('exit', ['']))
817 self.assertEquals(self.vty.node(), 'config')
818 self.assertTrue(self.vty.verify('nat', ['']))
819 self.assertEquals(self.vty.node(), 'config-nat')
820 self.checkForEndAndExit()
821 self.assertTrue(self.vty.verify('bsc 0', ['']))
822 self.assertEquals(self.vty.node(), 'config-nat-bsc')
823 self.checkForEndAndExit()
824 self.assertTrue(self.vty.verify('exit', ['']))
825 self.assertEquals(self.vty.node(), 'config-nat')
826 self.assertTrue(self.vty.verify('exit', ['']))
827 self.assertEquals(self.vty.node(), 'config')
828 self.assertTrue(self.vty.verify('exit', ['']))
829 self.assertTrue(self.vty.node() is None)
830
831 # Check searching for outer node's commands
832 self.vty.command('configure terminal')
833 self.vty.command('mgcp')
834 self.vty.command('nat')
835 self.assertEquals(self.vty.node(), 'config-nat')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200836 self.vty.command('mgcp')
837 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200838 self.vty.command('nat')
839 self.assertEquals(self.vty.node(), 'config-nat')
840 self.vty.command('bsc 0')
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
Holger Hans Peter Freytherb718ad32013-06-25 09:08:02 +0200844 def testRewriteNoRewrite(self):
845 self.vty.enable()
846 res = self.vty.command("configure terminal")
847 res = self.vty.command("nat")
848 res = self.vty.command("number-rewrite rewrite.cfg")
849 res = self.vty.command("no number-rewrite")
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200850
Holger Hans Peter Freyther7f100c92015-04-23 20:25:17 -0400851 def testEnsureNoEnsureModeSet(self):
852 self.vty.enable()
853 res = self.vty.command("configure terminal")
854 res = self.vty.command("nat")
855
856 # Ensure the default
857 res = self.vty.command("show running-config")
858 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
859
860 self.vty.command("sdp-ensure-amr-mode-set")
861 res = self.vty.command("show running-config")
862 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
863
864 self.vty.command("no sdp-ensure-amr-mode-set")
865 res = self.vty.command("show running-config")
866 self.assert_(res.find('\n no sdp-ensure-amr-mode-set') > 0)
867
Holger Hans Peter Freyther67e423c2013-06-25 15:38:31 +0200868 def testRewritePostNoRewrite(self):
869 self.vty.enable()
870 self.vty.command("configure terminal")
871 self.vty.command("nat")
872 self.vty.verify("number-rewrite-post rewrite.cfg", [''])
873 self.vty.verify("no number-rewrite-post", [''])
874
875
Holger Hans Peter Freytherddf191e2013-06-25 11:44:01 +0200876 def testPrefixTreeLoading(self):
877 cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv")
878
879 self.vty.enable()
880 self.vty.command("configure terminal")
881 self.vty.command("nat")
882 res = self.vty.command("prefix-tree %s" % cfg)
883 self.assertEqual(res, "% prefix-tree loaded 17 rules.")
884 self.vty.command("end")
885
886 res = self.vty.command("show prefix-tree")
887 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')
888
889 self.vty.command("configure terminal")
890 self.vty.command("nat")
891 self.vty.command("no prefix-tree")
892 self.vty.command("end")
893
894 res = self.vty.command("show prefix-tree")
895 self.assertEqual(res, "% there is now prefix tree loaded.")
896
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200897 def testUssdSideChannelProvider(self):
898 self.vty.command("end")
899 self.vty.enable()
900 self.vty.command("configure terminal")
901 self.vty.command("nat")
902 self.vty.command("ussd-token key")
903 self.vty.command("end")
904
905 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
906 self.assertTrue(res)
907
908 ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
909 ussdSocket.connect(('127.0.0.1', 5001))
910 ussdSocket.settimeout(2.0)
911 print "Connected to %s:%d" % ussdSocket.getpeername()
912
913 print "Expecting ID_GET request"
914 data = ussdSocket.recv(4)
915 self.assertEqual(data, "\x00\x01\xfe\x04")
916
917 print "Going to send ID_RESP response"
Max3e676892016-11-16 14:55:21 +0100918 res = ussdSocket.send(IPA().id_resp(IPA().tag_name('key')))
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200919 self.assertEqual(res, 10)
920
921 # initiating PING/PONG cycle to know, that the ID_RESP message has been processed
922
923 print "Going to send PING request"
Max3e676892016-11-16 14:55:21 +0100924 res = ussdSocket.send(IPA().ping())
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200925 self.assertEqual(res, 4)
926
927 print "Expecting PONG response"
928 data = ussdSocket.recv(4)
929 self.assertEqual(data, "\x00\x01\xfe\x01")
930
931 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.'])
932 self.assertTrue(res)
933
934 print "Going to shut down connection"
935 ussdSocket.shutdown(socket.SHUT_WR)
936
937 print "Expecting EOF"
938 data = ussdSocket.recv(4)
939 self.assertEqual(data, "")
940
941 ussdSocket.close()
942
943 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
944 self.assertTrue(res)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200945
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100946 def testAccessList(self):
947 """
948 Verify that the imsi-deny can have a reject cause or no reject cause
949 """
950 self.vty.enable()
951 self.vty.command("configure terminal")
952 self.vty.command("nat")
953
954 # Old default
955 self.vty.command("access-list test-default imsi-deny ^123[0-9]*$")
956 res = self.vty.command("show running-config").split("\r\n")
957 asserted = False
958 for line in res:
Holger Hans Peter Freyther4ecc6872014-03-04 15:38:00 +0100959 if line.startswith(" access-list test-default"):
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100960 self.assertEqual(line, " access-list test-default imsi-deny ^123[0-9]*$ 11 11")
961 asserted = True
962 self.assert_(asserted)
963
964 # Check the optional CM Service Reject Cause
965 self.vty.command("access-list test-cm-deny imsi-deny ^123[0-9]*$ 42").split("\r\n")
966 res = self.vty.command("show running-config").split("\r\n")
967 asserted = False
968 for line in res:
969 if line.startswith(" access-list test-cm"):
970 self.assertEqual(line, " access-list test-cm-deny imsi-deny ^123[0-9]*$ 42 11")
971 asserted = True
972 self.assert_(asserted)
973
974 # Check the optional LU Reject Cause
975 self.vty.command("access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42").split("\r\n")
976 res = self.vty.command("show running-config").split("\r\n")
977 asserted = False
978 for line in res:
979 if line.startswith(" access-list test-lu"):
980 self.assertEqual(line, " access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42")
981 asserted = True
982 self.assert_(asserted)
983
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200984class TestVTYGbproxy(TestVTYGenericBSC):
985
986 def vty_command(self):
987 return ["./src/gprs/osmo-gbproxy", "-c",
988 "doc/examples/osmo-gbproxy/osmo-gbproxy.cfg"]
989
990 def vty_app(self):
991 return (4246, "./src/gprs/osmo-gbproxy", "OsmoGbProxy", "bsc")
992
993 def testVtyTree(self):
994 self.vty.enable()
995 self.assertTrue(self.vty.verify('configure terminal', ['']))
996 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100997 self.checkForEndAndExit()
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200998 self.assertTrue(self.vty.verify('ns', ['']))
999 self.assertEquals(self.vty.node(), 'config-ns')
1000 self.checkForEndAndExit()
1001 self.assertTrue(self.vty.verify('exit', ['']))
1002 self.assertEquals(self.vty.node(), 'config')
1003 self.assertTrue(self.vty.verify('gbproxy', ['']))
1004 self.assertEquals(self.vty.node(), 'config-gbproxy')
1005 self.checkForEndAndExit()
1006 self.assertTrue(self.vty.verify('exit', ['']))
1007 self.assertEquals(self.vty.node(), 'config')
1008
1009 def testVtyShow(self):
1010 res = self.vty.command("show ns")
1011 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
1012
1013 res = self.vty.command("show gbproxy stats")
1014 self.assert_(res.find('GBProxy Global Statistics') >= 0)
1015
Jacob Erlbeck4211d792013-10-24 12:48:23 +02001016 def testVtyDeletePeer(self):
1017 self.vty.enable()
1018 self.assertTrue(self.vty.verify('delete-gbproxy-peer 9999 bvci 7777', ['BVC not found']))
1019 res = self.vty.command("delete-gbproxy-peer 9999 all dry-run")
1020 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
1021 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
1022 res = self.vty.command("delete-gbproxy-peer 9999 only-bvc dry-run")
1023 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
1024 self.assert_(res.find('Not Deleted 0 NS-VC') < 0)
1025 res = self.vty.command("delete-gbproxy-peer 9999 only-nsvc dry-run")
1026 self.assert_(res.find('Not Deleted 0 BVC') < 0)
1027 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
1028 res = self.vty.command("delete-gbproxy-peer 9999 all")
1029 self.assert_(res.find('Deleted 0 BVC') >= 0)
1030 self.assert_(res.find('Deleted 0 NS-VC') >= 0)
1031
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001032class TestVTYSGSN(TestVTYGenericBSC):
1033
1034 def vty_command(self):
1035 return ["./src/gprs/osmo-sgsn", "-c",
1036 "doc/examples/osmo-sgsn/osmo-sgsn.cfg"]
1037
1038 def vty_app(self):
1039 return (4245, "./src/gprs/osmo-sgsn", "OsmoSGSN", "sgsn")
1040
1041 def testVtyTree(self):
1042 self.vty.enable()
1043 self.assertTrue(self.vty.verify('configure terminal', ['']))
1044 self.assertEquals(self.vty.node(), 'config')
1045 self.checkForEndAndExit()
1046 self.assertTrue(self.vty.verify('ns', ['']))
1047 self.assertEquals(self.vty.node(), 'config-ns')
1048 self.checkForEndAndExit()
1049 self.assertTrue(self.vty.verify('exit', ['']))
1050 self.assertEquals(self.vty.node(), 'config')
1051 self.assertTrue(self.vty.verify('sgsn', ['']))
1052 self.assertEquals(self.vty.node(), 'config-sgsn')
1053 self.checkForEndAndExit()
1054 self.assertTrue(self.vty.verify('exit', ['']))
1055 self.assertEquals(self.vty.node(), 'config')
1056
1057 def testVtyShow(self):
1058 res = self.vty.command("show ns")
1059 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
1060 self.assertTrue(self.vty.verify('show bssgp', ['']))
1061 self.assertTrue(self.vty.verify('show bssgp stats', ['']))
1062 # TODO: uncomment when the command does not segfault anymore
1063 # self.assertTrue(self.vty.verify('show bssgp nsei 123', ['']))
1064 # self.assertTrue(self.vty.verify('show bssgp nsei 123 stats', ['']))
1065
1066 self.assertTrue(self.vty.verify('show sgsn', ['']))
1067 self.assertTrue(self.vty.verify('show mm-context all', ['']))
1068 self.assertTrue(self.vty.verify('show mm-context imsi 000001234567', ['No MM context for IMSI 000001234567']))
1069 self.assertTrue(self.vty.verify('show pdp-context all', ['']))
1070
1071 res = self.vty.command("show sndcp")
1072 self.assert_(res.find('State of SNDCP Entities') >= 0)
1073
1074 res = self.vty.command("show llc")
1075 self.assert_(res.find('State of LLC Entities') >= 0)
1076
Jacob Erlbeck106f5472014-11-04 10:08:37 +01001077 def testVtyAuth(self):
1078 self.vty.enable()
1079 self.assertTrue(self.vty.verify('configure terminal', ['']))
1080 self.assertEquals(self.vty.node(), 'config')
1081 self.assertTrue(self.vty.verify('sgsn', ['']))
1082 self.assertEquals(self.vty.node(), 'config-sgsn')
1083 self.assertTrue(self.vty.verify('auth-policy accept-all', ['']))
1084 res = self.vty.command("show running-config")
1085 self.assert_(res.find('auth-policy accept-all') > 0)
1086 self.assertTrue(self.vty.verify('auth-policy acl-only', ['']))
1087 res = self.vty.command("show running-config")
1088 self.assert_(res.find('auth-policy acl-only') > 0)
1089 self.assertTrue(self.vty.verify('auth-policy closed', ['']))
1090 res = self.vty.command("show running-config")
1091 self.assert_(res.find('auth-policy closed') > 0)
Max176b62a2016-07-04 11:09:07 +02001092 self.assertTrue(self.vty.verify('gsup remote-ip 127.0.0.4', ['']))
1093 self.assertTrue(self.vty.verify('gsup remote-port 2222', ['']))
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +01001094 self.assertTrue(self.vty.verify('auth-policy remote', ['']))
1095 res = self.vty.command("show running-config")
1096 self.assert_(res.find('auth-policy remote') > 0)
Jacob Erlbeck106f5472014-11-04 10:08:37 +01001097
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001098 def testVtySubscriber(self):
1099 self.vty.enable()
1100 res = self.vty.command('show subscriber cache')
1101 self.assert_(res.find('1234567890') < 0)
Jacob Erlbeckd9193432015-01-19 14:11:46 +01001102 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 create', ['']))
1103 res = self.vty.command('show subscriber cache')
1104 self.assert_(res.find('1234567890') >= 0)
1105 self.assert_(res.find('Authorized: 0') >= 0)
1106 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 update-location-result ok', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001107 res = self.vty.command('show subscriber cache')
1108 self.assert_(res.find('1234567890') >= 0)
1109 self.assert_(res.find('Authorized: 1') >= 0)
Jacob Erlbeck8000e0e2015-01-27 14:56:40 +01001110 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 cancel update-procedure', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001111 res = self.vty.command('show subscriber cache')
Jacob Erlbecke988ae42015-01-27 12:41:19 +01001112 self.assert_(res.find('1234567890') >= 0)
1113 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 destroy', ['']))
1114 res = self.vty.command('show subscriber cache')
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001115 self.assert_(res.find('1234567890') < 0)
1116
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +01001117 def testVtyGgsn(self):
1118 self.vty.enable()
1119 self.assertTrue(self.vty.verify('configure terminal', ['']))
1120 self.assertEquals(self.vty.node(), 'config')
1121 self.assertTrue(self.vty.verify('sgsn', ['']))
1122 self.assertEquals(self.vty.node(), 'config-sgsn')
1123 self.assertTrue(self.vty.verify('ggsn 0 remote-ip 127.99.99.99', ['']))
1124 self.assertTrue(self.vty.verify('ggsn 0 gtp-version 1', ['']))
1125 self.assertTrue(self.vty.verify('apn * ggsn 0', ['']))
1126 self.assertTrue(self.vty.verify('apn apn1.test ggsn 0', ['']))
1127 self.assertTrue(self.vty.verify('apn apn1.test ggsn 1', ['% a GGSN with id 1 has not been defined']))
1128 self.assertTrue(self.vty.verify('apn apn1.test imsi-prefix 123456 ggsn 0', ['']))
1129 self.assertTrue(self.vty.verify('apn apn2.test imsi-prefix 123456 ggsn 0', ['']))
1130 res = self.vty.command("show running-config")
1131 self.assert_(res.find('ggsn 0 remote-ip 127.99.99.99') >= 0)
1132 self.assert_(res.find('ggsn 0 gtp-version 1') >= 0)
1133 self.assert_(res.find('apn * ggsn 0') >= 0)
1134 self.assert_(res.find('apn apn1.test ggsn 0') >= 0)
1135 self.assert_(res.find('apn apn1.test imsi-prefix 123456 ggsn 0') >= 0)
1136 self.assert_(res.find('apn apn2.test imsi-prefix 123456 ggsn 0') >= 0)
1137
Holger Hans Peter Freyther9c20a5f2015-02-06 16:23:29 +01001138 def testVtyEasyAPN(self):
1139 self.vty.enable()
1140 self.assertTrue(self.vty.verify('configure terminal', ['']))
1141 self.assertEquals(self.vty.node(), 'config')
1142 self.assertTrue(self.vty.verify('sgsn', ['']))
1143 self.assertEquals(self.vty.node(), 'config-sgsn')
1144
1145 res = self.vty.command("show running-config")
1146 self.assertEquals(res.find("apn internet"), -1)
1147
1148 self.assertTrue(self.vty.verify("access-point-name internet.apn", ['']))
1149 res = self.vty.command("show running-config")
1150 self.assert_(res.find("apn internet.apn ggsn 0") >= 0)
1151
1152 self.assertTrue(self.vty.verify("no access-point-name internet.apn", ['']))
1153 res = self.vty.command("show running-config")
1154 self.assertEquals(res.find("apn internet"), -1)
1155
Holger Hans Peter Freytherc15c61c2015-05-06 17:46:08 +02001156 def testVtyCDR(self):
1157 self.vty.enable()
1158 self.assertTrue(self.vty.verify('configure terminal', ['']))
1159 self.assertEquals(self.vty.node(), 'config')
1160 self.assertTrue(self.vty.verify('sgsn', ['']))
1161 self.assertEquals(self.vty.node(), 'config-sgsn')
1162
1163 res = self.vty.command("show running-config")
1164 self.assert_(res.find("no cdr filename") > 0)
1165
1166 self.vty.command("cdr filename bla.cdr")
1167 res = self.vty.command("show running-config")
1168 self.assertEquals(res.find("no cdr filename"), -1)
1169 self.assert_(res.find(" cdr filename bla.cdr") > 0)
1170
1171 self.vty.command("no cdr filename")
1172 res = self.vty.command("show running-config")
1173 self.assert_(res.find("no cdr filename") > 0)
1174 self.assertEquals(res.find(" cdr filename bla.cdr"), -1)
1175
1176 res = self.vty.command("show running-config")
1177 self.assert_(res.find(" cdr interval 600") > 0)
1178
1179 self.vty.command("cdr interval 900")
1180 res = self.vty.command("show running-config")
1181 self.assert_(res.find(" cdr interval 900") > 0)
1182 self.assertEquals(res.find(" cdr interval 600"), -1)
1183
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001184def add_nat_test(suite, workdir):
1185 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
1186 print("Skipping the NAT test")
1187 return
1188 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT)
1189 suite.addTest(test)
1190
Max49364482016-04-13 11:36:39 +02001191def nat_bsc_reload(x):
1192 x.vty.command("configure terminal")
1193 x.vty.command("nat")
1194 x.vty.command("bscs-config-file bscs.config")
1195 x.vty.command("end")
1196
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001197def nat_msc_ip(x, ip, port):
Max49364482016-04-13 11:36:39 +02001198 x.vty.command("configure terminal")
1199 x.vty.command("nat")
1200 x.vty.command("msc ip " + ip)
Holger Hans Peter Freyther84ae27e2016-04-14 10:40:06 -04001201 x.vty.command("msc port " + str(port))
Max49364482016-04-13 11:36:39 +02001202 x.vty.command("end")
1203
1204def data2str(d):
Holger Hans Peter Freyther8bb62042016-04-14 21:40:04 -04001205 return d.encode('hex').lower()
Max49364482016-04-13 11:36:39 +02001206
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001207def nat_msc_test(x, ip, port, verbose = False):
Max49364482016-04-13 11:36:39 +02001208 msc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Neels Hofmeyrcaeb62d2016-09-28 23:38:45 +02001209 msc.settimeout(5)
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001210 msc.bind((ip, port))
Max49364482016-04-13 11:36:39 +02001211 msc.listen(5)
1212 if (verbose):
1213 print "MSC is ready at " + ip
Neels Hofmeyr89d20b62016-09-26 12:59:36 +02001214 conn = None
Neels Hofmeyrcaeb62d2016-09-28 23:38:45 +02001215 while True:
1216 vty_response = x.vty.command("show msc connection")
1217 print "'show msc connection' says: %r" % vty_response
1218 if vty_response == "MSC is connected: 1":
1219 # success
1220 break;
1221 if vty_response != "MSC is connected: 0":
1222 raise Exception("Unexpected response to 'show msc connection'"
1223 " vty command: %r" % vty_response)
1224
1225 timeout_retries = 6
1226 while timeout_retries > 0:
1227 try:
1228 conn, addr = msc.accept()
1229 print "MSC got connection from ", addr
1230 break
1231 except socket.timeout:
1232 print "socket timed out."
1233 timeout_retries -= 1
1234 continue
1235
Neels Hofmeyr89d20b62016-09-26 12:59:36 +02001236 if not conn:
Neels Hofmeyr0867b722016-09-28 23:28:06 +02001237 raise Exception("VTY reports MSC is connected, but I haven't"
1238 " connected yet: %r %r" % (ip, port))
Max49364482016-04-13 11:36:39 +02001239 return conn
1240
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001241def cmd(what):
1242 print '\n> %s' % what
1243 sys.stdout.flush()
1244 subprocess.call(what, shell=True)
1245 sys.stdout.flush()
1246 sys.stderr.flush()
1247 print ''
1248 sys.stdout.flush()
1249
1250def checkxxx():
1251 cmd('cat /proc/net/tcp');
1252 cmd('ps xua | grep osmo');
1253
Max49364482016-04-13 11:36:39 +02001254def ipa_handle_small(x, verbose = False):
1255 s = data2str(x.recv(4))
Neels Hofmeyrba1468e2017-02-03 04:23:46 +01001256 if len(s) != 4*2:
1257 raise Exception("expected to receive 4 bytes, but got %d (%r)" % (len(s)/2, s))
Max49364482016-04-13 11:36:39 +02001258 if "0001fe00" == s:
1259 if (verbose):
1260 print "\tBSC <- NAT: PING?"
Max3e676892016-11-16 14:55:21 +01001261 x.send(IPA().pong())
Max49364482016-04-13 11:36:39 +02001262 elif "0001fe06" == s:
1263 if (verbose):
1264 print "\tBSC <- NAT: IPA ID ACK"
Max3e676892016-11-16 14:55:21 +01001265 x.send(IPA().id_ack())
Max49364482016-04-13 11:36:39 +02001266 elif "0001fe00" == s:
1267 if (verbose):
1268 print "\tBSC <- NAT: PONG!"
1269 else:
1270 if (verbose):
1271 print "\tBSC <- NAT: ", s
1272
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001273def ipa_handle_resp(x, tk, verbose = False, proc=None):
Max49364482016-04-13 11:36:39 +02001274 s = data2str(x.recv(38))
1275 if "0023fe040108010701020103010401050101010011" in s:
Neels Hofmeyr7d17c3e2017-01-26 23:04:28 +01001276 retries = 3
1277 while True:
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001278 if proc:
1279 print "\tproc.poll() = %r" % proc.poll()
1280 print "\tproc.pid = %r" % proc.pid
1281 checkxxx()
Neels Hofmeyr7d17c3e2017-01-26 23:04:28 +01001282 print "\tsending IPA identity(%s) at %s" % (tk, time.strftime("%T"))
1283 try:
1284 x.send(IPA().id_resp(IPA().identity(name = tk.encode('utf-8'))))
1285 print "\tdone sending IPA identity(%s) at %s" % (tk,
1286 time.strftime("%T"))
1287 break
1288 except:
1289 print "\tfailed sending IPA identity at", time.strftime("%T")
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001290 if proc:
1291 print "\tproc.poll() = %r" % proc.poll()
Neels Hofmeyr7d17c3e2017-01-26 23:04:28 +01001292 if retries < 1:
1293 print "\tgiving up"
1294 raise
Neels Hofmeyre02e1e72017-02-03 05:55:26 +01001295 print "\tretrying (%d attempts left)" % retries
Neels Hofmeyr7d17c3e2017-01-26 23:04:28 +01001296 retries -= 1
Max49364482016-04-13 11:36:39 +02001297 else:
1298 if (verbose):
1299 print "\tBSC <- NAT: ", s
1300
1301def nat_bsc_num_con(x):
1302 return len(x.vty.command("show bsc connections").split('\n'))
1303
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001304def nat_bsc_sock_test(nr, tk, verbose = False, proc=None):
Max49364482016-04-13 11:36:39 +02001305 bsc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Holger Hans Peter Freyther2abf2b02016-04-14 21:13:51 -04001306 bsc.bind(('127.0.0.1', 0))
Max49364482016-04-13 11:36:39 +02001307 bsc.connect(('127.0.0.1', 5000))
1308 if (verbose):
1309 print "BSC%d " %nr
1310 print "\tconnected to %s:%d" % bsc.getpeername()
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001311 if proc:
1312 print "\tproc.poll() = %r" % proc.poll()
1313 print "\tproc.pid = %r" % proc.pid
1314 checkxxx()
Max49364482016-04-13 11:36:39 +02001315 ipa_handle_small(bsc, verbose)
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001316 checkxxx()
1317 ipa_handle_resp(bsc, tk, verbose, proc=proc)
1318 if proc:
1319 print "\tproc.poll() = %r" % proc.poll()
1320 checkxxx()
Max49364482016-04-13 11:36:39 +02001321 bsc.recv(27) # MGCP msg
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001322 if proc:
1323 print "\tproc.poll() = %r" % proc.poll()
1324 checkxxx()
Max49364482016-04-13 11:36:39 +02001325 ipa_handle_small(bsc, verbose)
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001326 checkxxx()
Max49364482016-04-13 11:36:39 +02001327 return bsc
1328
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001329def add_bsc_test(suite, workdir):
1330 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")):
1331 print("Skipping the BSC test")
1332 return
1333 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC)
1334 suite.addTest(test)
1335
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001336def add_gbproxy_test(suite, workdir):
1337 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-gbproxy")):
1338 print("Skipping the Gb-Proxy test")
1339 return
1340 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYGbproxy)
1341 suite.addTest(test)
1342
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001343def add_sgsn_test(suite, workdir):
1344 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-sgsn")):
1345 print("Skipping the SGSN test")
1346 return
1347 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYSGSN)
1348 suite.addTest(test)
1349
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001350if __name__ == '__main__':
1351 import argparse
1352 import sys
1353
1354 workdir = '.'
1355
1356 parser = argparse.ArgumentParser()
1357 parser.add_argument("-v", "--verbose", dest="verbose",
1358 action="store_true", help="verbose mode")
1359 parser.add_argument("-p", "--pythonconfpath", dest="p",
1360 help="searchpath for config")
1361 parser.add_argument("-w", "--workdir", dest="w",
1362 help="Working directory")
1363 args = parser.parse_args()
1364
1365 verbose_level = 1
1366 if args.verbose:
1367 verbose_level = 2
1368
1369 if args.w:
1370 workdir = args.w
1371
1372 if args.p:
1373 confpath = args.p
1374
1375 print "confpath %s, workdir %s" % (confpath, workdir)
1376 os.chdir(workdir)
1377 print "Running tests for specific VTY commands"
1378 suite = unittest.TestSuite()
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +02001379 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYMGCP))
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +02001380 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB))
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001381 add_bsc_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001382 add_nat_test(suite, workdir)
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001383 add_gbproxy_test(suite, workdir)
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001384 add_sgsn_test(suite, workdir)
Neels Hofmeyr0a45c1e2016-09-28 23:48:02 +02001385 res = unittest.TextTestRunner(verbosity=verbose_level, stream=sys.stdout).run(suite)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001386 sys.exit(len(res.errors) + len(res.failures))
Neels Hofmeyr23d37c92016-09-26 03:18:32 +02001387
Neels Hofmeyr0867b722016-09-28 23:28:06 +02001388# vim: shiftwidth=4 expandtab nocin ai