blob: 12e53e5b2d47c7aadb15e1a3cb521afa1440fb8d [file] [log] [blame]
andrewonlab79244cc2015-01-26 01:11:49 -05001# TopoPerfNext
andrewonlab2a6c9342014-10-16 13:40:15 -04002#
andrewonlab79244cc2015-01-26 01:11:49 -05003# Topology Performance test for ONOS-next
andrewonlab2a6c9342014-10-16 13:40:15 -04004#
andrewonlab79244cc2015-01-26 01:11:49 -05005# andrew@onlab.us
andrewonlab4f50ec92014-11-11 14:24:45 -05006#
andrewonlab79244cc2015-01-26 01:11:49 -05007# If your machine does not come with numpy
8# run the following command:
9# sudo apt-get install python-numpy python-scipy
andrewonlab2a6c9342014-10-16 13:40:15 -040010
11import time
12import sys
13import os
14import re
15
andrewonlab79244cc2015-01-26 01:11:49 -050016
andrewonlab2a6c9342014-10-16 13:40:15 -040017class TopoPerfNext:
andrewonlab79244cc2015-01-26 01:11:49 -050018
19 def __init__( self ):
andrewonlab2a6c9342014-10-16 13:40:15 -040020 self.default = ''
21
andrewonlab79244cc2015-01-26 01:11:49 -050022 def CASE1( self, main ):
23 """
andrewonlab2a6c9342014-10-16 13:40:15 -040024 ONOS startup sequence
andrewonlab79244cc2015-01-26 01:11:49 -050025 """
andrewonlabe9fb6722014-10-24 12:20:35 -040026 import time
andrewonlab79244cc2015-01-26 01:11:49 -050027
28 # Global cluster count for scale-out purposes
29 global clusterCount
30 # Set initial cluster count
31 clusterCount = 1
andrewonlaba57a3042015-01-23 13:53:05 -050032 ##
andrewonlab2a6c9342014-10-16 13:40:15 -040033
andrewonlab79244cc2015-01-26 01:11:49 -050034 cellName = main.params[ 'ENV' ][ 'cellName' ]
andrewonlab2a6c9342014-10-16 13:40:15 -040035
andrewonlab79244cc2015-01-26 01:11:49 -050036 gitPull = main.params[ 'GIT' ][ 'autoPull' ]
37 checkoutBranch = main.params[ 'GIT' ][ 'checkout' ]
kelvin-onlab8a832582015-01-16 17:06:11 -080038
andrewonlab79244cc2015-01-26 01:11:49 -050039 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
40 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
41 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
42 ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
43 ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
44 ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
45 ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
46
47 MN1Ip = main.params[ 'MN' ][ 'ip1' ]
48 BENCHIp = main.params[ 'BENCH' ][ 'ip' ]
49
50 topoCfgFile = main.params[ 'TEST' ][ 'topoConfigFile' ]
51 topoCfgName = main.params[ 'TEST' ][ 'topoConfigName' ]
52
53 mvnCleanInstall = main.params[ 'TEST' ][ 'mci' ]
andrewonlaba57a3042015-01-23 13:53:05 -050054
andrewonlab79244cc2015-01-26 01:11:49 -050055 main.case( "Setting up test environment" )
56 main.log.info( "Copying topology event accumulator config" +
57 " to ONOS /package/etc" )
58 main.ONOSbench.handle.sendline( "cp ~/" +
59 topoCfgFile +
60 " ~/ONOS/tools/package/etc/" +
61 topoCfgName )
62 main.ONOSbench.handle.expect( "\$" )
andrewonlab6c8bbeb2014-11-14 12:43:48 -050063
andrewonlab79244cc2015-01-26 01:11:49 -050064 main.log.report( "Setting up test environment" )
andrewonlab2a6c9342014-10-16 13:40:15 -040065
andrewonlab79244cc2015-01-26 01:11:49 -050066 main.step( "Cleaning previously installed ONOS if any" )
67 main.ONOSbench.onosUninstall( nodeIp=ONOS2Ip )
68 main.ONOSbench.onosUninstall( nodeIp=ONOS3Ip )
69 main.ONOSbench.onosUninstall( nodeIp=ONOS4Ip )
70 main.ONOSbench.onosUninstall( nodeIp=ONOS5Ip )
71 main.ONOSbench.onosUninstall( nodeIp=ONOS6Ip )
72 #main.ONOSbench.onosUninstall( nodeIp=ONOS7Ip )
andrewonlab0e1825c2014-11-20 20:07:00 -050073
andrewonlab79244cc2015-01-26 01:11:49 -050074 main.step( "Creating cell file" )
75 cellFileResult = main.ONOSbench.createCellFile(
76 BENCHIp, cellName, MN1Ip,
77 "onos-core,onos-app-metrics,onos-app-gui",
78 ONOS1Ip )
andrewonlab2a6c9342014-10-16 13:40:15 -040079
andrewonlab79244cc2015-01-26 01:11:49 -050080 main.step( "Applying cell file to environment" )
81 cellApplyResult = main.ONOSbench.setCell( cellName )
82 verifyCellResult = main.ONOSbench.verifyCell()
andrewonlab6c8bbeb2014-11-14 12:43:48 -050083
andrewonlab79244cc2015-01-26 01:11:49 -050084 # NOTE: This step may be removed after proper
kelvin-onlab8a832582015-01-16 17:06:11 -080085 # copy cat log functionality
andrewonlab79244cc2015-01-26 01:11:49 -050086 main.step( "Removing raft/copy-cat logs from ONOS nodes" )
87 main.ONOSbench.onosRemoveRaftLogs()
88 time.sleep( 30 )
kelvin-onlab8a832582015-01-16 17:06:11 -080089
andrewonlab79244cc2015-01-26 01:11:49 -050090 main.step( "Git checkout and pull " + checkoutBranch )
91 if gitPull == 'on':
92 # checkoutResult = \
93 # main.ONOSbench.gitCheckout( checkoutBranch )
94 checkoutResult = main.TRUE
95 pullResult = main.ONOSbench.gitPull()
andrewonlab2a6c9342014-10-16 13:40:15 -040096 else:
andrewonlab79244cc2015-01-26 01:11:49 -050097 checkoutResult = main.TRUE
98 pullResult = main.TRUE
99 main.log.info( "Skipped git checkout and pull" )
andrewonlab2a6c9342014-10-16 13:40:15 -0400100
andrewonlab79244cc2015-01-26 01:11:49 -0500101 main.log.report( "Commit information - " )
102 main.ONOSbench.getVersion( report=True )
andrewonlab92844342014-11-18 16:39:11 -0500103
andrewonlab79244cc2015-01-26 01:11:49 -0500104 main.step( "Using mvn clean & install" )
105 if mvnCleanInstall == 'on':
106 mvnResult = main.ONOSbench.cleanInstall()
107 elif mvnCleanInstall == 'off':
108 main.log.info("mci turned off by settings")
109 mvnResult = main.TRUE
andrewonlab2a6c9342014-10-16 13:40:15 -0400110
andrewonlab79244cc2015-01-26 01:11:49 -0500111 main.step( "Set cell for ONOS cli env" )
112 main.ONOS1cli.setCell( cellName )
113 # main.ONOS2cli.setCell( cellName )
114 # main.ONOS3cli.setCell( cellName )
andrewonlabb1998c52014-11-10 13:31:43 -0500115
andrewonlab79244cc2015-01-26 01:11:49 -0500116 main.step( "Creating ONOS package" )
117 packageResult = main.ONOSbench.onosPackage()
andrewonlab2a6c9342014-10-16 13:40:15 -0400118
andrewonlab79244cc2015-01-26 01:11:49 -0500119 main.step( "Installing ONOS package" )
120 install1Result = main.ONOSbench.onosInstall( node=ONOS1Ip )
121 #install2Result = main.ONOSbench.onosInstall( node=ONOS2Ip )
122 #install3Result = main.ONOSbench.onosInstall( node=ONOS3Ip )
andrewonlab2a6c9342014-10-16 13:40:15 -0400123
andrewonlab79244cc2015-01-26 01:11:49 -0500124 time.sleep( 10 )
andrewonlabe9fb6722014-10-24 12:20:35 -0400125
andrewonlab79244cc2015-01-26 01:11:49 -0500126 main.step( "Start onos cli" )
127 cli1 = main.ONOS1cli.startOnosCli( ONOS1Ip )
128 #cli2 = main.ONOS2cli.startOnosCli( ONOS2Ip )
129 #cli3 = main.ONOS3cli.startOnosCli( ONOS3Ip )
andrewonlabe9fb6722014-10-24 12:20:35 -0400130
andrewonlab79244cc2015-01-26 01:11:49 -0500131 utilities.assert_equals( expect=main.TRUE,
132 actual=cellFileResult and cellApplyResult and
133 verifyCellResult and checkoutResult and
134 pullResult and mvnResult and
135 install1Result, # and install2Result and
136 # install3Result,
137 onpass="Test Environment setup successful",
138 onfail="Failed to setup test environment" )
andrewonlab2a6c9342014-10-16 13:40:15 -0400139
andrewonlab79244cc2015-01-26 01:11:49 -0500140 def CASE2( self, main ):
141 """
andrewonlabba44bcf2014-10-16 16:54:41 -0400142 Assign s1 to ONOS1 and measure latency
andrewonlab79244cc2015-01-26 01:11:49 -0500143
andrewonlab3a7c3c72014-10-24 17:21:03 -0400144 There are 4 levels of latency measurements to this test:
andrewonlab79244cc2015-01-26 01:11:49 -0500145 1 ) End-to-end measurement: Complete end-to-end measurement
146 from TCP ( SYN/ACK ) handshake to Graph change
147 2 ) OFP-to-graph measurement: 'ONOS processing' snippet of
andrewonlab3a7c3c72014-10-24 17:21:03 -0400148 measurement from OFP Vendor message to Graph change
andrewonlab79244cc2015-01-26 01:11:49 -0500149 3 ) OFP-to-device measurement: 'ONOS processing without
andrewonlab3a7c3c72014-10-24 17:21:03 -0400150 graph change' snippet of measurement from OFP vendor
151 message to Device change timestamp
andrewonlab79244cc2015-01-26 01:11:49 -0500152 4 ) T0-to-device measurement: Measurement that includes
153 the switch handshake to devices timestamp without
154 the graph view change. ( TCP handshake -> Device
155 change )
156 """
andrewonlabba44bcf2014-10-16 16:54:41 -0400157 import time
andrewonlabe6745342014-10-17 14:29:13 -0400158 import subprocess
159 import json
160 import requests
161 import os
andrewonlab4f50ec92014-11-11 14:24:45 -0500162 import numpy
andrewonlab79244cc2015-01-26 01:11:49 -0500163 global clusterCount
andrewonlabba44bcf2014-10-16 16:54:41 -0400164
andrewonlab79244cc2015-01-26 01:11:49 -0500165 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
166 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
167 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
168 ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
169 ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
170 ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
171 ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
andrewonlabe6745342014-10-17 14:29:13 -0400172
andrewonlab79244cc2015-01-26 01:11:49 -0500173 ONOSUser = main.params[ 'CTRL' ][ 'user' ]
andrewonlab4b5c8b92014-11-10 16:04:33 -0500174
andrewonlab79244cc2015-01-26 01:11:49 -0500175 defaultSwPort = main.params[ 'CTRL' ][ 'port1' ]
andrewonlab226024e2014-10-24 16:01:32 -0400176
andrewonlab79244cc2015-01-26 01:11:49 -0500177 # Number of iterations of case
178 numIter = main.params[ 'TEST' ][ 'numIter' ]
179 # Number of first 'x' iterations to ignore:
180 iterIgnore = int( main.params[ 'TEST' ][ 'iterIgnore' ] )
andrewonlab58f7d702014-11-07 13:21:19 -0500181
andrewonlab79244cc2015-01-26 01:11:49 -0500182 # Timestamp 'keys' for json metrics output.
183 # These are subject to change, hence moved into params
184 deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ]
185 graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ]
andrewonlabe5bcef92014-11-06 17:53:20 -0500186
andrewonlab79244cc2015-01-26 01:11:49 -0500187 debugMode = main.params[ 'TEST' ][ 'debugMode' ]
188 onosLog = main.params[ 'TEST' ][ 'onosLogFile' ]
kelvin-onlab8a832582015-01-16 17:06:11 -0800189
andrewonlab79244cc2015-01-26 01:11:49 -0500190 # Threshold for the test
191 thresholdStr = main.params[ 'TEST' ][ 'singleSwThreshold' ]
192 thresholdObj = thresholdStr.split( "," )
193 thresholdMin = int( thresholdObj[ 0 ] )
194 thresholdMax = int( thresholdObj[ 1 ] )
andrewonlab226024e2014-10-24 16:01:32 -0400195
andrewonlab79244cc2015-01-26 01:11:49 -0500196 # List of switch add latency collected from
197 # all iterations
198 latencyEndToEndList = []
199 latencyOfpToGraphList = []
200 latencyOfpToDeviceList = []
201 latencyT0ToDeviceList = []
202 latencyTcpToOfpList = []
andrewonlabba44bcf2014-10-16 16:54:41 -0400203
andrewonlab79244cc2015-01-26 01:11:49 -0500204 # Directory/file to store tshark results
205 tsharkOfOutput = "/tmp/tshark_of_topo.txt"
206 tsharkTcpOutput = "/tmp/tshark_tcp_topo.txt"
207
208 # String to grep in tshark output
209 tsharkTcpString = "TCP 74 " + defaultSwPort
210 tsharkOfString = "OFP 86 Vendor"
211
212 # Initialize assertion to TRUE
andrewonlabe6745342014-10-17 14:29:13 -0400213 assertion = main.TRUE
andrewonlabb1998c52014-11-10 13:31:43 -0500214
andrewonlab79244cc2015-01-26 01:11:49 -0500215 localTime = time.strftime( '%x %X' )
216 localTime = localTime.replace( "/", "" )
217 localTime = localTime.replace( " ", "_" )
218 localTime = localTime.replace( ":", "" )
219 if debugMode == 'on':
220 main.ONOS1.tsharkPcap( "eth0",
221 "/tmp/single_sw_lat_pcap_" + localTime )
andrewonlab58f7d702014-11-07 13:21:19 -0500222
andrewonlab79244cc2015-01-26 01:11:49 -0500223 main.log.info( "Debug mode is on" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400224
andrewonlab79244cc2015-01-26 01:11:49 -0500225 main.log.report( "Latency of adding one switch to controller" )
226 main.log.report( "First " + str( iterIgnore ) + " iterations ignored" +
227 " for jvm warmup time" )
228 main.log.report( "Total iterations of test: " + str( numIter ) )
andrewonlabba44bcf2014-10-16 16:54:41 -0400229
andrewonlab79244cc2015-01-26 01:11:49 -0500230 for i in range( 0, int( numIter ) ):
231 main.log.info( "Starting tshark capture" )
232
233 #* TCP [ ACK, SYN ] is used as t0A, the
234 # very first "exchange" between ONOS and
andrewonlabba44bcf2014-10-16 16:54:41 -0400235 # the switch for end-to-end measurement
andrewonlab79244cc2015-01-26 01:11:49 -0500236 #* OFP [ Stats Reply ] is used for t0B
andrewonlabba44bcf2014-10-16 16:54:41 -0400237 # the very last OFP message between ONOS
238 # and the switch for ONOS measurement
andrewonlab79244cc2015-01-26 01:11:49 -0500239 main.ONOS1.tsharkGrep( tsharkTcpString,
240 tsharkTcpOutput )
241 main.ONOS1.tsharkGrep( tsharkOfString,
242 tsharkOfOutput )
andrewonlabba44bcf2014-10-16 16:54:41 -0400243
andrewonlab79244cc2015-01-26 01:11:49 -0500244 # Wait and ensure tshark is started and
245 # capturing
246 time.sleep( 10 )
andrewonlabba44bcf2014-10-16 16:54:41 -0400247
andrewonlab79244cc2015-01-26 01:11:49 -0500248 main.log.info( "Assigning s1 to controller" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400249
andrewonlab79244cc2015-01-26 01:11:49 -0500250 main.Mininet1.assignSwController(
251 sw="1",
252 ip1=ONOS1Ip,
253 port1=defaultSwPort )
andrewonlabba44bcf2014-10-16 16:54:41 -0400254
andrewonlab79244cc2015-01-26 01:11:49 -0500255 # Wait and ensure switch is assigned
256 # before stopping tshark
257 time.sleep( 30 )
andrewonlabba44bcf2014-10-16 16:54:41 -0400258
andrewonlab79244cc2015-01-26 01:11:49 -0500259 main.log.info( "Stopping all Tshark processes" )
260 main.ONOS1.stopTshark()
kelvin-onlab8a832582015-01-16 17:06:11 -0800261
andrewonlab79244cc2015-01-26 01:11:49 -0500262 # tshark output is saved in ONOS. Use subprocess
263 # to copy over files to TestON for parsing
264 main.log.info( "Copying over tshark files" )
265
266 # TCP CAPTURE ****
267 # Copy the tshark output from ONOS machine to
268 # TestON machine in tsharkTcpOutput directory>file
269 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
270 tsharkTcpOutput + " /tmp/" )
271 tcpFile = open( tsharkTcpOutput, 'r' )
272 tempText = tcpFile.readline()
273 tempText = tempText.split( " " )
274
275 main.log.info( "Object read in from TCP capture: " +
276 str( tempText ) )
277 if len( tempText ) > 1:
278 t0Tcp = float( tempText[ 1 ] ) * 1000.0
andrewonlabe6745342014-10-17 14:29:13 -0400279 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500280 main.log.error( "Tshark output file for TCP" +
281 " returned unexpected results" )
282 t0Tcp = 0
andrewonlabe6745342014-10-17 14:29:13 -0400283 assertion = main.FALSE
andrewonlab79244cc2015-01-26 01:11:49 -0500284
285 tcpFile.close()
andrewonlabe6745342014-10-17 14:29:13 -0400286 #****************
andrewonlabba44bcf2014-10-16 16:54:41 -0400287
andrewonlab79244cc2015-01-26 01:11:49 -0500288 # OF CAPTURE ****
289 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
290 tsharkOfOutput + " /tmp/" )
291 ofFile = open( tsharkOfOutput, 'r' )
292
293 lineOfp = ""
294 # Read until last line of file
andrewonlabe6745342014-10-17 14:29:13 -0400295 while True:
andrewonlab79244cc2015-01-26 01:11:49 -0500296 tempText = ofFile.readline()
297 if tempText != '':
298 lineOfp = tempText
andrewonlabe6745342014-10-17 14:29:13 -0400299 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500300 break
301 obj = lineOfp.split( " " )
302
303 main.log.info( "Object read in from OFP capture: " +
304 str( lineOfp ) )
305
306 if len( lineOfp ) > 1:
307 t0Ofp = float( obj[ 1 ] ) * 1000.0
andrewonlabe6745342014-10-17 14:29:13 -0400308 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500309 main.log.error( "Tshark output file for OFP" +
310 " returned unexpected results" )
311 t0Ofp = 0
andrewonlabe6745342014-10-17 14:29:13 -0400312 assertion = main.FALSE
andrewonlab79244cc2015-01-26 01:11:49 -0500313
314 ofFile.close()
andrewonlabe6745342014-10-17 14:29:13 -0400315 #****************
andrewonlab867212a2014-10-22 20:13:38 -0400316
andrewonlab79244cc2015-01-26 01:11:49 -0500317 jsonStr1 = main.ONOS1cli.topologyEventsMetrics()
318 # Initialize scale-out variables
319 jsonStr2 = ""
320 jsonStr3 = ""
321 jsonStr4 = ""
322 jsonStr5 = ""
323 jsonStr6 = ""
324 jsonStr7 = ""
andrewonlabe9fb6722014-10-24 12:20:35 -0400325
andrewonlab79244cc2015-01-26 01:11:49 -0500326 jsonObj1 = json.loads( jsonStr1 )
327 # Initialize scale-out variables
328 jsonObj2 = ""
329 jsonObj3 = ""
330 jsonObj4 = ""
331 jsonObj5 = ""
332 jsonObj6 = ""
333 jsonObj7 = ""
kelvin-onlab8a832582015-01-16 17:06:11 -0800334
andrewonlab79244cc2015-01-26 01:11:49 -0500335 # Obtain graph timestamp. This timestsamp captures
336 # the epoch time at which the topology graph was updated.
337 graphTimestamp1 = \
338 jsonObj1[ graphTimestamp ][ 'value' ]
339 # Obtain device timestamp. This timestamp captures
340 # the epoch time at which the device event happened
341 deviceTimestamp1 = \
342 jsonObj1[ deviceTimestamp ][ 'value' ]
343
344 # t0 to device processing latency
345 deltaDevice1 = int( deviceTimestamp1 ) - int( t0Tcp )
346
347 # t0 to graph processing latency ( end-to-end )
348 deltaGraph1 = int( graphTimestamp1 ) - int( t0Tcp )
349
350 # ofp to graph processing latency ( ONOS processing )
351 deltaOfpGraph1 = int( graphTimestamp1 ) - int( t0Ofp )
352
353 # ofp to device processing latency ( ONOS processing )
354 deltaOfpDevice1 = float( deviceTimestamp1 ) - float( t0Ofp )
355
356 # TODO: Create even cluster number events
357
358 # Include scale-out measurements when applicable
359 if clusterCount >= 3:
360 jsonStr2 = main.ONOS2cli.topologyEventsMetrics()
361 jsonStr3 = main.ONOS3cli.topologyEventsMetrics()
362 jsonObj2 = json.loads( jsonStr2 )
363 jsonObj3 = json.loads( jsonStr3 )
364 graphTimestamp2 = \
365 jsonObj2[ graphTimestamp ][ 'value' ]
366 graphTimestamp3 = \
367 jsonObj3[ graphTimestamp ][ 'value' ]
368 deviceTimestamp2 = \
369 jsonObj2[ deviceTimestamp ][ 'value' ]
370 deviceTimestamp3 = \
371 jsonObj3[ deviceTimestamp ][ 'value' ]
372 deltaDevice2 = int( deviceTimestamp2 ) - int( t0Tcp )
373 deltaDevice3 = int( deviceTimestamp3 ) - int( t0Tcp )
374 deltaGraph2 = int( graphTimestamp2 ) - int( t0Tcp )
375 deltaGraph3 = int( graphTimestamp3 ) - int( t0Tcp )
376 deltaOfpGraph2 = int( graphTimestamp2 ) - int( t0Ofp )
377 deltaOfpGraph3 = int( graphTimestamp3 ) - int( t0Ofp )
378 deltaOfpDevice2 = float( deviceTimestamp2 ) -\
379 float( t0Ofp )
380 deltaOfpDevice3 = float( deviceTimestamp3 ) -\
381 float( t0Ofp )
andrewonlaba57a3042015-01-23 13:53:05 -0500382 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500383 deltaDevice2 = 0
384 deltaDevice3 = 0
385 deltaGraph2 = 0
386 deltaGraph3 = 0
387 deltaOfpGraph2 = 0
388 deltaOfpGraph3 = 0
389 deltaOfpDevice2 = 0
390 deltaOfpDevice3 = 0
andrewonlaba57a3042015-01-23 13:53:05 -0500391
andrewonlab79244cc2015-01-26 01:11:49 -0500392 if clusterCount >= 5:
393 jsonStr4 = main.ONOS4cli.topologyEventsMetrics()
394 jsonStr5 = main.ONOS5cli.topologyEventsMetrics()
395 jsonObj4 = json.loads( jsonStr4 )
396 jsonObj5 = json.loads( jsonStr5 )
397 graphTimestamp4 = \
398 jsonObj4[ graphTimestamp ][ 'value' ]
399 graphTimestamp5 = \
400 jsonObj5[ graphTimestamp ][ 'value' ]
401 deviceTimestamp4 = \
402 jsonObj4[ deviceTimestamp ][ 'value' ]
403 deviceTimestamp5 = \
404 jsonObj5[ deviceTimestamp ][ 'value' ]
405 deltaDevice4 = int( deviceTimestamp4 ) - int( t0Tcp )
406 deltaDevice5 = int( deviceTimestamp5 ) - int( t0Tcp )
407 deltaGraph4 = int( graphTimestamp4 ) - int( t0Tcp )
408 deltaGraph5 = int( graphTimestamp5 ) - int( t0Tcp )
409 deltaOfpGraph4 = int( graphTimestamp4 ) - int( t0Ofp )
410 deltaOfpGraph5 = int( graphTimestamp5 ) - int( t0Ofp )
411 deltaOfpDevice4 = float( deviceTimestamp4 ) -\
412 float( t0Ofp )
413 deltaOfpDevice5 = float( deviceTimestamp5 ) -\
414 float( t0Ofp )
andrewonlaba57a3042015-01-23 13:53:05 -0500415 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500416 deltaDevice4 = 0
417 deltaDevice5 = 0
418 deltaGraph4 = 0
419 deltaGraph5 = 0
420 deltaOfpGraph4 = 0
421 deltaOfpGraph5 = 0
422 deltaOfpDevice4 = 0
423 deltaOfpDevice5 = 0
andrewonlaba57a3042015-01-23 13:53:05 -0500424
andrewonlab79244cc2015-01-26 01:11:49 -0500425 if clusterCount >= 7:
426 jsonStr6 = main.ONOS6cli.topologyEventsMetrics()
427 jsonStr7 = main.ONOS7cli.topologyEventsMetrics()
428 jsonObj6 = json.loads( jsonStr6 )
429 jsonObj7 = json.loads( jsonStr7 )
430 graphTimestamp6 = \
431 jsonObj6[ graphTimestamp ][ 'value' ]
432 graphTimestamp7 = \
433 jsonObj7[ graphTimestamp ][ 'value' ]
434 deviceTimestamp6 = \
435 jsonObj6[ deviceTimestamp ][ 'value' ]
436 deviceTimestamp7 = \
437 jsonObj7[ deviceTimestamp ][ 'value' ]
438 deltaDevice6 = int( deviceTimestamp6 ) - int( t0Tcp )
439 deltaDevice7 = int( deviceTimestamp7 ) - int( t0Tcp )
440 deltaGraph6 = int( graphTimestamp6 ) - int( t0Tcp )
441 deltaGraph7 = int( graphTimestamp7 ) - int( t0Tcp )
442 deltaOfpGraph6 = int( graphTimestamp6 ) - int( t0Ofp )
443 deltaOfpGraph7 = int( graphTimestamp7 ) - int( t0Ofp )
444 deltaOfpDevice6 = float( deviceTimestamp6 ) -\
445 float( t0Ofp )
446 deltaOfpDevice7 = float( deviceTimestamp7 ) -\
447 float( t0Ofp )
andrewonlaba57a3042015-01-23 13:53:05 -0500448 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500449 deltaDevice6 = 0
450 deltaDevice7 = 0
451 deltaGraph6 = 0
452 deltaGraph7 = 0
453 deltaOfpGraph6 = 0
454 deltaOfpGraph7 = 0
455 deltaOfpDevice6 = 0
456 deltaOfpDevice7 = 0
andrewonlaba57a3042015-01-23 13:53:05 -0500457
andrewonlab79244cc2015-01-26 01:11:49 -0500458 # Get average of delta from all instances
459 avgDeltaDevice = \
460 ( int( deltaDevice1 ) +
461 int( deltaDevice2 ) +
462 int( deltaDevice3 ) +
463 int( deltaDevice4 ) +
464 int( deltaDevice5 ) +
465 int( deltaDevice6 ) +
466 int( deltaDevice7 ) ) / clusterCount
andrewonlabba44bcf2014-10-16 16:54:41 -0400467
andrewonlab79244cc2015-01-26 01:11:49 -0500468 # Ensure avg delta meets the threshold before appending
469 if avgDeltaDevice > 0.0 and avgDeltaDevice < 10000\
470 and int( i ) > iterIgnore:
471 latencyT0ToDeviceList.append( avgDeltaDevice )
andrewonlabee4efeb2014-10-24 16:44:51 -0400472 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500473 main.log.info(
474 "Results for t0-to-device ignored" +
475 "due to excess in threshold / warmup iteration." )
andrewonlabee4efeb2014-10-24 16:44:51 -0400476
andrewonlab79244cc2015-01-26 01:11:49 -0500477 # Get average of delta from all instances
478 # TODO: use max delta graph
479 #maxDeltaGraph = max( three )
480 avgDeltaGraph = \
481 ( int( deltaGraph1 ) +
482 int( deltaGraph2 ) +
483 int( deltaGraph3 ) +
484 int( deltaGraph4 ) +
485 int( deltaGraph5 ) +
486 int( deltaGraph6 ) +
487 int( deltaGraph7 ) ) / clusterCount
andrewonlab226024e2014-10-24 16:01:32 -0400488
andrewonlab79244cc2015-01-26 01:11:49 -0500489 # Ensure avg delta meets the threshold before appending
490 if avgDeltaGraph > 0.0 and avgDeltaGraph < 10000\
491 and int( i ) > iterIgnore:
492 latencyEndToEndList.append( avgDeltaGraph )
andrewonlabee4efeb2014-10-24 16:44:51 -0400493 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500494 main.log.info( "Results for end-to-end ignored" +
495 "due to excess in threshold" )
andrewonlab226024e2014-10-24 16:01:32 -0400496
andrewonlab79244cc2015-01-26 01:11:49 -0500497 avgDeltaOfpGraph = \
498 ( int( deltaOfpGraph1 ) +
499 int( deltaOfpGraph2 ) +
500 int( deltaOfpGraph3 ) +
501 int( deltaOfpGraph4 ) +
502 int( deltaOfpGraph5 ) +
503 int( deltaOfpGraph6 ) +
504 int( deltaOfpGraph7 ) ) / clusterCount
505
506 if avgDeltaOfpGraph > thresholdMin \
507 and avgDeltaOfpGraph < thresholdMax\
508 and int( i ) > iterIgnore:
509 latencyOfpToGraphList.append( avgDeltaOfpGraph )
510 elif avgDeltaOfpGraph > ( -10 ) and \
511 avgDeltaOfpGraph < 0.0 and\
512 int( i ) > iterIgnore:
513 main.log.info( "Sub-millisecond result likely; " +
514 "negative result was rounded to 0" )
515 # NOTE: Current metrics framework does not
516 # support sub-millisecond accuracy. Therefore,
517 # if the result is negative, we can reasonably
518 # conclude sub-millisecond results and just
519 # append the best rounded effort - 0 ms.
520 latencyOfpToGraphList.append( 0 )
andrewonlabee4efeb2014-10-24 16:44:51 -0400521 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500522 main.log.info( "Results for ofp-to-graph " +
523 "ignored due to excess in threshold" )
andrewonlabee4efeb2014-10-24 16:44:51 -0400524
andrewonlab79244cc2015-01-26 01:11:49 -0500525 avgDeltaOfpDevice = \
526 ( float( deltaOfpDevice1 ) +
527 float( deltaOfpDevice2 ) +
528 float( deltaOfpDevice3 ) +
529 float( deltaOfpDevice4 ) +
530 float( deltaOfpDevice5 ) +
531 float( deltaOfpDevice6 ) +
532 float( deltaOfpDevice7 ) ) / clusterCount
533
534 # NOTE: ofp - delta measurements are occasionally negative
kelvin-onlab8a832582015-01-16 17:06:11 -0800535 # due to system time misalignment.
andrewonlab79244cc2015-01-26 01:11:49 -0500536 latencyOfpToDeviceList.append( avgDeltaOfpDevice )
kelvin-onlab8a832582015-01-16 17:06:11 -0800537
andrewonlab79244cc2015-01-26 01:11:49 -0500538 deltaOfpTcp = int( t0Ofp ) - int( t0Tcp )
539 if deltaOfpTcp > thresholdMin \
540 and deltaOfpTcp < thresholdMax and\
541 int( i ) > iterIgnore:
542 latencyTcpToOfpList.append( deltaOfpTcp )
andrewonlab65d73892014-11-10 17:36:00 -0500543 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500544 main.log.info( "Results fo tcp-to-ofp " +
545 "ignored due to excess in threshold" )
andrewonlab65d73892014-11-10 17:36:00 -0500546
andrewonlab79244cc2015-01-26 01:11:49 -0500547 # TODO:
548 # Fetch logs upon threshold excess
andrewonlabba44bcf2014-10-16 16:54:41 -0400549
andrewonlab79244cc2015-01-26 01:11:49 -0500550 main.log.info( "ONOS1 delta end-to-end: " +
551 str( deltaGraph1 ) + " ms" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400552
andrewonlab79244cc2015-01-26 01:11:49 -0500553 main.log.info( "ONOS1 delta OFP - graph: " +
554 str( deltaOfpGraph1 ) + " ms" )
andrewonlab226024e2014-10-24 16:01:32 -0400555
andrewonlab79244cc2015-01-26 01:11:49 -0500556 main.log.info( "ONOS1 delta device - t0: " +
557 str( deltaDevice1 ) + " ms" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400558
andrewonlab79244cc2015-01-26 01:11:49 -0500559 main.log.info( "TCP to OFP delta: " +
560 str( deltaOfpTcp ) + " ms" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400561
andrewonlab79244cc2015-01-26 01:11:49 -0500562 main.step( "Remove switch from controller" )
563 main.Mininet1.deleteSwController( "s1" )
andrewonlabf47993a2014-10-24 17:56:01 -0400564
andrewonlab79244cc2015-01-26 01:11:49 -0500565 time.sleep( 5 )
566
567 # END of for loop iteration
568
569 # If there is at least 1 element in each list,
570 # pass the test case
571 if len( latencyEndToEndList ) > 0 and\
572 len( latencyOfpToGraphList ) > 0 and\
573 len( latencyOfpToDeviceList ) > 0 and\
574 len( latencyT0ToDeviceList ) > 0 and\
575 len( latencyTcpToOfpList ) > 0:
andrewonlabc15c9582014-10-24 16:35:52 -0400576 assertion = main.TRUE
andrewonlab79244cc2015-01-26 01:11:49 -0500577 elif len( latencyEndToEndList ) == 0:
578 # The appending of 0 here is to prevent
579 # the min,max,sum functions from failing
580 # below
581 latencyEndToEndList.append( 0 )
andrewonlabf47993a2014-10-24 17:56:01 -0400582 assertion = main.FALSE
andrewonlab79244cc2015-01-26 01:11:49 -0500583 elif len( latencyOfpToGraphList ) == 0:
584 latencyOfpToGraphList.append( 0 )
andrewonlabf47993a2014-10-24 17:56:01 -0400585 assertion = main.FALSE
andrewonlab79244cc2015-01-26 01:11:49 -0500586 elif len( latencyOfpToDeviceList ) == 0:
587 latencyOfpToDeviceList.append( 0 )
andrewonlabf47993a2014-10-24 17:56:01 -0400588 assertion = main.FALSE
andrewonlab79244cc2015-01-26 01:11:49 -0500589 elif len( latencyT0ToDeviceList ) == 0:
590 latencyT0ToDeviceList.append( 0 )
andrewonlabf47993a2014-10-24 17:56:01 -0400591 assertion = main.FALSE
andrewonlab79244cc2015-01-26 01:11:49 -0500592 elif len( latencyTcpToOfpList ) == 0:
593 latencyTcpToOfpList.append( 0 )
andrewonlab65d73892014-11-10 17:36:00 -0500594 assertion = main.FALSE
andrewonlabc15c9582014-10-24 16:35:52 -0400595
andrewonlab79244cc2015-01-26 01:11:49 -0500596 # Calculate min, max, avg of latency lists
597 latencyEndToEndMax = \
598 int( max( latencyEndToEndList ) )
599 latencyEndToEndMin = \
600 int( min( latencyEndToEndList ) )
601 latencyEndToEndAvg = \
602 ( int( sum( latencyEndToEndList ) ) /
603 len( latencyEndToEndList ) )
604 latencyEndToEndStdDev = \
605 str( round( numpy.std( latencyEndToEndList ), 1 ) )
andrewonlab69864162014-11-11 16:28:48 -0500606
andrewonlab79244cc2015-01-26 01:11:49 -0500607 latencyOfpToGraphMax = \
608 int( max( latencyOfpToGraphList ) )
609 latencyOfpToGraphMin = \
610 int( min( latencyOfpToGraphList ) )
611 latencyOfpToGraphAvg = \
612 ( int( sum( latencyOfpToGraphList ) ) /
613 len( latencyOfpToGraphList ) )
614 latencyOfpToGraphStdDev = \
615 str( round( numpy.std( latencyOfpToGraphList ), 1 ) )
andrewonlabc15c9582014-10-24 16:35:52 -0400616
andrewonlab79244cc2015-01-26 01:11:49 -0500617 latencyOfpToDeviceMax = \
618 int( max( latencyOfpToDeviceList ) )
619 latencyOfpToDeviceMin = \
620 int( min( latencyOfpToDeviceList ) )
621 latencyOfpToDeviceAvg = \
622 ( int( sum( latencyOfpToDeviceList ) ) /
623 len( latencyOfpToDeviceList ) )
624 latencyOfpToDeviceStdDev = \
625 str( round( numpy.std( latencyOfpToDeviceList ), 1 ) )
andrewonlabc15c9582014-10-24 16:35:52 -0400626
andrewonlab79244cc2015-01-26 01:11:49 -0500627 latencyT0ToDeviceMax = \
628 int( max( latencyT0ToDeviceList ) )
629 latencyT0ToDeviceMin = \
630 int( min( latencyT0ToDeviceList ) )
631 latencyT0ToDeviceAvg = \
632 ( int( sum( latencyT0ToDeviceList ) ) /
633 len( latencyT0ToDeviceList ) )
634 latencyOfpToDeviceStdDev = \
635 str( round( numpy.std( latencyT0ToDeviceList ), 1 ) )
andrewonlabc15c9582014-10-24 16:35:52 -0400636
andrewonlab79244cc2015-01-26 01:11:49 -0500637 latencyTcpToOfpMax = \
638 int( max( latencyTcpToOfpList ) )
639 latencyTcpToOfpMin = \
640 int( min( latencyTcpToOfpList ) )
641 latencyTcpToOfpAvg = \
642 ( int( sum( latencyTcpToOfpList ) ) /
643 len( latencyTcpToOfpList ) )
644 latencyTcpToOfpStdDev = \
645 str( round( numpy.std( latencyTcpToOfpList ), 1 ) )
andrewonlab65d73892014-11-10 17:36:00 -0500646
andrewonlab79244cc2015-01-26 01:11:49 -0500647 main.log.report( "Cluster size: " + str( clusterCount ) +
648 " node(s)" )
649 main.log.report( "Switch add - End-to-end latency: " +
650 "Avg: " + str( latencyEndToEndAvg ) + " ms " +
651 "Std Deviation: " + latencyEndToEndStdDev + " ms" )
652 main.log.report(
653 "Switch add - OFP-to-Graph latency: " +
654 "Note: results are not accurate to sub-millisecond. " +
655 "Any sub-millisecond results are rounded to 0 ms. " )
656 main.log.report( "Avg: " + str( latencyOfpToGraphAvg ) + " ms " +
657 "Std Deviation: " + latencyOfpToGraphStdDev + " ms" )
658 main.log.report( "Switch add - TCP-to-OFP latency: " +
659 "Avg: " + str( latencyTcpToOfpAvg ) + " ms " +
660 "Std Deviation: " + latencyTcpToOfpStdDev + " ms" )
andrewonlab226024e2014-10-24 16:01:32 -0400661
andrewonlab79244cc2015-01-26 01:11:49 -0500662 if debugMode == 'on':
663 main.ONOS1.cpLogsToDir( "/opt/onos/log/karaf.log",
664 "/tmp/", copyFileName="sw_lat_karaf" )
andrewonlabb1998c52014-11-10 13:31:43 -0500665
andrewonlab79244cc2015-01-26 01:11:49 -0500666 utilities.assert_equals( expect=main.TRUE, actual=assertion,
667 onpass="Switch latency test successful",
668 onfail="Switch latency test failed" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400669
andrewonlab79244cc2015-01-26 01:11:49 -0500670 def CASE3( self, main ):
671 """
andrewonlab8d29f122014-10-22 17:15:04 -0400672 Bring port up / down and measure latency.
673 Port enable / disable is simulated by ifconfig up / down
andrewonlab79244cc2015-01-26 01:11:49 -0500674
675 In ONOS-next, we must ensure that the port we are
andrewonlab393531a2014-10-27 18:36:26 -0400676 manipulating is connected to another switch with a valid
677 connection. Otherwise, graph view will not be updated.
andrewonlab79244cc2015-01-26 01:11:49 -0500678 """
andrewonlab8d29f122014-10-22 17:15:04 -0400679 import time
680 import subprocess
681 import os
682 import requests
683 import json
andrewonlab4f50ec92014-11-11 14:24:45 -0500684 import numpy
andrewonlab79244cc2015-01-26 01:11:49 -0500685 global clusterCount
andrewonlab2a6c9342014-10-16 13:40:15 -0400686
andrewonlab79244cc2015-01-26 01:11:49 -0500687 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
688 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
689 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
690 ONOSUser = main.params[ 'CTRL' ][ 'user' ]
andrewonlab8d29f122014-10-22 17:15:04 -0400691
andrewonlab79244cc2015-01-26 01:11:49 -0500692 defaultSwPort = main.params[ 'CTRL' ][ 'port1' ]
693
andrewonlab8790abb2014-11-06 13:51:54 -0500694 assertion = main.TRUE
andrewonlab79244cc2015-01-26 01:11:49 -0500695 # Number of iterations of case
696 numIter = main.params[ 'TEST' ][ 'numIter' ]
andrewonlab58f7d702014-11-07 13:21:19 -0500697
andrewonlab79244cc2015-01-26 01:11:49 -0500698 # Timestamp 'keys' for json metrics output.
699 # These are subject to change, hence moved into params
700 deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ]
701 graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ]
andrewonlab393531a2014-10-27 18:36:26 -0400702
andrewonlab79244cc2015-01-26 01:11:49 -0500703 debugMode = main.params[ 'TEST' ][ 'debugMode' ]
andrewonlabe5bcef92014-11-06 17:53:20 -0500704
andrewonlab79244cc2015-01-26 01:11:49 -0500705 localTime = time.strftime( '%x %X' )
706 localTime = localTime.replace( "/", "" )
707 localTime = localTime.replace( " ", "_" )
708 localTime = localTime.replace( ":", "" )
709 if debugMode == 'on':
710 main.ONOS1.tsharkPcap( "eth0",
711 "/tmp/port_lat_pcap_" + localTime )
andrewonlabe5bcef92014-11-06 17:53:20 -0500712
andrewonlab79244cc2015-01-26 01:11:49 -0500713 # Threshold for this test case
714 upThresholdStr = main.params[ 'TEST' ][ 'portUpThreshold' ]
715 downThresholdStr = main.params[ 'TEST' ][ 'portDownThreshold' ]
andrewonlabe5bcef92014-11-06 17:53:20 -0500716
andrewonlab79244cc2015-01-26 01:11:49 -0500717 upThresholdObj = upThresholdStr.split( "," )
718 downThresholdObj = downThresholdStr.split( "," )
719
720 upThresholdMin = int( upThresholdObj[ 0 ] )
721 upThresholdMax = int( upThresholdObj[ 1 ] )
722
723 downThresholdMin = int( downThresholdObj[ 0 ] )
724 downThresholdMax = int( downThresholdObj[ 1 ] )
725
726 # NOTE: Some hardcoded variables you may need to configure
andrewonlab393531a2014-10-27 18:36:26 -0400727 # besides the params
andrewonlab8d29f122014-10-22 17:15:04 -0400728
andrewonlab79244cc2015-01-26 01:11:49 -0500729 tsharkPortStatus = "OFP 130 Port Status"
andrewonlab8d29f122014-10-22 17:15:04 -0400730
andrewonlab79244cc2015-01-26 01:11:49 -0500731 tsharkPortUp = "/tmp/tshark_port_up.txt"
732 tsharkPortDown = "/tmp/tshark_port_down.txt"
733 interfaceConfig = "s1-eth1"
andrewonlab8d29f122014-10-22 17:15:04 -0400734
andrewonlab79244cc2015-01-26 01:11:49 -0500735 main.log.report( "Port enable / disable latency" )
736 main.log.report( "Simulated by ifconfig up / down" )
737 main.log.report( "Total iterations of test: " + str( numIter ) )
andrewonlab8d29f122014-10-22 17:15:04 -0400738
andrewonlab79244cc2015-01-26 01:11:49 -0500739 main.step( "Assign switches s1 and s2 to controller 1" )
740 main.Mininet1.assignSwController( sw="1", ip1=ONOS1Ip,
741 port1=defaultSwPort )
742 main.Mininet1.assignSwController( sw="2", ip1=ONOS1Ip,
743 port1=defaultSwPort )
andrewonlab8d29f122014-10-22 17:15:04 -0400744
andrewonlab79244cc2015-01-26 01:11:49 -0500745 # Give enough time for metrics to propagate the
746 # assign controller event. Otherwise, these events may
747 # carry over to our measurements
748 time.sleep( 15 )
andrewonlab393531a2014-10-27 18:36:26 -0400749
andrewonlab79244cc2015-01-26 01:11:49 -0500750 portUpDeviceToOfpList = []
751 portUpGraphToOfpList = []
752 portDownDeviceToOfpList = []
753 portDownGraphToOfpList = []
andrewonlab8d29f122014-10-22 17:15:04 -0400754
andrewonlab79244cc2015-01-26 01:11:49 -0500755 for i in range( 0, int( numIter ) ):
756 main.step( "Starting wireshark capture for port status down" )
757 main.ONOS1.tsharkGrep( tsharkPortStatus,
758 tsharkPortDown )
andrewonlab8d29f122014-10-22 17:15:04 -0400759
andrewonlab79244cc2015-01-26 01:11:49 -0500760 time.sleep( 5 )
761
762 # Disable interface that is connected to switch 2
763 main.step( "Disable port: " + interfaceConfig )
764 main.Mininet1.handle.sendline( "sh ifconfig " +
765 interfaceConfig + " down" )
766 main.Mininet1.handle.expect( "mininet>" )
767
768 time.sleep( 3 )
769 main.ONOS1.tsharkStop()
770
771 # Copy tshark output file from ONOS to TestON instance
kelvin-onlab8a832582015-01-16 17:06:11 -0800772 #/tmp directory
andrewonlab79244cc2015-01-26 01:11:49 -0500773 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
774 tsharkPortDown + " /tmp/" )
kelvin-onlab8a832582015-01-16 17:06:11 -0800775
andrewonlab79244cc2015-01-26 01:11:49 -0500776 fPortDown = open( tsharkPortDown, 'r' )
777 # Get first line of port down event from tshark
778 fLine = fPortDown.readline()
779 objDown = fLine.split( " " )
780 if len( fLine ) > 0:
781 # NOTE: objDown[ 1 ] is a very unreliable
782 # way to determine the timestamp. If
783 # results seem way off, check the object
andrewonlaba57a3042015-01-23 13:53:05 -0500784 # itself by printing it out
andrewonlab79244cc2015-01-26 01:11:49 -0500785 timestampBeginPtDown = int( float( objDown[ 1 ] ) * 1000 )
786 # For some reason, wireshark decides to record the
andrewonlaba57a3042015-01-23 13:53:05 -0500787 # timestamp at the 3rd object position instead of
andrewonlab79244cc2015-01-26 01:11:49 -0500788 # 2nd at unpredictable times. This statement is
andrewonlaba57a3042015-01-23 13:53:05 -0500789 # used to capture that odd behavior and use the
790 # correct epoch time
andrewonlab79244cc2015-01-26 01:11:49 -0500791 if timestampBeginPtDown < 1400000000000:
792 timestampBeginPtDown = \
793 int( float( objDown[ 2 ] ) * 1000 )
andrewonlaba57a3042015-01-23 13:53:05 -0500794
andrewonlab79244cc2015-01-26 01:11:49 -0500795 main.log.info( "Port down begin timestamp: " +
796 str( timestampBeginPtDown ) )
andrewonlab8d29f122014-10-22 17:15:04 -0400797 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500798 main.log.info( "Tshark output file returned unexpected" +
799 " results: " + str( objDown ) )
800 timestampBeginPtDown = 0
801 fPortDown.close()
802
803 main.step( "Obtain t1 by metrics call" )
804 jsonStrUp1 = main.ONOS1cli.topologyEventsMetrics()
805 jsonObj1 = json.loads( jsonStrUp1 )
806 # Obtain graph timestamp. This timestsamp captures
807 # the epoch time at which the topology graph was updated.
808 graphTimestamp1 = \
809 jsonObj1[ graphTimestamp ][ 'value' ]
810 # Obtain device timestamp. This timestamp captures
811 # the epoch time at which the device event happened
812 deviceTimestamp1 = \
813 jsonObj1[ deviceTimestamp ][ 'value' ]
814 # Get delta between graph event and OFP
815 ptDownGraphToOfp1 = int( graphTimestamp1 ) -\
816 int( timestampBeginPtDown )
817 # Get delta between device event and OFP
818 ptDownDeviceToOfp1 = int( deviceTimestamp1 ) -\
819 int( timestampBeginPtDown )
820
821 if clusterCount >= 3:
822 jsonStrUp2 = main.ONOS2cli.topologyEventsMetrics()
823 jsonStrUp3 = main.ONOS3cli.topologyEventsMetrics()
824 jsonObj2 = json.loads( jsonStrUp2 )
825 jsonObj3 = json.loads( jsonStrUp3 )
826 graphTimestamp2 = \
827 jsonObj2[ graphTimestamp ][ 'value' ]
828 graphTimestamp3 = \
829 jsonObj3[ graphTimestamp ][ 'value' ]
830 deviceTimestamp2 = \
831 jsonObj2[ deviceTimestamp ][ 'value' ]
832 deviceTimestamp3 = \
833 jsonObj3[ deviceTimestamp ][ 'value' ]
834 ptDownGraphToOfp2 = int( graphTimestamp2 ) -\
835 int( timestampBeginPtDown )
836 ptDownGraphToOfp3 = int( graphTimestamp3 ) -\
837 int( timestampBeginPtDown )
838 ptDownDeviceToOfp2 = int( deviceTimestamp2 ) -\
839 int( timestampBeginPtDown )
840 ptDownDeviceToOfp3 = int( deviceTimestamp3 ) -\
841 int( timestampBeginPtDown )
andrewonlaba57a3042015-01-23 13:53:05 -0500842 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500843 ptDownGraphToOfp2 = 0
844 ptDownGraphToOfp3 = 0
845 ptDownDeviceToOfp2 = 0
846 ptDownDeviceToOfp3 = 0
andrewonlab393531a2014-10-27 18:36:26 -0400847
andrewonlab79244cc2015-01-26 01:11:49 -0500848 if clusterCount >= 5:
849 jsonStrUp4 = main.ONOS4cli.topologyEventsMetrics()
850 jsonStrUp5 = main.ONOS5cli.topologyEventsMetrics()
851 jsonObj4 = json.loads( jsonStrUp4 )
852 jsonObj5 = json.loads( jsonStrUp5 )
853 graphTimestamp4 = \
854 jsonObj4[ graphTimestamp ][ 'value' ]
855 graphTimestamp5 = \
856 jsonObj5[ graphTimestamp ][ 'value' ]
857 deviceTimestamp4 = \
858 jsonObj4[ deviceTimestamp ][ 'value' ]
859 deviceTimestamp5 = \
860 jsonObj5[ deviceTimestamp ][ 'value' ]
861 ptDownGraphToOfp4 = int( graphTimestamp4 ) -\
862 int( timestampBeginPtDown )
863 ptDownGraphToOfp5 = int( graphTimestamp5 ) -\
864 int( timestampBeginPtDown )
865 ptDownDeviceToOfp4 = int( deviceTimestamp4 ) -\
866 int( timestampBeginPtDown )
867 ptDownDeviceToOfp5 = int( deviceTimestamp5 ) -\
868 int( timestampBeginPtDown )
andrewonlaba57a3042015-01-23 13:53:05 -0500869 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500870 ptDownGraphToOfp4 = 0
871 ptDownGraphToOfp5 = 0
872 ptDownDeviceToOfp4 = 0
873 ptDownDeviceToOfp5 = 0
andrewonlab393531a2014-10-27 18:36:26 -0400874
andrewonlab79244cc2015-01-26 01:11:49 -0500875 if clusterCount >= 7:
876 jsonStrUp6 = main.ONOS6cli.topologyEventsMetrics()
877 jsonStrUp7 = main.ONOS7cli.topologyEventsMetrics()
878 jsonObj6 = json.loads( jsonStrUp6 )
879 jsonObj7 = json.loads( jsonStrUp7 )
880 graphTimestamp6 = \
881 jsonObj6[ graphTimestamp ][ 'value' ]
882 graphTimestamp7 = \
883 jsonObj7[ graphTimestamp ][ 'value' ]
884 deviceTimestamp6 = \
885 jsonObj6[ deviceTimestamp ][ 'value' ]
886 deviceTimestamp7 = \
887 jsonObj7[ deviceTimestamp ][ 'value' ]
888 ptDownGraphToOfp6 = int( graphTimestamp6 ) -\
889 int( timestampBeginPtDown )
890 ptDownGraphToOfp7 = int( graphTimestamp7 ) -\
891 int( timestampBeginPtDown )
892 ptDownDeviceToOfp6 = int( deviceTimestamp6 ) -\
893 int( timestampBeginPtDown )
894 ptDownDeviceToOfp7 = int( deviceTimestamp7 ) -\
895 int( timestampBeginPtDown )
andrewonlaba57a3042015-01-23 13:53:05 -0500896 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500897 ptDownGraphToOfp6 = 0
898 ptDownGraphToOfp7 = 0
899 ptDownDeviceToOfp6 = 0
900 ptDownDeviceToOfp7 = 0
kelvin-onlab8a832582015-01-16 17:06:11 -0800901
andrewonlab79244cc2015-01-26 01:11:49 -0500902 time.sleep( 3 )
andrewonlaba57a3042015-01-23 13:53:05 -0500903
andrewonlab79244cc2015-01-26 01:11:49 -0500904 # Caluclate average across clusters
905 ptDownGraphToOfpAvg =\
906 ( int( ptDownGraphToOfp1 ) +
907 int( ptDownGraphToOfp2 ) +
908 int( ptDownGraphToOfp3 ) +
909 int( ptDownGraphToOfp4 ) +
910 int( ptDownGraphToOfp5 ) +
911 int( ptDownGraphToOfp6 ) +
912 int( ptDownGraphToOfp7 ) ) / clusterCount
913 ptDownDeviceToOfpAvg = \
914 ( int( ptDownDeviceToOfp1 ) +
915 int( ptDownDeviceToOfp2 ) +
916 int( ptDownDeviceToOfp3 ) +
917 int( ptDownDeviceToOfp4 ) +
918 int( ptDownDeviceToOfp5 ) +
919 int( ptDownDeviceToOfp6 ) +
920 int( ptDownDeviceToOfp7 ) ) / clusterCount
andrewonlab393531a2014-10-27 18:36:26 -0400921
andrewonlab79244cc2015-01-26 01:11:49 -0500922 if ptDownGraphToOfpAvg > downThresholdMin and \
923 ptDownGraphToOfpAvg < downThresholdMax:
924 portDownGraphToOfpList.append(
925 ptDownGraphToOfpAvg )
926 main.log.info( "Port down: graph to ofp avg: " +
927 str( ptDownGraphToOfpAvg ) + " ms" )
andrewonlab393531a2014-10-27 18:36:26 -0400928 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500929 main.log.info( "Average port down graph-to-ofp result" +
930 " exceeded the threshold: " +
931 str( ptDownGraphToOfpAvg ) )
andrewonlab393531a2014-10-27 18:36:26 -0400932
andrewonlab79244cc2015-01-26 01:11:49 -0500933 if ptDownDeviceToOfpAvg > 0 and \
934 ptDownDeviceToOfpAvg < 1000:
935 portDownDeviceToOfpList.append(
936 ptDownDeviceToOfpAvg )
937 main.log.info( "Port down: device to ofp avg: " +
938 str( ptDownDeviceToOfpAvg ) + " ms" )
andrewonlab3622beb2014-10-28 16:07:56 -0400939 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500940 main.log.info( "Average port down device-to-ofp result" +
941 " exceeded the threshold: " +
942 str( ptDownDeviceToOfpAvg ) )
andrewonlab3622beb2014-10-28 16:07:56 -0400943
andrewonlab79244cc2015-01-26 01:11:49 -0500944 # Port up events
945 main.step( "Enable port and obtain timestamp" )
946 main.step( "Starting wireshark capture for port status up" )
947 main.ONOS1.tsharkGrep( tsharkPortStatus, tsharkPortUp )
948 time.sleep( 5 )
andrewonlab8d29f122014-10-22 17:15:04 -0400949
andrewonlab79244cc2015-01-26 01:11:49 -0500950 main.Mininet1.handle.sendline( "sh ifconfig " +
951 interfaceConfig + " up" )
952 main.Mininet1.handle.expect( "mininet>" )
953
954 # Allow time for tshark to capture event
955 time.sleep( 5 )
956 main.ONOS1.tsharkStop()
957
958 time.sleep( 3 )
959 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
960 tsharkPortUp + " /tmp/" )
961 fPortUp = open( tsharkPortUp, 'r' )
962 fLine = fPortUp.readline()
963 objUp = fLine.split( " " )
964 if len( fLine ) > 0:
965 timestampBeginPtUp = int( float( objUp[ 1 ] ) * 1000 )
966 if timestampBeginPtUp < 1400000000000:
967 timestampBeginPtUp = \
968 int( float( objUp[ 2 ] ) * 1000 )
969 main.log.info( "Port up begin timestamp: " +
970 str( timestampBeginPtUp ) )
andrewonlab8d29f122014-10-22 17:15:04 -0400971 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500972 main.log.info( "Tshark output file returned unexpected" +
973 " results." )
974 timestampBeginPtUp = 0
975 fPortUp.close()
andrewonlab393531a2014-10-27 18:36:26 -0400976
andrewonlab79244cc2015-01-26 01:11:49 -0500977 # Obtain metrics shortly afterwards
978 # This timestsamp captures
979 # the epoch time at which the topology graph was updated.
980 main.step( "Obtain t1 by REST call" )
981 jsonStrUp1 = main.ONOS1cli.topologyEventsMetrics()
982 jsonObj1 = json.loads( jsonStrUp1 )
983 graphTimestamp1 = \
984 jsonObj1[ graphTimestamp ][ 'value' ]
985 # Obtain device timestamp. This timestamp captures
986 # the epoch time at which the device event happened
987 deviceTimestamp1 = \
988 jsonObj1[ deviceTimestamp ][ 'value' ]
989 # Get delta between graph event and OFP
990 ptUpGraphToOfp1 = int( graphTimestamp1 ) -\
991 int( timestampBeginPtUp )
992 # Get delta between device event and OFP
993 ptUpDeviceToOfp1 = int( deviceTimestamp1 ) -\
994 int( timestampBeginPtUp )
andrewonlab393531a2014-10-27 18:36:26 -0400995
andrewonlab79244cc2015-01-26 01:11:49 -0500996 if clusterCount >= 3:
997 jsonStrUp2 = main.ONOS2cli.topologyEventsMetrics()
998 jsonStrUp3 = main.ONOS3cli.topologyEventsMetrics()
999 jsonObj2 = json.loads( jsonStrUp2 )
1000 jsonObj3 = json.loads( jsonStrUp3 )
1001 graphTimestamp2 = \
1002 jsonObj2[ graphTimestamp ][ 'value' ]
1003 graphTimestamp3 = \
1004 jsonObj3[ graphTimestamp ][ 'value' ]
1005 deviceTimestamp2 = \
1006 jsonObj2[ deviceTimestamp ][ 'value' ]
1007 deviceTimestamp3 = \
1008 jsonObj3[ deviceTimestamp ][ 'value' ]
1009 ptUpGraphToOfp2 = int( graphTimestamp2 ) -\
1010 int( timestampBeginPtUp )
1011 ptUpGraphToOfp3 = int( graphTimestamp3 ) -\
1012 int( timestampBeginPtUp )
1013 ptUpDeviceToOfp2 = int( deviceTimestamp2 ) -\
1014 int( timestampBeginPtUp )
1015 ptUpDeviceToOfp3 = int( deviceTimestamp3 ) -\
1016 int( timestampBeginPtUp )
andrewonlaba57a3042015-01-23 13:53:05 -05001017 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001018 ptUpGraphToOfp2 = 0
1019 ptUpGraphToOfp3 = 0
1020 ptUpDeviceToOfp2 = 0
1021 ptUpDeviceToOfp3 = 0
andrewonlabb1998c52014-11-10 13:31:43 -05001022
andrewonlab79244cc2015-01-26 01:11:49 -05001023 if clusterCount >= 5:
1024 jsonStrUp4 = main.ONOS4cli.topologyEventsMetrics()
1025 jsonStrUp5 = main.ONOS5cli.topologyEventsMetrics()
1026 jsonObj4 = json.loads( jsonStrUp4 )
1027 jsonObj5 = json.loads( jsonStrUp5 )
1028 graphTimestamp4 = \
1029 jsonObj4[ graphTimestamp ][ 'value' ]
1030 graphTimestamp5 = \
1031 jsonObj5[ graphTimestamp ][ 'value' ]
1032 deviceTimestamp4 = \
1033 jsonObj4[ deviceTimestamp ][ 'value' ]
1034 deviceTimestamp5 = \
1035 jsonObj5[ deviceTimestamp ][ 'value' ]
1036 ptUpGraphToOfp4 = int( graphTimestamp4 ) -\
1037 int( timestampBeginPtUp )
1038 ptUpGraphToOfp5 = int( graphTimestamp5 ) -\
1039 int( timestampBeginPtUp )
1040 ptUpDeviceToOfp4 = int( deviceTimestamp4 ) -\
1041 int( timestampBeginPtUp )
1042 ptUpDeviceToOfp5 = int( deviceTimestamp5 ) -\
1043 int( timestampBeginPtUp )
andrewonlab3622beb2014-10-28 16:07:56 -04001044 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001045 ptUpGraphToOfp4 = 0
1046 ptUpGraphToOfp5 = 0
1047 ptUpDeviceToOfp4 = 0
1048 ptUpDeviceToOfp5 = 0
1049
1050 if clusterCount >= 7:
1051 jsonStrUp6 = main.ONOS6cli.topologyEventsMetrics()
1052 jsonStrUp7 = main.ONOS7cli.topologyEventsMetrics()
1053 jsonObj6 = json.loads( jsonStrUp6 )
1054 jsonObj7 = json.loads( jsonStrUp7 )
1055 graphTimestamp6 = \
1056 jsonObj6[ graphTimestamp ][ 'value' ]
1057 graphTimestamp7 = \
1058 jsonObj7[ graphTimestamp ][ 'value' ]
1059 deviceTimestamp6 = \
1060 jsonObj6[ deviceTimestamp ][ 'value' ]
1061 deviceTimestamp7 = \
1062 jsonObj7[ deviceTimestamp ][ 'value' ]
1063 ptUpGraphToOfp6 = int( graphTimestamp6 ) -\
1064 int( timestampBeginPtUp )
1065 ptUpGraphToOfp7 = int( graphTimestamp7 ) -\
1066 int( timestampBeginPtUp )
1067 ptUpDeviceToOfp6 = int( deviceTimestamp6 ) -\
1068 int( timestampBeginPtUp )
1069 ptUpDeviceToOfp7 = int( deviceTimestamp7 ) -\
1070 int( timestampBeginPtUp )
andrewonlab3622beb2014-10-28 16:07:56 -04001071 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001072 ptUpGraphToOfp6 = 0
1073 ptUpGraphToOfp7 = 0
1074 ptUpDeviceToOfp6 = 0
1075 ptUpDeviceToOfp7 = 0
1076
1077 ptUpGraphToOfpAvg = \
1078 ( int( ptUpGraphToOfp1 ) +
1079 int( ptUpGraphToOfp2 ) +
1080 int( ptUpGraphToOfp3 ) +
1081 int( ptUpGraphToOfp4 ) +
1082 int( ptUpGraphToOfp5 ) +
1083 int( ptUpGraphToOfp6 ) +
1084 int( ptUpGraphToOfp7 ) ) / clusterCount
1085
1086 ptUpDeviceToOfpAvg = \
1087 ( int( ptUpDeviceToOfp1 ) +
1088 int( ptUpDeviceToOfp2 ) +
1089 int( ptUpDeviceToOfp3 ) +
1090 int( ptUpDeviceToOfp4 ) +
1091 int( ptUpDeviceToOfp5 ) +
1092 int( ptUpDeviceToOfp6 ) +
1093 int( ptUpDeviceToOfp7 ) ) / clusterCount
1094
1095 if ptUpGraphToOfpAvg > upThresholdMin and \
1096 ptUpGraphToOfpAvg < upThresholdMax:
1097 portUpGraphToOfpList.append(
1098 ptUpGraphToOfpAvg )
1099 main.log.info( "Port down: graph to ofp avg: " +
1100 str( ptUpGraphToOfpAvg ) + " ms" )
1101 else:
1102 main.log.info( "Average port up graph-to-ofp result" +
1103 " exceeded the threshold: " +
1104 str( ptUpGraphToOfpAvg ) )
1105
1106 if ptUpDeviceToOfpAvg > upThresholdMin and \
1107 ptUpDeviceToOfpAvg < upThresholdMax:
1108 portUpDeviceToOfpList.append(
1109 ptUpDeviceToOfpAvg )
1110 main.log.info( "Port up: device to ofp avg: " +
1111 str( ptUpDeviceToOfpAvg ) + " ms" )
1112 else:
1113 main.log.info( "Average port up device-to-ofp result" +
1114 " exceeded the threshold: " +
1115 str( ptUpDeviceToOfpAvg ) )
1116
1117 # END ITERATION FOR LOOP
1118
1119 # Check all list for latency existence and set assertion
1120 if ( portDownGraphToOfpList and portDownDeviceToOfpList
1121 and portUpGraphToOfpList and portUpDeviceToOfpList ):
andrewonlab8790abb2014-11-06 13:51:54 -05001122 assertion = main.TRUE
andrewonlab8790abb2014-11-06 13:51:54 -05001123
andrewonlab79244cc2015-01-26 01:11:49 -05001124 main.log.report( "Cluster size: " + str( clusterCount ) +
1125 " node(s)" )
1126 # Calculate and report latency measurements
1127 portDownGraphToOfpMin = min( portDownGraphToOfpList )
1128 portDownGraphToOfpMax = max( portDownGraphToOfpList )
1129 portDownGraphToOfpAvg = \
1130 ( sum( portDownGraphToOfpList ) /
1131 len( portDownGraphToOfpList ) )
1132 portDownGraphToOfpStdDev = \
1133 str( round( numpy.std( portDownGraphToOfpList ), 1 ) )
andrewonlababb11c32014-11-04 15:03:24 -05001134
andrewonlab79244cc2015-01-26 01:11:49 -05001135 main.log.report( "Port down graph-to-ofp " +
1136 "Avg: " + str( portDownGraphToOfpAvg ) + " ms " +
1137 "Std Deviation: " + portDownGraphToOfpStdDev + " ms" )
1138
1139 portDownDeviceToOfpMin = min( portDownDeviceToOfpList )
1140 portDownDeviceToOfpMax = max( portDownDeviceToOfpList )
1141 portDownDeviceToOfpAvg = \
1142 ( sum( portDownDeviceToOfpList ) /
1143 len( portDownDeviceToOfpList ) )
1144 portDownDeviceToOfpStdDev = \
1145 str( round( numpy.std( portDownDeviceToOfpList ), 1 ) )
1146
1147 main.log.report(
1148 "Port down device-to-ofp " +
1149 "Avg: " +
1150 str( portDownDeviceToOfpAvg ) +
1151 " ms " +
1152 "Std Deviation: " +
1153 portDownDeviceToOfpStdDev +
1154 " ms" )
1155
1156 portUpGraphToOfpMin = min( portUpGraphToOfpList )
1157 portUpGraphToOfpMax = max( portUpGraphToOfpList )
1158 portUpGraphToOfpAvg = \
1159 ( sum( portUpGraphToOfpList ) /
1160 len( portUpGraphToOfpList ) )
1161 portUpGraphToOfpStdDev = \
1162 str( round( numpy.std( portUpGraphToOfpList ), 1 ) )
1163
1164 main.log.report( "Port up graph-to-ofp " +
1165 "Avg: " + str( portUpGraphToOfpAvg ) + " ms " +
1166 "Std Deviation: " + portUpGraphToOfpStdDev + " ms" )
1167
1168 portUpDeviceToOfpMin = min( portUpDeviceToOfpList )
1169 portUpDeviceToOfpMax = max( portUpDeviceToOfpList )
1170 portUpDeviceToOfpAvg = \
1171 ( sum( portUpDeviceToOfpList ) /
1172 len( portUpDeviceToOfpList ) )
1173 portUpDeviceToOfpStdDev = \
1174 str( round( numpy.std( portUpDeviceToOfpList ), 1 ) )
1175
1176 main.log.report( "Port up device-to-ofp " +
1177 "Avg: " + str( portUpDeviceToOfpAvg ) + " ms " +
1178 "Std Deviation: " + portUpDeviceToOfpStdDev + " ms" )
1179
1180 # Remove switches from controller for next test
1181 main.Mininet1.deleteSwController( "s1" )
1182 main.Mininet1.deleteSwController( "s2" )
1183
1184 utilities.assert_equals(
1185 expect=main.TRUE,
1186 actual=assertion,
1187 onpass="Port discovery latency calculation successful",
1188 onfail="Port discovery test failed" )
1189
1190 def CASE4( self, main ):
1191 """
andrewonlab3622beb2014-10-28 16:07:56 -04001192 Link down event using loss rate 100%
andrewonlab79244cc2015-01-26 01:11:49 -05001193
andrewonlab53b641c2014-10-31 19:44:44 -04001194 Important:
1195 Use a simple 2 switch topology with 1 link between
andrewonlab79244cc2015-01-26 01:11:49 -05001196 the two switches. Ensure that mac addresses of the
andrewonlab53b641c2014-10-31 19:44:44 -04001197 switches are 1 / 2 respectively
andrewonlab79244cc2015-01-26 01:11:49 -05001198 """
andrewonlab3622beb2014-10-28 16:07:56 -04001199 import time
1200 import subprocess
1201 import os
1202 import requests
1203 import json
andrewonlab79244cc2015-01-26 01:11:49 -05001204 import numpy
andrewonlab3622beb2014-10-28 16:07:56 -04001205
andrewonlab79244cc2015-01-26 01:11:49 -05001206 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
1207 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
1208 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
1209 ONOSUser = main.params[ 'CTRL' ][ 'user' ]
andrewonlab58f7d702014-11-07 13:21:19 -05001210
andrewonlab79244cc2015-01-26 01:11:49 -05001211 defaultSwPort = main.params[ 'CTRL' ][ 'port1' ]
andrewonlab53b641c2014-10-31 19:44:44 -04001212
andrewonlab79244cc2015-01-26 01:11:49 -05001213 # Number of iterations of case
1214 numIter = main.params[ 'TEST' ][ 'numIter' ]
andrewonlabe5bcef92014-11-06 17:53:20 -05001215
andrewonlab79244cc2015-01-26 01:11:49 -05001216 # Timestamp 'keys' for json metrics output.
1217 # These are subject to change, hence moved into params
1218 deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ]
1219 linkTimestamp = main.params[ 'JSON' ][ 'linkTimestamp' ]
1220 graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ]
andrewonlabe5bcef92014-11-06 17:53:20 -05001221
andrewonlab79244cc2015-01-26 01:11:49 -05001222 debugMode = main.params[ 'TEST' ][ 'debugMode' ]
andrewonlabe5bcef92014-11-06 17:53:20 -05001223
andrewonlab79244cc2015-01-26 01:11:49 -05001224 localTime = time.strftime( '%x %X' )
1225 localTime = localTime.replace( "/", "" )
1226 localTime = localTime.replace( " ", "_" )
1227 localTime = localTime.replace( ":", "" )
1228 if debugMode == 'on':
1229 main.ONOS1.tsharkPcap( "eth0",
1230 "/tmp/link_lat_pcap_" + localTime )
1231
1232 # Threshold for this test case
1233 upThresholdStr = main.params[ 'TEST' ][ 'linkUpThreshold' ]
1234 downThresholdStr = main.params[ 'TEST' ][ 'linkDownThreshold' ]
1235
1236 upThresholdObj = upThresholdStr.split( "," )
1237 downThresholdObj = downThresholdStr.split( "," )
1238
1239 upThresholdMin = int( upThresholdObj[ 0 ] )
1240 upThresholdMax = int( upThresholdObj[ 1 ] )
1241
1242 downThresholdMin = int( downThresholdObj[ 0 ] )
1243 downThresholdMax = int( downThresholdObj[ 1 ] )
andrewonlabe5bcef92014-11-06 17:53:20 -05001244
andrewonlab3622beb2014-10-28 16:07:56 -04001245 assertion = main.TRUE
andrewonlab79244cc2015-01-26 01:11:49 -05001246 # Link event timestamp to system time list
1247 linkDownLinkToSystemList = []
1248 linkUpLinkToSystemList = []
1249 # Graph event timestamp to system time list
1250 linkDownGraphToSystemList = []
1251 linkUpGraphToSystemList = []
andrewonlab3622beb2014-10-28 16:07:56 -04001252
andrewonlab79244cc2015-01-26 01:11:49 -05001253 main.log.report( "Link up / down discovery latency between " +
1254 "two switches" )
1255 main.log.report( "Simulated by setting loss-rate 100%" )
1256 main.log.report( "'tc qdisc add dev <intfs> root netem loss 100%'" )
1257 main.log.report( "Total iterations of test: " + str( numIter ) )
andrewonlab3622beb2014-10-28 16:07:56 -04001258
andrewonlab79244cc2015-01-26 01:11:49 -05001259 main.step( "Assign all switches" )
1260 main.Mininet1.assignSwController( sw="1",
1261 ip1=ONOS1Ip, port1=defaultSwPort )
1262 main.Mininet1.assignSwController( sw="2",
1263 ip1=ONOS1Ip, port1=defaultSwPort )
andrewonlab3622beb2014-10-28 16:07:56 -04001264
andrewonlab79244cc2015-01-26 01:11:49 -05001265 main.step( "Verifying switch assignment" )
1266 resultS1 = main.Mininet1.getSwController( sw="s1" )
1267 resultS2 = main.Mininet1.getSwController( sw="s2" )
andrewonlab3622beb2014-10-28 16:07:56 -04001268
andrewonlab79244cc2015-01-26 01:11:49 -05001269 # Allow time for events to finish before taking measurements
1270 time.sleep( 10 )
1271
1272 linkDown1 = False
1273 linkDown2 = False
1274 linkDown3 = False
1275 # Start iteration of link event test
1276 for i in range( 0, int( numIter ) ):
1277 main.step( "Getting initial system time as t0" )
1278
1279 # System time in epoch ms
1280 timestampLinkDownT0 = time.time() * 1000
1281 # Link down is simulated by 100% loss rate using traffic
1282 # control command
kelvin-onlab8a832582015-01-16 17:06:11 -08001283 main.Mininet1.handle.sendline(
andrewonlab79244cc2015-01-26 01:11:49 -05001284 "sh tc qdisc add dev s1-eth1 root netem loss 100%" )
kelvin-onlab8a832582015-01-16 17:06:11 -08001285
andrewonlab79244cc2015-01-26 01:11:49 -05001286 # TODO: Iterate through 'links' command to verify that
1287 # link s1 -> s2 went down ( loop timeout 30 seconds )
andrewonlababb11c32014-11-04 15:03:24 -05001288 # on all 3 ONOS instances
andrewonlab79244cc2015-01-26 01:11:49 -05001289 main.log.info( "Checking ONOS for link update" )
1290 loopCount = 0
1291 while( not ( linkDown1 and linkDown2 and linkDown3 )
1292 and loopCount < 30 ):
1293 jsonStr1 = main.ONOS1cli.links()
1294 jsonStr2 = main.ONOS2cli.links()
1295 jsonStr3 = main.ONOS3cli.links()
1296
1297 if not ( jsonStr1 and jsonStr2 and jsonStr3 ):
1298 main.log.error( "CLI command returned error " )
andrewonlab53b641c2014-10-31 19:44:44 -04001299 break
1300 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001301 jsonObj1 = json.loads( jsonStr1 )
1302 jsonObj2 = json.loads( jsonStr2 )
1303 jsonObj3 = json.loads( jsonStr3 )
1304 for obj1 in jsonObj1:
1305 if '01' not in obj1[ 'src' ][ 'device' ]:
1306 linkDown1 = True
1307 main.log.info( "Link down from " +
1308 "s1 -> s2 on ONOS1 detected" )
1309 for obj2 in jsonObj2:
1310 if '01' not in obj2[ 'src' ][ 'device' ]:
1311 linkDown2 = True
1312 main.log.info( "Link down from " +
1313 "s1 -> s2 on ONOS2 detected" )
1314 for obj3 in jsonObj3:
1315 if '01' not in obj3[ 'src' ][ 'device' ]:
1316 linkDown3 = True
1317 main.log.info( "Link down from " +
1318 "s1 -> s2 on ONOS3 detected" )
1319
1320 loopCount += 1
1321 # If CLI doesn't like the continuous requests
1322 # and exits in this loop, increase the sleep here.
1323 # Consequently, while loop timeout will increase
1324 time.sleep( 1 )
1325
1326 # Give time for metrics measurement to catch up
1327 # NOTE: May need to be configured more accurately
1328 time.sleep( 10 )
1329 # If we exited the while loop and link down 1,2,3 are still
1330 # false, then ONOS has failed to discover link down event
1331 if not ( linkDown1 and linkDown2 and linkDown3 ):
1332 main.log.info( "Link down discovery failed" )
1333
1334 linkDownLatGraph1 = 0
1335 linkDownLatGraph2 = 0
1336 linkDownLatGraph3 = 0
1337 linkDownLatDevice1 = 0
1338 linkDownLatDevice2 = 0
1339 linkDownLatDevice3 = 0
1340
andrewonlab53b641c2014-10-31 19:44:44 -04001341 assertion = main.FALSE
1342 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001343 jsonTopoMetrics1 =\
1344 main.ONOS1cli.topologyEventsMetrics()
1345 jsonTopoMetrics2 =\
1346 main.ONOS2cli.topologyEventsMetrics()
1347 jsonTopoMetrics3 =\
1348 main.ONOS3cli.topologyEventsMetrics()
1349 jsonTopoMetrics1 = json.loads( jsonTopoMetrics1 )
1350 jsonTopoMetrics2 = json.loads( jsonTopoMetrics2 )
1351 jsonTopoMetrics3 = json.loads( jsonTopoMetrics3 )
andrewonlab53b641c2014-10-31 19:44:44 -04001352
andrewonlab79244cc2015-01-26 01:11:49 -05001353 main.log.info( "Obtaining graph and device timestamp" )
1354 graphTimestamp1 = \
1355 jsonTopoMetrics1[ graphTimestamp ][ 'value' ]
1356 graphTimestamp2 = \
1357 jsonTopoMetrics2[ graphTimestamp ][ 'value' ]
1358 graphTimestamp3 = \
1359 jsonTopoMetrics3[ graphTimestamp ][ 'value' ]
andrewonlab53b641c2014-10-31 19:44:44 -04001360
andrewonlab79244cc2015-01-26 01:11:49 -05001361 linkTimestamp1 = \
1362 jsonTopoMetrics1[ linkTimestamp ][ 'value' ]
1363 linkTimestamp2 = \
1364 jsonTopoMetrics2[ linkTimestamp ][ 'value' ]
1365 linkTimestamp3 = \
1366 jsonTopoMetrics3[ linkTimestamp ][ 'value' ]
andrewonlab53b641c2014-10-31 19:44:44 -04001367
andrewonlab79244cc2015-01-26 01:11:49 -05001368 if graphTimestamp1 and graphTimestamp2 and\
1369 graphTimestamp3 and linkTimestamp1 and\
1370 linkTimestamp2 and linkTimestamp3:
1371 linkDownLatGraph1 = int( graphTimestamp1 ) -\
1372 int( timestampLinkDownT0 )
1373 linkDownLatGraph2 = int( graphTimestamp2 ) -\
1374 int( timestampLinkDownT0 )
1375 linkDownLatGraph3 = int( graphTimestamp3 ) -\
1376 int( timestampLinkDownT0 )
1377
1378 linkDownLatLink1 = int( linkTimestamp1 ) -\
1379 int( timestampLinkDownT0 )
1380 linkDownLatLink2 = int( linkTimestamp2 ) -\
1381 int( timestampLinkDownT0 )
1382 linkDownLatLink3 = int( linkTimestamp3 ) -\
1383 int( timestampLinkDownT0 )
andrewonlab53b641c2014-10-31 19:44:44 -04001384 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001385 main.log.error( "There was an error calculating" +
1386 " the delta for link down event" )
1387 linkDownLatGraph1 = 0
1388 linkDownLatGraph2 = 0
1389 linkDownLatGraph3 = 0
kelvin-onlab8a832582015-01-16 17:06:11 -08001390
andrewonlab79244cc2015-01-26 01:11:49 -05001391 linkDownLatDevice1 = 0
1392 linkDownLatDevice2 = 0
1393 linkDownLatDevice3 = 0
andrewonlab53b641c2014-10-31 19:44:44 -04001394
andrewonlab79244cc2015-01-26 01:11:49 -05001395 main.log.info( "Link down latency ONOS1 iteration " +
1396 str( i ) + " (end-to-end): " +
1397 str( linkDownLatGraph1 ) + " ms" )
1398 main.log.info( "Link down latency ONOS2 iteration " +
1399 str( i ) + " (end-to-end): " +
1400 str( linkDownLatGraph2 ) + " ms" )
1401 main.log.info( "Link down latency ONOS3 iteration " +
1402 str( i ) + " (end-to-end): " +
1403 str( linkDownLatGraph3 ) + " ms" )
1404
1405 main.log.info( "Link down latency ONOS1 iteration " +
1406 str( i ) + " (link-event-to-system-timestamp): " +
1407 str( linkDownLatLink1 ) + " ms" )
1408 main.log.info( "Link down latency ONOS2 iteration " +
1409 str( i ) + " (link-event-to-system-timestamp): " +
1410 str( linkDownLatLink2 ) + " ms" )
1411 main.log.info( "Link down latency ONOS3 iteration " +
1412 str( i ) + " (link-event-to-system-timestamp): " +
1413 str( linkDownLatLink3 ) )
1414
1415 # Calculate avg of node calculations
1416 linkDownLatGraphAvg =\
1417 ( linkDownLatGraph1 +
1418 linkDownLatGraph2 +
1419 linkDownLatGraph3 ) / 3
1420 linkDownLatLinkAvg =\
1421 ( linkDownLatLink1 +
1422 linkDownLatLink2 +
1423 linkDownLatLink3 ) / 3
1424
1425 # Set threshold and append latency to list
1426 if linkDownLatGraphAvg > downThresholdMin and\
1427 linkDownLatGraphAvg < downThresholdMax:
1428 linkDownGraphToSystemList.append(
1429 linkDownLatGraphAvg )
1430 else:
1431 main.log.info( "Link down latency exceeded threshold" )
1432 main.log.info( "Results for iteration " + str( i ) +
1433 "have been omitted" )
1434 if linkDownLatLinkAvg > downThresholdMin and\
1435 linkDownLatLinkAvg < downThresholdMax:
1436 linkDownLinkToSystemList.append(
1437 linkDownLatLinkAvg )
1438 else:
1439 main.log.info( "Link down latency exceeded threshold" )
1440 main.log.info( "Results for iteration " + str( i ) +
1441 "have been omitted" )
1442
1443 # NOTE: To remove loss rate and measure latency:
andrewonlab53b641c2014-10-31 19:44:44 -04001444 # 'sh tc qdisc del dev s1-eth1 root'
andrewonlab79244cc2015-01-26 01:11:49 -05001445 timestampLinkUpT0 = time.time() * 1000
1446 main.Mininet1.handle.sendline( "sh tc qdisc del dev " +
1447 "s1-eth1 root" )
1448 main.Mininet1.handle.expect( "mininet>" )
1449
1450 main.log.info( "Checking ONOS for link update" )
1451
1452 linkDown1 = True
1453 linkDown2 = True
1454 linkDown3 = True
1455 loopCount = 0
1456 while( ( linkDown1 and linkDown2 and linkDown3 )
1457 and loopCount < 30 ):
1458 jsonStr1 = main.ONOS1cli.links()
1459 jsonStr2 = main.ONOS2cli.links()
1460 jsonStr3 = main.ONOS3cli.links()
1461 if not ( jsonStr1 and jsonStr2 and jsonStr3 ):
1462 main.log.error( "CLI command returned error " )
andrewonlababb11c32014-11-04 15:03:24 -05001463 break
1464 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001465 jsonObj1 = json.loads( jsonStr1 )
1466 jsonObj2 = json.loads( jsonStr2 )
1467 jsonObj3 = json.loads( jsonStr3 )
1468
1469 for obj1 in jsonObj1:
1470 if '01' in obj1[ 'src' ][ 'device' ]:
1471 linkDown1 = False
1472 main.log.info( "Link up from " +
1473 "s1 -> s2 on ONOS1 detected" )
1474 for obj2 in jsonObj2:
1475 if '01' in obj2[ 'src' ][ 'device' ]:
1476 linkDown2 = False
1477 main.log.info( "Link up from " +
1478 "s1 -> s2 on ONOS2 detected" )
1479 for obj3 in jsonObj3:
1480 if '01' in obj3[ 'src' ][ 'device' ]:
1481 linkDown3 = False
1482 main.log.info( "Link up from " +
1483 "s1 -> s2 on ONOS3 detected" )
1484
1485 loopCount += 1
1486 time.sleep( 1 )
1487
1488 if ( linkDown1 and linkDown2 and linkDown3 ):
1489 main.log.info( "Link up discovery failed" )
1490
1491 linkUpLatGraph1 = 0
1492 linkUpLatGraph2 = 0
1493 linkUpLatGraph3 = 0
1494 linkUpLatDevice1 = 0
1495 linkUpLatDevice2 = 0
1496 linkUpLatDevice3 = 0
1497
andrewonlababb11c32014-11-04 15:03:24 -05001498 assertion = main.FALSE
1499 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001500 jsonTopoMetrics1 =\
1501 main.ONOS1cli.topologyEventsMetrics()
1502 jsonTopoMetrics2 =\
1503 main.ONOS2cli.topologyEventsMetrics()
1504 jsonTopoMetrics3 =\
1505 main.ONOS3cli.topologyEventsMetrics()
1506 jsonTopoMetrics1 = json.loads( jsonTopoMetrics1 )
1507 jsonTopoMetrics2 = json.loads( jsonTopoMetrics2 )
1508 jsonTopoMetrics3 = json.loads( jsonTopoMetrics3 )
andrewonlababb11c32014-11-04 15:03:24 -05001509
andrewonlab79244cc2015-01-26 01:11:49 -05001510 main.log.info( "Obtaining graph and device timestamp" )
1511 graphTimestamp1 = \
1512 jsonTopoMetrics1[ graphTimestamp ][ 'value' ]
1513 graphTimestamp2 = \
1514 jsonTopoMetrics2[ graphTimestamp ][ 'value' ]
1515 graphTimestamp3 = \
1516 jsonTopoMetrics3[ graphTimestamp ][ 'value' ]
andrewonlababb11c32014-11-04 15:03:24 -05001517
andrewonlab79244cc2015-01-26 01:11:49 -05001518 linkTimestamp1 = \
1519 jsonTopoMetrics1[ linkTimestamp ][ 'value' ]
1520 linkTimestamp2 = \
1521 jsonTopoMetrics2[ linkTimestamp ][ 'value' ]
1522 linkTimestamp3 = \
1523 jsonTopoMetrics3[ linkTimestamp ][ 'value' ]
andrewonlababb11c32014-11-04 15:03:24 -05001524
andrewonlab79244cc2015-01-26 01:11:49 -05001525 if graphTimestamp1 and graphTimestamp2 and\
1526 graphTimestamp3 and linkTimestamp1 and\
1527 linkTimestamp2 and linkTimestamp3:
1528 linkUpLatGraph1 = int( graphTimestamp1 ) -\
1529 int( timestampLinkUpT0 )
1530 linkUpLatGraph2 = int( graphTimestamp2 ) -\
1531 int( timestampLinkUpT0 )
1532 linkUpLatGraph3 = int( graphTimestamp3 ) -\
1533 int( timestampLinkUpT0 )
1534
1535 linkUpLatLink1 = int( linkTimestamp1 ) -\
1536 int( timestampLinkUpT0 )
1537 linkUpLatLink2 = int( linkTimestamp2 ) -\
1538 int( timestampLinkUpT0 )
1539 linkUpLatLink3 = int( linkTimestamp3 ) -\
1540 int( timestampLinkUpT0 )
andrewonlababb11c32014-11-04 15:03:24 -05001541 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001542 main.log.error( "There was an error calculating" +
1543 " the delta for link down event" )
1544 linkUpLatGraph1 = 0
1545 linkUpLatGraph2 = 0
1546 linkUpLatGraph3 = 0
kelvin-onlab8a832582015-01-16 17:06:11 -08001547
andrewonlab79244cc2015-01-26 01:11:49 -05001548 linkUpLatDevice1 = 0
1549 linkUpLatDevice2 = 0
1550 linkUpLatDevice3 = 0
1551
1552 if debugMode == 'on':
1553 main.log.info( "Link up latency ONOS1 iteration " +
1554 str( i ) + " (end-to-end): " +
1555 str( linkUpLatGraph1 ) + " ms" )
1556 main.log.info( "Link up latency ONOS2 iteration " +
1557 str( i ) + " (end-to-end): " +
1558 str( linkUpLatGraph2 ) + " ms" )
1559 main.log.info( "Link up latency ONOS3 iteration " +
1560 str( i ) + " (end-to-end): " +
1561 str( linkUpLatGraph3 ) + " ms" )
1562
1563 main.log.info(
1564 "Link up latency ONOS1 iteration " +
1565 str( i ) +
1566 " (link-event-to-system-timestamp): " +
1567 str( linkUpLatLink1 ) +
1568 " ms" )
1569 main.log.info(
1570 "Link up latency ONOS2 iteration " +
1571 str( i ) +
1572 " (link-event-to-system-timestamp): " +
1573 str( linkUpLatLink2 ) +
1574 " ms" )
1575 main.log.info(
1576 "Link up latency ONOS3 iteration " +
1577 str( i ) +
1578 " (link-event-to-system-timestamp): " +
1579 str( linkUpLatLink3 ) )
1580
1581 # Calculate avg of node calculations
1582 linkUpLatGraphAvg =\
1583 ( linkUpLatGraph1 +
1584 linkUpLatGraph2 +
1585 linkUpLatGraph3 ) / 3
1586 linkUpLatLinkAvg =\
1587 ( linkUpLatLink1 +
1588 linkUpLatLink2 +
1589 linkUpLatLink3 ) / 3
1590
1591 # Set threshold and append latency to list
1592 if linkUpLatGraphAvg > upThresholdMin and\
1593 linkUpLatGraphAvg < upThresholdMax:
1594 linkUpGraphToSystemList.append(
1595 linkUpLatGraphAvg )
andrewonlab8790abb2014-11-06 13:51:54 -05001596 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001597 main.log.info( "Link up latency exceeded threshold" )
1598 main.log.info( "Results for iteration " + str( i ) +
1599 "have been omitted" )
1600 if linkUpLatLinkAvg > upThresholdMin and\
1601 linkUpLatLinkAvg < upThresholdMax:
1602 linkUpLinkToSystemList.append(
1603 linkUpLatLinkAvg )
andrewonlab8790abb2014-11-06 13:51:54 -05001604 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001605 main.log.info( "Link up latency exceeded threshold" )
1606 main.log.info( "Results for iteration " + str( i ) +
1607 "have been omitted" )
andrewonlab53b641c2014-10-31 19:44:44 -04001608
andrewonlab79244cc2015-01-26 01:11:49 -05001609 # Calculate min, max, avg of list and report
1610 linkDownMin = min( linkDownGraphToSystemList )
1611 linkDownMax = max( linkDownGraphToSystemList )
1612 linkDownAvg = sum( linkDownGraphToSystemList ) / \
1613 len( linkDownGraphToSystemList )
1614 linkUpMin = min( linkUpGraphToSystemList )
1615 linkUpMax = max( linkUpGraphToSystemList )
1616 linkUpAvg = sum( linkUpGraphToSystemList ) / \
1617 len( linkUpGraphToSystemList )
1618 linkDownStdDev = \
1619 str( round( numpy.std( linkDownGraphToSystemList ), 1 ) )
1620 linkUpStdDev = \
1621 str( round( numpy.std( linkUpGraphToSystemList ), 1 ) )
andrewonlababb11c32014-11-04 15:03:24 -05001622
andrewonlab79244cc2015-01-26 01:11:49 -05001623 main.log.report( "Link down latency " +
1624 "Avg: " + str( linkDownAvg ) + " ms " +
1625 "Std Deviation: " + linkDownStdDev + " ms" )
1626 main.log.report( "Link up latency " +
1627 "Avg: " + str( linkUpAvg ) + " ms " +
1628 "Std Deviation: " + linkUpStdDev + " ms" )
andrewonlab4e124482014-11-04 13:37:25 -05001629
andrewonlab79244cc2015-01-26 01:11:49 -05001630 utilities.assert_equals(
1631 expect=main.TRUE,
1632 actual=assertion,
1633 onpass="Link discovery latency calculation successful",
1634 onfail="Link discovery latency case failed" )
andrewonlab8790abb2014-11-06 13:51:54 -05001635
andrewonlab79244cc2015-01-26 01:11:49 -05001636 def CASE5( self, main ):
1637 """
andrewonlabb54b85b2014-10-28 18:43:57 -04001638 100 Switch discovery latency
1639
1640 Important:
andrewonlab79244cc2015-01-26 01:11:49 -05001641 This test case can be potentially dangerous if
andrewonlab16ce4852014-10-30 13:41:09 -04001642 your machine has previously set iptables rules.
1643 One of the steps of the test case will flush
1644 all existing iptables rules.
andrewonlab8790abb2014-11-06 13:51:54 -05001645 Note:
andrewonlab79244cc2015-01-26 01:11:49 -05001646 You can specify the number of switches in the
andrewonlab8790abb2014-11-06 13:51:54 -05001647 params file to adjust the switch discovery size
andrewonlab79244cc2015-01-26 01:11:49 -05001648 ( and specify the corresponding topology in Mininet1
1649 .topo file )
1650 """
andrewonlabb54b85b2014-10-28 18:43:57 -04001651 import time
1652 import subprocess
1653 import os
1654 import requests
1655 import json
1656
andrewonlab79244cc2015-01-26 01:11:49 -05001657 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
1658 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
1659 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
1660 MN1Ip = main.params[ 'MN' ][ 'ip1' ]
1661 ONOSUser = main.params[ 'CTRL' ][ 'user' ]
andrewonlabb54b85b2014-10-28 18:43:57 -04001662
andrewonlab79244cc2015-01-26 01:11:49 -05001663 defaultSwPort = main.params[ 'CTRL' ][ 'port1' ]
andrewonlab16ce4852014-10-30 13:41:09 -04001664
andrewonlab79244cc2015-01-26 01:11:49 -05001665 # Number of iterations of case
1666 numIter = main.params[ 'TEST' ][ 'numIter' ]
1667 numSw = main.params[ 'TEST' ][ 'numSwitch' ]
andrewonlab58f7d702014-11-07 13:21:19 -05001668
andrewonlab79244cc2015-01-26 01:11:49 -05001669 # Timestamp 'keys' for json metrics output.
1670 # These are subject to change, hence moved into params
1671 deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ]
1672 graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ]
andrewonlabe5bcef92014-11-06 17:53:20 -05001673
andrewonlab79244cc2015-01-26 01:11:49 -05001674 debugMode = main.params[ 'TEST' ][ 'debugMode' ]
andrewonlab53b641c2014-10-31 19:44:44 -04001675
andrewonlab79244cc2015-01-26 01:11:49 -05001676 localTime = time.strftime( '%X' )
1677 localTime = localTime.replace( "/", "" )
1678 localTime = localTime.replace( " ", "_" )
1679 localTime = localTime.replace( ":", "" )
1680 if debugMode == 'on':
1681 main.ONOS1.tsharkPcap( "eth0",
1682 "/tmp/100_sw_lat_pcap_" + localTime )
andrewonlabb54b85b2014-10-28 18:43:57 -04001683
andrewonlab79244cc2015-01-26 01:11:49 -05001684 # Threshold for this test case
1685 swDiscThresholdStr = main.params[ 'TEST' ][ 'swDisc100Threshold' ]
1686 swDiscThresholdObj = swDiscThresholdStr.split( "," )
1687 swDiscThresholdMin = int( swDiscThresholdObj[ 0 ] )
1688 swDiscThresholdMax = int( swDiscThresholdObj[ 1 ] )
andrewonlabe5bcef92014-11-06 17:53:20 -05001689
andrewonlab79244cc2015-01-26 01:11:49 -05001690 tsharkOfpOutput = "/tmp/tshark_ofp_" + numSw + "sw.txt"
1691 tsharkTcpOutput = "/tmp/tshark_tcp_" + numSw + "sw.txt"
andrewonlabb54b85b2014-10-28 18:43:57 -04001692
andrewonlab79244cc2015-01-26 01:11:49 -05001693 tsharkOfpResultList = []
1694 tsharkTcpResultList = []
1695
1696 swDiscoveryLatList = []
1697
1698 main.case( numSw + " Switch discovery latency" )
1699 main.step( "Assigning all switches to ONOS1" )
1700 for i in range( 1, int( numSw ) + 1 ):
1701 main.Mininet1.assignSwController(
1702 sw=str( i ),
1703 ip1=ONOS1Ip,
1704 port1=defaultSwPort )
1705
1706 # Ensure that nodes are configured with ptpd
1707 # Just a warning message
1708 main.log.info( "Please check ptpd configuration to ensure" +
1709 " All nodes' system times are in sync" )
1710 time.sleep( 5 )
1711
1712 for i in range( 0, int( numIter ) ):
1713
1714 main.step( "Set iptables rule to block incoming sw connections" )
1715 # Set iptables rule to block incoming switch connections
1716 # The rule description is as follows:
andrewonlab53b641c2014-10-31 19:44:44 -04001717 # Append to INPUT rule,
1718 # behavior DROP that matches following:
1719 # * packet type: tcp
andrewonlab79244cc2015-01-26 01:11:49 -05001720 # * source IP: MN1Ip
andrewonlab53b641c2014-10-31 19:44:44 -04001721 # * destination PORT: 6633
andrewonlabb54b85b2014-10-28 18:43:57 -04001722 main.ONOS1.handle.sendline(
andrewonlab79244cc2015-01-26 01:11:49 -05001723 "sudo iptables -A INPUT -p tcp -s " + MN1Ip +
1724 " --dport " + defaultSwPort + " -j DROP" )
1725 main.ONOS1.handle.expect( "\$" )
1726 # Append to OUTPUT rule,
andrewonlab53b641c2014-10-31 19:44:44 -04001727 # behavior DROP that matches following:
1728 # * packet type: tcp
andrewonlab79244cc2015-01-26 01:11:49 -05001729 # * source IP: MN1Ip
andrewonlab53b641c2014-10-31 19:44:44 -04001730 # * destination PORT: 6633
1731 main.ONOS1.handle.sendline(
andrewonlab79244cc2015-01-26 01:11:49 -05001732 "sudo iptables -A OUTPUT -p tcp -s " + MN1Ip +
1733 " --dport " + defaultSwPort + " -j DROP" )
1734 main.ONOS1.handle.expect( "\$" )
1735 # Give time to allow rule to take effect
1736 # NOTE: Sleep period may need to be configured
andrewonlab8790abb2014-11-06 13:51:54 -05001737 # based on the number of switches in the topology
andrewonlab79244cc2015-01-26 01:11:49 -05001738 main.log.info( "Please wait for switch connection to " +
1739 "time out" )
1740 time.sleep( 60 )
andrewonlabb54b85b2014-10-28 18:43:57 -04001741
andrewonlab79244cc2015-01-26 01:11:49 -05001742 # Gather vendor OFP with tshark
1743 main.ONOS1.tsharkGrep( "OFP 86 Vendor",
1744 tsharkOfpOutput )
1745 main.ONOS1.tsharkGrep( "TCP 74 ",
1746 tsharkTcpOutput )
1747
1748 # NOTE: Remove all iptables rule quickly ( flush )
1749 # Before removal, obtain TestON timestamp at which
andrewonlab16ce4852014-10-30 13:41:09 -04001750 # removal took place
andrewonlab79244cc2015-01-26 01:11:49 -05001751 # ( ensuring nodes are configured via ptp )
andrewonlabb54b85b2014-10-28 18:43:57 -04001752 # sudo iptables -F
andrewonlab79244cc2015-01-26 01:11:49 -05001753
1754 t0System = time.time() * 1000
andrewonlab16ce4852014-10-30 13:41:09 -04001755 main.ONOS1.handle.sendline(
andrewonlab79244cc2015-01-26 01:11:49 -05001756 "sudo iptables -F" )
andrewonlabb54b85b2014-10-28 18:43:57 -04001757
andrewonlab79244cc2015-01-26 01:11:49 -05001758 # Counter to track loop count
1759 counterLoop = 0
1760 counterAvail1 = 0
1761 counterAvail2 = 0
1762 counterAvail3 = 0
1763 onos1Dev = False
1764 onos2Dev = False
1765 onos3Dev = False
1766 while counterLoop < 60:
1767 # Continue to check devices for all device
1768 # availability. When all devices in all 3
1769 # ONOS instances indicate that devices are available
1770 # obtain graph event timestamp for t1.
1771 deviceStrObj1 = main.ONOS1cli.devices()
1772 deviceStrObj2 = main.ONOS2cli.devices()
1773 deviceStrObj3 = main.ONOS3cli.devices()
andrewonlab16ce4852014-10-30 13:41:09 -04001774
andrewonlab79244cc2015-01-26 01:11:49 -05001775 deviceJson1 = json.loads( deviceStrObj1 )
1776 deviceJson2 = json.loads( deviceStrObj2 )
1777 deviceJson3 = json.loads( deviceStrObj3 )
1778
1779 for device1 in deviceJson1:
1780 if device1[ 'available' ]:
1781 counterAvail1 += 1
1782 if counterAvail1 == int( numSw ):
1783 onos1Dev = True
1784 main.log.info( "All devices have been " +
1785 "discovered on ONOS1" )
andrewonlab16ce4852014-10-30 13:41:09 -04001786 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001787 counterAvail1 = 0
1788 for device2 in deviceJson2:
1789 if device2[ 'available' ]:
1790 counterAvail2 += 1
1791 if counterAvail2 == int( numSw ):
1792 onos2Dev = True
1793 main.log.info( "All devices have been " +
1794 "discovered on ONOS2" )
andrewonlab16ce4852014-10-30 13:41:09 -04001795 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001796 counterAvail2 = 0
1797 for device3 in deviceJson3:
1798 if device3[ 'available' ]:
1799 counterAvail3 += 1
1800 if counterAvail3 == int( numSw ):
1801 onos3Dev = True
1802 main.log.info( "All devices have been " +
1803 "discovered on ONOS3" )
andrewonlab16ce4852014-10-30 13:41:09 -04001804 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001805 counterAvail3 = 0
andrewonlab16ce4852014-10-30 13:41:09 -04001806
andrewonlab79244cc2015-01-26 01:11:49 -05001807 if onos1Dev and onos2Dev and onos3Dev:
1808 main.log.info( "All devices have been discovered " +
1809 "on all ONOS instances" )
1810 jsonStrTopologyMetrics1 =\
1811 main.ONOS1cli.topologyEventsMetrics()
1812 jsonStrTopologyMetrics2 =\
1813 main.ONOS2cli.topologyEventsMetrics()
1814 jsonStrTopologyMetrics3 =\
1815 main.ONOS3cli.topologyEventsMetrics()
andrewonlab16ce4852014-10-30 13:41:09 -04001816
andrewonlab79244cc2015-01-26 01:11:49 -05001817 # Exit while loop if all devices discovered
1818 break
andrewonlab16ce4852014-10-30 13:41:09 -04001819
andrewonlab79244cc2015-01-26 01:11:49 -05001820 counterLoop += 1
1821 # Give some time in between CLI calls
1822 #( will not affect measurement )
1823 time.sleep( 3 )
andrewonlab16ce4852014-10-30 13:41:09 -04001824
andrewonlab79244cc2015-01-26 01:11:49 -05001825 main.ONOS1.tsharkStop()
andrewonlab53b641c2014-10-31 19:44:44 -04001826
andrewonlab79244cc2015-01-26 01:11:49 -05001827 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
1828 tsharkOfpOutput + " /tmp/" )
1829 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
1830 tsharkTcpOutput + " /tmp/" )
andrewonlab16ce4852014-10-30 13:41:09 -04001831
andrewonlab79244cc2015-01-26 01:11:49 -05001832 # TODO: Automate OFP output analysis
1833 # Debug mode - print out packets captured at runtime
1834 if debugMode == 'on':
1835 ofpFile = open( tsharkOfpOutput, 'r' )
1836 main.log.info( "Tshark OFP Vendor output: " )
1837 for line in ofpFile:
1838 tsharkOfpResultList.append( line )
1839 main.log.info( line )
1840 ofpFile.close()
andrewonlab16ce4852014-10-30 13:41:09 -04001841
andrewonlab79244cc2015-01-26 01:11:49 -05001842 tcpFile = open( tsharkTcpOutput, 'r' )
1843 main.log.info( "Tshark TCP 74 output: " )
1844 for line in tcpFile:
1845 tsharkTcpResultList.append( line )
1846 main.log.info( line )
1847 tcpFile.close()
andrewonlab16ce4852014-10-30 13:41:09 -04001848
andrewonlab79244cc2015-01-26 01:11:49 -05001849 jsonObj1 = json.loads( jsonStrTopologyMetrics1 )
1850 jsonObj2 = json.loads( jsonStrTopologyMetrics2 )
1851 jsonObj3 = json.loads( jsonStrTopologyMetrics3 )
1852
1853 graphTimestamp1 = \
1854 jsonObj1[ graphTimestamp ][ 'value' ]
1855 graphTimestamp2 = \
1856 jsonObj2[ graphTimestamp ][ 'value' ]
1857 graphTimestamp3 = \
1858 jsonObj3[ graphTimestamp ][ 'value' ]
1859
1860 graphLat1 = int( graphTimestamp1 ) - int( t0System )
1861 graphLat2 = int( graphTimestamp2 ) - int( t0System )
1862 graphLat3 = int( graphTimestamp3 ) - int( t0System )
1863
1864 avgGraphLat = \
1865 ( int( graphLat1 ) +
1866 int( graphLat2 ) +
1867 int( graphLat3 ) ) / 3
1868
1869 if avgGraphLat > swDiscThresholdMin \
1870 and avgGraphLat < swDiscThresholdMax:
1871 swDiscoveryLatList.append(
1872 avgGraphLat )
andrewonlabe5bcef92014-11-06 17:53:20 -05001873 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001874 main.log.info( "100 Switch discovery latency " +
1875 "exceeded the threshold." )
andrewonlab16ce4852014-10-30 13:41:09 -04001876
andrewonlab79244cc2015-01-26 01:11:49 -05001877 # END ITERATION FOR LOOP
andrewonlab16ce4852014-10-30 13:41:09 -04001878
andrewonlab79244cc2015-01-26 01:11:49 -05001879 swLatMin = min( swDiscoveryLatList )
1880 swLatMax = max( swDiscoveryLatList )
1881 swLatAvg = sum( swDiscoveryLatList ) /\
1882 len( swDiscoveryLatList )
andrewonlab16ce4852014-10-30 13:41:09 -04001883
andrewonlab79244cc2015-01-26 01:11:49 -05001884 main.log.report( "100 Switch discovery lat " +
1885 "Min: " + str( swLatMin ) + " ms" +
1886 "Max: " + str( swLatMax ) + " ms" +
1887 "Avg: " + str( swLatAvg ) + " ms" )
1888
1889 def CASE6( self, main ):
1890 """
andrewonlaba57a3042015-01-23 13:53:05 -05001891 Increase number of nodes and initiate CLI
andrewonlab79244cc2015-01-26 01:11:49 -05001892 """
andrewonlaba57a3042015-01-23 13:53:05 -05001893 import time
andrewonlaba57a3042015-01-23 13:53:05 -05001894
andrewonlab79244cc2015-01-26 01:11:49 -05001895 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
1896 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
1897 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
1898 ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
1899 ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
1900 ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
1901 ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
andrewonlaba57a3042015-01-23 13:53:05 -05001902
andrewonlab79244cc2015-01-26 01:11:49 -05001903 cellName = main.params[ 'ENV' ][ 'cellName' ]
andrewonlaba57a3042015-01-23 13:53:05 -05001904
andrewonlab79244cc2015-01-26 01:11:49 -05001905 global clusterCount
andrewonlaba57a3042015-01-23 13:53:05 -05001906
andrewonlab79244cc2015-01-26 01:11:49 -05001907 # Cluster size increased everytime the case is defined
1908 clusterCount += 2
andrewonlaba57a3042015-01-23 13:53:05 -05001909
andrewonlab79244cc2015-01-26 01:11:49 -05001910 main.log.report( "Increasing cluster size to " +
1911 str( clusterCount ) )
andrewonlaba57a3042015-01-23 13:53:05 -05001912
andrewonlab79244cc2015-01-26 01:11:49 -05001913 installResult = main.FALSE
1914 if clusterCount == 3:
1915 main.log.info( "Installing nodes 2 and 3" )
1916 node2Result = \
1917 main.ONOSbench.onosInstall( node=ONOS2Ip )
1918 node3Result = \
1919 main.ONOSbench.onosInstall( node=ONOS3Ip )
1920 installResult = node2Result and node3Result
andrewonlaba57a3042015-01-23 13:53:05 -05001921
andrewonlab79244cc2015-01-26 01:11:49 -05001922 time.sleep( 5 )
andrewonlaba57a3042015-01-23 13:53:05 -05001923
andrewonlab79244cc2015-01-26 01:11:49 -05001924 main.ONOS2cli.startOnosCli( ONOS2Ip )
1925 main.ONOS3cli.startOnosCli( ONOS3Ip )
andrewonlaba57a3042015-01-23 13:53:05 -05001926
andrewonlab79244cc2015-01-26 01:11:49 -05001927 elif clusterCount == 5:
1928 main.log.info( "Installing nodes 4 and 5" )
1929 node4Result = \
1930 main.ONOSbench.onosInstall( node=ONOS4Ip )
1931 node5Result = \
1932 main.ONOSbench.onosInstall( node=ONOS5Ip )
1933 installResult = node4Result and node5Result
andrewonlaba57a3042015-01-23 13:53:05 -05001934
andrewonlab79244cc2015-01-26 01:11:49 -05001935 time.sleep( 5 )
andrewonlaba57a3042015-01-23 13:53:05 -05001936
andrewonlab79244cc2015-01-26 01:11:49 -05001937 main.ONOS4cli.startOnosCli( ONOS4Ip )
1938 main.ONOS5cli.startOnosCli( ONOS5Ip )
andrewonlaba57a3042015-01-23 13:53:05 -05001939
andrewonlab79244cc2015-01-26 01:11:49 -05001940 elif clusterCount == 7:
1941 main.log.info( "Installing nodes 4 and 5" )
1942 node6Result = \
1943 main.ONOSbench.onosInstall( node=ONOS6Ip )
1944 node7Result = \
1945 main.ONOSbench.onosInstall( node=ONOS7Ip )
1946 installResult = node6Result and node7Result
andrewonlaba57a3042015-01-23 13:53:05 -05001947
andrewonlab79244cc2015-01-26 01:11:49 -05001948 time.sleep( 5 )
1949
1950 main.ONOS6cli.startOnosCli( ONOS6Ip )
1951 main.ONOS7cli.startOnosCli( ONOS7Ip )