shahshreya | b512cd0 | 2015-01-27 17:01:47 -0800 | [diff] [blame] | 1 | |
| 2 | #Testing the basic functionality of ONOS Next |
| 3 | #For sanity and driver functionality excercises only. |
| 4 | |
| 5 | import time |
| 6 | import sys |
| 7 | import os |
| 8 | import re |
| 9 | import time |
| 10 | |
| 11 | time.sleep(1) |
| 12 | class FuncNext: |
| 13 | def __init__(self): |
| 14 | self.default = '' |
| 15 | |
| 16 | def CASE1(self, main): |
| 17 | ''' |
| 18 | Startup sequence: |
| 19 | git pull |
| 20 | mvn clean install |
| 21 | onos-package |
| 22 | cell <name> |
| 23 | onos-verify-cell |
| 24 | onos-install -f |
| 25 | onos-wait-for-start |
| 26 | ''' |
| 27 | |
| 28 | cell_name = main.params['ENV']['cellName'] |
| 29 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 30 | ONOS1_port = main.params['CTRL']['port1'] |
| 31 | |
| 32 | main.case("Setting up test environment") |
| 33 | |
| 34 | main.step("Git checkout and pull master and get version") |
| 35 | main.ONOSbench.git_checkout("master") |
| 36 | git_pull_result = main.ONOSbench.git_pull() |
| 37 | version_result = main.ONOSbench.get_version() |
| 38 | |
| 39 | main.step("Using mvn clean & install") |
| 40 | #clean_install_result = main.ONOSbench.clean_install() |
| 41 | #clean_install_result = main.TRUE |
| 42 | |
| 43 | main.step("Applying cell variable to environment") |
| 44 | cell_result = main.ONOSbench.set_cell(cell_name) |
| 45 | verify_result = main.ONOSbench.verify_cell() |
| 46 | cell_result = main.ONOS2.set_cell(cell_name) |
| 47 | #verify_result = main.ONOS2.verify_cell() |
| 48 | main.ONOS2.start_onos_cli(ONOS_ip=main.params['CTRL']['ip1']) |
| 49 | |
| 50 | main.step("Creating ONOS package") |
| 51 | package_result = main.ONOSbench.onos_package() |
| 52 | |
| 53 | #main.step("Creating a cell") |
| 54 | #cell_create_result = main.ONOSbench.create_cell_file(**************) |
| 55 | |
| 56 | main.step("Installing ONOS package") |
| 57 | onos_install_result = main.ONOSbench.onos_install() |
| 58 | onos1_isup = main.ONOSbench.isup() |
| 59 | |
| 60 | main.step("Starting ONOS service") |
| 61 | start_result = main.ONOSbench.onos_start(ONOS1_ip) |
| 62 | |
| 63 | case1_result = (package_result and\ |
| 64 | cell_result and verify_result and onos_install_result and\ |
| 65 | onos1_isup and start_result ) |
| 66 | utilities.assert_equals(expect=main.TRUE, actual=case1_result, |
| 67 | onpass="Test startup successful", |
| 68 | onfail="Test startup NOT successful") |
| 69 | |
| 70 | def CASE11(self, main): |
| 71 | ''' |
| 72 | Cleanup sequence: |
| 73 | onos-service <node_ip> stop |
| 74 | onos-uninstall |
| 75 | |
| 76 | TODO: Define rest of cleanup |
| 77 | |
| 78 | ''' |
| 79 | |
| 80 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 81 | |
| 82 | main.case("Cleaning up test environment") |
| 83 | |
| 84 | main.step("Testing ONOS kill function") |
| 85 | kill_result = main.ONOSbench.onos_kill(ONOS1_ip) |
| 86 | |
| 87 | main.step("Stopping ONOS service") |
| 88 | stop_result = main.ONOSbench.onos_stop(ONOS1_ip) |
| 89 | |
| 90 | main.step("Uninstalling ONOS service") |
| 91 | uninstall_result = main.ONOSbench.onos_uninstall() |
| 92 | |
| 93 | def CASE3(self, main): |
| 94 | ''' |
| 95 | Test 'onos' command and its functionality in driver |
| 96 | ''' |
| 97 | |
| 98 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 99 | |
| 100 | main.case("Testing 'onos' command") |
| 101 | |
| 102 | main.step("Sending command 'onos -w <onos-ip> system:name'") |
| 103 | cmdstr1 = "system:name" |
| 104 | cmd_result1 = main.ONOSbench.onos_cli(ONOS1_ip, cmdstr1) |
| 105 | main.log.info("onos command returned: "+cmd_result1) |
| 106 | |
| 107 | main.step("Sending command 'onos -w <onos-ip> onos:topology'") |
| 108 | cmdstr2 = "onos:topology" |
| 109 | cmd_result2 = main.ONOSbench.onos_cli(ONOS1_ip, cmdstr2) |
| 110 | main.log.info("onos command returned: "+cmd_result2) |
| 111 | |
| 112 | |
| 113 | |
| 114 | def CASE4(self, main): |
| 115 | import re |
| 116 | import time |
| 117 | main.case("Pingall Test") |
| 118 | main.step("Assigning switches to controllers") |
| 119 | for i in range(1,29): |
| 120 | if i ==1: |
| 121 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=ONOS1_ip,port1=ONOS1_port) |
| 122 | elif i>=2 and i<5: |
| 123 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=ONOS1_ip,port1=ONOS1_port) |
| 124 | elif i>=5 and i<8: |
| 125 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=ONOS1_ip,port1=ONOS1_port) |
| 126 | elif i>=8 and i<18: |
| 127 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=ONOS1_ip,port1=ONOS1_port) |
| 128 | elif i>=18 and i<28: |
| 129 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=ONOS1_ip,port1=ONOS1_port) |
| 130 | else: |
| 131 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=ONOS1_ip,port1=ONOS1_port) |
| 132 | Switch_Mastership = main.TRUE |
| 133 | for i in range (1,29): |
| 134 | if i==1: |
| 135 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 136 | print("Response is " + str(response)) |
| 137 | if re.search("tcp:"+ONOS1_ip,response): |
| 138 | Switch_Mastership = Switch_Mastership and main.TRUE |
| 139 | else: |
| 140 | Switch_Mastership = main.FALSE |
| 141 | elif i>=2 and i<5: |
| 142 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 143 | print("Response is " + str(response)) |
| 144 | if re.search("tcp:"+ONOS1_ip,response): |
| 145 | Switch_Mastership = Switch_Mastership and main.TRUE |
| 146 | else: |
| 147 | Switch_Mastership = main.FALSE |
| 148 | elif i>=5 and i<8: |
| 149 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 150 | print("Response is " + str(response)) |
| 151 | if re.search("tcp:"+ONOS1_ip,response): |
| 152 | Switch_Mastership = Switch_Mastership and main.TRUE |
| 153 | else: |
| 154 | Switch_Mastership = main.FALSE |
| 155 | elif i>=8 and i<18: |
| 156 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 157 | print("Response is " + str(response)) |
| 158 | if re.search("tcp:"+ONOS1_ip,response): |
| 159 | Switch_Mastership = Switch_Mastership and main.TRUE |
| 160 | else: |
| 161 | Switch_Mastership = main.FALSE |
| 162 | elif i>=18 and i<28: |
| 163 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 164 | print("Response is " + str(response)) |
| 165 | if re.search("tcp:"+ONOS1_ip,response): |
| 166 | Switch_Mastership = Switch_Mastership and main.TRUE |
| 167 | else: |
| 168 | Switch_Mastership = main.FALSE |
| 169 | else: |
| 170 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 171 | print("Response is" + str(response)) |
| 172 | if re.search("tcp:" +ONOS1_ip,response): |
| 173 | Switch_Mastership = Switch_Mastership and main.TRUE |
| 174 | else: |
| 175 | Switch_Mastership = main.FALSE |
| 176 | |
| 177 | if Switch_Mastership == main.TRUE: |
| 178 | main.log.report("MasterControllers assigned correctly") |
| 179 | utilities.assert_equals(expect = main.TRUE,actual=Switch_Mastership, |
| 180 | onpass="MasterControllers assigned correctly") |
| 181 | ''' |
| 182 | for i in range (1,29): |
| 183 | main.Mininet1.assign_sw_controller(sw=str(i),count=5, |
| 184 | ip1=ONOS1_ip,port1=ONOS1_port, |
| 185 | ip2=ONOS2_ip,port2=ONOS2_port, |
| 186 | ip3=ONOS3_ip,port3=ONOS3_port, |
| 187 | ip4=ONOS4_ip,port4=ONOS4_port, |
| 188 | ip5=ONOS5_ip,port5=ONOS5_port) |
| 189 | ''' |
| 190 | #REACTIVE FWD test |
| 191 | |
| 192 | main.step("Get list of hosts from Mininet") |
| 193 | host_list = main.Mininet1.get_hosts() |
| 194 | main.log.info(host_list) |
| 195 | |
| 196 | main.step("Get host list in ONOS format") |
| 197 | host_onos_list = main.ONOS2.get_hosts_id(host_list) |
| 198 | main.log.info(host_onos_list) |
| 199 | #time.sleep(5) |
| 200 | |
| 201 | #We must use ping from hosts we want to add intents from |
| 202 | #to make the hosts talk |
| 203 | #main.Mininet2.handle.sendline("\r") |
| 204 | #main.Mininet2.handle.sendline("h4 ping 10.1.1.1 -c 1 -W 1") |
| 205 | #time.sleep(3) |
| 206 | #main.Mininet2.handle.sendline("h5 ping 10.1.1.1 -c 1 -W 1") |
| 207 | #time.sleep(5) |
| 208 | |
| 209 | main.step("Pingall") |
| 210 | ping_result = main.FALSE |
| 211 | while ping_result == main.FALSE: |
| 212 | time1 = time.time() |
| 213 | ping_result = main.Mininet1.pingall() |
| 214 | time2 = time.time() |
| 215 | print "Time for pingall: %2f seconds" % (time2 - time1) |
| 216 | |
| 217 | #Start onos cli again because u might have dropped out of onos prompt to the shell prompt |
| 218 | #if there was no activity |
| 219 | main.ONOS2.start_onos_cli(ONOS_ip=main.params['CTRL']['ip1']) |
| 220 | |
| 221 | main.step("Get hosts") |
| 222 | main.ONOS2.handle.sendline("hosts") |
| 223 | main.ONOS2.handle.expect("onos>") |
| 224 | hosts = main.ONOS2.handle.before |
| 225 | main.log.info(hosts) |
| 226 | |
| 227 | main.step("Get all devices id") |
| 228 | devices_id_list = main.ONOS2.get_all_devices_id() |
| 229 | main.log.info(devices_id_list) |
| 230 | ''' |
| 231 | main.step("Add point-to-point intents") |
| 232 | ptp_intent_result = main.ONOS2.add_point_intent( |
| 233 | devices_id_list[0], 1, devices_id_list[1], 2) |
| 234 | if ptp_intent_result == main.TRUE: |
| 235 | get_intent_result = main.ONOS2.intents() |
| 236 | main.log.info("Point to point intent install successful") |
| 237 | main.log.info(get_intent_result) |
| 238 | ''' |
| 239 | |
| 240 | case4_result = Switch_Mastership and ping_result |
| 241 | utilities.assert_equals(expect=main.TRUE, actual=case4_result, |
| 242 | onpass="Pingall Test successful", |
| 243 | onfail="Pingall Test NOT successful") |
| 244 | |
| 245 | def CASE5(self,main) : |
| 246 | import time |
| 247 | from subprocess import Popen, PIPE |
| 248 | from sts.topology.teston_topology import TestONTopology # assumes that sts is already in you PYTHONPATH |
| 249 | #main.ONOS2.start_onos_cli(ONOS_ip=main.params['CTRL']['ip1']) |
| 250 | deviceResult = main.ONOS2.devices() |
| 251 | linksResult = main.ONOS2.links() |
| 252 | portsResult = main.ONOS2.ports() |
| 253 | print "**************" |
| 254 | main.step("Start continuous pings") |
| 255 | main.Mininet2.pingLong(src=main.params['PING']['source1'], |
| 256 | target=main.params['PING']['target1'],pingTime=500) |
| 257 | main.Mininet2.pingLong(src=main.params['PING']['source2'], |
| 258 | target=main.params['PING']['target2'],pingTime=500) |
| 259 | main.Mininet2.pingLong(src=main.params['PING']['source3'], |
| 260 | target=main.params['PING']['target3'],pingTime=500) |
| 261 | main.Mininet2.pingLong(src=main.params['PING']['source4'], |
| 262 | target=main.params['PING']['target4'],pingTime=500) |
| 263 | main.Mininet2.pingLong(src=main.params['PING']['source5'], |
| 264 | target=main.params['PING']['target5'],pingTime=500) |
| 265 | main.Mininet2.pingLong(src=main.params['PING']['source6'], |
| 266 | target=main.params['PING']['target6'],pingTime=500) |
| 267 | main.Mininet2.pingLong(src=main.params['PING']['source7'], |
| 268 | target=main.params['PING']['target7'],pingTime=500) |
| 269 | main.Mininet2.pingLong(src=main.params['PING']['source8'], |
| 270 | target=main.params['PING']['target8'],pingTime=500) |
| 271 | main.Mininet2.pingLong(src=main.params['PING']['source9'], |
| 272 | target=main.params['PING']['target9'],pingTime=500) |
| 273 | main.Mininet2.pingLong(src=main.params['PING']['source10'], |
| 274 | target=main.params['PING']['target10'],pingTime=500) |
| 275 | |
| 276 | main.step("Create TestONTopology object") |
| 277 | global ctrls |
| 278 | ctrls = [] |
| 279 | count = 1 |
| 280 | while True: |
| 281 | temp = () |
| 282 | if ('ip' + str(count)) in main.params['CTRL']: |
| 283 | temp = temp + (getattr(main,('ONOS' + str(count))),) |
| 284 | temp = temp + ("ONOS"+str(count),) |
| 285 | temp = temp + (main.params['CTRL']['ip'+str(count)],) |
| 286 | temp = temp + (eval(main.params['CTRL']['port'+str(count)]),) |
| 287 | ctrls.append(temp) |
| 288 | count = count + 1 |
| 289 | else: |
| 290 | break |
| 291 | global MNTopo |
| 292 | Topo = TestONTopology(main.Mininet1, ctrls) # can also add Intent API info for intent operations |
| 293 | MNTopo = Topo |
| 294 | |
| 295 | Topology_Check = main.TRUE |
| 296 | main.step("Compare ONOS Topology to MN Topology") |
| 297 | '''for n in range(1,6): |
| 298 | result = main.Mininet1.compare_topo(MNTopo, |
| 299 | main.ONOS1.get_json(main.params['CTRL']['ip'+str(n)]+":"+ \ |
| 300 | main.params['CTRL']['restPort'+str(n)]+main.params['TopoRest'])) |
| 301 | if result == main.TRUE: |
| 302 | main.log.report("ONOS"+str(n) + " Topology matches MN Topology") |
| 303 | utilities.assert_equals(expect=main.TRUE,actual=result, |
| 304 | onpass="ONOS" + str(n) + " Topology matches MN Topology", |
| 305 | onfail="ONOS" + str(n) + " Topology does not match MN Topology") |
| 306 | Topology_Check = Topology_Check and result |
| 307 | utilities.assert_equals(expect=main.TRUE,actual=Topology_Check, |
| 308 | onpass="Topology checks passed", onfail="Topology checks failed") |
| 309 | ''' |
| 310 | |
| 311 | |