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 | |
Holger Hans Peter Freyther | c63f6f1 | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 234 | def testEnableDisablePeriodicLU(self): |
| 235 | self.vty.enable() |
| 236 | self.vty.command("configure terminal") |
| 237 | self.vty.command("network") |
| 238 | self.vty.command("bts 0") |
| 239 | |
| 240 | # Test invalid input |
| 241 | self.vty.verify("periodic location update 0", ['% Unknown command.']) |
| 242 | self.vty.verify("periodic location update 5", ['% Unknown command.']) |
| 243 | self.vty.verify("periodic location update 1531", ['% Unknown command.']) |
| 244 | |
| 245 | # Enable periodic lu.. |
| 246 | self.vty.verify("periodic location update 60", ['']) |
| 247 | res = self.vty.command("write terminal") |
Holger Hans Peter Freyther | c0438e3 | 2013-07-27 22:23:25 +0200 | [diff] [blame] | 248 | self.assert_(res.find('periodic location update 60') > 0) |
Holger Hans Peter Freyther | c63f6f1 | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 249 | self.assertEquals(res.find('no periodic location update'), -1) |
| 250 | |
| 251 | # Now disable it.. |
| 252 | self.vty.verify("no periodic location update", ['']) |
| 253 | res = self.vty.command("write terminal") |
| 254 | self.assertEquals(res.find('periodic location update 60'), -1) |
Holger Hans Peter Freyther | c0438e3 | 2013-07-27 22:23:25 +0200 | [diff] [blame] | 255 | self.assert_(res.find('no periodic location update') > 0) |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 256 | |
Jacob Erlbeck | 65d114f | 2014-01-16 11:02:14 +0100 | [diff] [blame] | 257 | def testEnableDisableSiHacks(self): |
| 258 | self.vty.enable() |
| 259 | self.vty.command("configure terminal") |
| 260 | self.vty.command("network") |
| 261 | self.vty.command("bts 0") |
| 262 | |
| 263 | # Enable periodic lu.. |
| 264 | self.vty.verify("force-combined-si", ['']) |
| 265 | res = self.vty.command("write terminal") |
| 266 | self.assert_(res.find(' force-combined-si') > 0) |
| 267 | self.assertEquals(res.find('no force-combined-si'), -1) |
| 268 | |
| 269 | # Now disable it.. |
| 270 | self.vty.verify("no force-combined-si", ['']) |
| 271 | res = self.vty.command("write terminal") |
| 272 | self.assertEquals(res.find(' force-combined-si'), -1) |
| 273 | self.assert_(res.find('no force-combined-si') > 0) |
| 274 | |
Ivan Kluchnikov | 6792059 | 2013-09-16 13:13:04 +0400 | [diff] [blame] | 275 | def testRachAccessControlClass(self): |
| 276 | self.vty.enable() |
| 277 | self.vty.command("configure terminal") |
| 278 | self.vty.command("network") |
| 279 | self.vty.command("bts 0") |
| 280 | |
| 281 | # Test invalid input |
| 282 | self.vty.verify("rach access-control-class", ['% Command incomplete.']) |
| 283 | self.vty.verify("rach access-control-class 1", ['% Command incomplete.']) |
| 284 | self.vty.verify("rach access-control-class -1", ['% Unknown command.']) |
| 285 | self.vty.verify("rach access-control-class 10", ['% Unknown command.']) |
| 286 | self.vty.verify("rach access-control-class 16", ['% Unknown command.']) |
| 287 | |
| 288 | # Barred rach access control classes |
| 289 | for classNum in range(16): |
| 290 | if classNum != 10: |
| 291 | self.vty.verify("rach access-control-class " + str(classNum) + " barred", ['']) |
| 292 | |
| 293 | # Verify settings |
| 294 | res = self.vty.command("write terminal") |
| 295 | for classNum in range(16): |
| 296 | if classNum != 10: |
| 297 | self.assert_(res.find("rach access-control-class " + str(classNum) + " barred") > 0) |
| 298 | |
| 299 | # Allowed rach access control classes |
| 300 | for classNum in range(16): |
| 301 | if classNum != 10: |
| 302 | self.vty.verify("rach access-control-class " + str(classNum) + " allowed", ['']) |
| 303 | |
| 304 | # Verify settings |
| 305 | res = self.vty.command("write terminal") |
| 306 | for classNum in range(16): |
| 307 | if classNum != 10: |
| 308 | self.assertEquals(res.find("rach access-control-class " + str(classNum) + " barred"), -1) |
| 309 | |
Ruben Pollan | ed04a0d | 2014-09-24 20:50:13 -0500 | [diff] [blame] | 310 | def testSubscriberCreateDelete(self): |
Alexander Chemeris | bd6d40f | 2013-10-04 23:54:17 +0200 | [diff] [blame] | 311 | self.vty.enable() |
| 312 | |
| 313 | imsi = "204300854013739" |
| 314 | |
| 315 | # Initially we don't have this subscriber |
| 316 | self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi]) |
| 317 | |
| 318 | # Lets create one |
| 319 | res = self.vty.command('subscriber create imsi '+imsi) |
| 320 | self.assert_(res.find(" IMSI: "+imsi) > 0) |
| 321 | |
| 322 | # Now we have it |
| 323 | res = self.vty.command('show subscriber imsi '+imsi) |
| 324 | self.assert_(res.find(" IMSI: "+imsi) > 0) |
| 325 | |
Ruben Pollan | ed04a0d | 2014-09-24 20:50:13 -0500 | [diff] [blame] | 326 | # Delete it |
| 327 | res = self.vty.command('subscriber delete imsi '+imsi) |
| 328 | self.assert_(res != "") |
| 329 | |
| 330 | # Now it should not be there anymore |
| 331 | res = self.vty.command('show subscriber imsi '+imsi) |
| 332 | self.assert_(res != '% No subscriber found for imsi '+imsi) |
| 333 | |
Jacob Erlbeck | 322b149 | 2015-04-07 17:49:49 +0200 | [diff] [blame] | 334 | def testSubscriberSettings(self): |
| 335 | self.vty.enable() |
| 336 | |
| 337 | imsi = "204300854013739" |
| 338 | wrong_imsi = "204300999999999" |
| 339 | |
| 340 | # Lets create one |
| 341 | res = self.vty.command('subscriber create imsi '+imsi) |
| 342 | self.assert_(res.find(" IMSI: "+imsi) > 0) |
| 343 | |
| 344 | self.vty.verify('subscriber imsi '+wrong_imsi+' name wrong', ['% No subscriber found for imsi '+wrong_imsi]) |
| 345 | res = self.vty.command('subscriber imsi '+imsi+' name '+('X' * 160)) |
| 346 | self.assert_(res.find("NAME is too long") > 0) |
| 347 | |
| 348 | self.vty.verify('subscriber imsi '+imsi+' name '+('G' * 159), ['']) |
| 349 | |
| 350 | self.vty.verify('subscriber imsi '+wrong_imsi+' extension 840', ['% No subscriber found for imsi '+wrong_imsi]) |
| 351 | res = self.vty.command('subscriber imsi '+imsi+' extension '+('9' * 15)) |
| 352 | self.assert_(res.find("EXTENSION is too long") > 0) |
| 353 | |
| 354 | self.vty.verify('subscriber imsi '+imsi+' extension '+('1' * 14), ['']) |
| 355 | |
| 356 | # Delete it |
| 357 | res = self.vty.command('subscriber delete imsi '+imsi) |
| 358 | self.assert_(res != "") |
| 359 | |
Holger Hans Peter Freyther | ec37bb2 | 2013-02-05 09:39:09 +0100 | [diff] [blame] | 360 | def testShowPagingGroup(self): |
| 361 | res = self.vty.command("show paging-group 255 1234567") |
| 362 | self.assertEqual(res, "% can't find BTS 255") |
| 363 | res = self.vty.command("show paging-group 0 1234567") |
| 364 | self.assertEquals(res, "%Paging group for IMSI 1234567 on BTS #0 is 7") |
| 365 | |
Ciaby | ec6e4f8 | 2014-03-06 17:20:55 +0100 | [diff] [blame] | 366 | def testShowNetwork(self): |
| 367 | res = self.vty.command("show network") |
| 368 | self.assert_(res.startswith('BSC is on Country Code') >= 0) |
| 369 | |
Holger Hans Peter Freyther | 8657326 | 2015-01-31 09:47:37 +0100 | [diff] [blame] | 370 | def testMeasurementFeed(self): |
| 371 | self.vty.enable() |
| 372 | self.vty.command("configure terminal") |
| 373 | self.vty.command("mncc-int") |
| 374 | |
| 375 | res = self.vty.command("write terminal") |
| 376 | self.assertEquals(res.find('meas-feed scenario'), -1) |
| 377 | |
| 378 | self.vty.command("meas-feed scenario bla") |
| 379 | res = self.vty.command("write terminal") |
| 380 | self.assert_(res.find('meas-feed scenario bla') > 0) |
| 381 | |
| 382 | self.vty.command("meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890") |
| 383 | res = self.vty.command("write terminal") |
| 384 | self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890'), -1) |
| 385 | self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz012345'), -1) |
| 386 | self.assert_(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234') > 0) |
| 387 | |
| 388 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 389 | class TestVTYBSC(TestVTYGenericBSC): |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 390 | |
| 391 | def vty_command(self): |
| 392 | return ["./src/osmo-bsc/osmo-bsc", "-c", |
| 393 | "doc/examples/osmo-bsc/osmo-bsc.cfg"] |
| 394 | |
| 395 | def vty_app(self): |
| 396 | return (4242, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc") |
| 397 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 398 | def testConfigNetworkTree(self): |
Jacob Erlbeck | 7587727 | 2013-10-23 11:24:14 +0200 | [diff] [blame] | 399 | self._testConfigNetworkTree() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 400 | |
| 401 | def testVtyTree(self): |
| 402 | self.vty.enable() |
| 403 | self.assertTrue(self.vty.verify("configure terminal", [''])) |
| 404 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 405 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 406 | self.assertTrue(self.vty.verify("msc 0", [''])) |
| 407 | self.assertEquals(self.vty.node(), 'config-msc') |
Jacob Erlbeck | 0ae92a9 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 408 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 409 | self.assertTrue(self.vty.verify("exit", [''])) |
Jacob Erlbeck | 0ae92a9 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 410 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 411 | self.assertTrue(self.vty.verify("bsc", [''])) |
| 412 | self.assertEquals(self.vty.node(), 'config-bsc') |
Jacob Erlbeck | 0ae92a9 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 413 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 414 | self.assertTrue(self.vty.verify("exit", [''])) |
Jacob Erlbeck | 0ae92a9 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 415 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 416 | self.assertTrue(self.vty.verify("exit", [''])) |
| 417 | self.assertTrue(self.vty.node() is None) |
| 418 | |
| 419 | # Check searching for outer node's commands |
| 420 | self.vty.command("configure terminal") |
| 421 | self.vty.command('msc 0') |
| 422 | self.vty.command("bsc") |
| 423 | self.assertEquals(self.vty.node(), 'config-bsc') |
| 424 | self.vty.command("msc 0") |
| 425 | self.assertEquals(self.vty.node(), 'config-msc') |
| 426 | |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 427 | def testUssdNotificationsMsc(self): |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 428 | self.vty.enable() |
| 429 | self.vty.command("configure terminal") |
| 430 | self.vty.command("msc") |
| 431 | |
| 432 | # Test invalid input |
| 433 | self.vty.verify("bsc-msc-lost-text", ['% Command incomplete.']) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 434 | self.vty.verify("bsc-welcome-text", ['% Command incomplete.']) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 435 | self.vty.verify("bsc-grace-text", ['% Command incomplete.']) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 436 | |
| 437 | # Enable USSD notifications |
| 438 | self.vty.verify("bsc-msc-lost-text MSC disconnected", ['']) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 439 | self.vty.verify("bsc-welcome-text Hello MS", ['']) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 440 | self.vty.verify("bsc-grace-text In grace period", ['']) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 441 | |
| 442 | # Verify settings |
| 443 | res = self.vty.command("write terminal") |
| 444 | self.assert_(res.find('bsc-msc-lost-text MSC disconnected') > 0) |
| 445 | self.assertEquals(res.find('no bsc-msc-lost-text'), -1) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 446 | self.assert_(res.find('bsc-welcome-text Hello MS') > 0) |
| 447 | self.assertEquals(res.find('no bsc-welcome-text'), -1) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 448 | self.assert_(res.find('bsc-grace-text In grace period') > 0) |
| 449 | self.assertEquals(res.find('no bsc-grace-text'), -1) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 450 | |
| 451 | # Now disable it.. |
| 452 | self.vty.verify("no bsc-msc-lost-text", ['']) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 453 | self.vty.verify("no bsc-welcome-text", ['']) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 454 | self.vty.verify("no bsc-grace-text", ['']) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 455 | |
| 456 | # Verify settings |
| 457 | res = self.vty.command("write terminal") |
| 458 | self.assertEquals(res.find('bsc-msc-lost-text MSC disconnected'), -1) |
| 459 | self.assert_(res.find('no bsc-msc-lost-text') > 0) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 460 | self.assertEquals(res.find('bsc-welcome-text Hello MS'), -1) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 461 | self.assert_(res.find('no bsc-welcome-text') > 0) |
| 462 | self.assertEquals(res.find('bsc-grace-text In grace period'), -1) |
| 463 | self.assert_(res.find('no bsc-grace-text') > 0) |
| 464 | |
| 465 | def testUssdNotificationsBsc(self): |
| 466 | self.vty.enable() |
| 467 | self.vty.command("configure terminal") |
| 468 | self.vty.command("bsc") |
| 469 | |
| 470 | # Test invalid input |
| 471 | self.vty.verify("missing-msc-text", ['% Command incomplete.']) |
| 472 | |
| 473 | # Enable USSD notifications |
| 474 | self.vty.verify("missing-msc-text No MSC found", ['']) |
| 475 | |
| 476 | # Verify settings |
| 477 | res = self.vty.command("write terminal") |
| 478 | self.assert_(res.find('missing-msc-text No MSC found') > 0) |
| 479 | self.assertEquals(res.find('no missing-msc-text'), -1) |
| 480 | |
| 481 | # Now disable it.. |
| 482 | self.vty.verify("no missing-msc-text", ['']) |
| 483 | |
| 484 | # Verify settings |
| 485 | res = self.vty.command("write terminal") |
| 486 | self.assertEquals(res.find('missing-msc-text No MSC found'), -1) |
| 487 | self.assert_(res.find('no missing-msc-text') > 0) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 488 | |
Jacob Erlbeck | 946d141 | 2013-09-17 13:59:29 +0200 | [diff] [blame] | 489 | def testNetworkTimezone(self): |
| 490 | self.vty.enable() |
| 491 | self.vty.verify("configure terminal", ['']) |
| 492 | self.vty.verify("network", ['']) |
| 493 | self.vty.verify("bts 0", ['']) |
| 494 | |
| 495 | # Test invalid input |
| 496 | self.vty.verify("timezone", ['% Command incomplete.']) |
| 497 | self.vty.verify("timezone 20 0", ['% Unknown command.']) |
| 498 | self.vty.verify("timezone 0 11", ['% Unknown command.']) |
| 499 | self.vty.verify("timezone 0 0 99", ['% Unknown command.']) |
| 500 | |
| 501 | # Set time zone without DST |
| 502 | self.vty.verify("timezone 2 30", ['']) |
| 503 | |
| 504 | # Verify settings |
| 505 | res = self.vty.command("write terminal") |
| 506 | self.assert_(res.find('timezone 2 30') > 0) |
| 507 | self.assertEquals(res.find('timezone 2 30 '), -1) |
| 508 | |
| 509 | # Set time zone with DST |
| 510 | self.vty.verify("timezone 2 30 1", ['']) |
| 511 | |
| 512 | # Verify settings |
| 513 | res = self.vty.command("write terminal") |
| 514 | self.assert_(res.find('timezone 2 30 1') > 0) |
| 515 | |
| 516 | # Now disable it.. |
| 517 | self.vty.verify("no timezone", ['']) |
| 518 | |
| 519 | # Verify settings |
| 520 | res = self.vty.command("write terminal") |
| 521 | self.assertEquals(res.find(' timezone'), -1) |
| 522 | |
Ciaby | ec6e4f8 | 2014-03-06 17:20:55 +0100 | [diff] [blame] | 523 | def testShowNetwork(self): |
| 524 | res = self.vty.command("show network") |
| 525 | self.assert_(res.startswith('BSC is on Country Code') >= 0) |
| 526 | |
Holger Hans Peter Freyther | db64f2e | 2014-10-29 10:06:15 +0100 | [diff] [blame] | 527 | def testPingPongConfiguration(self): |
| 528 | self.vty.enable() |
| 529 | self.vty.verify("configure terminal", ['']) |
| 530 | self.vty.verify("network", ['']) |
| 531 | self.vty.verify("msc 0", ['']) |
| 532 | |
| 533 | self.vty.verify("timeout-ping 12", ['']) |
| 534 | self.vty.verify("timeout-pong 14", ['']) |
| 535 | res = self.vty.command("show running-config") |
| 536 | self.assert_(res.find(" timeout-ping 12") > 0) |
| 537 | self.assert_(res.find(" timeout-pong 14") > 0) |
| 538 | self.assert_(res.find(" no timeout-ping advanced") > 0) |
| 539 | |
| 540 | self.vty.verify("timeout-ping advanced", ['']) |
| 541 | res = self.vty.command("show running-config") |
| 542 | self.assert_(res.find(" timeout-ping 12") > 0) |
| 543 | self.assert_(res.find(" timeout-pong 14") > 0) |
| 544 | self.assert_(res.find(" timeout-ping advanced") > 0) |
| 545 | |
| 546 | self.vty.verify("no timeout-ping advanced", ['']) |
| 547 | res = self.vty.command("show running-config") |
| 548 | self.assert_(res.find(" timeout-ping 12") > 0) |
| 549 | self.assert_(res.find(" timeout-pong 14") > 0) |
| 550 | self.assert_(res.find(" no timeout-ping advanced") > 0) |
| 551 | |
| 552 | self.vty.verify("no timeout-ping", ['']) |
| 553 | res = self.vty.command("show running-config") |
| 554 | self.assertEquals(res.find(" timeout-ping 12"), -1) |
| 555 | self.assertEquals(res.find(" timeout-pong 14"), -1) |
| 556 | self.assertEquals(res.find(" no timeout-ping advanced"), -1) |
| 557 | self.assert_(res.find(" no timeout-ping") > 0) |
| 558 | |
| 559 | self.vty.verify("timeout-ping advanced", ['%ping handling is disabled. Enable it first.']) |
| 560 | |
| 561 | # And back to enabling it |
| 562 | self.vty.verify("timeout-ping 12", ['']) |
| 563 | self.vty.verify("timeout-pong 14", ['']) |
| 564 | res = self.vty.command("show running-config") |
| 565 | self.assert_(res.find(" timeout-ping 12") > 0) |
| 566 | self.assert_(res.find(" timeout-pong 14") > 0) |
| 567 | self.assert_(res.find(" timeout-ping advanced") > 0) |
| 568 | |
Holger Hans Peter Freyther | 32dd2f3 | 2015-04-01 18:15:48 +0200 | [diff] [blame] | 569 | def testMscDataCoreLACCI(self): |
| 570 | self.vty.enable() |
| 571 | res = self.vty.command("show running-config") |
| 572 | self.assertEquals(res.find("core-location-area-code"), -1) |
| 573 | self.assertEquals(res.find("core-cell-identity"), -1) |
| 574 | |
| 575 | self.vty.command("configure terminal") |
| 576 | self.vty.command("msc 0") |
| 577 | self.vty.command("core-location-area-code 666") |
| 578 | self.vty.command("core-cell-identity 333") |
| 579 | |
| 580 | res = self.vty.command("show running-config") |
| 581 | self.assert_(res.find("core-location-area-code 666") > 0) |
| 582 | self.assert_(res.find("core-cell-identity 333") > 0) |
| 583 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 584 | class TestVTYNAT(TestVTYGenericBSC): |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 585 | |
| 586 | def vty_command(self): |
| 587 | return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-c", |
| 588 | "doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"] |
| 589 | |
| 590 | def vty_app(self): |
| 591 | return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat") |
| 592 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 593 | def testVtyTree(self): |
| 594 | self.vty.enable() |
| 595 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 596 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 597 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 598 | self.assertTrue(self.vty.verify('mgcp', [''])) |
| 599 | self.assertEquals(self.vty.node(), 'config-mgcp') |
| 600 | self.checkForEndAndExit() |
| 601 | self.assertTrue(self.vty.verify('exit', [''])) |
| 602 | self.assertEquals(self.vty.node(), 'config') |
| 603 | self.assertTrue(self.vty.verify('nat', [''])) |
| 604 | self.assertEquals(self.vty.node(), 'config-nat') |
| 605 | self.checkForEndAndExit() |
| 606 | self.assertTrue(self.vty.verify('bsc 0', [''])) |
| 607 | self.assertEquals(self.vty.node(), 'config-nat-bsc') |
| 608 | self.checkForEndAndExit() |
| 609 | self.assertTrue(self.vty.verify('exit', [''])) |
| 610 | self.assertEquals(self.vty.node(), 'config-nat') |
| 611 | self.assertTrue(self.vty.verify('exit', [''])) |
| 612 | self.assertEquals(self.vty.node(), 'config') |
| 613 | self.assertTrue(self.vty.verify('exit', [''])) |
| 614 | self.assertTrue(self.vty.node() is None) |
| 615 | |
| 616 | # Check searching for outer node's commands |
| 617 | self.vty.command('configure terminal') |
| 618 | self.vty.command('mgcp') |
| 619 | self.vty.command('nat') |
| 620 | self.assertEquals(self.vty.node(), 'config-nat') |
Jacob Erlbeck | 4c9dff5 | 2013-09-02 13:17:17 +0200 | [diff] [blame] | 621 | self.vty.command('mgcp') |
| 622 | self.assertEquals(self.vty.node(), 'config-mgcp') |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 623 | self.vty.command('nat') |
| 624 | self.assertEquals(self.vty.node(), 'config-nat') |
| 625 | self.vty.command('bsc 0') |
Jacob Erlbeck | 4c9dff5 | 2013-09-02 13:17:17 +0200 | [diff] [blame] | 626 | self.vty.command('mgcp') |
| 627 | self.assertEquals(self.vty.node(), 'config-mgcp') |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 628 | |
Holger Hans Peter Freyther | b718ad3 | 2013-06-25 09:08:02 +0200 | [diff] [blame] | 629 | def testRewriteNoRewrite(self): |
| 630 | self.vty.enable() |
| 631 | res = self.vty.command("configure terminal") |
| 632 | res = self.vty.command("nat") |
| 633 | res = self.vty.command("number-rewrite rewrite.cfg") |
| 634 | res = self.vty.command("no number-rewrite") |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 635 | |
Holger Hans Peter Freyther | 7f100c9 | 2015-04-23 20:25:17 -0400 | [diff] [blame] | 636 | def testEnsureNoEnsureModeSet(self): |
| 637 | self.vty.enable() |
| 638 | res = self.vty.command("configure terminal") |
| 639 | res = self.vty.command("nat") |
| 640 | |
| 641 | # Ensure the default |
| 642 | res = self.vty.command("show running-config") |
| 643 | self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0) |
| 644 | |
| 645 | self.vty.command("sdp-ensure-amr-mode-set") |
| 646 | res = self.vty.command("show running-config") |
| 647 | self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0) |
| 648 | |
| 649 | self.vty.command("no sdp-ensure-amr-mode-set") |
| 650 | res = self.vty.command("show running-config") |
| 651 | self.assert_(res.find('\n no sdp-ensure-amr-mode-set') > 0) |
| 652 | |
Holger Hans Peter Freyther | 67e423c | 2013-06-25 15:38:31 +0200 | [diff] [blame] | 653 | def testRewritePostNoRewrite(self): |
| 654 | self.vty.enable() |
| 655 | self.vty.command("configure terminal") |
| 656 | self.vty.command("nat") |
| 657 | self.vty.verify("number-rewrite-post rewrite.cfg", ['']) |
| 658 | self.vty.verify("no number-rewrite-post", ['']) |
| 659 | |
| 660 | |
Holger Hans Peter Freyther | ddf191e | 2013-06-25 11:44:01 +0200 | [diff] [blame] | 661 | def testPrefixTreeLoading(self): |
| 662 | cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv") |
| 663 | |
| 664 | self.vty.enable() |
| 665 | self.vty.command("configure terminal") |
| 666 | self.vty.command("nat") |
| 667 | res = self.vty.command("prefix-tree %s" % cfg) |
| 668 | self.assertEqual(res, "% prefix-tree loaded 17 rules.") |
| 669 | self.vty.command("end") |
| 670 | |
| 671 | res = self.vty.command("show prefix-tree") |
| 672 | 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') |
| 673 | |
| 674 | self.vty.command("configure terminal") |
| 675 | self.vty.command("nat") |
| 676 | self.vty.command("no prefix-tree") |
| 677 | self.vty.command("end") |
| 678 | |
| 679 | res = self.vty.command("show prefix-tree") |
| 680 | self.assertEqual(res, "% there is now prefix tree loaded.") |
| 681 | |
Jacob Erlbeck | 6cb2ccc | 2013-08-14 11:10:34 +0200 | [diff] [blame] | 682 | def testUssdSideChannelProvider(self): |
| 683 | self.vty.command("end") |
| 684 | self.vty.enable() |
| 685 | self.vty.command("configure terminal") |
| 686 | self.vty.command("nat") |
| 687 | self.vty.command("ussd-token key") |
| 688 | self.vty.command("end") |
| 689 | |
| 690 | res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.']) |
| 691 | self.assertTrue(res) |
| 692 | |
| 693 | ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 694 | ussdSocket.connect(('127.0.0.1', 5001)) |
| 695 | ussdSocket.settimeout(2.0) |
| 696 | print "Connected to %s:%d" % ussdSocket.getpeername() |
| 697 | |
| 698 | print "Expecting ID_GET request" |
| 699 | data = ussdSocket.recv(4) |
| 700 | self.assertEqual(data, "\x00\x01\xfe\x04") |
| 701 | |
| 702 | print "Going to send ID_RESP response" |
| 703 | res = ussdSocket.send("\x00\x07\xfe\x05\x00\x04\x01\x6b\x65\x79") |
| 704 | self.assertEqual(res, 10) |
| 705 | |
| 706 | # initiating PING/PONG cycle to know, that the ID_RESP message has been processed |
| 707 | |
| 708 | print "Going to send PING request" |
| 709 | res = ussdSocket.send("\x00\x01\xfe\x00") |
| 710 | self.assertEqual(res, 4) |
| 711 | |
| 712 | print "Expecting PONG response" |
| 713 | data = ussdSocket.recv(4) |
| 714 | self.assertEqual(data, "\x00\x01\xfe\x01") |
| 715 | |
| 716 | res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.']) |
| 717 | self.assertTrue(res) |
| 718 | |
| 719 | print "Going to shut down connection" |
| 720 | ussdSocket.shutdown(socket.SHUT_WR) |
| 721 | |
| 722 | print "Expecting EOF" |
| 723 | data = ussdSocket.recv(4) |
| 724 | self.assertEqual(data, "") |
| 725 | |
| 726 | ussdSocket.close() |
| 727 | |
| 728 | res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.']) |
| 729 | self.assertTrue(res) |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 730 | |
Holger Hans Peter Freyther | 6419018 | 2014-01-20 10:14:05 +0100 | [diff] [blame] | 731 | def testAccessList(self): |
| 732 | """ |
| 733 | Verify that the imsi-deny can have a reject cause or no reject cause |
| 734 | """ |
| 735 | self.vty.enable() |
| 736 | self.vty.command("configure terminal") |
| 737 | self.vty.command("nat") |
| 738 | |
| 739 | # Old default |
| 740 | self.vty.command("access-list test-default imsi-deny ^123[0-9]*$") |
| 741 | res = self.vty.command("show running-config").split("\r\n") |
| 742 | asserted = False |
| 743 | for line in res: |
Holger Hans Peter Freyther | 4ecc687 | 2014-03-04 15:38:00 +0100 | [diff] [blame] | 744 | if line.startswith(" access-list test-default"): |
Holger Hans Peter Freyther | 6419018 | 2014-01-20 10:14:05 +0100 | [diff] [blame] | 745 | self.assertEqual(line, " access-list test-default imsi-deny ^123[0-9]*$ 11 11") |
| 746 | asserted = True |
| 747 | self.assert_(asserted) |
| 748 | |
| 749 | # Check the optional CM Service Reject Cause |
| 750 | self.vty.command("access-list test-cm-deny imsi-deny ^123[0-9]*$ 42").split("\r\n") |
| 751 | res = self.vty.command("show running-config").split("\r\n") |
| 752 | asserted = False |
| 753 | for line in res: |
| 754 | if line.startswith(" access-list test-cm"): |
| 755 | self.assertEqual(line, " access-list test-cm-deny imsi-deny ^123[0-9]*$ 42 11") |
| 756 | asserted = True |
| 757 | self.assert_(asserted) |
| 758 | |
| 759 | # Check the optional LU Reject Cause |
| 760 | self.vty.command("access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42").split("\r\n") |
| 761 | res = self.vty.command("show running-config").split("\r\n") |
| 762 | asserted = False |
| 763 | for line in res: |
| 764 | if line.startswith(" access-list test-lu"): |
| 765 | self.assertEqual(line, " access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42") |
| 766 | asserted = True |
| 767 | self.assert_(asserted) |
| 768 | |
Jacob Erlbeck | 6d23371 | 2013-10-23 11:24:15 +0200 | [diff] [blame] | 769 | class TestVTYGbproxy(TestVTYGenericBSC): |
| 770 | |
| 771 | def vty_command(self): |
| 772 | return ["./src/gprs/osmo-gbproxy", "-c", |
| 773 | "doc/examples/osmo-gbproxy/osmo-gbproxy.cfg"] |
| 774 | |
| 775 | def vty_app(self): |
| 776 | return (4246, "./src/gprs/osmo-gbproxy", "OsmoGbProxy", "bsc") |
| 777 | |
| 778 | def testVtyTree(self): |
| 779 | self.vty.enable() |
| 780 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 781 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 782 | self.checkForEndAndExit() |
Jacob Erlbeck | 6d23371 | 2013-10-23 11:24:15 +0200 | [diff] [blame] | 783 | self.assertTrue(self.vty.verify('ns', [''])) |
| 784 | self.assertEquals(self.vty.node(), 'config-ns') |
| 785 | self.checkForEndAndExit() |
| 786 | self.assertTrue(self.vty.verify('exit', [''])) |
| 787 | self.assertEquals(self.vty.node(), 'config') |
| 788 | self.assertTrue(self.vty.verify('gbproxy', [''])) |
| 789 | self.assertEquals(self.vty.node(), 'config-gbproxy') |
| 790 | self.checkForEndAndExit() |
| 791 | self.assertTrue(self.vty.verify('exit', [''])) |
| 792 | self.assertEquals(self.vty.node(), 'config') |
| 793 | |
| 794 | def testVtyShow(self): |
| 795 | res = self.vty.command("show ns") |
| 796 | self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0) |
| 797 | |
| 798 | res = self.vty.command("show gbproxy stats") |
| 799 | self.assert_(res.find('GBProxy Global Statistics') >= 0) |
| 800 | |
Jacob Erlbeck | 4211d79 | 2013-10-24 12:48:23 +0200 | [diff] [blame] | 801 | def testVtyDeletePeer(self): |
| 802 | self.vty.enable() |
| 803 | self.assertTrue(self.vty.verify('delete-gbproxy-peer 9999 bvci 7777', ['BVC not found'])) |
| 804 | res = self.vty.command("delete-gbproxy-peer 9999 all dry-run") |
| 805 | self.assert_(res.find('Not Deleted 0 BVC') >= 0) |
| 806 | self.assert_(res.find('Not Deleted 0 NS-VC') >= 0) |
| 807 | res = self.vty.command("delete-gbproxy-peer 9999 only-bvc dry-run") |
| 808 | self.assert_(res.find('Not Deleted 0 BVC') >= 0) |
| 809 | self.assert_(res.find('Not Deleted 0 NS-VC') < 0) |
| 810 | res = self.vty.command("delete-gbproxy-peer 9999 only-nsvc dry-run") |
| 811 | self.assert_(res.find('Not Deleted 0 BVC') < 0) |
| 812 | self.assert_(res.find('Not Deleted 0 NS-VC') >= 0) |
| 813 | res = self.vty.command("delete-gbproxy-peer 9999 all") |
| 814 | self.assert_(res.find('Deleted 0 BVC') >= 0) |
| 815 | self.assert_(res.find('Deleted 0 NS-VC') >= 0) |
| 816 | |
Jacob Erlbeck | 144b8b1 | 2014-11-04 11:15:01 +0100 | [diff] [blame] | 817 | class TestVTYSGSN(TestVTYGenericBSC): |
| 818 | |
| 819 | def vty_command(self): |
| 820 | return ["./src/gprs/osmo-sgsn", "-c", |
| 821 | "doc/examples/osmo-sgsn/osmo-sgsn.cfg"] |
| 822 | |
| 823 | def vty_app(self): |
| 824 | return (4245, "./src/gprs/osmo-sgsn", "OsmoSGSN", "sgsn") |
| 825 | |
| 826 | def testVtyTree(self): |
| 827 | self.vty.enable() |
| 828 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 829 | self.assertEquals(self.vty.node(), 'config') |
| 830 | self.checkForEndAndExit() |
| 831 | self.assertTrue(self.vty.verify('ns', [''])) |
| 832 | self.assertEquals(self.vty.node(), 'config-ns') |
| 833 | self.checkForEndAndExit() |
| 834 | self.assertTrue(self.vty.verify('exit', [''])) |
| 835 | self.assertEquals(self.vty.node(), 'config') |
| 836 | self.assertTrue(self.vty.verify('sgsn', [''])) |
| 837 | self.assertEquals(self.vty.node(), 'config-sgsn') |
| 838 | self.checkForEndAndExit() |
| 839 | self.assertTrue(self.vty.verify('exit', [''])) |
| 840 | self.assertEquals(self.vty.node(), 'config') |
| 841 | |
| 842 | def testVtyShow(self): |
| 843 | res = self.vty.command("show ns") |
| 844 | self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0) |
| 845 | self.assertTrue(self.vty.verify('show bssgp', [''])) |
| 846 | self.assertTrue(self.vty.verify('show bssgp stats', [''])) |
| 847 | # TODO: uncomment when the command does not segfault anymore |
| 848 | # self.assertTrue(self.vty.verify('show bssgp nsei 123', [''])) |
| 849 | # self.assertTrue(self.vty.verify('show bssgp nsei 123 stats', [''])) |
| 850 | |
| 851 | self.assertTrue(self.vty.verify('show sgsn', [''])) |
| 852 | self.assertTrue(self.vty.verify('show mm-context all', [''])) |
| 853 | self.assertTrue(self.vty.verify('show mm-context imsi 000001234567', ['No MM context for IMSI 000001234567'])) |
| 854 | self.assertTrue(self.vty.verify('show pdp-context all', [''])) |
| 855 | |
| 856 | res = self.vty.command("show sndcp") |
| 857 | self.assert_(res.find('State of SNDCP Entities') >= 0) |
| 858 | |
| 859 | res = self.vty.command("show llc") |
| 860 | self.assert_(res.find('State of LLC Entities') >= 0) |
| 861 | |
Jacob Erlbeck | 106f547 | 2014-11-04 10:08:37 +0100 | [diff] [blame] | 862 | def testVtyAuth(self): |
| 863 | self.vty.enable() |
| 864 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 865 | self.assertEquals(self.vty.node(), 'config') |
| 866 | self.assertTrue(self.vty.verify('sgsn', [''])) |
| 867 | self.assertEquals(self.vty.node(), 'config-sgsn') |
| 868 | self.assertTrue(self.vty.verify('auth-policy accept-all', [''])) |
| 869 | res = self.vty.command("show running-config") |
| 870 | self.assert_(res.find('auth-policy accept-all') > 0) |
| 871 | self.assertTrue(self.vty.verify('auth-policy acl-only', [''])) |
| 872 | res = self.vty.command("show running-config") |
| 873 | self.assert_(res.find('auth-policy acl-only') > 0) |
| 874 | self.assertTrue(self.vty.verify('auth-policy closed', [''])) |
| 875 | res = self.vty.command("show running-config") |
| 876 | self.assert_(res.find('auth-policy closed') > 0) |
Jacob Erlbeck | be2c8d9 | 2014-11-12 10:18:09 +0100 | [diff] [blame] | 877 | self.assertTrue(self.vty.verify('auth-policy remote', [''])) |
| 878 | res = self.vty.command("show running-config") |
| 879 | self.assert_(res.find('auth-policy remote') > 0) |
Jacob Erlbeck | 106f547 | 2014-11-04 10:08:37 +0100 | [diff] [blame] | 880 | |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 881 | def testVtySubscriber(self): |
| 882 | self.vty.enable() |
| 883 | res = self.vty.command('show subscriber cache') |
| 884 | self.assert_(res.find('1234567890') < 0) |
Jacob Erlbeck | d919343 | 2015-01-19 14:11:46 +0100 | [diff] [blame] | 885 | self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 create', [''])) |
| 886 | res = self.vty.command('show subscriber cache') |
| 887 | self.assert_(res.find('1234567890') >= 0) |
| 888 | self.assert_(res.find('Authorized: 0') >= 0) |
| 889 | 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] | 890 | res = self.vty.command('show subscriber cache') |
| 891 | self.assert_(res.find('1234567890') >= 0) |
| 892 | self.assert_(res.find('Authorized: 1') >= 0) |
Jacob Erlbeck | 8000e0e | 2015-01-27 14:56:40 +0100 | [diff] [blame] | 893 | self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 cancel update-procedure', [''])) |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 894 | res = self.vty.command('show subscriber cache') |
Jacob Erlbeck | e988ae4 | 2015-01-27 12:41:19 +0100 | [diff] [blame] | 895 | self.assert_(res.find('1234567890') >= 0) |
| 896 | self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 destroy', [''])) |
| 897 | res = self.vty.command('show subscriber cache') |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 898 | self.assert_(res.find('1234567890') < 0) |
| 899 | |
Jacob Erlbeck | cb1db8b | 2015-02-03 13:47:53 +0100 | [diff] [blame] | 900 | def testVtyGgsn(self): |
| 901 | self.vty.enable() |
| 902 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 903 | self.assertEquals(self.vty.node(), 'config') |
| 904 | self.assertTrue(self.vty.verify('sgsn', [''])) |
| 905 | self.assertEquals(self.vty.node(), 'config-sgsn') |
| 906 | self.assertTrue(self.vty.verify('ggsn 0 remote-ip 127.99.99.99', [''])) |
| 907 | self.assertTrue(self.vty.verify('ggsn 0 gtp-version 1', [''])) |
| 908 | self.assertTrue(self.vty.verify('apn * ggsn 0', [''])) |
| 909 | self.assertTrue(self.vty.verify('apn apn1.test ggsn 0', [''])) |
| 910 | self.assertTrue(self.vty.verify('apn apn1.test ggsn 1', ['% a GGSN with id 1 has not been defined'])) |
| 911 | self.assertTrue(self.vty.verify('apn apn1.test imsi-prefix 123456 ggsn 0', [''])) |
| 912 | self.assertTrue(self.vty.verify('apn apn2.test imsi-prefix 123456 ggsn 0', [''])) |
| 913 | res = self.vty.command("show running-config") |
| 914 | self.assert_(res.find('ggsn 0 remote-ip 127.99.99.99') >= 0) |
| 915 | self.assert_(res.find('ggsn 0 gtp-version 1') >= 0) |
| 916 | self.assert_(res.find('apn * ggsn 0') >= 0) |
| 917 | self.assert_(res.find('apn apn1.test ggsn 0') >= 0) |
| 918 | self.assert_(res.find('apn apn1.test imsi-prefix 123456 ggsn 0') >= 0) |
| 919 | self.assert_(res.find('apn apn2.test imsi-prefix 123456 ggsn 0') >= 0) |
| 920 | |
Holger Hans Peter Freyther | 9c20a5f | 2015-02-06 16:23:29 +0100 | [diff] [blame] | 921 | def testVtyEasyAPN(self): |
| 922 | self.vty.enable() |
| 923 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 924 | self.assertEquals(self.vty.node(), 'config') |
| 925 | self.assertTrue(self.vty.verify('sgsn', [''])) |
| 926 | self.assertEquals(self.vty.node(), 'config-sgsn') |
| 927 | |
| 928 | res = self.vty.command("show running-config") |
| 929 | self.assertEquals(res.find("apn internet"), -1) |
| 930 | |
| 931 | self.assertTrue(self.vty.verify("access-point-name internet.apn", [''])) |
| 932 | res = self.vty.command("show running-config") |
| 933 | self.assert_(res.find("apn internet.apn ggsn 0") >= 0) |
| 934 | |
| 935 | self.assertTrue(self.vty.verify("no access-point-name internet.apn", [''])) |
| 936 | res = self.vty.command("show running-config") |
| 937 | self.assertEquals(res.find("apn internet"), -1) |
| 938 | |
Holger Hans Peter Freyther | c15c61c | 2015-05-06 17:46:08 +0200 | [diff] [blame] | 939 | def testVtyCDR(self): |
| 940 | self.vty.enable() |
| 941 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 942 | self.assertEquals(self.vty.node(), 'config') |
| 943 | self.assertTrue(self.vty.verify('sgsn', [''])) |
| 944 | self.assertEquals(self.vty.node(), 'config-sgsn') |
| 945 | |
| 946 | res = self.vty.command("show running-config") |
| 947 | self.assert_(res.find("no cdr filename") > 0) |
| 948 | |
| 949 | self.vty.command("cdr filename bla.cdr") |
| 950 | res = self.vty.command("show running-config") |
| 951 | self.assertEquals(res.find("no cdr filename"), -1) |
| 952 | self.assert_(res.find(" cdr filename bla.cdr") > 0) |
| 953 | |
| 954 | self.vty.command("no cdr filename") |
| 955 | res = self.vty.command("show running-config") |
| 956 | self.assert_(res.find("no cdr filename") > 0) |
| 957 | self.assertEquals(res.find(" cdr filename bla.cdr"), -1) |
| 958 | |
| 959 | res = self.vty.command("show running-config") |
| 960 | self.assert_(res.find(" cdr interval 600") > 0) |
| 961 | |
| 962 | self.vty.command("cdr interval 900") |
| 963 | res = self.vty.command("show running-config") |
| 964 | self.assert_(res.find(" cdr interval 900") > 0) |
| 965 | self.assertEquals(res.find(" cdr interval 600"), -1) |
| 966 | |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 967 | def add_nat_test(suite, workdir): |
| 968 | if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")): |
| 969 | print("Skipping the NAT test") |
| 970 | return |
| 971 | test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT) |
| 972 | suite.addTest(test) |
| 973 | |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 974 | def add_bsc_test(suite, workdir): |
| 975 | if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")): |
| 976 | print("Skipping the BSC test") |
| 977 | return |
| 978 | test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC) |
| 979 | suite.addTest(test) |
| 980 | |
Jacob Erlbeck | 6d23371 | 2013-10-23 11:24:15 +0200 | [diff] [blame] | 981 | def add_gbproxy_test(suite, workdir): |
| 982 | if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-gbproxy")): |
| 983 | print("Skipping the Gb-Proxy test") |
| 984 | return |
| 985 | test = unittest.TestLoader().loadTestsFromTestCase(TestVTYGbproxy) |
| 986 | suite.addTest(test) |
| 987 | |
Jacob Erlbeck | 144b8b1 | 2014-11-04 11:15:01 +0100 | [diff] [blame] | 988 | def add_sgsn_test(suite, workdir): |
| 989 | if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-sgsn")): |
| 990 | print("Skipping the SGSN test") |
| 991 | return |
| 992 | test = unittest.TestLoader().loadTestsFromTestCase(TestVTYSGSN) |
| 993 | suite.addTest(test) |
| 994 | |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 995 | if __name__ == '__main__': |
| 996 | import argparse |
| 997 | import sys |
| 998 | |
| 999 | workdir = '.' |
| 1000 | |
| 1001 | parser = argparse.ArgumentParser() |
| 1002 | parser.add_argument("-v", "--verbose", dest="verbose", |
| 1003 | action="store_true", help="verbose mode") |
| 1004 | parser.add_argument("-p", "--pythonconfpath", dest="p", |
| 1005 | help="searchpath for config") |
| 1006 | parser.add_argument("-w", "--workdir", dest="w", |
| 1007 | help="Working directory") |
| 1008 | args = parser.parse_args() |
| 1009 | |
| 1010 | verbose_level = 1 |
| 1011 | if args.verbose: |
| 1012 | verbose_level = 2 |
| 1013 | |
| 1014 | if args.w: |
| 1015 | workdir = args.w |
| 1016 | |
| 1017 | if args.p: |
| 1018 | confpath = args.p |
| 1019 | |
| 1020 | print "confpath %s, workdir %s" % (confpath, workdir) |
| 1021 | os.chdir(workdir) |
| 1022 | print "Running tests for specific VTY commands" |
| 1023 | suite = unittest.TestSuite() |
Holger Hans Peter Freyther | 8d998a7 | 2014-07-04 20:23:56 +0200 | [diff] [blame] | 1024 | suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYMGCP)) |
Holger Hans Peter Freyther | c63f6f1 | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 1025 | suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB)) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 1026 | add_bsc_test(suite, workdir) |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 1027 | add_nat_test(suite, workdir) |
Jacob Erlbeck | 6d23371 | 2013-10-23 11:24:15 +0200 | [diff] [blame] | 1028 | add_gbproxy_test(suite, workdir) |
Jacob Erlbeck | 144b8b1 | 2014-11-04 11:15:01 +0100 | [diff] [blame] | 1029 | add_sgsn_test(suite, workdir) |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 1030 | res = unittest.TextTestRunner(verbosity=verbose_level).run(suite) |
| 1031 | sys.exit(len(res.errors) + len(res.failures)) |