shahshreya | 4e13a06 | 2014-11-11 16:46:18 -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 | import json |
| 11 | |
| 12 | time.sleep(1) |
| 13 | class ProdFunc13: |
| 14 | def __init__(self): |
| 15 | self.default = '' |
| 16 | |
| 17 | def CASE1(self, main): |
| 18 | ''' |
| 19 | Startup sequence: |
| 20 | git pull |
| 21 | mvn clean install |
| 22 | onos-package |
| 23 | cell <name> |
| 24 | onos-verify-cell |
| 25 | onos-install -f |
| 26 | onos-wait-for-start |
| 27 | ''' |
| 28 | |
| 29 | cell_name = main.params['ENV']['cellName'] |
| 30 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 31 | ONOS1_port = main.params['CTRL']['port1'] |
| 32 | |
| 33 | main.case("Setting up test environment") |
| 34 | main.log.report("This testcase is testing setting up test environment") |
| 35 | main.log.report("__________________________________") |
| 36 | main.step("Git checkout and pull master and get version") |
| 37 | main.ONOSbench.git_checkout("master") |
| 38 | git_pull_result = main.ONOSbench.git_pull() |
| 39 | print "git_pull_result = ", git_pull_result |
| 40 | version_result = main.ONOSbench.get_version(report=True) |
| 41 | |
| 42 | if git_pull_result == 1: |
| 43 | main.step("Using mvn clean & install") |
| 44 | clean_install_result = main.ONOSbench.clean_install() |
| 45 | #clean_install_result = main.TRUE |
| 46 | |
| 47 | main.step("Applying cell variable to environment") |
| 48 | cell_result1 = main.ONOSbench.set_cell(cell_name) |
| 49 | verify_result = main.ONOSbench.verify_cell() |
| 50 | cell_result2 = main.ONOS2.set_cell(cell_name) |
| 51 | #verify_result = main.ONOS2.verify_cell() |
| 52 | main.ONOS2.start_onos_cli(ONOS_ip=main.params['CTRL']['ip1']) |
| 53 | |
| 54 | cell_result = cell_result1 and cell_result2 |
| 55 | |
| 56 | main.step("Creating ONOS package") |
| 57 | package_result = main.ONOSbench.onos_package() |
| 58 | |
| 59 | #main.step("Creating a cell") |
| 60 | #cell_create_result = main.ONOSbench.create_cell_file(**************) |
| 61 | |
| 62 | main.step("Installing ONOS package") |
| 63 | onos_install_result = main.ONOSbench.onos_install() |
| 64 | if onos_install_result == main.TRUE: |
| 65 | main.log.report("Installing ONOS package successful") |
| 66 | else: |
| 67 | main.log.report("Installing ONOS package failed") |
| 68 | |
| 69 | onos1_isup = main.ONOSbench.isup() |
| 70 | if onos1_isup == main.TRUE: |
| 71 | main.log.report("ONOS instance is up and ready") |
| 72 | else: |
| 73 | main.log.report("ONOS instance may not be up") |
| 74 | |
| 75 | main.step("Starting ONOS service") |
| 76 | start_result = main.ONOSbench.onos_start(ONOS1_ip) |
| 77 | |
| 78 | case1_result = (package_result and\ |
| 79 | cell_result and verify_result and onos_install_result and\ |
| 80 | onos1_isup and start_result ) |
| 81 | utilities.assert_equals(expect=main.TRUE, actual=case1_result, |
| 82 | onpass="Test startup successful", |
| 83 | onfail="Test startup NOT successful") |
| 84 | |
| 85 | def CASE11(self, main): |
| 86 | ''' |
| 87 | Cleanup sequence: |
| 88 | onos-service <node_ip> stop |
| 89 | onos-uninstall |
| 90 | |
| 91 | TODO: Define rest of cleanup |
| 92 | |
| 93 | ''' |
| 94 | |
| 95 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 96 | |
| 97 | main.case("Cleaning up test environment") |
| 98 | |
| 99 | main.step("Testing ONOS kill function") |
| 100 | kill_result = main.ONOSbench.onos_kill(ONOS1_ip) |
| 101 | |
| 102 | main.step("Stopping ONOS service") |
| 103 | stop_result = main.ONOSbench.onos_stop(ONOS1_ip) |
| 104 | |
| 105 | main.step("Uninstalling ONOS service") |
| 106 | uninstall_result = main.ONOSbench.onos_uninstall() |
| 107 | |
| 108 | def CASE3(self, main): |
| 109 | ''' |
| 110 | Test 'onos' command and its functionality in driver |
| 111 | ''' |
| 112 | |
| 113 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 114 | |
| 115 | main.case("Testing 'onos' command") |
| 116 | |
| 117 | main.step("Sending command 'onos -w <onos-ip> system:name'") |
| 118 | cmdstr1 = "system:name" |
| 119 | cmd_result1 = main.ONOSbench.onos_cli(ONOS1_ip, cmdstr1) |
| 120 | main.log.info("onos command returned: "+cmd_result1) |
| 121 | |
| 122 | main.step("Sending command 'onos -w <onos-ip> onos:topology'") |
| 123 | cmdstr2 = "onos:topology" |
| 124 | cmd_result2 = main.ONOSbench.onos_cli(ONOS1_ip, cmdstr2) |
| 125 | main.log.info("onos command returned: "+cmd_result2) |
| 126 | |
| 127 | |
| 128 | |
| 129 | def CASE4(self, main): |
| 130 | import re |
| 131 | import time |
| 132 | main.log.report("This testcase is testing the assignment of all the switches to all the controllers and discovering the hosts in reactive mode") |
| 133 | main.log.report("__________________________________") |
| 134 | main.case("Pingall Test") |
| 135 | main.step("Assigning switches to controllers") |
| 136 | for i in range(1,29): |
| 137 | if i ==1: |
| 138 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=ONOS1_ip,port1=ONOS1_port) |
| 139 | elif i>=2 and i<5: |
| 140 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=ONOS1_ip,port1=ONOS1_port) |
| 141 | elif i>=5 and i<8: |
| 142 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=ONOS1_ip,port1=ONOS1_port) |
| 143 | elif i>=8 and i<18: |
| 144 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=ONOS1_ip,port1=ONOS1_port) |
| 145 | elif i>=18 and i<28: |
| 146 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=ONOS1_ip,port1=ONOS1_port) |
| 147 | else: |
| 148 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=ONOS1_ip,port1=ONOS1_port) |
| 149 | Switch_Mastership = main.TRUE |
| 150 | for i in range (1,29): |
| 151 | if i==1: |
| 152 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 153 | print("Response is " + str(response)) |
| 154 | if re.search("tcp:"+ONOS1_ip,response): |
| 155 | Switch_Mastership = Switch_Mastership and main.TRUE |
| 156 | else: |
| 157 | Switch_Mastership = main.FALSE |
| 158 | elif i>=2 and i<5: |
| 159 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 160 | print("Response is " + str(response)) |
| 161 | if re.search("tcp:"+ONOS1_ip,response): |
| 162 | Switch_Mastership = Switch_Mastership and main.TRUE |
| 163 | else: |
| 164 | Switch_Mastership = main.FALSE |
| 165 | elif i>=5 and i<8: |
| 166 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 167 | print("Response is " + str(response)) |
| 168 | if re.search("tcp:"+ONOS1_ip,response): |
| 169 | Switch_Mastership = Switch_Mastership and main.TRUE |
| 170 | else: |
| 171 | Switch_Mastership = main.FALSE |
| 172 | elif i>=8 and i<18: |
| 173 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 174 | print("Response is " + str(response)) |
| 175 | if re.search("tcp:"+ONOS1_ip,response): |
| 176 | Switch_Mastership = Switch_Mastership and main.TRUE |
| 177 | else: |
| 178 | Switch_Mastership = main.FALSE |
| 179 | elif i>=18 and i<28: |
| 180 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 181 | print("Response is " + str(response)) |
| 182 | if re.search("tcp:"+ONOS1_ip,response): |
| 183 | Switch_Mastership = Switch_Mastership and main.TRUE |
| 184 | else: |
| 185 | Switch_Mastership = main.FALSE |
| 186 | else: |
| 187 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 188 | print("Response is" + str(response)) |
| 189 | if re.search("tcp:" +ONOS1_ip,response): |
| 190 | Switch_Mastership = Switch_Mastership and main.TRUE |
| 191 | else: |
| 192 | Switch_Mastership = main.FALSE |
| 193 | |
| 194 | if Switch_Mastership == main.TRUE: |
| 195 | main.log.report("Controller assignmnet successful") |
| 196 | else: |
| 197 | main.log.report("Controller assignmnet failed") |
| 198 | utilities.assert_equals(expect = main.TRUE,actual=Switch_Mastership, |
| 199 | onpass="MasterControllers assigned correctly") |
| 200 | ''' |
| 201 | for i in range (1,29): |
| 202 | main.Mininet1.assign_sw_controller(sw=str(i),count=5, |
| 203 | ip1=ONOS1_ip,port1=ONOS1_port, |
| 204 | ip2=ONOS2_ip,port2=ONOS2_port, |
| 205 | ip3=ONOS3_ip,port3=ONOS3_port, |
| 206 | ip4=ONOS4_ip,port4=ONOS4_port, |
| 207 | ip5=ONOS5_ip,port5=ONOS5_port) |
| 208 | ''' |
| 209 | #REACTIVE FWD test |
| 210 | |
| 211 | main.step("Get list of hosts from Mininet") |
| 212 | host_list = main.Mininet1.get_hosts() |
| 213 | main.log.info(host_list) |
| 214 | |
| 215 | main.step("Get host list in ONOS format") |
| 216 | host_onos_list = main.ONOS2.get_hosts_id(host_list) |
| 217 | main.log.info(host_onos_list) |
| 218 | #time.sleep(5) |
| 219 | |
| 220 | main.step("Pingall") |
| 221 | ping_result = main.FALSE |
| 222 | while ping_result == main.FALSE: |
| 223 | time1 = time.time() |
| 224 | ping_result = main.Mininet1.pingall() |
| 225 | time2 = time.time() |
| 226 | print "Time for pingall: %2f seconds" % (time2 - time1) |
| 227 | |
| 228 | #Start onos cli again because u might have dropped out of onos prompt to the shell prompt |
| 229 | #if there was no activity |
| 230 | main.ONOS2.start_onos_cli(ONOS_ip=main.params['CTRL']['ip1']) |
| 231 | |
| 232 | case4_result = Switch_Mastership and ping_result |
| 233 | if ping_result == main.TRUE: |
| 234 | main.log.report("Pingall Test in reactive mode to discover the hosts successful") |
| 235 | else: |
| 236 | main.log.report("Pingall Test in reactive mode to discover the hosts failed") |
| 237 | |
| 238 | utilities.assert_equals(expect=main.TRUE, actual=case4_result,onpass="Controller assignment and Pingall T est successful",onfail="Controller assignment and Pingall Test NOT successful") |
| 239 | |
| 240 | |
| 241 | def CASE6(self): |
| 242 | main.log.report("This testcase is testing the addition of host intents and then doing pingall") |
| 243 | main.log.report("__________________________________") |
| 244 | main.case("Uninstalling reactive forwarding app and addhost intents") |
| 245 | main.step("Get hosts") |
| 246 | main.ONOS2.handle.sendline("hosts") |
| 247 | main.ONOS2.handle.expect("onos>") |
| 248 | hosts = main.ONOS2.handle.before |
| 249 | main.log.info(hosts) |
| 250 | |
| 251 | main.step("Get all devices id") |
| 252 | devices_id_list = main.ONOS2.get_all_devices_id() |
| 253 | main.log.info(devices_id_list) |
| 254 | |
| 255 | #ONOS displays the hosts in hex format unlike mininet which does in decimal format |
| 256 | #So take care while adding intents |
| 257 | |
| 258 | main.step("Add host-to-host intents for mininet hosts h8 and h18 or ONOS hosts h8 and h12") |
| 259 | hth_intent_result = main.ONOS2.add_host_intent("00:00:00:00:00:08/-1", "00:00:00:00:00:12/-1") |
| 260 | hth_intent_result = main.ONOS2.add_host_intent("00:00:00:00:00:09/-1", "00:00:00:00:00:13/-1") |
| 261 | hth_intent_result = main.ONOS2.add_host_intent("00:00:00:00:00:0A/-1", "00:00:00:00:00:14/-1") |
| 262 | hth_intent_result = main.ONOS2.add_host_intent("00:00:00:00:00:0B/-1", "00:00:00:00:00:15/-1") |
| 263 | hth_intent_result = main.ONOS2.add_host_intent("00:00:00:00:00:0C/-1", "00:00:00:00:00:16/-1") |
| 264 | hth_intent_result = main.ONOS2.add_host_intent("00:00:00:00:00:0D/-1", "00:00:00:00:00:17/-1") |
| 265 | hth_intent_result = main.ONOS2.add_host_intent("00:00:00:00:00:0E/-1", "00:00:00:00:00:18/-1") |
| 266 | hth_intent_result = main.ONOS2.add_host_intent("00:00:00:00:00:0F/-1", "00:00:00:00:00:19/-1") |
| 267 | hth_intent_result = main.ONOS2.add_host_intent("00:00:00:00:00:10/-1", "00:00:00:00:00:1A/-1") |
| 268 | hth_intent_result = main.ONOS2.add_host_intent("00:00:00:00:00:11/-1", "00:00:00:00:00:1B/-1") |
| 269 | |
| 270 | |
| 271 | |
| 272 | print "_____________________________________________________________________________________" |
| 273 | |
| 274 | #Unistall onos-app-fwd app to disable reactive forwarding |
| 275 | appUninstall_result = main.ONOS2.feature_uninstall("onos-app-fwd") |
| 276 | main.log.info("onos-app-fwd uninstalled") |
| 277 | |
| 278 | #After reactive forwarding is disabled, the reactive flows on switches timeout in 10-15s |
| 279 | #So sleep for 15s |
| 280 | time.sleep(15) |
| 281 | |
| 282 | flowHandle = main.ONOS2.flows() |
| 283 | #print "flowHandle = ", flowHandle |
| 284 | main.log.info("flow:" +flowHandle) |
| 285 | |
| 286 | count = 1 |
| 287 | i = 8 |
| 288 | Ping_Result = main.TRUE |
| 289 | #while i<10: |
| 290 | while i <18 : |
| 291 | main.log.info("\n\nh"+str(i)+" is Pinging h" + str(i+10)) |
| 292 | ping = main.Mininet1.pingHost(src="h"+str(i),target="h"+str(i+10)) |
| 293 | if ping == main.FALSE and count <5: |
| 294 | count+=1 |
| 295 | #i = 8 |
| 296 | Ping_Result = main.FALSE |
| 297 | main.log.report("Ping between h" + str(i) + " and h" + str(i+10) + " failed. Making attempt number "+str(count) + " in 2 seconds") |
| 298 | time.sleep(2) |
| 299 | elif ping==main.FALSE: |
| 300 | main.log.report("All ping attempts between h" + str(i) + " and h" + str(i+10) +"have failed") |
| 301 | i=19 |
| 302 | Ping_Result = main.FALSE |
| 303 | elif ping==main.TRUE: |
| 304 | main.log.info("Ping test between h" + str(i) + " and h" + str(i+10) + "passed!") |
| 305 | i+=1 |
| 306 | Ping_Result = main.TRUE |
| 307 | else: |
| 308 | main.log.info("Unknown error") |
| 309 | Ping_Result = main.ERROR |
| 310 | if Ping_Result==main.FALSE: |
| 311 | main.log.report("Ping all test after Host intent addition failed. Cleaning up") |
| 312 | #main.cleanup() |
| 313 | #main.exit() |
| 314 | if Ping_Result==main.TRUE: |
| 315 | main.log.report("Ping all test after Host intent addition successful") |
| 316 | |
| 317 | case6_result = Ping_Result |
| 318 | utilities.assert_equals(expect=main.TRUE, actual=case4_result, |
| 319 | onpass="Pingall Test after Host intents addition successful", |
| 320 | onfail="Pingall Test after Host intents addition failed") |
| 321 | |
| 322 | |
| 323 | def CASE5(self,main) : |
| 324 | import json |
| 325 | from subprocess import Popen, PIPE |
| 326 | from sts.topology.teston_topology import TestONTopology # assumes that sts is already in you PYTHONPATH |
| 327 | #main.ONOS2.start_onos_cli(ONOS_ip=main.params['CTRL']['ip1']) |
| 328 | deviceResult = main.ONOS2.devices() |
| 329 | linksResult = main.ONOS2.links() |
| 330 | #portsResult = main.ONOS2.ports() |
| 331 | print "**************" |
| 332 | |
| 333 | main.log.report("This testcase is testing if all ONOS nodes are in topology sync with mininet") |
| 334 | main.log.report("__________________________________") |
| 335 | main.case("Comparing Mininet topology with the topology of ONOS") |
| 336 | main.step("Start continuous pings") |
| 337 | main.Mininet2.pingLong(src=main.params['PING']['source1'], |
| 338 | target=main.params['PING']['target1'],pingTime=500) |
| 339 | main.Mininet2.pingLong(src=main.params['PING']['source2'], |
| 340 | target=main.params['PING']['target2'],pingTime=500) |
| 341 | main.Mininet2.pingLong(src=main.params['PING']['source3'], |
| 342 | target=main.params['PING']['target3'],pingTime=500) |
| 343 | main.Mininet2.pingLong(src=main.params['PING']['source4'], |
| 344 | target=main.params['PING']['target4'],pingTime=500) |
| 345 | main.Mininet2.pingLong(src=main.params['PING']['source5'], |
| 346 | target=main.params['PING']['target5'],pingTime=500) |
| 347 | main.Mininet2.pingLong(src=main.params['PING']['source6'], |
| 348 | target=main.params['PING']['target6'],pingTime=500) |
| 349 | main.Mininet2.pingLong(src=main.params['PING']['source7'], |
| 350 | target=main.params['PING']['target7'],pingTime=500) |
| 351 | main.Mininet2.pingLong(src=main.params['PING']['source8'], |
| 352 | target=main.params['PING']['target8'],pingTime=500) |
| 353 | main.Mininet2.pingLong(src=main.params['PING']['source9'], |
| 354 | target=main.params['PING']['target9'],pingTime=500) |
| 355 | main.Mininet2.pingLong(src=main.params['PING']['source10'], |
| 356 | target=main.params['PING']['target10'],pingTime=500) |
| 357 | |
| 358 | main.step("Create TestONTopology object") |
| 359 | global ctrls |
| 360 | ctrls = [] |
| 361 | count = 1 |
| 362 | while True: |
| 363 | temp = () |
| 364 | if ('ip' + str(count)) in main.params['CTRL']: |
| 365 | temp = temp + (getattr(main,('ONOS' + str(count))),) |
| 366 | temp = temp + ("ONOS"+str(count),) |
| 367 | temp = temp + (main.params['CTRL']['ip'+str(count)],) |
| 368 | temp = temp + (eval(main.params['CTRL']['port'+str(count)]),) |
| 369 | ctrls.append(temp) |
| 370 | count = count + 1 |
| 371 | else: |
| 372 | break |
| 373 | global MNTopo |
| 374 | Topo = TestONTopology(main.Mininet1, ctrls) # can also add Intent API info for intent operations |
| 375 | MNTopo = Topo |
| 376 | |
| 377 | Topology_Check = main.TRUE |
| 378 | main.step("Compare ONOS Topology to MN Topology") |
| 379 | devices_json = main.ONOS2.devices() |
| 380 | links_json = main.ONOS2.links() |
| 381 | #ports_json = main.ONOS2.ports() |
| 382 | print "devices_json= ", devices_json |
| 383 | |
| 384 | result1 = main.Mininet1.compare_switches(MNTopo, json.loads(devices_json)) |
| 385 | result2 = main.Mininet1.compare_links(MNTopo, json.loads(links_json)) |
| 386 | #result3 = main.Mininet1.compare_ports(MNTopo, json.loads(ports_json)) |
| 387 | |
| 388 | #result = result1 and result2 and result3 |
| 389 | result = result1 and result2 |
| 390 | |
| 391 | print "***********************" |
| 392 | if result == main.TRUE: |
| 393 | main.log.report("ONOS"+ " Topology matches MN Topology") |
| 394 | else: |
| 395 | main.log.report("ONOS"+ " Topology does not match MN Topology") |
| 396 | |
| 397 | utilities.assert_equals(expect=main.TRUE,actual=result, |
| 398 | onpass="ONOS" + " Topology matches MN Topology", |
| 399 | onfail="ONOS" + " Topology does not match MN Topology") |
| 400 | |
| 401 | Topology_Check = Topology_Check and result |
| 402 | utilities.assert_equals(expect=main.TRUE,actual=Topology_Check, |
| 403 | onpass="Topology checks passed", onfail="Topology checks failed") |
| 404 | |
| 405 | |
| 406 | def CASE7 (self,main): |
| 407 | |
| 408 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 409 | |
| 410 | link_sleep = int(main.params['timers']['LinkDiscovery']) |
| 411 | |
| 412 | main.log.report("This testscase is killing a link to ensure that link discovery is consistent") |
| 413 | main.log.report("__________________________________") |
| 414 | main.log.report("Killing a link to ensure that link discovery is consistent") |
| 415 | main.case("Killing a link to Ensure that Link Discovery is Working Properly") |
| 416 | main.step("Start continuous pings") |
| 417 | |
| 418 | main.Mininet2.pingLong(src=main.params['PING']['source1'], |
| 419 | target=main.params['PING']['target1'],pingTime=500) |
| 420 | main.Mininet2.pingLong(src=main.params['PING']['source2'], |
| 421 | target=main.params['PING']['target2'],pingTime=500) |
| 422 | main.Mininet2.pingLong(src=main.params['PING']['source3'], |
| 423 | target=main.params['PING']['target3'],pingTime=500) |
| 424 | main.Mininet2.pingLong(src=main.params['PING']['source4'], |
| 425 | target=main.params['PING']['target4'],pingTime=500) |
| 426 | main.Mininet2.pingLong(src=main.params['PING']['source5'], |
| 427 | target=main.params['PING']['target5'],pingTime=500) |
| 428 | main.Mininet2.pingLong(src=main.params['PING']['source6'], |
| 429 | target=main.params['PING']['target6'],pingTime=500) |
| 430 | main.Mininet2.pingLong(src=main.params['PING']['source7'], |
| 431 | target=main.params['PING']['target7'],pingTime=500) |
| 432 | main.Mininet2.pingLong(src=main.params['PING']['source8'], |
| 433 | target=main.params['PING']['target8'],pingTime=500) |
| 434 | main.Mininet2.pingLong(src=main.params['PING']['source9'], |
| 435 | target=main.params['PING']['target9'],pingTime=500) |
| 436 | main.Mininet2.pingLong(src=main.params['PING']['source10'], |
| 437 | target=main.params['PING']['target10'],pingTime=500) |
| 438 | |
| 439 | |
| 440 | main.step("Determine the current number of switches and links") |
| 441 | topology_output = main.ONOS2.topology() |
| 442 | topology_result = main.ONOS1.get_topology(topology_output) |
| 443 | activeSwitches = topology_result['devices'] |
| 444 | links = topology_result['links'] |
| 445 | print "activeSwitches = ", type(activeSwitches) |
| 446 | print "links = ", type(links) |
| 447 | main.log.info("Currently there are %s switches and %s links" %(str(activeSwitches), str(links))) |
| 448 | |
| 449 | main.step("Kill Link between s3 and s28") |
| 450 | main.Mininet1.link(END1="s3",END2="s28",OPTION="down") |
| 451 | time.sleep(link_sleep) |
| 452 | topology_output = main.ONOS2.topology() |
| 453 | Link_Down = main.ONOS1.check_status(topology_output,activeSwitches,str(int(links)-2)) |
| 454 | if Link_Down == main.TRUE: |
| 455 | main.log.report("Link Down discovered properly") |
| 456 | utilities.assert_equals(expect=main.TRUE,actual=Link_Down, |
| 457 | onpass="Link Down discovered properly", |
| 458 | onfail="Link down was not discovered in "+ str(link_sleep) + " seconds") |
| 459 | |
| 460 | #Check ping result here..add code for it |
| 461 | |
| 462 | main.step("Bring link between s3 and s28 back up") |
| 463 | Link_Up = main.Mininet1.link(END1="s3",END2="s28",OPTION="up") |
| 464 | time.sleep(link_sleep) |
| 465 | topology_output = main.ONOS2.topology() |
| 466 | Link_Up = main.ONOS1.check_status(topology_output,activeSwitches,str(links)) |
| 467 | if Link_Up == main.TRUE: |
| 468 | main.log.report("Link up discovered properly") |
| 469 | utilities.assert_equals(expect=main.TRUE,actual=Link_Up, |
| 470 | onpass="Link up discovered properly", |
| 471 | onfail="Link up was not discovered in "+ str(link_sleep) + " seconds") |
| 472 | |
| 473 | #Check ping result here..add code for it |
| 474 | main.step("Start continuous pings") |
| 475 | |
| 476 | main.Mininet2.pingLong(src=main.params['PING']['source1'], |
| 477 | target=main.params['PING']['target1'],pingTime=500) |
| 478 | main.Mininet2.pingLong(src=main.params['PING']['source2'], |
| 479 | target=main.params['PING']['target2'],pingTime=500) |
| 480 | main.Mininet2.pingLong(src=main.params['PING']['source3'], |
| 481 | target=main.params['PING']['target3'],pingTime=500) |
| 482 | main.Mininet2.pingLong(src=main.params['PING']['source4'], |
| 483 | target=main.params['PING']['target4'],pingTime=500) |
| 484 | main.Mininet2.pingLong(src=main.params['PING']['source5'], |
| 485 | target=main.params['PING']['target5'],pingTime=500) |
| 486 | main.Mininet2.pingLong(src=main.params['PING']['source6'], |
| 487 | target=main.params['PING']['target6'],pingTime=500) |
| 488 | main.Mininet2.pingLong(src=main.params['PING']['source7'], |
| 489 | target=main.params['PING']['target7'],pingTime=500) |
| 490 | main.Mininet2.pingLong(src=main.params['PING']['source8'], |
| 491 | target=main.params['PING']['target8'],pingTime=500) |
| 492 | main.Mininet2.pingLong(src=main.params['PING']['source9'], |
| 493 | target=main.params['PING']['target9'],pingTime=500) |
| 494 | main.Mininet2.pingLong(src=main.params['PING']['source10'], |
| 495 | target=main.params['PING']['target10'],pingTime=500) |
| 496 | |
| 497 | main.step("Compare ONOS Topology to MN Topology") |
| 498 | Topo = TestONTopology(main.Mininet1, ctrls) # can also add Intent API info for intent operations |
| 499 | MNTopo = Topo |
| 500 | Topology_Check = main.TRUE |
| 501 | |
| 502 | devices_json = main.ONOS2.devices() |
| 503 | links_json = main.ONOS2.links() |
| 504 | ports_json = main.ONOS2.ports() |
| 505 | print "devices_json= ", devices_json |
| 506 | |
| 507 | result1 = main.Mininet1.compare_switches(MNTopo, json.loads(devices_json)) |
| 508 | result2 = main.Mininet1.compare_links(MNTopo, json.loads(links_json)) |
| 509 | #result3 = main.Mininet1.compare_ports(MNTopo, json.loads(ports_json)) |
| 510 | |
| 511 | #result = result1 and result2 and result3 |
| 512 | result = result1 and result2 |
| 513 | print "***********************" |
| 514 | |
| 515 | if result == main.TRUE: |
| 516 | main.log.report("ONOS"+ " Topology matches MN Topology") |
| 517 | utilities.assert_equals(expect=main.TRUE,actual=result, |
| 518 | onpass="ONOS" + " Topology matches MN Topology", |
| 519 | onfail="ONOS" + " Topology does not match MN Topology") |
| 520 | |
| 521 | Topology_Check = Topology_Check and result |
| 522 | utilities.assert_equals(expect=main.TRUE,actual=Topology_Check, |
| 523 | onpass="Topology checks passed", onfail="Topology checks failed") |
| 524 | |
| 525 | result = Link_Down and Link_Up and Topology_Check |
| 526 | utilities.assert_equals(expect=main.TRUE,actual=result, |
| 527 | onpass="Link failure is discovered correctly", |
| 528 | onfail="Link Discovery failed") |
| 529 | |
| 530 | |
| 531 | def CASE8(self): |
| 532 | ''' |
| 533 | Host intents removal |
| 534 | ''' |
| 535 | main.log.report("This testcase removes host intents before adding the point intents") |
| 536 | main.log.report("__________________________________") |
| 537 | main.log.info("Host intents removal") |
| 538 | main.case("Removing host intents") |
| 539 | main.step("Obtain the intent id's") |
| 540 | intent_result = main.ONOS2.intents() |
| 541 | #print "intent_result = ",intent_result |
| 542 | intent_linewise = intent_result.split("\n") |
| 543 | intent_linewise = intent_linewise[1:-1] #ignore the first and last item of the list obtained from split |
| 544 | #for line in intent_linewise: |
| 545 | #print "line = ", line |
| 546 | intentids = [] |
| 547 | for line in intent_linewise: |
| 548 | intentids.append(line.split(",")[0].split("=")[1]) |
| 549 | for id in intentids: |
| 550 | print "id = ", id |
| 551 | |
| 552 | main.step("Iterate through the intentids list and remove each intent") |
| 553 | for id in intentids: |
| 554 | main.ONOS2.remove_intent(intent_id = id) |
| 555 | |
| 556 | intent_result = main.ONOS2.intents() |
| 557 | intent_linewise = intent_result.split("\n") |
| 558 | intent_linewise = intent_linewise[1:-1] #ignore the first and last item of the list obtained from split |
| 559 | |
| 560 | intentState = {} |
| 561 | for id, line in zip(intentids, intent_linewise): |
| 562 | #print "line after removing intent = ", line |
| 563 | x = line.split(",") |
| 564 | state = x[1].split("=")[1] |
| 565 | intentState[id] = state |
| 566 | |
| 567 | case8_result = main.TRUE |
| 568 | for key,value in intentState.iteritems(): |
| 569 | print "key,value = ", key, value |
| 570 | if value == "WITHDRAWN": |
| 571 | case8_result = case8_result and main.TRUE |
| 572 | else: |
| 573 | case8_result = case8_result and main.FALSE |
| 574 | |
| 575 | if case8_result == main.TRUE: |
| 576 | main.log.report("Intent removal successful") |
| 577 | else: |
| 578 | main.log.report("Intent removal failed") |
| 579 | |
| 580 | utilities.assert_equals(expect=main.TRUE, actual=case8_result, |
| 581 | onpass="Intent removal test successful", |
| 582 | onfail="Intent removal test failed") |
| 583 | |
| 584 | |
| 585 | |
| 586 | |
| 587 | |
| 588 | def CASE9(self): |
| 589 | main.log.report("This testcase adds point intents and then does pingall") |
| 590 | main.log.report("__________________________________") |
| 591 | main.log.info("Adding point intents") |
| 592 | main.case("Adding bidirectional point for mn hosts(h8-h18,h9-h19,h10-h20,h11-h21,h12-h22,h13-h23,h14-h24,h15-h25,h16-h26,h17-h27)") |
| 593 | main.step("Add point-to-point intents for mininet hosts h8 and h18 or ONOS hosts h8 and h12") |
| 594 | ptp_intent_result = main.ONOS2.add_point_intent("of:0000000000003008", 1, "of:0000000000006018", 1) |
| 595 | if ptp_intent_result == main.TRUE: |
| 596 | get_intent_result = main.ONOS2.intents() |
| 597 | main.log.info("Point to point intent install successful") |
| 598 | main.log.info(get_intent_result) |
| 599 | |
| 600 | ptp_intent_result = main.ONOS2.add_point_intent("of:0000000000006018", 1, "of:0000000000003008", 1) |
| 601 | if ptp_intent_result == main.TRUE: |
| 602 | get_intent_result = main.ONOS2.intents() |
| 603 | main.log.info("Point to point intent install successful") |
| 604 | main.log.info(get_intent_result) |
| 605 | |
| 606 | main.step("Add point-to-point intents for mininet hosts h9 and h19 or ONOS hosts h9 and h13") |
| 607 | ptp_intent_result = main.ONOS2.add_point_intent("of:0000000000003009", 1, "of:0000000000006019", 1) |
| 608 | if ptp_intent_result == main.TRUE: |
| 609 | get_intent_result = main.ONOS2.intents() |
| 610 | main.log.info("Point to point intent install successful") |
| 611 | main.log.info(get_intent_result) |
| 612 | |
| 613 | ptp_intent_result = main.ONOS2.add_point_intent("of:0000000000006019", 1, "of:0000000000003009", 1) |
| 614 | if ptp_intent_result == main.TRUE: |
| 615 | get_intent_result = main.ONOS2.intents() |
| 616 | main.log.info("Point to point intent install successful") |
| 617 | main.log.info(get_intent_result) |
| 618 | |
| 619 | main.step("Add point-to-point intents for mininet hosts h10 and h20 or ONOS hosts hA and h14") |
| 620 | ptp_intent_result = main.ONOS2.add_point_intent("of:0000000000003010", 1, "of:0000000000006020", 1) |
| 621 | if ptp_intent_result == main.TRUE: |
| 622 | get_intent_result = main.ONOS2.intents() |
| 623 | main.log.info("Point to point intent install successful") |
| 624 | main.log.info(get_intent_result) |
| 625 | |
| 626 | ptp_intent_result = main.ONOS2.add_point_intent("of:0000000000006020", 1, "of:0000000000003010", 1) |
| 627 | if ptp_intent_result == main.TRUE: |
| 628 | get_intent_result = main.ONOS2.intents() |
| 629 | main.log.info("Point to point intent install successful") |
| 630 | main.log.info(get_intent_result) |
| 631 | |
| 632 | main.step("Add point-to-point intents for mininet hosts h11 and h21 or ONOS hosts hB and h15") |
| 633 | ptp_intent_result = main.ONOS2.add_point_intent("of:0000000000003011", 1, "of:0000000000006021", 1) |
| 634 | if ptp_intent_result == main.TRUE: |
| 635 | get_intent_result = main.ONOS2.intents() |
| 636 | main.log.info("Point to point intent install successful") |
| 637 | main.log.info(get_intent_result) |
| 638 | |
| 639 | ptp_intent_result = main.ONOS2.add_point_intent("of:0000000000006021", 1, "of:0000000000003011", 1) |
| 640 | if ptp_intent_result == main.TRUE: |
| 641 | get_intent_result = main.ONOS2.intents() |
| 642 | main.log.info("Point to point intent install successful") |
| 643 | main.log.info(get_intent_result) |
| 644 | |
| 645 | main.step("Add point-to-point intents for mininet hosts h12 and h22 or ONOS hosts hC and h16") |
| 646 | ptp_intent_result = main.ONOS2.add_point_intent("of:0000000000003012", 1, "of:0000000000006022", 1) |
| 647 | if ptp_intent_result == main.TRUE: |
| 648 | get_intent_result = main.ONOS2.intents() |
| 649 | main.log.info("Point to point intent install successful") |
| 650 | main.log.info(get_intent_result) |
| 651 | |
| 652 | ptp_intent_result = main.ONOS2.add_point_intent("of:0000000000006022", 1, "of:0000000000003012", 1) |
| 653 | if ptp_intent_result == main.TRUE: |
| 654 | get_intent_result = main.ONOS2.intents() |
| 655 | main.log.info("Point to point intent install successful") |
| 656 | main.log.info(get_intent_result) |
| 657 | |
| 658 | main.step("Add point-to-point intents for mininet hosts h13 and h23 or ONOS hosts hD and h17") |
| 659 | ptp_intent_result = main.ONOS2.add_point_intent("of:0000000000003013", 1, "of:0000000000006023", 1) |
| 660 | if ptp_intent_result == main.TRUE: |
| 661 | get_intent_result = main.ONOS2.intents() |
| 662 | main.log.info("Point to point intent install successful") |
| 663 | main.log.info(get_intent_result) |
| 664 | |
| 665 | ptp_intent_result = main.ONOS2.add_point_intent("of:0000000000006023", 1, "of:0000000000003013", 1) |
| 666 | if ptp_intent_result == main.TRUE: |
| 667 | get_intent_result = main.ONOS2.intents() |
| 668 | main.log.info("Point to point intent install successful") |
| 669 | main.log.info(get_intent_result) |
| 670 | |
| 671 | main.step("Add point-to-point intents for mininet hosts h14 and h24 or ONOS hosts hE and h18") |
| 672 | ptp_intent_result = main.ONOS2.add_point_intent("of:0000000000003014", 1, "of:0000000000006024", 1) |
| 673 | if ptp_intent_result == main.TRUE: |
| 674 | get_intent_result = main.ONOS2.intents() |
| 675 | main.log.info("Point to point intent install successful") |
| 676 | main.log.info(get_intent_result) |
| 677 | |
| 678 | ptp_intent_result = main.ONOS2.add_point_intent("of:0000000000006024", 1, "of:0000000000003014", 1) |
| 679 | if ptp_intent_result == main.TRUE: |
| 680 | get_intent_result = main.ONOS2.intents() |
| 681 | main.log.info("Point to point intent install successful") |
| 682 | main.log.info(get_intent_result) |
| 683 | |
| 684 | main.step("Add point-to-point intents for mininet hosts h15 and h25 or ONOS hosts hF and h19") |
| 685 | ptp_intent_result = main.ONOS2.add_point_intent("of:0000000000003015", 1, "of:0000000000006025", 1) |
| 686 | if ptp_intent_result == main.TRUE: |
| 687 | get_intent_result = main.ONOS2.intents() |
| 688 | main.log.info("Point to point intent install successful") |
| 689 | main.log.info(get_intent_result) |
| 690 | |
| 691 | ptp_intent_result = main.ONOS2.add_point_intent("of:0000000000006025", 1, "of:0000000000003015", 1) |
| 692 | if ptp_intent_result == main.TRUE: |
| 693 | get_intent_result = main.ONOS2.intents() |
| 694 | main.log.info("Point to point intent install successful") |
| 695 | main.log.info(get_intent_result) |
| 696 | |
| 697 | main.step("Add point-to-point intents for mininet hosts h16 and h26 or ONOS hosts h10 and h1A") |
| 698 | ptp_intent_result = main.ONOS2.add_point_intent("of:0000000000003016", 1, "of:0000000000006026", 1) |
| 699 | if ptp_intent_result == main.TRUE: |
| 700 | get_intent_result = main.ONOS2.intents() |
| 701 | main.log.info("Point to point intent install successful") |
| 702 | main.log.info(get_intent_result) |
| 703 | |
| 704 | ptp_intent_result = main.ONOS2.add_point_intent("of:0000000000006026", 1, "of:0000000000003016", 1) |
| 705 | if ptp_intent_result == main.TRUE: |
| 706 | get_intent_result = main.ONOS2.intents() |
| 707 | main.log.info("Point to point intent install successful") |
| 708 | main.log.info(get_intent_result) |
| 709 | |
| 710 | |
| 711 | main.step("Add point-to-point intents for mininet hosts h17 and h27 or ONOS hosts h11 and h1B") |
| 712 | ptp_intent_result = main.ONOS2.add_point_intent("of:0000000000003017", 1, "of:0000000000006027", 1) |
| 713 | if ptp_intent_result == main.TRUE: |
| 714 | get_intent_result = main.ONOS2.intents() |
| 715 | main.log.info("Point to point intent install successful") |
| 716 | main.log.info(get_intent_result) |
| 717 | |
| 718 | ptp_intent_result = main.ONOS2.add_point_intent("of:0000000000006027", 1, "of:0000000000003017", 1) |
| 719 | if ptp_intent_result == main.TRUE: |
| 720 | get_intent_result = main.ONOS2.intents() |
| 721 | main.log.info("Point to point intent install successful") |
| 722 | main.log.info(get_intent_result) |
| 723 | |
| 724 | print("_______________________________________________________________________________________") |
| 725 | |
| 726 | flowHandle = main.ONOS2.flows() |
| 727 | #print "flowHandle = ", flowHandle |
| 728 | main.log.info("flows :" + flowHandle) |
| 729 | |
| 730 | count = 1 |
| 731 | i = 8 |
| 732 | Ping_Result = main.TRUE |
| 733 | while i <18 : |
| 734 | main.log.info("\n\nh"+str(i)+" is Pinging h" + str(i+10)) |
| 735 | ping = main.Mininet1.pingHost(src="h"+str(i),target="h"+str(i+10)) |
| 736 | if ping == main.FALSE and count <5: |
| 737 | count+=1 |
| 738 | #i = 8 |
| 739 | Ping_Result = main.FALSE |
| 740 | main.log.report("Ping between h" + str(i) + " and h" + str(i+10) + " failed. Making attempt number "+str(count) + " in 2 seconds") |
| 741 | time.sleep(2) |
| 742 | elif ping==main.FALSE: |
| 743 | main.log.report("All ping attempts between h" + str(i) + " and h" + str(i+10) +"have failed") |
| 744 | i=19 |
| 745 | Ping_Result = main.FALSE |
| 746 | elif ping==main.TRUE: |
| 747 | main.log.info("Ping test between h" + str(i) + " and h" + str(i+10) + "passed!") |
| 748 | i+=1 |
| 749 | Ping_Result = main.TRUE |
| 750 | else: |
| 751 | main.log.info("Unknown error") |
| 752 | Ping_Result = main.ERROR |
| 753 | |
| 754 | if Ping_Result==main.FALSE: |
| 755 | main.log.report("Point intents have not ben installed correctly. Cleaning up") |
| 756 | #main.cleanup() |
| 757 | #main.exit() |
| 758 | if Ping_Result==main.TRUE: |
| 759 | main.log.report("Point Intents have been installed correctly") |
| 760 | |
| 761 | case9_result = Ping_Result |
| 762 | utilities.assert_equals(expect=main.TRUE, actual=case9_result, |
| 763 | onpass="Point intents addition and Pingall Test successful", |
| 764 | onfail="Point intents addition and Pingall Test NOT successful") |
| 765 | |
| 766 | |