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