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 2016 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 | """ |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 21 | import os |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 22 | import time |
| 23 | import json |
| 24 | import urllib |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 25 | import re |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 26 | from core import utilities |
| 27 | |
| 28 | |
| 29 | class Testcaselib: |
Pier | fb719b1 | 2016-09-19 14:51:44 -0700 | [diff] [blame] | 30 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 31 | useSSH = True |
Pier | fb719b1 | 2016-09-19 14:51:44 -0700 | [diff] [blame] | 32 | |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 33 | @staticmethod |
| 34 | def initTest( main ): |
| 35 | """ |
| 36 | - Construct tests variables |
| 37 | - GIT ( optional ) |
| 38 | - Checkout ONOS master branch |
| 39 | - Pull latest ONOS code |
| 40 | - Building ONOS ( optional ) |
| 41 | - Install ONOS package |
| 42 | - Build ONOS package |
| 43 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 44 | try: |
| 45 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 46 | main.testSetUp = ONOSSetup() |
| 47 | except ImportError: |
| 48 | main.log.error( "ONOSSetup not found. exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 49 | main.cleanAndExit() |
You Wang | d587348 | 2018-01-24 12:30:00 -0800 | [diff] [blame] | 50 | from tests.dependencies.Network import Network |
| 51 | main.Network = Network() |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 52 | main.testSetUp.envSetupDescription( False ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 53 | stepResult = main.FALSE |
| 54 | try: |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 55 | # Test variables |
| 56 | main.cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 57 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 58 | main.path = os.path.dirname( main.testFile ) |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 59 | main.useCommonTopo = main.params[ 'DEPENDENCY' ][ 'useCommonTopo' ] == 'True' |
| 60 | main.topoPath = main.path + ( "/.." if main.useCommonTopo else "" ) + "/dependencies/" |
| 61 | main.useCommonConf = main.params[ 'DEPENDENCY' ][ 'useCommonConf' ] == 'True' |
You Wang | 68568b1 | 2019-03-04 11:49:57 -0800 | [diff] [blame] | 62 | if main.params[ 'DEPENDENCY' ].get( 'useBmv2' ): |
| 63 | main.useBmv2 = main.params[ 'DEPENDENCY' ][ 'useBmv2' ] == 'True' |
| 64 | else: |
| 65 | main.useBmv2 = False |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 66 | main.configPath = main.path + ( "/.." if main.useCommonConf else "" ) + "/dependencies/" |
Jon Hall | bc1c1c9 | 2020-05-27 09:29:30 -0700 | [diff] [blame] | 67 | main.bmv2Path = "/tools/dev/mininet/" |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 68 | main.forJson = "json/" |
| 69 | main.forChart = "chart/" |
| 70 | main.forConfig = "conf/" |
| 71 | main.forHost = "host/" |
You Wang | 2731757 | 2018-03-06 12:13:11 -0800 | [diff] [blame] | 72 | main.forSwitchFailure = "switchFailure/" |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 73 | main.forLinkFailure = "linkFailure/" |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 74 | main.forMulticast = "multicast/" |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 75 | main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ] |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 76 | main.topologyLib = main.params[ 'DEPENDENCY' ][ 'lib' ] if 'lib' in main.params[ 'DEPENDENCY' ] else None |
| 77 | main.topologyConf = main.params[ 'DEPENDENCY' ][ 'conf' ] if 'conf' in main.params[ 'DEPENDENCY' ] else None |
You Wang | 68568b1 | 2019-03-04 11:49:57 -0800 | [diff] [blame] | 78 | main.bmv2 = "bmv2.py" |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 79 | main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 80 | main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] ) |
You Wang | 5bf4959 | 2020-07-08 18:47:46 -0700 | [diff] [blame^] | 81 | main.trellisOar = main.params[ 'DEPENDENCY' ][ 'trellisOar' ] |
| 82 | main.t3Oar = main.params[ 'DEPENDENCY' ][ 't3Oar' ] if 't3Oar' in main.params[ 'DEPENDENCY' ] else None |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 83 | |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 84 | stepResult = main.testSetUp.envSetup( False ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 85 | except Exception as e: |
| 86 | main.testSetUp.envSetupException( e ) |
Jonghwan Hyun | 3731d6a | 2017-10-19 11:59:31 -0700 | [diff] [blame] | 87 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 88 | main.testSetUp.evnSetupConclusion( stepResult ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 89 | |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 90 | @staticmethod |
Andreas Pantelopoulos | 90f0b10 | 2018-02-01 13:21:45 -0800 | [diff] [blame] | 91 | def installOnos( main, vlanCfg=True, skipPackage=False, cliSleep=10, |
| 92 | parallel=True ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 93 | """ |
| 94 | - Set up cell |
| 95 | - Create cell file |
| 96 | - Set cell file |
| 97 | - Verify cell file |
| 98 | - Kill ONOS process |
| 99 | - Uninstall ONOS cluster |
| 100 | - Verify ONOS start up |
| 101 | - Install ONOS cluster |
| 102 | - Connect to cli |
| 103 | """ |
| 104 | # main.scale[ 0 ] determines the current number of ONOS controller |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 105 | if not main.apps: |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 106 | main.log.error( "App list is empty" ) |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 107 | main.log.info( "Cluster size: " + str( main.Cluster.numCtrls ) ) |
| 108 | main.log.info( "Cluster ips: " + ', '.join( main.Cluster.getIps() ) ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 109 | main.dynamicHosts = [ 'in1', 'out1' ] |
You Wang | a0f6ff6 | 2018-01-11 15:46:30 -0800 | [diff] [blame] | 110 | main.testSetUp.ONOSSetUp( main.Cluster, newCell=True, cellName=main.cellName, |
Andreas Pantelopoulos | 90f0b10 | 2018-02-01 13:21:45 -0800 | [diff] [blame] | 111 | skipPack=skipPackage, |
| 112 | useSSH=Testcaselib.useSSH, |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 113 | installParallel=parallel, includeCaseDesc=False ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 114 | ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary, |
You Wang | 5bf4959 | 2020-07-08 18:47:46 -0700 | [diff] [blame^] | 115 | [ None, main.FALSE ], |
You Wang | 1cdc5f5 | 2017-12-19 16:47:51 -0800 | [diff] [blame] | 116 | sleep=cliSleep, |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 117 | attempts=10 ) |
| 118 | if ready: |
| 119 | ready = main.TRUE |
| 120 | utilities.assert_equals( expect=main.TRUE, actual=ready, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 121 | onpass="ONOS summary command succeded", |
| 122 | onfail="ONOS summary command failed" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 123 | if not ready: |
| 124 | main.log.error( "ONOS startup failed!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 125 | main.cleanAndExit() |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 126 | |
You Wang | 5bf4959 | 2020-07-08 18:47:46 -0700 | [diff] [blame^] | 127 | # Install segmentrouting and t3 app |
| 128 | appInstallResult = main.ONOSbench.onosAppInstall( main.Cluster.runningNodes[0].ipAddress, main.trellisOar) |
| 129 | if main.t3Oar: |
| 130 | appInstallResult = appInstallResult and main.ONOSbench.onosAppInstall( main.Cluster.runningNodes[0].ipAddress, main.t3Oar) |
| 131 | utilities.assert_equals( expect=main.TRUE, actual=appInstallResult, |
| 132 | onpass="SR app installation succeded", |
| 133 | onfail="SR app installation failed" ) |
| 134 | if not appInstallResult: |
| 135 | main.cleanAndExit() |
| 136 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 137 | for ctrl in main.Cluster.active(): |
| 138 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.segmentrouting" ) |
You Wang | f5f104f | 2018-03-30 17:09:10 -0700 | [diff] [blame] | 139 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.driver" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 140 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.net.flowobjective.impl" ) |
You Wang | f5f104f | 2018-03-30 17:09:10 -0700 | [diff] [blame] | 141 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.routeservice.impl" ) |
| 142 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.routeservice.store" ) |
| 143 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.routing.fpm" ) |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 144 | ctrl.CLI.logSet( "TRACE", "org.onosproject.events" ) |
| 145 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.mcast" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 146 | |
| 147 | @staticmethod |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 148 | def loadCount( main ): |
| 149 | with open("%s/count/%s.count" % (main.configPath, main.cfgName)) as count: |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 150 | main.count = json.load(count) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 151 | |
| 152 | @staticmethod |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 153 | def loadJson( main ): |
| 154 | with open( "%s%s.json" % ( main.configPath + main.forJson, |
| 155 | main.cfgName ) ) as cfg: |
| 156 | main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) ) |
| 157 | |
| 158 | @staticmethod |
| 159 | def loadChart( main ): |
| 160 | try: |
| 161 | with open( "%s%s.chart" % ( main.configPath + main.forChart, |
| 162 | main.cfgName ) ) as chart: |
| 163 | main.pingChart = json.load(chart) |
| 164 | except IOError: |
| 165 | main.log.warn( "No chart file found." ) |
| 166 | |
| 167 | @staticmethod |
| 168 | def loadHost( main ): |
| 169 | with open( "%s%s.host" % ( main.configPath + main.forHost, |
| 170 | main.cfgName ) ) as host: |
| 171 | main.expectedHosts = json.load( host ) |
| 172 | |
| 173 | @staticmethod |
You Wang | 2731757 | 2018-03-06 12:13:11 -0800 | [diff] [blame] | 174 | def loadSwitchFailureChart( main ): |
| 175 | with open( "%s%s.switchFailureChart" % ( main.configPath + main.forSwitchFailure, |
| 176 | main.cfgName ) ) as sfc: |
| 177 | main.switchFailureChart = json.load( sfc ) |
| 178 | |
| 179 | @staticmethod |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 180 | def loadLinkFailureChart( main ): |
| 181 | with open( "%s%s.linkFailureChart" % ( main.configPath + main.forLinkFailure, |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 182 | main.cfgName ) ) as lfc: |
| 183 | main.linkFailureChart = json.load( lfc ) |
| 184 | |
| 185 | @staticmethod |
| 186 | def loadMulticastConfig( main ): |
| 187 | with open( "%s%s.multicastConfig" % ( main.configPath + main.forMulticast, |
| 188 | main.cfgName ) ) as cfg: |
| 189 | main.multicastConfig = json.load( cfg ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 190 | |
| 191 | @staticmethod |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 192 | def startMininet( main, topology, args="" ): |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 193 | copyResult = main.ONOSbench.scp( main.Mininet1, |
| 194 | main.topoPath + main.topology, |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 195 | main.Mininet1.home + "custom", |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 196 | direction="to" ) |
| 197 | if main.topologyLib: |
| 198 | for lib in main.topologyLib.split(","): |
| 199 | copyResult = copyResult and main.ONOSbench.scp( main.Mininet1, |
| 200 | main.topoPath + lib, |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 201 | main.Mininet1.home + "custom", |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 202 | direction="to" ) |
| 203 | if main.topologyConf: |
You Wang | a877ea4 | 2018-04-05 15:27:40 -0700 | [diff] [blame] | 204 | import re |
| 205 | controllerIPs = [ ctrl.ipAddress for ctrl in main.Cluster.runningNodes ] |
| 206 | index = 0 |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 207 | for conf in main.topologyConf.split(","): |
You Wang | a877ea4 | 2018-04-05 15:27:40 -0700 | [diff] [blame] | 208 | # Update zebra configurations with correct ONOS instance IP |
| 209 | if conf in [ "zebradbgp1.conf", "zebradbgp2.conf" ]: |
| 210 | ip = controllerIPs[ index ] |
| 211 | index = ( index + 1 ) % len( controllerIPs ) |
| 212 | with open( main.configPath + main.forConfig + conf ) as f: |
| 213 | s = f.read() |
| 214 | s = re.sub( r"(fpm connection ip).*(port 2620)", r"\1 " + ip + r" \2", s ) |
| 215 | with open( main.configPath + main.forConfig + conf, "w" ) as f: |
| 216 | f.write( s ) |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 217 | copyResult = copyResult and main.ONOSbench.scp( main.Mininet1, |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 218 | main.configPath + main.forConfig + conf, |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 219 | "~/", |
| 220 | direction="to" ) |
You Wang | 68568b1 | 2019-03-04 11:49:57 -0800 | [diff] [blame] | 221 | copyResult = copyResult and main.ONOSbench.scp( main.Mininet1, |
Jon Hall | bc1c1c9 | 2020-05-27 09:29:30 -0700 | [diff] [blame] | 222 | main.ONOSbench.home + main.bmv2Path + main.bmv2, |
You Wang | 68568b1 | 2019-03-04 11:49:57 -0800 | [diff] [blame] | 223 | main.Mininet1.home + "custom", |
| 224 | direction="to" ) |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 225 | stepResult = copyResult |
| 226 | utilities.assert_equals( expect=main.TRUE, |
| 227 | actual=stepResult, |
| 228 | onpass="Successfully copied topo files", |
| 229 | onfail="Failed to copy topo files" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 230 | main.step( "Starting Mininet Topology" ) |
Jonghwan Hyun | 3731d6a | 2017-10-19 11:59:31 -0700 | [diff] [blame] | 231 | arg = "--onos-ip=%s %s" % (",".join([ctrl.ipAddress for ctrl in main.Cluster.runningNodes]), args) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 232 | main.topology = topology |
| 233 | topoResult = main.Mininet1.startNet( |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 234 | topoFile=main.Mininet1.home + "custom/" + main.topology, args=arg ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 235 | stepResult = topoResult |
| 236 | utilities.assert_equals( expect=main.TRUE, |
| 237 | actual=stepResult, |
| 238 | onpass="Successfully loaded topology", |
| 239 | onfail="Failed to load topology" ) |
| 240 | # Exit if topology did not load properly |
| 241 | if not topoResult: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 242 | main.cleanAndExit() |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 243 | |
| 244 | @staticmethod |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 245 | def connectToPhysicalNetwork( main ): |
You Wang | 84f981d | 2018-01-12 16:11:50 -0800 | [diff] [blame] | 246 | main.step( "Connecting to physical netowrk" ) |
| 247 | topoResult = main.NetworkBench.connectToNet() |
| 248 | stepResult = topoResult |
| 249 | utilities.assert_equals( expect=main.TRUE, |
| 250 | actual=stepResult, |
| 251 | onpass="Successfully loaded topology", |
| 252 | onfail="Failed to load topology" ) |
| 253 | # Exit if topology did not load properly |
| 254 | if not topoResult: |
| 255 | main.cleanAndExit() |
| 256 | |
| 257 | main.step( "Assign switches to controllers." ) |
| 258 | assignResult = main.TRUE |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 259 | switches = main.NetworkBench.getSwitches() |
| 260 | pool = [] |
| 261 | for name in switches.keys(): |
| 262 | thread = main.Thread( target=main.NetworkBench.assignSwController, |
| 263 | name="assignSwitchToController", |
| 264 | args=[ name, main.Cluster.getIps(), '6653' ] ) |
| 265 | pool.append( thread ) |
| 266 | thread.start() |
| 267 | for thread in pool: |
| 268 | thread.join( 300 ) |
| 269 | if not thread.result: |
| 270 | stepResult = main.FALSE |
You Wang | 84f981d | 2018-01-12 16:11:50 -0800 | [diff] [blame] | 271 | utilities.assert_equals( expect=main.TRUE, |
| 272 | actual=stepResult, |
| 273 | onpass="Successfully assign switches to controllers", |
| 274 | onfail="Failed to assign switches to controllers" ) |
| 275 | |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 276 | # Check devices |
| 277 | Testcaselib.checkDevices( main, switches=int( main.params[ 'TOPO' ][ 'switchNum' ] ) ) |
| 278 | time.sleep( float( main.params[ "timers" ][ "connectToNetSleep" ] ) ) |
| 279 | # Connecting to hosts that only have data plane connectivity |
| 280 | main.step( "Connecting inband hosts" ) |
| 281 | stepResult = main.Network.connectInbandHosts() |
| 282 | utilities.assert_equals( expect=main.TRUE, |
| 283 | actual=stepResult, |
| 284 | onpass="Successfully connected inband hosts", |
| 285 | onfail="Failed to connect inband hosts" ) |
| 286 | |
You Wang | 84f981d | 2018-01-12 16:11:50 -0800 | [diff] [blame] | 287 | @staticmethod |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 288 | def saveOnosDiagnostics( main ): |
| 289 | """ |
| 290 | Get onos-diags.tar.gz and save it to the log directory. |
| 291 | suffix: suffix string of the file name. E.g. onos-diags-case1.tar.gz |
| 292 | """ |
| 293 | main.log.info( "Collecting onos-diags..." ) |
| 294 | main.ONOSbench.onosDiagnostics( [ctrl.ipAddress for ctrl in main.Cluster.runningNodes], |
| 295 | main.logdir, |
| 296 | "-CASE%d" % main.CurrentTestCaseNumber ) |
| 297 | |
| 298 | @staticmethod |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 299 | def config( main, cfgName ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 300 | main.spines = [] |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 301 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 302 | main.failures = int( main.params[ 'failures' ] ) |
| 303 | main.cfgName = cfgName |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 304 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 305 | if main.cfgName == '2x2': |
| 306 | spine = {} |
| 307 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ] |
| 308 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ] |
| 309 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 310 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 311 | spine = {} |
| 312 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ] |
| 313 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ] |
| 314 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 315 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 316 | elif main.cfgName == '4x4': |
| 317 | spine = {} |
| 318 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ] |
| 319 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ] |
| 320 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 321 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 322 | spine = {} |
| 323 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ] |
| 324 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ] |
| 325 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 326 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 327 | spine = {} |
| 328 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine3' ] |
| 329 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid3' ] |
| 330 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 331 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 332 | spine = {} |
| 333 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine4' ] |
| 334 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid4' ] |
| 335 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 336 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 337 | else: |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 338 | main.log.error( "Configuration failed!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 339 | main.cleanAndExit() |
You Wang | 2731757 | 2018-03-06 12:13:11 -0800 | [diff] [blame] | 340 | |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 341 | @staticmethod |
| 342 | def addStaticOnosRoute( main, subnet, intf): |
| 343 | """ |
| 344 | Adds an ONOS static route with the use route-add command. |
| 345 | """ |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 346 | routeResult = main.Cluster.active( 0 ).addStaticRoute(subnet, intf) |
| 347 | |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 348 | @staticmethod |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 349 | def checkGroupsForBuckets( main, deviceId, subnetDict, routingTable=30 ): |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 350 | """ |
| 351 | Check number of groups for each subnet on device deviceId and matches |
| 352 | it with an expected value. subnetDict is a dictionarty containing values |
| 353 | of the type "10.0.1.0/24" : 5. |
| 354 | """ |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 355 | main.step( "Checking if number of groups for subnets in device {0} is as expected.".format( deviceId ) ) |
| 356 | groups = main.Cluster.active( 0 ).CLI.getGroups( deviceId, groupType="select" ) |
| 357 | flows = main.Cluster.active( 0 ).CLI.flows( jsonFormat=False, device=deviceId ) |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 358 | |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 359 | result = main.TRUE |
| 360 | for subnet, numberInSelect in subnetDict.iteritems(): |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 361 | for flow in flows.splitlines(): |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 362 | if "tableId={0}".format( routingTable ) in flow and subnet in flow: |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 363 | # this will match the group id that this flow entry points to, for example : |
| 364 | # 0x70000041 in flow entry which contains "deferred=[GROUP:0x70000041], transition=TABLE:60," |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 365 | groupId = re.search( r".*GROUP:(0x.*)], transition.*", flow ).groups()[0] |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 366 | count = 0 |
| 367 | for group in groups.splitlines(): |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 368 | if 'id={0}'.format( groupId ) in group: |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 369 | count += 1 |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 370 | if count - 1 != numberInSelect: |
| 371 | result = main.FALSE |
| 372 | main.log.warn( "Mismatch in number of buckets of select group, found {0}, expected {1} for subnet {2} on device {3}".format( count - 1, numberInSelect, subnet, deviceId ) ) |
| 373 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 374 | onpass="All bucket numbers are as expected", |
| 375 | onfail="Some bucket numbers are not as expected" ) |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 376 | |
| 377 | @staticmethod |
Jonghwan Hyun | 76a02b7 | 2018-01-30 16:40:48 +0900 | [diff] [blame] | 378 | def checkFlows( main, minFlowCount, tag="", dumpflows=True, sleep=10 ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 379 | main.step( |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 380 | "Check whether the flow count is bigger than %s" % minFlowCount ) |
Jonghwan Hyun | 76a02b7 | 2018-01-30 16:40:48 +0900 | [diff] [blame] | 381 | if tag == "": |
| 382 | tag = 'CASE%d' % main.CurrentTestCaseNumber |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 383 | count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowCount, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 384 | main.FALSE, |
| 385 | kwargs={ 'min': minFlowCount }, |
| 386 | attempts=10, |
You Wang | 1cdc5f5 | 2017-12-19 16:47:51 -0800 | [diff] [blame] | 387 | sleep=sleep ) |
steven30801 | eccfe21 | 2019-01-24 13:00:42 +0800 | [diff] [blame] | 388 | if count == main.FALSE: |
| 389 | count = main.Cluster.active( 0 ).CLI.checkFlowCount() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 390 | utilities.assertEquals( |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 391 | expect=True, |
steven30801 | eccfe21 | 2019-01-24 13:00:42 +0800 | [diff] [blame] | 392 | actual=( count > minFlowCount ), |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 393 | onpass="Flow count looks correct: " + str( count ), |
| 394 | onfail="Flow count looks wrong: " + str( count ) ) |
| 395 | |
| 396 | main.step( "Check whether all flow status are ADDED" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 397 | flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 398 | main.FALSE, |
| 399 | kwargs={ 'isPENDING': False }, |
Jonghwan Hyun | 98fb40a | 2018-01-04 16:16:28 -0800 | [diff] [blame] | 400 | attempts=5, |
You Wang | 1cdc5f5 | 2017-12-19 16:47:51 -0800 | [diff] [blame] | 401 | sleep=sleep ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 402 | utilities.assertEquals( |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 403 | expect=main.TRUE, |
| 404 | actual=flowCheck, |
| 405 | onpass="Flow status is correct!", |
| 406 | onfail="Flow status is wrong!" ) |
| 407 | if dumpflows: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 408 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 409 | "flows", |
| 410 | main.logdir, |
Jonghwan Hyun | 76a02b7 | 2018-01-30 16:40:48 +0900 | [diff] [blame] | 411 | tag + "_FlowsBefore" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 412 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 413 | "groups", |
| 414 | main.logdir, |
Jonghwan Hyun | 76a02b7 | 2018-01-30 16:40:48 +0900 | [diff] [blame] | 415 | tag + "_GroupsBefore" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 416 | |
| 417 | @staticmethod |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 418 | def checkDevices( main, switches, tag="", sleep=10 ): |
| 419 | main.step( |
| 420 | "Check whether the switches count is equal to %s" % switches ) |
| 421 | if tag == "": |
| 422 | tag = 'CASE%d' % main.CurrentTestCaseNumber |
| 423 | result = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
| 424 | main.FALSE, |
| 425 | kwargs={ 'numoswitch': switches}, |
| 426 | attempts=10, |
| 427 | sleep=sleep ) |
| 428 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 429 | onpass="Device up successful", |
| 430 | onfail="Failed to boot up devices?" ) |
| 431 | |
| 432 | @staticmethod |
Jonghwan Hyun | 98fb40a | 2018-01-04 16:16:28 -0800 | [diff] [blame] | 433 | def checkFlowsByDpid( main, dpid, minFlowCount, sleep=10 ): |
| 434 | main.step( |
Jonghwan Hyun | cf2345c | 2018-02-26 11:07:54 -0800 | [diff] [blame] | 435 | " Check whether the flow count of device %s is bigger than %s" % ( dpid, minFlowCount ) ) |
| 436 | count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount, |
| 437 | main.FALSE, |
| 438 | args=( dpid, minFlowCount ), |
Jonghwan Hyun | 98fb40a | 2018-01-04 16:16:28 -0800 | [diff] [blame] | 439 | attempts=5, |
| 440 | sleep=sleep ) |
steven30801 | eccfe21 | 2019-01-24 13:00:42 +0800 | [diff] [blame] | 441 | if count == main.FALSE: |
| 442 | count = main.Cluster.active( 0 ).CLI.checkFlowAddedCount( dpid ) |
Jonghwan Hyun | 98fb40a | 2018-01-04 16:16:28 -0800 | [diff] [blame] | 443 | utilities.assertEquals( |
Jonghwan Hyun | cf2345c | 2018-02-26 11:07:54 -0800 | [diff] [blame] | 444 | expect=True, |
| 445 | actual=( count > minFlowCount ), |
| 446 | onpass="Flow count looks correct: " + str( count ), |
steven30801 | eccfe21 | 2019-01-24 13:00:42 +0800 | [diff] [blame] | 447 | onfail="Flow count looks wrong: " + str( count ) ) |
Jonghwan Hyun | 98fb40a | 2018-01-04 16:16:28 -0800 | [diff] [blame] | 448 | |
| 449 | @staticmethod |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 450 | def checkFlowEqualityByDpid( main, dpid, flowCount, sleep=10 ): |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 451 | main.step( |
| 452 | " Check whether the flow count of device %s is equal to %s" % ( dpid, flowCount ) ) |
| 453 | count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount, |
| 454 | main.FALSE, |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 455 | args=( dpid, flowCount, False, 1 ), |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 456 | attempts=5, |
| 457 | sleep=sleep ) |
steven30801 | eccfe21 | 2019-01-24 13:00:42 +0800 | [diff] [blame] | 458 | if count == main.FALSE: |
| 459 | count = main.Cluster.active( 0 ).CLI.checkFlowAddedCount( dpid ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 460 | utilities.assertEquals( |
| 461 | expect=True, |
steven30801 | eccfe21 | 2019-01-24 13:00:42 +0800 | [diff] [blame] | 462 | actual=( count == flowCount ), |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 463 | onpass="Flow count looks correct: " + str( count ) , |
| 464 | onfail="Flow count looks wrong. found {}, should be {}.".format( count, flowCount ) ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 465 | |
| 466 | @staticmethod |
| 467 | def checkGroupEqualityByDpid( main, dpid, groupCount, sleep=10): |
| 468 | main.step( |
| 469 | " Check whether the group count of device %s is equal to %s" % ( dpid, groupCount ) ) |
| 470 | count = utilities.retry( main.Cluster.active( 0 ).CLI.checkGroupAddedCount, |
| 471 | main.FALSE, |
| 472 | args=( dpid, groupCount, False, 1), |
| 473 | attempts=5, |
| 474 | sleep=sleep ) |
steven30801 | eccfe21 | 2019-01-24 13:00:42 +0800 | [diff] [blame] | 475 | if count == main.FALSE: |
steven30801 | 2399797 | 2019-01-29 17:01:40 +0800 | [diff] [blame] | 476 | count = main.Cluster.active( 0 ).CLI.checkGroupAddedCount( dpid ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 477 | utilities.assertEquals( |
| 478 | expect=True, |
| 479 | actual=( count == groupCount ), |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 480 | onpass="Group count looks correct: " + str( count ) , |
| 481 | onfail="Group count looks wrong. found {}, should be {}.".format( count, groupCount ) ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 482 | |
| 483 | @staticmethod |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 484 | def checkFlowsGroupsFromFile( main ): |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 485 | |
| 486 | for dpid, values in main.count.items(): |
| 487 | flowCount = values["flows"] |
| 488 | groupCount = values["groups"] |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 489 | main.log.report( "Check flow count for dpid " + str( dpid ) + |
| 490 | ", should be " + str( flowCount ) ) |
| 491 | Testcaselib.checkFlowEqualityByDpid( main, dpid, flowCount ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 492 | |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 493 | main.log.report( "Check group count for dpid " + str( dpid ) + |
| 494 | ", should be " + str( groupCount ) ) |
| 495 | Testcaselib.checkGroupEqualityByDpid( main, dpid, groupCount ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 496 | |
| 497 | return |
| 498 | |
| 499 | @staticmethod |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 500 | def pingAll( main, tag="", dumpflows=True, acceptableFailed=0, basedOnIp=False, |
| 501 | sleep=10, retryAttempts=1, skipOnFail=False ): |
You Wang | f19d9f4 | 2018-02-23 16:34:19 -0800 | [diff] [blame] | 502 | ''' |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 503 | Verify connectivity between hosts according to the ping chart |
| 504 | acceptableFailed: max number of acceptable failed pings. |
You Wang | f19d9f4 | 2018-02-23 16:34:19 -0800 | [diff] [blame] | 505 | basedOnIp: if True, run ping or ping6 based on suffix of host names |
Jonghwan Hyun | 812c70f | 2018-02-16 16:33:16 -0800 | [diff] [blame] | 506 | retryAttempts: the number of retry ping. Only works for IPv4 hosts. |
You Wang | f19d9f4 | 2018-02-23 16:34:19 -0800 | [diff] [blame] | 507 | ''' |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 508 | main.log.report( "Check host connectivity" ) |
| 509 | main.log.debug( "Ping chart: %s" % main.pingChart ) |
Andreas Pantelopoulos | f6ed501 | 2018-02-08 21:26:01 -0800 | [diff] [blame] | 510 | if tag == "": |
| 511 | tag = 'CASE%d' % main.CurrentTestCaseNumber |
| 512 | for entry in main.pingChart.itervalues(): |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 513 | main.log.debug( "Entry in ping chart: %s" % entry ) |
| 514 | expect = entry[ 'expect' ] |
| 515 | if expect == "Unidirectional": |
| 516 | # Verify ping from each src host to each dst host |
| 517 | src = entry[ 'src' ] |
| 518 | dst = entry[ 'dst' ] |
| 519 | expect = main.TRUE |
| 520 | main.step( "Verify unidirectional connectivity from %s to %s with tag %s" % ( str( src ), str( dst ), tag ) ) |
| 521 | if basedOnIp: |
| 522 | if ("v4" in src[0]): |
| 523 | pa = main.Network.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed ) |
| 524 | utilities.assert_equals( expect=expect, actual=pa, |
| 525 | onpass="IPv4 connectivity successfully tested", |
| 526 | onfail="IPv4 connectivity failed" ) |
| 527 | if ("v6" in src[0]): |
| 528 | pa = main.Network.pingallHostsUnidirectional( src, dst, ipv6=True, acceptableFailed=acceptableFailed ) |
| 529 | utilities.assert_equals( expect=expect, actual=pa, |
| 530 | onpass="IPv6 connectivity successfully tested", |
| 531 | onfail="IPv6 connectivity failed" ) |
| 532 | else: |
| 533 | pa = main.Network.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed ) |
| 534 | utilities.assert_equals( expect=expect, actual=pa, |
| 535 | onpass="IP connectivity successfully tested", |
| 536 | onfail="IP connectivity failed" ) |
| 537 | else: |
| 538 | # Verify ping between each host pair |
| 539 | hosts = entry[ 'hosts' ] |
| 540 | try: |
| 541 | expect = main.TRUE if str(expect).lower() == 'true' else main.FALSE |
| 542 | except: |
| 543 | expect = main.FALSE |
| 544 | main.step( "Verify full connectivity for %s with tag %s" % ( str( hosts ), tag ) ) |
| 545 | if basedOnIp: |
| 546 | if ("v4" in hosts[0]): |
Jonghwan Hyun | 812c70f | 2018-02-16 16:33:16 -0800 | [diff] [blame] | 547 | pa = utilities.retry( main.Network.pingallHosts, |
| 548 | main.FALSE if expect else main.TRUE, |
| 549 | args=(hosts,), |
| 550 | attempts=retryAttempts, |
| 551 | sleep=sleep ) |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 552 | utilities.assert_equals( expect=expect, actual=pa, |
| 553 | onpass="IPv4 connectivity successfully tested", |
| 554 | onfail="IPv4 connectivity failed" ) |
| 555 | if ("v6" in hosts[0]): |
| 556 | pa = main.Network.pingIpv6Hosts( hosts, acceptableFailed=acceptableFailed ) |
| 557 | utilities.assert_equals( expect=expect, actual=pa, |
| 558 | onpass="IPv6 connectivity successfully tested", |
| 559 | onfail="IPv6 connectivity failed" ) |
| 560 | else: |
You Wang | f19d9f4 | 2018-02-23 16:34:19 -0800 | [diff] [blame] | 561 | pa = main.Network.pingallHosts( hosts ) |
| 562 | utilities.assert_equals( expect=expect, actual=pa, |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 563 | onpass="IP connectivity successfully tested", |
| 564 | onfail="IP connectivity failed" ) |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 565 | if skipOnFail and pa != expect: |
| 566 | Testcaselib.saveOnosDiagnostics( main ) |
You Wang | 24ad2f5 | 2018-04-10 10:47:12 -0700 | [diff] [blame] | 567 | Testcaselib.cleanup( main, copyKarafLog=False ) |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 568 | main.skipCase() |
Andreas Pantelopoulos | f6ed501 | 2018-02-08 21:26:01 -0800 | [diff] [blame] | 569 | |
| 570 | if dumpflows: |
| 571 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
| 572 | "flows", |
| 573 | main.logdir, |
| 574 | tag + "_FlowsOn" ) |
| 575 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
| 576 | "groups", |
| 577 | main.logdir, |
| 578 | tag + "_GroupsOn" ) |
| 579 | |
| 580 | @staticmethod |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 581 | def killLink( main, end1, end2, switches, links, sleep=None ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 582 | """ |
| 583 | end1,end2: identify the switches, ex.: 'leaf1', 'spine1' |
| 584 | switches, links: number of expected switches and links after linkDown, ex.: '4', '6' |
| 585 | Kill a link and verify ONOS can see the proper link change |
| 586 | """ |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 587 | if sleep is None: |
| 588 | sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 589 | else: |
| 590 | sleep = float( sleep ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 591 | main.step( "Kill link between %s and %s" % ( end1, end2 ) ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 592 | linkDown = main.Network.link( END1=end1, END2=end2, OPTION="down" ) |
| 593 | linkDown = linkDown and main.Network.link( END2=end1, END1=end2, OPTION="down" ) |
| 594 | # TODO: Can remove this, since in the retry we will wait anyways if topology is incorrect |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 595 | main.log.info( |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 596 | "Waiting %s seconds for link down to be discovered" % sleep ) |
| 597 | time.sleep( sleep ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 598 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 599 | main.FALSE, |
| 600 | kwargs={ 'numoswitch': switches, |
| 601 | 'numolink': links }, |
| 602 | attempts=10, |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 603 | sleep=sleep ) |
| 604 | result = topology and linkDown |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 605 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 606 | onpass="Link down successful", |
| 607 | onfail="Failed to turn off link?" ) |
| 608 | |
| 609 | @staticmethod |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 610 | def killLinkBatch( main, links, linksAfter, switches, sleep=None ): |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 611 | """ |
| 612 | links = list of links (src, dst) to bring down. |
| 613 | """ |
| 614 | |
| 615 | main.step("Killing a batch of links {0}".format(links)) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 616 | if sleep is None: |
| 617 | sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 618 | else: |
| 619 | sleep = float( sleep ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 620 | |
| 621 | for end1, end2 in links: |
| 622 | main.Network.link( END1=end1, END2=end2, OPTION="down") |
| 623 | main.Network.link( END1=end2, END2=end1, OPTION="down") |
| 624 | |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 625 | # TODO: Can remove this, since in the retry we will wait anyways if topology is incorrect |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 626 | main.log.info( |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 627 | "Waiting %s seconds for links down to be discovered" % sleep ) |
| 628 | time.sleep( sleep ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 629 | |
| 630 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
| 631 | main.FALSE, |
| 632 | kwargs={ 'numoswitch': switches, |
| 633 | 'numolink': linksAfter }, |
| 634 | attempts=10, |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 635 | sleep=sleep ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 636 | |
You Wang | 2854bce | 2018-03-30 10:15:32 -0700 | [diff] [blame] | 637 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 638 | onpass="Link batch down successful", |
| 639 | onfail="Link batch down failed" ) |
| 640 | |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 641 | @staticmethod |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 642 | def restoreLinkBatch( main, links, linksAfter, switches, sleep=None ): |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 643 | """ |
| 644 | links = list of link (src, dst) to bring up again. |
| 645 | """ |
| 646 | |
| 647 | main.step("Restoring a batch of links {0}".format(links)) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 648 | if sleep is None: |
| 649 | sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 650 | else: |
| 651 | sleep = float( sleep ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 652 | |
| 653 | for end1, end2 in links: |
| 654 | main.Network.link( END1=end1, END2=end2, OPTION="up") |
| 655 | main.Network.link( END1=end2, END2=end1, OPTION="up") |
| 656 | |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 657 | main.log.info( |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 658 | "Waiting %s seconds for links up to be discovered" % sleep ) |
| 659 | time.sleep( sleep ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 660 | |
| 661 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
| 662 | main.FALSE, |
| 663 | kwargs={ 'numoswitch': switches, |
| 664 | 'numolink': linksAfter }, |
| 665 | attempts=10, |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 666 | sleep=sleep ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 667 | |
You Wang | 2854bce | 2018-03-30 10:15:32 -0700 | [diff] [blame] | 668 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 669 | onpass="Link batch up successful", |
| 670 | onfail="Link batch up failed" ) |
| 671 | |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 672 | @staticmethod |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 673 | def disablePortBatch( main, ports, switches=None, links=None, sleep=None ): |
| 674 | """ |
| 675 | Disable a list of switch ports using 'portstate' and verify ONOS can see the proper link change |
| 676 | ports: a list of ports to disable ex. [ [ "of:0000000000000001", 1 ] ] |
| 677 | switches, links: number of expected switches and links after link change, ex.: '4', '6' |
| 678 | """ |
| 679 | if sleep is None: |
| 680 | sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 681 | else: |
| 682 | sleep = float( sleep ) |
| 683 | main.step( "Disable a batch of ports" ) |
| 684 | for dpid, port in ports: |
| 685 | main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="disable" ) |
| 686 | main.log.info( "Waiting {} seconds for port down to be discovered".format( sleep ) ) |
| 687 | time.sleep( sleep ) |
| 688 | if switches and links: |
| 689 | result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches, |
| 690 | numolink=links ) |
| 691 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 692 | onpass="Port down successful", |
| 693 | onfail="Port down failed" ) |
| 694 | |
| 695 | @staticmethod |
| 696 | def enablePortBatch( main, ports, switches, links, sleep=None ): |
| 697 | """ |
| 698 | Enable a list of switch ports using 'portstate' and verify ONOS can see the proper link change |
| 699 | ports: a list of ports to enable ex. [ [ "of:0000000000000001", 1 ] ] |
| 700 | switches, links: number of expected switches and links after link change, ex.: '4', '6' |
| 701 | """ |
| 702 | if sleep is None: |
| 703 | sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 704 | else: |
| 705 | sleep = float( sleep ) |
| 706 | main.step( "Enable a batch of ports" ) |
| 707 | for dpid, port in ports: |
| 708 | main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="enable" ) |
| 709 | main.log.info( "Waiting {} seconds for port up to be discovered".format( sleep ) ) |
| 710 | time.sleep( sleep ) |
| 711 | if switches and links: |
| 712 | result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches, |
| 713 | numolink=links ) |
| 714 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 715 | onpass="Port up successful", |
| 716 | onfail="Port up failed" ) |
| 717 | |
| 718 | @staticmethod |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 719 | def restoreLink( main, end1, end2, switches, links, |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 720 | portUp=False, dpid1='', dpid2='', port1='', port2='', sleep=None ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 721 | """ |
| 722 | Params: |
| 723 | end1,end2: identify the end switches, ex.: 'leaf1', 'spine1' |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 724 | portUp: enable portstate after restoring link |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 725 | dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002' |
| 726 | port1, port2: respective port of the end switches that connects to the link, ex.:'1' |
| 727 | switches, links: number of expected switches and links after linkDown, ex.: '4', '6' |
| 728 | Kill a link and verify ONOS can see the proper link change |
| 729 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 730 | main.step( "Restore link between %s and %s" % ( end1, end2 ) ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 731 | if sleep is None: |
| 732 | sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 733 | else: |
| 734 | sleep = float( sleep ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 735 | result = False |
| 736 | count = 0 |
| 737 | while True: |
| 738 | count += 1 |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 739 | ctrl = main.Cluster.next() |
You Wang | d587348 | 2018-01-24 12:30:00 -0800 | [diff] [blame] | 740 | main.Network.link( END1=end1, END2=end2, OPTION="up" ) |
| 741 | main.Network.link( END2=end1, END1=end2, OPTION="up" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 742 | main.log.info( |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 743 | "Waiting %s seconds for link up to be discovered" % sleep ) |
| 744 | time.sleep( sleep ) |
Pier | fb719b1 | 2016-09-19 14:51:44 -0700 | [diff] [blame] | 745 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 746 | if portUp: |
| 747 | ctrl.CLI.portstate( dpid=dpid1, port=port1, state='Enable' ) |
| 748 | ctrl.CLI.portstate( dpid=dpid2, port=port2, state='Enable' ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 749 | time.sleep( sleep ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 750 | |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 751 | result = ctrl.CLI.checkStatus( numoswitch=switches, |
| 752 | numolink=links ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 753 | if count > 5 or result: |
| 754 | break |
| 755 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 756 | onpass="Link up successful", |
| 757 | onfail="Failed to bring link up" ) |
| 758 | |
| 759 | @staticmethod |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 760 | def killSwitch( main, switch, switches, links, sleep=None ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 761 | """ |
| 762 | Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6' |
| 763 | Completely kill a switch and verify ONOS can see the proper change |
| 764 | """ |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 765 | if sleep is None: |
| 766 | sleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
| 767 | else: |
| 768 | sleep = float( sleep ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 769 | switch = switch if isinstance( switch, list ) else [ switch ] |
| 770 | main.step( "Kill " + str( switch ) ) |
| 771 | for s in switch: |
| 772 | main.log.info( "Stopping " + s ) |
| 773 | main.Network.switch( SW=s, OPTION="stop" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 774 | # todo make this repeatable |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 775 | |
| 776 | # TODO: Can remove this, since in the retry we will wait anyways if topology is incorrect |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 777 | main.log.info( "Waiting %s seconds for switch down to be discovered" % ( |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 778 | sleep ) ) |
| 779 | time.sleep( sleep ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 780 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 781 | main.FALSE, |
| 782 | kwargs={ 'numoswitch': switches, |
| 783 | 'numolink': links }, |
| 784 | attempts=10, |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 785 | sleep=sleep ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 786 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 787 | onpass="Kill switch successful", |
| 788 | onfail="Failed to kill switch?" ) |
| 789 | |
| 790 | @staticmethod |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 791 | def recoverSwitch( main, switch, switches, links, rediscoverHosts=False, hostsToDiscover=[], sleep=None ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 792 | """ |
| 793 | Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6' |
| 794 | Recover a switch and verify ONOS can see the proper change |
| 795 | """ |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 796 | if sleep is None: |
| 797 | sleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
| 798 | else: |
| 799 | sleep = float( sleep ) |
| 800 | # TODO make this repeatable |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 801 | switch = switch if isinstance( switch, list ) else [ switch ] |
| 802 | main.step( "Recovering " + str( switch ) ) |
| 803 | for s in switch: |
| 804 | main.log.info( "Starting " + s ) |
| 805 | main.Network.switch( SW=s, OPTION="start" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 806 | main.log.info( "Waiting %s seconds for switch up to be discovered" % ( |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 807 | sleep ) ) |
| 808 | time.sleep( sleep ) |
Andreas Pantelopoulos | 74c7ff2 | 2018-05-01 15:42:02 -0700 | [diff] [blame] | 809 | if rediscoverHosts: |
You Wang | 4838175 | 2018-05-07 13:50:57 -0700 | [diff] [blame] | 810 | main.Network.discoverHosts( hostList=hostsToDiscover ) |
Andreas Pantelopoulos | 74c7ff2 | 2018-05-01 15:42:02 -0700 | [diff] [blame] | 811 | main.log.info( "Waiting %s seconds for hosts to get re-discovered" % ( |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 812 | sleep ) ) |
| 813 | time.sleep( sleep ) |
Andreas Pantelopoulos | 74c7ff2 | 2018-05-01 15:42:02 -0700 | [diff] [blame] | 814 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 815 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 816 | main.FALSE, |
| 817 | kwargs={ 'numoswitch': switches, |
| 818 | 'numolink': links }, |
| 819 | attempts=10, |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 820 | sleep=sleep ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 821 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 822 | onpass="Switch recovery successful", |
| 823 | onfail="Failed to recover switch?" ) |
| 824 | |
Jonghwan Hyun | 25c98a6 | 2018-05-04 13:59:09 -0700 | [diff] [blame] | 825 | @staticmethod |
You Wang | 0f745de | 2018-07-27 15:49:22 -0700 | [diff] [blame] | 826 | def killRouter( main, router, sleep=None ): |
| 827 | """ |
| 828 | Kill bgpd process on a quagga router |
| 829 | router: name of the router to be killed. E.g. "bgp1" |
| 830 | """ |
| 831 | sleep = float( sleep ) |
| 832 | main.step( "Kill " + str( router ) ) |
| 833 | if hasattr( main, 'Mininet1' ): |
| 834 | main.Mininet1.handle.sendline( "px {}.stopProtocols()".format( router ) ) |
| 835 | main.Mininet1.handle.expect( "mininet>" ) |
| 836 | else: |
| 837 | # TODO: support killing router in physical network |
| 838 | pass |
| 839 | main.log.info( "Waiting %s seconds for router down to be discovered" % ( sleep ) ) |
| 840 | time.sleep( sleep ) |
| 841 | |
| 842 | @staticmethod |
| 843 | def recoverRouter( main, router, sleep=None ): |
| 844 | """ |
| 845 | Restart bgpd process on a quagga router |
| 846 | router: name of the router to be recovered. E.g. "bgp1" |
| 847 | """ |
| 848 | sleep = float( sleep ) |
| 849 | main.step( "Recovering " + str( router ) ) |
| 850 | if hasattr( main, 'Mininet1' ): |
| 851 | main.Mininet1.handle.sendline( "px {}.startProtocols()".format( router ) ) |
| 852 | main.Mininet1.handle.expect( "mininet>" ) |
| 853 | else: |
| 854 | # TODO: support recovering router in physical network |
| 855 | pass |
| 856 | main.log.info( "Waiting %s seconds for router up to be discovered" % ( sleep ) ) |
| 857 | time.sleep( sleep ) |
| 858 | |
| 859 | @staticmethod |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 860 | def cleanup( main, copyKarafLog=True, removeHostComponent=False ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 861 | """ |
| 862 | Stop Onos-cluster. |
| 863 | Stops Mininet |
| 864 | Copies ONOS log |
| 865 | """ |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 866 | from tests.dependencies.utils import Utils |
| 867 | main.utils = Utils() |
| 868 | # Clean up scapy hosts |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 869 | if hasattr( main, "scapyHosts" ): |
| 870 | scapyResult = main.TRUE |
| 871 | for host in main.scapyHosts: |
| 872 | scapyResult = host.stopScapy() and scapyResult |
| 873 | main.log.info( "Stopped Scapy Host: {0}".format( host.name ) ) |
| 874 | for host in main.scapyHosts: |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 875 | if hasattr( main, 'Mininet1' ): |
| 876 | scapyResult = main.Scapy.removeHostComponent( host.name ) and scapyResult |
| 877 | else: |
| 878 | scapyResult = main.Network.removeHostComponent( host.name ) and scapyResult |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 879 | main.log.info( "Removed Scapy Host Component: {0}".format( host.name ) ) |
| 880 | main.scapyHosts = [] |
| 881 | |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 882 | if removeHostComponent: |
| 883 | for host in main.internalIpv4Hosts + main.internalIpv6Hosts + main.externalIpv4Hosts + main.externalIpv6Hosts: |
| 884 | if hasattr( main, host ): |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 885 | if hasattr( main, 'Mininet1' ): |
| 886 | pass |
| 887 | else: |
| 888 | getattr( main, host ).disconnectInband() |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 889 | main.Network.removeHostComponent( host ) |
| 890 | |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 891 | if hasattr( main, 'Mininet1' ): |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 892 | main.utils.mininetCleanup( main.Mininet1 ) |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 893 | else: |
| 894 | main.Network.disconnectInbandHosts() |
| 895 | main.Network.disconnectFromNet() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 896 | |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 897 | if copyKarafLog: |
| 898 | main.utils.copyKarafLog( "CASE%d" % main.CurrentTestCaseNumber, before=True, includeCaseDesc=False ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 899 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 900 | for ctrl in main.Cluster.active(): |
| 901 | main.ONOSbench.onosStop( ctrl.ipAddress ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 902 | |
| 903 | @staticmethod |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 904 | def verifyNodes( main ): |
| 905 | """ |
| 906 | Verifies Each active node in the cluster has an accurate view of other node's and their status |
| 907 | |
| 908 | Params: |
| 909 | nodes, integer array with position of the ONOS nodes in the CLIs array |
| 910 | """ |
| 911 | nodeResults = utilities.retry( main.Cluster.nodesCheck, |
| 912 | False, |
| 913 | attempts=10, |
| 914 | sleep=10 ) |
| 915 | utilities.assert_equals( expect=True, actual=nodeResults, |
| 916 | onpass="Nodes check successful", |
| 917 | onfail="Nodes check NOT successful" ) |
| 918 | |
| 919 | if not nodeResults: |
| 920 | for ctrl in main.Cluster.runningNodes: |
| 921 | main.log.debug( "{} components not ACTIVE: \n{}".format( |
| 922 | ctrl.name, |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 923 | ctrl.CLI.sendline( "onos:scr-list | grep -v ACTIVE" ) ) ) |
You Wang | 0bed593 | 2018-12-11 14:45:41 -0800 | [diff] [blame] | 924 | main.log.error( "Failed to verify nodes, stopping test" ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 925 | main.cleanAndExit() |
| 926 | |
| 927 | @staticmethod |
| 928 | def verifyTopology( main, switches, links, expNodes ): |
| 929 | """ |
| 930 | Verifies that the ONOS cluster has an acuurate view of the topology |
| 931 | |
| 932 | Params: |
| 933 | switches, links, expNodes: number of expected switches, links, and nodes at this point in the test ex.: '4', '6', '2' |
| 934 | """ |
| 935 | main.step( "Check number of topology elements" ) |
| 936 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
| 937 | main.FALSE, |
| 938 | kwargs={ 'numoswitch': switches, |
| 939 | 'numolink': links, |
| 940 | 'numoctrl': expNodes }, |
| 941 | attempts=10, |
| 942 | sleep=12 ) |
| 943 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 944 | onpass="Number of topology elements are correct", |
| 945 | onfail="Unexpected number of links, switches, and/or controllers" ) |
| 946 | |
| 947 | @staticmethod |
| 948 | def killOnos( main, nodes, switches, links, expNodes, sleep=None ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 949 | """ |
| 950 | Params: nodes, integer array with position of the ONOS nodes in the CLIs array |
| 951 | switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6' |
| 952 | Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change |
| 953 | """ |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 954 | # TODO: We have enough information in the Cluster instance to remove expNodes from here and verifyTopology |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 955 | main.step( "Killing ONOS instances with index(es): {}".format( nodes ) ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 956 | if sleep is None: |
| 957 | sleep = float( main.params[ 'timers' ][ 'OnosDiscovery' ] ) |
| 958 | else: |
| 959 | sleep = float( sleep ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 960 | |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 961 | for i in nodes: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 962 | killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 963 | utilities.assert_equals( expect=main.TRUE, actual=killResult, |
| 964 | onpass="ONOS instance Killed", |
| 965 | onfail="Error killing ONOS instance" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 966 | main.Cluster.runningNodes[ i ].active = False |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 967 | main.Cluster.reset() |
| 968 | time.sleep( sleep ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 969 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 970 | if len( nodes ) < main.Cluster.numCtrls: |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 971 | Testcaselib.verifyNodes( main ) |
| 972 | Testcaselib.verifyTopology( main, switches, links, expNodes ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 973 | |
| 974 | @staticmethod |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 975 | def recoverOnos( main, nodes, switches, links, expNodes, sleep=None ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 976 | """ |
| 977 | Params: nodes, integer array with position of the ONOS nodes in the CLIs array |
| 978 | switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6' |
| 979 | Recover an ONOS instance and verify the ONOS cluster can see the proper change |
| 980 | """ |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 981 | main.step( "Recovering ONOS instances with index(es): {}".format( nodes ) ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 982 | if sleep is None: |
| 983 | sleep = float( main.params[ 'timers' ][ 'OnosDiscovery' ] ) |
| 984 | else: |
| 985 | sleep = float( sleep ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 986 | [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ] |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 987 | time.sleep( sleep ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 988 | for i in nodes: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 989 | isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 990 | utilities.assert_equals( expect=main.TRUE, actual=isUp, |
| 991 | onpass="ONOS service is ready", |
| 992 | onfail="ONOS service did not start properly" ) |
| 993 | for i in nodes: |
| 994 | main.step( "Checking if ONOS CLI is ready" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 995 | ctrl = main.Cluster.runningNodes[ i ] |
Jonghwan Hyun | 76a02b7 | 2018-01-30 16:40:48 +0900 | [diff] [blame] | 996 | # ctrl.CLI.startCellCli() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 997 | cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress, |
| 998 | commandlineTimeout=60, |
| 999 | onosStartTimeout=100 ) |
| 1000 | ctrl.active = True |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1001 | utilities.assert_equals( expect=main.TRUE, |
| 1002 | actual=cliResult, |
| 1003 | onpass="ONOS CLI is ready", |
| 1004 | onfail="ONOS CLI is not ready" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1005 | |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1006 | main.Cluster.reset() |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 1007 | main.step( "Checking ONOS nodes" ) |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1008 | Testcaselib.verifyNodes( main ) |
| 1009 | Testcaselib.verifyTopology( main, switches, links, expNodes ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 1010 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1011 | ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary, |
You Wang | 5bf4959 | 2020-07-08 18:47:46 -0700 | [diff] [blame^] | 1012 | [ None, main.FALSE ], |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1013 | attempts=10, |
| 1014 | sleep=12 ) |
| 1015 | if ready: |
| 1016 | ready = main.TRUE |
| 1017 | utilities.assert_equals( expect=main.TRUE, actual=ready, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1018 | onpass="ONOS summary command succeded", |
| 1019 | onfail="ONOS summary command failed" ) |
| 1020 | if not ready: |
| 1021 | main.log.error( "ONOS startup failed!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1022 | main.cleanAndExit() |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1023 | |
| 1024 | @staticmethod |
| 1025 | def addHostCfg( main ): |
| 1026 | """ |
| 1027 | Adds Host Configuration to ONOS |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1028 | Updates expected state of the network ( pingChart ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1029 | """ |
| 1030 | import json |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1031 | hostCfg = {} |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 1032 | with open( main.configPath + main.forJson + "extra.json" ) as template: |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1033 | hostCfg = json.load( template ) |
| 1034 | main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ] |
| 1035 | main.step( "Pushing new configuration" ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1036 | mac, cfg = hostCfg[ 'hosts' ].popitem() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1037 | main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ], |
| 1038 | subjectClass="hosts", |
| 1039 | subjectKey=urllib.quote( mac, |
| 1040 | safe='' ), |
| 1041 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1042 | main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ] |
| 1043 | main.step( "Pushing new configuration" ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1044 | mac, cfg = hostCfg[ 'hosts' ].popitem() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1045 | main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ], |
| 1046 | subjectClass="hosts", |
| 1047 | subjectKey=urllib.quote( mac, |
| 1048 | safe='' ), |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1049 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1050 | main.pingChart.update( { 'vlan1': { "expect": "True", |
| 1051 | "hosts": [ "olt1", "vsg1" ] } } ) |
| 1052 | main.pingChart[ 'vlan5' ][ 'expect' ] = 0 |
| 1053 | main.pingChart[ 'vlan10' ][ 'expect' ] = 0 |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1054 | ports = "[%s,%s]" % ( 5, 6 ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1055 | cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1056 | main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ), |
| 1057 | subjectClass="apps", |
| 1058 | subjectKey="org.onosproject.segmentrouting", |
| 1059 | configKey="xconnect" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1060 | |
| 1061 | @staticmethod |
| 1062 | def delHostCfg( main ): |
| 1063 | """ |
| 1064 | Removest Host Configuration from ONOS |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1065 | Updates expected state of the network ( pingChart ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1066 | """ |
| 1067 | import json |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1068 | hostCfg = {} |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 1069 | with open( main.configPath + main.forJson + "extra.json" ) as template: |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1070 | hostCfg = json.load( template ) |
| 1071 | main.step( "Removing host configuration" ) |
| 1072 | main.pingChart[ 'ip' ][ 'expect' ] = 0 |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1073 | mac, cfg = hostCfg[ 'hosts' ].popitem() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1074 | main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts", |
| 1075 | subjectKey=urllib.quote( |
| 1076 | mac, |
| 1077 | safe='' ), |
| 1078 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1079 | main.step( "Removing configuration" ) |
| 1080 | main.pingChart[ 'ip' ][ 'expect' ] = 0 |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1081 | mac, cfg = hostCfg[ 'hosts' ].popitem() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1082 | main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts", |
| 1083 | subjectKey=urllib.quote( |
| 1084 | mac, |
| 1085 | safe='' ), |
| 1086 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 1087 | main.step( "Removing vlan configuration" ) |
| 1088 | main.pingChart[ 'vlan1' ][ 'expect' ] = 0 |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1089 | main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps", |
| 1090 | subjectKey="org.onosproject.segmentrouting", |
| 1091 | configKey="xconnect" ) |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1092 | |
| 1093 | @staticmethod |
| 1094 | def verifyNetworkHostIp( main, attempts=10, sleep=10 ): |
| 1095 | """ |
| 1096 | Verifies IP address assignment from the hosts |
| 1097 | """ |
| 1098 | main.step( "Verify IP address assignment from hosts" ) |
| 1099 | ipResult = main.TRUE |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 1100 | main.Network.update() |
You Wang | 6acb7a4 | 2018-05-04 15:12:25 -0700 | [diff] [blame] | 1101 | # Find out names of disconnected hosts |
| 1102 | disconnectedHosts = [] |
| 1103 | if hasattr( main, "disconnectedIpv4Hosts" ): |
| 1104 | for host in main.disconnectedIpv4Hosts: |
| 1105 | disconnectedHosts.append( host ) |
| 1106 | if hasattr( main, "disconnectedIpv6Hosts" ): |
| 1107 | for host in main.disconnectedIpv6Hosts: |
| 1108 | disconnectedHosts.append( host ) |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1109 | for hostName, ip in main.expectedHosts[ "network" ].items(): |
You Wang | 6acb7a4 | 2018-05-04 15:12:25 -0700 | [diff] [blame] | 1110 | # Exclude disconnected hosts |
| 1111 | if hostName in disconnectedHosts: |
| 1112 | main.log.debug( "Skip verifying IP for {} as it's disconnected".format( hostName ) ) |
| 1113 | continue |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1114 | ipResult = ipResult and utilities.retry( main.Network.verifyHostIp, |
| 1115 | main.FALSE, |
| 1116 | kwargs={ 'hostList': [ hostName ], |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 1117 | 'prefix': ip, |
| 1118 | 'update': False }, |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1119 | attempts=attempts, |
| 1120 | sleep=sleep ) |
| 1121 | utilities.assert_equals( expect=main.TRUE, actual=ipResult, |
| 1122 | onpass="Verify network host IP succeded", |
| 1123 | onfail="Verify network host IP failed" ) |
| 1124 | |
| 1125 | @staticmethod |
You Wang | aec6a09 | 2018-08-06 15:36:31 -0700 | [diff] [blame] | 1126 | def verifyOnosHostIp( main, attempts=10, sleep=10, skipOnFail=True ): |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1127 | """ |
| 1128 | Verifies host IP address assignment from ONOS |
| 1129 | """ |
| 1130 | main.step( "Verify host IP address assignment in ONOS" ) |
| 1131 | ipResult = main.TRUE |
You Wang | 6acb7a4 | 2018-05-04 15:12:25 -0700 | [diff] [blame] | 1132 | # Find out IPs of disconnected hosts |
| 1133 | disconnectedIps = [] |
| 1134 | if hasattr( main, "disconnectedIpv4Hosts" ): |
| 1135 | for host in main.disconnectedIpv4Hosts: |
| 1136 | disconnectedIps.append( main.expectedHosts[ "network" ][ host ] ) |
| 1137 | if hasattr( main, "disconnectedIpv6Hosts" ): |
| 1138 | for host in main.disconnectedIpv6Hosts: |
| 1139 | disconnectedIps.append( main.expectedHosts[ "network" ][ host ] ) |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1140 | for hostName, ip in main.expectedHosts[ "onos" ].items(): |
You Wang | 6acb7a4 | 2018-05-04 15:12:25 -0700 | [diff] [blame] | 1141 | # Exclude disconnected hosts |
| 1142 | if ip in disconnectedIps: |
| 1143 | main.log.debug( "Skip verifying IP for {} as it's disconnected".format( ip ) ) |
| 1144 | continue |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1145 | ipResult = ipResult and utilities.retry( main.Cluster.active( 0 ).verifyHostIp, |
| 1146 | main.FALSE, |
| 1147 | kwargs={ 'hostList': [ hostName ], |
| 1148 | 'prefix': ip }, |
| 1149 | attempts=attempts, |
| 1150 | sleep=sleep ) |
| 1151 | utilities.assert_equals( expect=main.TRUE, actual=ipResult, |
| 1152 | onpass="Verify ONOS host IP succeded", |
| 1153 | onfail="Verify ONOS host IP failed" ) |
You Wang | aec6a09 | 2018-08-06 15:36:31 -0700 | [diff] [blame] | 1154 | if not ipResult and skipOnFail: |
| 1155 | Testcaselib.saveOnosDiagnostics( main ) |
You Wang | 8947715 | 2018-08-07 14:19:02 -0700 | [diff] [blame] | 1156 | Testcaselib.cleanup( main, copyKarafLog=False ) |
You Wang | aec6a09 | 2018-08-06 15:36:31 -0700 | [diff] [blame] | 1157 | main.skipCase() |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 1158 | |
Jonghwan Hyun | 812c70f | 2018-02-16 16:33:16 -0800 | [diff] [blame] | 1159 | @staticmethod |
| 1160 | def updateIntfCfg( main, connectPoint, ips=[], untagged=0, tagged=[], native=0 ): |
| 1161 | """ |
| 1162 | Description: |
| 1163 | Updates interface configuration in ONOS, with given IP and vlan parameters |
| 1164 | Required: |
| 1165 | * connectPoint: connect point to update configuration |
| 1166 | Optional: |
| 1167 | * ips: list of IP addresses, combined with '/xx' subnet representation, |
| 1168 | corresponding to 'ips' field in the configuration |
| 1169 | * untagged: vlan ID as an integer, corresponding to 'vlan-untagged' field in the configuration |
| 1170 | * tagged: integer list of vlan IDs, corresponding to 'vlan-tagged' field in the configuration |
| 1171 | * native: vlan ID as an integer, corresponding to 'vlan-native' field in the configuration |
| 1172 | """ |
| 1173 | cfg = dict() |
| 1174 | cfg[ "ports" ] = dict() |
| 1175 | cfg[ "ports" ][ connectPoint ] = dict() |
| 1176 | cfg[ "ports" ][ connectPoint ][ "interfaces" ] = [ dict() ] |
| 1177 | cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "ips" ] = ips |
| 1178 | if untagged > 0: |
| 1179 | cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-untagged" ] = untagged |
| 1180 | else: |
| 1181 | cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-tagged" ] = tagged |
| 1182 | if native > 0: |
| 1183 | cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-native" ] = native |
| 1184 | |
| 1185 | main.Cluster.active( 0 ).REST.setNetCfg( json.loads( json.dumps( cfg ) ) ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 1186 | |
| 1187 | @staticmethod |
You Wang | 2cb7017 | 2018-07-25 16:44:13 -0700 | [diff] [blame] | 1188 | def startScapyHosts( main, scapyNames=[], mininetNames=[] ): |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 1189 | """ |
| 1190 | Create host components and start Scapy CLIs |
You Wang | 2cb7017 | 2018-07-25 16:44:13 -0700 | [diff] [blame] | 1191 | scapyNames: list of names that will be used as component names for scapy hosts |
| 1192 | mininetNames: used when scapy host names are different from the host names |
| 1193 | in Mininet. E.g. when scapyNames=['h1Scapy'], it's required to specify the |
| 1194 | name of the corresponding Mininet host by mininetNames=['h1'] |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 1195 | """ |
| 1196 | main.step( "Start Scapy CLIs" ) |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 1197 | main.scapyNames = scapyNames if scapyNames else main.params[ 'SCAPY' ][ 'HOSTNAMES' ].split( ',' ) |
| 1198 | main.scapyHosts = [] if not hasattr( main, "scapyHosts" ) else main.scapyHosts |
You Wang | 2cb7017 | 2018-07-25 16:44:13 -0700 | [diff] [blame] | 1199 | for scapyName in main.scapyNames: |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 1200 | if hasattr( main, 'Mininet1' ): |
| 1201 | main.Scapy.createHostComponent( scapyName ) |
| 1202 | scapyHandle = getattr( main, scapyName ) |
| 1203 | if mininetNames: |
| 1204 | mininetName = mininetNames[ scapyNames.index( scapyName ) ] |
| 1205 | else: |
| 1206 | mininetName = None |
| 1207 | scapyHandle.startHostCli( mininetName ) |
You Wang | 2cb7017 | 2018-07-25 16:44:13 -0700 | [diff] [blame] | 1208 | else: |
You Wang | 0fc2170 | 2018-11-02 17:49:18 -0700 | [diff] [blame] | 1209 | main.Network.createHostComponent( scapyName ) |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 1210 | scapyHandle = getattr( main, scapyName ) |
| 1211 | scapyHandle.connectInband() |
| 1212 | main.scapyHosts.append( scapyHandle ) |
You Wang | 2cb7017 | 2018-07-25 16:44:13 -0700 | [diff] [blame] | 1213 | scapyHandle.startScapy() |
| 1214 | scapyHandle.updateSelf() |
| 1215 | main.log.debug( scapyHandle.name ) |
| 1216 | main.log.debug( scapyHandle.hostIp ) |
| 1217 | main.log.debug( scapyHandle.hostMac ) |
| 1218 | |
| 1219 | @staticmethod |
| 1220 | def verifyTraffic( main, srcHosts, dstIp, dstHost, dstIntf, ipv6=False, expect=True, skipOnFail=True, maxRetry=2 ): |
| 1221 | """ |
| 1222 | Verify unicast traffic by pinging from source hosts to the destination IP |
| 1223 | and capturing the packets at the destination host using Scapy. |
| 1224 | srcHosts: List of host names to send the ping packets |
| 1225 | dstIp: destination IP of the ping packets |
| 1226 | dstHost: host that runs Scapy to capture the packets |
| 1227 | dstIntf: name of the interface on the destination host |
| 1228 | expect: use True if the ping is expected to be captured at destination; |
| 1229 | Otherwise False |
| 1230 | skipOnFail: skip the rest of this test case if result is not expected |
| 1231 | maxRetry: number of retries allowed |
| 1232 | """ |
| 1233 | from tests.dependencies.topology import Topology |
| 1234 | try: |
| 1235 | main.topo |
| 1236 | except ( NameError, AttributeError ): |
| 1237 | main.topo = Topology() |
| 1238 | main.step( "Verify traffic to {} by capturing packets on {}".format( dstIp, dstHost ) ) |
| 1239 | result = main.TRUE |
| 1240 | for srcHost in srcHosts: |
| 1241 | trafficResult = main.topo.pingAndCapture( srcHost, dstIp, dstHost, dstIntf, ipv6, |
| 1242 | expect, maxRetry, True ) |
| 1243 | if not trafficResult: |
You Wang | 2cb7017 | 2018-07-25 16:44:13 -0700 | [diff] [blame] | 1244 | result = main.FALSE |
| 1245 | main.log.warn( "Scapy result from {} to {} is not as expected".format( srcHost, dstIp ) ) |
| 1246 | utilities.assert_equals( expect=main.TRUE, |
| 1247 | actual=result, |
| 1248 | onpass="Verify traffic to {}: Pass".format( dstIp ), |
| 1249 | onfail="Verify traffic to {}: Fail".format( dstIp ) ) |
| 1250 | if skipOnFail and result != main.TRUE: |
| 1251 | Testcaselib.saveOnosDiagnostics( main ) |
| 1252 | Testcaselib.cleanup( main, copyKarafLog=False ) |
| 1253 | main.skipCase() |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 1254 | |
| 1255 | @staticmethod |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 1256 | def verifyMulticastTraffic( main, routeName, expect, skipOnFail=True, maxRetry=1 ): |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 1257 | """ |
| 1258 | Verify multicast traffic using scapy |
| 1259 | """ |
You Wang | c564c6f | 2018-05-01 15:24:57 -0700 | [diff] [blame] | 1260 | from tests.dependencies.topology import Topology |
| 1261 | try: |
| 1262 | main.topo |
| 1263 | except ( NameError, AttributeError ): |
| 1264 | main.topo = Topology() |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1265 | main.step( "Verify {} multicast traffic".format( routeName ) ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 1266 | routeData = main.multicastConfig[ routeName ] |
| 1267 | srcs = main.mcastRoutes[ routeName ][ "src" ] |
| 1268 | dsts = main.mcastRoutes[ routeName ][ "dst" ] |
| 1269 | main.log.info( "Sending multicast traffic from {} to {}".format( [ routeData[ "src" ][ i ][ "host" ] for i in srcs ], |
| 1270 | [ routeData[ "dst" ][ i ][ "host" ] for i in dsts ] ) ) |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1271 | result = main.TRUE |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 1272 | for src in srcs: |
| 1273 | srcEntry = routeData[ "src" ][ src ] |
| 1274 | for dst in dsts: |
| 1275 | dstEntry = routeData[ "dst" ][ dst ] |
| 1276 | sender = getattr( main, srcEntry[ "host" ] ) |
| 1277 | receiver = getattr( main, dstEntry[ "host" ] ) |
| 1278 | main.Network.addRoute( str( srcEntry[ "host" ] ), |
| 1279 | str( routeData[ "group" ] ), |
| 1280 | str( srcEntry[ "interface" ] ), |
| 1281 | True if routeData[ "ipVersion" ] == 6 else False ) |
| 1282 | # Build the packet |
| 1283 | sender.buildEther( dst=str( srcEntry[ "Ether" ] ) ) |
| 1284 | if routeData[ "ipVersion" ] == 4: |
| 1285 | sender.buildIP( dst=str( routeData[ "group" ] ) ) |
| 1286 | elif routeData[ "ipVersion" ] == 6: |
| 1287 | sender.buildIPv6( dst=str( routeData[ "group" ] ) ) |
| 1288 | sender.buildUDP( ipVersion=routeData[ "ipVersion" ], dport=srcEntry[ "UDP" ] ) |
| 1289 | sIface = srcEntry[ "interface" ] |
| 1290 | dIface = dstEntry[ "interface" ] if "interface" in dstEntry.keys() else None |
| 1291 | pktFilter = srcEntry[ "filter" ] |
| 1292 | pkt = srcEntry[ "packet" ] |
| 1293 | # Send packet and check received packet |
| 1294 | expectedResult = expect.pop( 0 ) if isinstance( expect, list ) else expect |
You Wang | c564c6f | 2018-05-01 15:24:57 -0700 | [diff] [blame] | 1295 | t3Cmd = "t3-troubleshoot -vv -sp {} -et ipv{} -d {} -dm {}".format( srcEntry[ "port" ], routeData[ "ipVersion" ], |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 1296 | routeData[ "group" ], srcEntry[ "Ether" ] ) |
You Wang | c564c6f | 2018-05-01 15:24:57 -0700 | [diff] [blame] | 1297 | trafficResult = main.topo.sendScapyPackets( sender, receiver, pktFilter, pkt, sIface, dIface, |
| 1298 | expectedResult, maxRetry, True, t3Cmd ) |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1299 | if not trafficResult: |
| 1300 | result = main.FALSE |
| 1301 | main.log.warn( "Scapy result from {} to {} is not as expected".format( srcEntry[ "host" ], |
| 1302 | dstEntry[ "host" ] ) ) |
| 1303 | utilities.assert_equals( expect=main.TRUE, |
| 1304 | actual=result, |
| 1305 | onpass="Verify {} multicast traffic: Pass".format( routeName ), |
| 1306 | onfail="Verify {} multicast traffic: Fail".format( routeName ) ) |
You Wang | ba823f0 | 2018-05-17 13:54:08 -0700 | [diff] [blame] | 1307 | if skipOnFail and result != main.TRUE: |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1308 | Testcaselib.saveOnosDiagnostics( main ) |
| 1309 | Testcaselib.cleanup( main, copyKarafLog=False ) |
| 1310 | main.skipCase() |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 1311 | |
| 1312 | @staticmethod |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1313 | def verifyPing( main, srcList, dstList, ipv6=False, expect=True, wait=1, |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 1314 | acceptableFailed=0, skipOnFail=True, stepMsg="Verify Ping", |
| 1315 | t3Simple=True ): |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 1316 | """ |
| 1317 | Verify reachability from each host in srcList to each host in dstList |
| 1318 | """ |
| 1319 | from tests.dependencies.topology import Topology |
| 1320 | try: |
| 1321 | main.topo |
| 1322 | except ( NameError, AttributeError ): |
| 1323 | main.topo = Topology() |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1324 | main.step( stepMsg ) |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 1325 | pingResult = main.topo.ping( srcList, dstList, ipv6, expect, wait, acceptableFailed, skipOnFail, t3Simple ) |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1326 | utilities.assert_equals( expect=main.TRUE, |
| 1327 | actual=pingResult, |
| 1328 | onpass="{}: Pass".format( stepMsg ), |
| 1329 | onfail="{}: Fail".format( stepMsg ) ) |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 1330 | if not pingResult and skipOnFail: |
| 1331 | Testcaselib.saveOnosDiagnostics( main ) |
| 1332 | Testcaselib.cleanup( main, copyKarafLog=False, removeHostComponent=True ) |
| 1333 | main.skipCase() |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1334 | |
| 1335 | @staticmethod |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1336 | def verifyHostLocations( main, locationDict, retry=2 ): |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1337 | """ |
| 1338 | Verify if the specified host is discovered by ONOS on the given locations |
| 1339 | Required: |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1340 | locationDict: a dictionary that maps host names to expected locations. |
| 1341 | locations could be a string or a list. |
| 1342 | ex. { "h1v4": ["of:0000000000000005/8"] } |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1343 | Returns: |
| 1344 | main.TRUE if host is discovered on all locations provided, otherwise main.FALSE |
| 1345 | """ |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1346 | main.step( "Verify locations of hosts {}".format( locationDict.keys() ) ) |
| 1347 | result = main.TRUE |
| 1348 | for hostName, locations in locationDict.items(): |
| 1349 | main.log.info( "Verify host {} is discovered at {}".format( hostName, locations ) ) |
| 1350 | hostIp = main.Network.getIPAddress( hostName, proto='IPV4' ) |
| 1351 | if not hostIp: |
| 1352 | hostIp = main.Network.getIPAddress( hostName, proto='IPV6' ) |
| 1353 | if not hostIp: |
| 1354 | main.log.warn( "Failed to find IP address for host {}, skipping location verification".format( hostName ) ) |
| 1355 | result = main.FALSE |
| 1356 | continue |
| 1357 | locationResult = utilities.retry( main.Cluster.active( 0 ).CLI.verifyHostLocation, |
| 1358 | main.FALSE, |
| 1359 | args=( hostIp, locations ), |
| 1360 | attempts=retry + 1, |
| 1361 | sleep=10 ) |
| 1362 | if not locationResult: |
| 1363 | result = main.FALSE |
| 1364 | main.log.warn( "location verification for host {} failed".format( hostName ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 1365 | utilities.assert_equals( expect=main.TRUE, actual=result, |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 1366 | onpass="Location verification passed", |
| 1367 | onfail="Location verification failed" ) |
Jonghwan Hyun | 785471d | 2018-05-14 14:48:19 -0700 | [diff] [blame] | 1368 | |
| 1369 | @staticmethod |
You Wang | 6e5b48e | 2018-07-23 16:17:38 -0700 | [diff] [blame] | 1370 | def moveHost( main, hostName, srcSw, dstSw, gw, macAddr=None, prefixLen=None, cfg='', ipv6=False, vlan=None ): |
Jonghwan Hyun | 785471d | 2018-05-14 14:48:19 -0700 | [diff] [blame] | 1371 | """ |
| 1372 | Move specified host from srcSw to dstSw. |
| 1373 | If srcSw and dstSw are same, the host will be moved from current port to |
| 1374 | next available port. |
| 1375 | Required: |
| 1376 | hostName: name of the host. e.g., "h1" |
| 1377 | srcSw: name of the switch that the host is attached to. e.g., "leaf1" |
| 1378 | dstSw: name of the switch that the host will be moved to. e.g., "leaf2" |
| 1379 | gw: ip address of the gateway of the new location |
| 1380 | Optional: |
| 1381 | macAddr: if specified, change MAC address of the host to the specified MAC address. |
| 1382 | prefixLen: prefix length |
| 1383 | cfg: port configuration as JSON string |
| 1384 | ipv6: Use True to move IPv6 host |
You Wang | 6e5b48e | 2018-07-23 16:17:38 -0700 | [diff] [blame] | 1385 | vlan: vlan number of the host |
Jonghwan Hyun | 785471d | 2018-05-14 14:48:19 -0700 | [diff] [blame] | 1386 | """ |
Jonghwan Hyun | 785471d | 2018-05-14 14:48:19 -0700 | [diff] [blame] | 1387 | if not hasattr( main, 'Mininet1' ): |
| 1388 | main.log.warn( "moveHost is supposed to be used only in Mininet." ) |
| 1389 | return |
| 1390 | |
You Wang | 6e5b48e | 2018-07-23 16:17:38 -0700 | [diff] [blame] | 1391 | main.step( "Moving {} host {} from {} to {}".format( 'tagged' if vlan else 'untagged', hostName, srcSw, dstSw ) ) |
| 1392 | main.Mininet1.moveHost( hostName, srcSw, dstSw, macAddr, prefixLen, ipv6, vlan=vlan ) |
| 1393 | if not ipv6: |
You Wang | 6260ed5 | 2018-07-18 17:54:25 -0700 | [diff] [blame] | 1394 | main.Mininet1.changeDefaultGateway( hostName, gw ) |
Jonghwan Hyun | 785471d | 2018-05-14 14:48:19 -0700 | [diff] [blame] | 1395 | if cfg: |
| 1396 | main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ), |
| 1397 | subjectClass="ports" ) |
You Wang | 6260ed5 | 2018-07-18 17:54:25 -0700 | [diff] [blame] | 1398 | # Wait for the host to get RA for setting up default gateway |
| 1399 | time.sleep( 5 ) |
Jonghwan Hyun | 785471d | 2018-05-14 14:48:19 -0700 | [diff] [blame] | 1400 | |
| 1401 | main.Mininet1.discoverHosts( [ hostName, ] ) |
| 1402 | |
| 1403 | # Update expectedHost when MAC address is changed. |
| 1404 | if macAddr is not None: |
| 1405 | ipAddr = main.expectedHosts[ "network" ][ hostName ] |
| 1406 | if ipAddr is not None: |
| 1407 | for hostName, ip in main.expectedHosts[ "onos" ].items(): |
| 1408 | if ip == ipAddr: |
| 1409 | vlan = hostName.split( "/" )[ -1 ] |
| 1410 | del main.expectedHosts[ "onos" ][ hostName ] |
You Wang | 7ea9058 | 2018-07-19 15:27:58 -0700 | [diff] [blame] | 1411 | main.expectedHosts[ "onos" ][ "{}/{}".format( macAddr.upper(), vlan ) ] = ip |
Jonghwan Hyun | 785471d | 2018-05-14 14:48:19 -0700 | [diff] [blame] | 1412 | break |
Jonghwan Hyun | 5fad178 | 2018-05-21 14:11:16 -0700 | [diff] [blame] | 1413 | |
| 1414 | @staticmethod |
| 1415 | def moveDualHomedHost( main, hostName, srcSw, srcPairSw, dstSw, dstPairSw, gw, |
You Wang | 6e5b48e | 2018-07-23 16:17:38 -0700 | [diff] [blame] | 1416 | macAddr=None, prefixLen=24, cfg='', ipv6=False, vlan=None ): |
Jonghwan Hyun | 5fad178 | 2018-05-21 14:11:16 -0700 | [diff] [blame] | 1417 | """ |
| 1418 | Move specified dual-homed host from srcSw-srcPairSw to dstSw-dstPairSw. |
| 1419 | If srcSw-srcPairSw and dstSw-dstPairSw are same, the host will be moved from current port |
| 1420 | to next available port. |
| 1421 | Required: |
| 1422 | hostName: name of the host. e.g., "h1" |
| 1423 | srcSw: name of the switch that the host is attached to. e.g., "leaf1" |
| 1424 | srcPairSw: name of the paired-switch that the host is attached to. e.g., "leaf2" |
| 1425 | dstSw: name of the switch that the host will be moved to. e.g., "leaf1" |
| 1426 | dstPairSw: name of the paired-switch that the host will be moved to. e.g., "leaf2" |
| 1427 | gw: ip address of the gateway of the new location |
| 1428 | Optional: |
| 1429 | macAddr: if specified, change MAC address of the host to the specified MAC address. |
| 1430 | prefixLen: prefix length |
| 1431 | cfg: port configurations as JSON string |
You Wang | 7ea9058 | 2018-07-19 15:27:58 -0700 | [diff] [blame] | 1432 | ipv6: Use True to move IPv6 host |
You Wang | 6e5b48e | 2018-07-23 16:17:38 -0700 | [diff] [blame] | 1433 | vlan: vlan number of the host |
Jonghwan Hyun | 5fad178 | 2018-05-21 14:11:16 -0700 | [diff] [blame] | 1434 | """ |
Jonghwan Hyun | 5fad178 | 2018-05-21 14:11:16 -0700 | [diff] [blame] | 1435 | if not hasattr( main, 'Mininet1' ): |
| 1436 | main.log.warn( "moveDualHomedHost is supposed to be used only in Mininet." ) |
| 1437 | return |
| 1438 | |
You Wang | 6e5b48e | 2018-07-23 16:17:38 -0700 | [diff] [blame] | 1439 | main.step( "Moving {} host {} from {} and {} to {} and {}".format( 'tagged' if vlan else 'untagged', hostName, |
| 1440 | srcSw, srcPairSw, dstSw, dstPairSw ) ) |
| 1441 | main.Mininet1.moveDualHomedHost( hostName, srcSw, srcPairSw, dstSw, dstPairSw, |
| 1442 | macAddr=macAddr, prefixLen=prefixLen, ipv6=ipv6, vlan=vlan ) |
| 1443 | if not ipv6: |
You Wang | 7ea9058 | 2018-07-19 15:27:58 -0700 | [diff] [blame] | 1444 | main.Mininet1.changeDefaultGateway( hostName, gw ) |
Jonghwan Hyun | 5fad178 | 2018-05-21 14:11:16 -0700 | [diff] [blame] | 1445 | if cfg: |
| 1446 | main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ), |
| 1447 | subjectClass="ports" ) |
You Wang | 7ea9058 | 2018-07-19 15:27:58 -0700 | [diff] [blame] | 1448 | # Wait for the host to get RA for setting up default gateway |
| 1449 | time.sleep( 5 ) |
Jonghwan Hyun | 5fad178 | 2018-05-21 14:11:16 -0700 | [diff] [blame] | 1450 | |
| 1451 | main.Mininet1.discoverHosts( [ hostName, ] ) |
| 1452 | |
| 1453 | # Update expectedHost when MAC address is changed. |
| 1454 | if macAddr is not None: |
| 1455 | ipAddr = main.expectedHosts[ "network" ][ hostName ] |
| 1456 | if ipAddr is not None: |
| 1457 | for hostName, ip in main.expectedHosts[ "onos" ].items(): |
| 1458 | if ip == ipAddr: |
| 1459 | vlan = hostName.split( "/" )[ -1 ] |
| 1460 | del main.expectedHosts[ "onos" ][ hostName ] |
You Wang | 7ea9058 | 2018-07-19 15:27:58 -0700 | [diff] [blame] | 1461 | main.expectedHosts[ "onos" ][ "{}/{}".format( macAddr.upper(), vlan ) ] = ip |