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