suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 1 | class COMPflow: |
| 2 | |
| 3 | def __init__( self ): |
| 4 | self.default = '' |
| 5 | |
| 6 | def CASE1( self, main ): |
| 7 | import time |
| 8 | import os |
| 9 | import imp |
| 10 | |
| 11 | """ |
| 12 | - Construct tests variables |
| 13 | - GIT ( optional ) |
| 14 | - Checkout ONOS master branch |
| 15 | - Pull latest ONOS code |
| 16 | - Building ONOS ( optional ) |
| 17 | - Install ONOS package |
| 18 | - Build ONOS package |
| 19 | """ |
| 20 | |
| 21 | main.case( "Constructing test variables and building ONOS package" ) |
| 22 | main.step( "Constructing test variables" ) |
| 23 | stepResult = main.FALSE |
| 24 | |
| 25 | # Test variables |
| 26 | main.testOnDirectory = os.path.dirname( os.getcwd ( ) ) |
| 27 | main.cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 28 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
| 29 | gitBranch = main.params[ 'GIT' ][ 'branch' ] |
| 30 | gitPull = main.params[ 'GIT' ][ 'pull' ] |
| 31 | main.ONOSport = main.params[ 'CTRL' ][ 'port' ] |
| 32 | main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] ) |
| 33 | main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] ) |
| 34 | main.startMNSleep = int( main.params[ 'SLEEP' ][ 'startMN' ] ) |
| 35 | main.addFlowSleep = int( main.params[ 'SLEEP' ][ 'addFlow' ] ) |
| 36 | main.delFlowSleep = int( main.params[ 'SLEEP' ][ 'delFlow' ] ) |
| 37 | main.debug = main.params['DEBUG'] |
| 38 | #main.swDPID = main.params[ 'TEST' ][ 'swDPID' ] |
| 39 | main.cellData = {} # for creating cell file |
| 40 | main.CLIs = [] |
| 41 | main.ONOSip = [] |
| 42 | |
| 43 | main.debug = True if "on" in main.debug else False |
| 44 | |
| 45 | main.ONOSip = main.ONOSbench.getOnosIps() |
| 46 | |
| 47 | # Assigning ONOS cli handles to a list |
| 48 | for i in range( 1, main.maxNodes + 1 ): |
| 49 | main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) ) |
| 50 | |
| 51 | |
| 52 | if main.CLIs: |
| 53 | stepResult = main.TRUE |
| 54 | else: |
| 55 | main.log.error( "Did not properly created list of ONOS CLI handle" ) |
| 56 | stepResult = main.FALSE |
| 57 | |
| 58 | utilities.assert_equals( expect=main.TRUE, |
| 59 | actual=stepResult, |
| 60 | onpass="Successfully construct " + |
| 61 | "test variables ", |
| 62 | onfail="Failed to construct test variables" ) |
| 63 | |
| 64 | if gitPull == 'True': |
| 65 | main.step( "Building ONOS in " + gitBranch + " branch" ) |
| 66 | onosBuildResult = main.startUp.onosBuild( main, gitBranch ) |
| 67 | stepResult = onosBuildResult |
| 68 | utilities.assert_equals( expect=main.TRUE, |
| 69 | actual=stepResult, |
| 70 | onpass="Successfully compiled " + |
| 71 | "latest ONOS", |
| 72 | onfail="Failed to compile " + |
| 73 | "latest ONOS" ) |
| 74 | else: |
| 75 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 76 | "clean install" ) |
| 77 | |
| 78 | def CASE2( self, main ): |
| 79 | """ |
| 80 | - Set up cell |
| 81 | - Create cell file |
| 82 | - Set cell file |
| 83 | - Verify cell file |
| 84 | - Kill ONOS process |
| 85 | - Uninstall ONOS cluster |
| 86 | - Verify ONOS start up |
| 87 | - Install ONOS cluster |
| 88 | - Connect to cli |
| 89 | """ |
| 90 | |
| 91 | main.numCtrls = int( main.maxNodes ) |
| 92 | |
| 93 | main.case( "Starting up " + str( main.numCtrls ) + |
| 94 | " node(s) ONOS cluster" ) |
| 95 | |
| 96 | #kill off all onos processes |
| 97 | main.log.info( "Safety check, killing all ONOS processes" + |
| 98 | " before initiating environment setup" ) |
| 99 | |
suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 100 | |
| 101 | print "NODE COUNT = ", main.numCtrls |
| 102 | |
| 103 | tempOnosIp = [] |
| 104 | for i in range( main.numCtrls ): |
| 105 | tempOnosIp.append( main.ONOSip[i] ) |
| 106 | |
| 107 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address, "temp", main.Mininet1.ip_address, main.apps, tempOnosIp ) |
| 108 | |
| 109 | main.step( "Apply cell to environment" ) |
| 110 | cellResult = main.ONOSbench.setCell( "temp" ) |
| 111 | verifyResult = main.ONOSbench.verifyCell() |
| 112 | stepResult = cellResult and verifyResult |
| 113 | utilities.assert_equals( expect=main.TRUE, |
| 114 | actual=stepResult, |
| 115 | onpass="Successfully applied cell to " + \ |
| 116 | "environment", |
| 117 | onfail="Failed to apply cell to environment " ) |
| 118 | |
| 119 | main.step( "Creating ONOS package" ) |
suibin zhang | 570cb45 | 2016-03-29 19:03:15 -0700 | [diff] [blame] | 120 | packageResult = main.ONOSbench.onosPackage(opTimeout=120) |
suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 121 | stepResult = packageResult |
| 122 | utilities.assert_equals( expect=main.TRUE, |
| 123 | actual=stepResult, |
| 124 | onpass="Successfully created ONOS package", |
| 125 | onfail="Failed to create ONOS package" ) |
| 126 | |
| 127 | time.sleep( main.startUpSleep ) |
| 128 | main.step( "Uninstalling ONOS package" ) |
| 129 | onosUninstallResult = main.TRUE |
| 130 | for i in range( main.numCtrls ): |
| 131 | onosUninstallResult = onosUninstallResult and \ |
| 132 | main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[ i ] ) |
| 133 | stepResult = onosUninstallResult |
| 134 | utilities.assert_equals( expect=main.TRUE, |
| 135 | actual=stepResult, |
| 136 | onpass="Successfully uninstalled ONOS package", |
| 137 | onfail="Failed to uninstall ONOS package" ) |
| 138 | |
| 139 | time.sleep( main.startUpSleep ) |
| 140 | main.step( "Installing ONOS package" ) |
| 141 | onosInstallResult = main.TRUE |
| 142 | for i in range( main.numCtrls ): |
| 143 | onosInstallResult = onosInstallResult and \ |
| 144 | main.ONOSbench.onosInstall( node=main.ONOSip[ i ] ) |
| 145 | stepResult = onosInstallResult |
| 146 | utilities.assert_equals( expect=main.TRUE, |
| 147 | actual=stepResult, |
| 148 | onpass="Successfully installed ONOS package", |
| 149 | onfail="Failed to install ONOS package" ) |
| 150 | |
| 151 | time.sleep( main.startUpSleep ) |
| 152 | main.step( "Starting ONOS service" ) |
| 153 | stopResult = main.TRUE |
| 154 | startResult = main.TRUE |
| 155 | onosIsUp = main.TRUE |
| 156 | |
| 157 | for i in range( main.numCtrls ): |
| 158 | onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] ) |
| 159 | if onosIsUp == main.TRUE: |
| 160 | main.log.report( "ONOS instance is up and ready" ) |
| 161 | else: |
| 162 | main.log.report( "ONOS instance may not be up, stop and " + |
| 163 | "start ONOS again " ) |
| 164 | for i in range( main.numCtrls ): |
| 165 | stopResult = stopResult and \ |
| 166 | main.ONOSbench.onosStop( main.ONOSip[ i ] ) |
| 167 | for i in range( main.numCtrls ): |
| 168 | startResult = startResult and \ |
| 169 | main.ONOSbench.onosStart( main.ONOSip[ i ] ) |
| 170 | stepResult = onosIsUp and stopResult and startResult |
| 171 | utilities.assert_equals( expect=main.TRUE, |
| 172 | actual=stepResult, |
| 173 | onpass="ONOS service is ready", |
| 174 | onfail="ONOS service did not start properly" ) |
| 175 | |
suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 176 | |
| 177 | def CASE10( self, main ): |
| 178 | ''' |
| 179 | Start Mininet |
| 180 | ''' |
| 181 | import json |
| 182 | |
| 183 | main.numSw = int(main.params['CASE10']['numSw']) |
| 184 | main.case( "Setup mininet and compare ONOS topology view to Mininet topology" ) |
| 185 | main.caseExplanation = "Start mininet with custom topology and compare topology " +\ |
| 186 | "elements between Mininet and ONOS" |
| 187 | |
| 188 | main.step( "Setup Mininet Linear Topology with " + str(main.numSw) + " switches" ) |
| 189 | stepResult = main.Mininet1.startNet( args = main.params['CASE10']['mnArgs'] ) |
| 190 | |
| 191 | utilities.assert_equals( expect=main.TRUE, |
| 192 | actual=stepResult, |
| 193 | onpass="Successfully loaded topology", |
| 194 | onfail="Failed to load topology" ) |
| 195 | |
| 196 | main.step( "Assign switches to controller" ) |
| 197 | for i in range(1, main.numSw + 1): |
| 198 | main.Mininet1.assignSwController( "s" + str(i), main.ONOSip[0] ) |
| 199 | |
| 200 | utilities.assert_equals( expect=main.TRUE, |
| 201 | actual=stepResult, |
| 202 | onpass="Successfully assigned switch to controller", |
| 203 | onfail="Failed to assign switch to controller" ) |
| 204 | |
| 205 | time.sleep( main.startMNSleep ) |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | def CASE1000( self, main ): |
| 211 | ''' |
| 212 | create JSON object with batched flows |
| 213 | ''' |
| 214 | import numpy |
| 215 | import time |
suibin zhang | 570cb45 | 2016-03-29 19:03:15 -0700 | [diff] [blame] | 216 | from pprint import pprint |
suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 217 | |
| 218 | main.case( "Create a json object for the batched flows" ) |
| 219 | |
| 220 | main.step( "Parse batch information" ) |
suibin zhang | a82fe3f | 2016-03-29 11:26:21 -0700 | [diff] [blame] | 221 | main.batchSize = int(main.params['CASE1000']['batchSize']) |
| 222 | main.log.info("Number of flows in a batch is:" + str(main.batchSize)) |
suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 223 | |
| 224 | main.flowJsonBatchList = [] |
suibin zhang | 570cb45 | 2016-03-29 19:03:15 -0700 | [diff] [blame] | 225 | main.addedBatchList = [] |
suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 226 | postTimes = [] |
suibin zhang | a82fe3f | 2016-03-29 11:26:21 -0700 | [diff] [blame] | 227 | startSw = 1 |
suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 228 | |
| 229 | main.step("Creating a full list of batches") |
| 230 | for index in range(1, int(main.params['CASE1000']['batches']) + 1): |
suibin zhang | a82fe3f | 2016-03-29 11:26:21 -0700 | [diff] [blame] | 231 | if startSw <= main.numSw: |
suibin zhang | ff4abfe | 2016-03-29 11:52:08 -0700 | [diff] [blame] | 232 | ind = startSw |
| 233 | else: |
| 234 | startSw = 1 |
| 235 | ind = startSw |
| 236 | |
| 237 | main.log.info("Creating batch: " + str(index)) |
| 238 | flowJsonBatch = main.ONOSrest.createFlowBatch( numSw = main.numSw, |
| 239 | swIndex = ind, |
suibin zhang | a82fe3f | 2016-03-29 11:26:21 -0700 | [diff] [blame] | 240 | batchSize = main.batchSize, |
suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 241 | batchIndex = index, |
| 242 | ingressPort = 2, |
| 243 | egressPort = 3) |
suibin zhang | ff4abfe | 2016-03-29 11:52:08 -0700 | [diff] [blame] | 244 | main.flowJsonBatchList.append(flowJsonBatch) |
suibin zhang | a82fe3f | 2016-03-29 11:26:21 -0700 | [diff] [blame] | 245 | |
suibin zhang | ff4abfe | 2016-03-29 11:52:08 -0700 | [diff] [blame] | 246 | startSw += 1 |
| 247 | |
suibin zhang | a82fe3f | 2016-03-29 11:26:21 -0700 | [diff] [blame] | 248 | |
suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 249 | |
| 250 | main.step("Using REST API /flows/{} to post flow batch") |
| 251 | tStartPost = time.time() |
| 252 | for item in main.flowJsonBatchList: |
| 253 | ts = time.time() |
suibin zhang | 570cb45 | 2016-03-29 19:03:15 -0700 | [diff] [blame] | 254 | status, response = main.ONOSrest.sendFlowBatch(batch = item ) |
suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 255 | teBatch = time.time() - ts |
| 256 | postTimes.append(teBatch) |
| 257 | main.log.info("Batch Rest Post Elapse time is: " + str(teBatch)) |
suibin zhang | 570cb45 | 2016-03-29 19:03:15 -0700 | [diff] [blame] | 258 | main.addedBatchList.append(response[1]) |
suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 259 | |
| 260 | tLastPostEnd = time.time() |
| 261 | |
| 262 | main.step("Check to ensure all flows are in added state.") |
suibin zhang | 570cb45 | 2016-03-29 19:03:15 -0700 | [diff] [blame] | 263 | pprint(main.addedBatchList) |
suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 264 | resp = main.FALSE |
| 265 | while resp != main.TRUE: |
| 266 | resp = main.ONOSrest.checkFlowsState() |
| 267 | time.sleep(0.5) |
| 268 | tAllAdded = time.time() |
| 269 | |
suibin zhang | dec01c5 | 2016-03-29 19:23:33 -0700 | [diff] [blame^] | 270 | main.numFlows = int(main.params['CASE1000']['batches']) *\ |
suibin zhang | a82fe3f | 2016-03-29 11:26:21 -0700 | [diff] [blame] | 271 | int(main.params['CASE1000']['batchSize']) |
suibin zhang | dec01c5 | 2016-03-29 19:23:33 -0700 | [diff] [blame^] | 272 | main.log.info("Total number of flows: " + str (main.numFlows) ) |
suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 273 | main.log.info("Sum of each POST elapse time: " + str(numpy.sum(postTimes)) ) |
| 274 | main.log.info("Total POST elapse time: " + str(tLastPostEnd-tStartPost)) |
suibin zhang | dec01c5 | 2016-03-29 19:23:33 -0700 | [diff] [blame^] | 275 | main.log.info("Rate of ADD Controller response: " + str(main.numFlows / (tLastPostEnd - tStartPost))) |
suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 276 | |
| 277 | duration = tAllAdded - tLastPostEnd |
| 278 | main.log.info("Elapse time from end of last REST POST to Flows in ADDED state: " +\ |
| 279 | str(duration)) |
suibin zhang | dec01c5 | 2016-03-29 19:23:33 -0700 | [diff] [blame^] | 280 | main.log.info("Rate of Batch Flow add is (flows/sec): " + str( main.numFlows / duration)) |
suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 281 | |
| 282 | def CASE2000(self, main): |
| 283 | import time |
| 284 | import numpy |
suibin zhang | 570cb45 | 2016-03-29 19:03:15 -0700 | [diff] [blame] | 285 | import json |
suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 286 | |
| 287 | rmTimes = [] |
| 288 | |
| 289 | main.case("Remove flow timing") |
| 290 | |
| 291 | tStartRemove = time.time() |
suibin zhang | 570cb45 | 2016-03-29 19:03:15 -0700 | [diff] [blame] | 292 | for item in main.addedBatchList: |
suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 293 | ts = time.time() |
suibin zhang | 570cb45 | 2016-03-29 19:03:15 -0700 | [diff] [blame] | 294 | print(item) |
| 295 | resp = main.ONOSrest.removeFlowBatch(batch = json.loads(item) ) |
suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 296 | teBatch = time.time() - ts |
| 297 | rmTimes.append(teBatch) |
| 298 | main.log.info("Batch Rest Remove Elapse time is: " + str(teBatch)) |
| 299 | |
| 300 | tLastRemoveEnd = time.time() |
| 301 | |
| 302 | main.step("Check to ensure all flows are in added state.") |
| 303 | resp = main.FALSE |
| 304 | while resp != main.TRUE: |
| 305 | resp = main.ONOSrest.checkFlowsState() |
| 306 | time.sleep(0.5) |
| 307 | tAllRemoved = time.time() |
| 308 | |
| 309 | main.log.info("Total number of flows: " + str (int(main.params['CASE1000']['batches']) *\ |
suibin zhang | a82fe3f | 2016-03-29 11:26:21 -0700 | [diff] [blame] | 310 | int(main.params['CASE1000']['batchSize']) *\ |
suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 311 | int(main.params['CASE10']['numSw'])) ) |
| 312 | main.log.info("Sum of each DELETE elapse time: " + str(numpy.sum(rmTimes)) ) |
suibin zhang | 570cb45 | 2016-03-29 19:03:15 -0700 | [diff] [blame] | 313 | main.log.info("Total DELETE elapse time: " + str(tLastRemoveEnd-tStartRemove)) |
suibin zhang | dec01c5 | 2016-03-29 19:23:33 -0700 | [diff] [blame^] | 314 | main.log.info("Rate of ADD Controller response: " + str(main.numFlows / (tLastRemoveEnd - tStartRemove))) |
suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 315 | |
suibin zhang | dec01c5 | 2016-03-29 19:23:33 -0700 | [diff] [blame^] | 316 | duration = tAllRemoved - tLastRemoveEnd |
| 317 | main.log.info("Elapse time from end of last REST POST to Flows in ADDED state: " +\ |
| 318 | str(duration)) |
| 319 | main.log.info("Rate of Batch Flow add is (flows/sec): " + str( main.numFlows / duration)) |
suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 320 | |
| 321 | def CASE100(self,main): |
| 322 | from pprint import pprint |
| 323 | |
| 324 | main.case( "Check to ensure onos flows." ) |
| 325 | |
| 326 | resp = main.ONOSrest.checkFlowsState() |
suibin zhang | dec01c5 | 2016-03-29 19:23:33 -0700 | [diff] [blame^] | 327 | #pprint(resp) |
suibin zhang | d0f09b3 | 2016-03-29 00:57:57 -0700 | [diff] [blame] | 328 | |
| 329 | |
| 330 | def CASE110( self, main ): |
| 331 | ''' |
| 332 | Report errors/warnings/exceptions |
| 333 | ''' |
| 334 | main.log.info("Error report: \n" ) |
| 335 | main.ONOSbench.logReport( main.ONOSip[ 0 ], |
| 336 | [ "INFO", |
| 337 | "FOLLOWER", |
| 338 | "WARN", |
| 339 | "flow", |
| 340 | "ERROR", |
| 341 | "Except" ], |
| 342 | "s" ) |
| 343 | main.stop() |
| 344 | |