kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1 | """ |
| 2 | Wrapper functions for FuncIntent |
| 3 | This functions include Onosclidriver and Mininetclidriver driver functions |
| 4 | Author: kelvin@onlab.us |
| 5 | """ |
| 6 | import time |
| 7 | import copy |
| 8 | import json |
| 9 | |
| 10 | def __init__( self ): |
| 11 | self.default = '' |
| 12 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 13 | def installHostIntent( main, |
Jeremy | 2f190ca | 2016-01-29 15:23:57 -0800 | [diff] [blame] | 14 | name, |
| 15 | host1, |
| 16 | host2, |
| 17 | onosNode=0, |
| 18 | ethType="", |
| 19 | bandwidth="", |
| 20 | lambdaAlloc=False, |
| 21 | ipProto="", |
| 22 | ipAddresses="", |
| 23 | tcp="", |
| 24 | sw1="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 25 | sw2="", |
| 26 | setVlan="" ): |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 27 | """ |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 28 | Installs a Host Intent |
| 29 | |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 30 | Description: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 31 | Install a host intent using |
| 32 | add-host-intent |
| 33 | |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 34 | Steps: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 35 | - Fetch host data if not given |
| 36 | - Add host intent |
| 37 | - Ingress device is the first sender host |
| 38 | - Egress devices are the recipient devices |
| 39 | - Ports if defined in senders or recipients |
| 40 | - MAC address ethSrc loaded from Ingress device |
| 41 | - Check intent state with retry |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 42 | Required: |
| 43 | name - Type of point intent to add eg. IPV4 | VLAN | Dualstack |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 44 | host1 - Dictionary for host1 |
| 45 | { "name":"h8", "id":"of:0000000000000005/8" } |
| 46 | host2 - Dictionary for host2 |
| 47 | { "name":"h16", "id":"of:0000000000000006/8" } |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 48 | Optional: |
| 49 | onosNode - ONOS node to install the intents in main.CLIs[ ] |
| 50 | 0 by default so that it will always use the first |
| 51 | ONOS node |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 52 | ethType - Ethernet type eg. IPV4, IPV6 |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 53 | bandwidth - Bandwidth capacity |
| 54 | lambdaAlloc - Allocate lambda, defaults to False |
| 55 | ipProto - IP protocol |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 56 | tcp - TCP ports in the same order as the hosts in hostNames |
| 57 | """ |
| 58 | |
| 59 | assert main, "There is no main variable" |
| 60 | assert host1, "You must specify host1" |
| 61 | assert host2, "You must specify host2" |
| 62 | |
| 63 | global itemName # The name of this run. Used for logs. |
| 64 | itemName = name |
| 65 | onosNode = int( onosNode ) |
| 66 | |
| 67 | main.log.info( itemName + ": Adding single point to multi point intents" ) |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 68 | try: |
| 69 | if not host1.get( "id" ): |
| 70 | main.log.warn( "ID not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) ) |
| 71 | main.log.debug( main.hostsData.get( host1.get( "name" ) ) ) |
| 72 | host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "id" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 73 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 74 | if not host2.get( "id" ): |
| 75 | main.log.warn( "ID not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) ) |
| 76 | host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "id" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 77 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 78 | # Adding point intent |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 79 | vlanId = host1.get( "vlan" ) |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 80 | intentId = main.CLIs[ onosNode ].addHostIntent( hostIdOne=host1.get( "id" ), |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 81 | hostIdTwo=host2.get( "id" ), |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 82 | vlanId=vlanId, |
| 83 | setVlan=setVlan ) |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 84 | except (KeyError, TypeError): |
| 85 | errorMsg = "There was a problem loading the hosts data." |
| 86 | if intentId: |
| 87 | errorMsg += " There was a problem installing host to host intent." |
| 88 | main.log.error( errorMsg ) |
| 89 | return main.FALSE |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 90 | |
| 91 | # Check intents state |
| 92 | if utilities.retry( f=checkIntentState, retValue=main.FALSE, |
| 93 | args=( main, [ intentId ] ), sleep=main.checkIntentSleep ): |
| 94 | return intentId |
| 95 | else: |
Jeremy | 2f190ca | 2016-01-29 15:23:57 -0800 | [diff] [blame] | 96 | main.log.error( "Host Intent did not install correctly" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 97 | return main.FALSE |
| 98 | |
| 99 | def testHostIntent( main, |
| 100 | name, |
| 101 | intentId, |
| 102 | host1, |
| 103 | host2, |
| 104 | onosNode=0, |
| 105 | sw1="s5", |
| 106 | sw2="s2", |
| 107 | expectedLink=0): |
| 108 | """ |
| 109 | Test a Host Intent |
| 110 | |
| 111 | Description: |
| 112 | Test a host intent of given ID between given hosts |
| 113 | |
| 114 | Steps: |
| 115 | - Fetch host data if not given |
| 116 | - Check Intent State |
| 117 | - Check Flow State |
| 118 | - Check Connectivity |
| 119 | - Check Lack of Connectivity Between Hosts not in the Intent |
| 120 | - Reroute |
| 121 | - Take Expected Link Down |
| 122 | - Check Intent State |
| 123 | - Check Flow State |
| 124 | - Check Topology |
| 125 | - Check Connectivity |
| 126 | - Bring Expected Link Up |
| 127 | - Check Intent State |
| 128 | - Check Flow State |
| 129 | - Check Topology |
| 130 | - Check Connectivity |
| 131 | - Remove Topology |
| 132 | |
| 133 | Required: |
| 134 | name - Type of point intent to add eg. IPV4 | VLAN | Dualstack |
| 135 | intentId - intent ID to be tested ( and removed ) |
| 136 | host1 - Dictionary for host1 |
| 137 | { "name":"h8", "id":"of:0000000000000005/8" } |
| 138 | host2 - Dictionary for host2 |
| 139 | { "name":"h16", "id":"of:0000000000000006/8" } |
| 140 | Optional: |
| 141 | onosNode - ONOS node to install the intents in main.CLIs[ ] |
| 142 | 0 by default so that it will always use the first |
| 143 | ONOS node |
| 144 | sw1 - First switch to bring down & up for rerouting purpose |
| 145 | sw2 - Second switch to bring down & up for rerouting purpose |
| 146 | expectedLink - Expected link when the switches are down, it should |
| 147 | be two links lower than the links before the two |
| 148 | switches are down |
| 149 | |
| 150 | """ |
| 151 | |
| 152 | # Parameter Validity Check |
| 153 | assert main, "There is no main variable" |
| 154 | assert host1, "You must specify host1" |
| 155 | assert host2, "You must specify host2" |
| 156 | |
| 157 | global itemName |
| 158 | itemName = name |
| 159 | tempHostsData = {} |
| 160 | onosNode = int( onosNode ) |
| 161 | |
Jeremy | 2f190ca | 2016-01-29 15:23:57 -0800 | [diff] [blame] | 162 | main.log.info( itemName + ": Testing Host Intent" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 163 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 164 | try: |
| 165 | if not host1.get( "id" ): |
| 166 | main.log.warn( "Id not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) ) |
| 167 | host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "location" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 168 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 169 | if not host2.get( "id" ): |
| 170 | main.log.warn( "Id not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) ) |
| 171 | host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "location" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 172 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 173 | senderNames = [ host1.get( "name" ), host2.get( "name" ) ] |
| 174 | recipientNames = [ host1.get( "name" ), host2.get( "name" ) ] |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 175 | vlanId = host1.get( "vlan" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 176 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 177 | testResult = main.TRUE |
| 178 | except (KeyError, TypeError): |
| 179 | main.log.error( "There was a problem loading the hosts data." ) |
| 180 | return main.FALSE |
| 181 | |
| 182 | main.log.info( itemName + ": Testing Host to Host intents" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 183 | |
| 184 | # Check intent state |
| 185 | if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ): |
| 186 | main.assertReturnString += 'Initial Intent State Passed\n' |
| 187 | else: |
| 188 | main.assertReturnString += 'Initial Intent State Failed\n' |
| 189 | testResult = main.FALSE |
| 190 | |
| 191 | # Check flows count in each node |
Jeremy | 03dab01 | 2016-04-11 08:59:17 -0700 | [diff] [blame] | 192 | if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 193 | main.assertReturnString += 'Initial Flow State Passed\n' |
| 194 | else: |
| 195 | main.assertReturnString += 'Intial Flow State Failed\n' |
| 196 | testResult = main.FALSE |
| 197 | |
| 198 | # Check Connectivity |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 199 | if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 200 | main.assertReturnString += 'Initial Ping Passed\n' |
| 201 | else: |
| 202 | main.assertReturnString += 'Initial Ping Failed\n' |
| 203 | testResult = main.FALSE |
| 204 | |
| 205 | # Test rerouting if these variables exist |
| 206 | if sw1 and sw2 and expectedLink: |
| 207 | # Take link down |
| 208 | if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ): |
| 209 | main.assertReturnString += 'Link Down Passed\n' |
| 210 | else: |
| 211 | main.assertReturnString += 'Link Down Failed\n' |
| 212 | testResult = main.FALSE |
| 213 | |
| 214 | # Check intent state |
| 215 | if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ): |
| 216 | main.assertReturnString += 'Link Down Intent State Passed\n' |
| 217 | else: |
| 218 | main.assertReturnString += 'Link Down Intent State Failed\n' |
| 219 | testResult = main.FALSE |
| 220 | |
| 221 | # Check flows count in each node |
Jeremy | 03dab01 | 2016-04-11 08:59:17 -0700 | [diff] [blame] | 222 | if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 223 | main.assertReturnString += 'Link Down Flow State Passed\n' |
| 224 | else: |
| 225 | main.assertReturnString += 'Link Down Flow State Failed\n' |
| 226 | testResult = main.FALSE |
| 227 | |
| 228 | # Check OnosTopology |
| 229 | if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink ) ): |
| 230 | main.assertReturnString += 'Link Down Topology State Passed\n' |
| 231 | else: |
| 232 | main.assertReturnString += 'Link Down Topology State Failed\n' |
| 233 | testResult = main.FALSE |
| 234 | |
| 235 | # Check Connection |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 236 | if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 237 | main.assertReturnString += 'Link Down Pingall Passed\n' |
| 238 | else: |
| 239 | main.assertReturnString += 'Link Down Pingall Failed\n' |
| 240 | testResult = main.FALSE |
| 241 | |
| 242 | # Bring link up |
| 243 | if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ): |
| 244 | main.assertReturnString += 'Link Up Passed\n' |
| 245 | else: |
| 246 | main.assertReturnString += 'Link Up Failed\n' |
| 247 | testResult = main.FALSE |
| 248 | |
| 249 | # Wait for reroute |
| 250 | time.sleep( main.rerouteSleep ) |
| 251 | |
| 252 | # Check Intents |
| 253 | if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ): |
| 254 | main.assertReturnString += 'Link Up Intent State Passed\n' |
| 255 | else: |
| 256 | main.assertReturnString += 'Link Up Intent State Failed\n' |
| 257 | testResult = main.FALSE |
| 258 | |
| 259 | # Check flows count in each node |
Jeremy | 03dab01 | 2016-04-11 08:59:17 -0700 | [diff] [blame] | 260 | if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 261 | main.assertReturnString += 'Link Up Flow State Passed\n' |
| 262 | else: |
| 263 | main.assertReturnString += 'Link Up Flow State Failed\n' |
| 264 | testResult = main.FALSE |
| 265 | |
| 266 | # Check OnosTopology |
| 267 | if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ): |
| 268 | main.assertReturnString += 'Link Up Topology State Passed\n' |
| 269 | else: |
| 270 | main.assertReturnString += 'Link Up Topology State Failed\n' |
| 271 | testResult = main.FALSE |
| 272 | |
| 273 | # Check Connection |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 274 | if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 275 | main.assertReturnString += 'Link Up Pingall Passed\n' |
| 276 | else: |
| 277 | main.assertReturnString += 'Link Up Pingall Failed\n' |
| 278 | testResult = main.FALSE |
| 279 | |
| 280 | # Remove all intents |
| 281 | if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ): |
| 282 | main.assertReturnString += 'Remove Intents Passed' |
| 283 | else: |
| 284 | main.assertReturnString += 'Remove Intents Failed' |
| 285 | testResult = main.FALSE |
| 286 | |
| 287 | return testResult |
| 288 | |
| 289 | def installPointIntent( main, |
| 290 | name, |
| 291 | senders, |
| 292 | recipients, |
| 293 | onosNode=0, |
| 294 | ethType="", |
| 295 | bandwidth="", |
| 296 | lambdaAlloc=False, |
| 297 | ipProto="", |
| 298 | ipSrc="", |
| 299 | ipDst="", |
| 300 | tcpSrc="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 301 | tcpDst="", |
| 302 | setVlan=""): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 303 | """ |
| 304 | Installs a Single to Single Point Intent |
| 305 | |
| 306 | Description: |
| 307 | Install a single to single point intent |
| 308 | |
| 309 | Steps: |
| 310 | - Fetch host data if not given |
| 311 | - Add point intent |
| 312 | - Ingress device is the first sender device |
| 313 | - Egress device is the first recipient device |
| 314 | - Ports if defined in senders or recipients |
| 315 | - MAC address ethSrc loaded from Ingress device |
| 316 | - Check intent state with retry |
| 317 | Required: |
| 318 | name - Type of point intent to add eg. IPV4 | VLAN | Dualstack |
| 319 | senders - List of host dictionaries i.e. |
| 320 | [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ] |
| 321 | recipients - List of host dictionaries i.e. |
| 322 | [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ] |
| 323 | Optional: |
| 324 | onosNode - ONOS node to install the intents in main.CLIs[ ] |
| 325 | 0 by default so that it will always use the first |
| 326 | ONOS node |
| 327 | ethType - Ethernet type eg. IPV4, IPV6 |
| 328 | bandwidth - Bandwidth capacity |
| 329 | lambdaAlloc - Allocate lambda, defaults to False |
| 330 | ipProto - IP protocol |
| 331 | tcp - TCP ports in the same order as the hosts in hostNames |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 332 | sw1 - First switch to bring down & up for rerouting purpose |
| 333 | sw2 - Second switch to bring down & up for rerouting purpose |
| 334 | expectedLink - Expected link when the switches are down, it should |
| 335 | be two links lower than the links before the two |
| 336 | switches are down |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 337 | """ |
| 338 | |
| 339 | assert main, "There is no main variable" |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 340 | assert senders, "You must specify a sender" |
| 341 | assert recipients, "You must specify a recipient" |
| 342 | # Assert devices or main.hostsData, "You must specify devices" |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 343 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 344 | global itemName # The name of this run. Used for logs. |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 345 | itemName = name |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 346 | onosNode = int( onosNode ) |
| 347 | |
Jeremy | 6f000c6 | 2016-02-25 17:02:28 -0800 | [diff] [blame] | 348 | main.log.info( itemName + ": Adding point to point intents" ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 349 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 350 | try: |
| 351 | for sender in senders: |
| 352 | if not sender.get( "device" ): |
| 353 | main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) ) |
| 354 | sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 355 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 356 | for recipient in recipients: |
| 357 | if not recipient.get( "device" ): |
| 358 | main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) ) |
| 359 | recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 360 | |
| 361 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 362 | ingressDevice = senders[ 0 ].get( "device" ) |
| 363 | egressDevice = recipients[ 0 ].get( "device" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 364 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 365 | portIngress = senders[ 0 ].get( "port", "" ) |
| 366 | portEgress = recipients[ 0 ].get( "port", "" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 367 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 368 | dstMac = recipients[ 0 ].get( "mac" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 369 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 370 | ipSrc = senders[ 0 ].get( "ip" ) |
| 371 | ipDst = recipients[ 0 ].get( "ip" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 372 | |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 373 | vlanId = senders[ 0 ].get( "vlan" ) |
| 374 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 375 | # Adding point intent |
| 376 | intentId = main.CLIs[ onosNode ].addPointIntent( |
| 377 | ingressDevice=ingressDevice, |
| 378 | egressDevice=egressDevice, |
| 379 | portIngress=portIngress, |
| 380 | portEgress=portEgress, |
| 381 | ethType=ethType, |
| 382 | ethDst=dstMac, |
| 383 | bandwidth=bandwidth, |
| 384 | lambdaAlloc=lambdaAlloc, |
| 385 | ipProto=ipProto, |
| 386 | ipSrc=ipSrc, |
| 387 | ipDst=ipDst, |
| 388 | tcpSrc=tcpSrc, |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 389 | tcpDst=tcpDst, |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 390 | vlanId=vlanId, |
| 391 | setVlan=setVlan ) |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 392 | except (KeyError, TypeError): |
| 393 | errorMsg = "There was a problem loading the hosts data." |
| 394 | if intentId: |
| 395 | errorMsg += " There was a problem installing Point to Point intent." |
| 396 | main.log.error( errorMsg ) |
| 397 | return main.FALSE |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 398 | |
| 399 | # Check intents state |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 400 | if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ): |
| 401 | return intentId |
acsmars | d4862d1 | 2015-10-06 17:57:34 -0700 | [diff] [blame] | 402 | else: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 403 | main.log.error( "Point Intent did not install correctly" ) |
| 404 | return main.FALSE |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 405 | |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 406 | def pointIntentTcp( main, |
| 407 | name, |
| 408 | host1, |
| 409 | host2, |
| 410 | onosNode=0, |
| 411 | deviceId1="", |
| 412 | deviceId2="", |
| 413 | port1="", |
| 414 | port2="", |
| 415 | ethType="", |
| 416 | mac1="", |
| 417 | mac2="", |
| 418 | bandwidth="", |
| 419 | lambdaAlloc=False, |
| 420 | ipProto="", |
| 421 | ip1="", |
| 422 | ip2="", |
| 423 | tcp1="", |
| 424 | tcp2="", |
| 425 | sw1="", |
| 426 | sw2="", |
| 427 | expectedLink=0 ): |
| 428 | |
| 429 | """ |
| 430 | Description: |
| 431 | Verify add-point-intent only for TCP |
| 432 | Steps: |
| 433 | - Get device ids | ports |
| 434 | - Add point intents |
| 435 | - Check intents |
| 436 | - Verify flows |
| 437 | - Ping hosts |
| 438 | - Reroute |
| 439 | - Link down |
| 440 | - Verify flows |
| 441 | - Check topology |
| 442 | - Ping hosts |
| 443 | - Link up |
| 444 | - Verify flows |
| 445 | - Check topology |
| 446 | - Ping hosts |
| 447 | - Remove intents |
| 448 | Required: |
| 449 | name - Type of point intent to add eg. IPV4 | VLAN | Dualstack |
| 450 | host1 - Name of first host |
| 451 | host2 - Name of second host |
| 452 | Optional: |
| 453 | onosNode - ONOS node to install the intents in main.CLIs[ ] |
| 454 | 0 by default so that it will always use the first |
| 455 | ONOS node |
| 456 | deviceId1 - ONOS device id of the first switch, the same as the |
| 457 | location of the first host eg. of:0000000000000001/1, |
| 458 | located at device 1 port 1 |
| 459 | deviceId2 - ONOS device id of the second switch |
| 460 | port1 - The port number where the first host is attached |
| 461 | port2 - The port number where the second host is attached |
| 462 | ethType - Ethernet type eg. IPV4, IPV6 |
| 463 | mac1 - Mac address of first host |
| 464 | mac2 - Mac address of the second host |
| 465 | bandwidth - Bandwidth capacity |
| 466 | lambdaAlloc - Allocate lambda, defaults to False |
| 467 | ipProto - IP protocol |
| 468 | ip1 - IP address of first host |
| 469 | ip2 - IP address of second host |
| 470 | tcp1 - TCP port of first host |
| 471 | tcp2 - TCP port of second host |
| 472 | sw1 - First switch to bring down & up for rerouting purpose |
| 473 | sw2 - Second switch to bring down & up for rerouting purpose |
| 474 | expectedLink - Expected link when the switches are down, it should |
| 475 | be two links lower than the links before the two |
| 476 | switches are down |
| 477 | """ |
| 478 | |
| 479 | assert main, "There is no main variable" |
| 480 | assert name, "variable name is empty" |
| 481 | assert host1 and host2, "You must specify hosts" |
| 482 | |
| 483 | global itemName |
| 484 | itemName = name |
| 485 | host1 = host1 |
| 486 | host2 = host2 |
| 487 | hostNames = [ host1, host2 ] |
| 488 | intentsId = [] |
| 489 | |
| 490 | iperfResult = main.TRUE |
| 491 | intentResult = main.TRUE |
| 492 | removeIntentResult = main.TRUE |
| 493 | flowResult = main.TRUE |
| 494 | topoResult = main.TRUE |
| 495 | linkDownResult = main.TRUE |
| 496 | linkUpResult = main.TRUE |
| 497 | onosNode = int( onosNode ) |
| 498 | |
| 499 | # Adding bidirectional point intents |
| 500 | main.log.info( itemName + ": Adding point intents" ) |
| 501 | intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1, |
| 502 | egressDevice=deviceId2, |
| 503 | portIngress=port1, |
| 504 | portEgress=port2, |
| 505 | ethType=ethType, |
| 506 | ethSrc=mac1, |
| 507 | ethDst=mac2, |
| 508 | bandwidth=bandwidth, |
| 509 | lambdaAlloc=lambdaAlloc, |
| 510 | ipProto=ipProto, |
| 511 | ipSrc=ip1, |
| 512 | ipDst=ip2, |
| 513 | tcpSrc=tcp1, |
| 514 | tcpDst="" ) |
| 515 | |
| 516 | intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2, |
| 517 | egressDevice=deviceId1, |
| 518 | portIngress=port2, |
| 519 | portEgress=port1, |
| 520 | ethType=ethType, |
| 521 | ethSrc=mac2, |
| 522 | ethDst=mac1, |
| 523 | bandwidth=bandwidth, |
| 524 | lambdaAlloc=lambdaAlloc, |
| 525 | ipProto=ipProto, |
| 526 | ipSrc=ip2, |
| 527 | ipDst=ip1, |
| 528 | tcpSrc=tcp2, |
| 529 | tcpDst="" ) |
| 530 | |
| 531 | intent3 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1, |
| 532 | egressDevice=deviceId2, |
| 533 | portIngress=port1, |
| 534 | portEgress=port2, |
| 535 | ethType=ethType, |
| 536 | ethSrc=mac1, |
| 537 | ethDst=mac2, |
| 538 | bandwidth=bandwidth, |
| 539 | lambdaAlloc=lambdaAlloc, |
| 540 | ipProto=ipProto, |
| 541 | ipSrc=ip1, |
| 542 | ipDst=ip2, |
| 543 | tcpSrc="", |
| 544 | tcpDst=tcp2 ) |
| 545 | |
| 546 | intent4 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2, |
| 547 | egressDevice=deviceId1, |
| 548 | portIngress=port2, |
| 549 | portEgress=port1, |
| 550 | ethType=ethType, |
| 551 | ethSrc=mac2, |
| 552 | ethDst=mac1, |
| 553 | bandwidth=bandwidth, |
| 554 | lambdaAlloc=lambdaAlloc, |
| 555 | ipProto=ipProto, |
| 556 | ipSrc=ip2, |
| 557 | ipDst=ip1, |
| 558 | tcpSrc="", |
| 559 | tcpDst=tcp1 ) |
| 560 | intentsId.append( intent1 ) |
| 561 | intentsId.append( intent2 ) |
| 562 | intentsId.append( intent3 ) |
| 563 | intentsId.append( intent4 ) |
| 564 | |
| 565 | # Check intents state |
| 566 | time.sleep( main.checkIntentSleep ) |
| 567 | intentResult = checkIntentState( main, intentsId ) |
| 568 | # Check flows count in each node |
| 569 | checkFlowsCount( main ) |
| 570 | |
| 571 | # Check intents state again if first check fails... |
| 572 | if not intentResult: |
| 573 | intentResult = checkIntentState( main, intentsId ) |
| 574 | |
| 575 | # Check flows count in each node |
| 576 | checkFlowsCount( main ) |
| 577 | |
| 578 | # Verify flows |
| 579 | checkFlowsState( main ) |
| 580 | |
| 581 | # Run iperf to both host |
acsmars | d4862d1 | 2015-10-06 17:57:34 -0700 | [diff] [blame] | 582 | iperfTemp = main.Mininet1.iperftcp( host1,host2,10 ) |
| 583 | iperfResult = iperfResult and iperfTemp |
| 584 | if iperfTemp: |
| 585 | main.assertReturnString += 'Initial Iperf Passed\n' |
| 586 | else: |
| 587 | main.assertReturnString += 'Initial Iperf Failed\n' |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 588 | |
| 589 | # Test rerouting if these variables exist |
| 590 | if sw1 and sw2 and expectedLink: |
| 591 | # link down |
| 592 | linkDownResult = link( main, sw1, sw2, "down" ) |
acsmars | d4862d1 | 2015-10-06 17:57:34 -0700 | [diff] [blame] | 593 | |
| 594 | if linkDownResult: |
| 595 | main.assertReturnString += 'Link Down Passed\n' |
| 596 | else: |
| 597 | main.assertReturnString += 'Link Down Failed\n' |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 598 | |
| 599 | # Check flows count in each node |
| 600 | checkFlowsCount( main ) |
| 601 | # Verify flows |
| 602 | checkFlowsState( main ) |
| 603 | |
| 604 | # Check OnosTopology |
| 605 | topoResult = checkTopology( main, expectedLink ) |
acsmars | d4862d1 | 2015-10-06 17:57:34 -0700 | [diff] [blame] | 606 | if topoResult: |
| 607 | main.assertReturnString += 'Link Down Topology State Passed\n' |
| 608 | else: |
| 609 | main.assertReturnString += 'Link Down Topology State Failed\n' |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 610 | |
| 611 | # Run iperf to both host |
acsmars | d4862d1 | 2015-10-06 17:57:34 -0700 | [diff] [blame] | 612 | iperfTemp = main.Mininet1.iperftcp( host1,host2,10 ) |
| 613 | iperfResult = iperfResult and iperfTemp |
| 614 | if iperfTemp: |
| 615 | main.assertReturnString += 'Link Down Iperf Passed\n' |
| 616 | else: |
| 617 | main.assertReturnString += 'Link Down Iperf Failed\n' |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 618 | |
acsmars | d4862d1 | 2015-10-06 17:57:34 -0700 | [diff] [blame] | 619 | # Check intent state |
| 620 | intentTemp = checkIntentState( main, intentsId ) |
| 621 | intentResult = intentResult and intentTemp |
| 622 | if intentTemp: |
| 623 | main.assertReturnString += 'Link Down Intent State Passed\n' |
| 624 | else: |
| 625 | main.assertReturnString += 'Link Down Intent State Failed\n' |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 626 | |
| 627 | # Checks ONOS state in link down |
| 628 | if linkDownResult and topoResult and iperfResult and intentResult: |
| 629 | main.log.info( itemName + ": Successfully brought link down" ) |
| 630 | else: |
| 631 | main.log.error( itemName + ": Failed to bring link down" ) |
| 632 | |
| 633 | # link up |
| 634 | linkUpResult = link( main, sw1, sw2, "up" ) |
acsmars | d4862d1 | 2015-10-06 17:57:34 -0700 | [diff] [blame] | 635 | if linkUpTemp: |
| 636 | main.assertReturnString += 'Link Up Passed\n' |
| 637 | else: |
| 638 | main.assertReturnString += 'Link Up Failed\n' |
| 639 | |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 640 | time.sleep( main.rerouteSleep ) |
| 641 | |
| 642 | # Check flows count in each node |
| 643 | checkFlowsCount( main ) |
| 644 | # Verify flows |
| 645 | checkFlowsState( main ) |
| 646 | |
| 647 | # Check OnosTopology |
| 648 | topoResult = checkTopology( main, main.numLinks ) |
| 649 | |
acsmars | d4862d1 | 2015-10-06 17:57:34 -0700 | [diff] [blame] | 650 | if topoResult: |
| 651 | main.assertReturnString += 'Link Up Topology State Passed\n' |
| 652 | else: |
| 653 | main.assertReturnString += 'Link Up Topology State Failed\n' |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 654 | |
acsmars | d4862d1 | 2015-10-06 17:57:34 -0700 | [diff] [blame] | 655 | # Run iperf to both host |
| 656 | iperfTemp = main.Mininet1.iperftcp( host1,host2,10 ) |
| 657 | iperfResult = iperfResult and iperfTemp |
| 658 | if iperfTemp: |
| 659 | main.assertReturnString += 'Link Up Iperf Passed\n' |
| 660 | else: |
| 661 | main.assertReturnString += 'Link Up Iperf Failed\n' |
| 662 | |
| 663 | # Check intent state |
| 664 | intentTemp = checkIntentState( main, intentsId ) |
| 665 | intentResult = intentResult and intentTemp |
| 666 | if intentTemp: |
| 667 | main.assertReturnString += 'Link Down Intent State Passed\n' |
| 668 | else: |
| 669 | main.assertReturnString += 'Link Down Intent State Failed\n' |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 670 | |
| 671 | # Checks ONOS state in link up |
| 672 | if linkUpResult and topoResult and iperfResult and intentResult: |
| 673 | main.log.info( itemName + ": Successfully brought link back up" ) |
| 674 | else: |
| 675 | main.log.error( itemName + ": Failed to bring link back up" ) |
| 676 | |
| 677 | # Remove all intents |
| 678 | removeIntentResult = removeAllIntents( main, intentsId ) |
acsmars | d4862d1 | 2015-10-06 17:57:34 -0700 | [diff] [blame] | 679 | if removeIntentResult: |
| 680 | main.assertReturnString += 'Remove Intents Passed' |
| 681 | else: |
| 682 | main.assertReturnString += 'Remove Intents Failed' |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 683 | |
| 684 | stepResult = iperfResult and linkDownResult and linkUpResult \ |
| 685 | and intentResult and removeIntentResult |
| 686 | |
| 687 | return stepResult |
| 688 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 689 | def installSingleToMultiIntent( main, |
| 690 | name, |
| 691 | senders, |
| 692 | recipients, |
| 693 | onosNode=0, |
| 694 | ethType="", |
| 695 | bandwidth="", |
| 696 | lambdaAlloc=False, |
| 697 | ipProto="", |
| 698 | ipAddresses="", |
| 699 | tcp="", |
| 700 | sw1="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 701 | sw2="", |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 702 | setVlan="", |
| 703 | partial=False ): |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 704 | """ |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 705 | Installs a Single to Multi Point Intent |
| 706 | |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 707 | Description: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 708 | Install a single to multi point intent using |
| 709 | add-single-to-multi-intent |
| 710 | |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 711 | Steps: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 712 | - Fetch host data if not given |
| 713 | - Add single to multi intent |
| 714 | - Ingress device is the first sender host |
| 715 | - Egress devices are the recipient devices |
| 716 | - Ports if defined in senders or recipients |
| 717 | - MAC address ethSrc loaded from Ingress device |
| 718 | - Check intent state with retry |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 719 | Required: |
| 720 | name - Type of point intent to add eg. IPV4 | VLAN | Dualstack |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 721 | senders - List of host dictionaries i.e. |
| 722 | { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } |
| 723 | recipients - List of host dictionaries i.e. |
| 724 | { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 725 | Optional: |
| 726 | onosNode - ONOS node to install the intents in main.CLIs[ ] |
| 727 | 0 by default so that it will always use the first |
| 728 | ONOS node |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 729 | ethType - Ethernet type eg. IPV4, IPV6 |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 730 | bandwidth - Bandwidth capacity |
| 731 | lambdaAlloc - Allocate lambda, defaults to False |
| 732 | ipProto - IP protocol |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 733 | tcp - TCP ports in the same order as the hosts in hostNames |
| 734 | sw1 - First switch to bring down & up for rerouting purpose |
| 735 | sw2 - Second switch to bring down & up for rerouting purpose |
| 736 | expectedLink - Expected link when the switches are down, it should |
| 737 | be two links lower than the links before the two |
| 738 | switches are down |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 739 | """ |
| 740 | |
| 741 | assert main, "There is no main variable" |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 742 | assert senders, "You must specify a sender" |
| 743 | assert recipients, "You must specify a recipient" |
| 744 | # Assert devices or main.hostsData, "You must specify devices" |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 745 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 746 | global itemName # The name of this run. Used for logs. |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 747 | itemName = name |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 748 | onosNode = int( onosNode ) |
| 749 | |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 750 | main.log.info( itemName + ": Adding single point to multi point intents" ) |
| 751 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 752 | try: |
| 753 | for sender in senders: |
| 754 | if not sender.get( "device" ): |
| 755 | main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) ) |
| 756 | sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 757 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 758 | for recipient in recipients: |
| 759 | if not recipient.get( "device" ): |
| 760 | main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) ) |
| 761 | recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 762 | |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 763 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 764 | ingressDevice = senders[ 0 ].get( "device" ) |
| 765 | egressDeviceList = [ x.get( "device" ) for x in recipients if x.get( "device" ) ] |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 766 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 767 | portIngress = senders[ 0 ].get( "port", "" ) |
| 768 | portEgressList = [ x.get( "port" ) for x in recipients if x.get( "port" ) ] |
| 769 | if not portEgressList: |
| 770 | portEgressList = None |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 771 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 772 | srcMac = senders[ 0 ].get( "mac" ) |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 773 | vlanId = senders[ 0 ].get( "vlan" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 774 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 775 | # Adding point intent |
| 776 | intentId = main.CLIs[ onosNode ].addSinglepointToMultipointIntent( |
| 777 | ingressDevice=ingressDevice, |
| 778 | egressDeviceList=egressDeviceList, |
| 779 | portIngress=portIngress, |
| 780 | portEgressList=portEgressList, |
| 781 | ethType=ethType, |
| 782 | ethSrc=srcMac, |
| 783 | bandwidth=bandwidth, |
| 784 | lambdaAlloc=lambdaAlloc, |
| 785 | ipProto=ipProto, |
| 786 | ipSrc="", |
| 787 | ipDst="", |
| 788 | tcpSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 789 | tcpDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 790 | vlanId=vlanId, |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 791 | setVlan=setVlan, |
| 792 | partial=partial ) |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 793 | except (KeyError, TypeError): |
| 794 | errorMsg = "There was a problem loading the hosts data." |
| 795 | if intentId: |
| 796 | errorMsg += " There was a problem installing Singlepoint to Multipoint intent." |
| 797 | main.log.error( errorMsg ) |
| 798 | return main.FALSE |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 799 | |
| 800 | # Check intents state |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 801 | if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ): |
| 802 | return intentId |
acsmars | d4862d1 | 2015-10-06 17:57:34 -0700 | [diff] [blame] | 803 | else: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 804 | main.log.error( "Single to Multi Intent did not install correctly" ) |
| 805 | return main.FALSE |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 806 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 807 | def installMultiToSingleIntent( main, |
| 808 | name, |
| 809 | senders, |
| 810 | recipients, |
| 811 | onosNode=0, |
| 812 | ethType="", |
| 813 | bandwidth="", |
| 814 | lambdaAlloc=False, |
| 815 | ipProto="", |
| 816 | ipAddresses="", |
| 817 | tcp="", |
| 818 | sw1="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 819 | sw2="", |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 820 | setVlan="", |
| 821 | partial=False ): |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 822 | """ |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 823 | Installs a Multi to Single Point Intent |
| 824 | |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 825 | Description: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 826 | Install a multi to single point intent using |
| 827 | add-multi-to-single-intent |
| 828 | |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 829 | Steps: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 830 | - Fetch host data if not given |
| 831 | - Add multi to single intent |
| 832 | - Ingress devices are the senders devices |
| 833 | - Egress device is the first recipient host |
| 834 | - Ports if defined in senders or recipients |
| 835 | - MAC address ethSrc loaded from Ingress device |
| 836 | - Check intent state with retry |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 837 | Required: |
| 838 | name - Type of point intent to add eg. IPV4 | VLAN | Dualstack |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 839 | senders - List of host dictionaries i.e. |
| 840 | [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ] |
| 841 | recipients - List of host dictionaries i.e. |
| 842 | [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ] |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 843 | Optional: |
| 844 | onosNode - ONOS node to install the intents in main.CLIs[ ] |
| 845 | 0 by default so that it will always use the first |
| 846 | ONOS node |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 847 | ethType - Ethernet type eg. IPV4, IPV6 |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 848 | bandwidth - Bandwidth capacity |
| 849 | lambdaAlloc - Allocate lambda, defaults to False |
| 850 | ipProto - IP protocol |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 851 | tcp - TCP ports in the same order as the hosts in hostNames |
| 852 | sw1 - First switch to bring down & up for rerouting purpose |
| 853 | sw2 - Second switch to bring down & up for rerouting purpose |
| 854 | expectedLink - Expected link when the switches are down, it should |
| 855 | be two links lower than the links before the two |
| 856 | switches are down |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 857 | """ |
| 858 | |
| 859 | assert main, "There is no main variable" |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 860 | assert senders, "You must specify a sender" |
| 861 | assert recipients, "You must specify a recipient" |
| 862 | # Assert devices or main.hostsData, "You must specify devices" |
| 863 | |
| 864 | global itemName # The name of this run. Used for logs. |
| 865 | itemName = name |
| 866 | onosNode = int( onosNode ) |
| 867 | |
| 868 | main.log.info( itemName + ": Adding mutli to single point intents" ) |
| 869 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 870 | try: |
| 871 | for sender in senders: |
| 872 | if not sender.get( "device" ): |
| 873 | main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) ) |
| 874 | sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 875 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 876 | for recipient in recipients: |
| 877 | if not recipient.get( "device" ): |
| 878 | main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) ) |
| 879 | recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 880 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 881 | ingressDeviceList = [ x.get( "device" ) for x in senders if x.get( "device" ) ] |
| 882 | egressDevice = recipients[ 0 ].get( "device" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 883 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 884 | portIngressList = [ x.get( "port" ) for x in senders if x.get( "port" ) ] |
| 885 | portEgress = recipients[ 0 ].get( "port", "" ) |
| 886 | if not portIngressList: |
| 887 | portIngressList = None |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 888 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 889 | dstMac = recipients[ 0 ].get( "mac" ) |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 890 | vlanId = senders[ 0 ].get( "vlan" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 891 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 892 | # Adding point intent |
| 893 | intentId = main.CLIs[ onosNode ].addMultipointToSinglepointIntent( |
| 894 | ingressDeviceList=ingressDeviceList, |
| 895 | egressDevice=egressDevice, |
| 896 | portIngressList=portIngressList, |
| 897 | portEgress=portEgress, |
| 898 | ethType=ethType, |
| 899 | ethDst=dstMac, |
| 900 | bandwidth=bandwidth, |
| 901 | lambdaAlloc=lambdaAlloc, |
| 902 | ipProto=ipProto, |
| 903 | ipSrc="", |
| 904 | ipDst="", |
| 905 | tcpSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 906 | tcpDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 907 | vlanId=vlanId, |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 908 | setVlan=setVlan, |
| 909 | partial=partial ) |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 910 | except (KeyError, TypeError): |
| 911 | errorMsg = "There was a problem loading the hosts data." |
| 912 | if intentId: |
| 913 | errorMsg += " There was a problem installing Multipoint to Singlepoint intent." |
| 914 | main.log.error( errorMsg ) |
| 915 | return main.FALSE |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 916 | |
| 917 | # Check intents state |
| 918 | if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ): |
| 919 | return intentId |
| 920 | else: |
| 921 | main.log.error( "Multi to Single Intent did not install correctly" ) |
| 922 | return main.FALSE |
| 923 | |
| 924 | def testPointIntent( main, |
Jeremy | e0cb5eb | 2016-01-27 17:39:09 -0800 | [diff] [blame] | 925 | name, |
| 926 | intentId, |
| 927 | senders, |
| 928 | recipients, |
| 929 | badSenders={}, |
| 930 | badRecipients={}, |
| 931 | onosNode=0, |
| 932 | ethType="", |
| 933 | bandwidth="", |
| 934 | lambdaAlloc=False, |
| 935 | ipProto="", |
| 936 | ipAddresses="", |
| 937 | tcp="", |
| 938 | sw1="s5", |
| 939 | sw2="s2", |
Jeremy Songster | e405d3d | 2016-05-17 11:18:57 -0700 | [diff] [blame] | 940 | expectedLink=0, |
| 941 | useTCP=False): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 942 | """ |
| 943 | Test a Point Intent |
| 944 | |
| 945 | Description: |
| 946 | Test a point intent |
| 947 | |
| 948 | Steps: |
| 949 | - Fetch host data if not given |
| 950 | - Check Intent State |
| 951 | - Check Flow State |
| 952 | - Check Connectivity |
| 953 | - Check Lack of Connectivity Between Hosts not in the Intent |
| 954 | - Reroute |
| 955 | - Take Expected Link Down |
| 956 | - Check Intent State |
| 957 | - Check Flow State |
| 958 | - Check Topology |
| 959 | - Check Connectivity |
| 960 | - Bring Expected Link Up |
| 961 | - Check Intent State |
| 962 | - Check Flow State |
| 963 | - Check Topology |
| 964 | - Check Connectivity |
| 965 | - Remove Topology |
| 966 | |
| 967 | Required: |
| 968 | name - Type of point intent to add eg. IPV4 | VLAN | Dualstack |
| 969 | |
| 970 | senders - List of host dictionaries i.e. |
| 971 | { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } |
| 972 | recipients - List of host dictionaries i.e. |
| 973 | { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } |
| 974 | Optional: |
| 975 | onosNode - ONOS node to install the intents in main.CLIs[ ] |
| 976 | 0 by default so that it will always use the first |
| 977 | ONOS node |
| 978 | ethType - Ethernet type eg. IPV4, IPV6 |
| 979 | bandwidth - Bandwidth capacity |
| 980 | lambdaAlloc - Allocate lambda, defaults to False |
| 981 | ipProto - IP protocol |
| 982 | tcp - TCP ports in the same order as the hosts in hostNames |
| 983 | sw1 - First switch to bring down & up for rerouting purpose |
| 984 | sw2 - Second switch to bring down & up for rerouting purpose |
| 985 | expectedLink - Expected link when the switches are down, it should |
| 986 | be two links lower than the links before the two |
| 987 | switches are down |
| 988 | |
| 989 | """ |
| 990 | |
| 991 | # Parameter Validity Check |
| 992 | assert main, "There is no main variable" |
| 993 | assert senders, "You must specify a sender" |
| 994 | assert recipients, "You must specify a recipient" |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 995 | |
| 996 | global itemName |
| 997 | itemName = name |
| 998 | tempHostsData = {} |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 999 | onosNode = int( onosNode ) |
| 1000 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1001 | main.log.info( itemName + ": Testing Point Intent" ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1002 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 1003 | try: |
| 1004 | # Names for scapy |
| 1005 | senderNames = [ x.get( "name" ) for x in senders ] |
| 1006 | recipientNames = [ x.get( "name" ) for x in recipients ] |
| 1007 | badSenderNames = [ x.get( "name" ) for x in badSenders ] |
| 1008 | badRecipientNames = [ x.get( "name" ) for x in badRecipients ] |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1009 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 1010 | for sender in senders: |
| 1011 | if not sender.get( "device" ): |
| 1012 | main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) ) |
| 1013 | sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1014 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 1015 | for recipient in recipients: |
| 1016 | if not recipient.get( "device" ): |
| 1017 | main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) ) |
| 1018 | recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" ) |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1019 | vlanId = senders[ 0 ].get( "vlan" ) |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 1020 | except (KeyError, TypeError): |
| 1021 | main.log.error( "There was a problem loading the hosts data." ) |
| 1022 | return main.FALSE |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1023 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1024 | testResult = main.TRUE |
| 1025 | main.log.info( itemName + ": Adding single point to multi point intents" ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1026 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1027 | # Check intent state |
| 1028 | if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ): |
| 1029 | main.assertReturnString += 'Initial Intent State Passed\n' |
acsmars | d4862d1 | 2015-10-06 17:57:34 -0700 | [diff] [blame] | 1030 | else: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1031 | main.assertReturnString += 'Initial Intent State Failed\n' |
| 1032 | testResult = main.FALSE |
| 1033 | |
| 1034 | # Check flows count in each node |
Jeremy | 03dab01 | 2016-04-11 08:59:17 -0700 | [diff] [blame] | 1035 | if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1036 | main.assertReturnString += 'Initial Flow State Passed\n' |
| 1037 | else: |
| 1038 | main.assertReturnString += 'Intial Flow State Failed\n' |
| 1039 | testResult = main.FALSE |
| 1040 | |
| 1041 | # Check Connectivity |
Jeremy Songster | e405d3d | 2016-05-17 11:18:57 -0700 | [diff] [blame] | 1042 | if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId, useTCP ), attempts=3, sleep=5 ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1043 | main.assertReturnString += 'Initial Ping Passed\n' |
| 1044 | else: |
| 1045 | main.assertReturnString += 'Initial Ping Failed\n' |
| 1046 | testResult = main.FALSE |
| 1047 | |
| 1048 | # Check connections that shouldn't work |
| 1049 | if badSenderNames: |
| 1050 | main.log.info( "Checking that packets from incorrect sender do not go through" ) |
| 1051 | if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, badSenderNames, recipientNames ), kwargs={ "expectFailure":True } ): |
| 1052 | main.assertReturnString += 'Bad Sender Ping Passed\n' |
| 1053 | else: |
| 1054 | main.assertReturnString += 'Bad Sender Ping Failed\n' |
| 1055 | testResult = main.FALSE |
| 1056 | |
| 1057 | if badRecipientNames: |
| 1058 | main.log.info( "Checking that packets to incorrect recipients do not go through" ) |
| 1059 | if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, badRecipientNames ), kwargs={ "expectFailure":True } ): |
| 1060 | main.assertReturnString += 'Bad Recipient Ping Passed\n' |
| 1061 | else: |
| 1062 | main.assertReturnString += 'Bad Recipient Ping Failed\n' |
| 1063 | testResult = main.FALSE |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1064 | |
| 1065 | # Test rerouting if these variables exist |
| 1066 | if sw1 and sw2 and expectedLink: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1067 | # Take link down |
| 1068 | if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ): |
acsmars | d4862d1 | 2015-10-06 17:57:34 -0700 | [diff] [blame] | 1069 | main.assertReturnString += 'Link Down Passed\n' |
| 1070 | else: |
| 1071 | main.assertReturnString += 'Link Down Failed\n' |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1072 | testResult = main.FALSE |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1073 | |
acsmars | d4862d1 | 2015-10-06 17:57:34 -0700 | [diff] [blame] | 1074 | # Check intent state |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1075 | if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ): |
acsmars | d4862d1 | 2015-10-06 17:57:34 -0700 | [diff] [blame] | 1076 | main.assertReturnString += 'Link Down Intent State Passed\n' |
| 1077 | else: |
| 1078 | main.assertReturnString += 'Link Down Intent State Failed\n' |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1079 | testResult = main.FALSE |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1080 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1081 | # Check flows count in each node |
Jeremy | 03dab01 | 2016-04-11 08:59:17 -0700 | [diff] [blame] | 1082 | if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1083 | main.assertReturnString += 'Link Down Flow State Passed\n' |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1084 | else: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1085 | main.assertReturnString += 'Link Down Flow State Failed\n' |
| 1086 | testResult = main.FALSE |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1087 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1088 | # Check OnosTopology |
| 1089 | if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink ) ): |
| 1090 | main.assertReturnString += 'Link Down Topology State Passed\n' |
| 1091 | else: |
| 1092 | main.assertReturnString += 'Link Down Topology State Failed\n' |
| 1093 | testResult = main.FALSE |
| 1094 | |
| 1095 | # Check Connection |
Jeremy Songster | e405d3d | 2016-05-17 11:18:57 -0700 | [diff] [blame] | 1096 | if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId, useTCP ) ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1097 | main.assertReturnString += 'Link Down Pingall Passed\n' |
| 1098 | else: |
| 1099 | main.assertReturnString += 'Link Down Pingall Failed\n' |
| 1100 | testResult = main.FALSE |
| 1101 | |
| 1102 | # Bring link up |
| 1103 | if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ): |
acsmars | d4862d1 | 2015-10-06 17:57:34 -0700 | [diff] [blame] | 1104 | main.assertReturnString += 'Link Up Passed\n' |
| 1105 | else: |
| 1106 | main.assertReturnString += 'Link Up Failed\n' |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1107 | testResult = main.FALSE |
acsmars | d4862d1 | 2015-10-06 17:57:34 -0700 | [diff] [blame] | 1108 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1109 | # Wait for reroute |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1110 | time.sleep( main.rerouteSleep ) |
| 1111 | |
acsmars | d4862d1 | 2015-10-06 17:57:34 -0700 | [diff] [blame] | 1112 | # Check Intents |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1113 | if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ): |
acsmars | d4862d1 | 2015-10-06 17:57:34 -0700 | [diff] [blame] | 1114 | main.assertReturnString += 'Link Up Intent State Passed\n' |
| 1115 | else: |
| 1116 | main.assertReturnString += 'Link Up Intent State Failed\n' |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1117 | testResult = main.FALSE |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1118 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1119 | # Check flows count in each node |
Jeremy | 03dab01 | 2016-04-11 08:59:17 -0700 | [diff] [blame] | 1120 | if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1121 | main.assertReturnString += 'Link Up Flow State Passed\n' |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1122 | else: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1123 | main.assertReturnString += 'Link Up Flow State Failed\n' |
| 1124 | testResult = main.FALSE |
| 1125 | |
| 1126 | # Check OnosTopology |
| 1127 | if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ): |
| 1128 | main.assertReturnString += 'Link Up Topology State Passed\n' |
| 1129 | else: |
| 1130 | main.assertReturnString += 'Link Up Topology State Failed\n' |
| 1131 | testResult = main.FALSE |
| 1132 | |
| 1133 | # Check Connection |
Jeremy Songster | e405d3d | 2016-05-17 11:18:57 -0700 | [diff] [blame] | 1134 | if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId, useTCP ) ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1135 | main.assertReturnString += 'Link Up Scapy Packet Received Passed\n' |
| 1136 | else: |
| 1137 | main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n' |
| 1138 | testResult = main.FALSE |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1139 | |
| 1140 | # Remove all intents |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1141 | if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ): |
acsmars | d4862d1 | 2015-10-06 17:57:34 -0700 | [diff] [blame] | 1142 | main.assertReturnString += 'Remove Intents Passed' |
| 1143 | else: |
| 1144 | main.assertReturnString += 'Remove Intents Failed' |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1145 | testResult = main.FALSE |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1146 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1147 | return testResult |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1148 | |
Jeremy | e0cb5eb | 2016-01-27 17:39:09 -0800 | [diff] [blame] | 1149 | def testEndPointFail( main, |
| 1150 | name, |
| 1151 | intentId, |
| 1152 | senders, |
| 1153 | recipients, |
| 1154 | isolatedSenders, |
| 1155 | isolatedRecipients, |
| 1156 | onosNode=0, |
| 1157 | ethType="", |
| 1158 | bandwidth="", |
| 1159 | lambdaAlloc=False, |
| 1160 | ipProto="", |
| 1161 | ipAddresses="", |
| 1162 | tcp="", |
| 1163 | sw1="", |
| 1164 | sw2="", |
| 1165 | sw3="", |
| 1166 | sw4="", |
| 1167 | sw5="", |
| 1168 | expectedLink1=0, |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1169 | expectedLink2=0, |
| 1170 | partial=False ): |
Jeremy | e0cb5eb | 2016-01-27 17:39:09 -0800 | [diff] [blame] | 1171 | """ |
| 1172 | Test Single to Multipoint Topology for Endpoint failures |
| 1173 | """ |
| 1174 | |
| 1175 | # Parameter Validity Check |
| 1176 | assert main, "There is no main variable" |
| 1177 | assert senders, "You must specify a sender" |
| 1178 | assert recipients, "You must specify a recipient" |
| 1179 | |
| 1180 | global itemName |
| 1181 | itemName = name |
| 1182 | tempHostsData = {} |
| 1183 | onosNode = int( onosNode ) |
| 1184 | |
| 1185 | main.log.info( itemName + ": Testing Point Intent" ) |
| 1186 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 1187 | try: |
| 1188 | # Names for scapy |
| 1189 | senderNames = [ x.get( "name" ) for x in senders ] |
| 1190 | recipientNames = [ x.get( "name" ) for x in recipients ] |
| 1191 | isolatedSenderNames = [ x.get( "name" ) for x in isolatedSenders ] |
| 1192 | isolatedRecipientNames = [ x.get( "name" ) for x in isolatedRecipients ] |
| 1193 | connectedSenderNames = [x.get("name") for x in senders if x.get("name") not in isolatedSenderNames] |
| 1194 | connectedRecipientNames = [x.get("name") for x in recipients if x.get("name") not in isolatedRecipientNames] |
Jeremy | e0cb5eb | 2016-01-27 17:39:09 -0800 | [diff] [blame] | 1195 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 1196 | for sender in senders: |
| 1197 | if not sender.get( "device" ): |
| 1198 | main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) ) |
| 1199 | sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" ) |
Jeremy | e0cb5eb | 2016-01-27 17:39:09 -0800 | [diff] [blame] | 1200 | |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 1201 | for recipient in recipients: |
| 1202 | if not recipient.get( "device" ): |
| 1203 | main.log.warn( "Device not given for recipient {0}. Loading from\ |
| 1204 | main.hostData".format( recipient.get( "name" ) ) ) |
| 1205 | recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" ) |
| 1206 | except (KeyError, TypeError): |
| 1207 | main.log.error( "There was a problem loading the hosts data." ) |
| 1208 | return main.FALSE |
Jeremy | e0cb5eb | 2016-01-27 17:39:09 -0800 | [diff] [blame] | 1209 | |
| 1210 | testResult = main.TRUE |
| 1211 | main.log.info( itemName + ": Adding multi point to single point intents" ) |
| 1212 | |
| 1213 | # Check intent state |
| 1214 | if utilities.retry( f=checkIntentState, retValue=main.FALSE, |
| 1215 | args=( main, [ intentId ] ), sleep=main.checkIntentSleep ): |
| 1216 | main.assertReturnString += 'Initial Intent State Passed\n' |
| 1217 | else: |
| 1218 | main.assertReturnString += 'Initial Intent State Failed\n' |
| 1219 | testResult = main.FALSE |
| 1220 | |
| 1221 | # Check flows count in each node |
| 1222 | if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1223 | args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState, |
| 1224 | retValue=main.FALSE, |
| 1225 | args=[ main ], attempts=5 ): |
Jeremy | e0cb5eb | 2016-01-27 17:39:09 -0800 | [diff] [blame] | 1226 | main.assertReturnString += 'Initial Flow State Passed\n' |
| 1227 | else: |
| 1228 | main.assertReturnString += 'Intial Flow State Failed\n' |
| 1229 | testResult = main.FALSE |
| 1230 | |
| 1231 | # Check Connectivity |
| 1232 | if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, |
| 1233 | args=( main, senderNames, recipientNames ) ): |
| 1234 | main.assertReturnString += 'Initial Connectivity Check Passed\n' |
| 1235 | else: |
| 1236 | main.assertReturnString += 'Initial Connectivity Check Failed\n' |
| 1237 | testResult = main.FALSE |
| 1238 | |
| 1239 | # Take two links down |
| 1240 | # Take first link down |
| 1241 | if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ): |
| 1242 | main.assertReturnString += 'Link Down Passed\n' |
| 1243 | else: |
| 1244 | main.assertReturnString += 'Link Down Failed\n' |
| 1245 | testResult = main.FALSE |
| 1246 | |
| 1247 | # Take second link down |
| 1248 | if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw4, "down" ) ): |
| 1249 | main.assertReturnString += 'Link Down Passed\n' |
| 1250 | else: |
| 1251 | main.assertReturnString += 'Link Down Failed\n' |
| 1252 | testResult = main.FALSE |
| 1253 | |
| 1254 | # Check intent state |
| 1255 | if utilities.retry( f=checkIntentState, retValue=main.FALSE, |
| 1256 | args=( main, [ intentId ] ), sleep=main.checkIntentSleep ): |
| 1257 | main.assertReturnString += 'Link Down Intent State Passed\n' |
| 1258 | else: |
| 1259 | main.assertReturnString += 'Link Down Intent State Failed\n' |
| 1260 | testResult = main.FALSE |
| 1261 | |
| 1262 | # Check flows count in each node |
| 1263 | if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, |
| 1264 | args=[ main ] ) and utilities.retry( f=checkFlowsState, |
| 1265 | retValue=main.FALSE, args=[ main ] ): |
| 1266 | main.assertReturnString += 'Link Down Flow State Passed\n' |
| 1267 | else: |
| 1268 | main.assertReturnString += 'Link Down Flow State Failed\n' |
| 1269 | testResult = main.FALSE |
| 1270 | |
| 1271 | # Check OnosTopology |
| 1272 | if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink1 ) ): |
| 1273 | main.assertReturnString += 'Link Down Topology State Passed\n' |
| 1274 | else: |
| 1275 | main.assertReturnString += 'Link Down Topology State Failed\n' |
| 1276 | testResult = main.FALSE |
| 1277 | |
| 1278 | # Check Connection |
| 1279 | if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, |
| 1280 | args=( main, senderNames, recipientNames ) ): |
| 1281 | main.assertReturnString += 'Link Down Connectivity Check Passed\n' |
| 1282 | else: |
| 1283 | main.assertReturnString += 'Link Down Connectivity Check Failed\n' |
| 1284 | testResult = main.FALSE |
| 1285 | |
| 1286 | # Take a third link down to isolate one node |
| 1287 | if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw5, "down" ) ): |
| 1288 | main.assertReturnString += 'Isolation link Down Passed\n' |
| 1289 | else: |
| 1290 | main.assertReturnString += 'Isolation link Down Failed\n' |
| 1291 | testResult = main.FALSE |
| 1292 | |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1293 | if partial: |
| 1294 | # Check intent state |
| 1295 | if utilities.retry( f=checkIntentState, retValue=main.FALSE, |
| 1296 | args=( main, [ intentId ] ), sleep=main.checkIntentSleep ): |
| 1297 | main.assertReturnString += 'Partial failure isolation link Down Intent State Passed\n' |
| 1298 | else: |
| 1299 | main.assertReturnString += 'Partial failure isolation link Down Intent State Failed\n' |
| 1300 | testResult = main.FALSE |
Jeremy | e0cb5eb | 2016-01-27 17:39:09 -0800 | [diff] [blame] | 1301 | |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1302 | # Check flows count in each node |
| 1303 | if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, |
| 1304 | args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState, |
| 1305 | retValue=main.FALSE, |
| 1306 | args=[ main ], attempts=5 ): |
| 1307 | main.assertReturnString += 'Partial failure isolation link Down Flow State Passed\n' |
| 1308 | else: |
| 1309 | main.assertReturnString += 'Partial failure isolation link Down Flow State Failed\n' |
| 1310 | testResult = main.FALSE |
Jeremy | e0cb5eb | 2016-01-27 17:39:09 -0800 | [diff] [blame] | 1311 | |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1312 | # Check OnosTopology |
| 1313 | if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink2 ) ): |
| 1314 | main.assertReturnString += 'Partial failure isolation link Down Topology State Passed\n' |
| 1315 | else: |
| 1316 | main.assertReturnString += 'Partial failure isolation link Down Topology State Failed\n' |
| 1317 | testResult = main.FALSE |
Jeremy | e0cb5eb | 2016-01-27 17:39:09 -0800 | [diff] [blame] | 1318 | |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1319 | # Check Connectivity |
| 1320 | # First check connectivity of any isolated senders to recipients |
| 1321 | if isolatedSenderNames: |
| 1322 | if scapyCheckConnection( main, isolatedSenderNames, recipientNames, None, None, None, None, main.TRUE ): |
| 1323 | main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n' |
| 1324 | else: |
| 1325 | main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n' |
| 1326 | testResult = main.FALSE |
| 1327 | |
| 1328 | # Next check connectivity of senders to any isolated recipients |
| 1329 | if isolatedRecipientNames: |
| 1330 | if scapyCheckConnection( main, senderNames, isolatedRecipientNames, None, None, None, None, main.TRUE ): |
| 1331 | main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n' |
| 1332 | else: |
| 1333 | main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n' |
| 1334 | testResult = main.FALSE |
| 1335 | |
| 1336 | # Next check connectivity of connected senders and recipients |
| 1337 | if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, |
| 1338 | args=( main, connectedSenderNames , connectedRecipientNames ) ): |
| 1339 | main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n' |
| 1340 | else: |
| 1341 | main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n' |
| 1342 | testResult = main.FALSE |
| 1343 | else: |
| 1344 | # Check intent state |
| 1345 | if not utilities.retry( f=checkIntentState, retValue=main.TRUE, |
| 1346 | args=( main, [ intentId ] ), sleep=main.checkIntentSleep ): |
| 1347 | main.assertReturnString += 'Isolation link Down Intent State Passed\n' |
| 1348 | else: |
| 1349 | main.assertReturnString += 'Isolation link Down Intent State Failed\n' |
| 1350 | testResult = main.FALSE |
| 1351 | |
| 1352 | # Check flows count in each node |
| 1353 | if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, |
| 1354 | args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState, |
| 1355 | retValue=main.FALSE, |
| 1356 | args=[ main ], attempts=5 ): |
| 1357 | main.assertReturnString += 'Isolation link Down Flow State Passed\n' |
| 1358 | else: |
| 1359 | main.assertReturnString += 'Isolation link Down Flow State Failed\n' |
| 1360 | testResult = main.FALSE |
| 1361 | |
| 1362 | # Check OnosTopology |
| 1363 | if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink2 ) ): |
| 1364 | main.assertReturnString += 'Isolation link Down Topology State Passed\n' |
| 1365 | else: |
| 1366 | main.assertReturnString += 'Isolation link Down Topology State Failed\n' |
| 1367 | testResult = main.FALSE |
| 1368 | |
| 1369 | # Check Connectivity |
| 1370 | # First check connectivity of any isolated senders to recipients |
| 1371 | if isolatedSenderNames: |
| 1372 | if scapyCheckConnection( main, isolatedSenderNames, recipientNames, None, None, None, None, main.TRUE ): |
| 1373 | main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n' |
| 1374 | else: |
| 1375 | main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n' |
| 1376 | testResult = main.FALSE |
| 1377 | |
| 1378 | # Next check connectivity of senders to any isolated recipients |
| 1379 | if isolatedRecipientNames: |
| 1380 | if scapyCheckConnection( main, senderNames, isolatedRecipientNames, None, None, None, None, main.TRUE ): |
| 1381 | main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n' |
| 1382 | else: |
| 1383 | main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n' |
| 1384 | testResult = main.FALSE |
| 1385 | |
| 1386 | # Next check connectivity of connected senders and recipients |
| 1387 | if utilities.retry( f=scapyCheckConnection, retValue=main.TRUE, |
| 1388 | args=( main, connectedSenderNames , connectedRecipientNames, None, None, None, None, main.TRUE ) ): |
Jeremy | e0cb5eb | 2016-01-27 17:39:09 -0800 | [diff] [blame] | 1389 | main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n' |
| 1390 | else: |
| 1391 | main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n' |
| 1392 | testResult = main.FALSE |
| 1393 | |
Jeremy | e0cb5eb | 2016-01-27 17:39:09 -0800 | [diff] [blame] | 1394 | # Bring the links back up |
| 1395 | # Bring first link up |
| 1396 | if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ): |
| 1397 | main.assertReturnString += 'Link Up Passed\n' |
| 1398 | else: |
| 1399 | main.assertReturnString += 'Link Up Failed\n' |
| 1400 | testResult = main.FALSE |
| 1401 | |
| 1402 | # Bring second link up |
| 1403 | if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw5, "up" ) ): |
| 1404 | main.assertReturnString += 'Link Up Passed\n' |
| 1405 | else: |
| 1406 | main.assertReturnString += 'Link Up Failed\n' |
| 1407 | testResult = main.FALSE |
| 1408 | |
| 1409 | # Bring third link up |
| 1410 | if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw4, "up" ) ): |
| 1411 | main.assertReturnString += 'Link Up Passed\n' |
| 1412 | else: |
| 1413 | main.assertReturnString += 'Link Up Failed\n' |
| 1414 | testResult = main.FALSE |
| 1415 | |
| 1416 | # Wait for reroute |
| 1417 | time.sleep( main.rerouteSleep ) |
| 1418 | |
| 1419 | # Check Intents |
| 1420 | if utilities.retry( f=checkIntentState, retValue=main.FALSE, |
| 1421 | args=( main, [ intentId ] ), sleep=main.checkIntentSleep ): |
| 1422 | main.assertReturnString += 'Link Up Intent State Passed\n' |
| 1423 | else: |
| 1424 | main.assertReturnString += 'Link Up Intent State Failed\n' |
| 1425 | testResult = main.FALSE |
| 1426 | |
| 1427 | # Check flows count in each node |
| 1428 | if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1429 | args=[ main ], sleep=5, attempts=5 ) and utilities.retry( f=checkFlowsState, |
| 1430 | retValue=main.FALSE, |
| 1431 | args=[ main ], sleep=5, attempts=5 ): |
Jeremy | e0cb5eb | 2016-01-27 17:39:09 -0800 | [diff] [blame] | 1432 | main.assertReturnString += 'Link Up Flow State Passed\n' |
| 1433 | else: |
| 1434 | main.assertReturnString += 'Link Up Flow State Failed\n' |
| 1435 | testResult = main.FALSE |
| 1436 | |
| 1437 | # Check OnosTopology |
| 1438 | if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ): |
| 1439 | main.assertReturnString += 'Link Up Topology State Passed\n' |
| 1440 | else: |
| 1441 | main.assertReturnString += 'Link Up Topology State Failed\n' |
| 1442 | testResult = main.FALSE |
| 1443 | |
| 1444 | # Check Connection |
| 1445 | if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, |
| 1446 | args=( main, senderNames, recipientNames ) ): |
| 1447 | main.assertReturnString += 'Link Up Scapy Packet Received Passed\n' |
| 1448 | else: |
| 1449 | main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n' |
| 1450 | testResult = main.FALSE |
| 1451 | |
| 1452 | # Remove all intents |
| 1453 | if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ): |
| 1454 | main.assertReturnString += 'Remove Intents Passed' |
| 1455 | else: |
| 1456 | main.assertReturnString += 'Remove Intents Failed' |
| 1457 | testResult = main.FALSE |
| 1458 | |
| 1459 | return testResult |
| 1460 | |
| 1461 | |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 1462 | def pingallHosts( main, hostList ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1463 | """ |
| 1464 | Ping all host in the hosts list variable |
| 1465 | """ |
Jon Hall | a5cb341 | 2015-08-18 14:08:22 -0700 | [diff] [blame] | 1466 | main.log.info( "Pinging: " + str( hostList ) ) |
| 1467 | return main.Mininet1.pingallHosts( hostList ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1468 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1469 | def fwdPingall( main ): |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1470 | """ |
| 1471 | Use fwd app and pingall to discover all the hosts |
| 1472 | """ |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1473 | activateResult = main.TRUE |
| 1474 | appCheck = main.TRUE |
| 1475 | getDataResult = main.TRUE |
| 1476 | main.log.info( "Activating reactive forwarding app " ) |
| 1477 | activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1478 | |
| 1479 | # Wait for forward app activation to propagate |
kelvin-onlab | 0ad05d1 | 2015-07-23 14:21:15 -0700 | [diff] [blame] | 1480 | time.sleep( main.fwdSleep ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1481 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1482 | # Check that forwarding is enabled on all nodes |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1483 | for i in range( main.numCtrls ): |
| 1484 | appCheck = appCheck and main.CLIs[ i ].appToIDCheck() |
| 1485 | if appCheck != main.TRUE: |
| 1486 | main.log.warn( main.CLIs[ i ].apps() ) |
| 1487 | main.log.warn( main.CLIs[ i ].appIDs() ) |
| 1488 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1489 | # Send pingall in mininet |
| 1490 | main.log.info( "Run Pingall" ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1491 | pingResult = main.Mininet1.pingall( timeout = 600 ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1492 | |
| 1493 | main.log.info( "Deactivating reactive forwarding app " ) |
| 1494 | deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1495 | if activateResult and deactivateResult: |
| 1496 | main.log.info( "Successfully used fwd app to discover hosts" ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1497 | getDataResult = main.TRUE |
| 1498 | else: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1499 | main.log.info( "Failed to use fwd app to discover hosts" ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1500 | getDataResult = main.FALSE |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1501 | return getDataResult |
| 1502 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1503 | def confirmHostDiscovery( main ): |
| 1504 | """ |
| 1505 | Confirms that all ONOS nodes have discovered all scapy hosts |
| 1506 | """ |
| 1507 | import collections |
| 1508 | scapyHostCount = len( main.scapyHosts ) |
| 1509 | hosts = main.topo.getAllHosts( main ) # Get host data from each ONOS node |
| 1510 | hostFails = [] # Reset for each failed attempt |
| 1511 | |
| 1512 | # Check for matching hosts on each node |
| 1513 | scapyHostIPs = [ x.hostIp for x in main.scapyHosts if x.hostIp != "0.0.0.0" ] |
| 1514 | for controller in range( main.numCtrls ): |
| 1515 | controllerStr = str( controller + 1 ) # ONOS node number |
| 1516 | # Compare Hosts |
| 1517 | # Load hosts data for controller node |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 1518 | try: |
| 1519 | if hosts[ controller ]: |
| 1520 | main.log.info( "Hosts discovered" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1521 | else: |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 1522 | main.log.error( "Problem discovering hosts" ) |
| 1523 | if hosts[ controller ] and "Error" not in hosts[ controller ]: |
| 1524 | try: |
| 1525 | hostData = json.loads( hosts[ controller ] ) |
| 1526 | except ( TypeError, ValueError ): |
| 1527 | main.log.error( "Could not load json:" + str( hosts[ controller ] ) ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1528 | hostFails.append( controllerStr ) |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 1529 | else: |
| 1530 | onosHostIPs = [ x.get( "ipAddresses" )[ 0 ] |
| 1531 | for x in hostData |
| 1532 | if len( x.get( "ipAddresses" ) ) > 0 ] |
| 1533 | if not set( collections.Counter( scapyHostIPs ) ).issubset( set ( collections.Counter( onosHostIPs ) ) ): |
| 1534 | main.log.warn( "Controller {0} only sees nodes with {1} IPs. It should see all of the following: {2}".format( controllerStr, onosHostIPs, scapyHostIPs ) ) |
| 1535 | hostFails.append( controllerStr ) |
| 1536 | else: |
| 1537 | main.log.error( "Hosts returned nothing or an error." ) |
| 1538 | hostFails.append( controllerStr ) |
| 1539 | except IndexError: |
| 1540 | main.log.error( "Hosts returned nothing, Failed to discover hosts." ) |
| 1541 | return main.FALSE |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1542 | |
| 1543 | if hostFails: |
| 1544 | main.log.error( "List of failed ONOS Nodes:" + ', '.join(map(str, hostFails )) ) |
| 1545 | return main.FALSE |
| 1546 | else: |
| 1547 | return main.TRUE |
| 1548 | |
| 1549 | def sendDiscoveryArp( main, hosts=None ): |
| 1550 | """ |
| 1551 | Sends Discovery ARP packets from each host provided |
| 1552 | Defaults to each host in main.scapyHosts |
| 1553 | """ |
| 1554 | # Send an arp ping from each host |
| 1555 | if not hosts: |
| 1556 | hosts = main.scapyHosts |
| 1557 | for host in hosts: |
| 1558 | pkt = 'Ether( src="{0}")/ARP( psrc="{1}")'.format( host.hostMac ,host.hostIp ) |
| 1559 | # Send from the VLAN interface if there is one so ONOS discovers the VLAN correctly |
| 1560 | iface = None |
| 1561 | for interface in host.getIfList(): |
| 1562 | if '.' in interface: |
| 1563 | main.log.debug( "Detected VLAN interface {0}. Sending ARP packet from {0}".format( interface ) ) |
| 1564 | iface = interface |
| 1565 | break |
| 1566 | host.sendPacket( packet=pkt, iface=iface ) |
| 1567 | main.log.info( "Sending ARP packet from {0}".format( host.name ) ) |
| 1568 | |
| 1569 | def populateHostData( main ): |
| 1570 | """ |
| 1571 | Populates hostsData |
| 1572 | """ |
| 1573 | import json |
| 1574 | try: |
| 1575 | hostsJson = json.loads( main.CLIs[ 0 ].hosts() ) |
| 1576 | hosts = main.Mininet1.getHosts().keys() |
| 1577 | # TODO: Make better use of new getHosts function |
| 1578 | for host in hosts: |
| 1579 | main.hostsData[ host ] = {} |
| 1580 | main.hostsData[ host ][ 'mac' ] = \ |
| 1581 | main.Mininet1.getMacAddress( host ).upper() |
| 1582 | for hostj in hostsJson: |
| 1583 | if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]: |
| 1584 | main.hostsData[ host ][ 'id' ] = hostj[ 'id' ] |
| 1585 | main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ] |
| 1586 | main.hostsData[ host ][ 'location' ] = \ |
| 1587 | hostj[ 'location' ][ 'elementId' ] + '/' + \ |
| 1588 | hostj[ 'location' ][ 'port' ] |
| 1589 | main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ] |
| 1590 | return main.TRUE |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 1591 | except ValueError: |
| 1592 | main.log.error( "ValueError while populating hostsData" ) |
| 1593 | return main.FALSE |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1594 | except KeyError: |
| 1595 | main.log.error( "KeyError while populating hostsData") |
| 1596 | return main.FALSE |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 1597 | except IndexError: |
| 1598 | main.log.error( "IndexError while populating hostsData" ) |
| 1599 | return main.FALSE |
| 1600 | except TypeError: |
| 1601 | main.log.error( "TypeError while populating hostsData" ) |
| 1602 | return main.FALSE |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1603 | |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1604 | def checkTopology( main, expectedLink ): |
| 1605 | statusResult = main.TRUE |
| 1606 | # Check onos topology |
| 1607 | main.log.info( itemName + ": Checking ONOS topology " ) |
| 1608 | |
| 1609 | for i in range( main.numCtrls ): |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 1610 | statusResult = main.CLIs[ i ].checkStatus( main.numSwitch, |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1611 | expectedLink )\ |
| 1612 | and statusResult |
| 1613 | if not statusResult: |
| 1614 | main.log.error( itemName + ": Topology mismatch" ) |
| 1615 | else: |
| 1616 | main.log.info( itemName + ": Topology match" ) |
| 1617 | return statusResult |
| 1618 | |
| 1619 | def checkIntentState( main, intentsId ): |
| 1620 | """ |
| 1621 | This function will check intent state to make sure all the intents |
| 1622 | are in INSTALLED state |
| 1623 | """ |
| 1624 | |
| 1625 | intentResult = main.TRUE |
| 1626 | results = [] |
| 1627 | |
| 1628 | main.log.info( itemName + ": Checking intents state" ) |
| 1629 | # First check of intents |
| 1630 | for i in range( main.numCtrls ): |
| 1631 | tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId ) |
| 1632 | results.append( tempResult ) |
| 1633 | |
| 1634 | expectedState = [ 'INSTALLED', 'INSTALLING' ] |
| 1635 | |
| 1636 | if all( result == main.TRUE for result in results ): |
| 1637 | main.log.info( itemName + ": Intents are installed correctly" ) |
| 1638 | else: |
| 1639 | # Wait for at least 5 second before checking the intents again |
acsmars | b9a9269 | 2015-10-08 16:43:01 -0700 | [diff] [blame] | 1640 | main.log.error( "Intents are not installed correctly. Waiting 5 sec" ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1641 | time.sleep( 5 ) |
| 1642 | results = [] |
| 1643 | # Second check of intents since some of the intents may be in |
| 1644 | # INSTALLING state, they should be in INSTALLED at this time |
| 1645 | for i in range( main.numCtrls ): |
Jeremy | 2f190ca | 2016-01-29 15:23:57 -0800 | [diff] [blame] | 1646 | tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1647 | results.append( tempResult ) |
| 1648 | if all( result == main.TRUE for result in results ): |
| 1649 | main.log.info( itemName + ": Intents are installed correctly" ) |
acsmars | b9a9269 | 2015-10-08 16:43:01 -0700 | [diff] [blame] | 1650 | intentResult = main.TRUE |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1651 | else: |
| 1652 | main.log.error( itemName + ": Intents are NOT installed correctly" ) |
| 1653 | intentResult = main.FALSE |
| 1654 | |
| 1655 | return intentResult |
| 1656 | |
| 1657 | def checkFlowsState( main ): |
| 1658 | |
| 1659 | main.log.info( itemName + ": Check flows state" ) |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1660 | checkFlowsResult = main.CLIs[ 0 ].checkFlowsState( isPENDING=False ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1661 | return checkFlowsResult |
| 1662 | |
| 1663 | def link( main, sw1, sw2, option): |
| 1664 | |
| 1665 | # link down |
| 1666 | main.log.info( itemName + ": Bring link " + option + "between " + |
| 1667 | sw1 + " and " + sw2 ) |
| 1668 | linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option ) |
| 1669 | return linkResult |
| 1670 | |
Jeremy Songster | e405d3d | 2016-05-17 11:18:57 -0700 | [diff] [blame] | 1671 | def scapyCheckConnection( main, senders, recipients, vlanId=None, useTCP=False, packet=None, packetFilter=None, expectFailure=False ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1672 | """ |
| 1673 | Checks the connectivity between all given sender hosts and all given recipient hosts |
| 1674 | Packet may be specified. Defaults to Ether/IP packet |
| 1675 | Packet Filter may be specified. Defaults to Ether/IP from current sender MAC |
| 1676 | Todo: Optional packet and packet filter attributes for sender and recipients |
| 1677 | Expect Failure when the sender and recipient are not supposed to have connectivity |
| 1678 | Timeout of 1 second, returns main.TRUE if the filter is not triggered and kills the filter |
| 1679 | |
| 1680 | """ |
| 1681 | connectionsFunctional = main.TRUE |
| 1682 | |
| 1683 | if not packetFilter: |
| 1684 | packetFilter = 'ether host {}' |
Jeremy Songster | e405d3d | 2016-05-17 11:18:57 -0700 | [diff] [blame] | 1685 | if useTCP: |
| 1686 | packetFilter += ' ip proto \\tcp tcp port {}'.format(main.params[ 'SDNIP' ][ 'dstPort' ]) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1687 | if expectFailure: |
| 1688 | timeout = 1 |
| 1689 | else: |
| 1690 | timeout = 10 |
| 1691 | |
| 1692 | for sender in senders: |
| 1693 | try: |
| 1694 | senderComp = getattr( main, sender ) |
| 1695 | except AttributeError: |
| 1696 | main.log.error( "main has no attribute {}".format( sender ) ) |
| 1697 | connectionsFunctional = main.FALSE |
| 1698 | continue |
| 1699 | |
| 1700 | for recipient in recipients: |
| 1701 | # Do not send packets to self since recipient CLI will already be busy |
| 1702 | if recipient == sender: |
| 1703 | continue |
| 1704 | try: |
| 1705 | recipientComp = getattr( main, recipient ) |
| 1706 | except AttributeError: |
| 1707 | main.log.error( "main has no attribute {}".format( recipient ) ) |
| 1708 | connectionsFunctional = main.FALSE |
| 1709 | continue |
| 1710 | |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1711 | if vlanId: |
| 1712 | recipientComp.startFilter( pktFilter = ( "vlan {}".format( vlanId ) + " && " + packetFilter.format( senderComp.hostMac ) ) ) |
| 1713 | else: |
| 1714 | recipientComp.startFilter( pktFilter = packetFilter.format( senderComp.hostMac ) ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1715 | |
| 1716 | if not packet: |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1717 | if vlanId: |
| 1718 | pkt = 'Ether( src="{0}", dst="{2}" )/Dot1Q(vlan={4})/IP( src="{1}", dst="{3}" )'.format( |
| 1719 | senderComp.hostMac, |
| 1720 | senderComp.hostIp, |
| 1721 | recipientComp.hostMac, |
| 1722 | recipientComp.hostIp, |
| 1723 | vlanId ) |
| 1724 | else: |
| 1725 | pkt = 'Ether( src="{0}", dst="{2}" )/IP( src="{1}", dst="{3}" )'.format( |
| 1726 | senderComp.hostMac, |
| 1727 | senderComp.hostIp, |
| 1728 | recipientComp.hostMac, |
| 1729 | recipientComp.hostIp ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1730 | else: |
| 1731 | pkt = packet |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1732 | if vlanId: |
| 1733 | senderComp.sendPacket( iface=( "{0}-eth0.{1}".format( sender, vlanId ) ), packet = pkt ) |
| 1734 | else: |
| 1735 | senderComp.sendPacket( packet = pkt ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1736 | |
| 1737 | if recipientComp.checkFilter( timeout ): |
| 1738 | if expectFailure: |
| 1739 | main.log.error( "Packet from {0} successfully received by {1} when it should not have been".format( sender , recipient ) ) |
| 1740 | connectionsFunctional = main.FALSE |
| 1741 | else: |
| 1742 | main.log.info( "Packet from {0} successfully received by {1}".format( sender , recipient ) ) |
| 1743 | else: |
| 1744 | recipientComp.killFilter() |
| 1745 | if expectFailure: |
| 1746 | main.log.info( "As expected, packet from {0} was not received by {1}".format( sender , recipient ) ) |
| 1747 | else: |
| 1748 | main.log.error( "Packet from {0} was not received by {1}".format( sender , recipient ) ) |
| 1749 | connectionsFunctional = main.FALSE |
| 1750 | |
| 1751 | return connectionsFunctional |
| 1752 | |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1753 | def removeAllIntents( main, intentsId ): |
| 1754 | """ |
| 1755 | Remove all intents in the intentsId |
| 1756 | """ |
| 1757 | |
kelvin-onlab | 5c706ff | 2015-07-20 10:56:52 -0700 | [diff] [blame] | 1758 | onosSummary = [] |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1759 | removeIntentResult = main.TRUE |
| 1760 | # Remove intents |
| 1761 | for intent in intentsId: |
| 1762 | main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True ) |
| 1763 | |
acsmars | cfa5227 | 2015-08-06 15:21:45 -0700 | [diff] [blame] | 1764 | time.sleep( main.removeIntentSleep ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1765 | |
kelvin-onlab | 5c706ff | 2015-07-20 10:56:52 -0700 | [diff] [blame] | 1766 | # If there is remianing intents then remove intents should fail |
| 1767 | for i in range( main.numCtrls ): |
| 1768 | onosSummary.append( json.loads( main.CLIs[ i ].summary() ) ) |
| 1769 | |
| 1770 | for summary in onosSummary: |
| 1771 | if summary.get( 'intents' ) != 0: |
| 1772 | main.log.warn( itemName + ": There are " + |
| 1773 | str( summary.get( 'intents' ) ) + |
| 1774 | " intents remaining in node " + |
| 1775 | str( summary.get( 'node' ) ) + |
| 1776 | ", failed to remove all the intents " ) |
| 1777 | removeIntentResult = main.FALSE |
| 1778 | |
| 1779 | if removeIntentResult: |
| 1780 | main.log.info( itemName + ": There are no more intents remaining, " + |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1781 | "successfully removed all the intents." ) |
kelvin-onlab | 5c706ff | 2015-07-20 10:56:52 -0700 | [diff] [blame] | 1782 | |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1783 | return removeIntentResult |
| 1784 | |
| 1785 | def checkFlowsCount( main ): |
| 1786 | """ |
| 1787 | Check flows count in each node |
| 1788 | """ |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1789 | flowsCount = [] |
| 1790 | main.log.info( itemName + ": Checking flows count in each ONOS node" ) |
| 1791 | for i in range( main.numCtrls ): |
| 1792 | summaryResult = main.CLIs[ i ].summary() |
| 1793 | if not summaryResult: |
| 1794 | main.log.error( itemName + ": There is something wrong with " + |
| 1795 | "summary command" ) |
| 1796 | return main.FALSE |
| 1797 | else: |
| 1798 | summaryJson = json.loads( summaryResult ) |
| 1799 | flowsCount.append( summaryJson.get( 'flows' ) ) |
| 1800 | |
| 1801 | if flowsCount: |
| 1802 | if all( flows==flowsCount[ 0 ] for flows in flowsCount ): |
| 1803 | main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) + |
| 1804 | " flows in all ONOS node" ) |
| 1805 | else: |
| 1806 | for i in range( main.numCtrls ): |
| 1807 | main.log.debug( itemName + ": ONOS node " + str( i ) + " has " + |
kelvin-onlab | 6dea6e6 | 2015-07-23 13:07:26 -0700 | [diff] [blame] | 1808 | str( flowsCount[ i ] ) + " flows" ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 1809 | else: |
| 1810 | main.log.error( "Checking flows count failed, check summary command" ) |
| 1811 | return main.FALSE |
| 1812 | |
| 1813 | return main.TRUE |
| 1814 | |
kelvin-onlab | 58dc39e | 2015-08-06 08:11:09 -0700 | [diff] [blame] | 1815 | def checkLeaderChange( leaders1, leaders2 ): |
acsmars | e6b410f | 2015-07-17 14:39:34 -0700 | [diff] [blame] | 1816 | """ |
| 1817 | Checks for a change in intent partition leadership. |
| 1818 | |
| 1819 | Takes the output of leaders -c in json string format before and after |
| 1820 | a potential change as input |
| 1821 | |
| 1822 | Returns main.TRUE if no mismatches are detected |
| 1823 | Returns main.FALSE if there is a mismatch or on error loading the input |
| 1824 | """ |
| 1825 | try: |
| 1826 | leaders1 = json.loads( leaders1 ) |
| 1827 | leaders2 = json.loads( leaders2 ) |
| 1828 | except ( AttributeError, TypeError): |
| 1829 | main.log.exception( self.name + ": Object not as expected" ) |
| 1830 | return main.FALSE |
| 1831 | except Exception: |
| 1832 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1833 | main.cleanup() |
| 1834 | main.exit() |
| 1835 | main.log.info( "Checking Intent Paritions for Change in Leadership" ) |
| 1836 | mismatch = False |
| 1837 | for dict1 in leaders1: |
| 1838 | if "intent" in dict1.get( "topic", [] ): |
| 1839 | for dict2 in leaders2: |
| 1840 | if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \ |
| 1841 | dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ): |
| 1842 | mismatch = True |
| 1843 | main.log.error( "{0} changed leader from {1} to {2}".\ |
| 1844 | format( dict1.get( "topic", "no-topic" ),\ |
| 1845 | dict1.get( "leader", "no-leader" ),\ |
| 1846 | dict2.get( "leader", "no-leader" ) ) ) |
| 1847 | if mismatch: |
| 1848 | return main.FALSE |
| 1849 | else: |
| 1850 | return main.TRUE |
kelvin-onlab | 016dce2 | 2015-08-10 09:54:11 -0700 | [diff] [blame] | 1851 | |
| 1852 | def report( main ): |
| 1853 | """ |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1854 | Report errors/warnings/exceptions |
kelvin-onlab | 016dce2 | 2015-08-10 09:54:11 -0700 | [diff] [blame] | 1855 | """ |
kelvin-onlab | 016dce2 | 2015-08-10 09:54:11 -0700 | [diff] [blame] | 1856 | main.ONOSbench.logReport( main.ONOSip[ 0 ], |
| 1857 | [ "INFO", |
| 1858 | "FOLLOWER", |
| 1859 | "WARN", |
| 1860 | "flow", |
| 1861 | "ERROR", |
| 1862 | "Except" ], |
| 1863 | "s" ) |
| 1864 | |
| 1865 | main.log.info( "ERROR report: \n" ) |
| 1866 | for i in range( main.numCtrls ): |
| 1867 | main.ONOSbench.logReport( main.ONOSip[ i ], |
| 1868 | [ "ERROR" ], |
| 1869 | "d" ) |
| 1870 | |
| 1871 | main.log.info( "EXCEPTIONS report: \n" ) |
| 1872 | for i in range( main.numCtrls ): |
| 1873 | main.ONOSbench.logReport( main.ONOSip[ i ], |
| 1874 | [ "Except" ], |
| 1875 | "d" ) |
| 1876 | |
| 1877 | main.log.info( "WARNING report: \n" ) |
| 1878 | for i in range( main.numCtrls ): |
| 1879 | main.ONOSbench.logReport( main.ONOSip[ i ], |
| 1880 | [ "WARN" ], |
| 1881 | "d" ) |