blob: eab5a9680146bf2fb997493b92216ead6fc736b1 [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 MultiProd13:
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
shahshreyaa9d79f22014-11-18 15:41:29 -0800358
359
360
361 def CASE10(self):
362 main.log.report("This testcase uninstalls the reactive forwarding app")
363 main.log.report("__________________________________")
364 main.case("Uninstalling reactive forwarding app")
365 #Unistall onos-app-fwd app to disable reactive forwarding
366 appUninstall_result = main.ONOScli1.feature_uninstall("onos-app-fwd")
367 appUninstall_result = main.ONOScli2.feature_uninstall("onos-app-fwd")
368 appUninstall_result = main.ONOScli3.feature_uninstall("onos-app-fwd")
369 main.log.info("onos-app-fwd uninstalled")
370
371 #After reactive forwarding is disabled, the reactive flows on switches timeout in 10-15s
372 #So sleep for 15s
373 time.sleep(15)
374
375 case10_result = appUninstall_result
376 utilities.assert_equals(expect=main.TRUE, actual=case10_result,onpass="Reactive forwarding app uninstallation successful",onfail="Reactive forwarding app uninstallation failed")
377
378
shahshreya4e13a062014-11-11 16:46:18 -0800379 def CASE6(self):
380 main.log.report("This testcase is testing the addition of host intents and then doing pingall")
381 main.log.report("__________________________________")
shahshreyaa9d79f22014-11-18 15:41:29 -0800382 main.case("Obtaining hostsfor adding host intents")
shahshreya4e13a062014-11-11 16:46:18 -0800383 main.step("Get hosts")
384 main.ONOScli1.handle.sendline("hosts")
385 main.ONOScli1.handle.expect("onos>")
386 hosts = main.ONOScli1.handle.before
387 main.log.info(hosts)
388
389 main.step("Get all devices id")
390 devices_id_list = main.ONOScli1.get_all_devices_id()
391 main.log.info(devices_id_list)
392
393 #ONOS displays the hosts in hex format unlike mininet which does in decimal format
394 #So take care while adding intents
shahshreyaa9d79f22014-11-18 15:41:29 -0800395
396 '''
shahshreya4e13a062014-11-11 16:46:18 -0800397 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)")
398 hth_intent_result = main.ONOScli1.add_host_intent("00:00:00:00:00:08/-1", "00:00:00:00:00:12/-1")
399 hth_intent_result = main.ONOScli1.add_host_intent("00:00:00:00:00:09/-1", "00:00:00:00:00:13/-1")
400 hth_intent_result = main.ONOScli1.add_host_intent("00:00:00:00:00:0A/-1", "00:00:00:00:00:14/-1")
401 hth_intent_result = main.ONOScli1.add_host_intent("00:00:00:00:00:0B/-1", "00:00:00:00:00:15/-1")
402 hth_intent_result = main.ONOScli1.add_host_intent("00:00:00:00:00:0C/-1", "00:00:00:00:00:16/-1")
403 hth_intent_result = main.ONOScli1.add_host_intent("00:00:00:00:00:0D/-1", "00:00:00:00:00:17/-1")
404 hth_intent_result = main.ONOScli1.add_host_intent("00:00:00:00:00:0E/-1", "00:00:00:00:00:18/-1")
405 hth_intent_result = main.ONOScli1.add_host_intent("00:00:00:00:00:0F/-1", "00:00:00:00:00:19/-1")
406 hth_intent_result = main.ONOScli1.add_host_intent("00:00:00:00:00:10/-1", "00:00:00:00:00:1A/-1")
407 hth_intent_result = main.ONOScli1.add_host_intent("00:00:00:00:00:11/-1", "00:00:00:00:00:1B/-1")
shahshreyaa9d79f22014-11-18 15:41:29 -0800408 '''
shahshreya4e13a062014-11-11 16:46:18 -0800409
shahshreyaa9d79f22014-11-18 15:41:29 -0800410 for i in range(8,18):
411 main.log.info("Adding host intent between h"+str(i)+" and h"+str(i+10))
412 host1 = "00:00:00:00:00:" + str(hex(i)[2:]).zfill(2).upper()
413 host2 = "00:00:00:00:00:" + str(hex(i+10)[2:]).zfill(2).upper()
414 #NOTE: get host can return None
415 #TODO: handle this
416 host1_id = main.ONOScli1.get_host(host1)['id']
417 host2_id = main.ONOScli1.get_host(host2)['id']
418 tmp_result = main.ONOScli1.add_host_intent(host1_id, host2_id )
shahshreya4e13a062014-11-11 16:46:18 -0800419
420 flowHandle = main.ONOScli1.flows()
421 #print "flowHandle = ", flowHandle
422 main.log.info("flows:" +flowHandle)
423
424 count = 1
425 i = 8
426 Ping_Result = main.TRUE
427 while i <18 :
428 main.log.info("\n\nh"+str(i)+" is Pinging h" + str(i+10))
429 ping = main.Mininet1.pingHost(src="h"+str(i),target="h"+str(i+10))
430 if ping == main.FALSE and count <5:
431 count+=1
432 #i = 8
433 Ping_Result = main.FALSE
434 main.log.report("Ping between h" + str(i) + " and h" + str(i+10) + " failed. Making attempt number "+str(count) + " in 2 seconds")
435 time.sleep(2)
436 elif ping==main.FALSE:
437 main.log.report("All ping attempts between h" + str(i) + " and h" + str(i+10) +"have failed")
438 i=19
439 Ping_Result = main.FALSE
440 elif ping==main.TRUE:
441 main.log.info("Ping test between h" + str(i) + " and h" + str(i+10) + "passed!")
442 i+=1
443 Ping_Result = main.TRUE
444 else:
445 main.log.info("Unknown error")
446 Ping_Result = main.ERROR
447 if Ping_Result==main.FALSE:
448 main.log.report("Host intents have not ben installed correctly. Cleaning up")
449 #main.cleanup()
450 #main.exit()
451 if Ping_Result==main.TRUE:
452 main.log.report("Host intents have been installed correctly")
453
454 case6_result = Ping_Result
455 utilities.assert_equals(expect=main.TRUE, actual=case6_result,
456 onpass="Host intent addition and Pingall Test successful",
457 onfail="Host intent addition and Pingall Test NOT successful")
458
459
460 def CASE7 (self,main):
461
462 ONOS1_ip = main.params['CTRL']['ip1']
463
464 link_sleep = int(main.params['timers']['LinkDiscovery'])
465
466 main.log.report("This testscase is killing a link to ensure that link discovery is consistent")
467 main.log.report("__________________________________")
468 main.case("Killing a link to Ensure that Link Discovery is Working Properly")
469 main.step("Start continuous pings")
470
471 main.Mininet2.pingLong(src=main.params['PING']['source1'],
472 target=main.params['PING']['target1'],pingTime=500)
473 main.Mininet2.pingLong(src=main.params['PING']['source2'],
474 target=main.params['PING']['target2'],pingTime=500)
475 main.Mininet2.pingLong(src=main.params['PING']['source3'],
476 target=main.params['PING']['target3'],pingTime=500)
477 main.Mininet2.pingLong(src=main.params['PING']['source4'],
478 target=main.params['PING']['target4'],pingTime=500)
479 main.Mininet2.pingLong(src=main.params['PING']['source5'],
480 target=main.params['PING']['target5'],pingTime=500)
481 main.Mininet2.pingLong(src=main.params['PING']['source6'],
482 target=main.params['PING']['target6'],pingTime=500)
483 main.Mininet2.pingLong(src=main.params['PING']['source7'],
484 target=main.params['PING']['target7'],pingTime=500)
485 main.Mininet2.pingLong(src=main.params['PING']['source8'],
486 target=main.params['PING']['target8'],pingTime=500)
487 main.Mininet2.pingLong(src=main.params['PING']['source9'],
488 target=main.params['PING']['target9'],pingTime=500)
489 main.Mininet2.pingLong(src=main.params['PING']['source10'],
490 target=main.params['PING']['target10'],pingTime=500)
491
492
493 main.step("Determine the current number of switches and links")
494 topology_output = main.ONOScli1.topology()
495 topology_result = main.ONOSbench.get_topology(topology_output)
496 activeSwitches = topology_result['devices']
497 links = topology_result['links']
498 print "activeSwitches = ", type(activeSwitches)
499 print "links = ", type(links)
500 main.log.info("Currently there are %s switches and %s links" %(str(activeSwitches), str(links)))
501
502 main.step("Kill Link between s3 and s28")
503 main.Mininet1.link(END1="s3",END2="s28",OPTION="down")
504 time.sleep(link_sleep)
505 topology_output = main.ONOScli2.topology()
506 Link_Down = main.ONOSbench.check_status(topology_output,activeSwitches,str(int(links)-2))
507 if Link_Down == main.TRUE:
508 main.log.report("Link Down discovered properly")
509 utilities.assert_equals(expect=main.TRUE,actual=Link_Down,
510 onpass="Link Down discovered properly",
511 onfail="Link down was not discovered in "+ str(link_sleep) + " seconds")
512
513 main.step("Bring link between s3 and s28 back up")
514 Link_Up = main.Mininet1.link(END1="s3",END2="s28",OPTION="up")
515 time.sleep(link_sleep)
516 topology_output = main.ONOScli2.topology()
517 Link_Up = main.ONOSbench.check_status(topology_output,activeSwitches,str(links))
518 if Link_Up == main.TRUE:
519 main.log.report("Link up discovered properly")
520 utilities.assert_equals(expect=main.TRUE,actual=Link_Up,
521 onpass="Link up discovered properly",
522 onfail="Link up was not discovered in "+ str(link_sleep) + " seconds")
523
524 main.step("Compare ONOS Topology to MN Topology")
525 main.case ("Testing Mininet topology with the topology of multi instances ONOS")
526 main.step("Collecting topology information from ONOS")
527 devices1 = main.ONOScli1.devices()
528 devices2 = main.ONOScli2.devices()
529 devices3 = main.ONOScli3.devices()
530 print "devices1 = ", devices1
531 print "devices2 = ", devices2
532 print "devices3 = ", devices3
533 hosts1 = main.ONOScli1.hosts()
534 hosts2 = main.ONOScli2.hosts()
535 hosts3 = main.ONOScli3.hosts()
536 #print "hosts1 = ", hosts1
537 #print "hosts2 = ", hosts2
538 #print "hosts3 = ", hosts3
539 ports1 = main.ONOScli1.ports()
540 ports2 = main.ONOScli2.ports()
541 ports3 = main.ONOScli3.ports()
542 #print "ports1 = ", ports1
543 #print "ports2 = ", ports2
544 #print "ports3 = ", ports3
545 links1 = main.ONOScli1.links()
546 links2 = main.ONOScli2.links()
547 links3 = main.ONOScli3.links()
548 #print "links1 = ", links1
549 #print "links2 = ", links2
550 #print "links3 = ", links3
551
552 print "**************"
553
554 main.step("Start continuous pings")
555 main.Mininet2.pingLong(src=main.params['PING']['source1'],
556 target=main.params['PING']['target1'],pingTime=500)
557 main.Mininet2.pingLong(src=main.params['PING']['source2'],
558 target=main.params['PING']['target2'],pingTime=500)
559 main.Mininet2.pingLong(src=main.params['PING']['source3'],
560 target=main.params['PING']['target3'],pingTime=500)
561 main.Mininet2.pingLong(src=main.params['PING']['source4'],
562 target=main.params['PING']['target4'],pingTime=500)
563 main.Mininet2.pingLong(src=main.params['PING']['source5'],
564 target=main.params['PING']['target5'],pingTime=500)
565 main.Mininet2.pingLong(src=main.params['PING']['source6'],
566 target=main.params['PING']['target6'],pingTime=500)
567 main.Mininet2.pingLong(src=main.params['PING']['source7'],
568 target=main.params['PING']['target7'],pingTime=500)
569 main.Mininet2.pingLong(src=main.params['PING']['source8'],
570 target=main.params['PING']['target8'],pingTime=500)
571 main.Mininet2.pingLong(src=main.params['PING']['source9'],
572 target=main.params['PING']['target9'],pingTime=500)
573 main.Mininet2.pingLong(src=main.params['PING']['source10'],
574 target=main.params['PING']['target10'],pingTime=500)
575
576 main.step("Create TestONTopology object")
577 global ctrls
578 ctrls = []
579 count = 1
580 while True:
581 temp = ()
582 if ('ip' + str(count)) in main.params['CTRL']:
583 temp = temp + (getattr(main,('ONOS' + str(count))),)
584 temp = temp + ("ONOS"+str(count),)
585 temp = temp + (main.params['CTRL']['ip'+str(count)],)
586 temp = temp + (eval(main.params['CTRL']['port'+str(count)]),)
587 ctrls.append(temp)
588 count = count + 1
589 else:
590 break
591 global MNTopo
592 Topo = TestONTopology(main.Mininet1, ctrls) # can also add Intent API info for intent operations
593 MNTopo = Topo
594
595 Topology_Check = main.TRUE
596 main.step("Compare ONOS Topology to MN Topology")
597
598 switches_results1 = main.Mininet1.compare_switches(MNTopo, json.loads(devices1))
599 print "switches_Result1 = ", switches_results1
600 utilities.assert_equals(expect=main.TRUE, actual=switches_results1,
601 onpass="ONOS1 Switches view is correct",
602 onfail="ONOS1 Switches view is incorrect")
603
604 switches_results2 = main.Mininet1.compare_switches(MNTopo, json.loads(devices2))
605 utilities.assert_equals(expect=main.TRUE, actual=switches_results2,
606 onpass="ONOS2 Switches view is correct",
607 onfail="ONOS2 Switches view is incorrect")
608
609 switches_results3 = main.Mininet1.compare_switches(MNTopo, json.loads(devices3))
610 utilities.assert_equals(expect=main.TRUE, actual=switches_results3,
611 onpass="ONOS3 Switches view is correct",
612 onfail="ONOS3 Switches view is incorrect")
613
614 '''
615 ports_results1 = main.Mininet1.compare_ports(MNTopo, json.loads(ports1))
616 utilities.assert_equals(expect=main.TRUE, actual=ports_results1,
617 onpass="ONOS1 Ports view is correct",
618 onfail="ONOS1 Ports view is incorrect")
619
620 ports_results2 = main.Mininet1.compare_ports(MNTopo, json.loads(ports2))
621 utilities.assert_equals(expect=main.TRUE, actual=ports_results2,
622 onpass="ONOS2 Ports view is correct",
623 onfail="ONOS2 Ports view is incorrect")
624
625 ports_results3 = main.Mininet1.compare_ports(MNTopo, json.loads(ports3))
626 utilities.assert_equals(expect=main.TRUE, actual=ports_results3,
627 onpass="ONOS3 Ports view is correct",
628 onfail="ONOS3 Ports view is incorrect")
629 '''
630
631 links_results1 = main.Mininet1.compare_links(MNTopo, json.loads(links1))
632 utilities.assert_equals(expect=main.TRUE, actual=links_results1,
633 onpass="ONOS1 Links view is correct",
634 onfail="ONOS1 Links view is incorrect")
635
636 links_results2 = main.Mininet1.compare_links(MNTopo, json.loads(links2))
637 utilities.assert_equals(expect=main.TRUE, actual=links_results2,
638 onpass="ONOS2 Links view is correct",
639 onfail="ONOS2 Links view is incorrect")
640
641 links_results3 = main.Mininet1.compare_links(MNTopo, json.loads(links3))
642 utilities.assert_equals(expect=main.TRUE, actual=links_results3,
643 onpass="ONOS2 Links view is correct",
644 onfail="ONOS2 Links view is incorrect")
645
646 #topo_result = switches_results1 and switches_results2 and switches_results3\
647 #and ports_results1 and ports_results2 and ports_results3\
648 #and links_results1 and links_results2 and links_results3
649
650 topo_result = switches_results1 and switches_results2 and switches_results3\
651 and links_results1 and links_results2 and links_results3
652
653 utilities.assert_equals(expect=main.TRUE, actual=topo_result and Link_Up and Link_Down,
654 onpass="Topology Check Test successful",
655 onfail="Topology Check Test NOT successful")
656
657
658 def CASE8(self):
659 '''
660 Host intents removal
661 '''
662 main.log.report("This testcase removes host intents before adding the point intents")
663 main.log.report("__________________________________")
664 main.log.info("Host intents removal")
665 main.case("Removing host intents")
666 main.step("Obtain the intent id's")
667 intent_result = main.ONOScli1.intents()
668 #print "intent_result = ",intent_result
shahshreyaa9d79f22014-11-18 15:41:29 -0800669
shahshreya4e13a062014-11-11 16:46:18 -0800670 intent_linewise = intent_result.split("\n")
shahshreyaa9d79f22014-11-18 15:41:29 -0800671 intentList = []
shahshreya4e13a062014-11-11 16:46:18 -0800672 for line in intent_linewise:
shahshreyaa9d79f22014-11-18 15:41:29 -0800673 if line.startswith("id="):
674 intentList.append(line)
675
676 intentids = []
677 for line in intentList:
shahshreya4e13a062014-11-11 16:46:18 -0800678 intentids.append(line.split(",")[0].split("=")[1])
679 for id in intentids:
680 print "id = ", id
shahshreyaa9d79f22014-11-18 15:41:29 -0800681
shahshreya4e13a062014-11-11 16:46:18 -0800682 main.step("Iterate through the intentids list and remove each intent")
683 for id in intentids:
684 main.ONOScli1.remove_intent(intent_id = id)
shahshreyaa9d79f22014-11-18 15:41:29 -0800685
shahshreya4e13a062014-11-11 16:46:18 -0800686 intent_result = main.ONOScli1.intents()
687 intent_linewise = intent_result.split("\n")
shahshreyaa9d79f22014-11-18 15:41:29 -0800688 list_afterRemoval = []
689 for line in intent_linewise:
690 if line.startswith("id="):
691 list_afterRemoval.append(line)
692
shahshreya4e13a062014-11-11 16:46:18 -0800693 intentState = {}
shahshreyaa9d79f22014-11-18 15:41:29 -0800694 for id, line in zip(intentids, list_afterRemoval):
shahshreya4e13a062014-11-11 16:46:18 -0800695 #print "line after removing intent = ", line
696 x = line.split(",")
697 state = x[1].split("=")[1]
698 intentState[id] = state
shahshreyaa9d79f22014-11-18 15:41:29 -0800699
shahshreya4e13a062014-11-11 16:46:18 -0800700 case8_result = main.TRUE
701 for key,value in intentState.iteritems():
702 print "key,value = ", key, value
703 if value == "WITHDRAWN":
704 case8_result = case8_result and main.TRUE
705 else:
706 case8_result = case8_result and main.FALSE
707
708 if case8_result == main.TRUE:
709 main.log.report("Intent removal successful")
710 else:
711 main.log.report("Intent removal failed")
712
713 utilities.assert_equals(expect=main.TRUE, actual=case8_result,
714 onpass="Intent removal test successful",
715 onfail="Intent removal test failed")
716
717
718 def CASE9(self):
719 '''
720 This test case adds point intents. Make sure you run test case 8 which is host intent removal before executing this test case.
721 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
722 '''
723 main.log.report("This testcase adds point intents and then does pingall")
724 main.log.report("__________________________________")
725 main.log.info("Adding point intents")
726 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)")
727 main.step("Add point-to-point intents for mininet hosts h8 and h18 or ONOS hosts h8 and h12")
728 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000003008", 1, "of:0000000000006018", 1)
729 if ptp_intent_result == main.TRUE:
730 get_intent_result = main.ONOScli1.intents()
731 main.log.info("Point to point intent install successful")
732 #main.log.info(get_intent_result)
733
734 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000006018", 1, "of:0000000000003008", 1)
735 if ptp_intent_result == main.TRUE:
736 get_intent_result = main.ONOScli1.intents()
737 main.log.info("Point to point intent install successful")
738 #main.log.info(get_intent_result)
739
740 main.step("Add point-to-point intents for mininet hosts h9 and h19 or ONOS hosts h9 and h13")
741 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000003009", 1, "of:0000000000006019", 1)
742 if ptp_intent_result == main.TRUE:
743 get_intent_result = main.ONOScli1.intents()
744 main.log.info("Point to point intent install successful")
745 #main.log.info(get_intent_result)
746
747 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000006019", 1, "of:0000000000003009", 1)
748 if ptp_intent_result == main.TRUE:
749 get_intent_result = main.ONOScli1.intents()
750 main.log.info("Point to point intent install successful")
751 #main.log.info(get_intent_result)
752
753 main.step("Add point-to-point intents for mininet hosts h10 and h20 or ONOS hosts hA and h14")
754 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000003010", 1, "of:0000000000006020", 1)
755 if ptp_intent_result == main.TRUE:
756 get_intent_result = main.ONOScli1.intents()
757 main.log.info("Point to point intent install successful")
758 #main.log.info(get_intent_result)
759
760 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000006020", 1, "of:0000000000003010", 1)
761 if ptp_intent_result == main.TRUE:
762 get_intent_result = main.ONOScli1.intents()
763 main.log.info("Point to point intent install successful")
764 #main.log.info(get_intent_result)
765
766 main.step("Add point-to-point intents for mininet hosts h11 and h21 or ONOS hosts hB and h15")
767 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000003011", 1, "of:0000000000006021", 1)
768 if ptp_intent_result == main.TRUE:
769 get_intent_result = main.ONOScli1.intents()
770 main.log.info("Point to point intent install successful")
771 #main.log.info(get_intent_result)
772
773 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000006021", 1, "of:0000000000003011", 1)
774 if ptp_intent_result == main.TRUE:
775 get_intent_result = main.ONOScli1.intents()
776 main.log.info("Point to point intent install successful")
777 #main.log.info(get_intent_result)
778
779 main.step("Add point-to-point intents for mininet hosts h12 and h22 or ONOS hosts hC and h16")
780 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000003012", 1, "of:0000000000006022", 1)
781 if ptp_intent_result == main.TRUE:
782 get_intent_result = main.ONOScli1.intents()
783 main.log.info("Point to point intent install successful")
784 #main.log.info(get_intent_result)
785
786 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000006022", 1, "of:0000000000003012", 1)
787 if ptp_intent_result == main.TRUE:
788 get_intent_result = main.ONOScli1.intents()
789 main.log.info("Point to point intent install successful")
790 #main.log.info(get_intent_result)
791
792 main.step("Add point-to-point intents for mininet hosts h13 and h23 or ONOS hosts hD and h17")
793 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000003013", 1, "of:0000000000006023", 1)
794 if ptp_intent_result == main.TRUE:
795 get_intent_result = main.ONOScli1.intents()
796 main.log.info("Point to point intent install successful")
797 #main.log.info(get_intent_result)
798
799 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000006023", 1, "of:0000000000003013", 1)
800 if ptp_intent_result == main.TRUE:
801 get_intent_result = main.ONOScli1.intents()
802 main.log.info("Point to point intent install successful")
803 #main.log.info(get_intent_result)
804
805 main.step("Add point-to-point intents for mininet hosts h14 and h24 or ONOS hosts hE and h18")
806 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000003014", 1, "of:0000000000006024", 1)
807 if ptp_intent_result == main.TRUE:
808 get_intent_result = main.ONOScli1.intents()
809 main.log.info("Point to point intent install successful")
810 #main.log.info(get_intent_result)
811
812 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000006024", 1, "of:0000000000003014", 1)
813 if ptp_intent_result == main.TRUE:
814 get_intent_result = main.ONOScli1.intents()
815 main.log.info("Point to point intent install successful")
816 #main.log.info(get_intent_result)
817
818 main.step("Add point-to-point intents for mininet hosts h15 and h25 or ONOS hosts hF and h19")
819 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000003015", 1, "of:0000000000006025", 1)
820 if ptp_intent_result == main.TRUE:
821 get_intent_result = main.ONOScli1.intents()
822 main.log.info("Point to point intent install successful")
823 #main.log.info(get_intent_result)
824
825 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000006025", 1, "of:0000000000003015", 1)
826 if ptp_intent_result == main.TRUE:
827 get_intent_result = main.ONOScli1.intents()
828 main.log.info("Point to point intent install successful")
829 #main.log.info(get_intent_result)
830
831 main.step("Add point-to-point intents for mininet hosts h16 and h26 or ONOS hosts h10 and h1A")
832 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000003016", 1, "of:0000000000006026", 1)
833 if ptp_intent_result == main.TRUE:
834 get_intent_result = main.ONOScli1.intents()
835 main.log.info("Point to point intent install successful")
836 #main.log.info(get_intent_result)
837
838 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000006026", 1, "of:0000000000003016", 1)
839 if ptp_intent_result == main.TRUE:
840 get_intent_result = main.ONOScli1.intents()
841 main.log.info("Point to point intent install successful")
842 #main.log.info(get_intent_result)
843
844
845 main.step("Add point-to-point intents for mininet hosts h17 and h27 or ONOS hosts h11 and h1B")
846 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000003017", 1, "of:0000000000006027", 1)
847 if ptp_intent_result == main.TRUE:
848 get_intent_result = main.ONOScli1.intents()
849 main.log.info("Point to point intent install successful")
850 #main.log.info(get_intent_result)
851
852 ptp_intent_result = main.ONOScli1.add_point_intent("of:0000000000006027", 1, "of:0000000000003017", 1)
853 if ptp_intent_result == main.TRUE:
854 get_intent_result = main.ONOScli1.intents()
855 main.log.info("Point to point intent install successful")
856 #main.log.info(get_intent_result)
857
858 print("_______________________________________________________________________________________")
859
860 flowHandle = main.ONOScli1.flows()
861 #print "flowHandle = ", flowHandle
862 main.log.info("flows :" + flowHandle)
863
864 count = 1
865 i = 8
866 Ping_Result = main.TRUE
867 while i <18 :
868 main.log.info("\n\nh"+str(i)+" is Pinging h" + str(i+10))
869 ping = main.Mininet1.pingHost(src="h"+str(i),target="h"+str(i+10))
870 if ping == main.FALSE and count <5:
871 count+=1
872 #i = 8
873 Ping_Result = main.FALSE
874 main.log.report("Ping between h" + str(i) + " and h" + str(i+10) + " failed. Making attempt number "+str(count) + " in 2 seconds")
875 time.sleep(2)
876 elif ping==main.FALSE:
877 main.log.report("All ping attempts between h" + str(i) + " and h" + str(i+10) +"have failed")
878 i=19
879 Ping_Result = main.FALSE
880 elif ping==main.TRUE:
881 main.log.info("Ping test between h" + str(i) + " and h" + str(i+10) + "passed!")
882 i+=1
883 Ping_Result = main.TRUE
884 else:
885 main.log.info("Unknown error")
886 Ping_Result = main.ERROR
887 if Ping_Result==main.FALSE:
888 main.log.report("Ping all test after Point intents addition failed. Cleaning up")
889 #main.cleanup()
890 #main.exit()
891 if Ping_Result==main.TRUE:
892 main.log.report("Ping all test after Point intents addition successful")
893
894 case8_result = Ping_Result
895 utilities.assert_equals(expect=main.TRUE, actual=case8_result,
896 onpass="Ping all test after Point intents addition successful",
897 onfail="Ping all test after Point intents addition failed")
898
shahshreyaa9d79f22014-11-18 15:41:29 -0800899 def CASE31(self):
900 '''
901 This test case adds point intent related to SDN-IP matching on ICMP (ethertype=IPV4, ipProto=1)
902 '''
903 import json
904
905 main.log.report("This test case adds point intent related to SDN-IP matching on ICMP")
906 main.step("Adding bidirectional point intent")
907 #add-point-intent --ipSrc=10.0.0.8/32 --ipDst=10.0.0.18/32 --ethType=IPV4 --ipProto=1 of:0000000000003008/1 of:0000000000006018/1
908
909 hosts_json = json.loads(main.ONOScli1.hosts())
910 for i in range(8,11):
911 main.log.info("Adding point intent between h"+str(i)+" and h"+str(i+10))
912 host1 = "00:00:00:00:00:" + str(hex(i)[2:]).zfill(2).upper()
913 host2 = "00:00:00:00:00:" + str(hex(i+10)[2:]).zfill(2).upper()
914 host1_id = main.ONOScli1.get_host(host1)['id']
915 host2_id = main.ONOScli1.get_host(host2)['id']
916 for host in hosts_json:
917 if host['id'] == host1_id:
918 ip1 = str(host['ips'])
919 device1 = str(host['location']['device'])
920 port1 = 1
921 print "ip1 = ", ip1
922 print "device1 = ", device1
923 elif host['id'] == host2_id:
924 ip2 = host['ips']
925 device2 = host['location']["device"]
926 port2 = 1
927 print "ip2 = ", ip2
928 print "device2 = ", device2