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 |
| 22 | import imp |
| 23 | import time |
| 24 | import json |
| 25 | import urllib |
| 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: |
| 55 | main.step( "Constructing test variables" ) |
| 56 | # Test variables |
| 57 | main.cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 58 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 59 | main.path = os.path.dirname( main.testFile ) |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 60 | main.useCommonTopo = main.params[ 'DEPENDENCY' ][ 'useCommonTopo' ] == 'True' |
| 61 | main.topoPath = main.path + ( "/.." if main.useCommonTopo else "" ) + "/dependencies/" |
| 62 | main.useCommonConf = main.params[ 'DEPENDENCY' ][ 'useCommonConf' ] == 'True' |
| 63 | main.configPath = main.path + ( "/.." if main.useCommonConf else "" ) + "/dependencies/" |
| 64 | main.forJson = "json/" |
| 65 | main.forChart = "chart/" |
| 66 | main.forConfig = "conf/" |
| 67 | main.forHost = "host/" |
You Wang | 2731757 | 2018-03-06 12:13:11 -0800 | [diff] [blame] | 68 | main.forSwitchFailure = "switchFailure/" |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 69 | main.forLinkFailure = "linkFailure/" |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 70 | main.forMulticast = "multicast/" |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 71 | main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ] |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 72 | main.topologyLib = main.params[ 'DEPENDENCY' ][ 'lib' ] if 'lib' in main.params[ 'DEPENDENCY' ] else None |
| 73 | main.topologyConf = main.params[ 'DEPENDENCY' ][ 'conf' ] if 'conf' in main.params[ 'DEPENDENCY' ] else None |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 74 | main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 75 | main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 76 | |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 77 | stepResult = main.testSetUp.envSetup( False ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 78 | except Exception as e: |
| 79 | main.testSetUp.envSetupException( e ) |
Jonghwan Hyun | 3731d6a | 2017-10-19 11:59:31 -0700 | [diff] [blame] | 80 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 81 | main.testSetUp.evnSetupConclusion( stepResult ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 82 | |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 83 | @staticmethod |
Andreas Pantelopoulos | 90f0b10 | 2018-02-01 13:21:45 -0800 | [diff] [blame] | 84 | def installOnos( main, vlanCfg=True, skipPackage=False, cliSleep=10, |
| 85 | parallel=True ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 86 | """ |
| 87 | - Set up cell |
| 88 | - Create cell file |
| 89 | - Set cell file |
| 90 | - Verify cell file |
| 91 | - Kill ONOS process |
| 92 | - Uninstall ONOS cluster |
| 93 | - Verify ONOS start up |
| 94 | - Install ONOS cluster |
| 95 | - Connect to cli |
| 96 | """ |
| 97 | # main.scale[ 0 ] determines the current number of ONOS controller |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 98 | if not main.apps: |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 99 | main.log.error( "App list is empty" ) |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 100 | main.log.info( "Cluster size: " + str( main.Cluster.numCtrls ) ) |
| 101 | main.log.info( "Cluster ips: " + ', '.join( main.Cluster.getIps() ) ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 102 | main.dynamicHosts = [ 'in1', 'out1' ] |
You Wang | a0f6ff6 | 2018-01-11 15:46:30 -0800 | [diff] [blame] | 103 | main.testSetUp.ONOSSetUp( main.Cluster, newCell=True, cellName=main.cellName, |
Andreas Pantelopoulos | 90f0b10 | 2018-02-01 13:21:45 -0800 | [diff] [blame] | 104 | skipPack=skipPackage, |
| 105 | useSSH=Testcaselib.useSSH, |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 106 | installParallel=parallel, includeCaseDesc=False ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 107 | ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary, |
| 108 | main.FALSE, |
You Wang | 1cdc5f5 | 2017-12-19 16:47:51 -0800 | [diff] [blame] | 109 | sleep=cliSleep, |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 110 | attempts=10 ) |
| 111 | if ready: |
| 112 | ready = main.TRUE |
| 113 | utilities.assert_equals( expect=main.TRUE, actual=ready, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 114 | onpass="ONOS summary command succeded", |
| 115 | onfail="ONOS summary command failed" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 116 | if not ready: |
| 117 | main.log.error( "ONOS startup failed!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 118 | main.cleanAndExit() |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 119 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 120 | for ctrl in main.Cluster.active(): |
| 121 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.segmentrouting" ) |
You Wang | f5f104f | 2018-03-30 17:09:10 -0700 | [diff] [blame] | 122 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.driver" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 123 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.net.flowobjective.impl" ) |
You Wang | f5f104f | 2018-03-30 17:09:10 -0700 | [diff] [blame] | 124 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.routeservice.impl" ) |
| 125 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.routeservice.store" ) |
| 126 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.routing.fpm" ) |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 127 | ctrl.CLI.logSet( "TRACE", "org.onosproject.events" ) |
| 128 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.mcast" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 129 | |
| 130 | @staticmethod |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 131 | def loadCount( main ): |
| 132 | with open("%s/count/%s.count" % (main.configPath, main.cfgName)) as count: |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 133 | main.count = json.load(count) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 134 | |
| 135 | @staticmethod |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 136 | def loadJson( main ): |
| 137 | with open( "%s%s.json" % ( main.configPath + main.forJson, |
| 138 | main.cfgName ) ) as cfg: |
| 139 | main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) ) |
| 140 | |
| 141 | @staticmethod |
| 142 | def loadChart( main ): |
| 143 | try: |
| 144 | with open( "%s%s.chart" % ( main.configPath + main.forChart, |
| 145 | main.cfgName ) ) as chart: |
| 146 | main.pingChart = json.load(chart) |
| 147 | except IOError: |
| 148 | main.log.warn( "No chart file found." ) |
| 149 | |
| 150 | @staticmethod |
| 151 | def loadHost( main ): |
| 152 | with open( "%s%s.host" % ( main.configPath + main.forHost, |
| 153 | main.cfgName ) ) as host: |
| 154 | main.expectedHosts = json.load( host ) |
| 155 | |
| 156 | @staticmethod |
You Wang | 2731757 | 2018-03-06 12:13:11 -0800 | [diff] [blame] | 157 | def loadSwitchFailureChart( main ): |
| 158 | with open( "%s%s.switchFailureChart" % ( main.configPath + main.forSwitchFailure, |
| 159 | main.cfgName ) ) as sfc: |
| 160 | main.switchFailureChart = json.load( sfc ) |
| 161 | |
| 162 | @staticmethod |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 163 | def loadLinkFailureChart( main ): |
| 164 | with open( "%s%s.linkFailureChart" % ( main.configPath + main.forLinkFailure, |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 165 | main.cfgName ) ) as lfc: |
| 166 | main.linkFailureChart = json.load( lfc ) |
| 167 | |
| 168 | @staticmethod |
| 169 | def loadMulticastConfig( main ): |
| 170 | with open( "%s%s.multicastConfig" % ( main.configPath + main.forMulticast, |
| 171 | main.cfgName ) ) as cfg: |
| 172 | main.multicastConfig = json.load( cfg ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 173 | |
| 174 | @staticmethod |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 175 | def startMininet( main, topology, args="" ): |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 176 | copyResult = main.ONOSbench.scp( main.Mininet1, |
| 177 | main.topoPath + main.topology, |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 178 | main.Mininet1.home + "custom", |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 179 | direction="to" ) |
| 180 | if main.topologyLib: |
| 181 | for lib in main.topologyLib.split(","): |
| 182 | copyResult = copyResult and main.ONOSbench.scp( main.Mininet1, |
| 183 | main.topoPath + lib, |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 184 | main.Mininet1.home + "custom", |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 185 | direction="to" ) |
| 186 | if main.topologyConf: |
You Wang | a877ea4 | 2018-04-05 15:27:40 -0700 | [diff] [blame] | 187 | import re |
| 188 | controllerIPs = [ ctrl.ipAddress for ctrl in main.Cluster.runningNodes ] |
| 189 | index = 0 |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 190 | for conf in main.topologyConf.split(","): |
You Wang | a877ea4 | 2018-04-05 15:27:40 -0700 | [diff] [blame] | 191 | # Update zebra configurations with correct ONOS instance IP |
| 192 | if conf in [ "zebradbgp1.conf", "zebradbgp2.conf" ]: |
| 193 | ip = controllerIPs[ index ] |
| 194 | index = ( index + 1 ) % len( controllerIPs ) |
| 195 | with open( main.configPath + main.forConfig + conf ) as f: |
| 196 | s = f.read() |
| 197 | s = re.sub( r"(fpm connection ip).*(port 2620)", r"\1 " + ip + r" \2", s ) |
| 198 | with open( main.configPath + main.forConfig + conf, "w" ) as f: |
| 199 | f.write( s ) |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 200 | copyResult = copyResult and main.ONOSbench.scp( main.Mininet1, |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 201 | main.configPath + main.forConfig + conf, |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 202 | "~/", |
| 203 | direction="to" ) |
| 204 | stepResult = copyResult |
| 205 | utilities.assert_equals( expect=main.TRUE, |
| 206 | actual=stepResult, |
| 207 | onpass="Successfully copied topo files", |
| 208 | onfail="Failed to copy topo files" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 209 | main.step( "Starting Mininet Topology" ) |
Jonghwan Hyun | 3731d6a | 2017-10-19 11:59:31 -0700 | [diff] [blame] | 210 | 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] | 211 | main.topology = topology |
| 212 | topoResult = main.Mininet1.startNet( |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 213 | topoFile=main.Mininet1.home + "custom/" + main.topology, args=arg ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 214 | stepResult = topoResult |
| 215 | utilities.assert_equals( expect=main.TRUE, |
| 216 | actual=stepResult, |
| 217 | onpass="Successfully loaded topology", |
| 218 | onfail="Failed to load topology" ) |
| 219 | # Exit if topology did not load properly |
| 220 | if not topoResult: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 221 | main.cleanAndExit() |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 222 | |
| 223 | @staticmethod |
You Wang | 84f981d | 2018-01-12 16:11:50 -0800 | [diff] [blame] | 224 | def connectToPhysicalNetwork( main, switchNames ): |
| 225 | main.step( "Connecting to physical netowrk" ) |
| 226 | topoResult = main.NetworkBench.connectToNet() |
| 227 | stepResult = topoResult |
| 228 | utilities.assert_equals( expect=main.TRUE, |
| 229 | actual=stepResult, |
| 230 | onpass="Successfully loaded topology", |
| 231 | onfail="Failed to load topology" ) |
| 232 | # Exit if topology did not load properly |
| 233 | if not topoResult: |
| 234 | main.cleanAndExit() |
| 235 | |
| 236 | main.step( "Assign switches to controllers." ) |
| 237 | assignResult = main.TRUE |
| 238 | for name in switchNames: |
| 239 | assignResult = assignResult & main.NetworkBench.assignSwController( sw=name, |
| 240 | ip=main.Cluster.getIps(), |
| 241 | port='6653' ) |
| 242 | utilities.assert_equals( expect=main.TRUE, |
| 243 | actual=stepResult, |
| 244 | onpass="Successfully assign switches to controllers", |
| 245 | onfail="Failed to assign switches to controllers" ) |
| 246 | |
| 247 | @staticmethod |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 248 | def saveOnosDiagnostics( main ): |
| 249 | """ |
| 250 | Get onos-diags.tar.gz and save it to the log directory. |
| 251 | suffix: suffix string of the file name. E.g. onos-diags-case1.tar.gz |
| 252 | """ |
| 253 | main.log.info( "Collecting onos-diags..." ) |
| 254 | main.ONOSbench.onosDiagnostics( [ctrl.ipAddress for ctrl in main.Cluster.runningNodes], |
| 255 | main.logdir, |
| 256 | "-CASE%d" % main.CurrentTestCaseNumber ) |
| 257 | |
| 258 | @staticmethod |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 259 | def config( main, cfgName ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 260 | main.spines = [] |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 261 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 262 | main.failures = int( main.params[ 'failures' ] ) |
| 263 | main.cfgName = cfgName |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 264 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 265 | if main.cfgName == '2x2': |
| 266 | spine = {} |
| 267 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ] |
| 268 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ] |
| 269 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 270 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 271 | spine = {} |
| 272 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ] |
| 273 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ] |
| 274 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 275 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 276 | elif main.cfgName == '4x4': |
| 277 | spine = {} |
| 278 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ] |
| 279 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ] |
| 280 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 281 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 282 | spine = {} |
| 283 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ] |
| 284 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ] |
| 285 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 286 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 287 | spine = {} |
| 288 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine3' ] |
| 289 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid3' ] |
| 290 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 291 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 292 | spine = {} |
| 293 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine4' ] |
| 294 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid4' ] |
| 295 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 296 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 297 | else: |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 298 | main.log.error( "Configuration failed!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 299 | main.cleanAndExit() |
You Wang | 2731757 | 2018-03-06 12:13:11 -0800 | [diff] [blame] | 300 | |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 301 | @staticmethod |
| 302 | def addStaticOnosRoute( main, subnet, intf): |
| 303 | """ |
| 304 | Adds an ONOS static route with the use route-add command. |
| 305 | """ |
| 306 | main.step("Add static route for subnet {0} towards router interface {1}".format(subnet, intf)) |
| 307 | routeResult = main.Cluster.active( 0 ).addStaticRoute(subnet, intf) |
| 308 | |
| 309 | utilities.assert_equals( expect=True, actual=( not routeResult ), |
| 310 | onpass="route-add command succeeded", |
| 311 | onfail="route-add command failed") |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 312 | |
| 313 | @staticmethod |
Jonghwan Hyun | 76a02b7 | 2018-01-30 16:40:48 +0900 | [diff] [blame] | 314 | def checkFlows( main, minFlowCount, tag="", dumpflows=True, sleep=10 ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 315 | main.step( |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 316 | "Check whether the flow count is bigger than %s" % minFlowCount ) |
Jonghwan Hyun | 76a02b7 | 2018-01-30 16:40:48 +0900 | [diff] [blame] | 317 | if tag == "": |
| 318 | tag = 'CASE%d' % main.CurrentTestCaseNumber |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 319 | count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowCount, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 320 | main.FALSE, |
| 321 | kwargs={ 'min': minFlowCount }, |
| 322 | attempts=10, |
You Wang | 1cdc5f5 | 2017-12-19 16:47:51 -0800 | [diff] [blame] | 323 | sleep=sleep ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 324 | utilities.assertEquals( |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 325 | expect=True, |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 326 | actual=( count > 0 ), |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 327 | onpass="Flow count looks correct: " + str( count ), |
| 328 | onfail="Flow count looks wrong: " + str( count ) ) |
| 329 | |
| 330 | main.step( "Check whether all flow status are ADDED" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 331 | flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 332 | main.FALSE, |
| 333 | kwargs={ 'isPENDING': False }, |
Jonghwan Hyun | 98fb40a | 2018-01-04 16:16:28 -0800 | [diff] [blame] | 334 | attempts=5, |
You Wang | 1cdc5f5 | 2017-12-19 16:47:51 -0800 | [diff] [blame] | 335 | sleep=sleep ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 336 | utilities.assertEquals( |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 337 | expect=main.TRUE, |
| 338 | actual=flowCheck, |
| 339 | onpass="Flow status is correct!", |
| 340 | onfail="Flow status is wrong!" ) |
| 341 | if dumpflows: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 342 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 343 | "flows", |
| 344 | main.logdir, |
Jonghwan Hyun | 76a02b7 | 2018-01-30 16:40:48 +0900 | [diff] [blame] | 345 | tag + "_FlowsBefore" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 346 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 347 | "groups", |
| 348 | main.logdir, |
Jonghwan Hyun | 76a02b7 | 2018-01-30 16:40:48 +0900 | [diff] [blame] | 349 | tag + "_GroupsBefore" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 350 | |
| 351 | @staticmethod |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 352 | def checkDevices( main, switches, tag="", sleep=10 ): |
| 353 | main.step( |
| 354 | "Check whether the switches count is equal to %s" % switches ) |
| 355 | if tag == "": |
| 356 | tag = 'CASE%d' % main.CurrentTestCaseNumber |
| 357 | result = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
| 358 | main.FALSE, |
| 359 | kwargs={ 'numoswitch': switches}, |
| 360 | attempts=10, |
| 361 | sleep=sleep ) |
| 362 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 363 | onpass="Device up successful", |
| 364 | onfail="Failed to boot up devices?" ) |
| 365 | |
| 366 | @staticmethod |
Jonghwan Hyun | 98fb40a | 2018-01-04 16:16:28 -0800 | [diff] [blame] | 367 | def checkFlowsByDpid( main, dpid, minFlowCount, sleep=10 ): |
| 368 | main.step( |
Jonghwan Hyun | cf2345c | 2018-02-26 11:07:54 -0800 | [diff] [blame] | 369 | " Check whether the flow count of device %s is bigger than %s" % ( dpid, minFlowCount ) ) |
| 370 | count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount, |
| 371 | main.FALSE, |
| 372 | args=( dpid, minFlowCount ), |
Jonghwan Hyun | 98fb40a | 2018-01-04 16:16:28 -0800 | [diff] [blame] | 373 | attempts=5, |
| 374 | sleep=sleep ) |
| 375 | utilities.assertEquals( |
Jonghwan Hyun | cf2345c | 2018-02-26 11:07:54 -0800 | [diff] [blame] | 376 | expect=True, |
| 377 | actual=( count > minFlowCount ), |
| 378 | onpass="Flow count looks correct: " + str( count ), |
| 379 | onfail="Flow count looks wrong. " ) |
Jonghwan Hyun | 98fb40a | 2018-01-04 16:16:28 -0800 | [diff] [blame] | 380 | |
| 381 | @staticmethod |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 382 | def checkFlowEqualityByDpid( main, dpid, flowCount, sleep=10 ): |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 383 | main.step( |
| 384 | " Check whether the flow count of device %s is equal to %s" % ( dpid, flowCount ) ) |
| 385 | count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount, |
| 386 | main.FALSE, |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 387 | args=( dpid, flowCount, False, 1 ), |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 388 | attempts=5, |
| 389 | sleep=sleep ) |
| 390 | |
| 391 | utilities.assertEquals( |
| 392 | expect=True, |
| 393 | actual=( int( count ) == flowCount ), |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 394 | onpass="Flow count looks correct: " + str( count ) , |
| 395 | onfail="Flow count looks wrong. found {}, should be {}.".format( count, flowCount ) ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 396 | |
| 397 | @staticmethod |
| 398 | def checkGroupEqualityByDpid( main, dpid, groupCount, sleep=10): |
| 399 | main.step( |
| 400 | " Check whether the group count of device %s is equal to %s" % ( dpid, groupCount ) ) |
| 401 | count = utilities.retry( main.Cluster.active( 0 ).CLI.checkGroupAddedCount, |
| 402 | main.FALSE, |
| 403 | args=( dpid, groupCount, False, 1), |
| 404 | attempts=5, |
| 405 | sleep=sleep ) |
| 406 | |
| 407 | utilities.assertEquals( |
| 408 | expect=True, |
| 409 | actual=( count == groupCount ), |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 410 | onpass="Group count looks correct: " + str( count ) , |
| 411 | onfail="Group count looks wrong. found {}, should be {}.".format( count, groupCount ) ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 412 | |
| 413 | @staticmethod |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 414 | def checkFlowsGroupsFromFile( main ): |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 415 | |
| 416 | for dpid, values in main.count.items(): |
| 417 | flowCount = values["flows"] |
| 418 | groupCount = values["groups"] |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 419 | main.log.report( "Check flow count for dpid " + str( dpid ) + |
| 420 | ", should be " + str( flowCount ) ) |
| 421 | Testcaselib.checkFlowEqualityByDpid( main, dpid, flowCount ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 422 | |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 423 | main.log.report( "Check group count for dpid " + str( dpid ) + |
| 424 | ", should be " + str( groupCount ) ) |
| 425 | Testcaselib.checkGroupEqualityByDpid( main, dpid, groupCount ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 426 | |
| 427 | return |
| 428 | |
| 429 | @staticmethod |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 430 | def pingAll( main, tag="", dumpflows=True, acceptableFailed=0, basedOnIp=False, sleep=10, retryAttempts=1, skipOnFail=False ): |
You Wang | f19d9f4 | 2018-02-23 16:34:19 -0800 | [diff] [blame] | 431 | ''' |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 432 | Verify connectivity between hosts according to the ping chart |
| 433 | acceptableFailed: max number of acceptable failed pings. |
You Wang | f19d9f4 | 2018-02-23 16:34:19 -0800 | [diff] [blame] | 434 | 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] | 435 | retryAttempts: the number of retry ping. Only works for IPv4 hosts. |
You Wang | f19d9f4 | 2018-02-23 16:34:19 -0800 | [diff] [blame] | 436 | ''' |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 437 | main.log.report( "Check host connectivity" ) |
| 438 | main.log.debug( "Ping chart: %s" % main.pingChart ) |
Andreas Pantelopoulos | f6ed501 | 2018-02-08 21:26:01 -0800 | [diff] [blame] | 439 | if tag == "": |
| 440 | tag = 'CASE%d' % main.CurrentTestCaseNumber |
| 441 | for entry in main.pingChart.itervalues(): |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 442 | main.log.debug( "Entry in ping chart: %s" % entry ) |
| 443 | expect = entry[ 'expect' ] |
| 444 | if expect == "Unidirectional": |
| 445 | # Verify ping from each src host to each dst host |
| 446 | src = entry[ 'src' ] |
| 447 | dst = entry[ 'dst' ] |
| 448 | expect = main.TRUE |
| 449 | main.step( "Verify unidirectional connectivity from %s to %s with tag %s" % ( str( src ), str( dst ), tag ) ) |
| 450 | if basedOnIp: |
| 451 | if ("v4" in src[0]): |
| 452 | pa = main.Network.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed ) |
| 453 | utilities.assert_equals( expect=expect, actual=pa, |
| 454 | onpass="IPv4 connectivity successfully tested", |
| 455 | onfail="IPv4 connectivity failed" ) |
| 456 | if ("v6" in src[0]): |
| 457 | pa = main.Network.pingallHostsUnidirectional( src, dst, ipv6=True, acceptableFailed=acceptableFailed ) |
| 458 | utilities.assert_equals( expect=expect, actual=pa, |
| 459 | onpass="IPv6 connectivity successfully tested", |
| 460 | onfail="IPv6 connectivity failed" ) |
| 461 | else: |
| 462 | pa = main.Network.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed ) |
| 463 | utilities.assert_equals( expect=expect, actual=pa, |
| 464 | onpass="IP connectivity successfully tested", |
| 465 | onfail="IP connectivity failed" ) |
| 466 | else: |
| 467 | # Verify ping between each host pair |
| 468 | hosts = entry[ 'hosts' ] |
| 469 | try: |
| 470 | expect = main.TRUE if str(expect).lower() == 'true' else main.FALSE |
| 471 | except: |
| 472 | expect = main.FALSE |
| 473 | main.step( "Verify full connectivity for %s with tag %s" % ( str( hosts ), tag ) ) |
| 474 | if basedOnIp: |
| 475 | if ("v4" in hosts[0]): |
Jonghwan Hyun | 812c70f | 2018-02-16 16:33:16 -0800 | [diff] [blame] | 476 | pa = utilities.retry( main.Network.pingallHosts, |
| 477 | main.FALSE if expect else main.TRUE, |
| 478 | args=(hosts,), |
| 479 | attempts=retryAttempts, |
| 480 | sleep=sleep ) |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 481 | utilities.assert_equals( expect=expect, actual=pa, |
| 482 | onpass="IPv4 connectivity successfully tested", |
| 483 | onfail="IPv4 connectivity failed" ) |
| 484 | if ("v6" in hosts[0]): |
| 485 | pa = main.Network.pingIpv6Hosts( hosts, acceptableFailed=acceptableFailed ) |
| 486 | utilities.assert_equals( expect=expect, actual=pa, |
| 487 | onpass="IPv6 connectivity successfully tested", |
| 488 | onfail="IPv6 connectivity failed" ) |
| 489 | else: |
You Wang | f19d9f4 | 2018-02-23 16:34:19 -0800 | [diff] [blame] | 490 | pa = main.Network.pingallHosts( hosts ) |
| 491 | utilities.assert_equals( expect=expect, actual=pa, |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 492 | onpass="IP connectivity successfully tested", |
| 493 | onfail="IP connectivity failed" ) |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 494 | if skipOnFail and pa != expect: |
| 495 | Testcaselib.saveOnosDiagnostics( main ) |
You Wang | 24ad2f5 | 2018-04-10 10:47:12 -0700 | [diff] [blame] | 496 | Testcaselib.cleanup( main, copyKarafLog=False ) |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 497 | main.skipCase() |
Andreas Pantelopoulos | f6ed501 | 2018-02-08 21:26:01 -0800 | [diff] [blame] | 498 | |
| 499 | if dumpflows: |
| 500 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
| 501 | "flows", |
| 502 | main.logdir, |
| 503 | tag + "_FlowsOn" ) |
| 504 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
| 505 | "groups", |
| 506 | main.logdir, |
| 507 | tag + "_GroupsOn" ) |
| 508 | |
| 509 | @staticmethod |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 510 | def killLink( main, end1, end2, switches, links ): |
| 511 | """ |
| 512 | end1,end2: identify the switches, ex.: 'leaf1', 'spine1' |
| 513 | switches, links: number of expected switches and links after linkDown, ex.: '4', '6' |
| 514 | Kill a link and verify ONOS can see the proper link change |
| 515 | """ |
| 516 | main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 517 | main.step( "Kill link between %s and %s" % ( end1, end2 ) ) |
You Wang | d587348 | 2018-01-24 12:30:00 -0800 | [diff] [blame] | 518 | LinkDown = main.Network.link( END1=end1, END2=end2, OPTION="down" ) |
| 519 | LinkDown = main.Network.link( END2=end1, END1=end2, OPTION="down" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 520 | main.log.info( |
| 521 | "Waiting %s seconds for link down to be discovered" % main.linkSleep ) |
| 522 | time.sleep( main.linkSleep ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 523 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 524 | main.FALSE, |
| 525 | kwargs={ 'numoswitch': switches, |
| 526 | 'numolink': links }, |
| 527 | attempts=10, |
| 528 | sleep=main.linkSleep ) |
| 529 | result = topology & LinkDown |
| 530 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 531 | onpass="Link down successful", |
| 532 | onfail="Failed to turn off link?" ) |
| 533 | |
| 534 | @staticmethod |
You Wang | eb717bc | 2018-04-05 17:36:11 -0700 | [diff] [blame] | 535 | def killLinkBatch( main, links, linksAfter, switches ): |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 536 | """ |
| 537 | links = list of links (src, dst) to bring down. |
| 538 | """ |
| 539 | |
| 540 | main.step("Killing a batch of links {0}".format(links)) |
| 541 | |
| 542 | for end1, end2 in links: |
| 543 | main.Network.link( END1=end1, END2=end2, OPTION="down") |
| 544 | main.Network.link( END1=end2, END2=end1, OPTION="down") |
| 545 | |
| 546 | main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 547 | main.log.info( |
| 548 | "Waiting %s seconds for links down to be discovered" % main.linkSleep ) |
| 549 | time.sleep( main.linkSleep ) |
| 550 | |
| 551 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
| 552 | main.FALSE, |
| 553 | kwargs={ 'numoswitch': switches, |
| 554 | 'numolink': linksAfter }, |
| 555 | attempts=10, |
| 556 | sleep=main.linkSleep ) |
| 557 | |
You Wang | 2854bce | 2018-03-30 10:15:32 -0700 | [diff] [blame] | 558 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 559 | onpass="Link batch down successful", |
| 560 | onfail="Link batch down failed" ) |
| 561 | |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 562 | @staticmethod |
You Wang | eb717bc | 2018-04-05 17:36:11 -0700 | [diff] [blame] | 563 | def restoreLinkBatch( main, links, linksAfter, switches ): |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 564 | """ |
| 565 | links = list of link (src, dst) to bring up again. |
| 566 | """ |
| 567 | |
| 568 | main.step("Restoring a batch of links {0}".format(links)) |
| 569 | |
| 570 | for end1, end2 in links: |
| 571 | main.Network.link( END1=end1, END2=end2, OPTION="up") |
| 572 | main.Network.link( END1=end2, END2=end1, OPTION="up") |
| 573 | |
| 574 | main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 575 | main.log.info( |
| 576 | "Waiting %s seconds for links down to be discovered" % main.linkSleep ) |
| 577 | time.sleep( main.linkSleep ) |
| 578 | |
| 579 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
| 580 | main.FALSE, |
| 581 | kwargs={ 'numoswitch': switches, |
| 582 | 'numolink': linksAfter }, |
| 583 | attempts=10, |
| 584 | sleep=main.linkSleep ) |
| 585 | |
You Wang | 2854bce | 2018-03-30 10:15:32 -0700 | [diff] [blame] | 586 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 587 | onpass="Link batch up successful", |
| 588 | onfail="Link batch up failed" ) |
| 589 | |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 590 | @staticmethod |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 591 | def restoreLink( main, end1, end2, switches, links, |
| 592 | portUp=False, dpid1='', dpid2='', port1='', port2='' ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 593 | """ |
| 594 | Params: |
| 595 | end1,end2: identify the end switches, ex.: 'leaf1', 'spine1' |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 596 | portUp: enable portstate after restoring link |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 597 | dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002' |
| 598 | port1, port2: respective port of the end switches that connects to the link, ex.:'1' |
| 599 | switches, links: number of expected switches and links after linkDown, ex.: '4', '6' |
| 600 | Kill a link and verify ONOS can see the proper link change |
| 601 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 602 | main.step( "Restore link between %s and %s" % ( end1, end2 ) ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 603 | result = False |
| 604 | count = 0 |
| 605 | while True: |
| 606 | count += 1 |
You Wang | d587348 | 2018-01-24 12:30:00 -0800 | [diff] [blame] | 607 | main.Network.link( END1=end1, END2=end2, OPTION="up" ) |
| 608 | main.Network.link( END2=end1, END1=end2, OPTION="up" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 609 | main.log.info( |
| 610 | "Waiting %s seconds for link up to be discovered" % main.linkSleep ) |
| 611 | time.sleep( main.linkSleep ) |
Pier | fb719b1 | 2016-09-19 14:51:44 -0700 | [diff] [blame] | 612 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 613 | if portUp: |
| 614 | ctrl.CLI.portstate( dpid=dpid1, port=port1, state='Enable' ) |
| 615 | ctrl.CLI.portstate( dpid=dpid2, port=port2, state='Enable' ) |
| 616 | time.sleep( main.linkSleep ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 617 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 618 | result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches, |
| 619 | numolink=links ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 620 | if count > 5 or result: |
| 621 | break |
| 622 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 623 | onpass="Link up successful", |
| 624 | onfail="Failed to bring link up" ) |
| 625 | |
| 626 | @staticmethod |
| 627 | def killSwitch( main, switch, switches, links ): |
| 628 | """ |
| 629 | Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6' |
| 630 | Completely kill a switch and verify ONOS can see the proper change |
| 631 | """ |
| 632 | main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 633 | switch = switch if isinstance( switch, list ) else [ switch ] |
| 634 | main.step( "Kill " + str( switch ) ) |
| 635 | for s in switch: |
| 636 | main.log.info( "Stopping " + s ) |
| 637 | main.Network.switch( SW=s, OPTION="stop" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 638 | # todo make this repeatable |
| 639 | main.log.info( "Waiting %s seconds for switch down to be discovered" % ( |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 640 | main.switchSleep ) ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 641 | time.sleep( main.switchSleep ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 642 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 643 | main.FALSE, |
| 644 | kwargs={ 'numoswitch': switches, |
| 645 | 'numolink': links }, |
| 646 | attempts=10, |
| 647 | sleep=main.switchSleep ) |
| 648 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 649 | onpass="Kill switch successful", |
| 650 | onfail="Failed to kill switch?" ) |
| 651 | |
| 652 | @staticmethod |
You Wang | ac363b9 | 2018-05-05 00:01:07 +0000 | [diff] [blame] | 653 | def recoverSwitch( main, switch, switches, links, rediscoverHosts=False ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 654 | """ |
| 655 | Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6' |
| 656 | Recover a switch and verify ONOS can see the proper change |
| 657 | """ |
| 658 | # todo make this repeatable |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 659 | switch = switch if isinstance( switch, list ) else [ switch ] |
| 660 | main.step( "Recovering " + str( switch ) ) |
| 661 | for s in switch: |
| 662 | main.log.info( "Starting " + s ) |
| 663 | main.Network.switch( SW=s, OPTION="start" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 664 | main.log.info( "Waiting %s seconds for switch up to be discovered" % ( |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 665 | main.switchSleep ) ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 666 | time.sleep( main.switchSleep ) |
Andreas Pantelopoulos | 74c7ff2 | 2018-05-01 15:42:02 -0700 | [diff] [blame] | 667 | if rediscoverHosts: |
| 668 | main.Network.discoverIpv4Hosts( main.internalIpv4Hosts ) |
| 669 | main.Network.discoverIpv6Hosts( main.internalIpv6Hosts ) |
| 670 | main.log.info( "Waiting %s seconds for hosts to get re-discovered" % ( |
| 671 | main.switchSleep ) ) |
| 672 | time.sleep( main.switchSleep ) |
| 673 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 674 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 675 | main.FALSE, |
| 676 | kwargs={ 'numoswitch': switches, |
| 677 | 'numolink': links }, |
| 678 | attempts=10, |
| 679 | sleep=main.switchSleep ) |
| 680 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 681 | onpass="Switch recovery successful", |
| 682 | onfail="Failed to recover switch?" ) |
| 683 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 684 | def portstate( main, dpid, port, state, switches, links ): |
| 685 | """ |
| 686 | Disable/enable a switch port using 'portstate' and verify ONOS can see the proper link change |
| 687 | Params: |
| 688 | dpid: dpid of the switch, ex.: 'of:0000000000000002' |
| 689 | port: port of the switch to disable/enable, ex.:'1' |
| 690 | state: disable or enable |
| 691 | switches, links: number of expected switches and links after link change, ex.: '4', '6' |
| 692 | """ |
| 693 | main.step( "Port %s on %s:%s" % ( state, dpid, port ) ) |
| 694 | main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state=state ) |
| 695 | main.log.info( "Waiting %s seconds for port %s to be discovered" % ( main.linkSleep, state ) ) |
| 696 | time.sleep( main.linkSleep ) |
| 697 | result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches, |
| 698 | numolink=links ) |
| 699 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 700 | onpass="Port %s successful" % state, |
| 701 | onfail="Port %s failed" % state ) |
| 702 | |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 703 | @staticmethod |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 704 | def cleanup( main, copyKarafLog=True, removeHostComponent=False ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 705 | """ |
| 706 | Stop Onos-cluster. |
| 707 | Stops Mininet |
| 708 | Copies ONOS log |
| 709 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 710 | try: |
| 711 | from tests.dependencies.utils import Utils |
| 712 | except ImportError: |
| 713 | main.log.error( "Utils not found exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 714 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 715 | try: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 716 | main.utils |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 717 | except ( NameError, AttributeError ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 718 | main.utils = Utils() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 719 | |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 720 | if hasattr( main, "scapyHosts" ): |
| 721 | scapyResult = main.TRUE |
| 722 | for host in main.scapyHosts: |
| 723 | scapyResult = host.stopScapy() and scapyResult |
| 724 | main.log.info( "Stopped Scapy Host: {0}".format( host.name ) ) |
| 725 | for host in main.scapyHosts: |
| 726 | scapyResult = main.Scapy.removeHostComponent( host.name ) and scapyResult |
| 727 | main.log.info( "Removed Scapy Host Component: {0}".format( host.name ) ) |
| 728 | main.scapyHosts = [] |
| 729 | |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 730 | if removeHostComponent: |
| 731 | for host in main.internalIpv4Hosts + main.internalIpv6Hosts + main.externalIpv4Hosts + main.externalIpv6Hosts: |
| 732 | if hasattr( main, host ): |
| 733 | main.Network.removeHostComponent( host ) |
| 734 | |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 735 | if hasattr( main, 'Mininet1' ): |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 736 | main.utils.mininetCleanup( main.Mininet1 ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 737 | |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 738 | if copyKarafLog: |
| 739 | main.utils.copyKarafLog( "CASE%d" % main.CurrentTestCaseNumber, before=True, includeCaseDesc=False ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 740 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 741 | for ctrl in main.Cluster.active(): |
| 742 | main.ONOSbench.onosStop( ctrl.ipAddress ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 743 | |
| 744 | @staticmethod |
| 745 | def killOnos( main, nodes, switches, links, expNodes ): |
| 746 | """ |
| 747 | Params: nodes, integer array with position of the ONOS nodes in the CLIs array |
| 748 | switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6' |
| 749 | Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change |
| 750 | """ |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 751 | main.step( "Killing ONOS instances with index(es): {}".format( nodes ) ) |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 752 | main.onosSleep = float( main.params[ 'timers' ][ 'OnosDiscovery' ] ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 753 | |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 754 | for i in nodes: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 755 | killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 756 | utilities.assert_equals( expect=main.TRUE, actual=killResult, |
| 757 | onpass="ONOS instance Killed", |
| 758 | onfail="Error killing ONOS instance" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 759 | main.Cluster.runningNodes[ i ].active = False |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 760 | time.sleep( main.onosSleep ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 761 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 762 | if len( nodes ) < main.Cluster.numCtrls: |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 763 | |
Jonghwan Hyun | 3731d6a | 2017-10-19 11:59:31 -0700 | [diff] [blame] | 764 | nodeResults = utilities.retry( main.Cluster.nodesCheck, |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 765 | False, |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 766 | attempts=10, |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 767 | sleep=10 ) |
| 768 | utilities.assert_equals( expect=True, actual=nodeResults, |
| 769 | onpass="Nodes check successful", |
| 770 | onfail="Nodes check NOT successful" ) |
| 771 | |
| 772 | if not nodeResults: |
| 773 | for i in nodes: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 774 | ctrl = main.Cluster.runningNodes[ i ] |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 775 | main.log.debug( "{} components not ACTIVE: \n{}".format( |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 776 | ctrl.name, |
| 777 | ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 778 | main.log.error( "Failed to kill ONOS, stopping test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 779 | main.cleanAndExit() |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 780 | |
Jonghwan Hyun | 76a02b7 | 2018-01-30 16:40:48 +0900 | [diff] [blame] | 781 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 782 | main.FALSE, |
| 783 | kwargs={ 'numoswitch': switches, |
| 784 | 'numolink': links, |
| 785 | 'numoctrl': expNodes }, |
| 786 | attempts=10, |
| 787 | sleep=12 ) |
| 788 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 789 | onpass="ONOS Instance down successful", |
| 790 | onfail="Failed to turn off ONOS Instance" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 791 | |
| 792 | @staticmethod |
| 793 | def recoverOnos( main, nodes, switches, links, expNodes ): |
| 794 | """ |
| 795 | Params: nodes, integer array with position of the ONOS nodes in the CLIs array |
| 796 | switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6' |
| 797 | Recover an ONOS instance and verify the ONOS cluster can see the proper change |
| 798 | """ |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 799 | main.step( "Recovering ONOS instances with index(es): {}".format( nodes ) ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 800 | [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ] |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 801 | time.sleep( main.onosSleep ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 802 | for i in nodes: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 803 | isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 804 | utilities.assert_equals( expect=main.TRUE, actual=isUp, |
| 805 | onpass="ONOS service is ready", |
| 806 | onfail="ONOS service did not start properly" ) |
| 807 | for i in nodes: |
| 808 | main.step( "Checking if ONOS CLI is ready" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 809 | ctrl = main.Cluster.runningNodes[ i ] |
Jonghwan Hyun | 76a02b7 | 2018-01-30 16:40:48 +0900 | [diff] [blame] | 810 | # ctrl.CLI.startCellCli() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 811 | cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress, |
| 812 | commandlineTimeout=60, |
| 813 | onosStartTimeout=100 ) |
| 814 | ctrl.active = True |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 815 | utilities.assert_equals( expect=main.TRUE, |
| 816 | actual=cliResult, |
| 817 | onpass="ONOS CLI is ready", |
| 818 | onfail="ONOS CLI is not ready" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 819 | |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 820 | main.step( "Checking ONOS nodes" ) |
Jonghwan Hyun | 3731d6a | 2017-10-19 11:59:31 -0700 | [diff] [blame] | 821 | nodeResults = utilities.retry( main.Cluster.nodesCheck, |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 822 | False, |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 823 | attempts=5, |
| 824 | sleep=10 ) |
| 825 | utilities.assert_equals( expect=True, actual=nodeResults, |
| 826 | onpass="Nodes check successful", |
| 827 | onfail="Nodes check NOT successful" ) |
| 828 | |
| 829 | if not nodeResults: |
| 830 | for i in nodes: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 831 | ctrl = main.Cluster.runningNodes[ i ] |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 832 | main.log.debug( "{} components not ACTIVE: \n{}".format( |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 833 | ctrl.name, |
| 834 | ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 835 | main.log.error( "Failed to start ONOS, stopping test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 836 | main.cleanAndExit() |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 837 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 838 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 839 | main.FALSE, |
| 840 | kwargs={ 'numoswitch': switches, |
| 841 | 'numolink': links, |
| 842 | 'numoctrl': expNodes }, |
| 843 | attempts=10, |
| 844 | sleep=12 ) |
| 845 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 846 | onpass="ONOS Instance down successful", |
| 847 | onfail="Failed to turn off ONOS Instance" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 848 | ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary, |
| 849 | main.FALSE, |
| 850 | attempts=10, |
| 851 | sleep=12 ) |
| 852 | if ready: |
| 853 | ready = main.TRUE |
| 854 | utilities.assert_equals( expect=main.TRUE, actual=ready, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 855 | onpass="ONOS summary command succeded", |
| 856 | onfail="ONOS summary command failed" ) |
| 857 | if not ready: |
| 858 | main.log.error( "ONOS startup failed!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 859 | main.cleanAndExit() |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 860 | |
| 861 | @staticmethod |
| 862 | def addHostCfg( main ): |
| 863 | """ |
| 864 | Adds Host Configuration to ONOS |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 865 | Updates expected state of the network ( pingChart ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 866 | """ |
| 867 | import json |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 868 | hostCfg = {} |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 869 | with open( main.configPath + main.forJson + "extra.json" ) as template: |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 870 | hostCfg = json.load( template ) |
| 871 | main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ] |
| 872 | main.step( "Pushing new configuration" ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 873 | mac, cfg = hostCfg[ 'hosts' ].popitem() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 874 | main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ], |
| 875 | subjectClass="hosts", |
| 876 | subjectKey=urllib.quote( mac, |
| 877 | safe='' ), |
| 878 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 879 | main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ] |
| 880 | main.step( "Pushing new configuration" ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 881 | mac, cfg = hostCfg[ 'hosts' ].popitem() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 882 | main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ], |
| 883 | subjectClass="hosts", |
| 884 | subjectKey=urllib.quote( mac, |
| 885 | safe='' ), |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 886 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 887 | main.pingChart.update( { 'vlan1': { "expect": "True", |
| 888 | "hosts": [ "olt1", "vsg1" ] } } ) |
| 889 | main.pingChart[ 'vlan5' ][ 'expect' ] = 0 |
| 890 | main.pingChart[ 'vlan10' ][ 'expect' ] = 0 |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 891 | ports = "[%s,%s]" % ( 5, 6 ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 892 | cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 893 | main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ), |
| 894 | subjectClass="apps", |
| 895 | subjectKey="org.onosproject.segmentrouting", |
| 896 | configKey="xconnect" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 897 | |
| 898 | @staticmethod |
| 899 | def delHostCfg( main ): |
| 900 | """ |
| 901 | Removest Host Configuration from ONOS |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 902 | Updates expected state of the network ( pingChart ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 903 | """ |
| 904 | import json |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 905 | hostCfg = {} |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 906 | with open( main.configPath + main.forJson + "extra.json" ) as template: |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 907 | hostCfg = json.load( template ) |
| 908 | main.step( "Removing host configuration" ) |
| 909 | main.pingChart[ 'ip' ][ 'expect' ] = 0 |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 910 | mac, cfg = hostCfg[ 'hosts' ].popitem() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 911 | main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts", |
| 912 | subjectKey=urllib.quote( |
| 913 | mac, |
| 914 | safe='' ), |
| 915 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 916 | main.step( "Removing configuration" ) |
| 917 | main.pingChart[ 'ip' ][ 'expect' ] = 0 |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 918 | mac, cfg = hostCfg[ 'hosts' ].popitem() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 919 | main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts", |
| 920 | subjectKey=urllib.quote( |
| 921 | mac, |
| 922 | safe='' ), |
| 923 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 924 | main.step( "Removing vlan configuration" ) |
| 925 | main.pingChart[ 'vlan1' ][ 'expect' ] = 0 |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 926 | main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps", |
| 927 | subjectKey="org.onosproject.segmentrouting", |
| 928 | configKey="xconnect" ) |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 929 | |
| 930 | @staticmethod |
| 931 | def verifyNetworkHostIp( main, attempts=10, sleep=10 ): |
| 932 | """ |
| 933 | Verifies IP address assignment from the hosts |
| 934 | """ |
| 935 | main.step( "Verify IP address assignment from hosts" ) |
| 936 | ipResult = main.TRUE |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 937 | main.Network.update() |
You Wang | 6acb7a4 | 2018-05-04 15:12:25 -0700 | [diff] [blame] | 938 | # Find out names of disconnected hosts |
| 939 | disconnectedHosts = [] |
| 940 | if hasattr( main, "disconnectedIpv4Hosts" ): |
| 941 | for host in main.disconnectedIpv4Hosts: |
| 942 | disconnectedHosts.append( host ) |
| 943 | if hasattr( main, "disconnectedIpv6Hosts" ): |
| 944 | for host in main.disconnectedIpv6Hosts: |
| 945 | disconnectedHosts.append( host ) |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 946 | for hostName, ip in main.expectedHosts[ "network" ].items(): |
You Wang | 6acb7a4 | 2018-05-04 15:12:25 -0700 | [diff] [blame] | 947 | # Exclude disconnected hosts |
| 948 | if hostName in disconnectedHosts: |
| 949 | main.log.debug( "Skip verifying IP for {} as it's disconnected".format( hostName ) ) |
| 950 | continue |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 951 | ipResult = ipResult and utilities.retry( main.Network.verifyHostIp, |
| 952 | main.FALSE, |
| 953 | kwargs={ 'hostList': [ hostName ], |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 954 | 'prefix': ip, |
| 955 | 'update': False }, |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 956 | attempts=attempts, |
| 957 | sleep=sleep ) |
| 958 | utilities.assert_equals( expect=main.TRUE, actual=ipResult, |
| 959 | onpass="Verify network host IP succeded", |
| 960 | onfail="Verify network host IP failed" ) |
| 961 | |
| 962 | @staticmethod |
| 963 | def verifyOnosHostIp( main, attempts=10, sleep=10 ): |
| 964 | """ |
| 965 | Verifies host IP address assignment from ONOS |
| 966 | """ |
| 967 | main.step( "Verify host IP address assignment in ONOS" ) |
| 968 | ipResult = main.TRUE |
You Wang | 6acb7a4 | 2018-05-04 15:12:25 -0700 | [diff] [blame] | 969 | # Find out IPs of disconnected hosts |
| 970 | disconnectedIps = [] |
| 971 | if hasattr( main, "disconnectedIpv4Hosts" ): |
| 972 | for host in main.disconnectedIpv4Hosts: |
| 973 | disconnectedIps.append( main.expectedHosts[ "network" ][ host ] ) |
| 974 | if hasattr( main, "disconnectedIpv6Hosts" ): |
| 975 | for host in main.disconnectedIpv6Hosts: |
| 976 | disconnectedIps.append( main.expectedHosts[ "network" ][ host ] ) |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 977 | for hostName, ip in main.expectedHosts[ "onos" ].items(): |
You Wang | 6acb7a4 | 2018-05-04 15:12:25 -0700 | [diff] [blame] | 978 | # Exclude disconnected hosts |
| 979 | if ip in disconnectedIps: |
| 980 | main.log.debug( "Skip verifying IP for {} as it's disconnected".format( ip ) ) |
| 981 | continue |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 982 | ipResult = ipResult and utilities.retry( main.Cluster.active( 0 ).verifyHostIp, |
| 983 | main.FALSE, |
| 984 | kwargs={ 'hostList': [ hostName ], |
| 985 | 'prefix': ip }, |
| 986 | attempts=attempts, |
| 987 | sleep=sleep ) |
| 988 | utilities.assert_equals( expect=main.TRUE, actual=ipResult, |
| 989 | onpass="Verify ONOS host IP succeded", |
| 990 | onfail="Verify ONOS host IP failed" ) |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 991 | |
Jonghwan Hyun | 812c70f | 2018-02-16 16:33:16 -0800 | [diff] [blame] | 992 | @staticmethod |
| 993 | def updateIntfCfg( main, connectPoint, ips=[], untagged=0, tagged=[], native=0 ): |
| 994 | """ |
| 995 | Description: |
| 996 | Updates interface configuration in ONOS, with given IP and vlan parameters |
| 997 | Required: |
| 998 | * connectPoint: connect point to update configuration |
| 999 | Optional: |
| 1000 | * ips: list of IP addresses, combined with '/xx' subnet representation, |
| 1001 | corresponding to 'ips' field in the configuration |
| 1002 | * untagged: vlan ID as an integer, corresponding to 'vlan-untagged' field in the configuration |
| 1003 | * tagged: integer list of vlan IDs, corresponding to 'vlan-tagged' field in the configuration |
| 1004 | * native: vlan ID as an integer, corresponding to 'vlan-native' field in the configuration |
| 1005 | """ |
| 1006 | cfg = dict() |
| 1007 | cfg[ "ports" ] = dict() |
| 1008 | cfg[ "ports" ][ connectPoint ] = dict() |
| 1009 | cfg[ "ports" ][ connectPoint ][ "interfaces" ] = [ dict() ] |
| 1010 | cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "ips" ] = ips |
| 1011 | if untagged > 0: |
| 1012 | cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-untagged" ] = untagged |
| 1013 | else: |
| 1014 | cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-tagged" ] = tagged |
| 1015 | if native > 0: |
| 1016 | cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-native" ] = native |
| 1017 | |
| 1018 | main.Cluster.active( 0 ).REST.setNetCfg( json.loads( json.dumps( cfg ) ) ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 1019 | |
| 1020 | @staticmethod |
| 1021 | def startScapyHosts( main ): |
| 1022 | """ |
| 1023 | Create host components and start Scapy CLIs |
| 1024 | """ |
| 1025 | main.step( "Start Scapy CLIs" ) |
| 1026 | main.scapyHostNames = main.params[ 'SCAPY' ][ 'HOSTNAMES' ].split( ',' ) |
| 1027 | main.scapyHosts = [] |
| 1028 | for hostName in main.scapyHostNames: |
| 1029 | main.Scapy.createHostComponent( hostName ) |
| 1030 | main.scapyHosts.append( getattr( main, hostName ) ) |
| 1031 | for host in main.scapyHosts: |
| 1032 | host.startHostCli() |
| 1033 | host.startScapy() |
| 1034 | host.updateSelf() |
| 1035 | main.log.debug( host.name ) |
| 1036 | main.log.debug( host.hostIp ) |
| 1037 | main.log.debug( host.hostMac ) |
| 1038 | |
| 1039 | @staticmethod |
You Wang | c564c6f | 2018-05-01 15:24:57 -0700 | [diff] [blame] | 1040 | def verifyMulticastTraffic( main, routeName, expect, skipOnFail=True, maxRetry=0 ): |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 1041 | """ |
| 1042 | Verify multicast traffic using scapy |
| 1043 | """ |
You Wang | c564c6f | 2018-05-01 15:24:57 -0700 | [diff] [blame] | 1044 | from tests.dependencies.topology import Topology |
| 1045 | try: |
| 1046 | main.topo |
| 1047 | except ( NameError, AttributeError ): |
| 1048 | main.topo = Topology() |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 1049 | routeData = main.multicastConfig[ routeName ] |
| 1050 | srcs = main.mcastRoutes[ routeName ][ "src" ] |
| 1051 | dsts = main.mcastRoutes[ routeName ][ "dst" ] |
| 1052 | main.log.info( "Sending multicast traffic from {} to {}".format( [ routeData[ "src" ][ i ][ "host" ] for i in srcs ], |
| 1053 | [ routeData[ "dst" ][ i ][ "host" ] for i in dsts ] ) ) |
| 1054 | for src in srcs: |
| 1055 | srcEntry = routeData[ "src" ][ src ] |
| 1056 | for dst in dsts: |
| 1057 | dstEntry = routeData[ "dst" ][ dst ] |
| 1058 | sender = getattr( main, srcEntry[ "host" ] ) |
| 1059 | receiver = getattr( main, dstEntry[ "host" ] ) |
| 1060 | main.Network.addRoute( str( srcEntry[ "host" ] ), |
| 1061 | str( routeData[ "group" ] ), |
| 1062 | str( srcEntry[ "interface" ] ), |
| 1063 | True if routeData[ "ipVersion" ] == 6 else False ) |
| 1064 | # Build the packet |
| 1065 | sender.buildEther( dst=str( srcEntry[ "Ether" ] ) ) |
| 1066 | if routeData[ "ipVersion" ] == 4: |
| 1067 | sender.buildIP( dst=str( routeData[ "group" ] ) ) |
| 1068 | elif routeData[ "ipVersion" ] == 6: |
| 1069 | sender.buildIPv6( dst=str( routeData[ "group" ] ) ) |
| 1070 | sender.buildUDP( ipVersion=routeData[ "ipVersion" ], dport=srcEntry[ "UDP" ] ) |
| 1071 | sIface = srcEntry[ "interface" ] |
| 1072 | dIface = dstEntry[ "interface" ] if "interface" in dstEntry.keys() else None |
| 1073 | pktFilter = srcEntry[ "filter" ] |
| 1074 | pkt = srcEntry[ "packet" ] |
| 1075 | # Send packet and check received packet |
| 1076 | expectedResult = expect.pop( 0 ) if isinstance( expect, list ) else expect |
You Wang | c564c6f | 2018-05-01 15:24:57 -0700 | [diff] [blame] | 1077 | t3Cmd = "t3-troubleshoot -vv -sp {} -et ipv{} -d {} -dm {}".format( srcEntry[ "port" ], routeData[ "ipVersion" ], |
| 1078 | routeData[ "group" ], srcEntry[ "Ether" ] ) |
| 1079 | trafficResult = main.topo.sendScapyPackets( sender, receiver, pktFilter, pkt, sIface, dIface, |
| 1080 | expectedResult, maxRetry, True, t3Cmd ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 1081 | utilities.assert_equals( expect=main.TRUE, |
| 1082 | actual=trafficResult, |
| 1083 | onpass="{} to {}: Pass".format( srcEntry[ "host" ], dstEntry[ "host" ] ), |
| 1084 | onfail="{} to {}: Fail".format( srcEntry[ "host" ], dstEntry[ "host" ] ) ) |
| 1085 | if skipOnFail and trafficResult != main.TRUE: |
| 1086 | Testcaselib.saveOnosDiagnostics( main ) |
| 1087 | Testcaselib.cleanup( main, copyKarafLog=False ) |
| 1088 | main.skipCase() |
| 1089 | |
| 1090 | @staticmethod |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 1091 | def verifyPing( main, srcList, dstList, ipv6=False, expect=True, wait=1, acceptableFailed=0, skipOnFail=True ): |
| 1092 | """ |
| 1093 | Verify reachability from each host in srcList to each host in dstList |
| 1094 | """ |
| 1095 | from tests.dependencies.topology import Topology |
| 1096 | try: |
| 1097 | main.topo |
| 1098 | except ( NameError, AttributeError ): |
| 1099 | main.topo = Topology() |
| 1100 | pingResult = main.topo.ping( srcList, dstList, ipv6, expect, wait, acceptableFailed, skipOnFail ) |
| 1101 | if not pingResult and skipOnFail: |
| 1102 | Testcaselib.saveOnosDiagnostics( main ) |
| 1103 | Testcaselib.cleanup( main, copyKarafLog=False, removeHostComponent=True ) |
| 1104 | main.skipCase() |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1105 | |
| 1106 | @staticmethod |
| 1107 | def verifyHostLocation( main, hostName, locations, ipv6=False ): |
| 1108 | """ |
| 1109 | Verify if the specified host is discovered by ONOS on the given locations |
| 1110 | Required: |
| 1111 | hostName: name of the host. ex. "h1" |
| 1112 | locations: expected locations of the host. ex. "of:0000000000000005/8" |
| 1113 | Could be a string or list |
| 1114 | Optional: |
| 1115 | ipv6: Use True for IPv6 only hosts |
| 1116 | Returns: |
| 1117 | main.TRUE if host is discovered on all locations provided, otherwise main.FALSE |
| 1118 | """ |
| 1119 | main.step( "Verify host {} is discovered at {}".format( hostName, locations ) ) |
| 1120 | hostIp = main.Network.getIPAddress( hostName, proto='IPV6' if ipv6 else 'IPV4' ) |
| 1121 | result = main.Cluster.active( 0 ).CLI.verifyHostLocation( hostIp, locations ) |
| 1122 | return result |