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