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 |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 21 | try: |
| 22 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 23 | main.testSetUp = ONOSSetup() |
| 24 | except ImportError: |
| 25 | main.log.error( "ONOSSetup not found. exiting the test" ) |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 26 | main.exit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 27 | main.testSetUp.envSetupDescription() |
| 28 | stepResult = main.FALSE |
| 29 | try: |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 30 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 31 | # Test variables |
| 32 | main.cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 33 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
| 34 | main.scale = ( main.params[ 'SCALE' ] ).split( "," ) |
| 35 | main.ONOSport = main.params[ 'CTRL' ][ 'port' ] |
| 36 | main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] ) |
| 37 | main.installSleep = int( main.params[ 'SLEEP' ][ 'install' ] ) |
| 38 | main.measurementSleep = int( main.params[ 'SLEEP' ][ 'measurement' ] ) |
| 39 | main.timeout = int( main.params[ 'SLEEP' ][ 'timeout' ] ) |
| 40 | main.dbFileName = main.params[ 'DATABASE' ][ 'file' ] |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 41 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 42 | # Tshark params |
| 43 | main.tsharkResultPath = main.params[ 'TSHARK' ][ 'tsharkPath' ] |
| 44 | main.tsharkPacketIn = main.params[ 'TSHARK' ][ 'tsharkPacketIn' ] |
| 45 | |
| 46 | main.numlter = main.params[ 'TEST' ][ 'numIter' ] |
| 47 | main.iterIgnore = int( main.params[ 'TEST' ][ 'iterIgnore' ] ) |
| 48 | main.hostTimestampKey = main.params[ 'TEST' ][ 'hostTimestamp' ] |
| 49 | main.thresholdStr = main.params[ 'TEST' ][ 'singleSwThreshold' ] |
| 50 | main.thresholdObj = main.thresholdStr.split( ',' ) |
| 51 | main.thresholdMin = int( main.thresholdObj[ 0 ] ) |
| 52 | main.thresholdMax = int( main.thresholdObj[ 1 ] ) |
| 53 | main.threadID = 0 |
| 54 | |
| 55 | main.maxNumBatch = 0 |
| 56 | main.setupSkipped = False |
| 57 | |
| 58 | nic = main.params[ 'DATABASE' ][ 'nic' ] |
| 59 | node = main.params[ 'DATABASE' ][ 'node' ] |
| 60 | nic = main.params[ 'DATABASE' ][ 'nic' ] |
| 61 | node = main.params[ 'DATABASE' ][ 'node' ] |
| 62 | stepResult = main.TRUE |
| 63 | |
| 64 | main.log.info( "Cresting DB file" ) |
| 65 | with open( main.dbFileName, "w+" ) as dbFile: |
| 66 | dbFile.write( "" ) |
| 67 | |
| 68 | stepResult = main.testSetUp.gitPulling() |
| 69 | except Exception as e: |
| 70 | main.testSetUp.envSetupException( e ) |
| 71 | main.testSetUp.evnSetupConclusion( stepResult ) |
| 72 | |
| 73 | main.commit = main.commit.split( " " )[ 1 ] |
| 74 | |
| 75 | with open( main.dbFileName, "a" ) as dbFile: |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 76 | temp = "'" + main.commit + "'," |
| 77 | temp += "'" + nic + "'," |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 78 | dbFile.write( temp ) |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 79 | dbFile.close() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 80 | def CASE1( self ): |
| 81 | # main.scale[ 0 ] determines the current number of ONOS controller |
| 82 | main.testSetUp.getNumCtrls( True ) |
| 83 | main.testSetUp.envSetup( includeGitPull=False, makeMaxNodes=False ) |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 84 | |
| 85 | def CASE2( self, main ): |
| 86 | """ |
| 87 | - Uninstall ONOS cluster |
| 88 | - Verify ONOS start up |
| 89 | - Install ONOS cluster |
| 90 | - Connect to cli |
| 91 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 92 | main.testSetUp.ONOSSetUp( main.Mininet1, True, |
| 93 | cellName=main.cellName, killRemoveMax=False, |
| 94 | CtrlsSet=False ) |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 95 | |
| 96 | def CASE11( self, main ): |
| 97 | main.log.info( "set and configure Application" ) |
| 98 | import json |
| 99 | import time |
| 100 | time.sleep(main.startUpSleep) |
| 101 | main.step( "Activating org.onosproject.proxyarp" ) |
| 102 | appStatus = utilities.retry( main.ONOSrest1.activateApp, |
| 103 | main.FALSE, |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 104 | [ 'org.onosproject.proxyarp' ], |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 105 | sleep=3, |
| 106 | attempts=3 ) |
| 107 | utilities.assert_equals( expect=main.TRUE, |
| 108 | actual=appStatus, |
| 109 | onpass="Successfully activated proxyarp", |
| 110 | onfail="Failed to activated proxyarp") |
| 111 | |
| 112 | main.step( "Set up Default Topology Provider" ) |
| 113 | appStatus = main.TRUE |
| 114 | configName = 'org.onosproject.net.topology.impl.DefaultTopologyProvider' |
| 115 | configParam = 'maxEvents' |
| 116 | appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam,'1' ) |
| 117 | configParam = 'maxBatchMs' |
| 118 | appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam, '0') |
| 119 | configParam = 'maxIdleMs' |
| 120 | appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam,'0' ) |
| 121 | utilities.assert_equals( expect=main.TRUE, |
| 122 | actual=appStatus, |
| 123 | onpass="Successfully set DefaultTopologyProvider", |
| 124 | onfail="Failed to set DefaultTopologyProvider" ) |
| 125 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 126 | time.sleep( main.startUpSleep) |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 127 | main.step('Starting mininet topology') |
| 128 | mnStatus = main.Mininet1.startNet(args='--topo=linear,1') |
| 129 | utilities.assert_equals( expect=main.TRUE, |
| 130 | actual=mnStatus, |
| 131 | onpass="Successfully started Mininet", |
| 132 | onfail="Failed to activate Mininet" ) |
| 133 | main.step("Assinging masters to switches") |
| 134 | switches = main.Mininet1.getSwitches() |
| 135 | swStatus = main.Mininet1.assignSwController( sw=switches.keys(), ip=main.ONOSip[0] ) |
| 136 | utilities.assert_equals( expect=main.TRUE, |
| 137 | actual=swStatus, |
| 138 | onpass="Successfully assigned switches to masters", |
| 139 | onfail="Failed assign switches to masters" ) |
| 140 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 141 | time.sleep( main.startUpSleep) |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 142 | |
| 143 | def CASE20(self, main): |
| 144 | """ |
| 145 | host1 send arping package and measure latency |
| 146 | |
| 147 | There are only 1 levels of latency measurements to this test: |
| 148 | 1 ) ARPING-to-device measurement: Measurement the time from host1 |
| 149 | send apring package to onos processing the host event |
| 150 | |
| 151 | """ |
| 152 | import time |
| 153 | import subprocess |
| 154 | import json |
| 155 | import requests |
| 156 | import os |
| 157 | import numpy |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 158 | try: |
| 159 | from tests.dependencies.utils import Utils |
| 160 | except ImportError: |
| 161 | main.log.error( "Utils not found exiting the test" ) |
| 162 | main.exit() |
| 163 | try: |
| 164 | main.Utils |
| 165 | except ( NameError, AttributeError ): |
| 166 | main.Utils = Utils() |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 167 | # Host adding measurement |
| 168 | assertion = main.TRUE |
| 169 | |
| 170 | main.log.report('Latency of adding one host to ONOS') |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 171 | main.log.report('First ' + str( main.iterIgnore ) + ' iterations ignored' + ' for jvm warmup time') |
| 172 | main.log.report('Total iterations of test: ' + str( main.numlter ) ) |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 173 | |
| 174 | addingHostTime = [] |
| 175 | metricsResultList = [] |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 176 | for i in range( 0, int( main.numlter ) ): |
| 177 | main.log.info( 'Clean up data file' ) |
| 178 | with open( main.tsharkResultPath, "w" ) as dbFile: |
| 179 | dbFile.write( "" ) |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 180 | |
| 181 | main.log.info('Starting tshark capture') |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 182 | main.ONOSbench.tsharkGrep( main.tsharkPacketIn, main.tsharkResultPath ) |
| 183 | time.sleep( main.measurementSleep ) |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 184 | |
| 185 | main.log.info('host 1 arping...') |
| 186 | main.Mininet1.arping(srcHost='h1', dstHost='10.0.0.2') |
| 187 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 188 | time.sleep( main.measurementSleep ) |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 189 | |
| 190 | main.log.info('Stopping all Tshark processes') |
| 191 | main.ONOSbench.tsharkStop() |
| 192 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 193 | time.sleep( main.measurementSleep ) |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 194 | |
| 195 | # Get tshark output |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 196 | with open( main.tsharkResultPath, "r" ) as resultFile: |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 197 | resultText = resultFile.readline() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 198 | main.log.info( 'Capture result:' + resultText ) |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 199 | resultText = resultText.split(' ') |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 200 | if len( resultText ) > 1: |
| 201 | tsharkResultTime = float( resultText[ 1 ] ) * 1000.0 |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 202 | else: |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 203 | main.log.error( 'Tshark output file for packet_in' + ' returned unexpected results' ) |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 204 | hostTime = 0 |
| 205 | caseResult = main.FALSE |
| 206 | resultFile.close() |
| 207 | # Compare the timestemps, and get the lowest one. |
| 208 | temp = 0; |
| 209 | # Get host event timestamps from each nodes |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 210 | for node in range ( 0, main.numCtrls ): |
| 211 | metricsResult = json.loads( main.CLIs[ node ].topologyEventsMetrics() ) |
| 212 | metricsResult = metricsResult.get( main.hostTimestampKey ).get( "value" ) |
| 213 | main.log.info( "ONOS topology event matrics timestemp: {}".format( str( metricsResult ) ) ) |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 214 | |
| 215 | if temp < metricsResult: |
| 216 | temp = metricsResult |
| 217 | metricsResult = temp |
| 218 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 219 | addingHostTime.append( float( metricsResult ) - tsharkResultTime ) |
| 220 | main.log.info( "Result of this iteration: {}".format( str( float( metricsResult ) - tsharkResultTime) ) ) |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 221 | # gethost to remove |
| 222 | gethost = main.ONOSrest1.hosts() |
| 223 | HosttoRemove = [] |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 224 | HosttoRemove.append( json.loads( gethost[ 1:len( gethost )-1 ] ).get( 'id' ) ) |
| 225 | main.CLIs[0].removeHost( HosttoRemove ) |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 226 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 227 | main.log.info( "Result List: {}".format( addingHostTime ) ) |
YPZhang | 82ca589 | 2016-03-01 15:32:09 -0800 | [diff] [blame] | 228 | |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 229 | # calculate average latency from each nodes |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 230 | averageResult = numpy.average( addingHostTime ) |
| 231 | main.log.info( "Average Latency: {}".format( averageResult ) ) |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 232 | |
| 233 | # calculate std |
| 234 | stdResult = numpy.std(addingHostTime) |
YPZhang | 82ca589 | 2016-03-01 15:32:09 -0800 | [diff] [blame] | 235 | main.log.info("std: {}".format(stdResult)) |
YPZhang | a482c20 | 2016-02-18 17:03:07 -0800 | [diff] [blame] | 236 | |
| 237 | # write to DB file |
| 238 | main.log.info("Writing results to DS file") |
| 239 | with open(main.dbFileName, "a") as dbFile: |
| 240 | # Scale number |
| 241 | temp = str(main.numCtrls) |
| 242 | temp += ",'" + "baremetal1" + "'" |
| 243 | # average latency |
| 244 | temp += "," + str( averageResult ) |
| 245 | # std of latency |
| 246 | temp += "," + str(stdResult) |
| 247 | temp += "\n" |
| 248 | dbFile.write( temp ) |
| 249 | |
| 250 | assertion = main.TRUE |
| 251 | |
| 252 | utilities.assert_equals(expect=main.TRUE, actual=assertion, |
| 253 | onpass='Host latency test successful', |
| 254 | onfail='Host latency test failed') |
| 255 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 256 | main.Utils.mininetCleanup( main.Mininet1 ) |