blob: ec12f354e68903f602c030986eca41af62e2f631 [file] [log] [blame]
YPZhanga482c202016-02-18 17:03:07 -08001"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07002Copyright 2016 Open Networking Foundation (ONF)
3
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
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"""
YPZhanga482c202016-02-18 17:03:07 -080023 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"""
31class 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 Lim58046fa2017-07-05 16:55:00 -070042 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" )
YPZhanga482c202016-02-18 17:03:07 -080047 main.exit()
Devin Lim58046fa2017-07-05 16:55:00 -070048 main.testSetUp.envSetupDescription()
49 stepResult = main.FALSE
50 try:
YPZhanga482c202016-02-18 17:03:07 -080051
Devin Lim58046fa2017-07-05 16:55:00 -070052 # 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' ]
YPZhanga482c202016-02-18 17:03:07 -080062
Devin Lim58046fa2017-07-05 16:55:00 -070063 # 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
Devin Lim87e12c42017-07-20 13:53:04 -070079 main.nic = main.params[ 'DATABASE' ][ 'nic' ]
Devin Lim58046fa2017-07-05 16:55:00 -070080 node = main.params[ 'DATABASE' ][ 'node' ]
81 stepResult = main.TRUE
82
83 main.log.info( "Cresting DB file" )
84 with open( main.dbFileName, "w+" ) as dbFile:
85 dbFile.write( "" )
Devin Lim58046fa2017-07-05 16:55:00 -070086 stepResult = main.testSetUp.gitPulling()
87 except Exception as e:
88 main.testSetUp.envSetupException( e )
89 main.testSetUp.evnSetupConclusion( stepResult )
90
91 main.commit = main.commit.split( " " )[ 1 ]
92
Devin Lim58046fa2017-07-05 16:55:00 -070093 def CASE1( self ):
94 # main.scale[ 0 ] determines the current number of ONOS controller
95 main.testSetUp.getNumCtrls( True )
96 main.testSetUp.envSetup( includeGitPull=False, makeMaxNodes=False )
YPZhanga482c202016-02-18 17:03:07 -080097
98 def CASE2( self, main ):
99 """
100 - Uninstall ONOS cluster
101 - Verify ONOS start up
102 - Install ONOS cluster
103 - Connect to cli
104 """
Devin Lim58046fa2017-07-05 16:55:00 -0700105 main.testSetUp.ONOSSetUp( main.Mininet1, True,
106 cellName=main.cellName, killRemoveMax=False,
107 CtrlsSet=False )
YPZhanga482c202016-02-18 17:03:07 -0800108
109 def CASE11( self, main ):
110 main.log.info( "set and configure Application" )
111 import json
112 import time
113 time.sleep(main.startUpSleep)
114 main.step( "Activating org.onosproject.proxyarp" )
115 appStatus = utilities.retry( main.ONOSrest1.activateApp,
116 main.FALSE,
Devin Lim58046fa2017-07-05 16:55:00 -0700117 [ 'org.onosproject.proxyarp' ],
YPZhanga482c202016-02-18 17:03:07 -0800118 sleep=3,
119 attempts=3 )
120 utilities.assert_equals( expect=main.TRUE,
121 actual=appStatus,
122 onpass="Successfully activated proxyarp",
123 onfail="Failed to activated proxyarp")
124
125 main.step( "Set up Default Topology Provider" )
126 appStatus = main.TRUE
127 configName = 'org.onosproject.net.topology.impl.DefaultTopologyProvider'
128 configParam = 'maxEvents'
129 appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam,'1' )
130 configParam = 'maxBatchMs'
131 appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam, '0')
132 configParam = 'maxIdleMs'
133 appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam,'0' )
134 utilities.assert_equals( expect=main.TRUE,
135 actual=appStatus,
136 onpass="Successfully set DefaultTopologyProvider",
137 onfail="Failed to set DefaultTopologyProvider" )
138
Devin Lim58046fa2017-07-05 16:55:00 -0700139 time.sleep( main.startUpSleep)
YPZhanga482c202016-02-18 17:03:07 -0800140 main.step('Starting mininet topology')
141 mnStatus = main.Mininet1.startNet(args='--topo=linear,1')
142 utilities.assert_equals( expect=main.TRUE,
143 actual=mnStatus,
144 onpass="Successfully started Mininet",
145 onfail="Failed to activate Mininet" )
146 main.step("Assinging masters to switches")
147 switches = main.Mininet1.getSwitches()
148 swStatus = main.Mininet1.assignSwController( sw=switches.keys(), ip=main.ONOSip[0] )
149 utilities.assert_equals( expect=main.TRUE,
150 actual=swStatus,
151 onpass="Successfully assigned switches to masters",
152 onfail="Failed assign switches to masters" )
153
Devin Lim58046fa2017-07-05 16:55:00 -0700154 time.sleep( main.startUpSleep)
YPZhanga482c202016-02-18 17:03:07 -0800155
156 def CASE20(self, main):
157 """
158 host1 send arping package and measure latency
159
160 There are only 1 levels of latency measurements to this test:
161 1 ) ARPING-to-device measurement: Measurement the time from host1
162 send apring package to onos processing the host event
163
164 """
165 import time
166 import subprocess
167 import json
168 import requests
169 import os
170 import numpy
Devin Lim58046fa2017-07-05 16:55:00 -0700171 try:
172 from tests.dependencies.utils import Utils
173 except ImportError:
174 main.log.error( "Utils not found exiting the test" )
175 main.exit()
176 try:
177 main.Utils
178 except ( NameError, AttributeError ):
179 main.Utils = Utils()
YPZhanga482c202016-02-18 17:03:07 -0800180 # Host adding measurement
181 assertion = main.TRUE
182
183 main.log.report('Latency of adding one host to ONOS')
Devin Lim58046fa2017-07-05 16:55:00 -0700184 main.log.report('First ' + str( main.iterIgnore ) + ' iterations ignored' + ' for jvm warmup time')
185 main.log.report('Total iterations of test: ' + str( main.numlter ) )
YPZhanga482c202016-02-18 17:03:07 -0800186
187 addingHostTime = []
188 metricsResultList = []
Devin Lim58046fa2017-07-05 16:55:00 -0700189 for i in range( 0, int( main.numlter ) ):
190 main.log.info( 'Clean up data file' )
191 with open( main.tsharkResultPath, "w" ) as dbFile:
192 dbFile.write( "" )
YPZhanga482c202016-02-18 17:03:07 -0800193
194 main.log.info('Starting tshark capture')
Devin Lim58046fa2017-07-05 16:55:00 -0700195 main.ONOSbench.tsharkGrep( main.tsharkPacketIn, main.tsharkResultPath )
196 time.sleep( main.measurementSleep )
YPZhanga482c202016-02-18 17:03:07 -0800197
198 main.log.info('host 1 arping...')
199 main.Mininet1.arping(srcHost='h1', dstHost='10.0.0.2')
200
Devin Lim58046fa2017-07-05 16:55:00 -0700201 time.sleep( main.measurementSleep )
YPZhanga482c202016-02-18 17:03:07 -0800202
203 main.log.info('Stopping all Tshark processes')
204 main.ONOSbench.tsharkStop()
205
Devin Lim58046fa2017-07-05 16:55:00 -0700206 time.sleep( main.measurementSleep )
YPZhanga482c202016-02-18 17:03:07 -0800207
208 # Get tshark output
Devin Lim58046fa2017-07-05 16:55:00 -0700209 with open( main.tsharkResultPath, "r" ) as resultFile:
YPZhanga482c202016-02-18 17:03:07 -0800210 resultText = resultFile.readline()
Devin Lim58046fa2017-07-05 16:55:00 -0700211 main.log.info( 'Capture result:' + resultText )
YPZhanga482c202016-02-18 17:03:07 -0800212 resultText = resultText.split(' ')
Devin Lim58046fa2017-07-05 16:55:00 -0700213 if len( resultText ) > 1:
214 tsharkResultTime = float( resultText[ 1 ] ) * 1000.0
YPZhanga482c202016-02-18 17:03:07 -0800215 else:
Devin Lim58046fa2017-07-05 16:55:00 -0700216 main.log.error( 'Tshark output file for packet_in' + ' returned unexpected results' )
YPZhanga482c202016-02-18 17:03:07 -0800217 hostTime = 0
218 caseResult = main.FALSE
219 resultFile.close()
220 # Compare the timestemps, and get the lowest one.
221 temp = 0;
222 # Get host event timestamps from each nodes
Devin Lim58046fa2017-07-05 16:55:00 -0700223 for node in range ( 0, main.numCtrls ):
224 metricsResult = json.loads( main.CLIs[ node ].topologyEventsMetrics() )
225 metricsResult = metricsResult.get( main.hostTimestampKey ).get( "value" )
226 main.log.info( "ONOS topology event matrics timestemp: {}".format( str( metricsResult ) ) )
YPZhanga482c202016-02-18 17:03:07 -0800227
228 if temp < metricsResult:
229 temp = metricsResult
230 metricsResult = temp
231
Devin Lim58046fa2017-07-05 16:55:00 -0700232 addingHostTime.append( float( metricsResult ) - tsharkResultTime )
233 main.log.info( "Result of this iteration: {}".format( str( float( metricsResult ) - tsharkResultTime) ) )
YPZhanga482c202016-02-18 17:03:07 -0800234 # gethost to remove
235 gethost = main.ONOSrest1.hosts()
236 HosttoRemove = []
Devin Lim58046fa2017-07-05 16:55:00 -0700237 HosttoRemove.append( json.loads( gethost[ 1:len( gethost )-1 ] ).get( 'id' ) )
238 main.CLIs[0].removeHost( HosttoRemove )
YPZhanga482c202016-02-18 17:03:07 -0800239
Devin Lim58046fa2017-07-05 16:55:00 -0700240 main.log.info( "Result List: {}".format( addingHostTime ) )
YPZhang82ca5892016-03-01 15:32:09 -0800241
YPZhanga482c202016-02-18 17:03:07 -0800242 # calculate average latency from each nodes
Devin Lim58046fa2017-07-05 16:55:00 -0700243 averageResult = numpy.average( addingHostTime )
244 main.log.info( "Average Latency: {}".format( averageResult ) )
YPZhanga482c202016-02-18 17:03:07 -0800245
246 # calculate std
247 stdResult = numpy.std(addingHostTime)
YPZhang82ca5892016-03-01 15:32:09 -0800248 main.log.info("std: {}".format(stdResult))
YPZhanga482c202016-02-18 17:03:07 -0800249
250 # write to DB file
251 main.log.info("Writing results to DS file")
252 with open(main.dbFileName, "a") as dbFile:
Devin Lim87e12c42017-07-20 13:53:04 -0700253 temp = "'" + main.commit + "',"
254 temp += "'" + main.nic + "',"
YPZhanga482c202016-02-18 17:03:07 -0800255 # Scale number
Devin Lim87e12c42017-07-20 13:53:04 -0700256 temp += str( main.numCtrls )
YPZhanga482c202016-02-18 17:03:07 -0800257 temp += ",'" + "baremetal1" + "'"
258 # average latency
259 temp += "," + str( averageResult )
260 # std of latency
261 temp += "," + str(stdResult)
262 temp += "\n"
263 dbFile.write( temp )
264
265 assertion = main.TRUE
266
267 utilities.assert_equals(expect=main.TRUE, actual=assertion,
268 onpass='Host latency test successful',
269 onfail='Host latency test failed')
270
Devin Lim58046fa2017-07-05 16:55:00 -0700271 main.Utils.mininetCleanup( main.Mininet1 )