blob: e040caccf2f8dc73fe7190fc143bd94cc99fa0a3 [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
70 def ignoredCheckForEndAndExit(self):
71 sys.stderr.write('Going to ignore the next assertion(s) due to known bugs\n')
72 try:
73 self.checkForEndAndExit()
74 except BaseException as e:
Jacob Erlbeck75877272013-10-23 11:24:14 +020075 sys.stderr.write('Expected and ignored failure: %s\n' % (str(e)))
Jacob Erlbeck96903c42013-09-02 13:17:14 +020076
Jacob Erlbeck96903c42013-09-02 13:17:14 +020077 def _testConfigNetworkTree(self):
78 self.vty.enable()
79 self.assertTrue(self.vty.verify("configure terminal",['']))
80 self.assertEquals(self.vty.node(), 'config')
81 self.ignoredCheckForEndAndExit()
82 self.assertTrue(self.vty.verify("network",['']))
83 self.assertEquals(self.vty.node(), 'config-net')
84 self.checkForEndAndExit()
85 self.assertTrue(self.vty.verify("bts 0",['']))
86 self.assertEquals(self.vty.node(), 'config-net-bts')
87 self.checkForEndAndExit()
88 self.assertTrue(self.vty.verify("trx 0",['']))
89 self.assertEquals(self.vty.node(), 'config-net-bts-trx')
90 self.checkForEndAndExit()
Jacob Erlbeck733bec82013-09-11 10:46:56 +020091 self.vty.command("write terminal")
92 self.assertTrue(self.vty.verify("exit",['']))
93 self.assertEquals(self.vty.node(), 'config-net-bts')
94 self.assertTrue(self.vty.verify("exit",['']))
95 self.assertTrue(self.vty.verify("bts 1",['']))
96 self.assertEquals(self.vty.node(), 'config-net-bts')
97 self.checkForEndAndExit()
98 self.assertTrue(self.vty.verify("trx 1",['']))
99 self.assertEquals(self.vty.node(), 'config-net-bts-trx')
100 self.checkForEndAndExit()
101 self.vty.command("write terminal")
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200102 self.assertTrue(self.vty.verify("exit",['']))
103 self.assertEquals(self.vty.node(), 'config-net-bts')
104 self.assertTrue(self.vty.verify("exit",['']))
105 self.assertEquals(self.vty.node(), 'config-net')
106 self.assertTrue(self.vty.verify("exit",['']))
107 self.assertEquals(self.vty.node(), 'config')
108 self.assertTrue(self.vty.verify("exit",['']))
109 self.assertTrue(self.vty.node() is None)
110
111class TestVTYNITB(TestVTYGenericBSC):
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200112
113 def vty_command(self):
114 return ["./src/osmo-nitb/osmo-nitb", "-c",
115 "doc/examples/osmo-nitb/nanobts/openbsc.cfg"]
116
117 def vty_app(self):
118 return (4242, "./src/osmo-nitb/osmo-nitb", "OpenBSC", "nitb")
119
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200120 def testConfigNetworkTree(self):
Jacob Erlbeck75877272013-10-23 11:24:14 +0200121 self._testConfigNetworkTree()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200122
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200123 def checkForSmpp(self):
124 """SMPP is not always enabled, check if it is"""
125 res = self.vty.command("list")
126 return "smpp" in res
127
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200128 def testVtyTree(self):
129 self.vty.enable()
130 self.assertTrue(self.vty.verify("configure terminal", ['']))
131 self.assertEquals(self.vty.node(), 'config')
132 self.ignoredCheckForEndAndExit()
133 self.assertTrue(self.vty.verify('mncc-int', ['']))
134 self.assertEquals(self.vty.node(), 'config-mncc-int')
135 self.checkForEndAndExit()
136 self.assertTrue(self.vty.verify('exit', ['']))
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200137
138 if self.checkForSmpp():
139 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck75877272013-10-23 11:24:14 +0200140 self.assertTrue(self.vty.verify('smpp', ['']))
141 self.assertEquals(self.vty.node(), 'config-smpp')
142 self.ignoredCheckForEndAndExit()
143 self.assertTrue(self.vty.verify("exit", ['']))
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200144
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200145 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200146 self.assertTrue(self.vty.verify("exit", ['']))
147 self.assertTrue(self.vty.node() is None)
148
149 # Check searching for outer node's commands
150 self.vty.command("configure terminal")
151 self.vty.command('mncc-int')
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200152
153 if self.checkForSmpp():
154 self.vty.command('smpp')
155 self.assertEquals(self.vty.node(), 'config-smpp')
156 self.vty.command('mncc-int')
157
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200158 self.assertEquals(self.vty.node(), 'config-mncc-int')
159
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200160 def testEnableDisablePeriodicLU(self):
161 self.vty.enable()
162 self.vty.command("configure terminal")
163 self.vty.command("network")
164 self.vty.command("bts 0")
165
166 # Test invalid input
167 self.vty.verify("periodic location update 0", ['% Unknown command.'])
168 self.vty.verify("periodic location update 5", ['% Unknown command.'])
169 self.vty.verify("periodic location update 1531", ['% Unknown command.'])
170
171 # Enable periodic lu..
172 self.vty.verify("periodic location update 60", [''])
173 res = self.vty.command("write terminal")
Holger Hans Peter Freytherc0438e32013-07-27 22:23:25 +0200174 self.assert_(res.find('periodic location update 60') > 0)
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200175 self.assertEquals(res.find('no periodic location update'), -1)
176
177 # Now disable it..
178 self.vty.verify("no periodic location update", [''])
179 res = self.vty.command("write terminal")
180 self.assertEquals(res.find('periodic location update 60'), -1)
Holger Hans Peter Freytherc0438e32013-07-27 22:23:25 +0200181 self.assert_(res.find('no periodic location update') > 0)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200182
Ivan Kluchnikov67920592013-09-16 13:13:04 +0400183 def testRachAccessControlClass(self):
184 self.vty.enable()
185 self.vty.command("configure terminal")
186 self.vty.command("network")
187 self.vty.command("bts 0")
188
189 # Test invalid input
190 self.vty.verify("rach access-control-class", ['% Command incomplete.'])
191 self.vty.verify("rach access-control-class 1", ['% Command incomplete.'])
192 self.vty.verify("rach access-control-class -1", ['% Unknown command.'])
193 self.vty.verify("rach access-control-class 10", ['% Unknown command.'])
194 self.vty.verify("rach access-control-class 16", ['% Unknown command.'])
195
196 # Barred rach access control classes
197 for classNum in range(16):
198 if classNum != 10:
199 self.vty.verify("rach access-control-class " + str(classNum) + " barred", [''])
200
201 # Verify settings
202 res = self.vty.command("write terminal")
203 for classNum in range(16):
204 if classNum != 10:
205 self.assert_(res.find("rach access-control-class " + str(classNum) + " barred") > 0)
206
207 # Allowed rach access control classes
208 for classNum in range(16):
209 if classNum != 10:
210 self.vty.verify("rach access-control-class " + str(classNum) + " allowed", [''])
211
212 # Verify settings
213 res = self.vty.command("write terminal")
214 for classNum in range(16):
215 if classNum != 10:
216 self.assertEquals(res.find("rach access-control-class " + str(classNum) + " barred"), -1)
217
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200218 def testSubscriberCreate(self):
219 self.vty.enable()
220
221 imsi = "204300854013739"
222
223 # Initially we don't have this subscriber
224 self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi])
225
226 # Lets create one
227 res = self.vty.command('subscriber create imsi '+imsi)
228 self.assert_(res.find(" IMSI: "+imsi) > 0)
229
230 # Now we have it
231 res = self.vty.command('show subscriber imsi '+imsi)
232 self.assert_(res.find(" IMSI: "+imsi) > 0)
233
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200234class TestVTYBSC(TestVTYGenericBSC):
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200235
236 def vty_command(self):
237 return ["./src/osmo-bsc/osmo-bsc", "-c",
238 "doc/examples/osmo-bsc/osmo-bsc.cfg"]
239
240 def vty_app(self):
241 return (4242, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc")
242
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200243 def testConfigNetworkTree(self):
Jacob Erlbeck75877272013-10-23 11:24:14 +0200244 self._testConfigNetworkTree()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200245
246 def testVtyTree(self):
247 self.vty.enable()
248 self.assertTrue(self.vty.verify("configure terminal", ['']))
249 self.assertEquals(self.vty.node(), 'config')
250 self.ignoredCheckForEndAndExit()
251 self.assertTrue(self.vty.verify("msc 0", ['']))
252 self.assertEquals(self.vty.node(), 'config-msc')
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200253 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200254 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200255 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200256 self.assertTrue(self.vty.verify("bsc", ['']))
257 self.assertEquals(self.vty.node(), 'config-bsc')
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200258 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200259 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200260 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200261 self.assertTrue(self.vty.verify("exit", ['']))
262 self.assertTrue(self.vty.node() is None)
263
264 # Check searching for outer node's commands
265 self.vty.command("configure terminal")
266 self.vty.command('msc 0')
267 self.vty.command("bsc")
268 self.assertEquals(self.vty.node(), 'config-bsc')
269 self.vty.command("msc 0")
270 self.assertEquals(self.vty.node(), 'config-msc')
271
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200272 def testUssdNotificationsMsc(self):
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200273 self.vty.enable()
274 self.vty.command("configure terminal")
275 self.vty.command("msc")
276
277 # Test invalid input
278 self.vty.verify("bsc-msc-lost-text", ['% Command incomplete.'])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200279 self.vty.verify("bsc-welcome-text", ['% Command incomplete.'])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200280 self.vty.verify("bsc-grace-text", ['% Command incomplete.'])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200281
282 # Enable USSD notifications
283 self.vty.verify("bsc-msc-lost-text MSC disconnected", [''])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200284 self.vty.verify("bsc-welcome-text Hello MS", [''])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200285 self.vty.verify("bsc-grace-text In grace period", [''])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200286
287 # Verify settings
288 res = self.vty.command("write terminal")
289 self.assert_(res.find('bsc-msc-lost-text MSC disconnected') > 0)
290 self.assertEquals(res.find('no bsc-msc-lost-text'), -1)
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200291 self.assert_(res.find('bsc-welcome-text Hello MS') > 0)
292 self.assertEquals(res.find('no bsc-welcome-text'), -1)
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200293 self.assert_(res.find('bsc-grace-text In grace period') > 0)
294 self.assertEquals(res.find('no bsc-grace-text'), -1)
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200295
296 # Now disable it..
297 self.vty.verify("no bsc-msc-lost-text", [''])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200298 self.vty.verify("no bsc-welcome-text", [''])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200299 self.vty.verify("no bsc-grace-text", [''])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200300
301 # Verify settings
302 res = self.vty.command("write terminal")
303 self.assertEquals(res.find('bsc-msc-lost-text MSC disconnected'), -1)
304 self.assert_(res.find('no bsc-msc-lost-text') > 0)
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200305 self.assertEquals(res.find('bsc-welcome-text Hello MS'), -1)
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200306 self.assert_(res.find('no bsc-welcome-text') > 0)
307 self.assertEquals(res.find('bsc-grace-text In grace period'), -1)
308 self.assert_(res.find('no bsc-grace-text') > 0)
309
310 def testUssdNotificationsBsc(self):
311 self.vty.enable()
312 self.vty.command("configure terminal")
313 self.vty.command("bsc")
314
315 # Test invalid input
316 self.vty.verify("missing-msc-text", ['% Command incomplete.'])
317
318 # Enable USSD notifications
319 self.vty.verify("missing-msc-text No MSC found", [''])
320
321 # Verify settings
322 res = self.vty.command("write terminal")
323 self.assert_(res.find('missing-msc-text No MSC found') > 0)
324 self.assertEquals(res.find('no missing-msc-text'), -1)
325
326 # Now disable it..
327 self.vty.verify("no missing-msc-text", [''])
328
329 # Verify settings
330 res = self.vty.command("write terminal")
331 self.assertEquals(res.find('missing-msc-text No MSC found'), -1)
332 self.assert_(res.find('no missing-msc-text') > 0)
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200333
Jacob Erlbeck946d1412013-09-17 13:59:29 +0200334 def testNetworkTimezone(self):
335 self.vty.enable()
336 self.vty.verify("configure terminal", [''])
337 self.vty.verify("network", [''])
338 self.vty.verify("bts 0", [''])
339
340 # Test invalid input
341 self.vty.verify("timezone", ['% Command incomplete.'])
342 self.vty.verify("timezone 20 0", ['% Unknown command.'])
343 self.vty.verify("timezone 0 11", ['% Unknown command.'])
344 self.vty.verify("timezone 0 0 99", ['% Unknown command.'])
345
346 # Set time zone without DST
347 self.vty.verify("timezone 2 30", [''])
348
349 # Verify settings
350 res = self.vty.command("write terminal")
351 self.assert_(res.find('timezone 2 30') > 0)
352 self.assertEquals(res.find('timezone 2 30 '), -1)
353
354 # Set time zone with DST
355 self.vty.verify("timezone 2 30 1", [''])
356
357 # Verify settings
358 res = self.vty.command("write terminal")
359 self.assert_(res.find('timezone 2 30 1') > 0)
360
361 # Now disable it..
362 self.vty.verify("no timezone", [''])
363
364 # Verify settings
365 res = self.vty.command("write terminal")
366 self.assertEquals(res.find(' timezone'), -1)
367
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200368class TestVTYNAT(TestVTYGenericBSC):
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200369
370 def vty_command(self):
371 return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-c",
372 "doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"]
373
374 def vty_app(self):
375 return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat")
376
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200377 def testVtyTree(self):
378 self.vty.enable()
379 self.assertTrue(self.vty.verify('configure terminal', ['']))
380 self.assertEquals(self.vty.node(), 'config')
381 self.ignoredCheckForEndAndExit()
382 self.assertTrue(self.vty.verify('mgcp', ['']))
383 self.assertEquals(self.vty.node(), 'config-mgcp')
384 self.checkForEndAndExit()
385 self.assertTrue(self.vty.verify('exit', ['']))
386 self.assertEquals(self.vty.node(), 'config')
387 self.assertTrue(self.vty.verify('nat', ['']))
388 self.assertEquals(self.vty.node(), 'config-nat')
389 self.checkForEndAndExit()
390 self.assertTrue(self.vty.verify('bsc 0', ['']))
391 self.assertEquals(self.vty.node(), 'config-nat-bsc')
392 self.checkForEndAndExit()
393 self.assertTrue(self.vty.verify('exit', ['']))
394 self.assertEquals(self.vty.node(), 'config-nat')
395 self.assertTrue(self.vty.verify('exit', ['']))
396 self.assertEquals(self.vty.node(), 'config')
397 self.assertTrue(self.vty.verify('exit', ['']))
398 self.assertTrue(self.vty.node() is None)
399
400 # Check searching for outer node's commands
401 self.vty.command('configure terminal')
402 self.vty.command('mgcp')
403 self.vty.command('nat')
404 self.assertEquals(self.vty.node(), 'config-nat')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200405 self.vty.command('mgcp')
406 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200407 self.vty.command('nat')
408 self.assertEquals(self.vty.node(), 'config-nat')
409 self.vty.command('bsc 0')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200410 self.vty.command('mgcp')
411 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200412
Holger Hans Peter Freytherb718ad32013-06-25 09:08:02 +0200413 def testRewriteNoRewrite(self):
414 self.vty.enable()
415 res = self.vty.command("configure terminal")
416 res = self.vty.command("nat")
417 res = self.vty.command("number-rewrite rewrite.cfg")
418 res = self.vty.command("no number-rewrite")
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200419
Holger Hans Peter Freyther67e423c2013-06-25 15:38:31 +0200420 def testRewritePostNoRewrite(self):
421 self.vty.enable()
422 self.vty.command("configure terminal")
423 self.vty.command("nat")
424 self.vty.verify("number-rewrite-post rewrite.cfg", [''])
425 self.vty.verify("no number-rewrite-post", [''])
426
427
Holger Hans Peter Freytherddf191e2013-06-25 11:44:01 +0200428 def testPrefixTreeLoading(self):
429 cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv")
430
431 self.vty.enable()
432 self.vty.command("configure terminal")
433 self.vty.command("nat")
434 res = self.vty.command("prefix-tree %s" % cfg)
435 self.assertEqual(res, "% prefix-tree loaded 17 rules.")
436 self.vty.command("end")
437
438 res = self.vty.command("show prefix-tree")
439 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')
440
441 self.vty.command("configure terminal")
442 self.vty.command("nat")
443 self.vty.command("no prefix-tree")
444 self.vty.command("end")
445
446 res = self.vty.command("show prefix-tree")
447 self.assertEqual(res, "% there is now prefix tree loaded.")
448
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200449 def testUssdSideChannelProvider(self):
450 self.vty.command("end")
451 self.vty.enable()
452 self.vty.command("configure terminal")
453 self.vty.command("nat")
454 self.vty.command("ussd-token key")
455 self.vty.command("end")
456
457 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
458 self.assertTrue(res)
459
460 ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
461 ussdSocket.connect(('127.0.0.1', 5001))
462 ussdSocket.settimeout(2.0)
463 print "Connected to %s:%d" % ussdSocket.getpeername()
464
465 print "Expecting ID_GET request"
466 data = ussdSocket.recv(4)
467 self.assertEqual(data, "\x00\x01\xfe\x04")
468
469 print "Going to send ID_RESP response"
470 res = ussdSocket.send("\x00\x07\xfe\x05\x00\x04\x01\x6b\x65\x79")
471 self.assertEqual(res, 10)
472
473 # initiating PING/PONG cycle to know, that the ID_RESP message has been processed
474
475 print "Going to send PING request"
476 res = ussdSocket.send("\x00\x01\xfe\x00")
477 self.assertEqual(res, 4)
478
479 print "Expecting PONG response"
480 data = ussdSocket.recv(4)
481 self.assertEqual(data, "\x00\x01\xfe\x01")
482
483 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.'])
484 self.assertTrue(res)
485
486 print "Going to shut down connection"
487 ussdSocket.shutdown(socket.SHUT_WR)
488
489 print "Expecting EOF"
490 data = ussdSocket.recv(4)
491 self.assertEqual(data, "")
492
493 ussdSocket.close()
494
495 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
496 self.assertTrue(res)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200497
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200498class TestVTYGbproxy(TestVTYGenericBSC):
499
500 def vty_command(self):
501 return ["./src/gprs/osmo-gbproxy", "-c",
502 "doc/examples/osmo-gbproxy/osmo-gbproxy.cfg"]
503
504 def vty_app(self):
505 return (4246, "./src/gprs/osmo-gbproxy", "OsmoGbProxy", "bsc")
506
507 def testVtyTree(self):
508 self.vty.enable()
509 self.assertTrue(self.vty.verify('configure terminal', ['']))
510 self.assertEquals(self.vty.node(), 'config')
511 self.ignoredCheckForEndAndExit()
512 self.assertTrue(self.vty.verify('ns', ['']))
513 self.assertEquals(self.vty.node(), 'config-ns')
514 self.checkForEndAndExit()
515 self.assertTrue(self.vty.verify('exit', ['']))
516 self.assertEquals(self.vty.node(), 'config')
517 self.assertTrue(self.vty.verify('gbproxy', ['']))
518 self.assertEquals(self.vty.node(), 'config-gbproxy')
519 self.checkForEndAndExit()
520 self.assertTrue(self.vty.verify('exit', ['']))
521 self.assertEquals(self.vty.node(), 'config')
522
523 def testVtyShow(self):
524 res = self.vty.command("show ns")
525 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
526
527 res = self.vty.command("show gbproxy stats")
528 self.assert_(res.find('GBProxy Global Statistics') >= 0)
529
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200530def add_nat_test(suite, workdir):
531 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
532 print("Skipping the NAT test")
533 return
534 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT)
535 suite.addTest(test)
536
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200537def add_bsc_test(suite, workdir):
538 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")):
539 print("Skipping the BSC test")
540 return
541 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC)
542 suite.addTest(test)
543
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200544def add_gbproxy_test(suite, workdir):
545 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-gbproxy")):
546 print("Skipping the Gb-Proxy test")
547 return
548 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYGbproxy)
549 suite.addTest(test)
550
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200551if __name__ == '__main__':
552 import argparse
553 import sys
554
555 workdir = '.'
556
557 parser = argparse.ArgumentParser()
558 parser.add_argument("-v", "--verbose", dest="verbose",
559 action="store_true", help="verbose mode")
560 parser.add_argument("-p", "--pythonconfpath", dest="p",
561 help="searchpath for config")
562 parser.add_argument("-w", "--workdir", dest="w",
563 help="Working directory")
564 args = parser.parse_args()
565
566 verbose_level = 1
567 if args.verbose:
568 verbose_level = 2
569
570 if args.w:
571 workdir = args.w
572
573 if args.p:
574 confpath = args.p
575
576 print "confpath %s, workdir %s" % (confpath, workdir)
577 os.chdir(workdir)
578 print "Running tests for specific VTY commands"
579 suite = unittest.TestSuite()
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200580 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB))
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200581 add_bsc_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200582 add_nat_test(suite, workdir)
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200583 add_gbproxy_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200584 res = unittest.TextTestRunner(verbosity=verbose_level).run(suite)
585 sys.exit(len(res.errors) + len(res.failures))