blob: 7097e273ab4b0b2e19fc0e1ea0e3c3ae21fcc7a4 [file] [log] [blame]
jenkins7ead5a82015-03-13 10:28:21 -07001# 2015.03.12 10:22:05 PDT
2#Embedded file name: ../tests/TopoPerfNextBM/TopoPerfNextBM.py
3import time
4import sys
5import os
6import re
7
8class TopoPerfNextBM:
9
10 def __init__(self):
11 self.default = ''
12
13 def CASE1(self, main):
14 """
15 ONOS startup sequence
16 """
17 global clusterCount
18 global timeToPost
19 global runNum
andrew@onlab.us09a4a0c2015-04-09 13:38:13 -040020 global jenkinsBuildNumber
andrew@onlab.us0f468c42015-04-02 17:05:47 -040021
jenkins7ead5a82015-03-13 10:28:21 -070022 import time
andrew@onlab.us09a4a0c2015-04-09 13:38:13 -040023 import os
24
jenkins7ead5a82015-03-13 10:28:21 -070025 clusterCount = 1
26 timeToPost = time.strftime('%Y-%m-%d %H:%M:%S')
27 runNum = time.strftime('%d%H%M%S')
28 cellName = main.params['ENV']['cellName']
29 gitPull = main.params['GIT']['autoPull']
30 checkoutBranch = main.params['GIT']['checkout']
andrew@onlab.us09a4a0c2015-04-09 13:38:13 -040031
32 # Get jenkins build number from environment.
33 # This environment variable will only exist when
34 # triggered by a jenkins job
35 try:
36 jenkinsBuildNumber = str(os.environ['BUILD_NUMBER'])
37 main.log.report( 'Jenkins build number: ' +
38 jenkinsBuildNumber )
39 except KeyError:
40 # Jenkins build number is also used in posting to DB
41 # If this test is not triggered by jenkins, give
42 # it the runNum variable instead, ensuring that
43 # the DB post will recognize it as a non-jenkins run
44 jenkinsBuildNumber = str(runNum)
45 main.log.info( 'Job is not run by jenkins. '+
46 'Build number set to: ' + jenkinsBuildNumber)
47
andrew@onlab.us0f468c42015-04-02 17:05:47 -040048 global CLIs
49 CLIs = []
50 global nodes
51 nodes = []
52 global nodeIpList
53 nodeIpList = []
54 for i in range( 1, 8 ):
55 CLIs.append( getattr( main, 'ONOS' + str( i ) + 'cli' ) )
56 nodes.append( getattr( main, 'ONOS' + str( i ) ) )
57 nodeIpList.append( main.params[ 'CTRL' ][ 'ip'+str(i) ] )
58
jenkins7ead5a82015-03-13 10:28:21 -070059 MN1Ip = main.params['MN']['ip1']
60 BENCHIp = main.params['BENCH']['ip']
andrew@onlab.us0f468c42015-04-02 17:05:47 -040061 cellFeatures = main.params['ENV']['cellFeatures']
jenkins7ead5a82015-03-13 10:28:21 -070062 topoCfgFile = main.params['TEST']['topoConfigFile']
63 topoCfgName = main.params['TEST']['topoConfigName']
64 portEventResultPath = main.params['DB']['portEventResultPath']
65 switchEventResultPath = main.params['DB']['switchEventResultPath']
66 mvnCleanInstall = main.params['TEST']['mci']
67
68 main.case('Setting up test environment')
andrew@onlab.us0f468c42015-04-02 17:05:47 -040069
70 # NOTE: Below is deprecated after new way to install features
71 #main.log.info('Copying topology event accumulator config' +
72 # ' to ONOS /package/etc')
73 #main.ONOSbench.handle.sendline('cp ~/' +
74 # topoCfgFile + ' ~/ONOS/tools/package/etc/' +
75 # topoCfgName)
76 #main.ONOSbench.handle.expect('\\$')
jenkins7ead5a82015-03-13 10:28:21 -070077
78 main.log.report('Setting up test environment')
79
80 main.step('Starting mininet topology ')
81 main.Mininet1.startNet()
82
83 main.step('Cleaning previously installed ONOS if any')
andrew@onlab.us0f468c42015-04-02 17:05:47 -040084 # Nodes 2 ~ 7
85 for i in range( 1, 7 ):
86 main.ONOSbench.onosUninstall(nodeIp=nodeIpList[i])
jenkins7ead5a82015-03-13 10:28:21 -070087
88 main.step('Clearing previous DB log file')
89
90 fPortLog = open(portEventResultPath, 'w')
91 fPortLog.write('')
92 fPortLog.close()
93 fSwitchLog = open(switchEventResultPath, 'w')
94 fSwitchLog.write('')
95 fSwitchLog.close()
96
jenkins7ead5a82015-03-13 10:28:21 -070097 main.step('Creating cell file')
98 cellFileResult = main.ONOSbench.createCellFile(
andrew@onlab.us0f468c42015-04-02 17:05:47 -040099 BENCHIp, cellName, MN1Ip, cellFeatures, nodeIpList[0])
jenkins7ead5a82015-03-13 10:28:21 -0700100
101 main.step('Applying cell file to environment')
102 cellApplyResult = main.ONOSbench.setCell(cellName)
103 verifyCellResult = main.ONOSbench.verifyCell()
104
105 main.step('Git checkout and pull ' + checkoutBranch)
106 if gitPull == 'on':
107 checkoutResult = main.TRUE
108 pullResult = main.ONOSbench.gitPull()
109 else:
110 checkoutResult = main.TRUE
111 pullResult = main.TRUE
112 main.log.info('Skipped git checkout and pull')
113
114 main.log.report('Commit information - ')
115 main.ONOSbench.getVersion(report=True)
116 main.step('Using mvn clean & install')
117 if mvnCleanInstall == 'on':
118 mvnResult = main.ONOSbench.cleanInstall()
119 elif mvnCleanInstall == 'off':
120 main.log.info('mci turned off by settings')
121 mvnResult = main.TRUE
122 main.step('Set cell for ONOS cli env')
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400123 CLIs[0].setCell(cellName)
jenkins7ead5a82015-03-13 10:28:21 -0700124
125 main.step('Creating ONOS package')
126 packageResult = main.ONOSbench.onosPackage()
127
128 main.step('Installing ONOS package')
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400129 install1Result = main.ONOSbench.onosInstall(node=nodeIpList[0])
jenkins7ead5a82015-03-13 10:28:21 -0700130
131 time.sleep(10)
132
133 main.step('Start onos cli')
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400134 cli1 = CLIs[0].startOnosCli(nodeIpList[0])
135
136 main.step( 'activating essential applications' )
137 CLIs[0].activateApp( 'org.onosproject.metrics' )
138 CLIs[0].activateApp( 'org.onosproject.openflow' )
139
140 main.step( 'Configuring application parameters' )
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400141
142 configName = 'org.onosproject.net.topology.impl.DefaultTopologyProvider'
143 configParam = 'maxEvents 1'
144 main.ONOSbench.onosCfgSet( nodeIpList[0], configName, configParam )
145 configParam = 'maxBatchMs 0'
146 main.ONOSbench.onosCfgSet( nodeIpList[0], configName, configParam )
147 configParam = 'maxIdleMs 0'
148 main.ONOSbench.onosCfgSet( nodeIpList[0], configName, configParam )
149
jenkins7ead5a82015-03-13 10:28:21 -0700150 utilities.assert_equals(expect=main.TRUE,
151 actual=cellFileResult and cellApplyResult and\
152 verifyCellResult and checkoutResult and\
153 pullResult and mvnResult and\
154 install1Result,
155 onpass='Test Environment setup successful',
156 onfail='Failed to setup test environment')
157
158 def CASE2(self, main):
159 """
andrew@onlab.usaa1f0dc2015-04-10 12:18:01 -0400160 Assign s3 to ONOS1 and measure latency
jenkins7ead5a82015-03-13 10:28:21 -0700161
162 There are 4 levels of latency measurements to this test:
163 1 ) End-to-end measurement: Complete end-to-end measurement
164 from TCP ( SYN/ACK ) handshake to Graph change
165 2 ) OFP-to-graph measurement: 'ONOS processing' snippet of
166 measurement from OFP Vendor message to Graph change
167 3 ) OFP-to-device measurement: 'ONOS processing without
168 graph change' snippet of measurement from OFP vendor
169 message to Device change timestamp
170 4 ) T0-to-device measurement: Measurement that includes
171 the switch handshake to devices timestamp without
172 the graph view change. ( TCP handshake -> Device
173 change )
174 """
175 import time
176 import subprocess
177 import json
178 import requests
179 import os
180 import numpy
andrew@onlab.us09a4a0c2015-04-09 13:38:13 -0400181
jenkins7ead5a82015-03-13 10:28:21 -0700182 ONOSUser = main.params['CTRL']['user']
183 defaultSwPort = main.params['CTRL']['port1']
184 numIter = main.params['TEST']['numIter']
185 iterIgnore = int(main.params['TEST']['iterIgnore'])
jenkins8ba10ab2015-03-24 10:31:31 -0700186
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400187 deviceTimestampKey = main.params['JSON']['deviceTimestamp']
188 graphTimestampKey = main.params['JSON']['graphTimestamp']
jenkins8ba10ab2015-03-24 10:31:31 -0700189
jenkins7ead5a82015-03-13 10:28:21 -0700190 debugMode = main.params['TEST']['debugMode']
191 onosLog = main.params['TEST']['onosLogFile']
192 resultPath = main.params['DB']['switchEventResultPath']
193 thresholdStr = main.params['TEST']['singleSwThreshold']
194 thresholdObj = thresholdStr.split(',')
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400195 thresholdMin = float(thresholdObj[0])
196 thresholdMax = float(thresholdObj[1])
jenkins7ead5a82015-03-13 10:28:21 -0700197
jenkins8ba10ab2015-03-24 10:31:31 -0700198 # Look for 'role-request' messages,
199 # which replaces the 'vendor' messages previously seen
200 # on OVS 2.0.1
jenkins7ead5a82015-03-13 10:28:21 -0700201 tsharkTcpString = main.params[ 'TSHARK' ][ 'tcpSynAck' ]
jenkins8ba10ab2015-03-24 10:31:31 -0700202 tsharkFeatureReply = main.params[ 'TSHARK' ][ 'featureReply' ]
203 tsharkRoleRequest = main.params[ 'TSHARK' ][ 'roleRequest' ]
204 tsharkOfString = main.params[ 'TSHARK' ][ 'ofpRoleReply' ]
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400205 tsharkFinAckSequence = main.params[ 'TSHARK' ][ 'finAckSequence' ]
jenkins8ba10ab2015-03-24 10:31:31 -0700206
jenkins7ead5a82015-03-13 10:28:21 -0700207 tsharkOfOutput = '/tmp/tshark_of_topo.txt'
208 tsharkTcpOutput = '/tmp/tshark_tcp_topo.txt'
jenkins8ba10ab2015-03-24 10:31:31 -0700209 tsharkRoleOutput = '/tmp/tshark_role_request.txt'
210 tsharkFeatureOutput = '/tmp/tshark_feature_reply.txt'
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400211 tsharkFinAckOutput = '/tmp/tshark_fin_ack.txt'
212
213 # Switch connect measurement list
214 # TCP Syn/Ack -> Feature Reply latency collection for each node
215 tcpToFeatureLatNodeIter = numpy.zeros((clusterCount, int(numIter)))
216 # Feature Reply -> Role Request latency collection for each node
217 featureToRoleRequestLatNodeIter = numpy.zeros((clusterCount,
218 int(numIter)))
219 # Role Request -> Role Reply latency collection for each node
220 roleRequestToRoleReplyLatNodeIter = numpy.zeros((clusterCount,
221 int(numIter)))
222 # Role Reply -> Device Update latency collection for each node
223 roleReplyToDeviceLatNodeIter = numpy.zeros((clusterCount,
224 int(numIter)))
225 # Device Update -> Graph Update latency collection for each node
226 deviceToGraphLatNodeIter = numpy.zeros((clusterCount,
227 int(numIter)))
andrew@onlab.us9210ba12015-04-09 14:11:27 -0400228 endToEndLatNodeIter = numpy.zeros((clusterCount, int(numIter)))
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400229
230 # Switch disconnect measurement lists
231 # Mininet Fin / Ack -> Mininet Ack
232 finAckTransactionLatNodeIter = numpy.zeros((clusterCount,
233 int(numIter)))
234 # Mininet Ack -> Device Event
235 ackToDeviceLatNodeIter = numpy.zeros((clusterCount,
236 int(numIter)))
237 # Device event -> Graph event
238 deviceToGraphDiscLatNodeIter = numpy.zeros((clusterCount,
239 int(numIter)))
andrew@onlab.us9210ba12015-04-09 14:11:27 -0400240 endToEndDiscLatNodeIter = numpy.zeros((clusterCount, int(numIter)))
jenkins7ead5a82015-03-13 10:28:21 -0700241
jenkins7ead5a82015-03-13 10:28:21 -0700242 assertion = main.TRUE
243 localTime = time.strftime('%x %X')
244 localTime = localTime.replace('/', '')
245 localTime = localTime.replace(' ', '_')
246 localTime = localTime.replace(':', '')
247
248 if debugMode == 'on':
249 main.ONOS1.tsharkPcap('eth0',
250 '/tmp/single_sw_lat_pcap_' + localTime)
251 main.log.info('Debug mode is on')
252 main.log.report('Latency of adding one switch to controller')
253 main.log.report('First ' + str(iterIgnore) +
254 ' iterations ignored' + ' for jvm warmup time')
255 main.log.report('Total iterations of test: ' + str(numIter))
256
257 for i in range(0, int(numIter)):
258 main.log.info('Starting tshark capture')
259 main.ONOS1.tsharkGrep(tsharkTcpString, tsharkTcpOutput)
260 main.ONOS1.tsharkGrep(tsharkOfString, tsharkOfOutput)
jenkins8ba10ab2015-03-24 10:31:31 -0700261 main.ONOS1.tsharkGrep(tsharkRoleRequest, tsharkRoleOutput)
262 main.ONOS1.tsharkGrep(tsharkFeatureReply, tsharkFeatureOutput)
263
jenkins7ead5a82015-03-13 10:28:21 -0700264 time.sleep(10)
265
266 main.log.info('Assigning s3 to controller')
267 main.Mininet1.assignSwController(sw='3',
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400268 ip1=nodeIpList[0], port1=defaultSwPort)
jenkins7ead5a82015-03-13 10:28:21 -0700269
270 time.sleep(10)
271
272 main.log.info('Stopping all Tshark processes')
273 main.ONOS1.tsharkStop()
274
275 main.log.info('Copying over tshark files')
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400276 os.system('scp ' + ONOSUser + '@' + nodeIpList[0] +
jenkins7ead5a82015-03-13 10:28:21 -0700277 ':' + tsharkTcpOutput + ' /tmp/')
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400278 os.system('scp ' + ONOSUser + '@' + nodeIpList[0] +
jenkins8ba10ab2015-03-24 10:31:31 -0700279 ':' + tsharkRoleOutput + ' /tmp/')
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400280 os.system('scp ' + ONOSUser + '@' + nodeIpList[0] +
jenkins8ba10ab2015-03-24 10:31:31 -0700281 ':' + tsharkFeatureOutput + ' /tmp/')
282 os.system('scp ' + ONOSUser + '@' +
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400283 nodeIpList[0] + ':' + tsharkOfOutput + ' /tmp/')
jenkins8ba10ab2015-03-24 10:31:31 -0700284
285 # Get tcp syn / ack output
jenkins7ead5a82015-03-13 10:28:21 -0700286 time.sleep(5)
287 tcpFile = open(tsharkTcpOutput, 'r')
288 tempText = tcpFile.readline()
289 tempText = tempText.split(' ')
290 main.log.info('Object read in from TCP capture: ' +
291 str(tempText))
292
293 if len(tempText) > 1:
294 t0Tcp = float(tempText[1]) * 1000.0
295 else:
296 main.log.error('Tshark output file for TCP' +
297 ' returned unexpected results')
298 t0Tcp = 0
299 assertion = main.FALSE
300 tcpFile.close()
jenkins8ba10ab2015-03-24 10:31:31 -0700301
302 # Get Role reply output
jenkins7ead5a82015-03-13 10:28:21 -0700303 time.sleep(5)
304 ofFile = open(tsharkOfOutput, 'r')
305 lineOfp = ''
306 while True:
307 tempText = ofFile.readline()
308 if tempText != '':
309 lineOfp = tempText
310 else:
311 break
jenkins7ead5a82015-03-13 10:28:21 -0700312 obj = lineOfp.split(' ')
313 main.log.info('Object read in from OFP capture: ' +
314 str(lineOfp))
315 if len(obj) > 1:
316 t0Ofp = float(obj[1]) * 1000.0
317 else:
318 main.log.error('Tshark output file for OFP' +
319 ' returned unexpected results')
320 t0Ofp = 0
321 assertion = main.FALSE
322 ofFile.close()
jenkins8ba10ab2015-03-24 10:31:31 -0700323
324 # Get role request output
325 roleFile = open(tsharkRoleOutput, 'r')
326 tempText = roleFile.readline()
327 tempText = tempText.split(' ')
328 if len(tempText) > 1:
329 main.log.info('Object read in from role request capture:' +
330 str(tempText))
331 roleTimestamp = float(tempText[1]) * 1000.0
332 else:
333 main.log.error('Tshark output file for role request' +
334 ' returned unexpected results')
335 timeRoleRequest = 0
336 assertion = main.FALSE
337 roleFile.close()
338
339 # Get feature reply output
340 featureFile = open(tsharkFeatureOutput, 'r')
341 tempText = featureFile.readline()
342 tempText = tempText.split(' ')
343 if len(tempText) > 1:
344 main.log.info('Object read in from feature reply capture: '+
345 str(tempText))
346 featureTimestamp = float(tempText[1]) * 1000.0
347 else:
348 main.log.error('Tshark output file for feature reply' +
349 ' returned unexpected results')
350 timeFeatureReply = 0
351 assertion = main.FALSE
352 featureFile.close()
353
354 # TODO: calculate feature reply, role request times
355 # stack measurements correctly and report
356
jenkins8ba10ab2015-03-24 10:31:31 -0700357 #TODO: Refactor in progress
358
359 for node in range(0, clusterCount):
360 nodeNum = node+1
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400361 metricsSwUp = CLIs[node].topologyEventsMetrics
jenkins8ba10ab2015-03-24 10:31:31 -0700362 jsonStr = metricsSwUp()
363 jsonObj = json.loads(jsonStr)
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400364 if jsonObj:
365 graphTimestamp = jsonObj[graphTimestampKey]['value']
366 deviceTimestamp = jsonObj[deviceTimestampKey]['value']
jenkins8ba10ab2015-03-24 10:31:31 -0700367 else:
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400368 main.log.error( "Unexpected JSON object" )
369 # If we could not obtain the JSON object,
370 # set the timestamps to 0, which will be
371 # excluded from the measurement later on
372 # (realized as invalid)
373 graphTimestamp = 0
374 deviceTimestamp = 0
375
376 endToEnd = int(graphTimestamp) - int(t0Tcp)
377
378 # Below are measurement breakdowns of the end-to-end
379 # measurement.
380 tcpToFeature = int(featureTimestamp) - int(t0Tcp)
381 featureToRole = int(roleTimestamp) - int(featureTimestamp)
andrew@onlab.usaa1f0dc2015-04-10 12:18:01 -0400382 roleToOfp = float(t0Ofp) - float(roleTimestamp)
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400383 ofpToDevice = int(deviceTimestamp) - int(t0Ofp)
384 deviceToGraph = float(graphTimestamp) - float(deviceTimestamp)
385
386 if endToEnd > thresholdMin and\
387 endToEnd < thresholdMax and i >= iterIgnore:
388 endToEndLatNodeIter[node][i] = endToEnd
389 main.log.info("ONOS "+str(nodeNum)+ " end-to-end: "+
390 str(endToEnd) + " ms")
391 else:
392 main.log.info("ONOS "+str(nodeNum)+ " end-to-end "+
jenkins8ba10ab2015-03-24 10:31:31 -0700393 "measurement ignored due to excess in "+
394 "threshold or premature iteration")
395
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400396 if tcpToFeature > thresholdMin and\
397 tcpToFeature < thresholdMax and i >= iterIgnore:
398 tcpToFeatureLatNodeIter[node][i] = tcpToFeature
399 main.log.info("ONOS "+str(nodeNum)+ " tcp-to-feature: "+
400 str(tcpToFeature) + " ms")
jenkins8ba10ab2015-03-24 10:31:31 -0700401 else:
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400402 main.log.info("ONOS "+str(nodeNum)+ " tcp-to-feature "+
jenkins8ba10ab2015-03-24 10:31:31 -0700403 "measurement ignored due to excess in "+
404 "threshold or premature iteration")
405
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400406 if featureToRole > thresholdMin and\
407 featureToRole < thresholdMax and i >= iterIgnore:
408 featureToRoleRequestLatNodeIter[node][i] = featureToRole
409 main.log.info("ONOS "+str(nodeNum)+ " feature-to-role: "+
410 str(featureToRole) + " ms")
jenkins8ba10ab2015-03-24 10:31:31 -0700411 else:
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400412 main.log.info("ONOS "+str(nodeNum)+ " feature-to-role "+
jenkins8ba10ab2015-03-24 10:31:31 -0700413 "measurement ignored due to excess in "+
414 "threshold or premature iteration")
415
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400416 if roleToOfp > thresholdMin and\
417 roleToOfp < thresholdMax and i >= iterIgnore:
418 roleRequestToRoleReplyLatNodeIter[node][i] = roleToOfp
419 main.log.info("ONOS "+str(nodeNum)+ " role-to-reply: "+
420 str(roleToOfp) + " ms")
421 else:
422 main.log.info("ONOS "+str(nodeNum)+ " role-to-reply "+
423 "measurement ignored due to excess in "+
424 "threshold or premature iteration")
425
426 if ofpToDevice > thresholdMin and\
427 ofpToDevice < thresholdMax and i >= iterIgnore:
428 roleReplyToDeviceLatNodeIter[node][i] = ofpToDevice
429 main.log.info("ONOS "+str(nodeNum)+ " reply-to-device: "+
430 str(ofpToDevice) + " ms")
431 else:
andrew@onlab.usaa1f0dc2015-04-10 12:18:01 -0400432 main.log.info("ONOS "+str(nodeNum)+ " reply-to-device "+
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400433 "measurement ignored due to excess in "+
434 "threshold or premature iteration")
jenkins8ba10ab2015-03-24 10:31:31 -0700435
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400436 if deviceToGraph > thresholdMin and\
437 deviceToGraph < thresholdMax and i >= iterIgnore:
438 deviceToGraphLatNodeIter[node][i] = deviceToGraph
439 main.log.info("ONOS "+str(nodeNum)+ " device-to-graph: "+
440 str(deviceToGraph) + " ms")
441 else:
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400442 main.log.info("ONOS "+str(nodeNum)+ " device-to-graph "+
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400443 "measurement ignored due to excess in "+
444 "threshold or premature iteration")
445
jenkins8ba10ab2015-03-24 10:31:31 -0700446 # ********************
jenkins7ead5a82015-03-13 10:28:21 -0700447 time.sleep(5)
448
449 # Get device id to remove
450 deviceIdJsonStr = main.ONOS1cli.devices()
451
452 main.log.info( "Device obj obtained: " + str(deviceIdJsonStr) )
453 deviceId = json.loads(deviceIdJsonStr)
454
455 deviceList = []
456 for device in deviceId:
457 deviceList.append(device['id'])
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400458
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400459 # Measure switch down metrics
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400460 # TCP FIN/ACK -> TCP FIN
461 # TCP FIN -> Device Event
462 # Device Event -> Graph Event
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400463 # Capture switch down FIN / ACK packets
464
andrew@onlab.us09a4a0c2015-04-09 13:38:13 -0400465 # The -A 1 grep option allows us to grab 1 extra line after the
466 # last tshark output grepped originally
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400467 main.ONOS1.tsharkGrep( tsharkFinAckSequence, tsharkFinAckOutput,
468 grepOptions = '-A 1' )
469
470 time.sleep( 5 )
471
472 removeJsonList = []
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400473
jenkins7ead5a82015-03-13 10:28:21 -0700474 main.step('Remove switch from controller')
475 main.Mininet1.deleteSwController('s3')
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400476 firstDevice = deviceList[0]
jenkins7ead5a82015-03-13 10:28:21 -0700477 main.log.info( "Removing device " +str(firstDevice)+
478 " from ONOS" )
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400479
480 time.sleep( 5 )
481
482 # We need to get metrics before removing
483 # device from the store below.
484 for node in range(0, clusterCount):
485 metricsSwDown = CLIs[node].topologyEventsMetrics
486 jsonStr = metricsSwDown()
487 removeJsonList.append( json.loads(jsonStr) )
488
jenkins7ead5a82015-03-13 10:28:21 -0700489 #if deviceId:
490 main.ONOS1cli.deviceRemove(firstDevice)
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400491
492 main.ONOS1.tsharkStop()
493
494 main.log.info('Copying over tshark files')
495 os.system('scp ' + ONOSUser + '@' + nodeIpList[0] +
496 ':' + tsharkFinAckOutput + ' /tmp/')
497
498 time.sleep( 10 )
499 finAckOutputList = []
500 with open(tsharkFinAckOutput, 'r') as f:
501 tempLine = f.readlines()
502 main.log.info('Object read in from FinAck capture: ' +
andrew@onlab.usaa1f0dc2015-04-10 12:18:01 -0400503 "\n".join(tempLine))
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400504
505 index = 1
506 for line in tempLine:
507 obj = line.split(' ')
jenkins7ead5a82015-03-13 10:28:21 -0700508
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400509 if len(obj) > 1:
510 if index == 1:
511 tFinAck = float(obj[1]) * 1000.0
512 elif index == 3:
513 tAck = float(obj[1]) * 1000.0
514 else:
515 main.log.error('Tshark output file for OFP' +
516 ' returned unexpected results')
517 tFinAck = 0
518 tAck = 0
519 assertion = main.FALSE
520
521 index = index+1
522
523 # with open() as f takes care of closing file
524
jenkins7ead5a82015-03-13 10:28:21 -0700525 time.sleep(5)
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400526
527 for node in range(0, clusterCount):
528 nodeNum = node+1
529 jsonObj = removeJsonList[node]
530 if jsonObj:
531 graphTimestamp = jsonObj[graphTimestampKey]['value']
532 deviceTimestamp = jsonObj[deviceTimestampKey]['value']
533 main.log.info("Graph timestamp: "+str(graphTimestamp))
534 main.log.info("Device timestamp: "+str(deviceTimestamp))
535 else:
536 main.log.error( "Unexpected JSON object" )
537 # If we could not obtain the JSON object,
538 # set the timestamps to 0, which will be
539 # excluded from the measurement later on
540 # (realized as invalid)
541 graphTimestamp = 0
542 deviceTimestamp = 0
543
andrew@onlab.usaa1f0dc2015-04-10 12:18:01 -0400544 finAckTransaction = float(tAck) - float(tFinAck)
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400545 ackToDevice = int(deviceTimestamp) - int(tAck)
546 deviceToGraph = int(graphTimestamp) - int(deviceTimestamp)
andrew@onlab.us9210ba12015-04-09 14:11:27 -0400547 endToEndDisc = int(graphTimestamp) - int(tFinAck)
548
549 if endToEndDisc > thresholdMin and\
550 endToEndDisc < thresholdMax and i >= iterIgnore:
551 endToEndDiscLatNodeIter[node][i] = endToEndDisc
552 main.log.info("ONOS "+str(nodeNum) +
553 "end-to-end disconnection: "+
554 str(endToEndDisc) + " ms" )
555 else:
556 main.log.info("ONOS " + str(nodeNum) +
557 " end-to-end disconnection "+
558 "measurement ignored due to excess in "+
559 "threshold or premature iteration")
560
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400561 if finAckTransaction > thresholdMin and\
562 finAckTransaction < thresholdMax and i >= iterIgnore:
563 finAckTransactionLatNodeIter[node][i] = finAckTransaction
564 main.log.info("ONOS "+str(nodeNum)+
565 " fin/ack transaction: "+
566 str(finAckTransaction) + " ms")
567 else:
568 main.log.info("ONOS "+str(nodeNum)+
569 " fin/ack transaction "+
570 "measurement ignored due to excess in "+
571 "threshold or premature iteration")
572
573 if ackToDevice > thresholdMin and\
574 ackToDevice < thresholdMax and i >= iterIgnore:
575 ackToDeviceLatNodeIter[node][i] = ackToDevice
576 main.log.info("ONOS "+str(nodeNum)+
577 " ack-to-device: "+
578 str(ackToDevice) + " ms")
579 else:
580 main.log.info("ONOS "+str(nodeNum)+
581 " ack-to-device "+
582 "measurement ignored due to excess in "+
583 "threshold or premature iteration")
584
585 if deviceToGraph > thresholdMin and\
586 deviceToGraph < thresholdMax and i >= iterIgnore:
587 deviceToGraphDiscLatNodeIter[node][i] = deviceToGraph
588 main.log.info("ONOS "+str(nodeNum)+
589 " device-to-graph disconnect: "+
590 str(deviceToGraph) + " ms")
591 else:
592 main.log.info("ONOS "+str(nodeNum)+
593 " device-to-graph disconnect "+
594 "measurement ignored due to excess in "+
595 "threshold or premature iteration")
jenkins7ead5a82015-03-13 10:28:21 -0700596
597 endToEndAvg = 0
598 ofpToGraphAvg = 0
jenkins7ead5a82015-03-13 10:28:21 -0700599 dbCmdList = []
600 for node in range(0, clusterCount):
jenkins8ba10ab2015-03-24 10:31:31 -0700601 # List of latency for each node
602 endToEndList = []
jenkins8ba10ab2015-03-24 10:31:31 -0700603 tcpToFeatureList = []
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400604 featureToRoleList = []
605 roleToOfpList = []
606 ofpToDeviceList = []
607 deviceToGraphList = []
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400608
609 finAckTransactionList = []
610 ackToDeviceList = []
611 deviceToGraphDiscList = []
andrew@onlab.us9210ba12015-04-09 14:11:27 -0400612 endToEndDiscList = []
613
jenkins8ba10ab2015-03-24 10:31:31 -0700614 # LatNodeIter 2d arrays contain all iteration latency
615 # for each node of the current scale cluster size
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400616 # Switch connection measurements
617 # Set further acceptance criteria for measurements
618 # here if you would like to filter reporting results
jenkins7ead5a82015-03-13 10:28:21 -0700619 for item in endToEndLatNodeIter[node]:
620 if item > 0.0:
621 endToEndList.append(item)
622
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400623 for item in tcpToFeatureLatNodeIter[node]:
jenkins8ba10ab2015-03-24 10:31:31 -0700624 if item > 0.0:
625 tcpToFeatureList.append(item)
626
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400627 for item in featureToRoleRequestLatNodeIter[node]:
jenkins8ba10ab2015-03-24 10:31:31 -0700628 if item > 0.0:
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400629 featureToRoleList.append(item)
630
631 for item in roleRequestToRoleReplyLatNodeIter[node]:
632 if item > 0.0:
633 roleToOfpList.append(item)
634
635 for item in roleReplyToDeviceLatNodeIter[node]:
636 if item > 0.0:
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400637 tcpToFeatureList.append(item)
638
639 for item in featureToRoleRequestLatNodeIter[node]:
640 if item > 0.0:
641 featureToRoleList.append(item)
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400642
643 for item in deviceToGraphLatNodeIter[node]:
644 if item > 0.0:
645 deviceToGraphList.append(item)
jenkins8ba10ab2015-03-24 10:31:31 -0700646
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400647 # Switch disconnect measurements
andrew@onlab.us9210ba12015-04-09 14:11:27 -0400648 for item in endToEndDiscLatNodeIter[node]:
649 if item > 0.0:
650 endToEndDiscList.append(item)
651
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400652 for item in finAckTransactionLatNodeIter[node]:
653 if item > 0.0:
654 finAckTransactionList.append(item)
655
656 for item in ackToDeviceLatNodeIter[node]:
657 if item > 0.0:
658 ackToDeviceList.append(item)
659
660 for item in deviceToGraphDiscLatNodeIter[node]:
661 if item > 0.0:
662 deviceToGraphDiscList.append(item)
663
jenkins7ead5a82015-03-13 10:28:21 -0700664 endToEndAvg = round(numpy.mean(endToEndList), 2)
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400665 endToEndStdDev = round(numpy.std(endToEndList), 2)
666
jenkins8ba10ab2015-03-24 10:31:31 -0700667 tcpToFeatureAvg = round(numpy.mean(tcpToFeatureList), 2)
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400668 tcpToFeatureStdDev = round(numpy.std(tcpToFeatureList), 2)
669
670 featureToRoleAvg = round(numpy.mean(featureToRoleList), 2)
671 featureToRoleStdDev = round(numpy.std(featureToRoleList), 2)
672
673 roleToOfpAvg = round(numpy.mean(roleToOfpList), 2)
674 roleToOfpStdDev = round(numpy.std(roleToOfpList), 2)
675
jenkins7ead5a82015-03-13 10:28:21 -0700676 ofpToDeviceAvg = round(numpy.mean(ofpToDeviceList), 2)
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400677 ofpToDeviceStdDev = round(numpy.std(ofpToDeviceList), 2)
678
679 deviceToGraphAvg = round(numpy.mean(deviceToGraphList), 2)
680 deviceToGraphStdDev = round(numpy.std(deviceToGraphList), 2)
681
andrew@onlab.us9210ba12015-04-09 14:11:27 -0400682 endToEndDiscAvg = round(numpy.mean(endToEndDiscList), 2)
683 endToEndDiscStdDev = round(numpy.std(endToEndDiscList), 2)
684
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400685 finAckAvg = round(numpy.mean(finAckTransactionList), 2)
686 finAckStdDev = round(numpy.std(finAckTransactionList), 2)
687
688 ackToDeviceAvg = round(numpy.mean(ackToDeviceList), 2)
689 ackToDeviceStdDev = round(numpy.std(ackToDeviceList), 2)
690
691 deviceToGraphDiscAvg = round(numpy.mean(deviceToGraphDiscList), 2)
692 deviceToGraphDiscStdDev = round(numpy.std(deviceToGraphDiscList), 2)
693
jenkins7ead5a82015-03-13 10:28:21 -0700694 main.log.report(' - Node ' + str(node + 1) + ' Summary - ')
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400695 main.log.report(' - Switch Connection Statistics - ')
696
jenkins7ead5a82015-03-13 10:28:21 -0700697 main.log.report(' End-to-end Avg: ' + str(endToEndAvg) +
698 ' ms' + ' End-to-end Std dev: ' +
andrew@onlab.us0f468c42015-04-02 17:05:47 -0400699 str(endToEndStdDev) + ' ms')
700
701 main.log.report(' Tcp-to-feature-reply Avg: ' +
702 str(tcpToFeatureAvg) + ' ms')
703 main.log.report(' Tcp-to-feature-reply Std dev: '+
704 str(tcpToFeatureStdDev) + ' ms')
705
706 main.log.report(' Feature-reply-to-role-request Avg: ' +
707 str(featureToRoleAvg) + ' ms')
708 main.log.report(' Feature-reply-to-role-request Std Dev: ' +
709 str(featureToRoleStdDev) + ' ms')
710
711 main.log.report(' Role-request-to-role-reply Avg: ' +
712 str(roleToOfpAvg) +' ms')
713 main.log.report(' Role-request-to-role-reply Std dev: ' +
714 str(roleToOfpStdDev) + ' ms')
715
716 main.log.report(' Role-reply-to-device Avg: ' +
717 str(ofpToDeviceAvg) +' ms')
718 main.log.report(' Role-reply-to-device Std dev: ' +
719 str(ofpToDeviceStdDev) + ' ms')
720
721 main.log.report(' Device-to-graph Avg: ' +
722 str(deviceToGraphAvg) + ' ms')
723 main.log.report( 'Device-to-graph Std dev: ' +
724 str(deviceToGraphStdDev) + ' ms')
725
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400726 main.log.report(' - Switch Disconnection Statistics - ')
andrew@onlab.us9210ba12015-04-09 14:11:27 -0400727 main.log.report(' End-to-end switch disconnect Avg: ' +
728 str(endToEndDiscAvg) + ' ms')
729 main.log.report(' End-to-end switch disconnect Std dev: ' +
730 str(endToEndDiscStdDev) + ' ms')
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400731 main.log.report(' Fin/Ack-to-Ack Avg: ' + str(finAckAvg) + ' ms')
732 main.log.report(' Fin/Ack-to-Ack Std dev: ' +
733 str(finAckStdDev) + ' ms')
734
735 main.log.report(' Ack-to-device Avg: ' + str(ackToDeviceAvg) +
736 ' ms')
737 main.log.report(' Ack-to-device Std dev: ' + str(ackToDeviceStdDev) +
738 ' ms')
739
740 main.log.report(' Device-to-graph (disconnect) Avg: ' +
741 str(deviceToGraphDiscAvg) + ' ms')
742 main.log.report(' Device-to-graph (disconnect) Std dev: ' +
743 str(deviceToGraphDiscStdDev) + ' ms')
744
andrew@onlab.usaa1f0dc2015-04-10 12:18:01 -0400745 # For database schema, refer to Amazon web services
jenkins7ead5a82015-03-13 10:28:21 -0700746 dbCmdList.append(
andrew@onlab.usaa1f0dc2015-04-10 12:18:01 -0400747 "INSERT INTO switch_latency_details VALUES('" +
jenkins7ead5a82015-03-13 10:28:21 -0700748 timeToPost + "','switch_latency_results'," +
andrew@onlab.us09a4a0c2015-04-09 13:38:13 -0400749 jenkinsBuildNumber + ',' + str(clusterCount) + ",'baremetal" +
andrew@onlab.usaa1f0dc2015-04-10 12:18:01 -0400750 str(node + 1) + "'," +
751 str(endToEndAvg) + ',' +
752 str(tcpToFeatureAvg) + ',' +
753 str(featureToRoleAvg) + ',' +
754 str(roleToOfpAvg) + ',' +
755 str(ofpToDeviceAvg) + ',' +
756 str(deviceToGraphAvg) + ',' +
757 str(endToEndDiscAvg) + ',' +
758 str(finAckAvg) + ',' +
759 str(ackToDeviceAvg) + ',' +
760 str(deviceToGraphDiscAvg) +
761 ');')
jenkins7ead5a82015-03-13 10:28:21 -0700762
763 if debugMode == 'on':
764 main.ONOS1.cpLogsToDir('/opt/onos/log/karaf.log',
765 '/tmp/', copyFileName='sw_lat_karaf')
766 fResult = open(resultPath, 'a')
767 for line in dbCmdList:
768 if line:
769 fResult.write(line + '\n')
jenkins7ead5a82015-03-13 10:28:21 -0700770 fResult.close()
andrew@onlab.usaa1f0dc2015-04-10 12:18:01 -0400771
jenkins7ead5a82015-03-13 10:28:21 -0700772 assertion = main.TRUE
andrew@onlab.usaa1f0dc2015-04-10 12:18:01 -0400773
jenkins7ead5a82015-03-13 10:28:21 -0700774 utilities.assert_equals(expect=main.TRUE, actual=assertion,
775 onpass='Switch latency test successful',
776 onfail='Switch latency test failed')
777
778 def CASE3(self, main):
779 """
780 Bring port up / down and measure latency.
781 Port enable / disable is simulated by ifconfig up / down
782
783 In ONOS-next, we must ensure that the port we are
784 manipulating is connected to another switch with a valid
785 connection. Otherwise, graph view will not be updated.
786 """
787 global timeToPost
788 import time
789 import subprocess
790 import os
791 import requests
792 import json
793 import numpy
794 ONOS1Ip = main.params['CTRL']['ip1']
795 ONOS2Ip = main.params['CTRL']['ip2']
796 ONOS3Ip = main.params['CTRL']['ip3']
797 ONOSUser = main.params['CTRL']['user']
798 defaultSwPort = main.params['CTRL']['port1']
799 assertion = main.TRUE
800 numIter = main.params['TEST']['numIter']
801 iterIgnore = int(main.params['TEST']['iterIgnore'])
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400802
803 deviceTimestampKey = main.params['JSON']['deviceTimestamp']
804 graphTimestampKey = main.params['JSON']['graphTimestamp']
805 linkTimestampKey = main.params['JSON']['linkTimestamp']
jenkins7ead5a82015-03-13 10:28:21 -0700806
807 tsharkPortUp = '/tmp/tshark_port_up.txt'
808 tsharkPortDown = '/tmp/tshark_port_down.txt'
809 tsharkPortStatus = main.params[ 'TSHARK' ][ 'ofpPortStatus' ]
810
811 debugMode = main.params['TEST']['debugMode']
812 postToDB = main.params['DB']['postToDB']
813 resultPath = main.params['DB']['portEventResultPath']
814 timeToPost = time.strftime('%Y-%m-%d %H:%M:%S')
815 localTime = time.strftime('%x %X')
816 localTime = localTime.replace('/', '')
817 localTime = localTime.replace(' ', '_')
818 localTime = localTime.replace(':', '')
819
820 if debugMode == 'on':
821 main.ONOS1.tsharkPcap('eth0', '/tmp/port_lat_pcap_' + localTime)
822
823 upThresholdStr = main.params['TEST']['portUpThreshold']
824 downThresholdStr = main.params['TEST']['portDownThreshold']
825 upThresholdObj = upThresholdStr.split(',')
826 downThresholdObj = downThresholdStr.split(',')
827 upThresholdMin = int(upThresholdObj[0])
828 upThresholdMax = int(upThresholdObj[1])
829 downThresholdMin = int(downThresholdObj[0])
830 downThresholdMax = int(downThresholdObj[1])
831
832 interfaceConfig = 's1-eth1'
833 main.log.report('Port enable / disable latency')
834 main.log.report('Simulated by ifconfig up / down')
835 main.log.report('Total iterations of test: ' + str(numIter))
836 main.step('Assign switches s1 and s2 to controller 1')
837
838 main.Mininet1.assignSwController(sw='1',
839 ip1=ONOS1Ip, port1=defaultSwPort)
840 main.Mininet1.assignSwController(sw='2',
841 ip1=ONOS1Ip, port1=defaultSwPort)
842
843 time.sleep(15)
844
845 portUpDeviceToOfpList = []
846 portUpGraphToOfpList = []
847 portDownDeviceToOfpList = []
848 portDownGraphToOfpList = []
849
850 portUpDevNodeIter = numpy.zeros((clusterCount, int(numIter)))
851 portUpGraphNodeIter = numpy.zeros((clusterCount, int(numIter)))
852 portUpLinkLatNodeIter = numpy.zeros((clusterCount, int(numIter)))
853 portDownDevNodeIter = numpy.zeros((clusterCount, int(numIter)))
854 portDownGraphNodeIter = numpy.zeros((clusterCount, int(numIter)))
855 portDownLinkNodeIter = numpy.zeros((clusterCount, int(numIter)))
856 portUpLinkNodeIter = numpy.zeros((clusterCount, int(numIter)))
857
858 for i in range(0, int(numIter)):
859 main.step('Starting wireshark capture for port status down')
860 main.ONOS1.tsharkGrep(tsharkPortStatus, tsharkPortDown)
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400861
jenkins7ead5a82015-03-13 10:28:21 -0700862 time.sleep(5)
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400863
jenkins7ead5a82015-03-13 10:28:21 -0700864 main.step('Disable port: ' + interfaceConfig)
865 main.Mininet1.handle.sendline('sh ifconfig ' +
866 interfaceConfig + ' down')
867 main.Mininet1.handle.expect('mininet>')
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400868
jenkins7ead5a82015-03-13 10:28:21 -0700869 time.sleep(3)
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400870
jenkins7ead5a82015-03-13 10:28:21 -0700871 main.ONOS1.tsharkStop()
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400872
jenkins7ead5a82015-03-13 10:28:21 -0700873 os.system('scp ' + ONOSUser + '@' + ONOS1Ip + ':' +
874 tsharkPortDown + ' /tmp/')
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400875
jenkins7ead5a82015-03-13 10:28:21 -0700876 fPortDown = open(tsharkPortDown, 'r')
877 fLine = fPortDown.readline()
878 objDown = fLine.split(' ')
879 if len(fLine) > 0:
880 timestampBeginPtDown = int(float(objDown[1]) * 1000)
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400881 # At times, tshark reports timestamp at the 3rd
882 # index of the array. If initial readings were
883 # unlike the epoch timestamp, then check the 3rd
884 # index and set that as a timestamp
jenkins7ead5a82015-03-13 10:28:21 -0700885 if timestampBeginPtDown < 1400000000000:
886 timestampBeginPtDown = int(float(objDown[2]) * 1000)
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400887 # If there are any suspicion of invalid results
888 # check this reported value
jenkins7ead5a82015-03-13 10:28:21 -0700889 main.log.info('Port down begin timestamp: ' +
890 str(timestampBeginPtDown))
891 else:
892 main.log.info('Tshark output file returned unexpected' +
893 ' results: ' + str(objDown))
894 timestampBeginPtDown = 0
895 fPortDown.close()
jenkins8ba10ab2015-03-24 10:31:31 -0700896
jenkins8ba10ab2015-03-24 10:31:31 -0700897 for node in range(0, clusterCount):
898 nodeNum = node+1
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400899 metricsDown = CLIs[node].topologyEventsMetrics
jenkins8ba10ab2015-03-24 10:31:31 -0700900 jsonStrDown = metricsDown()
901 jsonObj = json.loads(jsonStrDown)
902
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400903 if jsonObj:
904 graphTimestamp = jsonObj[graphTimestampKey]['value']
905 deviceTimestamp = jsonObj[deviceTimestampKey]['value']
906 linkTimestamp = jsonObj[linkTimestampKey]['value']
907 else:
908 main.log.error( "Unexpected json object" )
909 graphTimestamp = 0
910 deviceTimestamp = 0
911 linkTimestamp = 0
912
jenkins8ba10ab2015-03-24 10:31:31 -0700913 ptDownGraphToOfp = int(graphTimestamp) - int(timestampBeginPtDown)
914 ptDownDeviceToOfp = int(deviceTimestamp) - int(timestampBeginPtDown)
915 ptDownLinkToOfp = int(linkTimestamp) - int(timestampBeginPtDown)
916
917 if ptDownGraphToOfp > downThresholdMin and\
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400918 ptDownGraphToOfp < downThresholdMax and i >= iterIgnore:
jenkins8ba10ab2015-03-24 10:31:31 -0700919 portDownGraphNodeIter[node][i] = ptDownGraphToOfp
920 main.log.info("ONOS "+str(nodeNum)+
921 " port down graph-to-ofp: "+
922 str(ptDownGraphToOfp) + " ms")
923 else:
924 main.log.info("ONOS "+str(nodeNum)+
925 " port down graph-to-ofp ignored"+
926 " due to excess in threshold or premature iteration")
927
928 if ptDownDeviceToOfp > downThresholdMin and\
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400929 ptDownDeviceToOfp < downThresholdMax and i >= iterIgnore:
930 portDownDevNodeIter[node][i] = ptDownDeviceToOfp
jenkins8ba10ab2015-03-24 10:31:31 -0700931 main.log.info("ONOS "+str(nodeNum)+
932 " port down device-to-ofp: "+
933 str(ptDownDeviceToOfp) + " ms")
934 else:
935 main.log.info("ONOS "+str(nodeNum)+
936 " port down device-to-ofp ignored"+
937 " due to excess in threshold or premature iteration")
938
939 if ptDownLinkToOfp > downThresholdMin and\
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400940 ptDownLinkToOfp < downThresholdMax and i >= iterIgnore:
jenkins8ba10ab2015-03-24 10:31:31 -0700941 portDownLinkNodeIter[node][i] = ptDownLinkToOfp
942 main.log.info("ONOS "+str(nodeNum)+
943 " port down link-to-ofp: "+
944 str(ptDownLinkToOfp) + " ms")
945 else:
946 main.log.info("ONOS "+str(nodeNum)+
947 " port down link-to-ofp ignored"+
948 " due to excess in threshold or premature iteration")
jenkins8ba10ab2015-03-24 10:31:31 -0700949
jenkins7ead5a82015-03-13 10:28:21 -0700950 time.sleep(3)
951
952 main.step('Starting wireshark capture for port status up')
953 main.ONOS1.tsharkGrep(tsharkPortStatus, tsharkPortUp)
954
955 time.sleep(5)
956 main.step('Enable port and obtain timestamp')
957 main.Mininet1.handle.sendline('sh ifconfig ' + interfaceConfig + ' up')
958 main.Mininet1.handle.expect('mininet>')
959
960 time.sleep(5)
961 main.ONOS1.tsharkStop()
962
963 time.sleep(3)
964 os.system('scp ' + ONOSUser + '@' +
965 ONOS1Ip + ':' + tsharkPortUp + ' /tmp/')
966
967 fPortUp = open(tsharkPortUp, 'r')
968 fLine = fPortUp.readline()
969 objUp = fLine.split(' ')
970 if len(fLine) > 0:
971 timestampBeginPtUp = int(float(objUp[1]) * 1000)
972 if timestampBeginPtUp < 1400000000000:
973 timestampBeginPtUp = int(float(objUp[2]) * 1000)
974 main.log.info('Port up begin timestamp: ' + str(timestampBeginPtUp))
975 else:
976 main.log.info('Tshark output file returned unexpected' + ' results.')
977 timestampBeginPtUp = 0
978 fPortUp.close()
jenkins8ba10ab2015-03-24 10:31:31 -0700979
980 for node in range(0, clusterCount):
981 nodeNum = node+1
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400982 metricsUp = CLIs[node].topologyEventsMetrics
jenkins8ba10ab2015-03-24 10:31:31 -0700983 jsonStrUp = metricsUp()
984 jsonObj = json.loads(jsonStrUp)
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -0400985
986 if jsonObj:
987 graphTimestamp = jsonObj[graphTimestampKey]['value']
988 deviceTimestamp = jsonObj[deviceTimestampKey]['value']
989 linkTimestamp = jsonObj[linkTimestampKey]['value']
990 else:
991 main.log.error( "Unexpected json object" )
992 graphTimestamp = 0
993 deviceTimestamp = 0
994 linkTimestamp = 0
jenkins8ba10ab2015-03-24 10:31:31 -0700995
jenkins8ba10ab2015-03-24 10:31:31 -0700996 ptUpGraphToOfp = int(graphTimestamp) - int(timestampBeginPtUp)
997 ptUpDeviceToOfp = int(deviceTimestamp) - int(timestampBeginPtUp)
998 ptUpLinkToOfp = int(linkTimestamp) - int(timestampBeginPtUp)
999
1000 if ptUpGraphToOfp > upThresholdMin and\
1001 ptUpGraphToOfp < upThresholdMax and i > iterIgnore:
1002 portUpGraphNodeIter[node][i] = ptUpGraphToOfp
1003 main.log.info("ONOS "+str(nodeNum)+
1004 " port up graph-to-ofp: "+
1005 str(ptUpGraphToOfp) + " ms")
1006 else:
1007 main.log.info("ONOS "+str(nodeNum)+
1008 " port up graph-to-ofp ignored"+
1009 " due to excess in threshold or premature iteration")
1010
1011 if ptUpDeviceToOfp > upThresholdMin and\
1012 ptUpDeviceToOfp < upThresholdMax and i > iterIgnore:
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -04001013 portUpDevNodeIter[node][i] = ptUpDeviceToOfp
jenkins8ba10ab2015-03-24 10:31:31 -07001014 main.log.info("ONOS "+str(nodeNum)+
1015 " port up device-to-ofp: "+
1016 str(ptUpDeviceToOfp) + " ms")
1017 else:
1018 main.log.info("ONOS "+str(nodeNum)+
1019 " port up device-to-ofp ignored"+
1020 " due to excess in threshold or premature iteration")
1021
1022 if ptUpLinkToOfp > upThresholdMin and\
1023 ptUpLinkToOfp < upThresholdMax and i > iterIgnore:
1024 portUpLinkNodeIter[node][i] = ptUpLinkToOfp
1025 main.log.info("ONOS "+str(nodeNum)+
1026 " port up link-to-ofp: "+
1027 str(ptUpLinkToOfp) + " ms")
1028 else:
1029 main.log.info("ONOS "+str(nodeNum)+
1030 " port up link-to-ofp ignored"+
1031 " due to excess in threshold or premature iteration")
1032
jenkins7ead5a82015-03-13 10:28:21 -07001033 dbCmdList = []
1034 for node in range(0, clusterCount):
1035 portUpDevList = []
1036 portUpGraphList = []
jenkins8ba10ab2015-03-24 10:31:31 -07001037 portUpLinkList = []
jenkins7ead5a82015-03-13 10:28:21 -07001038 portDownDevList = []
1039 portDownGraphList = []
jenkins8ba10ab2015-03-24 10:31:31 -07001040 portDownLinkList = []
1041
jenkins7ead5a82015-03-13 10:28:21 -07001042 portUpDevAvg = 0
1043 portUpGraphAvg = 0
jenkins8ba10ab2015-03-24 10:31:31 -07001044 portUpLinkAvg = 0
jenkins7ead5a82015-03-13 10:28:21 -07001045 portDownDevAvg = 0
1046 portDownGraphAvg = 0
jenkins8ba10ab2015-03-24 10:31:31 -07001047 portDownLinkAvg = 0
1048
andrew@onlab.usaa1f0dc2015-04-10 12:18:01 -04001049 # TODO: Update for more pythonic way to get list
1050 # portUpDevList = [item for item in portUpDevNodeIter[node]
1051 # if item > 0.0]
1052
jenkins7ead5a82015-03-13 10:28:21 -07001053 for item in portUpDevNodeIter[node]:
1054 if item > 0.0:
1055 portUpDevList.append(item)
1056
1057 for item in portUpGraphNodeIter[node]:
1058 if item > 0.0:
1059 portUpGraphList.append(item)
1060
jenkins8ba10ab2015-03-24 10:31:31 -07001061 for item in portUpLinkNodeIter[node]:
1062 if item > 0.0:
1063 portUpLinkList.append(item)
1064
jenkins7ead5a82015-03-13 10:28:21 -07001065 for item in portDownDevNodeIter[node]:
1066 if item > 0.0:
1067 portDownDevList.append(item)
1068
1069 for item in portDownGraphNodeIter[node]:
1070 if item > 0.0:
1071 portDownGraphList.append(item)
1072
jenkins8ba10ab2015-03-24 10:31:31 -07001073 for item in portDownLinkNodeIter[node]:
1074 if item > 0.0:
1075 portDownLinkList.append(item)
1076
jenkins7ead5a82015-03-13 10:28:21 -07001077 portUpDevAvg = round(numpy.mean(portUpDevList), 2)
1078 portUpGraphAvg = round(numpy.mean(portUpGraphList), 2)
jenkins8ba10ab2015-03-24 10:31:31 -07001079 portUpLinkAvg = round(numpy.mean(portUpLinkList), 2)
1080
jenkins7ead5a82015-03-13 10:28:21 -07001081 portDownDevAvg = round(numpy.mean(portDownDevList), 2)
1082 portDownGraphAvg = round(numpy.mean(portDownGraphList), 2)
jenkins8ba10ab2015-03-24 10:31:31 -07001083 portDownLinkAvg = round(numpy.mean(portDownLinkList), 2)
1084
jenkins7ead5a82015-03-13 10:28:21 -07001085 portUpStdDev = round(numpy.std(portUpGraphList), 2)
1086 portDownStdDev = round(numpy.std(portDownGraphList), 2)
jenkins8ba10ab2015-03-24 10:31:31 -07001087
jenkins7ead5a82015-03-13 10:28:21 -07001088 main.log.report(' - Node ' + str(node + 1) + ' Summary - ')
1089 main.log.report(' Port up ofp-to-device ' +
jenkins8ba10ab2015-03-24 10:31:31 -07001090 str(portUpDevAvg) + ' ms')
jenkins7ead5a82015-03-13 10:28:21 -07001091 main.log.report(' Port up ofp-to-graph ' +
1092 str(portUpGraphAvg) + ' ms')
jenkins8ba10ab2015-03-24 10:31:31 -07001093 main.log.report(' Port up ofp-to-link ' +
1094 str(portUpLinkAvg) + ' ms')
1095
jenkins7ead5a82015-03-13 10:28:21 -07001096 main.log.report(' Port down ofp-to-device ' +
1097 str(round(portDownDevAvg, 2)) + ' ms')
1098 main.log.report(' Port down ofp-to-graph ' +
1099 str(portDownGraphAvg) + ' ms')
jenkins8ba10ab2015-03-24 10:31:31 -07001100 main.log.report(' Port down ofp-to-link ' +
1101 str(portDownLinkAvg) + ' ms')
1102
jenkins7ead5a82015-03-13 10:28:21 -07001103 dbCmdList.append("INSERT INTO port_latency_tests VALUES('" +
andrew@onlab.us09a4a0c2015-04-09 13:38:13 -04001104 timeToPost + "','port_latency_results'," + jenkinsBuildNumber +
jenkins7ead5a82015-03-13 10:28:21 -07001105 ',' + str(clusterCount) + ",'baremetal" + str(node + 1) +
1106 "'," + str(portUpGraphAvg) + ',' + str(portUpStdDev) +
1107 '' + str(portDownGraphAvg) + ',' + str(portDownStdDev) + ');')
1108
1109 fResult = open(resultPath, 'a')
1110 for line in dbCmdList:
1111 if line:
1112 fResult.write(line + '\n')
1113
1114 fResult.close()
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -04001115
1116 # Delete switches from controller to prepare for next
1117 # set of tests
jenkins7ead5a82015-03-13 10:28:21 -07001118 main.Mininet1.deleteSwController('s1')
1119 main.Mininet1.deleteSwController('s2')
1120 utilities.assert_equals(expect=main.TRUE,
1121 actual=assertion,
1122 onpass='Port discovery latency calculation successful',
1123 onfail='Port discovery test failed')
1124
1125 def CASE4(self, main):
1126 """
1127 Increase number of nodes and initiate CLI
1128
1129 With the most recent implementation, we need a method to
1130 ensure all ONOS nodes are killed, as well as redefine
1131 the cell files to ensure all nodes that will be used
1132 is in the cell file. Otherwise, exceptions will
1133 prohibit test from running successfully.
1134
1135 3/12/15
1136
1137 """
1138 global clusterCount
1139 import time
1140 import os
1141
1142 clusterCount += 2
1143
1144 benchIp = main.params[ 'BENCH' ][ 'ip' ]
1145 features = main.params[ 'ENV' ][ 'cellFeatures' ]
1146 cellName = main.params[ 'ENV' ][ 'cellName' ]
1147 mininetIp = main.params[ 'MN' ][ 'ip1' ]
1148
1149 main.log.report('Increasing cluster size to ' + str(clusterCount))
1150
1151 main.log.step( "Killing all ONOS processes before scale-out" )
1152
1153 for i in range( 1, 8 ):
1154 main.ONOSbench.onosDie(
1155 main.params[ 'CTRL' ][ 'ip'+str(i) ] )
1156 main.ONOSbench.onosUninstall(
1157 main.params[ 'CTRL' ][ 'ip'+str(i) ] )
1158
1159 main.step( "Creating scale-out cell file" )
1160 cellIp = []
1161 for node in range( 1, clusterCount + 1 ):
1162 cellIp.append( main.params[ 'CTRL' ][ 'ip'+str(node) ] )
1163
1164 main.log.info( "Cell Ip list: " + str(cellIp) )
1165 main.ONOSbench.createCellFile( benchIp, cellName, mininetIp,
1166 str(features), *cellIp )
1167
1168 main.step( "Setting cell definition" )
1169 main.ONOSbench.setCell(cellName)
1170
1171 main.step( "Packaging cell definition" )
1172 main.ONOSbench.onosPackage()
1173
jenkins7ead5a82015-03-13 10:28:21 -07001174 for node in range( 1, clusterCount + 1 ):
jenkinsac38ab72015-03-13 11:24:10 -07001175 main.ONOSbench.onosInstall(
1176 node = main.params[ 'CTRL' ][ 'ip'+str(node) ])
1177
1178 time.sleep( 20 )
1179
jenkins7ead5a82015-03-13 10:28:21 -07001180 for node in range( 1, clusterCount + 1):
1181 for i in range( 2 ):
1182 isup = main.ONOSbench.isup(
1183 main.params[ 'CTRL' ][ 'ip'+str(node) ] )
1184 if isup:
1185 main.log.info( "ONOS "+str(node) + " is up\n")
1186 break
1187 if not isup:
1188 main.log.error( "ONOS "+str(node) + " did not start" )
jenkinsac38ab72015-03-13 11:24:10 -07001189
andrew@onlab.usb4cb2b82015-04-03 14:06:09 -04001190 for node in range( 0, clusterCount ):
1191 CLIs[node].startOnosCli( cellIp[node] )
1192
1193 main.step( 'Setting configurations for metrics' )
1194 configParam = 'maxEvents 1'
1195 main.ONOSbench.onosCfgSet( nodeIpList[0], configName, configParam )
1196 configParam = 'maxBatchMs 0'
1197 main.ONOSbench.onosCfgSet( nodeIpList[0], configName, configParam )
1198 configParam = 'maxIdleMs 0'
1199 main.ONOSbench.onosCfgSet( nodeIpList[0], configName, configParam )
1200
1201 main.step( 'Activating essential applications' )
1202 CLIs[0].activateApp( 'org.onosproject.metrics' )
1203 CLIs[0].activateApp( 'org.onosproject.openflow' )
jenkinsac38ab72015-03-13 11:24:10 -07001204