Andrew | 809df1c | 2014-06-27 14:28:53 -0700 | [diff] [blame] | 1 | |
| 2 | class RCOnosSanity : |
| 3 | |
| 4 | def __init__(self) : |
| 5 | self.default = '' |
| 6 | |
| 7 | #***************************************************************************************************************************************************************************************** |
| 8 | #Test startup |
| 9 | #Tests the startup of Zookeeper1, RamCloud1, and ONOS1 to be certain that all started up successfully |
| 10 | def CASE1(self,main) : #Check to be sure ZK, Cass, and ONOS are up, then get ONOS version |
| 11 | import time |
| 12 | main.ONOS.start() |
| 13 | time.sleep(20) |
Andrew | 04677bd | 2014-07-01 14:31:01 -0700 | [diff] [blame] | 14 | main.ONOS.rest_stop() |
Andrew | 809df1c | 2014-06-27 14:28:53 -0700 | [diff] [blame] | 15 | main.ONOS.start_rest() |
| 16 | test= main.ONOS.rest_status() |
| 17 | if test == main.FALSE: |
| 18 | main.ONOS.start_rest() |
| 19 | main.ONOS.get_version() |
| 20 | main.log.report("Started Zookeeper, RamCloud, and ONOS") |
| 21 | main.case("Checking if the startup was clean...") |
| 22 | main.step("Testing Zookeeper Status") |
| 23 | data = main.ONOS.zk_status() |
| 24 | utilities.assert_equals(expect=main.TRUE,actual=data,onpass="Zookeeper is up!",onfail="Zookeeper is down...") |
| 25 | main.step("Testing Ramcloud Coord Status") |
| 26 | data = main.ONOS.rcc_status() |
| 27 | utilities.assert_equals(expect=main.TRUE,actual=data,onpass="Ramcloud Coord is up!",onfail="Ramcloud Coord is down...") |
| 28 | main.step("Testing Ramcloud Server Status") |
| 29 | data = main.ONOS.rcs_status() |
| 30 | utilities.assert_equals(expect=main.TRUE,actual=data,onpass="Ramcloud Server is up!",onfail="Ramcloud Server is down...") |
| 31 | main.step("Testing ONOS Status") |
| 32 | data = main.ONOS.status() |
| 33 | utilities.assert_equals(expect=main.TRUE,actual=data,onpass="ONOS is up!",onfail="ONOS is down...") |
| 34 | main.step("Testing Rest Status") |
| 35 | data = main.ONOS.rest_status() |
| 36 | utilities.assert_equals(expect=main.TRUE,actual=data,onpass="REST is up!",onfail="REST is down...") |
| 37 | |
| 38 | #********************************************************************************************************************************************************************************************** |
| 39 | #Assign Controllers |
| 40 | #This test first checks the ip of a mininet host, to be certain that the mininet exists(Host is defined #inParams as <CASE1><destination>). |
| 41 | #Then the program assignes each ONOS instance a single controller to a switch(To be the initial master), then #assigns all controllers. |
| 42 | |
| 43 | def CASE2(self,main) : #Make sure mininet exists, then assign controllers to switches |
| 44 | import time |
| 45 | main.log.report("Check if mininet started properly, then assign controllers ONOS 1,2,3 and 4") |
| 46 | main.case("Checking if one MN host exists") |
| 47 | main.step("Host IP Checking using checkIP") |
| 48 | result = main.Mininet.checkIP(main.params['CASE1']['destination']) |
| 49 | main.step("Verifying the result") |
| 50 | utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Host IP address configured",onfail="Host IP address not configured") |
| 51 | main.step("assigning ONOS controller to switches") |
| 52 | for i in range(25): |
| 53 | if i < 15: |
| 54 | j=i+1 |
| 55 | main.Mininet.assign_sw_controller(sw=str(j),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1']) |
| 56 | else: |
| 57 | j=i+16 |
| 58 | main.Mininet.assign_sw_controller(sw=str(j),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1']) |
Andrew | 04677bd | 2014-07-01 14:31:01 -0700 | [diff] [blame] | 59 | #time.sleep(1) |
Andrew | 809df1c | 2014-06-27 14:28:53 -0700 | [diff] [blame] | 60 | main.Mininet.get_sw_controller("s1") |
| 61 | |
| 62 | # ********************************************************************************************************************************************************************************************** |
| 63 | #Add Flows |
| 64 | #Deletes any remnant flows from any previous test, add flows from the file labeled <FLOWDEF>, then runs the #check flow test |
| 65 | |
| 66 | def CASE3(self,main) : #Delete any remnant flows, then add flows, and time how long it takes flow tables to update |
| 67 | main.log.report("Delete any flows from previous tests, then add flows from FLOWDEF file, then wait for switch flow tables to update") |
| 68 | import time |
| 69 | main.case("Taking care of these flows!") |
| 70 | main.step("Cleaning out any leftover flows...") |
| 71 | main.ONOS.delete_flow(main.params['INTENTS']['rem'], main.params['FLOWDEF']) |
| 72 | strtTime = time.time() |
| 73 | main.ONOS.add_flow(main.params['INTENTS']['add'], main.params['FLOWDEF']) |
| 74 | main.case("Checking flows") |
| 75 | |
| 76 | count = 1 |
| 77 | i = 6 |
| 78 | while i < 16 : |
| 79 | main.log.info("\n\t\t\t\th"+str(i)+" IS PINGING h"+str(i+25) ) |
| 80 | ping = main.Mininet.pingHost(SRC="h"+str(i),TARGET="h"+str(i+25)) |
| 81 | if ping == main.FALSE and count < 9: |
| 82 | count = count + 1 |
| 83 | i = 6 |
| 84 | main.log.info("Ping failed, making attempt number "+str(count)+" in 2 seconds") |
| 85 | time.sleep(2) |
| 86 | elif ping == main.FALSE and count ==9: |
| 87 | main.log.error("Ping test failed") |
| 88 | i = 17 |
| 89 | result = main.FALSE |
| 90 | elif ping == main.TRUE: |
| 91 | i = i + 1 |
| 92 | result = main.TRUE |
| 93 | endTime = time.time() |
| 94 | if result == main.TRUE: |
| 95 | main.log.report("\tTime to add flows: "+str(round(endTime-strtTime,2))+" seconds") |
| 96 | else: |
| 97 | main.log.report("\tFlows failed check") |
| 98 | |
| 99 | result2 = main.ONOS.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links']) |
| 100 | main.step("Verifying the result") |
| 101 | utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Flow check PASS",onfail="Flow check FAIL") |
| 102 | |
| 103 | #************************************************************************************* |
| 104 | #************************************************************************************** |
| 105 | #******************* |
| 106 | #This test case removes Controllers 2,3, and 4 then performs a ping test. |
| 107 | #The assign controller is used because the ovs-vsctl module deletes all current controllers when a new #controller is #assigned. |
| 108 | #The ping test performs single pings on hosts from opposite sides of the topology. If |
| 109 | #one ping fails, the test waits 5 seconds before trying again. |
| 110 | #If the ping test fails 6 times, then the test case will return false |
| 111 | def CASE41(self,main) : |
| 112 | main.log.report("Testing Removal") |
| 113 | strtTime = time.time() |
| 114 | result = main.ONOS.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links']) |
| 115 | for i in range(10): |
| 116 | if result == main.FALSE: |
| 117 | time.sleep(5) |
| 118 | result = main.ONOS.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links']) |
| 119 | else: |
| 120 | break |
| 121 | |
| 122 | count = 1 |
| 123 | i = 6 |
| 124 | while i < 16 : |
| 125 | main.log.info("\n\t\t\t\th"+str(i)+" IS PINGING h"+str(i+25) ) |
| 126 | ping = main.Mininet.pingHost(src="h"+str(i),target="h"+str(i+25)) |
| 127 | if ping == main.FALSE and count < 6: |
| 128 | count = count + 1 |
| 129 | i = 6 |
| 130 | main.log.info("Ping failed, making attempt number "+str(count)+" in 2 seconds") |
| 131 | time.sleep(2) |
| 132 | elif ping == main.FALSE and count ==6: |
| 133 | main.log.error("Ping test failed") |
| 134 | i = 17 |
| 135 | result = main.FALSE |
| 136 | elif ping == main.TRUE: |
| 137 | i = i + 1 |
| 138 | result = main.TRUE |
| 139 | endTime = time.time() |
| 140 | if result == main.TRUE: |
| 141 | main.log.report("\tTime to complete ping test: "+str(round(endTime-strtTime,2))+" seconds") |
| 142 | else: |
| 143 | main.log.report("\tPING TEST FAIL") |
| 144 | utilities.assert_equals(expect=main.TRUE,actual=result,onpass="NO PACKET LOSS,HOST IS REACHABLE",onfail="PACKET LOST, HOST IS NOT REACHABLE") |
| 145 | time.sleep(10) |
| 146 | |
| 147 | ##########***************************************************** |
| 148 | def CASE4(self,main) : |
| 149 | main.log.report("Remove ONOS 2,3,4 then ping until all hosts are reachable or fail after 6 attempts") |
| 150 | import time |
| 151 | for i in range(25): |
| 152 | if i < 15: |
| 153 | j=i+1 |
| 154 | main.Mininet.assign_sw_controller(sw=str(j),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1']) |
| 155 | else: |
| 156 | j=i+16 |
| 157 | main.Mininet.assign_sw_controller(sw=str(j),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1']) |
| 158 | strtTime = time.time() |
| 159 | result = main.ONOS.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links']) |
| 160 | for i in range(10): |
| 161 | if result == main.FALSE: |
| 162 | time.sleep(5) |
| 163 | result = main.ONOS.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links']) |
| 164 | else: |
| 165 | break |
| 166 | count = 1 |
| 167 | i = 6 |
| 168 | while i < 16 : |
| 169 | main.log.info("\n\t\t\t\th"+str(i)+" IS PINGING h"+str(i+25) ) |
| 170 | ping = main.Mininet.pingHost(src="h"+str(i),target="h"+str(i+25)) |
| 171 | if ping == main.FALSE and count < 6: |
| 172 | count = count + 1 |
| 173 | i = 6 |
| 174 | main.log.info("Ping failed, making attempt number "+str(count)+" in 2 seconds") |
| 175 | time.sleep(2) |
| 176 | elif ping == main.FALSE and count ==6: |
| 177 | main.log.error("Ping test failed") |
| 178 | i = 17 |
| 179 | result = main.FALSE |
| 180 | elif ping == main.TRUE: |
| 181 | i = i + 1 |
| 182 | result = main.TRUE |
| 183 | endTime = time.time() |
| 184 | if result == main.TRUE: |
| 185 | main.log.report("\tTime to complete ping test: "+str(round(endTime-strtTime,2))+" seconds") |
| 186 | else: |
| 187 | main.log.report("\tPING TEST FAIL") |
| 188 | utilities.assert_equals(expect=main.TRUE,actual=result,onpass="NO PACKET LOSS, HOST IS REACHABLE",onfail="PACKET LOST, HOST IS NOT REACHABLE") |
| 189 | time.sleep(10) |
| 190 | |
| 191 | # ********************************************************************************************************************************************************************************************** |
| 192 | #This test case restores the controllers removed by Case 4 then performs a ping test. |
| 193 | |
| 194 | def CASE5(self,main) : |
| 195 | main.log.report("Restore ONOS 2,3,4 then ping until all hosts are reachable or fail after 6 attempts") |
| 196 | import time |
| 197 | for i in range(25): |
| 198 | if i < 15: |
| 199 | j=i+1 |
| 200 | main.Mininet.assign_sw_controller(sw=str(j),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1']) |
| 201 | else: |
| 202 | j=i+16 |
| 203 | main.Mininet.assign_sw_controller(sw=str(j),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1']) |
| 204 | strtTime = time.time() |
| 205 | result = main.ONOS.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links']) |
| 206 | for i in range(2): |
| 207 | if result == main.FALSE: |
| 208 | time.sleep(5) |
| 209 | result = main.ONOS.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links']) |
| 210 | else: |
| 211 | break |
| 212 | count = 1 |
| 213 | i = 6 |
| 214 | while i < 16 : |
| 215 | main.log.info("\n\t\t\t\th"+str(i)+" IS PINGING h"+str(i+25) ) |
| 216 | ping = main.Mininet.pingHost(src="h"+str(i),target="h"+str(i+25)) |
| 217 | if ping == main.FALSE and count < 6: |
| 218 | count = count + 1 |
| 219 | i = 6 |
| 220 | main.log.info("Ping failed, making attempt number "+str(count)+" in 2 seconds") |
| 221 | time.sleep(2) |
| 222 | elif ping == main.FALSE and count ==6: |
| 223 | main.log.error("Ping test failed") |
| 224 | i = 17 |
| 225 | result = main.FALSE |
| 226 | elif ping == main.TRUE: |
| 227 | i = i + 1 |
| 228 | result = main.TRUE |
| 229 | endTime = time.time() |
| 230 | if result == main.TRUE: |
| 231 | main.log.report("\tTime to complete ping test: "+str(round(endTime-strtTime,2))+" seconds") |
| 232 | else: |
| 233 | main.log.report("\tPING TEST FAILED") |
| 234 | utilities.assert_equals(expect=main.TRUE,actual=result,onpass="NO PACKET LOSS, HOST IS REACHABLE",onfail="PACKET LOST, HOST IS NOT REACHABLE") |
| 235 | # #********************************************************************************************************************************************************************************************** |
| 236 | #Brings a link that all flows pass through in the mininet down, then runs a ping test to view reroute time |
| 237 | |
| 238 | def CASE6(self,main) : |
| 239 | main.log.report("Bring Link between s1 and s2 down, then ping until all hosts are reachable or fail after 10 attempts") |
| 240 | import time |
| 241 | main.case("Bringing Link down... ") |
| 242 | result = main.Mininet.link(END1=main.params['LINK']['begin'],END2=main.params['LINK']['end'],OPTION="down") |
| 243 | utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Link DOWN!",onfail="Link not brought down...") |
| 244 | |
| 245 | strtTime = time.time() |
| 246 | result = main.ONOS.check_status_report(main.params['RestIP'],main.params['NR_Switches'],str(int(main.params['NR_Links'])-2)) |
| 247 | for i in range(2): |
| 248 | if result == main.FALSE: |
| 249 | time.sleep(5) |
| 250 | result = main.ONOS.check_status_report(main.params['RestIP'],main.params['NR_Switches'],str(int(main.params['NR_Links'])-2)) |
| 251 | else: |
| 252 | break |
| 253 | count = 1 |
| 254 | i = 6 |
| 255 | while i < 16 : |
| 256 | main.log.info("\n\t\t\t\th"+str(i)+" IS PINGING h"+str(i+25) ) |
| 257 | ping = main.Mininet.pingHost(src="h"+str(i),target="h"+str(i+25)) |
| 258 | if ping == main.FALSE and count < 10: |
| 259 | count = count + 1 |
| 260 | main.log.info("Ping failed, making attempt number "+str(count)+" in 2 seconds") |
| 261 | i = 6 |
| 262 | time.sleep(2) |
| 263 | elif ping == main.FALSE and count == 10: |
| 264 | main.log.error("Ping test failed") |
| 265 | i = 17 |
| 266 | result = main.FALSE |
| 267 | elif ping == main.TRUE: |
| 268 | i = i + 1 |
| 269 | result = main.TRUE |
| 270 | endTime = time.time() |
| 271 | if result == main.TRUE: |
| 272 | main.log.report("\tTime to complete ping test: "+str(round(endTime-strtTime,2))+" seconds") |
| 273 | else: |
| 274 | main.log.report("\tPING TEST FAILED") |
| 275 | utilities.assert_equals(expect=main.TRUE,actual=result,onpass="NO PACKET LOSS, HOST IS REACHABLE",onfail="PACKET LOST, HOST IS NOT REACHABLE") |
| 276 | # #********************************************************************************************************************************************************************************************** |
| 277 | #Brings the link that Case 6 took down back up, then runs a ping test to view reroute time |
| 278 | |
| 279 | def CASE7(self,main) : |
| 280 | main.log.report("Bring Link between s1 and s2 up, then ping until all hosts are reachable or fail after 10 attempts") |
| 281 | import time |
| 282 | main.case("Bringing Link up... ") |
| 283 | result = main.Mininet.link(END1=main.params['LINK']['begin'],END2=main.params['LINK']['end'],OPTION="up") |
| 284 | utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Link UP!",onfail="Link not brought up...") |
| 285 | strtTime = time.time() |
| 286 | result = main.ONOS.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links']) |
| 287 | for i in range(2): |
| 288 | if result == main.FALSE: |
| 289 | time.sleep(5) |
| 290 | result = main.ONOS.check_status_report(main.params['RestIP'],main.params['NR_Switches'],main.params['NR_Links']) |
| 291 | else: |
| 292 | break |
| 293 | strtTime = time.time() |
| 294 | count = 1 |
| 295 | i = 6 |
| 296 | while i < 16 : |
| 297 | main.log.info("\n\t\t\t\th"+str(i)+" IS PINGING h"+str(i+25) ) |
| 298 | ping = main.Mininet.pingHost(src="h"+str(i),target="h"+str(i+25)) |
| 299 | if ping == main.FALSE and count < 10: |
| 300 | count = count + 1 |
| 301 | main.log.info("Ping failed, making attempt number "+str(count)+" in 2 seconds") |
| 302 | i = 6 |
| 303 | time.sleep(2) |
| 304 | elif ping == main.FALSE and count ==10: |
| 305 | main.log.error("Ping test failed") |
| 306 | i = 17 |
| 307 | result = main.FALSE |
| 308 | elif ping == main.TRUE: |
| 309 | i = i + 1 |
| 310 | result = main.TRUE |
| 311 | endTime = time.time() |
| 312 | if result == main.TRUE: |
| 313 | main.log.report("\tTime to complete ping test: "+str(round(endTime-strtTime,2))+" seconds") |
| 314 | else: |
| 315 | main.log.report("\tPING TESTS FAILED") |
| 316 | utilities.assert_equals(expect=main.TRUE,actual=result,onpass="NO PACKET LOSS, HOST IS REACHABLE",onfail="PACKET LOST, HOST IS NOT REACHABLE") |
| 317 | # #****************************************************************************************************************************************************************** |
| 318 | # Test Device Discovery function by yanking s6:s6-eth0 interface and re-plug it into a switch |
| 319 | |
| 320 | def CASE21(self,main) : |
| 321 | import json |
| 322 | main.log.report("Test device discovery function, by attach, detach, move host h1 from s1->s6->s1. Per mininet naming, switch port the host attaches will remain as 's1-eth1' throughout the test.") |
| 323 | main.log.report("Check initially hostMAC/IP exist on the mininet...") |
| 324 | host = main.params['YANK']['hostname'] |
| 325 | mac = main.params['YANK']['hostmac'] |
| 326 | hostip = main.params['YANK']['hostip'] |
| 327 | RestIP1 = main.params['RESTCALL']['restIP1'] |
| 328 | RestPort = main.params['RESTCALL']['restPort'] |
| 329 | url = main.params['RESTCALL']['restURL'] |
| 330 | |
| 331 | t_topowait = 0 |
| 332 | t_restwait = 10 |
| 333 | main.log.report( "Wait time from topo change to ping set to " + str(t_topowait)) |
| 334 | main.log.report( "Wait time from ping to rest call set to " + str(t_restwait)) |
| 335 | #print "host=" + host + "; RestIP=" + RestIP1 + "; RestPort=" + str(RestPort) |
| 336 | time.sleep(t_topowait) |
| 337 | main.log.info("\n\t\t\t\t ping issue one ping from " + str(host) + " to generate arp to switch. Ping result is not important" ) |
| 338 | ping = main.Mininet.pingHost(SRC = str(host),TARGET = "10.0.0.254") |
| 339 | time.sleep(t_restwait) |
| 340 | Reststatus, Switch, Port, MAC = main.ONOS.find_host(RestIP1,RestPort,url, hostip) |
| 341 | main.log.report("Number of host with IP=10.0.0.1 found by ONOS is: " + str(Reststatus)) |
| 342 | if Reststatus == 1: |
| 343 | main.log.report("\t PASSED - Found host IP = " + hostip + "; MAC = " + "".join(MAC) + "; attached to switchDPID = " + "".join(Switch) + "; at port = " + "".join(Port)) |
| 344 | result1 = main.TRUE |
| 345 | elif Reststatus > 1: |
| 346 | main.log.report("\t FAILED - Host " + host + " with MAC:" + mac + " has " + str(Reststatus) + " duplicated IP addresses. FAILED") |
| 347 | main.log.report("switches are: " + "; ".join(Switch)) |
| 348 | main.log.report("Ports are: " + "; ".join(Port)) |
| 349 | main.log.report("MACs are: " + "; ".join(MAC)) |
| 350 | result1 = main.FALSE |
| 351 | else: |
| 352 | main.log.report("\t FAILED - Host " + host + " with MAC:" + mac + " does not exist. FAILED") |
| 353 | result1 = main.FALSE |
| 354 | ##### Step to yank out "s1-eth1" from s1, which is on autoONOS1 ##### |
| 355 | main.log.report("Yank out s1-eth1") |
| 356 | main.step("Yankout s6-eth1 (link to h1) from s1") |
| 357 | result = main.Mininet.yank(SW=main.params['YANK']['sw1'],INTF=main.params['YANK']['intf']) |
| 358 | time.sleep(t_topowait) |
| 359 | utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Yank command suceeded",onfail="Yank command failed...") |
| 360 | |
| 361 | main.log.info("\n\t\t\t\t ping issue one ping from" + str(host) + "to generate arp to switch. Ping result is not important" ) |
| 362 | ping = main.Mininet.pingHost(SRC = str(host),TARGET = "10.0.0.254") |
| 363 | time.sleep(t_restwait) |
| 364 | Reststatus, Switch, Port, MAC = main.ONOS.find_host(RestIP1,RestPort,url, hostip) |
| 365 | |
| 366 | main.log.report("Number of host with IP=10.0.0.1 found by ONOS is: " + str(Reststatus)) |
| 367 | if Reststatus == 1: |
| 368 | main.log.report("\tFAILED - Found host IP = " + hostip + "; MAC = " + "".join(MAC) + "; attached to switchDPID = " + "".join(Switch) + "; at port = " + "".join(Port)) |
| 369 | result2 = main.FALSE |
| 370 | elif Reststatus > 1: |
| 371 | main.log.report("\t FAILED - Host " + host + " with MAC:" + str(mac) + " has " + str(Reststatus) + " duplicated IP addresses. FAILED") |
| 372 | main.log.report("switches are: " + "; ".join(Switch)) |
| 373 | main.log.report("Ports are: " + "; ".join(Port)) |
| 374 | main.log.report("MACs are: " + "; ".join(MAC)) |
| 375 | result2 = main.FALSE |
| 376 | else: |
| 377 | main.log.report("\t PASSED - Host " + host + " with MAC:" + str(mac) + " does not exist. PASSED - host is not supposed to be attached to the switch.") |
| 378 | result2 = main.TRUE |
| 379 | |
| 380 | ##### Step to plug "s1-eth1" to s6, which is on autoONOS3 ###### |
| 381 | main.log.report("Plug s1-eth1 into s6") |
| 382 | main.step("Plug s1-eth1 to s6") |
| 383 | result = main.Mininet.plug(SW=main.params['PLUG']['sw6'],INTF=main.params['PLUG']['intf']) |
| 384 | time.sleep(t_topowait) |
| 385 | utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Plug command suceeded",onfail="Plug command failed...") |
| 386 | main.log.info("\n\t\t\t\t ping issue one ping from" + str(host) + "to generate arp to switch. Ping result is not important" ) |
| 387 | |
| 388 | ping = main.Mininet.pingHost(src = str(host),target = "10.0.0.254") |
| 389 | time.sleep(t_restwait) |
| 390 | Reststatus, Switch, Port, MAC = main.ONOS.find_host(RestIP1,RestPort,url, hostip) |
| 391 | |
| 392 | main.log.report("Number of host with IP=10.0.0.1 found by ONOS is: " + str(Reststatus)) |
| 393 | if Reststatus == 1: |
| 394 | main.log.report("\tPASSED - Found host IP = " + hostip + "; MAC = " + "".join(MAC) + "; attached to switchDPID = " + "".join(Switch) + "; at port = " + "".join(Port)) |
| 395 | result3 = main.TRUE |
| 396 | elif Reststatus > 1: |
| 397 | main.log.report("\t FAILED - Host " + host + " with MAC:" + str(mac) + " has " + str(Reststatus) + " duplicated IP addresses. FAILED") |
| 398 | main.log.report("switches are: " + "; ".join(Switch)) |
| 399 | main.log.report("Ports are: " + "; ".join(Port)) |
| 400 | main.log.report("MACs are: " + "; ".join(MAC)) |
| 401 | result3 = main.FALSE |
| 402 | else: |
| 403 | main.log.report("\t FAILED - Host " + host + " with MAC:" + str(mac) + " does not exist. FAILED") |
| 404 | result3 = main.FALSE |
| 405 | |
| 406 | ###### Step to put interface "s1-eth1" back to s1"##### |
| 407 | main.log.report("Move s1-eth1 back on to s1") |
| 408 | main.step("Move s1-eth1 back to s1") |
| 409 | result = main.Mininet.yank(SW=main.params['YANK']['sw6'],INTF=main.params['YANK']['intf']) |
| 410 | time.sleep(t_topowait) |
| 411 | result = main.Mininet.plug(SW=main.params['PLUG']['sw1'],INTF=main.params['PLUG']['intf']) |
| 412 | utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Yank/Plug command suceeded",onfail="Yank/Plug command failed...") |
| 413 | main.log.info("\n\t\t\t\t ping issue one ping from" + str(host) + "to generate arp to switch. Ping result is not important" ) |
| 414 | |
| 415 | ping = main.Mininet.pingHost(src = str(host),target = "10.0.0.254") |
| 416 | time.sleep(t_restwait) |
| 417 | Reststatus, Switch, Port, MAC = main.ONOS.find_host(RestIP1,RestPort,url, hostip) |
| 418 | |
| 419 | main.log.report("Number of host with IP=10.0.0.1 found by ONOS is: " + str(Reststatus)) |
| 420 | if Reststatus == 1: |
| 421 | main.log.report("\tPASSED - Found host IP = " + hostip + "; MAC = " + "".join(MAC) + "; attached to switchDPID = " + "".join(Switch) + "; at port = " + "".join(Port)) |
| 422 | result4 = main.TRUE |
| 423 | elif Reststatus > 1: |
| 424 | main.log.report("\t FAILED - Host " + host + " with MAC:" + str(mac) + " has " + str(Reststatus) + " duplicated IP addresses. FAILED") |
| 425 | main.log.report("switches are: " + "; ".join(Switch)) |
| 426 | main.log.report("Ports are: " + "; ".join(Port)) |
| 427 | main.log.report("MACs are: " + "; ".join(MAC)) |
| 428 | result4 = main.FALSE |
| 429 | else: |
| 430 | main.log.report("\t FAILED -Host " + host + " with MAC:" + str(mac) + " does not exist. FAILED") |
| 431 | result4 = main.FALSE |
| 432 | |
| 433 | result = result1 and result2 and result3 and result4 |
| 434 | utilities.assert_equals(expect=main.TRUE,actual=result,onpass="DEVICE DISCOVERY TEST PASSED PLUG/UNPLUG/MOVE TEST",onfail="DEVICE DISCOVERY TEST FAILED") |
| 435 | |
| 436 | # Run a pure ping test. |
| 437 | |
| 438 | def CASE31(self, main): |
| 439 | main.log.report("Performing Ping Test") |
| 440 | count = 1 |
| 441 | i = 6 |
| 442 | while i < 16 : |
| 443 | main.log.info("\n\t\t\t\th"+str(i)+" IS PINGING h"+str(i+25) ) |
| 444 | strtTime = time.time() |
| 445 | ping = main.Mininet.pingHost(src="h"+str(i),target="h"+str(i+25)) |
| 446 | if ping == main.FALSE and count < 6: |
| 447 | count = count + 1 |
| 448 | i = 6 |
| 449 | main.log.info("Ping failed, making attempt number "+str(count)+" in 2 seconds") |
| 450 | time.sleep(2) |
| 451 | elif ping == main.FALSE and count ==6: |
| 452 | main.log.error("Ping test failed") |
| 453 | i = 17 |
| 454 | result = main.FALSE |
| 455 | elif ping == main.TRUE: |
| 456 | i = i + 1 |
| 457 | result = main.TRUE |
| 458 | endTime = time.time() |
| 459 | if result == main.TRUE: |
| 460 | main.log.report("\tTime to complete ping test: "+str(round(endTime-strtTime,2))+" seconds") |
| 461 | else: |
| 462 | main.log.report("\tPING TEST FAIL") |
| 463 | utilities.assert_equals(expect=main.TRUE,actual=result,onpass="NO PACKET LOSS, HOST IS REACHABLE",onfail="PACKET LOST, HOST IS NOT REACHABLE") |
| 464 | |
| 465 | |
| 466 | def CASE200(self, main): |
| 467 | ''' |
| 468 | POSTS 2 pre-set intents to the REST server and compares the REST server output to expected flows. |
| 469 | ''' |
| 470 | import time |
| 471 | import requests |
| 472 | import json |
| 473 | import re |
| 474 | main.case("Testing Rest Status") |
| 475 | |
| 476 | #---------------------- |
| 477 | |
| 478 | main.log.report("Starting Rest API Only Test") |
| 479 | main.log.report("Rest IP used: " + main.params['RestIP']) |
| 480 | restcall1 = "http://"+ main.params['RESTCALL']['restIP1'] + ":" + main.params['RESTCALL']['restPort'] + main.params['RESTCALL']['restURL'] |
| 481 | restcall2 = "http://"+ main.params['RESTCALL']['restIP1'] + ":" + main.params['RESTCALL']['restPort'] + main.params['RESTCALL']['restURL2'] |
| 482 | restcall3 = "http://"+ main.params['RESTCALL']['restIP1'] + ":" + main.params['RESTCALL']['restPort'] + main.params['RESTCALL']['restURL3'] |
| 483 | restcall4 = "http://"+ main.params['RESTCALL']['restIP1'] + ":" + main.params['RESTCALL']['restPort'] + main.params['RESTCALL']['restURL4'] |
| 484 | |
| 485 | main.log.report("Rest Calls used: " + restcall1) |
| 486 | main.log.report("Rest Calls used: " + restcall2) |
| 487 | main.log.report("Rest Calls used: " + restcall3) |
| 488 | main.log.report("Rest Calls used: " + restcall4) |
| 489 | |
| 490 | url = main.params['RESTTEST']['url'] |
| 491 | #headers = main.params['RESTTEST']['head'] |
| 492 | headers = {'Content-type': 'application/json', 'Accept': 'application/json'} |
| 493 | expSrcMac = main.params['RESTTEST']['srcMac'] |
| 494 | expDstMac = main.params['RESTTEST']['dstMac'] |
| 495 | expSrcSwitch = main.params['RESTTEST']['srcSwitch'] |
| 496 | expDstSwitch = main.params['RESTTEST']['dstSwitch'] |
| 497 | srcPort = main.params['RESTTEST']['srcPort'] |
| 498 | dstPort = main.params['RESTTEST']['dstPort'] |
| 499 | intID = int(main.params['RESTTEST']['intID']) |
| 500 | |
| 501 | intent = [{'intent_id': '%d' %(intID),'intent_type':'shortest_intent_type','intent_op':'add','srcSwitch':expSrcSwitch,'srcPort':int(srcPort),'srcMac':expSrcMac,'dstSwitch':expDstSwitch,'dstPort':int(dstPort),'dstMac':expDstMac}] |
| 502 | r = requests.post(url, data=json.dumps(intent, sort_keys=True), headers = headers) |
| 503 | |
| 504 | intent = [{'intent_id': '%d' %(intID+10),'intent_type':'shortest_intent_type','intent_op':'add','srcSwitch':expDstSwitch,'srcPort':int(dstPort),'srcMac':expDstMac,'dstSwitch':expSrcSwitch,'dstPort':int(srcPort),'dstMac':expSrcMac}] |
| 505 | r = requests.post(url, data=json.dumps(intent, sort_keys=True), headers = headers) |
| 506 | |
| 507 | count = 0 |
| 508 | main.step("Getting JSON...") |
| 509 | #r1 = main.ONOS.get_json_string(restcall1, expSrcSwitch, expDstSwitch, expSrcMac, expDstMac, srcPort, dstPort, intID) |
| 510 | r1 = main.ONOS.get_json(restcall1) |
| 511 | if re.search(expSrcSwitch, str(r1)) and re.search(expDstSwitch, str(r1)): |
| 512 | main.log.report("Restcall: "+restcall1) |
| 513 | main.log.report("Expected SrcSwitch "+expSrcSwitch+" found") |
| 514 | main.log.report("Expected DstSwitch "+expDstSwitch+" found") |
| 515 | count = count+1 |
| 516 | #r2 = main.ONOS.get_json_string(restcall2, expSrcSwitch, expDstSwitch, expSrcMac, expDstMac, srcPort, dstPort, intID) |
| 517 | r2 = main.ONOS.get_json(restcall2) |
| 518 | if re.search("u\'srcMac\': u\'"+expSrcMac+"\'", str(r2)) and re.search("u\'dstMac\': u\'"+expDstMac+"\'", str(r2)): |
| 519 | main.log.report("Restcall: "+restcall2) |
| 520 | main.log.report("Expected SrcMac "+expSrcMac+" found") |
| 521 | main.log.report("Expected DstMac "+expDstMac+" found") |
| 522 | if re.search("u\'srcSwitchDpid\': u\'"+expSrcSwitch+"\'", str(r2)) and re.search("u\'dstSwitchDpid\': u\'"+expDstSwitch+"\'", str(r2)): |
| 523 | main.log.report("Expected SrcSwitch "+expSrcSwitch+" found") |
| 524 | main.log.report("Expected DstSwitch "+expDstSwitch+" found") |
| 525 | if re.search("u\'srcPortNumber\': u\'"+srcPort+"\'", str(r2)) and re.search("u\'dstPortNumber\': u\'"+dstPort+"\'", str(r2)): |
| 526 | main.log.report("Expected SrcPort "+srcPort+" found") |
| 527 | main.log.report("Expected DstPort "+dstPort+" found") |
| 528 | count = count+1 |
| 529 | else: |
| 530 | main.log.report("Expected SrcPort "+srcPort+" NOT found") |
| 531 | main.log.report("Expected DstPort "+dstPort+" NOT found") |
| 532 | else: |
| 533 | main.log.report("Expected SrcSwitch "+expSrcSwitch+" NOT found") |
| 534 | main.log.report("Expected DstSwitch "+expDstSwitch+" NOT found") |
| 535 | else: |
| 536 | main.log.report("Expected SrcMac "+expSrcMac+" NOT found") |
| 537 | main.log.report("Expected DstMac "+expDstMac+" NOT found") |
| 538 | if count != 2: |
| 539 | main.log.report("Actual data: "+str(r2)) |
| 540 | |
| 541 | #r3 = main.ONOS.get_json_string(restcall3, expSrcSwitch, expDstSwitch, expSrcMac, expDstMac, srcPort, dstPort, intID) |
| 542 | r3 = main.ONOS.get_json(restcall3) |
| 543 | if re.search("", str(r3)): |
| 544 | main.log.report("Restcall: "+restcall3) |
| 545 | count = count+1 |
| 546 | |
| 547 | #r4 = main.ONOS.get_json_string(restcall4, expSrcSwitch, expDstSwitch, expSrcMac, expDstMac, srcPort, dstPort, intID) |
| 548 | r4 = main.ONOS.get_json(restcall4) |
| 549 | if re.search(expSrcSwitch, str(r4)) and re.search(expDstSwitch, str(r4)): |
| 550 | main.log.report("Restcall: "+restcall4) |
| 551 | main.log.report("Expected SrcSwitch: "+expSrcSwitch+" found") |
| 552 | main.log.report("Expected DstSwitch: "+expDstSwitch+" found") |
| 553 | count = count+1 |
| 554 | else: |
| 555 | main.log.report("Expected SrcSwitch: "+expSrcSwitch+" NOT found") |
| 556 | main.log.report("Expected DstSwitch: "+expDstSwitch+" NOT found") |
| 557 | |
| 558 | utilities.assert_equals(expect=4,actual=count,onpass="REST API test passed!",onfail="REST API test failed...") |
| 559 | |