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