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