blob: a658e23e9e96eec529f9fd677a918c78902bfadf [file] [log] [blame]
YPZhanga482c202016-02-18 17:03:07 -08001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2016 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or 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 Ronquillo23fb2162017-09-15 14:59:57 -070011 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070012
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 Ronquillob27ce4c2017-07-17 12:41:28 -070021"""
YPZhanga482c202016-02-18 17:03:07 -080022 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"""
30class SCPFhostLat:
31
32 def __init__( self ):
33 self.default = ''
34
Devin Lim142b5342017-07-20 15:22:39 -070035 def CASE0( self, main ):
YPZhanga482c202016-02-18 17:03:07 -080036 import sys
37 import json
38 import time
39 import os
40 import imp
Devin Lim58046fa2017-07-05 16:55:00 -070041 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 Lim44075962017-08-11 10:56:37 -070046 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070047 main.testSetUp.envSetupDescription()
48 stepResult = main.FALSE
49 try:
YPZhanga482c202016-02-18 17:03:07 -080050
Devin Lim58046fa2017-07-05 16:55:00 -070051 # 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' ]
YPZhanga482c202016-02-18 17:03:07 -080061
Devin Lim58046fa2017-07-05 16:55:00 -070062 # 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 Lim87e12c42017-07-20 13:53:04 -070078 main.nic = main.params[ 'DATABASE' ][ 'nic' ]
Devin Lim58046fa2017-07-05 16:55:00 -070079 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 Lim142b5342017-07-20 15:22:39 -070085 stepResult = main.testSetUp.envSetup()
Devin Lim58046fa2017-07-05 16:55:00 -070086 except Exception as e:
87 main.testSetUp.envSetupException( e )
88 main.testSetUp.evnSetupConclusion( stepResult )
89
90 main.commit = main.commit.split( " " )[ 1 ]
91
YPZhanga482c202016-02-18 17:03:07 -080092 def CASE2( self, main ):
93 """
94 - Uninstall ONOS cluster
95 - Verify ONOS start up
96 - Install ONOS cluster
97 - Connect to cli
98 """
You Wanga0f6ff62018-01-11 15:46:30 -080099 main.testSetUp.ONOSSetUp( main.Cluster, True,
Devin Lim142b5342017-07-20 15:22:39 -0700100 cellName=main.cellName, killRemoveMax=False )
YPZhanga482c202016-02-18 17:03:07 -0800101
102 def CASE11( self, main ):
103 main.log.info( "set and configure Application" )
104 import json
105 import time
Devin Lim142b5342017-07-20 15:22:39 -0700106 time.sleep( main.startUpSleep )
YPZhanga482c202016-02-18 17:03:07 -0800107 main.step( "Activating org.onosproject.proxyarp" )
Devin Lim142b5342017-07-20 15:22:39 -0700108 appStatus = utilities.retry( main.Cluster.active( 0 ).REST.activateApp,
YPZhanga482c202016-02-18 17:03:07 -0800109 main.FALSE,
Devin Lim58046fa2017-07-05 16:55:00 -0700110 [ 'org.onosproject.proxyarp' ],
YPZhanga482c202016-02-18 17:03:07 -0800111 sleep=3,
112 attempts=3 )
113 utilities.assert_equals( expect=main.TRUE,
114 actual=appStatus,
115 onpass="Successfully activated proxyarp",
Devin Lim142b5342017-07-20 15:22:39 -0700116 onfail="Failed to activated proxyarp" )
YPZhanga482c202016-02-18 17:03:07 -0800117
118 main.step( "Set up Default Topology Provider" )
119 appStatus = main.TRUE
120 configName = 'org.onosproject.net.topology.impl.DefaultTopologyProvider'
121 configParam = 'maxEvents'
Devin Lim142b5342017-07-20 15:22:39 -0700122 appStatus = appStatus and main.Cluster.active( 0 ).CLI.setCfg( configName, configParam, '1' )
YPZhanga482c202016-02-18 17:03:07 -0800123 configParam = 'maxBatchMs'
Devin Lim142b5342017-07-20 15:22:39 -0700124 appStatus = appStatus and main.Cluster.active( 0 ).CLI.setCfg( configName, configParam, '0' )
YPZhanga482c202016-02-18 17:03:07 -0800125 configParam = 'maxIdleMs'
Devin Lim142b5342017-07-20 15:22:39 -0700126 appStatus = appStatus and main.Cluster.active( 0 ).CLI.setCfg( configName, configParam, '0' )
YPZhanga482c202016-02-18 17:03:07 -0800127 utilities.assert_equals( expect=main.TRUE,
128 actual=appStatus,
129 onpass="Successfully set DefaultTopologyProvider",
130 onfail="Failed to set DefaultTopologyProvider" )
131
Devin Lim142b5342017-07-20 15:22:39 -0700132 time.sleep( main.startUpSleep )
133 main.step( 'Starting mininet topology' )
Devin Lim3e8c6d92018-05-10 16:03:07 -0700134 mnCmd = '--topo=linear,1 '
135 for ctrl in main.Cluster.active():
136 mnCmd += " --controller remote,ip=" + ctrl.ipAddress
137 mnStatus = main.Mininet1.startNet( args=mnCmd )
YPZhanga482c202016-02-18 17:03:07 -0800138 utilities.assert_equals( expect=main.TRUE,
139 actual=mnStatus,
140 onpass="Successfully started Mininet",
141 onfail="Failed to activate Mininet" )
Devin Lim142b5342017-07-20 15:22:39 -0700142 main.step( "Assinging masters to switches" )
YPZhanga482c202016-02-18 17:03:07 -0800143 switches = main.Mininet1.getSwitches()
Devin Lim142b5342017-07-20 15:22:39 -0700144 swStatus = main.Mininet1.assignSwController( sw=switches.keys(),
145 ip=main.Cluster.active( 0 ).ipAddress )
YPZhanga482c202016-02-18 17:03:07 -0800146 utilities.assert_equals( expect=main.TRUE,
147 actual=swStatus,
148 onpass="Successfully assigned switches to masters",
149 onfail="Failed assign switches to masters" )
150
Devin Lim142b5342017-07-20 15:22:39 -0700151 time.sleep( main.startUpSleep )
YPZhanga482c202016-02-18 17:03:07 -0800152
Devin Lim142b5342017-07-20 15:22:39 -0700153 def CASE20( self, main ):
YPZhanga482c202016-02-18 17:03:07 -0800154 """
155 host1 send arping package and measure latency
156
157 There are only 1 levels of latency measurements to this test:
158 1 ) ARPING-to-device measurement: Measurement the time from host1
159 send apring package to onos processing the host event
160
161 """
162 import time
163 import subprocess
164 import json
165 import requests
166 import os
167 import numpy
Devin Lim58046fa2017-07-05 16:55:00 -0700168 try:
169 from tests.dependencies.utils import Utils
170 except ImportError:
171 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700172 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700173 try:
174 main.Utils
175 except ( NameError, AttributeError ):
176 main.Utils = Utils()
YPZhanga482c202016-02-18 17:03:07 -0800177 # Host adding measurement
178 assertion = main.TRUE
179
Devin Lim142b5342017-07-20 15:22:39 -0700180 main.log.report( 'Latency of adding one host to ONOS' )
181 main.log.report( 'First ' + str( main.iterIgnore ) + ' iterations ignored' + ' for jvm warmup time' )
182 main.log.report( 'Total iterations of test: ' + str( main.numlter ) )
YPZhanga482c202016-02-18 17:03:07 -0800183
184 addingHostTime = []
185 metricsResultList = []
Devin Lim58046fa2017-07-05 16:55:00 -0700186 for i in range( 0, int( main.numlter ) ):
187 main.log.info( 'Clean up data file' )
188 with open( main.tsharkResultPath, "w" ) as dbFile:
189 dbFile.write( "" )
YPZhanga482c202016-02-18 17:03:07 -0800190
Devin Lim142b5342017-07-20 15:22:39 -0700191 main.log.info( 'Starting tshark capture' )
Devin Lim58046fa2017-07-05 16:55:00 -0700192 main.ONOSbench.tsharkGrep( main.tsharkPacketIn, main.tsharkResultPath )
193 time.sleep( main.measurementSleep )
YPZhanga482c202016-02-18 17:03:07 -0800194
Devin Lim142b5342017-07-20 15:22:39 -0700195 main.log.info( 'host 1 arping...' )
196 main.Mininet1.arping( srcHost='h1', dstHost='10.0.0.2' )
YPZhanga482c202016-02-18 17:03:07 -0800197
Devin Lim58046fa2017-07-05 16:55:00 -0700198 time.sleep( main.measurementSleep )
YPZhanga482c202016-02-18 17:03:07 -0800199
Devin Lim142b5342017-07-20 15:22:39 -0700200 main.log.info( 'Stopping all Tshark processes' )
YPZhanga482c202016-02-18 17:03:07 -0800201 main.ONOSbench.tsharkStop()
202
Devin Lim58046fa2017-07-05 16:55:00 -0700203 time.sleep( main.measurementSleep )
YPZhanga482c202016-02-18 17:03:07 -0800204
205 # Get tshark output
Devin Lim58046fa2017-07-05 16:55:00 -0700206 with open( main.tsharkResultPath, "r" ) as resultFile:
YPZhanga482c202016-02-18 17:03:07 -0800207 resultText = resultFile.readline()
Devin Lim58046fa2017-07-05 16:55:00 -0700208 main.log.info( 'Capture result:' + resultText )
Devin Lim142b5342017-07-20 15:22:39 -0700209 resultText = resultText.split( ' ' )
Devin Lim58046fa2017-07-05 16:55:00 -0700210 if len( resultText ) > 1:
211 tsharkResultTime = float( resultText[ 1 ] ) * 1000.0
YPZhanga482c202016-02-18 17:03:07 -0800212 else:
Devin Lim58046fa2017-07-05 16:55:00 -0700213 main.log.error( 'Tshark output file for packet_in' + ' returned unexpected results' )
YPZhanga482c202016-02-18 17:03:07 -0800214 hostTime = 0
215 caseResult = main.FALSE
216 resultFile.close()
217 # Compare the timestemps, and get the lowest one.
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700218 temp = 0
YPZhanga482c202016-02-18 17:03:07 -0800219 # Get host event timestamps from each nodes
Devin Lim142b5342017-07-20 15:22:39 -0700220 for ctrl in main.Cluster.active():
221 metricsResult = json.loads( ctrl.CLI.topologyEventsMetrics() )
Devin Lim58046fa2017-07-05 16:55:00 -0700222 metricsResult = metricsResult.get( main.hostTimestampKey ).get( "value" )
223 main.log.info( "ONOS topology event matrics timestemp: {}".format( str( metricsResult ) ) )
YPZhanga482c202016-02-18 17:03:07 -0800224
225 if temp < metricsResult:
226 temp = metricsResult
227 metricsResult = temp
228
You Wang02a83a72018-07-17 12:48:11 -0700229 if i >= main.iterIgnore:
230 addingHostTime.append( float( metricsResult ) - tsharkResultTime )
Devin Lim142b5342017-07-20 15:22:39 -0700231 main.log.info( "Result of this iteration: {}".format( str( float( metricsResult ) - tsharkResultTime ) ) )
YPZhanga482c202016-02-18 17:03:07 -0800232 # gethost to remove
Devin Lim142b5342017-07-20 15:22:39 -0700233 gethost = main.Cluster.active( 0 ).REST.hosts()
YPZhanga482c202016-02-18 17:03:07 -0800234 HosttoRemove = []
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700235 HosttoRemove.append( json.loads( gethost[ 1:len( gethost ) - 1 ] ).get( 'id' ) )
Devin Lim142b5342017-07-20 15:22:39 -0700236 main.Cluster.active( 0 ).CLI.removeHost( HosttoRemove )
YPZhanga482c202016-02-18 17:03:07 -0800237
Devin Lim58046fa2017-07-05 16:55:00 -0700238 main.log.info( "Result List: {}".format( addingHostTime ) )
YPZhang82ca5892016-03-01 15:32:09 -0800239
YPZhanga482c202016-02-18 17:03:07 -0800240 # calculate average latency from each nodes
Devin Lim58046fa2017-07-05 16:55:00 -0700241 averageResult = numpy.average( addingHostTime )
242 main.log.info( "Average Latency: {}".format( averageResult ) )
YPZhanga482c202016-02-18 17:03:07 -0800243
244 # calculate std
Devin Lim142b5342017-07-20 15:22:39 -0700245 stdResult = numpy.std( addingHostTime )
246 main.log.info( "std: {}".format( stdResult ) )
YPZhanga482c202016-02-18 17:03:07 -0800247
You Wang012300d2019-02-21 17:55:39 -0800248 # Check test results
249 threshold = float( main.params[ 'ALARM' ][ 'maxLat' ].split( ',' )[ main.cycle - 1 ] )
250 if averageResult > threshold:
251 main.log.alarm( "{}-node: {} ms > {} ms".format( main.Cluster.numCtrls,
252 averageResult, threshold ) )
253
YPZhanga482c202016-02-18 17:03:07 -0800254 # write to DB file
Devin Lim142b5342017-07-20 15:22:39 -0700255 main.log.info( "Writing results to DS file" )
256 with open( main.dbFileName, "a" ) as dbFile:
Devin Lim87e12c42017-07-20 13:53:04 -0700257 temp = "'" + main.commit + "',"
258 temp += "'" + main.nic + "',"
YPZhanga482c202016-02-18 17:03:07 -0800259 # Scale number
Devin Lim142b5342017-07-20 15:22:39 -0700260 temp += str( main.Cluster.numCtrls )
YPZhanga482c202016-02-18 17:03:07 -0800261 temp += ",'" + "baremetal1" + "'"
262 # average latency
263 temp += "," + str( averageResult )
264 # std of latency
Devin Lim142b5342017-07-20 15:22:39 -0700265 temp += "," + str( stdResult )
YPZhanga482c202016-02-18 17:03:07 -0800266 temp += "\n"
267 dbFile.write( temp )
268
269 assertion = main.TRUE
270
Devin Lim142b5342017-07-20 15:22:39 -0700271 utilities.assert_equals( expect=main.TRUE, actual=assertion,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700272 onpass='Host latency test successful',
273 onfail='Host latency test failed' )
YPZhanga482c202016-02-18 17:03:07 -0800274
Devin Lim58046fa2017-07-05 16:55:00 -0700275 main.Utils.mininetCleanup( main.Mininet1 )