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