blob: fa861cf55853370511798ed7636b949af84f474e [file] [log] [blame]
YPZhangfebf7302016-05-24 16:45:56 -07001# SCPFintentRerouteLat
2"""
3SCPFintentRerouteLat
4 - Test Intent Reroute Latency
5 - Test Algorithm:
6 1. Start Null Provider reroute Topology
7 2. Using Push-test-intents to push batch size intents from switch 1 to switch 7
8 3. Cut the link between switch 3 and switch 4 (the path will reroute to switch 8)
9 4. Get the topology time stamp
10 5. Get Intent reroute(Installed) time stamp from each nodes
11 6. Use the latest intent time stamp subtract topology time stamp
12 - This test will run 5 warm up by default, warm up iteration can be setup in Param file
13 - The intent batch size will default set to 1, 100, and 1000, also can be set in Param file
14 - The unit of the latency result is milliseconds
15"""
cameron@onlab.us78b89652015-07-08 15:21:03 -070016
17class SCPFintentRerouteLat:
YPZhangfebf7302016-05-24 16:45:56 -070018 def __init__(self):
cameron@onlab.us78b89652015-07-08 15:21:03 -070019 self.default = ''
20
YPZhangfebf7302016-05-24 16:45:56 -070021 def CASE0( self, main ):
22 '''
23 - GIT
24 - BUILDING ONOS
25 Pull specific ONOS branch, then Build ONOS ono ONOS Bench.
26 This step is usually skipped. Because in a Jenkins driven automated
27 test env. We want Jenkins jobs to pull&build for flexibility to handle
28 different versions of ONOS.
29 - Construct tests variables
30 '''
31 gitPull = main.params['GIT']['gitPull']
32 gitBranch = main.params['GIT']['gitBranch']
cameron@onlab.us78b89652015-07-08 15:21:03 -070033
YPZhangfebf7302016-05-24 16:45:56 -070034 main.case("Pull onos branch and build onos on Teststation.")
35
36 if gitPull == 'True':
37 main.step("Git Checkout ONOS branch: " + gitBranch)
38 stepResult = main.ONOSbench.gitCheckout(branch=gitBranch)
39 utilities.assert_equals(expect=main.TRUE,
40 actual=stepResult,
41 onpass="Successfully checkout onos branch.",
42 onfail="Failed to checkout onos branch. Exiting test...")
43 if not stepResult: main.exit()
44
45 main.step("Git Pull on ONOS branch:" + gitBranch)
46 stepResult = main.ONOSbench.gitPull()
47 utilities.assert_equals(expect=main.TRUE,
48 actual=stepResult,
49 onpass="Successfully pull onos. ",
50 onfail="Failed to pull onos. Exiting test ...")
51 if not stepResult: main.exit()
52
53 main.step("Building ONOS branch: " + gitBranch)
54 stepResult = main.ONOSbench.cleanInstall(skipTest=True)
55 utilities.assert_equals(expect=main.TRUE,
56 actual=stepResult,
57 onpass="Successfully build onos.",
58 onfail="Failed to build onos. Exiting test...")
59 if not stepResult: main.exit()
60
61 else:
62 main.log.warn("Skipped pulling onos and Skipped building ONOS")
63
64 main.apps = main.params['ENV']['cellApps']
65 main.BENCHUser = main.params['BENCH']['user']
66 main.BENCHIp = main.params['BENCH']['ip1']
67 main.MN1Ip = main.params['MN']['ip1']
68 main.maxNodes = int(main.params['max'])
69 main.skipMvn = main.params['TEST']['skipCleanInstall']
70 main.cellName = main.params['ENV']['cellName']
71 main.scale = (main.params['SCALE']).split(",")
72 main.dbFileName = main.params['DATABASE']['file']
73 main.timeout = int(main.params['SLEEP']['timeout'])
74 main.startUpSleep = int(main.params['SLEEP']['startup'])
75 main.installSleep = int(main.params['SLEEP']['install'])
76 main.verifySleep = int(main.params['SLEEP']['verify'])
77 main.verifyAttempts = int(main.params['ATTEMPTS']['verify'])
78 main.sampleSize = int(main.params['TEST']['sampleSize'])
79 main.warmUp = int(main.params['TEST']['warmUp'])
80 main.intentsList = (main.params['TEST']['intents']).split(",")
81 main.ingress = main.params['TEST']['ingress']
82 main.egress = main.params['TEST']['egress']
83 main.debug = main.params['TEST']['debug']
84 for i in range(0, len(main.intentsList)):
85 main.intentsList[i] = int(main.intentsList[i])
86 # Create DataBase file
87 main.log.info("Create Database file " + main.dbFileName)
88 resultsDB = open(main.dbFileName, "w+")
89 resultsDB.close()
90
91 def CASE1( self, main ):
92 '''
93 clean up test environment and set up
94 '''
cameron@onlab.us78b89652015-07-08 15:21:03 -070095 import time
96
YPZhangfebf7302016-05-24 16:45:56 -070097 main.log.info("Get ONOS cluster IP")
98 print(main.scale)
99 main.numCtrls = int(main.scale[0])
100 main.ONOSip = []
101 main.maxNumBatch = 0
102 main.AllONOSip = main.ONOSbench.getOnosIps()
103 for i in range(main.numCtrls):
104 main.ONOSip.append(main.AllONOSip[i])
105 main.log.info(main.ONOSip)
106 main.CLIs = []
107 main.log.info("Creating list of ONOS cli handles")
108 for i in range(main.numCtrls):
109 main.CLIs.append(getattr(main, 'ONOS%scli' % (i + 1)))
cameron@onlab.us78b89652015-07-08 15:21:03 -0700110
YPZhangfebf7302016-05-24 16:45:56 -0700111 if not main.CLIs:
112 main.log.error("Failed to create the list of ONOS cli handles")
113 main.cleanup()
114 main.exit()
cameron@onlab.us78b89652015-07-08 15:21:03 -0700115
YPZhangfebf7302016-05-24 16:45:56 -0700116 main.commit = main.ONOSbench.getVersion(report=True)
117 main.commit = main.commit.split(" ")[1]
118 main.log.info("Starting up %s node(s) ONOS cluster" % main.numCtrls)
119 main.log.info("Safety check, killing all ONOS processes" +
120 " before initiating environment setup")
cameron@onlab.us78b89652015-07-08 15:21:03 -0700121
YPZhangfebf7302016-05-24 16:45:56 -0700122 for i in range(main.numCtrls):
123 main.ONOSbench.onosDie(main.ONOSip[i])
cameron@onlab.us78b89652015-07-08 15:21:03 -0700124
YPZhangfebf7302016-05-24 16:45:56 -0700125 main.log.info("NODE COUNT = %s" % main.numCtrls)
YPZhangfebf7302016-05-24 16:45:56 -0700126 main.ONOSbench.createCellFile(main.ONOSbench.ip_address,
127 main.cellName,
128 main.MN1Ip,
129 main.apps,
130 main.ONOSip)
131 main.step("Apply cell to environment")
132 cellResult = main.ONOSbench.setCell(main.cellName)
133 verifyResult = main.ONOSbench.verifyCell()
134 stepResult = cellResult and verifyResult
135 utilities.assert_equals(expect=main.TRUE,
136 actual=stepResult,
137 onpass="Successfully applied cell to " + \
138 "environment",
139 onfail="Failed to apply cell to environment ")
cameron@onlab.us78b89652015-07-08 15:21:03 -0700140
YPZhangfebf7302016-05-24 16:45:56 -0700141 main.step("Creating ONOS package")
Jon Hall4ba53f02015-07-29 13:07:41 -0700142 packageResult = main.ONOSbench.onosPackage()
YPZhangfebf7302016-05-24 16:45:56 -0700143 stepResult = packageResult
144 utilities.assert_equals(expect=main.TRUE,
145 actual=stepResult,
146 onpass="Successfully created ONOS package",
147 onfail="Failed to create ONOS package")
cameron@onlab.us78b89652015-07-08 15:21:03 -0700148
YPZhangfebf7302016-05-24 16:45:56 -0700149 main.step("Uninstall ONOS package on all Nodes")
150 uninstallResult = main.TRUE
151 for i in range(int(main.numCtrls)):
152 main.log.info("Uninstalling package on ONOS Node IP: " + main.ONOSip[i])
153 u_result = main.ONOSbench.onosUninstall(main.ONOSip[i])
154 utilities.assert_equals(expect=main.TRUE, actual=u_result,
155 onpass="Test step PASS",
156 onfail="Test step FAIL")
157 uninstallResult = (uninstallResult and u_result)
Jon Hall4ba53f02015-07-29 13:07:41 -0700158
YPZhangfebf7302016-05-24 16:45:56 -0700159 main.step("Install ONOS package on all Nodes")
160 installResult = main.TRUE
161 for i in range(int(main.numCtrls)):
162 main.log.info("Installing package on ONOS Node IP: " + main.ONOSip[i])
163 i_result = main.ONOSbench.onosInstall(node=main.ONOSip[i])
164 utilities.assert_equals(expect=main.TRUE, actual=i_result,
165 onpass="Test step PASS",
166 onfail="Test step FAIL")
167 installResult = installResult and i_result
cameron@onlab.us78b89652015-07-08 15:21:03 -0700168
YPZhangfebf7302016-05-24 16:45:56 -0700169 main.step("Verify ONOS nodes UP status")
170 statusResult = main.TRUE
171 for i in range(int(main.numCtrls)):
172 main.log.info("ONOS Node " + main.ONOSip[i] + " status:")
173 onos_status = main.ONOSbench.onosStatus(node=main.ONOSip[i])
174 utilities.assert_equals(expect=main.TRUE, actual=onos_status,
175 onpass="Test step PASS",
176 onfail="Test step FAIL")
177 statusResult = (statusResult and onos_status)
178 time.sleep(2)
179 main.step("Start ONOS CLI on all nodes")
180 cliResult = main.TRUE
181 main.log.step(" Start ONOS cli using thread ")
182 startCliResult = main.TRUE
183 pool = []
184 main.threadID = 0
185 for i in range(int(main.numCtrls)):
186 t = main.Thread(target=main.CLIs[i].startOnosCli,
187 threadID=main.threadID,
188 name="startOnosCli",
189 args=[main.ONOSip[i]],
190 kwargs={"onosStartTimeout": main.timeout})
191 pool.append(t)
192 t.start()
193 main.threadID = main.threadID + 1
194 for t in pool:
195 t.join()
196 startCliResult = startCliResult and t.result
197 time.sleep(main.startUpSleep)
Jon Hall4ba53f02015-07-29 13:07:41 -0700198
YPZhangfebf7302016-05-24 16:45:56 -0700199 # configure apps
200 main.CLIs[0].setCfg("org.onosproject.provider.nil.NullProviders", "deviceCount", value=8)
201 main.CLIs[0].setCfg("org.onosproject.provider.nil.NullProviders", "topoShape", value="reroute")
202 main.CLIs[0].setCfg("org.onosproject.provider.nil.NullProviders", "enabled", value="true")
203 main.CLIs[0].setCfg("org.onosproject.store.flow.impl.DistributedFlowRuleStore", "backupEnabled", value="false")
cameron@onlab.us78b89652015-07-08 15:21:03 -0700204
YPZhangfebf7302016-05-24 16:45:56 -0700205 time.sleep(main.startUpSleep)
cameron@onlab.us78b89652015-07-08 15:21:03 -0700206
YPZhangfebf7302016-05-24 16:45:56 -0700207 # Balance Master
208 main.CLIs[0].balanceMasters()
209 if len(main.ONOSip) > 1:
210 main.CLIs[0].deviceRole("null:0000000000000003", main.ONOSip[0])
211 main.CLIs[0].deviceRole("null:0000000000000004", main.ONOSip[0])
cameron@onlab.us78b89652015-07-08 15:21:03 -0700212
213 def CASE2( self, main ):
cameron@onlab.us78b89652015-07-08 15:21:03 -0700214 import time
215 import numpy
216 import datetime
YPZhangfebf7302016-05-24 16:45:56 -0700217 import json
218 # from scipy import stats
cameron@onlab.us78b89652015-07-08 15:21:03 -0700219
220 ts = time.time()
YPZhangfebf7302016-05-24 16:45:56 -0700221 print(main.intentsList)
222 for batchSize in main.intentsList:
223 main.log.report("Intent Batch size: " + str(batchSize) + "\n ")
224 main.LatencyList = []
YPZhang8742d2e2016-06-16 15:31:58 -0700225 validRun = 0
226 invalidRun = 0
227 while validRun <= main.warmUp + main.sampleSize and invalidRun <= 20:
228 if validRun >= main.warmUp:
YPZhangfebf7302016-05-24 16:45:56 -0700229 main.log.info("================================================")
YPZhang8742d2e2016-06-16 15:31:58 -0700230 main.log.info("Starting test iteration: {} ".format(validRun - main.warmUp))
231 main.log.info("Total iteration: {}".format(validRun + invalidRun))
YPZhangfebf7302016-05-24 16:45:56 -0700232 main.log.info("================================================")
cameron@onlab.us78b89652015-07-08 15:21:03 -0700233 else:
YPZhangfebf7302016-05-24 16:45:56 -0700234 main.log.info("====================Warm Up=====================")
cameron@onlab.us78b89652015-07-08 15:21:03 -0700235
YPZhangfebf7302016-05-24 16:45:56 -0700236 # push intents
237 main.CLIs[0].pushTestIntents(main.ingress, main.egress, batchSize,
238 offset=1, options="-i", timeout=main.timeout)
cameron@onlab.us78b89652015-07-08 15:21:03 -0700239
YPZhangfebf7302016-05-24 16:45:56 -0700240 # check links and flows
241 k = 0
242 verify = main.FALSE
243 linkCheck = 0
244 flowsCheck = 0
245 while k <= main.verifyAttempts:
246 time.sleep(main.verifySleep)
247 summary = json.loads(main.CLIs[0].summary(timeout=main.timeout))
248 linkCheck = summary.get("links")
249 flowsCheck = summary.get("flows")
250 if linkCheck == 16 and flowsCheck == batchSize * 7:
251 main.log.info("links: {}, flows: {} ".format(linkCheck, flowsCheck))
252 verify = main.TRUE
253 break
254 k += 1
255 if not verify:
256 main.log.warn("Links or flows number are not match!")
257 main.log.warn("links: {}, flows: {} ".format(linkCheck, flowsCheck))
YPZhang8742d2e2016-06-16 15:31:58 -0700258 # bring back topology
259 main.CLIs[0].removeAllIntents(purge=True, sync=True, timeout=main.timeout)
260 time.sleep(1)
261 main.CLIs[0].purgeWithdrawnIntents()
262 main.CLIs[0].setCfg("org.onosproject.provider.nil.NullProviders", "deviceCount", value=0)
263 main.CLIs[0].setCfg("org.onosproject.provider.nil.NullProviders", "enabled", value="false")
264 main.CLIs[0].setCfg("org.onosproject.provider.nil.NullProviders", "deviceCount", value=8)
265 main.CLIs[0].setCfg("org.onosproject.provider.nil.NullProviders", "enabled", value="true")
266 if validRun >= main.warmUp:
267 invalidRun += 1
268 continue
269 else:
270 validRun += 1
271 continue
cameron@onlab.us78b89652015-07-08 15:21:03 -0700272
YPZhangfebf7302016-05-24 16:45:56 -0700273 # Bring link down
274 main.CLIs[0].link("0000000000000004/1", "0000000000000003/2", "down",
275 timeout=main.timeout, showResponse=False)
276 verify = main.FALSE
277 k = 0
278 topoManagerLog = ""
279 while k <= main.verifyAttempts:
280 time.sleep(main.verifySleep)
281 summary = json.loads(main.CLIs[0].summary(timeout=main.timeout))
282 linkCheck = summary.get("links")
283 flowsCheck = summary.get("flows")
284 if linkCheck == 14:
285 main.log.info("links: {}, flows: {} ".format(linkCheck, flowsCheck))
286 verify = main.TRUE
287 break
288 k += 1
289 if not verify:
290 main.log.warn("Links number are not match in TopologyManager log!")
291 main.log.warn(topoManagerLog)
YPZhang8742d2e2016-06-16 15:31:58 -0700292 # bring back topology
293 main.CLIs[0].removeAllIntents(purge=True, sync=True, timeout=main.timeout)
294 time.sleep(1)
295 main.CLIs[0].purgeWithdrawnIntents()
296 main.CLIs[0].setCfg("org.onosproject.provider.nil.NullProviders", "deviceCount", value=0)
297 main.CLIs[0].setCfg("org.onosproject.provider.nil.NullProviders", "enabled", value="false")
298 main.CLIs[0].setCfg("org.onosproject.provider.nil.NullProviders", "deviceCount", value=8)
299 main.CLIs[0].setCfg("org.onosproject.provider.nil.NullProviders", "enabled", value="true")
300 if validRun >= main.warmUp:
301 invalidRun += 1
302 continue
303 else:
304 validRun += 1
305 continue
cameron@onlab.us78b89652015-07-08 15:21:03 -0700306
YPZhangfebf7302016-05-24 16:45:56 -0700307 try:
308 # expect twice to clean the pexpect buffer
309 main.ONOSbench.handle.sendline("")
310 main.ONOSbench.handle.expect("\$")
311 main.ONOSbench.handle.expect("\$")
312 # send line by using bench, can't use driver because pexpect buffer problem
313 cmd = "onos-ssh $OC1 cat /opt/onos/log/karaf.log | grep TopologyManager| tail -1"
314 main.ONOSbench.handle.sendline(cmd)
315 time.sleep(1)
316 main.ONOSbench.handle.expect(":~")
317 topoManagerLog = main.ONOSbench.handle.before
318 topoManagerLogTemp = topoManagerLog.splitlines()
319 # To make sure we get correct topology log
320 for lines in topoManagerLogTemp:
321 if "creationTime" in lines:
322 topoManagerLog = lines
323 main.log.info("Topology Manager log:")
324 print(topoManagerLog)
325 cutTimestamp = float(topoManagerLog.split("creationTime=")[1].split(",")[0])
326 except:
327 main.log.error("Topology Log is not correct!")
328 print(topoManagerLog)
YPZhang8742d2e2016-06-16 15:31:58 -0700329 # bring back topology
330 verify = main.FALSE
331 main.CLIs[0].removeAllIntents(purge=True, sync=True, timeout=main.timeout)
332 time.sleep(1)
333 main.CLIs[0].purgeWithdrawnIntents()
334 main.CLIs[0].setCfg("org.onosproject.provider.nil.NullProviders", "deviceCount", value=0)
335 main.CLIs[0].setCfg("org.onosproject.provider.nil.NullProviders", "enabled", value="false")
336 main.CLIs[0].setCfg("org.onosproject.provider.nil.NullProviders", "deviceCount", value=8)
337 main.CLIs[0].setCfg("org.onosproject.provider.nil.NullProviders", "enabled", value="true")
338 if validRun >= main.warmUp:
339 invalidRun += 1
340 else:
341 validRun += 1
YPZhangfebf7302016-05-24 16:45:56 -0700342 # If we got wrong Topology log, we should skip this iteration, and continue for next one
343 continue
344
345 installedTemp = []
346 time.sleep(1)
347 for cli in main.CLIs:
348 tempJson = json.loads(cli.intentsEventsMetrics())
349 Installedtime = tempJson.get('intentInstalledTimestamp').get('value')
350 installedTemp.append(float(Installedtime))
351 for i in range(0, len(installedTemp)):
352 main.log.info("ONOS Node {} Installed Time stemp: {}".format((i + 1), installedTemp[i]))
353 maxInstallTime = float(max(installedTemp))
YPZhang8742d2e2016-06-16 15:31:58 -0700354 if validRun >= main.warmUp and verify:
YPZhangfebf7302016-05-24 16:45:56 -0700355 main.log.info("Installed time stemp: {0:f}".format(maxInstallTime))
356 main.log.info("CutTimestamp: {0:f}".format(cutTimestamp))
357 # Both timeStemps are milliseconds
358 main.log.info("Latency: {0:f}".format(float(maxInstallTime - cutTimestamp)))
359 main.LatencyList.append(float(maxInstallTime - cutTimestamp))
YPZhang8742d2e2016-06-16 15:31:58 -0700360 # We get valid latency, validRun + 1
361 validRun += 1
YPZhangfebf7302016-05-24 16:45:56 -0700362
363 # Verify Summary after we bring up link, and withdrawn intents
364 main.CLIs[0].link("0000000000000004/1", "0000000000000003/2", "up",
365 timeout=main.timeout)
366 k = 0
367 verify = main.FALSE
368 linkCheck = 0
369 flowsCheck = 0
370 while k <= main.verifyAttempts:
371 time.sleep(main.verifySleep)
372 main.CLIs[0].removeAllIntents(purge=True, sync=True, timeout=main.timeout)
373 time.sleep(1)
374 main.CLIs[0].purgeWithdrawnIntents()
375 summary = json.loads(main.CLIs[0].summary())
376 linkCheck = summary.get("links")
377 flowsCheck = summary.get("flows")
378 intentCheck = summary.get("intents")
379 if linkCheck == 16 and flowsCheck == 0 and intentCheck == 0:
380 main.log.info("links: {}, flows: {}, intents: {} ".format(linkCheck, flowsCheck, intentCheck))
381 verify = main.TRUE
382 break
383 k += 1
384 if not verify:
385 main.log.error("links, flows, or intents are not correct!")
386 main.log.info("links: {}, flows: {}, intents: {} ".format(linkCheck, flowsCheck, intentCheck))
YPZhang8742d2e2016-06-16 15:31:58 -0700387 # bring back topology
388 main.log.info("Bring back topology...")
389 main.CLIs[0].removeAllIntents(purge=True, sync=True, timeout=main.timeout)
390 time.sleep(1)
391 main.CLIs[0].purgeWithdrawnIntents()
392 main.CLIs[0].setCfg("org.onosproject.provider.nil.NullProviders", "deviceCount", value=0)
393 main.CLIs[0].setCfg("org.onosproject.provider.nil.NullProviders", "enabled", value="false")
394 main.CLIs[0].setCfg("org.onosproject.provider.nil.NullProviders", "deviceCount", value=8)
395 main.CLIs[0].setCfg("org.onosproject.provider.nil.NullProviders", "enabled", value="true")
YPZhangfebf7302016-05-24 16:45:56 -0700396 continue
397
398 aveLatency = 0
399 stdLatency = 0
400 aveLatency = numpy.average(main.LatencyList)
401 stdLatency = numpy.std(main.LatencyList)
402 main.log.report("Scale: " + str(main.numCtrls) + " \tIntent batch: " + str(batchSize))
403 main.log.report("Latency average:................" + str(aveLatency))
404 main.log.report("Latency standard deviation:....." + str(stdLatency))
cameron@onlab.us78b89652015-07-08 15:21:03 -0700405 main.log.report("________________________________________________________")
406
YPZhang8742d2e2016-06-16 15:31:58 -0700407 if not (numpy.isnan(aveLatency) or numpy.isnan(stdLatency)):
408 # check if got NaN for result
409 resultsDB = open(main.dbFileName, "a")
410 resultsDB.write("'" + main.commit + "',")
411 resultsDB.write(str(main.numCtrls) + ",")
412 resultsDB.write(str(batchSize) + ",")
413 resultsDB.write(str(aveLatency) + ",")
414 resultsDB.write(str(stdLatency) + "\n")
415 resultsDB.close()
YPZhangfebf7302016-05-24 16:45:56 -0700416 del main.scale[0]