Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1 | """ |
| 2 | Wrapper functions for FuncIntent |
| 3 | This functions include Onosclidriver and Mininetclidriver driver functions |
| 4 | Author: subhash_singh@criterionnetworks.com |
| 5 | """ |
| 6 | import time |
| 7 | import copy |
| 8 | import json |
| 9 | |
| 10 | def __init__( self ): |
| 11 | self.default = '' |
| 12 | |
| 13 | def hostIntent( main, |
| 14 | name, |
| 15 | host1, |
| 16 | host2, |
| 17 | onosNode=0, |
| 18 | host1Id="", |
| 19 | host2Id="", |
| 20 | mac1="", |
| 21 | mac2="", |
| 22 | vlan1="-1", |
| 23 | vlan2="-1", |
| 24 | sw1="", |
| 25 | sw2="", |
| 26 | expectedLink=0 ): |
| 27 | """ |
| 28 | Description: |
| 29 | Verify add-host-intent |
| 30 | Steps: |
| 31 | - Discover hosts |
| 32 | - Add host intents |
| 33 | - Check intents |
| 34 | - Verify flows |
| 35 | - Ping hosts |
| 36 | - Reroute |
| 37 | - Link down |
| 38 | - Verify flows |
| 39 | - Check topology |
| 40 | - Ping hosts |
| 41 | - Link up |
| 42 | - Verify flows |
| 43 | - Check topology |
| 44 | - Ping hosts |
| 45 | - Remove intents |
| 46 | Required: |
| 47 | name - Type of host intent to add eg. IPV4 | VLAN | Dualstack |
| 48 | host1 - Name of first host |
| 49 | host2 - Name of second host |
| 50 | Optional: |
| 51 | onosNode - ONOS node to install the intents in main.CLIs[ ] |
| 52 | 0 by default so that it will always use the first |
| 53 | ONOS node |
| 54 | host1Id - ONOS id of the first host eg. 00:00:00:00:00:01/-1 |
| 55 | host2Id - ONOS id of the second host |
| 56 | mac1 - Mac address of first host |
| 57 | mac2 - Mac address of the second host |
| 58 | vlan1 - Vlan tag of first host, defaults to -1 |
| 59 | vlan2 - Vlan tag of second host, defaults to -1 |
| 60 | sw1 - First switch to bring down & up for rerouting purpose |
| 61 | sw2 - Second switch to bring down & up for rerouting purpose |
| 62 | expectedLink - Expected link when the switches are down, it should |
| 63 | be two links lower than the links before the two |
| 64 | switches are down |
| 65 | Return: |
| 66 | Returns main.TRUE if all verification passed, otherwise return |
| 67 | main.FALSE; returns main.FALSE if there is a key error |
| 68 | """ |
| 69 | |
| 70 | # Assert variables |
| 71 | assert main, "There is no main variable" |
| 72 | assert name, "variable name is empty" |
| 73 | assert host1 and host2, "You must specify hosts" |
| 74 | |
| 75 | global itemName |
| 76 | itemName = name |
| 77 | h1Id = host1Id |
| 78 | h2Id = host2Id |
| 79 | h1Mac = mac1 |
| 80 | h2Mac = mac2 |
| 81 | vlan1 = vlan1 |
| 82 | vlan2 = vlan2 |
| 83 | hostNames = [ host1 , host2 ] |
| 84 | intentsId = [] |
| 85 | stepResult = main.TRUE |
| 86 | pingResult = main.TRUE |
| 87 | intentResult = main.TRUE |
| 88 | removeIntentResult = main.TRUE |
| 89 | flowResult = main.TRUE |
| 90 | topoResult = main.TRUE |
| 91 | linkDownResult = main.TRUE |
| 92 | linkUpResult = main.TRUE |
| 93 | onosNode = int( onosNode ) |
| 94 | |
| 95 | try: |
| 96 | if main.hostsData: |
| 97 | if not h1Mac: |
| 98 | h1Mac = main.hostsData[ host1 ][ 'mac' ] |
| 99 | if not h2Mac: |
| 100 | h2Mac = main.hostsData[ host2 ][ 'mac' ] |
| 101 | if main.hostsData[ host1 ].get( 'vlan' ): |
| 102 | vlan1 = main.hostsData[ host1 ][ 'vlan' ] |
| 103 | if main.hostsData[ host1 ].get( 'vlan' ): |
| 104 | vlan2 = main.hostsData[ host2 ][ 'vlan' ] |
| 105 | if not h1Id: |
| 106 | h1Id = main.hostsData[ host1 ][ 'id' ] |
| 107 | if not h2Id: |
| 108 | h2Id = main.hostsData[ host2 ][ 'id' ] |
| 109 | |
| 110 | assert h1Id and h2Id, "You must specify host IDs" |
| 111 | if not ( h1Id and h2Id ): |
| 112 | main.log.info( "There are no host IDs" ) |
| 113 | return main.FALSE |
| 114 | |
| 115 | except KeyError: |
| 116 | main.log.error( itemName + ": Key error Exception" ) |
| 117 | return main.FALSE |
| 118 | |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 119 | # Check flows count in each node |
| 120 | checkFlowsCount( main ) |
| 121 | |
| 122 | # Adding host intents |
| 123 | main.log.info( itemName + ": Adding host intents" ) |
| 124 | intent1 = main.CLIs[ onosNode ].addHostIntent( hostIdOne=h1Id, |
| 125 | hostIdTwo=h2Id ) |
| 126 | intentsId.append( intent1 ) |
| 127 | |
| 128 | # Check intents state |
| 129 | time.sleep( main.checkIntentSleep ) |
| 130 | intentResult = checkIntentState( main, intentsId ) |
| 131 | checkFlowsCount( main ) |
| 132 | |
| 133 | # Check intents state again if first check fails... |
| 134 | if not intentResult: |
| 135 | intentResult = checkIntentState( main, intentsId ) |
| 136 | |
| 137 | # Check flows count in each node |
| 138 | checkFlowsCount( main ) |
| 139 | # Verify flows |
| 140 | checkFlowsState( main ) |
| 141 | |
| 142 | # Ping hosts |
sathishm | ad95346 | 2015-12-03 17:42:07 +0530 | [diff] [blame] | 143 | firstPingResult = main.Mininet1.ping6pair(SRC=hostNames[0], TARGET=main.hostsData[ host2 ][ 'ipAddresses' ][ 0 ]) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 144 | if not firstPingResult: |
| 145 | main.log.debug( "First ping failed, there must be" + |
| 146 | " something wrong with ONOS performance" ) |
| 147 | |
| 148 | # Ping hosts again... |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 149 | pingTemp = ping6allHosts( main, hostNames ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 150 | pingResult = pingResult and pingTemp |
| 151 | if pingTemp: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 152 | main.assertReturnString += 'Initial Ping6all Passed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 153 | else: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 154 | main.assertReturnString += 'Initial Ping6all Failed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 155 | |
| 156 | # Test rerouting if these variables exist |
| 157 | if sw1 and sw2 and expectedLink: |
| 158 | # Link down |
| 159 | linkDownResult = link( main, sw1, sw2, "down" ) |
| 160 | |
| 161 | if linkDownResult: |
| 162 | main.assertReturnString += 'Link Down Passed\n' |
| 163 | else: |
| 164 | main.assertReturnString += 'Link Down Failed\n' |
| 165 | |
| 166 | # Check flows count in each node |
| 167 | checkFlowsCount( main ) |
| 168 | # Verify flows |
| 169 | checkFlowsState( main ) |
| 170 | |
| 171 | # Check OnosTopology |
| 172 | topoResult = checkTopology( main, expectedLink ) |
| 173 | if topoResult: |
| 174 | main.assertReturnString += 'Link Down Topology State Passed\n' |
| 175 | else: |
| 176 | main.assertReturnString += 'Link Down Topology State Failed\n' |
| 177 | |
| 178 | # Ping hosts |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 179 | pingTemp = ping6allHosts( main, hostNames ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 180 | pingResult = pingResult and pingTemp |
| 181 | |
| 182 | if pingTemp: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 183 | main.assertReturnString += 'Link Down Ping6all Passed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 184 | else: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 185 | main.assertReturnString += 'Link Down Ping6all Failed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 186 | |
| 187 | # Check intent states |
| 188 | intentTemp = checkIntentState( main, intentsId ) |
| 189 | intentResult = intentResult and intentTemp |
| 190 | if intentTemp: |
| 191 | main.assertReturnString += 'Link Down Intent State Passed\n' |
| 192 | else: |
| 193 | main.assertReturnString += 'Link Down Intent State Failed\n' |
| 194 | |
| 195 | # Checks ONOS state in link down |
| 196 | if linkDownResult and topoResult and pingResult and intentResult: |
| 197 | main.log.info( itemName + ": Successfully brought link down" ) |
| 198 | else: |
| 199 | main.log.error( itemName + ": Failed to bring link down" ) |
| 200 | |
| 201 | # Link up |
| 202 | linkUpResult = link( main, sw1, sw2, "up" ) |
| 203 | time.sleep( main.rerouteSleep ) |
| 204 | |
| 205 | if linkUpResult: |
| 206 | main.assertReturnString += 'Link Up Passed\n' |
| 207 | else: |
| 208 | main.assertReturnString += 'Link Up Failed\n' |
| 209 | |
| 210 | # Check flows count in each node |
| 211 | checkFlowsCount( main ) |
| 212 | # Verify flows |
| 213 | checkFlowsState( main ) |
| 214 | |
| 215 | # Check OnosTopology |
| 216 | topoResult = checkTopology( main, main.numLinks ) |
| 217 | |
| 218 | if topoResult: |
| 219 | main.assertReturnString += 'Link Up Topology State Passed\n' |
| 220 | else: |
| 221 | main.assertReturnString += 'Link Up Topology State Failed\n' |
| 222 | |
| 223 | # Ping hosts |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 224 | pingTemp = ping6allHosts( main, hostNames ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 225 | pingResult = pingResult and pingTemp |
| 226 | |
| 227 | if pingTemp: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 228 | main.assertReturnString += 'Link Up Ping6all Passed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 229 | else: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 230 | main.assertReturnString += 'Link Up Ping6all Failed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 231 | |
| 232 | intentTemp = checkIntentState( main, intentsId ) |
| 233 | intentResult = intentResult and intentTemp |
| 234 | if intentTemp: |
| 235 | main.assertReturnString += 'Link Up Intent State Passed\n' |
| 236 | else: |
| 237 | main.assertReturnString += 'Link Up Intent State Failed\n' |
| 238 | |
| 239 | # Checks ONOS state in link up |
| 240 | if linkUpResult and topoResult and pingResult and intentResult: |
| 241 | main.log.info( itemName + ": Successfully brought link back up" ) |
| 242 | else: |
| 243 | main.log.error( itemName + ": Failed to bring link back up" ) |
| 244 | |
| 245 | # Remove all intents |
| 246 | removeIntentResult = removeAllIntents( main, intentsId ) |
| 247 | |
| 248 | if removeIntentResult: |
| 249 | main.assertReturnString += 'Remove Intents Passed' |
| 250 | else: |
| 251 | main.assertReturnString += 'Remove Intents Failed' |
| 252 | |
| 253 | stepResult = pingResult and linkDownResult and linkUpResult \ |
| 254 | and intentResult and removeIntentResult |
| 255 | |
| 256 | return stepResult |
| 257 | |
| 258 | def pointIntent( main, |
| 259 | name, |
| 260 | host1, |
| 261 | host2, |
| 262 | onosNode=0, |
| 263 | deviceId1="", |
| 264 | deviceId2="", |
| 265 | port1="", |
| 266 | port2="", |
| 267 | ethType="", |
| 268 | mac1="", |
| 269 | mac2="", |
| 270 | bandwidth="", |
| 271 | lambdaAlloc=False, |
| 272 | ipProto="", |
| 273 | ip1="", |
| 274 | ip2="", |
| 275 | tcp1="", |
| 276 | tcp2="", |
| 277 | sw1="", |
| 278 | sw2="", |
| 279 | expectedLink=0 ): |
| 280 | |
| 281 | """ |
| 282 | Description: |
| 283 | Verify add-point-intent |
| 284 | Steps: |
| 285 | - Get device ids | ports |
| 286 | - Add point intents |
| 287 | - Check intents |
| 288 | - Verify flows |
| 289 | - Ping hosts |
| 290 | - Reroute |
| 291 | - Link down |
| 292 | - Verify flows |
| 293 | - Check topology |
| 294 | - Ping hosts |
| 295 | - Link up |
| 296 | - Verify flows |
| 297 | - Check topology |
| 298 | - Ping hosts |
| 299 | - Remove intents |
| 300 | Required: |
| 301 | name - Type of point intent to add eg. IPV4 | VLAN | Dualstack |
| 302 | host1 - Name of first host |
| 303 | host2 - Name of second host |
| 304 | Optional: |
| 305 | onosNode - ONOS node to install the intents in main.CLIs[ ] |
| 306 | 0 by default so that it will always use the first |
| 307 | ONOS node |
| 308 | deviceId1 - ONOS device id of the first switch, the same as the |
| 309 | location of the first host eg. of:0000000000000001/1, |
| 310 | located at device 1 port 1 |
| 311 | deviceId2 - ONOS device id of the second switch |
| 312 | port1 - The port number where the first host is attached |
| 313 | port2 - The port number where the second host is attached |
| 314 | ethType - Ethernet type eg. IPV4, IPV6 |
| 315 | mac1 - Mac address of first host |
| 316 | mac2 - Mac address of the second host |
| 317 | bandwidth - Bandwidth capacity |
| 318 | lambdaAlloc - Allocate lambda, defaults to False |
| 319 | ipProto - IP protocol |
| 320 | ip1 - IP address of first host |
| 321 | ip2 - IP address of second host |
| 322 | tcp1 - TCP port of first host |
| 323 | tcp2 - TCP port of second host |
| 324 | sw1 - First switch to bring down & up for rerouting purpose |
| 325 | sw2 - Second switch to bring down & up for rerouting purpose |
| 326 | expectedLink - Expected link when the switches are down, it should |
| 327 | be two links lower than the links before the two |
| 328 | switches are down |
| 329 | """ |
| 330 | |
| 331 | assert main, "There is no main variable" |
| 332 | assert name, "variable name is empty" |
| 333 | assert host1 and host2, "You must specify hosts" |
| 334 | |
| 335 | global itemName |
| 336 | itemName = name |
| 337 | host1 = host1 |
| 338 | host2 = host2 |
| 339 | hostNames = [ host1, host2 ] |
| 340 | intentsId = [] |
| 341 | |
| 342 | pingResult = main.TRUE |
| 343 | intentResult = main.TRUE |
| 344 | removeIntentResult = main.TRUE |
| 345 | flowResult = main.TRUE |
| 346 | topoResult = main.TRUE |
| 347 | linkDownResult = main.TRUE |
| 348 | linkUpResult = main.TRUE |
| 349 | onosNode = int( onosNode ) |
| 350 | |
| 351 | # Adding bidirectional point intents |
| 352 | main.log.info( itemName + ": Adding point intents" ) |
| 353 | intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1, |
| 354 | egressDevice=deviceId2, |
| 355 | portIngress=port1, |
| 356 | portEgress=port2, |
| 357 | ethType=ethType, |
| 358 | ethSrc=mac1, |
| 359 | ethDst=mac2, |
| 360 | bandwidth=bandwidth, |
| 361 | lambdaAlloc=lambdaAlloc, |
| 362 | ipProto=ipProto, |
| 363 | ipSrc=ip1, |
| 364 | ipDst=ip2, |
| 365 | tcpSrc=tcp1, |
| 366 | tcpDst=tcp2 ) |
| 367 | |
| 368 | intentsId.append( intent1 ) |
| 369 | intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2, |
| 370 | egressDevice=deviceId1, |
| 371 | portIngress=port2, |
| 372 | portEgress=port1, |
| 373 | ethType=ethType, |
| 374 | ethSrc=mac2, |
| 375 | ethDst=mac1, |
| 376 | bandwidth=bandwidth, |
| 377 | lambdaAlloc=lambdaAlloc, |
| 378 | ipProto=ipProto, |
| 379 | ipSrc=ip2, |
| 380 | ipDst=ip1, |
| 381 | tcpSrc=tcp2, |
| 382 | tcpDst=tcp1 ) |
| 383 | intentsId.append( intent2 ) |
| 384 | |
| 385 | # Check intents state |
| 386 | time.sleep( main.checkIntentSleep ) |
| 387 | intentResult = checkIntentState( main, intentsId ) |
| 388 | # Check flows count in each node |
| 389 | checkFlowsCount( main ) |
| 390 | |
| 391 | # Check intents state again if first check fails... |
| 392 | if not intentResult: |
| 393 | intentResult = checkIntentState( main, intentsId ) |
| 394 | |
| 395 | # Check flows count in each node |
| 396 | checkFlowsCount( main ) |
| 397 | # Verify flows |
| 398 | checkFlowsState( main ) |
| 399 | |
| 400 | # Ping hosts |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 401 | pingTemp = ping6allHosts( main, hostNames ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 402 | pingResult = pingResult and pingTemp |
| 403 | if pingTemp: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 404 | main.assertReturnString += 'Initial Ping6all Passed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 405 | else: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 406 | main.assertReturnString += 'Initial Ping6all Failed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 407 | |
| 408 | # Test rerouting if these variables exist |
| 409 | if sw1 and sw2 and expectedLink: |
| 410 | # link down |
| 411 | linkDownResult = link( main, sw1, sw2, "down" ) |
| 412 | |
| 413 | if linkDownResult: |
| 414 | main.assertReturnString += 'Link Down Passed\n' |
| 415 | else: |
| 416 | main.assertReturnString += 'Link Down Failed\n' |
| 417 | |
| 418 | # Check flows count in each node |
| 419 | checkFlowsCount( main ) |
| 420 | # Verify flows |
| 421 | checkFlowsState( main ) |
| 422 | |
| 423 | # Check OnosTopology |
| 424 | topoResult = checkTopology( main, expectedLink ) |
| 425 | if topoResult: |
| 426 | main.assertReturnString += 'Link Down Topology State Passed\n' |
| 427 | else: |
| 428 | main.assertReturnString += 'Link Down Topology State Failed\n' |
| 429 | |
| 430 | # Ping hosts |
Subhash Kumar Singh | 5ea4d30 | 2015-11-05 14:36:52 +0530 | [diff] [blame] | 431 | pingTemp = ping6allHosts( main, hostNames ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 432 | pingResult = pingResult and pingTemp |
| 433 | if pingTemp: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 434 | main.assertReturnString += 'Link Down Ping6all Passed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 435 | else: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 436 | main.assertReturnString += 'Link Down Ping6all Failed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 437 | |
| 438 | # Check intent state |
| 439 | intentTemp = checkIntentState( main, intentsId ) |
| 440 | intentResult = intentResult and intentTemp |
| 441 | if intentTemp: |
| 442 | main.assertReturnString += 'Link Down Intent State Passed\n' |
| 443 | else: |
| 444 | main.assertReturnString += 'Link Down Intent State Failed\n' |
| 445 | |
| 446 | # Checks ONOS state in link down |
| 447 | if linkDownResult and topoResult and pingResult and intentResult: |
| 448 | main.log.info( itemName + ": Successfully brought link down" ) |
| 449 | else: |
| 450 | main.log.error( itemName + ": Failed to bring link down" ) |
| 451 | |
| 452 | # link up |
| 453 | linkUpResult = link( main, sw1, sw2, "up" ) |
| 454 | if linkUpResult: |
| 455 | main.assertReturnString += 'Link Up Passed\n' |
| 456 | else: |
| 457 | main.assertReturnString += 'Link Up Failed\n' |
| 458 | |
| 459 | time.sleep( main.rerouteSleep ) |
| 460 | |
| 461 | # Check flows count in each node |
| 462 | checkFlowsCount( main ) |
| 463 | # Verify flows |
| 464 | checkFlowsState( main ) |
| 465 | |
| 466 | # Check OnosTopology |
| 467 | topoResult = checkTopology( main, main.numLinks ) |
| 468 | if topoResult: |
| 469 | main.assertReturnString += 'Link Up Topology State Passed\n' |
| 470 | else: |
| 471 | main.assertReturnString += 'Link Up Topology State Failed\n' |
| 472 | |
| 473 | # Ping hosts |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 474 | pingTemp = ping6allHosts( main, hostNames ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 475 | pingResult = pingResult and pingTemp |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 476 | if pingTemp: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 477 | main.assertReturnString += 'Link Up Ping6all Passed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 478 | else: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 479 | main.assertReturnString += 'Link Up Ping6all Failed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 480 | |
| 481 | intentTemp = checkIntentState( main, intentsId ) |
| 482 | intentResult = intentResult and intentTemp |
| 483 | if intentTemp: |
| 484 | main.assertReturnString += 'Link Up Intent State Passed\n' |
| 485 | else: |
| 486 | main.assertReturnString += 'Link Up Intent State Failed\n' |
| 487 | |
| 488 | # Checks ONOS state in link up |
| 489 | if linkUpResult and topoResult and pingResult and intentResult: |
| 490 | main.log.info( itemName + ": Successfully brought link back up" ) |
| 491 | else: |
| 492 | main.log.error( itemName + ": Failed to bring link back up" ) |
| 493 | |
| 494 | # Remove all intents |
| 495 | removeIntentResult = removeAllIntents( main, intentsId ) |
| 496 | if removeIntentResult: |
| 497 | main.assertReturnString += 'Remove Intents Passed' |
| 498 | else: |
| 499 | main.assertReturnString += 'Remove Intents Failed' |
| 500 | |
| 501 | stepResult = pingResult and linkDownResult and linkUpResult \ |
| 502 | and intentResult and removeIntentResult |
| 503 | |
| 504 | return stepResult |
| 505 | |
| 506 | def pointIntentTcp( main, |
| 507 | name, |
| 508 | host1, |
| 509 | host2, |
| 510 | onosNode=0, |
| 511 | deviceId1="", |
| 512 | deviceId2="", |
| 513 | port1="", |
| 514 | port2="", |
| 515 | ethType="", |
| 516 | mac1="", |
| 517 | mac2="", |
| 518 | bandwidth="", |
| 519 | lambdaAlloc=False, |
| 520 | ipProto="", |
| 521 | ip1="", |
| 522 | ip2="", |
| 523 | tcp1="", |
| 524 | tcp2="", |
| 525 | sw1="", |
| 526 | sw2="", |
| 527 | expectedLink=0 ): |
| 528 | |
| 529 | """ |
| 530 | Description: |
| 531 | Verify add-point-intent only for TCP |
| 532 | Steps: |
| 533 | - Get device ids | ports |
| 534 | - Add point intents |
| 535 | - Check intents |
| 536 | - Verify flows |
| 537 | - Ping hosts |
| 538 | - Reroute |
| 539 | - Link down |
| 540 | - Verify flows |
| 541 | - Check topology |
| 542 | - Ping hosts |
| 543 | - Link up |
| 544 | - Verify flows |
| 545 | - Check topology |
| 546 | - Ping hosts |
| 547 | - Remove intents |
| 548 | Required: |
| 549 | name - Type of point intent to add eg. IPV4 | VLAN | Dualstack |
| 550 | host1 - Name of first host |
| 551 | host2 - Name of second host |
| 552 | Optional: |
| 553 | onosNode - ONOS node to install the intents in main.CLIs[ ] |
| 554 | 0 by default so that it will always use the first |
| 555 | ONOS node |
| 556 | deviceId1 - ONOS device id of the first switch, the same as the |
| 557 | location of the first host eg. of:0000000000000001/1, |
| 558 | located at device 1 port 1 |
| 559 | deviceId2 - ONOS device id of the second switch |
| 560 | port1 - The port number where the first host is attached |
| 561 | port2 - The port number where the second host is attached |
| 562 | ethType - Ethernet type eg. IPV4, IPV6 |
| 563 | mac1 - Mac address of first host |
| 564 | mac2 - Mac address of the second host |
| 565 | bandwidth - Bandwidth capacity |
| 566 | lambdaAlloc - Allocate lambda, defaults to False |
| 567 | ipProto - IP protocol |
| 568 | ip1 - IP address of first host |
| 569 | ip2 - IP address of second host |
| 570 | tcp1 - TCP port of first host |
| 571 | tcp2 - TCP port of second host |
| 572 | sw1 - First switch to bring down & up for rerouting purpose |
| 573 | sw2 - Second switch to bring down & up for rerouting purpose |
| 574 | expectedLink - Expected link when the switches are down, it should |
| 575 | be two links lower than the links before the two |
| 576 | switches are down |
| 577 | """ |
| 578 | |
| 579 | assert main, "There is no main variable" |
| 580 | assert name, "variable name is empty" |
| 581 | assert host1 and host2, "You must specify hosts" |
| 582 | |
| 583 | global itemName |
| 584 | itemName = name |
| 585 | host1 = host1 |
| 586 | host2 = host2 |
| 587 | hostNames = [ host1, host2 ] |
| 588 | intentsId = [] |
| 589 | |
| 590 | iperfResult = main.TRUE |
| 591 | intentResult = main.TRUE |
| 592 | removeIntentResult = main.TRUE |
| 593 | flowResult = main.TRUE |
| 594 | topoResult = main.TRUE |
| 595 | linkDownResult = main.TRUE |
| 596 | linkUpResult = main.TRUE |
| 597 | onosNode = int( onosNode ) |
| 598 | |
| 599 | # Adding bidirectional point intents |
| 600 | main.log.info( itemName + ": Adding point intents" ) |
| 601 | intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1, |
| 602 | egressDevice=deviceId2, |
| 603 | portIngress=port1, |
| 604 | portEgress=port2, |
| 605 | ethType=ethType, |
| 606 | ethSrc=mac1, |
| 607 | ethDst=mac2, |
| 608 | bandwidth=bandwidth, |
| 609 | lambdaAlloc=lambdaAlloc, |
| 610 | ipProto=ipProto, |
| 611 | ipSrc=ip1, |
| 612 | ipDst=ip2, |
| 613 | tcpSrc=tcp1, |
| 614 | tcpDst="" ) |
| 615 | |
| 616 | intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2, |
| 617 | egressDevice=deviceId1, |
| 618 | portIngress=port2, |
| 619 | portEgress=port1, |
| 620 | ethType=ethType, |
| 621 | ethSrc=mac2, |
| 622 | ethDst=mac1, |
| 623 | bandwidth=bandwidth, |
| 624 | lambdaAlloc=lambdaAlloc, |
| 625 | ipProto=ipProto, |
| 626 | ipSrc=ip2, |
| 627 | ipDst=ip1, |
| 628 | tcpSrc=tcp2, |
| 629 | tcpDst="" ) |
| 630 | |
| 631 | intent3 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1, |
| 632 | egressDevice=deviceId2, |
| 633 | portIngress=port1, |
| 634 | portEgress=port2, |
| 635 | ethType=ethType, |
| 636 | ethSrc=mac1, |
| 637 | ethDst=mac2, |
| 638 | bandwidth=bandwidth, |
| 639 | lambdaAlloc=lambdaAlloc, |
| 640 | ipProto=ipProto, |
| 641 | ipSrc=ip1, |
| 642 | ipDst=ip2, |
| 643 | tcpSrc="", |
| 644 | tcpDst=tcp2 ) |
| 645 | |
| 646 | intent4 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2, |
| 647 | egressDevice=deviceId1, |
| 648 | portIngress=port2, |
| 649 | portEgress=port1, |
| 650 | ethType=ethType, |
| 651 | ethSrc=mac2, |
| 652 | ethDst=mac1, |
| 653 | bandwidth=bandwidth, |
| 654 | lambdaAlloc=lambdaAlloc, |
| 655 | ipProto=ipProto, |
| 656 | ipSrc=ip2, |
| 657 | ipDst=ip1, |
| 658 | tcpSrc="", |
| 659 | tcpDst=tcp1 ) |
| 660 | intentsId.append( intent1 ) |
| 661 | intentsId.append( intent2 ) |
| 662 | intentsId.append( intent3 ) |
| 663 | intentsId.append( intent4 ) |
| 664 | |
| 665 | # Check intents state |
| 666 | time.sleep( main.checkIntentSleep ) |
| 667 | intentResult = checkIntentState( main, intentsId ) |
| 668 | # Check flows count in each node |
| 669 | checkFlowsCount( main ) |
| 670 | |
| 671 | # Check intents state again if first check fails... |
| 672 | if not intentResult: |
| 673 | intentResult = checkIntentState( main, intentsId ) |
| 674 | |
| 675 | # Check flows count in each node |
| 676 | checkFlowsCount( main ) |
| 677 | |
| 678 | # Verify flows |
| 679 | checkFlowsState( main ) |
| 680 | |
| 681 | # Run iperf to both host |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 682 | iperfTemp = main.Mininet1.iperftcpipv6( host1,host2 ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 683 | iperfResult = iperfResult and iperfTemp |
| 684 | if iperfTemp: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 685 | main.assertReturnString += 'Initial Iperf6 Passed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 686 | else: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 687 | main.assertReturnString += 'Initial Iperf6 Failed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 688 | |
| 689 | # Test rerouting if these variables exist |
| 690 | if sw1 and sw2 and expectedLink: |
| 691 | # link down |
| 692 | linkDownResult = link( main, sw1, sw2, "down" ) |
| 693 | |
| 694 | if linkDownResult: |
| 695 | main.assertReturnString += 'Link Down Passed\n' |
| 696 | else: |
| 697 | main.assertReturnString += 'Link Down Failed\n' |
| 698 | |
| 699 | # Check flows count in each node |
| 700 | checkFlowsCount( main ) |
| 701 | # Verify flows |
| 702 | checkFlowsState( main ) |
| 703 | |
| 704 | # Check OnosTopology |
| 705 | topoResult = checkTopology( main, expectedLink ) |
| 706 | if topoResult: |
| 707 | main.assertReturnString += 'Link Down Topology State Passed\n' |
| 708 | else: |
| 709 | main.assertReturnString += 'Link Down Topology State Failed\n' |
| 710 | |
| 711 | # Run iperf to both host |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 712 | iperfTemp = main.Mininet1.iperftcpipv6( host1,host2 ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 713 | iperfResult = iperfResult and iperfTemp |
| 714 | if iperfTemp: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 715 | main.assertReturnString += 'Link Down Iperf6 Passed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 716 | else: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 717 | main.assertReturnString += 'Link Down Iperf6 Failed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 718 | |
| 719 | # Check intent state |
| 720 | intentTemp = checkIntentState( main, intentsId ) |
| 721 | intentResult = intentResult and intentTemp |
| 722 | if intentTemp: |
| 723 | main.assertReturnString += 'Link Down Intent State Passed\n' |
| 724 | else: |
| 725 | main.assertReturnString += 'Link Down Intent State Failed\n' |
| 726 | |
| 727 | # Checks ONOS state in link down |
| 728 | if linkDownResult and topoResult and iperfResult and intentResult: |
| 729 | main.log.info( itemName + ": Successfully brought link down" ) |
| 730 | else: |
| 731 | main.log.error( itemName + ": Failed to bring link down" ) |
| 732 | |
| 733 | # link up |
| 734 | linkUpResult = link( main, sw1, sw2, "up" ) |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 735 | if linkUpResult: |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 736 | main.assertReturnString += 'Link Up Passed\n' |
| 737 | else: |
| 738 | main.assertReturnString += 'Link Up Failed\n' |
| 739 | |
| 740 | time.sleep( main.rerouteSleep ) |
| 741 | |
| 742 | # Check flows count in each node |
| 743 | checkFlowsCount( main ) |
| 744 | # Verify flows |
| 745 | checkFlowsState( main ) |
| 746 | |
| 747 | # Check OnosTopology |
| 748 | topoResult = checkTopology( main, main.numLinks ) |
| 749 | |
| 750 | if topoResult: |
| 751 | main.assertReturnString += 'Link Up Topology State Passed\n' |
| 752 | else: |
| 753 | main.assertReturnString += 'Link Up Topology State Failed\n' |
| 754 | |
| 755 | # Run iperf to both host |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 756 | iperfTemp = main.Mininet1.iperftcpipv6( host1,host2,timeout=10 ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 757 | iperfResult = iperfResult and iperfTemp |
| 758 | if iperfTemp: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 759 | main.assertReturnString += 'Link Up Iperf6 Passed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 760 | else: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 761 | main.assertReturnString += 'Link Up Iperf6 Failed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 762 | |
| 763 | # Check intent state |
| 764 | intentTemp = checkIntentState( main, intentsId ) |
| 765 | intentResult = intentResult and intentTemp |
| 766 | if intentTemp: |
| 767 | main.assertReturnString += 'Link Down Intent State Passed\n' |
| 768 | else: |
| 769 | main.assertReturnString += 'Link Down Intent State Failed\n' |
| 770 | |
| 771 | # Checks ONOS state in link up |
| 772 | if linkUpResult and topoResult and iperfResult and intentResult: |
| 773 | main.log.info( itemName + ": Successfully brought link back up" ) |
| 774 | else: |
| 775 | main.log.error( itemName + ": Failed to bring link back up" ) |
| 776 | |
| 777 | # Remove all intents |
| 778 | removeIntentResult = removeAllIntents( main, intentsId ) |
| 779 | if removeIntentResult: |
| 780 | main.assertReturnString += 'Remove Intents Passed' |
| 781 | else: |
| 782 | main.assertReturnString += 'Remove Intents Failed' |
| 783 | |
| 784 | stepResult = iperfResult and linkDownResult and linkUpResult \ |
| 785 | and intentResult and removeIntentResult |
| 786 | |
| 787 | return stepResult |
| 788 | |
| 789 | def singleToMultiIntent( main, |
| 790 | name, |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 791 | hostNames="", |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 792 | onosNode=0, |
| 793 | devices="", |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 794 | ports="", |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 795 | ethType="", |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 796 | macs="", |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 797 | bandwidth="", |
| 798 | lambdaAlloc=False, |
| 799 | ipProto="", |
| 800 | ipAddresses="", |
| 801 | tcp="", |
| 802 | sw1="", |
| 803 | sw2="", |
| 804 | expectedLink=0 ): |
| 805 | """ |
| 806 | Verify Single to Multi Point intents |
| 807 | NOTE:If main.hostsData is not defined, variables data should be passed |
| 808 | in the same order index wise. All devices in the list should have the same |
| 809 | format, either all the devices have its port or it doesn't. |
| 810 | eg. hostName = [ 'h1', 'h2' ,.. ] |
| 811 | devices = [ 'of:0000000000000001', 'of:0000000000000002', ...] |
| 812 | ports = [ '1', '1', ..] |
| 813 | ... |
| 814 | Description: |
| 815 | Verify add-single-to-multi-intent iterates through the list of given |
| 816 | host | devices and add intents |
| 817 | Steps: |
| 818 | - Get device ids | ports |
| 819 | - Add single to multi point intents |
| 820 | - Check intents |
| 821 | - Verify flows |
| 822 | - Ping hosts |
| 823 | - Reroute |
| 824 | - Link down |
| 825 | - Verify flows |
| 826 | - Check topology |
| 827 | - Ping hosts |
| 828 | - Link up |
| 829 | - Verify flows |
| 830 | - Check topology |
| 831 | - Ping hosts |
| 832 | - Remove intents |
| 833 | Required: |
| 834 | name - Type of point intent to add eg. IPV4 | VLAN | Dualstack |
| 835 | hostNames - List of host names |
| 836 | Optional: |
| 837 | onosNode - ONOS node to install the intents in main.CLIs[ ] |
| 838 | 0 by default so that it will always use the first |
| 839 | ONOS node |
| 840 | devices - List of device ids in the same order as the hosts |
| 841 | in hostNames |
| 842 | ports - List of port numbers in the same order as the device in |
| 843 | devices |
| 844 | ethType - Ethernet type eg. IPV4, IPV6 |
| 845 | macs - List of hosts mac address in the same order as the hosts in |
| 846 | hostNames |
| 847 | bandwidth - Bandwidth capacity |
| 848 | lambdaAlloc - Allocate lambda, defaults to False |
| 849 | ipProto - IP protocol |
| 850 | ipAddresses - IP addresses of host in the same order as the hosts in |
| 851 | hostNames |
| 852 | tcp - TCP ports in the same order as the hosts in hostNames |
| 853 | sw1 - First switch to bring down & up for rerouting purpose |
| 854 | sw2 - Second switch to bring down & up for rerouting purpose |
| 855 | expectedLink - Expected link when the switches are down, it should |
| 856 | be two links lower than the links before the two |
| 857 | switches are down |
| 858 | """ |
| 859 | |
| 860 | assert main, "There is no main variable" |
| 861 | assert hostNames, "You must specify hosts" |
| 862 | assert devices or main.hostsData, "You must specify devices" |
| 863 | |
| 864 | global itemName |
| 865 | itemName = name |
| 866 | tempHostsData = {} |
| 867 | intentsId = [] |
| 868 | onosNode = int( onosNode ) |
| 869 | |
| 870 | macsDict = {} |
| 871 | ipDict = {} |
| 872 | if hostNames and devices: |
| 873 | if len( hostNames ) != len( devices ): |
| 874 | main.log.debug( "hosts and devices does not have the same length" ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 875 | return main.FALSE |
| 876 | if ports: |
| 877 | if len( ports ) != len( devices ): |
| 878 | main.log.error( "Ports and devices does " + |
| 879 | "not have the same length" ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 880 | return main.FALSE |
| 881 | else: |
| 882 | main.log.info( "Device Ports are not specified" ) |
| 883 | if macs: |
| 884 | for i in range( len( devices ) ): |
| 885 | macsDict[ devices[ i ] ] = macs[ i ] |
| 886 | |
| 887 | elif hostNames and not devices and main.hostsData: |
| 888 | devices = [] |
| 889 | main.log.info( "singleToMultiIntent function is using main.hostsData" ) |
| 890 | for host in hostNames: |
| 891 | devices.append( main.hostsData.get( host ).get( 'location' ) ) |
| 892 | macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \ |
| 893 | main.hostsData.get( host ).get( 'mac' ) |
| 894 | ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \ |
| 895 | main.hostsData.get( host ).get( 'ipAddresses' ) |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 896 | |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 897 | pingResult = main.TRUE |
| 898 | intentResult = main.TRUE |
| 899 | removeIntentResult = main.TRUE |
| 900 | flowResult = main.TRUE |
| 901 | topoResult = main.TRUE |
| 902 | linkDownResult = main.TRUE |
| 903 | linkUpResult = main.TRUE |
| 904 | |
| 905 | devicesCopy = copy.copy( devices ) |
| 906 | if ports: |
| 907 | portsCopy = copy.copy( ports ) |
| 908 | main.log.info( itemName + ": Adding single point to multi point intents" ) |
| 909 | |
| 910 | # Check flows count in each node |
| 911 | checkFlowsCount( main ) |
| 912 | |
| 913 | # Adding bidirectional point intents |
| 914 | for i in range( len( devices ) ): |
| 915 | ingressDevice = devicesCopy[ i ] |
| 916 | egressDeviceList = copy.copy( devicesCopy ) |
| 917 | egressDeviceList.remove( ingressDevice ) |
| 918 | if ports: |
| 919 | portIngress = portsCopy[ i ] |
| 920 | portEgressList = copy.copy( portsCopy ) |
| 921 | del portEgressList[ i ] |
| 922 | else: |
| 923 | portIngress = "" |
| 924 | portEgressList = None |
| 925 | if not macsDict: |
| 926 | srcMac = "" |
| 927 | else: |
| 928 | srcMac = macsDict[ ingressDevice ] |
| 929 | if srcMac == None: |
| 930 | main.log.debug( "There is no MAC in device - " + ingressDevice ) |
| 931 | srcMac = "" |
| 932 | |
| 933 | intentsId.append( |
| 934 | main.CLIs[ onosNode ].addSinglepointToMultipointIntent( |
| 935 | ingressDevice=ingressDevice, |
| 936 | egressDeviceList=egressDeviceList, |
| 937 | portIngress=portIngress, |
| 938 | portEgressList=portEgressList, |
| 939 | ethType=ethType, |
| 940 | ethSrc=srcMac, |
| 941 | bandwidth=bandwidth, |
| 942 | lambdaAlloc=lambdaAlloc, |
| 943 | ipProto=ipProto, |
| 944 | ipSrc="", |
| 945 | ipDst="", |
| 946 | tcpSrc="", |
| 947 | tcpDst="" ) ) |
| 948 | |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 949 | |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 950 | # Check intents state |
| 951 | time.sleep( main.checkIntentSleep ) |
| 952 | intentResult = checkIntentState( main, intentsId ) |
| 953 | |
| 954 | # Check intents state again if first check fails... |
| 955 | if not intentResult: |
| 956 | intentResult = checkIntentState( main, intentsId ) |
| 957 | |
| 958 | # Check flows count in each node |
| 959 | checkFlowsCount( main ) |
| 960 | # Verify flows |
| 961 | checkFlowsState( main ) |
| 962 | |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 963 | firstPingResult = main.Mininet1.ping6pair(SRC=hostNames[0], TARGET=main.hostsData[ hostNames[1] ][ 'ipAddresses' ][0]) |
| 964 | if not firstPingResult: |
| 965 | main.log.debug( "First ping failed, there must be" + |
| 966 | " something wrong with ONOS performance" ) |
| 967 | |
| 968 | # Ping hosts again... |
| 969 | pingTemp = ping6allHosts( main, hostNames ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 970 | pingResult = pingResult and pingTemp |
| 971 | if pingTemp: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 972 | main.assertReturnString += 'Initial Ping6all Passed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 973 | else: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 974 | main.assertReturnString += 'Initial Ping6all Failed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 975 | |
| 976 | # Test rerouting if these variables exist |
| 977 | if sw1 and sw2 and expectedLink: |
| 978 | # link down |
| 979 | linkDownResult = link( main, sw1, sw2, "down" ) |
| 980 | |
| 981 | if linkDownResult: |
| 982 | main.assertReturnString += 'Link Down Passed\n' |
| 983 | else: |
| 984 | main.assertReturnString += 'Link Down Failed\n' |
| 985 | |
| 986 | # Check flows count in each node |
| 987 | checkFlowsCount( main ) |
| 988 | # Verify flows |
| 989 | checkFlowsState( main ) |
| 990 | |
| 991 | # Check OnosTopology |
| 992 | topoResult = checkTopology( main, expectedLink ) |
| 993 | if topoResult: |
| 994 | main.assertReturnString += 'Link Down Topology State Passed\n' |
| 995 | else: |
| 996 | main.assertReturnString += 'Link Down Topology State Failed\n' |
| 997 | |
| 998 | # Ping hosts |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 999 | pingTemp = ping6allHosts( main, hostNames ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1000 | pingResult = pingResult and pingTemp |
| 1001 | if pingTemp: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 1002 | main.assertReturnString += 'Link Down Ping6all Passed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1003 | else: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 1004 | main.assertReturnString += 'Link Down Ping6all Failed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1005 | |
| 1006 | # Check intent state |
| 1007 | intentTemp = checkIntentState( main, intentsId ) |
| 1008 | intentResult = intentResult and intentTemp |
| 1009 | if intentTemp: |
| 1010 | main.assertReturnString += 'Link Down Intent State Passed\n' |
| 1011 | else: |
| 1012 | main.assertReturnString += 'Link Down Intent State Failed\n' |
| 1013 | |
| 1014 | # Checks ONOS state in link down |
| 1015 | if linkDownResult and topoResult and pingResult and intentResult: |
| 1016 | main.log.info( itemName + ": Successfully brought link down" ) |
| 1017 | else: |
| 1018 | main.log.error( itemName + ": Failed to bring link down" ) |
| 1019 | |
| 1020 | # link up |
| 1021 | linkUpResult = link( main, sw1, sw2, "up" ) |
| 1022 | if linkUpResult: |
| 1023 | main.assertReturnString += 'Link Up Passed\n' |
| 1024 | else: |
| 1025 | main.assertReturnString += 'Link Up Failed\n' |
| 1026 | |
| 1027 | time.sleep( main.rerouteSleep ) |
| 1028 | |
| 1029 | # Check flows count in each node |
| 1030 | checkFlowsCount( main ) |
| 1031 | # Verify flows |
| 1032 | checkFlowsState( main ) |
| 1033 | |
| 1034 | # Check OnosTopology |
| 1035 | topoResult = checkTopology( main, main.numLinks ) |
| 1036 | if topoResult: |
| 1037 | main.assertReturnString += 'Link Up Topology State Passed\n' |
| 1038 | else: |
| 1039 | main.assertReturnString += 'Link Up Topology State Failed\n' |
| 1040 | |
| 1041 | # Ping hosts |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 1042 | pingTemp = ping6allHosts( main, hostNames ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1043 | pingResult = pingResult and pingTemp |
| 1044 | if pingTemp: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 1045 | main.assertReturnString += 'Link Up Ping6all Passed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1046 | else: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 1047 | main.assertReturnString += 'Link Up Ping6all Failed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1048 | |
| 1049 | # Check Intents |
| 1050 | intentTemp = checkIntentState( main, intentsId ) |
| 1051 | intentResult = intentResult and intentTemp |
| 1052 | if intentTemp: |
| 1053 | main.assertReturnString += 'Link Up Intent State Passed\n' |
| 1054 | else: |
| 1055 | main.assertReturnString += 'Link Up Intent State Failed\n' |
| 1056 | |
| 1057 | # Checks ONOS state in link up |
| 1058 | if linkUpResult and topoResult and pingResult and intentResult: |
| 1059 | main.log.info( itemName + ": Successfully brought link back up" ) |
| 1060 | else: |
| 1061 | main.log.error( itemName + ": Failed to bring link back up" ) |
| 1062 | |
| 1063 | # Remove all intents |
| 1064 | removeIntentResult = removeAllIntents( main, intentsId ) |
| 1065 | if removeIntentResult: |
| 1066 | main.assertReturnString += 'Remove Intents Passed' |
| 1067 | else: |
| 1068 | main.assertReturnString += 'Remove Intents Failed' |
| 1069 | |
| 1070 | stepResult = pingResult and linkDownResult and linkUpResult \ |
| 1071 | and intentResult and removeIntentResult |
| 1072 | |
| 1073 | return stepResult |
| 1074 | |
| 1075 | def multiToSingleIntent( main, |
| 1076 | name, |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 1077 | hostNames="", |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1078 | onosNode=0, |
| 1079 | devices="", |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 1080 | ports="", |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1081 | ethType="", |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 1082 | macs="", |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1083 | bandwidth="", |
| 1084 | lambdaAlloc=False, |
| 1085 | ipProto="", |
| 1086 | ipAddresses="", |
| 1087 | tcp="", |
| 1088 | sw1="", |
| 1089 | sw2="", |
| 1090 | expectedLink=0 ): |
| 1091 | """ |
| 1092 | Verify Single to Multi Point intents |
| 1093 | NOTE:If main.hostsData is not defined, variables data should be passed in the |
| 1094 | same order index wise. All devices in the list should have the same |
| 1095 | format, either all the devices have its port or it doesn't. |
| 1096 | eg. hostName = [ 'h1', 'h2' ,.. ] |
| 1097 | devices = [ 'of:0000000000000001', 'of:0000000000000002', ...] |
| 1098 | ports = [ '1', '1', ..] |
| 1099 | ... |
| 1100 | Description: |
| 1101 | Verify add-multi-to-single-intent |
| 1102 | Steps: |
| 1103 | - Get device ids | ports |
| 1104 | - Add multi to single point intents |
| 1105 | - Check intents |
| 1106 | - Verify flows |
| 1107 | - Ping hosts |
| 1108 | - Reroute |
| 1109 | - Link down |
| 1110 | - Verify flows |
| 1111 | - Check topology |
| 1112 | - Ping hosts |
| 1113 | - Link up |
| 1114 | - Verify flows |
| 1115 | - Check topology |
| 1116 | - Ping hosts |
| 1117 | - Remove intents |
| 1118 | Required: |
| 1119 | name - Type of point intent to add eg. IPV4 | VLAN | Dualstack |
| 1120 | hostNames - List of host names |
| 1121 | Optional: |
| 1122 | onosNode - ONOS node to install the intents in main.CLIs[ ] |
| 1123 | 0 by default so that it will always use the first |
| 1124 | ONOS node |
| 1125 | devices - List of device ids in the same order as the hosts |
| 1126 | in hostNames |
| 1127 | ports - List of port numbers in the same order as the device in |
| 1128 | devices |
| 1129 | ethType - Ethernet type eg. IPV4, IPV6 |
| 1130 | macs - List of hosts mac address in the same order as the hosts in |
| 1131 | hostNames |
| 1132 | bandwidth - Bandwidth capacity |
| 1133 | lambdaAlloc - Allocate lambda, defaults to False |
| 1134 | ipProto - IP protocol |
| 1135 | ipAddresses - IP addresses of host in the same order as the hosts in |
| 1136 | hostNames |
| 1137 | tcp - TCP ports in the same order as the hosts in hostNames |
| 1138 | sw1 - First switch to bring down & up for rerouting purpose |
| 1139 | sw2 - Second switch to bring down & up for rerouting purpose |
| 1140 | expectedLink - Expected link when the switches are down, it should |
| 1141 | be two links lower than the links before the two |
| 1142 | switches are down |
| 1143 | """ |
| 1144 | |
| 1145 | assert main, "There is no main variable" |
| 1146 | assert hostNames, "You must specify hosts" |
| 1147 | assert devices or main.hostsData, "You must specify devices" |
| 1148 | |
| 1149 | global itemName |
| 1150 | itemName = name |
| 1151 | tempHostsData = {} |
| 1152 | intentsId = [] |
| 1153 | onosNode = int( onosNode ) |
| 1154 | |
| 1155 | macsDict = {} |
| 1156 | ipDict = {} |
| 1157 | if hostNames and devices: |
| 1158 | if len( hostNames ) != len( devices ): |
| 1159 | main.log.debug( "hosts and devices does not have the same length" ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1160 | return main.FALSE |
| 1161 | if ports: |
| 1162 | if len( ports ) != len( devices ): |
| 1163 | main.log.error( "Ports and devices does " + |
| 1164 | "not have the same length" ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1165 | return main.FALSE |
| 1166 | else: |
| 1167 | main.log.info( "Device Ports are not specified" ) |
| 1168 | if macs: |
| 1169 | for i in range( len( devices ) ): |
| 1170 | macsDict[ devices[ i ] ] = macs[ i ] |
| 1171 | elif hostNames and not devices and main.hostsData: |
| 1172 | devices = [] |
| 1173 | main.log.info( "multiToSingleIntent function is using main.hostsData" ) |
| 1174 | for host in hostNames: |
| 1175 | devices.append( main.hostsData.get( host ).get( 'location' ) ) |
| 1176 | macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \ |
| 1177 | main.hostsData.get( host ).get( 'mac' ) |
| 1178 | ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \ |
| 1179 | main.hostsData.get( host ).get( 'ipAddresses' ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1180 | |
| 1181 | pingResult = main.TRUE |
| 1182 | intentResult = main.TRUE |
| 1183 | removeIntentResult = main.TRUE |
| 1184 | flowResult = main.TRUE |
| 1185 | topoResult = main.TRUE |
| 1186 | linkDownResult = main.TRUE |
| 1187 | linkUpResult = main.TRUE |
| 1188 | |
| 1189 | devicesCopy = copy.copy( devices ) |
| 1190 | if ports: |
| 1191 | portsCopy = copy.copy( ports ) |
| 1192 | main.log.info( itemName + ": Adding multi point to single point intents" ) |
| 1193 | |
| 1194 | # Check flows count in each node |
| 1195 | checkFlowsCount( main ) |
| 1196 | |
| 1197 | # Adding bidirectional point intents |
| 1198 | for i in range( len( devices ) ): |
| 1199 | egressDevice = devicesCopy[ i ] |
| 1200 | ingressDeviceList = copy.copy( devicesCopy ) |
| 1201 | ingressDeviceList.remove( egressDevice ) |
| 1202 | if ports: |
| 1203 | portEgress = portsCopy[ i ] |
| 1204 | portIngressList = copy.copy( portsCopy ) |
| 1205 | del portIngressList[ i ] |
| 1206 | else: |
| 1207 | portEgress = "" |
| 1208 | portIngressList = None |
| 1209 | if not macsDict: |
| 1210 | dstMac = "" |
| 1211 | else: |
| 1212 | dstMac = macsDict[ egressDevice ] |
| 1213 | if dstMac == None: |
| 1214 | main.log.debug( "There is no MAC in device - " + egressDevice ) |
| 1215 | dstMac = "" |
| 1216 | |
| 1217 | intentsId.append( |
| 1218 | main.CLIs[ onosNode ].addMultipointToSinglepointIntent( |
| 1219 | ingressDeviceList=ingressDeviceList, |
| 1220 | egressDevice=egressDevice, |
| 1221 | portIngressList=portIngressList, |
| 1222 | portEgress=portEgress, |
| 1223 | ethType=ethType, |
| 1224 | ethDst=dstMac, |
| 1225 | bandwidth=bandwidth, |
| 1226 | lambdaAlloc=lambdaAlloc, |
| 1227 | ipProto=ipProto, |
| 1228 | ipSrc="", |
| 1229 | ipDst="", |
| 1230 | tcpSrc="", |
| 1231 | tcpDst="" ) ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1232 | # Check intents state |
| 1233 | time.sleep( main.checkIntentSleep ) |
| 1234 | intentResult = checkIntentState( main, intentsId ) |
| 1235 | |
| 1236 | # Check intents state again if first check fails... |
| 1237 | if not intentResult: |
| 1238 | intentResult = checkIntentState( main, intentsId ) |
| 1239 | |
| 1240 | # Check flows count in each node |
| 1241 | checkFlowsCount( main ) |
| 1242 | # Verify flows |
| 1243 | checkFlowsState( main ) |
| 1244 | |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 1245 | # Ping hosts... |
| 1246 | pingTemp = ping6allHosts( main, hostNames ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1247 | pingResult = pingResult and pingTemp |
| 1248 | if pingTemp: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 1249 | main.assertReturnString += 'Initial Ping6all Passed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1250 | else: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 1251 | main.assertReturnString += 'Initial Ping6all Failed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1252 | |
| 1253 | # Test rerouting if these variables exist |
| 1254 | if sw1 and sw2 and expectedLink: |
| 1255 | # link down |
| 1256 | linkDownResult = link( main, sw1, sw2, "down" ) |
| 1257 | |
| 1258 | if linkDownResult: |
| 1259 | main.assertReturnString += 'Link Down Passed\n' |
| 1260 | else: |
| 1261 | main.assertReturnString += 'Link Down Failed\n' |
| 1262 | |
| 1263 | # Check flows count in each node |
| 1264 | checkFlowsCount( main ) |
| 1265 | # Verify flows |
| 1266 | checkFlowsState( main ) |
| 1267 | |
| 1268 | # Check OnosTopology |
| 1269 | topoResult = checkTopology( main, expectedLink ) |
| 1270 | if topoResult: |
| 1271 | main.assertReturnString += 'Link Down Topology State Passed\n' |
| 1272 | else: |
| 1273 | main.assertReturnString += 'Link Down Topology State Failed\n' |
| 1274 | |
| 1275 | # Ping hosts |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 1276 | pingTemp = ping6allHosts( main, hostNames ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1277 | pingResult = pingResult and pingTemp |
| 1278 | if pingTemp: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 1279 | main.assertReturnString += 'Link Down Ping6all Passed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1280 | else: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 1281 | main.assertReturnString += 'Link Down Ping6all Failed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1282 | |
| 1283 | # Check intent state |
| 1284 | intentTemp = checkIntentState( main, intentsId ) |
| 1285 | intentResult = intentResult and intentTemp |
| 1286 | if intentTemp: |
| 1287 | main.assertReturnString += 'Link Down Intent State Passed\n' |
| 1288 | else: |
| 1289 | main.assertReturnString += 'Link Down Intent State Failed\n' |
| 1290 | |
| 1291 | # Checks ONOS state in link down |
| 1292 | if linkDownResult and topoResult and pingResult and intentResult: |
| 1293 | main.log.info( itemName + ": Successfully brought link down" ) |
| 1294 | else: |
| 1295 | main.log.error( itemName + ": Failed to bring link down" ) |
| 1296 | |
| 1297 | # link up |
| 1298 | linkUpResult = link( main, sw1, sw2, "up" ) |
| 1299 | if linkUpResult: |
| 1300 | main.assertReturnString += 'Link Up Passed\n' |
| 1301 | else: |
| 1302 | main.assertReturnString += 'Link Up Failed\n' |
| 1303 | |
| 1304 | time.sleep( main.rerouteSleep ) |
| 1305 | |
| 1306 | # Check flows count in each node |
| 1307 | checkFlowsCount( main ) |
| 1308 | # Verify flows |
| 1309 | checkFlowsState( main ) |
| 1310 | |
| 1311 | # Check OnosTopology |
| 1312 | topoResult = checkTopology( main, main.numLinks ) |
| 1313 | if topoResult: |
| 1314 | main.assertReturnString += 'Link Up Topology State Passed\n' |
| 1315 | else: |
| 1316 | main.assertReturnString += 'Link Up Topology State Failed\n' |
| 1317 | |
| 1318 | # Ping hosts |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 1319 | pingTemp = ping6allHosts( main, hostNames ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1320 | pingResult = pingResult and pingTemp |
| 1321 | if pingTemp: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 1322 | main.assertReturnString += 'Link Up Ping6all Passed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1323 | else: |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 1324 | main.assertReturnString += 'Link Up Ping6all Failed\n' |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1325 | |
| 1326 | # Check Intents |
| 1327 | intentTemp = checkIntentState( main, intentsId ) |
| 1328 | intentResult = intentResult and intentTemp |
| 1329 | if intentTemp: |
| 1330 | main.assertReturnString += 'Link Up Intent State Passed\n' |
| 1331 | else: |
| 1332 | main.assertReturnString += 'Link Up Intent State Failed\n' |
| 1333 | |
| 1334 | # Checks ONOS state in link up |
| 1335 | if linkUpResult and topoResult and pingResult and intentResult: |
| 1336 | main.log.info( itemName + ": Successfully brought link back up" ) |
| 1337 | else: |
| 1338 | main.log.error( itemName + ": Failed to bring link back up" ) |
| 1339 | |
| 1340 | # Remove all intents |
| 1341 | removeIntentResult = removeAllIntents( main, intentsId ) |
| 1342 | if removeIntentResult: |
| 1343 | main.assertReturnString += 'Remove Intents Passed' |
| 1344 | else: |
| 1345 | main.assertReturnString += 'Remove Intents Failed' |
| 1346 | |
| 1347 | stepResult = pingResult and linkDownResult and linkUpResult \ |
| 1348 | and intentResult and removeIntentResult |
| 1349 | |
| 1350 | return stepResult |
| 1351 | |
Subhash Kumar Singh | 5ea4d30 | 2015-11-05 14:36:52 +0530 | [diff] [blame] | 1352 | def ping6allHosts( main, hostList ): |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1353 | # Ping all host in the hosts list variable |
| 1354 | main.log.info( "Pinging: " + str( hostList ) ) |
Subhash Kumar Singh | 5ea4d30 | 2015-11-05 14:36:52 +0530 | [diff] [blame] | 1355 | return main.Mininet1.pingIpv6Hosts( hostList ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1356 | |
| 1357 | def getHostsData( main ): |
| 1358 | """ |
| 1359 | Use fwd app and pingall to discover all the hosts |
| 1360 | """ |
| 1361 | |
| 1362 | activateResult = main.TRUE |
| 1363 | appCheck = main.TRUE |
| 1364 | getDataResult = main.TRUE |
| 1365 | main.log.info( "Activating reactive forwarding app " ) |
| 1366 | activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" ) |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 1367 | main.CLIs[ 0 ].setCfg( "org.onosproject.provider.host.impl.HostLocationProvider", "ipv6NeighborDiscovery", "true") |
| 1368 | main.CLIs[ 0 ].setCfg( "org.onosproject.proxyarp.ProxyArp", "ipv6NeighborDiscovery", "true") |
sathishm | ad95346 | 2015-12-03 17:42:07 +0530 | [diff] [blame] | 1369 | main.CLIs[ 0 ].setCfg( "org.onosproject.fwd.ReactiveForwarding", "ipv6Forwarding", "true") |
| 1370 | main.CLIs[ 0 ].setCfg( "org.onosproject.fwd.ReactiveForwarding", "matchIpv6Address", "true") |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1371 | time.sleep( main.fwdSleep ) |
| 1372 | |
| 1373 | for i in range( main.numCtrls ): |
| 1374 | appCheck = appCheck and main.CLIs[ i ].appToIDCheck() |
| 1375 | if appCheck != main.TRUE: |
| 1376 | main.log.warn( main.CLIs[ i ].apps() ) |
| 1377 | main.log.warn( main.CLIs[ i ].appIDs() ) |
| 1378 | |
sathishm | ad95346 | 2015-12-03 17:42:07 +0530 | [diff] [blame] | 1379 | pingResult = main.Mininet1.pingall( protocol="IPv6", timeout = 600 ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1380 | hostsJson = json.loads( main.CLIs[ 0 ].hosts() ) |
| 1381 | hosts = main.Mininet1.getHosts().keys() |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1382 | for host in hosts: |
| 1383 | main.hostsData[ host ] = {} |
| 1384 | main.hostsData[ host ][ 'mac' ] = \ |
| 1385 | main.Mininet1.getMacAddress( host ).upper() |
| 1386 | for hostj in hostsJson: |
| 1387 | if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]: |
| 1388 | main.hostsData[ host ][ 'id' ] = hostj[ 'id' ] |
| 1389 | main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ] |
| 1390 | main.hostsData[ host ][ 'location' ] = \ |
| 1391 | hostj[ 'location' ][ 'elementId' ] + '/' + \ |
| 1392 | hostj[ 'location' ][ 'port' ] |
| 1393 | main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ] |
| 1394 | |
| 1395 | main.log.info( "Deactivating reactive forwarding app " ) |
| 1396 | deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" ) |
| 1397 | if activateResult and deactivateResult and main.hostsData: |
| 1398 | main.log.info( "Successfully used fwd app to discover hosts " ) |
| 1399 | getDataResult = main.TRUE |
| 1400 | else: |
| 1401 | main.log.info( "Failed to use fwd app to discover hosts " ) |
| 1402 | getDataResult = main.FALSE |
| 1403 | |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 1404 | main.log.info( "Removing the automatically configured ipv6 link-local addresses in hostsData to avoid unnecessary ping with these addresses during initial ping test - link-local starts with 'fe' " ) |
| 1405 | for host in main.hostsData.keys(): |
| 1406 | if main.hostsData[ host ].get( 'ipAddresses' ) != None: |
| 1407 | main.hostsData[ host ][ 'ipAddresses' ] = [ v for v in main.hostsData[ host ][ 'ipAddresses' ] if not v.startswith('fe') ] |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1408 | print main.hostsData |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1409 | return getDataResult |
| 1410 | |
| 1411 | def checkTopology( main, expectedLink ): |
| 1412 | statusResult = main.TRUE |
| 1413 | # Check onos topology |
| 1414 | main.log.info( itemName + ": Checking ONOS topology " ) |
| 1415 | |
| 1416 | for i in range( main.numCtrls ): |
| 1417 | topologyResult = main.CLIs[ i ].topology() |
| 1418 | statusResult = main.ONOSbench.checkStatus( topologyResult, |
| 1419 | main.numSwitch, |
| 1420 | expectedLink )\ |
| 1421 | and statusResult |
| 1422 | if not statusResult: |
| 1423 | main.log.error( itemName + ": Topology mismatch" ) |
| 1424 | else: |
| 1425 | main.log.info( itemName + ": Topology match" ) |
| 1426 | return statusResult |
| 1427 | |
| 1428 | def checkIntentState( main, intentsId ): |
| 1429 | """ |
| 1430 | This function will check intent state to make sure all the intents |
| 1431 | are in INSTALLED state |
| 1432 | """ |
| 1433 | |
| 1434 | intentResult = main.TRUE |
| 1435 | results = [] |
| 1436 | |
| 1437 | main.log.info( itemName + ": Checking intents state" ) |
| 1438 | # First check of intents |
| 1439 | for i in range( main.numCtrls ): |
| 1440 | tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId ) |
| 1441 | results.append( tempResult ) |
| 1442 | |
| 1443 | expectedState = [ 'INSTALLED', 'INSTALLING' ] |
| 1444 | |
| 1445 | if all( result == main.TRUE for result in results ): |
| 1446 | main.log.info( itemName + ": Intents are installed correctly" ) |
| 1447 | else: |
| 1448 | # Wait for at least 5 second before checking the intents again |
| 1449 | main.log.error( "Intents are not installed correctly. Waiting 5 sec" ) |
| 1450 | time.sleep( 5 ) |
| 1451 | results = [] |
| 1452 | # Second check of intents since some of the intents may be in |
| 1453 | # INSTALLING state, they should be in INSTALLED at this time |
| 1454 | for i in range( main.numCtrls ): |
| 1455 | tempResult = main.CLIs[ i ].checkIntentState( |
| 1456 | intentsId=intentsId ) |
| 1457 | results.append( tempResult ) |
| 1458 | if all( result == main.TRUE for result in results ): |
| 1459 | main.log.info( itemName + ": Intents are installed correctly" ) |
| 1460 | intentResult = main.TRUE |
| 1461 | else: |
| 1462 | main.log.error( itemName + ": Intents are NOT installed correctly" ) |
| 1463 | intentResult = main.FALSE |
| 1464 | |
| 1465 | return intentResult |
| 1466 | |
| 1467 | def checkFlowsState( main ): |
| 1468 | |
| 1469 | main.log.info( itemName + ": Check flows state" ) |
| 1470 | checkFlowsResult = main.CLIs[ 0 ].checkFlowsState() |
| 1471 | return checkFlowsResult |
| 1472 | |
| 1473 | def link( main, sw1, sw2, option): |
| 1474 | |
| 1475 | # link down |
| 1476 | main.log.info( itemName + ": Bring link " + option + "between " + |
| 1477 | sw1 + " and " + sw2 ) |
| 1478 | linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option ) |
| 1479 | return linkResult |
| 1480 | |
| 1481 | def removeAllIntents( main, intentsId ): |
| 1482 | """ |
| 1483 | Remove all intents in the intentsId |
| 1484 | """ |
| 1485 | |
| 1486 | onosSummary = [] |
| 1487 | removeIntentResult = main.TRUE |
| 1488 | # Remove intents |
| 1489 | for intent in intentsId: |
| 1490 | main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True ) |
| 1491 | |
| 1492 | time.sleep( main.removeIntentSleep ) |
| 1493 | |
| 1494 | # If there is remianing intents then remove intents should fail |
| 1495 | for i in range( main.numCtrls ): |
| 1496 | onosSummary.append( json.loads( main.CLIs[ i ].summary() ) ) |
| 1497 | |
| 1498 | for summary in onosSummary: |
| 1499 | if summary.get( 'intents' ) != 0: |
| 1500 | main.log.warn( itemName + ": There are " + |
| 1501 | str( summary.get( 'intents' ) ) + |
| 1502 | " intents remaining in node " + |
| 1503 | str( summary.get( 'node' ) ) + |
| 1504 | ", failed to remove all the intents " ) |
| 1505 | removeIntentResult = main.FALSE |
| 1506 | |
| 1507 | if removeIntentResult: |
| 1508 | main.log.info( itemName + ": There are no more intents remaining, " + |
| 1509 | "successfully removed all the intents." ) |
| 1510 | |
| 1511 | return removeIntentResult |
| 1512 | |
| 1513 | def checkFlowsCount( main ): |
| 1514 | """ |
| 1515 | Check flows count in each node |
| 1516 | """ |
| 1517 | |
| 1518 | flowsCount = [] |
| 1519 | main.log.info( itemName + ": Checking flows count in each ONOS node" ) |
| 1520 | for i in range( main.numCtrls ): |
| 1521 | summaryResult = main.CLIs[ i ].summary() |
| 1522 | if not summaryResult: |
| 1523 | main.log.error( itemName + ": There is something wrong with " + |
| 1524 | "summary command" ) |
| 1525 | return main.FALSE |
| 1526 | else: |
| 1527 | summaryJson = json.loads( summaryResult ) |
| 1528 | flowsCount.append( summaryJson.get( 'flows' ) ) |
| 1529 | |
| 1530 | if flowsCount: |
| 1531 | if all( flows==flowsCount[ 0 ] for flows in flowsCount ): |
| 1532 | main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) + |
| 1533 | " flows in all ONOS node" ) |
| 1534 | else: |
| 1535 | for i in range( main.numCtrls ): |
| 1536 | main.log.debug( itemName + ": ONOS node " + str( i ) + " has " + |
| 1537 | str( flowsCount[ i ] ) + " flows" ) |
| 1538 | else: |
| 1539 | main.log.error( "Checking flows count failed, check summary command" ) |
| 1540 | return main.FALSE |
| 1541 | |
| 1542 | return main.TRUE |
| 1543 | |
| 1544 | def checkLeaderChange( leaders1, leaders2 ): |
| 1545 | """ |
| 1546 | Checks for a change in intent partition leadership. |
| 1547 | |
| 1548 | Takes the output of leaders -c in json string format before and after |
| 1549 | a potential change as input |
| 1550 | |
| 1551 | Returns main.TRUE if no mismatches are detected |
| 1552 | Returns main.FALSE if there is a mismatch or on error loading the input |
| 1553 | """ |
| 1554 | try: |
| 1555 | leaders1 = json.loads( leaders1 ) |
| 1556 | leaders2 = json.loads( leaders2 ) |
| 1557 | except ( AttributeError, TypeError): |
| 1558 | main.log.exception( self.name + ": Object not as expected" ) |
| 1559 | return main.FALSE |
| 1560 | except Exception: |
| 1561 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1562 | main.cleanup() |
| 1563 | main.exit() |
| 1564 | main.log.info( "Checking Intent Paritions for Change in Leadership" ) |
| 1565 | mismatch = False |
| 1566 | for dict1 in leaders1: |
| 1567 | if "intent" in dict1.get( "topic", [] ): |
| 1568 | for dict2 in leaders2: |
| 1569 | if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \ |
| 1570 | dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ): |
| 1571 | mismatch = True |
| 1572 | main.log.error( "{0} changed leader from {1} to {2}".\ |
| 1573 | format( dict1.get( "topic", "no-topic" ),\ |
| 1574 | dict1.get( "leader", "no-leader" ),\ |
| 1575 | dict2.get( "leader", "no-leader" ) ) ) |
| 1576 | if mismatch: |
| 1577 | return main.FALSE |
| 1578 | else: |
| 1579 | return main.TRUE |
| 1580 | |
| 1581 | def report( main ): |
| 1582 | """ |
| 1583 | Report errors/warnings/exceptions |
| 1584 | """ |
| 1585 | |
| 1586 | main.ONOSbench.logReport( main.ONOSip[ 0 ], |
| 1587 | [ "INFO", |
| 1588 | "FOLLOWER", |
| 1589 | "WARN", |
| 1590 | "flow", |
| 1591 | "ERROR", |
| 1592 | "Except" ], |
| 1593 | "s" ) |
| 1594 | |
| 1595 | main.log.info( "ERROR report: \n" ) |
| 1596 | for i in range( main.numCtrls ): |
| 1597 | main.ONOSbench.logReport( main.ONOSip[ i ], |
| 1598 | [ "ERROR" ], |
| 1599 | "d" ) |
| 1600 | |
| 1601 | main.log.info( "EXCEPTIONS report: \n" ) |
| 1602 | for i in range( main.numCtrls ): |
| 1603 | main.ONOSbench.logReport( main.ONOSip[ i ], |
| 1604 | [ "Except" ], |
| 1605 | "d" ) |
| 1606 | |
| 1607 | main.log.info( "WARNING report: \n" ) |
| 1608 | for i in range( main.numCtrls ): |
| 1609 | main.ONOSbench.logReport( main.ONOSip[ i ], |
| 1610 | [ "WARN" ], |
| 1611 | "d" ) |