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