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