blob: 33d86b4bc8eb40fb2d06910489786110b546187b [file] [log] [blame]
shahshreya4e13a062014-11-11 16:46:18 -08001
2#Testing the basic functionality of ONOS Next
3#For sanity and driver functionality excercises only.
4
5import time
6import sys
7import os
8import re
9import time
10import json
11
12time.sleep(1)
13class MultiProd:
14 def __init__(self):
15 self.default = ''
16
17 def CASE1(self, main):
18 '''
19 Startup sequence:
20 git pull
21 mvn clean install
22 onos-package
23 cell <name>
24 onos-verify-cell
25 onos-install -f
26 onos-wait-for-start
27 '''
28
29 cell_name = main.params['ENV']['cellName']
30 ONOS1_ip = main.params['CTRL']['ip1']
31 ONOS2_ip = main.params['CTRL']['ip2']
32 ONOS3_ip = main.params['CTRL']['ip3']
33 ONOS1_port = main.params['CTRL']['port1']
34 ONOS2_port = main.params['CTRL']['port2']
35 ONOS3_port = main.params['CTRL']['port3']
36
37 main.case("Setting up test environment")
38 main.log.report("This testcase is testing setting up test environment")
39 main.log.report("__________________________________")
40 main.step("Git checkout and pull master and get version")
41 main.ONOSbench.git_checkout("master")
42 git_pull_result = main.ONOSbench.git_pull()
43 print "git_pull_result = ", git_pull_result
44 version_result = main.ONOSbench.get_version(report=True)
45
46 if git_pull_result == 1:
47 main.step("Using mvn clean & install")
48 clean_install_result = main.ONOSbench.clean_install()
49 #clean_install_result = main.TRUE
50
51 main.step("Applying cell variable to environment")
52 cell_result1 = main.ONOSbench.set_cell(cell_name)
53 #cell_result2 = main.ONOScli1.set_cell(cell_name)
54 #cell_result3 = main.ONOScli2.set_cell(cell_name)
55 #cell_result4 = main.ONOScli3.set_cell(cell_name)
56 verify_result = main.ONOSbench.verify_cell()
57 cell_result = cell_result1
58
59 main.step("Creating ONOS package")
60 package_result = main.ONOSbench.onos_package()
61
62 #main.step("Creating a cell")
63 #cell_create_result = main.ONOSbench.create_cell_file(**************)
64
65 main.step("Installing ONOS package")
66 onos1_install_result = main.ONOSbench.onos_install(options="-f", node=ONOS1_ip)
67 onos2_install_result = main.ONOSbench.onos_install(options="-f", node=ONOS2_ip)
68 onos3_install_result = main.ONOSbench.onos_install(options="-f", node=ONOS3_ip)
69 onos_install_result = onos1_install_result and onos2_install_result and onos3_install_result
70 if onos_install_result == main.TRUE:
71 main.log.report("Installing ONOS package successful")
72 else:
73 main.log.report("Installing ONOS package failed")
74
75 onos1_isup = main.ONOSbench.isup(ONOS1_ip)
76 onos2_isup = main.ONOSbench.isup(ONOS2_ip)
77 onos3_isup = main.ONOSbench.isup(ONOS3_ip)
78 onos_isup = onos1_isup and onos2_isup and onos3_isup
79 if onos_isup == main.TRUE:
80 main.log.report("ONOS instances are up and ready")
81 else:
82 main.log.report("ONOS instances may not be up")
83
84 main.step("Starting ONOS service")
85 start_result = main.TRUE
86 #start_result = main.ONOSbench.onos_start(ONOS1_ip)
87 startcli1 = main.ONOScli1.start_onos_cli(ONOS_ip = ONOS1_ip)
88 startcli2 = main.ONOScli2.start_onos_cli(ONOS_ip = ONOS2_ip)
89 startcli3 = main.ONOScli3.start_onos_cli(ONOS_ip = ONOS3_ip)
90 print startcli1
91 print startcli2
92 print startcli3
93
94 case1_result = (package_result and\
95 cell_result and verify_result and onos_install_result and\
96 onos_isup and start_result )
97 utilities.assert_equals(expect=main.TRUE, actual=case1_result,
98 onpass="Test startup successful",
99 onfail="Test startup NOT successful")
100
101 def CASE11(self, main):
102 '''
103 Cleanup sequence:
104 onos-service <node_ip> stop
105 onos-uninstall
106
107 TODO: Define rest of cleanup
108
109 '''
110
111 ONOS1_ip = main.params['CTRL']['ip1']
112 ONOS2_ip = main.params['CTRL']['ip2']
113 ONOS3_ip = main.params['CTRL']['ip3']
114
115 main.case("Cleaning up test environment")
116
117 main.step("Testing ONOS kill function")
118 kill_result1 = main.ONOSbench.onos_kill(ONOS1_ip)
119 kill_result2 = main.ONOSbench.onos_kill(ONOS2_ip)
120 kill_result3 = main.ONOSbench.onos_kill(ONOS3_ip)
121
122 main.step("Stopping ONOS service")
123 stop_result1 = main.ONOSbench.onos_stop(ONOS1_ip)
124 stop_result2 = main.ONOSbench.onos_stop(ONOS2_ip)
125 stop_result3 = main.ONOSbench.onos_stop(ONOS3_ip)
126
127 main.step("Uninstalling ONOS service")
128 uninstall_result = main.ONOSbench.onos_uninstall()
129
130 def CASE3(self, main):
131 '''
132 Test 'onos' command and its functionality in driver
133 '''
134
135 ONOS1_ip = main.params['CTRL']['ip1']
136 ONOS2_ip = main.params['CTRL']['ip2']
137 ONOS3_ip = main.params['CTRL']['ip3']
138
139 main.case("Testing 'onos' command")
140
141 main.step("Sending command 'onos -w <onos-ip> system:name'")
142 cmdstr1 = "system:name"
143 cmd_result1 = main.ONOSbench.onos_cli(ONOS1_ip, cmdstr1)
144 main.log.info("onos command returned: "+cmd_result1)
145 cmd_result2 = main.ONOSbench.onos_cli(ONOS2_ip, cmdstr1)
146 main.log.info("onos command returned: "+cmd_result2)
147 cmd_result3 = main.ONOSbench.onos_cli(ONOS3_ip, cmdstr1)
148 main.log.info("onos command returned: "+cmd_result3)
149
150 main.step("Sending command 'onos -w <onos-ip> onos:topology'")
151 cmdstr2 = "onos:topology"
152 cmd_result4 = main.ONOSbench.onos_cli(ONOS1_ip, cmdstr2)
153 main.log.info("onos command returned: "+cmd_result4)
154 cmd_result5 = main.ONOSbench.onos_cli(ONOS2_ip, cmdstr2)
155 main.log.info("onos command returned: "+cmd_result5)
156 cmd_result6 = main.ONOSbench.onos_cli(ONOS6_ip, cmdstr2)
157 main.log.info("onos command returned: "+cmd_result6)
158
159
160 def CASE4(self, main):
161 import re
162 import time
163 ONOS1_ip = main.params['CTRL']['ip1']
164 ONOS2_ip = main.params['CTRL']['ip2']
165 ONOS3_ip = main.params['CTRL']['ip3']
166 ONOS1_port = main.params['CTRL']['port1']
167 ONOS2_port = main.params['CTRL']['port2']
168 ONOS3_port = main.params['CTRL']['port3']
169
170 main.log.report("This testcase is testing the assignment of all the switches to all controllers and discovering the hosts in reactive mode")
171 main.log.report("__________________________________")
172 main.case("Pingall Test(No intents are added)")
173 main.step("Assigning switches to controllers")
174 for i in range(1,29): #1 to (num of switches +1)
175 main.Mininet1.assign_sw_controller(sw=str(i),count=3,
176 ip1=ONOS1_ip, port1=ONOS1_port,
177 ip2=ONOS2_ip, port2=ONOS2_port,
178 ip3=ONOS3_ip, port3=ONOS3_port)
179
180 switch_mastership = main.TRUE
181 for i in range (1,29):
182 response = main.Mininet1.get_sw_controller("s"+str(i))
183 print("Response is " + str(response))
184 if re.search("tcp:"+ONOS1_ip,response):
185 switch_mastership = switch_mastership and main.TRUE
186 else:
187 switch_mastership = main.FALSE
188
189 if switch_mastership == main.TRUE:
190 main.log.report("Controller assignment successfull")
191 else:
192 main.log.report("Controller assignment failed")
193 #REACTIVE FWD test
194 main.step("Pingall")
195 ping_result = main.FALSE
196 time1 = time.time()
197 ping_result = main.Mininet1.pingall()
198 time2 = time.time()
199 print "Time for pingall: %2f seconds" % (time2 - time1)
200
201 case4_result = switch_mastership and ping_result
202 if ping_result == main.TRUE:
203 main.log.report("Pingall Test in reactive mode to discover the hosts successful")
204 else:
205 main.log.report("Pingall Test in reactive mode to discover the hosts failed")
206
207 utilities.assert_equals(expect=main.TRUE, actual=case4_result,onpass="Controller assignment and Pingall Test successful",onfail="Controller assignment and Pingall Test NOT successful")
208
209
210
211 def CASE5(self,main) :
212 import json
213 from subprocess import Popen, PIPE
214 from sts.topology.teston_topology import TestONTopology # assumes that sts is already in you PYTHONPATH
215 ONOS1_ip = main.params['CTRL']['ip1']
216 ONOS2_ip = main.params['CTRL']['ip2']
217 ONOS3_ip = main.params['CTRL']['ip3']
218
219 main.log.report("This testcase is testing if all ONOS nodes are in topology sync with mininet and its peer ONOS nodes")
220 main.log.report("__________________________________")
221 main.case ("Testing Mininet topology with the topology of multi instances ONOS")
222 main.step("Collecting topology information from ONOS")
223 devices1 = main.ONOScli1.devices()
224 devices2 = main.ONOScli2.devices()
225 devices3 = main.ONOScli3.devices()
226 print "devices1 = ", devices1
227 print "devices2 = ", devices2
228 print "devices3 = ", devices3
229 hosts1 = main.ONOScli1.hosts()
230 hosts2 = main.ONOScli2.hosts()
231 hosts3 = main.ONOScli3.hosts()
232 #print "hosts1 = ", hosts1
233 #print "hosts2 = ", hosts2
234 #print "hosts3 = ", hosts3
235 ports1 = main.ONOScli1.ports()
236 ports2 = main.ONOScli2.ports()
237 ports3 = main.ONOScli3.ports()
238 #print "ports1 = ", ports1
239 #print "ports2 = ", ports2
240 #print "ports3 = ", ports3
241 links1 = main.ONOScli1.links()
242 links2 = main.ONOScli2.links()
243 links3 = main.ONOScli3.links()
244 #print "links1 = ", links1
245 #print "links2 = ", links2
246 #print "links3 = ", links3
247
248 print "**************"
249
250 main.step("Start continuous pings")
251 main.Mininet2.pingLong(src=main.params['PING']['source1'],
252 target=main.params['PING']['target1'],pingTime=500)
253 main.Mininet2.pingLong(src=main.params['PING']['source2'],
254 target=main.params['PING']['target2'],pingTime=500)
255 main.Mininet2.pingLong(src=main.params['PING']['source3'],
256 target=main.params['PING']['target3'],pingTime=500)
257 main.Mininet2.pingLong(src=main.params['PING']['source4'],
258 target=main.params['PING']['target4'],pingTime=500)
259 main.Mininet2.pingLong(src=main.params['PING']['source5'],
260 target=main.params['PING']['target5'],pingTime=500)
261 main.Mininet2.pingLong(src=main.params['PING']['source6'],
262 target=main.params['PING']['target6'],pingTime=500)
263 main.Mininet2.pingLong(src=main.params['PING']['source7'],
264 target=main.params['PING']['target7'],pingTime=500)
265 main.Mininet2.pingLong(src=main.params['PING']['source8'],
266 target=main.params['PING']['target8'],pingTime=500)
267 main.Mininet2.pingLong(src=main.params['PING']['source9'],
268 target=main.params['PING']['target9'],pingTime=500)
269 main.Mininet2.pingLong(src=main.params['PING']['source10'],
270 target=main.params['PING']['target10'],pingTime=500)
271
272 main.step("Create TestONTopology object")
273 global ctrls
274 ctrls = []
275 count = 1
276 while True:
277 temp = ()
278 if ('ip' + str(count)) in main.params['CTRL']:
279 temp = temp + (getattr(main,('ONOS' + str(count))),)
280 temp = temp + ("ONOS"+str(count),)
281 temp = temp + (main.params['CTRL']['ip'+str(count)],)
282 temp = temp + (eval(main.params['CTRL']['port'+str(count)]),)
283 ctrls.append(temp)
284 count = count + 1
285 else:
286 break
287 global MNTopo
288 Topo = TestONTopology(main.Mininet1, ctrls) # can also add Intent API info for intent operations
289 MNTopo = Topo
290
291 Topology_Check = main.TRUE
292 main.step("Compare ONOS Topology to MN Topology")
293
294 switches_results1 = main.Mininet1.compare_switches(MNTopo, json.loads(devices1))
295 print "switches_Result1 = ", switches_results1
296 utilities.assert_equals(expect=main.TRUE, actual=switches_results1,
297 onpass="ONOS1 Switches view is correct",
298 onfail="ONOS1 Switches view is incorrect")
299
300 switches_results2 = main.Mininet1.compare_switches(MNTopo, json.loads(devices2))
301 utilities.assert_equals(expect=main.TRUE, actual=switches_results2,
302 onpass="ONOS2 Switches view is correct",
303 onfail="ONOS2 Switches view is incorrect")
304
305 switches_results3 = main.Mininet1.compare_switches(MNTopo, json.loads(devices3))
306 utilities.assert_equals(expect=main.TRUE, actual=switches_results3,
307 onpass="ONOS3 Switches view is correct",
308 onfail="ONOS3 Switches view is incorrect")
309
310 '''
311 ports_results1 = main.Mininet1.compare_ports(MNTopo, json.loads(ports1))
312 utilities.assert_equals(expect=main.TRUE, actual=ports_results1,
313 onpass="ONOS1 Ports view is correct",
314 onfail="ONOS1 Ports view is incorrect")
315
316 ports_results2 = main.Mininet1.compare_ports(MNTopo, json.loads(ports2))
317 utilities.assert_equals(expect=main.TRUE, actual=ports_results2,
318 onpass="ONOS2 Ports view is correct",
319 onfail="ONOS2 Ports view is incorrect")
320
321 ports_results3 = main.Mininet1.compare_ports(MNTopo, json.loads(ports3))
322 utilities.assert_equals(expect=main.TRUE, actual=ports_results3,
323 onpass="ONOS3 Ports view is correct",
324 onfail="ONOS3 Ports view is incorrect")
325 '''
326
327 links_results1 = main.Mininet1.compare_links(MNTopo, json.loads(links1))
328 utilities.assert_equals(expect=main.TRUE, actual=links_results1,
329 onpass="ONOS1 Links view is correct",
330 onfail="ONOS1 Links view is incorrect")
331
332 links_results2 = main.Mininet1.compare_links(MNTopo, json.loads(links2))
333 utilities.assert_equals(expect=main.TRUE, actual=links_results2,
334 onpass="ONOS2 Links view is correct",
335 onfail="ONOS2 Links view is incorrect")
336
337 links_results3 = main.Mininet1.compare_links(MNTopo, json.loads(links3))
338 utilities.assert_equals(expect=main.TRUE, actual=links_results3,
339 onpass="ONOS2 Links view is correct",
340 onfail="ONOS2 Links view is incorrect")
341
342 #topo_result = switches_results1 and switches_results2 and switches_results3\
343 #and ports_results1 and ports_results2 and ports_results3\
344 #and links_results1 and links_results2 and links_results3
345
346 topo_result = switches_results1 and switches_results2 and switches_results3\
347 and links_results1 and links_results2 and links_results3
348
349 if topo_result == main.TRUE:
350 main.log.report("Topology Check Test with mininet and ONOS instances successful")
351 else:
352 main.log.report("Topology Check Test with mininet and ONOS instances failed")
353
354 utilities.assert_equals(expect=main.TRUE, actual=topo_result,
355 onpass="Topology Check Test successful",
356 onfail="Topology Check Test NOT successful")
357
358 def CASE6(self):
359 main.log.report("This testcase is testing the addition of host intents and then doing pingall")
360 main.log.report("__________________________________")
361 main.case("Uninstalling reactive forwarding app and addhost intents")
362 main.step("Get hosts")
363 main.ONOScli1.handle.sendline("hosts")
364 main.ONOScli1.handle.expect("onos>")
365 hosts = main.ONOScli1.handle.before
366 main.log.info(hosts)
367
368 main.step("Get all devices id")
369 devices_id_list = main.ONOScli1.get_all_devices_id()
370 main.log.info(devices_id_list)
371
372 #ONOS displays the hosts in hex format unlike mininet which does in decimal format
373 #So take care while adding intents
374
375 main.step("Add host intents for mn hosts(h8-h18,h9-h19,h10-h20,h11-h21,h12-h22,h13-h23,h14-h24,h15-h25,h16-h26,h17-h27)")
376 hth_intent_result = main.ONOScli1.add_host_intent("00:00:00:00:00:08/-1", "00:00:00:00:00:12/-1")
377 hth_intent_result = main.ONOScli1.add_host_intent("00:00:00:00:00:09/-1", "00:00:00:00:00:13/-1")
378 hth_intent_result = main.ONOScli1.add_host_intent("00:00:00:00:00:0A/-1", "00:00:00:00:00:14/-1")
379 hth_intent_result = main.ONOScli1.add_host_intent("00:00:00:00:00:0B/-1", "00:00:00:00:00:15/-1")
380 hth_intent_result = main.ONOScli1.add_host_intent("00:00:00:00:00:0C/-1", "00:00:00:00:00:16/-1")
381 hth_intent_result = main.ONOScli1.add_host_intent("00:00:00:00:00:0D/-1", "00:00:00:00:00:17/-1")
382 hth_intent_result = main.ONOScli1.add_host_intent("00:00:00:00:00:0E/-1", "00:00:00:00:00:18/-1")
383 hth_intent_result = main.ONOScli1.add_host_intent("00:00:00:00:00:0F/-1", "00:00:00:00:00:19/-1")
384 hth_intent_result = main.ONOScli1.add_host_intent("00:00:00:00:00:10/-1", "00:00:00:00:00:1A/-1")
385 hth_intent_result = main.ONOScli1.add_host_intent("00:00:00:00:00:11/-1", "00:00:00:00:00:1B/-1")
386
387
388 #Unistall onos-app-fwd app to disable reactive forwarding
389 main.step("Unistall onos-app-fwd app to disable reactive forwarding")
390 appUninstall_result = main.ONOScli1.feature_uninstall("onos-app-fwd")
391 main.log.info("onos-app-fwd uninstalled")
392
393 #After reactive forwarding is disabled, the reactive flows on switches timeout in 10-15s
394 #So sleep for 15s
395 time.sleep(15)
396
397 flowHandle = main.ONOScli1.flows()
398 #print "flowHandle = ", flowHandle
399 main.log.info("flows:" +flowHandle)
400
401 count = 1
402 i = 8
403 Ping_Result = main.TRUE
404 while i <18 :
405 main.log.info("\n\nh"+str(i)+" is Pinging h" + str(i+10))
406 ping = main.Mininet1.pingHost(src="h"+str(i),target="h"+str(i+10))
407 if ping == main.FALSE and count <5:
408 count+=1
409 #i = 8
410 Ping_Result = main.FALSE
411 main.log.report("Ping between h" + str(i) + " and h" + str(i+10) + " failed. Making attempt number "+str(count) + " in 2 seconds")
412 time.sleep(2)
413 elif ping==main.FALSE:
414 main.log.report("All ping attempts between h" + str(i) + " and h" + str(i+10) +"have failed")
415 i=19
416 Ping_Result = main.FALSE
417 elif ping==main.TRUE:
418 main.log.info("Ping test between h" + str(i) + " and h" + str(i+10) + "passed!")
419 i+=1
420 Ping_Result = main.TRUE
421 else:
422 main.log.info("Unknown error")
423 Ping_Result = main.ERROR
424 if Ping_Result==main.FALSE:
425 main.log.report("Host intents have not ben installed correctly. Cleaning up")
426 #main.cleanup()
427 #main.exit()
428 if Ping_Result==main.TRUE:
429 main.log.report("Host intents have been installed correctly")
430
431 case6_result = Ping_Result
432 utilities.assert_equals(expect=main.TRUE, actual=case6_result,
433 onpass="Host intent addition and Pingall Test successful",
434 onfail="Host intent addition and Pingall Test NOT successful")
435
436
437 def CASE7 (self,main):
438
439 ONOS1_ip = main.params['CTRL']['ip1']
440
441 link_sleep = int(main.params['timers']['LinkDiscovery'])
442
443 main.log.report("This testscase is killing a link to ensure that link discovery is consistent")
444 main.log.report("__________________________________")
445 main.case("Killing a link to Ensure that Link Discovery is Working Properly")
446 main.step("Start continuous pings")
447
448 main.Mininet2.pingLong(src=main.params['PING']['source1'],
449 target=main.params['PING']['target1'],pingTime=500)
450 main.Mininet2.pingLong(src=main.params['PING']['source2'],
451 target=main.params['PING']['target2'],pingTime=500)
452 main.Mininet2.pingLong(src=main.params['PING']['source3'],
453 target=main.params['PING']['target3'],pingTime=500)
454 main.Mininet2.pingLong(src=main.params['PING']['source4'],
455 target=main.params['PING']['target4'],pingTime=500)
456 main.Mininet2.pingLong(src=main.params['PING']['source5'],
457 target=main.params['PING']['target5'],pingTime=500)
458 main.Mininet2.pingLong(src=main.params['PING']['source6'],
459 target=main.params['PING']['target6'],pingTime=500)
460 main.Mininet2.pingLong(src=main.params['PING']['source7'],
461 target=main.params['PING']['target7'],pingTime=500)
462 main.Mininet2.pingLong(src=main.params['PING']['source8'],
463 target=main.params['PING']['target8'],pingTime=500)
464 main.Mininet2.pingLong(src=main.params['PING']['source9'],
465 target=main.params['PING']['target9'],pingTime=500)
466 main.Mininet2.pingLong(src=main.params['PING']['source10'],
467 target=main.params['PING']['target10'],pingTime=500)
468
469
470 main.step("Determine the current number of switches and links")
471 topology_output = main.ONOScli1.topology()
472 topology_result = main.ONOSbench.get_topology(topology_output)
473 activeSwitches = topology_result['devices']
474 links = topology_result['links']
475 print "activeSwitches = ", type(activeSwitches)
476 print "links = ", type(links)
477 main.log.info("Currently there are %s switches and %s links" %(str(activeSwitches), str(links)))
478
479 main.step("Kill Link between s3 and s28")
480 main.Mininet1.link(END1="s3",END2="s28",OPTION="down")
481 time.sleep(link_sleep)
482 topology_output = main.ONOScli2.topology()
483 Link_Down = main.ONOSbench.check_status(topology_output,activeSwitches,str(int(links)-2))
484 if Link_Down == main.TRUE:
485 main.log.report("Link Down discovered properly")
486 utilities.assert_equals(expect=main.TRUE,actual=Link_Down,
487 onpass="Link Down discovered properly",
488 onfail="Link down was not discovered in "+ str(link_sleep) + " seconds")
489
490 main.step("Bring link between s3 and s28 back up")
491 Link_Up = main.Mininet1.link(END1="s3",END2="s28",OPTION="up")
492 time.sleep(link_sleep)
493 topology_output = main.ONOScli2.topology()
494 Link_Up = main.ONOSbench.check_status(topology_output,activeSwitches,str(links))
495 if Link_Up == main.TRUE:
496 main.log.report("Link up discovered properly")
497 utilities.assert_equals(expect=main.TRUE,actual=Link_Up,
498 onpass="Link up discovered properly",
499 onfail="Link up was not discovered in "+ str(link_sleep) + " seconds")
500
501 main.step("Compare ONOS Topology to MN Topology")
502 main.case ("Testing Mininet topology with the topology of multi instances ONOS")
503 main.step("Collecting topology information from ONOS")
504 devices1 = main.ONOScli1.devices()
505 devices2 = main.ONOScli2.devices()
506 devices3 = main.ONOScli3.devices()
507 print "devices1 = ", devices1
508 print "devices2 = ", devices2
509 print "devices3 = ", devices3
510 hosts1 = main.ONOScli1.hosts()
511 hosts2 = main.ONOScli2.hosts()
512 hosts3 = main.ONOScli3.hosts()
513 #print "hosts1 = ", hosts1
514 #print "hosts2 = ", hosts2
515 #print "hosts3 = ", hosts3
516 ports1 = main.ONOScli1.ports()
517 ports2 = main.ONOScli2.ports()
518 ports3 = main.ONOScli3.ports()
519 #print "ports1 = ", ports1
520 #print "ports2 = ", ports2
521 #print "ports3 = ", ports3
522 links1 = main.ONOScli1.links()
523 links2 = main.ONOScli2.links()
524 links3 = main.ONOScli3.links()
525 #print "links1 = ", links1
526 #print "links2 = ", links2
527 #print "links3 = ", links3
528
529 print "**************"
530
531 main.step("Start continuous pings")
532 main.Mininet2.pingLong(src=main.params['PING']['source1'],
533 target=main.params['PING']['target1'],pingTime=500)
534 main.Mininet2.pingLong(src=main.params['PING']['source2'],
535 target=main.params['PING']['target2'],pingTime=500)
536 main.Mininet2.pingLong(src=main.params['PING']['source3'],
537 target=main.params['PING']['target3'],pingTime=500)
538 main.Mininet2.pingLong(src=main.params['PING']['source4'],
539 target=main.params['PING']['target4'],pingTime=500)
540 main.Mininet2.pingLong(src=main.params['PING']['source5'],
541 target=main.params['PING']['target5'],pingTime=500)
542 main.Mininet2.pingLong(src=main.params['PING']['source6'],
543 target=main.params['PING']['target6'],pingTime=500)
544 main.Mininet2.pingLong(src=main.params['PING']['source7'],
545 target=main.params['PING']['target7'],pingTime=500)
546 main.Mininet2.pingLong(src=main.params['PING']['source8'],
547 target=main.params['PING']['target8'],pingTime=500)
548 main.Mininet2.pingLong(src=main.params['PING']['source9'],
549 target=main.params['PING']['target9'],pingTime=500)
550 main.Mininet2.pingLong(src=main.params['PING']['source10'],
551 target=main.params['PING']['target10'],pingTime=500)
552
553 main.step("Create TestONTopology object")
554 global ctrls
555 ctrls = []
556 count = 1
557 while True:
558 temp = ()
559 if ('ip' + str(count)) in main.params['CTRL']:
560 temp = temp + (getattr(main,('ONOS' + str(count))),)
561 temp = temp + ("ONOS"+str(count),)
562 temp = temp + (main.params['CTRL']['ip'+str(count)],)
563 temp = temp + (eval(main.params['CTRL']['port'+str(count)]),)
564 ctrls.append(temp)
565 count = count + 1
566 else:
567 break
568 global MNTopo
569 Topo = TestONTopology(main.Mininet1, ctrls) # can also add Intent API info for intent operations
570 MNTopo = Topo
571
572 Topology_Check = main.TRUE
573 main.step("Compare ONOS Topology to MN Topology")
574
575 switches_results1 = main.Mininet1.compare_switches(MNTopo, json.loads(devices1))
576 print "switches_Result1 = ", switches_results1
577 utilities.assert_equals(expect=main.TRUE, actual=switches_results1,
578 onpass="ONOS1 Switches view is correct",
579 onfail="ONOS1 Switches view is incorrect")
580
581 switches_results2 = main.Mininet1.compare_switches(MNTopo, json.loads(devices2))
582 utilities.assert_equals(expect=main.TRUE, actual=switches_results2,
583 onpass="ONOS2 Switches view is correct",
584 onfail="ONOS2 Switches view is incorrect")
585
586 switches_results3 = main.Mininet1.compare_switches(MNTopo, json.loads(devices3))
587 utilities.assert_equals(expect=main.TRUE, actual=switches_results3,
588 onpass="ONOS3 Switches view is correct",
589 onfail="ONOS3 Switches view is incorrect")
590
591 '''
592 ports_results1 = main.Mininet1.compare_ports(MNTopo, json.loads(ports1))
593 utilities.assert_equals(expect=main.TRUE, actual=ports_results1,
594 onpass="ONOS1 Ports view is correct",
595 onfail="ONOS1 Ports view is incorrect")
596
597 ports_results2 = main.Mininet1.compare_ports(MNTopo, json.loads(ports2))
598 utilities.assert_equals(expect=main.TRUE, actual=ports_results2,
599 onpass="ONOS2 Ports view is correct",
600 onfail="ONOS2 Ports view is incorrect")
601
602 ports_results3 = main.Mininet1.compare_ports(MNTopo, json.loads(ports3))
603 utilities.assert_equals(expect=main.TRUE, actual=ports_results3,
604 onpass="ONOS3 Ports view is correct",
605 onfail="ONOS3 Ports view is incorrect")
606 '''
607
608 links_results1 = main.Mininet1.compare_links(MNTopo, json.loads(links1))
609 utilities.assert_equals(expect=main.TRUE, actual=links_results1,
610 onpass="ONOS1 Links view is correct",
611 onfail="ONOS1 Links view is incorrect")
612
613 links_results2 = main.Mininet1.compare_links(MNTopo, json.loads(links2))
614 utilities.assert_equals(expect=main.TRUE, actual=links_results2,
615 onpass="ONOS2 Links view is correct",
616 onfail="ONOS2 Links view is incorrect")
617
618 links_results3 = main.Mininet1.compare_links(MNTopo, json.loads(links3))
619 utilities.assert_equals(expect=main.TRUE, actual=links_results3,
620 onpass="ONOS2 Links view is correct",
621 onfail="ONOS2 Links view is incorrect")
622
623 #topo_result = switches_results1 and switches_results2 and switches_results3\
624 #and ports_results1 and ports_results2 and ports_results3\
625 #and links_results1 and links_results2 and links_results3
626
627 topo_result = switches_results1 and switches_results2 and switches_results3\
628 and links_results1 and links_results2 and links_results3
629
630 utilities.assert_equals(expect=main.TRUE, actual=topo_result and Link_Up and Link_Down,
631 onpass="Topology Check Test successful",
632 onfail="Topology Check Test NOT successful")
633
634
635 def CASE8(self):
636 '''
637 Host intents removal
638 '''
639 main.log.report("This testcase removes host intents before adding the point intents")
640 main.log.report("__________________________________")
641 main.log.info("Host intents removal")
642 main.case("Removing host intents")
643 main.step("Obtain the intent id's")
644 intent_result = main.ONOScli1.intents()
645 #print "intent_result = ",intent_result
646 intent_linewise = intent_result.split("\n")
647 intent_linewise = intent_linewise[1:-1] #ignore the first and last item of the list obtained from split
648 #for line in intent_linewise:
649 #print "line = ", line
650 intentids = []
651 for line in intent_linewise:
652 intentids.append(line.split(",")[0].split("=")[1])
653 for id in intentids:
654 print "id = ", id
655
656 main.step("Iterate through the intentids list and remove each intent")
657 for id in intentids:
658 main.ONOScli1.remove_intent(intent_id = id)
659
660 intent_result = main.ONOScli1.intents()
661 intent_linewise = intent_result.split("\n")
662 intent_linewise = intent_linewise[1:-1] #ignore the first and last item of the list obtained from split
663
664 intentState = {}
665 for id, line in zip(intentids, intent_linewise):
666 #print "line after removing intent = ", line
667 x = line.split(",")
668 state = x[1].split("=")[1]
669 intentState[id] = state
670
671 case8_result = main.TRUE
672 for key,value in intentState.iteritems():
673 print "key,value = ", key, value
674 if value == "WITHDRAWN":
675 case8_result = case8_result and main.TRUE
676 else:
677 case8_result = case8_result and main.FALSE
678
679 if case8_result == main.TRUE:
680 main.log.report("Intent removal successful")
681 else:
682 main.log.report("Intent removal failed")
683
684 utilities.assert_equals(expect=main.TRUE, actual=case8_result,
685 onpass="Intent removal test successful",
686 onfail="Intent removal test failed")
687
688
689 def CASE9(self):
690 '''
691 This test case adds point intents. Make sure you run test case 8 which is host intent removal before executing this test case.
692 Else the host intent's flows will persist on switches and the pings would work even if there is some issue with the point intent's flows
693 '''
694 main.log.report("This testcase adds point intents and then does pingall")
695 main.log.report("__________________________________")
696 main.log.info("Adding point intents")
697 main.case("Adding bidirectional point for mn hosts(h8-h18,h9-h19,h10-h20,h11-h21,h12-h22,h13-h23,h14-h24,h15-h25,h16-h26,h17-h27)")
698 main.step("Add point-to-point intents for mininet hosts h8 and h18 or ONOS hosts h8 and h12")
699 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000003008", 1, "of:0000000000006018", 1)
700 if ptp_intent_result == main.TRUE:
701 get_intent_result = main.ONOScli1.intents()
702 main.log.info("Point to point intent install successful")
703 #main.log.info(get_intent_result)
704
705 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000006018", 1, "of:0000000000003008", 1)
706 if ptp_intent_result == main.TRUE:
707 get_intent_result = main.ONOScli1.intents()
708 main.log.info("Point to point intent install successful")
709 #main.log.info(get_intent_result)
710
711 main.step("Add point-to-point intents for mininet hosts h9 and h19 or ONOS hosts h9 and h13")
712 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000003009", 1, "of:0000000000006019", 1)
713 if ptp_intent_result == main.TRUE:
714 get_intent_result = main.ONOScli1.intents()
715 main.log.info("Point to point intent install successful")
716 #main.log.info(get_intent_result)
717
718 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000006019", 1, "of:0000000000003009", 1)
719 if ptp_intent_result == main.TRUE:
720 get_intent_result = main.ONOScli1.intents()
721 main.log.info("Point to point intent install successful")
722 #main.log.info(get_intent_result)
723
724 main.step("Add point-to-point intents for mininet hosts h10 and h20 or ONOS hosts hA and h14")
725 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000003010", 1, "of:0000000000006020", 1)
726 if ptp_intent_result == main.TRUE:
727 get_intent_result = main.ONOScli1.intents()
728 main.log.info("Point to point intent install successful")
729 #main.log.info(get_intent_result)
730
731 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000006020", 1, "of:0000000000003010", 1)
732 if ptp_intent_result == main.TRUE:
733 get_intent_result = main.ONOScli1.intents()
734 main.log.info("Point to point intent install successful")
735 #main.log.info(get_intent_result)
736
737 main.step("Add point-to-point intents for mininet hosts h11 and h21 or ONOS hosts hB and h15")
738 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000003011", 1, "of:0000000000006021", 1)
739 if ptp_intent_result == main.TRUE:
740 get_intent_result = main.ONOScli1.intents()
741 main.log.info("Point to point intent install successful")
742 #main.log.info(get_intent_result)
743
744 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000006021", 1, "of:0000000000003011", 1)
745 if ptp_intent_result == main.TRUE:
746 get_intent_result = main.ONOScli1.intents()
747 main.log.info("Point to point intent install successful")
748 #main.log.info(get_intent_result)
749
750 main.step("Add point-to-point intents for mininet hosts h12 and h22 or ONOS hosts hC and h16")
751 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000003012", 1, "of:0000000000006022", 1)
752 if ptp_intent_result == main.TRUE:
753 get_intent_result = main.ONOScli1.intents()
754 main.log.info("Point to point intent install successful")
755 #main.log.info(get_intent_result)
756
757 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000006022", 1, "of:0000000000003012", 1)
758 if ptp_intent_result == main.TRUE:
759 get_intent_result = main.ONOScli1.intents()
760 main.log.info("Point to point intent install successful")
761 #main.log.info(get_intent_result)
762
763 main.step("Add point-to-point intents for mininet hosts h13 and h23 or ONOS hosts hD and h17")
764 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000003013", 1, "of:0000000000006023", 1)
765 if ptp_intent_result == main.TRUE:
766 get_intent_result = main.ONOScli1.intents()
767 main.log.info("Point to point intent install successful")
768 #main.log.info(get_intent_result)
769
770 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000006023", 1, "of:0000000000003013", 1)
771 if ptp_intent_result == main.TRUE:
772 get_intent_result = main.ONOScli1.intents()
773 main.log.info("Point to point intent install successful")
774 #main.log.info(get_intent_result)
775
776 main.step("Add point-to-point intents for mininet hosts h14 and h24 or ONOS hosts hE and h18")
777 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000003014", 1, "of:0000000000006024", 1)
778 if ptp_intent_result == main.TRUE:
779 get_intent_result = main.ONOScli1.intents()
780 main.log.info("Point to point intent install successful")
781 #main.log.info(get_intent_result)
782
783 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000006024", 1, "of:0000000000003014", 1)
784 if ptp_intent_result == main.TRUE:
785 get_intent_result = main.ONOScli1.intents()
786 main.log.info("Point to point intent install successful")
787 #main.log.info(get_intent_result)
788
789 main.step("Add point-to-point intents for mininet hosts h15 and h25 or ONOS hosts hF and h19")
790 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000003015", 1, "of:0000000000006025", 1)
791 if ptp_intent_result == main.TRUE:
792 get_intent_result = main.ONOScli1.intents()
793 main.log.info("Point to point intent install successful")
794 #main.log.info(get_intent_result)
795
796 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000006025", 1, "of:0000000000003015", 1)
797 if ptp_intent_result == main.TRUE:
798 get_intent_result = main.ONOScli1.intents()
799 main.log.info("Point to point intent install successful")
800 #main.log.info(get_intent_result)
801
802 main.step("Add point-to-point intents for mininet hosts h16 and h26 or ONOS hosts h10 and h1A")
803 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000003016", 1, "of:0000000000006026", 1)
804 if ptp_intent_result == main.TRUE:
805 get_intent_result = main.ONOScli1.intents()
806 main.log.info("Point to point intent install successful")
807 #main.log.info(get_intent_result)
808
809 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000006026", 1, "of:0000000000003016", 1)
810 if ptp_intent_result == main.TRUE:
811 get_intent_result = main.ONOScli1.intents()
812 main.log.info("Point to point intent install successful")
813 #main.log.info(get_intent_result)
814
815
816 main.step("Add point-to-point intents for mininet hosts h17 and h27 or ONOS hosts h11 and h1B")
817 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000003017", 1, "of:0000000000006027", 1)
818 if ptp_intent_result == main.TRUE:
819 get_intent_result = main.ONOScli1.intents()
820 main.log.info("Point to point intent install successful")
821 #main.log.info(get_intent_result)
822
823 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000006027", 1, "of:0000000000003017", 1)
824 if ptp_intent_result == main.TRUE:
825 get_intent_result = main.ONOScli1.intents()
826 main.log.info("Point to point intent install successful")
827 #main.log.info(get_intent_result)
828
829 print("_______________________________________________________________________________________")
830
831 flowHandle = main.ONOScli1.flows()
832 #print "flowHandle = ", flowHandle
833 main.log.info("flows :" + flowHandle)
834
835 count = 1
836 i = 8
837 Ping_Result = main.TRUE
838 while i <18 :
839 main.log.info("\n\nh"+str(i)+" is Pinging h" + str(i+10))
840 ping = main.Mininet1.pingHost(src="h"+str(i),target="h"+str(i+10))
841 if ping == main.FALSE and count <5:
842 count+=1
843 #i = 8
844 Ping_Result = main.FALSE
845 main.log.report("Ping between h" + str(i) + " and h" + str(i+10) + " failed. Making attempt number "+str(count) + " in 2 seconds")
846 time.sleep(2)
847 elif ping==main.FALSE:
848 main.log.report("All ping attempts between h" + str(i) + " and h" + str(i+10) +"have failed")
849 i=19
850 Ping_Result = main.FALSE
851 elif ping==main.TRUE:
852 main.log.info("Ping test between h" + str(i) + " and h" + str(i+10) + "passed!")
853 i+=1
854 Ping_Result = main.TRUE
855 else:
856 main.log.info("Unknown error")
857 Ping_Result = main.ERROR
858 if Ping_Result==main.FALSE:
859 main.log.report("Ping all test after Point intents addition failed. Cleaning up")
860 #main.cleanup()
861 #main.exit()
862 if Ping_Result==main.TRUE:
863 main.log.report("Ping all test after Point intents addition successful")
864
865 case8_result = Ping_Result
866 utilities.assert_equals(expect=main.TRUE, actual=case8_result,
867 onpass="Ping all test after Point intents addition successful",
868 onfail="Ping all test after Point intents addition failed")
869