blob: 5a06353de2a5705c9d9f5b5a7b3f6d2a4ca9bc4e [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()
You Wang3b148ea2016-06-20 20:33:42 -0700205 time.sleep(main.startUpSleep)
YPZhang737d0012016-03-24 13:56:24 -0700206
207 def CASE2( self, main ):
YPZhang737d0012016-03-24 13:56:24 -0700208 import time
209 import numpy
YPZhangb34b7e12016-06-14 14:28:19 -0700210 import json
211 print(main.intentsList)
212 for batchSize in main.intentsList:
213 main.log.report("Intent Batch size: {}".format(batchSize))
214 main.installLatList = []
215 main.withdrawLatList = []
216 validrun = 0
217 invalidrun = 0
218 # we use two variables to control the iteration
219 while validrun <= main.warmUp + main.sampleSize and invalidrun < 20:
220 if validrun >= main.warmUp:
221 main.log.info("================================================")
222 main.log.info("Starting test iteration " + str(validrun - main.warmUp))
223 main.log.info("Total test iteration: " + str(invalidrun + validrun))
224 main.log.info("================================================")
225 else:
226 main.log.info("====================Warm Up=====================")
YPZhang737d0012016-03-24 13:56:24 -0700227
YPZhangb34b7e12016-06-14 14:28:19 -0700228 # push intents
229 installResult = main.CLIs[0].pushTestIntents(main.ingress, main.egress, batchSize,
230 offset=1, options="-i", timeout=main.timeout,
231 getResponse=True)
232 if type(installResult) is str:
233 if "Failure" in installResult:
234 main.log.error("Install Intents failure, ignore this iteration.")
235 if validrun < main.warmUp:
236 validrun += 1
237 continue
238 else:
239 invalidrun += 1
240 continue
YPZhang737d0012016-03-24 13:56:24 -0700241
YPZhangb34b7e12016-06-14 14:28:19 -0700242 try:
243 latency = int(installResult.split()[5])
244 main.log.info(installResult)
245 except:
246 main.log.error("Failed to get latency, ignore this iteration.")
247 main.log.error("Response from ONOS:")
248 print(installResult)
249 if validrun < main.warmUp:
250 validrun += 1
251 continue
252 else:
253 invalidrun += 1
254 continue
YPZhang737d0012016-03-24 13:56:24 -0700255
YPZhangb34b7e12016-06-14 14:28:19 -0700256 if validrun >= main.warmUp:
257 main.installLatList.append(latency)
258 else:
259 invalidrun += 1
260 continue
261 time.sleep(2)
262 # Withdraw Intents
263 withdrawResult = main.CLIs[0].pushTestIntents(main.ingress, main.egress, batchSize,
264 offset=1, options="-w", timeout=main.timeout,
265 getResponse=True)
YPZhang737d0012016-03-24 13:56:24 -0700266
YPZhangb34b7e12016-06-14 14:28:19 -0700267 if type(withdrawResult) is str:
268 if "Failure" in withdrawResult:
269 main.log.error("withdraw Intents failure, ignore this iteration.")
270 if validrun < main.warmUp:
271 validrun += 1
272 continue
273 else:
274 invalidrun += 1
275 continue
YPZhang737d0012016-03-24 13:56:24 -0700276
YPZhangb34b7e12016-06-14 14:28:19 -0700277 try:
278 latency = int(withdrawResult.split()[5])
279 main.log.info(withdrawResult)
280 except:
281 main.log.error("Failed to get latency, ignore this iteration.")
282 main.log.error("Response from ONOS:")
283 print(withdrawResult)
284 if validrun < main.warmUp:
285 validrun += 1
286 continue
287 else:
288 invalidrun += 1
289 continue
YPZhang737d0012016-03-24 13:56:24 -0700290
YPZhangb34b7e12016-06-14 14:28:19 -0700291 if validrun >= main.warmUp:
292 main.withdrawLatList.append(latency)
293 else:
294 invalidrun += 1
295 continue
296 time.sleep(2)
297 main.CLIs[0].purgeWithdrawnIntents()
298 validrun += 1
299 installave = numpy.average(main.installLatList)
300 installstd = numpy.std(main.installLatList)
301 withdrawave = numpy.average(main.withdrawLatList)
302 withdrawstd = numpy.std(main.withdrawLatList)
303 # log report
YPZhang737d0012016-03-24 13:56:24 -0700304 main.log.report("----------------------------------------------------")
YPZhangb34b7e12016-06-14 14:28:19 -0700305 main.log.report("Scale: " + str(main.numCtrls))
306 main.log.report("Intent batch: " + str(batchSize))
307 main.log.report("Install average: {} std: {}".format(installave, installstd))
308 main.log.report("Withdraw average: {} std: {}".format(withdrawave, withdrawstd))
309 # write result to database file
310 if not (numpy.isnan(installave) or numpy.isnan(installstd) or \
311 numpy.isnan(withdrawstd) or numpy.isnan(withdrawave)):
312 databaseString = "'" + main.commit + "',"
313 databaseString += str(main.numCtrls) + ","
314 databaseString += str(batchSize) + ","
315 databaseString += str(installave) + ","
316 databaseString += str(installstd) + ","
317 databaseString += str(withdrawave) + ","
318 databaseString += str(withdrawstd) + "\n"
319 resultsDB = open(main.dbFileName, "a")
320 resultsDB.write(databaseString)
321 resultsDB.close()
322 del main.scale[0]