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