blob: ec0a794b10045dd4d5cf0eebbede83092dbedb7e [file] [log] [blame]
YPZhangb34b7e12016-06-14 14:28:19 -07001"""
2SCPFintentInstallWithdrawLatWithFlowObj:
3 - Test the latency of intent installed and withdrawn
4 - Use Push-test-intents command to push intents
5 - Use Null provider with 7 devices and linear topology
6 - Always push intents between 1/6 and 7/5
7 - The batch size is defined in parm file. (default 1,100)
8 - org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator useFlowObjectives set
9 to true
10 yunpeng@onlab.us
11"""
YPZhang737d0012016-03-24 13:56:24 -070012
13import sys
14import os.path
15
16
17class SCPFintentInstallWithdrawLatWithFlowObj:
YPZhang737d0012016-03-24 13:56:24 -070018 def __init__( self ):
19 self.default = ''
YPZhangb34b7e12016-06-14 14:28:19 -070020
21 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']
33
34 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.cellName = main.params['ENV']['cellName']
70 main.scale = (main.params['SCALE']).split(",")
71 main.dbFileName = main.params['DATABASE']['file']
72 main.timeout = int(main.params['SLEEP']['timeout'])
73 main.startUpSleep = int(main.params['SLEEP']['startup'])
74 main.installSleep = int(main.params['SLEEP']['install'])
75 main.verifySleep = int(main.params['SLEEP']['verify'])
76 main.verifyAttempts = int(main.params['ATTEMPTS']['verify'])
77 main.sampleSize = int(main.params['TEST']['sampleSize'])
78 main.warmUp = int(main.params['TEST']['warmUp'])
79 main.intentsList = (main.params['TEST']['intents']).split(",")
80 main.ingress = main.params['TEST']['ingress']
81 main.egress = main.params['TEST']['egress']
82 main.debug = main.params['TEST']['debug']
83 for i in range(0, len(main.intentsList)):
84 main.intentsList[i] = int(main.intentsList[i])
85 # Create DataBase file
86 main.log.info("Create Database file " + main.dbFileName)
87 resultsDB = open(main.dbFileName, "w+")
88 resultsDB.close()
89
YPZhang737d0012016-03-24 13:56:24 -070090 def CASE1( self, main ):
YPZhangb34b7e12016-06-14 14:28:19 -070091 # Clean up test environment and set up
YPZhang737d0012016-03-24 13:56:24 -070092 import time
YPZhangb34b7e12016-06-14 14:28:19 -070093 main.log.info("Get ONOS cluster IP")
94 print(main.scale)
95 main.numCtrls = int(main.scale[0])
96 main.ONOSip = []
97 main.maxNumBatch = 0
98 main.AllONOSip = main.ONOSbench.getOnosIps()
99 for i in range(main.numCtrls):
100 main.ONOSip.append(main.AllONOSip[i])
101 main.log.info(main.ONOSip)
102 main.CLIs = []
103 main.log.info("Creating list of ONOS cli handles")
104 for i in range(main.numCtrls):
105 main.CLIs.append(getattr(main, 'ONOS%scli' % (i + 1)))
YPZhang737d0012016-03-24 13:56:24 -0700106
YPZhangb34b7e12016-06-14 14:28:19 -0700107 if not main.CLIs:
108 main.log.error("Failed to create the list of ONOS cli handles")
109 main.cleanup()
110 main.exit()
YPZhang737d0012016-03-24 13:56:24 -0700111
YPZhangb34b7e12016-06-14 14:28:19 -0700112 main.commit = main.ONOSbench.getVersion(report=True)
113 main.commit = main.commit.split(" ")[1]
114 main.log.info("Starting up %s node(s) ONOS cluster" % main.numCtrls)
115 main.log.info("Safety check, killing all ONOS processes" +
116 " before initiating environment setup")
YPZhang737d0012016-03-24 13:56:24 -0700117
YPZhangb34b7e12016-06-14 14:28:19 -0700118 for i in range(main.numCtrls):
119 main.ONOSbench.onosDie(main.ONOSip[i])
YPZhang737d0012016-03-24 13:56:24 -0700120
YPZhangb34b7e12016-06-14 14:28:19 -0700121 main.log.info("NODE COUNT = %s" % main.numCtrls)
122 main.ONOSbench.createCellFile(main.ONOSbench.ip_address,
123 main.cellName,
124 main.MN1Ip,
125 main.apps,
126 main.ONOSip)
127 main.step("Apply cell to environment")
128 cellResult = main.ONOSbench.setCell(main.cellName)
129 verifyResult = main.ONOSbench.verifyCell()
130 stepResult = cellResult and verifyResult
131 utilities.assert_equals(expect=main.TRUE,
132 actual=stepResult,
133 onpass="Successfully applied cell to " + \
134 "environment",
135 onfail="Failed to apply cell to environment ")
YPZhang737d0012016-03-24 13:56:24 -0700136
YPZhangb34b7e12016-06-14 14:28:19 -0700137 main.step("Creating ONOS package")
YPZhang737d0012016-03-24 13:56:24 -0700138 packageResult = main.ONOSbench.onosPackage()
YPZhangb34b7e12016-06-14 14:28:19 -0700139 stepResult = packageResult
140 utilities.assert_equals(expect=main.TRUE,
141 actual=stepResult,
142 onpass="Successfully created ONOS package",
143 onfail="Failed to create ONOS package")
YPZhang737d0012016-03-24 13:56:24 -0700144
YPZhangb34b7e12016-06-14 14:28:19 -0700145 main.step("Uninstall ONOS package on all Nodes")
146 uninstallResult = main.TRUE
147 for i in range(int(main.numCtrls)):
148 main.log.info("Uninstalling package on ONOS Node IP: " + main.ONOSip[i])
149 u_result = main.ONOSbench.onosUninstall(main.ONOSip[i])
150 utilities.assert_equals(expect=main.TRUE, actual=u_result,
151 onpass="Test step PASS",
152 onfail="Test step FAIL")
153 uninstallResult = (uninstallResult and u_result)
YPZhang737d0012016-03-24 13:56:24 -0700154
YPZhangb34b7e12016-06-14 14:28:19 -0700155 main.step("Install ONOS package on all Nodes")
156 installResult = main.TRUE
157 for i in range(int(main.numCtrls)):
158 main.log.info("Installing package on ONOS Node IP: " + main.ONOSip[i])
159 i_result = main.ONOSbench.onosInstall(node=main.ONOSip[i])
160 utilities.assert_equals(expect=main.TRUE, actual=i_result,
161 onpass="Test step PASS",
162 onfail="Test step FAIL")
163 installResult = installResult and i_result
YPZhang737d0012016-03-24 13:56:24 -0700164
YPZhangb34b7e12016-06-14 14:28:19 -0700165 main.step("Verify ONOS nodes UP status")
166 statusResult = main.TRUE
167 for i in range(int(main.numCtrls)):
168 main.log.info("ONOS Node " + main.ONOSip[i] + " status:")
169 onos_status = main.ONOSbench.onosStatus(node=main.ONOSip[i])
170 utilities.assert_equals(expect=main.TRUE, actual=onos_status,
171 onpass="Test step PASS",
172 onfail="Test step FAIL")
173 statusResult = (statusResult and onos_status)
174 time.sleep(2)
175 main.step("Start ONOS CLI on all nodes")
176 cliResult = main.TRUE
177 main.log.step(" Start ONOS cli using thread ")
178 startCliResult = main.TRUE
179 pool = []
180 main.threadID = 0
181 for i in range(int(main.numCtrls)):
182 t = main.Thread(target=main.CLIs[i].startOnosCli,
183 threadID=main.threadID,
184 name="startOnosCli",
185 args=[main.ONOSip[i]],
186 kwargs={"onosStartTimeout": main.timeout})
187 pool.append(t)
188 t.start()
189 main.threadID = main.threadID + 1
190 for t in pool:
191 t.join()
192 startCliResult = startCliResult and t.result
193 time.sleep(main.startUpSleep)
YPZhang737d0012016-03-24 13:56:24 -0700194
YPZhangb34b7e12016-06-14 14:28:19 -0700195 # configure apps
196 main.CLIs[0].setCfg("org.onosproject.provider.nil.NullProviders", "deviceCount", value=7)
197 main.CLIs[0].setCfg("org.onosproject.provider.nil.NullProviders", "topoShape", value="linear")
198 main.CLIs[0].setCfg("org.onosproject.provider.nil.NullProviders", "enabled", value="true")
199 main.CLIs[0].setCfg("org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator",
200 "useFlowObjectives", value="true")
201 time.sleep(main.startUpSleep)
YPZhang737d0012016-03-24 13:56:24 -0700202
YPZhangb34b7e12016-06-14 14:28:19 -0700203 # balanceMasters
204 main.CLIs[0].balanceMasters()
YPZhang737d0012016-03-24 13:56:24 -0700205
206 def CASE2( self, main ):
YPZhang737d0012016-03-24 13:56:24 -0700207 import time
208 import numpy
YPZhangb34b7e12016-06-14 14:28:19 -0700209 import json
210 print(main.intentsList)
211 for batchSize in main.intentsList:
212 main.log.report("Intent Batch size: {}".format(batchSize))
213 main.installLatList = []
214 main.withdrawLatList = []
215 validrun = 0
216 invalidrun = 0
217 # we use two variables to control the iteration
218 while validrun <= main.warmUp + main.sampleSize and invalidrun < 20:
219 if validrun >= main.warmUp:
220 main.log.info("================================================")
221 main.log.info("Starting test iteration " + str(validrun - main.warmUp))
222 main.log.info("Total test iteration: " + str(invalidrun + validrun))
223 main.log.info("================================================")
224 else:
225 main.log.info("====================Warm Up=====================")
YPZhang737d0012016-03-24 13:56:24 -0700226
YPZhangb34b7e12016-06-14 14:28:19 -0700227 # push intents
228 installResult = main.CLIs[0].pushTestIntents(main.ingress, main.egress, batchSize,
229 offset=1, options="-i", timeout=main.timeout,
230 getResponse=True)
231 if type(installResult) is str:
232 if "Failure" in installResult:
233 main.log.error("Install Intents failure, ignore this iteration.")
234 if validrun < main.warmUp:
235 validrun += 1
236 continue
237 else:
238 invalidrun += 1
239 continue
YPZhang737d0012016-03-24 13:56:24 -0700240
YPZhangb34b7e12016-06-14 14:28:19 -0700241 try:
242 latency = int(installResult.split()[5])
243 main.log.info(installResult)
244 except:
245 main.log.error("Failed to get latency, ignore this iteration.")
246 main.log.error("Response from ONOS:")
247 print(installResult)
248 if validrun < main.warmUp:
249 validrun += 1
250 continue
251 else:
252 invalidrun += 1
253 continue
YPZhang737d0012016-03-24 13:56:24 -0700254
YPZhangb34b7e12016-06-14 14:28:19 -0700255 if validrun >= main.warmUp:
256 main.installLatList.append(latency)
257 else:
258 invalidrun += 1
259 continue
260 time.sleep(2)
261 # Withdraw Intents
262 withdrawResult = main.CLIs[0].pushTestIntents(main.ingress, main.egress, batchSize,
263 offset=1, options="-w", timeout=main.timeout,
264 getResponse=True)
YPZhang737d0012016-03-24 13:56:24 -0700265
YPZhangb34b7e12016-06-14 14:28:19 -0700266 if type(withdrawResult) is str:
267 if "Failure" in withdrawResult:
268 main.log.error("withdraw Intents failure, ignore this iteration.")
269 if validrun < main.warmUp:
270 validrun += 1
271 continue
272 else:
273 invalidrun += 1
274 continue
YPZhang737d0012016-03-24 13:56:24 -0700275
YPZhangb34b7e12016-06-14 14:28:19 -0700276 try:
277 latency = int(withdrawResult.split()[5])
278 main.log.info(withdrawResult)
279 except:
280 main.log.error("Failed to get latency, ignore this iteration.")
281 main.log.error("Response from ONOS:")
282 print(withdrawResult)
283 if validrun < main.warmUp:
284 validrun += 1
285 continue
286 else:
287 invalidrun += 1
288 continue
YPZhang737d0012016-03-24 13:56:24 -0700289
YPZhangb34b7e12016-06-14 14:28:19 -0700290 if validrun >= main.warmUp:
291 main.withdrawLatList.append(latency)
292 else:
293 invalidrun += 1
294 continue
295 time.sleep(2)
296 main.CLIs[0].purgeWithdrawnIntents()
297 validrun += 1
298 installave = numpy.average(main.installLatList)
299 installstd = numpy.std(main.installLatList)
300 withdrawave = numpy.average(main.withdrawLatList)
301 withdrawstd = numpy.std(main.withdrawLatList)
302 # log report
YPZhang737d0012016-03-24 13:56:24 -0700303 main.log.report("----------------------------------------------------")
YPZhangb34b7e12016-06-14 14:28:19 -0700304 main.log.report("Scale: " + str(main.numCtrls))
305 main.log.report("Intent batch: " + str(batchSize))
306 main.log.report("Install average: {} std: {}".format(installave, installstd))
307 main.log.report("Withdraw average: {} std: {}".format(withdrawave, withdrawstd))
308 # write result to database file
309 if not (numpy.isnan(installave) or numpy.isnan(installstd) or \
310 numpy.isnan(withdrawstd) or numpy.isnan(withdrawave)):
311 databaseString = "'" + main.commit + "',"
312 databaseString += str(main.numCtrls) + ","
313 databaseString += str(batchSize) + ","
314 databaseString += str(installave) + ","
315 databaseString += str(installstd) + ","
316 databaseString += str(withdrawave) + ","
317 databaseString += str(withdrawstd) + "\n"
318 resultsDB = open(main.dbFileName, "a")
319 resultsDB.write(databaseString)
320 resultsDB.close()
321 del main.scale[0]