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