You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 1 | """ |
| 2 | CHOTestMonkey class |
| 3 | Author: you@onlab.us |
| 4 | """ |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 5 | import sys |
| 6 | import os |
| 7 | import re |
| 8 | import time |
| 9 | import json |
| 10 | import itertools |
| 11 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 12 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 13 | class CHOTestMonkey: |
| 14 | |
| 15 | def __init__( self ): |
| 16 | self.default = '' |
| 17 | |
| 18 | def CASE0( self, main ): |
| 19 | """ |
| 20 | Startup sequence: |
| 21 | apply cell <name> |
| 22 | git pull |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 23 | onos-package |
| 24 | onos-verify-cell |
| 25 | onos-uninstall |
| 26 | onos-install |
| 27 | onos-start-cli |
| 28 | Set IPv6 cfg parameters for Neighbor Discovery |
| 29 | start event scheduler |
| 30 | start event listener |
| 31 | """ |
| 32 | import time |
| 33 | from threading import Lock, Condition |
You Wang | 221db32 | 2016-06-03 15:45:52 -0700 | [diff] [blame] | 34 | from core.graph import Graph |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 35 | from tests.CHOTestMonkey.dependencies.elements.ONOSElement import Controller |
| 36 | from tests.CHOTestMonkey.dependencies.EventGenerator import EventGenerator |
| 37 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduler |
| 38 | |
| 39 | gitPull = main.params[ 'TEST' ][ 'autoPull' ] |
| 40 | onosPackage = main.params[ 'TEST' ][ 'package' ] |
| 41 | gitBranch = main.params[ 'TEST' ][ 'branch' ] |
| 42 | karafTimeout = main.params[ 'TEST' ][ 'karafCliTimeout' ] |
| 43 | main.enableIPv6 = main.params[ 'TEST' ][ 'IPv6' ] |
| 44 | main.enableIPv6 = True if main.enableIPv6 == "on" else False |
| 45 | main.caseSleep = int( main.params[ 'TEST' ][ 'caseSleep' ] ) |
You Wang | 2d32ef4 | 2017-03-03 14:09:44 -0800 | [diff] [blame] | 46 | main.numCtrls = int( main.params[ 'TEST' ][ 'numCtrl' ] ) |
| 47 | main.ONOSip = [] |
| 48 | main.AllONOSip = main.ONOSbench.getOnosIps() |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 49 | main.controllers = [] |
You Wang | 2d32ef4 | 2017-03-03 14:09:44 -0800 | [diff] [blame] | 50 | for i in range( 1, main.numCtrls + 1 ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 51 | main.ONOSip.append( main.AllONOSip[ i - 1 ] ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 52 | newController = Controller( i ) |
| 53 | newController.setCLI( getattr( main, 'ONOScli' + str( i ) ) ) |
| 54 | main.controllers.append( newController ) |
| 55 | main.devices = [] |
| 56 | main.links = [] |
| 57 | main.hosts = [] |
| 58 | main.intents = [] |
| 59 | main.enabledEvents = {} |
| 60 | for eventName in main.params[ 'EVENT' ].keys(): |
| 61 | if main.params[ 'EVENT' ][ eventName ][ 'status' ] == 'on': |
| 62 | main.enabledEvents[ int( main.params[ 'EVENT' ][ eventName ][ 'typeIndex' ] ) ] = eventName |
| 63 | print main.enabledEvents |
You Wang | 221db32 | 2016-06-03 15:45:52 -0700 | [diff] [blame] | 64 | main.graph = Graph() |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 65 | main.eventScheduler = EventScheduler() |
| 66 | main.eventGenerator = EventGenerator() |
| 67 | main.variableLock = Lock() |
| 68 | main.mininetLock = Lock() |
| 69 | main.ONOSbenchLock = Lock() |
| 70 | main.threadID = 0 |
| 71 | main.eventID = 0 |
| 72 | main.caseResult = main.TRUE |
| 73 | |
| 74 | main.case( "Set up test environment" ) |
| 75 | main.log.report( "Set up test environment" ) |
| 76 | main.log.report( "_______________________" ) |
| 77 | |
| 78 | main.step( "Apply Cell environment for ONOS" ) |
| 79 | if ( main.onoscell ): |
| 80 | cellName = main.onoscell |
| 81 | cellResult = main.ONOSbench.setCell( cellName ) |
| 82 | utilities.assert_equals( expect=main.TRUE, |
| 83 | actual=cellResult, |
| 84 | onpass="Test step PASS", |
| 85 | onfail="Test step FAIL" ) |
| 86 | else: |
| 87 | main.log.error( "Please provide onoscell option at TestON CLI to run CHO tests" ) |
| 88 | main.log.error( "Example: ~/TestON/bin/cli.py run CHOTestMonkey onoscell <cellName>" ) |
| 89 | main.cleanup() |
| 90 | main.exit() |
| 91 | |
| 92 | main.step( "Git checkout and pull " + gitBranch ) |
| 93 | if gitPull == 'on': |
| 94 | checkoutResult = main.ONOSbench.gitCheckout( gitBranch ) |
| 95 | pullResult = main.ONOSbench.gitPull() |
| 96 | cpResult = ( checkoutResult and pullResult ) |
| 97 | else: |
| 98 | checkoutResult = main.TRUE |
| 99 | pullResult = main.TRUE |
| 100 | main.log.info( "Skipped git checkout and pull as they are disabled in params file" ) |
| 101 | cpResult = ( checkoutResult and pullResult ) |
| 102 | utilities.assert_equals( expect=main.TRUE, |
| 103 | actual=cpResult, |
| 104 | onpass="Test step PASS", |
| 105 | onfail="Test step FAIL" ) |
| 106 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 107 | main.ONOSbench.getVersion( report=True ) |
| 108 | |
| 109 | main.step( "Create ONOS package" ) |
| 110 | if onosPackage == 'on': |
Jon Hall | bd60ea0 | 2016-08-23 10:03:59 -0700 | [diff] [blame] | 111 | packageResult = main.ONOSbench.buckBuild() |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 112 | else: |
| 113 | packageResult = main.TRUE |
| 114 | main.log.info( "Skipped onos package as it is disabled in params file" ) |
| 115 | utilities.assert_equals( expect=main.TRUE, |
| 116 | actual=packageResult, |
| 117 | onpass="Test step PASS", |
| 118 | onfail="Test step FAIL" ) |
| 119 | |
| 120 | main.step( "Uninstall ONOS package on all Nodes" ) |
| 121 | uninstallResult = main.TRUE |
You Wang | 2d32ef4 | 2017-03-03 14:09:44 -0800 | [diff] [blame] | 122 | for i in range( main.numCtrls ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 123 | main.log.info( "Uninstalling package on ONOS Node IP: " + main.ONOSip[ i ] ) |
| 124 | uResult = main.ONOSbench.onosUninstall( main.ONOSip[ i ] ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 125 | utilities.assert_equals( expect=main.TRUE, |
| 126 | actual=uResult, |
| 127 | onpass="Test step PASS", |
| 128 | onfail="Test step FAIL" ) |
| 129 | uninstallResult = ( uninstallResult and uResult ) |
| 130 | |
| 131 | main.step( "Install ONOS package on all Nodes" ) |
| 132 | installResult = main.TRUE |
You Wang | 2d32ef4 | 2017-03-03 14:09:44 -0800 | [diff] [blame] | 133 | for i in range( main.numCtrls ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 134 | main.log.info( "Installing package on ONOS Node IP: " + main.ONOSip[ i ] ) |
| 135 | iResult = main.ONOSbench.onosInstall( node=main.ONOSip[ i ] ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 136 | utilities.assert_equals( expect=main.TRUE, |
| 137 | actual=iResult, |
| 138 | onpass="Test step PASS", |
| 139 | onfail="Test step FAIL" ) |
| 140 | installResult = ( installResult and iResult ) |
| 141 | |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 142 | main.step( "Set up ONOS secure SSH" ) |
| 143 | secureSshResult = main.TRUE |
You Wang | 2d32ef4 | 2017-03-03 14:09:44 -0800 | [diff] [blame] | 144 | for i in range( main.numCtrls ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 145 | secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[ i ] ) |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 146 | utilities.assert_equals( expect=main.TRUE, actual=secureSshResult, |
| 147 | onpass="Test step PASS", |
| 148 | onfail="Test step FAIL" ) |
| 149 | |
You Wang | 0357c43 | 2017-01-09 16:13:33 -0800 | [diff] [blame] | 150 | time.sleep( 5 ) |
| 151 | main.step( "Starting ONOS service" ) |
| 152 | stopResult = main.TRUE |
| 153 | startResult = main.TRUE |
| 154 | onosIsUp = main.TRUE |
| 155 | for i in range( main.numCtrls ): |
| 156 | onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] ) |
| 157 | if onosIsUp == main.TRUE: |
| 158 | main.log.report( "ONOS instance is up and ready" ) |
| 159 | else: |
| 160 | main.log.report( "ONOS instance may not be up, stop and " + |
| 161 | "start ONOS again " ) |
| 162 | for i in range( main.numCtrls ): |
| 163 | stopResult = stopResult and \ |
| 164 | main.ONOSbench.onosStop( main.ONOSip[ i ] ) |
| 165 | for i in range( main.numCtrls ): |
| 166 | startResult = startResult and \ |
| 167 | main.ONOSbench.onosStart( main.ONOSip[ i ] ) |
| 168 | stepResult = onosIsUp and stopResult and startResult |
| 169 | utilities.assert_equals( expect=main.TRUE, |
| 170 | actual=stepResult, |
| 171 | onpass="ONOS service is ready", |
| 172 | onfail="ONOS service did not start properly" ) |
| 173 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 174 | main.step( "Start ONOS CLI on all nodes" ) |
| 175 | cliResult = main.TRUE |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 176 | startCliResult = main.TRUE |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 177 | pool = [] |
| 178 | for controller in main.controllers: |
| 179 | t = main.Thread( target=controller.startCLI, |
| 180 | threadID=main.threadID, |
| 181 | name="startOnosCli", |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 182 | args=[] ) |
| 183 | pool.append( t ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 184 | t.start() |
| 185 | main.threadID = main.threadID + 1 |
| 186 | for t in pool: |
| 187 | t.join() |
| 188 | startCliResult = startCliResult and t.result |
| 189 | if not startCliResult: |
| 190 | main.log.info( "ONOS CLI did not start up properly" ) |
| 191 | main.cleanup() |
| 192 | main.exit() |
| 193 | else: |
| 194 | main.log.info( "Successful CLI startup" ) |
| 195 | startCliResult = main.TRUE |
| 196 | utilities.assert_equals( expect=main.TRUE, |
| 197 | actual=startCliResult, |
| 198 | onpass="Test step PASS", |
| 199 | onfail="Test step FAIL" ) |
| 200 | |
| 201 | main.step( "Set IPv6 cfg parameters for Neighbor Discovery" ) |
| 202 | setIPv6CfgSleep = int( main.params[ 'TEST' ][ 'setIPv6CfgSleep' ] ) |
| 203 | if main.enableIPv6: |
| 204 | time.sleep( setIPv6CfgSleep ) |
You Wang | 5f4f36e | 2016-09-21 15:30:30 -0700 | [diff] [blame] | 205 | cfgResult1 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.incubator.net.neighbour.impl.NeighbourResolutionManager", |
| 206 | "ndpEnabled", |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 207 | "true" ) |
| 208 | time.sleep( setIPv6CfgSleep ) |
| 209 | cfgResult2 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.provider.host.impl.HostLocationProvider", |
You Wang | 092d9b2 | 2016-11-22 13:38:01 -0800 | [diff] [blame] | 210 | "useIpv6ND", |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 211 | "true" ) |
| 212 | else: |
| 213 | main.log.info( "Skipped setting IPv6 cfg parameters as it is disabled in params file" ) |
| 214 | cfgResult1 = main.TRUE |
| 215 | cfgResult2 = main.TRUE |
| 216 | cfgResult = cfgResult1 and cfgResult2 |
| 217 | utilities.assert_equals( expect=main.TRUE, |
| 218 | actual=cfgResult, |
| 219 | onpass="ipv6NeighborDiscovery cfg is set to true", |
| 220 | onfail="Failed to cfg set ipv6NeighborDiscovery" ) |
| 221 | |
| 222 | main.step( "Start a thread for the scheduler" ) |
| 223 | t = main.Thread( target=main.eventScheduler.startScheduler, |
| 224 | threadID=main.threadID, |
| 225 | name="startScheduler", |
| 226 | args=[] ) |
| 227 | t.start() |
| 228 | stepResult = main.TRUE |
| 229 | with main.variableLock: |
| 230 | main.threadID = main.threadID + 1 |
| 231 | |
| 232 | utilities.assert_equals( expect=main.TRUE, |
| 233 | actual=stepResult, |
| 234 | onpass="Test step PASS", |
| 235 | onfail="Test step FAIL" ) |
| 236 | |
| 237 | main.step( "Start a thread to listen to and handle network, ONOS and application events" ) |
| 238 | t = main.Thread( target=main.eventGenerator.startListener, |
| 239 | threadID=main.threadID, |
| 240 | name="startListener", |
| 241 | args=[] ) |
| 242 | t.start() |
| 243 | with main.variableLock: |
| 244 | main.threadID = main.threadID + 1 |
| 245 | |
| 246 | caseResult = installResult and uninstallResult and startCliResult and cfgResult |
| 247 | utilities.assert_equals( expect=main.TRUE, |
| 248 | actual=caseResult, |
| 249 | onpass="Set up test environment PASS", |
| 250 | onfail="Set up test environment FAIL" ) |
| 251 | |
| 252 | def CASE1( self, main ): |
| 253 | """ |
| 254 | Load Mininet topology and balances all switches |
| 255 | """ |
| 256 | import re |
| 257 | import time |
| 258 | import copy |
| 259 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 260 | main.topoIndex = "topo" + str( main.params[ 'TEST' ][ 'topo' ] ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 261 | |
| 262 | main.log.report( "Load Mininet topology and Balance all Mininet switches across controllers" ) |
| 263 | main.log.report( "________________________________________________________________________" ) |
| 264 | main.case( "Assign and Balance all Mininet switches across controllers" ) |
| 265 | |
| 266 | main.step( "Start Mininet topology" ) |
| 267 | newTopo = main.params[ 'TOPO' ][ main.topoIndex ][ 'fileName' ] |
| 268 | mininetDir = main.Mininet1.home + "/custom/" |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 269 | topoPath = main.testDir + "/" + main.TEST + "/dependencies/topologies/" + newTopo |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 270 | main.ONOSbench.secureCopy( main.Mininet1.user_name, main.Mininet1.ip_address, topoPath, mininetDir, direction="to" ) |
| 271 | topoPath = mininetDir + newTopo |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 272 | startStatus = main.Mininet1.startNet( topoFile=topoPath ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 273 | main.mininetSwitches = main.Mininet1.getSwitches() |
| 274 | main.mininetHosts = main.Mininet1.getHosts() |
You Wang | 55503a3 | 2016-06-27 15:11:40 -0700 | [diff] [blame] | 275 | main.mininetLinks = main.Mininet1.getLinks( timeout=60 ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 276 | utilities.assert_equals( expect=main.TRUE, |
| 277 | actual=startStatus, |
| 278 | onpass="Start Mininet topology test PASS", |
| 279 | onfail="Start Mininet topology test FAIL" ) |
| 280 | |
| 281 | main.step( "Assign switches to controllers" ) |
| 282 | switchMastership = main.TRUE |
| 283 | for switchName in main.mininetSwitches.keys(): |
You Wang | 2d32ef4 | 2017-03-03 14:09:44 -0800 | [diff] [blame] | 284 | main.Mininet1.assignSwController( sw=switchName, ip=main.ONOSip ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 285 | response = main.Mininet1.getSwController( switchName ) |
| 286 | print( "Response is " + str( response ) ) |
You Wang | 2d32ef4 | 2017-03-03 14:09:44 -0800 | [diff] [blame] | 287 | if re.search( "tcp:" + main.ONOSip[ 0 ], response ): |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 288 | switchMastership = switchMastership and main.TRUE |
| 289 | else: |
| 290 | switchMastership = main.FALSE |
| 291 | utilities.assert_equals( expect=main.TRUE, |
| 292 | actual=switchMastership, |
| 293 | onpass="Assign switches to controllers test PASS", |
| 294 | onfail="Assign switches to controllers test FAIL" ) |
| 295 | # Waiting here to make sure topology converges across all nodes |
| 296 | sleep = int( main.params[ 'TEST' ][ 'loadTopoSleep' ] ) |
| 297 | time.sleep( sleep ) |
| 298 | |
| 299 | main.step( "Balance devices across controllers" ) |
| 300 | balanceResult = main.ONOScli1.balanceMasters() |
| 301 | # giving some breathing time for ONOS to complete re-balance |
| 302 | time.sleep( sleep ) |
| 303 | |
| 304 | caseResult = ( startStatus and switchMastership and balanceResult ) |
| 305 | utilities.assert_equals( expect=main.TRUE, |
| 306 | actual=caseResult, |
| 307 | onpass="Starting new Att topology test PASS", |
| 308 | onfail="Starting new Att topology test FAIL" ) |
| 309 | |
| 310 | def CASE2( self, main ): |
| 311 | """ |
| 312 | Collect and store device and link data from ONOS |
| 313 | """ |
| 314 | import json |
| 315 | from tests.CHOTestMonkey.dependencies.elements.NetworkElement import Device, Link |
| 316 | |
| 317 | main.log.report( "Collect and Store topology details from ONOS" ) |
| 318 | main.log.report( "____________________________________________________________________" ) |
| 319 | main.case( "Collect and Store Topology Details from ONOS" ) |
| 320 | topoResult = main.TRUE |
| 321 | topologyOutput = main.ONOScli1.topology() |
| 322 | topologyResult = main.ONOScli1.getTopology( topologyOutput ) |
| 323 | ONOSDeviceNum = int( topologyResult[ 'devices' ] ) |
| 324 | ONOSLinkNum = int( topologyResult[ 'links' ] ) |
| 325 | mininetSwitchNum = len( main.mininetSwitches ) |
| 326 | mininetLinkNum = ( len( main.mininetLinks ) - len( main.mininetHosts ) ) * 2 |
| 327 | if mininetSwitchNum == ONOSDeviceNum and mininetLinkNum == ONOSLinkNum: |
| 328 | main.step( "Collect and store device data" ) |
| 329 | stepResult = main.TRUE |
| 330 | dpidToName = {} |
| 331 | for key, value in main.mininetSwitches.items(): |
| 332 | dpidToName[ 'of:' + str( value[ 'dpid' ] ) ] = key |
| 333 | devicesRaw = main.ONOScli1.devices() |
| 334 | devices = json.loads( devicesRaw ) |
| 335 | deviceInitIndex = 0 |
| 336 | for device in devices: |
| 337 | name = dpidToName[ device[ 'id' ] ] |
| 338 | newDevice = Device( deviceInitIndex, name, device[ 'id' ] ) |
| 339 | print newDevice |
| 340 | main.devices.append( newDevice ) |
| 341 | deviceInitIndex += 1 |
| 342 | utilities.assert_equals( expect=main.TRUE, |
| 343 | actual=stepResult, |
| 344 | onpass="Successfully collected and stored device data", |
| 345 | onfail="Failed to collect and store device data" ) |
| 346 | |
| 347 | main.step( "Collect and store link data" ) |
| 348 | stepResult = main.TRUE |
| 349 | linksRaw = main.ONOScli1.links() |
| 350 | links = json.loads( linksRaw ) |
| 351 | linkInitIndex = 0 |
| 352 | for link in links: |
| 353 | for device in main.devices: |
| 354 | if device.dpid == link[ 'src' ][ 'device' ]: |
| 355 | deviceA = device |
| 356 | elif device.dpid == link[ 'dst' ][ 'device' ]: |
| 357 | deviceB = device |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 358 | assert deviceA is not None and deviceB is not None |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 359 | newLink = Link( linkInitIndex, deviceA, link[ 'src' ][ 'port' ], deviceB, link[ 'dst' ][ 'port' ] ) |
| 360 | print newLink |
| 361 | main.links.append( newLink ) |
| 362 | linkInitIndex += 1 |
| 363 | # Set backward links and outgoing links of devices |
| 364 | for linkA in main.links: |
| 365 | linkA.deviceA.outgoingLinks.append( linkA ) |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 366 | if linkA.backwardLink is not None: |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 367 | continue |
| 368 | for linkB in main.links: |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 369 | if linkB.backwardLink is not None: |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 370 | continue |
| 371 | if linkA.deviceA == linkB.deviceB and\ |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 372 | linkA.deviceB == linkB.deviceA and\ |
| 373 | linkA.portA == linkB.portB and\ |
| 374 | linkA.portB == linkB.portA: |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 375 | linkA.setBackwardLink( linkB ) |
| 376 | linkB.setBackwardLink( linkA ) |
| 377 | utilities.assert_equals( expect=main.TRUE, |
| 378 | actual=stepResult, |
| 379 | onpass="Successfully collected and stored link data", |
| 380 | onfail="Failed to collect and store link data" ) |
| 381 | else: |
| 382 | main.log.info( "Devices (expected): %s, Links (expected): %s" % ( mininetSwitchNum, mininetLinkNum ) ) |
| 383 | main.log.info( "Devices (actual): %s, Links (actual): %s" % ( ONOSDeviceNum, ONOSLinkNum ) ) |
| 384 | topoResult = main.FALSE |
| 385 | |
| 386 | caseResult = topoResult |
| 387 | utilities.assert_equals( expect=main.TRUE, |
| 388 | actual=caseResult, |
| 389 | onpass="Saving ONOS topology data test PASS", |
| 390 | onfail="Saving ONOS topology data test FAIL" ) |
| 391 | |
| 392 | if not caseResult: |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 393 | main.log.info( "Topology does not match, exiting test..." ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 394 | main.cleanup() |
| 395 | main.exit() |
| 396 | |
| 397 | def CASE3( self, main ): |
| 398 | """ |
| 399 | Collect and store host data from ONOS |
| 400 | """ |
| 401 | import json |
| 402 | from tests.CHOTestMonkey.dependencies.elements.NetworkElement import Host |
| 403 | |
| 404 | main.log.report( "Collect and store host adta from ONOS" ) |
| 405 | main.log.report( "______________________________________________" ) |
| 406 | main.case( "Use fwd app and pingall to discover all the hosts, then collect and store host data" ) |
| 407 | |
| 408 | main.step( "Enable Reactive forwarding" ) |
| 409 | appResult = main.controllers[ 0 ].CLI.activateApp( "org.onosproject.fwd" ) |
| 410 | cfgResult1 = main.TRUE |
| 411 | cfgResult2 = main.TRUE |
| 412 | if main.enableIPv6: |
| 413 | cfgResult1 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.fwd.ReactiveForwarding", "ipv6Forwarding", "true" ) |
| 414 | cfgResult2 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.fwd.ReactiveForwarding", "matchIpv6Address", "true" ) |
| 415 | stepResult = appResult and cfgResult1 and cfgResult2 |
| 416 | utilities.assert_equals( expect=main.TRUE, |
| 417 | actual=stepResult, |
| 418 | onpass="Successfully enabled reactive forwarding", |
| 419 | onfail="Failed to enable reactive forwarding" ) |
| 420 | |
| 421 | main.step( "Discover hosts using pingall" ) |
| 422 | stepResult = main.TRUE |
| 423 | main.Mininet1.pingall() |
| 424 | if main.enableIPv6: |
| 425 | ping6Result = main.Mininet1.pingall( protocol="IPv6" ) |
| 426 | hosts = main.controllers[ 0 ].CLI.hosts() |
| 427 | hosts = json.loads( hosts ) |
| 428 | if not len( hosts ) == len( main.mininetHosts ): |
| 429 | stepResult = main.FALSE |
| 430 | utilities.assert_equals( expect=main.TRUE, |
| 431 | actual=stepResult, |
| 432 | onpass="Host discovery PASS", |
| 433 | onfail="Host discovery FAIL" ) |
| 434 | if not stepResult: |
| 435 | main.log.debug( hosts ) |
| 436 | main.cleanup() |
| 437 | main.exit() |
| 438 | |
| 439 | main.step( "Disable Reactive forwarding" ) |
| 440 | appResult = main.controllers[ 0 ].CLI.deactivateApp( "org.onosproject.fwd" ) |
| 441 | stepResult = appResult |
| 442 | utilities.assert_equals( expect=main.TRUE, |
| 443 | actual=stepResult, |
| 444 | onpass="Successfully deactivated fwd app", |
| 445 | onfail="Failed to deactivate fwd app" ) |
| 446 | |
| 447 | main.step( "Collect and store host data" ) |
| 448 | stepResult = main.TRUE |
| 449 | macToName = {} |
| 450 | for key, value in main.mininetHosts.items(): |
| 451 | macToName[ value[ 'interfaces' ][ 0 ][ 'mac' ].upper() ] = key |
| 452 | dpidToDevice = {} |
| 453 | for device in main.devices: |
| 454 | dpidToDevice[ device.dpid ] = device |
| 455 | hostInitIndex = 0 |
| 456 | for host in hosts: |
| 457 | name = macToName[ host[ 'mac' ] ] |
Jeremy Ronquillo | 0e538bc | 2017-06-13 15:16:09 -0700 | [diff] [blame] | 458 | dpid = host[ 'locations' ][ 0 ][ 'elementId' ] |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 459 | device = dpidToDevice[ dpid ] |
| 460 | newHost = Host( hostInitIndex, |
| 461 | name, host[ 'id' ], host[ 'mac' ], |
Jeremy Ronquillo | 0e538bc | 2017-06-13 15:16:09 -0700 | [diff] [blame] | 462 | device, host[ 'locations' ][ 0 ][ 'port' ], |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 463 | host[ 'vlan' ], host[ 'ipAddresses' ] ) |
| 464 | print newHost |
| 465 | main.hosts.append( newHost ) |
| 466 | main.devices[ device.index ].hosts.append( newHost ) |
| 467 | hostInitIndex += 1 |
| 468 | utilities.assert_equals( expect=main.TRUE, |
| 469 | actual=stepResult, |
| 470 | onpass="Successfully collected and stored host data", |
| 471 | onfail="Failed to collect and store host data" ) |
| 472 | |
| 473 | main.step( "Create one host component for each host and then start host cli" ) |
| 474 | for host in main.hosts: |
| 475 | main.Mininet1.createHostComponent( host.name ) |
| 476 | hostHandle = getattr( main, host.name ) |
| 477 | main.log.info( "Starting CLI on host " + str( host.name ) ) |
| 478 | startCLIResult = hostHandle.startHostCli() |
| 479 | host.setHandle( hostHandle ) |
| 480 | stepResult = startCLIResult |
| 481 | utilities.assert_equals( expect=main.TRUE, |
| 482 | actual=startCLIResult, |
| 483 | onpass="Host CLI started", |
| 484 | onfail="Failed to start host CLI" ) |
| 485 | |
| 486 | def CASE10( self, main ): |
| 487 | """ |
| 488 | Run all enabled checks |
| 489 | """ |
| 490 | import time |
| 491 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 492 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 493 | |
| 494 | main.log.report( "Run all enabled checks" ) |
| 495 | main.log.report( "__________________________________________________" ) |
| 496 | main.case( "Run all enabled checks" ) |
| 497 | main.step( "Run all enabled checks" ) |
| 498 | main.caseResult = main.TRUE |
| 499 | main.eventGenerator.triggerEvent( EventType().CHECK_ALL, EventScheduleMethod().RUN_BLOCK ) |
| 500 | # Wait for the scheduler to become idle before going to the next testcase |
| 501 | with main.eventScheduler.idleCondition: |
| 502 | while not main.eventScheduler.isIdle(): |
| 503 | main.eventScheduler.idleCondition.wait() |
| 504 | utilities.assert_equals( expect=main.TRUE, |
| 505 | actual=main.caseResult, |
| 506 | onpass="All enabled checks passed", |
| 507 | onfail="Not all enabled checks passed" ) |
| 508 | time.sleep( main.caseSleep ) |
| 509 | |
| 510 | def CASE20( self, main ): |
| 511 | """ |
| 512 | Bring down/up links and check topology and ping |
| 513 | """ |
| 514 | import time |
| 515 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 516 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 517 | |
| 518 | main.log.report( "Bring down/up links and check topology and ping" ) |
| 519 | main.log.report( "__________________________________________________" ) |
| 520 | main.case( "Bring down/up links and check topology and ping" ) |
| 521 | main.step( "Bring down/up links and check topology and ping" ) |
| 522 | main.caseResult = main.TRUE |
| 523 | linkToggleNum = int( main.params[ 'CASE20' ][ 'linkToggleNum' ] ) |
| 524 | linkDownUpInterval = int( main.params[ 'CASE20' ][ 'linkDownUpInterval' ] ) |
| 525 | for i in range( 0, linkToggleNum ): |
| 526 | main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_RANDOM_TOGGLE, EventScheduleMethod().RUN_BLOCK, linkDownUpInterval ) |
| 527 | with main.eventScheduler.idleCondition: |
| 528 | while not main.eventScheduler.isIdle(): |
| 529 | main.eventScheduler.idleCondition.wait() |
| 530 | utilities.assert_equals( expect=main.TRUE, |
| 531 | actual=main.caseResult, |
| 532 | onpass="Toggle network links test passed", |
| 533 | onfail="Toggle network links test failed" ) |
| 534 | time.sleep( main.caseSleep ) |
| 535 | |
| 536 | def CASE21( self, main ): |
| 537 | """ |
| 538 | Bring down/up a group of links and check topology and ping |
| 539 | """ |
| 540 | import time |
| 541 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 542 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 543 | |
| 544 | main.log.report( "Bring down/up a group of links and check topology and ping" ) |
| 545 | main.log.report( "__________________________________________________" ) |
| 546 | main.case( "Bring down/up a group of links and check topology and ping" ) |
| 547 | main.step( "Bring down/up a group of links and check topology and ping" ) |
| 548 | main.caseResult = main.TRUE |
| 549 | linkGroupSize = int( main.params[ 'CASE21' ][ 'linkGroupSize' ] ) |
| 550 | linkDownDownInterval = int( main.params[ 'CASE21' ][ 'linkDownDownInterval' ] ) |
| 551 | linkDownUpInterval = int( main.params[ 'CASE21' ][ 'linkDownUpInterval' ] ) |
| 552 | main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_GROUP_RANDOM_TOGGLE, EventScheduleMethod().RUN_BLOCK, linkGroupSize, linkDownDownInterval, linkDownUpInterval ) |
| 553 | with main.eventScheduler.idleCondition: |
| 554 | while not main.eventScheduler.isIdle(): |
| 555 | main.eventScheduler.idleCondition.wait() |
| 556 | utilities.assert_equals( expect=main.TRUE, |
| 557 | actual=main.caseResult, |
| 558 | onpass="Toggle network link group test passed", |
| 559 | onfail="Toggle network link group test failed" ) |
| 560 | time.sleep( main.caseSleep ) |
| 561 | |
| 562 | def CASE30( self, main ): |
| 563 | """ |
| 564 | Install host intents and check intent states and ping |
| 565 | """ |
| 566 | import time |
| 567 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 568 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 569 | |
| 570 | main.log.report( "Install host intents and check intent states and ping" ) |
| 571 | main.log.report( "__________________________________________________" ) |
| 572 | main.case( "Install host intents and check intent states and ping" ) |
| 573 | main.step( "Install host intents and check intent states and ping" ) |
| 574 | main.caseResult = main.TRUE |
| 575 | main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_ADD_ALL, EventScheduleMethod().RUN_BLOCK ) |
| 576 | with main.eventScheduler.idleCondition: |
| 577 | while not main.eventScheduler.isIdle(): |
| 578 | main.eventScheduler.idleCondition.wait() |
| 579 | utilities.assert_equals( expect=main.TRUE, |
| 580 | actual=main.caseResult, |
| 581 | onpass="Install host intents test passed", |
| 582 | onfail="Install host intents test failed" ) |
| 583 | time.sleep( main.caseSleep ) |
| 584 | |
| 585 | def CASE31( self, main ): |
| 586 | """ |
| 587 | Uninstall host intents and check intent states and ping |
| 588 | """ |
| 589 | import time |
| 590 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 591 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 592 | |
| 593 | main.log.report( "Uninstall host intents and check intent states and ping" ) |
| 594 | main.log.report( "__________________________________________________" ) |
| 595 | main.case( "Uninstall host intents and check intent states and ping" ) |
| 596 | main.step( "Uninstall host intents and check intent states and ping" ) |
| 597 | main.caseResult = main.TRUE |
| 598 | main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_DEL_ALL, EventScheduleMethod().RUN_BLOCK ) |
| 599 | with main.eventScheduler.idleCondition: |
| 600 | while not main.eventScheduler.isIdle(): |
| 601 | main.eventScheduler.idleCondition.wait() |
| 602 | utilities.assert_equals( expect=main.TRUE, |
| 603 | actual=main.caseResult, |
| 604 | onpass="Uninstall host intents test passed", |
| 605 | onfail="Uninstall host intents test failed" ) |
| 606 | time.sleep( main.caseSleep ) |
| 607 | |
| 608 | def CASE32( self, main ): |
| 609 | """ |
| 610 | Install point intents and check intent states and ping |
| 611 | """ |
| 612 | import time |
| 613 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 614 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 615 | |
| 616 | main.log.report( "Install point intents and check intent states and ping" ) |
| 617 | main.log.report( "__________________________________________________" ) |
| 618 | main.case( "Install point intents and check intent states and ping" ) |
| 619 | main.step( "Install point intents and check intent states and ping" ) |
| 620 | main.caseResult = main.TRUE |
| 621 | main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_ADD_ALL, EventScheduleMethod().RUN_BLOCK ) |
| 622 | with main.eventScheduler.idleCondition: |
| 623 | while not main.eventScheduler.isIdle(): |
| 624 | main.eventScheduler.idleCondition.wait() |
| 625 | utilities.assert_equals( expect=main.TRUE, |
| 626 | actual=main.caseResult, |
| 627 | onpass="Install point intents test passed", |
| 628 | onfail="Install point intents test failed" ) |
| 629 | time.sleep( main.caseSleep ) |
| 630 | |
| 631 | def CASE33( self, main ): |
| 632 | """ |
| 633 | Uninstall point intents and check intent states and ping |
| 634 | """ |
| 635 | import time |
| 636 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 637 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 638 | |
| 639 | main.log.report( "Uninstall point intents and check intent states and ping" ) |
| 640 | main.log.report( "__________________________________________________" ) |
| 641 | main.case( "Uninstall point intents and check intent states and ping" ) |
| 642 | main.step( "Uninstall point intents and check intent states and ping" ) |
| 643 | main.caseResult = main.TRUE |
| 644 | main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_DEL_ALL, EventScheduleMethod().RUN_BLOCK ) |
| 645 | with main.eventScheduler.idleCondition: |
| 646 | while not main.eventScheduler.isIdle(): |
| 647 | main.eventScheduler.idleCondition.wait() |
| 648 | utilities.assert_equals( expect=main.TRUE, |
| 649 | actual=main.caseResult, |
| 650 | onpass="Uninstall point intents test passed", |
| 651 | onfail="Uninstall point intents test failed" ) |
| 652 | time.sleep( main.caseSleep ) |
| 653 | |
| 654 | def CASE40( self, main ): |
| 655 | """ |
| 656 | Randomly bring down one ONOS node |
| 657 | """ |
| 658 | import time |
| 659 | import random |
| 660 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 661 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 662 | |
| 663 | main.log.report( "Randomly bring down one ONOS node" ) |
| 664 | main.log.report( "__________________________________________________" ) |
| 665 | main.case( "Randomly bring down one ONOS node" ) |
| 666 | main.step( "Randomly bring down one ONOS node" ) |
| 667 | main.caseResult = main.TRUE |
| 668 | availableControllers = [] |
| 669 | for controller in main.controllers: |
| 670 | if controller.isUp(): |
| 671 | availableControllers.append( controller.index ) |
| 672 | if len( availableControllers ) == 0: |
| 673 | main.log.warn( "No available controllers" ) |
| 674 | main.caseResult = main.FALSE |
| 675 | else: |
| 676 | index = random.sample( availableControllers, 1 ) |
| 677 | main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_DOWN, EventScheduleMethod().RUN_BLOCK, index[ 0 ] ) |
| 678 | with main.eventScheduler.idleCondition: |
| 679 | while not main.eventScheduler.isIdle(): |
| 680 | main.eventScheduler.idleCondition.wait() |
| 681 | utilities.assert_equals( expect=main.TRUE, |
| 682 | actual=main.caseResult, |
| 683 | onpass="Randomly bring down ONOS test passed", |
| 684 | onfail="Randomly bring down ONOS test failed" ) |
| 685 | time.sleep( main.caseSleep ) |
| 686 | |
| 687 | def CASE41( self, main ): |
| 688 | """ |
| 689 | Randomly bring up one ONOS node that is down |
| 690 | """ |
| 691 | import time |
| 692 | import random |
| 693 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 694 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 695 | |
| 696 | main.log.report( "Randomly bring up one ONOS node that is down" ) |
| 697 | main.log.report( "__________________________________________________" ) |
| 698 | main.case( "Randomly bring up one ONOS node that is down" ) |
| 699 | main.step( "Randomly bring up one ONOS node that is down" ) |
| 700 | main.caseResult = main.TRUE |
| 701 | targetControllers = [] |
| 702 | for controller in main.controllers: |
| 703 | if not controller.isUp(): |
| 704 | targetControllers.append( controller.index ) |
| 705 | if len( targetControllers ) == 0: |
| 706 | main.log.warn( "All controllers are up" ) |
| 707 | main.caseResult = main.FALSE |
| 708 | else: |
| 709 | index = random.sample( targetControllers, 1 ) |
| 710 | main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_UP, EventScheduleMethod().RUN_BLOCK, index[ 0 ] ) |
| 711 | with main.eventScheduler.idleCondition: |
| 712 | while not main.eventScheduler.isIdle(): |
| 713 | main.eventScheduler.idleCondition.wait() |
| 714 | utilities.assert_equals( expect=main.TRUE, |
| 715 | actual=main.caseResult, |
| 716 | onpass="Randomly bring up ONOS test passed", |
| 717 | onfail="Randomly bring up ONOS test failed" ) |
| 718 | time.sleep( main.caseSleep ) |
| 719 | |
| 720 | def CASE50( self, main ): |
| 721 | """ |
| 722 | Set FlowObjective to True |
| 723 | """ |
| 724 | import time |
| 725 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 726 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 727 | |
| 728 | main.log.report( "Set FlowObjective to True" ) |
| 729 | main.log.report( "__________________________________________________" ) |
| 730 | main.case( "Set FlowObjective to True" ) |
| 731 | main.step( "Set FlowObjective to True" ) |
| 732 | main.caseResult = main.TRUE |
| 733 | main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'true' ) |
| 734 | with main.eventScheduler.idleCondition: |
| 735 | while not main.eventScheduler.isIdle(): |
| 736 | main.eventScheduler.idleCondition.wait() |
| 737 | utilities.assert_equals( expect=main.TRUE, |
| 738 | actual=main.caseResult, |
| 739 | onpass="Set FlowObjective test passed", |
| 740 | onfail="Set FlowObjective test failed" ) |
| 741 | time.sleep( main.caseSleep ) |
| 742 | |
| 743 | def CASE51( self, main ): |
| 744 | """ |
| 745 | Set FlowObjective to False |
| 746 | """ |
| 747 | import time |
| 748 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 749 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 750 | |
| 751 | main.log.report( "Set FlowObjective to False" ) |
| 752 | main.log.report( "__________________________________________________" ) |
| 753 | main.case( "Set FlowObjective to False" ) |
| 754 | main.step( "Set FlowObjective to False" ) |
| 755 | main.caseResult = main.TRUE |
| 756 | main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'false' ) |
| 757 | with main.eventScheduler.idleCondition: |
| 758 | while not main.eventScheduler.isIdle(): |
| 759 | main.eventScheduler.idleCondition.wait() |
| 760 | utilities.assert_equals( expect=main.TRUE, |
| 761 | actual=main.caseResult, |
| 762 | onpass="Set FlowObjective test passed", |
| 763 | onfail="Set FlowObjective test failed" ) |
| 764 | time.sleep( main.caseSleep ) |
| 765 | |
| 766 | def CASE60( self, main ): |
| 767 | """ |
| 768 | Balance device masters |
| 769 | """ |
| 770 | import time |
| 771 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 772 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 773 | |
| 774 | main.log.report( "Balance device masters" ) |
| 775 | main.log.report( "__________________________________________________" ) |
| 776 | main.case( "Balance device masters" ) |
| 777 | main.step( "Balance device masters" ) |
| 778 | main.caseResult = main.TRUE |
| 779 | main.eventGenerator.triggerEvent( EventType().ONOS_BALANCE_MASTERS, EventScheduleMethod().RUN_BLOCK ) |
| 780 | with main.eventScheduler.idleCondition: |
| 781 | while not main.eventScheduler.isIdle(): |
| 782 | main.eventScheduler.idleCondition.wait() |
| 783 | utilities.assert_equals( expect=main.TRUE, |
| 784 | actual=main.caseResult, |
| 785 | onpass="Balance masters test passed", |
| 786 | onfail="Balance masters test failed" ) |
| 787 | time.sleep( main.caseSleep ) |
| 788 | |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 789 | def CASE70( self, main ): |
| 790 | """ |
| 791 | Randomly generate events |
| 792 | """ |
| 793 | import time |
| 794 | import random |
| 795 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 796 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 797 | |
| 798 | main.log.report( "Randomly generate events" ) |
| 799 | main.log.report( "__________________________________________________" ) |
| 800 | main.case( "Randomly generate events" ) |
| 801 | main.step( "Randomly generate events" ) |
| 802 | main.caseResult = main.TRUE |
| 803 | sleepSec = int( main.params[ 'CASE70' ][ 'sleepSec' ] ) |
| 804 | hostIntentNum = 0 |
| 805 | pointIntentNum = 0 |
| 806 | downDeviceNum = 0 |
| 807 | downLinkNum = 0 |
You Wang | f6e98a8 | 2016-11-14 14:46:49 -0800 | [diff] [blame] | 808 | flowObj = False |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 809 | upControllers = [ 1, 2, 3 ] |
| 810 | while True: |
| 811 | events = [] |
You Wang | f6e98a8 | 2016-11-14 14:46:49 -0800 | [diff] [blame] | 812 | for i in range( int( main.params[ 'CASE70' ][ 'toggleFlowObj' ] ) ): |
| 813 | events.append( 'toggle-flowobj' ) |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 814 | for i in range( int( main.params[ 'CASE70' ][ 'addHostIntentWeight' ] ) ): |
| 815 | events.append( 'add-host-intent' ) |
| 816 | for i in range( int( main.params[ 'CASE70' ][ 'addPointIntentWeight' ] ) ): |
| 817 | events.append( 'add-point-intent' ) |
| 818 | for i in range( int( main.params[ 'CASE70' ][ 'linkDownWeight' ] ) ): |
| 819 | events.append( 'link-down' ) |
| 820 | for i in range( int( main.params[ 'CASE70' ][ 'deviceDownWeight' ] ) ): |
| 821 | events.append( 'device-down' ) |
| 822 | for i in range( int( pow( hostIntentNum, 1.5 ) / 100 ) ): |
| 823 | events.append( 'del-host-intent' ) |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 824 | for i in range( int( pow( pointIntentNum, 1.5 ) / 100 ) ): |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 825 | events.append( 'del-point-intent' ) |
| 826 | for i in range( pow( 2, downLinkNum ) - 1 ): |
| 827 | events.append( 'link-up' ) |
| 828 | for i in range( pow( 5, downDeviceNum ) - 1 ): |
| 829 | events.append( 'device-up' ) |
| 830 | main.log.debug( events ) |
| 831 | event = random.sample( events, 1 )[ 0 ] |
| 832 | if event == 'add-host-intent': |
| 833 | n = random.randint( 5, 50 ) |
| 834 | for i in range( n ): |
| 835 | cliIndex = random.sample( upControllers, 1 )[ 0 ] |
You Wang | c848af1 | 2016-07-14 09:53:58 -0700 | [diff] [blame] | 836 | main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_ADD, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex ) |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 837 | hostIntentNum += 1 |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 838 | elif event == 'del-host-intent': |
| 839 | n = random.randint( 5, hostIntentNum ) |
| 840 | for i in range( n ): |
| 841 | cliIndex = random.sample( upControllers, 1 )[ 0 ] |
You Wang | c848af1 | 2016-07-14 09:53:58 -0700 | [diff] [blame] | 842 | main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_DEL, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex ) |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 843 | hostIntentNum -= 1 |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 844 | elif event == 'add-point-intent': |
| 845 | n = random.randint( 5, 50 ) |
| 846 | for i in range( n ): |
| 847 | cliIndex = random.sample( upControllers, 1 )[ 0 ] |
You Wang | c848af1 | 2016-07-14 09:53:58 -0700 | [diff] [blame] | 848 | main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_ADD, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex, 'bidirectional' ) |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 849 | pointIntentNum += 2 |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 850 | elif event == 'del-point-intent': |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 851 | n = random.randint( 5, pointIntentNum / 2 ) |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 852 | for i in range( n ): |
| 853 | cliIndex = random.sample( upControllers, 1 )[ 0 ] |
You Wang | c848af1 | 2016-07-14 09:53:58 -0700 | [diff] [blame] | 854 | main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_DEL, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex, 'bidirectional' ) |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 855 | pointIntentNum -= 2 |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 856 | elif event == 'link-down': |
| 857 | main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_DOWN, EventScheduleMethod().RUN_BLOCK, 'random', 'random' ) |
| 858 | downLinkNum += 1 |
| 859 | elif event == 'link-up': |
| 860 | main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_UP, EventScheduleMethod().RUN_BLOCK, 'random', 'random' ) |
| 861 | downLinkNum -= 1 |
| 862 | elif event == 'device-down': |
| 863 | main.eventGenerator.triggerEvent( EventType().NETWORK_DEVICE_DOWN, EventScheduleMethod().RUN_BLOCK, 'random' ) |
| 864 | downDeviceNum += 1 |
| 865 | elif event == 'device-up': |
| 866 | main.eventGenerator.triggerEvent( EventType().NETWORK_DEVICE_UP, EventScheduleMethod().RUN_BLOCK, 'random' ) |
| 867 | downDeviceNum -= 1 |
You Wang | f6e98a8 | 2016-11-14 14:46:49 -0800 | [diff] [blame] | 868 | elif event == 'toggle-flowobj': |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 869 | if not flowObj: |
You Wang | f6e98a8 | 2016-11-14 14:46:49 -0800 | [diff] [blame] | 870 | main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'true' ) |
| 871 | else: |
| 872 | main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'false' ) |
| 873 | flowObj = not flowObj |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 874 | else: |
| 875 | pass |
| 876 | main.eventGenerator.triggerEvent( EventType().CHECK_TOPO, EventScheduleMethod().RUN_NON_BLOCK ) |
| 877 | main.eventGenerator.triggerEvent( EventType().CHECK_ONOS, EventScheduleMethod().RUN_NON_BLOCK ) |
| 878 | main.eventGenerator.triggerEvent( EventType().CHECK_TRAFFIC, EventScheduleMethod().RUN_NON_BLOCK ) |
| 879 | main.eventGenerator.triggerEvent( EventType().CHECK_FLOW, EventScheduleMethod().RUN_NON_BLOCK ) |
| 880 | main.eventGenerator.triggerEvent( EventType().CHECK_INTENT, EventScheduleMethod().RUN_NON_BLOCK ) |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 881 | with main.eventScheduler.idleCondition: |
| 882 | while not main.eventScheduler.isIdle(): |
| 883 | main.eventScheduler.idleCondition.wait() |
You Wang | 5f4f36e | 2016-09-21 15:30:30 -0700 | [diff] [blame] | 884 | time.sleep( sleepSec ) |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 885 | utilities.assert_equals( expect=main.TRUE, |
| 886 | actual=main.caseResult, |
| 887 | onpass="Randomly generate events test passed", |
| 888 | onfail="Randomly generate events test failed" ) |
| 889 | time.sleep( main.caseSleep ) |
| 890 | |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 891 | def CASE80( self, main ): |
| 892 | """ |
| 893 | Replay events from log file |
| 894 | """ |
| 895 | import time |
| 896 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 897 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 898 | |
| 899 | main.log.report( "Replay events from log file" ) |
| 900 | main.log.report( "__________________________________________________" ) |
| 901 | main.case( "Replay events from log file" ) |
| 902 | main.step( "Replay events from log file" ) |
| 903 | main.caseResult = main.TRUE |
| 904 | try: |
| 905 | f = open( main.params[ 'CASE80' ][ 'filePath' ], 'r' ) |
| 906 | for line in f.readlines(): |
| 907 | if 'CHOTestMonkey' in line and 'Event recorded' in line: |
| 908 | line = line.split() |
| 909 | eventIndex = int( line[ 9 ] ) |
| 910 | eventName = line[ 10 ] |
| 911 | args = line[ 11: ] |
| 912 | assert eventName.startswith( 'CHECK' )\ |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 913 | or eventName.startswith( 'NETWORK' )\ |
| 914 | or eventName.startswith( 'APP' )\ |
| 915 | or eventName.startswith( 'ONOS' ) |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 916 | if main.params[ 'CASE80' ][ 'skipChecks' ] == 'on' and eventName.startswith( 'CHECK' ): |
| 917 | continue |
| 918 | with main.eventScheduler.idleCondition: |
| 919 | while not main.eventScheduler.isIdle(): |
| 920 | main.eventScheduler.idleCondition.wait() |
| 921 | main.eventGenerator.triggerEvent( eventIndex, EventScheduleMethod().RUN_BLOCK, *args ) |
| 922 | time.sleep( float( main.params[ 'CASE80' ][ 'sleepTime' ] ) ) |
| 923 | except Exception as e: |
| 924 | print e |
| 925 | utilities.assert_equals( expect=main.TRUE, |
| 926 | actual=main.caseResult, |
| 927 | onpass="Replay from log file passed", |
| 928 | onfail="Replay from log file failed" ) |
| 929 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 930 | def CASE90( self, main ): |
| 931 | """ |
| 932 | Sleep for some time |
| 933 | """ |
| 934 | import time |
| 935 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 936 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 937 | |
| 938 | main.log.report( "Sleep for some time" ) |
| 939 | main.log.report( "__________________________________________________" ) |
| 940 | main.case( "Sleep for some time" ) |
| 941 | main.step( "Sleep for some time" ) |
| 942 | main.caseResult = main.TRUE |
| 943 | sleepSec = int( main.params[ 'CASE90' ][ 'sleepSec' ] ) |
| 944 | main.eventGenerator.triggerEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, sleepSec ) |
| 945 | with main.eventScheduler.idleCondition: |
| 946 | while not main.eventScheduler.isIdle(): |
| 947 | main.eventScheduler.idleCondition.wait() |
| 948 | utilities.assert_equals( expect=main.TRUE, |
| 949 | actual=main.caseResult, |
| 950 | onpass="Sleep test passed", |
| 951 | onfail="Sleep test failed" ) |
| 952 | time.sleep( main.caseSleep ) |
| 953 | |
| 954 | def CASE100( self, main ): |
| 955 | """ |
| 956 | Do something else? |
| 957 | """ |
| 958 | import time |
| 959 | |
| 960 | main.log.report( "Do something else?" ) |
| 961 | main.log.report( "__________________________________________________" ) |
| 962 | main.case( "..." ) |
| 963 | |
| 964 | main.step( "Wait until the test stops" ) |
| 965 | |
| 966 | main.caseResult = main.TRUE |
| 967 | utilities.assert_equals( expect=main.TRUE, |
| 968 | actual=main.caseResult, |
| 969 | onpass="Test PASS", |
| 970 | onfail="Test FAIL" ) |
| 971 | |
| 972 | testDuration = int( main.params[ 'TEST' ][ 'testDuration' ] ) |
| 973 | time.sleep( testDuration ) |