blob: 08c94b1b5b04b6e21e500215a2c2d4040bef7c9d [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
18import os
19import time
20import unittest
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +020021import socket
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +020022
23import osmopy.obscvty as obscvty
24import osmopy.osmoutil as osmoutil
25
26confpath = '.'
27
28class TestVTYBase(unittest.TestCase):
29
30 def vty_command(self):
31 raise Exception("Needs to be implemented by a subclass")
32
33 def vty_app(self):
34 raise Exception("Needs to be implemented by a subclass")
35
36 def setUp(self):
37 osmo_vty_cmd = self.vty_command()[:]
38 config_index = osmo_vty_cmd.index('-c')
39 if config_index:
40 cfi = config_index + 1
41 osmo_vty_cmd[cfi] = os.path.join(confpath, osmo_vty_cmd[cfi])
42
43 try:
44 print "Launch: %s from %s" % (' '.join(osmo_vty_cmd), os.getcwd())
45 self.proc = osmoutil.popen_devnull(osmo_vty_cmd)
46 except OSError:
47 print >> sys.stderr, "Current directory: %s" % os.getcwd()
48 print >> sys.stderr, "Consider setting -b"
49 time.sleep(1)
50
51 appstring = self.vty_app()[2]
52 appport = self.vty_app()[0]
53 self.vty = obscvty.VTYInteract(appstring, "127.0.0.1", appport)
54
55 def tearDown(self):
56 self.vty = None
57 osmoutil.end_proc(self.proc)
58
Jacob Erlbeck96903c42013-09-02 13:17:14 +020059
60class TestVTYGenericBSC(TestVTYBase):
61
62 def checkForEndAndExit(self):
63 res = self.vty.command("list")
64 #print ('looking for "exit"\n')
65 self.assert_(res.find(' exit\r') > 0)
66 #print 'found "exit"\nlooking for "end"\n'
67 self.assert_(res.find(' end\r') > 0)
68 #print 'found "end"\n'
69
Jacob Erlbeck96903c42013-09-02 13:17:14 +020070 def _testConfigNetworkTree(self):
71 self.vty.enable()
72 self.assertTrue(self.vty.verify("configure terminal",['']))
73 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +010074 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +020075 self.assertTrue(self.vty.verify("network",['']))
76 self.assertEquals(self.vty.node(), 'config-net')
77 self.checkForEndAndExit()
78 self.assertTrue(self.vty.verify("bts 0",['']))
79 self.assertEquals(self.vty.node(), 'config-net-bts')
80 self.checkForEndAndExit()
81 self.assertTrue(self.vty.verify("trx 0",['']))
82 self.assertEquals(self.vty.node(), 'config-net-bts-trx')
83 self.checkForEndAndExit()
Jacob Erlbeck733bec82013-09-11 10:46:56 +020084 self.vty.command("write terminal")
85 self.assertTrue(self.vty.verify("exit",['']))
86 self.assertEquals(self.vty.node(), 'config-net-bts')
87 self.assertTrue(self.vty.verify("exit",['']))
88 self.assertTrue(self.vty.verify("bts 1",['']))
89 self.assertEquals(self.vty.node(), 'config-net-bts')
90 self.checkForEndAndExit()
91 self.assertTrue(self.vty.verify("trx 1",['']))
92 self.assertEquals(self.vty.node(), 'config-net-bts-trx')
93 self.checkForEndAndExit()
94 self.vty.command("write terminal")
Jacob Erlbeck96903c42013-09-02 13:17:14 +020095 self.assertTrue(self.vty.verify("exit",['']))
96 self.assertEquals(self.vty.node(), 'config-net-bts')
97 self.assertTrue(self.vty.verify("exit",['']))
98 self.assertEquals(self.vty.node(), 'config-net')
99 self.assertTrue(self.vty.verify("exit",['']))
100 self.assertEquals(self.vty.node(), 'config')
101 self.assertTrue(self.vty.verify("exit",['']))
102 self.assertTrue(self.vty.node() is None)
103
104class TestVTYNITB(TestVTYGenericBSC):
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200105
106 def vty_command(self):
107 return ["./src/osmo-nitb/osmo-nitb", "-c",
108 "doc/examples/osmo-nitb/nanobts/openbsc.cfg"]
109
110 def vty_app(self):
111 return (4242, "./src/osmo-nitb/osmo-nitb", "OpenBSC", "nitb")
112
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200113 def testConfigNetworkTree(self):
Jacob Erlbeck75877272013-10-23 11:24:14 +0200114 self._testConfigNetworkTree()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200115
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200116 def checkForSmpp(self):
117 """SMPP is not always enabled, check if it is"""
118 res = self.vty.command("list")
119 return "smpp" in res
120
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200121 def testVtyTree(self):
122 self.vty.enable()
123 self.assertTrue(self.vty.verify("configure terminal", ['']))
124 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100125 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200126 self.assertTrue(self.vty.verify('mncc-int', ['']))
127 self.assertEquals(self.vty.node(), 'config-mncc-int')
128 self.checkForEndAndExit()
129 self.assertTrue(self.vty.verify('exit', ['']))
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200130
131 if self.checkForSmpp():
132 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck75877272013-10-23 11:24:14 +0200133 self.assertTrue(self.vty.verify('smpp', ['']))
134 self.assertEquals(self.vty.node(), 'config-smpp')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100135 self.checkForEndAndExit()
Jacob Erlbeck75877272013-10-23 11:24:14 +0200136 self.assertTrue(self.vty.verify("exit", ['']))
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200137
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200138 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200139 self.assertTrue(self.vty.verify("exit", ['']))
140 self.assertTrue(self.vty.node() is None)
141
142 # Check searching for outer node's commands
143 self.vty.command("configure terminal")
144 self.vty.command('mncc-int')
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200145
146 if self.checkForSmpp():
147 self.vty.command('smpp')
148 self.assertEquals(self.vty.node(), 'config-smpp')
149 self.vty.command('mncc-int')
150
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200151 self.assertEquals(self.vty.node(), 'config-mncc-int')
152
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200153 def testEnableDisablePeriodicLU(self):
154 self.vty.enable()
155 self.vty.command("configure terminal")
156 self.vty.command("network")
157 self.vty.command("bts 0")
158
159 # Test invalid input
160 self.vty.verify("periodic location update 0", ['% Unknown command.'])
161 self.vty.verify("periodic location update 5", ['% Unknown command.'])
162 self.vty.verify("periodic location update 1531", ['% Unknown command.'])
163
164 # Enable periodic lu..
165 self.vty.verify("periodic location update 60", [''])
166 res = self.vty.command("write terminal")
Holger Hans Peter Freytherc0438e32013-07-27 22:23:25 +0200167 self.assert_(res.find('periodic location update 60') > 0)
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200168 self.assertEquals(res.find('no periodic location update'), -1)
169
170 # Now disable it..
171 self.vty.verify("no periodic location update", [''])
172 res = self.vty.command("write terminal")
173 self.assertEquals(res.find('periodic location update 60'), -1)
Holger Hans Peter Freytherc0438e32013-07-27 22:23:25 +0200174 self.assert_(res.find('no periodic location update') > 0)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200175
Ivan Kluchnikov67920592013-09-16 13:13:04 +0400176 def testRachAccessControlClass(self):
177 self.vty.enable()
178 self.vty.command("configure terminal")
179 self.vty.command("network")
180 self.vty.command("bts 0")
181
182 # Test invalid input
183 self.vty.verify("rach access-control-class", ['% Command incomplete.'])
184 self.vty.verify("rach access-control-class 1", ['% Command incomplete.'])
185 self.vty.verify("rach access-control-class -1", ['% Unknown command.'])
186 self.vty.verify("rach access-control-class 10", ['% Unknown command.'])
187 self.vty.verify("rach access-control-class 16", ['% Unknown command.'])
188
189 # Barred rach access control classes
190 for classNum in range(16):
191 if classNum != 10:
192 self.vty.verify("rach access-control-class " + str(classNum) + " barred", [''])
193
194 # Verify settings
195 res = self.vty.command("write terminal")
196 for classNum in range(16):
197 if classNum != 10:
198 self.assert_(res.find("rach access-control-class " + str(classNum) + " barred") > 0)
199
200 # Allowed rach access control classes
201 for classNum in range(16):
202 if classNum != 10:
203 self.vty.verify("rach access-control-class " + str(classNum) + " allowed", [''])
204
205 # Verify settings
206 res = self.vty.command("write terminal")
207 for classNum in range(16):
208 if classNum != 10:
209 self.assertEquals(res.find("rach access-control-class " + str(classNum) + " barred"), -1)
210
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200211 def testSubscriberCreate(self):
212 self.vty.enable()
213
214 imsi = "204300854013739"
215
216 # Initially we don't have this subscriber
217 self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi])
218
219 # Lets create one
220 res = self.vty.command('subscriber create imsi '+imsi)
221 self.assert_(res.find(" IMSI: "+imsi) > 0)
222
223 # Now we have it
224 res = self.vty.command('show subscriber imsi '+imsi)
225 self.assert_(res.find(" IMSI: "+imsi) > 0)
226
Holger Hans Peter Freytherec37bb22013-02-05 09:39:09 +0100227 def testShowPagingGroup(self):
228 res = self.vty.command("show paging-group 255 1234567")
229 self.assertEqual(res, "% can't find BTS 255")
230 res = self.vty.command("show paging-group 0 1234567")
231 self.assertEquals(res, "%Paging group for IMSI 1234567 on BTS #0 is 7")
232
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200233class TestVTYBSC(TestVTYGenericBSC):
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200234
235 def vty_command(self):
236 return ["./src/osmo-bsc/osmo-bsc", "-c",
237 "doc/examples/osmo-bsc/osmo-bsc.cfg"]
238
239 def vty_app(self):
240 return (4242, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc")
241
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200242 def testConfigNetworkTree(self):
Jacob Erlbeck75877272013-10-23 11:24:14 +0200243 self._testConfigNetworkTree()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200244
245 def testVtyTree(self):
246 self.vty.enable()
247 self.assertTrue(self.vty.verify("configure terminal", ['']))
248 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100249 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200250 self.assertTrue(self.vty.verify("msc 0", ['']))
251 self.assertEquals(self.vty.node(), 'config-msc')
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200252 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200253 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200254 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200255 self.assertTrue(self.vty.verify("bsc", ['']))
256 self.assertEquals(self.vty.node(), 'config-bsc')
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200257 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200258 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200259 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200260 self.assertTrue(self.vty.verify("exit", ['']))
261 self.assertTrue(self.vty.node() is None)
262
263 # Check searching for outer node's commands
264 self.vty.command("configure terminal")
265 self.vty.command('msc 0')
266 self.vty.command("bsc")
267 self.assertEquals(self.vty.node(), 'config-bsc')
268 self.vty.command("msc 0")
269 self.assertEquals(self.vty.node(), 'config-msc')
270
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200271 def testUssdNotificationsMsc(self):
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200272 self.vty.enable()
273 self.vty.command("configure terminal")
274 self.vty.command("msc")
275
276 # Test invalid input
277 self.vty.verify("bsc-msc-lost-text", ['% Command incomplete.'])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200278 self.vty.verify("bsc-welcome-text", ['% Command incomplete.'])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200279 self.vty.verify("bsc-grace-text", ['% Command incomplete.'])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200280
281 # Enable USSD notifications
282 self.vty.verify("bsc-msc-lost-text MSC disconnected", [''])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200283 self.vty.verify("bsc-welcome-text Hello MS", [''])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200284 self.vty.verify("bsc-grace-text In grace period", [''])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200285
286 # Verify settings
287 res = self.vty.command("write terminal")
288 self.assert_(res.find('bsc-msc-lost-text MSC disconnected') > 0)
289 self.assertEquals(res.find('no bsc-msc-lost-text'), -1)
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200290 self.assert_(res.find('bsc-welcome-text Hello MS') > 0)
291 self.assertEquals(res.find('no bsc-welcome-text'), -1)
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200292 self.assert_(res.find('bsc-grace-text In grace period') > 0)
293 self.assertEquals(res.find('no bsc-grace-text'), -1)
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200294
295 # Now disable it..
296 self.vty.verify("no bsc-msc-lost-text", [''])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200297 self.vty.verify("no bsc-welcome-text", [''])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200298 self.vty.verify("no bsc-grace-text", [''])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200299
300 # Verify settings
301 res = self.vty.command("write terminal")
302 self.assertEquals(res.find('bsc-msc-lost-text MSC disconnected'), -1)
303 self.assert_(res.find('no bsc-msc-lost-text') > 0)
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200304 self.assertEquals(res.find('bsc-welcome-text Hello MS'), -1)
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200305 self.assert_(res.find('no bsc-welcome-text') > 0)
306 self.assertEquals(res.find('bsc-grace-text In grace period'), -1)
307 self.assert_(res.find('no bsc-grace-text') > 0)
308
309 def testUssdNotificationsBsc(self):
310 self.vty.enable()
311 self.vty.command("configure terminal")
312 self.vty.command("bsc")
313
314 # Test invalid input
315 self.vty.verify("missing-msc-text", ['% Command incomplete.'])
316
317 # Enable USSD notifications
318 self.vty.verify("missing-msc-text No MSC found", [''])
319
320 # Verify settings
321 res = self.vty.command("write terminal")
322 self.assert_(res.find('missing-msc-text No MSC found') > 0)
323 self.assertEquals(res.find('no missing-msc-text'), -1)
324
325 # Now disable it..
326 self.vty.verify("no missing-msc-text", [''])
327
328 # Verify settings
329 res = self.vty.command("write terminal")
330 self.assertEquals(res.find('missing-msc-text No MSC found'), -1)
331 self.assert_(res.find('no missing-msc-text') > 0)
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200332
Jacob Erlbeck946d1412013-09-17 13:59:29 +0200333 def testNetworkTimezone(self):
334 self.vty.enable()
335 self.vty.verify("configure terminal", [''])
336 self.vty.verify("network", [''])
337 self.vty.verify("bts 0", [''])
338
339 # Test invalid input
340 self.vty.verify("timezone", ['% Command incomplete.'])
341 self.vty.verify("timezone 20 0", ['% Unknown command.'])
342 self.vty.verify("timezone 0 11", ['% Unknown command.'])
343 self.vty.verify("timezone 0 0 99", ['% Unknown command.'])
344
345 # Set time zone without DST
346 self.vty.verify("timezone 2 30", [''])
347
348 # Verify settings
349 res = self.vty.command("write terminal")
350 self.assert_(res.find('timezone 2 30') > 0)
351 self.assertEquals(res.find('timezone 2 30 '), -1)
352
353 # Set time zone with DST
354 self.vty.verify("timezone 2 30 1", [''])
355
356 # Verify settings
357 res = self.vty.command("write terminal")
358 self.assert_(res.find('timezone 2 30 1') > 0)
359
360 # Now disable it..
361 self.vty.verify("no timezone", [''])
362
363 # Verify settings
364 res = self.vty.command("write terminal")
365 self.assertEquals(res.find(' timezone'), -1)
366
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200367class TestVTYNAT(TestVTYGenericBSC):
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200368
369 def vty_command(self):
370 return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-c",
371 "doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"]
372
373 def vty_app(self):
374 return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat")
375
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200376 def testVtyTree(self):
377 self.vty.enable()
378 self.assertTrue(self.vty.verify('configure terminal', ['']))
379 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100380 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200381 self.assertTrue(self.vty.verify('mgcp', ['']))
382 self.assertEquals(self.vty.node(), 'config-mgcp')
383 self.checkForEndAndExit()
384 self.assertTrue(self.vty.verify('exit', ['']))
385 self.assertEquals(self.vty.node(), 'config')
386 self.assertTrue(self.vty.verify('nat', ['']))
387 self.assertEquals(self.vty.node(), 'config-nat')
388 self.checkForEndAndExit()
389 self.assertTrue(self.vty.verify('bsc 0', ['']))
390 self.assertEquals(self.vty.node(), 'config-nat-bsc')
391 self.checkForEndAndExit()
392 self.assertTrue(self.vty.verify('exit', ['']))
393 self.assertEquals(self.vty.node(), 'config-nat')
394 self.assertTrue(self.vty.verify('exit', ['']))
395 self.assertEquals(self.vty.node(), 'config')
396 self.assertTrue(self.vty.verify('exit', ['']))
397 self.assertTrue(self.vty.node() is None)
398
399 # Check searching for outer node's commands
400 self.vty.command('configure terminal')
401 self.vty.command('mgcp')
402 self.vty.command('nat')
403 self.assertEquals(self.vty.node(), 'config-nat')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200404 self.vty.command('mgcp')
405 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200406 self.vty.command('nat')
407 self.assertEquals(self.vty.node(), 'config-nat')
408 self.vty.command('bsc 0')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200409 self.vty.command('mgcp')
410 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200411
Holger Hans Peter Freytherb718ad32013-06-25 09:08:02 +0200412 def testRewriteNoRewrite(self):
413 self.vty.enable()
414 res = self.vty.command("configure terminal")
415 res = self.vty.command("nat")
416 res = self.vty.command("number-rewrite rewrite.cfg")
417 res = self.vty.command("no number-rewrite")
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200418
Holger Hans Peter Freyther67e423c2013-06-25 15:38:31 +0200419 def testRewritePostNoRewrite(self):
420 self.vty.enable()
421 self.vty.command("configure terminal")
422 self.vty.command("nat")
423 self.vty.verify("number-rewrite-post rewrite.cfg", [''])
424 self.vty.verify("no number-rewrite-post", [''])
425
426
Holger Hans Peter Freytherddf191e2013-06-25 11:44:01 +0200427 def testPrefixTreeLoading(self):
428 cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv")
429
430 self.vty.enable()
431 self.vty.command("configure terminal")
432 self.vty.command("nat")
433 res = self.vty.command("prefix-tree %s" % cfg)
434 self.assertEqual(res, "% prefix-tree loaded 17 rules.")
435 self.vty.command("end")
436
437 res = self.vty.command("show prefix-tree")
438 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')
439
440 self.vty.command("configure terminal")
441 self.vty.command("nat")
442 self.vty.command("no prefix-tree")
443 self.vty.command("end")
444
445 res = self.vty.command("show prefix-tree")
446 self.assertEqual(res, "% there is now prefix tree loaded.")
447
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200448 def testUssdSideChannelProvider(self):
449 self.vty.command("end")
450 self.vty.enable()
451 self.vty.command("configure terminal")
452 self.vty.command("nat")
453 self.vty.command("ussd-token key")
454 self.vty.command("end")
455
456 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
457 self.assertTrue(res)
458
459 ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
460 ussdSocket.connect(('127.0.0.1', 5001))
461 ussdSocket.settimeout(2.0)
462 print "Connected to %s:%d" % ussdSocket.getpeername()
463
464 print "Expecting ID_GET request"
465 data = ussdSocket.recv(4)
466 self.assertEqual(data, "\x00\x01\xfe\x04")
467
468 print "Going to send ID_RESP response"
469 res = ussdSocket.send("\x00\x07\xfe\x05\x00\x04\x01\x6b\x65\x79")
470 self.assertEqual(res, 10)
471
472 # initiating PING/PONG cycle to know, that the ID_RESP message has been processed
473
474 print "Going to send PING request"
475 res = ussdSocket.send("\x00\x01\xfe\x00")
476 self.assertEqual(res, 4)
477
478 print "Expecting PONG response"
479 data = ussdSocket.recv(4)
480 self.assertEqual(data, "\x00\x01\xfe\x01")
481
482 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.'])
483 self.assertTrue(res)
484
485 print "Going to shut down connection"
486 ussdSocket.shutdown(socket.SHUT_WR)
487
488 print "Expecting EOF"
489 data = ussdSocket.recv(4)
490 self.assertEqual(data, "")
491
492 ussdSocket.close()
493
494 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
495 self.assertTrue(res)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200496
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200497class TestVTYGbproxy(TestVTYGenericBSC):
498
499 def vty_command(self):
500 return ["./src/gprs/osmo-gbproxy", "-c",
501 "doc/examples/osmo-gbproxy/osmo-gbproxy.cfg"]
502
503 def vty_app(self):
504 return (4246, "./src/gprs/osmo-gbproxy", "OsmoGbProxy", "bsc")
505
506 def testVtyTree(self):
507 self.vty.enable()
508 self.assertTrue(self.vty.verify('configure terminal', ['']))
509 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100510 self.checkForEndAndExit()
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200511 self.assertTrue(self.vty.verify('ns', ['']))
512 self.assertEquals(self.vty.node(), 'config-ns')
513 self.checkForEndAndExit()
514 self.assertTrue(self.vty.verify('exit', ['']))
515 self.assertEquals(self.vty.node(), 'config')
516 self.assertTrue(self.vty.verify('gbproxy', ['']))
517 self.assertEquals(self.vty.node(), 'config-gbproxy')
518 self.checkForEndAndExit()
519 self.assertTrue(self.vty.verify('exit', ['']))
520 self.assertEquals(self.vty.node(), 'config')
521
522 def testVtyShow(self):
523 res = self.vty.command("show ns")
524 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
525
526 res = self.vty.command("show gbproxy stats")
527 self.assert_(res.find('GBProxy Global Statistics') >= 0)
528
Jacob Erlbeck4211d792013-10-24 12:48:23 +0200529 def testVtyDeletePeer(self):
530 self.vty.enable()
531 self.assertTrue(self.vty.verify('delete-gbproxy-peer 9999 bvci 7777', ['BVC not found']))
532 res = self.vty.command("delete-gbproxy-peer 9999 all dry-run")
533 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
534 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
535 res = self.vty.command("delete-gbproxy-peer 9999 only-bvc dry-run")
536 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
537 self.assert_(res.find('Not Deleted 0 NS-VC') < 0)
538 res = self.vty.command("delete-gbproxy-peer 9999 only-nsvc dry-run")
539 self.assert_(res.find('Not Deleted 0 BVC') < 0)
540 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
541 res = self.vty.command("delete-gbproxy-peer 9999 all")
542 self.assert_(res.find('Deleted 0 BVC') >= 0)
543 self.assert_(res.find('Deleted 0 NS-VC') >= 0)
544
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200545def add_nat_test(suite, workdir):
546 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
547 print("Skipping the NAT test")
548 return
549 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT)
550 suite.addTest(test)
551
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200552def add_bsc_test(suite, workdir):
553 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")):
554 print("Skipping the BSC test")
555 return
556 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC)
557 suite.addTest(test)
558
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200559def add_gbproxy_test(suite, workdir):
560 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-gbproxy")):
561 print("Skipping the Gb-Proxy test")
562 return
563 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYGbproxy)
564 suite.addTest(test)
565
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200566if __name__ == '__main__':
567 import argparse
568 import sys
569
570 workdir = '.'
571
572 parser = argparse.ArgumentParser()
573 parser.add_argument("-v", "--verbose", dest="verbose",
574 action="store_true", help="verbose mode")
575 parser.add_argument("-p", "--pythonconfpath", dest="p",
576 help="searchpath for config")
577 parser.add_argument("-w", "--workdir", dest="w",
578 help="Working directory")
579 args = parser.parse_args()
580
581 verbose_level = 1
582 if args.verbose:
583 verbose_level = 2
584
585 if args.w:
586 workdir = args.w
587
588 if args.p:
589 confpath = args.p
590
591 print "confpath %s, workdir %s" % (confpath, workdir)
592 os.chdir(workdir)
593 print "Running tests for specific VTY commands"
594 suite = unittest.TestSuite()
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200595 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB))
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200596 add_bsc_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200597 add_nat_test(suite, workdir)
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200598 add_gbproxy_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200599 res = unittest.TextTestRunner(verbosity=verbose_level).run(suite)
600 sys.exit(len(res.errors) + len(res.failures))