blob: d0b66c9871b716af9146b5e7d88b1e54a3c642da [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 )
andrewonlab67630692015-01-29 20:16:01 -050072 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
andrewonlab67630692015-01-29 20:16:01 -0500204 # Initialize 2d array for [node][iteration] storage
205 endToEndLatNodeIter = numpy.zeros(( clusterCount, int(numIter) ))
206 ofpToGraphLatNodeIter = numpy.zeros(( clusterCount, int(numIter) ))
207 # tcp-to-ofp measurements are same throughout each iteration
208 tcpToOfpLatIter = []
209
andrewonlab79244cc2015-01-26 01:11:49 -0500210 # Directory/file to store tshark results
211 tsharkOfOutput = "/tmp/tshark_of_topo.txt"
212 tsharkTcpOutput = "/tmp/tshark_tcp_topo.txt"
213
214 # String to grep in tshark output
215 tsharkTcpString = "TCP 74 " + defaultSwPort
216 tsharkOfString = "OFP 86 Vendor"
217
218 # Initialize assertion to TRUE
andrewonlabe6745342014-10-17 14:29:13 -0400219 assertion = main.TRUE
andrewonlabb1998c52014-11-10 13:31:43 -0500220
andrewonlab79244cc2015-01-26 01:11:49 -0500221 localTime = time.strftime( '%x %X' )
222 localTime = localTime.replace( "/", "" )
223 localTime = localTime.replace( " ", "_" )
224 localTime = localTime.replace( ":", "" )
225 if debugMode == 'on':
226 main.ONOS1.tsharkPcap( "eth0",
227 "/tmp/single_sw_lat_pcap_" + localTime )
andrewonlab58f7d702014-11-07 13:21:19 -0500228
andrewonlab79244cc2015-01-26 01:11:49 -0500229 main.log.info( "Debug mode is on" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400230
andrewonlab79244cc2015-01-26 01:11:49 -0500231 main.log.report( "Latency of adding one switch to controller" )
232 main.log.report( "First " + str( iterIgnore ) + " iterations ignored" +
233 " for jvm warmup time" )
234 main.log.report( "Total iterations of test: " + str( numIter ) )
andrewonlabba44bcf2014-10-16 16:54:41 -0400235
andrewonlab79244cc2015-01-26 01:11:49 -0500236 for i in range( 0, int( numIter ) ):
237 main.log.info( "Starting tshark capture" )
238
239 #* TCP [ ACK, SYN ] is used as t0A, the
240 # very first "exchange" between ONOS and
andrewonlabba44bcf2014-10-16 16:54:41 -0400241 # the switch for end-to-end measurement
andrewonlab79244cc2015-01-26 01:11:49 -0500242 #* OFP [ Stats Reply ] is used for t0B
andrewonlabba44bcf2014-10-16 16:54:41 -0400243 # the very last OFP message between ONOS
244 # and the switch for ONOS measurement
andrewonlab79244cc2015-01-26 01:11:49 -0500245 main.ONOS1.tsharkGrep( tsharkTcpString,
246 tsharkTcpOutput )
247 main.ONOS1.tsharkGrep( tsharkOfString,
248 tsharkOfOutput )
andrewonlabba44bcf2014-10-16 16:54:41 -0400249
andrewonlab79244cc2015-01-26 01:11:49 -0500250 # Wait and ensure tshark is started and
251 # capturing
252 time.sleep( 10 )
andrewonlabba44bcf2014-10-16 16:54:41 -0400253
andrewonlab79244cc2015-01-26 01:11:49 -0500254 main.log.info( "Assigning s1 to controller" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400255
andrewonlab79244cc2015-01-26 01:11:49 -0500256 main.Mininet1.assignSwController(
257 sw="1",
258 ip1=ONOS1Ip,
259 port1=defaultSwPort )
andrewonlabba44bcf2014-10-16 16:54:41 -0400260
andrewonlab79244cc2015-01-26 01:11:49 -0500261 # Wait and ensure switch is assigned
262 # before stopping tshark
263 time.sleep( 30 )
andrewonlabba44bcf2014-10-16 16:54:41 -0400264
andrewonlab79244cc2015-01-26 01:11:49 -0500265 main.log.info( "Stopping all Tshark processes" )
266 main.ONOS1.stopTshark()
kelvin-onlab8a832582015-01-16 17:06:11 -0800267
andrewonlab79244cc2015-01-26 01:11:49 -0500268 # tshark output is saved in ONOS. Use subprocess
269 # to copy over files to TestON for parsing
270 main.log.info( "Copying over tshark files" )
271
272 # TCP CAPTURE ****
273 # Copy the tshark output from ONOS machine to
274 # TestON machine in tsharkTcpOutput directory>file
275 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
276 tsharkTcpOutput + " /tmp/" )
277 tcpFile = open( tsharkTcpOutput, 'r' )
278 tempText = tcpFile.readline()
279 tempText = tempText.split( " " )
280
281 main.log.info( "Object read in from TCP capture: " +
282 str( tempText ) )
283 if len( tempText ) > 1:
284 t0Tcp = float( tempText[ 1 ] ) * 1000.0
andrewonlabe6745342014-10-17 14:29:13 -0400285 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500286 main.log.error( "Tshark output file for TCP" +
287 " returned unexpected results" )
288 t0Tcp = 0
andrewonlabe6745342014-10-17 14:29:13 -0400289 assertion = main.FALSE
andrewonlab79244cc2015-01-26 01:11:49 -0500290
291 tcpFile.close()
andrewonlabe6745342014-10-17 14:29:13 -0400292 #****************
andrewonlabba44bcf2014-10-16 16:54:41 -0400293
andrewonlab79244cc2015-01-26 01:11:49 -0500294 # OF CAPTURE ****
295 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
296 tsharkOfOutput + " /tmp/" )
297 ofFile = open( tsharkOfOutput, 'r' )
298
299 lineOfp = ""
300 # Read until last line of file
andrewonlabe6745342014-10-17 14:29:13 -0400301 while True:
andrewonlab79244cc2015-01-26 01:11:49 -0500302 tempText = ofFile.readline()
303 if tempText != '':
304 lineOfp = tempText
andrewonlabe6745342014-10-17 14:29:13 -0400305 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500306 break
307 obj = lineOfp.split( " " )
308
309 main.log.info( "Object read in from OFP capture: " +
310 str( lineOfp ) )
311
312 if len( lineOfp ) > 1:
313 t0Ofp = float( obj[ 1 ] ) * 1000.0
andrewonlabe6745342014-10-17 14:29:13 -0400314 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500315 main.log.error( "Tshark output file for OFP" +
316 " returned unexpected results" )
317 t0Ofp = 0
andrewonlabe6745342014-10-17 14:29:13 -0400318 assertion = main.FALSE
andrewonlab79244cc2015-01-26 01:11:49 -0500319
320 ofFile.close()
andrewonlabe6745342014-10-17 14:29:13 -0400321 #****************
andrewonlab867212a2014-10-22 20:13:38 -0400322
andrewonlab79244cc2015-01-26 01:11:49 -0500323 jsonStr1 = main.ONOS1cli.topologyEventsMetrics()
324 # Initialize scale-out variables
325 jsonStr2 = ""
326 jsonStr3 = ""
327 jsonStr4 = ""
328 jsonStr5 = ""
329 jsonStr6 = ""
330 jsonStr7 = ""
andrewonlabe9fb6722014-10-24 12:20:35 -0400331
andrewonlab79244cc2015-01-26 01:11:49 -0500332 jsonObj1 = json.loads( jsonStr1 )
333 # Initialize scale-out variables
334 jsonObj2 = ""
335 jsonObj3 = ""
336 jsonObj4 = ""
337 jsonObj5 = ""
338 jsonObj6 = ""
339 jsonObj7 = ""
kelvin-onlab8a832582015-01-16 17:06:11 -0800340
andrewonlab79244cc2015-01-26 01:11:49 -0500341 # Obtain graph timestamp. This timestsamp captures
342 # the epoch time at which the topology graph was updated.
343 graphTimestamp1 = \
344 jsonObj1[ graphTimestamp ][ 'value' ]
345 # Obtain device timestamp. This timestamp captures
346 # the epoch time at which the device event happened
347 deviceTimestamp1 = \
348 jsonObj1[ deviceTimestamp ][ 'value' ]
349
350 # t0 to device processing latency
351 deltaDevice1 = int( deviceTimestamp1 ) - int( t0Tcp )
andrewonlab79244cc2015-01-26 01:11:49 -0500352 # t0 to graph processing latency ( end-to-end )
353 deltaGraph1 = int( graphTimestamp1 ) - int( t0Tcp )
andrewonlab79244cc2015-01-26 01:11:49 -0500354 # ofp to graph processing latency ( ONOS processing )
355 deltaOfpGraph1 = int( graphTimestamp1 ) - int( t0Ofp )
andrewonlab79244cc2015-01-26 01:11:49 -0500356 # ofp to device processing latency ( ONOS processing )
357 deltaOfpDevice1 = float( deviceTimestamp1 ) - float( t0Ofp )
andrewonlab67630692015-01-29 20:16:01 -0500358 # tcp to ofp processing latency ( switch connection )
359 deltaTcpOfp1 = int(t0Ofp) - int(t0Tcp)
360
361 if deltaTcpOfp1 > thresholdMin and deltaTcpOfp1 < thresholdMax\
362 and i >= iterIgnore:
363 tcpToOfpLatIter.append(deltaTcpOfp1)
364 main.log.info("iter"+str(i)+" tcp-to-ofp: "+
365 str(deltaTcpOfp1)+" ms")
366 else:
367 tcpToOfpLatIter.append(0)
368 main.log.info("iter"+str(i)+" tcp-to-ofp: "+
369 str(deltaTcpOfp1)+" ms - ignored this iteration")
370
371 # Store initial measurements in data array
372 #This measurement is for node 1
373
374 if deltaGraph1 > thresholdMin and deltaGraph1 < thresholdMax\
375 and i >= iterIgnore:
376 endToEndLatNodeIter[0][i] = deltaGraph1
377 main.log.info("ONOS1 iter"+str(i)+" end-to-end: "+
378 str(deltaGraph1)+" ms")
379 else:
380 main.log.info("ONOS1 iter"+str(i)+" end-to-end: "+
381 str(deltaGraph1)+" ms - ignored this iteration")
382
383
384 if deltaOfpGraph1 > thresholdMin and deltaOfpGraph1 < thresholdMax\
385 and i >= iterIgnore:
386 ofpToGraphLatNodeIter[0][i] = deltaOfpGraph1
387
388 main.log.info("ONOS1 iter"+str(i)+" ofp-to-graph: "+
389 str(deltaOfpGraph1)+" ms")
andrewonlab79244cc2015-01-26 01:11:49 -0500390
391 # TODO: Create even cluster number events
392
393 # Include scale-out measurements when applicable
394 if clusterCount >= 3:
395 jsonStr2 = main.ONOS2cli.topologyEventsMetrics()
396 jsonStr3 = main.ONOS3cli.topologyEventsMetrics()
397 jsonObj2 = json.loads( jsonStr2 )
398 jsonObj3 = json.loads( jsonStr3 )
399 graphTimestamp2 = \
400 jsonObj2[ graphTimestamp ][ 'value' ]
401 graphTimestamp3 = \
402 jsonObj3[ graphTimestamp ][ 'value' ]
403 deviceTimestamp2 = \
404 jsonObj2[ deviceTimestamp ][ 'value' ]
405 deviceTimestamp3 = \
406 jsonObj3[ deviceTimestamp ][ 'value' ]
407 deltaDevice2 = int( deviceTimestamp2 ) - int( t0Tcp )
408 deltaDevice3 = int( deviceTimestamp3 ) - int( t0Tcp )
409 deltaGraph2 = int( graphTimestamp2 ) - int( t0Tcp )
410 deltaGraph3 = int( graphTimestamp3 ) - int( t0Tcp )
411 deltaOfpGraph2 = int( graphTimestamp2 ) - int( t0Ofp )
412 deltaOfpGraph3 = int( graphTimestamp3 ) - int( t0Ofp )
413 deltaOfpDevice2 = float( deviceTimestamp2 ) -\
414 float( t0Ofp )
415 deltaOfpDevice3 = float( deviceTimestamp3 ) -\
416 float( t0Ofp )
andrewonlaba57a3042015-01-23 13:53:05 -0500417
andrewonlab67630692015-01-29 20:16:01 -0500418 if deltaGraph2 > thresholdMin and\
419 deltaGraph2 < thresholdMax and i >= iterIgnore:
420 endToEndLatNodeIter[1][i] = deltaGraph2
421 main.log.info("ONOS2 iter"+str(i)+" end-to-end: "+
422 str(deltaGraph2)+" ms")
423
424 if deltaOfpGraph2 > thresholdMin and\
425 deltaOfpGraph2 < thresholdMax and i >= iterIgnore:
426 ofpToGraphLatNodeIter[1][i] = deltaOfpGraph2
427 main.log.info("ONOS2 iter"+str(i)+" ofp-to-graph: "+
428 str(deltaOfpGraph2)+" ms")
429
430 if deltaGraph3 > thresholdMin and\
431 deltaGraph3 < thresholdMax and i >= iterIgnore:
432 endToEndLatNodeIter[2][i] = deltaGraph3
433 main.log.info("ONOS3 iter"+str(i)+" end-to-end: "+
434 str(deltaGraph3)+" ms")
435
436 if deltaOfpGraph3 > thresholdMin and\
437 deltaOfpGraph3 < thresholdMax and i >= iterIgnore:
438 ofpToGraphLatNodeIter[2][i] = deltaOfpGraph3
439 main.log.info("ONOS3 iter"+str(i)+" ofp-to-graph: "+
440 str(deltaOfpGraph3)+" ms")
441
andrewonlab79244cc2015-01-26 01:11:49 -0500442 if clusterCount >= 5:
443 jsonStr4 = main.ONOS4cli.topologyEventsMetrics()
444 jsonStr5 = main.ONOS5cli.topologyEventsMetrics()
445 jsonObj4 = json.loads( jsonStr4 )
446 jsonObj5 = json.loads( jsonStr5 )
447 graphTimestamp4 = \
448 jsonObj4[ graphTimestamp ][ 'value' ]
449 graphTimestamp5 = \
450 jsonObj5[ graphTimestamp ][ 'value' ]
451 deviceTimestamp4 = \
452 jsonObj4[ deviceTimestamp ][ 'value' ]
453 deviceTimestamp5 = \
454 jsonObj5[ deviceTimestamp ][ 'value' ]
455 deltaDevice4 = int( deviceTimestamp4 ) - int( t0Tcp )
456 deltaDevice5 = int( deviceTimestamp5 ) - int( t0Tcp )
457 deltaGraph4 = int( graphTimestamp4 ) - int( t0Tcp )
458 deltaGraph5 = int( graphTimestamp5 ) - int( t0Tcp )
459 deltaOfpGraph4 = int( graphTimestamp4 ) - int( t0Ofp )
460 deltaOfpGraph5 = int( graphTimestamp5 ) - int( t0Ofp )
461 deltaOfpDevice4 = float( deviceTimestamp4 ) -\
462 float( t0Ofp )
463 deltaOfpDevice5 = float( deviceTimestamp5 ) -\
464 float( t0Ofp )
andrewonlab67630692015-01-29 20:16:01 -0500465
466 if deltaGraph4 > thresholdMin and\
467 deltaGraph4 < thresholdMax and i >= iterIgnore:
468 endToEndLatNodeIter[3][i] = deltaGraph4
469 main.log.info("ONOS4 iter"+str(i)+" end-to-end: "+
470 str(deltaGraph4)+" ms")
471
472 #TODO:
473 if deltaOfpGraph4 > thresholdMin and\
474 deltaOfpGraph4 < thresholdMax and i >= iterIgnore:
475 ofpToGraphLatNodeIter[3][i] = deltaOfpGraph4
476 main.log.info("ONOS4 iter"+str(i)+" ofp-to-graph: "+
477 str(deltaOfpGraph4)+" ms")
andrewonlaba57a3042015-01-23 13:53:05 -0500478
andrewonlab67630692015-01-29 20:16:01 -0500479 if deltaGraph5 > thresholdMin and\
480 deltaGraph5 < thresholdMax and i >= iterIgnore:
481 endToEndLatNodeIter[4][i] = deltaGraph5
482 main.log.info("ONOS5 iter"+str(i)+" end-to-end: "+
483 str(deltaGraph5)+" ms")
484
485 if deltaOfpGraph5 > thresholdMin and\
486 deltaOfpGraph5 < thresholdMax and i >= iterIgnore:
487 ofpToGraphLatNodeIter[4][i] = deltaOfpGraph5
488 main.log.info("ONOS5 iter"+str(i)+" ofp-to-graph: "+
489 str(deltaOfpGraph5)+" ms")
490
andrewonlab79244cc2015-01-26 01:11:49 -0500491 if clusterCount >= 7:
492 jsonStr6 = main.ONOS6cli.topologyEventsMetrics()
493 jsonStr7 = main.ONOS7cli.topologyEventsMetrics()
494 jsonObj6 = json.loads( jsonStr6 )
495 jsonObj7 = json.loads( jsonStr7 )
496 graphTimestamp6 = \
497 jsonObj6[ graphTimestamp ][ 'value' ]
498 graphTimestamp7 = \
499 jsonObj7[ graphTimestamp ][ 'value' ]
500 deviceTimestamp6 = \
501 jsonObj6[ deviceTimestamp ][ 'value' ]
502 deviceTimestamp7 = \
503 jsonObj7[ deviceTimestamp ][ 'value' ]
504 deltaDevice6 = int( deviceTimestamp6 ) - int( t0Tcp )
505 deltaDevice7 = int( deviceTimestamp7 ) - int( t0Tcp )
506 deltaGraph6 = int( graphTimestamp6 ) - int( t0Tcp )
507 deltaGraph7 = int( graphTimestamp7 ) - int( t0Tcp )
508 deltaOfpGraph6 = int( graphTimestamp6 ) - int( t0Ofp )
509 deltaOfpGraph7 = int( graphTimestamp7 ) - int( t0Ofp )
510 deltaOfpDevice6 = float( deviceTimestamp6 ) -\
511 float( t0Ofp )
512 deltaOfpDevice7 = float( deviceTimestamp7 ) -\
513 float( t0Ofp )
andrewonlab67630692015-01-29 20:16:01 -0500514
515 if deltaGraph6 > thresholdMin and\
516 deltaGraph6 < thresholdMax and i >= iterIgnore:
517 endToEndLatNodeIter[5][i] = deltaGraph6
518 main.log.info("ONOS6 iter"+str(i)+" end-to-end: "+
519 str(deltaGraph6)+" ms")
520
521 #TODO:
522 if deltaOfpGraph6 > thresholdMin and\
523 deltaOfpGraph6 < thresholdMax and i >= iterIgnore:
524 ofpToGraphLatNodeIter[5][i] = deltaOfpGraph6
525 main.log.info("ONOS6 iter"+str(i)+" ofp-to-graph: "+
526 str(deltaOfpGraph6)+" ms")
andrewonlaba57a3042015-01-23 13:53:05 -0500527
andrewonlab67630692015-01-29 20:16:01 -0500528 if deltaGraph7 > thresholdMin and\
529 deltaGraph7 < thresholdMax and i >= iterIgnore:
530 endToEndLatNodeIter[6][i] = deltaGraph7
531 main.log.info("ONOS7 iter"+str(i)+" end-to-end: "+
532 str(deltaGraph7)+" ms")
533
534 if deltaOfpGraph7 > thresholdMin and\
535 deltaOfpGraph7 < thresholdMax and i >= iterIgnore:
536 ofpToGraphLatNodeIter[6][i] = deltaOfpGraph7
537 main.log.info("ONOS7 iter"+str(i)+" ofp-to-graph: "+
538 str(deltaOfpGraph7)+" ms")
andrewonlabba44bcf2014-10-16 16:54:41 -0400539
andrewonlab79244cc2015-01-26 01:11:49 -0500540 main.step( "Remove switch from controller" )
541 main.Mininet1.deleteSwController( "s1" )
andrewonlabf47993a2014-10-24 17:56:01 -0400542
andrewonlab79244cc2015-01-26 01:11:49 -0500543 time.sleep( 5 )
544
545 # END of for loop iteration
546
andrewonlab67630692015-01-29 20:16:01 -0500547 #str( round( numpy.std( latencyT0ToDeviceList ), 1 ) )
andrewonlabc15c9582014-10-24 16:35:52 -0400548
andrewonlab67630692015-01-29 20:16:01 -0500549 endToEndAvg = 0
550 ofpToGraphAvg = 0
551 endToEndList = []
552 ofpToGraphList = []
andrewonlab69864162014-11-11 16:28:48 -0500553
andrewonlab67630692015-01-29 20:16:01 -0500554 for node in range( 0, clusterCount ):
555 # The latency 2d array was initialized to 0.
556 # If an iteration was ignored, then we have some 0's in
557 # our calculation. To avoid having this interfere with our
558 # results, we must delete any index where 0 is found...
559 # WARN: Potentially, we could have latency that hovers at
560 # 0 ms once we have optimized code. FIXME for when this is
561 # the case. Being able to obtain sub-millisecond accuracy
562 # can prevent this from happening
563 for item in endToEndLatNodeIter[node]:
564 if item > 0.0:
565 endToEndList.append(item)
566 for item in ofpToGraphLatNodeIter[node]:
567 if item > 0.0:
568 ofpToGraphList.append(item)
andrewonlabc15c9582014-10-24 16:35:52 -0400569
andrewonlab67630692015-01-29 20:16:01 -0500570 endToEndAvg = numpy.mean(endToEndList)
571 ofpToGraphAvg = numpy.mean(ofpToGraphList)
andrewonlabc15c9582014-10-24 16:35:52 -0400572
andrewonlab67630692015-01-29 20:16:01 -0500573 main.log.report( " - Node "+str(node+1)+" Summary - " )
574 main.log.report( " End-to-end Avg: "+
575 str(round(endToEndAvg,2))+" ms"+
576 " End-to-end Std dev: "+
577 str(round(numpy.std(endToEndList),2))+" ms")
andrewonlabd5367a42015-01-30 14:46:17 -0500578 #main.log.report( " Ofp-to-graph Avg: "+
579 # str(round(ofpToGraphAvg,2))+" ms"+
580 # " Ofp-to-graph Std dev: "+
581 # str(round(numpy.std(ofpToGraphList),2))+
582 # " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400583
andrewonlab79244cc2015-01-26 01:11:49 -0500584 if debugMode == 'on':
585 main.ONOS1.cpLogsToDir( "/opt/onos/log/karaf.log",
586 "/tmp/", copyFileName="sw_lat_karaf" )
andrewonlabb1998c52014-11-10 13:31:43 -0500587
andrewonlab67630692015-01-29 20:16:01 -0500588 #TODO: correct assert
589 assertion = main.TRUE
590
andrewonlab79244cc2015-01-26 01:11:49 -0500591 utilities.assert_equals( expect=main.TRUE, actual=assertion,
592 onpass="Switch latency test successful",
593 onfail="Switch latency test failed" )
andrewonlabba44bcf2014-10-16 16:54:41 -0400594
andrewonlab79244cc2015-01-26 01:11:49 -0500595 def CASE3( self, main ):
596 """
andrewonlab8d29f122014-10-22 17:15:04 -0400597 Bring port up / down and measure latency.
598 Port enable / disable is simulated by ifconfig up / down
andrewonlab79244cc2015-01-26 01:11:49 -0500599
600 In ONOS-next, we must ensure that the port we are
andrewonlab393531a2014-10-27 18:36:26 -0400601 manipulating is connected to another switch with a valid
602 connection. Otherwise, graph view will not be updated.
andrewonlab79244cc2015-01-26 01:11:49 -0500603 """
andrewonlab8d29f122014-10-22 17:15:04 -0400604 import time
605 import subprocess
606 import os
607 import requests
608 import json
andrewonlab4f50ec92014-11-11 14:24:45 -0500609 import numpy
andrewonlab79244cc2015-01-26 01:11:49 -0500610 global clusterCount
andrewonlab2a6c9342014-10-16 13:40:15 -0400611
andrewonlab79244cc2015-01-26 01:11:49 -0500612 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
613 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
614 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
615 ONOSUser = main.params[ 'CTRL' ][ 'user' ]
andrewonlab8d29f122014-10-22 17:15:04 -0400616
andrewonlab79244cc2015-01-26 01:11:49 -0500617 defaultSwPort = main.params[ 'CTRL' ][ 'port1' ]
618
andrewonlab8790abb2014-11-06 13:51:54 -0500619 assertion = main.TRUE
andrewonlab79244cc2015-01-26 01:11:49 -0500620 # Number of iterations of case
621 numIter = main.params[ 'TEST' ][ 'numIter' ]
andrewonlabd5367a42015-01-30 14:46:17 -0500622 iterIgnore = int( main.params[ 'TEST' ][ 'iterIgnore' ] )
andrewonlab58f7d702014-11-07 13:21:19 -0500623
andrewonlab79244cc2015-01-26 01:11:49 -0500624 # Timestamp 'keys' for json metrics output.
625 # These are subject to change, hence moved into params
626 deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ]
627 graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ]
andrewonlab393531a2014-10-27 18:36:26 -0400628
andrewonlab79244cc2015-01-26 01:11:49 -0500629 debugMode = main.params[ 'TEST' ][ 'debugMode' ]
andrewonlabe5bcef92014-11-06 17:53:20 -0500630
andrewonlab79244cc2015-01-26 01:11:49 -0500631 localTime = time.strftime( '%x %X' )
632 localTime = localTime.replace( "/", "" )
633 localTime = localTime.replace( " ", "_" )
634 localTime = localTime.replace( ":", "" )
635 if debugMode == 'on':
636 main.ONOS1.tsharkPcap( "eth0",
637 "/tmp/port_lat_pcap_" + localTime )
andrewonlabe5bcef92014-11-06 17:53:20 -0500638
andrewonlab79244cc2015-01-26 01:11:49 -0500639 # Threshold for this test case
640 upThresholdStr = main.params[ 'TEST' ][ 'portUpThreshold' ]
641 downThresholdStr = main.params[ 'TEST' ][ 'portDownThreshold' ]
andrewonlabe5bcef92014-11-06 17:53:20 -0500642
andrewonlab79244cc2015-01-26 01:11:49 -0500643 upThresholdObj = upThresholdStr.split( "," )
644 downThresholdObj = downThresholdStr.split( "," )
645
646 upThresholdMin = int( upThresholdObj[ 0 ] )
647 upThresholdMax = int( upThresholdObj[ 1 ] )
648
649 downThresholdMin = int( downThresholdObj[ 0 ] )
650 downThresholdMax = int( downThresholdObj[ 1 ] )
651
652 # NOTE: Some hardcoded variables you may need to configure
andrewonlab393531a2014-10-27 18:36:26 -0400653 # besides the params
andrewonlab8d29f122014-10-22 17:15:04 -0400654
andrewonlab79244cc2015-01-26 01:11:49 -0500655 tsharkPortStatus = "OFP 130 Port Status"
andrewonlab8d29f122014-10-22 17:15:04 -0400656
andrewonlab79244cc2015-01-26 01:11:49 -0500657 tsharkPortUp = "/tmp/tshark_port_up.txt"
658 tsharkPortDown = "/tmp/tshark_port_down.txt"
659 interfaceConfig = "s1-eth1"
andrewonlab8d29f122014-10-22 17:15:04 -0400660
andrewonlab79244cc2015-01-26 01:11:49 -0500661 main.log.report( "Port enable / disable latency" )
662 main.log.report( "Simulated by ifconfig up / down" )
663 main.log.report( "Total iterations of test: " + str( numIter ) )
andrewonlab8d29f122014-10-22 17:15:04 -0400664
andrewonlab79244cc2015-01-26 01:11:49 -0500665 main.step( "Assign switches s1 and s2 to controller 1" )
666 main.Mininet1.assignSwController( sw="1", ip1=ONOS1Ip,
667 port1=defaultSwPort )
668 main.Mininet1.assignSwController( sw="2", ip1=ONOS1Ip,
669 port1=defaultSwPort )
andrewonlab8d29f122014-10-22 17:15:04 -0400670
andrewonlab79244cc2015-01-26 01:11:49 -0500671 # Give enough time for metrics to propagate the
672 # assign controller event. Otherwise, these events may
673 # carry over to our measurements
674 time.sleep( 15 )
andrewonlab393531a2014-10-27 18:36:26 -0400675
andrewonlab79244cc2015-01-26 01:11:49 -0500676 portUpDeviceToOfpList = []
677 portUpGraphToOfpList = []
678 portDownDeviceToOfpList = []
679 portDownGraphToOfpList = []
andrewonlabd5367a42015-01-30 14:46:17 -0500680
681 # Initialize 2d array filled with 0's
682 # arraySizeFormat[clusterCount][numIter]
683 portUpDevNodeIter = numpy.zeros(( clusterCount, int(numIter) ))
684 portUpGraphNodeIter = numpy.zeros(( clusterCount, int(numIter) ))
685 portDownDevNodeIter = numpy.zeros(( clusterCount, int(numIter) ))
686 portDownGraphNodeIter = numpy.zeros(( clusterCount, int(numIter) ))
andrewonlab8d29f122014-10-22 17:15:04 -0400687
andrewonlab79244cc2015-01-26 01:11:49 -0500688 for i in range( 0, int( numIter ) ):
689 main.step( "Starting wireshark capture for port status down" )
690 main.ONOS1.tsharkGrep( tsharkPortStatus,
691 tsharkPortDown )
andrewonlab8d29f122014-10-22 17:15:04 -0400692
andrewonlab79244cc2015-01-26 01:11:49 -0500693 time.sleep( 5 )
694
695 # Disable interface that is connected to switch 2
696 main.step( "Disable port: " + interfaceConfig )
697 main.Mininet1.handle.sendline( "sh ifconfig " +
698 interfaceConfig + " down" )
699 main.Mininet1.handle.expect( "mininet>" )
700
701 time.sleep( 3 )
702 main.ONOS1.tsharkStop()
703
704 # Copy tshark output file from ONOS to TestON instance
kelvin-onlab8a832582015-01-16 17:06:11 -0800705 #/tmp directory
andrewonlab79244cc2015-01-26 01:11:49 -0500706 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
707 tsharkPortDown + " /tmp/" )
kelvin-onlab8a832582015-01-16 17:06:11 -0800708
andrewonlab79244cc2015-01-26 01:11:49 -0500709 fPortDown = open( tsharkPortDown, 'r' )
710 # Get first line of port down event from tshark
711 fLine = fPortDown.readline()
712 objDown = fLine.split( " " )
713 if len( fLine ) > 0:
714 # NOTE: objDown[ 1 ] is a very unreliable
715 # way to determine the timestamp. If
716 # results seem way off, check the object
andrewonlaba57a3042015-01-23 13:53:05 -0500717 # itself by printing it out
andrewonlab79244cc2015-01-26 01:11:49 -0500718 timestampBeginPtDown = int( float( objDown[ 1 ] ) * 1000 )
719 # For some reason, wireshark decides to record the
andrewonlaba57a3042015-01-23 13:53:05 -0500720 # timestamp at the 3rd object position instead of
andrewonlab79244cc2015-01-26 01:11:49 -0500721 # 2nd at unpredictable times. This statement is
andrewonlaba57a3042015-01-23 13:53:05 -0500722 # used to capture that odd behavior and use the
723 # correct epoch time
andrewonlab79244cc2015-01-26 01:11:49 -0500724 if timestampBeginPtDown < 1400000000000:
725 timestampBeginPtDown = \
726 int( float( objDown[ 2 ] ) * 1000 )
andrewonlaba57a3042015-01-23 13:53:05 -0500727
andrewonlab79244cc2015-01-26 01:11:49 -0500728 main.log.info( "Port down begin timestamp: " +
729 str( timestampBeginPtDown ) )
andrewonlab8d29f122014-10-22 17:15:04 -0400730 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500731 main.log.info( "Tshark output file returned unexpected" +
732 " results: " + str( objDown ) )
733 timestampBeginPtDown = 0
734 fPortDown.close()
735
736 main.step( "Obtain t1 by metrics call" )
737 jsonStrUp1 = main.ONOS1cli.topologyEventsMetrics()
738 jsonObj1 = json.loads( jsonStrUp1 )
739 # Obtain graph timestamp. This timestsamp captures
740 # the epoch time at which the topology graph was updated.
741 graphTimestamp1 = \
742 jsonObj1[ graphTimestamp ][ 'value' ]
743 # Obtain device timestamp. This timestamp captures
744 # the epoch time at which the device event happened
745 deviceTimestamp1 = \
746 jsonObj1[ deviceTimestamp ][ 'value' ]
747 # Get delta between graph event and OFP
748 ptDownGraphToOfp1 = int( graphTimestamp1 ) -\
749 int( timestampBeginPtDown )
750 # Get delta between device event and OFP
751 ptDownDeviceToOfp1 = int( deviceTimestamp1 ) -\
752 int( timestampBeginPtDown )
753
andrewonlabd5367a42015-01-30 14:46:17 -0500754 if ptDownGraphToOfp1 > downThresholdMin and\
755 ptDownGraphToOfp1 < downThresholdMax and i > iterIgnore:
756 portDownGraphNodeIter[0][i] = ptDownGraphToOfp1
757 main.log.info("iter"+str(i)+" port down graph-to-ofp: "+
758 str(ptDownGraphToOfp1)+" ms")
759 else:
760 main.log.info("iter"+str(i)+" skipped. Result: "+
761 str(ptDownGraphToOfp1)+" ms")
762 if ptDownDeviceToOfp1 > downThresholdMin and\
763 ptDownDeviceToOfp1 < downThresholdMax and i > iterIgnore:
764 portDownDevNodeIter[0][i] = ptDownDeviceToOfp1
765 main.log.info("iter"+str(i)+" port down device-to-ofp: "+
766 str(ptDownDeviceToOfp1)+" ms")
767 else:
768 main.log.info("iter"+str(i)+" skipped. Result: "+
769 str(ptDownDeviceToOfp1)+" ms")
770
andrewonlab79244cc2015-01-26 01:11:49 -0500771 if clusterCount >= 3:
772 jsonStrUp2 = main.ONOS2cli.topologyEventsMetrics()
773 jsonStrUp3 = main.ONOS3cli.topologyEventsMetrics()
774 jsonObj2 = json.loads( jsonStrUp2 )
775 jsonObj3 = json.loads( jsonStrUp3 )
776 graphTimestamp2 = \
777 jsonObj2[ graphTimestamp ][ 'value' ]
778 graphTimestamp3 = \
779 jsonObj3[ graphTimestamp ][ 'value' ]
780 deviceTimestamp2 = \
781 jsonObj2[ deviceTimestamp ][ 'value' ]
782 deviceTimestamp3 = \
783 jsonObj3[ deviceTimestamp ][ 'value' ]
784 ptDownGraphToOfp2 = int( graphTimestamp2 ) -\
785 int( timestampBeginPtDown )
786 ptDownGraphToOfp3 = int( graphTimestamp3 ) -\
787 int( timestampBeginPtDown )
788 ptDownDeviceToOfp2 = int( deviceTimestamp2 ) -\
789 int( timestampBeginPtDown )
790 ptDownDeviceToOfp3 = int( deviceTimestamp3 ) -\
791 int( timestampBeginPtDown )
andrewonlabd5367a42015-01-30 14:46:17 -0500792
793 if ptDownGraphToOfp2 > downThresholdMin and\
794 ptDownGraphToOfp2 < downThresholdMax and i > iterIgnore:
795 portDownGraphNodeIter[1][i] = ptDownGraphToOfp2
796 main.log.info("ONOS2 iter"+str(i)+" graph-to-ofp: "+
797 str(ptDownGraphToOfp2)+" ms")
798
799 if ptDownDeviceToOfp2 > downThresholdMin and\
800 ptDownDeviceToOfp2 < downThresholdMax and i > iterIgnore:
801 portDownDevNodeIter[1][i] = ptDownDeviceToOfp2
802 main.log.info("ONOS2 iter"+str(i)+" device-to-ofp: "+
803 str(ptDownDeviceToOfp2)+" ms")
804
805 if ptDownGraphToOfp3 > downThresholdMin and\
806 ptDownGraphToOfp3 < downThresholdMax and i > iterIgnore:
807 portDownGraphNodeIter[2][i] = ptDownGraphToOfp3
808 main.log.info("ONOS3 iter"+str(i)+" graph-to-ofp: "+
809 str(ptDownGraphToOfp3)+" ms")
810
811 if ptDownDeviceToOfp3 > downThresholdMin and\
812 ptDownDeviceToOfp3 < downThresholdMax and i > iterIgnore:
813 portDownDevNodeIter[2][i] = ptDownDeviceToOfp3
814 main.log.info("ONOS3 iter"+str(i)+" device-to-ofp: "+
815 str(ptDownDeviceToOfp3)+" ms")
andrewonlab393531a2014-10-27 18:36:26 -0400816
andrewonlab79244cc2015-01-26 01:11:49 -0500817 if clusterCount >= 5:
818 jsonStrUp4 = main.ONOS4cli.topologyEventsMetrics()
819 jsonStrUp5 = main.ONOS5cli.topologyEventsMetrics()
820 jsonObj4 = json.loads( jsonStrUp4 )
821 jsonObj5 = json.loads( jsonStrUp5 )
822 graphTimestamp4 = \
823 jsonObj4[ graphTimestamp ][ 'value' ]
824 graphTimestamp5 = \
825 jsonObj5[ graphTimestamp ][ 'value' ]
826 deviceTimestamp4 = \
827 jsonObj4[ deviceTimestamp ][ 'value' ]
828 deviceTimestamp5 = \
829 jsonObj5[ deviceTimestamp ][ 'value' ]
830 ptDownGraphToOfp4 = int( graphTimestamp4 ) -\
831 int( timestampBeginPtDown )
832 ptDownGraphToOfp5 = int( graphTimestamp5 ) -\
833 int( timestampBeginPtDown )
834 ptDownDeviceToOfp4 = int( deviceTimestamp4 ) -\
835 int( timestampBeginPtDown )
836 ptDownDeviceToOfp5 = int( deviceTimestamp5 ) -\
837 int( timestampBeginPtDown )
andrewonlabd5367a42015-01-30 14:46:17 -0500838
839 if ptDownGraphToOfp4 > downThresholdMin and\
840 ptDownGraphToOfp4 < downThresholdMax and i > iterIgnore:
841 portDownGraphNodeIter[3][i] = ptDownGraphToOfp4
842 main.log.info("ONOS4 iter"+str(i)+" graph-to-ofp: "+
843 str(ptDownGraphToOfp4)+" ms")
844
845 if ptDownDeviceToOfp4 > downThresholdMin and\
846 ptDownDeviceToOfp4 < downThresholdMax and i > iterIgnore:
847 portDownDevNodeIter[3][i] = ptDownDeviceToOfp4
848 main.log.info("ONOS4 iter"+str(i)+" device-to-ofp: "+
849 str(ptDownDeviceToOfp4)+" ms")
850
851 if ptDownGraphToOfp5 > downThresholdMin and\
852 ptDownGraphToOfp5 < downThresholdMax and i > iterIgnore:
853 portDownGraphNodeIter[4][i] = ptDownGraphToOfp5
854 main.log.info("ONOS5 iter"+str(i)+" graph-to-ofp: "+
855 str(ptDownGraphToOfp5)+" ms")
856
857 if ptDownDeviceToOfp5 > downThresholdMin and\
858 ptDownDeviceToOfp5 < downThresholdMax and i > iterIgnore:
859 portDownDevNodeIter[4][i] = ptDownDeviceToOfp5
860 main.log.info("ONOS5 iter"+str(i)+" device-to-ofp: "+
861 str(ptDownDeviceToOfp5)+" ms")
andrewonlab393531a2014-10-27 18:36:26 -0400862
andrewonlab79244cc2015-01-26 01:11:49 -0500863 if clusterCount >= 7:
864 jsonStrUp6 = main.ONOS6cli.topologyEventsMetrics()
865 jsonStrUp7 = main.ONOS7cli.topologyEventsMetrics()
866 jsonObj6 = json.loads( jsonStrUp6 )
867 jsonObj7 = json.loads( jsonStrUp7 )
868 graphTimestamp6 = \
869 jsonObj6[ graphTimestamp ][ 'value' ]
870 graphTimestamp7 = \
871 jsonObj7[ graphTimestamp ][ 'value' ]
872 deviceTimestamp6 = \
873 jsonObj6[ deviceTimestamp ][ 'value' ]
874 deviceTimestamp7 = \
875 jsonObj7[ deviceTimestamp ][ 'value' ]
876 ptDownGraphToOfp6 = int( graphTimestamp6 ) -\
877 int( timestampBeginPtDown )
878 ptDownGraphToOfp7 = int( graphTimestamp7 ) -\
879 int( timestampBeginPtDown )
880 ptDownDeviceToOfp6 = int( deviceTimestamp6 ) -\
881 int( timestampBeginPtDown )
882 ptDownDeviceToOfp7 = int( deviceTimestamp7 ) -\
883 int( timestampBeginPtDown )
andrewonlabd5367a42015-01-30 14:46:17 -0500884
885 if ptDownGraphToOfp6 > downThresholdMin and\
886 ptDownGraphToOfp6 < downThresholdMax and i > iterIgnore:
887 portDownGraphNodeIter[5][i] = ptDownGraphToOfp6
888 main.log.info("ONOS6 iter"+str(i)+" graph-to-ofp: "+
889 str(ptDownGraphToOfp6)+" ms")
890
891 if ptDownDeviceToOfp6 > downThresholdMin and\
892 ptDownDeviceToOfp6 < downThresholdMax and i > iterIgnore:
893 portDownDevNodeIter[5][i] = ptDownDeviceToOfp6
894 main.log.info("ONOS6 iter"+str(i)+" device-to-ofp: "+
895 str(ptDownDeviceToOfp6)+" ms")
896
897 if ptDownGraphToOfp7 > downThresholdMin and\
898 ptDownGraphToOfp7 < downThresholdMax and i > iterIgnore:
899 portDownGraphNodeIter[6][i] = ptDownGraphToOfp7
900 main.log.info("ONOS7 iter"+str(i)+" graph-to-ofp: "+
901 str(ptDownGraphToOfp7)+" ms")
902
903 if ptDownDeviceToOfp7 > downThresholdMin and\
904 ptDownDeviceToOfp7 < downThresholdMax and i > iterIgnore:
905 portDownDevNodeIter[6][i] = ptDownDeviceToOfp7
906 main.log.info("ONOS7 iter"+str(i)+" device-to-ofp: "+
907 str(ptDownDeviceToOfp7)+" ms")
kelvin-onlab8a832582015-01-16 17:06:11 -0800908
andrewonlab79244cc2015-01-26 01:11:49 -0500909 time.sleep( 3 )
andrewonlaba57a3042015-01-23 13:53:05 -0500910
andrewonlab79244cc2015-01-26 01:11:49 -0500911 # Port up events
912 main.step( "Enable port and obtain timestamp" )
913 main.step( "Starting wireshark capture for port status up" )
914 main.ONOS1.tsharkGrep( tsharkPortStatus, tsharkPortUp )
915 time.sleep( 5 )
andrewonlab8d29f122014-10-22 17:15:04 -0400916
andrewonlab79244cc2015-01-26 01:11:49 -0500917 main.Mininet1.handle.sendline( "sh ifconfig " +
918 interfaceConfig + " up" )
919 main.Mininet1.handle.expect( "mininet>" )
920
921 # Allow time for tshark to capture event
922 time.sleep( 5 )
923 main.ONOS1.tsharkStop()
924
925 time.sleep( 3 )
926 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
927 tsharkPortUp + " /tmp/" )
928 fPortUp = open( tsharkPortUp, 'r' )
929 fLine = fPortUp.readline()
930 objUp = fLine.split( " " )
931 if len( fLine ) > 0:
932 timestampBeginPtUp = int( float( objUp[ 1 ] ) * 1000 )
933 if timestampBeginPtUp < 1400000000000:
934 timestampBeginPtUp = \
935 int( float( objUp[ 2 ] ) * 1000 )
936 main.log.info( "Port up begin timestamp: " +
937 str( timestampBeginPtUp ) )
andrewonlab8d29f122014-10-22 17:15:04 -0400938 else:
andrewonlab79244cc2015-01-26 01:11:49 -0500939 main.log.info( "Tshark output file returned unexpected" +
940 " results." )
941 timestampBeginPtUp = 0
942 fPortUp.close()
andrewonlab393531a2014-10-27 18:36:26 -0400943
andrewonlab79244cc2015-01-26 01:11:49 -0500944 # Obtain metrics shortly afterwards
945 # This timestsamp captures
946 # the epoch time at which the topology graph was updated.
947 main.step( "Obtain t1 by REST call" )
948 jsonStrUp1 = main.ONOS1cli.topologyEventsMetrics()
949 jsonObj1 = json.loads( jsonStrUp1 )
950 graphTimestamp1 = \
951 jsonObj1[ graphTimestamp ][ 'value' ]
952 # Obtain device timestamp. This timestamp captures
953 # the epoch time at which the device event happened
954 deviceTimestamp1 = \
955 jsonObj1[ deviceTimestamp ][ 'value' ]
956 # Get delta between graph event and OFP
957 ptUpGraphToOfp1 = int( graphTimestamp1 ) -\
958 int( timestampBeginPtUp )
959 # Get delta between device event and OFP
960 ptUpDeviceToOfp1 = int( deviceTimestamp1 ) -\
961 int( timestampBeginPtUp )
andrewonlabd5367a42015-01-30 14:46:17 -0500962
963 if ptUpGraphToOfp1 > upThresholdMin and\
964 ptUpGraphToOfp1 < upThresholdMax and i > iterIgnore:
965 portUpGraphNodeIter[0][i] = ptUpGraphToOfp1
966 main.log.info("iter"+str(i)+" port up graph-to-ofp: "+
967 str(ptUpGraphToOfp1)+" ms")
968 else:
969 main.log.info("iter"+str(i)+" skipped. Result: "+
970 str(ptUpGraphToOfp1)+" ms")
971
972 if ptUpDeviceToOfp1 > upThresholdMin and\
973 ptUpDeviceToOfp1 < upThresholdMax and i > iterIgnore:
974 portUpDevNodeIter[0][i] = ptUpDeviceToOfp1
975 main.log.info("iter"+str(i)+" port up device-to-ofp: "+
976 str(ptUpDeviceToOfp1)+" ms")
977 else:
978 main.log.info("iter"+str(i)+" skipped. Result: "+
979 str(ptUpDeviceToOfp1)+" ms")
andrewonlab393531a2014-10-27 18:36:26 -0400980
andrewonlab79244cc2015-01-26 01:11:49 -0500981 if clusterCount >= 3:
982 jsonStrUp2 = main.ONOS2cli.topologyEventsMetrics()
983 jsonStrUp3 = main.ONOS3cli.topologyEventsMetrics()
984 jsonObj2 = json.loads( jsonStrUp2 )
985 jsonObj3 = json.loads( jsonStrUp3 )
986 graphTimestamp2 = \
987 jsonObj2[ graphTimestamp ][ 'value' ]
988 graphTimestamp3 = \
989 jsonObj3[ graphTimestamp ][ 'value' ]
990 deviceTimestamp2 = \
991 jsonObj2[ deviceTimestamp ][ 'value' ]
992 deviceTimestamp3 = \
993 jsonObj3[ deviceTimestamp ][ 'value' ]
994 ptUpGraphToOfp2 = int( graphTimestamp2 ) -\
995 int( timestampBeginPtUp )
996 ptUpGraphToOfp3 = int( graphTimestamp3 ) -\
997 int( timestampBeginPtUp )
998 ptUpDeviceToOfp2 = int( deviceTimestamp2 ) -\
999 int( timestampBeginPtUp )
1000 ptUpDeviceToOfp3 = int( deviceTimestamp3 ) -\
1001 int( timestampBeginPtUp )
andrewonlabd5367a42015-01-30 14:46:17 -05001002
1003 if ptUpGraphToOfp2 > upThresholdMin and\
1004 ptUpGraphToOfp2 < upThresholdMax and i > iterIgnore:
1005 portUpGraphNodeIter[1][i] = ptUpGraphToOfp2
1006 main.log.info("iter"+str(i)+" port up graph-to-ofp: "+
1007 str(ptUpGraphToOfp2)+" ms")
1008
1009 if ptUpDeviceToOfp2 > upThresholdMin and\
1010 ptUpDeviceToOfp2 < upThresholdMax and i > iterIgnore:
1011 portUpDevNodeIter[1][i] = ptUpDeviceToOfp2
1012 main.log.info("iter"+str(i)+" port up device-to-ofp: "+
1013 str(ptUpDeviceToOfp2)+" ms")
1014
1015 if ptUpGraphToOfp3 > upThresholdMin and\
1016 ptUpGraphToOfp3 < upThresholdMax and i > iterIgnore:
1017 portUpGraphNodeIter[2][i] = ptUpGraphToOfp3
1018 main.log.info("iter"+str(i)+" port up graph-to-ofp: "+
1019 str(ptUpGraphToOfp3)+" ms")
1020
1021 if ptUpDeviceToOfp3 > upThresholdMin and\
1022 ptUpDeviceToOfp3 < upThresholdMax and i > iterIgnore:
1023 portUpDevNodeIter[2][i] = ptUpDeviceToOfp3
1024 main.log.info("iter"+str(i)+" port up device-to-ofp: "+
1025 str(ptUpDeviceToOfp3)+" ms")
andrewonlabb1998c52014-11-10 13:31:43 -05001026
andrewonlab79244cc2015-01-26 01:11:49 -05001027 if clusterCount >= 5:
1028 jsonStrUp4 = main.ONOS4cli.topologyEventsMetrics()
1029 jsonStrUp5 = main.ONOS5cli.topologyEventsMetrics()
1030 jsonObj4 = json.loads( jsonStrUp4 )
1031 jsonObj5 = json.loads( jsonStrUp5 )
1032 graphTimestamp4 = \
1033 jsonObj4[ graphTimestamp ][ 'value' ]
1034 graphTimestamp5 = \
1035 jsonObj5[ graphTimestamp ][ 'value' ]
1036 deviceTimestamp4 = \
1037 jsonObj4[ deviceTimestamp ][ 'value' ]
1038 deviceTimestamp5 = \
1039 jsonObj5[ deviceTimestamp ][ 'value' ]
1040 ptUpGraphToOfp4 = int( graphTimestamp4 ) -\
1041 int( timestampBeginPtUp )
1042 ptUpGraphToOfp5 = int( graphTimestamp5 ) -\
1043 int( timestampBeginPtUp )
1044 ptUpDeviceToOfp4 = int( deviceTimestamp4 ) -\
1045 int( timestampBeginPtUp )
1046 ptUpDeviceToOfp5 = int( deviceTimestamp5 ) -\
1047 int( timestampBeginPtUp )
andrewonlabd5367a42015-01-30 14:46:17 -05001048
1049 if ptUpGraphToOfp4 > upThresholdMin and\
1050 ptUpGraphToOfp4 < upThresholdMax and i > iterIgnore:
1051 portUpGraphNodeIter[3][i] = ptUpGraphToOfp4
1052 main.log.info("iter"+str(i)+" port up graph-to-ofp: "+
1053 str(ptUpGraphToOfp4)+" ms")
1054
1055 if ptUpDeviceToOfp4 > upThresholdMin and\
1056 ptUpDeviceToOfp4 < upThresholdMax and i > iterIgnore:
1057 portUpDevNodeIter[3][i] = ptUpDeviceToOfp4
1058 main.log.info("iter"+str(i)+" port up device-to-ofp: "+
1059 str(ptUpDeviceToOfp4)+" ms")
1060
1061 if ptUpGraphToOfp5 > upThresholdMin and\
1062 ptUpGraphToOfp5 < upThresholdMax and i > iterIgnore:
1063 portUpGraphNodeIter[4][i] = ptUpGraphToOfp5
1064 main.log.info("iter"+str(i)+" port up graph-to-ofp: "+
1065 str(ptUpGraphToOfp5)+" ms")
1066
1067 if ptUpDeviceToOfp5 > upThresholdMin and\
1068 ptUpDeviceToOfp5 < upThresholdMax and i > iterIgnore:
1069 portUpDevNodeIter[4][i] = ptUpDeviceToOfp5
1070 main.log.info("iter"+str(i)+" port up device-to-ofp: "+
1071 str(ptUpDeviceToOfp5)+" ms")
andrewonlab79244cc2015-01-26 01:11:49 -05001072
1073 if clusterCount >= 7:
1074 jsonStrUp6 = main.ONOS6cli.topologyEventsMetrics()
1075 jsonStrUp7 = main.ONOS7cli.topologyEventsMetrics()
1076 jsonObj6 = json.loads( jsonStrUp6 )
1077 jsonObj7 = json.loads( jsonStrUp7 )
1078 graphTimestamp6 = \
1079 jsonObj6[ graphTimestamp ][ 'value' ]
1080 graphTimestamp7 = \
1081 jsonObj7[ graphTimestamp ][ 'value' ]
1082 deviceTimestamp6 = \
1083 jsonObj6[ deviceTimestamp ][ 'value' ]
1084 deviceTimestamp7 = \
1085 jsonObj7[ deviceTimestamp ][ 'value' ]
1086 ptUpGraphToOfp6 = int( graphTimestamp6 ) -\
1087 int( timestampBeginPtUp )
1088 ptUpGraphToOfp7 = int( graphTimestamp7 ) -\
1089 int( timestampBeginPtUp )
1090 ptUpDeviceToOfp6 = int( deviceTimestamp6 ) -\
1091 int( timestampBeginPtUp )
1092 ptUpDeviceToOfp7 = int( deviceTimestamp7 ) -\
1093 int( timestampBeginPtUp )
andrewonlabd5367a42015-01-30 14:46:17 -05001094
1095 if ptUpGraphToOfp6 > upThresholdMin and\
1096 ptUpGraphToOfp6 < upThresholdMax and i > iterIgnore:
1097 portUpGraphNodeIter[5][i] = ptUpGraphToOfp6
1098 main.log.info("iter"+str(i)+" port up graph-to-ofp: "+
1099 str(ptUpGraphToOfp6)+" ms")
1100
1101 if ptUpDeviceToOfp6 > upThresholdMin and\
1102 ptUpDeviceToOfp6 < upThresholdMax and i > iterIgnore:
1103 portUpDevNodeIter[5][i] = ptUpDeviceToOfp6
1104 main.log.info("iter"+str(i)+" port up device-to-ofp: "+
1105 str(ptUpDeviceToOfp6)+" ms")
1106
1107 if ptUpGraphToOfp7 > upThresholdMin and\
1108 ptUpGraphToOfp7 < upThresholdMax and i > iterIgnore:
1109 portUpGraphNodeIter[6][i] = ptUpGraphToOfp7
1110 main.log.info("iter"+str(i)+" port up graph-to-ofp: "+
1111 str(ptUpGraphToOfp7)+" ms")
1112
1113 if ptUpDeviceToOfp7 > upThresholdMin and\
1114 ptUpDeviceToOfp7 < upThresholdMax and i > iterIgnore:
1115 portUpDevNodeIter[6][i] = ptUpDeviceToOfp7
1116 main.log.info("iter"+str(i)+" port up device-to-ofp: "+
1117 str(ptUpDeviceToOfp7)+" ms")
andrewonlab79244cc2015-01-26 01:11:49 -05001118
1119 # END ITERATION FOR LOOP
andrewonlabd5367a42015-01-30 14:46:17 -05001120
1121 portUpDevList = []
1122 portUpGraphList = []
1123 portDownDevList = []
1124 portDownGraphList = []
andrewonlab79244cc2015-01-26 01:11:49 -05001125
andrewonlabd5367a42015-01-30 14:46:17 -05001126 portUpDevAvg = 0
1127 portUpGraphAvg = 0
1128 portDownDevAvg = 0
1129 portDownGraphAvg = 0
andrewonlab8790abb2014-11-06 13:51:54 -05001130
andrewonlabd5367a42015-01-30 14:46:17 -05001131 for node in range( 0, clusterCount ):
andrewonlababb11c32014-11-04 15:03:24 -05001132
andrewonlabd5367a42015-01-30 14:46:17 -05001133 # NOTE:
1134 # Currently the 2d array is initialized with 0's.
1135 # We want to avoid skewing our results if the array
1136 # was not modified with the correct latency.
1137 for item in portUpDevNodeIter[node]:
1138 if item > 0.0:
1139 portUpDevList.append(item)
1140 for item in portUpGraphNodeIter[node]:
1141 if item > 0.0:
1142 portUpGraphList.append(item)
1143 for item in portDownDevNodeIter[node]:
1144 if item > 0.0:
1145 portDownDevList.append(item)
1146 for item in portDownGraphNodeIter[node]:
1147 if item > 0.0:
1148 portDownGraphList.append(item)
1149
1150 portUpDevAvg = numpy.mean(portUpDevList)
1151 portUpGraphAvg = numpy.mean(portUpGraphList)
1152 portDownDevAvg = numpy.mean(portDownDevList)
1153 portDownGraphAvg = numpy.mean(portDownGraphList)
andrewonlab79244cc2015-01-26 01:11:49 -05001154
andrewonlabd5367a42015-01-30 14:46:17 -05001155 main.log.report( " - Node "+str(node+1)+" Summary - " )
1156 #main.log.report( " Port up ofp-to-device "+
1157 # str(round(portUpDevAvg, 2))+" ms")
1158 main.log.report( " Port up ofp-to-graph "+
1159 str(round(portUpGraphAvg, 2))+" ms")
1160 #main.log.report( " Port down ofp-to-device "+
1161 # str(round(portDownDevAvg, 2))+" ms")
1162 main.log.report( " Port down ofp-to-graph "+
1163 str(round(portDownGraphAvg, 2))+" ms")
andrewonlab79244cc2015-01-26 01:11:49 -05001164
1165 # Remove switches from controller for next test
1166 main.Mininet1.deleteSwController( "s1" )
1167 main.Mininet1.deleteSwController( "s2" )
1168
andrewonlabd5367a42015-01-30 14:46:17 -05001169 #TODO: correct assertion
1170
andrewonlab79244cc2015-01-26 01:11:49 -05001171 utilities.assert_equals(
1172 expect=main.TRUE,
1173 actual=assertion,
1174 onpass="Port discovery latency calculation successful",
1175 onfail="Port discovery test failed" )
1176
1177 def CASE4( self, main ):
1178 """
andrewonlab3622beb2014-10-28 16:07:56 -04001179 Link down event using loss rate 100%
andrewonlab79244cc2015-01-26 01:11:49 -05001180
andrewonlab53b641c2014-10-31 19:44:44 -04001181 Important:
1182 Use a simple 2 switch topology with 1 link between
andrewonlab79244cc2015-01-26 01:11:49 -05001183 the two switches. Ensure that mac addresses of the
andrewonlab53b641c2014-10-31 19:44:44 -04001184 switches are 1 / 2 respectively
andrewonlab79244cc2015-01-26 01:11:49 -05001185 """
andrewonlab3622beb2014-10-28 16:07:56 -04001186 import time
1187 import subprocess
1188 import os
1189 import requests
1190 import json
andrewonlab79244cc2015-01-26 01:11:49 -05001191 import numpy
andrewonlab3622beb2014-10-28 16:07:56 -04001192
andrewonlab79244cc2015-01-26 01:11:49 -05001193 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
1194 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
1195 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
1196 ONOSUser = main.params[ 'CTRL' ][ 'user' ]
andrewonlab58f7d702014-11-07 13:21:19 -05001197
andrewonlab79244cc2015-01-26 01:11:49 -05001198 defaultSwPort = main.params[ 'CTRL' ][ 'port1' ]
andrewonlab53b641c2014-10-31 19:44:44 -04001199
andrewonlab79244cc2015-01-26 01:11:49 -05001200 # Number of iterations of case
1201 numIter = main.params[ 'TEST' ][ 'numIter' ]
andrewonlabe5bcef92014-11-06 17:53:20 -05001202
andrewonlab79244cc2015-01-26 01:11:49 -05001203 # Timestamp 'keys' for json metrics output.
1204 # These are subject to change, hence moved into params
1205 deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ]
1206 linkTimestamp = main.params[ 'JSON' ][ 'linkTimestamp' ]
1207 graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ]
andrewonlabe5bcef92014-11-06 17:53:20 -05001208
andrewonlab79244cc2015-01-26 01:11:49 -05001209 debugMode = main.params[ 'TEST' ][ 'debugMode' ]
andrewonlabe5bcef92014-11-06 17:53:20 -05001210
andrewonlab79244cc2015-01-26 01:11:49 -05001211 localTime = time.strftime( '%x %X' )
1212 localTime = localTime.replace( "/", "" )
1213 localTime = localTime.replace( " ", "_" )
1214 localTime = localTime.replace( ":", "" )
1215 if debugMode == 'on':
1216 main.ONOS1.tsharkPcap( "eth0",
1217 "/tmp/link_lat_pcap_" + localTime )
1218
1219 # Threshold for this test case
1220 upThresholdStr = main.params[ 'TEST' ][ 'linkUpThreshold' ]
1221 downThresholdStr = main.params[ 'TEST' ][ 'linkDownThreshold' ]
1222
1223 upThresholdObj = upThresholdStr.split( "," )
1224 downThresholdObj = downThresholdStr.split( "," )
1225
1226 upThresholdMin = int( upThresholdObj[ 0 ] )
1227 upThresholdMax = int( upThresholdObj[ 1 ] )
1228
1229 downThresholdMin = int( downThresholdObj[ 0 ] )
1230 downThresholdMax = int( downThresholdObj[ 1 ] )
andrewonlabe5bcef92014-11-06 17:53:20 -05001231
andrewonlab3622beb2014-10-28 16:07:56 -04001232 assertion = main.TRUE
andrewonlab79244cc2015-01-26 01:11:49 -05001233 # Link event timestamp to system time list
1234 linkDownLinkToSystemList = []
1235 linkUpLinkToSystemList = []
1236 # Graph event timestamp to system time list
1237 linkDownGraphToSystemList = []
1238 linkUpGraphToSystemList = []
andrewonlab3622beb2014-10-28 16:07:56 -04001239
andrewonlab79244cc2015-01-26 01:11:49 -05001240 main.log.report( "Link up / down discovery latency between " +
1241 "two switches" )
1242 main.log.report( "Simulated by setting loss-rate 100%" )
1243 main.log.report( "'tc qdisc add dev <intfs> root netem loss 100%'" )
1244 main.log.report( "Total iterations of test: " + str( numIter ) )
andrewonlab3622beb2014-10-28 16:07:56 -04001245
andrewonlab79244cc2015-01-26 01:11:49 -05001246 main.step( "Assign all switches" )
1247 main.Mininet1.assignSwController( sw="1",
1248 ip1=ONOS1Ip, port1=defaultSwPort )
1249 main.Mininet1.assignSwController( sw="2",
1250 ip1=ONOS1Ip, port1=defaultSwPort )
andrewonlab3622beb2014-10-28 16:07:56 -04001251
andrewonlab79244cc2015-01-26 01:11:49 -05001252 main.step( "Verifying switch assignment" )
1253 resultS1 = main.Mininet1.getSwController( sw="s1" )
1254 resultS2 = main.Mininet1.getSwController( sw="s2" )
andrewonlab3622beb2014-10-28 16:07:56 -04001255
andrewonlab79244cc2015-01-26 01:11:49 -05001256 # Allow time for events to finish before taking measurements
1257 time.sleep( 10 )
1258
1259 linkDown1 = False
1260 linkDown2 = False
1261 linkDown3 = False
1262 # Start iteration of link event test
1263 for i in range( 0, int( numIter ) ):
1264 main.step( "Getting initial system time as t0" )
1265
1266 # System time in epoch ms
1267 timestampLinkDownT0 = time.time() * 1000
1268 # Link down is simulated by 100% loss rate using traffic
1269 # control command
kelvin-onlab8a832582015-01-16 17:06:11 -08001270 main.Mininet1.handle.sendline(
andrewonlab79244cc2015-01-26 01:11:49 -05001271 "sh tc qdisc add dev s1-eth1 root netem loss 100%" )
kelvin-onlab8a832582015-01-16 17:06:11 -08001272
andrewonlab79244cc2015-01-26 01:11:49 -05001273 # TODO: Iterate through 'links' command to verify that
1274 # link s1 -> s2 went down ( loop timeout 30 seconds )
andrewonlababb11c32014-11-04 15:03:24 -05001275 # on all 3 ONOS instances
andrewonlab79244cc2015-01-26 01:11:49 -05001276 main.log.info( "Checking ONOS for link update" )
1277 loopCount = 0
1278 while( not ( linkDown1 and linkDown2 and linkDown3 )
1279 and loopCount < 30 ):
1280 jsonStr1 = main.ONOS1cli.links()
1281 jsonStr2 = main.ONOS2cli.links()
1282 jsonStr3 = main.ONOS3cli.links()
1283
1284 if not ( jsonStr1 and jsonStr2 and jsonStr3 ):
1285 main.log.error( "CLI command returned error " )
andrewonlab53b641c2014-10-31 19:44:44 -04001286 break
1287 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001288 jsonObj1 = json.loads( jsonStr1 )
1289 jsonObj2 = json.loads( jsonStr2 )
1290 jsonObj3 = json.loads( jsonStr3 )
1291 for obj1 in jsonObj1:
1292 if '01' not in obj1[ 'src' ][ 'device' ]:
1293 linkDown1 = True
1294 main.log.info( "Link down from " +
1295 "s1 -> s2 on ONOS1 detected" )
1296 for obj2 in jsonObj2:
1297 if '01' not in obj2[ 'src' ][ 'device' ]:
1298 linkDown2 = True
1299 main.log.info( "Link down from " +
1300 "s1 -> s2 on ONOS2 detected" )
1301 for obj3 in jsonObj3:
1302 if '01' not in obj3[ 'src' ][ 'device' ]:
1303 linkDown3 = True
1304 main.log.info( "Link down from " +
1305 "s1 -> s2 on ONOS3 detected" )
1306
1307 loopCount += 1
1308 # If CLI doesn't like the continuous requests
1309 # and exits in this loop, increase the sleep here.
1310 # Consequently, while loop timeout will increase
1311 time.sleep( 1 )
1312
1313 # Give time for metrics measurement to catch up
1314 # NOTE: May need to be configured more accurately
1315 time.sleep( 10 )
1316 # If we exited the while loop and link down 1,2,3 are still
1317 # false, then ONOS has failed to discover link down event
1318 if not ( linkDown1 and linkDown2 and linkDown3 ):
1319 main.log.info( "Link down discovery failed" )
1320
1321 linkDownLatGraph1 = 0
1322 linkDownLatGraph2 = 0
1323 linkDownLatGraph3 = 0
1324 linkDownLatDevice1 = 0
1325 linkDownLatDevice2 = 0
1326 linkDownLatDevice3 = 0
1327
andrewonlab53b641c2014-10-31 19:44:44 -04001328 assertion = main.FALSE
1329 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001330 jsonTopoMetrics1 =\
1331 main.ONOS1cli.topologyEventsMetrics()
1332 jsonTopoMetrics2 =\
1333 main.ONOS2cli.topologyEventsMetrics()
1334 jsonTopoMetrics3 =\
1335 main.ONOS3cli.topologyEventsMetrics()
1336 jsonTopoMetrics1 = json.loads( jsonTopoMetrics1 )
1337 jsonTopoMetrics2 = json.loads( jsonTopoMetrics2 )
1338 jsonTopoMetrics3 = json.loads( jsonTopoMetrics3 )
andrewonlab53b641c2014-10-31 19:44:44 -04001339
andrewonlab79244cc2015-01-26 01:11:49 -05001340 main.log.info( "Obtaining graph and device timestamp" )
1341 graphTimestamp1 = \
1342 jsonTopoMetrics1[ graphTimestamp ][ 'value' ]
1343 graphTimestamp2 = \
1344 jsonTopoMetrics2[ graphTimestamp ][ 'value' ]
1345 graphTimestamp3 = \
1346 jsonTopoMetrics3[ graphTimestamp ][ 'value' ]
andrewonlab53b641c2014-10-31 19:44:44 -04001347
andrewonlab79244cc2015-01-26 01:11:49 -05001348 linkTimestamp1 = \
1349 jsonTopoMetrics1[ linkTimestamp ][ 'value' ]
1350 linkTimestamp2 = \
1351 jsonTopoMetrics2[ linkTimestamp ][ 'value' ]
1352 linkTimestamp3 = \
1353 jsonTopoMetrics3[ linkTimestamp ][ 'value' ]
andrewonlab53b641c2014-10-31 19:44:44 -04001354
andrewonlab79244cc2015-01-26 01:11:49 -05001355 if graphTimestamp1 and graphTimestamp2 and\
1356 graphTimestamp3 and linkTimestamp1 and\
1357 linkTimestamp2 and linkTimestamp3:
1358 linkDownLatGraph1 = int( graphTimestamp1 ) -\
1359 int( timestampLinkDownT0 )
1360 linkDownLatGraph2 = int( graphTimestamp2 ) -\
1361 int( timestampLinkDownT0 )
1362 linkDownLatGraph3 = int( graphTimestamp3 ) -\
1363 int( timestampLinkDownT0 )
1364
1365 linkDownLatLink1 = int( linkTimestamp1 ) -\
1366 int( timestampLinkDownT0 )
1367 linkDownLatLink2 = int( linkTimestamp2 ) -\
1368 int( timestampLinkDownT0 )
1369 linkDownLatLink3 = int( linkTimestamp3 ) -\
1370 int( timestampLinkDownT0 )
andrewonlab53b641c2014-10-31 19:44:44 -04001371 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001372 main.log.error( "There was an error calculating" +
1373 " the delta for link down event" )
1374 linkDownLatGraph1 = 0
1375 linkDownLatGraph2 = 0
1376 linkDownLatGraph3 = 0
kelvin-onlab8a832582015-01-16 17:06:11 -08001377
andrewonlab79244cc2015-01-26 01:11:49 -05001378 linkDownLatDevice1 = 0
1379 linkDownLatDevice2 = 0
1380 linkDownLatDevice3 = 0
andrewonlab53b641c2014-10-31 19:44:44 -04001381
andrewonlab79244cc2015-01-26 01:11:49 -05001382 main.log.info( "Link down latency ONOS1 iteration " +
1383 str( i ) + " (end-to-end): " +
1384 str( linkDownLatGraph1 ) + " ms" )
1385 main.log.info( "Link down latency ONOS2 iteration " +
1386 str( i ) + " (end-to-end): " +
1387 str( linkDownLatGraph2 ) + " ms" )
1388 main.log.info( "Link down latency ONOS3 iteration " +
1389 str( i ) + " (end-to-end): " +
1390 str( linkDownLatGraph3 ) + " ms" )
1391
1392 main.log.info( "Link down latency ONOS1 iteration " +
1393 str( i ) + " (link-event-to-system-timestamp): " +
1394 str( linkDownLatLink1 ) + " ms" )
1395 main.log.info( "Link down latency ONOS2 iteration " +
1396 str( i ) + " (link-event-to-system-timestamp): " +
1397 str( linkDownLatLink2 ) + " ms" )
1398 main.log.info( "Link down latency ONOS3 iteration " +
1399 str( i ) + " (link-event-to-system-timestamp): " +
1400 str( linkDownLatLink3 ) )
1401
1402 # Calculate avg of node calculations
1403 linkDownLatGraphAvg =\
1404 ( linkDownLatGraph1 +
1405 linkDownLatGraph2 +
1406 linkDownLatGraph3 ) / 3
1407 linkDownLatLinkAvg =\
1408 ( linkDownLatLink1 +
1409 linkDownLatLink2 +
1410 linkDownLatLink3 ) / 3
1411
1412 # Set threshold and append latency to list
1413 if linkDownLatGraphAvg > downThresholdMin and\
1414 linkDownLatGraphAvg < downThresholdMax:
1415 linkDownGraphToSystemList.append(
1416 linkDownLatGraphAvg )
1417 else:
1418 main.log.info( "Link down latency exceeded threshold" )
1419 main.log.info( "Results for iteration " + str( i ) +
1420 "have been omitted" )
1421 if linkDownLatLinkAvg > downThresholdMin and\
1422 linkDownLatLinkAvg < downThresholdMax:
1423 linkDownLinkToSystemList.append(
1424 linkDownLatLinkAvg )
1425 else:
1426 main.log.info( "Link down latency exceeded threshold" )
1427 main.log.info( "Results for iteration " + str( i ) +
1428 "have been omitted" )
1429
1430 # NOTE: To remove loss rate and measure latency:
andrewonlab53b641c2014-10-31 19:44:44 -04001431 # 'sh tc qdisc del dev s1-eth1 root'
andrewonlab79244cc2015-01-26 01:11:49 -05001432 timestampLinkUpT0 = time.time() * 1000
1433 main.Mininet1.handle.sendline( "sh tc qdisc del dev " +
1434 "s1-eth1 root" )
1435 main.Mininet1.handle.expect( "mininet>" )
1436
1437 main.log.info( "Checking ONOS for link update" )
1438
1439 linkDown1 = True
1440 linkDown2 = True
1441 linkDown3 = True
1442 loopCount = 0
1443 while( ( linkDown1 and linkDown2 and linkDown3 )
1444 and loopCount < 30 ):
1445 jsonStr1 = main.ONOS1cli.links()
1446 jsonStr2 = main.ONOS2cli.links()
1447 jsonStr3 = main.ONOS3cli.links()
1448 if not ( jsonStr1 and jsonStr2 and jsonStr3 ):
1449 main.log.error( "CLI command returned error " )
andrewonlababb11c32014-11-04 15:03:24 -05001450 break
1451 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001452 jsonObj1 = json.loads( jsonStr1 )
1453 jsonObj2 = json.loads( jsonStr2 )
1454 jsonObj3 = json.loads( jsonStr3 )
1455
1456 for obj1 in jsonObj1:
1457 if '01' in obj1[ 'src' ][ 'device' ]:
1458 linkDown1 = False
1459 main.log.info( "Link up from " +
1460 "s1 -> s2 on ONOS1 detected" )
1461 for obj2 in jsonObj2:
1462 if '01' in obj2[ 'src' ][ 'device' ]:
1463 linkDown2 = False
1464 main.log.info( "Link up from " +
1465 "s1 -> s2 on ONOS2 detected" )
1466 for obj3 in jsonObj3:
1467 if '01' in obj3[ 'src' ][ 'device' ]:
1468 linkDown3 = False
1469 main.log.info( "Link up from " +
1470 "s1 -> s2 on ONOS3 detected" )
1471
1472 loopCount += 1
1473 time.sleep( 1 )
1474
1475 if ( linkDown1 and linkDown2 and linkDown3 ):
1476 main.log.info( "Link up discovery failed" )
1477
1478 linkUpLatGraph1 = 0
1479 linkUpLatGraph2 = 0
1480 linkUpLatGraph3 = 0
1481 linkUpLatDevice1 = 0
1482 linkUpLatDevice2 = 0
1483 linkUpLatDevice3 = 0
1484
andrewonlababb11c32014-11-04 15:03:24 -05001485 assertion = main.FALSE
1486 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001487 jsonTopoMetrics1 =\
1488 main.ONOS1cli.topologyEventsMetrics()
1489 jsonTopoMetrics2 =\
1490 main.ONOS2cli.topologyEventsMetrics()
1491 jsonTopoMetrics3 =\
1492 main.ONOS3cli.topologyEventsMetrics()
1493 jsonTopoMetrics1 = json.loads( jsonTopoMetrics1 )
1494 jsonTopoMetrics2 = json.loads( jsonTopoMetrics2 )
1495 jsonTopoMetrics3 = json.loads( jsonTopoMetrics3 )
andrewonlababb11c32014-11-04 15:03:24 -05001496
andrewonlab79244cc2015-01-26 01:11:49 -05001497 main.log.info( "Obtaining graph and device timestamp" )
1498 graphTimestamp1 = \
1499 jsonTopoMetrics1[ graphTimestamp ][ 'value' ]
1500 graphTimestamp2 = \
1501 jsonTopoMetrics2[ graphTimestamp ][ 'value' ]
1502 graphTimestamp3 = \
1503 jsonTopoMetrics3[ graphTimestamp ][ 'value' ]
andrewonlababb11c32014-11-04 15:03:24 -05001504
andrewonlab79244cc2015-01-26 01:11:49 -05001505 linkTimestamp1 = \
1506 jsonTopoMetrics1[ linkTimestamp ][ 'value' ]
1507 linkTimestamp2 = \
1508 jsonTopoMetrics2[ linkTimestamp ][ 'value' ]
1509 linkTimestamp3 = \
1510 jsonTopoMetrics3[ linkTimestamp ][ 'value' ]
andrewonlababb11c32014-11-04 15:03:24 -05001511
andrewonlab79244cc2015-01-26 01:11:49 -05001512 if graphTimestamp1 and graphTimestamp2 and\
1513 graphTimestamp3 and linkTimestamp1 and\
1514 linkTimestamp2 and linkTimestamp3:
1515 linkUpLatGraph1 = int( graphTimestamp1 ) -\
1516 int( timestampLinkUpT0 )
1517 linkUpLatGraph2 = int( graphTimestamp2 ) -\
1518 int( timestampLinkUpT0 )
1519 linkUpLatGraph3 = int( graphTimestamp3 ) -\
1520 int( timestampLinkUpT0 )
1521
1522 linkUpLatLink1 = int( linkTimestamp1 ) -\
1523 int( timestampLinkUpT0 )
1524 linkUpLatLink2 = int( linkTimestamp2 ) -\
1525 int( timestampLinkUpT0 )
1526 linkUpLatLink3 = int( linkTimestamp3 ) -\
1527 int( timestampLinkUpT0 )
andrewonlababb11c32014-11-04 15:03:24 -05001528 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001529 main.log.error( "There was an error calculating" +
1530 " the delta for link down event" )
1531 linkUpLatGraph1 = 0
1532 linkUpLatGraph2 = 0
1533 linkUpLatGraph3 = 0
kelvin-onlab8a832582015-01-16 17:06:11 -08001534
andrewonlab79244cc2015-01-26 01:11:49 -05001535 linkUpLatDevice1 = 0
1536 linkUpLatDevice2 = 0
1537 linkUpLatDevice3 = 0
1538
1539 if debugMode == 'on':
1540 main.log.info( "Link up latency ONOS1 iteration " +
1541 str( i ) + " (end-to-end): " +
1542 str( linkUpLatGraph1 ) + " ms" )
1543 main.log.info( "Link up latency ONOS2 iteration " +
1544 str( i ) + " (end-to-end): " +
1545 str( linkUpLatGraph2 ) + " ms" )
1546 main.log.info( "Link up latency ONOS3 iteration " +
1547 str( i ) + " (end-to-end): " +
1548 str( linkUpLatGraph3 ) + " ms" )
1549
1550 main.log.info(
1551 "Link up latency ONOS1 iteration " +
1552 str( i ) +
1553 " (link-event-to-system-timestamp): " +
1554 str( linkUpLatLink1 ) +
1555 " ms" )
1556 main.log.info(
1557 "Link up latency ONOS2 iteration " +
1558 str( i ) +
1559 " (link-event-to-system-timestamp): " +
1560 str( linkUpLatLink2 ) +
1561 " ms" )
1562 main.log.info(
1563 "Link up latency ONOS3 iteration " +
1564 str( i ) +
1565 " (link-event-to-system-timestamp): " +
1566 str( linkUpLatLink3 ) )
1567
1568 # Calculate avg of node calculations
1569 linkUpLatGraphAvg =\
1570 ( linkUpLatGraph1 +
1571 linkUpLatGraph2 +
1572 linkUpLatGraph3 ) / 3
1573 linkUpLatLinkAvg =\
1574 ( linkUpLatLink1 +
1575 linkUpLatLink2 +
1576 linkUpLatLink3 ) / 3
1577
1578 # Set threshold and append latency to list
1579 if linkUpLatGraphAvg > upThresholdMin and\
1580 linkUpLatGraphAvg < upThresholdMax:
1581 linkUpGraphToSystemList.append(
1582 linkUpLatGraphAvg )
andrewonlab8790abb2014-11-06 13:51:54 -05001583 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001584 main.log.info( "Link up latency exceeded threshold" )
1585 main.log.info( "Results for iteration " + str( i ) +
1586 "have been omitted" )
1587 if linkUpLatLinkAvg > upThresholdMin and\
1588 linkUpLatLinkAvg < upThresholdMax:
1589 linkUpLinkToSystemList.append(
1590 linkUpLatLinkAvg )
andrewonlab8790abb2014-11-06 13:51:54 -05001591 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001592 main.log.info( "Link up latency exceeded threshold" )
1593 main.log.info( "Results for iteration " + str( i ) +
1594 "have been omitted" )
andrewonlab53b641c2014-10-31 19:44:44 -04001595
andrewonlab79244cc2015-01-26 01:11:49 -05001596 # Calculate min, max, avg of list and report
1597 linkDownMin = min( linkDownGraphToSystemList )
1598 linkDownMax = max( linkDownGraphToSystemList )
1599 linkDownAvg = sum( linkDownGraphToSystemList ) / \
1600 len( linkDownGraphToSystemList )
1601 linkUpMin = min( linkUpGraphToSystemList )
1602 linkUpMax = max( linkUpGraphToSystemList )
1603 linkUpAvg = sum( linkUpGraphToSystemList ) / \
1604 len( linkUpGraphToSystemList )
1605 linkDownStdDev = \
1606 str( round( numpy.std( linkDownGraphToSystemList ), 1 ) )
1607 linkUpStdDev = \
1608 str( round( numpy.std( linkUpGraphToSystemList ), 1 ) )
andrewonlababb11c32014-11-04 15:03:24 -05001609
andrewonlab79244cc2015-01-26 01:11:49 -05001610 main.log.report( "Link down latency " +
1611 "Avg: " + str( linkDownAvg ) + " ms " +
1612 "Std Deviation: " + linkDownStdDev + " ms" )
1613 main.log.report( "Link up latency " +
1614 "Avg: " + str( linkUpAvg ) + " ms " +
1615 "Std Deviation: " + linkUpStdDev + " ms" )
andrewonlab4e124482014-11-04 13:37:25 -05001616
andrewonlab79244cc2015-01-26 01:11:49 -05001617 utilities.assert_equals(
1618 expect=main.TRUE,
1619 actual=assertion,
1620 onpass="Link discovery latency calculation successful",
1621 onfail="Link discovery latency case failed" )
andrewonlab8790abb2014-11-06 13:51:54 -05001622
andrewonlab79244cc2015-01-26 01:11:49 -05001623 def CASE5( self, main ):
1624 """
andrewonlabb54b85b2014-10-28 18:43:57 -04001625 100 Switch discovery latency
1626
1627 Important:
andrewonlab79244cc2015-01-26 01:11:49 -05001628 This test case can be potentially dangerous if
andrewonlab16ce4852014-10-30 13:41:09 -04001629 your machine has previously set iptables rules.
1630 One of the steps of the test case will flush
1631 all existing iptables rules.
andrewonlab8790abb2014-11-06 13:51:54 -05001632 Note:
andrewonlab79244cc2015-01-26 01:11:49 -05001633 You can specify the number of switches in the
andrewonlab8790abb2014-11-06 13:51:54 -05001634 params file to adjust the switch discovery size
andrewonlab79244cc2015-01-26 01:11:49 -05001635 ( and specify the corresponding topology in Mininet1
1636 .topo file )
1637 """
andrewonlabb54b85b2014-10-28 18:43:57 -04001638 import time
1639 import subprocess
1640 import os
1641 import requests
1642 import json
1643
andrewonlab79244cc2015-01-26 01:11:49 -05001644 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
1645 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
1646 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
1647 MN1Ip = main.params[ 'MN' ][ 'ip1' ]
1648 ONOSUser = main.params[ 'CTRL' ][ 'user' ]
andrewonlabb54b85b2014-10-28 18:43:57 -04001649
andrewonlab79244cc2015-01-26 01:11:49 -05001650 defaultSwPort = main.params[ 'CTRL' ][ 'port1' ]
andrewonlab16ce4852014-10-30 13:41:09 -04001651
andrewonlab79244cc2015-01-26 01:11:49 -05001652 # Number of iterations of case
1653 numIter = main.params[ 'TEST' ][ 'numIter' ]
1654 numSw = main.params[ 'TEST' ][ 'numSwitch' ]
andrewonlab58f7d702014-11-07 13:21:19 -05001655
andrewonlab79244cc2015-01-26 01:11:49 -05001656 # Timestamp 'keys' for json metrics output.
1657 # These are subject to change, hence moved into params
1658 deviceTimestamp = main.params[ 'JSON' ][ 'deviceTimestamp' ]
1659 graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ]
andrewonlabe5bcef92014-11-06 17:53:20 -05001660
andrewonlab79244cc2015-01-26 01:11:49 -05001661 debugMode = main.params[ 'TEST' ][ 'debugMode' ]
andrewonlab53b641c2014-10-31 19:44:44 -04001662
andrewonlab79244cc2015-01-26 01:11:49 -05001663 localTime = time.strftime( '%X' )
1664 localTime = localTime.replace( "/", "" )
1665 localTime = localTime.replace( " ", "_" )
1666 localTime = localTime.replace( ":", "" )
1667 if debugMode == 'on':
1668 main.ONOS1.tsharkPcap( "eth0",
1669 "/tmp/100_sw_lat_pcap_" + localTime )
andrewonlabb54b85b2014-10-28 18:43:57 -04001670
andrewonlab79244cc2015-01-26 01:11:49 -05001671 # Threshold for this test case
1672 swDiscThresholdStr = main.params[ 'TEST' ][ 'swDisc100Threshold' ]
1673 swDiscThresholdObj = swDiscThresholdStr.split( "," )
1674 swDiscThresholdMin = int( swDiscThresholdObj[ 0 ] )
1675 swDiscThresholdMax = int( swDiscThresholdObj[ 1 ] )
andrewonlabe5bcef92014-11-06 17:53:20 -05001676
andrewonlab79244cc2015-01-26 01:11:49 -05001677 tsharkOfpOutput = "/tmp/tshark_ofp_" + numSw + "sw.txt"
1678 tsharkTcpOutput = "/tmp/tshark_tcp_" + numSw + "sw.txt"
andrewonlabb54b85b2014-10-28 18:43:57 -04001679
andrewonlab79244cc2015-01-26 01:11:49 -05001680 tsharkOfpResultList = []
1681 tsharkTcpResultList = []
1682
1683 swDiscoveryLatList = []
1684
1685 main.case( numSw + " Switch discovery latency" )
1686 main.step( "Assigning all switches to ONOS1" )
1687 for i in range( 1, int( numSw ) + 1 ):
1688 main.Mininet1.assignSwController(
1689 sw=str( i ),
1690 ip1=ONOS1Ip,
1691 port1=defaultSwPort )
1692
1693 # Ensure that nodes are configured with ptpd
1694 # Just a warning message
1695 main.log.info( "Please check ptpd configuration to ensure" +
1696 " All nodes' system times are in sync" )
1697 time.sleep( 5 )
1698
1699 for i in range( 0, int( numIter ) ):
1700
1701 main.step( "Set iptables rule to block incoming sw connections" )
1702 # Set iptables rule to block incoming switch connections
1703 # The rule description is as follows:
andrewonlab53b641c2014-10-31 19:44:44 -04001704 # Append to INPUT rule,
1705 # behavior DROP that matches following:
1706 # * packet type: tcp
andrewonlab79244cc2015-01-26 01:11:49 -05001707 # * source IP: MN1Ip
andrewonlab53b641c2014-10-31 19:44:44 -04001708 # * destination PORT: 6633
andrewonlabb54b85b2014-10-28 18:43:57 -04001709 main.ONOS1.handle.sendline(
andrewonlab79244cc2015-01-26 01:11:49 -05001710 "sudo iptables -A INPUT -p tcp -s " + MN1Ip +
1711 " --dport " + defaultSwPort + " -j DROP" )
1712 main.ONOS1.handle.expect( "\$" )
1713 # Append to OUTPUT rule,
andrewonlab53b641c2014-10-31 19:44:44 -04001714 # behavior DROP that matches following:
1715 # * packet type: tcp
andrewonlab79244cc2015-01-26 01:11:49 -05001716 # * source IP: MN1Ip
andrewonlab53b641c2014-10-31 19:44:44 -04001717 # * destination PORT: 6633
1718 main.ONOS1.handle.sendline(
andrewonlab79244cc2015-01-26 01:11:49 -05001719 "sudo iptables -A OUTPUT -p tcp -s " + MN1Ip +
1720 " --dport " + defaultSwPort + " -j DROP" )
1721 main.ONOS1.handle.expect( "\$" )
1722 # Give time to allow rule to take effect
1723 # NOTE: Sleep period may need to be configured
andrewonlab8790abb2014-11-06 13:51:54 -05001724 # based on the number of switches in the topology
andrewonlab79244cc2015-01-26 01:11:49 -05001725 main.log.info( "Please wait for switch connection to " +
1726 "time out" )
1727 time.sleep( 60 )
andrewonlabb54b85b2014-10-28 18:43:57 -04001728
andrewonlab79244cc2015-01-26 01:11:49 -05001729 # Gather vendor OFP with tshark
1730 main.ONOS1.tsharkGrep( "OFP 86 Vendor",
1731 tsharkOfpOutput )
1732 main.ONOS1.tsharkGrep( "TCP 74 ",
1733 tsharkTcpOutput )
1734
1735 # NOTE: Remove all iptables rule quickly ( flush )
1736 # Before removal, obtain TestON timestamp at which
andrewonlab16ce4852014-10-30 13:41:09 -04001737 # removal took place
andrewonlab79244cc2015-01-26 01:11:49 -05001738 # ( ensuring nodes are configured via ptp )
andrewonlabb54b85b2014-10-28 18:43:57 -04001739 # sudo iptables -F
andrewonlab79244cc2015-01-26 01:11:49 -05001740
1741 t0System = time.time() * 1000
andrewonlab16ce4852014-10-30 13:41:09 -04001742 main.ONOS1.handle.sendline(
andrewonlab79244cc2015-01-26 01:11:49 -05001743 "sudo iptables -F" )
andrewonlabb54b85b2014-10-28 18:43:57 -04001744
andrewonlab79244cc2015-01-26 01:11:49 -05001745 # Counter to track loop count
1746 counterLoop = 0
1747 counterAvail1 = 0
1748 counterAvail2 = 0
1749 counterAvail3 = 0
1750 onos1Dev = False
1751 onos2Dev = False
1752 onos3Dev = False
1753 while counterLoop < 60:
1754 # Continue to check devices for all device
1755 # availability. When all devices in all 3
1756 # ONOS instances indicate that devices are available
1757 # obtain graph event timestamp for t1.
1758 deviceStrObj1 = main.ONOS1cli.devices()
1759 deviceStrObj2 = main.ONOS2cli.devices()
1760 deviceStrObj3 = main.ONOS3cli.devices()
andrewonlab16ce4852014-10-30 13:41:09 -04001761
andrewonlab79244cc2015-01-26 01:11:49 -05001762 deviceJson1 = json.loads( deviceStrObj1 )
1763 deviceJson2 = json.loads( deviceStrObj2 )
1764 deviceJson3 = json.loads( deviceStrObj3 )
1765
1766 for device1 in deviceJson1:
1767 if device1[ 'available' ]:
1768 counterAvail1 += 1
1769 if counterAvail1 == int( numSw ):
1770 onos1Dev = True
1771 main.log.info( "All devices have been " +
1772 "discovered on ONOS1" )
andrewonlab16ce4852014-10-30 13:41:09 -04001773 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001774 counterAvail1 = 0
1775 for device2 in deviceJson2:
1776 if device2[ 'available' ]:
1777 counterAvail2 += 1
1778 if counterAvail2 == int( numSw ):
1779 onos2Dev = True
1780 main.log.info( "All devices have been " +
1781 "discovered on ONOS2" )
andrewonlab16ce4852014-10-30 13:41:09 -04001782 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001783 counterAvail2 = 0
1784 for device3 in deviceJson3:
1785 if device3[ 'available' ]:
1786 counterAvail3 += 1
1787 if counterAvail3 == int( numSw ):
1788 onos3Dev = True
1789 main.log.info( "All devices have been " +
1790 "discovered on ONOS3" )
andrewonlab16ce4852014-10-30 13:41:09 -04001791 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001792 counterAvail3 = 0
andrewonlab16ce4852014-10-30 13:41:09 -04001793
andrewonlab79244cc2015-01-26 01:11:49 -05001794 if onos1Dev and onos2Dev and onos3Dev:
1795 main.log.info( "All devices have been discovered " +
1796 "on all ONOS instances" )
1797 jsonStrTopologyMetrics1 =\
1798 main.ONOS1cli.topologyEventsMetrics()
1799 jsonStrTopologyMetrics2 =\
1800 main.ONOS2cli.topologyEventsMetrics()
1801 jsonStrTopologyMetrics3 =\
1802 main.ONOS3cli.topologyEventsMetrics()
andrewonlab16ce4852014-10-30 13:41:09 -04001803
andrewonlab79244cc2015-01-26 01:11:49 -05001804 # Exit while loop if all devices discovered
1805 break
andrewonlab16ce4852014-10-30 13:41:09 -04001806
andrewonlab79244cc2015-01-26 01:11:49 -05001807 counterLoop += 1
1808 # Give some time in between CLI calls
1809 #( will not affect measurement )
1810 time.sleep( 3 )
andrewonlab16ce4852014-10-30 13:41:09 -04001811
andrewonlab79244cc2015-01-26 01:11:49 -05001812 main.ONOS1.tsharkStop()
andrewonlab53b641c2014-10-31 19:44:44 -04001813
andrewonlab79244cc2015-01-26 01:11:49 -05001814 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
1815 tsharkOfpOutput + " /tmp/" )
1816 os.system( "scp " + ONOSUser + "@" + ONOS1Ip + ":" +
1817 tsharkTcpOutput + " /tmp/" )
andrewonlab16ce4852014-10-30 13:41:09 -04001818
andrewonlab79244cc2015-01-26 01:11:49 -05001819 # TODO: Automate OFP output analysis
1820 # Debug mode - print out packets captured at runtime
1821 if debugMode == 'on':
1822 ofpFile = open( tsharkOfpOutput, 'r' )
1823 main.log.info( "Tshark OFP Vendor output: " )
1824 for line in ofpFile:
1825 tsharkOfpResultList.append( line )
1826 main.log.info( line )
1827 ofpFile.close()
andrewonlab16ce4852014-10-30 13:41:09 -04001828
andrewonlab79244cc2015-01-26 01:11:49 -05001829 tcpFile = open( tsharkTcpOutput, 'r' )
1830 main.log.info( "Tshark TCP 74 output: " )
1831 for line in tcpFile:
1832 tsharkTcpResultList.append( line )
1833 main.log.info( line )
1834 tcpFile.close()
andrewonlab16ce4852014-10-30 13:41:09 -04001835
andrewonlab79244cc2015-01-26 01:11:49 -05001836 jsonObj1 = json.loads( jsonStrTopologyMetrics1 )
1837 jsonObj2 = json.loads( jsonStrTopologyMetrics2 )
1838 jsonObj3 = json.loads( jsonStrTopologyMetrics3 )
1839
1840 graphTimestamp1 = \
1841 jsonObj1[ graphTimestamp ][ 'value' ]
1842 graphTimestamp2 = \
1843 jsonObj2[ graphTimestamp ][ 'value' ]
1844 graphTimestamp3 = \
1845 jsonObj3[ graphTimestamp ][ 'value' ]
1846
1847 graphLat1 = int( graphTimestamp1 ) - int( t0System )
1848 graphLat2 = int( graphTimestamp2 ) - int( t0System )
1849 graphLat3 = int( graphTimestamp3 ) - int( t0System )
1850
1851 avgGraphLat = \
1852 ( int( graphLat1 ) +
1853 int( graphLat2 ) +
1854 int( graphLat3 ) ) / 3
1855
1856 if avgGraphLat > swDiscThresholdMin \
1857 and avgGraphLat < swDiscThresholdMax:
1858 swDiscoveryLatList.append(
1859 avgGraphLat )
andrewonlabe5bcef92014-11-06 17:53:20 -05001860 else:
andrewonlab79244cc2015-01-26 01:11:49 -05001861 main.log.info( "100 Switch discovery latency " +
1862 "exceeded the threshold." )
andrewonlab16ce4852014-10-30 13:41:09 -04001863
andrewonlab79244cc2015-01-26 01:11:49 -05001864 # END ITERATION FOR LOOP
andrewonlab16ce4852014-10-30 13:41:09 -04001865
andrewonlab79244cc2015-01-26 01:11:49 -05001866 swLatMin = min( swDiscoveryLatList )
1867 swLatMax = max( swDiscoveryLatList )
1868 swLatAvg = sum( swDiscoveryLatList ) /\
1869 len( swDiscoveryLatList )
andrewonlab16ce4852014-10-30 13:41:09 -04001870
andrewonlab79244cc2015-01-26 01:11:49 -05001871 main.log.report( "100 Switch discovery lat " +
1872 "Min: " + str( swLatMin ) + " ms" +
1873 "Max: " + str( swLatMax ) + " ms" +
1874 "Avg: " + str( swLatAvg ) + " ms" )
1875
1876 def CASE6( self, main ):
1877 """
andrewonlaba57a3042015-01-23 13:53:05 -05001878 Increase number of nodes and initiate CLI
andrewonlab79244cc2015-01-26 01:11:49 -05001879 """
andrewonlaba57a3042015-01-23 13:53:05 -05001880 import time
andrewonlaba57a3042015-01-23 13:53:05 -05001881
andrewonlab79244cc2015-01-26 01:11:49 -05001882 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
1883 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
1884 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
1885 ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
1886 ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
1887 ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
1888 ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
andrewonlaba57a3042015-01-23 13:53:05 -05001889
andrewonlab79244cc2015-01-26 01:11:49 -05001890 cellName = main.params[ 'ENV' ][ 'cellName' ]
andrewonlaba57a3042015-01-23 13:53:05 -05001891
andrewonlab79244cc2015-01-26 01:11:49 -05001892 global clusterCount
andrewonlaba57a3042015-01-23 13:53:05 -05001893
andrewonlab79244cc2015-01-26 01:11:49 -05001894 # Cluster size increased everytime the case is defined
1895 clusterCount += 2
andrewonlaba57a3042015-01-23 13:53:05 -05001896
andrewonlab79244cc2015-01-26 01:11:49 -05001897 main.log.report( "Increasing cluster size to " +
1898 str( clusterCount ) )
andrewonlaba57a3042015-01-23 13:53:05 -05001899
andrewonlab79244cc2015-01-26 01:11:49 -05001900 installResult = main.FALSE
1901 if clusterCount == 3:
1902 main.log.info( "Installing nodes 2 and 3" )
1903 node2Result = \
1904 main.ONOSbench.onosInstall( node=ONOS2Ip )
1905 node3Result = \
1906 main.ONOSbench.onosInstall( node=ONOS3Ip )
1907 installResult = node2Result and node3Result
andrewonlaba57a3042015-01-23 13:53:05 -05001908
andrewonlab79244cc2015-01-26 01:11:49 -05001909 time.sleep( 5 )
andrewonlaba57a3042015-01-23 13:53:05 -05001910
andrewonlab79244cc2015-01-26 01:11:49 -05001911 main.ONOS2cli.startOnosCli( ONOS2Ip )
1912 main.ONOS3cli.startOnosCli( ONOS3Ip )
andrewonlaba57a3042015-01-23 13:53:05 -05001913
andrewonlab79244cc2015-01-26 01:11:49 -05001914 elif clusterCount == 5:
1915 main.log.info( "Installing nodes 4 and 5" )
1916 node4Result = \
1917 main.ONOSbench.onosInstall( node=ONOS4Ip )
1918 node5Result = \
1919 main.ONOSbench.onosInstall( node=ONOS5Ip )
1920 installResult = node4Result and node5Result
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.ONOS4cli.startOnosCli( ONOS4Ip )
1925 main.ONOS5cli.startOnosCli( ONOS5Ip )
andrewonlaba57a3042015-01-23 13:53:05 -05001926
andrewonlab79244cc2015-01-26 01:11:49 -05001927 elif clusterCount == 7:
andrewonlab67630692015-01-29 20:16:01 -05001928 main.log.info( "Installing nodes 6 and 7" )
andrewonlab79244cc2015-01-26 01:11:49 -05001929 node6Result = \
1930 main.ONOSbench.onosInstall( node=ONOS6Ip )
1931 node7Result = \
1932 main.ONOSbench.onosInstall( node=ONOS7Ip )
1933 installResult = node6Result and node7Result
andrewonlaba57a3042015-01-23 13:53:05 -05001934
andrewonlab79244cc2015-01-26 01:11:49 -05001935 time.sleep( 5 )
1936
1937 main.ONOS6cli.startOnosCli( ONOS6Ip )
1938 main.ONOS7cli.startOnosCli( ONOS7Ip )