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