blob: 87b9eba974afc5af4e28738fb9fb9f81eda84477 [file] [log] [blame]
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001#!/usr/bin/env python
2
3# (C) 2013 by Katerina Barone-Adesi <kat.obsc@gmail.com>
4# (C) 2013 by Holger Hans Peter Freyther
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
Max3e676892016-11-16 14:55:21 +010018import os, sys
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +020019import time
20import unittest
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +020021import socket
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +010022import subprocess
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +020023
24import osmopy.obscvty as obscvty
25import osmopy.osmoutil as osmoutil
26
Max3e676892016-11-16 14:55:21 +010027sys.path.append("../contrib")
28from ipa import IPA
29
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +020030confpath = '.'
31
32class TestVTYBase(unittest.TestCase):
33
34 def vty_command(self):
35 raise Exception("Needs to be implemented by a subclass")
36
37 def vty_app(self):
38 raise Exception("Needs to be implemented by a subclass")
39
40 def setUp(self):
41 osmo_vty_cmd = self.vty_command()[:]
42 config_index = osmo_vty_cmd.index('-c')
43 if config_index:
44 cfi = config_index + 1
45 osmo_vty_cmd[cfi] = os.path.join(confpath, osmo_vty_cmd[cfi])
46
47 try:
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +020048 self.proc = osmoutil.popen_devnull(osmo_vty_cmd)
49 except OSError:
50 print >> sys.stderr, "Current directory: %s" % os.getcwd()
51 print >> sys.stderr, "Consider setting -b"
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +020052
53 appstring = self.vty_app()[2]
54 appport = self.vty_app()[0]
55 self.vty = obscvty.VTYInteract(appstring, "127.0.0.1", appport)
56
57 def tearDown(self):
Neels Hofmeyr40a91b32017-02-24 17:54:22 +010058 if self.vty:
59 self.vty._close_socket()
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +020060 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 Hofmeyr0b619322017-02-28 02:37:39 +0100785 msc_socket, msc = nat_msc_test(self, ip, port, verbose=True)
786 try:
787 b0 = nat_bsc_sock_test(0, "lol", verbose=True, proc=self.proc)
788 b1 = nat_bsc_sock_test(1, "xyu", verbose=True, proc=self.proc)
789 b2 = nat_bsc_sock_test(5, "key", verbose=True, proc=self.proc)
Max49364482016-04-13 11:36:39 +0200790
Neels Hofmeyr0b619322017-02-28 02:37:39 +0100791 self.assertEquals("3 BSCs configured", self.vty.command("show nat num-bscs-configured"))
792 self.assertTrue(3 == nat_bsc_num_con(self))
793 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
Max49364482016-04-13 11:36:39 +0200794
Neels Hofmeyr0b619322017-02-28 02:37:39 +0100795 nat_bsc_reload(self)
796 bscs2 = self.vty.command("show bscs-config")
797 # check that the reset to initial config succeeded
798 self.assertEquals(bscs1, bscs2)
Max49364482016-04-13 11:36:39 +0200799
Neels Hofmeyr0b619322017-02-28 02:37:39 +0100800 self.assertEquals("2 BSCs configured", self.vty.command("show nat num-bscs-configured"))
801 self.assertTrue(1 == nat_bsc_num_con(self))
802 rem = self.vty.command("show bsc connections").split(' ')
803 # remaining connection is for BSC0
804 self.assertEquals('0', rem[2])
805 # remaining connection is authorized
806 self.assertEquals('1', rem[4])
807 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
808 finally:
809 msc.close()
810 msc_socket.close()
Max49364482016-04-13 11:36:39 +0200811
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200812 def testVtyTree(self):
813 self.vty.enable()
814 self.assertTrue(self.vty.verify('configure terminal', ['']))
815 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100816 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200817 self.assertTrue(self.vty.verify('mgcp', ['']))
818 self.assertEquals(self.vty.node(), 'config-mgcp')
819 self.checkForEndAndExit()
820 self.assertTrue(self.vty.verify('exit', ['']))
821 self.assertEquals(self.vty.node(), 'config')
822 self.assertTrue(self.vty.verify('nat', ['']))
823 self.assertEquals(self.vty.node(), 'config-nat')
824 self.checkForEndAndExit()
825 self.assertTrue(self.vty.verify('bsc 0', ['']))
826 self.assertEquals(self.vty.node(), 'config-nat-bsc')
827 self.checkForEndAndExit()
828 self.assertTrue(self.vty.verify('exit', ['']))
829 self.assertEquals(self.vty.node(), 'config-nat')
830 self.assertTrue(self.vty.verify('exit', ['']))
831 self.assertEquals(self.vty.node(), 'config')
832 self.assertTrue(self.vty.verify('exit', ['']))
833 self.assertTrue(self.vty.node() is None)
834
835 # Check searching for outer node's commands
836 self.vty.command('configure terminal')
837 self.vty.command('mgcp')
838 self.vty.command('nat')
839 self.assertEquals(self.vty.node(), 'config-nat')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200840 self.vty.command('mgcp')
841 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200842 self.vty.command('nat')
843 self.assertEquals(self.vty.node(), 'config-nat')
844 self.vty.command('bsc 0')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200845 self.vty.command('mgcp')
846 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200847
Holger Hans Peter Freytherb718ad32013-06-25 09:08:02 +0200848 def testRewriteNoRewrite(self):
849 self.vty.enable()
850 res = self.vty.command("configure terminal")
851 res = self.vty.command("nat")
852 res = self.vty.command("number-rewrite rewrite.cfg")
853 res = self.vty.command("no number-rewrite")
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200854
Holger Hans Peter Freyther7f100c92015-04-23 20:25:17 -0400855 def testEnsureNoEnsureModeSet(self):
856 self.vty.enable()
857 res = self.vty.command("configure terminal")
858 res = self.vty.command("nat")
859
860 # Ensure the default
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("sdp-ensure-amr-mode-set")
865 res = self.vty.command("show running-config")
866 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
867
868 self.vty.command("no sdp-ensure-amr-mode-set")
869 res = self.vty.command("show running-config")
870 self.assert_(res.find('\n no sdp-ensure-amr-mode-set') > 0)
871
Holger Hans Peter Freyther67e423c2013-06-25 15:38:31 +0200872 def testRewritePostNoRewrite(self):
873 self.vty.enable()
874 self.vty.command("configure terminal")
875 self.vty.command("nat")
876 self.vty.verify("number-rewrite-post rewrite.cfg", [''])
877 self.vty.verify("no number-rewrite-post", [''])
878
879
Holger Hans Peter Freytherddf191e2013-06-25 11:44:01 +0200880 def testPrefixTreeLoading(self):
881 cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv")
882
883 self.vty.enable()
884 self.vty.command("configure terminal")
885 self.vty.command("nat")
886 res = self.vty.command("prefix-tree %s" % cfg)
887 self.assertEqual(res, "% prefix-tree loaded 17 rules.")
888 self.vty.command("end")
889
890 res = self.vty.command("show prefix-tree")
891 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')
892
893 self.vty.command("configure terminal")
894 self.vty.command("nat")
895 self.vty.command("no prefix-tree")
896 self.vty.command("end")
897
898 res = self.vty.command("show prefix-tree")
899 self.assertEqual(res, "% there is now prefix tree loaded.")
900
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200901 def testUssdSideChannelProvider(self):
902 self.vty.command("end")
903 self.vty.enable()
904 self.vty.command("configure terminal")
905 self.vty.command("nat")
906 self.vty.command("ussd-token key")
907 self.vty.command("end")
908
909 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
910 self.assertTrue(res)
911
912 ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
913 ussdSocket.connect(('127.0.0.1', 5001))
914 ussdSocket.settimeout(2.0)
915 print "Connected to %s:%d" % ussdSocket.getpeername()
916
917 print "Expecting ID_GET request"
918 data = ussdSocket.recv(4)
919 self.assertEqual(data, "\x00\x01\xfe\x04")
920
921 print "Going to send ID_RESP response"
Max3e676892016-11-16 14:55:21 +0100922 res = ussdSocket.send(IPA().id_resp(IPA().tag_name('key')))
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200923 self.assertEqual(res, 10)
924
925 # initiating PING/PONG cycle to know, that the ID_RESP message has been processed
926
927 print "Going to send PING request"
Max3e676892016-11-16 14:55:21 +0100928 res = ussdSocket.send(IPA().ping())
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200929 self.assertEqual(res, 4)
930
931 print "Expecting PONG response"
932 data = ussdSocket.recv(4)
933 self.assertEqual(data, "\x00\x01\xfe\x01")
934
935 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.'])
936 self.assertTrue(res)
937
938 print "Going to shut down connection"
939 ussdSocket.shutdown(socket.SHUT_WR)
940
941 print "Expecting EOF"
942 data = ussdSocket.recv(4)
943 self.assertEqual(data, "")
944
945 ussdSocket.close()
946
947 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
948 self.assertTrue(res)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200949
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100950 def testAccessList(self):
951 """
952 Verify that the imsi-deny can have a reject cause or no reject cause
953 """
954 self.vty.enable()
955 self.vty.command("configure terminal")
956 self.vty.command("nat")
957
958 # Old default
959 self.vty.command("access-list test-default imsi-deny ^123[0-9]*$")
960 res = self.vty.command("show running-config").split("\r\n")
961 asserted = False
962 for line in res:
Holger Hans Peter Freyther4ecc6872014-03-04 15:38:00 +0100963 if line.startswith(" access-list test-default"):
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100964 self.assertEqual(line, " access-list test-default imsi-deny ^123[0-9]*$ 11 11")
965 asserted = True
966 self.assert_(asserted)
967
968 # Check the optional CM Service Reject Cause
969 self.vty.command("access-list test-cm-deny imsi-deny ^123[0-9]*$ 42").split("\r\n")
970 res = self.vty.command("show running-config").split("\r\n")
971 asserted = False
972 for line in res:
973 if line.startswith(" access-list test-cm"):
974 self.assertEqual(line, " access-list test-cm-deny imsi-deny ^123[0-9]*$ 42 11")
975 asserted = True
976 self.assert_(asserted)
977
978 # Check the optional LU Reject Cause
979 self.vty.command("access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42").split("\r\n")
980 res = self.vty.command("show running-config").split("\r\n")
981 asserted = False
982 for line in res:
983 if line.startswith(" access-list test-lu"):
984 self.assertEqual(line, " access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42")
985 asserted = True
986 self.assert_(asserted)
987
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200988class TestVTYGbproxy(TestVTYGenericBSC):
989
990 def vty_command(self):
991 return ["./src/gprs/osmo-gbproxy", "-c",
992 "doc/examples/osmo-gbproxy/osmo-gbproxy.cfg"]
993
994 def vty_app(self):
995 return (4246, "./src/gprs/osmo-gbproxy", "OsmoGbProxy", "bsc")
996
997 def testVtyTree(self):
998 self.vty.enable()
999 self.assertTrue(self.vty.verify('configure terminal', ['']))
1000 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +01001001 self.checkForEndAndExit()
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001002 self.assertTrue(self.vty.verify('ns', ['']))
1003 self.assertEquals(self.vty.node(), 'config-ns')
1004 self.checkForEndAndExit()
1005 self.assertTrue(self.vty.verify('exit', ['']))
1006 self.assertEquals(self.vty.node(), 'config')
1007 self.assertTrue(self.vty.verify('gbproxy', ['']))
1008 self.assertEquals(self.vty.node(), 'config-gbproxy')
1009 self.checkForEndAndExit()
1010 self.assertTrue(self.vty.verify('exit', ['']))
1011 self.assertEquals(self.vty.node(), 'config')
1012
1013 def testVtyShow(self):
1014 res = self.vty.command("show ns")
1015 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
1016
1017 res = self.vty.command("show gbproxy stats")
1018 self.assert_(res.find('GBProxy Global Statistics') >= 0)
1019
Jacob Erlbeck4211d792013-10-24 12:48:23 +02001020 def testVtyDeletePeer(self):
1021 self.vty.enable()
1022 self.assertTrue(self.vty.verify('delete-gbproxy-peer 9999 bvci 7777', ['BVC not found']))
1023 res = self.vty.command("delete-gbproxy-peer 9999 all dry-run")
1024 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
1025 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
1026 res = self.vty.command("delete-gbproxy-peer 9999 only-bvc dry-run")
1027 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
1028 self.assert_(res.find('Not Deleted 0 NS-VC') < 0)
1029 res = self.vty.command("delete-gbproxy-peer 9999 only-nsvc dry-run")
1030 self.assert_(res.find('Not Deleted 0 BVC') < 0)
1031 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
1032 res = self.vty.command("delete-gbproxy-peer 9999 all")
1033 self.assert_(res.find('Deleted 0 BVC') >= 0)
1034 self.assert_(res.find('Deleted 0 NS-VC') >= 0)
1035
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001036class TestVTYSGSN(TestVTYGenericBSC):
1037
1038 def vty_command(self):
1039 return ["./src/gprs/osmo-sgsn", "-c",
1040 "doc/examples/osmo-sgsn/osmo-sgsn.cfg"]
1041
1042 def vty_app(self):
1043 return (4245, "./src/gprs/osmo-sgsn", "OsmoSGSN", "sgsn")
1044
1045 def testVtyTree(self):
1046 self.vty.enable()
1047 self.assertTrue(self.vty.verify('configure terminal', ['']))
1048 self.assertEquals(self.vty.node(), 'config')
1049 self.checkForEndAndExit()
1050 self.assertTrue(self.vty.verify('ns', ['']))
1051 self.assertEquals(self.vty.node(), 'config-ns')
1052 self.checkForEndAndExit()
1053 self.assertTrue(self.vty.verify('exit', ['']))
1054 self.assertEquals(self.vty.node(), 'config')
1055 self.assertTrue(self.vty.verify('sgsn', ['']))
1056 self.assertEquals(self.vty.node(), 'config-sgsn')
1057 self.checkForEndAndExit()
1058 self.assertTrue(self.vty.verify('exit', ['']))
1059 self.assertEquals(self.vty.node(), 'config')
1060
1061 def testVtyShow(self):
1062 res = self.vty.command("show ns")
1063 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
1064 self.assertTrue(self.vty.verify('show bssgp', ['']))
1065 self.assertTrue(self.vty.verify('show bssgp stats', ['']))
1066 # TODO: uncomment when the command does not segfault anymore
1067 # self.assertTrue(self.vty.verify('show bssgp nsei 123', ['']))
1068 # self.assertTrue(self.vty.verify('show bssgp nsei 123 stats', ['']))
1069
1070 self.assertTrue(self.vty.verify('show sgsn', ['']))
1071 self.assertTrue(self.vty.verify('show mm-context all', ['']))
1072 self.assertTrue(self.vty.verify('show mm-context imsi 000001234567', ['No MM context for IMSI 000001234567']))
1073 self.assertTrue(self.vty.verify('show pdp-context all', ['']))
1074
1075 res = self.vty.command("show sndcp")
1076 self.assert_(res.find('State of SNDCP Entities') >= 0)
1077
1078 res = self.vty.command("show llc")
1079 self.assert_(res.find('State of LLC Entities') >= 0)
1080
Jacob Erlbeck106f5472014-11-04 10:08:37 +01001081 def testVtyAuth(self):
1082 self.vty.enable()
1083 self.assertTrue(self.vty.verify('configure terminal', ['']))
1084 self.assertEquals(self.vty.node(), 'config')
1085 self.assertTrue(self.vty.verify('sgsn', ['']))
1086 self.assertEquals(self.vty.node(), 'config-sgsn')
1087 self.assertTrue(self.vty.verify('auth-policy accept-all', ['']))
1088 res = self.vty.command("show running-config")
1089 self.assert_(res.find('auth-policy accept-all') > 0)
1090 self.assertTrue(self.vty.verify('auth-policy acl-only', ['']))
1091 res = self.vty.command("show running-config")
1092 self.assert_(res.find('auth-policy acl-only') > 0)
1093 self.assertTrue(self.vty.verify('auth-policy closed', ['']))
1094 res = self.vty.command("show running-config")
1095 self.assert_(res.find('auth-policy closed') > 0)
Max176b62a2016-07-04 11:09:07 +02001096 self.assertTrue(self.vty.verify('gsup remote-ip 127.0.0.4', ['']))
1097 self.assertTrue(self.vty.verify('gsup remote-port 2222', ['']))
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +01001098 self.assertTrue(self.vty.verify('auth-policy remote', ['']))
1099 res = self.vty.command("show running-config")
1100 self.assert_(res.find('auth-policy remote') > 0)
Jacob Erlbeck106f5472014-11-04 10:08:37 +01001101
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001102 def testVtySubscriber(self):
1103 self.vty.enable()
1104 res = self.vty.command('show subscriber cache')
1105 self.assert_(res.find('1234567890') < 0)
Jacob Erlbeckd9193432015-01-19 14:11:46 +01001106 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 create', ['']))
1107 res = self.vty.command('show subscriber cache')
1108 self.assert_(res.find('1234567890') >= 0)
1109 self.assert_(res.find('Authorized: 0') >= 0)
1110 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 update-location-result ok', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001111 res = self.vty.command('show subscriber cache')
1112 self.assert_(res.find('1234567890') >= 0)
1113 self.assert_(res.find('Authorized: 1') >= 0)
Jacob Erlbeck8000e0e2015-01-27 14:56:40 +01001114 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 cancel update-procedure', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001115 res = self.vty.command('show subscriber cache')
Jacob Erlbecke988ae42015-01-27 12:41:19 +01001116 self.assert_(res.find('1234567890') >= 0)
1117 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 destroy', ['']))
1118 res = self.vty.command('show subscriber cache')
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001119 self.assert_(res.find('1234567890') < 0)
1120
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +01001121 def testVtyGgsn(self):
1122 self.vty.enable()
1123 self.assertTrue(self.vty.verify('configure terminal', ['']))
1124 self.assertEquals(self.vty.node(), 'config')
1125 self.assertTrue(self.vty.verify('sgsn', ['']))
1126 self.assertEquals(self.vty.node(), 'config-sgsn')
1127 self.assertTrue(self.vty.verify('ggsn 0 remote-ip 127.99.99.99', ['']))
1128 self.assertTrue(self.vty.verify('ggsn 0 gtp-version 1', ['']))
1129 self.assertTrue(self.vty.verify('apn * ggsn 0', ['']))
1130 self.assertTrue(self.vty.verify('apn apn1.test ggsn 0', ['']))
1131 self.assertTrue(self.vty.verify('apn apn1.test ggsn 1', ['% a GGSN with id 1 has not been defined']))
1132 self.assertTrue(self.vty.verify('apn apn1.test imsi-prefix 123456 ggsn 0', ['']))
1133 self.assertTrue(self.vty.verify('apn apn2.test imsi-prefix 123456 ggsn 0', ['']))
1134 res = self.vty.command("show running-config")
1135 self.assert_(res.find('ggsn 0 remote-ip 127.99.99.99') >= 0)
1136 self.assert_(res.find('ggsn 0 gtp-version 1') >= 0)
1137 self.assert_(res.find('apn * ggsn 0') >= 0)
1138 self.assert_(res.find('apn apn1.test ggsn 0') >= 0)
1139 self.assert_(res.find('apn apn1.test imsi-prefix 123456 ggsn 0') >= 0)
1140 self.assert_(res.find('apn apn2.test imsi-prefix 123456 ggsn 0') >= 0)
1141
Holger Hans Peter Freyther9c20a5f2015-02-06 16:23:29 +01001142 def testVtyEasyAPN(self):
1143 self.vty.enable()
1144 self.assertTrue(self.vty.verify('configure terminal', ['']))
1145 self.assertEquals(self.vty.node(), 'config')
1146 self.assertTrue(self.vty.verify('sgsn', ['']))
1147 self.assertEquals(self.vty.node(), 'config-sgsn')
1148
1149 res = self.vty.command("show running-config")
1150 self.assertEquals(res.find("apn internet"), -1)
1151
1152 self.assertTrue(self.vty.verify("access-point-name internet.apn", ['']))
1153 res = self.vty.command("show running-config")
1154 self.assert_(res.find("apn internet.apn ggsn 0") >= 0)
1155
1156 self.assertTrue(self.vty.verify("no access-point-name internet.apn", ['']))
1157 res = self.vty.command("show running-config")
1158 self.assertEquals(res.find("apn internet"), -1)
1159
Holger Hans Peter Freytherc15c61c2015-05-06 17:46:08 +02001160 def testVtyCDR(self):
1161 self.vty.enable()
1162 self.assertTrue(self.vty.verify('configure terminal', ['']))
1163 self.assertEquals(self.vty.node(), 'config')
1164 self.assertTrue(self.vty.verify('sgsn', ['']))
1165 self.assertEquals(self.vty.node(), 'config-sgsn')
1166
1167 res = self.vty.command("show running-config")
1168 self.assert_(res.find("no cdr filename") > 0)
1169
1170 self.vty.command("cdr filename bla.cdr")
1171 res = self.vty.command("show running-config")
1172 self.assertEquals(res.find("no cdr filename"), -1)
1173 self.assert_(res.find(" cdr filename bla.cdr") > 0)
1174
1175 self.vty.command("no cdr filename")
1176 res = self.vty.command("show running-config")
1177 self.assert_(res.find("no cdr filename") > 0)
1178 self.assertEquals(res.find(" cdr filename bla.cdr"), -1)
1179
1180 res = self.vty.command("show running-config")
1181 self.assert_(res.find(" cdr interval 600") > 0)
1182
1183 self.vty.command("cdr interval 900")
1184 res = self.vty.command("show running-config")
1185 self.assert_(res.find(" cdr interval 900") > 0)
1186 self.assertEquals(res.find(" cdr interval 600"), -1)
1187
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001188def add_nat_test(suite, workdir):
1189 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
1190 print("Skipping the NAT test")
1191 return
1192 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT)
1193 suite.addTest(test)
1194
Max49364482016-04-13 11:36:39 +02001195def nat_bsc_reload(x):
1196 x.vty.command("configure terminal")
1197 x.vty.command("nat")
1198 x.vty.command("bscs-config-file bscs.config")
1199 x.vty.command("end")
1200
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001201def nat_msc_ip(x, ip, port):
Max49364482016-04-13 11:36:39 +02001202 x.vty.command("configure terminal")
1203 x.vty.command("nat")
1204 x.vty.command("msc ip " + ip)
Holger Hans Peter Freyther84ae27e2016-04-14 10:40:06 -04001205 x.vty.command("msc port " + str(port))
Max49364482016-04-13 11:36:39 +02001206 x.vty.command("end")
1207
1208def data2str(d):
Holger Hans Peter Freyther8bb62042016-04-14 21:40:04 -04001209 return d.encode('hex').lower()
Max49364482016-04-13 11:36:39 +02001210
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001211def nat_msc_test(x, ip, port, verbose = False):
Max49364482016-04-13 11:36:39 +02001212 msc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Neels Hofmeyr53403452017-02-28 02:38:43 +01001213 msc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
Neels Hofmeyrcaeb62d2016-09-28 23:38:45 +02001214 msc.settimeout(5)
Holger Hans Peter Freyther44ed4972016-04-14 10:05:13 -04001215 msc.bind((ip, port))
Max49364482016-04-13 11:36:39 +02001216 msc.listen(5)
1217 if (verbose):
1218 print "MSC is ready at " + ip
Neels Hofmeyr89d20b62016-09-26 12:59:36 +02001219 conn = None
Neels Hofmeyrcaeb62d2016-09-28 23:38:45 +02001220 while True:
1221 vty_response = x.vty.command("show msc connection")
1222 print "'show msc connection' says: %r" % vty_response
1223 if vty_response == "MSC is connected: 1":
1224 # success
1225 break;
1226 if vty_response != "MSC is connected: 0":
1227 raise Exception("Unexpected response to 'show msc connection'"
1228 " vty command: %r" % vty_response)
1229
1230 timeout_retries = 6
1231 while timeout_retries > 0:
1232 try:
1233 conn, addr = msc.accept()
1234 print "MSC got connection from ", addr
1235 break
1236 except socket.timeout:
1237 print "socket timed out."
1238 timeout_retries -= 1
1239 continue
1240
Neels Hofmeyr89d20b62016-09-26 12:59:36 +02001241 if not conn:
Neels Hofmeyr0867b722016-09-28 23:28:06 +02001242 raise Exception("VTY reports MSC is connected, but I haven't"
1243 " connected yet: %r %r" % (ip, port))
Neels Hofmeyr0b619322017-02-28 02:37:39 +01001244 return msc, conn
Max49364482016-04-13 11:36:39 +02001245
1246def ipa_handle_small(x, verbose = False):
1247 s = data2str(x.recv(4))
Neels Hofmeyrba1468e2017-02-03 04:23:46 +01001248 if len(s) != 4*2:
1249 raise Exception("expected to receive 4 bytes, but got %d (%r)" % (len(s)/2, s))
Max49364482016-04-13 11:36:39 +02001250 if "0001fe00" == s:
1251 if (verbose):
1252 print "\tBSC <- NAT: PING?"
Max3e676892016-11-16 14:55:21 +01001253 x.send(IPA().pong())
Max49364482016-04-13 11:36:39 +02001254 elif "0001fe06" == s:
1255 if (verbose):
1256 print "\tBSC <- NAT: IPA ID ACK"
Max3e676892016-11-16 14:55:21 +01001257 x.send(IPA().id_ack())
Max49364482016-04-13 11:36:39 +02001258 elif "0001fe00" == s:
1259 if (verbose):
1260 print "\tBSC <- NAT: PONG!"
1261 else:
1262 if (verbose):
1263 print "\tBSC <- NAT: ", s
1264
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001265def ipa_handle_resp(x, tk, verbose = False, proc=None):
Max49364482016-04-13 11:36:39 +02001266 s = data2str(x.recv(38))
1267 if "0023fe040108010701020103010401050101010011" in s:
Neels Hofmeyr7d17c3e2017-01-26 23:04:28 +01001268 retries = 3
1269 while True:
1270 print "\tsending IPA identity(%s) at %s" % (tk, time.strftime("%T"))
1271 try:
1272 x.send(IPA().id_resp(IPA().identity(name = tk.encode('utf-8'))))
1273 print "\tdone sending IPA identity(%s) at %s" % (tk,
1274 time.strftime("%T"))
1275 break
1276 except:
1277 print "\tfailed sending IPA identity at", time.strftime("%T")
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001278 if proc:
1279 print "\tproc.poll() = %r" % proc.poll()
Neels Hofmeyr7d17c3e2017-01-26 23:04:28 +01001280 if retries < 1:
1281 print "\tgiving up"
1282 raise
Neels Hofmeyre02e1e72017-02-03 05:55:26 +01001283 print "\tretrying (%d attempts left)" % retries
Neels Hofmeyr7d17c3e2017-01-26 23:04:28 +01001284 retries -= 1
Max49364482016-04-13 11:36:39 +02001285 else:
1286 if (verbose):
1287 print "\tBSC <- NAT: ", s
1288
1289def nat_bsc_num_con(x):
1290 return len(x.vty.command("show bsc connections").split('\n'))
1291
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001292def nat_bsc_sock_test(nr, tk, verbose = False, proc=None):
Max49364482016-04-13 11:36:39 +02001293 bsc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Holger Hans Peter Freyther2abf2b02016-04-14 21:13:51 -04001294 bsc.bind(('127.0.0.1', 0))
Max49364482016-04-13 11:36:39 +02001295 bsc.connect(('127.0.0.1', 5000))
1296 if (verbose):
1297 print "BSC%d " %nr
1298 print "\tconnected to %s:%d" % bsc.getpeername()
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001299 if proc:
1300 print "\tproc.poll() = %r" % proc.poll()
1301 print "\tproc.pid = %r" % proc.pid
Max49364482016-04-13 11:36:39 +02001302 ipa_handle_small(bsc, verbose)
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001303 ipa_handle_resp(bsc, tk, verbose, proc=proc)
1304 if proc:
1305 print "\tproc.poll() = %r" % proc.poll()
Max49364482016-04-13 11:36:39 +02001306 bsc.recv(27) # MGCP msg
Neels Hofmeyrbcfee2a2017-02-03 16:09:17 +01001307 if proc:
1308 print "\tproc.poll() = %r" % proc.poll()
Max49364482016-04-13 11:36:39 +02001309 ipa_handle_small(bsc, verbose)
1310 return bsc
1311
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001312def add_bsc_test(suite, workdir):
1313 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")):
1314 print("Skipping the BSC test")
1315 return
1316 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC)
1317 suite.addTest(test)
1318
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001319def add_gbproxy_test(suite, workdir):
1320 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-gbproxy")):
1321 print("Skipping the Gb-Proxy test")
1322 return
1323 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYGbproxy)
1324 suite.addTest(test)
1325
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001326def add_sgsn_test(suite, workdir):
1327 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-sgsn")):
1328 print("Skipping the SGSN test")
1329 return
1330 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYSGSN)
1331 suite.addTest(test)
1332
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001333if __name__ == '__main__':
1334 import argparse
1335 import sys
1336
1337 workdir = '.'
1338
1339 parser = argparse.ArgumentParser()
1340 parser.add_argument("-v", "--verbose", dest="verbose",
1341 action="store_true", help="verbose mode")
1342 parser.add_argument("-p", "--pythonconfpath", dest="p",
1343 help="searchpath for config")
1344 parser.add_argument("-w", "--workdir", dest="w",
1345 help="Working directory")
Neels Hofmeyr3f8a8f72017-02-28 02:43:29 +01001346 parser.add_argument("test_name", nargs="*", help="(parts of) test names to run, case-insensitive")
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001347 args = parser.parse_args()
1348
1349 verbose_level = 1
1350 if args.verbose:
1351 verbose_level = 2
1352
1353 if args.w:
1354 workdir = args.w
1355
1356 if args.p:
1357 confpath = args.p
1358
1359 print "confpath %s, workdir %s" % (confpath, workdir)
1360 os.chdir(workdir)
1361 print "Running tests for specific VTY commands"
1362 suite = unittest.TestSuite()
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +02001363 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYMGCP))
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +02001364 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB))
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001365 add_bsc_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001366 add_nat_test(suite, workdir)
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001367 add_gbproxy_test(suite, workdir)
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001368 add_sgsn_test(suite, workdir)
Neels Hofmeyr3f8a8f72017-02-28 02:43:29 +01001369
1370 if args.test_name:
1371 osmoutil.pick_tests(suite, *args.test_name)
1372
Neels Hofmeyr0a45c1e2016-09-28 23:48:02 +02001373 res = unittest.TextTestRunner(verbosity=verbose_level, stream=sys.stdout).run(suite)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001374 sys.exit(len(res.errors) + len(res.failures))
Neels Hofmeyr23d37c92016-09-26 03:18:32 +02001375
Neels Hofmeyr0867b722016-09-28 23:28:06 +02001376# vim: shiftwidth=4 expandtab nocin ai