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 | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 21 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 22 | def checkRouteNum( main, routeNumExpected, node=1 ): |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 23 | import time |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [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 | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 26 | main.log.info( "Route number expected:" ) |
| 27 | main.log.info( routeNumExpected ) |
| 28 | main.log.info( "Route number from ONOS CLI:" ) |
| 29 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 30 | cli = main.Cluster.active( node - 1 ).CLI |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 31 | routeNumActual = cli.ipv4RouteNumber() |
| 32 | if routeNumActual != routeNumExpected: |
| 33 | time.sleep( wait ) |
| 34 | routeNumActual = cli.ipv4RouteNumber() |
pingping-lin | a14c7c8 | 2015-10-09 15:44:36 -0700 | [diff] [blame] | 35 | |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 36 | main.log.info( routeNumActual ) |
| 37 | utilities.assertEquals( \ |
| 38 | expect = routeNumExpected, actual = routeNumActual, |
| 39 | onpass = "Route number is correct!", |
| 40 | onfail = "Route number is wrong!" ) |
| 41 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 42 | def checkM2SintentNum( main, intentNumExpected, node=1 ): |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 43 | import time |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 44 | main.step( "Check M2S intents installed" ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 45 | wait = int( main.params['timers']['PathAvailable'] ) |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 46 | main.log.info( "Intent number expected:" ) |
| 47 | main.log.info( intentNumExpected ) |
| 48 | main.log.info( "Intent number from ONOS CLI:" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 49 | cli = main.Cluster.active( node - 1 ).CLI |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 50 | jsonResult = cli.intents( jsonFormat = True, summary = True, |
| 51 | TYPE = "multiPointToSinglePoint" ) |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 52 | intentNumActual = jsonResult['installed'] |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 53 | if intentNumActual != intentNumExpected: |
| 54 | time.sleep( wait ) |
| 55 | jsonResult = cli.intents( jsonFormat = True, summary = True, |
| 56 | TYPE = "multiPointToSinglePoint" ) |
| 57 | intentNumActual = jsonResult['installed'] |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 58 | main.log.info( intentNumActual ) |
| 59 | utilities.assertEquals( \ |
| 60 | expect = intentNumExpected, actual = intentNumActual, |
| 61 | onpass = "M2S intent number is correct!", |
| 62 | onfail = "M2S intent number is wrong!" ) |
| 63 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 64 | def checkP2PintentNum( main, intentNumExpected, node=1 ): |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 65 | import time |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 66 | main.step( "Check P2P intents installed" ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 67 | wait = int( main.params['timers']['PathAvailable'] ) |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 68 | main.log.info( "Intent number expected:" ) |
| 69 | main.log.info( intentNumExpected ) |
| 70 | main.log.info( "Intent number from ONOS CLI:" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 71 | cli = main.Cluster.active( node - 1 ).CLI |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 72 | jsonResult = cli.intents( jsonFormat = True, summary = True, |
| 73 | TYPE = "pointToPoint" ) |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 74 | intentNumActual = jsonResult['installed'] |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 75 | |
| 76 | if intentNumActual != intentNumExpected: |
| 77 | time.sleep( wait ) |
| 78 | jsonResult = cli.intents( jsonFormat = True, summary = True, |
| 79 | TYPE = "pointToPoint" ) |
| 80 | intentNumActual = jsonResult['installed'] |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 81 | main.log.info( intentNumActual ) |
| 82 | utilities.assertEquals( \ |
| 83 | expect = intentNumExpected, actual = intentNumActual, |
| 84 | onpass = "P2P intent number is correct!", |
| 85 | onfail = "P2P intent number is wrong!" ) |
| 86 | |
| 87 | def checkFlowNum( main, switch, flowNumExpected ): |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 88 | import time |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 89 | main.step( "Check flow entry number in " + switch ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 90 | wait = int( main.params['timers']['PathAvailable'] ) |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 91 | main.log.info( "Flow number expected:" ) |
| 92 | main.log.info( flowNumExpected ) |
| 93 | main.log.info( "Flow number actual:" ) |
| 94 | flowNumActual = main.Mininet.getSwitchFlowCount( switch ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 95 | if flowNumActual != flowNumExpected : |
| 96 | time.sleep( wait ) |
| 97 | flowNumActual = main.Mininet.getSwitchFlowCount( switch ) |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 98 | main.log.info( flowNumActual ) |
| 99 | utilities.assertEquals( \ |
| 100 | expect = flowNumExpected, actual = flowNumActual, |
| 101 | onpass = "Flow number in " + switch + " is correct!", |
| 102 | onfail = "Flow number in " + switch + " is wrong!" ) |
| 103 | |
| 104 | |
alison | 62006dd | 2016-12-15 16:21:28 -0800 | [diff] [blame] | 105 | def pingSpeakerToPeer( main, speakers = ["spk1"], |
| 106 | peers = ["p64514", "p64515", "p64516"], |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 107 | expectAllSuccess = True ): |
| 108 | """ |
| 109 | Carry out ping test between each BGP speaker and peer pair |
| 110 | Optional argument: |
| 111 | * speakers - BGP speakers |
| 112 | * peers - BGP peers |
| 113 | * expectAllSuccess - boolean indicating if you expect all results |
| 114 | succeed if True, otherwise expect all results fail if False |
| 115 | """ |
| 116 | if len( speakers ) == 0: |
| 117 | main.log.error( "Parameter speakers can not be empty." ) |
| 118 | main.cleanup() |
| 119 | main.exit() |
| 120 | if len( peers ) == 0: |
| 121 | main.log.error( "Parameter speakers can not be empty." ) |
| 122 | main.cleanup() |
| 123 | main.exit() |
| 124 | |
| 125 | if expectAllSuccess: |
| 126 | main.step( "BGP speakers ping peers, expect all tests to succeed" ) |
| 127 | else: |
| 128 | main.step( "BGP speakers ping peers, expect all tests to fail" ) |
| 129 | |
| 130 | result = True |
| 131 | if expectAllSuccess: |
| 132 | for speaker in speakers: |
| 133 | for peer in peers: |
| 134 | tmpResult = main.Mininet.pingHost( src = speaker, |
| 135 | target = peer ) |
| 136 | result = result and ( tmpResult == main.TRUE ) |
| 137 | else: |
| 138 | for speaker in speakers: |
| 139 | for peer in peers: |
| 140 | tmpResult = main.Mininet.pingHost( src = speaker, |
| 141 | target = peer ) |
| 142 | |
| 143 | utilities.assert_equals( expect = True, actual = result, |
| 144 | onpass = "Ping test results are expected", |
| 145 | onfail = "Ping test results are Not expected" ) |
| 146 | |
| 147 | if result == False: |
| 148 | main.cleanup() |
| 149 | main.exit() |
| 150 | |
| 151 | |
alison | 62006dd | 2016-12-15 16:21:28 -0800 | [diff] [blame] | 152 | def pingHostToHost( main, hosts = ["h64514", "h64515", "h64516"], |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 153 | expectAllSuccess = True ): |
| 154 | """ |
| 155 | Carry out ping test between each BGP host pair |
| 156 | Optional argument: |
| 157 | * hosts - hosts behind BGP peer routers |
| 158 | * expectAllSuccess - boolean indicating if you expect all results |
| 159 | succeed if True, otherwise expect all results fail if False |
| 160 | """ |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 161 | main.step( "Check ping between each host pair, expect all to succede=" + |
| 162 | str( expectAllSuccess ) ) |
pingping-lin | ea32cf8 | 2015-10-08 22:37:37 -0700 | [diff] [blame] | 163 | if len( hosts ) == 0: |
| 164 | main.log.error( "Parameter hosts can not be empty." ) |
| 165 | main.cleanup() |
| 166 | main.exit() |
| 167 | |
| 168 | result = True |
| 169 | if expectAllSuccess: |
| 170 | for srcHost in hosts: |
| 171 | for targetHost in hosts: |
| 172 | if srcHost != targetHost: |
| 173 | tmpResult = main.Mininet.pingHost( src = srcHost, |
| 174 | target = targetHost ) |
| 175 | result = result and ( tmpResult == main.TRUE ) |
| 176 | else: |
| 177 | for srcHost in hosts: |
| 178 | for targetHost in hosts: |
| 179 | if srcHost != targetHost: |
| 180 | tmpResult = main.Mininet.pingHost( src = srcHost, |
| 181 | target = targetHost ) |
| 182 | result = result and ( tmpResult == main.FALSE ) |
| 183 | |
| 184 | utilities.assert_equals( expect = True, actual = result, |
| 185 | onpass = "Ping test results are expected", |
| 186 | onfail = "Ping test results are Not expected" ) |
| 187 | |
| 188 | ''' |
| 189 | if result == False: |
| 190 | main.cleanup() |
| 191 | main.exit() |
| 192 | ''' |
| 193 | |
| 194 | |
| 195 | def setupTunnel( main, srcIp, srcPort, dstIp, dstPort ): |
| 196 | """ |
| 197 | Create a tunnel from Mininet host to host outside Mininet |
| 198 | """ |
| 199 | main.step( "Set up tunnel from Mininet node " + |
| 200 | str( srcIp ) + ":" + str( srcPort ) + " to ONOS node " |
| 201 | + str(dstIp) + ":" + str(dstPort) ) |
| 202 | forwarding = '%s:%s:%s:%s' % ( srcIp, srcPort, dstIp, dstPort ) |
| 203 | command = 'ssh -nNT -o "PasswordAuthentication no" \ |
| 204 | -o "StrictHostKeyChecking no" -l sdn -L %s %s & ' % ( forwarding, dstIp ) |
| 205 | |
| 206 | |
| 207 | tunnelResult = main.TRUE |
| 208 | tunnelResult = main.Mininet.node( "root", command ) |
| 209 | utilities.assert_equals( expect = True, |
| 210 | actual = ( "PasswordAuthentication" in tunnelResult ), |
| 211 | onpass = "Created tunnel succeeded", |
| 212 | onfail = "Create tunnel failed" ) |
| 213 | if ( "PasswordAuthentication" not in tunnelResult ) : |
| 214 | main.cleanup() |
| 215 | main.exit() |
| 216 | |