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