kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 1 | """ |
| 2 | Wrapper functions for FuncIntent |
| 3 | This functions include Onosclidriver and Mininetclidriver driver functions |
| 4 | """ |
| 5 | def __init__( self ): |
| 6 | self.default = '' |
| 7 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 8 | def hostIntent( main, |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 9 | name, |
| 10 | host1, |
| 11 | host2, |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 12 | host1Id="", |
| 13 | host2Id="", |
| 14 | mac1="", |
| 15 | mac2="", |
| 16 | vlan1="-1", |
| 17 | vlan2="-1", |
| 18 | sw1="", |
| 19 | sw2="", |
| 20 | expectedLink=0 ): |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 21 | """ |
| 22 | Add host intents |
| 23 | """ |
| 24 | import time |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 25 | |
| 26 | # Assert variables |
| 27 | assert main, "There is no main variable" |
| 28 | assert name, "variable name is empty" |
| 29 | assert host1 and host2, "You must specify hosts" |
| 30 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 31 | global itemName |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 32 | itemName = name |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 33 | h1Id = host1Id |
| 34 | h2Id = host2Id |
| 35 | h1Mac = mac1 |
| 36 | h2Mac = mac2 |
| 37 | vlan1 = vlan1 |
| 38 | vlan2 = vlan2 |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 39 | hostNames = [ host1 , host2 ] |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 40 | intentsId = [] |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 41 | stepResult = main.TRUE |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 42 | pingResult = main.TRUE |
| 43 | intentResult = main.TRUE |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 44 | removeIntentResult = main.TRUE |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 45 | flowResult = main.TRUE |
| 46 | topoResult = main.TRUE |
| 47 | linkDownResult = main.TRUE |
| 48 | linkUpResult = main.TRUE |
| 49 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 50 | if main.hostsData: |
| 51 | if not h1Mac: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 52 | h1Mac = main.hostsData[ host1 ][ 'mac' ] |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 53 | if not h2Mac: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 54 | h2Mac = main.hostsData[ host2 ][ 'mac' ] |
| 55 | if main.hostsData[ host1 ][ 'vlan' ] != '-1': |
| 56 | vlan1 = main.hostsData[ host1 ][ 'vlan' ] |
| 57 | if main.hostsData[ host2 ][ 'vlan' ] != '-1': |
| 58 | vlan2 = main.hostsData[ host2 ][ 'vlan' ] |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 59 | if not h1Id: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 60 | h1Id = main.hostsData[ host1 ][ 'id' ] |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 61 | if not h2Id: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 62 | h2Id = main.hostsData[ host2 ][ 'id' ] |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 63 | |
| 64 | assert h1Id and h2Id, "You must specify host IDs" |
| 65 | if not ( h1Id and h2Id ): |
| 66 | main.log.info( "There are no host IDs" ) |
| 67 | return main.FALSE |
| 68 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 69 | # Discover hosts using arping |
| 70 | main.log.info( itemName + ": Discover host using arping" ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 71 | main.Mininet1.arping( host=host1 ) |
| 72 | main.Mininet1.arping( host=host2 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 73 | host1 = main.CLIs[ 0 ].getHost( mac=h1Mac ) |
| 74 | host2 = main.CLIs[ 0 ].getHost( mac=h2Mac ) |
| 75 | |
| 76 | # Adding host intents |
| 77 | main.log.info( itemName + ": Adding host intents" ) |
| 78 | intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne=h1Id, |
| 79 | hostIdTwo=h2Id ) |
| 80 | intentsId.append( intent1 ) |
| 81 | time.sleep( 5 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 82 | |
| 83 | # Check intents state |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 84 | time.sleep( 30 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 85 | intentResult = checkIntentState( main, intentsId ) |
| 86 | |
| 87 | # Verify flows |
| 88 | checkFlowsState( main ) |
| 89 | |
| 90 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 91 | firstPingResult = pingallHosts( main, hostNames ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 92 | if not firstPingResult: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 93 | main.log.debug( "First ping failed, there must be" + |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 94 | " something wrong with ONOS performance" ) |
| 95 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 96 | # Ping hosts again... |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 97 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 98 | time.sleep( 5 ) |
| 99 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 100 | # Test rerouting if these variables exist |
| 101 | if sw1 and sw2 and expectedLink: |
| 102 | # link down |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 103 | linkDownResult = link( main, sw1, sw2, "down" ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 104 | intentResult = intentResult and checkIntentState( main, intentsId ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 105 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 106 | # Verify flows |
| 107 | checkFlowsState( main ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 108 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 109 | # Check OnosTopology |
| 110 | topoResult = checkTopology( main, expectedLink ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 111 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 112 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 113 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 114 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 115 | intentResult = checkIntentState( main, intentsId ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 116 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 117 | # Checks ONOS state in link down |
| 118 | if linkDownResult and topoResult and pingResult and intentResult: |
| 119 | main.log.info( itemName + ": Successfully brought link down" ) |
| 120 | else: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 121 | main.log.error( itemName + ": Failed to bring link down" ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 122 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 123 | # link up |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 124 | linkUpResult = link( main, sw1, sw2, "up" ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 125 | time.sleep( 5 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 126 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 127 | # Verify flows |
| 128 | checkFlowsState( main ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 129 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 130 | # Check OnosTopology |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 131 | topoResult = checkTopology( main, main.numLinks ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 132 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 133 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 134 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 135 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 136 | intentResult = checkIntentState( main, intentsId ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 137 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 138 | # Checks ONOS state in link up |
| 139 | if linkUpResult and topoResult and pingResult and intentResult: |
| 140 | main.log.info( itemName + ": Successfully brought link back up" ) |
| 141 | else: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 142 | main.log.error( itemName + ": Failed to bring link back up" ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 143 | |
| 144 | # Remove all intents |
| 145 | removeIntentResult = removeAllIntents( main, intentsId ) |
| 146 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 147 | stepResult = pingResult and linkDownResult and linkUpResult \ |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 148 | and intentResult and removeIntentResult |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 149 | |
| 150 | return stepResult |
| 151 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 152 | def pointIntent( main, |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 153 | name, |
| 154 | host1, |
| 155 | host2, |
| 156 | deviceId1, |
| 157 | deviceId2, |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 158 | port1="", |
| 159 | port2="", |
| 160 | ethType="", |
| 161 | mac1="", |
| 162 | mac2="", |
| 163 | bandwidth="", |
| 164 | lambdaAlloc=False, |
| 165 | ipProto="", |
| 166 | ip1="", |
| 167 | ip2="", |
| 168 | tcp1="", |
| 169 | tcp2="", |
| 170 | sw1="", |
| 171 | sw2="", |
| 172 | expectedLink=0 ): |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 173 | """ |
| 174 | Add Point intents |
| 175 | """ |
| 176 | import time |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 177 | assert main, "There is no main variable" |
| 178 | assert name, "variable name is empty" |
| 179 | assert host1 and host2, "You must specify hosts" |
| 180 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 181 | global itemName |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 182 | itemName = name |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 183 | host1 = host1 |
| 184 | host2 = host2 |
| 185 | hostNames = [ host1, host2 ] |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 186 | intentsId = [] |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 187 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 188 | pingResult = main.TRUE |
| 189 | intentResult = main.TRUE |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 190 | removeIntentResult = main.TRUE |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 191 | flowResult = main.TRUE |
| 192 | topoResult = main.TRUE |
| 193 | linkDownResult = main.TRUE |
| 194 | linkUpResult = main.TRUE |
| 195 | |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 196 | # Adding bidirectional point intents |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 197 | main.log.info( itemName + ": Adding point intents" ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 198 | intent1 = main.CLIs[ 0 ].addPointIntent( ingressDevice=deviceId1, |
| 199 | egressDevice=deviceId2, |
| 200 | portIngress=port1, |
| 201 | portEgress=port2, |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 202 | ethType=ethType, |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 203 | ethSrc=mac1, |
| 204 | ethDst=mac2, |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 205 | bandwidth=bandwidth, |
| 206 | lambdaAlloc=lambdaAlloc, |
| 207 | ipProto=ipProto, |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 208 | ipSrc=ip1, |
| 209 | ipDst=ip2, |
| 210 | tcpSrc=tcp1, |
| 211 | tcpDst=tcp2 ) |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 212 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 213 | intentsId.append( intent1 ) |
| 214 | time.sleep( 5 ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 215 | intent2 = main.CLIs[ 0 ].addPointIntent( ingressDevice=deviceId2, |
| 216 | egressDevice=deviceId1, |
| 217 | portIngress=port2, |
| 218 | portEgress=port1, |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 219 | ethType=ethType, |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 220 | ethSrc=mac2, |
| 221 | ethDst=mac1, |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 222 | bandwidth=bandwidth, |
| 223 | lambdaAlloc=lambdaAlloc, |
| 224 | ipProto=ipProto, |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 225 | ipSrc=ip2, |
| 226 | ipDst=ip1, |
| 227 | tcpSrc=tcp2, |
| 228 | tcpDst=tcp1 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 229 | intentsId.append( intent2 ) |
| 230 | |
| 231 | # Check intents state |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 232 | time.sleep( 30 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 233 | intentResult = checkIntentState( main, intentsId ) |
| 234 | |
| 235 | # Verify flows |
| 236 | checkFlowsState( main ) |
| 237 | |
| 238 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 239 | firstPingResult = pingallHosts( main, hostNames ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 240 | if not firstPingResult: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 241 | main.log.debug( "First ping failed, there must be" + |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 242 | " something wrong with ONOS performance" ) |
| 243 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 244 | # Ping hosts again... |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 245 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 246 | time.sleep( 5 ) |
| 247 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 248 | # Test rerouting if these variables exist |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 249 | if sw1 and sw2 and expectedLink: |
| 250 | # link down |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 251 | linkDownResult = link( main, sw1, sw2, "down" ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 252 | intentResult = intentResult and checkIntentState( main, intentsId ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 253 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 254 | # Verify flows |
| 255 | checkFlowsState( main ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 256 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 257 | # Check OnosTopology |
| 258 | topoResult = checkTopology( main, expectedLink ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 259 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 260 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 261 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 262 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 263 | intentResult = checkIntentState( main, intentsId ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 264 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 265 | # Checks ONOS state in link down |
| 266 | if linkDownResult and topoResult and pingResult and intentResult: |
| 267 | main.log.info( itemName + ": Successfully brought link down" ) |
| 268 | else: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 269 | main.log.error( itemName + ": Failed to bring link down" ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 270 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 271 | # link up |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 272 | linkUpResult = link( main, sw1, sw2, "up" ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 273 | time.sleep( 5 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 274 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 275 | # Verify flows |
| 276 | checkFlowsState( main ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 277 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 278 | # Check OnosTopology |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 279 | topoResult = checkTopology( main, main.numLinks ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 280 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 281 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 282 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 283 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 284 | intentResult = checkIntentState( main, intentsId ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 285 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 286 | # Checks ONOS state in link up |
| 287 | if linkUpResult and topoResult and pingResult and intentResult: |
| 288 | main.log.info( itemName + ": Successfully brought link back up" ) |
| 289 | else: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 290 | main.log.error( itemName + ": Failed to bring link back up" ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 291 | |
| 292 | # Remove all intents |
| 293 | removeIntentResult = removeAllIntents( main, intentsId ) |
| 294 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 295 | stepResult = pingResult and linkDownResult and linkUpResult \ |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 296 | and intentResult and removeIntentResult |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 297 | |
| 298 | return stepResult |
| 299 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 300 | def singleToMultiIntent( main, |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 301 | name, |
| 302 | hostNames, |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 303 | devices="", |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 304 | ports=None, |
| 305 | ethType="", |
| 306 | macs=None, |
| 307 | bandwidth="", |
| 308 | lambdaAlloc=False, |
| 309 | ipProto="", |
| 310 | ipAddresses="", |
| 311 | tcp="", |
| 312 | sw1="", |
| 313 | sw2="", |
| 314 | expectedLink=0 ): |
| 315 | """ |
| 316 | Add Single to Multi Point intents |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 317 | If main.hostsData is not defined, variables data should be passed in the |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 318 | same order index wise. All devices in the list should have the same |
| 319 | format, either all the devices have its port or it doesn't. |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 320 | eg. hostName = [ 'h1', 'h2' ,.. ] |
| 321 | devices = [ 'of:0000000000000001', 'of:0000000000000002', ...] |
| 322 | ports = [ '1', '1', ..] |
| 323 | ... |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 324 | """ |
| 325 | import time |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 326 | import copy |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 327 | assert main, "There is no main variable" |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 328 | assert hostNames, "You must specify hosts" |
| 329 | assert devices or main.hostsData, "You must specify devices" |
| 330 | |
| 331 | global itemName |
| 332 | itemName = name |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 333 | tempHostsData = {} |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 334 | intentsId = [] |
| 335 | |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 336 | macsDict = {} |
| 337 | ipDict = {} |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 338 | if hostNames and devices: |
| 339 | if len( hostNames ) != len( devices ): |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 340 | main.log.debug( "hosts and devices does not have the same length" ) |
| 341 | #print "len hostNames = ", len( hostNames ) |
| 342 | #print "len devices = ", len( devices ) |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 343 | return main.FALSE |
| 344 | if ports: |
| 345 | if len( ports ) != len( devices ): |
| 346 | main.log.error( "Ports and devices does " + |
| 347 | "not have the same length" ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 348 | #print "len devices = ", len( devices ) |
| 349 | #print "len ports = ", len( ports ) |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 350 | return main.FALSE |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 351 | for i in range( len( devices ) ): |
| 352 | macsDict[ devices[ i ] ] = macs[ i ] |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 353 | else: |
| 354 | main.log.info( "Device Ports are not specified" ) |
| 355 | elif hostNames and not devices and main.hostsData: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 356 | devices = [] |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 357 | main.log.info( "singleToMultiIntent function is using main.hostsData" ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 358 | for host in hostNames: |
| 359 | print main.hostsData.get( host ).get( 'location' ) |
| 360 | devices.append( main.hostsData.get( host ).get( 'location' ) ) |
| 361 | macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \ |
| 362 | main.hostsData.get( host ).get( 'mac' ) |
| 363 | ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \ |
| 364 | main.hostsData.get( host ).get( 'ipAddresses' ) |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 365 | print main.hostsData |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 366 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 367 | |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 368 | print 'host names = ', hostNames |
| 369 | |
| 370 | print 'devices = ', devices |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 371 | |
| 372 | print "macsDict = ", macsDict |
| 373 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 374 | pingResult = main.TRUE |
| 375 | intentResult = main.TRUE |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 376 | removeIntentResult = main.TRUE |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 377 | flowResult = main.TRUE |
| 378 | topoResult = main.TRUE |
| 379 | linkDownResult = main.TRUE |
| 380 | linkUpResult = main.TRUE |
| 381 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 382 | devicesCopy = copy.copy( devices ) |
| 383 | if ports: |
| 384 | portsCopy = copy.copy( ports ) |
| 385 | main.log.info( itemName + ": Adding single point to multi point intents" ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 386 | # Adding bidirectional point intents |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 387 | for i in range( len( devices ) ): |
| 388 | ingressDevice = devicesCopy[ i ] |
| 389 | egressDeviceList = copy.copy( devicesCopy ) |
| 390 | egressDeviceList.remove( ingressDevice ) |
| 391 | if ports: |
| 392 | portIngress = portsCopy[ i ] |
| 393 | portEgressList = copy.copy( portsCopy ) |
| 394 | del portEgressList[ i ] |
| 395 | else: |
| 396 | portIngress = "" |
| 397 | portEgressList = None |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 398 | if not macsDict: |
| 399 | srcMac = "" |
| 400 | else: |
| 401 | srcMac = macsDict[ ingressDevice ] |
| 402 | if srcMac == None: |
| 403 | srcMac = "" |
| 404 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 405 | intentsId.append( main.CLIs[ 0 ].addSinglepointToMultipointIntent( |
| 406 | ingressDevice=ingressDevice, |
| 407 | egressDeviceList=egressDeviceList, |
| 408 | portIngress=portIngress, |
| 409 | portEgressList=portEgressList, |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 410 | ethType=ethType, |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 411 | ethSrc=srcMac, |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 412 | bandwidth=bandwidth, |
| 413 | lambdaAlloc=lambdaAlloc, |
| 414 | ipProto=ipProto, |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 415 | ipSrc="", |
| 416 | ipDst="", |
| 417 | tcpSrc="", |
| 418 | tcpDst="" ) ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 419 | |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 420 | pingResult = pingallHosts( main, hostNames ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 421 | |
| 422 | # Check intents state |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 423 | time.sleep( 30 ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 424 | intentResult = checkIntentState( main, intentsId ) |
| 425 | |
| 426 | # Verify flows |
| 427 | checkFlowsState( main ) |
| 428 | |
| 429 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 430 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 431 | # Ping hosts again... |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 432 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 433 | time.sleep( 5 ) |
| 434 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 435 | # Test rerouting if these variables exist |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 436 | if sw1 and sw2 and expectedLink: |
| 437 | # link down |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 438 | linkDownResult = link( main, sw1, sw2, "down" ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 439 | intentResult = intentResult and checkIntentState( main, intentsId ) |
| 440 | |
| 441 | # Verify flows |
| 442 | checkFlowsState( main ) |
| 443 | |
| 444 | # Check OnosTopology |
| 445 | topoResult = checkTopology( main, expectedLink ) |
| 446 | |
| 447 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 448 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 449 | |
| 450 | intentResult = checkIntentState( main, intentsId ) |
| 451 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 452 | # Checks ONOS state in link down |
| 453 | if linkDownResult and topoResult and pingResult and intentResult: |
| 454 | main.log.info( itemName + ": Successfully brought link down" ) |
| 455 | else: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 456 | main.log.error( itemName + ": Failed to bring link down" ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 457 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 458 | # link up |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 459 | linkUpResult = link( main, sw1, sw2, "up" ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 460 | time.sleep( 5 ) |
| 461 | |
| 462 | # Verify flows |
| 463 | checkFlowsState( main ) |
| 464 | |
| 465 | # Check OnosTopology |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 466 | topoResult = checkTopology( main, main.numLinks ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 467 | |
| 468 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 469 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 470 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 471 | intentResult = checkIntentState( main, intentsId ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 472 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 473 | # Checks ONOS state in link up |
| 474 | if linkUpResult and topoResult and pingResult and intentResult: |
| 475 | main.log.info( itemName + ": Successfully brought link back up" ) |
| 476 | else: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 477 | main.log.error( itemName + ": Failed to bring link back up" ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 478 | |
| 479 | # Remove all intents |
| 480 | removeIntentResult = removeAllIntents( main, intentsId ) |
| 481 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 482 | stepResult = pingResult and linkDownResult and linkUpResult \ |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 483 | and intentResult and removeIntentResult |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 484 | |
| 485 | return stepResult |
| 486 | |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 487 | def pingallHosts( main, hostList, pingType="ipv4" ): |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 488 | # Ping all host in the hosts list variable |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 489 | print "Pinging : ", hostList |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 490 | pingResult = main.TRUE |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 491 | pingResult = main.Mininet1.pingallHosts( hostList, pingType ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 492 | return pingResult |
| 493 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 494 | def getHostsData( main ): |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 495 | """ |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 496 | Use fwd app and pingall to discover all the hosts |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 497 | """ |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 498 | """ |
| 499 | hosts json format: |
| 500 | """ |
| 501 | import json |
| 502 | activateResult = main.TRUE |
| 503 | appCheck = main.TRUE |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 504 | getDataResult = main.TRUE |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 505 | main.log.info( "Activating reactive forwarding app " ) |
| 506 | activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" ) |
| 507 | |
| 508 | for i in range( main.numCtrls ): |
| 509 | appCheck = appCheck and main.CLIs[ i ].appToIDCheck() |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 510 | if appCheck != main.TRUE: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 511 | main.log.warn( main.CLIs[ i ].apps() ) |
| 512 | main.log.warn( main.CLIs[ i ].appIDs() ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 513 | |
| 514 | pingResult = main.Mininet1.pingall() |
| 515 | hostsJson = json.loads( main.CLIs[ 0 ].hosts() ) |
| 516 | hosts = main.Mininet1.getHosts() |
| 517 | for host in hosts: |
| 518 | main.hostsData[ host ] = {} |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 519 | main.hostsData[ host ][ 'mac' ] = \ |
| 520 | main.Mininet1.getMacAddress( host ).upper() |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 521 | for hostj in hostsJson: |
| 522 | if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]: |
| 523 | main.hostsData[ host ][ 'id' ] = hostj[ 'id' ] |
| 524 | main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ] |
| 525 | main.hostsData[ host ][ 'location' ] = \ |
| 526 | hostj[ 'location' ][ 'elementId' ] + '/' + \ |
| 527 | hostj[ 'location' ][ 'port' ] |
| 528 | main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ] |
| 529 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 530 | main.log.info( "Deactivating reactive forwarding app " ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 531 | deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 532 | if activateResult and deactivateResult and main.hostsData: |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 533 | main.log.info( "Successfully used fwd app to discover hosts " ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 534 | getDataResult = main.TRUE |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 535 | else: |
| 536 | main.log.info( "Failed to use fwd app to discover hosts " ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 537 | getDataResult = main.FALSE |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 538 | |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 539 | print main.hostsData |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 540 | |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 541 | return getDataResult |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 542 | |
| 543 | def checkTopology( main, expectedLink ): |
| 544 | statusResult = main.TRUE |
| 545 | # Check onos topology |
| 546 | main.log.info( itemName + ": Checking ONOS topology " ) |
| 547 | |
| 548 | for i in range( main.numCtrls ): |
| 549 | topologyResult = main.CLIs[ i ].topology() |
| 550 | statusResult = main.ONOSbench.checkStatus( topologyResult, |
| 551 | main.numSwitch, |
| 552 | expectedLink )\ |
| 553 | and statusResult |
| 554 | if not statusResult: |
| 555 | main.log.info( itemName + ": Topology mismatch" ) |
| 556 | else: |
| 557 | main.log.info( itemName + ": Topology match" ) |
| 558 | return statusResult |
| 559 | |
| 560 | def checkIntentState( main, intentsId ): |
| 561 | |
| 562 | main.log.info( itemName + ": Check host intents state" ) |
| 563 | for i in range( main.numCtrls ): |
| 564 | intentResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId ) |
| 565 | if not intentResult: |
| 566 | main.log.info( itemName + ": Check host intents state again") |
| 567 | for i in range( main.numCtrls ): |
| 568 | intentResult = main.CLIs[ i ].checkIntentState( |
| 569 | intentsId=intentsId ) |
| 570 | return intentResult |
| 571 | |
| 572 | def checkFlowsState( main ): |
| 573 | |
| 574 | main.log.info( itemName + ": Check flows state" ) |
| 575 | checkFlowsResult = main.CLIs[ 0 ].checkFlowsState() |
| 576 | return checkFlowsResult |
| 577 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 578 | def link( main, sw1, sw2, option): |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 579 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 580 | # link down |
| 581 | main.log.info( itemName + ": Bring link " + option + "between " + |
| 582 | sw1 + " and " + sw2 ) |
| 583 | linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option ) |
| 584 | return linkResult |
| 585 | |
| 586 | def removeAllIntents( main, intentsId ): |
| 587 | """ |
| 588 | Remove all intents in the intentsId |
| 589 | """ |
| 590 | import time |
| 591 | intentsRemaining = [] |
| 592 | removeIntentResult = main.TRUE |
| 593 | # Remove intents |
| 594 | for intent in intentsId: |
| 595 | main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True ) |
| 596 | |
| 597 | time.sleep( 5 ) |
| 598 | # Checks if there is remaining intents using intents() |
| 599 | intentsRemaining = main.CLIs[ 0 ].intents() |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 600 | # If there is remianing intents then remove intents should fail |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 601 | if intentsRemaining == []: |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 602 | main.log.info( itemName + ": There are " + |
| 603 | str( len( intentsRemaining ) ) + " intents remaining, " |
| 604 | + "failed to remove all the intents " ) |
| 605 | removeIntentResult = main.FALSE |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame^] | 606 | main.log.info( intentsRemaining ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 607 | else: |
| 608 | main.log.info( itemName + ": There are no intents remaining, " + |
| 609 | "successfully removed all the intents." ) |
| 610 | removeIntentResult = main.TRUE |
| 611 | return removeIntentResult |