blob: 8ab7a44f8b444ac5676933017f21c5ff8af86f8f [file] [log] [blame]
YPZhanga482c202016-02-18 17:03:07 -08001"""
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"""
10class 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 Lim58046fa2017-07-05 16:55:00 -070021 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" )
YPZhanga482c202016-02-18 17:03:07 -080026 main.exit()
Devin Lim58046fa2017-07-05 16:55:00 -070027 main.testSetUp.envSetupDescription()
28 stepResult = main.FALSE
29 try:
YPZhanga482c202016-02-18 17:03:07 -080030
Devin Lim58046fa2017-07-05 16:55:00 -070031 # 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' ]
YPZhanga482c202016-02-18 17:03:07 -080041
Devin Lim58046fa2017-07-05 16:55:00 -070042 # 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:
YPZhanga482c202016-02-18 17:03:07 -080076 temp = "'" + main.commit + "',"
77 temp += "'" + nic + "',"
Devin Lim58046fa2017-07-05 16:55:00 -070078 dbFile.write( temp )
YPZhanga482c202016-02-18 17:03:07 -080079 dbFile.close()
Devin Lim58046fa2017-07-05 16:55:00 -070080 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 )
YPZhanga482c202016-02-18 17:03:07 -080084
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 Lim58046fa2017-07-05 16:55:00 -070092 main.testSetUp.ONOSSetUp( main.Mininet1, True,
93 cellName=main.cellName, killRemoveMax=False,
94 CtrlsSet=False )
YPZhanga482c202016-02-18 17:03:07 -080095
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 Lim58046fa2017-07-05 16:55:00 -0700104 [ 'org.onosproject.proxyarp' ],
YPZhanga482c202016-02-18 17:03:07 -0800105 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 Lim58046fa2017-07-05 16:55:00 -0700126 time.sleep( main.startUpSleep)
YPZhanga482c202016-02-18 17:03:07 -0800127 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 Lim58046fa2017-07-05 16:55:00 -0700141 time.sleep( main.startUpSleep)
YPZhanga482c202016-02-18 17:03:07 -0800142
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 Lim58046fa2017-07-05 16:55:00 -0700158 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()
YPZhanga482c202016-02-18 17:03:07 -0800167 # Host adding measurement
168 assertion = main.TRUE
169
170 main.log.report('Latency of adding one host to ONOS')
Devin Lim58046fa2017-07-05 16:55:00 -0700171 main.log.report('First ' + str( main.iterIgnore ) + ' iterations ignored' + ' for jvm warmup time')
172 main.log.report('Total iterations of test: ' + str( main.numlter ) )
YPZhanga482c202016-02-18 17:03:07 -0800173
174 addingHostTime = []
175 metricsResultList = []
Devin Lim58046fa2017-07-05 16:55:00 -0700176 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( "" )
YPZhanga482c202016-02-18 17:03:07 -0800180
181 main.log.info('Starting tshark capture')
Devin Lim58046fa2017-07-05 16:55:00 -0700182 main.ONOSbench.tsharkGrep( main.tsharkPacketIn, main.tsharkResultPath )
183 time.sleep( main.measurementSleep )
YPZhanga482c202016-02-18 17:03:07 -0800184
185 main.log.info('host 1 arping...')
186 main.Mininet1.arping(srcHost='h1', dstHost='10.0.0.2')
187
Devin Lim58046fa2017-07-05 16:55:00 -0700188 time.sleep( main.measurementSleep )
YPZhanga482c202016-02-18 17:03:07 -0800189
190 main.log.info('Stopping all Tshark processes')
191 main.ONOSbench.tsharkStop()
192
Devin Lim58046fa2017-07-05 16:55:00 -0700193 time.sleep( main.measurementSleep )
YPZhanga482c202016-02-18 17:03:07 -0800194
195 # Get tshark output
Devin Lim58046fa2017-07-05 16:55:00 -0700196 with open( main.tsharkResultPath, "r" ) as resultFile:
YPZhanga482c202016-02-18 17:03:07 -0800197 resultText = resultFile.readline()
Devin Lim58046fa2017-07-05 16:55:00 -0700198 main.log.info( 'Capture result:' + resultText )
YPZhanga482c202016-02-18 17:03:07 -0800199 resultText = resultText.split(' ')
Devin Lim58046fa2017-07-05 16:55:00 -0700200 if len( resultText ) > 1:
201 tsharkResultTime = float( resultText[ 1 ] ) * 1000.0
YPZhanga482c202016-02-18 17:03:07 -0800202 else:
Devin Lim58046fa2017-07-05 16:55:00 -0700203 main.log.error( 'Tshark output file for packet_in' + ' returned unexpected results' )
YPZhanga482c202016-02-18 17:03:07 -0800204 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 Lim58046fa2017-07-05 16:55:00 -0700210 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 ) ) )
YPZhanga482c202016-02-18 17:03:07 -0800214
215 if temp < metricsResult:
216 temp = metricsResult
217 metricsResult = temp
218
Devin Lim58046fa2017-07-05 16:55:00 -0700219 addingHostTime.append( float( metricsResult ) - tsharkResultTime )
220 main.log.info( "Result of this iteration: {}".format( str( float( metricsResult ) - tsharkResultTime) ) )
YPZhanga482c202016-02-18 17:03:07 -0800221 # gethost to remove
222 gethost = main.ONOSrest1.hosts()
223 HosttoRemove = []
Devin Lim58046fa2017-07-05 16:55:00 -0700224 HosttoRemove.append( json.loads( gethost[ 1:len( gethost )-1 ] ).get( 'id' ) )
225 main.CLIs[0].removeHost( HosttoRemove )
YPZhanga482c202016-02-18 17:03:07 -0800226
Devin Lim58046fa2017-07-05 16:55:00 -0700227 main.log.info( "Result List: {}".format( addingHostTime ) )
YPZhang82ca5892016-03-01 15:32:09 -0800228
YPZhanga482c202016-02-18 17:03:07 -0800229 # calculate average latency from each nodes
Devin Lim58046fa2017-07-05 16:55:00 -0700230 averageResult = numpy.average( addingHostTime )
231 main.log.info( "Average Latency: {}".format( averageResult ) )
YPZhanga482c202016-02-18 17:03:07 -0800232
233 # calculate std
234 stdResult = numpy.std(addingHostTime)
YPZhang82ca5892016-03-01 15:32:09 -0800235 main.log.info("std: {}".format(stdResult))
YPZhanga482c202016-02-18 17:03:07 -0800236
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 Lim58046fa2017-07-05 16:55:00 -0700256 main.Utils.mininetCleanup( main.Mininet1 )