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