blob: 8e53fd2443a643be707115b71824d41529bb3636 [file] [log] [blame]
Jon Hall42db6dc2014-10-24 19:03:48 -04001
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
9
10class JonTest:
11 def __init__(self):
12 self.default = ''
13
14 def CASE1(self, main):
15 '''
16 Startup sequence:
17 git pull
18 mvn clean install
19 onos-package
20 cell <name>
21 onos-verify-cell
22 onos-install -f
23 onos-wait-for-start
24 '''
25 import time
26
27 PULL_CODE = False
28 if main.params['Git'] == 'True':
29 PULL_CODE = True
30 cell_name = main.params['ENV']['cellName']
31 ONOS1_ip = main.params['CTRL']['ip1']
32 ONOS1_port = main.params['CTRL']['port1']
33 ONOS2_ip = main.params['CTRL']['ip2']
34 ONOS2_port = main.params['CTRL']['port2']
35
36 main.case("Setting up test environment")
37
38 main.step("Applying cell variable to environment")
39 cell_result = main.ONOSbench.set_cell(cell_name)
40 #cell_result = main.ONOSbench.set_cell("temp_cell_2")
41 verify_result = main.ONOSbench.verify_cell()
42
43 if PULL_CODE:
44 main.step("Git checkout and pull master")
45 #main.log.report("Skipping git pull")
46 main.ONOSbench.git_checkout("master")
47 git_pull_result = main.ONOSbench.git_pull()
48 main.log.report(main.ONOSbench.get_version())
49
50 main.step("Using mvn clean & install")
51 clean_install_result = main.FALSE
Jon Hall413ade52014-10-28 19:06:56 -040052 if git_pull_result == main.TRUE:
Jon Hall42db6dc2014-10-24 19:03:48 -040053 clean_install_result = main.ONOSbench.clean_install()
54 else:
Jon Hall413ade52014-10-28 19:06:56 -040055 main.log.report("did not pull new code so skipping mvn clean install")
Jon Hall42db6dc2014-10-24 19:03:48 -040056
57 main.step("Creating ONOS package")
58 package_result = main.ONOSbench.onos_package()
59
60 main.step("Installing ONOS package")
61 onos1_install_result = main.ONOSbench.onos_install(options="-f", node=ONOS1_ip)
62 onos2_install_result = main.ONOSbench.onos_install(options="-f", node=ONOS2_ip)
63 onos1_isup = main.ONOSbench.isup(ONOS1_ip)
64 onos2_isup = main.ONOSbench.isup(ONOS2_ip)
65
66 main.step("Starting ONOS service")
67 start_result = main.TRUE
68 #start_result = main.ONOSbench.onos_start(ONOS1_ip)
69
Jon Hall413ade52014-10-28 19:06:56 -040070 main.ONOScli1.start_onos_cli(ONOS1_ip)
71 main.ONOScli2.start_onos_cli(ONOS2_ip)
72
Jon Hall42db6dc2014-10-24 19:03:48 -040073 case1_result = (clean_install_result and package_result and\
74 cell_result and verify_result and onos1_install_result and\
75 onos2_install_result and onos1_isup and onos2_isup )
76 utilities.assert_equals(expect=main.TRUE, actual=case1_result,
77 onpass="Test startup successful",
78 onfail="Test startup NOT successful")
79
80
81 def CASE11(self, main):
82 '''
83 Cleanup sequence:
84 onos-service <node_ip> stop
85 onos-uninstall
86
87 TODO: Define rest of cleanup
88
89 '''
90
91 ONOS1_ip = main.params['CTRL']['ip1']
92
93 main.case("Cleaning up test environment")
94
95 main.step("Testing ONOS kill function")
96 kill_result = main.ONOSbench.onos_kill(ONOS1_ip)
97
98 main.step("Stopping ONOS service")
99 stop_result = main.ONOSbench.onos_stop(ONOS1_ip)
100
101 main.step("Uninstalling ONOS service")
102 uninstall_result = main.ONOSbench.onos_uninstall()
103
104 def CASE3(self, main):
105 '''
106 Test 'onos' command and its functionality in driver
107 '''
108
109 ONOS1_ip = main.params['CTRL']['ip1']
110
111 main.case("Testing 'onos' command")
112
113 main.step("Sending command 'onos -w <onos-ip> system:name'")
114 cmdstr1 = "system:name"
115 cmd_result1 = main.ONOSbench.onos_cli(ONOS1_ip, cmdstr1)
116 main.log.info("onos command returned: "+cmd_result1)
117
118 main.step("Sending command 'onos -w <onos-ip> onos:topology'")
119 cmdstr2 = "onos:topology"
120 cmd_result2 = main.ONOSbench.onos_cli(ONOS1_ip, cmdstr2)
121 main.log.info("onos command returned: "+cmd_result2)
122
123 main.step("Testing check_status")
124 check_status_results = main.FALSE
Jon Hall413ade52014-10-28 19:06:56 -0400125 topology_result = main.ONOScli1.topology()
126 check_status_results = main.ONOSbench.check_status(topology_result, 4, 6)
Jon Hall42db6dc2014-10-24 19:03:48 -0400127 main.log.info("Results of check_status " + str(check_status_results))
128
129 main.step("Sending command 'onos -w <onos-ip> bundle:list'")
130 cmdstr3 = "bundle:list"
131 cmd_result3 = main.ONOSbench.onos_cli(ONOS1_ip, cmdstr3)
132 main.log.info("onos command returned: "+cmd_result3)
133 case3_result = (cmd_result1 and cmd_result2 and\
134 check_status_results and cmd_result3 )
135 utilities.assert_equals(expect=main.TRUE, actual=case3_result,
136 onpass="Test case 3 successful",
137 onfail="Test case 3 NOT successful")
138
139 def CASE4(self, main):
140 import re
141 import time
142 main.case("Pingall Test(No intents are added)")
143 main.step("Assigning switches to controllers")
144 for i in range(1,5): #1 to (num of switches +1)
145 main.Mininet1.assign_sw_controller(sw=str(i),count=2,
146 ip1=ONOS1_ip, port1=ONOS1_port,
147 ip2=ONOS2_ip, port2=ONOS2_port)
148
149 switch_mastership = main.TRUE
150 for i in range (1,5):
151 response = main.Mininet1.get_sw_controller("s"+str(i))
152 print("Response is " + str(response))
153 if re.search("tcp:"+ONOS1_ip,response):
154 switch_mastership = switch_mastership and main.TRUE
155 else:
156 switch_mastership = main.FALSE
157
158
159 #REACTIVE FWD test
160 main.step("Pingall")
161 ping_result = main.FALSE
162 time1 = time.time()
163 ping_result = main.Mininet1.pingall()
164 time2 = time.time()
165 print "Time for pingall: %2f seconds" % (time2 - time1)
166
167 case4_result = switch_mastership and ping_result
168 utilities.assert_equals(expect=main.TRUE, actual=case4_result,
169 onpass="Pingall Test successful",
170 onfail="Pingall Test NOT successful")
171
172 def CASE5(self, main):
173 '''
174 Test the ONOS-cli functionality
175
176 Below are demonstrations of what the
177 ONOS cli driver functions can be used for.
178 '''
179 import time
180 import json
181
182 cell_name = main.params['ENV']['cellName']
183 ONOS1_ip = main.params['CTRL']['ip1']
184
185 main.case("Testing the ONOS-cli")
186
187 main.step("Set cell for ONOS-cli environment")
188 main.ONOScli.set_cell(cell_name)
189
190 main.step("Start ONOS-cli")
191 main.ONOScli.start_onos_cli(ONOS1_ip)
192
193 main.step("issue command: onos:topology")
194 topology_obj = main.ONOScli.topology()
195
196 main.step("issue various feature:install <str> commands")
197 #main.ONOScli.feature_install("onos-app-fwd")
198 #main.ONOScli.feature_install("onos-rest")
199
200 main.step("Add a bad node")
201 node_result = main.ONOScli.add_node("111", "10.128.20.")
202 if node_result == main.TRUE:
203 main.log.info("Node successfully added")
204
205 main.step("Add a correct node")
206 node_result = main.ONOScli.add_node("111", "10.128.20.12")
207
208 main.step("Assign switches and list devices")
209 for i in range(1,8):
210 main.Mininet1.handle.sendline("sh ovs-vsctl set-controller s"+str(i)+
211 " tcp:10.128.20.11")
212 main.Mininet1.handle.expect("mininet>")
213 #Need to sleep to allow switch add processing
214 time.sleep(5)
215 list_result = main.ONOScli.devices()
216 main.log.info(list_result)
217
218 main.step("Get all devices id")
219 devices_id_list = main.ONOScli.get_all_devices_id()
220 main.log.info(devices_id_list)
221
222 main.step("Get path and cost between device 1 and 7")
223 (path, cost) = main.ONOScli.paths(devices_id_list[0], devices_id_list[6])
224 main.log.info("Path: "+str(path))
225 main.log.info("Cost: "+str(cost))
226
227 main.step("Get nodes currently visible")
228 nodes_str = main.ONOScli.nodes()
229 main.log.info(nodes_str)
230
231 main.step("Get all nodes id's")
232 node_id_list = main.ONOScli.get_all_nodes_id()
233 main.log.info(node_id_list)
234
235 main.step("Set device "+str(devices_id_list[0])+" to role: standby")
236 device_role_result = main.ONOScli.device_role(
237 devices_id_list[0], node_id_list[0], "standby")
238 if device_role_result == main.TRUE:
239 main.log.report("Device role successfully set")
240
241 main.step("Revert device role to master")
242 device_role = main.ONOScli.device_role(
243 devices_id_list[0], node_id_list[0], "master")
244
245 main.step("Check devices / role again")
246 dev_result = main.ONOScli.devices()
247 main.log.info(dev_result)
248
249 #Sample steps to push intents ***********
250 # * Obtain host id in ONOS format
251 # * Push intents
252 main.step("Get list of hosts from Mininet")
253 host_list = main.Mininet2.get_hosts()
254 main.log.info(host_list)
255
256 main.step("Get host list in ONOS format")
257 host_onos_list = main.ONOScli.get_hosts_id(host_list)
258 main.log.info(host_onos_list)
259
260 main.step("Ensure that reactive forwarding is installed")
261 feature_result = main.ONOScli.feature_install("onos-app-fwd")
262
263 time.sleep(5)
264
265 main.Mininet2.handle.sendline("\r")
266 main.Mininet2.handle.sendline("h4 ping h5 -c 1")
267
268 time.sleep(5)
269
270 main.step("Get hosts")
271 main.ONOScli.handle.sendline("hosts")
272 main.ONOScli.handle.expect("onos>")
273 hosts = main.ONOScli.handle.before
274 main.log.info(hosts)
275
276 main.step("Install host-to-host-intents between h4 and h5")
277 intent_install = main.ONOScli.add_host_intent(
278 host_onos_list[3], host_onos_list[4])
279 main.log.info(intent_install)
280
281 main.step("Uninstall reactive forwarding to test host-to-host intent")
282 main.ONOScli.feature_uninstall("onos-app-fwd")
283
284 main.step("Get intents installed on ONOS")
285 get_intent_result = main.ONOScli.intents()
286 main.log.info(get_intent_result)
287 #****************************************
288
289
290 def CASE7(self, main):
291 '''
292 Test compare topo functions
293 '''
294 import sys
295 sys.path.append("/home/admin/sts") # Trying to remove some dependancies, #FIXME add this path to params
296 from sts.topology.teston_topology import TestONTopology # assumes that sts is already in you PYTHONPATH
297 import json
298
299 main.step("Create TestONTopology object")
300 ctrls = []
301 count = 1
302 while True:
303 temp = ()
304 if ('ip' + str(count)) in main.params['CTRL']:
305 temp = temp + (getattr(main,('ONOS' + str(count))),)
306 temp = temp + ("ONOS"+str(count),)
307 temp = temp + (main.params['CTRL']['ip'+str(count)],)
308 temp = temp + (eval(main.params['CTRL']['port'+str(count)]),)
309 ctrls.append(temp)
310 count = count + 1
311 else:
312 break
313 MNTopo = TestONTopology(main.Mininet1, ctrls) # can also add Intent API info for intent operations
314
315 ONOS1_ip = main.params['CTRL']['ip1']
316 ONOS2_ip = main.params['CTRL']['ip2']
317
Jon Hall42db6dc2014-10-24 19:03:48 -0400318
319 main.step("Collecting topology information from ONOS")
320 devices1 = main.ONOScli1.devices()
321 devices2 = main.ONOScli2.devices()
322 switch1 = main.ONOScli1.get_device("0000000000000001")
323 hosts1 = main.ONOScli1.hosts()
324 hosts2 = main.ONOScli2.hosts()
325 host1 = main.ONOScli1.get_host("00:00:00:00:00:01")
Jon Hall413ade52014-10-28 19:06:56 -0400326 #print json.dumps(json.loads(hosts1), sort_keys=True,indent=4,separators=(',', ': '))
327 #print json.dumps(json.loads(hosts2), sort_keys=True,indent=4,separators=(',', ': '))
328 #print json.dumps(host1, sort_keys=True,indent=4,separators=(',', ': '))
Jon Hall42db6dc2014-10-24 19:03:48 -0400329 ports1 = main.ONOScli1.ports()
330 ports2 = main.ONOScli2.ports()
331 links1 = main.ONOScli1.links()
332 links2 = main.ONOScli2.links()
333
334
335 main.step("Comparing ONOS topology to MN")
336 #results = main.Mininet1.compare_topo(MNTopo, json.loads(devices))
337 switches_results1 = main.Mininet1.compare_switches(MNTopo, json.loads(devices1))
338 utilities.assert_equals(expect=main.TRUE, actual=switches_results1,
339 onpass="ONOS1 Switches view is correct",
340 onfail="ONOS1 Switches view is incorrect")
341
342 switches_results2 = main.Mininet1.compare_switches(MNTopo, json.loads(devices2))
343 utilities.assert_equals(expect=main.TRUE, actual=switches_results2,
344 onpass="ONOS2 Switches view is correct",
345 onfail="ONOS2 Switches view is incorrect")
346
347
348 ports_results1 = main.Mininet1.compare_ports(MNTopo, json.loads(ports1))
349 utilities.assert_equals(expect=main.TRUE, actual=ports_results1,
350 onpass="ONOS1 Ports view is correct",
351 onfail="ONOS1 Ports view is incorrect")
352
353 ports_results2 = main.Mininet1.compare_ports(MNTopo, json.loads(ports2))
354 utilities.assert_equals(expect=main.TRUE, actual=ports_results2,
355 onpass="ONOS2 Ports view is correct",
356 onfail="ONOS2 Ports view is incorrect")
357
358 links_results1 = main.Mininet1.compare_links(MNTopo, json.loads(links1))
359 utilities.assert_equals(expect=main.TRUE, actual=links_results1,
360 onpass="ONOS1 Links view is correct",
361 onfail="ONOS1 Links view is incorrect")
362
363 links_results2 = main.Mininet1.compare_links(MNTopo, json.loads(links2))
364 utilities.assert_equals(expect=main.TRUE, actual=links_results2,
365 onpass="ONOS2 Links view is correct",
366 onfail="ONOS2 Links view is incorrect")
367
368 topo_result = switches_results1 and switches_results2 \
369 and ports_results1 and ports_results2\
370 and links_results1 and links_results2
371 utilities.assert_equals(expect=main.TRUE, actual=topo_result,
372 onpass="Topology Check Test successful",
373 onfail="Topology Check Test NOT successful")
374
Jon Hall413ade52014-10-28 19:06:56 -0400375 def CASE8(self, main):
376 '''
377 try doing some role assignments
378 '''
379 import time
380 print main.ONOScli1.devices()
381 print main.ONOScli1.device_role("of:0000000000000001", " ", "none")
382 time.sleep(1)
383 roles = main.ONOScli1.roles()
384 roles2 = main.ONOScli2.roles()
385 print roles
386 print roles2
387 print main.ONOScli1.get_role("00001")
388
389 print main.ONOScli1.devices()
390 print main.ONOScli1.device_role("of:0000000000000001", "10.128.30.11", "master")
391 time.sleep(1)
392 roles = main.ONOScli1.roles()
393 roles2 = main.ONOScli2.roles()
394 print roles
395 print roles2
396 print main.ONOScli1.get_role("00001")
397
398 print main.ONOScli1.devices()
399 print main.ONOScli1.device_role("of:0000000000000001", "10.128.30.11", "standby")
400 time.sleep(1)
401 roles = main.ONOScli1.roles()
402 roles2 = main.ONOScli2.roles()
403 print roles
404 print roles2
405 print main.ONOScli1.get_role("00001")
406
407 print main.ONOScli1.devices()
408 print main.ONOScli1.device_role("of:0000000000000001", "10.128.30.11", "MASTER")
409 time.sleep(1)
410 roles = main.ONOScli1.roles()
411 roles2 = main.ONOScli2.roles()
412 print roles
413 print roles2
414 print main.ONOScli1.get_role("00001")
415 print main.ONOScli1.devices()
416
417 def CASE9(self, main):
418 '''
419 Bring Links down
420 '''
421 main.Mininet1.link(END1="s1", END2="s2", OPTION="down")
422 main.Mininet1.link(END1="s1", END2="s3", OPTION="down")
423 main.Mininet1.link(END1="s1", END2="s4", OPTION="down")
424
425
426
427
Jon Hall42db6dc2014-10-24 19:03:48 -0400428######
429#jhall@onlab.us
430#andrew@onlab.us
431######