blob: 377fd20a4180badba0377406c88e0ca1ae28b256 [file] [log] [blame]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001"""
2 Wrapper functions for FuncIntent
3 This functions include Onosclidriver and Mininetclidriver driver functions
4 Author: kelvin@onlab.us
5"""
6import time
7import copy
8import json
9
10def __init__( self ):
11 self.default = ''
12
13def 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-onlab58dc39e2015-08-06 08:11:09 -070028 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-onlabd48a68c2015-07-13 16:01:36 -070038 - Verify flows
kelvin-onlab58dc39e2015-08-06 08:11:09 -070039 - Check topology
kelvin-onlabd48a68c2015-07-13 16:01:36 -070040 - Ping hosts
kelvin-onlab58dc39e2015-08-06 08:11:09 -070041 - 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-onlabd48a68c2015-07-13 16:01:36 -070068 """
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-onlab6dea6e62015-07-23 13:07:26 -070095 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-onlabd48a68c2015-07-13 16:01:36 -0700109
kelvin-onlab6dea6e62015-07-23 13:07:26 -0700110 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-onlab6dea6e62015-07-23 13:07:26 -0700115 except KeyError:
116 main.log.error( itemName + ": Key error Exception" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700117 return main.FALSE
118
kelvin-onlab0ad05d12015-07-23 14:21:15 -0700119 # Discover hosts using arping incase pingall discovery failed
120 main.log.info( itemName + ": Discover host using arping" )
Jon Halla5cb3412015-08-18 14:08:22 -0700121 main.Mininet1.arping( srcHost=host1, dstHost=host2 )
122 main.Mininet1.arping( srcHost=host2, dstHost=host1 )
kelvin-onlab0ad05d12015-07-23 14:21:15 -0700123 host1 = main.CLIs[ 0 ].getHost( mac=h1Mac )
124 host2 = main.CLIs[ 0 ].getHost( mac=h2Mac )
125
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700126 # Check flows count in each node
127 checkFlowsCount( main )
128
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700129 # Adding host intents
130 main.log.info( itemName + ": Adding host intents" )
131 intent1 = main.CLIs[ onosNode ].addHostIntent( hostIdOne=h1Id,
kelvin-onlab6dea6e62015-07-23 13:07:26 -0700132 hostIdTwo=h2Id )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700133 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...
acsmarsd4862d12015-10-06 17:57:34 -0700156 pingTemp = pingallHosts( main, hostNames )
157 pingResult = pingResult and pingTemp
158 if pingTemp:
acsmars5d8cc862015-09-25 09:44:50 -0700159 main.assertReturnString += 'Initial Pingall Passed\n'
160 else:
161 main.assertReturnString += 'Initial Pingall Failed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700162
163 # Test rerouting if these variables exist
164 if sw1 and sw2 and expectedLink:
acsmars5d8cc862015-09-25 09:44:50 -0700165 # Link down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700166 linkDownResult = link( main, sw1, sw2, "down" )
acsmars5d8cc862015-09-25 09:44:50 -0700167
168 if linkDownResult:
169 main.assertReturnString += 'Link Down Passed\n'
170 else:
171 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700172
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 )
acsmars5d8cc862015-09-25 09:44:50 -0700180 if topoResult:
181 main.assertReturnString += 'Link Down Topology State Passed\n'
182 else:
183 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700184
185 # Ping hosts
acsmarsd4862d12015-10-06 17:57:34 -0700186 pingTemp = pingallHosts( main, hostNames )
187 pingResult = pingResult and pingTemp
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700188
acsmarsd4862d12015-10-06 17:57:34 -0700189 if pingTemp:
acsmars5d8cc862015-09-25 09:44:50 -0700190 main.assertReturnString += 'Link Down Pingall Passed\n'
191 else:
192 main.assertReturnString += 'Link Down Pingall Failed\n'
193
194 # Check intent states
acsmarsd4862d12015-10-06 17:57:34 -0700195 intentTemp = checkIntentState( main, intentsId )
196 intentResult = intentResult and intentTemp
197 if intentTemp:
acsmars5d8cc862015-09-25 09:44:50 -0700198 main.assertReturnString += 'Link Down Intent State Passed\n'
199 else:
200 main.assertReturnString += 'Link Down Intent State Failed\n'
201
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700202 # 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
acsmars5d8cc862015-09-25 09:44:50 -0700208 # Link up
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700209 linkUpResult = link( main, sw1, sw2, "up" )
210 time.sleep( main.rerouteSleep )
211
acsmars5d8cc862015-09-25 09:44:50 -0700212 if linkUpResult:
213 main.assertReturnString += 'Link Up Passed\n'
214 else:
215 main.assertReturnString += 'Link Up Failed\n'
216
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700217 # 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
acsmars5d8cc862015-09-25 09:44:50 -0700225 if topoResult:
226 main.assertReturnString += 'Link Up Topology State Passed\n'
227 else:
228 main.assertReturnString += 'Link Up Topology State Failed\n'
229
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700230 # Ping hosts
acsmarsd4862d12015-10-06 17:57:34 -0700231 pingTemp = pingallHosts( main, hostNames )
232 pingResult = pingResult and pingTemp
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700233
acsmarsd4862d12015-10-06 17:57:34 -0700234 if pingTemp:
acsmars5d8cc862015-09-25 09:44:50 -0700235 main.assertReturnString += 'Link Up Pingall Passed\n'
236 else:
237 main.assertReturnString += 'Link Up Pingall Failed\n'
238
acsmarsd4862d12015-10-06 17:57:34 -0700239 intentTemp = checkIntentState( main, intentsId )
240 intentResult = intentResult and intentTemp
241 if intentTemp:
acsmars5d8cc862015-09-25 09:44:50 -0700242 main.assertReturnString += 'Link Up Intent State Passed\n'
243 else:
244 main.assertReturnString += 'Link Up Intent State Failed\n'
245
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700246 # 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
acsmars5d8cc862015-09-25 09:44:50 -0700255 if removeIntentResult:
256 main.assertReturnString += 'Remove Intents Passed'
257 else:
258 main.assertReturnString += 'Remove Intents Failed'
259
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700260 stepResult = pingResult and linkDownResult and linkUpResult \
261 and intentResult and removeIntentResult
262
263 return stepResult
264
265def 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-onlab58dc39e2015-08-06 08:11:09 -0700289 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-onlabd48a68c2015-07-13 16:01:36 -0700299 - Verify flows
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700300 - Check topology
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700301 - Ping hosts
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700302 - 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-onlabd48a68c2015-07-13 16:01:36 -0700336 """
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-onlabd48a68c2015-07-13 16:01:36 -0700358 # 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
acsmarsd4862d12015-10-06 17:57:34 -0700408 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-onlabd48a68c2015-07-13 16:01:36 -0700414
415 # Test rerouting if these variables exist
416 if sw1 and sw2 and expectedLink:
417 # link down
418 linkDownResult = link( main, sw1, sw2, "down" )
acsmarsd4862d12015-10-06 17:57:34 -0700419
420 if linkDownResult:
421 main.assertReturnString += 'Link Down Passed\n'
422 else:
423 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700424
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 )
acsmarsd4862d12015-10-06 17:57:34 -0700432 if topoResult:
433 main.assertReturnString += 'Link Down Topology State Passed\n'
434 else:
435 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700436
437 # Ping hosts
acsmarsd4862d12015-10-06 17:57:34 -0700438 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-onlabd48a68c2015-07-13 16:01:36 -0700444
acsmarsd4862d12015-10-06 17:57:34 -0700445 # 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-onlabd48a68c2015-07-13 16:01:36 -0700452
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" )
acsmarsd4862d12015-10-06 17:57:34 -0700461 if linkUpResult:
462 main.assertReturnString += 'Link Up Passed\n'
463 else:
464 main.assertReturnString += 'Link Up Failed\n'
465
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700466 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 )
acsmarsd4862d12015-10-06 17:57:34 -0700475 if topoResult:
476 main.assertReturnString += 'Link Up Topology State Passed\n'
477 else:
478 main.assertReturnString += 'Link Up Topology State Failed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700479
480 # Ping hosts
acsmarsd4862d12015-10-06 17:57:34 -0700481 pingTemp = pingallHosts( main, hostNames )
482 pingResult = pingResult and pingTemp
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700483
acsmarsd4862d12015-10-06 17:57:34 -0700484 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-onlabd48a68c2015-07-13 16:01:36 -0700495
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 )
acsmarsd4862d12015-10-06 17:57:34 -0700504 if removeIntentResult:
505 main.assertReturnString += 'Remove Intents Passed'
506 else:
507 main.assertReturnString += 'Remove Intents Failed'
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700508
509 stepResult = pingResult and linkDownResult and linkUpResult \
510 and intentResult and removeIntentResult
511
512 return stepResult
513
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700514def 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
acsmarsd4862d12015-10-06 17:57:34 -0700690 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-onlab58dc39e2015-08-06 08:11:09 -0700696
697 # Test rerouting if these variables exist
698 if sw1 and sw2 and expectedLink:
699 # link down
700 linkDownResult = link( main, sw1, sw2, "down" )
acsmarsd4862d12015-10-06 17:57:34 -0700701
702 if linkDownResult:
703 main.assertReturnString += 'Link Down Passed\n'
704 else:
705 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700706
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 )
acsmarsd4862d12015-10-06 17:57:34 -0700714 if topoResult:
715 main.assertReturnString += 'Link Down Topology State Passed\n'
716 else:
717 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700718
719 # Run iperf to both host
acsmarsd4862d12015-10-06 17:57:34 -0700720 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-onlab58dc39e2015-08-06 08:11:09 -0700726
acsmarsd4862d12015-10-06 17:57:34 -0700727 # 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-onlab58dc39e2015-08-06 08:11:09 -0700734
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" )
acsmarsd4862d12015-10-06 17:57:34 -0700743 if linkUpTemp:
744 main.assertReturnString += 'Link Up Passed\n'
745 else:
746 main.assertReturnString += 'Link Up Failed\n'
747
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700748 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
acsmarsd4862d12015-10-06 17:57:34 -0700758 if topoResult:
759 main.assertReturnString += 'Link Up Topology State Passed\n'
760 else:
761 main.assertReturnString += 'Link Up Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700762
acsmarsd4862d12015-10-06 17:57:34 -0700763 # 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-onlab58dc39e2015-08-06 08:11:09 -0700778
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 )
acsmarsd4862d12015-10-06 17:57:34 -0700787 if removeIntentResult:
788 main.assertReturnString += 'Remove Intents Passed'
789 else:
790 main.assertReturnString += 'Remove Intents Failed'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700791
792 stepResult = iperfResult and linkDownResult and linkUpResult \
793 and intentResult and removeIntentResult
794
795 return stepResult
796
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700797def 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-onlab58dc39e2015-08-06 08:11:09 -0700814 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-onlabd48a68c2015-07-13 16:01:36 -0700833 - Verify flows
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700834 - Check topology
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700835 - Ping hosts
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700836 - 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-onlabd48a68c2015-07-13 16:01:36 -0700866 """
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-onlabd48a68c2015-07-13 16:01:36 -0700930 # 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
acsmarsd4862d12015-10-06 17:57:34 -0700967 pingTemp = pingallHosts( main, hostNames )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700968
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
acsmarsd4862d12015-10-06 17:57:34 -0700982 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-onlabd48a68c2015-07-13 16:01:36 -0700988
989 # Test rerouting if these variables exist
990 if sw1 and sw2 and expectedLink:
991 # link down
992 linkDownResult = link( main, sw1, sw2, "down" )
acsmarsd4862d12015-10-06 17:57:34 -0700993
994 if linkDownResult:
995 main.assertReturnString += 'Link Down Passed\n'
996 else:
997 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700998
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 )
acsmarsd4862d12015-10-06 17:57:34 -07001006 if topoResult:
1007 main.assertReturnString += 'Link Down Topology State Passed\n'
1008 else:
1009 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001010
1011 # Ping hosts
acsmarsd4862d12015-10-06 17:57:34 -07001012 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-onlabd48a68c2015-07-13 16:01:36 -07001018
acsmarsd4862d12015-10-06 17:57:34 -07001019 # 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-onlabd48a68c2015-07-13 16:01:36 -07001026
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" )
acsmarsd4862d12015-10-06 17:57:34 -07001035 if linkUpResult:
1036 main.assertReturnString += 'Link Up Passed\n'
1037 else:
1038 main.assertReturnString += 'Link Up Failed\n'
1039
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001040 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 )
acsmarsd4862d12015-10-06 17:57:34 -07001049 if topoResult:
1050 main.assertReturnString += 'Link Up Topology State Passed\n'
1051 else:
1052 main.assertReturnString += 'Link Up Topology State Failed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001053
1054 # Ping hosts
acsmarsd4862d12015-10-06 17:57:34 -07001055 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-onlabd48a68c2015-07-13 16:01:36 -07001061
acsmarsd4862d12015-10-06 17:57:34 -07001062 # 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-onlabd48a68c2015-07-13 16:01:36 -07001069
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 )
acsmarsd4862d12015-10-06 17:57:34 -07001078 if removeIntentResult:
1079 main.assertReturnString += 'Remove Intents Passed'
1080 else:
1081 main.assertReturnString += 'Remove Intents Failed'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001082
1083 stepResult = pingResult and linkDownResult and linkUpResult \
1084 and intentResult and removeIntentResult
1085
1086 return stepResult
1087
1088def 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-onlab58dc39e2015-08-06 08:11:09 -07001105 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-onlabd48a68c2015-07-13 16:01:36 -07001123 - Verify flows
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001124 - Check topology
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001125 - Ping hosts
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001126 - 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-onlabd48a68c2015-07-13 16:01:36 -07001156 """
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-onlabd48a68c2015-07-13 16:01:36 -07001219 # 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
acsmarsd4862d12015-10-06 17:57:34 -07001255 pingTemp = pingallHosts( main, hostNames )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001256
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
acsmarsd4862d12015-10-06 17:57:34 -07001271 pingTemp = pingallHosts( main, hostNames )
1272
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001273 # Ping hosts again...
acsmarsd4862d12015-10-06 17:57:34 -07001274 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-onlabd48a68c2015-07-13 16:01:36 -07001280
1281 # Test rerouting if these variables exist
1282 if sw1 and sw2 and expectedLink:
1283 # link down
1284 linkDownResult = link( main, sw1, sw2, "down" )
acsmarsd4862d12015-10-06 17:57:34 -07001285
1286 if linkDownResult:
1287 main.assertReturnString += 'Link Down Passed\n'
1288 else:
1289 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001290
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 )
acsmarsd4862d12015-10-06 17:57:34 -07001298 if topoResult:
1299 main.assertReturnString += 'Link Down Topology State Passed\n'
1300 else:
1301 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001302
1303 # Ping hosts
acsmarsd4862d12015-10-06 17:57:34 -07001304 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-onlabd48a68c2015-07-13 16:01:36 -07001310
acsmarsd4862d12015-10-06 17:57:34 -07001311 # 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-onlabd48a68c2015-07-13 16:01:36 -07001318
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" )
acsmarsd4862d12015-10-06 17:57:34 -07001327 if linkUpResult:
1328 main.assertReturnString += 'Link Up Passed\n'
1329 else:
1330 main.assertReturnString += 'Link Up Failed\n'
1331
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001332 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 )
acsmarsd4862d12015-10-06 17:57:34 -07001341 if topoResult:
1342 main.assertReturnString += 'Link Up Topology State Passed\n'
1343 else:
1344 main.assertReturnString += 'Link Up Topology State Failed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001345
1346 # Ping hosts
acsmarsd4862d12015-10-06 17:57:34 -07001347 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-onlabd48a68c2015-07-13 16:01:36 -07001353
acsmarsd4862d12015-10-06 17:57:34 -07001354 # 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-onlabd48a68c2015-07-13 16:01:36 -07001361
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 )
acsmarsd4862d12015-10-06 17:57:34 -07001370 if removeIntentResult:
1371 main.assertReturnString += 'Remove Intents Passed'
1372 else:
1373 main.assertReturnString += 'Remove Intents Failed'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001374
1375 stepResult = pingResult and linkDownResult and linkUpResult \
1376 and intentResult and removeIntentResult
1377
1378 return stepResult
1379
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001380def pingallHosts( main, hostList ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001381 # Ping all host in the hosts list variable
Jon Halla5cb3412015-08-18 14:08:22 -07001382 main.log.info( "Pinging: " + str( hostList ) )
1383 return main.Mininet1.pingallHosts( hostList )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001384
1385def 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-onlab0ad05d12015-07-23 14:21:15 -07001395 time.sleep( main.fwdSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001396
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
1433def 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
1450def 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
1471 time.sleep( 5 )
1472 results = []
1473 # Second check of intents since some of the intents may be in
1474 # INSTALLING state, they should be in INSTALLED at this time
1475 for i in range( main.numCtrls ):
1476 tempResult = main.CLIs[ i ].checkIntentState(
1477 intentsId=intentsId )
1478 results.append( tempResult )
1479 if all( result == main.TRUE for result in results ):
1480 main.log.info( itemName + ": Intents are installed correctly" )
1481 else:
1482 main.log.error( itemName + ": Intents are NOT installed correctly" )
1483 intentResult = main.FALSE
1484
1485 return intentResult
1486
1487def checkFlowsState( main ):
1488
1489 main.log.info( itemName + ": Check flows state" )
1490 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState()
1491 return checkFlowsResult
1492
1493def link( main, sw1, sw2, option):
1494
1495 # link down
1496 main.log.info( itemName + ": Bring link " + option + "between " +
1497 sw1 + " and " + sw2 )
1498 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
1499 return linkResult
1500
1501def removeAllIntents( main, intentsId ):
1502 """
1503 Remove all intents in the intentsId
1504 """
1505
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001506 onosSummary = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001507 removeIntentResult = main.TRUE
1508 # Remove intents
1509 for intent in intentsId:
1510 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
1511
acsmarscfa52272015-08-06 15:21:45 -07001512 time.sleep( main.removeIntentSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001513
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001514 # If there is remianing intents then remove intents should fail
1515 for i in range( main.numCtrls ):
1516 onosSummary.append( json.loads( main.CLIs[ i ].summary() ) )
1517
1518 for summary in onosSummary:
1519 if summary.get( 'intents' ) != 0:
1520 main.log.warn( itemName + ": There are " +
1521 str( summary.get( 'intents' ) ) +
1522 " intents remaining in node " +
1523 str( summary.get( 'node' ) ) +
1524 ", failed to remove all the intents " )
1525 removeIntentResult = main.FALSE
1526
1527 if removeIntentResult:
1528 main.log.info( itemName + ": There are no more intents remaining, " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001529 "successfully removed all the intents." )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001530
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001531 return removeIntentResult
1532
1533def checkFlowsCount( main ):
1534 """
1535 Check flows count in each node
1536 """
1537
1538 flowsCount = []
1539 main.log.info( itemName + ": Checking flows count in each ONOS node" )
1540 for i in range( main.numCtrls ):
1541 summaryResult = main.CLIs[ i ].summary()
1542 if not summaryResult:
1543 main.log.error( itemName + ": There is something wrong with " +
1544 "summary command" )
1545 return main.FALSE
1546 else:
1547 summaryJson = json.loads( summaryResult )
1548 flowsCount.append( summaryJson.get( 'flows' ) )
1549
1550 if flowsCount:
1551 if all( flows==flowsCount[ 0 ] for flows in flowsCount ):
1552 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
1553 " flows in all ONOS node" )
1554 else:
1555 for i in range( main.numCtrls ):
1556 main.log.debug( itemName + ": ONOS node " + str( i ) + " has " +
kelvin-onlab6dea6e62015-07-23 13:07:26 -07001557 str( flowsCount[ i ] ) + " flows" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001558 else:
1559 main.log.error( "Checking flows count failed, check summary command" )
1560 return main.FALSE
1561
1562 return main.TRUE
1563
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001564def checkLeaderChange( leaders1, leaders2 ):
acsmarse6b410f2015-07-17 14:39:34 -07001565 """
1566 Checks for a change in intent partition leadership.
1567
1568 Takes the output of leaders -c in json string format before and after
1569 a potential change as input
1570
1571 Returns main.TRUE if no mismatches are detected
1572 Returns main.FALSE if there is a mismatch or on error loading the input
1573 """
1574 try:
1575 leaders1 = json.loads( leaders1 )
1576 leaders2 = json.loads( leaders2 )
1577 except ( AttributeError, TypeError):
1578 main.log.exception( self.name + ": Object not as expected" )
1579 return main.FALSE
1580 except Exception:
1581 main.log.exception( self.name + ": Uncaught exception!" )
1582 main.cleanup()
1583 main.exit()
1584 main.log.info( "Checking Intent Paritions for Change in Leadership" )
1585 mismatch = False
1586 for dict1 in leaders1:
1587 if "intent" in dict1.get( "topic", [] ):
1588 for dict2 in leaders2:
1589 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \
1590 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
1591 mismatch = True
1592 main.log.error( "{0} changed leader from {1} to {2}".\
1593 format( dict1.get( "topic", "no-topic" ),\
1594 dict1.get( "leader", "no-leader" ),\
1595 dict2.get( "leader", "no-leader" ) ) )
1596 if mismatch:
1597 return main.FALSE
1598 else:
1599 return main.TRUE
kelvin-onlab016dce22015-08-10 09:54:11 -07001600
1601def report( main ):
1602 """
1603 Report errors/warnings/exceptions
1604 """
1605
1606 main.ONOSbench.logReport( main.ONOSip[ 0 ],
1607 [ "INFO",
1608 "FOLLOWER",
1609 "WARN",
1610 "flow",
1611 "ERROR",
1612 "Except" ],
1613 "s" )
1614
1615 main.log.info( "ERROR report: \n" )
1616 for i in range( main.numCtrls ):
1617 main.ONOSbench.logReport( main.ONOSip[ i ],
1618 [ "ERROR" ],
1619 "d" )
1620
1621 main.log.info( "EXCEPTIONS report: \n" )
1622 for i in range( main.numCtrls ):
1623 main.ONOSbench.logReport( main.ONOSip[ i ],
1624 [ "Except" ],
1625 "d" )
1626
1627 main.log.info( "WARNING report: \n" )
1628 for i in range( main.numCtrls ):
1629 main.ONOSbench.logReport( main.ONOSip[ i ],
1630 [ "WARN" ],
1631 "d" )