blob: b8869116f9c5ce6f62627397b95029cc60a5dc33 [file] [log] [blame]
Holger Hans Peter Freyther65397522013-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
Max5fd98942016-11-16 14:55:21 +010018import os, sys
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +020019import time
20import unittest
Jacob Erlbeck4684eb62013-08-14 11:10:34 +020021import socket
Neels Hofmeyrd81df4f2017-02-03 16:09:17 +010022import subprocess
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +020023
24import osmopy.obscvty as obscvty
25import osmopy.osmoutil as osmoutil
26
Neels Hofmeyr6226a362017-02-24 17:55:11 +010027# add $top_srcdir/contrib to find ipa.py
28sys.path.append(os.path.join(sys.path[0], '..', 'contrib'))
29
Max5fd98942016-11-16 14:55:21 +010030from ipa import IPA
31
Neels Hofmeyr6226a362017-02-24 17:55:11 +010032# to be able to find $top_srcdir/doc/...
33confpath = os.path.join(sys.path[0], '..')
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +020034
35class TestVTYBase(unittest.TestCase):
36
37 def vty_command(self):
38 raise Exception("Needs to be implemented by a subclass")
39
40 def vty_app(self):
41 raise Exception("Needs to be implemented by a subclass")
42
43 def setUp(self):
44 osmo_vty_cmd = self.vty_command()[:]
45 config_index = osmo_vty_cmd.index('-c')
46 if config_index:
47 cfi = config_index + 1
48 osmo_vty_cmd[cfi] = os.path.join(confpath, osmo_vty_cmd[cfi])
49
50 try:
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +020051 self.proc = osmoutil.popen_devnull(osmo_vty_cmd)
52 except OSError:
53 print >> sys.stderr, "Current directory: %s" % os.getcwd()
54 print >> sys.stderr, "Consider setting -b"
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +020055
56 appstring = self.vty_app()[2]
57 appport = self.vty_app()[0]
58 self.vty = obscvty.VTYInteract(appstring, "127.0.0.1", appport)
59
60 def tearDown(self):
Neels Hofmeyrd5834d12017-02-24 17:54:22 +010061 if self.vty:
62 self.vty._close_socket()
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +020063 self.vty = None
64 osmoutil.end_proc(self.proc)
65
Holger Hans Peter Freytherb30b3aa2014-07-04 20:23:56 +020066class TestVTYMGCP(TestVTYBase):
67 def vty_command(self):
68 return ["./src/osmo-bsc_mgcp/osmo-bsc_mgcp", "-c",
69 "doc/examples/osmo-bsc_mgcp/mgcp.cfg"]
70
71 def vty_app(self):
72 return (4243, "./src/osmo-bsc_mgcp/osmo-bsc_mgcp", "OpenBSC MGCP", "mgcp")
73
74 def testForcePtime(self):
Neels Hofmeyrb9935632016-09-28 23:28:06 +020075 self.vty.enable()
76 res = self.vty.command("show running-config")
77 self.assert_(res.find(' rtp force-ptime 20\r') > 0)
78 self.assertEquals(res.find(' no rtp force-ptime\r'), -1)
Holger Hans Peter Freytherb30b3aa2014-07-04 20:23:56 +020079
Neels Hofmeyrb9935632016-09-28 23:28:06 +020080 self.vty.command("configure terminal")
81 self.vty.command("mgcp")
82 self.vty.command("no rtp force-ptime")
83 res = self.vty.command("show running-config")
84 self.assertEquals(res.find(' rtp force-ptime 20\r'), -1)
85 self.assertEquals(res.find(' no rtp force-ptime\r'), -1)
Holger Hans Peter Freytherb30b3aa2014-07-04 20:23:56 +020086
Holger Hans Peter Freyther60e09922014-11-19 16:04:45 +010087 def testOmitAudio(self):
88 self.vty.enable()
Neels Hofmeyrb9935632016-09-28 23:28:06 +020089 res = self.vty.command("show running-config")
90 self.assert_(res.find(' sdp audio-payload send-name\r') > 0)
91 self.assertEquals(res.find(' no sdp audio-payload send-name\r'), -1)
Holger Hans Peter Freyther60e09922014-11-19 16:04:45 +010092
Neels Hofmeyrb9935632016-09-28 23:28:06 +020093 self.vty.command("configure terminal")
94 self.vty.command("mgcp")
95 self.vty.command("no sdp audio-payload send-name")
96 res = self.vty.command("show running-config")
97 self.assertEquals(res.find(' rtp sdp audio-payload send-name\r'), -1)
98 self.assert_(res.find(' no sdp audio-payload send-name\r') > 0)
Holger Hans Peter Freyther60e09922014-11-19 16:04:45 +010099
100 # TODO: test it for the trunk!
101
Holger Hans Peter Freythere5899382015-08-20 15:15:50 +0200102 def testBindAddr(self):
103 self.vty.enable()
104
Neels Hofmeyrb9935632016-09-28 23:28:06 +0200105 self.vty.command("configure terminal")
106 self.vty.command("mgcp")
Holger Hans Peter Freythere5899382015-08-20 15:15:50 +0200107
108 # enable.. disable bts-bind-ip
109 self.vty.command("rtp bts-bind-ip 254.253.252.250")
110 res = self.vty.command("show running-config")
111 self.assert_(res.find('rtp bts-bind-ip 254.253.252.250') > 0)
112 self.vty.command("no rtp bts-bind-ip")
113 res = self.vty.command("show running-config")
114 self.assertEquals(res.find(' rtp bts-bind-ip'), -1)
115
116 # enable.. disable net-bind-ip
117 self.vty.command("rtp net-bind-ip 254.253.252.250")
118 res = self.vty.command("show running-config")
119 self.assert_(res.find('rtp net-bind-ip 254.253.252.250') > 0)
120 self.vty.command("no rtp net-bind-ip")
121 res = self.vty.command("show running-config")
122 self.assertEquals(res.find(' rtp net-bind-ip'), -1)
123
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200124
125class TestVTYGenericBSC(TestVTYBase):
126
127 def checkForEndAndExit(self):
128 res = self.vty.command("list")
129 #print ('looking for "exit"\n')
130 self.assert_(res.find(' exit\r') > 0)
131 #print 'found "exit"\nlooking for "end"\n'
132 self.assert_(res.find(' end\r') > 0)
133 #print 'found "end"\n'
134
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200135 def _testConfigNetworkTree(self):
136 self.vty.enable()
137 self.assertTrue(self.vty.verify("configure terminal",['']))
138 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbecka4235912013-10-29 09:30:31 +0100139 self.checkForEndAndExit()
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200140 self.assertTrue(self.vty.verify("network",['']))
141 self.assertEquals(self.vty.node(), 'config-net')
142 self.checkForEndAndExit()
143 self.assertTrue(self.vty.verify("bts 0",['']))
144 self.assertEquals(self.vty.node(), 'config-net-bts')
145 self.checkForEndAndExit()
146 self.assertTrue(self.vty.verify("trx 0",['']))
147 self.assertEquals(self.vty.node(), 'config-net-bts-trx')
148 self.checkForEndAndExit()
Jacob Erlbeck5e229112013-09-11 10:46:56 +0200149 self.vty.command("write terminal")
150 self.assertTrue(self.vty.verify("exit",['']))
151 self.assertEquals(self.vty.node(), 'config-net-bts')
152 self.assertTrue(self.vty.verify("exit",['']))
153 self.assertTrue(self.vty.verify("bts 1",['']))
154 self.assertEquals(self.vty.node(), 'config-net-bts')
155 self.checkForEndAndExit()
156 self.assertTrue(self.vty.verify("trx 1",['']))
157 self.assertEquals(self.vty.node(), 'config-net-bts-trx')
158 self.checkForEndAndExit()
159 self.vty.command("write terminal")
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200160 self.assertTrue(self.vty.verify("exit",['']))
161 self.assertEquals(self.vty.node(), 'config-net-bts')
162 self.assertTrue(self.vty.verify("exit",['']))
163 self.assertEquals(self.vty.node(), 'config-net')
164 self.assertTrue(self.vty.verify("exit",['']))
165 self.assertEquals(self.vty.node(), 'config')
166 self.assertTrue(self.vty.verify("exit",['']))
167 self.assertTrue(self.vty.node() is None)
168
169class TestVTYNITB(TestVTYGenericBSC):
Holger Hans Peter Freyther2fb8ebf2013-07-27 21:07:57 +0200170
171 def vty_command(self):
172 return ["./src/osmo-nitb/osmo-nitb", "-c",
173 "doc/examples/osmo-nitb/nanobts/openbsc.cfg"]
174
175 def vty_app(self):
176 return (4242, "./src/osmo-nitb/osmo-nitb", "OpenBSC", "nitb")
177
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200178 def testConfigNetworkTree(self):
Jacob Erlbeck5c46e932013-10-23 11:24:14 +0200179 self._testConfigNetworkTree()
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200180
Holger Hans Peter Freytherabb54ae2013-09-02 20:58:38 +0200181 def checkForSmpp(self):
182 """SMPP is not always enabled, check if it is"""
183 res = self.vty.command("list")
184 return "smpp" in res
185
Holger Hans Peter Freyther3c64e2d2015-07-06 16:41:30 +0200186 def testSmppFirst(self):
Holger Hans Peter Freyther3c64e2d2015-07-06 16:41:30 +0200187 # enable the configuration
188 self.vty.enable()
189 self.vty.command("configure terminal")
Holger Hans Peter Freyther9c700ee2015-07-13 11:23:53 +0200190
191 if not self.checkForSmpp():
192 return
193
Holger Hans Peter Freyther3c64e2d2015-07-06 16:41:30 +0200194 self.vty.command("smpp")
195
196 # check the default
197 res = self.vty.command("write terminal")
198 self.assert_(res.find(' no smpp-first') > 0)
199
200 self.vty.verify("smpp-first", [''])
201 res = self.vty.command("write terminal")
202 self.assert_(res.find(' smpp-first') > 0)
203 self.assertEquals(res.find('no smpp-first'), -1)
204
205 self.vty.verify("no smpp-first", [''])
206 res = self.vty.command("write terminal")
207 self.assert_(res.find('no smpp-first') > 0)
208
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200209 def testVtyTree(self):
210 self.vty.enable()
211 self.assertTrue(self.vty.verify("configure terminal", ['']))
212 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbecka4235912013-10-29 09:30:31 +0100213 self.checkForEndAndExit()
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200214 self.assertTrue(self.vty.verify('mncc-int', ['']))
215 self.assertEquals(self.vty.node(), 'config-mncc-int')
216 self.checkForEndAndExit()
217 self.assertTrue(self.vty.verify('exit', ['']))
Holger Hans Peter Freytherabb54ae2013-09-02 20:58:38 +0200218
219 if self.checkForSmpp():
220 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck5c46e932013-10-23 11:24:14 +0200221 self.assertTrue(self.vty.verify('smpp', ['']))
222 self.assertEquals(self.vty.node(), 'config-smpp')
Jacob Erlbecka4235912013-10-29 09:30:31 +0100223 self.checkForEndAndExit()
Jacob Erlbeck5c46e932013-10-23 11:24:14 +0200224 self.assertTrue(self.vty.verify("exit", ['']))
Holger Hans Peter Freytherabb54ae2013-09-02 20:58:38 +0200225
Jacob Erlbeckbf8eec72013-09-02 13:17:16 +0200226 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200227 self.assertTrue(self.vty.verify("exit", ['']))
228 self.assertTrue(self.vty.node() is None)
229
230 # Check searching for outer node's commands
231 self.vty.command("configure terminal")
232 self.vty.command('mncc-int')
Holger Hans Peter Freytherabb54ae2013-09-02 20:58:38 +0200233
234 if self.checkForSmpp():
235 self.vty.command('smpp')
236 self.assertEquals(self.vty.node(), 'config-smpp')
237 self.vty.command('mncc-int')
238
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200239 self.assertEquals(self.vty.node(), 'config-mncc-int')
240
Max0a378ba2016-05-24 14:23:27 +0200241 def testVtyAuthorization(self):
242 self.vty.enable()
243 self.vty.command("configure terminal")
244 self.vty.command("network")
245 self.assertTrue(self.vty.verify("auth policy closed", ['']))
246 self.assertTrue(self.vty.verify("auth policy regexp", ['']))
247 self.assertTrue(self.vty.verify("authorized-regexp ^001", ['']))
248 self.assertTrue(self.vty.verify("authorized-regexp 02$", ['']))
249 self.assertTrue(self.vty.verify("authorized-regexp *123.*", ['']))
250 self.vty.command("end")
251 self.vty.command("configure terminal")
252 self.vty.command("nitb")
253 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
Max58726412016-06-30 10:25:49 +0200254 self.assertTrue(self.vty.verify("subscriber-create-on-demand no-extension", ['']))
Max0a378ba2016-05-24 14:23:27 +0200255 self.vty.command("end")
256
Max2befab12016-04-20 12:06:06 +0200257 def testSi2Q(self):
258 self.vty.enable()
259 self.vty.command("configure terminal")
260 self.vty.command("network")
261 self.vty.command("bts 0")
262 before = self.vty.command("show running-config")
263 self.vty.command("si2quater neighbor-list add earfcn 1911 threshold 11 2")
264 self.vty.command("si2quater neighbor-list add earfcn 1924 threshold 11 3")
265 self.vty.command("si2quater neighbor-list add earfcn 2111 threshold 11")
266 self.vty.command("si2quater neighbor-list del earfcn 1911")
267 self.vty.command("si2quater neighbor-list del earfcn 1924")
268 self.vty.command("si2quater neighbor-list del earfcn 2111")
269 self.assertEquals(before, self.vty.command("show running-config"))
Maxeaf196c2016-04-20 15:57:13 +0200270 self.vty.command("si2quater neighbor-list add uarfcn 1976 13 1")
271 self.vty.command("si2quater neighbor-list add uarfcn 1976 38 1")
272 self.vty.command("si2quater neighbor-list add uarfcn 1976 44 1")
273 self.vty.command("si2quater neighbor-list add uarfcn 1976 120 1")
274 self.vty.command("si2quater neighbor-list add uarfcn 1976 140 1")
275 self.vty.command("si2quater neighbor-list add uarfcn 1976 163 1")
276 self.vty.command("si2quater neighbor-list add uarfcn 1976 166 1")
277 self.vty.command("si2quater neighbor-list add uarfcn 1976 217 1")
278 self.vty.command("si2quater neighbor-list add uarfcn 1976 224 1")
279 self.vty.command("si2quater neighbor-list add uarfcn 1976 225 1")
280 self.vty.command("si2quater neighbor-list add uarfcn 1976 226 1")
281 self.vty.command("si2quater neighbor-list del uarfcn 1976 13")
282 self.vty.command("si2quater neighbor-list del uarfcn 1976 38")
283 self.vty.command("si2quater neighbor-list del uarfcn 1976 44")
284 self.vty.command("si2quater neighbor-list del uarfcn 1976 120")
285 self.vty.command("si2quater neighbor-list del uarfcn 1976 140")
286 self.vty.command("si2quater neighbor-list del uarfcn 1976 163")
287 self.vty.command("si2quater neighbor-list del uarfcn 1976 166")
288 self.vty.command("si2quater neighbor-list del uarfcn 1976 217")
289 self.vty.command("si2quater neighbor-list del uarfcn 1976 224")
290 self.vty.command("si2quater neighbor-list del uarfcn 1976 225")
291 self.vty.command("si2quater neighbor-list del uarfcn 1976 226")
292 self.assertEquals(before, self.vty.command("show running-config"))
Max2befab12016-04-20 12:06:06 +0200293
Holger Hans Peter Freyther2fb8ebf2013-07-27 21:07:57 +0200294 def testEnableDisablePeriodicLU(self):
295 self.vty.enable()
296 self.vty.command("configure terminal")
297 self.vty.command("network")
298 self.vty.command("bts 0")
299
300 # Test invalid input
301 self.vty.verify("periodic location update 0", ['% Unknown command.'])
302 self.vty.verify("periodic location update 5", ['% Unknown command.'])
303 self.vty.verify("periodic location update 1531", ['% Unknown command.'])
304
305 # Enable periodic lu..
306 self.vty.verify("periodic location update 60", [''])
307 res = self.vty.command("write terminal")
Holger Hans Peter Freythereda08672013-07-27 22:23:25 +0200308 self.assert_(res.find('periodic location update 60') > 0)
Holger Hans Peter Freyther2fb8ebf2013-07-27 21:07:57 +0200309 self.assertEquals(res.find('no periodic location update'), -1)
310
311 # Now disable it..
312 self.vty.verify("no periodic location update", [''])
313 res = self.vty.command("write terminal")
314 self.assertEquals(res.find('periodic location update 60'), -1)
Holger Hans Peter Freythereda08672013-07-27 22:23:25 +0200315 self.assert_(res.find('no periodic location update') > 0)
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +0200316
Jacob Erlbeck8f8e5bf2014-01-16 11:02:14 +0100317 def testEnableDisableSiHacks(self):
318 self.vty.enable()
319 self.vty.command("configure terminal")
320 self.vty.command("network")
321 self.vty.command("bts 0")
322
323 # Enable periodic lu..
324 self.vty.verify("force-combined-si", [''])
325 res = self.vty.command("write terminal")
326 self.assert_(res.find(' force-combined-si') > 0)
327 self.assertEquals(res.find('no force-combined-si'), -1)
328
329 # Now disable it..
330 self.vty.verify("no force-combined-si", [''])
331 res = self.vty.command("write terminal")
332 self.assertEquals(res.find(' force-combined-si'), -1)
333 self.assert_(res.find('no force-combined-si') > 0)
334
Ivan Kluchnikov80d58432013-09-16 13:13:04 +0400335 def testRachAccessControlClass(self):
336 self.vty.enable()
337 self.vty.command("configure terminal")
338 self.vty.command("network")
339 self.vty.command("bts 0")
340
341 # Test invalid input
342 self.vty.verify("rach access-control-class", ['% Command incomplete.'])
343 self.vty.verify("rach access-control-class 1", ['% Command incomplete.'])
344 self.vty.verify("rach access-control-class -1", ['% Unknown command.'])
345 self.vty.verify("rach access-control-class 10", ['% Unknown command.'])
346 self.vty.verify("rach access-control-class 16", ['% Unknown command.'])
347
348 # Barred rach access control classes
349 for classNum in range(16):
350 if classNum != 10:
351 self.vty.verify("rach access-control-class " + str(classNum) + " barred", [''])
352
353 # Verify settings
354 res = self.vty.command("write terminal")
355 for classNum in range(16):
356 if classNum != 10:
357 self.assert_(res.find("rach access-control-class " + str(classNum) + " barred") > 0)
358
359 # Allowed rach access control classes
360 for classNum in range(16):
361 if classNum != 10:
362 self.vty.verify("rach access-control-class " + str(classNum) + " allowed", [''])
363
364 # Verify settings
365 res = self.vty.command("write terminal")
366 for classNum in range(16):
367 if classNum != 10:
368 self.assertEquals(res.find("rach access-control-class " + str(classNum) + " barred"), -1)
369
Holger Hans Peter Freyther75543292016-04-01 19:44:00 +0200370 def testSubscriberCreateDeleteTwice(self):
371 """
372 OS#1657 indicates that there might be an issue creating the
373 same subscriber twice. This test will use the VTY command to
374 create a subscriber and then issue a second create command
375 with the same IMSI. The test passes if the VTY continues to
376 respond to VTY commands.
377 """
378 self.vty.enable()
379
380 imsi = "204300854013739"
381
382 # Initially we don't have this subscriber
383 self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi])
384
385 # Lets create one
386 res = self.vty.command('subscriber create imsi '+imsi)
387 self.assert_(res.find(" IMSI: "+imsi) > 0)
388 # And now create one again.
389 res2 = self.vty.command('subscriber create imsi '+imsi)
390 self.assert_(res2.find(" IMSI: "+imsi) > 0)
391 self.assertEqual(res, res2)
392
393 # Verify it has been created
394 res = self.vty.command('show subscriber imsi '+imsi)
395 self.assert_(res.find(" IMSI: "+imsi) > 0)
396
397 # Delete it
Maxc5d6a902016-06-22 14:02:39 +0200398 res = self.vty.command('subscriber imsi ' + imsi + ' delete')
399 self.assert_("" == res)
Holger Hans Peter Freyther75543292016-04-01 19:44:00 +0200400
401 # Now it should not be there anymore
402 res = self.vty.command('show subscriber imsi '+imsi)
Maxc5d6a902016-06-22 14:02:39 +0200403 self.assert_(('% No subscriber found for imsi ' + imsi) == res)
Holger Hans Peter Freyther75543292016-04-01 19:44:00 +0200404
405
Ruben Pollan6af2b402014-09-24 20:50:13 -0500406 def testSubscriberCreateDelete(self):
Alexander Chemerise092dec2013-10-04 23:54:17 +0200407 self.vty.enable()
408
409 imsi = "204300854013739"
Max58726412016-06-30 10:25:49 +0200410 imsi2 = "222301824913762"
411 imsi3 = "333500854113763"
412 imsi4 = "444583744053764"
Alexander Chemerise092dec2013-10-04 23:54:17 +0200413
414 # Initially we don't have this subscriber
415 self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi])
416
417 # Lets create one
418 res = self.vty.command('subscriber create imsi '+imsi)
419 self.assert_(res.find(" IMSI: "+imsi) > 0)
Max58726412016-06-30 10:25:49 +0200420 self.assert_(res.find("Extension") > 0)
Alexander Chemerise092dec2013-10-04 23:54:17 +0200421
422 # Now we have it
423 res = self.vty.command('show subscriber imsi '+imsi)
424 self.assert_(res.find(" IMSI: "+imsi) > 0)
425
Max58726412016-06-30 10:25:49 +0200426 # With narrow random interval
427 self.vty.command("configure terminal")
428 self.vty.command("nitb")
429 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
430 # wrong interval
431 res = self.vty.command("subscriber-create-on-demand random 221 122")
432 # error string will contain arguments
433 self.assert_(res.find("122") > 0)
434 self.assert_(res.find("221") > 0)
435 # correct interval - silent ok
436 self.assertTrue(self.vty.verify("subscriber-create-on-demand random 221 222", ['']))
437 self.vty.command("end")
438
439 res = self.vty.command('subscriber create imsi ' + imsi2)
440 self.assert_(res.find(" IMSI: " + imsi2) > 0)
441 self.assert_(res.find("221") > 0 or res.find("222") > 0)
442 self.assert_(res.find(" Extension: ") > 0)
443
444 # Without extension
445 self.vty.command("configure terminal")
446 self.vty.command("nitb")
447 self.assertTrue(self.vty.verify("subscriber-create-on-demand no-extension", ['']))
448 self.vty.command("end")
449 res = self.vty.command('subscriber create imsi ' + imsi3)
450 self.assert_(res.find(" IMSI: " + imsi3) > 0)
451 self.assertEquals(res.find("Extension"), -1)
452
453 # With extension again
454 self.vty.command("configure terminal")
455 self.vty.command("nitb")
456 self.assertTrue(self.vty.verify("no subscriber-create-on-demand", ['']))
457 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
458 self.assertTrue(self.vty.verify("subscriber-create-on-demand random 221 666", ['']))
459 self.vty.command("end")
460
461 res = self.vty.command('subscriber create imsi ' + imsi4)
462 self.assert_(res.find(" IMSI: " + imsi4) > 0)
463 self.assert_(res.find(" Extension: ") > 0)
464
Ruben Pollan6af2b402014-09-24 20:50:13 -0500465 # Delete it
Maxc5d6a902016-06-22 14:02:39 +0200466 res = self.vty.command('subscriber imsi ' + imsi + ' delete')
467 self.assert_("" == res)
Max58726412016-06-30 10:25:49 +0200468 res = self.vty.command('subscriber imsi ' + imsi2 + ' delete')
469 self.assert_("" == res)
470 res = self.vty.command('subscriber imsi ' + imsi3 + ' delete')
471 self.assert_("" == res)
472 res = self.vty.command('subscriber imsi ' + imsi4 + ' delete')
473 self.assert_("" == res)
Ruben Pollan6af2b402014-09-24 20:50:13 -0500474
475 # Now it should not be there anymore
476 res = self.vty.command('show subscriber imsi '+imsi)
Maxc5d6a902016-06-22 14:02:39 +0200477 self.assert_(('% No subscriber found for imsi ' + imsi) == res)
Ruben Pollan6af2b402014-09-24 20:50:13 -0500478
Neels Hofmeyrbdefe552017-05-12 14:56:25 +0200479 # range
480 self.vty.command("end")
481 self.vty.command("configure terminal")
482 self.vty.command("nitb")
483 self.assertTrue(self.vty.verify("subscriber-create-on-demand random 9999999998 9999999999", ['']))
484 res = self.vty.command("show running-config")
485 self.assert_(res.find("subscriber-create-on-demand random 9999999998 9999999999"))
486 self.vty.command("end")
487
488
489
Jacob Erlbeck508c3102015-04-07 17:49:49 +0200490 def testSubscriberSettings(self):
491 self.vty.enable()
492
493 imsi = "204300854013739"
Max39115332016-06-07 15:32:16 +0200494 imsi2 = "204301824913769"
Jacob Erlbeck508c3102015-04-07 17:49:49 +0200495 wrong_imsi = "204300999999999"
496
497 # Lets create one
498 res = self.vty.command('subscriber create imsi '+imsi)
499 self.assert_(res.find(" IMSI: "+imsi) > 0)
Max39115332016-06-07 15:32:16 +0200500 self.assert_(res.find("Extension") > 0)
Jacob Erlbeck508c3102015-04-07 17:49:49 +0200501
502 self.vty.verify('subscriber imsi '+wrong_imsi+' name wrong', ['% No subscriber found for imsi '+wrong_imsi])
503 res = self.vty.command('subscriber imsi '+imsi+' name '+('X' * 160))
504 self.assert_(res.find("NAME is too long") > 0)
505
506 self.vty.verify('subscriber imsi '+imsi+' name '+('G' * 159), [''])
507
508 self.vty.verify('subscriber imsi '+wrong_imsi+' extension 840', ['% No subscriber found for imsi '+wrong_imsi])
509 res = self.vty.command('subscriber imsi '+imsi+' extension '+('9' * 15))
510 self.assert_(res.find("EXTENSION is too long") > 0)
511
512 self.vty.verify('subscriber imsi '+imsi+' extension '+('1' * 14), [''])
513
Max39115332016-06-07 15:32:16 +0200514 # With narrow random interval
515 self.vty.command("configure terminal")
516 self.vty.command("nitb")
517 self.assertTrue(self.vty.verify("subscriber-create-on-demand", ['']))
518 # wrong interval
519 res = self.vty.command("subscriber-create-on-demand random 221 122")
520 self.assert_(res.find("122") > 0)
521 self.assert_(res.find("221") > 0)
522 # correct interval
523 self.assertTrue(self.vty.verify("subscriber-create-on-demand random 221 222", ['']))
524 self.vty.command("end")
525
Maxc5d6a902016-06-22 14:02:39 +0200526 # create subscriber with extension in a configured interval
Max39115332016-06-07 15:32:16 +0200527 res = self.vty.command('subscriber create imsi ' + imsi2)
528 self.assert_(res.find(" IMSI: " + imsi2) > 0)
529 self.assert_(res.find("221") > 0 or res.find("222") > 0)
530 self.assert_(res.find(" Extension: ") > 0)
531
Jacob Erlbeck508c3102015-04-07 17:49:49 +0200532 # Delete it
Maxc5d6a902016-06-22 14:02:39 +0200533 res = self.vty.command('subscriber imsi ' + imsi + ' delete')
Jacob Erlbeck508c3102015-04-07 17:49:49 +0200534 self.assert_(res != "")
Maxc5d6a902016-06-22 14:02:39 +0200535 # imsi2 is inactive so deletion should succeed
536 res = self.vty.command('subscriber imsi ' + imsi2 + ' delete')
537 self.assert_("" == res)
Jacob Erlbeck508c3102015-04-07 17:49:49 +0200538
Holger Hans Peter Freyther35e6fbb2013-02-05 09:39:09 +0100539 def testShowPagingGroup(self):
540 res = self.vty.command("show paging-group 255 1234567")
541 self.assertEqual(res, "% can't find BTS 255")
542 res = self.vty.command("show paging-group 0 1234567")
543 self.assertEquals(res, "%Paging group for IMSI 1234567 on BTS #0 is 7")
544
Ciaby38abd7b2014-03-06 17:20:55 +0100545 def testShowNetwork(self):
546 res = self.vty.command("show network")
547 self.assert_(res.startswith('BSC is on Country Code') >= 0)
548
Holger Hans Peter Freyther65b89922015-01-31 09:47:37 +0100549 def testMeasurementFeed(self):
550 self.vty.enable()
551 self.vty.command("configure terminal")
552 self.vty.command("mncc-int")
553
554 res = self.vty.command("write terminal")
555 self.assertEquals(res.find('meas-feed scenario'), -1)
556
557 self.vty.command("meas-feed scenario bla")
558 res = self.vty.command("write terminal")
559 self.assert_(res.find('meas-feed scenario bla') > 0)
560
Neels Hofmeyrb9935632016-09-28 23:28:06 +0200561 self.vty.command("meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890")
Holger Hans Peter Freyther65b89922015-01-31 09:47:37 +0100562 res = self.vty.command("write terminal")
563 self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890'), -1)
564 self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz012345'), -1)
565 self.assert_(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234') > 0)
566
567
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200568class TestVTYBSC(TestVTYGenericBSC):
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200569
570 def vty_command(self):
571 return ["./src/osmo-bsc/osmo-bsc", "-c",
572 "doc/examples/osmo-bsc/osmo-bsc.cfg"]
573
574 def vty_app(self):
575 return (4242, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc")
576
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200577 def testConfigNetworkTree(self):
Jacob Erlbeck5c46e932013-10-23 11:24:14 +0200578 self._testConfigNetworkTree()
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200579
580 def testVtyTree(self):
581 self.vty.enable()
582 self.assertTrue(self.vty.verify("configure terminal", ['']))
583 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbecka4235912013-10-29 09:30:31 +0100584 self.checkForEndAndExit()
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200585 self.assertTrue(self.vty.verify("msc 0", ['']))
586 self.assertEquals(self.vty.node(), 'config-msc')
Jacob Erlbeckbf8eec72013-09-02 13:17:16 +0200587 self.checkForEndAndExit()
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200588 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeckbf8eec72013-09-02 13:17:16 +0200589 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200590 self.assertTrue(self.vty.verify("bsc", ['']))
591 self.assertEquals(self.vty.node(), 'config-bsc')
Jacob Erlbeckbf8eec72013-09-02 13:17:16 +0200592 self.checkForEndAndExit()
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200593 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeckbf8eec72013-09-02 13:17:16 +0200594 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200595 self.assertTrue(self.vty.verify("exit", ['']))
596 self.assertTrue(self.vty.node() is None)
597
598 # Check searching for outer node's commands
599 self.vty.command("configure terminal")
600 self.vty.command('msc 0')
601 self.vty.command("bsc")
602 self.assertEquals(self.vty.node(), 'config-bsc')
603 self.vty.command("msc 0")
604 self.assertEquals(self.vty.node(), 'config-msc')
605
Jacob Erlbeck3ccb86b2013-09-11 10:46:55 +0200606 def testUssdNotificationsMsc(self):
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200607 self.vty.enable()
608 self.vty.command("configure terminal")
609 self.vty.command("msc")
610
611 # Test invalid input
612 self.vty.verify("bsc-msc-lost-text", ['% Command incomplete.'])
Jacob Erlbeckb62092a2013-08-28 10:16:55 +0200613 self.vty.verify("bsc-welcome-text", ['% Command incomplete.'])
Jacob Erlbeck3ccb86b2013-09-11 10:46:55 +0200614 self.vty.verify("bsc-grace-text", ['% Command incomplete.'])
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200615
616 # Enable USSD notifications
617 self.vty.verify("bsc-msc-lost-text MSC disconnected", [''])
Jacob Erlbeckb62092a2013-08-28 10:16:55 +0200618 self.vty.verify("bsc-welcome-text Hello MS", [''])
Jacob Erlbeck3ccb86b2013-09-11 10:46:55 +0200619 self.vty.verify("bsc-grace-text In grace period", [''])
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200620
621 # Verify settings
622 res = self.vty.command("write terminal")
623 self.assert_(res.find('bsc-msc-lost-text MSC disconnected') > 0)
624 self.assertEquals(res.find('no bsc-msc-lost-text'), -1)
Jacob Erlbeckb62092a2013-08-28 10:16:55 +0200625 self.assert_(res.find('bsc-welcome-text Hello MS') > 0)
626 self.assertEquals(res.find('no bsc-welcome-text'), -1)
Jacob Erlbeck3ccb86b2013-09-11 10:46:55 +0200627 self.assert_(res.find('bsc-grace-text In grace period') > 0)
628 self.assertEquals(res.find('no bsc-grace-text'), -1)
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200629
630 # Now disable it..
631 self.vty.verify("no bsc-msc-lost-text", [''])
Jacob Erlbeckb62092a2013-08-28 10:16:55 +0200632 self.vty.verify("no bsc-welcome-text", [''])
Jacob Erlbeck3ccb86b2013-09-11 10:46:55 +0200633 self.vty.verify("no bsc-grace-text", [''])
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200634
635 # Verify settings
636 res = self.vty.command("write terminal")
637 self.assertEquals(res.find('bsc-msc-lost-text MSC disconnected'), -1)
638 self.assert_(res.find('no bsc-msc-lost-text') > 0)
Jacob Erlbeckb62092a2013-08-28 10:16:55 +0200639 self.assertEquals(res.find('bsc-welcome-text Hello MS'), -1)
Jacob Erlbeck3ccb86b2013-09-11 10:46:55 +0200640 self.assert_(res.find('no bsc-welcome-text') > 0)
641 self.assertEquals(res.find('bsc-grace-text In grace period'), -1)
642 self.assert_(res.find('no bsc-grace-text') > 0)
643
644 def testUssdNotificationsBsc(self):
645 self.vty.enable()
646 self.vty.command("configure terminal")
647 self.vty.command("bsc")
648
649 # Test invalid input
650 self.vty.verify("missing-msc-text", ['% Command incomplete.'])
651
652 # Enable USSD notifications
653 self.vty.verify("missing-msc-text No MSC found", [''])
654
655 # Verify settings
656 res = self.vty.command("write terminal")
657 self.assert_(res.find('missing-msc-text No MSC found') > 0)
658 self.assertEquals(res.find('no missing-msc-text'), -1)
659
660 # Now disable it..
661 self.vty.verify("no missing-msc-text", [''])
662
663 # Verify settings
664 res = self.vty.command("write terminal")
665 self.assertEquals(res.find('missing-msc-text No MSC found'), -1)
666 self.assert_(res.find('no missing-msc-text') > 0)
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200667
Jacob Erlbeckcc0d8842013-09-17 13:59:29 +0200668 def testNetworkTimezone(self):
669 self.vty.enable()
670 self.vty.verify("configure terminal", [''])
671 self.vty.verify("network", [''])
Jacob Erlbeckcc0d8842013-09-17 13:59:29 +0200672
673 # Test invalid input
674 self.vty.verify("timezone", ['% Command incomplete.'])
675 self.vty.verify("timezone 20 0", ['% Unknown command.'])
676 self.vty.verify("timezone 0 11", ['% Unknown command.'])
677 self.vty.verify("timezone 0 0 99", ['% Unknown command.'])
678
679 # Set time zone without DST
680 self.vty.verify("timezone 2 30", [''])
681
682 # Verify settings
683 res = self.vty.command("write terminal")
684 self.assert_(res.find('timezone 2 30') > 0)
685 self.assertEquals(res.find('timezone 2 30 '), -1)
686
687 # Set time zone with DST
688 self.vty.verify("timezone 2 30 1", [''])
689
690 # Verify settings
691 res = self.vty.command("write terminal")
692 self.assert_(res.find('timezone 2 30 1') > 0)
693
694 # Now disable it..
695 self.vty.verify("no timezone", [''])
696
697 # Verify settings
698 res = self.vty.command("write terminal")
699 self.assertEquals(res.find(' timezone'), -1)
700
Ciaby38abd7b2014-03-06 17:20:55 +0100701 def testShowNetwork(self):
702 res = self.vty.command("show network")
703 self.assert_(res.startswith('BSC is on Country Code') >= 0)
704
Holger Hans Peter Freytherd2b37c52014-10-29 10:06:15 +0100705 def testPingPongConfiguration(self):
706 self.vty.enable()
707 self.vty.verify("configure terminal", [''])
708 self.vty.verify("network", [''])
709 self.vty.verify("msc 0", [''])
710
711 self.vty.verify("timeout-ping 12", [''])
712 self.vty.verify("timeout-pong 14", [''])
713 res = self.vty.command("show running-config")
714 self.assert_(res.find(" timeout-ping 12") > 0)
715 self.assert_(res.find(" timeout-pong 14") > 0)
716 self.assert_(res.find(" no timeout-ping advanced") > 0)
717
718 self.vty.verify("timeout-ping advanced", [''])
719 res = self.vty.command("show running-config")
720 self.assert_(res.find(" timeout-ping 12") > 0)
721 self.assert_(res.find(" timeout-pong 14") > 0)
722 self.assert_(res.find(" timeout-ping advanced") > 0)
723
724 self.vty.verify("no timeout-ping advanced", [''])
725 res = self.vty.command("show running-config")
726 self.assert_(res.find(" timeout-ping 12") > 0)
727 self.assert_(res.find(" timeout-pong 14") > 0)
728 self.assert_(res.find(" no timeout-ping advanced") > 0)
729
730 self.vty.verify("no timeout-ping", [''])
731 res = self.vty.command("show running-config")
732 self.assertEquals(res.find(" timeout-ping 12"), -1)
733 self.assertEquals(res.find(" timeout-pong 14"), -1)
734 self.assertEquals(res.find(" no timeout-ping advanced"), -1)
735 self.assert_(res.find(" no timeout-ping") > 0)
736
737 self.vty.verify("timeout-ping advanced", ['%ping handling is disabled. Enable it first.'])
738
739 # And back to enabling it
740 self.vty.verify("timeout-ping 12", [''])
741 self.vty.verify("timeout-pong 14", [''])
742 res = self.vty.command("show running-config")
743 self.assert_(res.find(" timeout-ping 12") > 0)
744 self.assert_(res.find(" timeout-pong 14") > 0)
745 self.assert_(res.find(" timeout-ping advanced") > 0)
746
Holger Hans Peter Freyther05e27702015-04-01 18:15:48 +0200747 def testMscDataCoreLACCI(self):
748 self.vty.enable()
749 res = self.vty.command("show running-config")
750 self.assertEquals(res.find("core-location-area-code"), -1)
751 self.assertEquals(res.find("core-cell-identity"), -1)
752
Neels Hofmeyrb9935632016-09-28 23:28:06 +0200753 self.vty.command("configure terminal")
Holger Hans Peter Freyther05e27702015-04-01 18:15:48 +0200754 self.vty.command("msc 0")
755 self.vty.command("core-location-area-code 666")
756 self.vty.command("core-cell-identity 333")
757
758 res = self.vty.command("show running-config")
759 self.assert_(res.find("core-location-area-code 666") > 0)
760 self.assert_(res.find("core-cell-identity 333") > 0)
761
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200762class TestVTYNAT(TestVTYGenericBSC):
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +0200763
764 def vty_command(self):
Max884b4da2016-04-13 11:36:39 +0200765 return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-l", "127.0.0.1", "-c",
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +0200766 "doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"]
767
768 def vty_app(self):
769 return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat")
770
Max884b4da2016-04-13 11:36:39 +0200771 def testBSCreload(self):
Holger Hans Peter Freyther4ad2e142016-04-14 10:05:13 -0400772 # Use different port for the mock msc to avoid clashing with
773 # the osmo-bsc_nat itself
Holger Hans Peter Freyther09f1afc2016-04-14 08:50:25 -0400774 ip = "127.0.0.1"
Holger Hans Peter Freyther46ba2ea2016-04-14 10:58:58 -0400775 port = 5522
Max884b4da2016-04-13 11:36:39 +0200776 self.vty.enable()
777 bscs1 = self.vty.command("show bscs-config")
778 nat_bsc_reload(self)
779 bscs2 = self.vty.command("show bscs-config")
780 # check that multiple calls to bscs-config-file give the same result
781 self.assertEquals(bscs1, bscs2)
782
783 # add new bsc
784 self.vty.command("configure terminal")
785 self.vty.command("nat")
786 self.vty.command("bsc 5")
787 self.vty.command("token key")
788 self.vty.command("location_area_code 666")
789 self.vty.command("end")
790
791 # update bsc token
792 self.vty.command("configure terminal")
793 self.vty.command("nat")
794 self.vty.command("bsc 1")
795 self.vty.command("token xyu")
796 self.vty.command("end")
797
Holger Hans Peter Freyther4ad2e142016-04-14 10:05:13 -0400798 nat_msc_ip(self, ip, port)
Neels Hofmeyr339f1792017-02-28 02:37:39 +0100799 msc_socket, msc = nat_msc_test(self, ip, port, verbose=True)
800 try:
801 b0 = nat_bsc_sock_test(0, "lol", verbose=True, proc=self.proc)
802 b1 = nat_bsc_sock_test(1, "xyu", verbose=True, proc=self.proc)
803 b2 = nat_bsc_sock_test(5, "key", verbose=True, proc=self.proc)
Max884b4da2016-04-13 11:36:39 +0200804
Neels Hofmeyr339f1792017-02-28 02:37:39 +0100805 self.assertEquals("3 BSCs configured", self.vty.command("show nat num-bscs-configured"))
806 self.assertTrue(3 == nat_bsc_num_con(self))
807 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
Max884b4da2016-04-13 11:36:39 +0200808
Neels Hofmeyr339f1792017-02-28 02:37:39 +0100809 nat_bsc_reload(self)
810 bscs2 = self.vty.command("show bscs-config")
811 # check that the reset to initial config succeeded
812 self.assertEquals(bscs1, bscs2)
Max884b4da2016-04-13 11:36:39 +0200813
Neels Hofmeyr339f1792017-02-28 02:37:39 +0100814 self.assertEquals("2 BSCs configured", self.vty.command("show nat num-bscs-configured"))
815 self.assertTrue(1 == nat_bsc_num_con(self))
816 rem = self.vty.command("show bsc connections").split(' ')
817 # remaining connection is for BSC0
818 self.assertEquals('0', rem[2])
819 # remaining connection is authorized
820 self.assertEquals('1', rem[4])
821 self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection"))
822 finally:
823 msc.close()
824 msc_socket.close()
Max884b4da2016-04-13 11:36:39 +0200825
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200826 def testVtyTree(self):
827 self.vty.enable()
828 self.assertTrue(self.vty.verify('configure terminal', ['']))
829 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbecka4235912013-10-29 09:30:31 +0100830 self.checkForEndAndExit()
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200831 self.assertTrue(self.vty.verify('mgcp', ['']))
832 self.assertEquals(self.vty.node(), 'config-mgcp')
833 self.checkForEndAndExit()
834 self.assertTrue(self.vty.verify('exit', ['']))
835 self.assertEquals(self.vty.node(), 'config')
836 self.assertTrue(self.vty.verify('nat', ['']))
837 self.assertEquals(self.vty.node(), 'config-nat')
838 self.checkForEndAndExit()
839 self.assertTrue(self.vty.verify('bsc 0', ['']))
840 self.assertEquals(self.vty.node(), 'config-nat-bsc')
841 self.checkForEndAndExit()
842 self.assertTrue(self.vty.verify('exit', ['']))
843 self.assertEquals(self.vty.node(), 'config-nat')
844 self.assertTrue(self.vty.verify('exit', ['']))
845 self.assertEquals(self.vty.node(), 'config')
846 self.assertTrue(self.vty.verify('exit', ['']))
847 self.assertTrue(self.vty.node() is None)
848
849 # Check searching for outer node's commands
850 self.vty.command('configure terminal')
851 self.vty.command('mgcp')
852 self.vty.command('nat')
853 self.assertEquals(self.vty.node(), 'config-nat')
Jacob Erlbeckcdf18572013-09-02 13:17:17 +0200854 self.vty.command('mgcp')
855 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200856 self.vty.command('nat')
857 self.assertEquals(self.vty.node(), 'config-nat')
858 self.vty.command('bsc 0')
Jacob Erlbeckcdf18572013-09-02 13:17:17 +0200859 self.vty.command('mgcp')
860 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200861
Holger Hans Peter Freytherbf123a12013-06-25 09:08:02 +0200862 def testRewriteNoRewrite(self):
863 self.vty.enable()
864 res = self.vty.command("configure terminal")
865 res = self.vty.command("nat")
866 res = self.vty.command("number-rewrite rewrite.cfg")
867 res = self.vty.command("no number-rewrite")
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +0200868
Holger Hans Peter Freytherf85852b2015-04-23 20:25:17 -0400869 def testEnsureNoEnsureModeSet(self):
870 self.vty.enable()
871 res = self.vty.command("configure terminal")
872 res = self.vty.command("nat")
873
874 # Ensure the default
875 res = self.vty.command("show running-config")
876 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
877
878 self.vty.command("sdp-ensure-amr-mode-set")
879 res = self.vty.command("show running-config")
880 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
881
882 self.vty.command("no sdp-ensure-amr-mode-set")
883 res = self.vty.command("show running-config")
884 self.assert_(res.find('\n no sdp-ensure-amr-mode-set') > 0)
885
Holger Hans Peter Freythere9c7e272013-06-25 15:38:31 +0200886 def testRewritePostNoRewrite(self):
887 self.vty.enable()
888 self.vty.command("configure terminal")
889 self.vty.command("nat")
890 self.vty.verify("number-rewrite-post rewrite.cfg", [''])
891 self.vty.verify("no number-rewrite-post", [''])
892
893
Holger Hans Peter Freyther367390b2013-06-25 11:44:01 +0200894 def testPrefixTreeLoading(self):
895 cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv")
896
897 self.vty.enable()
898 self.vty.command("configure terminal")
899 self.vty.command("nat")
900 res = self.vty.command("prefix-tree %s" % cfg)
901 self.assertEqual(res, "% prefix-tree loaded 17 rules.")
902 self.vty.command("end")
903
904 res = self.vty.command("show prefix-tree")
905 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')
906
907 self.vty.command("configure terminal")
908 self.vty.command("nat")
909 self.vty.command("no prefix-tree")
910 self.vty.command("end")
911
912 res = self.vty.command("show prefix-tree")
913 self.assertEqual(res, "% there is now prefix tree loaded.")
914
Jacob Erlbeck4684eb62013-08-14 11:10:34 +0200915 def testUssdSideChannelProvider(self):
916 self.vty.command("end")
917 self.vty.enable()
918 self.vty.command("configure terminal")
919 self.vty.command("nat")
920 self.vty.command("ussd-token key")
921 self.vty.command("end")
922
923 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
924 self.assertTrue(res)
925
926 ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
927 ussdSocket.connect(('127.0.0.1', 5001))
928 ussdSocket.settimeout(2.0)
929 print "Connected to %s:%d" % ussdSocket.getpeername()
930
931 print "Expecting ID_GET request"
932 data = ussdSocket.recv(4)
933 self.assertEqual(data, "\x00\x01\xfe\x04")
934
935 print "Going to send ID_RESP response"
Max5fd98942016-11-16 14:55:21 +0100936 res = ussdSocket.send(IPA().id_resp(IPA().tag_name('key')))
Jacob Erlbeck4684eb62013-08-14 11:10:34 +0200937 self.assertEqual(res, 10)
938
939 # initiating PING/PONG cycle to know, that the ID_RESP message has been processed
940
941 print "Going to send PING request"
Max5fd98942016-11-16 14:55:21 +0100942 res = ussdSocket.send(IPA().ping())
Jacob Erlbeck4684eb62013-08-14 11:10:34 +0200943 self.assertEqual(res, 4)
944
945 print "Expecting PONG response"
946 data = ussdSocket.recv(4)
947 self.assertEqual(data, "\x00\x01\xfe\x01")
948
949 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.'])
950 self.assertTrue(res)
951
952 print "Going to shut down connection"
953 ussdSocket.shutdown(socket.SHUT_WR)
954
955 print "Expecting EOF"
956 data = ussdSocket.recv(4)
957 self.assertEqual(data, "")
958
959 ussdSocket.close()
960
961 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
962 self.assertTrue(res)
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +0200963
Holger Hans Peter Freytherd8afce92014-01-20 10:14:05 +0100964 def testAccessList(self):
965 """
966 Verify that the imsi-deny can have a reject cause or no reject cause
967 """
968 self.vty.enable()
969 self.vty.command("configure terminal")
970 self.vty.command("nat")
971
972 # Old default
973 self.vty.command("access-list test-default imsi-deny ^123[0-9]*$")
974 res = self.vty.command("show running-config").split("\r\n")
975 asserted = False
976 for line in res:
Holger Hans Peter Freyther842137a2014-03-04 15:38:00 +0100977 if line.startswith(" access-list test-default"):
Holger Hans Peter Freytherd8afce92014-01-20 10:14:05 +0100978 self.assertEqual(line, " access-list test-default imsi-deny ^123[0-9]*$ 11 11")
979 asserted = True
980 self.assert_(asserted)
981
982 # Check the optional CM Service Reject Cause
983 self.vty.command("access-list test-cm-deny imsi-deny ^123[0-9]*$ 42").split("\r\n")
984 res = self.vty.command("show running-config").split("\r\n")
985 asserted = False
986 for line in res:
987 if line.startswith(" access-list test-cm"):
988 self.assertEqual(line, " access-list test-cm-deny imsi-deny ^123[0-9]*$ 42 11")
989 asserted = True
990 self.assert_(asserted)
991
992 # Check the optional LU Reject Cause
993 self.vty.command("access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42").split("\r\n")
994 res = self.vty.command("show running-config").split("\r\n")
995 asserted = False
996 for line in res:
997 if line.startswith(" access-list test-lu"):
998 self.assertEqual(line, " access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42")
999 asserted = True
1000 self.assert_(asserted)
1001
Jacob Erlbeck7553d1c2013-10-23 11:24:15 +02001002class TestVTYGbproxy(TestVTYGenericBSC):
1003
1004 def vty_command(self):
1005 return ["./src/gprs/osmo-gbproxy", "-c",
1006 "doc/examples/osmo-gbproxy/osmo-gbproxy.cfg"]
1007
1008 def vty_app(self):
1009 return (4246, "./src/gprs/osmo-gbproxy", "OsmoGbProxy", "bsc")
1010
1011 def testVtyTree(self):
1012 self.vty.enable()
1013 self.assertTrue(self.vty.verify('configure terminal', ['']))
1014 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbecka4235912013-10-29 09:30:31 +01001015 self.checkForEndAndExit()
Jacob Erlbeck7553d1c2013-10-23 11:24:15 +02001016 self.assertTrue(self.vty.verify('ns', ['']))
1017 self.assertEquals(self.vty.node(), 'config-ns')
1018 self.checkForEndAndExit()
1019 self.assertTrue(self.vty.verify('exit', ['']))
1020 self.assertEquals(self.vty.node(), 'config')
1021 self.assertTrue(self.vty.verify('gbproxy', ['']))
1022 self.assertEquals(self.vty.node(), 'config-gbproxy')
1023 self.checkForEndAndExit()
1024 self.assertTrue(self.vty.verify('exit', ['']))
1025 self.assertEquals(self.vty.node(), 'config')
1026
1027 def testVtyShow(self):
1028 res = self.vty.command("show ns")
1029 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
1030
1031 res = self.vty.command("show gbproxy stats")
1032 self.assert_(res.find('GBProxy Global Statistics') >= 0)
1033
Jacob Erlbeck7fee9722013-10-24 12:48:23 +02001034 def testVtyDeletePeer(self):
1035 self.vty.enable()
1036 self.assertTrue(self.vty.verify('delete-gbproxy-peer 9999 bvci 7777', ['BVC not found']))
1037 res = self.vty.command("delete-gbproxy-peer 9999 all dry-run")
1038 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
1039 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
1040 res = self.vty.command("delete-gbproxy-peer 9999 only-bvc dry-run")
1041 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
1042 self.assert_(res.find('Not Deleted 0 NS-VC') < 0)
1043 res = self.vty.command("delete-gbproxy-peer 9999 only-nsvc dry-run")
1044 self.assert_(res.find('Not Deleted 0 BVC') < 0)
1045 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
1046 res = self.vty.command("delete-gbproxy-peer 9999 all")
1047 self.assert_(res.find('Deleted 0 BVC') >= 0)
1048 self.assert_(res.find('Deleted 0 NS-VC') >= 0)
1049
Jacob Erlbeckca1c7aa2014-11-04 11:15:01 +01001050class TestVTYSGSN(TestVTYGenericBSC):
1051
1052 def vty_command(self):
1053 return ["./src/gprs/osmo-sgsn", "-c",
1054 "doc/examples/osmo-sgsn/osmo-sgsn.cfg"]
1055
1056 def vty_app(self):
1057 return (4245, "./src/gprs/osmo-sgsn", "OsmoSGSN", "sgsn")
1058
1059 def testVtyTree(self):
1060 self.vty.enable()
1061 self.assertTrue(self.vty.verify('configure terminal', ['']))
1062 self.assertEquals(self.vty.node(), 'config')
1063 self.checkForEndAndExit()
1064 self.assertTrue(self.vty.verify('ns', ['']))
1065 self.assertEquals(self.vty.node(), 'config-ns')
1066 self.checkForEndAndExit()
1067 self.assertTrue(self.vty.verify('exit', ['']))
1068 self.assertEquals(self.vty.node(), 'config')
1069 self.assertTrue(self.vty.verify('sgsn', ['']))
1070 self.assertEquals(self.vty.node(), 'config-sgsn')
1071 self.checkForEndAndExit()
1072 self.assertTrue(self.vty.verify('exit', ['']))
1073 self.assertEquals(self.vty.node(), 'config')
1074
1075 def testVtyShow(self):
1076 res = self.vty.command("show ns")
1077 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
1078 self.assertTrue(self.vty.verify('show bssgp', ['']))
1079 self.assertTrue(self.vty.verify('show bssgp stats', ['']))
1080 # TODO: uncomment when the command does not segfault anymore
1081 # self.assertTrue(self.vty.verify('show bssgp nsei 123', ['']))
1082 # self.assertTrue(self.vty.verify('show bssgp nsei 123 stats', ['']))
1083
1084 self.assertTrue(self.vty.verify('show sgsn', ['']))
1085 self.assertTrue(self.vty.verify('show mm-context all', ['']))
1086 self.assertTrue(self.vty.verify('show mm-context imsi 000001234567', ['No MM context for IMSI 000001234567']))
1087 self.assertTrue(self.vty.verify('show pdp-context all', ['']))
1088
1089 res = self.vty.command("show sndcp")
1090 self.assert_(res.find('State of SNDCP Entities') >= 0)
1091
1092 res = self.vty.command("show llc")
1093 self.assert_(res.find('State of LLC Entities') >= 0)
1094
Jacob Erlbeckd7b77732014-11-04 10:08:37 +01001095 def testVtyAuth(self):
1096 self.vty.enable()
1097 self.assertTrue(self.vty.verify('configure terminal', ['']))
1098 self.assertEquals(self.vty.node(), 'config')
1099 self.assertTrue(self.vty.verify('sgsn', ['']))
1100 self.assertEquals(self.vty.node(), 'config-sgsn')
1101 self.assertTrue(self.vty.verify('auth-policy accept-all', ['']))
1102 res = self.vty.command("show running-config")
1103 self.assert_(res.find('auth-policy accept-all') > 0)
1104 self.assertTrue(self.vty.verify('auth-policy acl-only', ['']))
1105 res = self.vty.command("show running-config")
1106 self.assert_(res.find('auth-policy acl-only') > 0)
1107 self.assertTrue(self.vty.verify('auth-policy closed', ['']))
1108 res = self.vty.command("show running-config")
1109 self.assert_(res.find('auth-policy closed') > 0)
Max6f9a6ca2016-07-04 11:09:07 +02001110 self.assertTrue(self.vty.verify('gsup remote-ip 127.0.0.4', ['']))
1111 self.assertTrue(self.vty.verify('gsup remote-port 2222', ['']))
Jacob Erlbeckd04f7cc2014-11-12 10:18:09 +01001112 self.assertTrue(self.vty.verify('auth-policy remote', ['']))
1113 res = self.vty.command("show running-config")
1114 self.assert_(res.find('auth-policy remote') > 0)
Jacob Erlbeckd7b77732014-11-04 10:08:37 +01001115
Jacob Erlbeckc16c3502014-11-11 14:01:48 +01001116 def testVtySubscriber(self):
1117 self.vty.enable()
1118 res = self.vty.command('show subscriber cache')
1119 self.assert_(res.find('1234567890') < 0)
Jacob Erlbeck90e3ead2015-01-19 14:11:46 +01001120 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 create', ['']))
1121 res = self.vty.command('show subscriber cache')
1122 self.assert_(res.find('1234567890') >= 0)
1123 self.assert_(res.find('Authorized: 0') >= 0)
1124 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 update-location-result ok', ['']))
Jacob Erlbeckc16c3502014-11-11 14:01:48 +01001125 res = self.vty.command('show subscriber cache')
1126 self.assert_(res.find('1234567890') >= 0)
1127 self.assert_(res.find('Authorized: 1') >= 0)
Jacob Erlbeck3b0d0c02015-01-27 14:56:40 +01001128 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 cancel update-procedure', ['']))
Jacob Erlbeckc16c3502014-11-11 14:01:48 +01001129 res = self.vty.command('show subscriber cache')
Jacob Erlbeckeafb8492015-01-27 12:41:19 +01001130 self.assert_(res.find('1234567890') >= 0)
1131 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 destroy', ['']))
1132 res = self.vty.command('show subscriber cache')
Jacob Erlbeckc16c3502014-11-11 14:01:48 +01001133 self.assert_(res.find('1234567890') < 0)
1134
Jacob Erlbeck9b3ca642015-02-03 13:47:53 +01001135 def testVtyGgsn(self):
1136 self.vty.enable()
1137 self.assertTrue(self.vty.verify('configure terminal', ['']))
1138 self.assertEquals(self.vty.node(), 'config')
1139 self.assertTrue(self.vty.verify('sgsn', ['']))
1140 self.assertEquals(self.vty.node(), 'config-sgsn')
1141 self.assertTrue(self.vty.verify('ggsn 0 remote-ip 127.99.99.99', ['']))
1142 self.assertTrue(self.vty.verify('ggsn 0 gtp-version 1', ['']))
1143 self.assertTrue(self.vty.verify('apn * ggsn 0', ['']))
1144 self.assertTrue(self.vty.verify('apn apn1.test ggsn 0', ['']))
1145 self.assertTrue(self.vty.verify('apn apn1.test ggsn 1', ['% a GGSN with id 1 has not been defined']))
1146 self.assertTrue(self.vty.verify('apn apn1.test imsi-prefix 123456 ggsn 0', ['']))
1147 self.assertTrue(self.vty.verify('apn apn2.test imsi-prefix 123456 ggsn 0', ['']))
1148 res = self.vty.command("show running-config")
1149 self.assert_(res.find('ggsn 0 remote-ip 127.99.99.99') >= 0)
1150 self.assert_(res.find('ggsn 0 gtp-version 1') >= 0)
1151 self.assert_(res.find('apn * ggsn 0') >= 0)
1152 self.assert_(res.find('apn apn1.test ggsn 0') >= 0)
1153 self.assert_(res.find('apn apn1.test imsi-prefix 123456 ggsn 0') >= 0)
1154 self.assert_(res.find('apn apn2.test imsi-prefix 123456 ggsn 0') >= 0)
1155
Holger Hans Peter Freyther37391482015-02-06 16:23:29 +01001156 def testVtyEasyAPN(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.assertEquals(res.find("apn internet"), -1)
1165
1166 self.assertTrue(self.vty.verify("access-point-name internet.apn", ['']))
1167 res = self.vty.command("show running-config")
1168 self.assert_(res.find("apn internet.apn ggsn 0") >= 0)
1169
1170 self.assertTrue(self.vty.verify("no access-point-name internet.apn", ['']))
1171 res = self.vty.command("show running-config")
1172 self.assertEquals(res.find("apn internet"), -1)
1173
Holger Hans Peter Freyther81283872015-05-06 17:46:08 +02001174 def testVtyCDR(self):
1175 self.vty.enable()
1176 self.assertTrue(self.vty.verify('configure terminal', ['']))
1177 self.assertEquals(self.vty.node(), 'config')
1178 self.assertTrue(self.vty.verify('sgsn', ['']))
1179 self.assertEquals(self.vty.node(), 'config-sgsn')
1180
1181 res = self.vty.command("show running-config")
1182 self.assert_(res.find("no cdr filename") > 0)
1183
1184 self.vty.command("cdr filename bla.cdr")
1185 res = self.vty.command("show running-config")
1186 self.assertEquals(res.find("no cdr filename"), -1)
1187 self.assert_(res.find(" cdr filename bla.cdr") > 0)
1188
1189 self.vty.command("no cdr filename")
1190 res = self.vty.command("show running-config")
1191 self.assert_(res.find("no cdr filename") > 0)
1192 self.assertEquals(res.find(" cdr filename bla.cdr"), -1)
1193
1194 res = self.vty.command("show running-config")
1195 self.assert_(res.find(" cdr interval 600") > 0)
1196
1197 self.vty.command("cdr interval 900")
1198 res = self.vty.command("show running-config")
1199 self.assert_(res.find(" cdr interval 900") > 0)
1200 self.assertEquals(res.find(" cdr interval 600"), -1)
1201
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +02001202def add_nat_test(suite, workdir):
1203 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
1204 print("Skipping the NAT test")
1205 return
1206 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT)
1207 suite.addTest(test)
1208
Max884b4da2016-04-13 11:36:39 +02001209def nat_bsc_reload(x):
1210 x.vty.command("configure terminal")
1211 x.vty.command("nat")
1212 x.vty.command("bscs-config-file bscs.config")
1213 x.vty.command("end")
1214
Holger Hans Peter Freyther4ad2e142016-04-14 10:05:13 -04001215def nat_msc_ip(x, ip, port):
Max884b4da2016-04-13 11:36:39 +02001216 x.vty.command("configure terminal")
1217 x.vty.command("nat")
1218 x.vty.command("msc ip " + ip)
Holger Hans Peter Freyther6d795892016-04-14 10:40:06 -04001219 x.vty.command("msc port " + str(port))
Max884b4da2016-04-13 11:36:39 +02001220 x.vty.command("end")
1221
1222def data2str(d):
Holger Hans Peter Freyther7db1ff62016-04-14 21:40:04 -04001223 return d.encode('hex').lower()
Max884b4da2016-04-13 11:36:39 +02001224
Holger Hans Peter Freyther4ad2e142016-04-14 10:05:13 -04001225def nat_msc_test(x, ip, port, verbose = False):
Max884b4da2016-04-13 11:36:39 +02001226 msc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Neels Hofmeyr82569eb2017-02-28 02:38:43 +01001227 msc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
Neels Hofmeyr7c3822d2016-09-28 23:38:45 +02001228 msc.settimeout(5)
Holger Hans Peter Freyther4ad2e142016-04-14 10:05:13 -04001229 msc.bind((ip, port))
Max884b4da2016-04-13 11:36:39 +02001230 msc.listen(5)
1231 if (verbose):
1232 print "MSC is ready at " + ip
Neels Hofmeyrd15dae72016-09-26 12:59:36 +02001233 conn = None
Neels Hofmeyr7c3822d2016-09-28 23:38:45 +02001234 while True:
1235 vty_response = x.vty.command("show msc connection")
1236 print "'show msc connection' says: %r" % vty_response
1237 if vty_response == "MSC is connected: 1":
1238 # success
1239 break;
1240 if vty_response != "MSC is connected: 0":
1241 raise Exception("Unexpected response to 'show msc connection'"
1242 " vty command: %r" % vty_response)
1243
1244 timeout_retries = 6
1245 while timeout_retries > 0:
1246 try:
1247 conn, addr = msc.accept()
1248 print "MSC got connection from ", addr
1249 break
1250 except socket.timeout:
1251 print "socket timed out."
1252 timeout_retries -= 1
1253 continue
1254
Neels Hofmeyrd15dae72016-09-26 12:59:36 +02001255 if not conn:
Neels Hofmeyrb9935632016-09-28 23:28:06 +02001256 raise Exception("VTY reports MSC is connected, but I haven't"
1257 " connected yet: %r %r" % (ip, port))
Neels Hofmeyr339f1792017-02-28 02:37:39 +01001258 return msc, conn
Max884b4da2016-04-13 11:36:39 +02001259
1260def ipa_handle_small(x, verbose = False):
1261 s = data2str(x.recv(4))
Neels Hofmeyra6e02f52017-02-03 04:23:46 +01001262 if len(s) != 4*2:
1263 raise Exception("expected to receive 4 bytes, but got %d (%r)" % (len(s)/2, s))
Max884b4da2016-04-13 11:36:39 +02001264 if "0001fe00" == s:
1265 if (verbose):
1266 print "\tBSC <- NAT: PING?"
Max5fd98942016-11-16 14:55:21 +01001267 x.send(IPA().pong())
Max884b4da2016-04-13 11:36:39 +02001268 elif "0001fe06" == s:
1269 if (verbose):
1270 print "\tBSC <- NAT: IPA ID ACK"
Max5fd98942016-11-16 14:55:21 +01001271 x.send(IPA().id_ack())
Max884b4da2016-04-13 11:36:39 +02001272 elif "0001fe00" == s:
1273 if (verbose):
1274 print "\tBSC <- NAT: PONG!"
1275 else:
1276 if (verbose):
1277 print "\tBSC <- NAT: ", s
1278
Neels Hofmeyrd81df4f2017-02-03 16:09:17 +01001279def ipa_handle_resp(x, tk, verbose = False, proc=None):
Max884b4da2016-04-13 11:36:39 +02001280 s = data2str(x.recv(38))
1281 if "0023fe040108010701020103010401050101010011" in s:
Neels Hofmeyra3822a32017-01-26 23:04:28 +01001282 retries = 3
1283 while True:
1284 print "\tsending IPA identity(%s) at %s" % (tk, time.strftime("%T"))
1285 try:
1286 x.send(IPA().id_resp(IPA().identity(name = tk.encode('utf-8'))))
1287 print "\tdone sending IPA identity(%s) at %s" % (tk,
1288 time.strftime("%T"))
1289 break
1290 except:
1291 print "\tfailed sending IPA identity at", time.strftime("%T")
Neels Hofmeyrd81df4f2017-02-03 16:09:17 +01001292 if proc:
1293 print "\tproc.poll() = %r" % proc.poll()
Neels Hofmeyra3822a32017-01-26 23:04:28 +01001294 if retries < 1:
1295 print "\tgiving up"
1296 raise
Neels Hofmeyr5e141032017-02-03 05:55:26 +01001297 print "\tretrying (%d attempts left)" % retries
Neels Hofmeyra3822a32017-01-26 23:04:28 +01001298 retries -= 1
Max884b4da2016-04-13 11:36:39 +02001299 else:
1300 if (verbose):
1301 print "\tBSC <- NAT: ", s
1302
1303def nat_bsc_num_con(x):
1304 return len(x.vty.command("show bsc connections").split('\n'))
1305
Neels Hofmeyrd81df4f2017-02-03 16:09:17 +01001306def nat_bsc_sock_test(nr, tk, verbose = False, proc=None):
Max884b4da2016-04-13 11:36:39 +02001307 bsc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Holger Hans Peter Freyther50445972016-04-14 21:13:51 -04001308 bsc.bind(('127.0.0.1', 0))
Max884b4da2016-04-13 11:36:39 +02001309 bsc.connect(('127.0.0.1', 5000))
1310 if (verbose):
1311 print "BSC%d " %nr
1312 print "\tconnected to %s:%d" % bsc.getpeername()
Neels Hofmeyrd81df4f2017-02-03 16:09:17 +01001313 if proc:
1314 print "\tproc.poll() = %r" % proc.poll()
1315 print "\tproc.pid = %r" % proc.pid
Max884b4da2016-04-13 11:36:39 +02001316 ipa_handle_small(bsc, verbose)
Neels Hofmeyrd81df4f2017-02-03 16:09:17 +01001317 ipa_handle_resp(bsc, tk, verbose, proc=proc)
1318 if proc:
1319 print "\tproc.poll() = %r" % proc.poll()
Max884b4da2016-04-13 11:36:39 +02001320 bsc.recv(27) # MGCP msg
Neels Hofmeyrd81df4f2017-02-03 16:09:17 +01001321 if proc:
1322 print "\tproc.poll() = %r" % proc.poll()
Max884b4da2016-04-13 11:36:39 +02001323 ipa_handle_small(bsc, verbose)
1324 return bsc
1325
Jacob Erlbeck058b1e52013-08-28 10:16:54 +02001326def add_bsc_test(suite, workdir):
1327 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")):
1328 print("Skipping the BSC test")
1329 return
1330 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC)
1331 suite.addTest(test)
1332
Jacob Erlbeck7553d1c2013-10-23 11:24:15 +02001333def add_gbproxy_test(suite, workdir):
1334 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-gbproxy")):
1335 print("Skipping the Gb-Proxy test")
1336 return
1337 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYGbproxy)
1338 suite.addTest(test)
1339
Jacob Erlbeckca1c7aa2014-11-04 11:15:01 +01001340def add_sgsn_test(suite, workdir):
1341 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-sgsn")):
1342 print("Skipping the SGSN test")
1343 return
1344 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYSGSN)
1345 suite.addTest(test)
1346
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +02001347if __name__ == '__main__':
1348 import argparse
1349 import sys
1350
1351 workdir = '.'
1352
1353 parser = argparse.ArgumentParser()
1354 parser.add_argument("-v", "--verbose", dest="verbose",
1355 action="store_true", help="verbose mode")
1356 parser.add_argument("-p", "--pythonconfpath", dest="p",
1357 help="searchpath for config")
1358 parser.add_argument("-w", "--workdir", dest="w",
1359 help="Working directory")
Neels Hofmeyrb21619e2017-02-28 02:43:29 +01001360 parser.add_argument("test_name", nargs="*", help="(parts of) test names to run, case-insensitive")
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +02001361 args = parser.parse_args()
1362
1363 verbose_level = 1
1364 if args.verbose:
1365 verbose_level = 2
1366
1367 if args.w:
1368 workdir = args.w
1369
1370 if args.p:
1371 confpath = args.p
1372
1373 print "confpath %s, workdir %s" % (confpath, workdir)
1374 os.chdir(workdir)
1375 print "Running tests for specific VTY commands"
1376 suite = unittest.TestSuite()
Holger Hans Peter Freytherb30b3aa2014-07-04 20:23:56 +02001377 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYMGCP))
Holger Hans Peter Freyther2fb8ebf2013-07-27 21:07:57 +02001378 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB))
Jacob Erlbeck058b1e52013-08-28 10:16:54 +02001379 add_bsc_test(suite, workdir)
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +02001380 add_nat_test(suite, workdir)
Jacob Erlbeck7553d1c2013-10-23 11:24:15 +02001381 add_gbproxy_test(suite, workdir)
Jacob Erlbeckca1c7aa2014-11-04 11:15:01 +01001382 add_sgsn_test(suite, workdir)
Neels Hofmeyrb21619e2017-02-28 02:43:29 +01001383
1384 if args.test_name:
1385 osmoutil.pick_tests(suite, *args.test_name)
1386
Neels Hofmeyr58b99ae2016-09-28 23:48:02 +02001387 res = unittest.TextTestRunner(verbosity=verbose_level, stream=sys.stdout).run(suite)
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +02001388 sys.exit(len(res.errors) + len(res.failures))
Neels Hofmeyr558af7a2016-09-26 03:18:32 +02001389
Neels Hofmeyrb9935632016-09-28 23:28:06 +02001390# vim: shiftwidth=4 expandtab nocin ai