blob: f01446c8c5de02e94ae0faf099b6d9e9a60c1ac1 [file] [log] [blame]
andrewonlab4a5c4472014-10-09 12:11:41 -04001
2#Testing the basic functionality of ONOS Next
3#For sanity and driver functionality excercises only.
4
andrewonlab7735d852014-10-09 13:02:47 -04005import time
6import sys
7import os
andrewonlab2d355162014-10-10 00:43:59 -04008import re
andrewonlab7735d852014-10-09 13:02:47 -04009
andrewonlab4a5c4472014-10-09 12:11:41 -040010class ONOSNextTest:
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 '''
andrewonlabe6745342014-10-17 14:29:13 -040025 import time
26
andrewonlab084307e2014-10-09 14:06:09 -040027 cell_name = main.params['ENV']['cellName']
28 ONOS1_ip = main.params['CTRL']['ip1']
andrew@onlab.us59e8f692014-10-09 21:41:48 -040029 ONOS1_port = main.params['CTRL']['port1']
Jon Hallea7818b2014-10-09 14:30:59 -040030
andrewonlab8d0d7d72014-10-09 16:33:15 -040031 main.case("Setting up test environment")
Jon Hall3be576e2014-10-09 22:23:03 -040032
andrewonlab94282092014-10-10 13:00:11 -040033 main.step("Creating cell file")
andrewonlab2c010fb2014-10-10 18:08:59 -040034 #params: (bench ip, cell name, mininet ip, *onos ips)
andrewonlab94282092014-10-10 13:00:11 -040035 cell_file_result = main.ONOSbench.create_cell_file(
36 "10.128.20.10", "temp_cell_2", "10.128.10.90",
andrewonlabe6745342014-10-17 14:29:13 -040037 "onos-core-trivial,onos-app-fwd",
38 "10.128.20.11")
andrewonlab94282092014-10-10 13:00:11 -040039
andrewonlab8d0d7d72014-10-09 16:33:15 -040040 main.step("Applying cell variable to environment")
andrewonlab4dbb4d82014-10-17 18:22:31 -040041 cell_result = main.ONOSbench.set_cell(cell_name)
42 #cell_result = main.ONOSbench.set_cell("temp_cell_2")
andrewonlabc03bf6c2014-10-09 14:56:18 -040043 verify_result = main.ONOSbench.verify_cell()
andrewonlab2fe32ad2014-10-09 16:36:40 -040044
Jon Hall77f53ce2014-10-13 18:02:06 -040045 main.step("Git checkout and pull master")
andrewonlabe6745342014-10-17 14:29:13 -040046 #main.ONOSbench.git_checkout("master")
47 #git_pull_result = main.ONOSbench.git_pull()
48
Jon Hall77f53ce2014-10-13 18:02:06 -040049 main.step("Using mvn clean & install")
andrewonlabe6745342014-10-17 14:29:13 -040050 #clean_install_result = main.ONOSbench.clean_install()
51 clean_install_result = main.TRUE
Jon Hall77f53ce2014-10-13 18:02:06 -040052
53 main.step("Creating ONOS package")
54 package_result = main.ONOSbench.onos_package()
55
andrewonlab2fe32ad2014-10-09 16:36:40 -040056 main.step("Installing ONOS package")
Jon Hall7993bfc2014-10-09 16:30:14 -040057 onos_install_result = main.ONOSbench.onos_install()
58 onos1_isup = main.ONOSbench.isup()
andrewonlab8d0d7d72014-10-09 16:33:15 -040059
60 main.step("Starting ONOS service")
61 start_result = main.ONOSbench.onos_start(ONOS1_ip)
62
Jon Hall7993bfc2014-10-09 16:30:14 -040063 case1_result = (clean_install_result and package_result and\
andrewonlab2b30bd32014-10-09 16:48:55 -040064 cell_result and verify_result and onos_install_result and\
andrewonlabf103e9f2014-10-10 00:59:07 -040065 onos1_isup and start_result )
andrewonlab0748d2a2014-10-09 13:24:17 -040066 utilities.assert_equals(expect=main.TRUE, actual=case1_result,
67 onpass="Test startup successful",
68 onfail="Test startup NOT successful")
andrewonlab4a5c4472014-10-09 12:11:41 -040069
andrewonlabe6745342014-10-17 14:29:13 -040070 time.sleep(10)
71
andrewonlab05e362f2014-10-10 00:40:57 -040072 def CASE11(self, main):
andrewonlab2b30bd32014-10-09 16:48:55 -040073 '''
74 Cleanup sequence:
75 onos-service <node_ip> stop
76 onos-uninstall
77
78 TODO: Define rest of cleanup
79
80 '''
81
82 ONOS1_ip = main.params['CTRL']['ip1']
83
84 main.case("Cleaning up test environment")
85
andrewonlab057c06a2014-10-09 17:19:21 -040086 main.step("Testing ONOS kill function")
87 kill_result = main.ONOSbench.onos_kill(ONOS1_ip)
88
andrewonlab2b30bd32014-10-09 16:48:55 -040089 main.step("Stopping ONOS service")
90 stop_result = main.ONOSbench.onos_stop(ONOS1_ip)
91
92 main.step("Uninstalling ONOS service")
andrewonlab057c06a2014-10-09 17:19:21 -040093 uninstall_result = main.ONOSbench.onos_uninstall()
andrewonlab4a5c4472014-10-09 12:11:41 -040094
andrewonlab05e362f2014-10-10 00:40:57 -040095 def CASE3(self, main):
96 '''
97 Test 'onos' command and its functionality in driver
98 '''
99
100 ONOS1_ip = main.params['CTRL']['ip1']
andrewonlab05e362f2014-10-10 00:40:57 -0400101
102 main.case("Testing 'onos' command")
103
andrewonlabf103e9f2014-10-10 00:59:07 -0400104 main.step("Sending command 'onos -w <onos-ip> system:name'")
105 cmdstr1 = "system:name"
106 cmd_result1 = main.ONOSbench.onos_cli(ONOS1_ip, cmdstr1)
107 main.log.info("onos command returned: "+cmd_result1)
108
109 main.step("Sending command 'onos -w <onos-ip> onos:topology'")
110 cmdstr2 = "onos:topology"
111 cmd_result2 = main.ONOSbench.onos_cli(ONOS1_ip, cmdstr2)
112 main.log.info("onos command returned: "+cmd_result2)
Jon Hall77f53ce2014-10-13 18:02:06 -0400113
114 main.step("Testing check_status")
115 check_status_results = main.ONOSbench.check_status(ONOS1_ip, 4, 6)
116 main.log.info("Results of check_status " + str(check_status_results))
andrewonlabf103e9f2014-10-10 00:59:07 -0400117
andrewonlab2c010fb2014-10-10 18:08:59 -0400118 main.step("Sending command 'onos -w <onos-ip> bundle:list'")
119 cmdstr3 = "bundle:list"
120 cmd_result3 = main.ONOSbench.onos_cli(ONOS1_ip, cmdstr3)
121 main.log.info("onos command returned: "+cmd_result3)
Jon Hall77f53ce2014-10-13 18:02:06 -0400122 case3_result = (cmd_result1 and cmd_result2 and\
123 check_status_results and cmd_result3 )
124 utilities.assert_equals(expect=main.TRUE, actual=case3_result,
125 onpass="Test case 3 successful",
126 onfail="Test case 3 NOT successful")
andrewonlab2c010fb2014-10-10 18:08:59 -0400127
andrewonlabf103e9f2014-10-10 00:59:07 -0400128 def CASE4(self, main):
Jon Hall31735332014-10-10 15:27:43 -0400129 import re
130 import time
Jon Hall77f53ce2014-10-13 18:02:06 -0400131 main.case("Pingall Test(No intents are added)")
andrewonlabf103e9f2014-10-10 00:59:07 -0400132 main.step("Assigning switches to controllers")
Jon Hall77f53ce2014-10-13 18:02:06 -0400133 for i in range(1,5): #1 to (num of switches +1)
andrewonlabf103e9f2014-10-10 00:59:07 -0400134 main.Mininet1.assign_sw_controller(sw=str(i),
135 ip1=ONOS1_ip, port1=ONOS1_port)
136 switch_mastership = main.TRUE
Jon Hall77f53ce2014-10-13 18:02:06 -0400137 for i in range (1,5):
andrewonlabf103e9f2014-10-10 00:59:07 -0400138 response = main.Mininet1.get_sw_controller("s"+str(i))
139 print("Response is " + str(response))
140 if re.search("tcp:"+ONOS1_ip,response):
141 switch_mastership = switch_mastership and main.TRUE
142 else:
143 switch_mastership = main.FALSE
144
145 #REACTIVE FWD test
146 main.step("Pingall")
147 ping_result = main.FALSE
148 while ping_result == main.FALSE:
149 time1 = time.time()
150 ping_result = main.Mininet1.pingall()
151 time2 = time.time()
152 print "Time for pingall: %2f seconds" % (time2 - time1)
153
154 case4_result = switch_mastership and ping_result
155 utilities.assert_equals(expect=main.TRUE, actual=case4_result,
Jon Hall31735332014-10-10 15:27:43 -0400156 onpass="Pingall Test successful",
157 onfail="Pingall Test NOT successful")
andrewonlabf103e9f2014-10-10 00:59:07 -0400158
andrewonlabc7345f22014-10-13 14:12:59 -0400159 def CASE5(self, main):
160 '''
161 Test the ONOS-cli functionality
andrewonlab7e4d2d32014-10-15 13:23:21 -0400162
andrewonlab3e15ead2014-10-15 14:21:34 -0400163 Below are demonstrations of what the
164 ONOS cli driver functions can be used for.
andrewonlabc7345f22014-10-13 14:12:59 -0400165 '''
andrewonlab86dc3082014-10-13 18:18:38 -0400166 import time
andrewonlabe6745342014-10-17 14:29:13 -0400167 import json
168
andrewonlabc7345f22014-10-13 14:12:59 -0400169 cell_name = main.params['ENV']['cellName']
170 ONOS1_ip = main.params['CTRL']['ip1']
171
172 main.case("Testing the ONOS-cli")
173
174 main.step("Set cell for ONOS-cli environment")
175 main.ONOScli.set_cell(cell_name)
176
177 main.step("Start ONOS-cli")
andrewonlab86dc3082014-10-13 18:18:38 -0400178 main.ONOScli.start_onos_cli(ONOS1_ip)
andrewonlabc7345f22014-10-13 14:12:59 -0400179
180 main.step("issue command: onos:topology")
andrewonlab7c211572014-10-15 16:45:20 -0400181 topology_obj = main.ONOScli.topology()
andrewonlab86dc3082014-10-13 18:18:38 -0400182
183 main.step("issue various feature:install <str> commands")
andrewonlabe6745342014-10-17 14:29:13 -0400184 #main.ONOScli.feature_install("onos-app-fwd")
185 #main.ONOScli.feature_install("onos-rest")
andrewonlab86dc3082014-10-13 18:18:38 -0400186
187 main.step("Add a bad node")
188 node_result = main.ONOScli.add_node("111", "10.128.20.")
189 if node_result == main.TRUE:
190 main.log.info("Node successfully added")
191
192 main.step("Add a correct node")
193 node_result = main.ONOScli.add_node("111", "10.128.20.12")
194
andrewonlab7e4d2d32014-10-15 13:23:21 -0400195 main.step("Assign switches and list devices")
andrewonlab86dc3082014-10-13 18:18:38 -0400196 for i in range(1,8):
andrewonlabf80585f2014-10-13 19:00:11 -0400197 main.Mininet2.handle.sendline("sh ovs-vsctl set-controller s"+str(i)+
andrewonlab86dc3082014-10-13 18:18:38 -0400198 " tcp:10.128.20.11")
andrewonlabf80585f2014-10-13 19:00:11 -0400199 main.Mininet2.handle.expect("mininet>")
andrewonlab86dc3082014-10-13 18:18:38 -0400200 #Need to sleep to allow switch add processing
andrewonlab7e4d2d32014-10-15 13:23:21 -0400201 time.sleep(5)
andrewonlab9a50dfe2014-10-17 17:22:31 -0400202 list_result = main.ONOScli.devices(json_format=False)
andrewonlab86dc3082014-10-13 18:18:38 -0400203 main.log.info(list_result)
204
andrewonlab7e4d2d32014-10-15 13:23:21 -0400205 main.step("Get all devices id")
206 devices_id_list = main.ONOScli.get_all_devices_id()
207 main.log.info(devices_id_list)
andrewonlabc7345f22014-10-13 14:12:59 -0400208
andrewonlab3e15ead2014-10-15 14:21:34 -0400209 main.step("Get path and cost between device 1 and 7")
210 (path, cost) = main.ONOScli.paths(devices_id_list[0], devices_id_list[6])
211 main.log.info("Path: "+str(path))
212 main.log.info("Cost: "+str(cost))
andrewonlab7c211572014-10-15 16:45:20 -0400213
214 main.step("Get nodes currently visible")
215 nodes_str = main.ONOScli.nodes()
216 main.log.info(nodes_str)
217
218 main.step("Get all nodes id's")
219 node_id_list = main.ONOScli.get_all_nodes_id()
220 main.log.info(node_id_list)
221
222 main.step("Set device "+str(devices_id_list[0])+" to role: standby")
223 device_role_result = main.ONOScli.device_role(
224 devices_id_list[0], node_id_list[0], "standby")
225 if device_role_result == main.TRUE:
226 main.log.report("Device role successfully set")
227
andrewonlabe6745342014-10-17 14:29:13 -0400228 main.step("Revert device role to master")
229 device_role = main.ONOScli.device_role(
230 devices_id_list[0], node_id_list[0], "master")
231
andrewonlab7c211572014-10-15 16:45:20 -0400232 main.step("Check devices / role again")
andrewonlab9a50dfe2014-10-17 17:22:31 -0400233 dev_result = main.ONOScli.devices(json_format=False)
andrewonlab7c211572014-10-15 16:45:20 -0400234 main.log.info(dev_result)
andrewonlabe6745342014-10-17 14:29:13 -0400235
236 #Sample steps to push intents ***********
237 # * Obtain host id in ONOS format
238 # * Push intents
239 main.step("Get list of hosts from Mininet")
240 host_list = main.Mininet2.get_hosts()
241 main.log.info(host_list)
242
243 main.step("Get host list in ONOS format")
244 host_onos_list = main.ONOScli.get_hosts_id(host_list)
245 main.log.info(host_onos_list)
246
andrewonlabe6745342014-10-17 14:29:13 -0400247 time.sleep(5)
248
andrewonlab9a50dfe2014-10-17 17:22:31 -0400249 #We must use ping from hosts we want to add intents from
250 #to make the hosts talk
251 #main.Mininet2.handle.sendline("\r")
252 #main.Mininet2.handle.sendline("h4 ping 10.1.1.1 -c 1 -W 1")
253 #time.sleep(3)
254 #main.Mininet2.handle.sendline("h5 ping 10.1.1.1 -c 1 -W 1")
255 #time.sleep(5)
256
257 main.ONOScli.feature_install("onos-app-fwd")
258
259 main.Mininet2.pingall()
andrewonlabe6745342014-10-17 14:29:13 -0400260
261 time.sleep(5)
262
263 main.step("Get hosts")
264 main.ONOScli.handle.sendline("hosts")
265 main.ONOScli.handle.expect("onos>")
266 hosts = main.ONOScli.handle.before
267 main.log.info(hosts)
268
andrewonlab9a50dfe2014-10-17 17:22:31 -0400269 main.step("Install host-to-host-intents")
270 intent_install1 = main.ONOScli.add_host_intent(
271 host_onos_list[0], host_onos_list[1])
272 intent_install2 = main.ONOScli.add_host_intent(
273 host_onos_list[2], host_onos_list[3])
274 intent_install3 = main.ONOScli.add_host_intent(
275 host_onos_list[4], host_onos_list[5])
andrewonlabe6745342014-10-17 14:29:13 -0400276
andrewonlab9a50dfe2014-10-17 17:22:31 -0400277 main.log.info(intent_install1)
278 main.log.info(intent_install2)
279 main.log.info(intent_install3)
andrewonlabe6745342014-10-17 14:29:13 -0400280
281 main.step("Get intents installed on ONOS")
282 get_intent_result = main.ONOScli.intents()
283 main.log.info(get_intent_result)
284 #****************************************
285
andrewonlab9a50dfe2014-10-17 17:22:31 -0400286 #Sample steps to delete intents ********
287 main.step("Get all intent id's")
288 intent_id = main.ONOScli.get_all_intents_id()
289 main.log.info(intent_id)
290
291 main.step("Remove specified intent id: "+str(intent_id[0]))
292 intent_result = main.ONOScli.remove_intent(intent_id[0])
293 main.log.info(intent_result)
294
295 main.step("Check installed intents again")
296 get_intent_result = main.ONOScli.intents()
297 main.log.info(get_intent_result)
298 #***************************************
299
andrewonlab4dbb4d82014-10-17 18:22:31 -0400300 #Sample steps to add point-to-point intents*
301 main.step("Add point-to-point intents")
302 ptp_intent_result = main.ONOScli.add_point_intent(
303 devices_id_list[0], 1, devices_id_list[1], 2)
304 if ptp_intent_result == main.TRUE:
305 get_intent_result = main.ONOScli.intents()
306 main.log.info("Point to point intent install successful")
307 main.log.info(get_intent_result)
308 #*******************************************
andrewonlab7c211572014-10-15 16:45:20 -0400309
andrewonlab7e4d2d32014-10-15 13:23:21 -0400310######
311#jhall@onlab.us
312#andrew@onlab.us
313######