andrewonlab | 4a5c447 | 2014-10-09 12:11:41 -0400 | [diff] [blame] | 1 | |
| 2 | #Testing the basic functionality of ONOS Next |
| 3 | #For sanity and driver functionality excercises only. |
| 4 | |
andrewonlab | 7735d85 | 2014-10-09 13:02:47 -0400 | [diff] [blame] | 5 | import time |
| 6 | import sys |
| 7 | import os |
andrewonlab | 2d35516 | 2014-10-10 00:43:59 -0400 | [diff] [blame] | 8 | import re |
andrewonlab | 7735d85 | 2014-10-09 13:02:47 -0400 | [diff] [blame] | 9 | |
andrewonlab | 4a5c447 | 2014-10-09 12:11:41 -0400 | [diff] [blame] | 10 | class 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 | ''' |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 25 | import time |
| 26 | |
andrewonlab | 084307e | 2014-10-09 14:06:09 -0400 | [diff] [blame] | 27 | cell_name = main.params['ENV']['cellName'] |
| 28 | ONOS1_ip = main.params['CTRL']['ip1'] |
andrew@onlab.us | 59e8f69 | 2014-10-09 21:41:48 -0400 | [diff] [blame] | 29 | ONOS1_port = main.params['CTRL']['port1'] |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 30 | |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 31 | main.case("Setting up test environment") |
Jon Hall | 3be576e | 2014-10-09 22:23:03 -0400 | [diff] [blame] | 32 | |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 33 | main.step("Creating cell file") |
andrewonlab | 2c010fb | 2014-10-10 18:08:59 -0400 | [diff] [blame] | 34 | #params: (bench ip, cell name, mininet ip, *onos ips) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 35 | cell_file_result = main.ONOSbench.create_cell_file( |
| 36 | "10.128.20.10", "temp_cell_2", "10.128.10.90", |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 37 | "onos-core-trivial,onos-app-fwd", |
| 38 | "10.128.20.11") |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 39 | |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 40 | main.step("Applying cell variable to environment") |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame^] | 41 | cell_result = main.ONOSbench.set_cell(cell_name) |
| 42 | #cell_result = main.ONOSbench.set_cell("temp_cell_2") |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 43 | verify_result = main.ONOSbench.verify_cell() |
andrewonlab | 2fe32ad | 2014-10-09 16:36:40 -0400 | [diff] [blame] | 44 | |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 45 | main.step("Git checkout and pull master") |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 46 | #main.ONOSbench.git_checkout("master") |
| 47 | #git_pull_result = main.ONOSbench.git_pull() |
| 48 | |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 49 | main.step("Using mvn clean & install") |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 50 | #clean_install_result = main.ONOSbench.clean_install() |
| 51 | clean_install_result = main.TRUE |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 52 | |
| 53 | main.step("Creating ONOS package") |
| 54 | package_result = main.ONOSbench.onos_package() |
| 55 | |
andrewonlab | 2fe32ad | 2014-10-09 16:36:40 -0400 | [diff] [blame] | 56 | main.step("Installing ONOS package") |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 57 | onos_install_result = main.ONOSbench.onos_install() |
| 58 | onos1_isup = main.ONOSbench.isup() |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 59 | |
| 60 | main.step("Starting ONOS service") |
| 61 | start_result = main.ONOSbench.onos_start(ONOS1_ip) |
| 62 | |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 63 | case1_result = (clean_install_result and package_result and\ |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 64 | cell_result and verify_result and onos_install_result and\ |
andrewonlab | f103e9f | 2014-10-10 00:59:07 -0400 | [diff] [blame] | 65 | onos1_isup and start_result ) |
andrewonlab | 0748d2a | 2014-10-09 13:24:17 -0400 | [diff] [blame] | 66 | utilities.assert_equals(expect=main.TRUE, actual=case1_result, |
| 67 | onpass="Test startup successful", |
| 68 | onfail="Test startup NOT successful") |
andrewonlab | 4a5c447 | 2014-10-09 12:11:41 -0400 | [diff] [blame] | 69 | |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 70 | time.sleep(10) |
| 71 | |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 72 | def CASE11(self, main): |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 73 | ''' |
| 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 | |
andrewonlab | 057c06a | 2014-10-09 17:19:21 -0400 | [diff] [blame] | 86 | main.step("Testing ONOS kill function") |
| 87 | kill_result = main.ONOSbench.onos_kill(ONOS1_ip) |
| 88 | |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 89 | main.step("Stopping ONOS service") |
| 90 | stop_result = main.ONOSbench.onos_stop(ONOS1_ip) |
| 91 | |
| 92 | main.step("Uninstalling ONOS service") |
andrewonlab | 057c06a | 2014-10-09 17:19:21 -0400 | [diff] [blame] | 93 | uninstall_result = main.ONOSbench.onos_uninstall() |
andrewonlab | 4a5c447 | 2014-10-09 12:11:41 -0400 | [diff] [blame] | 94 | |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 95 | def CASE3(self, main): |
| 96 | ''' |
| 97 | Test 'onos' command and its functionality in driver |
| 98 | ''' |
| 99 | |
| 100 | ONOS1_ip = main.params['CTRL']['ip1'] |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 101 | |
| 102 | main.case("Testing 'onos' command") |
| 103 | |
andrewonlab | f103e9f | 2014-10-10 00:59:07 -0400 | [diff] [blame] | 104 | 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 Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 113 | |
| 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)) |
andrewonlab | f103e9f | 2014-10-10 00:59:07 -0400 | [diff] [blame] | 117 | |
andrewonlab | 2c010fb | 2014-10-10 18:08:59 -0400 | [diff] [blame] | 118 | 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 Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 122 | 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") |
andrewonlab | 2c010fb | 2014-10-10 18:08:59 -0400 | [diff] [blame] | 127 | |
andrewonlab | f103e9f | 2014-10-10 00:59:07 -0400 | [diff] [blame] | 128 | def CASE4(self, main): |
Jon Hall | 3173533 | 2014-10-10 15:27:43 -0400 | [diff] [blame] | 129 | import re |
| 130 | import time |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 131 | main.case("Pingall Test(No intents are added)") |
andrewonlab | f103e9f | 2014-10-10 00:59:07 -0400 | [diff] [blame] | 132 | main.step("Assigning switches to controllers") |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 133 | for i in range(1,5): #1 to (num of switches +1) |
andrewonlab | f103e9f | 2014-10-10 00:59:07 -0400 | [diff] [blame] | 134 | main.Mininet1.assign_sw_controller(sw=str(i), |
| 135 | ip1=ONOS1_ip, port1=ONOS1_port) |
| 136 | switch_mastership = main.TRUE |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 137 | for i in range (1,5): |
andrewonlab | f103e9f | 2014-10-10 00:59:07 -0400 | [diff] [blame] | 138 | 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 Hall | 3173533 | 2014-10-10 15:27:43 -0400 | [diff] [blame] | 156 | onpass="Pingall Test successful", |
| 157 | onfail="Pingall Test NOT successful") |
andrewonlab | f103e9f | 2014-10-10 00:59:07 -0400 | [diff] [blame] | 158 | |
andrewonlab | c7345f2 | 2014-10-13 14:12:59 -0400 | [diff] [blame] | 159 | def CASE5(self, main): |
| 160 | ''' |
| 161 | Test the ONOS-cli functionality |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 162 | |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 163 | Below are demonstrations of what the |
| 164 | ONOS cli driver functions can be used for. |
andrewonlab | c7345f2 | 2014-10-13 14:12:59 -0400 | [diff] [blame] | 165 | ''' |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 166 | import time |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 167 | import json |
| 168 | |
andrewonlab | c7345f2 | 2014-10-13 14:12:59 -0400 | [diff] [blame] | 169 | 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") |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 178 | main.ONOScli.start_onos_cli(ONOS1_ip) |
andrewonlab | c7345f2 | 2014-10-13 14:12:59 -0400 | [diff] [blame] | 179 | |
| 180 | main.step("issue command: onos:topology") |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 181 | topology_obj = main.ONOScli.topology() |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 182 | |
| 183 | main.step("issue various feature:install <str> commands") |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 184 | #main.ONOScli.feature_install("onos-app-fwd") |
| 185 | #main.ONOScli.feature_install("onos-rest") |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 186 | |
| 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 | |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 195 | main.step("Assign switches and list devices") |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 196 | for i in range(1,8): |
andrewonlab | f80585f | 2014-10-13 19:00:11 -0400 | [diff] [blame] | 197 | main.Mininet2.handle.sendline("sh ovs-vsctl set-controller s"+str(i)+ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 198 | " tcp:10.128.20.11") |
andrewonlab | f80585f | 2014-10-13 19:00:11 -0400 | [diff] [blame] | 199 | main.Mininet2.handle.expect("mininet>") |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 200 | #Need to sleep to allow switch add processing |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 201 | time.sleep(5) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 202 | list_result = main.ONOScli.devices(json_format=False) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 203 | main.log.info(list_result) |
| 204 | |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 205 | main.step("Get all devices id") |
| 206 | devices_id_list = main.ONOScli.get_all_devices_id() |
| 207 | main.log.info(devices_id_list) |
andrewonlab | c7345f2 | 2014-10-13 14:12:59 -0400 | [diff] [blame] | 208 | |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 209 | 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)) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 213 | |
| 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 | |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 228 | 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 | |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 232 | main.step("Check devices / role again") |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 233 | dev_result = main.ONOScli.devices(json_format=False) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 234 | main.log.info(dev_result) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 235 | |
| 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 | |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 247 | time.sleep(5) |
| 248 | |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 249 | #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() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 260 | |
| 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 | |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 269 | 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]) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 276 | |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 277 | main.log.info(intent_install1) |
| 278 | main.log.info(intent_install2) |
| 279 | main.log.info(intent_install3) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 280 | |
| 281 | main.step("Get intents installed on ONOS") |
| 282 | get_intent_result = main.ONOScli.intents() |
| 283 | main.log.info(get_intent_result) |
| 284 | #**************************************** |
| 285 | |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 286 | #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 | |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame^] | 300 | #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 | #******************************************* |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 309 | |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 310 | ###### |
| 311 | #jhall@onlab.us |
| 312 | #andrew@onlab.us |
| 313 | ###### |