blob: 92b49652675932e3ca239050100f51b2fe6dfd7a [file] [log] [blame]
adminecb92652014-08-04 09:27:21 -07001
2class HATest1:
3
4 global topology
5 global masterSwitchList
6 global highIntentList
7 global lowIntentList
8 global flows
9 flows = []
10
11 def __init__(self) :
12 self.default = ''
13
14 '''
15 CASE1 is to close any existing instances of ONOS, clean out the
16 RAMCloud database, and start up ONOS instances.
17 '''
18 def CASE1(self,main) :
19 main.case("Initial Startup")
20 main.step("Stop ONOS")
21 if not main.ONOS1.status():
22 main.ONOS1.stop_all()
23 if not main.ONOS1.status():
24 main.ONOS2.stop_all()
25 if not main.ONOS1.status():
26 main.ONOS3.stop_all()
27 if not main.ONOS1.status():
28 main.ONOS4.stop_all()
29 main.ONOS1.stop_rest()
30 main.ONOS2.stop_rest()
31 main.ONOS3.stop_rest()
32 main.ONOS4.stop_rest()
33 result = main.ONOS1.status() or main.ONOS2.status() \
34 or main.ONOS3.status() or main.ONOS4.status()
35 utilities.assert_equals(expect=main.FALSE,actual=result,onpass="ONOS stopped successfully",onfail="ONOS WAS NOT KILLED PROPERLY")
36 main.step("Startup Zookeeper")
37 main.ZK1.start()
38 main.ZK2.start()
39 main.ZK3.start()
40 main.ZK4.start()
41 result = main.ZK1.isup() and main.ZK2.isup()\
42 and main.ZK3.isup() and main.ZK4.isup
43 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Zookeeper started successfully",onfail="ZOOKEEPER FAILED TO START")
44 main.step("Cleaning RC Database and Starting All")
45 main.RC1.deldb()
46 main.RC2.deldb()
47 main.RC3.deldb()
48 main.RC4.deldb()
49 main.ONOS1.start_all()
50 main.ONOS2.start_all()
51 main.ONOS3.start_all()
52 main.ONOS4.start_all()
53 main.ONOS1.start_rest()
54 main.step("Testing Startup")
55 result1 = main.ONOS1.rest_status()
56 vm1 = main.RC1.status_coor and main.RC1.status_serv and \
57 main.ONOS1.isup()
58 vm2 = main.RC2.status_coor and main.ONOS2.isup()
59 vm3 = main.RC3.status_coor and main.ONOS3.isup()
60 vm4 = main.RC4.status_coor and main.ONOS4.isup()
61 result = result1 and vm1 and vm2 and vm3 and vm4
62 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Everything started successfully",onfail="EVERYTHING FAILED TO START")
63
64 '''
65 CASE2
66 '''
67 def CASE2(self,main) :
68 import time
69 import json
70 import re
71 main.log.report("Assigning Controllers")
72 main.case("Assigning Controllers")
73 main.step("Assign Master Controllers")
74 for i in range(1,28):
75 if i ==1:
76 main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1'])
77 elif i>=2 and i<5:
78 main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip2'],port1=main.params['CTRL']['port2'])
79 elif i>=5 and i<8:
80 main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip3'],port1=main.params['CTRL']['port3'])
81 elif i>=8 and i<18:
82 main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip4'],port1=main.params['CTRL']['port4'])
83 elif i>=18 and i<28:
84 main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip5'],port1=main.params['CTRL']['port5'])
85 else:
86 main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1'])
87
88 result = main.TRUE
89 for i in range (1,28):
90 if i==1:
91 response = main.Mininet1.get_sw_controller("s"+str(i))
92 print("Response is " + str(response))
93 if re.search("tcp:"+main.params['CTRL']['ip1'],response):
94 result = result and main.TRUE
95 else:
96 result = main.FALSE
97 elif i>=2 and i<5:
98 response = main.Mininet1.get_sw_controller("s"+str(i))
99 print("Response is " + str(response))
100 if re.search("tcp:"+main.params['CTRL']['ip2'],response):
101 result = result and main.TRUE
102 else:
103 result = main.FALSE
104 elif i>=5 and i<8:
105 response = main.Mininet1.get_sw_controller("s"+str(i))
106 print("Response is " + str(response))
107 if re.search("tcp:"+main.params['CTRL']['ip3'],response):
108 result = result and main.TRUE
109 else:
110 result = main.FALSE
111 elif i>=8 and i<18:
112 response = main.Mininet1.get_sw_controller("s"+str(i))
113 print("Response is " + str(response))
114 if re.search("tcp:"+main.params['CTRL']['ip4'],response):
115 result = result and main.TRUE
116 else:
117 result = main.FALSE
118 elif i>=18 and i<28:
119 response = main.Mininet1.get_sw_controller("s"+str(i))
120 print("Response is " + str(response))
121 if re.search("tcp:"+main.params['CTRL']['ip5'],response):
122 result = result and main.TRUE
123 else:
124 result = main.FALSE
125 else:
126 response = main.Mininet1.get_sw_controller("s"+str(i))
127 print("Response is" + str(response))
128 if re.search("tcp:" +main.params['CTRL']['ip1'],response):
129 result = result and main.TRUE
130 else:
131 result = main.FALSE
132 utilities.assert_equals(expect = main.TRUE,actual=result,onpass="MasterControllers assigned correctly")
133
134 def CASE3(self,main) :
135 import time
136 import json
137 import re
138 main.case("Adding Intents")
139 intentIP = main.params['CTRL']['ip1']
140 intentPort=main.params['INTENTS']['intentPort']
141 intentURL=main.params['INTENTS']['intentURL']
142 count = 1
143 for i in range(8,18):
144 srcMac = '00:00:00:00:00:' + str(hex(i)[2:]).zfill(2)
145 dstMac = '00:00:00:00:00:'+str(hex(i+10)[2:])
146 srcDPID = '00:00:00:00:00:00:30:'+str(i).zfill(2)
147 dstDPID= '00:00:00:00:00:00:60:' +str(i+10)
148 main.ONOS1.add_intent(intent_id=str(count),src_dpid=srcDPID,dst_dpid=dstDPID,src_mac=srcMac,dst_mac=dstMac,intentIP=intentIP,intentPort=intentPort,intentURL=intentURL)
149 count+=1
150 dstDPID = '00:00:00:00:00:00:30:'+str(i).zfill(2)
151 srcDPID= '00:00:00:00:00:00:60:' +str(i+10)
152 dstMac = '00:00:00:00:00:' + str(hex(i)[2:]).zfill(2)
153 srcMac = '00:00:00:00:00:'+str(hex(i+10)[2:])
154 main.ONOS1.add_intent(intent_id=str(count),src_dpid=srcDPID,dst_dpid=dstDPID,src_mac=srcMac,dst_mac=dstMac,intentIP=intentIP,intentPort=intentPort,intentURL=intentURL)
155 count+=1
156 count = 1
157 i = 8
158 result = main.TRUE
159 while i <18 :
160 main.log.info("\n\nh"+str(i)+" is Pinging h" + str(i+10))
161 ping = main.Mininet1.pingHost(src="h"+str(i),target="h"+str(i+10))
162 if ping ==main.FALSE and count <9:
163 count+=1
164 i = 8
165 result = main.FALSE
166 main.log.info("Ping FAILED! Making attempt number "+str(count) + "in 2 seconds")
167 time.sleep(2)
168 elif ping==main.FALSE:
169 main.log.info("PINGS FAILED! MAX RETRIES REACHED!")
170 i=19
171 result = main.FALSE
172 elif ping==main.TRUE:
173 main.log.info("Ping passed!")
174 i+=1
175 result = main.TRUE
176 else:
177 main.log.info("ERROR!!")
178 result = main.ERROR
179 if result==main.FALSE:
180 main.log.info("INTENTS HAVE NOT BEEN INSTALLED CORRECTLY!! EXITING!!!")
181 main.cleanup()
182 main.exit()
183
184
185 def CASE4(self,main) :
186 import time
187 from subprocess import Popen, PIPE
188 main.case("Setting up and Gathering data for current state")
189 main.step("Get the current In-Memory Topology on each ONOS Instance")
190
191 '''
192 ctrls = []
193 count = 1
194 while True:
195 temp = ()
196 if ('ip'+str(count)) in main.params['CTRL']:
197 temp = temp+(getattr(main,('ONOS'+str(count))),)
198 temp = temp + ("ONOS"+str(count),)
199 temp = temp + (main.params['CTRL']['ip'+str(count)],)
200 temp = temp + (eval(main.params['CTRL']['port'+str(count)]),)
201 ctrls.append(temp)
202 count+=1
203 else:
204 break
205 topo_result = main.TRUE
206
207 for n in range(1,count):
208 temp_result = main.Mininet1.compare_topo(ctrls,main.ONOS1.get_json(main.params['CTRL']['ip'+str(n)]+":"+main.params['CTRL']['restPort'+str(n)]+main.params['TopoRest']))
209 '''
210
211 main.step("Get the Mastership of each switch")
212 (stdout,stderr)=Popen(["curl",main.params['CTRL']['ip1']+":"+main.params['CTRL']['restPort1']+main.params['CTRL']['switchURL']],stdout=PIPE).communicate()
213 global masterSwitchList1
214 masterSwitchList1 = stdout
215
216 main.step("Get the High Level Intents")
217 (stdout,stderr)=Popen(["curl",main.params['CTRL']['ip1']+":"+main.params['CTRL']['restPort1']+main.params['CTRL']['intentHighURL']],stdout=PIPE).communicate()
218 global highIntentList1
219 highIntentList1 = stdout
220
221 main.step("Get the Low level Intents")
222 (stdout,stderr)=Popen(["curl",main.params['CTRL']['ip1']+":"+main.params['CTRL']['restPort1']+main.params['CTRL']['intentLowURL']],stdout=PIPE).communicate()
223 global lowIntentList1
224 lowIntentList1= stdout
225
226 main.step("Get the OF Table entries")
227 global flows
228 flows=[]
229 for i in range(1,28):
230 print main.Mininet2.get_flowTable("s"+str(i))
231 flows.append(main.Mininet2.get_flowTable("s"+str(i)))
232
233
234 main.step("Start continuous pings")
235 main.Mininet2.pingLong(src=main.params['PING']['source1'],target=main.params['PING']['target1'],pingTime=500)
236 main.Mininet2.pingLong(src=main.params['PING']['source2'],target=main.params['PING']['target2'],pingTime=500)
237 main.Mininet2.pingLong(src=main.params['PING']['source3'],target=main.params['PING']['target3'],pingTime=500)
238 main.Mininet2.pingLong(src=main.params['PING']['source4'],target=main.params['PING']['target4'],pingTime=500)
239 main.Mininet2.pingLong(src=main.params['PING']['source5'],target=main.params['PING']['target5'],pingTime=500)
240 main.Mininet2.pingLong(src=main.params['PING']['source6'],target=main.params['PING']['target6'],pingTime=500)
241 main.Mininet2.pingLong(src=main.params['PING']['source7'],target=main.params['PING']['target7'],pingTime=500)
242 main.Mininet2.pingLong(src=main.params['PING']['source8'],target=main.params['PING']['target8'],pingTime=500)
243 main.Mininet2.pingLong(src=main.params['PING']['source9'],target=main.params['PING']['target9'],pingTime=500)
244 main.Mininet2.pingLong(src=main.params['PING']['source10'],target=main.params['PING']['target10'],pingTime=500)
245
246
247 def CASE5(self,main) :
248 import re
249 main.case("MAIN COMPONENT FAILURE AND SCENARIO SPECIFIC TESTS")
250 main.step("Zookeeper Server Failure!")
251 result = main.TRUE
252 master1 = main.ZK1.status()
253 print master1
254 if re.search("leader",master1):
255 main.ZK1.stop()
256 main.log.info("ZK1 was Master and Killed! Also Killing ZK2")
257 main.ZK2.stop()
258 time.sleep(10)
259 if re.search("leader",main.ZK3.status()) or re.search("leader",main.ZK4.status()) or re.search("leader",main.ZK5.status()):
260 result = main.TRUE
261 main.log.info("New Leader Elected")
262 else:
263 result = main.FALSE
264 main.log.info("NO NEW ZK LEADER ELECTED!!!")
265 else:
266 master2 = main.ZK2.status()
267 if re.search("leader",master2):
268 main.ZK2.stop()
269 main.log.info("ZK2 was Master and Killed! Also Killing ZK3")
270 main.ZK3.stop()
271 time.sleep(10)
272 if re.search("leader",main.ZK1.status()) or re.search("leader",main.ZK4.status()) or re.search("leader",main.ZK5.status()):
273 result = main.TRUE
274 main.log.info("New Leader Elected")
275 else:
276 result = main.FALSE
277 main.log.info("NO NEW ZK LEADER ELECTED!!!")
278 else:
279 master3 = main.ZK3.status()
280 if re.search("leader",master3):
281 main.ZK3.stop()
282 main.log.info("ZK3 was Master and Killed! Also Killing ZK4")
283 main.ZK4.stop()
284 time.sleep(10)
285 if re.search("leader",main.ZK1.status()) or re.search("leader",main.ZK2.status()) or re.search("leader",main.ZK5.status()):
286 result = main.TRUE
287 main.log.info("New Leader Elected")
288 else:
289 result = main.FALSE
290 main.log.info("NO NEW ZK LEADER ELECTED!!!")
291 else:
292 master4 = main.ZK4.status()
293 if re.search("leader",master4):
294 main.ZK4.stop()
295 main.log.info("ZK4 was Master and Killed! Also Killing ZK5")
296 main.ZK5.stop()
297 time.sleep(10)
298 if re.search("leader",main.ZK1.status()) or re.search("leader",main.ZK2.status()) or re.search("leader",main.ZK3.status()):
299 result = main.TRUE
300 main.log.info("New Leader Elected")
301 else:
302 result = main.FALSE
303 main.log.info("NO NEW ZK LEADER ELECTED!!!")
304 else:
305 main.ZK5.stop()
306 main.log.info("ZK5 was Master and Killed! Also Killing ZK1")
307 main.ZK1.stop()
308 time.sleep(10)
309 if re.search("leader",main.ZK3.status()) or re.search("leader",main.ZK4.status()) or re.search("leader",main.ZK2.status()):
310 result = main.TRUE
311 main.log.info("New Leader Elected")
312 else:
313 result = main.FALSE
314 main.log.info("NO NEW ZK LEADER ELECTED!!!")
315
316
317 def CASE6(self,main) :
318 import os
319 main.case("Running ONOS Constant State Tests")
320 main.step("Get the current In-Memory Topology on each ONOS Instance and Compare it to the Topology before component failure")
321
322 main.step("Get the Mastership of each switch and compare to the Mastership before component failure")
323 (stdout,stderr)=Popen(["curl",main.params['CTRL']['ip1']+":"+main.params['CTRL']['restPort1']+main.params['CTRL']['switchURL']],stdout=PIPE).communicate()
324 result = main.TRUE
325 for i in range(1,28):
326 if main.ZK1.findMaster(switchDPID="s"+str(i),switchList=masterSwitchList1)==main.ZK1.findMaster(switchDPID="s"+str(i),switchList=stdout):
327 result = result and main.TRUE
328 else:
329 result = main.FALSE
330 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Mastership of Switches was not changed",onfail="MASTERSHIP OF SWITCHES HAS CHANGED!!!")
331
332 main.step("Get the High Level Intents and compare to before component failure")
333 (stdout,stderr)=Popen(["curl",main.params['CTRL']['ip1']+":"+main.params['CTRL']['restPort1']+main.params['CTRL']['intentHighURL']],stdout=PIPE).communicate()
334 changesInIntents=main.ONOS1.comp_intents(preIntents=highIntentList1,postIntents=stdout)
335 if not changesInIntents:
336 result = main.TRUE
337 else:
338 main.log.info("THERE WERE CHANGES TO THE HIGH LEVEL INTENTS! CHANGES WERE: "+str(changesInIntents))
339 result = main.FALSE
340 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="No changes to High level Intents",onfail="CHANGES WERE MADE TO HIGH LEVEL INTENTS")
341
342 main.step("Get the Low level Intents and compare to before component failure")
343 (stdout,stderr)=Popen(["curl",main.params['CTRL']['ip1']+":"+main.params['CTRL']['restPort1']+main.params['CTRL']['intentLowURL']],stdout=PIPE).communicate()
344 changesInIntents=main.ONOS1.comp_low(preIntents=lowIntentList1,postIntents=stdout)
345 if not changesInIntents:
346 result = main.TRUE
347 else:
348 main.log.info("THERE WERE CHANGES TO THE LOW LEVEL INTENTS! CHANGES WERE: "+str(changesInIntents))
349 result = main.FALSE
350 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="No changes to Low level Intents",onfail="CHANGES WERE MADE TO LOW LEVEL INTENTS")
351
352
353 main.step("Get the OF Table entries and compare to before component failure")
354 result = main.TRUE
355 flows2=[]
356 for i in range(27):
357 flows2.append(main.Mininet2.get_flowTable(sw="s"+str(i+1)))
358 result = result and main.Mininet2.flow_comp(flow1=flows[i], flow2=main.Mininet2.get_flowTable(sw="s"+str(i+1)))
359 print flows[i]
360 print flows2[i]
361 if result == main.FALSE:
362 main.log.info("DIFFERENCES IN FLOW TABLES FOR SWITCH "+str(i))
363 break
364 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="No changes in the flow tables",onfail="CHANGES IN THE FLOW TABLES!!")
365
366 main.step("Check the continuous pings to ensure that no packets were dropped during component failure")
367 main.Mininet2.pingKill()
368 result = main.FALSE
369 for i in range(8,18):
370 result = result or main.Mininet2.checkForLoss("/tmp/ping.h"+str(i))
371 if result==main.TRUE:
372 main.log.info("LOSS IN THE PINGS!")
373 elif result == main.ERROR:
374 main.log.info("There are multiple mininet process running!!")
375 else:
376 main.log.info("No Loss in the pings!")
377 utilities.assert_equals(expect=main.FALSE,actual=result,onpass="No Loss of connectivity!",onfail="LOSS OF CONNECTIVITY")
378
379
380
381
382