admin | abe6bbe | 2014-07-25 16:22:27 -0700 | [diff] [blame] | 1 | |
| 2 | class HATest1: |
| 3 | |
| 4 | |
| 5 | def __init__(self) : |
| 6 | self.default = '' |
| 7 | |
| 8 | ''' |
| 9 | CASE1 is to close any existing instances of ONOS, clean out the |
| 10 | RAMCloud database, and start up ONOS instances. |
| 11 | ''' |
| 12 | def CASE1(self,main) : |
| 13 | main.case("Initial Startup") |
| 14 | main.step("Stop ONOS") |
| 15 | if not main.ONOS1.status(): |
| 16 | main.ONOS1.stop_all() |
| 17 | if not main.ONOS1.status(): |
| 18 | main.ONOS2.stop_all() |
| 19 | if not main.ONOS1.status(): |
| 20 | main.ONOS3.stop_all() |
| 21 | if not main.ONOS1.status(): |
| 22 | main.ONOS4.stop_all() |
| 23 | main.ONOS1.stop_rest() |
| 24 | main.ONOS2.stop_rest() |
| 25 | main.ONOS3.stop_rest() |
| 26 | main.ONOS4.stop_rest() |
| 27 | result = main.ONOS1.status() or main.ONOS2.status() \ |
| 28 | or main.ONOS3.status() or main.ONOS4.status() |
| 29 | utilities.assert_equals(expect=main.FALSE,actual=result,onpass="ONOS stopped successfully",onfail="ONOS WAS NOT KILLED PROPERLY") |
| 30 | main.step("Startup Zookeeper") |
| 31 | main.ZK1.start() |
| 32 | main.ZK2.start() |
| 33 | main.ZK3.start() |
| 34 | main.ZK4.start() |
| 35 | result = main.ZK1.isup() and main.ZK2.isup()\ |
| 36 | and main.ZK3.isup() and main.ZK4.isup |
| 37 | utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Zookeeper started successfully",onfail="ZOOKEEPER FAILED TO START") |
| 38 | main.step("Cleaning RC Database and Starting All") |
| 39 | main.RC1.deldb() |
| 40 | main.RC2.deldb() |
| 41 | main.RC3.deldb() |
| 42 | main.RC4.deldb() |
| 43 | main.ONOS1.start_all() |
| 44 | main.ONOS2.start_all() |
| 45 | main.ONOS3.start_all() |
| 46 | main.ONOS4.start_all() |
| 47 | main.ONOS1.start_rest() |
| 48 | main.step("Testing Startup") |
| 49 | result1 = main.ONOS1.rest_status() |
| 50 | vm1 = main.RC1.status_coor and main.RC1.status_serv and \ |
| 51 | main.ONOS1.isup() |
| 52 | vm2 = main.RC2.status_coor and main.ONOS2.isup() |
| 53 | vm3 = main.RC3.status_coor and main.ONOS3.isup() |
| 54 | vm4 = main.RC4.status_coor and main.ONOS4.isup() |
| 55 | result = result1 and vm1 and vm2 and vm3 and vm4 |
| 56 | utilities.assert_equals(expect=main.TRUE,actual=result,onpass="Everything started successfully",onfail="EVERYTHING FAILED TO START") |
| 57 | |
| 58 | ''' |
| 59 | CASE2 |
| 60 | ''' |
| 61 | def CASE2(self,main) : |
| 62 | import time |
| 63 | import json |
| 64 | import re |
| 65 | main.log.report("Assigning Controllers") |
| 66 | main.case("Assigning Controllers") |
| 67 | main.step("Assign Master Controllers") |
| 68 | for i in range(1,28): |
| 69 | if i ==1: |
| 70 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1']) |
| 71 | elif i>=2 and i<5: |
| 72 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip2'],port1=main.params['CTRL']['port1']) |
| 73 | elif i>=5 and i<8: |
| 74 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip3'],port1=main.params['CTRL']['port1']) |
| 75 | elif i>=8 and i<18: |
| 76 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip4'],port1=main.params['CTRL']['port1']) |
| 77 | elif i>=18 and i<28: |
| 78 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip5'],port1=main.params['CTRL']['port1']) |
| 79 | else: |
| 80 | main.Mininet1.assign_sw_controller(sw=str(i),ip1=main.params['CTRL']['ip1'],port1=main.params['CTRL']['port1']) |
| 81 | |
| 82 | result = main.TRUE |
| 83 | for i in range (1,28): |
| 84 | if i==1: |
| 85 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 86 | print("Response is " + str(response)) |
| 87 | if re.search("tcp:"+main.params['CTRL']['ip1'],response): |
| 88 | result = result and main.TRUE |
| 89 | else: |
| 90 | result = main.FALSE |
| 91 | elif i>=2 and i<5: |
| 92 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 93 | print("Response is " + str(response)) |
| 94 | if re.search("tcp:"+main.params['CTRL']['ip2'],response): |
| 95 | result = result and main.TRUE |
| 96 | else: |
| 97 | result = main.FALSE |
| 98 | elif i>=5 and i<8: |
| 99 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 100 | print("Response is " + str(response)) |
| 101 | if re.search("tcp:"+main.params['CTRL']['ip3'],response): |
| 102 | result = result and main.TRUE |
| 103 | else: |
| 104 | result = main.FALSE |
| 105 | elif i>=8 and i<18: |
| 106 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 107 | print("Response is " + str(response)) |
| 108 | if re.search("tcp:"+main.params['CTRL']['ip4'],response): |
| 109 | result = result and main.TRUE |
| 110 | else: |
| 111 | result = main.FALSE |
| 112 | elif i>=18 and i<28: |
| 113 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 114 | print("Response is " + str(response)) |
| 115 | if re.search("tcp:"+main.params['CTRL']['ip5'],response): |
| 116 | result = result and main.TRUE |
| 117 | else: |
| 118 | result = main.FALSE |
| 119 | else: |
| 120 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 121 | print("Response is" + str(response)) |
| 122 | if re.search("tcp:" +main.params['CTRL']['ip1'],response): |
| 123 | result = result and main.TRUE |
| 124 | else: |
| 125 | result = main.FALSE |
| 126 | utilities.assert_equals(expect = main.TRUE,actual=result,onpass="MasterControllers assigned correctly") |
| 127 | time.sleep(30) |
| 128 | |
| 129 | def CASE3(self,main) : |
| 130 | import time |
| 131 | import json |
| 132 | import re |
| 133 | main.case("Adding Intents") |
| 134 | intentIP = main.params['CTRL']['ip1'] |
| 135 | intentPort=main.params['INTENTS']['intentPort'] |
| 136 | intentURL=main.params['INTENTS']['intentURL'] |
| 137 | count = 1 |
| 138 | for i in range(8,18): |
| 139 | srcMac = '00:00:00:00:00:' + str(hex(i)[2:]).zfill(2) |
| 140 | dstMac = '00:00:00:00:00:'+str(hex(i+10)[2:]) |
| 141 | srcDPID = '00:00:00:00:00:00:30:'+str(i).zfill(2) |
| 142 | dstDPID= '00:00:00:00:00:00:60:' +str(i+10) |
| 143 | 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) |
| 144 | count+=1 |
| 145 | dstDPID = '00:00:00:00:00:00:30:'+str(i).zfill(2) |
| 146 | srcDPID= '00:00:00:00:00:00:60:' +str(i+10) |
| 147 | dstMac = '00:00:00:00:00:' + str(hex(i)[2:]).zfill(2) |
| 148 | srcMac = '00:00:00:00:00:'+str(hex(i+10)[2:]) |
| 149 | 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) |
| 150 | count+=1 |
| 151 | time.sleep(400) |
| 152 | count = 1 |
| 153 | i = 8 |
| 154 | result = main.TRUE |
| 155 | while i <18 : |
| 156 | main.log.info("\n\nh"+str(i)+" is Pinging h" + str(i+10)) |
| 157 | ping = main.Mininet1.pingHost(src="h"+str(i),target="h"+str(i+10)) |
| 158 | if ping ==main.FALSE and count <9: |
| 159 | count+=1 |
| 160 | i = 8 |
| 161 | result = main.FALSE |
| 162 | main.log.info("Ping FAILED! Making attempt number "+str(count) + "in 2 seconds") |
| 163 | time.sleep(2) |
| 164 | elif ping==main.FALSE: |
| 165 | main.log.info("PINGS FAILED! MAX RETRIES REACHED!") |
| 166 | i=19 |
| 167 | result = main.FALSE |
| 168 | elif ping==main.TRUE: |
| 169 | main.log.info("Ping passed!") |
| 170 | i+=1 |
| 171 | result = main.TRUE |
| 172 | else: |
| 173 | main.log.info("ERROR!!") |
| 174 | result = main.ERROR |
| 175 | if result==main.FALSE: |
| 176 | main.log.info("INTENTS HAVE NOT BEEN INSTALLED CORRECTLY!! EXITING!!!") |
| 177 | main.cleanup() |
| 178 | main.exit() |
| 179 | |
| 180 | |
| 181 | def CASE4(self,main) : |
| 182 | main.case("Setting up and Gathering data for current state") |
| 183 | |
| 184 | |
| 185 | |
| 186 | |