Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 1 | """ |
| 2 | Copyright 2015 Open Networking Foundation (ONF) |
| 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 7 | |
| 8 | TestON is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | TestON is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | """ |
pingping-lin | 26990f0 | 2015-11-30 15:48:06 -0800 | [diff] [blame] | 21 | |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 22 | def checkRouteNum( main, routeNumExpected, ONOScli="ONOScli1" ): |
| 23 | import time |
pingping-lin | 26990f0 | 2015-11-30 15:48:06 -0800 | [diff] [blame] | 24 | main.step( "Check routes installed" ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 25 | wait = int( main.params['timers']['PathAvailable'] ) |
pingping-lin | 26990f0 | 2015-11-30 15:48:06 -0800 | [diff] [blame] | 26 | main.log.info( "Route number expected:" ) |
| 27 | main.log.info( routeNumExpected ) |
| 28 | main.log.info( "Route number from ONOS CLI:" ) |
| 29 | |
| 30 | if ONOScli == "ONOScli1": |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 31 | cli = main.ONOScli1 |
pingping-lin | 26990f0 | 2015-11-30 15:48:06 -0800 | [diff] [blame] | 32 | else: |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 33 | cli = main.ONOScli2 |
| 34 | routeNumActual = cli.ipv4RouteNumber() |
| 35 | if routeNumActual != routeNumExpected: |
| 36 | time.sleep( wait ) |
| 37 | routeNumActual = cli.ipv4RouteNumber() |
pingping-lin | 26990f0 | 2015-11-30 15:48:06 -0800 | [diff] [blame] | 38 | |
| 39 | main.log.info( routeNumActual ) |
| 40 | utilities.assertEquals( \ |
| 41 | expect = routeNumExpected, actual = routeNumActual, |
| 42 | onpass = "Route number is correct!", |
| 43 | onfail = "Route number is wrong!" ) |
| 44 | |
| 45 | def checkM2SintentNum( main, intentNumExpected, ONOScli = "ONOScli1" ): |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 46 | import time |
pingping-lin | 26990f0 | 2015-11-30 15:48:06 -0800 | [diff] [blame] | 47 | main.step( "Check M2S intents installed" ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 48 | wait = int( main.params['timers']['PathAvailable'] ) |
pingping-lin | 26990f0 | 2015-11-30 15:48:06 -0800 | [diff] [blame] | 49 | main.log.info( "Intent number expected:" ) |
| 50 | main.log.info( intentNumExpected ) |
| 51 | main.log.info( "Intent number from ONOS CLI:" ) |
| 52 | if ONOScli == "ONOScli1": |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 53 | cli = main.ONOScli1 |
pingping-lin | 26990f0 | 2015-11-30 15:48:06 -0800 | [diff] [blame] | 54 | else: |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 55 | cli = main.ONOScli2 |
| 56 | jsonResult = cli.intents( jsonFormat = True, summary = True, |
| 57 | TYPE = "multiPointToSinglePoint" ) |
pingping-lin | 26990f0 | 2015-11-30 15:48:06 -0800 | [diff] [blame] | 58 | intentNumActual = jsonResult['installed'] |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 59 | if intentNumActual != intentNumExpected: |
| 60 | time.sleep( wait ) |
| 61 | jsonResult = cli.intents( jsonFormat = True, summary = True, |
| 62 | TYPE = "multiPointToSinglePoint" ) |
| 63 | intentNumActual = jsonResult['installed'] |
pingping-lin | 26990f0 | 2015-11-30 15:48:06 -0800 | [diff] [blame] | 64 | main.log.info( intentNumActual ) |
| 65 | utilities.assertEquals( \ |
| 66 | expect = intentNumExpected, actual = intentNumActual, |
| 67 | onpass = "M2S intent number is correct!", |
| 68 | onfail = "M2S intent number is wrong!" ) |
| 69 | |
| 70 | def checkP2PintentNum( main, intentNumExpected, ONOScli = "ONOScli1" ): |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 71 | import time |
pingping-lin | 26990f0 | 2015-11-30 15:48:06 -0800 | [diff] [blame] | 72 | main.step( "Check P2P intents installed" ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 73 | wait = int( main.params['timers']['PathAvailable'] ) |
pingping-lin | 26990f0 | 2015-11-30 15:48:06 -0800 | [diff] [blame] | 74 | main.log.info( "Intent number expected:" ) |
| 75 | main.log.info( intentNumExpected ) |
| 76 | main.log.info( "Intent number from ONOS CLI:" ) |
| 77 | if ONOScli == "ONOScli1": |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 78 | cli = main.ONOScli1 |
pingping-lin | 26990f0 | 2015-11-30 15:48:06 -0800 | [diff] [blame] | 79 | else: |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 80 | cli = main.ONOScli2 |
| 81 | jsonResult = cli.intents( jsonFormat = True, summary = True, |
| 82 | TYPE = "pointToPoint" ) |
pingping-lin | 26990f0 | 2015-11-30 15:48:06 -0800 | [diff] [blame] | 83 | intentNumActual = jsonResult['installed'] |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 84 | |
| 85 | if intentNumActual != intentNumExpected: |
| 86 | time.sleep( wait ) |
| 87 | jsonResult = cli.intents( jsonFormat = True, summary = True, |
| 88 | TYPE = "pointToPoint" ) |
| 89 | intentNumActual = jsonResult['installed'] |
pingping-lin | 26990f0 | 2015-11-30 15:48:06 -0800 | [diff] [blame] | 90 | main.log.info( intentNumActual ) |
| 91 | utilities.assertEquals( \ |
| 92 | expect = intentNumExpected, actual = intentNumActual, |
| 93 | onpass = "P2P intent number is correct!", |
| 94 | onfail = "P2P intent number is wrong!" ) |
| 95 | |
| 96 | def checkFlowNum( main, switch, flowNumExpected ): |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 97 | import time |
pingping-lin | 26990f0 | 2015-11-30 15:48:06 -0800 | [diff] [blame] | 98 | main.step( "Check flow entry number in " + switch ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 99 | wait = int( main.params['timers']['PathAvailable'] ) |
pingping-lin | 26990f0 | 2015-11-30 15:48:06 -0800 | [diff] [blame] | 100 | main.log.info( "Flow number expected:" ) |
| 101 | main.log.info( flowNumExpected ) |
| 102 | main.log.info( "Flow number actual:" ) |
| 103 | flowNumActual = main.Mininet.getSwitchFlowCount( switch ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 104 | if flowNumActual != flowNumExpected : |
| 105 | time.sleep( wait ) |
| 106 | flowNumActual = main.Mininet.getSwitchFlowCount( switch ) |
pingping-lin | 26990f0 | 2015-11-30 15:48:06 -0800 | [diff] [blame] | 107 | main.log.info( flowNumActual ) |
| 108 | utilities.assertEquals( \ |
| 109 | expect = flowNumExpected, actual = flowNumActual, |
| 110 | onpass = "Flow number in " + switch + " is correct!", |
| 111 | onfail = "Flow number in " + switch + " is wrong!" ) |
| 112 | |
| 113 | |
| 114 | def pingSpeakerToPeer( main, speakers = ["speaker1"], |
pingping-lin | 1477663 | 2015-12-16 12:05:30 -0800 | [diff] [blame] | 115 | peers = ["pr64514", "pr64515", "pr64516"], |
pingping-lin | 26990f0 | 2015-11-30 15:48:06 -0800 | [diff] [blame] | 116 | expectAllSuccess = True ): |
| 117 | """ |
| 118 | Carry out ping test between each BGP speaker and peer pair |
| 119 | Optional argument: |
| 120 | * speakers - BGP speakers |
| 121 | * peers - BGP peers |
| 122 | * expectAllSuccess - boolean indicating if you expect all results |
| 123 | succeed if True, otherwise expect all results fail if False |
| 124 | """ |
| 125 | if len( speakers ) == 0: |
| 126 | main.log.error( "Parameter speakers can not be empty." ) |
| 127 | main.cleanup() |
| 128 | main.exit() |
| 129 | if len( peers ) == 0: |
| 130 | main.log.error( "Parameter speakers can not be empty." ) |
| 131 | main.cleanup() |
| 132 | main.exit() |
| 133 | |
| 134 | if expectAllSuccess: |
| 135 | main.step( "BGP speakers ping peers, expect all tests to succeed" ) |
| 136 | else: |
| 137 | main.step( "BGP speakers ping peers, expect all tests to fail" ) |
| 138 | |
| 139 | result = True |
| 140 | if expectAllSuccess: |
| 141 | for speaker in speakers: |
| 142 | for peer in peers: |
| 143 | tmpResult = main.Mininet.pingHost( src = speaker, |
| 144 | target = peer ) |
| 145 | result = result and ( tmpResult == main.TRUE ) |
| 146 | else: |
| 147 | for speaker in speakers: |
| 148 | for peer in peers: |
| 149 | tmpResult = main.Mininet.pingHost( src = speaker, |
| 150 | target = peer ) |
| 151 | |
| 152 | utilities.assert_equals( expect = True, actual = result, |
| 153 | onpass = "Ping test results are expected", |
| 154 | onfail = "Ping test results are Not expected" ) |
| 155 | |
| 156 | if result == False: |
| 157 | main.cleanup() |
| 158 | main.exit() |
| 159 | |
| 160 | |
| 161 | def pingHostToHost( main, hosts = ["host64514", "host64515", "host64516"], |
| 162 | expectAllSuccess = True ): |
| 163 | """ |
| 164 | Carry out ping test between each BGP host pair |
| 165 | Optional argument: |
| 166 | * hosts - hosts behind BGP peer routers |
| 167 | * expectAllSuccess - boolean indicating if you expect all results |
| 168 | succeed if True, otherwise expect all results fail if False |
| 169 | """ |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 170 | main.step( "Check ping between each host pair, expect all to succede=" + |
| 171 | str( expectAllSuccess ) ) |
pingping-lin | 26990f0 | 2015-11-30 15:48:06 -0800 | [diff] [blame] | 172 | if len( hosts ) == 0: |
| 173 | main.log.error( "Parameter hosts can not be empty." ) |
| 174 | main.cleanup() |
| 175 | main.exit() |
| 176 | |
| 177 | result = True |
| 178 | if expectAllSuccess: |
| 179 | for srcHost in hosts: |
| 180 | for targetHost in hosts: |
| 181 | if srcHost != targetHost: |
| 182 | tmpResult = main.Mininet.pingHost( src = srcHost, |
| 183 | target = targetHost ) |
| 184 | result = result and ( tmpResult == main.TRUE ) |
| 185 | else: |
| 186 | for srcHost in hosts: |
| 187 | for targetHost in hosts: |
| 188 | if srcHost != targetHost: |
| 189 | tmpResult = main.Mininet.pingHost( src = srcHost, |
| 190 | target = targetHost ) |
| 191 | result = result and ( tmpResult == main.FALSE ) |
| 192 | |
| 193 | utilities.assert_equals( expect = True, actual = result, |
| 194 | onpass = "Ping test results are expected", |
| 195 | onfail = "Ping test results are Not expected" ) |
| 196 | |
| 197 | ''' |
| 198 | if result == False: |
| 199 | main.cleanup() |
| 200 | main.exit() |
| 201 | ''' |
| 202 | |
| 203 | |
| 204 | def setupTunnel( main, srcIp, srcPort, dstIp, dstPort ): |
| 205 | """ |
| 206 | Create a tunnel from Mininet host to host outside Mininet |
| 207 | """ |
| 208 | main.step( "Set up tunnel from Mininet node " + |
| 209 | str( srcIp ) + ":" + str( srcPort ) + " to ONOS node " |
| 210 | + str(dstIp) + ":" + str(dstPort) ) |
| 211 | forwarding = '%s:%s:%s:%s' % ( srcIp, srcPort, dstIp, dstPort ) |
| 212 | command = 'ssh -nNT -o "PasswordAuthentication no" \ |
| 213 | -o "StrictHostKeyChecking no" -l sdn -L %s %s & ' % ( forwarding, dstIp ) |
| 214 | |
| 215 | |
| 216 | tunnelResult = main.TRUE |
| 217 | tunnelResult = main.Mininet.node( "root", command ) |
| 218 | utilities.assert_equals( expect = True, |
| 219 | actual = ( "PasswordAuthentication" in tunnelResult ), |
| 220 | onpass = "Created tunnel succeeded", |
| 221 | onfail = "Create tunnel failed" ) |
| 222 | if ( "PasswordAuthentication" not in tunnelResult ) : |
| 223 | main.cleanup() |
| 224 | main.exit() |
| 225 | |