blob: 349677119347dc35240b1415f92e83f69bb3ff6b [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']
andrewonlabec9c3212014-10-17 20:02:53 -040028
andrewonlab084307e2014-10-09 14:06:09 -040029 ONOS1_ip = main.params['CTRL']['ip1']
andrew@onlab.us59e8f692014-10-09 21:41:48 -040030 ONOS1_port = main.params['CTRL']['port1']
Jon Hallea7818b2014-10-09 14:30:59 -040031
andrewonlabec9c3212014-10-17 20:02:53 -040032 git_pull_trigger = main.params['GIT']['autoPull']
andrewonlab8790abb2014-11-06 13:51:54 -050033 git_checkout_branch = main.params['GIT']['checkout']
andrewonlabec9c3212014-10-17 20:02:53 -040034
andrewonlab8d0d7d72014-10-09 16:33:15 -040035 main.case("Setting up test environment")
Jon Hall3be576e2014-10-09 22:23:03 -040036
andrewonlab94282092014-10-10 13:00:11 -040037 main.step("Creating cell file")
andrewonlab2c010fb2014-10-10 18:08:59 -040038 #params: (bench ip, cell name, mininet ip, *onos ips)
andrewonlab94282092014-10-10 13:00:11 -040039 cell_file_result = main.ONOSbench.create_cell_file(
40 "10.128.20.10", "temp_cell_2", "10.128.10.90",
andrewonlabe6745342014-10-17 14:29:13 -040041 "onos-core-trivial,onos-app-fwd",
andrewonlab8790abb2014-11-06 13:51:54 -050042 "10.128.174.1")
andrewonlab94282092014-10-10 13:00:11 -040043
andrewonlab8d0d7d72014-10-09 16:33:15 -040044 main.step("Applying cell variable to environment")
andrewonlabec9c3212014-10-17 20:02:53 -040045 #cell_result = main.ONOSbench.set_cell(cell_name)
46 cell_result = main.ONOSbench.set_cell("temp_cell_2")
andrewonlabc03bf6c2014-10-09 14:56:18 -040047 verify_result = main.ONOSbench.verify_cell()
andrewonlabec9c3212014-10-17 20:02:53 -040048
49 if git_pull_trigger == 'on':
50 main.step("Git checkout and pull master")
51 main.ONOSbench.git_checkout(git_checkout_branch)
52 git_pull_result = main.ONOSbench.git_pull()
53 else:
54 main.log.info("Git checkout and pull skipped by config")
55 git_pull_result = main.TRUE
56
Jon Hall77f53ce2014-10-13 18:02:06 -040057 main.step("Using mvn clean & install")
andrewonlabe6745342014-10-17 14:29:13 -040058 #clean_install_result = main.ONOSbench.clean_install()
59 clean_install_result = main.TRUE
Jon Hall77f53ce2014-10-13 18:02:06 -040060
61 main.step("Creating ONOS package")
62 package_result = main.ONOSbench.onos_package()
63
andrewonlab2fe32ad2014-10-09 16:36:40 -040064 main.step("Installing ONOS package")
Jon Hall7993bfc2014-10-09 16:30:14 -040065 onos_install_result = main.ONOSbench.onos_install()
66 onos1_isup = main.ONOSbench.isup()
andrewonlab8d0d7d72014-10-09 16:33:15 -040067
68 main.step("Starting ONOS service")
69 start_result = main.ONOSbench.onos_start(ONOS1_ip)
70
Jon Hall7993bfc2014-10-09 16:30:14 -040071 case1_result = (clean_install_result and package_result and\
andrewonlab2b30bd32014-10-09 16:48:55 -040072 cell_result and verify_result and onos_install_result and\
andrewonlabf103e9f2014-10-10 00:59:07 -040073 onos1_isup and start_result )
andrewonlab0748d2a2014-10-09 13:24:17 -040074 utilities.assert_equals(expect=main.TRUE, actual=case1_result,
75 onpass="Test startup successful",
76 onfail="Test startup NOT successful")
andrewonlab4a5c4472014-10-09 12:11:41 -040077
andrewonlabe6745342014-10-17 14:29:13 -040078 time.sleep(10)
79
andrewonlab05e362f2014-10-10 00:40:57 -040080 def CASE11(self, main):
andrewonlab2b30bd32014-10-09 16:48:55 -040081 '''
82 Cleanup sequence:
83 onos-service <node_ip> stop
84 onos-uninstall
85
86 TODO: Define rest of cleanup
87
88 '''
89
90 ONOS1_ip = main.params['CTRL']['ip1']
91
92 main.case("Cleaning up test environment")
93
andrewonlab057c06a2014-10-09 17:19:21 -040094 main.step("Testing ONOS kill function")
95 kill_result = main.ONOSbench.onos_kill(ONOS1_ip)
96
andrewonlab2b30bd32014-10-09 16:48:55 -040097 main.step("Stopping ONOS service")
98 stop_result = main.ONOSbench.onos_stop(ONOS1_ip)
99
100 main.step("Uninstalling ONOS service")
andrewonlab057c06a2014-10-09 17:19:21 -0400101 uninstall_result = main.ONOSbench.onos_uninstall()
andrewonlab4a5c4472014-10-09 12:11:41 -0400102
andrewonlab05e362f2014-10-10 00:40:57 -0400103 def CASE3(self, main):
104 '''
105 Test 'onos' command and its functionality in driver
106 '''
107
108 ONOS1_ip = main.params['CTRL']['ip1']
andrewonlab05e362f2014-10-10 00:40:57 -0400109
110 main.case("Testing 'onos' command")
111
andrewonlabf103e9f2014-10-10 00:59:07 -0400112 main.step("Sending command 'onos -w <onos-ip> system:name'")
113 cmdstr1 = "system:name"
114 cmd_result1 = main.ONOSbench.onos_cli(ONOS1_ip, cmdstr1)
115 main.log.info("onos command returned: "+cmd_result1)
116
117 main.step("Sending command 'onos -w <onos-ip> onos:topology'")
118 cmdstr2 = "onos:topology"
119 cmd_result2 = main.ONOSbench.onos_cli(ONOS1_ip, cmdstr2)
120 main.log.info("onos command returned: "+cmd_result2)
Jon Hall77f53ce2014-10-13 18:02:06 -0400121
122 main.step("Testing check_status")
123 check_status_results = main.ONOSbench.check_status(ONOS1_ip, 4, 6)
124 main.log.info("Results of check_status " + str(check_status_results))
andrewonlabf103e9f2014-10-10 00:59:07 -0400125
andrewonlab2c010fb2014-10-10 18:08:59 -0400126 main.step("Sending command 'onos -w <onos-ip> bundle:list'")
127 cmdstr3 = "bundle:list"
128 cmd_result3 = main.ONOSbench.onos_cli(ONOS1_ip, cmdstr3)
129 main.log.info("onos command returned: "+cmd_result3)
Jon Hall77f53ce2014-10-13 18:02:06 -0400130 case3_result = (cmd_result1 and cmd_result2 and\
131 check_status_results and cmd_result3 )
132 utilities.assert_equals(expect=main.TRUE, actual=case3_result,
133 onpass="Test case 3 successful",
134 onfail="Test case 3 NOT successful")
andrewonlab2c010fb2014-10-10 18:08:59 -0400135
andrewonlabf103e9f2014-10-10 00:59:07 -0400136 def CASE4(self, main):
Jon Hall31735332014-10-10 15:27:43 -0400137 import re
138 import time
Jon Hall77f53ce2014-10-13 18:02:06 -0400139 main.case("Pingall Test(No intents are added)")
andrewonlabf103e9f2014-10-10 00:59:07 -0400140 main.step("Assigning switches to controllers")
Jon Hall77f53ce2014-10-13 18:02:06 -0400141 for i in range(1,5): #1 to (num of switches +1)
andrewonlabf103e9f2014-10-10 00:59:07 -0400142 main.Mininet1.assign_sw_controller(sw=str(i),
143 ip1=ONOS1_ip, port1=ONOS1_port)
144 switch_mastership = main.TRUE
Jon Hall77f53ce2014-10-13 18:02:06 -0400145 for i in range (1,5):
andrewonlabf103e9f2014-10-10 00:59:07 -0400146 response = main.Mininet1.get_sw_controller("s"+str(i))
147 print("Response is " + str(response))
148 if re.search("tcp:"+ONOS1_ip,response):
149 switch_mastership = switch_mastership and main.TRUE
150 else:
151 switch_mastership = main.FALSE
152
153 #REACTIVE FWD test
154 main.step("Pingall")
155 ping_result = main.FALSE
156 while ping_result == main.FALSE:
157 time1 = time.time()
158 ping_result = main.Mininet1.pingall()
159 time2 = time.time()
160 print "Time for pingall: %2f seconds" % (time2 - time1)
161
162 case4_result = switch_mastership and ping_result
163 utilities.assert_equals(expect=main.TRUE, actual=case4_result,
Jon Hall31735332014-10-10 15:27:43 -0400164 onpass="Pingall Test successful",
165 onfail="Pingall Test NOT successful")
andrewonlabf103e9f2014-10-10 00:59:07 -0400166
andrewonlabc7345f22014-10-13 14:12:59 -0400167 def CASE5(self, main):
168 '''
169 Test the ONOS-cli functionality
andrewonlab7e4d2d32014-10-15 13:23:21 -0400170
andrewonlab3e15ead2014-10-15 14:21:34 -0400171 Below are demonstrations of what the
172 ONOS cli driver functions can be used for.
andrewonlabc7345f22014-10-13 14:12:59 -0400173 '''
andrewonlab86dc3082014-10-13 18:18:38 -0400174 import time
andrewonlabe6745342014-10-17 14:29:13 -0400175 import json
176
andrewonlabc7345f22014-10-13 14:12:59 -0400177 cell_name = main.params['ENV']['cellName']
178 ONOS1_ip = main.params['CTRL']['ip1']
179
180 main.case("Testing the ONOS-cli")
181
182 main.step("Set cell for ONOS-cli environment")
andrewonlab8790abb2014-11-06 13:51:54 -0500183 #main.ONOScli.set_cell(cell_name)
184 main.ONOScli.set_cell("temp_cell_2")
andrewonlabc7345f22014-10-13 14:12:59 -0400185
186 main.step("Start ONOS-cli")
andrewonlab86dc3082014-10-13 18:18:38 -0400187 main.ONOScli.start_onos_cli(ONOS1_ip)
andrewonlabc7345f22014-10-13 14:12:59 -0400188
189 main.step("issue command: onos:topology")
andrewonlab7c211572014-10-15 16:45:20 -0400190 topology_obj = main.ONOScli.topology()
andrewonlab86dc3082014-10-13 18:18:38 -0400191
192 main.step("issue various feature:install <str> commands")
andrewonlabe6745342014-10-17 14:29:13 -0400193 #main.ONOScli.feature_install("onos-app-fwd")
194 #main.ONOScli.feature_install("onos-rest")
andrewonlab86dc3082014-10-13 18:18:38 -0400195
196 main.step("Add a bad node")
197 node_result = main.ONOScli.add_node("111", "10.128.20.")
198 if node_result == main.TRUE:
199 main.log.info("Node successfully added")
200
201 main.step("Add a correct node")
andrewonlab8790abb2014-11-06 13:51:54 -0500202 node_result = main.ONOScli.add_node("111", "10.128.174.2")
andrewonlab86dc3082014-10-13 18:18:38 -0400203
andrewonlab7e4d2d32014-10-15 13:23:21 -0400204 main.step("Assign switches and list devices")
andrewonlab86dc3082014-10-13 18:18:38 -0400205 for i in range(1,8):
andrewonlabf80585f2014-10-13 19:00:11 -0400206 main.Mininet2.handle.sendline("sh ovs-vsctl set-controller s"+str(i)+
andrewonlab8790abb2014-11-06 13:51:54 -0500207 " tcp:10.128.174.1")
andrewonlabf80585f2014-10-13 19:00:11 -0400208 main.Mininet2.handle.expect("mininet>")
andrewonlab86dc3082014-10-13 18:18:38 -0400209 #Need to sleep to allow switch add processing
andrewonlab7e4d2d32014-10-15 13:23:21 -0400210 time.sleep(5)
andrewonlab9a50dfe2014-10-17 17:22:31 -0400211 list_result = main.ONOScli.devices(json_format=False)
andrewonlab86dc3082014-10-13 18:18:38 -0400212 main.log.info(list_result)
213
andrewonlab7e4d2d32014-10-15 13:23:21 -0400214 main.step("Get all devices id")
215 devices_id_list = main.ONOScli.get_all_devices_id()
216 main.log.info(devices_id_list)
andrewonlabc7345f22014-10-13 14:12:59 -0400217
andrewonlab3e15ead2014-10-15 14:21:34 -0400218 main.step("Get path and cost between device 1 and 7")
219 (path, cost) = main.ONOScli.paths(devices_id_list[0], devices_id_list[6])
220 main.log.info("Path: "+str(path))
221 main.log.info("Cost: "+str(cost))
andrewonlab7c211572014-10-15 16:45:20 -0400222
223 main.step("Get nodes currently visible")
224 nodes_str = main.ONOScli.nodes()
225 main.log.info(nodes_str)
226
227 main.step("Get all nodes id's")
228 node_id_list = main.ONOScli.get_all_nodes_id()
229 main.log.info(node_id_list)
230
231 main.step("Set device "+str(devices_id_list[0])+" to role: standby")
232 device_role_result = main.ONOScli.device_role(
233 devices_id_list[0], node_id_list[0], "standby")
234 if device_role_result == main.TRUE:
235 main.log.report("Device role successfully set")
236
andrewonlabe6745342014-10-17 14:29:13 -0400237 main.step("Revert device role to master")
238 device_role = main.ONOScli.device_role(
239 devices_id_list[0], node_id_list[0], "master")
240
andrewonlab7c211572014-10-15 16:45:20 -0400241 main.step("Check devices / role again")
andrewonlab9a50dfe2014-10-17 17:22:31 -0400242 dev_result = main.ONOScli.devices(json_format=False)
andrewonlab7c211572014-10-15 16:45:20 -0400243 main.log.info(dev_result)
andrewonlabe6745342014-10-17 14:29:13 -0400244
245 #Sample steps to push intents ***********
246 # * Obtain host id in ONOS format
247 # * Push intents
248 main.step("Get list of hosts from Mininet")
249 host_list = main.Mininet2.get_hosts()
250 main.log.info(host_list)
251
252 main.step("Get host list in ONOS format")
253 host_onos_list = main.ONOScli.get_hosts_id(host_list)
254 main.log.info(host_onos_list)
255
andrewonlabe6745342014-10-17 14:29:13 -0400256 time.sleep(5)
257
andrewonlab9a50dfe2014-10-17 17:22:31 -0400258 #We must use ping from hosts we want to add intents from
259 #to make the hosts talk
260 #main.Mininet2.handle.sendline("\r")
261 #main.Mininet2.handle.sendline("h4 ping 10.1.1.1 -c 1 -W 1")
262 #time.sleep(3)
263 #main.Mininet2.handle.sendline("h5 ping 10.1.1.1 -c 1 -W 1")
264 #time.sleep(5)
265
266 main.ONOScli.feature_install("onos-app-fwd")
267
268 main.Mininet2.pingall()
andrewonlabe6745342014-10-17 14:29:13 -0400269
270 time.sleep(5)
271
272 main.step("Get hosts")
273 main.ONOScli.handle.sendline("hosts")
274 main.ONOScli.handle.expect("onos>")
275 hosts = main.ONOScli.handle.before
276 main.log.info(hosts)
277
andrewonlab9a50dfe2014-10-17 17:22:31 -0400278 main.step("Install host-to-host-intents")
279 intent_install1 = main.ONOScli.add_host_intent(
280 host_onos_list[0], host_onos_list[1])
281 intent_install2 = main.ONOScli.add_host_intent(
282 host_onos_list[2], host_onos_list[3])
283 intent_install3 = main.ONOScli.add_host_intent(
284 host_onos_list[4], host_onos_list[5])
andrewonlabe6745342014-10-17 14:29:13 -0400285
andrewonlab9a50dfe2014-10-17 17:22:31 -0400286 main.log.info(intent_install1)
287 main.log.info(intent_install2)
288 main.log.info(intent_install3)
andrewonlabe6745342014-10-17 14:29:13 -0400289
290 main.step("Get intents installed on ONOS")
291 get_intent_result = main.ONOScli.intents()
292 main.log.info(get_intent_result)
293 #****************************************
294
andrewonlab9a50dfe2014-10-17 17:22:31 -0400295 #Sample steps to delete intents ********
296 main.step("Get all intent id's")
297 intent_id = main.ONOScli.get_all_intents_id()
298 main.log.info(intent_id)
299
300 main.step("Remove specified intent id: "+str(intent_id[0]))
301 intent_result = main.ONOScli.remove_intent(intent_id[0])
302 main.log.info(intent_result)
303
304 main.step("Check installed intents again")
305 get_intent_result = main.ONOScli.intents()
306 main.log.info(get_intent_result)
307 #***************************************
308
andrewonlab4dbb4d82014-10-17 18:22:31 -0400309 #Sample steps to add point-to-point intents*
310 main.step("Add point-to-point intents")
311 ptp_intent_result = main.ONOScli.add_point_intent(
312 devices_id_list[0], 1, devices_id_list[1], 2)
313 if ptp_intent_result == main.TRUE:
314 get_intent_result = main.ONOScli.intents()
315 main.log.info("Point to point intent install successful")
316 main.log.info(get_intent_result)
317 #*******************************************
andrewonlab7c211572014-10-15 16:45:20 -0400318
andrewonlab8790abb2014-11-06 13:51:54 -0500319 main.step("Print intents in json format")
320 intents = main.ONOScli.intents(json_format = True)
321 main.log.info(intents)
322
323 main.step("Add eth options in point-to-point intent")
324 ptp_eth = main.ONOScli.add_point_intent(
325 devices_id_list[2], 1, devices_id_list[3], 2,
326 ethSrc = "00:02", ethDst = "00:03")
327 main.log.info(ptp_eth)
328
329 main.step("Print intents with eth options")
330 intents = main.ONOScli.intents()
331 main.log.info(intents)
andrewonlab7e4d2d32014-10-15 13:23:21 -0400332######
333#jhall@onlab.us
334#andrew@onlab.us
335######