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