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