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