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