YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 1 | """ |
| 2 | SCPFhostLat |
| 3 | This test will test the host found latency. |
| 4 | Host will arping a ip address, tshark will caputure the package time, then compare with the topology event timestamp. |
| 5 | Test will run with 1 node from start, and scale up to 7 nodes. |
| 6 | The event timestamp will only greb the latest one, then calculate average and standar dev. |
| 7 | |
| 8 | yunpeng@onlab.us |
| 9 | """ |
| 10 | class SCPFhostLat: |
| 11 | |
| 12 | def __init__( self ): |
| 13 | self.default = '' |
| 14 | |
| 15 | def CASE0( self, main): |
| 16 | import sys |
| 17 | import json |
| 18 | import time |
| 19 | import os |
| 20 | import imp |
| 21 | |
| 22 | main.case( "Constructing test variables and building ONOS package" ) |
| 23 | main.step( "Constructing test variables" ) |
| 24 | stepResult = main.FALSE |
| 25 | |
| 26 | # Test variables |
| 27 | main.testOnDirectory = os.path.dirname( os.getcwd ( ) ) |
| 28 | main.cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 29 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
| 30 | main.scale = ( main.params[ 'SCALE' ] ).split( "," ) |
| 31 | main.ONOSport = main.params[ 'CTRL' ][ 'port' ] |
| 32 | main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] ) |
| 33 | main.installSleep = int( main.params[ 'SLEEP' ][ 'install' ] ) |
| 34 | main.measurementSleep = int( main.params['SLEEP']['measurement']) |
| 35 | main.timeout = int( main.params['SLEEP']['timeout'] ) |
| 36 | main.dbFileName = main.params['DATABASE']['file'] |
| 37 | main.cellData = {} # for creating cell file |
| 38 | |
| 39 | # Tshark params |
| 40 | main.tsharkResultPath = main.params['TSHARK']['tsharkPath'] |
| 41 | main.tsharkPacketIn = main.params['TSHARK']['tsharkPacketIn'] |
| 42 | |
| 43 | main.numlter = main.params['TEST']['numIter'] |
| 44 | main.iterIgnore = int(main.params['TEST']['iterIgnore']) |
| 45 | main.hostTimestampKey = main.params['TEST']['hostTimestamp'] |
| 46 | main.thresholdStr = main.params['TEST']['singleSwThreshold'] |
| 47 | main.thresholdObj = main.thresholdStr.split(',') |
| 48 | main.thresholdMin = int(main.thresholdObj[0]) |
| 49 | main.thresholdMax = int(main.thresholdObj[1]) |
| 50 | main.threadID = 0 |
| 51 | |
| 52 | main.CLIs = [] |
| 53 | main.ONOSip = [] |
| 54 | main.maxNumBatch = 0 |
| 55 | main.ONOSip = main.ONOSbench.getOnosIps() |
| 56 | main.log.info(main.ONOSip) |
| 57 | main.setupSkipped = False |
| 58 | |
| 59 | gitBranch = main.params[ 'GIT' ][ 'branch' ] |
| 60 | gitPull = main.params[ 'GIT' ][ 'pull' ] |
| 61 | nic = main.params['DATABASE']['nic'] |
| 62 | node = main.params['DATABASE']['node'] |
| 63 | nic = main.params['DATABASE']['nic'] |
| 64 | node = main.params['DATABASE']['node'] |
| 65 | stepResult = main.TRUE |
| 66 | |
| 67 | main.log.info("Cresting DB file") |
| 68 | with open(main.dbFileName, "w+") as dbFile: |
| 69 | dbFile.write("") |
| 70 | |
| 71 | utilities.assert_equals( expect=main.TRUE, |
| 72 | actual=stepResult, |
| 73 | onpass="environment set up successfull", |
| 74 | onfail="environment set up Failed" ) |
| 75 | |
| 76 | def CASE1( self ): |
| 77 | # main.scale[ 0 ] determines the current number of ONOS controller |
| 78 | main.CLIs = [] |
| 79 | main.numCtrls = int( main.scale[ 0 ] ) |
| 80 | main.log.info( "Creating list of ONOS cli handles" ) |
| 81 | for i in range(main.numCtrls): |
| 82 | main.CLIs.append( getattr( main, 'ONOScli%s' % (i+1) ) ) |
| 83 | |
| 84 | main.log.info(main.CLIs) |
| 85 | if not main.CLIs: |
| 86 | main.log.error( "Failed to create the list of ONOS cli handles" ) |
| 87 | main.cleanup() |
| 88 | main.exit() |
| 89 | |
| 90 | main.commit = main.ONOSbench.getVersion(report=True) |
| 91 | main.commit = main.commit.split(" ")[1] |
| 92 | |
| 93 | if gitPull == 'True': |
| 94 | if not main.startUp.onosBuild( main, gitBranch ): |
| 95 | main.log.error( "Failed to build ONOS" ) |
| 96 | main.cleanup() |
| 97 | main.exit() |
| 98 | else: |
| 99 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 100 | "clean install" ) |
| 101 | with open(main.dbFileName, "a") as dbFile: |
| 102 | temp = "'" + main.commit + "'," |
| 103 | temp += "'" + nic + "'," |
| 104 | dbFile.write(temp) |
| 105 | dbFile.close() |
| 106 | |
| 107 | def CASE2( self, main ): |
| 108 | """ |
| 109 | - Uninstall ONOS cluster |
| 110 | - Verify ONOS start up |
| 111 | - Install ONOS cluster |
| 112 | - Connect to cli |
| 113 | """ |
| 114 | main.log.info( "Starting up %s node(s) ONOS cluster" % main.numCtrls) |
| 115 | main.log.info( "Safety check, killing all ONOS processes" + |
| 116 | " before initiating environment setup" ) |
| 117 | |
| 118 | for i in range( main.numCtrls ): |
| 119 | main.ONOSbench.onosDie( main.ONOSip[ i ] ) |
| 120 | |
| 121 | main.log.info( "NODE COUNT = %s" % main.numCtrls) |
| 122 | |
| 123 | tempOnosIp = [] |
| 124 | for i in range( main.numCtrls ): |
| 125 | tempOnosIp.append( main.ONOSip[i] ) |
| 126 | |
| 127 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address, |
| 128 | "temp", |
| 129 | main.Mininet1.ip_address, |
| 130 | main.apps, |
| 131 | tempOnosIp ) |
| 132 | |
| 133 | main.step( "Apply cell to environment" ) |
| 134 | cellResult = main.ONOSbench.setCell( "temp" ) |
| 135 | verifyResult = main.ONOSbench.verifyCell() |
| 136 | stepResult = cellResult and verifyResult |
| 137 | utilities.assert_equals( expect=main.TRUE, |
| 138 | actual=stepResult, |
| 139 | onpass="Successfully applied cell to " + \ |
| 140 | "environment", |
| 141 | onfail="Failed to apply cell to environment " ) |
| 142 | |
| 143 | main.step( "Creating ONOS package" ) |
Jon Hall | bd60ea0 | 2016-08-23 10:03:59 -0700 | [diff] [blame] | 144 | packageResult = main.ONOSbench.buckBuild() |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 145 | stepResult = packageResult |
| 146 | utilities.assert_equals( expect=main.TRUE, |
| 147 | actual=stepResult, |
| 148 | onpass="Successfully created ONOS package", |
| 149 | onfail="Failed to create ONOS package" ) |
| 150 | |
| 151 | main.step( "Uninstall ONOS package on all Nodes" ) |
| 152 | uninstallResult = main.TRUE |
| 153 | for i in range( int( main.numCtrls ) ): |
| 154 | main.log.info( "Uninstalling package on ONOS Node IP: " + main.ONOSip[i] ) |
| 155 | u_result = main.ONOSbench.onosUninstall( main.ONOSip[i] ) |
| 156 | utilities.assert_equals( expect=main.TRUE, actual=u_result, |
| 157 | onpass="Test step PASS", |
| 158 | onfail="Test step FAIL" ) |
| 159 | uninstallResult = ( uninstallResult and u_result ) |
| 160 | |
| 161 | main.step( "Install ONOS package on all Nodes" ) |
| 162 | installResult = main.TRUE |
| 163 | for i in range( int( main.numCtrls ) ): |
| 164 | main.log.info( "Installing package on ONOS Node IP: " + main.ONOSip[i] ) |
| 165 | i_result = main.ONOSbench.onosInstall( node=main.ONOSip[i] ) |
| 166 | utilities.assert_equals( expect=main.TRUE, actual=i_result, |
| 167 | onpass="Test step PASS", |
| 168 | onfail="Test step FAIL" ) |
| 169 | installResult = installResult and i_result |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 170 | |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 171 | main.step( "Set up ONOS secure SSH" ) |
| 172 | secureSshResult = main.TRUE |
| 173 | for i in range( int( main.numCtrls ) ): |
| 174 | secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[i] ) |
| 175 | utilities.assert_equals( expect=main.TRUE, actual=secureSshResult, |
| 176 | onpass="Test step PASS", |
| 177 | onfail="Test step FAIL" ) |
| 178 | |
You Wang | 0357c43 | 2017-01-09 16:13:33 -0800 | [diff] [blame] | 179 | time.sleep( main.startUpSleep ) |
| 180 | main.step( "Starting ONOS service" ) |
| 181 | stopResult = main.TRUE |
| 182 | startResult = main.TRUE |
| 183 | onosIsUp = main.TRUE |
| 184 | |
| 185 | for i in range( main.numCtrls ): |
| 186 | onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] ) |
| 187 | if onosIsUp == main.TRUE: |
| 188 | main.log.report( "ONOS instance is up and ready" ) |
| 189 | else: |
| 190 | main.log.report( "ONOS instance may not be up, stop and " + |
| 191 | "start ONOS again " ) |
| 192 | for i in range( main.numCtrls ): |
| 193 | stopResult = stopResult and \ |
| 194 | main.ONOSbench.onosStop( main.ONOSip[ i ] ) |
| 195 | for i in range( main.numCtrls ): |
| 196 | startResult = startResult and \ |
| 197 | main.ONOSbench.onosStart( main.ONOSip[ i ] ) |
| 198 | stepResult = onosIsUp and stopResult and startResult |
| 199 | utilities.assert_equals( expect=main.TRUE, |
| 200 | actual=stepResult, |
| 201 | onpass="ONOS service is ready", |
| 202 | onfail="ONOS service did not start properly" ) |
| 203 | |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 204 | main.step( "Start ONOS CLI on all nodes" ) |
| 205 | cliResult = main.TRUE |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 206 | main.step(" Start ONOS cli using thread ") |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 207 | time.sleep( main.startUpSleep ) |
| 208 | startCliResult = main.TRUE |
| 209 | pool = [] |
| 210 | |
| 211 | for i in range( int( main.numCtrls) ): |
| 212 | t = main.Thread( target=main.CLIs[i].startOnosCli, |
| 213 | threadID=main.threadID, |
| 214 | name="startOnosCli", |
| 215 | args=[ main.ONOSip[i] ], |
| 216 | kwargs = {"onosStartTimeout":main.timeout} ) |
| 217 | pool.append(t) |
| 218 | t.start() |
| 219 | main.threadID = main.threadID + 1 |
| 220 | for t in pool: |
| 221 | t.join() |
| 222 | startCliResult = startCliResult and t.result |
| 223 | time.sleep( main.startUpSleep ) |
| 224 | |
| 225 | def CASE11( self, main ): |
| 226 | main.log.info( "set and configure Application" ) |
| 227 | import json |
| 228 | import time |
| 229 | time.sleep(main.startUpSleep) |
| 230 | main.step( "Activating org.onosproject.proxyarp" ) |
| 231 | appStatus = utilities.retry( main.ONOSrest1.activateApp, |
| 232 | main.FALSE, |
| 233 | ['org.onosproject.proxyarp'], |
| 234 | sleep=3, |
| 235 | attempts=3 ) |
| 236 | utilities.assert_equals( expect=main.TRUE, |
| 237 | actual=appStatus, |
| 238 | onpass="Successfully activated proxyarp", |
| 239 | onfail="Failed to activated proxyarp") |
| 240 | |
| 241 | main.step( "Set up Default Topology Provider" ) |
| 242 | appStatus = main.TRUE |
| 243 | configName = 'org.onosproject.net.topology.impl.DefaultTopologyProvider' |
| 244 | configParam = 'maxEvents' |
| 245 | appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam,'1' ) |
| 246 | configParam = 'maxBatchMs' |
| 247 | appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam, '0') |
| 248 | configParam = 'maxIdleMs' |
| 249 | appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam,'0' ) |
| 250 | utilities.assert_equals( expect=main.TRUE, |
| 251 | actual=appStatus, |
| 252 | onpass="Successfully set DefaultTopologyProvider", |
| 253 | onfail="Failed to set DefaultTopologyProvider" ) |
| 254 | |
| 255 | time.sleep(main.startUpSleep) |
| 256 | main.step('Starting mininet topology') |
| 257 | mnStatus = main.Mininet1.startNet(args='--topo=linear,1') |
| 258 | utilities.assert_equals( expect=main.TRUE, |
| 259 | actual=mnStatus, |
| 260 | onpass="Successfully started Mininet", |
| 261 | onfail="Failed to activate Mininet" ) |
| 262 | main.step("Assinging masters to switches") |
| 263 | switches = main.Mininet1.getSwitches() |
| 264 | swStatus = main.Mininet1.assignSwController( sw=switches.keys(), ip=main.ONOSip[0] ) |
| 265 | utilities.assert_equals( expect=main.TRUE, |
| 266 | actual=swStatus, |
| 267 | onpass="Successfully assigned switches to masters", |
| 268 | onfail="Failed assign switches to masters" ) |
| 269 | |
| 270 | time.sleep(main.startUpSleep) |
| 271 | |
| 272 | def CASE20(self, main): |
| 273 | """ |
| 274 | host1 send arping package and measure latency |
| 275 | |
| 276 | There are only 1 levels of latency measurements to this test: |
| 277 | 1 ) ARPING-to-device measurement: Measurement the time from host1 |
| 278 | send apring package to onos processing the host event |
| 279 | |
| 280 | """ |
| 281 | import time |
| 282 | import subprocess |
| 283 | import json |
| 284 | import requests |
| 285 | import os |
| 286 | import numpy |
| 287 | |
| 288 | # Host adding measurement |
| 289 | assertion = main.TRUE |
| 290 | |
| 291 | main.log.report('Latency of adding one host to ONOS') |
| 292 | main.log.report('First ' + str(main.iterIgnore) + ' iterations ignored' + ' for jvm warmup time') |
| 293 | main.log.report('Total iterations of test: ' + str(main.numlter)) |
| 294 | |
| 295 | addingHostTime = [] |
| 296 | metricsResultList = [] |
| 297 | for i in range(0, int(main.numlter)): |
| 298 | main.log.info('Clean up data file') |
| 299 | with open(main.tsharkResultPath, "w") as dbFile: |
| 300 | dbFile.write("") |
| 301 | |
| 302 | main.log.info('Starting tshark capture') |
| 303 | main.ONOSbench.tsharkGrep(main.tsharkPacketIn, main.tsharkResultPath) |
| 304 | time.sleep(main.measurementSleep) |
| 305 | |
| 306 | main.log.info('host 1 arping...') |
| 307 | main.Mininet1.arping(srcHost='h1', dstHost='10.0.0.2') |
| 308 | |
| 309 | time.sleep(main.measurementSleep) |
| 310 | |
| 311 | main.log.info('Stopping all Tshark processes') |
| 312 | main.ONOSbench.tsharkStop() |
| 313 | |
| 314 | time.sleep(main.measurementSleep) |
| 315 | |
| 316 | # Get tshark output |
| 317 | with open(main.tsharkResultPath, "r") as resultFile: |
| 318 | resultText = resultFile.readline() |
| 319 | main.log.info('Capture result:' + resultText) |
| 320 | resultText = resultText.split(' ') |
| 321 | if len(resultText) > 1: |
| 322 | tsharkResultTime = float(resultText[1]) * 1000.0 |
| 323 | else: |
| 324 | main.log.error('Tshark output file for packet_in' + ' returned unexpected results') |
| 325 | hostTime = 0 |
| 326 | caseResult = main.FALSE |
| 327 | resultFile.close() |
| 328 | # Compare the timestemps, and get the lowest one. |
| 329 | temp = 0; |
| 330 | # Get host event timestamps from each nodes |
| 331 | for node in range (0, main.numCtrls): |
| 332 | metricsResult = json.loads(main.CLIs[node].topologyEventsMetrics()) |
| 333 | metricsResult = metricsResult.get(main.hostTimestampKey).get("value") |
| 334 | main.log.info("ONOS topology event matrics timestemp: {}".format(str(metricsResult)) ) |
| 335 | |
| 336 | if temp < metricsResult: |
| 337 | temp = metricsResult |
| 338 | metricsResult = temp |
| 339 | |
| 340 | addingHostTime.append(float(metricsResult) - tsharkResultTime) |
| 341 | main.log.info("Result of this iteration: {}".format( str( float(metricsResult) - tsharkResultTime) )) |
| 342 | # gethost to remove |
| 343 | gethost = main.ONOSrest1.hosts() |
| 344 | HosttoRemove = [] |
| 345 | HosttoRemove.append( json.loads( gethost[1:len(gethost)-1] ).get('id') ) |
| 346 | main.CLIs[0].removeHost(HosttoRemove) |
| 347 | |
YPZhang | 82ca589 | 2016-03-01 15:32:09 -0800 | [diff] [blame] | 348 | main.log.info("Result List: {}".format(addingHostTime)) |
| 349 | |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 350 | # calculate average latency from each nodes |
| 351 | averageResult = numpy.average(addingHostTime) |
YPZhang | 82ca589 | 2016-03-01 15:32:09 -0800 | [diff] [blame] | 352 | main.log.info("Average Latency: {}".format(averageResult)) |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 353 | |
| 354 | # calculate std |
| 355 | stdResult = numpy.std(addingHostTime) |
YPZhang | 82ca589 | 2016-03-01 15:32:09 -0800 | [diff] [blame] | 356 | main.log.info("std: {}".format(stdResult)) |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 357 | |
| 358 | # write to DB file |
| 359 | main.log.info("Writing results to DS file") |
| 360 | with open(main.dbFileName, "a") as dbFile: |
| 361 | # Scale number |
| 362 | temp = str(main.numCtrls) |
| 363 | temp += ",'" + "baremetal1" + "'" |
| 364 | # average latency |
| 365 | temp += "," + str( averageResult ) |
| 366 | # std of latency |
| 367 | temp += "," + str(stdResult) |
| 368 | temp += "\n" |
| 369 | dbFile.write( temp ) |
| 370 | |
| 371 | assertion = main.TRUE |
| 372 | |
| 373 | utilities.assert_equals(expect=main.TRUE, actual=assertion, |
| 374 | onpass='Host latency test successful', |
| 375 | onfail='Host latency test failed') |
| 376 | |
| 377 | main.Mininet1.stopNet() |
| 378 | del main.scale[0] |