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