admin | abe6bbe | 2014-07-25 16:22:27 -0700 | [diff] [blame] | 1 | |
| 2 | class HATest1: |
| 3 | |
admin | 2580a0e | 2014-07-29 11:24:34 -0700 | [diff] [blame] | 4 | global topology |
| 5 | global masterSwitchList |
| 6 | global highIntentList |
| 7 | global lowIntentList |
| 8 | global flowTable |
admin | abe6bbe | 2014-07-25 16:22:27 -0700 | [diff] [blame] | 9 | def __init__(self) : |
| 10 | self.default = '' |
| 11 | |
| 12 | ''' |
| 13 | CASE1 is to close any existing instances of ONOS, clean out the |
| 14 | RAMCloud database, and start up ONOS instances. |
| 15 | ''' |
| 16 | def CASE1(self,main) : |
| 17 | main.case("Initial Startup") |
| 18 | main.step("Stop ONOS") |
| 19 | if not main.ONOS1.status(): |
| 20 | main.ONOS1.stop_all() |
| 21 | if not main.ONOS1.status(): |
| 22 | main.ONOS2.stop_all() |
| 23 | if not main.ONOS1.status(): |
| 24 | main.ONOS3.stop_all() |
| 25 | if not main.ONOS1.status(): |
| 26 | main.ONOS4.stop_all() |
| 27 | main.ONOS1.stop_rest() |
| 28 | main.ONOS2.stop_rest() |
| 29 | main.ONOS3.stop_rest() |
| 30 | main.ONOS4.stop_rest() |
| 31 | result = main.ONOS1.status() or main.ONOS2.status() \ |
| 32 | or main.ONOS3.status() or main.ONOS4.status() |
| 33 | utilities.assert_equals(expect=main.FALSE,actual=result,onpass="ONOS stopped successfully",onfail="ONOS WAS NOT KILLED PROPERLY") |
| 34 | main.step("Startup Zookeeper") |
| 35 | main.ZK1.start() |
| 36 | main.ZK2.start() |
| 37 | main.ZK3.start() |
| 38 | main.ZK4.start() |
| 39 | result = main.ZK1.isup() and main.ZK2.isup()\ |
| 40 | and main.ZK3.isup() and main.ZK4.isup |
| 41 | utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Zookeeper started successfully",onfail="ZOOKEEPER FAILED TO START") |
| 42 | main.step("Cleaning RC Database and Starting All") |
| 43 | main.RC1.deldb() |
| 44 | main.RC2.deldb() |
| 45 | main.RC3.deldb() |
| 46 | main.RC4.deldb() |
| 47 | main.ONOS1.start_all() |
| 48 | main.ONOS2.start_all() |
| 49 | main.ONOS3.start_all() |
| 50 | main.ONOS4.start_all() |
| 51 | main.ONOS1.start_rest() |
| 52 | main.step("Testing Startup") |
| 53 | result1 = main.ONOS1.rest_status() |
| 54 | vm1 = main.RC1.status_coor and main.RC1.status_serv and \ |
| 55 | main.ONOS1.isup() |
| 56 | vm2 = main.RC2.status_coor and main.ONOS2.isup() |
| 57 | vm3 = main.RC3.status_coor and main.ONOS3.isup() |
| 58 | vm4 = main.RC4.status_coor and main.ONOS4.isup() |
| 59 | result = result1 and vm1 and vm2 and vm3 and vm4 |
| 60 | utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Everything started successfully",onfail="EVERYTHING FAILED TO START") |
| 61 | |
| 62 | ''' |
| 63 | CASE2 |
| 64 | ''' |
| 65 | def CASE2(self,main) : |
| 66 | import time |
| 67 | import json |
| 68 | import re |
| 69 | main.log.report("Assigning Controllers") |
| 70 | main.case("Assigning Controllers") |
| 71 | main.step("Assign Master Controllers") |
| 72 | for i in range(1,28): |
| 73 | if i ==1: |
| 74 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1']) |
| 75 | elif i>=2 and i<5: |
admin | 2580a0e | 2014-07-29 11:24:34 -0700 | [diff] [blame] | 76 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip2'],port1=main.params['CTRL']['port2']) |
admin | abe6bbe | 2014-07-25 16:22:27 -0700 | [diff] [blame] | 77 | elif i>=5 and i<8: |
admin | 2580a0e | 2014-07-29 11:24:34 -0700 | [diff] [blame] | 78 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip3'],port1=main.params['CTRL']['port3']) |
admin | abe6bbe | 2014-07-25 16:22:27 -0700 | [diff] [blame] | 79 | elif i>=8 and i<18: |
admin | 2580a0e | 2014-07-29 11:24:34 -0700 | [diff] [blame] | 80 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip4'],port1=main.params['CTRL']['port4']) |
admin | abe6bbe | 2014-07-25 16:22:27 -0700 | [diff] [blame] | 81 | elif i>=18 and i<28: |
admin | 2580a0e | 2014-07-29 11:24:34 -0700 | [diff] [blame] | 82 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip5'],port1=main.params['CTRL']['port5']) |
admin | abe6bbe | 2014-07-25 16:22:27 -0700 | [diff] [blame] | 83 | else: |
| 84 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1']) |
| 85 | |
| 86 | result = main.TRUE |
| 87 | for i in range (1,28): |
| 88 | if i==1: |
| 89 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 90 | print("Response is " + str(response)) |
| 91 | if re.search("tcp:"+main.params['CTRL']['ip1'],response): |
| 92 | result = result and main.TRUE |
| 93 | else: |
| 94 | result = main.FALSE |
| 95 | elif i>=2 and i<5: |
| 96 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 97 | print("Response is " + str(response)) |
| 98 | if re.search("tcp:"+main.params['CTRL']['ip2'],response): |
| 99 | result = result and main.TRUE |
| 100 | else: |
| 101 | result = main.FALSE |
| 102 | elif i>=5 and i<8: |
| 103 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 104 | print("Response is " + str(response)) |
| 105 | if re.search("tcp:"+main.params['CTRL']['ip3'],response): |
| 106 | result = result and main.TRUE |
| 107 | else: |
| 108 | result = main.FALSE |
| 109 | elif i>=8 and i<18: |
| 110 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 111 | print("Response is " + str(response)) |
| 112 | if re.search("tcp:"+main.params['CTRL']['ip4'],response): |
| 113 | result = result and main.TRUE |
| 114 | else: |
| 115 | result = main.FALSE |
| 116 | elif i>=18 and i<28: |
| 117 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 118 | print("Response is " + str(response)) |
| 119 | if re.search("tcp:"+main.params['CTRL']['ip5'],response): |
| 120 | result = result and main.TRUE |
| 121 | else: |
| 122 | result = main.FALSE |
| 123 | else: |
| 124 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 125 | print("Response is" + str(response)) |
| 126 | if re.search("tcp:" +main.params['CTRL']['ip1'],response): |
| 127 | result = result and main.TRUE |
| 128 | else: |
| 129 | result = main.FALSE |
| 130 | utilities.assert_equals(expect = main.TRUE,actual=result,onpass="MasterControllers assigned correctly") |
admin | abe6bbe | 2014-07-25 16:22:27 -0700 | [diff] [blame] | 131 | |
| 132 | def CASE3(self,main) : |
| 133 | import time |
| 134 | import json |
| 135 | import re |
| 136 | main.case("Adding Intents") |
| 137 | intentIP = main.params['CTRL']['ip1'] |
| 138 | intentPort=main.params['INTENTS']['intentPort'] |
| 139 | intentURL=main.params['INTENTS']['intentURL'] |
| 140 | count = 1 |
| 141 | for i in range(8,18): |
| 142 | srcMac = '00:00:00:00:00:' + str(hex(i)[2:]).zfill(2) |
| 143 | dstMac = '00:00:00:00:00:'+str(hex(i+10)[2:]) |
| 144 | srcDPID = '00:00:00:00:00:00:30:'+str(i).zfill(2) |
| 145 | dstDPID= '00:00:00:00:00:00:60:' +str(i+10) |
| 146 | main.ONOS1.add_intent(intent_id=str(count),src_dpid=srcDPID,dst_dpid=dstDPID,src_mac=srcMac,dst_mac=dstMac,intentIP=intentIP,intentPort=intentPort,intentURL=intentURL) |
| 147 | count+=1 |
| 148 | dstDPID = '00:00:00:00:00:00:30:'+str(i).zfill(2) |
| 149 | srcDPID= '00:00:00:00:00:00:60:' +str(i+10) |
| 150 | dstMac = '00:00:00:00:00:' + str(hex(i)[2:]).zfill(2) |
| 151 | srcMac = '00:00:00:00:00:'+str(hex(i+10)[2:]) |
| 152 | main.ONOS1.add_intent(intent_id=str(count),src_dpid=srcDPID,dst_dpid=dstDPID,src_mac=srcMac,dst_mac=dstMac,intentIP=intentIP,intentPort=intentPort,intentURL=intentURL) |
| 153 | count+=1 |
admin | abe6bbe | 2014-07-25 16:22:27 -0700 | [diff] [blame] | 154 | count = 1 |
| 155 | i = 8 |
| 156 | result = main.TRUE |
| 157 | while i <18 : |
| 158 | main.log.info("\n\nh"+str(i)+" is Pinging h" + str(i+10)) |
| 159 | ping = main.Mininet1.pingHost(src="h"+str(i),target="h"+str(i+10)) |
| 160 | if ping ==main.FALSE and count <9: |
| 161 | count+=1 |
| 162 | i = 8 |
| 163 | result = main.FALSE |
| 164 | main.log.info("Ping FAILED! Making attempt number "+str(count) + "in 2 seconds") |
| 165 | time.sleep(2) |
| 166 | elif ping==main.FALSE: |
| 167 | main.log.info("PINGS FAILED! MAX RETRIES REACHED!") |
| 168 | i=19 |
| 169 | result = main.FALSE |
| 170 | elif ping==main.TRUE: |
| 171 | main.log.info("Ping passed!") |
| 172 | i+=1 |
| 173 | result = main.TRUE |
| 174 | else: |
| 175 | main.log.info("ERROR!!") |
| 176 | result = main.ERROR |
| 177 | if result==main.FALSE: |
| 178 | main.log.info("INTENTS HAVE NOT BEEN INSTALLED CORRECTLY!! EXITING!!!") |
| 179 | main.cleanup() |
| 180 | main.exit() |
| 181 | |
| 182 | |
| 183 | def CASE4(self,main) : |
admin | 2580a0e | 2014-07-29 11:24:34 -0700 | [diff] [blame] | 184 | import time |
| 185 | from subprocess import Popen, PIPE |
admin | abe6bbe | 2014-07-25 16:22:27 -0700 | [diff] [blame] | 186 | main.case("Setting up and Gathering data for current state") |
admin | 2580a0e | 2014-07-29 11:24:34 -0700 | [diff] [blame] | 187 | main.step("Get the current In-Memory Topology on each ONOS Instance") |
| 188 | ctrls = [] |
| 189 | count = 1 |
| 190 | while True: |
| 191 | temp = () |
| 192 | if ('ip'+str(count)) in main.params['CTRL']: |
| 193 | temp = temp+(getattr(main,('ONOS'+str(count))),) |
| 194 | temp = temp + ("ONOS"+str(count),) |
| 195 | temp = temp + (main.params['CTRL']['ip'+str(count)],) |
| 196 | temp = temp + (eval(main.params['CTRL']['port'+str(count)]),) |
| 197 | ctrls.append(temp) |
| 198 | count+=1 |
| 199 | else: |
| 200 | break |
| 201 | topo_result = main.TRUE |
| 202 | for n in range(1,count): |
| 203 | temp_result = main.Mininet1.compare_topo(ctrls,main.ONOS1.get_json(main.params['CTRL']['ip'+str(n)]+":"+main.params['CTRL']['restPort'+str(n)]+main.params['TopoRest'])) |
| 204 | |
| 205 | main.step("Get the Mastership of each switch") |
| 206 | (stdout,stderr)=Popen(["curl",main.params['CTRL']['ip1']+":"+main.params['CTRL']['apiPort']+main.params['CTRL']['switchURL']],stdout=PIPE).communicate() |
| 207 | global masterSwitchList1 |
| 208 | masterSwitchList1 = stdout |
| 209 | |
| 210 | main.step("Get the High Level Intents") |
| 211 | (stdout,stderr)=Popen(["curl",main.params['CTRL']['ip1']+":"+main.params['CTRL']['apiPort']+main.params['CTRL']['intentHighURL']],stdout=PIPE).communicate() |
| 212 | global highIntentList1 |
| 213 | highIntentList1 = stdout |
admin | abe6bbe | 2014-07-25 16:22:27 -0700 | [diff] [blame] | 214 | |
admin | 2580a0e | 2014-07-29 11:24:34 -0700 | [diff] [blame] | 215 | main.step("Get the Low level Intents") |
| 216 | (stdout,stderr)=Popen(["curl",main.params['CTRL']['ip1']+":"+main.params['CTRL']['apiPort']+main.params['CTRL']['intentLowURL']],stdout=PIPE).communicate() |
| 217 | global lowIntentList1 |
| 218 | lowIntentList1= stdout |
| 219 | |
| 220 | main.step("Get the OF Table entries") |
| 221 | |
| 222 | main.step("Start continuous pings") |
| 223 | main.Mininet2.pingLong(src=main.params['PING']['source1'],target=main.params['PING']['target1'],pingTime=500) |
| 224 | main.Mininet2.pingLong(src=main.params['PING']['source2'],target=main.params['PING']['target2'],pingTime=500) |
| 225 | main.Mininet2.pingLong(src=main.params['PING']['source3'],target=main.params['PING']['target3'],pingTime=500) |
| 226 | main.Mininet2.pingLong(src=main.params['PING']['source4'],target=main.params['PING']['target4'],pingTime=500) |
| 227 | main.Mininet2.pingLong(src=main.params['PING']['source5'],target=main.params['PING']['target5'],pingTime=500) |
| 228 | main.Mininet2.pingLong(src=main.params['PING']['source6'],target=main.params['PING']['target6'],pingTime=500) |
| 229 | main.Mininet2.pingLong(src=main.params['PING']['source7'],target=main.params['PING']['target7'],pingTime=500) |
| 230 | main.Mininet2.pingLong(src=main.params['PING']['source8'],target=main.params['PING']['target8'],pingTime=500) |
| 231 | main.Mininet2.pingLong(src=main.params['PING']['source9'],target=main.params['PING']['target9'],pingTime=500) |
| 232 | main.Mininet2.pingLong(src=main.params['PING']['source10'],target=main.params['PING']['target10'],pingTime=500) |
| 233 | |
| 234 | |
| 235 | def CASE5(self,main) : |
| 236 | main.case("MAIN COMPONENT FAILURE AND SCENARIO SPECIFIC TESTS") |
| 237 | |
| 238 | |
| 239 | def CASE6(self,main) : |
| 240 | import os |
| 241 | main.case("Running ONOS Constant State Tests") |
| 242 | main.step("Get the current In-Memory Topology on each ONOS Instance and Compare it to the Topology before component failure") |
| 243 | |
| 244 | main.step("Get the Mastership of each switch and compare to the Mastership before component failure") |
| 245 | (stdout,stderr)=Popen(["curl",main.params['CTRL']['ip1']+":"+main.params['CTRL']['apiPort']+main.params['CTRL']['switchURL']],stdout=PIPE).communicate() |
| 246 | result = main.TRUE |
| 247 | for i in range(1,28): |
| 248 | if main.ZK1.findMaster(switchDPID="s"+str(i),switchList=masterSwitchList1)==main.ZK1.findMaster(switchDPID="s"+str(i),switchList=stdout): |
| 249 | result = result and main.TRUE |
| 250 | else: |
| 251 | result = main.FALSE |
| 252 | utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Mastership of Switches was not changed",onfail="MASTERSHIP OF SWITCHES HAS CHANGED!!!") |
| 253 | |
| 254 | main.step("Get the High Level Intents and compare to before component failure") |
| 255 | (stdout,stderr)=Popen(["curl",main.params['CTRL']['ip1']+":"+main.params['CTRL']['apiPort']+main.params['CTRL']['intentHighURL']],stdout=PIPE).communicate() |
| 256 | changesInIntents=main.ONOS1.comp_intents(preIntents=highIntentList1,postIntents=stdout) |
| 257 | if not changesInIntents: |
| 258 | result = main.TRUE |
| 259 | else: |
| 260 | main.log.info("THERE WERE CHANGES TO THE HIGH LEVEL INTENTS! CHANGES WERE: "+str(changesInIntents)) |
| 261 | result = main.FALSE |
| 262 | utilities.assert_equals(expect=main.TRUE,actual=result,onpass="No changes to High level Intents",onfail="CHANGES WERE MADE TO HIGH LEVEL INTENTS") |
| 263 | |
| 264 | main.step("Get the Low level Intents and compare to before component failure") |
| 265 | (stdout,stderr)=Popen(["curl",main.params['CTRL']['ip1']+":"+main.params['CTRL']['apiPort']+main.params['CTRL']['intentLowURL']],stdout=PIPE).communicate() |
| 266 | changesInIntents=main.ONOS1.comp_low(preIntents=lowIntentList1,postIntents=stdout) |
| 267 | if not changesInIntents: |
| 268 | result = main.TRUE |
| 269 | else: |
| 270 | main.log.info("THERE WERE CHANGES TO THE LOW LEVEL INTENTS! CHANGES WERE: "+str(changesInIntents)) |
| 271 | result = main.FALSE |
| 272 | utilities.assert_equals(expect=main.TRUE,actual=result,onpass="No changes to Low level Intents",onfail="CHANGES WERE MADE TO LOW LEVEL INTENTS") |
| 273 | |
| 274 | |
| 275 | main.step("Get the OF Table entries and compare to before component failure") |
| 276 | |
| 277 | main.step("Check the continuous pings to ensure that no packets were dropped during component failure") |
| 278 | main.Mininet2.pingKill() |
| 279 | result = main.FALSE |
| 280 | for i in range(8,18): |
| 281 | result = result or main.Mininet2.checkForLoss("/tmp/ping.h"+str(i)) |
| 282 | if result==main.TRUE: |
| 283 | main.log.info("LOSS IN THE PINGS!") |
| 284 | elif result == main.ERROR: |
| 285 | main.log.info("There are multiple mininet process running!!") |
| 286 | else: |
| 287 | main.log.info("No Loss in the pings!") |
| 288 | utilities.assert_equals(expect=main.FALSE,actual=result,onpass="No Loss of connectivity!",onfail="LOSS OF CONNECTIVITY") |
| 289 | |
| 290 | |
admin | abe6bbe | 2014-07-25 16:22:27 -0700 | [diff] [blame] | 291 | |
| 292 | |
| 293 | |