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