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