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