blob: a0c9f987958064c2a40a030d73a6d231e80e99ed [file] [log] [blame]
admin07529932013-11-22 14:58:28 -08001
2class OnosSanity4nodes :
3
4 def __init__(self) :
5 self.default = ''
6
7#**********************************************************************************************************************************************************************************************
8#Test startup
9#Tests the startup of Zookeeper1, Cassandra1, and ONOS1 to be certain that all started up successfully
10 def CASE1(self,main) : #Check to be sure ZK, Cass, and ONOS are up, then get ONOS version
11 import time
12 main.log.report("Pulling latest code from github to all nodes")
13 main.ONOS1.git_pull()
14 main.ONOS2.git_pull()
15 main.ONOS3.git_pull()
16 main.ONOS4.git_pull()
17 main.Cassandra1.start()
18 main.Cassandra2.start()
19 main.Cassandra3.start()
20 main.Cassandra4.start()
21 time.sleep(20)
22 main.ONOS1.drop_keyspace()
23 main.ONOS1.start()
24 time.sleep(10)
25 main.ONOS2.start()
26 main.ONOS3.start()
27 main.ONOS4.start()
28 main.ONOS1.start_rest()
29 time.sleep(5)
30 test= main.ONOS1.rest_status()
31 if test == main.FALSE:
32 main.ONOS1.start_rest()
33 main.ONOS1.get_version()
34 main.log.report("Startup check Zookeeper1, Cassandra1, and ONOS1 connections")
35 main.case("Checking if the startup was clean...")
36 main.step("Testing startup Zookeeper")
37 data = main.Zookeeper1.isup()
38 utilities.assert_equals(expect=main.TRUE,actual=data,onpass="Zookeeper is up!",onfail="Zookeeper is down...")
39 main.step("Testing startup Cassandra")
40 data = main.Cassandra1.isup()
41 if data == main.FALSE:
42 main.Cassandra1.stop()
43 main.Cassandra2.stop()
44 main.Cassandra3.stop()
45 main.Cassandra4.stop()
46
47 time.sleep(5)
48
49 main.Cassandra1.start()
50 main.Cassandra2.start()
51 main.Cassandra3.start()
52 main.Cassandra4.start()
53 utilities.assert_equals(expect=main.TRUE,actual=data,onpass="Cassandra is up!",onfail="Cassandra is down...")
54 main.step("Testing startup ONOS")
55 data = main.ONOS1.isup()
56 if data == main.FALSE:
57 main.log.report("Something is funny... restarting ONOS")
58 main.ONOS1.stop()
59 time.sleep(3)
60 main.ONOS1.start()
61 time.sleep(5)
62 data = main.ONOS1.isup()
63 utilities.assert_equals(expect=main.TRUE,actual=data,onpass="ONOS is up and running!",onfail="ONOS didn't start...")
64
65#**********************************************************************************************************************************************************************************************
66#Assign Controllers
67#This test first checks the ip of a mininet host, to be certain that the mininet exists(Host is defined in Params as <CASE1><destination>).
68#Then the program assignes each ONOS instance a single controller to a switch(To be the initial master), then assigns all controllers.
69#NOTE: The reason why all four controllers are assigned although one was already assigned as the master is due to the 'ovs-vsctl set-controller' command erases all present controllers if
70# the controllers already assigned to the switch are not specified.
71
72 def CASE2(self,main) : #Make sure mininet exists, then assign controllers to switches
73 import time
74 main.log.report("Check if mininet started properly, then assign controllers ONOS 1,2,3 and 4")
75 main.case("Checking if one MN host exists")
76 main.step("Host IP Checking using checkIP")
77 result = main.Mininet1.checkIP(main.params['CASE1']['destination'])
78 main.step("Verifying the result")
79 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Host IP address configured",onfail="Host IP address not configured")
80 main.step("assigning ONOS controllers to switches")
81 for i in range(25):
82 if i < 3:
83 j=i+1
84 main.Mininet1.assign_sw_controller(sw=str(j),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1'])
85 time.sleep(1)
86 main.Mininet1.assign_sw_controller(sw=str(j),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'])
87 elif i >= 3 and i < 5:
88 j=i+1
89 main.Mininet1.assign_sw_controller(sw=str(j),ip1=main.params['CTRL']['ip2'],port1=main.params['CTRL']['port2'])
90 time.sleep(1)
91 main.Mininet1.assign_sw_controller(sw=str(j),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'])
92 elif i >= 5 and i < 15:
93 j=i+1
94 main.Mininet1.assign_sw_controller(sw=str(j),ip1=main.params['CTRL']['ip3'],port1=main.params['CTRL']['port3'])
95 time.sleep(1)
96 main.Mininet1.assign_sw_controller(sw=str(j),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'])
97 else:
98 j=i+16
99 main.Mininet1.assign_sw_controller(sw=str(j),ip1=main.params['CTRL']['ip4'],port1=main.params['CTRL']['port4'])
100 time.sleep(1)
101 main.Mininet1.assign_sw_controller(sw=str(j),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'])
102 main.Mininet1.get_sw_controller("s1")
103
104# **********************************************************************************************************************************************************************************************
105#Add Flows
106#Deletes any remnant flows from any previous test, add flows from the file labeled <FLOWDEF>, then runs the check flow test
107#NOTE: THE FLOWDEF FILE MUST BE PRESENT ON TESTON VM!!! TestON will copy the file from its home machine into /tmp/flowtmp on the machine the ONOS instance is present on
108
109 def CASE3(self,main) : #Delete any remnant flows, then add flows, and time how long it takes flow tables to update
110 main.log.report("Delete any flows from previous tests, then add flows from FLOWDEF file, then wait for switch flow tables to update")
111 import time
112 main.case("Taking care of these flows!")
113 main.step("Cleaning out any leftover flows...")
114 main.ONOS1.delete_flow("all")
115 time.sleep(5)
116 strtTime = time.time()
117 main.ONOS1.add_flow(main.params['FLOWDEF'])
118 main.case("Checking flows")
119 tmp = main.FALSE
120 count = 1
121 main.log.info("Wait for flows to be pushed to the switches, then check")
122 while tmp == main.FALSE:
123 main.step("Waiting")
124 time.sleep(10)
125 main.step("Checking")
126 tmp = main.ONOS1.check_flow()
127 if tmp == main.FALSE and count < 6:
128 count = count + 1
129 main.log.report("Flow failed, waiting 10 seconds then making attempt number "+str(count))
130 elif tmp == main.FALSE and count == 6:
131 result1 = main.FALSE
132 break
133 else:
134 result1 = main.TRUE
135 break
136 endTime = time.time()
137 if result1 == main.TRUE:
138 main.log.report("\n\t\t\t\tTime to add flows: "+str(round(endTime-strtTime,2))+" seconds")
139 else:
140 main.log.report("\tFlows failed check")
141
142 strtTime = time.time()
143 count = 1
144 i = 6
145 while i < 16 :
146 main.log.info("\n\t\t\t\th"+str(i)+" IS PINGING h"+str(i+25) )
147 ping = main.Mininet1.pingHost(src="h"+str(i),target="h"+str(i+25))
148 if ping == main.FALSE and count < 3:
149 count = count + 1
150 i = 6
151 main.log.info("Ping failed, making attempt number "+str(count)+" in 10 seconds")
152 time.sleep(10)
153 elif ping == main.FALSE and count ==3:
154 main.log.error("Ping test failed")
155 i = 17
156 result2 = main.FALSE
157 elif ping == main.TRUE:
158 i = i + 1
159 result2 = main.TRUE
160 endTime = time.time()
161 if result2 == main.TRUE:
162 main.log.report("\tTime to complete ping test: "+str(round(endTime-strtTime,2))+" seconds")
163 else:
164 main.log.report("\tPING TEST FAIL")
165
166 result3 = main.ONOS1.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links'])
167 main.step("Verifying the result")
168 utilities.assert_equals(expect=main.TRUE,actual=result1 and result2 and result3,onpass="Flow check PASS",onfail="Flow check FAIL")
169
170#**********************************************************************************************************************************************************************************************
171#This test case removes Controllers 2,3, and 4 then performs a ping test.
172#The assign controller is used because the ovs-vsctl module deletes all current controllers when a new controller is assigned.
173#The ping test performs single pings on hosts from opposite sides of the topology. If one ping fails, the test waits 5 seconds before trying again.
174#If the ping test fails 6 times, then the test case will return false
175
176 def CASE4(self,main) :
177 main.log.report("Remove ONOS 2,3,4 then ping until all hosts are reachable or fail after 6 attempts")
178 import time
179 for i in range(25):
180 if i < 15:
181 j=i+1
182 main.Mininet1.assign_sw_controller(sw=str(j),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1']) #Assigning a single controller removes all other controllers
183 else:
184 j=i+16
185 main.Mininet1.assign_sw_controller(sw=str(j),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1'])
186
187 strtTime = time.time()
188 result = main.ONOS1.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links'])
189 for i in range(2):
190 if result == main.FALSE:
191 time.sleep(5)
192 result = main.ONOS1.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links'])
193 else:
194 break
195
196 count = 1
197 i = 6
198 while i < 16 :
199 main.log.info("\n\t\t\t\th"+str(i)+" IS PINGING h"+str(i+25) )
200 ping = main.Mininet1.pingHost(src="h"+str(i),target="h"+str(i+25))
201 if ping == main.FALSE and count < 6:
202 count = count + 1
203 i = 6
204 main.log.info("Ping failed, making attempt number "+str(count)+" in 5 seconds")
205 time.sleep(5)
206 elif ping == main.FALSE and count ==6:
207 main.log.error("Ping test failed")
208 i = 17
209 result = main.FALSE
210 elif ping == main.TRUE:
211 i = i + 1
212 result = main.TRUE
213 endTime = time.time()
214 if result == main.TRUE:
215 main.log.report("\tTime to complete ping test: "+str(round(endTime-strtTime,2))+" seconds")
216 else:
217 main.log.report("\tPING TEST FAIL")
218 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="NO PACKET LOSS, HOST IS REACHABLE",onfail="PACKET LOST, HOST IS NOT REACHABLE")
219
220# **********************************************************************************************************************************************************************************************
221#This test case restores the controllers removed by Case 4 then performs a ping test.
222
223 def CASE5(self,main) :
224 main.log.report("Restore ONOS 2,3,4 then ping until all hosts are reachable or fail after 6 attempts")
225 import time
226 for i in range(25):
227 if i < 15:
228 j=i+1
229 main.Mininet1.assign_sw_controller(sw=str(j),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'])
230 else:
231 j=i+16
232 main.Mininet1.assign_sw_controller(sw=str(j),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'])
233
234 strtTime = time.time()
235 result = main.ONOS1.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links'])
236 for i in range(2):
237 if result == main.FALSE:
238 time.sleep(5)
239 result = main.ONOS1.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links'])
240 else:
241 break
242
243 count = 1
244 i = 6
245 while i < 16 :
246 main.log.info("\n\t\t\t\th"+str(i)+" IS PINGING h"+str(i+25) )
247 ping = main.Mininet1.pingHost(src="h"+str(i),target="h"+str(i+25))
248 if ping == main.FALSE and count < 6:
249 count = count + 1
250 i = 6
251 main.log.info("Ping failed, making attempt number "+str(count)+" in 5 seconds")
252 time.sleep(5)
253 elif ping == main.FALSE and count ==6:
254 main.log.error("Ping test failed")
255 i = 17
256 result = main.FALSE
257 elif ping == main.TRUE:
258 i = i + 1
259 result = main.TRUE
260 endTime = time.time()
261 if result == main.TRUE:
262 main.log.report("\tTime to complete ping test: "+str(round(endTime-strtTime,2))+" seconds")
263 else:
264 main.log.report("\tPING TEST FAILED")
265 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="NO PACKET LOSS, HOST IS REACHABLE",onfail="PACKET LOST, HOST IS NOT REACHABLE")
266
267# **********************************************************************************************************************************************************************************************
268#Brings a link that all flows pass through in the mininet down, then runs a ping test to view reroute time
269
270 def CASE6(self,main) :
271 main.log.report("Bring Link between s1 and s2 down, then ping until all hosts are reachable or fail after 10 attempts")
272 import time
273 main.case("Bringing Link down... ")
274 result = main.Mininet1.link(END1=main.params['LINK']['begin'],END2=main.params['LINK']['end'],OPTION="down")
275 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Link DOWN!",onfail="Link not brought down...")
276
277 strtTime = time.time()
278 result = main.ONOS1.check_status_report(main.params['RestIP'],main.params['NR_Switches'],str(int(main.params['NR_Links'])-2))
279 for i in range(2):
280 if result == main.FALSE:
281 time.sleep(5)
282 result = main.ONOS1.check_status_report(main.params['RestIP'],main.params['NR_Switches'],str(int(main.params['NR_Links'])-2))
283 else:
284 break
285
286 count = 1
287 i = 6
288 while i < 16 :
289 main.log.info("\n\t\t\t\th"+str(i)+" IS PINGING h"+str(i+25) )
290 ping = main.Mininet1.pingHost(src="h"+str(i),target="h"+str(i+25))
291 if ping == main.FALSE and count < 10:
292 count = count + 1
293 main.log.info("Ping failed, making attempt number "+str(count)+" in 5 seconds")
294 i = 6
295 time.sleep(5)
296 elif ping == main.FALSE and count == 10:
297 main.log.error("Ping test failed")
298 i = 17
299 result = main.FALSE
300 elif ping == main.TRUE:
301 i = i + 1
302 result = main.TRUE
303 endTime = time.time()
304 if result == main.TRUE:
305 main.log.report("\tTime to complete ping test: "+str(round(endTime-strtTime,2))+" seconds")
306 else:
307 main.log.report("\tPING TEST FAILED")
308 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="NO PACKET LOSS, HOST IS REACHABLE",onfail="PACKET LOST, HOST IS NOT REACHABLE")
309
310# **********************************************************************************************************************************************************************************************
311#Brings the link that Case 6 took down back up, then runs a ping test to view reroute time
312
313 def CASE7(self,main) :
314 main.log.report("Bring Link between s1 and s2 up, then ping until all hosts are reachable or fail after 10 attempts")
315 import time
316 main.case("Bringing Link up... ")
317 result = main.Mininet1.link(END1=main.params['LINK']['begin'],END2=main.params['LINK']['end'],OPTION="up")
318 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Link UP!",onfail="Link not brought up...")
319
320 strtTime = time.time()
321 result = main.ONOS1.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links'])
322 for i in range(2):
323 if result == main.FALSE:
324 time.sleep(5)
325 result = main.ONOS1.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links'])
326 else:
327 break
328
329 strtTime = time.time()
330 count = 1
331 i = 6
332 while i < 16 :
333 main.log.info("\n\t\t\t\th"+str(i)+" IS PINGING h"+str(i+25) )
334 ping = main.Mininet1.pingHost(src="h"+str(i),target="h"+str(i+25))
335 if ping == main.FALSE and count < 10:
336 count = count + 1
337 main.log.info("Ping failed, making attempt number "+str(count)+" in 5 seconds")
338 i = 6
339 time.sleep(5)
340 elif ping == main.FALSE and count ==10:
341 main.log.error("Ping test failed")
342 i = 17
343 result = main.FALSE
344 elif ping == main.TRUE:
345 i = i + 1
346 result = main.TRUE
347 endTime = time.time()
348 if result == main.TRUE:
349 main.log.report("\tTime to complete ping test: "+str(round(endTime-strtTime,2))+" seconds")
350 else:
351 main.log.report("\tPING TESTS FAILED")
352 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="NO PACKET LOSS, HOST IS REACHABLE",onfail="PACKET LOST, HOST IS NOT REACHABLE")
353
354
355# ******************************************************************************************************************************************************************
356# Test Device Discovery function by yanking s6:s6-eth0 interface and re-plug it into a switch
357
358 def CASE21(self,main) :
359 import json
360 from drivers.common.api.onosrestapidriver import *
361 main.log.report("Test device discovery function, by attach/detach/move host h1 from s1->s6->s1.")
362 main.log.report("Check initially hostMAC exist on the mininet...")
363 host = main.params['YANK']['hostname']
364 mac = main.params['YANK']['hostmac']
365 RestIP1 = main.params['RESTCALL']['restIP1']
366 RestIP2 = main.params['RESTCALL']['restIP2']
367 RestPort = main.params['RESTCALL']['restPort']
368 url = main.params['RESTCALL']['restURL']
369 #print "host=" + host + "; RestIP=" + RestIP1 + "; RestPort=" + str(RestPort)
370
371 main.log.info("\n\t\t\t\t ping issue one ping from" + str(host) + "to generate arp to switch. Ping result is not important" )
372 ping = main.Mininet1.pingHost(src = str(host),target = "10.0.0.254")
373 restcall = OnosRestApiDriver()
374 Reststatus, Hoststatus = restcall.find_host(RestIP1,RestPort,url,mac)
375 try:
376 attachedSW = Hoststatus[0]['attachmentPoint'][0]['switchDPID']
377 host_ip = Hoststatus[0]['ipv4'][0]
378 except:
379 Reststatus = 0
380 if Reststatus == 1 and host_ip == '10.0.0.1':
381 main.log.report("\tFound host " + host + " attached to switchDPID = " + attachedSW)
382 result = main.TRUE
383 else:
384 main.log.report("\t Host " + host + " with MAC:" + str(mac) + " does not exist. FAILED")
385 result = main.FALSE
386
387 ##### Step to yank out "s1-eth1" from s1, which is on autoONOS1 #####
388
389 main.log.report("Yank out s1-eth1")
390 main.case("Yankout s6-eth1 (link to h1) from s1")
391 result = main.Mininet1.yank(SW=main.params['YANK']['sw1'],INTF=main.params['YANK']['intf'])
392 time.sleep(3)
393 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Yank command suceeded",onfail="Yank command failed...")
394 ping = main.Mininet1.pingHost(src = str(host),target = "10.0.0.254")
395 Reststatus, Hoststatus = restcall.find_host(RestIP1,RestPort,url,mac)
396 try:
397 attachedSW = Hoststatus[0]['attachmentPoint'][0]['switchDPID']
398 except IndexError:
399 Reststatus = 0
400 if Reststatus == 0:
401 main.log.report("Attempt to yank out s1-eth1 from s1 sucessfully")
402 result = main.TRUE
403 else:
404 main.log.report("Attempt to yank out s1-eht1 from s1 failed.")
405 result = main.FALSE
406
407 ##### Step to plug "s1-eth1" to s6, which is on autoONOS3 ######
408 main.log.report("Plug s1-eth1 into s6")
409 main.case("Plug s1-eth1 to s6")
410 result = main.Mininet1.plug(SW=main.params['PLUG']['sw6'],INTF=main.params['PLUG']['intf'])
411 time.sleep(3)
412 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Plug command suceeded",onfail="Plug command failed...")
413 ping = main.Mininet1.pingHost(src = str(host),target = "10.0.0.254")
414 Reststatus, Hoststatus = restcall.find_host(RestIP2,RestPort,url,mac)
415 try:
416 attachedSW = Hoststatus[0]['attachmentPoint'][0]['switchDPID']
417 host_ip = Hoststatus[0]['ipv4'][0]
418 except:
419 Reststatus = 0
420 if Reststatus == 0:
421 main.log.report("Attempt to plug s1-eth1 to s6 FAILED")
422 result = main.FALSE
423 elif attachedSW == "00:00:00:00:00:00:00:06"and host_ip == '10.0.0.1':
424 main.log.report("Attempt to plug s1-eht1 to s6 succeded.")
425 result = main.TRUE
426 else:
427 main.log.report( "FAILED to attach s1-eth1 to s6 correctly!")
428 result = main.FALSE
429
430 ###### Step to put interface "s1-eth1" back to s1"#####
431 main.log.report("Move s1-eth1 back on to s1")
432 main.case("Move s1-eth1 back to s1")
433 result = main.Mininet1.yank(SW=main.params['YANK']['sw6'],INTF=main.params['YANK']['intf'])
434 time.sleep(3)
435 retult = main.Mininet1.plug(SW=main.params['PLUG']['sw1'],INTF=main.params['PLUG']['intf'])
436 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Yank/Plug command suceeded",onfail="Yank/Plug command failed...")
437 ping = main.Mininet1.pingHost(src = str(host),target = "10.0.0.254")
438 Reststatus, Hoststatus = restcall.find_host(RestIP1,RestPort,url,mac)
439 try:
440 attachedSW = Hoststatus[0]['attachmentPoint'][0]['switchDPID']
441 host_ip = Hoststatus[0]['ipv4'][0]
442 except:
443 Reststatus = 0
444 if Reststatus == 0:
445 main.log.report("Attempt to plug s1-eth1 back to s1 FAILED")
446 result = main.FALSE
447 elif attachedSW == "00:00:00:00:00:00:00:01" and host_ip == '10.0.0.1':
448 main.log.report("Attempt to plug s1-eht1 back to s1 succeded.")
449 result = main.TRUE
450 else:
451 main.log.report( "FAIL to attach s1-eth1 to s1 correctly!")
452 result = main.FALSE
453
454 utilities.assert_equals(expect=main.TRUE,actual=result,onpass="DEVICE DISCOVERY TEST PASSED PLUG/UNPLUG/MOVE TEST",onfail="DEVICE DISCOVERY TEST FAILED")
455
456