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