Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 1 | #!/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 | |
| 18 | import os |
| 19 | import time |
| 20 | import unittest |
Jacob Erlbeck | 6cb2ccc | 2013-08-14 11:10:34 +0200 | [diff] [blame] | 21 | import socket |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 22 | |
| 23 | import osmopy.obscvty as obscvty |
| 24 | import osmopy.osmoutil as osmoutil |
| 25 | |
| 26 | confpath = '.' |
| 27 | |
| 28 | class 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 | |
Holger Hans Peter Freyther | 8d998a7 | 2014-07-04 20:23:56 +0200 | [diff] [blame] | 59 | class TestVTYMGCP(TestVTYBase): |
| 60 | def vty_command(self): |
| 61 | return ["./src/osmo-bsc_mgcp/osmo-bsc_mgcp", "-c", |
| 62 | "doc/examples/osmo-bsc_mgcp/mgcp.cfg"] |
| 63 | |
| 64 | def vty_app(self): |
| 65 | return (4243, "./src/osmo-bsc_mgcp/osmo-bsc_mgcp", "OpenBSC MGCP", "mgcp") |
| 66 | |
| 67 | def testForcePtime(self): |
| 68 | self.vty.enable() |
| 69 | res = self.vty.command("show running-config") |
| 70 | self.assert_(res.find(' rtp force-ptime 20\r') > 0) |
| 71 | self.assertEquals(res.find(' no rtp force-ptime\r'), -1) |
| 72 | |
| 73 | self.vty.command("configure terminal") |
| 74 | self.vty.command("mgcp") |
| 75 | self.vty.command("no rtp force-ptime") |
| 76 | res = self.vty.command("show running-config") |
| 77 | self.assertEquals(res.find(' rtp force-ptime 20\r'), -1) |
| 78 | self.assertEquals(res.find(' no rtp force-ptime\r'), -1) |
| 79 | |
Holger Hans Peter Freyther | 619b014 | 2014-11-19 16:04:45 +0100 | [diff] [blame] | 80 | def testOmitAudio(self): |
| 81 | self.vty.enable() |
| 82 | res = self.vty.command("show running-config") |
| 83 | self.assert_(res.find(' sdp audio-payload send-name\r') > 0) |
| 84 | self.assertEquals(res.find(' no sdp audio-payload send-name\r'), -1) |
| 85 | |
| 86 | self.vty.command("configure terminal") |
| 87 | self.vty.command("mgcp") |
| 88 | self.vty.command("no sdp audio-payload send-name") |
| 89 | res = self.vty.command("show running-config") |
| 90 | self.assertEquals(res.find(' rtp sdp audio-payload send-name\r'), -1) |
| 91 | self.assert_(res.find(' no sdp audio-payload send-name\r') > 0) |
| 92 | |
| 93 | # TODO: test it for the trunk! |
| 94 | |
Holger Hans Peter Freyther | c390ae8 | 2015-08-20 15:15:50 +0200 | [diff] [blame] | 95 | def testBindAddr(self): |
| 96 | self.vty.enable() |
| 97 | |
| 98 | self.vty.command("configure terminal") |
| 99 | self.vty.command("mgcp") |
| 100 | |
| 101 | # enable.. disable bts-bind-ip |
| 102 | self.vty.command("rtp bts-bind-ip 254.253.252.250") |
| 103 | res = self.vty.command("show running-config") |
| 104 | self.assert_(res.find('rtp bts-bind-ip 254.253.252.250') > 0) |
| 105 | self.vty.command("no rtp bts-bind-ip") |
| 106 | res = self.vty.command("show running-config") |
| 107 | self.assertEquals(res.find(' rtp bts-bind-ip'), -1) |
| 108 | |
| 109 | # enable.. disable net-bind-ip |
| 110 | self.vty.command("rtp net-bind-ip 254.253.252.250") |
| 111 | res = self.vty.command("show running-config") |
| 112 | self.assert_(res.find('rtp net-bind-ip 254.253.252.250') > 0) |
| 113 | self.vty.command("no rtp net-bind-ip") |
| 114 | res = self.vty.command("show running-config") |
| 115 | self.assertEquals(res.find(' rtp net-bind-ip'), -1) |
| 116 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 117 | |
| 118 | class TestVTYGenericBSC(TestVTYBase): |
| 119 | |
| 120 | def checkForEndAndExit(self): |
| 121 | res = self.vty.command("list") |
| 122 | #print ('looking for "exit"\n') |
| 123 | self.assert_(res.find(' exit\r') > 0) |
| 124 | #print 'found "exit"\nlooking for "end"\n' |
| 125 | self.assert_(res.find(' end\r') > 0) |
| 126 | #print 'found "end"\n' |
| 127 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 128 | def _testConfigNetworkTree(self): |
| 129 | self.vty.enable() |
| 130 | self.assertTrue(self.vty.verify("configure terminal",[''])) |
| 131 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 132 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 133 | self.assertTrue(self.vty.verify("network",[''])) |
| 134 | self.assertEquals(self.vty.node(), 'config-net') |
| 135 | self.checkForEndAndExit() |
| 136 | self.assertTrue(self.vty.verify("bts 0",[''])) |
| 137 | self.assertEquals(self.vty.node(), 'config-net-bts') |
| 138 | self.checkForEndAndExit() |
| 139 | self.assertTrue(self.vty.verify("trx 0",[''])) |
| 140 | self.assertEquals(self.vty.node(), 'config-net-bts-trx') |
| 141 | self.checkForEndAndExit() |
Jacob Erlbeck | 733bec8 | 2013-09-11 10:46:56 +0200 | [diff] [blame] | 142 | self.vty.command("write terminal") |
| 143 | self.assertTrue(self.vty.verify("exit",[''])) |
| 144 | self.assertEquals(self.vty.node(), 'config-net-bts') |
| 145 | self.assertTrue(self.vty.verify("exit",[''])) |
| 146 | self.assertTrue(self.vty.verify("bts 1",[''])) |
| 147 | self.assertEquals(self.vty.node(), 'config-net-bts') |
| 148 | self.checkForEndAndExit() |
| 149 | self.assertTrue(self.vty.verify("trx 1",[''])) |
| 150 | self.assertEquals(self.vty.node(), 'config-net-bts-trx') |
| 151 | self.checkForEndAndExit() |
| 152 | self.vty.command("write terminal") |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 153 | self.assertTrue(self.vty.verify("exit",[''])) |
| 154 | self.assertEquals(self.vty.node(), 'config-net-bts') |
| 155 | self.assertTrue(self.vty.verify("exit",[''])) |
| 156 | self.assertEquals(self.vty.node(), 'config-net') |
| 157 | self.assertTrue(self.vty.verify("exit",[''])) |
| 158 | self.assertEquals(self.vty.node(), 'config') |
| 159 | self.assertTrue(self.vty.verify("exit",[''])) |
| 160 | self.assertTrue(self.vty.node() is None) |
| 161 | |
| 162 | class TestVTYNITB(TestVTYGenericBSC): |
Holger Hans Peter Freyther | c63f6f1 | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 163 | |
| 164 | def vty_command(self): |
| 165 | return ["./src/osmo-nitb/osmo-nitb", "-c", |
| 166 | "doc/examples/osmo-nitb/nanobts/openbsc.cfg"] |
| 167 | |
| 168 | def vty_app(self): |
| 169 | return (4242, "./src/osmo-nitb/osmo-nitb", "OpenBSC", "nitb") |
| 170 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 171 | def testConfigNetworkTree(self): |
Jacob Erlbeck | 7587727 | 2013-10-23 11:24:14 +0200 | [diff] [blame] | 172 | self._testConfigNetworkTree() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 173 | |
Holger Hans Peter Freyther | 0df1ab9 | 2013-09-02 20:58:38 +0200 | [diff] [blame] | 174 | def checkForSmpp(self): |
| 175 | """SMPP is not always enabled, check if it is""" |
| 176 | res = self.vty.command("list") |
| 177 | return "smpp" in res |
| 178 | |
Holger Hans Peter Freyther | 42cf2e0 | 2015-07-06 16:41:30 +0200 | [diff] [blame] | 179 | def testSmppFirst(self): |
Holger Hans Peter Freyther | 42cf2e0 | 2015-07-06 16:41:30 +0200 | [diff] [blame] | 180 | # enable the configuration |
| 181 | self.vty.enable() |
| 182 | self.vty.command("configure terminal") |
Holger Hans Peter Freyther | a2c41c4 | 2015-07-13 11:23:53 +0200 | [diff] [blame] | 183 | |
| 184 | if not self.checkForSmpp(): |
| 185 | return |
| 186 | |
Holger Hans Peter Freyther | 42cf2e0 | 2015-07-06 16:41:30 +0200 | [diff] [blame] | 187 | self.vty.command("smpp") |
| 188 | |
| 189 | # check the default |
| 190 | res = self.vty.command("write terminal") |
| 191 | self.assert_(res.find(' no smpp-first') > 0) |
| 192 | |
| 193 | self.vty.verify("smpp-first", ['']) |
| 194 | res = self.vty.command("write terminal") |
| 195 | self.assert_(res.find(' smpp-first') > 0) |
| 196 | self.assertEquals(res.find('no smpp-first'), -1) |
| 197 | |
| 198 | self.vty.verify("no smpp-first", ['']) |
| 199 | res = self.vty.command("write terminal") |
| 200 | self.assert_(res.find('no smpp-first') > 0) |
| 201 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 202 | def testVtyTree(self): |
| 203 | self.vty.enable() |
| 204 | self.assertTrue(self.vty.verify("configure terminal", [''])) |
| 205 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 206 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 207 | self.assertTrue(self.vty.verify('mncc-int', [''])) |
| 208 | self.assertEquals(self.vty.node(), 'config-mncc-int') |
| 209 | self.checkForEndAndExit() |
| 210 | self.assertTrue(self.vty.verify('exit', [''])) |
Holger Hans Peter Freyther | 0df1ab9 | 2013-09-02 20:58:38 +0200 | [diff] [blame] | 211 | |
| 212 | if self.checkForSmpp(): |
| 213 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 7587727 | 2013-10-23 11:24:14 +0200 | [diff] [blame] | 214 | self.assertTrue(self.vty.verify('smpp', [''])) |
| 215 | self.assertEquals(self.vty.node(), 'config-smpp') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 216 | self.checkForEndAndExit() |
Jacob Erlbeck | 7587727 | 2013-10-23 11:24:14 +0200 | [diff] [blame] | 217 | self.assertTrue(self.vty.verify("exit", [''])) |
Holger Hans Peter Freyther | 0df1ab9 | 2013-09-02 20:58:38 +0200 | [diff] [blame] | 218 | |
Jacob Erlbeck | 0ae92a9 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 219 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 220 | self.assertTrue(self.vty.verify("exit", [''])) |
| 221 | self.assertTrue(self.vty.node() is None) |
| 222 | |
| 223 | # Check searching for outer node's commands |
| 224 | self.vty.command("configure terminal") |
| 225 | self.vty.command('mncc-int') |
Holger Hans Peter Freyther | 0df1ab9 | 2013-09-02 20:58:38 +0200 | [diff] [blame] | 226 | |
| 227 | if self.checkForSmpp(): |
| 228 | self.vty.command('smpp') |
| 229 | self.assertEquals(self.vty.node(), 'config-smpp') |
| 230 | self.vty.command('mncc-int') |
| 231 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 232 | self.assertEquals(self.vty.node(), 'config-mncc-int') |
| 233 | |
Max | 0c1bc26 | 2016-04-20 12:06:06 +0200 | [diff] [blame] | 234 | def testSi2Q(self): |
| 235 | self.vty.enable() |
| 236 | self.vty.command("configure terminal") |
| 237 | self.vty.command("network") |
| 238 | self.vty.command("bts 0") |
| 239 | before = self.vty.command("show running-config") |
| 240 | self.vty.command("si2quater neighbor-list add earfcn 1911 threshold 11 2") |
| 241 | self.vty.command("si2quater neighbor-list add earfcn 1924 threshold 11 3") |
| 242 | self.vty.command("si2quater neighbor-list add earfcn 2111 threshold 11") |
| 243 | self.vty.command("si2quater neighbor-list del earfcn 1911") |
| 244 | self.vty.command("si2quater neighbor-list del earfcn 1924") |
| 245 | self.vty.command("si2quater neighbor-list del earfcn 2111") |
| 246 | self.assertEquals(before, self.vty.command("show running-config")) |
| 247 | |
Holger Hans Peter Freyther | c63f6f1 | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 248 | def testEnableDisablePeriodicLU(self): |
| 249 | self.vty.enable() |
| 250 | self.vty.command("configure terminal") |
| 251 | self.vty.command("network") |
| 252 | self.vty.command("bts 0") |
| 253 | |
| 254 | # Test invalid input |
| 255 | self.vty.verify("periodic location update 0", ['% Unknown command.']) |
| 256 | self.vty.verify("periodic location update 5", ['% Unknown command.']) |
| 257 | self.vty.verify("periodic location update 1531", ['% Unknown command.']) |
| 258 | |
| 259 | # Enable periodic lu.. |
| 260 | self.vty.verify("periodic location update 60", ['']) |
| 261 | res = self.vty.command("write terminal") |
Holger Hans Peter Freyther | c0438e3 | 2013-07-27 22:23:25 +0200 | [diff] [blame] | 262 | self.assert_(res.find('periodic location update 60') > 0) |
Holger Hans Peter Freyther | c63f6f1 | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 263 | self.assertEquals(res.find('no periodic location update'), -1) |
| 264 | |
| 265 | # Now disable it.. |
| 266 | self.vty.verify("no periodic location update", ['']) |
| 267 | res = self.vty.command("write terminal") |
| 268 | self.assertEquals(res.find('periodic location update 60'), -1) |
Holger Hans Peter Freyther | c0438e3 | 2013-07-27 22:23:25 +0200 | [diff] [blame] | 269 | self.assert_(res.find('no periodic location update') > 0) |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 270 | |
Jacob Erlbeck | 65d114f | 2014-01-16 11:02:14 +0100 | [diff] [blame] | 271 | def testEnableDisableSiHacks(self): |
| 272 | self.vty.enable() |
| 273 | self.vty.command("configure terminal") |
| 274 | self.vty.command("network") |
| 275 | self.vty.command("bts 0") |
| 276 | |
| 277 | # Enable periodic lu.. |
| 278 | self.vty.verify("force-combined-si", ['']) |
| 279 | res = self.vty.command("write terminal") |
| 280 | self.assert_(res.find(' force-combined-si') > 0) |
| 281 | self.assertEquals(res.find('no force-combined-si'), -1) |
| 282 | |
| 283 | # Now disable it.. |
| 284 | self.vty.verify("no force-combined-si", ['']) |
| 285 | res = self.vty.command("write terminal") |
| 286 | self.assertEquals(res.find(' force-combined-si'), -1) |
| 287 | self.assert_(res.find('no force-combined-si') > 0) |
| 288 | |
Ivan Kluchnikov | 6792059 | 2013-09-16 13:13:04 +0400 | [diff] [blame] | 289 | def testRachAccessControlClass(self): |
| 290 | self.vty.enable() |
| 291 | self.vty.command("configure terminal") |
| 292 | self.vty.command("network") |
| 293 | self.vty.command("bts 0") |
| 294 | |
| 295 | # Test invalid input |
| 296 | self.vty.verify("rach access-control-class", ['% Command incomplete.']) |
| 297 | self.vty.verify("rach access-control-class 1", ['% Command incomplete.']) |
| 298 | self.vty.verify("rach access-control-class -1", ['% Unknown command.']) |
| 299 | self.vty.verify("rach access-control-class 10", ['% Unknown command.']) |
| 300 | self.vty.verify("rach access-control-class 16", ['% Unknown command.']) |
| 301 | |
| 302 | # Barred rach access control classes |
| 303 | for classNum in range(16): |
| 304 | if classNum != 10: |
| 305 | self.vty.verify("rach access-control-class " + str(classNum) + " barred", ['']) |
| 306 | |
| 307 | # Verify settings |
| 308 | res = self.vty.command("write terminal") |
| 309 | for classNum in range(16): |
| 310 | if classNum != 10: |
| 311 | self.assert_(res.find("rach access-control-class " + str(classNum) + " barred") > 0) |
| 312 | |
| 313 | # Allowed rach access control classes |
| 314 | for classNum in range(16): |
| 315 | if classNum != 10: |
| 316 | self.vty.verify("rach access-control-class " + str(classNum) + " allowed", ['']) |
| 317 | |
| 318 | # Verify settings |
| 319 | res = self.vty.command("write terminal") |
| 320 | for classNum in range(16): |
| 321 | if classNum != 10: |
| 322 | self.assertEquals(res.find("rach access-control-class " + str(classNum) + " barred"), -1) |
| 323 | |
Holger Hans Peter Freyther | de39225 | 2016-04-01 19:44:00 +0200 | [diff] [blame] | 324 | def testSubscriberCreateDeleteTwice(self): |
| 325 | """ |
| 326 | OS#1657 indicates that there might be an issue creating the |
| 327 | same subscriber twice. This test will use the VTY command to |
| 328 | create a subscriber and then issue a second create command |
| 329 | with the same IMSI. The test passes if the VTY continues to |
| 330 | respond to VTY commands. |
| 331 | """ |
| 332 | self.vty.enable() |
| 333 | |
| 334 | imsi = "204300854013739" |
| 335 | |
| 336 | # Initially we don't have this subscriber |
| 337 | self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi]) |
| 338 | |
| 339 | # Lets create one |
| 340 | res = self.vty.command('subscriber create imsi '+imsi) |
| 341 | self.assert_(res.find(" IMSI: "+imsi) > 0) |
| 342 | # And now create one again. |
| 343 | res2 = self.vty.command('subscriber create imsi '+imsi) |
| 344 | self.assert_(res2.find(" IMSI: "+imsi) > 0) |
| 345 | self.assertEqual(res, res2) |
| 346 | |
| 347 | # Verify it has been created |
| 348 | res = self.vty.command('show subscriber imsi '+imsi) |
| 349 | self.assert_(res.find(" IMSI: "+imsi) > 0) |
| 350 | |
| 351 | # Delete it |
| 352 | res = self.vty.command('subscriber delete imsi '+imsi) |
| 353 | self.assert_(res != "") |
| 354 | |
| 355 | # Now it should not be there anymore |
| 356 | res = self.vty.command('show subscriber imsi '+imsi) |
| 357 | self.assert_(res != '% No subscriber found for imsi '+imsi) |
| 358 | |
| 359 | |
Ruben Pollan | ed04a0d | 2014-09-24 20:50:13 -0500 | [diff] [blame] | 360 | def testSubscriberCreateDelete(self): |
Alexander Chemeris | bd6d40f | 2013-10-04 23:54:17 +0200 | [diff] [blame] | 361 | self.vty.enable() |
| 362 | |
| 363 | imsi = "204300854013739" |
| 364 | |
| 365 | # Initially we don't have this subscriber |
| 366 | self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi]) |
| 367 | |
| 368 | # Lets create one |
| 369 | res = self.vty.command('subscriber create imsi '+imsi) |
| 370 | self.assert_(res.find(" IMSI: "+imsi) > 0) |
| 371 | |
| 372 | # Now we have it |
| 373 | res = self.vty.command('show subscriber imsi '+imsi) |
| 374 | self.assert_(res.find(" IMSI: "+imsi) > 0) |
| 375 | |
Ruben Pollan | ed04a0d | 2014-09-24 20:50:13 -0500 | [diff] [blame] | 376 | # Delete it |
| 377 | res = self.vty.command('subscriber delete imsi '+imsi) |
| 378 | self.assert_(res != "") |
| 379 | |
| 380 | # Now it should not be there anymore |
| 381 | res = self.vty.command('show subscriber imsi '+imsi) |
| 382 | self.assert_(res != '% No subscriber found for imsi '+imsi) |
| 383 | |
Jacob Erlbeck | 322b149 | 2015-04-07 17:49:49 +0200 | [diff] [blame] | 384 | def testSubscriberSettings(self): |
| 385 | self.vty.enable() |
| 386 | |
| 387 | imsi = "204300854013739" |
| 388 | wrong_imsi = "204300999999999" |
| 389 | |
| 390 | # Lets create one |
| 391 | res = self.vty.command('subscriber create imsi '+imsi) |
| 392 | self.assert_(res.find(" IMSI: "+imsi) > 0) |
| 393 | |
| 394 | self.vty.verify('subscriber imsi '+wrong_imsi+' name wrong', ['% No subscriber found for imsi '+wrong_imsi]) |
| 395 | res = self.vty.command('subscriber imsi '+imsi+' name '+('X' * 160)) |
| 396 | self.assert_(res.find("NAME is too long") > 0) |
| 397 | |
| 398 | self.vty.verify('subscriber imsi '+imsi+' name '+('G' * 159), ['']) |
| 399 | |
| 400 | self.vty.verify('subscriber imsi '+wrong_imsi+' extension 840', ['% No subscriber found for imsi '+wrong_imsi]) |
| 401 | res = self.vty.command('subscriber imsi '+imsi+' extension '+('9' * 15)) |
| 402 | self.assert_(res.find("EXTENSION is too long") > 0) |
| 403 | |
| 404 | self.vty.verify('subscriber imsi '+imsi+' extension '+('1' * 14), ['']) |
| 405 | |
| 406 | # Delete it |
| 407 | res = self.vty.command('subscriber delete imsi '+imsi) |
| 408 | self.assert_(res != "") |
| 409 | |
Holger Hans Peter Freyther | ec37bb2 | 2013-02-05 09:39:09 +0100 | [diff] [blame] | 410 | def testShowPagingGroup(self): |
| 411 | res = self.vty.command("show paging-group 255 1234567") |
| 412 | self.assertEqual(res, "% can't find BTS 255") |
| 413 | res = self.vty.command("show paging-group 0 1234567") |
| 414 | self.assertEquals(res, "%Paging group for IMSI 1234567 on BTS #0 is 7") |
| 415 | |
Ciaby | ec6e4f8 | 2014-03-06 17:20:55 +0100 | [diff] [blame] | 416 | def testShowNetwork(self): |
| 417 | res = self.vty.command("show network") |
| 418 | self.assert_(res.startswith('BSC is on Country Code') >= 0) |
| 419 | |
Holger Hans Peter Freyther | 8657326 | 2015-01-31 09:47:37 +0100 | [diff] [blame] | 420 | def testMeasurementFeed(self): |
| 421 | self.vty.enable() |
| 422 | self.vty.command("configure terminal") |
| 423 | self.vty.command("mncc-int") |
| 424 | |
| 425 | res = self.vty.command("write terminal") |
| 426 | self.assertEquals(res.find('meas-feed scenario'), -1) |
| 427 | |
| 428 | self.vty.command("meas-feed scenario bla") |
| 429 | res = self.vty.command("write terminal") |
| 430 | self.assert_(res.find('meas-feed scenario bla') > 0) |
| 431 | |
| 432 | self.vty.command("meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890") |
| 433 | res = self.vty.command("write terminal") |
| 434 | self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890'), -1) |
| 435 | self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz012345'), -1) |
| 436 | self.assert_(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234') > 0) |
| 437 | |
| 438 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 439 | class TestVTYBSC(TestVTYGenericBSC): |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 440 | |
| 441 | def vty_command(self): |
| 442 | return ["./src/osmo-bsc/osmo-bsc", "-c", |
| 443 | "doc/examples/osmo-bsc/osmo-bsc.cfg"] |
| 444 | |
| 445 | def vty_app(self): |
| 446 | return (4242, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc") |
| 447 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 448 | def testConfigNetworkTree(self): |
Jacob Erlbeck | 7587727 | 2013-10-23 11:24:14 +0200 | [diff] [blame] | 449 | self._testConfigNetworkTree() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 450 | |
| 451 | def testVtyTree(self): |
| 452 | self.vty.enable() |
| 453 | self.assertTrue(self.vty.verify("configure terminal", [''])) |
| 454 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 455 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 456 | self.assertTrue(self.vty.verify("msc 0", [''])) |
| 457 | self.assertEquals(self.vty.node(), 'config-msc') |
Jacob Erlbeck | 0ae92a9 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 458 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 459 | self.assertTrue(self.vty.verify("exit", [''])) |
Jacob Erlbeck | 0ae92a9 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 460 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 461 | self.assertTrue(self.vty.verify("bsc", [''])) |
| 462 | self.assertEquals(self.vty.node(), 'config-bsc') |
Jacob Erlbeck | 0ae92a9 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 463 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 464 | self.assertTrue(self.vty.verify("exit", [''])) |
Jacob Erlbeck | 0ae92a9 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 465 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 466 | self.assertTrue(self.vty.verify("exit", [''])) |
| 467 | self.assertTrue(self.vty.node() is None) |
| 468 | |
| 469 | # Check searching for outer node's commands |
| 470 | self.vty.command("configure terminal") |
| 471 | self.vty.command('msc 0') |
| 472 | self.vty.command("bsc") |
| 473 | self.assertEquals(self.vty.node(), 'config-bsc') |
| 474 | self.vty.command("msc 0") |
| 475 | self.assertEquals(self.vty.node(), 'config-msc') |
| 476 | |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 477 | def testUssdNotificationsMsc(self): |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 478 | self.vty.enable() |
| 479 | self.vty.command("configure terminal") |
| 480 | self.vty.command("msc") |
| 481 | |
| 482 | # Test invalid input |
| 483 | self.vty.verify("bsc-msc-lost-text", ['% Command incomplete.']) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 484 | self.vty.verify("bsc-welcome-text", ['% Command incomplete.']) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 485 | self.vty.verify("bsc-grace-text", ['% Command incomplete.']) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 486 | |
| 487 | # Enable USSD notifications |
| 488 | self.vty.verify("bsc-msc-lost-text MSC disconnected", ['']) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 489 | self.vty.verify("bsc-welcome-text Hello MS", ['']) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 490 | self.vty.verify("bsc-grace-text In grace period", ['']) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 491 | |
| 492 | # Verify settings |
| 493 | res = self.vty.command("write terminal") |
| 494 | self.assert_(res.find('bsc-msc-lost-text MSC disconnected') > 0) |
| 495 | self.assertEquals(res.find('no bsc-msc-lost-text'), -1) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 496 | self.assert_(res.find('bsc-welcome-text Hello MS') > 0) |
| 497 | self.assertEquals(res.find('no bsc-welcome-text'), -1) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 498 | self.assert_(res.find('bsc-grace-text In grace period') > 0) |
| 499 | self.assertEquals(res.find('no bsc-grace-text'), -1) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 500 | |
| 501 | # Now disable it.. |
| 502 | self.vty.verify("no bsc-msc-lost-text", ['']) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 503 | self.vty.verify("no bsc-welcome-text", ['']) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 504 | self.vty.verify("no bsc-grace-text", ['']) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 505 | |
| 506 | # Verify settings |
| 507 | res = self.vty.command("write terminal") |
| 508 | self.assertEquals(res.find('bsc-msc-lost-text MSC disconnected'), -1) |
| 509 | self.assert_(res.find('no bsc-msc-lost-text') > 0) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 510 | self.assertEquals(res.find('bsc-welcome-text Hello MS'), -1) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 511 | self.assert_(res.find('no bsc-welcome-text') > 0) |
| 512 | self.assertEquals(res.find('bsc-grace-text In grace period'), -1) |
| 513 | self.assert_(res.find('no bsc-grace-text') > 0) |
| 514 | |
| 515 | def testUssdNotificationsBsc(self): |
| 516 | self.vty.enable() |
| 517 | self.vty.command("configure terminal") |
| 518 | self.vty.command("bsc") |
| 519 | |
| 520 | # Test invalid input |
| 521 | self.vty.verify("missing-msc-text", ['% Command incomplete.']) |
| 522 | |
| 523 | # Enable USSD notifications |
| 524 | self.vty.verify("missing-msc-text No MSC found", ['']) |
| 525 | |
| 526 | # Verify settings |
| 527 | res = self.vty.command("write terminal") |
| 528 | self.assert_(res.find('missing-msc-text No MSC found') > 0) |
| 529 | self.assertEquals(res.find('no missing-msc-text'), -1) |
| 530 | |
| 531 | # Now disable it.. |
| 532 | self.vty.verify("no missing-msc-text", ['']) |
| 533 | |
| 534 | # Verify settings |
| 535 | res = self.vty.command("write terminal") |
| 536 | self.assertEquals(res.find('missing-msc-text No MSC found'), -1) |
| 537 | self.assert_(res.find('no missing-msc-text') > 0) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 538 | |
Jacob Erlbeck | 946d141 | 2013-09-17 13:59:29 +0200 | [diff] [blame] | 539 | def testNetworkTimezone(self): |
| 540 | self.vty.enable() |
| 541 | self.vty.verify("configure terminal", ['']) |
| 542 | self.vty.verify("network", ['']) |
| 543 | self.vty.verify("bts 0", ['']) |
| 544 | |
| 545 | # Test invalid input |
| 546 | self.vty.verify("timezone", ['% Command incomplete.']) |
| 547 | self.vty.verify("timezone 20 0", ['% Unknown command.']) |
| 548 | self.vty.verify("timezone 0 11", ['% Unknown command.']) |
| 549 | self.vty.verify("timezone 0 0 99", ['% Unknown command.']) |
| 550 | |
| 551 | # Set time zone without DST |
| 552 | self.vty.verify("timezone 2 30", ['']) |
| 553 | |
| 554 | # Verify settings |
| 555 | res = self.vty.command("write terminal") |
| 556 | self.assert_(res.find('timezone 2 30') > 0) |
| 557 | self.assertEquals(res.find('timezone 2 30 '), -1) |
| 558 | |
| 559 | # Set time zone with DST |
| 560 | self.vty.verify("timezone 2 30 1", ['']) |
| 561 | |
| 562 | # Verify settings |
| 563 | res = self.vty.command("write terminal") |
| 564 | self.assert_(res.find('timezone 2 30 1') > 0) |
| 565 | |
| 566 | # Now disable it.. |
| 567 | self.vty.verify("no timezone", ['']) |
| 568 | |
| 569 | # Verify settings |
| 570 | res = self.vty.command("write terminal") |
| 571 | self.assertEquals(res.find(' timezone'), -1) |
| 572 | |
Ciaby | ec6e4f8 | 2014-03-06 17:20:55 +0100 | [diff] [blame] | 573 | def testShowNetwork(self): |
| 574 | res = self.vty.command("show network") |
| 575 | self.assert_(res.startswith('BSC is on Country Code') >= 0) |
| 576 | |
Holger Hans Peter Freyther | db64f2e | 2014-10-29 10:06:15 +0100 | [diff] [blame] | 577 | def testPingPongConfiguration(self): |
| 578 | self.vty.enable() |
| 579 | self.vty.verify("configure terminal", ['']) |
| 580 | self.vty.verify("network", ['']) |
| 581 | self.vty.verify("msc 0", ['']) |
| 582 | |
| 583 | self.vty.verify("timeout-ping 12", ['']) |
| 584 | self.vty.verify("timeout-pong 14", ['']) |
| 585 | res = self.vty.command("show running-config") |
| 586 | self.assert_(res.find(" timeout-ping 12") > 0) |
| 587 | self.assert_(res.find(" timeout-pong 14") > 0) |
| 588 | self.assert_(res.find(" no timeout-ping advanced") > 0) |
| 589 | |
| 590 | self.vty.verify("timeout-ping advanced", ['']) |
| 591 | res = self.vty.command("show running-config") |
| 592 | self.assert_(res.find(" timeout-ping 12") > 0) |
| 593 | self.assert_(res.find(" timeout-pong 14") > 0) |
| 594 | self.assert_(res.find(" timeout-ping advanced") > 0) |
| 595 | |
| 596 | self.vty.verify("no timeout-ping advanced", ['']) |
| 597 | res = self.vty.command("show running-config") |
| 598 | self.assert_(res.find(" timeout-ping 12") > 0) |
| 599 | self.assert_(res.find(" timeout-pong 14") > 0) |
| 600 | self.assert_(res.find(" no timeout-ping advanced") > 0) |
| 601 | |
| 602 | self.vty.verify("no timeout-ping", ['']) |
| 603 | res = self.vty.command("show running-config") |
| 604 | self.assertEquals(res.find(" timeout-ping 12"), -1) |
| 605 | self.assertEquals(res.find(" timeout-pong 14"), -1) |
| 606 | self.assertEquals(res.find(" no timeout-ping advanced"), -1) |
| 607 | self.assert_(res.find(" no timeout-ping") > 0) |
| 608 | |
| 609 | self.vty.verify("timeout-ping advanced", ['%ping handling is disabled. Enable it first.']) |
| 610 | |
| 611 | # And back to enabling it |
| 612 | self.vty.verify("timeout-ping 12", ['']) |
| 613 | self.vty.verify("timeout-pong 14", ['']) |
| 614 | res = self.vty.command("show running-config") |
| 615 | self.assert_(res.find(" timeout-ping 12") > 0) |
| 616 | self.assert_(res.find(" timeout-pong 14") > 0) |
| 617 | self.assert_(res.find(" timeout-ping advanced") > 0) |
| 618 | |
Holger Hans Peter Freyther | 32dd2f3 | 2015-04-01 18:15:48 +0200 | [diff] [blame] | 619 | def testMscDataCoreLACCI(self): |
| 620 | self.vty.enable() |
| 621 | res = self.vty.command("show running-config") |
| 622 | self.assertEquals(res.find("core-location-area-code"), -1) |
| 623 | self.assertEquals(res.find("core-cell-identity"), -1) |
| 624 | |
| 625 | self.vty.command("configure terminal") |
| 626 | self.vty.command("msc 0") |
| 627 | self.vty.command("core-location-area-code 666") |
| 628 | self.vty.command("core-cell-identity 333") |
| 629 | |
| 630 | res = self.vty.command("show running-config") |
| 631 | self.assert_(res.find("core-location-area-code 666") > 0) |
| 632 | self.assert_(res.find("core-cell-identity 333") > 0) |
| 633 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 634 | class TestVTYNAT(TestVTYGenericBSC): |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 635 | |
| 636 | def vty_command(self): |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 637 | return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-l", "127.0.0.1", "-c", |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 638 | "doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"] |
| 639 | |
| 640 | def vty_app(self): |
| 641 | return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat") |
| 642 | |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 643 | def testBSCreload(self): |
Holger Hans Peter Freyther | 44ed497 | 2016-04-14 10:05:13 -0400 | [diff] [blame] | 644 | # Use different port for the mock msc to avoid clashing with |
| 645 | # the osmo-bsc_nat itself |
Holger Hans Peter Freyther | f1a61bb | 2016-04-14 08:50:25 -0400 | [diff] [blame] | 646 | ip = "127.0.0.1" |
Holger Hans Peter Freyther | e98c9c7 | 2016-04-14 10:58:58 -0400 | [diff] [blame] | 647 | port = 5522 |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 648 | self.vty.enable() |
| 649 | bscs1 = self.vty.command("show bscs-config") |
| 650 | nat_bsc_reload(self) |
| 651 | bscs2 = self.vty.command("show bscs-config") |
| 652 | # check that multiple calls to bscs-config-file give the same result |
| 653 | self.assertEquals(bscs1, bscs2) |
| 654 | |
| 655 | # add new bsc |
| 656 | self.vty.command("configure terminal") |
| 657 | self.vty.command("nat") |
| 658 | self.vty.command("bsc 5") |
| 659 | self.vty.command("token key") |
| 660 | self.vty.command("location_area_code 666") |
| 661 | self.vty.command("end") |
| 662 | |
| 663 | # update bsc token |
| 664 | self.vty.command("configure terminal") |
| 665 | self.vty.command("nat") |
| 666 | self.vty.command("bsc 1") |
| 667 | self.vty.command("token xyu") |
| 668 | self.vty.command("end") |
| 669 | |
Holger Hans Peter Freyther | 44ed497 | 2016-04-14 10:05:13 -0400 | [diff] [blame] | 670 | nat_msc_ip(self, ip, port) |
| 671 | msc = nat_msc_test(self, ip, port) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 672 | b0 = nat_bsc_sock_test(0, "lol") |
| 673 | b1 = nat_bsc_sock_test(1, "xyu") |
| 674 | b2 = nat_bsc_sock_test(5, "key") |
| 675 | |
| 676 | self.assertEquals("3 BSCs configured", self.vty.command("show nat num-bscs-configured")) |
| 677 | self.assertTrue(3 == nat_bsc_num_con(self)) |
| 678 | self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection")) |
| 679 | |
| 680 | nat_bsc_reload(self) |
| 681 | bscs2 = self.vty.command("show bscs-config") |
| 682 | # check that the reset to initial config succeeded |
| 683 | self.assertEquals(bscs1, bscs2) |
| 684 | |
| 685 | self.assertEquals("2 BSCs configured", self.vty.command("show nat num-bscs-configured")) |
| 686 | self.assertTrue(1 == nat_bsc_num_con(self)) |
| 687 | rem = self.vty.command("show bsc connections").split(' ') |
| 688 | # remaining connection is for BSC0 |
| 689 | self.assertEquals('0', rem[2]) |
| 690 | # remaining connection is authorized |
| 691 | self.assertEquals('1', rem[4]) |
| 692 | self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection")) |
| 693 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 694 | def testVtyTree(self): |
| 695 | self.vty.enable() |
| 696 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 697 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 698 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 699 | self.assertTrue(self.vty.verify('mgcp', [''])) |
| 700 | self.assertEquals(self.vty.node(), 'config-mgcp') |
| 701 | self.checkForEndAndExit() |
| 702 | self.assertTrue(self.vty.verify('exit', [''])) |
| 703 | self.assertEquals(self.vty.node(), 'config') |
| 704 | self.assertTrue(self.vty.verify('nat', [''])) |
| 705 | self.assertEquals(self.vty.node(), 'config-nat') |
| 706 | self.checkForEndAndExit() |
| 707 | self.assertTrue(self.vty.verify('bsc 0', [''])) |
| 708 | self.assertEquals(self.vty.node(), 'config-nat-bsc') |
| 709 | self.checkForEndAndExit() |
| 710 | self.assertTrue(self.vty.verify('exit', [''])) |
| 711 | self.assertEquals(self.vty.node(), 'config-nat') |
| 712 | self.assertTrue(self.vty.verify('exit', [''])) |
| 713 | self.assertEquals(self.vty.node(), 'config') |
| 714 | self.assertTrue(self.vty.verify('exit', [''])) |
| 715 | self.assertTrue(self.vty.node() is None) |
| 716 | |
| 717 | # Check searching for outer node's commands |
| 718 | self.vty.command('configure terminal') |
| 719 | self.vty.command('mgcp') |
| 720 | self.vty.command('nat') |
| 721 | self.assertEquals(self.vty.node(), 'config-nat') |
Jacob Erlbeck | 4c9dff5 | 2013-09-02 13:17:17 +0200 | [diff] [blame] | 722 | self.vty.command('mgcp') |
| 723 | self.assertEquals(self.vty.node(), 'config-mgcp') |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 724 | self.vty.command('nat') |
| 725 | self.assertEquals(self.vty.node(), 'config-nat') |
| 726 | self.vty.command('bsc 0') |
Jacob Erlbeck | 4c9dff5 | 2013-09-02 13:17:17 +0200 | [diff] [blame] | 727 | self.vty.command('mgcp') |
| 728 | self.assertEquals(self.vty.node(), 'config-mgcp') |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 729 | |
Holger Hans Peter Freyther | b718ad3 | 2013-06-25 09:08:02 +0200 | [diff] [blame] | 730 | def testRewriteNoRewrite(self): |
| 731 | self.vty.enable() |
| 732 | res = self.vty.command("configure terminal") |
| 733 | res = self.vty.command("nat") |
| 734 | res = self.vty.command("number-rewrite rewrite.cfg") |
| 735 | res = self.vty.command("no number-rewrite") |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 736 | |
Holger Hans Peter Freyther | 7f100c9 | 2015-04-23 20:25:17 -0400 | [diff] [blame] | 737 | def testEnsureNoEnsureModeSet(self): |
| 738 | self.vty.enable() |
| 739 | res = self.vty.command("configure terminal") |
| 740 | res = self.vty.command("nat") |
| 741 | |
| 742 | # Ensure the default |
| 743 | res = self.vty.command("show running-config") |
| 744 | self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0) |
| 745 | |
| 746 | self.vty.command("sdp-ensure-amr-mode-set") |
| 747 | res = self.vty.command("show running-config") |
| 748 | self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0) |
| 749 | |
| 750 | self.vty.command("no sdp-ensure-amr-mode-set") |
| 751 | res = self.vty.command("show running-config") |
| 752 | self.assert_(res.find('\n no sdp-ensure-amr-mode-set') > 0) |
| 753 | |
Holger Hans Peter Freyther | 67e423c | 2013-06-25 15:38:31 +0200 | [diff] [blame] | 754 | def testRewritePostNoRewrite(self): |
| 755 | self.vty.enable() |
| 756 | self.vty.command("configure terminal") |
| 757 | self.vty.command("nat") |
| 758 | self.vty.verify("number-rewrite-post rewrite.cfg", ['']) |
| 759 | self.vty.verify("no number-rewrite-post", ['']) |
| 760 | |
| 761 | |
Holger Hans Peter Freyther | ddf191e | 2013-06-25 11:44:01 +0200 | [diff] [blame] | 762 | def testPrefixTreeLoading(self): |
| 763 | cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv") |
| 764 | |
| 765 | self.vty.enable() |
| 766 | self.vty.command("configure terminal") |
| 767 | self.vty.command("nat") |
| 768 | res = self.vty.command("prefix-tree %s" % cfg) |
| 769 | self.assertEqual(res, "% prefix-tree loaded 17 rules.") |
| 770 | self.vty.command("end") |
| 771 | |
| 772 | res = self.vty.command("show prefix-tree") |
| 773 | 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') |
| 774 | |
| 775 | self.vty.command("configure terminal") |
| 776 | self.vty.command("nat") |
| 777 | self.vty.command("no prefix-tree") |
| 778 | self.vty.command("end") |
| 779 | |
| 780 | res = self.vty.command("show prefix-tree") |
| 781 | self.assertEqual(res, "% there is now prefix tree loaded.") |
| 782 | |
Jacob Erlbeck | 6cb2ccc | 2013-08-14 11:10:34 +0200 | [diff] [blame] | 783 | def testUssdSideChannelProvider(self): |
| 784 | self.vty.command("end") |
| 785 | self.vty.enable() |
| 786 | self.vty.command("configure terminal") |
| 787 | self.vty.command("nat") |
| 788 | self.vty.command("ussd-token key") |
| 789 | self.vty.command("end") |
| 790 | |
| 791 | res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.']) |
| 792 | self.assertTrue(res) |
| 793 | |
| 794 | ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 795 | ussdSocket.connect(('127.0.0.1', 5001)) |
| 796 | ussdSocket.settimeout(2.0) |
| 797 | print "Connected to %s:%d" % ussdSocket.getpeername() |
| 798 | |
| 799 | print "Expecting ID_GET request" |
| 800 | data = ussdSocket.recv(4) |
| 801 | self.assertEqual(data, "\x00\x01\xfe\x04") |
| 802 | |
| 803 | print "Going to send ID_RESP response" |
Max | 70cf729 | 2016-04-13 11:36:38 +0200 | [diff] [blame] | 804 | res = ipa_send_resp(ussdSocket, "\x6b\x65\x79") |
Jacob Erlbeck | 6cb2ccc | 2013-08-14 11:10:34 +0200 | [diff] [blame] | 805 | self.assertEqual(res, 10) |
| 806 | |
| 807 | # initiating PING/PONG cycle to know, that the ID_RESP message has been processed |
| 808 | |
| 809 | print "Going to send PING request" |
Max | 70cf729 | 2016-04-13 11:36:38 +0200 | [diff] [blame] | 810 | res = ipa_send_ping(ussdSocket) |
Jacob Erlbeck | 6cb2ccc | 2013-08-14 11:10:34 +0200 | [diff] [blame] | 811 | self.assertEqual(res, 4) |
| 812 | |
| 813 | print "Expecting PONG response" |
| 814 | data = ussdSocket.recv(4) |
| 815 | self.assertEqual(data, "\x00\x01\xfe\x01") |
| 816 | |
| 817 | res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.']) |
| 818 | self.assertTrue(res) |
| 819 | |
| 820 | print "Going to shut down connection" |
| 821 | ussdSocket.shutdown(socket.SHUT_WR) |
| 822 | |
| 823 | print "Expecting EOF" |
| 824 | data = ussdSocket.recv(4) |
| 825 | self.assertEqual(data, "") |
| 826 | |
| 827 | ussdSocket.close() |
| 828 | |
| 829 | res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.']) |
| 830 | self.assertTrue(res) |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 831 | |
Holger Hans Peter Freyther | 6419018 | 2014-01-20 10:14:05 +0100 | [diff] [blame] | 832 | def testAccessList(self): |
| 833 | """ |
| 834 | Verify that the imsi-deny can have a reject cause or no reject cause |
| 835 | """ |
| 836 | self.vty.enable() |
| 837 | self.vty.command("configure terminal") |
| 838 | self.vty.command("nat") |
| 839 | |
| 840 | # Old default |
| 841 | self.vty.command("access-list test-default imsi-deny ^123[0-9]*$") |
| 842 | res = self.vty.command("show running-config").split("\r\n") |
| 843 | asserted = False |
| 844 | for line in res: |
Holger Hans Peter Freyther | 4ecc687 | 2014-03-04 15:38:00 +0100 | [diff] [blame] | 845 | if line.startswith(" access-list test-default"): |
Holger Hans Peter Freyther | 6419018 | 2014-01-20 10:14:05 +0100 | [diff] [blame] | 846 | self.assertEqual(line, " access-list test-default imsi-deny ^123[0-9]*$ 11 11") |
| 847 | asserted = True |
| 848 | self.assert_(asserted) |
| 849 | |
| 850 | # Check the optional CM Service Reject Cause |
| 851 | self.vty.command("access-list test-cm-deny imsi-deny ^123[0-9]*$ 42").split("\r\n") |
| 852 | res = self.vty.command("show running-config").split("\r\n") |
| 853 | asserted = False |
| 854 | for line in res: |
| 855 | if line.startswith(" access-list test-cm"): |
| 856 | self.assertEqual(line, " access-list test-cm-deny imsi-deny ^123[0-9]*$ 42 11") |
| 857 | asserted = True |
| 858 | self.assert_(asserted) |
| 859 | |
| 860 | # Check the optional LU Reject Cause |
| 861 | self.vty.command("access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42").split("\r\n") |
| 862 | res = self.vty.command("show running-config").split("\r\n") |
| 863 | asserted = False |
| 864 | for line in res: |
| 865 | if line.startswith(" access-list test-lu"): |
| 866 | self.assertEqual(line, " access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42") |
| 867 | asserted = True |
| 868 | self.assert_(asserted) |
| 869 | |
Jacob Erlbeck | 6d23371 | 2013-10-23 11:24:15 +0200 | [diff] [blame] | 870 | class TestVTYGbproxy(TestVTYGenericBSC): |
| 871 | |
| 872 | def vty_command(self): |
| 873 | return ["./src/gprs/osmo-gbproxy", "-c", |
| 874 | "doc/examples/osmo-gbproxy/osmo-gbproxy.cfg"] |
| 875 | |
| 876 | def vty_app(self): |
| 877 | return (4246, "./src/gprs/osmo-gbproxy", "OsmoGbProxy", "bsc") |
| 878 | |
| 879 | def testVtyTree(self): |
| 880 | self.vty.enable() |
| 881 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 882 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 883 | self.checkForEndAndExit() |
Jacob Erlbeck | 6d23371 | 2013-10-23 11:24:15 +0200 | [diff] [blame] | 884 | self.assertTrue(self.vty.verify('ns', [''])) |
| 885 | self.assertEquals(self.vty.node(), 'config-ns') |
| 886 | self.checkForEndAndExit() |
| 887 | self.assertTrue(self.vty.verify('exit', [''])) |
| 888 | self.assertEquals(self.vty.node(), 'config') |
| 889 | self.assertTrue(self.vty.verify('gbproxy', [''])) |
| 890 | self.assertEquals(self.vty.node(), 'config-gbproxy') |
| 891 | self.checkForEndAndExit() |
| 892 | self.assertTrue(self.vty.verify('exit', [''])) |
| 893 | self.assertEquals(self.vty.node(), 'config') |
| 894 | |
| 895 | def testVtyShow(self): |
| 896 | res = self.vty.command("show ns") |
| 897 | self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0) |
| 898 | |
| 899 | res = self.vty.command("show gbproxy stats") |
| 900 | self.assert_(res.find('GBProxy Global Statistics') >= 0) |
| 901 | |
Jacob Erlbeck | 4211d79 | 2013-10-24 12:48:23 +0200 | [diff] [blame] | 902 | def testVtyDeletePeer(self): |
| 903 | self.vty.enable() |
| 904 | self.assertTrue(self.vty.verify('delete-gbproxy-peer 9999 bvci 7777', ['BVC not found'])) |
| 905 | res = self.vty.command("delete-gbproxy-peer 9999 all dry-run") |
| 906 | self.assert_(res.find('Not Deleted 0 BVC') >= 0) |
| 907 | self.assert_(res.find('Not Deleted 0 NS-VC') >= 0) |
| 908 | res = self.vty.command("delete-gbproxy-peer 9999 only-bvc dry-run") |
| 909 | self.assert_(res.find('Not Deleted 0 BVC') >= 0) |
| 910 | self.assert_(res.find('Not Deleted 0 NS-VC') < 0) |
| 911 | res = self.vty.command("delete-gbproxy-peer 9999 only-nsvc dry-run") |
| 912 | self.assert_(res.find('Not Deleted 0 BVC') < 0) |
| 913 | self.assert_(res.find('Not Deleted 0 NS-VC') >= 0) |
| 914 | res = self.vty.command("delete-gbproxy-peer 9999 all") |
| 915 | self.assert_(res.find('Deleted 0 BVC') >= 0) |
| 916 | self.assert_(res.find('Deleted 0 NS-VC') >= 0) |
| 917 | |
Jacob Erlbeck | 144b8b1 | 2014-11-04 11:15:01 +0100 | [diff] [blame] | 918 | class TestVTYSGSN(TestVTYGenericBSC): |
| 919 | |
| 920 | def vty_command(self): |
| 921 | return ["./src/gprs/osmo-sgsn", "-c", |
| 922 | "doc/examples/osmo-sgsn/osmo-sgsn.cfg"] |
| 923 | |
| 924 | def vty_app(self): |
| 925 | return (4245, "./src/gprs/osmo-sgsn", "OsmoSGSN", "sgsn") |
| 926 | |
| 927 | def testVtyTree(self): |
| 928 | self.vty.enable() |
| 929 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 930 | self.assertEquals(self.vty.node(), 'config') |
| 931 | self.checkForEndAndExit() |
| 932 | self.assertTrue(self.vty.verify('ns', [''])) |
| 933 | self.assertEquals(self.vty.node(), 'config-ns') |
| 934 | self.checkForEndAndExit() |
| 935 | self.assertTrue(self.vty.verify('exit', [''])) |
| 936 | self.assertEquals(self.vty.node(), 'config') |
| 937 | self.assertTrue(self.vty.verify('sgsn', [''])) |
| 938 | self.assertEquals(self.vty.node(), 'config-sgsn') |
| 939 | self.checkForEndAndExit() |
| 940 | self.assertTrue(self.vty.verify('exit', [''])) |
| 941 | self.assertEquals(self.vty.node(), 'config') |
| 942 | |
| 943 | def testVtyShow(self): |
| 944 | res = self.vty.command("show ns") |
| 945 | self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0) |
| 946 | self.assertTrue(self.vty.verify('show bssgp', [''])) |
| 947 | self.assertTrue(self.vty.verify('show bssgp stats', [''])) |
| 948 | # TODO: uncomment when the command does not segfault anymore |
| 949 | # self.assertTrue(self.vty.verify('show bssgp nsei 123', [''])) |
| 950 | # self.assertTrue(self.vty.verify('show bssgp nsei 123 stats', [''])) |
| 951 | |
| 952 | self.assertTrue(self.vty.verify('show sgsn', [''])) |
| 953 | self.assertTrue(self.vty.verify('show mm-context all', [''])) |
| 954 | self.assertTrue(self.vty.verify('show mm-context imsi 000001234567', ['No MM context for IMSI 000001234567'])) |
| 955 | self.assertTrue(self.vty.verify('show pdp-context all', [''])) |
| 956 | |
| 957 | res = self.vty.command("show sndcp") |
| 958 | self.assert_(res.find('State of SNDCP Entities') >= 0) |
| 959 | |
| 960 | res = self.vty.command("show llc") |
| 961 | self.assert_(res.find('State of LLC Entities') >= 0) |
| 962 | |
Jacob Erlbeck | 106f547 | 2014-11-04 10:08:37 +0100 | [diff] [blame] | 963 | def testVtyAuth(self): |
| 964 | self.vty.enable() |
| 965 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 966 | self.assertEquals(self.vty.node(), 'config') |
| 967 | self.assertTrue(self.vty.verify('sgsn', [''])) |
| 968 | self.assertEquals(self.vty.node(), 'config-sgsn') |
| 969 | self.assertTrue(self.vty.verify('auth-policy accept-all', [''])) |
| 970 | res = self.vty.command("show running-config") |
| 971 | self.assert_(res.find('auth-policy accept-all') > 0) |
| 972 | self.assertTrue(self.vty.verify('auth-policy acl-only', [''])) |
| 973 | res = self.vty.command("show running-config") |
| 974 | self.assert_(res.find('auth-policy acl-only') > 0) |
| 975 | self.assertTrue(self.vty.verify('auth-policy closed', [''])) |
| 976 | res = self.vty.command("show running-config") |
| 977 | self.assert_(res.find('auth-policy closed') > 0) |
Jacob Erlbeck | be2c8d9 | 2014-11-12 10:18:09 +0100 | [diff] [blame] | 978 | self.assertTrue(self.vty.verify('auth-policy remote', [''])) |
| 979 | res = self.vty.command("show running-config") |
| 980 | self.assert_(res.find('auth-policy remote') > 0) |
Jacob Erlbeck | 106f547 | 2014-11-04 10:08:37 +0100 | [diff] [blame] | 981 | |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 982 | def testVtySubscriber(self): |
| 983 | self.vty.enable() |
| 984 | res = self.vty.command('show subscriber cache') |
| 985 | self.assert_(res.find('1234567890') < 0) |
Jacob Erlbeck | d919343 | 2015-01-19 14:11:46 +0100 | [diff] [blame] | 986 | self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 create', [''])) |
| 987 | res = self.vty.command('show subscriber cache') |
| 988 | self.assert_(res.find('1234567890') >= 0) |
| 989 | self.assert_(res.find('Authorized: 0') >= 0) |
| 990 | self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 update-location-result ok', [''])) |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 991 | res = self.vty.command('show subscriber cache') |
| 992 | self.assert_(res.find('1234567890') >= 0) |
| 993 | self.assert_(res.find('Authorized: 1') >= 0) |
Jacob Erlbeck | 8000e0e | 2015-01-27 14:56:40 +0100 | [diff] [blame] | 994 | self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 cancel update-procedure', [''])) |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 995 | res = self.vty.command('show subscriber cache') |
Jacob Erlbeck | e988ae4 | 2015-01-27 12:41:19 +0100 | [diff] [blame] | 996 | self.assert_(res.find('1234567890') >= 0) |
| 997 | self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 destroy', [''])) |
| 998 | res = self.vty.command('show subscriber cache') |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 999 | self.assert_(res.find('1234567890') < 0) |
| 1000 | |
Jacob Erlbeck | cb1db8b | 2015-02-03 13:47:53 +0100 | [diff] [blame] | 1001 | def testVtyGgsn(self): |
| 1002 | self.vty.enable() |
| 1003 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 1004 | self.assertEquals(self.vty.node(), 'config') |
| 1005 | self.assertTrue(self.vty.verify('sgsn', [''])) |
| 1006 | self.assertEquals(self.vty.node(), 'config-sgsn') |
| 1007 | self.assertTrue(self.vty.verify('ggsn 0 remote-ip 127.99.99.99', [''])) |
| 1008 | self.assertTrue(self.vty.verify('ggsn 0 gtp-version 1', [''])) |
| 1009 | self.assertTrue(self.vty.verify('apn * ggsn 0', [''])) |
| 1010 | self.assertTrue(self.vty.verify('apn apn1.test ggsn 0', [''])) |
| 1011 | self.assertTrue(self.vty.verify('apn apn1.test ggsn 1', ['% a GGSN with id 1 has not been defined'])) |
| 1012 | self.assertTrue(self.vty.verify('apn apn1.test imsi-prefix 123456 ggsn 0', [''])) |
| 1013 | self.assertTrue(self.vty.verify('apn apn2.test imsi-prefix 123456 ggsn 0', [''])) |
| 1014 | res = self.vty.command("show running-config") |
| 1015 | self.assert_(res.find('ggsn 0 remote-ip 127.99.99.99') >= 0) |
| 1016 | self.assert_(res.find('ggsn 0 gtp-version 1') >= 0) |
| 1017 | self.assert_(res.find('apn * ggsn 0') >= 0) |
| 1018 | self.assert_(res.find('apn apn1.test ggsn 0') >= 0) |
| 1019 | self.assert_(res.find('apn apn1.test imsi-prefix 123456 ggsn 0') >= 0) |
| 1020 | self.assert_(res.find('apn apn2.test imsi-prefix 123456 ggsn 0') >= 0) |
| 1021 | |
Holger Hans Peter Freyther | 9c20a5f | 2015-02-06 16:23:29 +0100 | [diff] [blame] | 1022 | def testVtyEasyAPN(self): |
| 1023 | self.vty.enable() |
| 1024 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 1025 | self.assertEquals(self.vty.node(), 'config') |
| 1026 | self.assertTrue(self.vty.verify('sgsn', [''])) |
| 1027 | self.assertEquals(self.vty.node(), 'config-sgsn') |
| 1028 | |
| 1029 | res = self.vty.command("show running-config") |
| 1030 | self.assertEquals(res.find("apn internet"), -1) |
| 1031 | |
| 1032 | self.assertTrue(self.vty.verify("access-point-name internet.apn", [''])) |
| 1033 | res = self.vty.command("show running-config") |
| 1034 | self.assert_(res.find("apn internet.apn ggsn 0") >= 0) |
| 1035 | |
| 1036 | self.assertTrue(self.vty.verify("no access-point-name internet.apn", [''])) |
| 1037 | res = self.vty.command("show running-config") |
| 1038 | self.assertEquals(res.find("apn internet"), -1) |
| 1039 | |
Holger Hans Peter Freyther | c15c61c | 2015-05-06 17:46:08 +0200 | [diff] [blame] | 1040 | def testVtyCDR(self): |
| 1041 | self.vty.enable() |
| 1042 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 1043 | self.assertEquals(self.vty.node(), 'config') |
| 1044 | self.assertTrue(self.vty.verify('sgsn', [''])) |
| 1045 | self.assertEquals(self.vty.node(), 'config-sgsn') |
| 1046 | |
| 1047 | res = self.vty.command("show running-config") |
| 1048 | self.assert_(res.find("no cdr filename") > 0) |
| 1049 | |
| 1050 | self.vty.command("cdr filename bla.cdr") |
| 1051 | res = self.vty.command("show running-config") |
| 1052 | self.assertEquals(res.find("no cdr filename"), -1) |
| 1053 | self.assert_(res.find(" cdr filename bla.cdr") > 0) |
| 1054 | |
| 1055 | self.vty.command("no cdr filename") |
| 1056 | res = self.vty.command("show running-config") |
| 1057 | self.assert_(res.find("no cdr filename") > 0) |
| 1058 | self.assertEquals(res.find(" cdr filename bla.cdr"), -1) |
| 1059 | |
| 1060 | res = self.vty.command("show running-config") |
| 1061 | self.assert_(res.find(" cdr interval 600") > 0) |
| 1062 | |
| 1063 | self.vty.command("cdr interval 900") |
| 1064 | res = self.vty.command("show running-config") |
| 1065 | self.assert_(res.find(" cdr interval 900") > 0) |
| 1066 | self.assertEquals(res.find(" cdr interval 600"), -1) |
| 1067 | |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 1068 | def add_nat_test(suite, workdir): |
| 1069 | if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")): |
| 1070 | print("Skipping the NAT test") |
| 1071 | return |
| 1072 | test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT) |
| 1073 | suite.addTest(test) |
| 1074 | |
Max | 70cf729 | 2016-04-13 11:36:38 +0200 | [diff] [blame] | 1075 | def ipa_send_pong(x, verbose = False): |
| 1076 | if (verbose): |
| 1077 | print "\tBSC -> NAT: PONG!" |
| 1078 | return x.send("\x00\x01\xfe\x01") |
| 1079 | |
| 1080 | def ipa_send_ping(x, verbose = False): |
| 1081 | if (verbose): |
| 1082 | print "\tBSC -> NAT: PING?" |
| 1083 | return x.send("\x00\x01\xfe\x00") |
| 1084 | |
| 1085 | def ipa_send_ack(x, verbose = False): |
| 1086 | if (verbose): |
| 1087 | print "\tBSC -> NAT: IPA ID ACK" |
| 1088 | return x.send("\x00\x01\xfe\x06") |
| 1089 | |
| 1090 | def ipa_send_reset(x, verbose = False): |
| 1091 | if (verbose): |
| 1092 | print "\tBSC -> NAT: RESET" |
| 1093 | return x.send("\x00\x12\xfd\x09\x00\x03\x05\x07\x02\x42\xfe\x02\x42\xfe\x06\x00\x04\x30\x04\x01\x20") |
| 1094 | |
| 1095 | def ipa_send_resp(x, tk, verbose = False): |
| 1096 | if (verbose): |
| 1097 | print "\tBSC -> NAT: IPA ID RESP" |
| 1098 | return x.send("\x00\x07\xfe\x05\x00\x04\x01" + tk) |
| 1099 | |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1100 | def nat_bsc_reload(x): |
| 1101 | x.vty.command("configure terminal") |
| 1102 | x.vty.command("nat") |
| 1103 | x.vty.command("bscs-config-file bscs.config") |
| 1104 | x.vty.command("end") |
| 1105 | |
Holger Hans Peter Freyther | 44ed497 | 2016-04-14 10:05:13 -0400 | [diff] [blame] | 1106 | def nat_msc_ip(x, ip, port): |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1107 | x.vty.command("configure terminal") |
| 1108 | x.vty.command("nat") |
| 1109 | x.vty.command("msc ip " + ip) |
Holger Hans Peter Freyther | 84ae27e | 2016-04-14 10:40:06 -0400 | [diff] [blame] | 1110 | x.vty.command("msc port " + str(port)) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1111 | x.vty.command("end") |
| 1112 | |
| 1113 | def data2str(d): |
Holger Hans Peter Freyther | 8bb6204 | 2016-04-14 21:40:04 -0400 | [diff] [blame] | 1114 | return d.encode('hex').lower() |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1115 | |
Holger Hans Peter Freyther | 44ed497 | 2016-04-14 10:05:13 -0400 | [diff] [blame] | 1116 | def nat_msc_test(x, ip, port, verbose = False): |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1117 | msc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 1118 | msc.settimeout(32) |
Holger Hans Peter Freyther | 44ed497 | 2016-04-14 10:05:13 -0400 | [diff] [blame] | 1119 | msc.bind((ip, port)) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1120 | msc.listen(5) |
| 1121 | if (verbose): |
| 1122 | print "MSC is ready at " + ip |
| 1123 | while "MSC is connected: 0" == x.vty.command("show msc connection"): |
| 1124 | conn, addr = msc.accept() |
| 1125 | if (verbose): |
| 1126 | print "MSC got connection from ", addr |
| 1127 | return conn |
| 1128 | |
| 1129 | def ipa_handle_small(x, verbose = False): |
| 1130 | s = data2str(x.recv(4)) |
| 1131 | if "0001fe00" == s: |
| 1132 | if (verbose): |
| 1133 | print "\tBSC <- NAT: PING?" |
| 1134 | ipa_send_pong(x, verbose) |
| 1135 | elif "0001fe06" == s: |
| 1136 | if (verbose): |
| 1137 | print "\tBSC <- NAT: IPA ID ACK" |
| 1138 | ipa_send_ack(x, verbose) |
| 1139 | elif "0001fe00" == s: |
| 1140 | if (verbose): |
| 1141 | print "\tBSC <- NAT: PONG!" |
| 1142 | else: |
| 1143 | if (verbose): |
| 1144 | print "\tBSC <- NAT: ", s |
| 1145 | |
| 1146 | def ipa_handle_resp(x, tk, verbose = False): |
| 1147 | s = data2str(x.recv(38)) |
| 1148 | if "0023fe040108010701020103010401050101010011" in s: |
| 1149 | ipa_send_resp(x, tk, verbose) |
| 1150 | else: |
| 1151 | if (verbose): |
| 1152 | print "\tBSC <- NAT: ", s |
| 1153 | |
| 1154 | def nat_bsc_num_con(x): |
| 1155 | return len(x.vty.command("show bsc connections").split('\n')) |
| 1156 | |
| 1157 | def nat_bsc_sock_test(nr, tk, verbose = False): |
| 1158 | bsc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
Holger Hans Peter Freyther | 2abf2b0 | 2016-04-14 21:13:51 -0400 | [diff] [blame] | 1159 | bsc.bind(('127.0.0.1', 0)) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1160 | bsc.connect(('127.0.0.1', 5000)) |
| 1161 | if (verbose): |
| 1162 | print "BSC%d " %nr |
| 1163 | print "\tconnected to %s:%d" % bsc.getpeername() |
| 1164 | ipa_handle_small(bsc, verbose) |
| 1165 | ipa_handle_resp(bsc, tk, verbose) |
| 1166 | bsc.recv(27) # MGCP msg |
| 1167 | ipa_handle_small(bsc, verbose) |
| 1168 | return bsc |
| 1169 | |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 1170 | def add_bsc_test(suite, workdir): |
| 1171 | if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")): |
| 1172 | print("Skipping the BSC test") |
| 1173 | return |
| 1174 | test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC) |
| 1175 | suite.addTest(test) |
| 1176 | |
Jacob Erlbeck | 6d23371 | 2013-10-23 11:24:15 +0200 | [diff] [blame] | 1177 | def add_gbproxy_test(suite, workdir): |
| 1178 | if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-gbproxy")): |
| 1179 | print("Skipping the Gb-Proxy test") |
| 1180 | return |
| 1181 | test = unittest.TestLoader().loadTestsFromTestCase(TestVTYGbproxy) |
| 1182 | suite.addTest(test) |
| 1183 | |
Jacob Erlbeck | 144b8b1 | 2014-11-04 11:15:01 +0100 | [diff] [blame] | 1184 | def add_sgsn_test(suite, workdir): |
| 1185 | if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-sgsn")): |
| 1186 | print("Skipping the SGSN test") |
| 1187 | return |
| 1188 | test = unittest.TestLoader().loadTestsFromTestCase(TestVTYSGSN) |
| 1189 | suite.addTest(test) |
| 1190 | |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 1191 | if __name__ == '__main__': |
| 1192 | import argparse |
| 1193 | import sys |
| 1194 | |
| 1195 | workdir = '.' |
| 1196 | |
| 1197 | parser = argparse.ArgumentParser() |
| 1198 | parser.add_argument("-v", "--verbose", dest="verbose", |
| 1199 | action="store_true", help="verbose mode") |
| 1200 | parser.add_argument("-p", "--pythonconfpath", dest="p", |
| 1201 | help="searchpath for config") |
| 1202 | parser.add_argument("-w", "--workdir", dest="w", |
| 1203 | help="Working directory") |
| 1204 | args = parser.parse_args() |
| 1205 | |
| 1206 | verbose_level = 1 |
| 1207 | if args.verbose: |
| 1208 | verbose_level = 2 |
| 1209 | |
| 1210 | if args.w: |
| 1211 | workdir = args.w |
| 1212 | |
| 1213 | if args.p: |
| 1214 | confpath = args.p |
| 1215 | |
| 1216 | print "confpath %s, workdir %s" % (confpath, workdir) |
| 1217 | os.chdir(workdir) |
| 1218 | print "Running tests for specific VTY commands" |
| 1219 | suite = unittest.TestSuite() |
Holger Hans Peter Freyther | 8d998a7 | 2014-07-04 20:23:56 +0200 | [diff] [blame] | 1220 | suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYMGCP)) |
Holger Hans Peter Freyther | c63f6f1 | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 1221 | suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB)) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 1222 | add_bsc_test(suite, workdir) |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 1223 | add_nat_test(suite, workdir) |
Jacob Erlbeck | 6d23371 | 2013-10-23 11:24:15 +0200 | [diff] [blame] | 1224 | add_gbproxy_test(suite, workdir) |
Jacob Erlbeck | 144b8b1 | 2014-11-04 11:15:01 +0100 | [diff] [blame] | 1225 | add_sgsn_test(suite, workdir) |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 1226 | res = unittest.TextTestRunner(verbosity=verbose_level).run(suite) |
| 1227 | sys.exit(len(res.errors) + len(res.failures)) |