blob: 2f8c4624568185fd8b8bf529af242adbbc0790ef [file] [log] [blame]
Jon Hall97f859d2014-08-11 14:23:42 -07001'''
2Description: This case is to ensure that in the event of Zookeeper failures (including the leader node)
3the cluster should continue to function properly by the passing of Zookeeper functionality to the
4remaining nodes. In this test, a quorum of the Zookeeper instances must be kept alive.
admin4927d4f2014-07-30 09:47:49 -07005
Jon Hall97f859d2014-08-11 14:23:42 -07006'''
admin4927d4f2014-07-30 09:47:49 -07007class HATestZK:
8
admin4927d4f2014-07-30 09:47:49 -07009
10 def __init__(self) :
11 self.default = ''
12
13 '''
14 CASE1 is to close any existing instances of ONOS, clean out the
15 RAMCloud database, and start up ONOS instances.
16 '''
17 def CASE1(self,main) :
18 main.case("Initial Startup")
19 main.step("Stop ONOS")
adminecb92652014-08-04 09:27:21 -070020 main.ONOS1.stop_all()
21 main.ONOS2.stop_all()
22 main.ONOS3.stop_all()
23 main.ONOS4.stop_all()
24 main.ONOS5.stop_all()
admin4927d4f2014-07-30 09:47:49 -070025 main.ONOS1.stop_rest()
26 main.ONOS2.stop_rest()
27 main.ONOS3.stop_rest()
28 main.ONOS4.stop_rest()
adminecb92652014-08-04 09:27:21 -070029 main.ONOS5.stop_rest()
admin4927d4f2014-07-30 09:47:49 -070030 result = main.ONOS1.status() or main.ONOS2.status() \
adminecb92652014-08-04 09:27:21 -070031 or main.ONOS3.status() or main.ONOS4.status() or main.ONOS5.status()
admin4927d4f2014-07-30 09:47:49 -070032 utilities.assert_equals(expect=main.FALSE,actual=result,onpass="ONOS stopped successfully",onfail="ONOS WAS NOT KILLED PROPERLY")
33 main.step("Startup Zookeeper")
34 main.ZK1.start()
35 main.ZK2.start()
36 main.ZK3.start()
37 main.ZK4.start()
adminecb92652014-08-04 09:27:21 -070038 main.ZK5.start()
admin4927d4f2014-07-30 09:47:49 -070039 result = main.ZK1.isup() and main.ZK2.isup()\
adminecb92652014-08-04 09:27:21 -070040 and main.ZK3.isup() and main.ZK4.isup() and main.ZK5.isup()
admin4927d4f2014-07-30 09:47:49 -070041 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Zookeeper started successfully",onfail="ZOOKEEPER FAILED TO START")
42 main.step("Cleaning RC Database and Starting All")
adminecb92652014-08-04 09:27:21 -070043 main.RC1.del_db()
44 main.RC2.del_db()
45 main.RC3.del_db()
46 main.RC4.del_db()
47 main.RC5.del_db()
admin4927d4f2014-07-30 09:47:49 -070048 main.ONOS1.start_all()
49 main.ONOS2.start_all()
50 main.ONOS3.start_all()
51 main.ONOS4.start_all()
adminecb92652014-08-04 09:27:21 -070052 main.ONOS5.start_all()
Jon Hall1955d642014-08-15 10:17:10 -070053 main.ONOS1.start_rest()
admin4927d4f2014-07-30 09:47:49 -070054 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()
adminecb92652014-08-04 09:27:21 -070061 vm5 = main.RC5.status_coor and main.ONOS5.isup()
62 result = result1 and vm1 and vm2 and vm3 and vm4 and vm5
admin4927d4f2014-07-30 09:47:49 -070063 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Everything started successfully",onfail="EVERYTHING FAILED TO START")
adminecb92652014-08-04 09:27:21 -070064 if result==main.FALSE:
65 main.cleanup()
66 main.exit()
admin4927d4f2014-07-30 09:47:49 -070067
68 '''
69 CASE2
70 '''
71 def CASE2(self,main) :
72 import time
73 import json
74 import re
75 main.log.report("Assigning Controllers")
76 main.case("Assigning Controllers")
77 main.step("Assign Master Controllers")
adminecb92652014-08-04 09:27:21 -070078 for i in range(1,29):
admin4927d4f2014-07-30 09:47:49 -070079 if i ==1:
80 main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1'])
81 elif i>=2 and i<5:
82 main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip2'],port1=main.params['CTRL']['port2'])
83 elif i>=5 and i<8:
84 main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip3'],port1=main.params['CTRL']['port3'])
85 elif i>=8 and i<18:
86 main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip4'],port1=main.params['CTRL']['port4'])
87 elif i>=18 and i<28:
88 main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip5'],port1=main.params['CTRL']['port5'])
89 else:
90 main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1'])
91
92 result = main.TRUE
adminecb92652014-08-04 09:27:21 -070093 for i in range (1,29):
admin4927d4f2014-07-30 09:47:49 -070094 if i==1:
95 response = main.Mininet1.get_sw_controller("s"+str(i))
96 print("Response is " + str(response))
97 if re.search("tcp:"+main.params['CTRL']['ip1'],response):
98 result = result and main.TRUE
99 else:
100 result = main.FALSE
101 elif i>=2 and i<5:
102 response = main.Mininet1.get_sw_controller("s"+str(i))
103 print("Response is " + str(response))
104 if re.search("tcp:"+main.params['CTRL']['ip2'],response):
105 result = result and main.TRUE
106 else:
107 result = main.FALSE
108 elif i>=5 and i<8:
109 response = main.Mininet1.get_sw_controller("s"+str(i))
110 print("Response is " + str(response))
111 if re.search("tcp:"+main.params['CTRL']['ip3'],response):
112 result = result and main.TRUE
113 else:
114 result = main.FALSE
115 elif i>=8 and i<18:
116 response = main.Mininet1.get_sw_controller("s"+str(i))
117 print("Response is " + str(response))
118 if re.search("tcp:"+main.params['CTRL']['ip4'],response):
119 result = result and main.TRUE
120 else:
121 result = main.FALSE
122 elif i>=18 and i<28:
123 response = main.Mininet1.get_sw_controller("s"+str(i))
124 print("Response is " + str(response))
125 if re.search("tcp:"+main.params['CTRL']['ip5'],response):
126 result = result and main.TRUE
127 else:
128 result = main.FALSE
129 else:
130 response = main.Mininet1.get_sw_controller("s"+str(i))
131 print("Response is" + str(response))
132 if re.search("tcp:" +main.params['CTRL']['ip1'],response):
133 result = result and main.TRUE
134 else:
135 result = main.FALSE
adminecb92652014-08-04 09:27:21 -0700136
admin4927d4f2014-07-30 09:47:49 -0700137 utilities.assert_equals(expect = main.TRUE,actual=result,onpass="MasterControllers assigned correctly")
adminecb92652014-08-04 09:27:21 -0700138 for i in range (1,29):
139 main.Mininet1.assign_sw_controller(sw=str(i),count=5,ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1'],ip2=main.params['CTRL']['ip2'],port2=main.params['CTRL']['port2'],ip3=main.params['CTRL']['ip3'],port3=main.params['CTRL']['port3'],ip4=main.params['CTRL']['ip4'],port4=main.params['CTRL']['port4'],ip5=main.params['CTRL']['ip5'],port5=main.params['CTRL']['port5'])
admin4927d4f2014-07-30 09:47:49 -0700140
141 def CASE3(self,main) :
142 import time
143 import json
144 import re
145 main.case("Adding Intents")
146 intentIP = main.params['CTRL']['ip1']
147 intentPort=main.params['INTENTS']['intentPort']
148 intentURL=main.params['INTENTS']['intentURL']
149 count = 1
150 for i in range(8,18):
151 srcMac = '00:00:00:00:00:' + str(hex(i)[2:]).zfill(2)
152 dstMac = '00:00:00:00:00:'+str(hex(i+10)[2:])
153 srcDPID = '00:00:00:00:00:00:30:'+str(i).zfill(2)
154 dstDPID= '00:00:00:00:00:00:60:' +str(i+10)
155 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)
156 count+=1
157 dstDPID = '00:00:00:00:00:00:30:'+str(i).zfill(2)
158 srcDPID= '00:00:00:00:00:00:60:' +str(i+10)
159 dstMac = '00:00:00:00:00:' + str(hex(i)[2:]).zfill(2)
160 srcMac = '00:00:00:00:00:'+str(hex(i+10)[2:])
161 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)
162 count+=1
163 count = 1
164 i = 8
165 result = main.TRUE
166 while i <18 :
167 main.log.info("\n\nh"+str(i)+" is Pinging h" + str(i+10))
168 ping = main.Mininet1.pingHost(src="h"+str(i),target="h"+str(i+10))
169 if ping ==main.FALSE and count <9:
170 count+=1
171 i = 8
172 result = main.FALSE
173 main.log.info("Ping FAILED! Making attempt number "+str(count) + "in 2 seconds")
174 time.sleep(2)
175 elif ping==main.FALSE:
176 main.log.info("PINGS FAILED! MAX RETRIES REACHED!")
177 i=19
178 result = main.FALSE
179 elif ping==main.TRUE:
180 main.log.info("Ping passed!")
181 i+=1
182 result = main.TRUE
183 else:
184 main.log.info("ERROR!!")
185 result = main.ERROR
186 if result==main.FALSE:
187 main.log.info("INTENTS HAVE NOT BEEN INSTALLED CORRECTLY!! EXITING!!!")
188 main.cleanup()
189 main.exit()
190
191
192 def CASE4(self,main) :
193 import time
194 from subprocess import Popen, PIPE
Jon Hall1955d642014-08-15 10:17:10 -0700195 from sts.topology.teston_topology import TestONTopology # assumes that sts is already in you PYTHONPATH
admin4927d4f2014-07-30 09:47:49 -0700196 main.case("Setting up and Gathering data for current state")
admin4927d4f2014-07-30 09:47:49 -0700197
198 main.step("Get the Mastership of each switch")
199 (stdout,stderr)=Popen(["curl",main.params['CTRL']['ip1']+":"+main.params['CTRL']['restPort1']+main.params['CTRL']['switchURL']],stdout=PIPE).communicate()
200 global masterSwitchList1
201 masterSwitchList1 = stdout
202
203 main.step("Get the High Level Intents")
204 (stdout,stderr)=Popen(["curl",main.params['CTRL']['ip1']+":"+main.params['CTRL']['restPort1']+main.params['CTRL']['intentHighURL']],stdout=PIPE).communicate()
205 global highIntentList1
206 highIntentList1 = stdout
207
208 main.step("Get the Low level Intents")
209 (stdout,stderr)=Popen(["curl",main.params['CTRL']['ip1']+":"+main.params['CTRL']['restPort1']+main.params['CTRL']['intentLowURL']],stdout=PIPE).communicate()
210 global lowIntentList1
211 lowIntentList1= stdout
212
213 main.step("Get the OF Table entries")
214 global flows
215 flows=[]
adminecb92652014-08-04 09:27:21 -0700216 for i in range(1,29):
admin4927d4f2014-07-30 09:47:49 -0700217 flows.append(main.Mininet2.get_flowTable("s"+str(i)))
218
219
220 main.step("Start continuous pings")
221 main.Mininet2.pingLong(src=main.params['PING']['source1'],target=main.params['PING']['target1'],pingTime=500)
222 main.Mininet2.pingLong(src=main.params['PING']['source2'],target=main.params['PING']['target2'],pingTime=500)
223 main.Mininet2.pingLong(src=main.params['PING']['source3'],target=main.params['PING']['target3'],pingTime=500)
224 main.Mininet2.pingLong(src=main.params['PING']['source4'],target=main.params['PING']['target4'],pingTime=500)
225 main.Mininet2.pingLong(src=main.params['PING']['source5'],target=main.params['PING']['target5'],pingTime=500)
226 main.Mininet2.pingLong(src=main.params['PING']['source6'],target=main.params['PING']['target6'],pingTime=500)
227 main.Mininet2.pingLong(src=main.params['PING']['source7'],target=main.params['PING']['target7'],pingTime=500)
228 main.Mininet2.pingLong(src=main.params['PING']['source8'],target=main.params['PING']['target8'],pingTime=500)
229 main.Mininet2.pingLong(src=main.params['PING']['source9'],target=main.params['PING']['target9'],pingTime=500)
230 main.Mininet2.pingLong(src=main.params['PING']['source10'],target=main.params['PING']['target10'],pingTime=500)
231
Jon Hall97f859d2014-08-11 14:23:42 -0700232 main.step("Create TestONTopology object")
233 ctrls = []
234 count = 1
235 while True:
236 temp = ()
237 if ('ip' + str(count)) in main.params['CTRL']:
238 temp = temp + (getattr(main,('ONOS' + str(count))),)
239 temp = temp + ("ONOS"+str(count),)
240 temp = temp + (main.params['CTRL']['ip'+str(count)],)
241 temp = temp + (eval(main.params['CTRL']['port'+str(count)]),)
242 ctrls.append(temp)
243 count = count + 1
244 else:
245 break
Jon Hall97f859d2014-08-11 14:23:42 -0700246 global MNTopo
247 Topo = TestONTopology(main.Mininet1, ctrls) # can also add Intent API info for intent operations
248 MNTopo = Topo
249
Jon Hall1955d642014-08-15 10:17:10 -0700250 main.step("Compare ONOS Topology to MN Topology")
251 for n in range(1,5):
252 result = main.Mininet1.compare_topo(MNTopo, main.ONOS1.get_json(main.params['CTRL']['ip'+str(n)]+":"+main.params['CTRL']['restPort'+str(n)]+main.params['TopoRest']))
253 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="ONOS" + str(n) + " Topology matches MN Topology",onfail="ONOS" + str(n) + " Topology does not match MN Topology")
254
admin4927d4f2014-07-30 09:47:49 -0700255
256 def CASE5(self,main) :
257 import re
258 main.case("MAIN COMPONENT FAILURE AND SCENARIO SPECIFIC TESTS")
259 main.step("Zookeeper Server Failure!")
260 result = main.TRUE
261 master1 = main.ZK1.status()
262 print master1
263 if re.search("leader",master1):
admin795d34a2014-08-08 15:14:21 -0700264 main.ZK1.kill()
admin4927d4f2014-07-30 09:47:49 -0700265 main.log.info("ZK1 was Master and Killed! Also Killing ZK2")
admin795d34a2014-08-08 15:14:21 -0700266 main.ZK2.kill()
admin4927d4f2014-07-30 09:47:49 -0700267 time.sleep(10)
268 if re.search("leader",main.ZK3.status()) or re.search("leader",main.ZK4.status()) or re.search("leader",main.ZK5.status()):
269 result = main.TRUE
270 main.log.info("New Leader Elected")
271 else:
272 result = main.FALSE
273 main.log.info("NO NEW ZK LEADER ELECTED!!!")
274 else:
275 master2 = main.ZK2.status()
276 if re.search("leader",master2):
admin795d34a2014-08-08 15:14:21 -0700277 main.ZK2.kill()
admin4927d4f2014-07-30 09:47:49 -0700278 main.log.info("ZK2 was Master and Killed! Also Killing ZK3")
admin795d34a2014-08-08 15:14:21 -0700279 main.ZK3.kill()
admin4927d4f2014-07-30 09:47:49 -0700280 time.sleep(10)
281 if re.search("leader",main.ZK1.status()) or re.search("leader",main.ZK4.status()) or re.search("leader",main.ZK5.status()):
282 result = main.TRUE
283 main.log.info("New Leader Elected")
284 else:
285 result = main.FALSE
286 main.log.info("NO NEW ZK LEADER ELECTED!!!")
287 else:
288 master3 = main.ZK3.status()
289 if re.search("leader",master3):
admin795d34a2014-08-08 15:14:21 -0700290 main.ZK3.kill()
admin4927d4f2014-07-30 09:47:49 -0700291 main.log.info("ZK3 was Master and Killed! Also Killing ZK4")
admin795d34a2014-08-08 15:14:21 -0700292 main.ZK4.kill()
admin4927d4f2014-07-30 09:47:49 -0700293 time.sleep(10)
294 if re.search("leader",main.ZK1.status()) or re.search("leader",main.ZK2.status()) or re.search("leader",main.ZK5.status()):
295 result = main.TRUE
296 main.log.info("New Leader Elected")
297 else:
298 result = main.FALSE
299 main.log.info("NO NEW ZK LEADER ELECTED!!!")
300 else:
301 master4 = main.ZK4.status()
302 if re.search("leader",master4):
admin795d34a2014-08-08 15:14:21 -0700303 main.ZK4.kill()
admin4927d4f2014-07-30 09:47:49 -0700304 main.log.info("ZK4 was Master and Killed! Also Killing ZK5")
admin795d34a2014-08-08 15:14:21 -0700305 main.ZK5.kill()
admin4927d4f2014-07-30 09:47:49 -0700306 time.sleep(10)
307 if re.search("leader",main.ZK1.status()) or re.search("leader",main.ZK2.status()) or re.search("leader",main.ZK3.status()):
308 result = main.TRUE
309 main.log.info("New Leader Elected")
310 else:
311 result = main.FALSE
312 main.log.info("NO NEW ZK LEADER ELECTED!!!")
313 else:
admin795d34a2014-08-08 15:14:21 -0700314 main.ZK5.kill()
admin4927d4f2014-07-30 09:47:49 -0700315 main.log.info("ZK5 was Master and Killed! Also Killing ZK1")
admin795d34a2014-08-08 15:14:21 -0700316 main.ZK1.kill()
admin4927d4f2014-07-30 09:47:49 -0700317 time.sleep(10)
318 if re.search("leader",main.ZK3.status()) or re.search("leader",main.ZK4.status()) or re.search("leader",main.ZK2.status()):
319 result = main.TRUE
320 main.log.info("New Leader Elected")
321 else:
322 result = main.FALSE
323 main.log.info("NO NEW ZK LEADER ELECTED!!!")
adminecb92652014-08-04 09:27:21 -0700324 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="New Leader was Elected!",onfail="NO NEW LEADER WAS ELECTED!!!!")
325
admin4927d4f2014-07-30 09:47:49 -0700326
327
328 def CASE6(self,main) :
329 import os
330 main.case("Running ONOS Constant State Tests")
331 main.step("Get the current In-Memory Topology on each ONOS Instance and Compare it to the Topology before component failure")
332
Jon Hall1955d642014-08-15 10:17:10 -0700333 #NOTE: Expected behavior for this case is for switchs to change mastership to another
334 # controller if the current controller's zk client loses connection with the ZK controller
335 #
336 #main.step("Get the Mastership of each switch and compare to the Mastership before component failure")
337 #(stdout,stderr)=Popen(["curl",main.params['CTRL']['ip1']+":"+main.params['CTRL']['restPort1']+main.params['CTRL']['switchURL']],stdout=PIPE).communicate()
338 #result = main.TRUE
339 #for i in range(1,29):
340 # switchDPID = str(main.Mininet1.getSwitchDPID(switch="s"+str(i)))
341 # switchDPID = switchDPID[:2]+":"+switchDPID[2:4]+":"+switchDPID[4:6]+":"+switchDPID[6:8]+":"+switchDPID[8:10]+":"+switchDPID[10:12]+":"+switchDPID[12:14]+":"+switchDPID[14:]
342 # master1 = main.ZK1.findMaster(switchDPID=switchDPID,switchList=masterSwitchList1)
343 # master2 = main.ZK1.findMaster(switchDPID=switchDPID,switchList=stdout)
344 # if master1 == master2:
345 # #if main.ZK1.findMaster(switchDPID=switchDPID,switchList=masterSwitchList1)==main.ZK1.findMaster(switchDPID=switchDPID,switchList=stdout):
346 # result = result and main.TRUE
347 # else:
348 # result = main.FALSE
349 #utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Mastership of Switches was not changed",onfail="MASTERSHIP OF SWITCHES HAS CHANGED!!!")
350 #result1 = result
admin4927d4f2014-07-30 09:47:49 -0700351
352 main.step("Get the High Level Intents and compare to before component failure")
353 (stdout,stderr)=Popen(["curl",main.params['CTRL']['ip1']+":"+main.params['CTRL']['restPort1']+main.params['CTRL']['intentHighURL']],stdout=PIPE).communicate()
354 changesInIntents=main.ONOS1.comp_intents(preIntents=highIntentList1,postIntents=stdout)
355 if not changesInIntents:
356 result = main.TRUE
357 else:
358 main.log.info("THERE WERE CHANGES TO THE HIGH LEVEL INTENTS! CHANGES WERE: "+str(changesInIntents))
359 result = main.FALSE
360 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="No changes to High level Intents",onfail="CHANGES WERE MADE TO HIGH LEVEL INTENTS")
adminecb92652014-08-04 09:27:21 -0700361 result2=result
admin4927d4f2014-07-30 09:47:49 -0700362
363 main.step("Get the Low level Intents and compare to before component failure")
364 (stdout,stderr)=Popen(["curl",main.params['CTRL']['ip1']+":"+main.params['CTRL']['restPort1']+main.params['CTRL']['intentLowURL']],stdout=PIPE).communicate()
365 changesInIntents=main.ONOS1.comp_low(preIntents=lowIntentList1,postIntents=stdout)
366 if not changesInIntents:
367 result = main.TRUE
368 else:
369 main.log.info("THERE WERE CHANGES TO THE LOW LEVEL INTENTS! CHANGES WERE: "+str(changesInIntents))
370 result = main.FALSE
371 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="No changes to Low level Intents",onfail="CHANGES WERE MADE TO LOW LEVEL INTENTS")
adminecb92652014-08-04 09:27:21 -0700372 result3=result
admin4927d4f2014-07-30 09:47:49 -0700373
374
375 main.step("Get the OF Table entries and compare to before component failure")
376 result = main.TRUE
377 flows2=[]
378 for i in range(27):
379 flows2.append(main.Mininet2.get_flowTable(sw="s"+str(i+1)))
adminecb92652014-08-04 09:27:21 -0700380 result = result and main.Mininet2.flow_comp(flow1=flows[i], flow2=main.Mininet2.get_flowTable(sw="s"+str(i+1)))
admin4927d4f2014-07-30 09:47:49 -0700381 if result == main.FALSE:
382 main.log.info("DIFFERENCES IN FLOW TABLES FOR SWITCH "+str(i))
383 break
384 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="No changes in the flow tables",onfail="CHANGES IN THE FLOW TABLES!!")
adminecb92652014-08-04 09:27:21 -0700385 result4 = result
admin4927d4f2014-07-30 09:47:49 -0700386
387 main.step("Check the continuous pings to ensure that no packets were dropped during component failure")
Jon Hall1955d642014-08-15 10:17:10 -0700388 main.Mininet2.pingKill(main.params['TESTONUSER'], main.params['TESTONIP'])
admin4927d4f2014-07-30 09:47:49 -0700389 result = main.FALSE
390 for i in range(8,18):
391 result = result or main.Mininet2.checkForLoss("/tmp/ping.h"+str(i))
392 if result==main.TRUE:
393 main.log.info("LOSS IN THE PINGS!")
394 elif result == main.ERROR:
395 main.log.info("There are multiple mininet process running!!")
396 else:
397 main.log.info("No Loss in the pings!")
398 utilities.assert_equals(expect=main.FALSE,actual=result,onpass="No Loss of connectivity!",onfail="LOSS OF CONNECTIVITY")
adminecb92652014-08-04 09:27:21 -0700399 result5=not result
Jon Hall97f859d2014-08-11 14:23:42 -0700400
401 main.step("Check that ONOS Topology is consistent with MN Topology")
Jon Hall65bfea12014-08-11 15:11:09 -0700402 ctrls = []
403 count = 1
404 while True:
405 temp = ()
406 if ('ip' + str(count)) in main.params['CTRL']:
407 temp = temp + (getattr(main,('ONOS' + str(count))),)
408 temp = temp + ("ONOS"+str(count),)
409 temp = temp + (main.params['CTRL']['ip'+str(count)],)
410 temp = temp + (eval(main.params['CTRL']['port'+str(count)]),)
411 ctrls.append(temp)
412 count = count + 1
413 else:
414 break
Jon Hall97f859d2014-08-11 14:23:42 -0700415
Jon Hall97f859d2014-08-11 14:23:42 -0700416 result6 = main.TRUE
417 for n in range(1,5):
418 result = main.Mininet1.compare_topo(MNTopo, main.ONOS1.get_json(main.params['CTRL']['ip'+str(n)]+":"+main.params['CTRL']['restPort'+str(n)]+main.params['TopoRest']))
419 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="ONOS" + str(n) + " Topology matches MN Topology",onfail="ONOS" + str(n) + " Topology does not match MN Topology")
420 result6 = result6 and result
Jon Hall1955d642014-08-15 10:17:10 -0700421
422
Jon Hall97f859d2014-08-11 14:23:42 -0700423 result = result1 and result2 and result3 and result4 and result5 and result6
adminecb92652014-08-04 09:27:21 -0700424 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Constant State Tests Passed!",onfail="CONSTANT STATE TESTS FAILED!!")
admin4927d4f2014-07-30 09:47:49 -0700425
adminecb92652014-08-04 09:27:21 -0700426 def CASE7 (self,main):
427 main.case("Killing a link to Ensure that Link Discovery is Working Properly")
428 main.step("Start continuous pings")
429 main.Mininet2.pingLong(src=main.params['PING']['source1'],target=main.params['PING']['target1'],pingTime=500)
430 main.Mininet2.pingLong(src=main.params['PING']['source2'],target=main.params['PING']['target2'],pingTime=500)
431 main.Mininet2.pingLong(src=main.params['PING']['source3'],target=main.params['PING']['target3'],pingTime=500)
432 main.Mininet2.pingLong(src=main.params['PING']['source4'],target=main.params['PING']['target4'],pingTime=500)
433 main.Mininet2.pingLong(src=main.params['PING']['source5'],target=main.params['PING']['target5'],pingTime=500)
434 main.Mininet2.pingLong(src=main.params['PING']['source6'],target=main.params['PING']['target6'],pingTime=500)
435 main.Mininet2.pingLong(src=main.params['PING']['source7'],target=main.params['PING']['target7'],pingTime=500)
436 main.Mininet2.pingLong(src=main.params['PING']['source8'],target=main.params['PING']['target8'],pingTime=500)
437 main.Mininet2.pingLong(src=main.params['PING']['source9'],target=main.params['PING']['target9'],pingTime=500)
438 main.Mininet2.pingLong(src=main.params['PING']['source10'],target=main.params['PING']['target10'],pingTime=500)
admin4927d4f2014-07-30 09:47:49 -0700439
adminecb92652014-08-04 09:27:21 -0700440 main.step("Determine the current number of switches and links")
441 (number,active)=main.ONOS1.num_switch(RestIP=main.params['CTRL']['ip1'])
442 links = main.ONOS1.num_link(RestIP=main.params['CTRL']['ip1'])
Jon Hall1955d642014-08-15 10:17:10 -0700443 main.log.info("Currently there are %s switches %s of which are active, and %s links" %(number,active,links))
adminecb92652014-08-04 09:27:21 -0700444
445 main.step("Kill Link between s3 and s28")
446 main.Mininet1.link(END1="s3",END2="s28",OPTION="down")
447 result = main.ONOS1.check_status_report(main.params['CTRL']['ip1'],active,str(int(links)-2))
448 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Link Down discovered properly",onfail="LINKS NOT DISCOVERED PROPERLY")
449 result1 = result
450 result = main.Mininet1.link(END1="s3",END2="s28",OPTION="up")
admin4927d4f2014-07-30 09:47:49 -0700451
adminecb92652014-08-04 09:27:21 -0700452 main.step("Check for loss in pings when Link is brought down")
Jon Hall1955d642014-08-15 10:17:10 -0700453 main.Mininet2.pingKill(main.params['TESTONUSER'], main.params['TESTONIP'])
adminecb92652014-08-04 09:27:21 -0700454 result = main.FALSE
455 for i in range(8,18):
456 result = result or main.Mininet2.checkForLoss("/tmp/ping.h"+str(i))
457 if result==main.TRUE:
458 main.log.info("LOSS IN THE PINGS!")
459 elif result == main.ERROR:
460 main.log.info("There are multiple mininet process running!!")
461 else:
462 main.log.info("No Loss in the pings!")
463 utilities.assert_equals(expect=main.FALSE,actual=result,onpass="No Loss of connectivity!",onfail="LOSS OF CONNECTIVITY")
Jon Hall1955d642014-08-15 10:17:10 -0700464 result2 = not result
465 result = result1 and result2
466 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Link failure is discovered correctly and no traffic is lost!",onfail="Link Discovery failed or traffic was dropped!!!")
adminecb92652014-08-04 09:27:21 -0700467
admin4927d4f2014-07-30 09:47:49 -0700468
adminecb92652014-08-04 09:27:21 -0700469
470 def CASE8 (self, main) :
471 import time
472 main.case("Killing a switch to ensure switch discovery is working properly")
473 main.step("Start continuous pings")
474 main.Mininet2.pingLong(src=main.params['PING']['source1'],target=main.params['PING']['target1'],pingTime=500)
475 main.Mininet2.pingLong(src=main.params['PING']['source2'],target=main.params['PING']['target2'],pingTime=500)
476 main.Mininet2.pingLong(src=main.params['PING']['source3'],target=main.params['PING']['target3'],pingTime=500)
477 main.Mininet2.pingLong(src=main.params['PING']['source4'],target=main.params['PING']['target4'],pingTime=500)
478 main.Mininet2.pingLong(src=main.params['PING']['source5'],target=main.params['PING']['target5'],pingTime=500)
479 main.Mininet2.pingLong(src=main.params['PING']['source6'],target=main.params['PING']['target6'],pingTime=500)
480 main.Mininet2.pingLong(src=main.params['PING']['source7'],target=main.params['PING']['target7'],pingTime=500)
481 main.Mininet2.pingLong(src=main.params['PING']['source8'],target=main.params['PING']['target8'],pingTime=500)
482 main.Mininet2.pingLong(src=main.params['PING']['source9'],target=main.params['PING']['target9'],pingTime=500)
483 main.Mininet2.pingLong(src=main.params['PING']['source10'],target=main.params['PING']['target10'],pingTime=500)
484
485 main.step("Determine the current number of switches and links")
486 (number,active)=main.ONOS1.num_switch(RestIP=main.params['CTRL']['ip1'])
487 links = main.ONOS1.num_link(RestIP=main.params['CTRL']['ip1'])
Jon Hall1955d642014-08-15 10:17:10 -0700488 main.log.info("Currently there are %s switches %s of which are active, and %s links" %(number,active,links))
adminecb92652014-08-04 09:27:21 -0700489
490 main.step("Kill s28 ")
491 main.Mininet2.del_switch("s28")
Jon Hall1955d642014-08-15 10:17:10 -0700492 time.sleep(45)
adminecb92652014-08-04 09:27:21 -0700493 result = main.ONOS1.check_status_report(main.params['CTRL']['ip1'],str(int(active)-1),str(int(links)-4))
494 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Switch Discovery is Working",onfail="Switch Discovery FAILED TO WORK PROPERLY!")
495
496 main.step("Add back s28")
497 main.Mininet2.add_switch("s28")
498 main.Mininet1.assign_sw_controller(sw="28",ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1'])
499 main.Mininet1.assign_sw_controller(sw="28",count=5,ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1'],ip2=main.params['CTRL']['ip2'],port2=main.params['CTRL']['port2'],ip3=main.params['CTRL']['ip3'],port3=main.params['CTRL']['port3'],ip4=main.params['CTRL']['ip4'],port4=main.params['CTRL']['port4'],ip5=main.params['CTRL']['ip5'],port5=main.params['CTRL']['port5'])
Jon Hall1955d642014-08-15 10:17:10 -0700500 time.sleep(45)
adminecb92652014-08-04 09:27:21 -0700501 result = main.ONOS1.check_status_report(main.params['CTRL']['ip1'],active,links)
502 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Switch Discovery is Working",onfail="Switch Discovery FAILED TO WORK PROPERLY!")
503 result1=result
504
505 main.step("Checking for Traffic Loss")
Jon Hall1955d642014-08-15 10:17:10 -0700506 main.Mininet2.pingKill(main.params['TESTONUSER'], main.params['TESTONIP'])
adminecb92652014-08-04 09:27:21 -0700507 result = main.FALSE
508 for i in range(8,18):
509 result = result or main.Mininet2.checkForLoss("/tmp/ping.h"+str(i))
510 if result==main.TRUE:
511 main.log.info("LOSS IN THE PINGS!")
512 elif result == main.ERROR:
513 main.log.info("There are multiple mininet process running!!")
514 else:
515 main.log.info("No Loss in the pings!")
516 utilities.assert_equals(expect=main.FALSE,actual=result,onpass="No Loss of connectivity!",onfail="LOSS OF CONNECTIVITY")
517 result = not result and result1
518 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Switch Discovered Correctly and No Loss of traffic",onfail="Switch discovery failed or there was loss of traffic")
admin4927d4f2014-07-30 09:47:49 -0700519
admin795d34a2014-08-08 15:14:21 -0700520# Authored by James Lee
521# Just wanted to see how many people were paying attention here.
522# Elayne Boosler once said "I have six locks on my door all in a row
523# When I go out, I lock every other one. I figure no matter how long
524# somebody stands there picking the locks, they are always locking three"
525