Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1 | import time |
| 2 | import sys |
| 3 | import os |
| 4 | import re |
| 5 | import time |
| 6 | import json |
| 7 | import itertools |
| 8 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame^] | 9 | |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 10 | class OnosCHO: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame^] | 11 | |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 12 | def __init__(self): |
| 13 | self.default = '' |
| 14 | global deviceDPIDs |
| 15 | global hostMACs |
| 16 | global deviceLinks |
| 17 | global deviceActiveLinksCount |
| 18 | global devicePortsEnabledCount |
| 19 | global installedIntents |
| 20 | global randomLink1, randomLink2, randomLink3, numSwitches, numLinks |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame^] | 21 | |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 22 | def CASE1(self, main): |
| 23 | ''' |
| 24 | Startup sequence: |
| 25 | git pull |
| 26 | mvn clean install |
| 27 | onos-package |
| 28 | cell <name> |
| 29 | onos-verify-cell |
| 30 | onos-install -f |
| 31 | onos-wait-for-start |
| 32 | ''' |
| 33 | import time |
| 34 | cell_name = main.params['ENV']['cellName'] |
| 35 | git_pull = main.params['GIT']['autoPull'] |
| 36 | numCtrls = main.params['CTRL']['numCtrl'] |
| 37 | git_branch = main.params['GIT']['branch'] |
| 38 | |
| 39 | main.case("Set up test environment") |
| 40 | main.log.report("Set up test environment") |
| 41 | main.log.report("_______________________") |
| 42 | |
| 43 | main.step("Git checkout and pull "+git_branch) |
| 44 | if git_pull == 'on': |
| 45 | checkout_result = main.ONOSbench.git_checkout(git_branch) |
| 46 | pull_result = main.ONOSbench.git_pull() |
| 47 | cp_result = (checkout_result and pull_result) |
| 48 | else: |
| 49 | checkout_result = main.TRUE |
| 50 | pull_result = main.TRUE |
| 51 | main.log.info("Skipped git checkout and pull") |
| 52 | cp_result = (checkout_result and pull_result) |
| 53 | utilities.assert_equals(expect=main.TRUE, actual=cp_result, |
| 54 | onpass="Test step PASS", |
| 55 | onfail="Test step FAIL") |
| 56 | |
| 57 | main.step("mvn clean & install") |
| 58 | mvn_result = main.ONOSbench.clean_install() |
| 59 | utilities.assert_equals(expect=main.TRUE, actual=mvn_result, |
| 60 | onpass="Test step PASS", |
| 61 | onfail="Test step FAIL") |
| 62 | |
| 63 | main.ONOSbench.get_version(report=True) |
| 64 | |
| 65 | main.step("Apply Cell environment for ONOS") |
| 66 | cell_result = main.ONOSbench.set_cell(cell_name) |
| 67 | utilities.assert_equals(expect=main.TRUE, actual=cell_result, |
| 68 | onpass="Test step PASS", |
| 69 | onfail="Test step FAIL") |
| 70 | |
| 71 | main.step("Create ONOS package") |
| 72 | packageResult = main.ONOSbench.onos_package() |
| 73 | utilities.assert_equals(expect=main.TRUE, actual=packageResult, |
| 74 | onpass="Test step PASS", |
| 75 | onfail="Test step FAIL") |
| 76 | |
| 77 | main.step("Uninstall ONOS package on all Nodes") |
| 78 | uninstallResult=main.TRUE |
| 79 | for i in range(1,int(numCtrls)+1): |
| 80 | ONOS_ip = main.params['CTRL']['ip'+str(i)] |
| 81 | main.log.info("Unintsalling package on ONOS Node IP: "+ONOS_ip) |
| 82 | u_result= main.ONOSbench.onos_uninstall(ONOS_ip) |
| 83 | utilities.assert_equals(expect=main.TRUE, actual=u_result, |
| 84 | onpass="Test step PASS", |
| 85 | onfail="Test step FAIL") |
| 86 | uninstallResult=(uninstallResult and u_result) |
| 87 | |
| 88 | main.step("Removing copy-cat logs from ONOS nodes") |
| 89 | main.ONOSbench.onos_remove_raft_logs() |
| 90 | |
| 91 | main.step("Install ONOS package on all Nodes") |
| 92 | installResult=main.TRUE |
| 93 | for i in range(1,int(numCtrls)+1): |
| 94 | ONOS_ip = main.params['CTRL']['ip'+str(i)] |
| 95 | main.log.info("Intsalling package on ONOS Node IP: "+ONOS_ip) |
| 96 | i_result= main.ONOSbench.onos_install(node=ONOS_ip) |
| 97 | utilities.assert_equals(expect=main.TRUE, actual=i_result, |
| 98 | onpass="Test step PASS", |
| 99 | onfail="Test step FAIL") |
| 100 | installResult=(installResult and i_result) |
| 101 | |
| 102 | main.step("Verify ONOS nodes UP status") |
| 103 | statusResult=main.TRUE |
| 104 | for i in range(1,int(numCtrls)+1): |
| 105 | ONOS_ip = main.params['CTRL']['ip'+str(i)] |
| 106 | main.log.info("ONOS Node "+ONOS_ip+" status:") |
| 107 | onos_status = main.ONOSbench.onos_status(node=ONOS_ip) |
| 108 | utilities.assert_equals(expect=main.TRUE, actual=onos_status, |
| 109 | onpass="Test step PASS", |
| 110 | onfail="Test step FAIL") |
| 111 | statusResult=(statusResult and onos_status) |
| 112 | |
| 113 | main.step("Start ONOS CLI on all nodes") |
| 114 | cliResult = main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame^] | 115 | karafTimeout = "3600000" |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 116 | time.sleep(15) # need to wait here for sometime. This will be removed once ONOS is stable enough |
| 117 | for i in range(1,int(numCtrls)+1): |
| 118 | ONOS_ip = main.params['CTRL']['ip'+str(i)] |
| 119 | ONOScli = 'ONOScli'+str(i) |
| 120 | main.log.info("ONOS Node "+ONOS_ip+" cli start:") |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame^] | 121 | exec "startcli=main."+ONOScli+".start_onos_cli(ONOS_ip, karafTimeout=karafTimeout)" |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 122 | utilities.assert_equals(expect=main.TRUE, actual=startcli, |
| 123 | onpass="Test step PASS", |
| 124 | onfail="Test step FAIL") |
| 125 | cliResult = (cliResult and startcli) |
| 126 | |
| 127 | case1Result = (cp_result and cell_result |
| 128 | and packageResult and installResult and statusResult and cliResult) |
| 129 | utilities.assert_equals(expect=main.TRUE, actual=case1Result, |
| 130 | onpass="Set up test environment PASS", |
| 131 | onfail="Set up test environment FAIL") |
| 132 | |
| 133 | def CASE2(self, main): |
| 134 | ''' |
| 135 | This test script still needs more refactoring |
| 136 | ''' |
| 137 | import re |
| 138 | import time |
| 139 | import copy |
| 140 | numCtrls = main.params['CTRL']['numCtrl'] |
| 141 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 142 | ONOS2_ip = main.params['CTRL']['ip2'] |
| 143 | ONOS3_ip = main.params['CTRL']['ip3'] |
| 144 | ONOS4_ip = main.params['CTRL']['ip4'] |
| 145 | ONOS5_ip = main.params['CTRL']['ip5'] |
| 146 | ONOS1_port = main.params['CTRL']['port1'] |
| 147 | ONOS2_port = main.params['CTRL']['port2'] |
| 148 | ONOS3_port = main.params['CTRL']['port3'] |
| 149 | ONOS4_port = main.params['CTRL']['port4'] |
| 150 | ONOS5_port = main.params['CTRL']['port5'] |
| 151 | |
| 152 | numCtrls = main.params['CTRL']['numCtrl'] |
| 153 | main.log.report("Assign and Balance all Mininet switches across controllers") |
| 154 | main.log.report("_________________________________________________________") |
| 155 | time.sleep(15) # need to wait here for sometime. This will be removed once ONOS is stable enough |
| 156 | main.case("Assign and Balance all Mininet switches across controllers") |
| 157 | main.step("Assign switches to controllers") |
| 158 | for i in range(1,26): #1 to (num of switches +1) |
| 159 | main.Mininet1.assign_sw_controller(sw=str(i),count=int(numCtrls), |
| 160 | ip1=ONOS1_ip, port1=ONOS1_port, |
| 161 | ip2=ONOS2_ip, port2=ONOS2_port, |
| 162 | ip3=ONOS3_ip, port3=ONOS3_port, ip4=ONOS4_ip, port4=ONOS4_port, |
| 163 | ip5=ONOS5_ip, port5=ONOS5_port) |
| 164 | |
| 165 | switch_mastership = main.TRUE |
| 166 | for i in range (1,26): |
| 167 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 168 | print("Response is " + str(response)) |
| 169 | if re.search("tcp:"+ONOS1_ip,response): |
| 170 | switch_mastership = switch_mastership and main.TRUE |
| 171 | else: |
| 172 | switch_mastership = main.FALSE |
| 173 | |
| 174 | if switch_mastership == main.TRUE: |
| 175 | main.log.report("Controller assignment successfull") |
| 176 | else: |
| 177 | main.log.report("Controller assignment failed") |
| 178 | time.sleep(5) |
| 179 | |
| 180 | main.step("Balance devices across controllers") |
| 181 | for i in range(int(numCtrls)): |
| 182 | balanceResult = main.ONOScli1.balance_masters() |
| 183 | time.sleep(3) # giving some breathing time for ONOS to complete re-balance |
| 184 | |
| 185 | utilities.assert_equals(expect=main.TRUE, actual=balanceResult, |
| 186 | onpass="Assign and Balance devices test PASS", |
| 187 | onfail="Assign and Balance devices test FAIL") |
| 188 | |
| 189 | def CASE3(self,main) : |
| 190 | ''' |
| 191 | This Test case will be extended to collect and store more data related |
| 192 | ONOS state. |
| 193 | ''' |
| 194 | import re |
| 195 | import copy |
| 196 | deviceDPIDs = [] |
| 197 | hostMACs = [] |
| 198 | deviceLinks = [] |
| 199 | deviceActiveLinksCount = [] |
| 200 | devicePortsEnabledCount = [] |
| 201 | |
| 202 | main.log.report("Collect and Store topology details from ONOS before running any Tests") |
| 203 | main.log.report("____________________________________________________________________") |
| 204 | main.case ("Collect and Store Topology Deatils from ONOS") |
| 205 | |
| 206 | main.step("Collect and store current number of switches and links") |
| 207 | topology_output = main.ONOScli1.topology() |
| 208 | topology_result = main.ONOSbench.get_topology(topology_output) |
| 209 | numSwitches = topology_result['devices'] |
| 210 | numLinks = topology_result['links'] |
| 211 | main.log.info("Currently there are %s switches and %s links" %(str(numSwitches), str(numLinks))) |
| 212 | |
| 213 | main.step("Store Device DPIDs") |
| 214 | for i in range(1,26): |
| 215 | deviceDPIDs.append("of:00000000000000"+format(i, '02x')) |
| 216 | print "Device DPIDs in Store: \n", str(deviceDPIDs) |
| 217 | |
| 218 | main.step("Store Host MACs") |
| 219 | for i in range(1,26): |
| 220 | hostMACs.append("00:00:00:00:00:"+format(i, '02x')+"/-1") |
| 221 | print "Host MACs in Store: \n", str(hostMACs) |
| 222 | |
| 223 | main.step("Collect and store all Devices Links") |
| 224 | linksResult = main.ONOScli1.links(json_format=False) |
| 225 | ansi_escape = re.compile(r'\x1b[^m]*m') |
| 226 | linksResult = ansi_escape.sub('', linksResult) |
| 227 | linksResult = linksResult.replace(" links","").replace("\r\r","") |
| 228 | linksResult=linksResult.splitlines() |
| 229 | linksResult = linksResult[1:] |
| 230 | deviceLinks = copy.copy(linksResult) |
| 231 | print "Device Links Stored: \n", str(deviceLinks) |
| 232 | print "Length of Links Store", len(deviceLinks) # this will be asserted to check with the params provided count of links |
| 233 | |
| 234 | main.step("Collect and store each Device ports enabled Count") |
| 235 | for i in range(1,26): |
| 236 | portResult = main.ONOScli1.getDevicePortsEnabledCount("of:00000000000000"+format(i, '02x')) |
| 237 | portTemp = re.split(r'\t+', portResult) |
| 238 | portCount = portTemp[1].replace("\r\r\n\x1b[32m","") |
| 239 | devicePortsEnabledCount.append(portCount) |
| 240 | print "Device Enabled Port Counts Stored: \n", str(devicePortsEnabledCount) |
| 241 | |
| 242 | main.step("Collect and store each Device active links Count") |
| 243 | for i in range(1,26): |
| 244 | linkCountResult = main.ONOScli1.getDeviceLinksActiveCount("of:00000000000000"+format(i, '02x')) |
| 245 | linkCountTemp = re.split(r'\t+', linkCountResult) |
| 246 | linkCount = linkCountTemp[1].replace("\r\r\n\x1b[32m","") |
| 247 | deviceActiveLinksCount.append(linkCount) |
| 248 | print "Device Active Links Count Stored: \n", str(deviceActiveLinksCount) |
| 249 | |
| 250 | caseResult = main.TRUE # just returning TRUE for now as this one just collects data |
| 251 | utilities.assert_equals(expect=main.TRUE, actual=case1Result, |
| 252 | onpass="Saving ONOS topology data test PASS", |
| 253 | onfail="Saving ONOS topology data test FAIL") |
| 254 | |
| 255 | def CASE4(self,main) : |
| 256 | ''' |
| 257 | Enable onos-app-fwd, Verify Reactive forwarding through ping all and Disable it |
| 258 | ''' |
| 259 | import re |
| 260 | import copy |
| 261 | import time |
| 262 | numCtrls = main.params['CTRL']['numCtrl'] |
| 263 | main.log.report("Enable Reactive forwarding and Verify ping all") |
| 264 | main.log.report("______________________________________________") |
| 265 | main.case ("Enable Reactive forwarding and Verify ping all") |
| 266 | main.step("Enable Reactive forwarding") |
| 267 | installResult = main.TRUE |
| 268 | for i in range(1,int(numCtrls)+1): |
| 269 | onosFeature = 'onos-app-fwd' |
| 270 | ONOS_ip = main.params['CTRL']['ip'+str(i)] |
| 271 | ONOScli = 'ONOScli'+str(i) |
| 272 | main.log.info("Enabling Reactive mode on ONOS Node "+ONOS_ip) |
| 273 | exec "inResult=main."+ONOScli+".feature_install(onosFeature)" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame^] | 274 | time.sleep(3) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 275 | installResult = inResult and installResult |
| 276 | |
| 277 | time.sleep(5) |
| 278 | |
| 279 | main.step("Verify Pingall") |
| 280 | ping_result = main.FALSE |
| 281 | time1 = time.time() |
| 282 | ping_result = main.Mininet1.pingall() |
| 283 | time2 = time.time() |
| 284 | timeDiff = round((time2-time1),2) |
| 285 | main.log.report("Time taken for Ping All: "+str(timeDiff)+" seconds") |
| 286 | |
| 287 | if ping_result == main.TRUE: |
| 288 | main.log.report("Pingall Test in Reactive mode successful") |
| 289 | else: |
| 290 | main.log.report("Pingall Test in Reactive mode failed") |
| 291 | |
| 292 | main.step("Disable Reactive forwarding") |
| 293 | uninstallResult = main.TRUE |
| 294 | for i in range(1,int(numCtrls)+1): |
| 295 | onosFeature = 'onos-app-fwd' |
| 296 | ONOS_ip = main.params['CTRL']['ip'+str(i)] |
| 297 | ONOScli = 'ONOScli'+str(i) |
| 298 | main.log.info("Disabling Reactive mode on ONOS Node "+ONOS_ip) |
| 299 | exec "unResult=main."+ONOScli+".feature_uninstall(onosFeature)" |
| 300 | uninstallResult = unResult and uninstallResult |
| 301 | |
| 302 | #Waiting for reative flows to be cleared. |
| 303 | time.sleep(10) |
| 304 | |
| 305 | case3Result = installResult and ping_result and uninstallResult |
| 306 | utilities.assert_equals(expect=main.TRUE, actual=case3Result, |
| 307 | onpass="Reactive Mode Pingall test PASS", |
| 308 | onfail="Reactive Mode Pingall test FAIL") |
| 309 | |
| 310 | def CASE5(self,main) : |
| 311 | ''' |
| 312 | Compare current ONOS topology with reference data |
| 313 | ''' |
| 314 | import re |
| 315 | devicesDPID_tmp = [] |
| 316 | hostMACs_tmp = [] |
| 317 | deviceLinks_tmp = [] |
| 318 | deviceActiveLinksCount_tmp = [] |
| 319 | devicePortsEnabledCount_tmp = [] |
| 320 | |
| 321 | main.log.report("Compare ONOS topology with reference data in Stores") |
| 322 | main.log.report("__________________________________________________") |
| 323 | main.case ("Compare ONOS topology with reference data") |
| 324 | |
| 325 | main.step("Compare current Device ports enabled with reference") |
| 326 | for i in range(1,26): |
| 327 | portResult = main.ONOScli1.getDevicePortsEnabledCount("of:00000000000000"+format(i, '02x')) |
| 328 | portTemp = re.split(r'\t+', portResult) |
| 329 | portCount = portTemp[1].replace("\r\r\n\x1b[32m","") |
| 330 | devicePortsEnabledCount_tmp.append(portCount) |
| 331 | time.sleep(2) |
| 332 | print ("Device Enabled ports EXPECTED: \n"+ str(devicePortsEnabledCount)) |
| 333 | print ("Device Enabled ports ACTUAL: \n"+ str(devicePortsEnabledCount_tmp)) |
| 334 | if (cmp(devicePortsEnabledCount,devicePortsEnabledCount_tmp)==0): |
| 335 | stepResult1 = main.TRUE |
| 336 | else: |
| 337 | stepResult1 = main.FALSE |
| 338 | |
| 339 | main.step("Compare Device active links with reference") |
| 340 | for i in range(1,26): |
| 341 | linkResult = main.ONOScli1.getDeviceLinksActiveCount("of:00000000000000"+format(i, '02x')) |
| 342 | linkTemp = re.split(r'\t+', linkResult) |
| 343 | linkCount = linkTemp[1].replace("\r\r\n\x1b[32m","") |
| 344 | deviceActiveLinksCount_tmp.append(linkCount) |
| 345 | time.sleep(3) |
| 346 | print ("Device Active links EXPECTED: \n"+str(deviceActiveLinksCount)) |
| 347 | print ("Device Active links ACTUAL: \n"+str(deviceActiveLinksCount_tmp)) |
| 348 | if (cmp(deviceActiveLinksCount,deviceActiveLinksCount_tmp)==0): |
| 349 | stepResult2 = main.TRUE |
| 350 | else: |
| 351 | stepResult2 = main.FALSE |
| 352 | |
| 353 | ''' |
| 354 | place holder for comparing devices, hosts and paths if required. |
| 355 | Links and ports data would be incorrect with out devices anyways. |
| 356 | ''' |
| 357 | |
| 358 | caseResult=(stepResult1 and stepResult2) |
| 359 | utilities.assert_equals(expect=main.TRUE, actual=case1Result, |
| 360 | onpass="Compare Topology test PASS", |
| 361 | onfail="Compare Topology test FAIL") |
| 362 | if caseResult == main.TRUE: |
| 363 | main.log.report("Compare Topology test Pass") |
| 364 | |
| 365 | def CASE6(self): |
| 366 | ''' |
| 367 | Install 300 host intents and verify ping all |
| 368 | ''' |
| 369 | main.log.report("Add 300 host intents and verify pingall") |
| 370 | main.log.report("_______________________________________") |
| 371 | import itertools |
| 372 | main.case("Install 300 host intents") |
| 373 | main.step("Add host Intents") |
| 374 | intentResult=main.TRUE |
| 375 | hostCombos = list(itertools.combinations(hostMACs, 2)) |
| 376 | for i in range(len(hostCombos)): |
| 377 | iResult = main.ONOScli1.add_host_intent(hostCombos[i][0],hostCombos[i][1]) |
| 378 | intentResult=(intentResult and iResult) |
| 379 | |
| 380 | main.step("Verify Ping across all hosts") |
| 381 | pingResult = main.FALSE |
| 382 | time1 = time.time() |
| 383 | pingResult = main.Mininet1.pingall() |
| 384 | time2 = time.time() |
| 385 | timeDiff = round((time2-time1),2) |
| 386 | main.log.report("Time taken for Ping All: "+str(timeDiff)+" seconds") |
| 387 | utilities.assert_equals(expect=main.TRUE, actual=pingResult, |
| 388 | onpass="PING ALL PASS", |
| 389 | onfail="PING ALL FAIL") |
| 390 | |
| 391 | case4Result=(intentResult and pingResult) |
| 392 | utilities.assert_equals(expect=main.TRUE, actual=case4Result, |
| 393 | onpass="Install 300 Host Intents and Ping All test PASS", |
| 394 | onfail="Install 300 Host Intents and Ping All test FAIL") |
| 395 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame^] | 396 | def CASE70(self,main): |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 397 | ''' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame^] | 398 | Randomly bring some core links down and verify ping all (Host Intents Scenario) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 399 | ''' |
| 400 | import random |
| 401 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 402 | link1End1 = main.params['CORELINKS']['linkS3a'] |
| 403 | link1End2 = main.params['CORELINKS']['linkS3b'].split(',') |
| 404 | link2End1 = main.params['CORELINKS']['linkS14a'] |
| 405 | link2End2 = main.params['CORELINKS']['linkS14b'].split(',') |
| 406 | link3End1 = main.params['CORELINKS']['linkS18a'] |
| 407 | link3End2 = main.params['CORELINKS']['linkS18b'].split(',') |
| 408 | switchLinksToToggle = main.params['CORELINKS']['toggleLinks'] |
| 409 | link_sleep = int(main.params['timers']['LinkDiscovery']) |
| 410 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame^] | 411 | main.log.report("Host intents - Randomly bring some core links down and verify ping all") |
| 412 | main.log.report("_________________________________________________________________") |
| 413 | main.case("Host intents - Randomly bring some core links down and verify ping all") |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 414 | main.step("Verify number of Switch links to toggle on each Core Switch are between 1 - 5") |
| 415 | if (int(switchLinksToToggle) == 0 or int(switchLinksToToggle) > 5): |
| 416 | main.log.info("Please check you PARAMS file. Valid range for number of switch links to toggle is between 1 to 5") |
| 417 | main.cleanup() |
| 418 | main.exit() |
| 419 | else: |
| 420 | main.log.info("User provided Core switch links range to toggle is correct, proceeding to run the test") |
| 421 | |
| 422 | main.step("Cut links on Core devices using user provided range") |
| 423 | randomLink1 = random.sample(link1End2,int(switchLinksToToggle)) |
| 424 | randomLink2 = random.sample(link2End2,int(switchLinksToToggle)) |
| 425 | randomLink3 = random.sample(link3End2,int(switchLinksToToggle)) |
| 426 | for i in range(int(switchLinksToToggle)): |
| 427 | main.Mininet1.link(END1=link1End1,END2=randomLink1[i],OPTION="down") |
| 428 | main.Mininet1.link(END1=link2End1,END2=randomLink2[i],OPTION="down") |
| 429 | main.Mininet1.link(END1=link3End1,END2=randomLink3[i],OPTION="down") |
| 430 | time.sleep(link_sleep) |
| 431 | |
| 432 | topology_output = main.ONOScli2.topology() |
| 433 | linkDown = main.ONOSbench.check_status(topology_output,numSwitches,str(int(numLinks)-int(switchLinksToToggle)*6)) |
| 434 | utilities.assert_equals(expect=main.TRUE,actual=linkDown, |
| 435 | onpass="Link Down discovered properly", |
| 436 | onfail="Link down was not discovered in "+ str(link_sleep) + " seconds") |
| 437 | |
| 438 | main.step("Verify Ping across all hosts") |
| 439 | pingResultLinkDown = main.FALSE |
| 440 | time1 = time.time() |
| 441 | pingResultLinkDown = main.Mininet1.pingall() |
| 442 | time2 = time.time() |
| 443 | timeDiff = round((time2-time1),2) |
| 444 | main.log.report("Time taken for Ping All: "+str(timeDiff)+" seconds") |
| 445 | utilities.assert_equals(expect=main.TRUE, actual=pingResultLinkDown, |
| 446 | onpass="PING ALL PASS", |
| 447 | onfail="PING ALL FAIL") |
| 448 | |
| 449 | caseResult7 = linkDown and pingResultLinkDown |
| 450 | utilities.assert_equals(expect=main.TRUE, actual=caseResult7, |
| 451 | onpass="Random Link cut Test PASS", |
| 452 | onfail="Random Link cut Test FAIL") |
| 453 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame^] | 454 | def CASE80(self,main): |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 455 | ''' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame^] | 456 | Bring the core links up that are down and verify ping all (Host Intents Scenario) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 457 | ''' |
| 458 | import random |
| 459 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 460 | link1End1 = main.params['CORELINKS']['linkS3a'] |
| 461 | link2End1 = main.params['CORELINKS']['linkS14a'] |
| 462 | link3End1 = main.params['CORELINKS']['linkS18a'] |
| 463 | link_sleep = int(main.params['timers']['LinkDiscovery']) |
| 464 | switchLinksToToggle = main.params['CORELINKS']['toggleLinks'] |
| 465 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame^] | 466 | main.log.report("Host intents - Bring the core links up that are down and verify ping all") |
| 467 | main.log.report("__________________________________________________________________") |
| 468 | main.case("Host intents - Bring the core links up that are down and verify ping all") |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 469 | main.step("Bring randomly cut links on Core devices up") |
| 470 | for i in range(int(switchLinksToToggle)): |
| 471 | main.Mininet1.link(END1=link1End1,END2=randomLink1[i],OPTION="up") |
| 472 | main.Mininet1.link(END1=link2End1,END2=randomLink2[i],OPTION="up") |
| 473 | main.Mininet1.link(END1=link3End1,END2=randomLink3[i],OPTION="up") |
| 474 | time.sleep(link_sleep) |
| 475 | |
| 476 | topology_output = main.ONOScli2.topology() |
| 477 | linkUp = main.ONOSbench.check_status(topology_output,numSwitches,str(numLinks)) |
| 478 | utilities.assert_equals(expect=main.TRUE,actual=linkUp, |
| 479 | onpass="Link up discovered properly", |
| 480 | onfail="Link up was not discovered in "+ str(link_sleep) + " seconds") |
| 481 | |
| 482 | main.step("Verify Ping across all hosts") |
| 483 | pingResultLinkUp = main.FALSE |
| 484 | time1 = time.time() |
| 485 | pingResultLinkUp = main.Mininet1.pingall() |
| 486 | time2 = time.time() |
| 487 | timeDiff = round((time2-time1),2) |
| 488 | main.log.report("Time taken for Ping All: "+str(timeDiff)+" seconds") |
| 489 | utilities.assert_equals(expect=main.TRUE, actual=pingResultLinkUp, |
| 490 | onpass="PING ALL PASS", |
| 491 | onfail="PING ALL FAIL") |
| 492 | |
| 493 | caseResult8 = linkUp and pingResultLinkUp |
| 494 | utilities.assert_equals(expect=main.TRUE, actual=caseResult8, |
| 495 | onpass="Link Up Test PASS", |
| 496 | onfail="Link Up Test FAIL") |
| 497 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame^] | 498 | def CASE71(self,main): |
| 499 | ''' |
| 500 | Randomly bring some core links down and verify ping all (Point Intents Scenario) |
| 501 | ''' |
| 502 | import random |
| 503 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 504 | link1End1 = main.params['CORELINKS']['linkS3a'] |
| 505 | link1End2 = main.params['CORELINKS']['linkS3b'].split(',') |
| 506 | link2End1 = main.params['CORELINKS']['linkS14a'] |
| 507 | link2End2 = main.params['CORELINKS']['linkS14b'].split(',') |
| 508 | link3End1 = main.params['CORELINKS']['linkS18a'] |
| 509 | link3End2 = main.params['CORELINKS']['linkS18b'].split(',') |
| 510 | switchLinksToToggle = main.params['CORELINKS']['toggleLinks'] |
| 511 | link_sleep = int(main.params['timers']['LinkDiscovery']) |
| 512 | |
| 513 | main.log.report("Point Intents - Randomly bring some core links down and verify ping all") |
| 514 | main.log.report("__________________________________________________________________") |
| 515 | main.case("Point Intents - Randomly bring some core links down and verify ping all") |
| 516 | main.step("Verify number of Switch links to toggle on each Core Switch are between 1 - 5") |
| 517 | if (int(switchLinksToToggle) == 0 or int(switchLinksToToggle) > 5): |
| 518 | main.log.info("Please check you PARAMS file. Valid range for number of switch links to toggle is between 1 to 5") |
| 519 | main.cleanup() |
| 520 | main.exit() |
| 521 | else: |
| 522 | main.log.info("User provided Core switch links range to toggle is correct, proceeding to run the test") |
| 523 | |
| 524 | main.step("Cut links on Core devices using user provided range") |
| 525 | randomLink1 = random.sample(link1End2,int(switchLinksToToggle)) |
| 526 | randomLink2 = random.sample(link2End2,int(switchLinksToToggle)) |
| 527 | randomLink3 = random.sample(link3End2,int(switchLinksToToggle)) |
| 528 | for i in range(int(switchLinksToToggle)): |
| 529 | main.Mininet1.link(END1=link1End1,END2=randomLink1[i],OPTION="down") |
| 530 | main.Mininet1.link(END1=link2End1,END2=randomLink2[i],OPTION="down") |
| 531 | main.Mininet1.link(END1=link3End1,END2=randomLink3[i],OPTION="down") |
| 532 | time.sleep(link_sleep) |
| 533 | |
| 534 | topology_output = main.ONOScli2.topology() |
| 535 | linkDown = main.ONOSbench.check_status(topology_output,numSwitches,str(int(numLinks)-int(switchLinksToToggle)*6)) |
| 536 | utilities.assert_equals(expect=main.TRUE,actual=linkDown, |
| 537 | onpass="Link Down discovered properly", |
| 538 | onfail="Link down was not discovered in "+ str(link_sleep) + " seconds") |
| 539 | |
| 540 | main.step("Verify Ping across all hosts") |
| 541 | pingResultLinkDown = main.FALSE |
| 542 | time1 = time.time() |
| 543 | pingResultLinkDown = main.Mininet1.pingall() |
| 544 | time2 = time.time() |
| 545 | timeDiff = round((time2-time1),2) |
| 546 | main.log.report("Time taken for Ping All: "+str(timeDiff)+" seconds") |
| 547 | utilities.assert_equals(expect=main.TRUE, actual=pingResultLinkDown, |
| 548 | onpass="PING ALL PASS", |
| 549 | onfail="PING ALL FAIL") |
| 550 | |
| 551 | caseResult7 = linkDown and pingResultLinkDown |
| 552 | utilities.assert_equals(expect=main.TRUE, actual=caseResult7, |
| 553 | onpass="Random Link cut Test PASS", |
| 554 | onfail="Random Link cut Test FAIL") |
| 555 | |
| 556 | def CASE81(self,main): |
| 557 | ''' |
| 558 | Bring the core links up that are down and verify ping all (Point Intents Scenario) |
| 559 | ''' |
| 560 | import random |
| 561 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 562 | link1End1 = main.params['CORELINKS']['linkS3a'] |
| 563 | link2End1 = main.params['CORELINKS']['linkS14a'] |
| 564 | link3End1 = main.params['CORELINKS']['linkS18a'] |
| 565 | link_sleep = int(main.params['timers']['LinkDiscovery']) |
| 566 | switchLinksToToggle = main.params['CORELINKS']['toggleLinks'] |
| 567 | |
| 568 | main.log.report("Point intents - Bring the core links up that are down and verify ping all") |
| 569 | main.log.report("___________________________________________________________________") |
| 570 | main.case("Point intents - Bring the core links up that are down and verify ping all") |
| 571 | main.step("Bring randomly cut links on Core devices up") |
| 572 | for i in range(int(switchLinksToToggle)): |
| 573 | main.Mininet1.link(END1=link1End1,END2=randomLink1[i],OPTION="up") |
| 574 | main.Mininet1.link(END1=link2End1,END2=randomLink2[i],OPTION="up") |
| 575 | main.Mininet1.link(END1=link3End1,END2=randomLink3[i],OPTION="up") |
| 576 | time.sleep(link_sleep) |
| 577 | |
| 578 | topology_output = main.ONOScli2.topology() |
| 579 | linkUp = main.ONOSbench.check_status(topology_output,numSwitches,str(numLinks)) |
| 580 | utilities.assert_equals(expect=main.TRUE,actual=linkUp, |
| 581 | onpass="Link up discovered properly", |
| 582 | onfail="Link up was not discovered in "+ str(link_sleep) + " seconds") |
| 583 | |
| 584 | main.step("Verify Ping across all hosts") |
| 585 | pingResultLinkUp = main.FALSE |
| 586 | time1 = time.time() |
| 587 | pingResultLinkUp = main.Mininet1.pingall() |
| 588 | time2 = time.time() |
| 589 | timeDiff = round((time2-time1),2) |
| 590 | main.log.report("Time taken for Ping All: "+str(timeDiff)+" seconds") |
| 591 | utilities.assert_equals(expect=main.TRUE, actual=pingResultLinkUp, |
| 592 | onpass="PING ALL PASS", |
| 593 | onfail="PING ALL FAIL") |
| 594 | |
| 595 | caseResult8 = linkUp and pingResultLinkUp |
| 596 | utilities.assert_equals(expect=main.TRUE, actual=caseResult8, |
| 597 | onpass="Link Up Test PASS", |
| 598 | onfail="Link Up Test FAIL") |
| 599 | |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 600 | def CASE9(self): |
| 601 | ''' |
| 602 | Install 114 point intents and verify Ping all works |
| 603 | ''' |
| 604 | import copy |
| 605 | main.log.report("Install 114 point intents and verify Ping all") |
| 606 | main.log.report("___________________________________________") |
| 607 | main.case("Install 114 point intents and Ping all") |
| 608 | deviceLinks_copy = copy.copy(deviceLinks) |
| 609 | main.step("Install 114 point intents") |
| 610 | for i in range(len(deviceLinks_copy)): |
| 611 | pointLink = str(deviceLinks_copy[i]).replace("src=","").replace("dst=","").split(',') |
| 612 | point1 = pointLink[0].split('/') |
| 613 | point2 = pointLink[1].split('/') |
| 614 | installResult = main.ONOScli1.add_point_intent(point1[0],point2[0],int(point1[1]),int(point2[1])) |
| 615 | if installResult == main.TRUE: |
| 616 | print "Installed Point intent between :",point1[0], int(point1[1]), point2[0], int(point2[1]) |
| 617 | |
| 618 | main.step("Obtain the intent id's") |
| 619 | intentsList = main.ONOScli1.getAllIntentIds() |
| 620 | ansi_escape = re.compile(r'\x1b[^m]*m') |
| 621 | intentsList = ansi_escape.sub('', intentsList) |
| 622 | intentsList = intentsList.replace(" onos:intents | grep id=","").replace("id=","").replace("\r\r","") |
| 623 | intentsList=intentsList.splitlines() |
| 624 | intentsList = intentsList[1:] |
| 625 | intentIdList = [] |
| 626 | for i in range(len(intentsList)): |
| 627 | intentsTemp = intentsList[i].split(',') |
| 628 | intentIdList.append(intentsTemp[0]) |
| 629 | print "Intent IDs: ", intentIdList |
| 630 | print "Total Intents installed: ", len(intentIdList) |
| 631 | |
| 632 | main.step("Verify Ping across all hosts") |
| 633 | pingResult = main.FALSE |
| 634 | time1 = time.time() |
| 635 | pingResult = main.Mininet1.pingall() |
| 636 | time2 = time.time() |
| 637 | timeDiff = round((time2-time1),2) |
| 638 | main.log.report("Time taken for Ping All: "+str(timeDiff)+" seconds") |
| 639 | utilities.assert_equals(expect=main.TRUE, actual=pingResult, |
| 640 | onpass="PING ALL PASS", |
| 641 | onfail="PING ALL FAIL") |
| 642 | |
| 643 | case8_result = installResult and pingResult |
| 644 | utilities.assert_equals(expect=main.TRUE, actual=case8_result, |
| 645 | onpass="Ping all test after Point intents addition successful", |
| 646 | onfail="Ping all test after Point intents addition failed") |
| 647 | |
| 648 | def CASE10(self): |
| 649 | ''' |
| 650 | Remove all Intents |
| 651 | ''' |
| 652 | main.log.report("Remove all intents that were installed previously") |
| 653 | main.log.report("______________________________________________") |
| 654 | main.log.info("Remove all intents") |
| 655 | main.case("Removing intents") |
| 656 | main.step("Obtain the intent id's first") |
| 657 | intentsList = main.ONOScli1.getAllIntentIds() |
| 658 | ansi_escape = re.compile(r'\x1b[^m]*m') |
| 659 | intentsList = ansi_escape.sub('', intentsList) |
| 660 | intentsList = intentsList.replace(" onos:intents | grep id=","").replace("id=","").replace("\r\r","") |
| 661 | intentsList=intentsList.splitlines() |
| 662 | intentsList = intentsList[1:] |
| 663 | intentIdList = [] |
| 664 | step1Result = main.TRUE |
| 665 | if (len(intentsList) > 1): |
| 666 | for i in range(len(intentsList)): |
| 667 | intentsTemp = intentsList[i].split(',') |
| 668 | intentIdList.append(intentsTemp[0]) |
| 669 | print "Intent IDs: ", intentIdList |
| 670 | for id in range(len(intentIdList)): |
| 671 | print "Removing intent id (round 1) :", intentIdList[id] |
| 672 | main.ONOScli1.remove_intent(intent_id = intentIdList[id]) |
| 673 | time.sleep(1) |
| 674 | |
| 675 | main.log.info("Verify all intents are removed and if any leftovers try remove one more time") |
| 676 | intentsList1 = main.ONOScli1.getAllIntentIds() |
| 677 | ansi_escape = re.compile(r'\x1b[^m]*m') |
| 678 | intentsList1 = ansi_escape.sub('', intentsList1) |
| 679 | intentsList1 = intentsList1.replace(" onos:intents | grep id=","").replace(" state=","").replace("\r\r","") |
| 680 | intentsList1=intentsList1.splitlines() |
| 681 | intentsList1 = intentsList1[1:] |
| 682 | print "Round 2 (leftover) intents to remove: ", intentsList1 |
| 683 | intentIdList1 = [] |
| 684 | if (len(intentsList1) > 1): |
| 685 | for i in range(len(intentsList1)): |
| 686 | intentsTemp1 = intentsList[i].split(',') |
| 687 | intentIdList1.append(intentsTemp1[0]) |
| 688 | print "Leftover Intent IDs: ", intentIdList1 |
| 689 | for id in range(len(intentIdList1)): |
| 690 | print "Removing intent id (round 2):", intentIdList1[id] |
| 691 | main.ONOScli1.remove_intent(intent_id = intentIdList1[id]) |
| 692 | time.sleep(2) |
| 693 | else: |
| 694 | print "There are no more intents that need to be removed" |
| 695 | step1Result = main.TRUE |
| 696 | else: |
| 697 | print "No Intent IDs found in Intents list: ", intentsList |
| 698 | step1Result = main.FALSE |
| 699 | |
| 700 | caseResult7 = step1Result |
| 701 | utilities.assert_equals(expect=main.TRUE, actual=caseResult7, |
| 702 | onpass="Intent removal test successful", |
| 703 | onfail="Intent removal test failed") |