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