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