blob: d1b3b225c190bc3c824e142b6939c0fbc51d7568 [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...
acsmars5d8cc862015-09-25 09:44:50 -0700156 pingResult = pingallHosts( main, hostNames )
157 if pingResult:
158 main.assertReturnString += 'Initial Pingall Passed\n'
159 else:
160 main.assertReturnString += 'Initial Pingall Failed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700161
162 # Test rerouting if these variables exist
163 if sw1 and sw2 and expectedLink:
acsmars5d8cc862015-09-25 09:44:50 -0700164 # Link down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700165 linkDownResult = link( main, sw1, sw2, "down" )
acsmars5d8cc862015-09-25 09:44:50 -0700166
167 if linkDownResult:
168 main.assertReturnString += 'Link Down Passed\n'
169 else:
170 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700171
172 # Check flows count in each node
173 checkFlowsCount( main )
174 # Verify flows
175 checkFlowsState( main )
176
177 # Check OnosTopology
178 topoResult = checkTopology( main, expectedLink )
acsmars5d8cc862015-09-25 09:44:50 -0700179 if topoResult:
180 main.assertReturnString += 'Link Down Topology State Passed\n'
181 else:
182 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700183
184 # Ping hosts
185 pingResult = pingResult and pingallHosts( main, hostNames )
186
acsmars5d8cc862015-09-25 09:44:50 -0700187 if pingResult:
188 main.assertReturnString += 'Link Down Pingall Passed\n'
189 else:
190 main.assertReturnString += 'Link Down Pingall Failed\n'
191
192 # Check intent states
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700193 intentResult = checkIntentState( main, intentsId )
194
acsmars5d8cc862015-09-25 09:44:50 -0700195 if intentResult:
196 main.assertReturnString += 'Link Down Intent State Passed\n'
197 else:
198 main.assertReturnString += 'Link Down Intent State Failed\n'
199
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700200 # Checks ONOS state in link down
201 if linkDownResult and topoResult and pingResult and intentResult:
202 main.log.info( itemName + ": Successfully brought link down" )
203 else:
204 main.log.error( itemName + ": Failed to bring link down" )
205
acsmars5d8cc862015-09-25 09:44:50 -0700206 # Link up
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700207 linkUpResult = link( main, sw1, sw2, "up" )
208 time.sleep( main.rerouteSleep )
209
acsmars5d8cc862015-09-25 09:44:50 -0700210 if linkUpResult:
211 main.assertReturnString += 'Link Up Passed\n'
212 else:
213 main.assertReturnString += 'Link Up Failed\n'
214
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700215 # Check flows count in each node
216 checkFlowsCount( main )
217 # Verify flows
218 checkFlowsState( main )
219
220 # Check OnosTopology
221 topoResult = checkTopology( main, main.numLinks )
222
acsmars5d8cc862015-09-25 09:44:50 -0700223 if topoResult:
224 main.assertReturnString += 'Link Up Topology State Passed\n'
225 else:
226 main.assertReturnString += 'Link Up Topology State Failed\n'
227
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700228 # Ping hosts
229 pingResult = pingResult and pingallHosts( main, hostNames )
230
acsmars5d8cc862015-09-25 09:44:50 -0700231 if pingResult:
232 main.assertReturnString += 'Link Up Pingall Passed\n'
233 else:
234 main.assertReturnString += 'Link Up Pingall Failed\n'
235
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700236 intentResult = checkIntentState( main, intentsId )
237
acsmars5d8cc862015-09-25 09:44:50 -0700238 if intentResult:
239 main.assertReturnString += 'Link Up Intent State Passed\n'
240 else:
241 main.assertReturnString += 'Link Up Intent State Failed\n'
242
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700243 # Checks ONOS state in link up
244 if linkUpResult and topoResult and pingResult and intentResult:
245 main.log.info( itemName + ": Successfully brought link back up" )
246 else:
247 main.log.error( itemName + ": Failed to bring link back up" )
248
249 # Remove all intents
250 removeIntentResult = removeAllIntents( main, intentsId )
251
acsmars5d8cc862015-09-25 09:44:50 -0700252 if removeIntentResult:
253 main.assertReturnString += 'Remove Intents Passed'
254 else:
255 main.assertReturnString += 'Remove Intents Failed'
256
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700257 stepResult = pingResult and linkDownResult and linkUpResult \
258 and intentResult and removeIntentResult
259
260 return stepResult
261
262def pointIntent( main,
263 name,
264 host1,
265 host2,
266 onosNode=0,
267 deviceId1="",
268 deviceId2="",
269 port1="",
270 port2="",
271 ethType="",
272 mac1="",
273 mac2="",
274 bandwidth="",
275 lambdaAlloc=False,
276 ipProto="",
277 ip1="",
278 ip2="",
279 tcp1="",
280 tcp2="",
281 sw1="",
282 sw2="",
283 expectedLink=0 ):
284
285 """
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700286 Description:
287 Verify add-point-intent
288 Steps:
289 - Get device ids | ports
290 - Add point intents
291 - Check intents
292 - Verify flows
293 - Ping hosts
294 - Reroute
295 - Link down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700296 - Verify flows
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700297 - Check topology
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700298 - Ping hosts
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700299 - Link up
300 - Verify flows
301 - Check topology
302 - Ping hosts
303 - Remove intents
304 Required:
305 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
306 host1 - Name of first host
307 host2 - Name of second host
308 Optional:
309 onosNode - ONOS node to install the intents in main.CLIs[ ]
310 0 by default so that it will always use the first
311 ONOS node
312 deviceId1 - ONOS device id of the first switch, the same as the
313 location of the first host eg. of:0000000000000001/1,
314 located at device 1 port 1
315 deviceId2 - ONOS device id of the second switch
316 port1 - The port number where the first host is attached
317 port2 - The port number where the second host is attached
318 ethType - Ethernet type eg. IPV4, IPV6
319 mac1 - Mac address of first host
320 mac2 - Mac address of the second host
321 bandwidth - Bandwidth capacity
322 lambdaAlloc - Allocate lambda, defaults to False
323 ipProto - IP protocol
324 ip1 - IP address of first host
325 ip2 - IP address of second host
326 tcp1 - TCP port of first host
327 tcp2 - TCP port of second host
328 sw1 - First switch to bring down & up for rerouting purpose
329 sw2 - Second switch to bring down & up for rerouting purpose
330 expectedLink - Expected link when the switches are down, it should
331 be two links lower than the links before the two
332 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700333 """
334
335 assert main, "There is no main variable"
336 assert name, "variable name is empty"
337 assert host1 and host2, "You must specify hosts"
338
339 global itemName
340 itemName = name
341 host1 = host1
342 host2 = host2
343 hostNames = [ host1, host2 ]
344 intentsId = []
345
346 pingResult = main.TRUE
347 intentResult = main.TRUE
348 removeIntentResult = main.TRUE
349 flowResult = main.TRUE
350 topoResult = main.TRUE
351 linkDownResult = main.TRUE
352 linkUpResult = main.TRUE
353 onosNode = int( onosNode )
354
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700355 # Adding bidirectional point intents
356 main.log.info( itemName + ": Adding point intents" )
357 intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
358 egressDevice=deviceId2,
359 portIngress=port1,
360 portEgress=port2,
361 ethType=ethType,
362 ethSrc=mac1,
363 ethDst=mac2,
364 bandwidth=bandwidth,
365 lambdaAlloc=lambdaAlloc,
366 ipProto=ipProto,
367 ipSrc=ip1,
368 ipDst=ip2,
369 tcpSrc=tcp1,
370 tcpDst=tcp2 )
371
372 intentsId.append( intent1 )
373 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
374 egressDevice=deviceId1,
375 portIngress=port2,
376 portEgress=port1,
377 ethType=ethType,
378 ethSrc=mac2,
379 ethDst=mac1,
380 bandwidth=bandwidth,
381 lambdaAlloc=lambdaAlloc,
382 ipProto=ipProto,
383 ipSrc=ip2,
384 ipDst=ip1,
385 tcpSrc=tcp2,
386 tcpDst=tcp1 )
387 intentsId.append( intent2 )
388
389 # Check intents state
390 time.sleep( main.checkIntentSleep )
391 intentResult = checkIntentState( main, intentsId )
392 # Check flows count in each node
393 checkFlowsCount( main )
394
395 # Check intents state again if first check fails...
396 if not intentResult:
397 intentResult = checkIntentState( main, intentsId )
398
399 # Check flows count in each node
400 checkFlowsCount( main )
401 # Verify flows
402 checkFlowsState( main )
403
404 # Ping hosts
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700405 pingResult = pingResult and pingallHosts( main, hostNames )
406
407 # Test rerouting if these variables exist
408 if sw1 and sw2 and expectedLink:
409 # link down
410 linkDownResult = link( main, sw1, sw2, "down" )
411 intentResult = intentResult and checkIntentState( main, intentsId )
412
413 # Check flows count in each node
414 checkFlowsCount( main )
415 # Verify flows
416 checkFlowsState( main )
417
418 # Check OnosTopology
419 topoResult = checkTopology( main, expectedLink )
420
421 # Ping hosts
422 pingResult = pingResult and pingallHosts( main, hostNames )
423
424 intentResult = checkIntentState( main, intentsId )
425
426 # Checks ONOS state in link down
427 if linkDownResult and topoResult and pingResult and intentResult:
428 main.log.info( itemName + ": Successfully brought link down" )
429 else:
430 main.log.error( itemName + ": Failed to bring link down" )
431
432 # link up
433 linkUpResult = link( main, sw1, sw2, "up" )
434 time.sleep( main.rerouteSleep )
435
436 # Check flows count in each node
437 checkFlowsCount( main )
438 # Verify flows
439 checkFlowsState( main )
440
441 # Check OnosTopology
442 topoResult = checkTopology( main, main.numLinks )
443
444 # Ping hosts
445 pingResult = pingResult and pingallHosts( main, hostNames )
446
447 intentResult = checkIntentState( main, intentsId )
448
449 # Checks ONOS state in link up
450 if linkUpResult and topoResult and pingResult and intentResult:
451 main.log.info( itemName + ": Successfully brought link back up" )
452 else:
453 main.log.error( itemName + ": Failed to bring link back up" )
454
455 # Remove all intents
456 removeIntentResult = removeAllIntents( main, intentsId )
457
458 stepResult = pingResult and linkDownResult and linkUpResult \
459 and intentResult and removeIntentResult
460
461 return stepResult
462
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700463def pointIntentTcp( main,
464 name,
465 host1,
466 host2,
467 onosNode=0,
468 deviceId1="",
469 deviceId2="",
470 port1="",
471 port2="",
472 ethType="",
473 mac1="",
474 mac2="",
475 bandwidth="",
476 lambdaAlloc=False,
477 ipProto="",
478 ip1="",
479 ip2="",
480 tcp1="",
481 tcp2="",
482 sw1="",
483 sw2="",
484 expectedLink=0 ):
485
486 """
487 Description:
488 Verify add-point-intent only for TCP
489 Steps:
490 - Get device ids | ports
491 - Add point intents
492 - Check intents
493 - Verify flows
494 - Ping hosts
495 - Reroute
496 - Link down
497 - Verify flows
498 - Check topology
499 - Ping hosts
500 - Link up
501 - Verify flows
502 - Check topology
503 - Ping hosts
504 - Remove intents
505 Required:
506 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
507 host1 - Name of first host
508 host2 - Name of second host
509 Optional:
510 onosNode - ONOS node to install the intents in main.CLIs[ ]
511 0 by default so that it will always use the first
512 ONOS node
513 deviceId1 - ONOS device id of the first switch, the same as the
514 location of the first host eg. of:0000000000000001/1,
515 located at device 1 port 1
516 deviceId2 - ONOS device id of the second switch
517 port1 - The port number where the first host is attached
518 port2 - The port number where the second host is attached
519 ethType - Ethernet type eg. IPV4, IPV6
520 mac1 - Mac address of first host
521 mac2 - Mac address of the second host
522 bandwidth - Bandwidth capacity
523 lambdaAlloc - Allocate lambda, defaults to False
524 ipProto - IP protocol
525 ip1 - IP address of first host
526 ip2 - IP address of second host
527 tcp1 - TCP port of first host
528 tcp2 - TCP port of second host
529 sw1 - First switch to bring down & up for rerouting purpose
530 sw2 - Second switch to bring down & up for rerouting purpose
531 expectedLink - Expected link when the switches are down, it should
532 be two links lower than the links before the two
533 switches are down
534 """
535
536 assert main, "There is no main variable"
537 assert name, "variable name is empty"
538 assert host1 and host2, "You must specify hosts"
539
540 global itemName
541 itemName = name
542 host1 = host1
543 host2 = host2
544 hostNames = [ host1, host2 ]
545 intentsId = []
546
547 iperfResult = main.TRUE
548 intentResult = main.TRUE
549 removeIntentResult = main.TRUE
550 flowResult = main.TRUE
551 topoResult = main.TRUE
552 linkDownResult = main.TRUE
553 linkUpResult = main.TRUE
554 onosNode = int( onosNode )
555
556 # Adding bidirectional point intents
557 main.log.info( itemName + ": Adding point intents" )
558 intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
559 egressDevice=deviceId2,
560 portIngress=port1,
561 portEgress=port2,
562 ethType=ethType,
563 ethSrc=mac1,
564 ethDst=mac2,
565 bandwidth=bandwidth,
566 lambdaAlloc=lambdaAlloc,
567 ipProto=ipProto,
568 ipSrc=ip1,
569 ipDst=ip2,
570 tcpSrc=tcp1,
571 tcpDst="" )
572
573 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
574 egressDevice=deviceId1,
575 portIngress=port2,
576 portEgress=port1,
577 ethType=ethType,
578 ethSrc=mac2,
579 ethDst=mac1,
580 bandwidth=bandwidth,
581 lambdaAlloc=lambdaAlloc,
582 ipProto=ipProto,
583 ipSrc=ip2,
584 ipDst=ip1,
585 tcpSrc=tcp2,
586 tcpDst="" )
587
588 intent3 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
589 egressDevice=deviceId2,
590 portIngress=port1,
591 portEgress=port2,
592 ethType=ethType,
593 ethSrc=mac1,
594 ethDst=mac2,
595 bandwidth=bandwidth,
596 lambdaAlloc=lambdaAlloc,
597 ipProto=ipProto,
598 ipSrc=ip1,
599 ipDst=ip2,
600 tcpSrc="",
601 tcpDst=tcp2 )
602
603 intent4 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
604 egressDevice=deviceId1,
605 portIngress=port2,
606 portEgress=port1,
607 ethType=ethType,
608 ethSrc=mac2,
609 ethDst=mac1,
610 bandwidth=bandwidth,
611 lambdaAlloc=lambdaAlloc,
612 ipProto=ipProto,
613 ipSrc=ip2,
614 ipDst=ip1,
615 tcpSrc="",
616 tcpDst=tcp1 )
617 intentsId.append( intent1 )
618 intentsId.append( intent2 )
619 intentsId.append( intent3 )
620 intentsId.append( intent4 )
621
622 # Check intents state
623 time.sleep( main.checkIntentSleep )
624 intentResult = checkIntentState( main, intentsId )
625 # Check flows count in each node
626 checkFlowsCount( main )
627
628 # Check intents state again if first check fails...
629 if not intentResult:
630 intentResult = checkIntentState( main, intentsId )
631
632 # Check flows count in each node
633 checkFlowsCount( main )
634
635 # Verify flows
636 checkFlowsState( main )
637
638 # Run iperf to both host
639 iperfResult = iperfResult and main.Mininet1.iperftcp( host1,
640 host2, 10 )
641
642 # Test rerouting if these variables exist
643 if sw1 and sw2 and expectedLink:
644 # link down
645 linkDownResult = link( main, sw1, sw2, "down" )
646 intentResult = intentResult and checkIntentState( main, intentsId )
647
648 # Check flows count in each node
649 checkFlowsCount( main )
650 # Verify flows
651 checkFlowsState( main )
652
653 # Check OnosTopology
654 topoResult = checkTopology( main, expectedLink )
655
656 # Run iperf to both host
657 iperfResult = iperfResult and main.Mininet1.iperftcp( host1,
658 host2, 10 )
659
660 intentResult = checkIntentState( main, intentsId )
661
662 # Checks ONOS state in link down
663 if linkDownResult and topoResult and iperfResult and intentResult:
664 main.log.info( itemName + ": Successfully brought link down" )
665 else:
666 main.log.error( itemName + ": Failed to bring link down" )
667
668 # link up
669 linkUpResult = link( main, sw1, sw2, "up" )
670 time.sleep( main.rerouteSleep )
671
672 # Check flows count in each node
673 checkFlowsCount( main )
674 # Verify flows
675 checkFlowsState( main )
676
677 # Check OnosTopology
678 topoResult = checkTopology( main, main.numLinks )
679
680 # Run iperf to both host
681 iperfResult = iperfResult and main.Mininet1.iperftcp( host1,
682 host2, 10 )
683
684 intentResult = checkIntentState( main, intentsId )
685
686 # Checks ONOS state in link up
687 if linkUpResult and topoResult and iperfResult and intentResult:
688 main.log.info( itemName + ": Successfully brought link back up" )
689 else:
690 main.log.error( itemName + ": Failed to bring link back up" )
691
692 # Remove all intents
693 removeIntentResult = removeAllIntents( main, intentsId )
694
695 stepResult = iperfResult and linkDownResult and linkUpResult \
696 and intentResult and removeIntentResult
697
698 return stepResult
699
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700700def singleToMultiIntent( main,
701 name,
702 hostNames,
703 onosNode=0,
704 devices="",
705 ports=None,
706 ethType="",
707 macs=None,
708 bandwidth="",
709 lambdaAlloc=False,
710 ipProto="",
711 ipAddresses="",
712 tcp="",
713 sw1="",
714 sw2="",
715 expectedLink=0 ):
716 """
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700717 Verify Single to Multi Point intents
718 NOTE:If main.hostsData is not defined, variables data should be passed
719 in the same order index wise. All devices in the list should have the same
720 format, either all the devices have its port or it doesn't.
721 eg. hostName = [ 'h1', 'h2' ,.. ]
722 devices = [ 'of:0000000000000001', 'of:0000000000000002', ...]
723 ports = [ '1', '1', ..]
724 ...
725 Description:
726 Verify add-single-to-multi-intent iterates through the list of given
727 host | devices and add intents
728 Steps:
729 - Get device ids | ports
730 - Add single to multi point intents
731 - Check intents
732 - Verify flows
733 - Ping hosts
734 - Reroute
735 - Link down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700736 - Verify flows
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700737 - Check topology
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700738 - Ping hosts
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700739 - Link up
740 - Verify flows
741 - Check topology
742 - Ping hosts
743 - Remove intents
744 Required:
745 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
746 hostNames - List of host names
747 Optional:
748 onosNode - ONOS node to install the intents in main.CLIs[ ]
749 0 by default so that it will always use the first
750 ONOS node
751 devices - List of device ids in the same order as the hosts
752 in hostNames
753 ports - List of port numbers in the same order as the device in
754 devices
755 ethType - Ethernet type eg. IPV4, IPV6
756 macs - List of hosts mac address in the same order as the hosts in
757 hostNames
758 bandwidth - Bandwidth capacity
759 lambdaAlloc - Allocate lambda, defaults to False
760 ipProto - IP protocol
761 ipAddresses - IP addresses of host in the same order as the hosts in
762 hostNames
763 tcp - TCP ports in the same order as the hosts in hostNames
764 sw1 - First switch to bring down & up for rerouting purpose
765 sw2 - Second switch to bring down & up for rerouting purpose
766 expectedLink - Expected link when the switches are down, it should
767 be two links lower than the links before the two
768 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700769 """
770
771 assert main, "There is no main variable"
772 assert hostNames, "You must specify hosts"
773 assert devices or main.hostsData, "You must specify devices"
774
775 global itemName
776 itemName = name
777 tempHostsData = {}
778 intentsId = []
779 onosNode = int( onosNode )
780
781 macsDict = {}
782 ipDict = {}
783 if hostNames and devices:
784 if len( hostNames ) != len( devices ):
785 main.log.debug( "hosts and devices does not have the same length" )
786 #print "len hostNames = ", len( hostNames )
787 #print "len devices = ", len( devices )
788 return main.FALSE
789 if ports:
790 if len( ports ) != len( devices ):
791 main.log.error( "Ports and devices does " +
792 "not have the same length" )
793 #print "len devices = ", len( devices )
794 #print "len ports = ", len( ports )
795 return main.FALSE
796 else:
797 main.log.info( "Device Ports are not specified" )
798 if macs:
799 for i in range( len( devices ) ):
800 macsDict[ devices[ i ] ] = macs[ i ]
801
802 elif hostNames and not devices and main.hostsData:
803 devices = []
804 main.log.info( "singleToMultiIntent function is using main.hostsData" )
805 for host in hostNames:
806 devices.append( main.hostsData.get( host ).get( 'location' ) )
807 macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \
808 main.hostsData.get( host ).get( 'mac' )
809 ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \
810 main.hostsData.get( host ).get( 'ipAddresses' )
811 #print main.hostsData
812
813 #print 'host names = ', hostNames
814 #print 'devices = ', devices
815 #print "macsDict = ", macsDict
816
817 pingResult = main.TRUE
818 intentResult = main.TRUE
819 removeIntentResult = main.TRUE
820 flowResult = main.TRUE
821 topoResult = main.TRUE
822 linkDownResult = main.TRUE
823 linkUpResult = main.TRUE
824
825 devicesCopy = copy.copy( devices )
826 if ports:
827 portsCopy = copy.copy( ports )
828 main.log.info( itemName + ": Adding single point to multi point intents" )
829
830 # Check flows count in each node
831 checkFlowsCount( main )
832
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700833 # Adding bidirectional point intents
834 for i in range( len( devices ) ):
835 ingressDevice = devicesCopy[ i ]
836 egressDeviceList = copy.copy( devicesCopy )
837 egressDeviceList.remove( ingressDevice )
838 if ports:
839 portIngress = portsCopy[ i ]
840 portEgressList = copy.copy( portsCopy )
841 del portEgressList[ i ]
842 else:
843 portIngress = ""
844 portEgressList = None
845 if not macsDict:
846 srcMac = ""
847 else:
848 srcMac = macsDict[ ingressDevice ]
849 if srcMac == None:
850 main.log.debug( "There is no MAC in device - " + ingressDevice )
851 srcMac = ""
852
853 intentsId.append(
854 main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
855 ingressDevice=ingressDevice,
856 egressDeviceList=egressDeviceList,
857 portIngress=portIngress,
858 portEgressList=portEgressList,
859 ethType=ethType,
860 ethSrc=srcMac,
861 bandwidth=bandwidth,
862 lambdaAlloc=lambdaAlloc,
863 ipProto=ipProto,
864 ipSrc="",
865 ipDst="",
866 tcpSrc="",
867 tcpDst="" ) )
868
869 # Wait some time for the flow to go through when using multi instance
870 pingResult = pingallHosts( main, hostNames )
871
872 # Check intents state
873 time.sleep( main.checkIntentSleep )
874 intentResult = checkIntentState( main, intentsId )
875
876 # Check intents state again if first check fails...
877 if not intentResult:
878 intentResult = checkIntentState( main, intentsId )
879
880 # Check flows count in each node
881 checkFlowsCount( main )
882 # Verify flows
883 checkFlowsState( main )
884
885 pingResult = pingResult and pingallHosts( main, hostNames )
886
887 # Test rerouting if these variables exist
888 if sw1 and sw2 and expectedLink:
889 # link down
890 linkDownResult = link( main, sw1, sw2, "down" )
891 intentResult = intentResult and checkIntentState( main, intentsId )
892
893 # Check flows count in each node
894 checkFlowsCount( main )
895 # Verify flows
896 checkFlowsState( main )
897
898 # Check OnosTopology
899 topoResult = checkTopology( main, expectedLink )
900
901 # Ping hosts
902 pingResult = pingResult and pingallHosts( main, hostNames )
903
904 intentResult = checkIntentState( main, intentsId )
905
906 # Checks ONOS state in link down
907 if linkDownResult and topoResult and pingResult and intentResult:
908 main.log.info( itemName + ": Successfully brought link down" )
909 else:
910 main.log.error( itemName + ": Failed to bring link down" )
911
912 # link up
913 linkUpResult = link( main, sw1, sw2, "up" )
914 time.sleep( main.rerouteSleep )
915
916 # Check flows count in each node
917 checkFlowsCount( main )
918 # Verify flows
919 checkFlowsState( main )
920
921 # Check OnosTopology
922 topoResult = checkTopology( main, main.numLinks )
923
924 # Ping hosts
925 pingResult = pingResult and pingallHosts( main, hostNames )
926
927 intentResult = checkIntentState( main, intentsId )
928
929 # Checks ONOS state in link up
930 if linkUpResult and topoResult and pingResult and intentResult:
931 main.log.info( itemName + ": Successfully brought link back up" )
932 else:
933 main.log.error( itemName + ": Failed to bring link back up" )
934
935 # Remove all intents
936 removeIntentResult = removeAllIntents( main, intentsId )
937
938 stepResult = pingResult and linkDownResult and linkUpResult \
939 and intentResult and removeIntentResult
940
941 return stepResult
942
943def multiToSingleIntent( main,
944 name,
945 hostNames,
946 onosNode=0,
947 devices="",
948 ports=None,
949 ethType="",
950 macs=None,
951 bandwidth="",
952 lambdaAlloc=False,
953 ipProto="",
954 ipAddresses="",
955 tcp="",
956 sw1="",
957 sw2="",
958 expectedLink=0 ):
959 """
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700960 Verify Single to Multi Point intents
961 NOTE:If main.hostsData is not defined, variables data should be passed in the
962 same order index wise. All devices in the list should have the same
963 format, either all the devices have its port or it doesn't.
964 eg. hostName = [ 'h1', 'h2' ,.. ]
965 devices = [ 'of:0000000000000001', 'of:0000000000000002', ...]
966 ports = [ '1', '1', ..]
967 ...
968 Description:
969 Verify add-multi-to-single-intent
970 Steps:
971 - Get device ids | ports
972 - Add multi to single point intents
973 - Check intents
974 - Verify flows
975 - Ping hosts
976 - Reroute
977 - Link down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700978 - Verify flows
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700979 - Check topology
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700980 - Ping hosts
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700981 - Link up
982 - Verify flows
983 - Check topology
984 - Ping hosts
985 - Remove intents
986 Required:
987 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
988 hostNames - List of host names
989 Optional:
990 onosNode - ONOS node to install the intents in main.CLIs[ ]
991 0 by default so that it will always use the first
992 ONOS node
993 devices - List of device ids in the same order as the hosts
994 in hostNames
995 ports - List of port numbers in the same order as the device in
996 devices
997 ethType - Ethernet type eg. IPV4, IPV6
998 macs - List of hosts mac address in the same order as the hosts in
999 hostNames
1000 bandwidth - Bandwidth capacity
1001 lambdaAlloc - Allocate lambda, defaults to False
1002 ipProto - IP protocol
1003 ipAddresses - IP addresses of host in the same order as the hosts in
1004 hostNames
1005 tcp - TCP ports in the same order as the hosts in hostNames
1006 sw1 - First switch to bring down & up for rerouting purpose
1007 sw2 - Second switch to bring down & up for rerouting purpose
1008 expectedLink - Expected link when the switches are down, it should
1009 be two links lower than the links before the two
1010 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001011 """
1012
1013 assert main, "There is no main variable"
1014 assert hostNames, "You must specify hosts"
1015 assert devices or main.hostsData, "You must specify devices"
1016
1017 global itemName
1018 itemName = name
1019 tempHostsData = {}
1020 intentsId = []
1021 onosNode = int( onosNode )
1022
1023 macsDict = {}
1024 ipDict = {}
1025 if hostNames and devices:
1026 if len( hostNames ) != len( devices ):
1027 main.log.debug( "hosts and devices does not have the same length" )
1028 #print "len hostNames = ", len( hostNames )
1029 #print "len devices = ", len( devices )
1030 return main.FALSE
1031 if ports:
1032 if len( ports ) != len( devices ):
1033 main.log.error( "Ports and devices does " +
1034 "not have the same length" )
1035 #print "len devices = ", len( devices )
1036 #print "len ports = ", len( ports )
1037 return main.FALSE
1038 else:
1039 main.log.info( "Device Ports are not specified" )
1040 if macs:
1041 for i in range( len( devices ) ):
1042 macsDict[ devices[ i ] ] = macs[ i ]
1043 elif hostNames and not devices and main.hostsData:
1044 devices = []
1045 main.log.info( "multiToSingleIntent function is using main.hostsData" )
1046 for host in hostNames:
1047 devices.append( main.hostsData.get( host ).get( 'location' ) )
1048 macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \
1049 main.hostsData.get( host ).get( 'mac' )
1050 ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \
1051 main.hostsData.get( host ).get( 'ipAddresses' )
1052 #print main.hostsData
1053
1054 #print 'host names = ', hostNames
1055 #print 'devices = ', devices
1056 #print "macsDict = ", macsDict
1057
1058 pingResult = main.TRUE
1059 intentResult = main.TRUE
1060 removeIntentResult = main.TRUE
1061 flowResult = main.TRUE
1062 topoResult = main.TRUE
1063 linkDownResult = main.TRUE
1064 linkUpResult = main.TRUE
1065
1066 devicesCopy = copy.copy( devices )
1067 if ports:
1068 portsCopy = copy.copy( ports )
1069 main.log.info( itemName + ": Adding multi point to single point intents" )
1070
1071 # Check flows count in each node
1072 checkFlowsCount( main )
1073
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001074 # Adding bidirectional point intents
1075 for i in range( len( devices ) ):
1076 egressDevice = devicesCopy[ i ]
1077 ingressDeviceList = copy.copy( devicesCopy )
1078 ingressDeviceList.remove( egressDevice )
1079 if ports:
1080 portEgress = portsCopy[ i ]
1081 portIngressList = copy.copy( portsCopy )
1082 del portIngressList[ i ]
1083 else:
1084 portEgress = ""
1085 portIngressList = None
1086 if not macsDict:
1087 dstMac = ""
1088 else:
1089 dstMac = macsDict[ egressDevice ]
1090 if dstMac == None:
1091 main.log.debug( "There is no MAC in device - " + egressDevice )
1092 dstMac = ""
1093
1094 intentsId.append(
1095 main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
1096 ingressDeviceList=ingressDeviceList,
1097 egressDevice=egressDevice,
1098 portIngressList=portIngressList,
1099 portEgress=portEgress,
1100 ethType=ethType,
1101 ethDst=dstMac,
1102 bandwidth=bandwidth,
1103 lambdaAlloc=lambdaAlloc,
1104 ipProto=ipProto,
1105 ipSrc="",
1106 ipDst="",
1107 tcpSrc="",
1108 tcpDst="" ) )
1109
1110 pingResult = pingallHosts( main, hostNames )
1111
1112 # Check intents state
1113 time.sleep( main.checkIntentSleep )
1114 intentResult = checkIntentState( main, intentsId )
1115
1116 # Check intents state again if first check fails...
1117 if not intentResult:
1118 intentResult = checkIntentState( main, intentsId )
1119
1120 # Check flows count in each node
1121 checkFlowsCount( main )
1122 # Verify flows
1123 checkFlowsState( main )
1124
1125 # Ping hosts
1126 pingResult = pingResult and pingallHosts( main, hostNames )
1127 # Ping hosts again...
1128 pingResult = pingResult and pingallHosts( main, hostNames )
1129
1130 # Test rerouting if these variables exist
1131 if sw1 and sw2 and expectedLink:
1132 # link down
1133 linkDownResult = link( main, sw1, sw2, "down" )
1134 intentResult = intentResult and checkIntentState( main, intentsId )
1135
1136 # Check flows count in each node
1137 checkFlowsCount( main )
1138 # Verify flows
1139 checkFlowsState( main )
1140
1141 # Check OnosTopology
1142 topoResult = checkTopology( main, expectedLink )
1143
1144 # Ping hosts
1145 pingResult = pingResult and pingallHosts( main, hostNames )
1146
1147 intentResult = checkIntentState( main, intentsId )
1148
1149 # Checks ONOS state in link down
1150 if linkDownResult and topoResult and pingResult and intentResult:
1151 main.log.info( itemName + ": Successfully brought link down" )
1152 else:
1153 main.log.error( itemName + ": Failed to bring link down" )
1154
1155 # link up
1156 linkUpResult = link( main, sw1, sw2, "up" )
1157 time.sleep( main.rerouteSleep )
1158
1159 # Check flows count in each node
1160 checkFlowsCount( main )
1161 # Verify flows
1162 checkFlowsState( main )
1163
1164 # Check OnosTopology
1165 topoResult = checkTopology( main, main.numLinks )
1166
1167 # Ping hosts
1168 pingResult = pingResult and pingallHosts( main, hostNames )
1169
1170 intentResult = checkIntentState( main, intentsId )
1171
1172 # Checks ONOS state in link up
1173 if linkUpResult and topoResult and pingResult and intentResult:
1174 main.log.info( itemName + ": Successfully brought link back up" )
1175 else:
1176 main.log.error( itemName + ": Failed to bring link back up" )
1177
1178 # Remove all intents
1179 removeIntentResult = removeAllIntents( main, intentsId )
1180
1181 stepResult = pingResult and linkDownResult and linkUpResult \
1182 and intentResult and removeIntentResult
1183
1184 return stepResult
1185
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001186def pingallHosts( main, hostList ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001187 # Ping all host in the hosts list variable
Jon Halla5cb3412015-08-18 14:08:22 -07001188 main.log.info( "Pinging: " + str( hostList ) )
1189 return main.Mininet1.pingallHosts( hostList )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001190
1191def getHostsData( main ):
1192 """
1193 Use fwd app and pingall to discover all the hosts
1194 """
1195
1196 activateResult = main.TRUE
1197 appCheck = main.TRUE
1198 getDataResult = main.TRUE
1199 main.log.info( "Activating reactive forwarding app " )
1200 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
kelvin-onlab0ad05d12015-07-23 14:21:15 -07001201 time.sleep( main.fwdSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001202
1203 for i in range( main.numCtrls ):
1204 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
1205 if appCheck != main.TRUE:
1206 main.log.warn( main.CLIs[ i ].apps() )
1207 main.log.warn( main.CLIs[ i ].appIDs() )
1208
1209 pingResult = main.Mininet1.pingall( timeout = 600 )
1210 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
1211 hosts = main.Mininet1.getHosts().keys()
1212 # TODO: Make better use of new getHosts function
1213 for host in hosts:
1214 main.hostsData[ host ] = {}
1215 main.hostsData[ host ][ 'mac' ] = \
1216 main.Mininet1.getMacAddress( host ).upper()
1217 for hostj in hostsJson:
1218 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
1219 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
1220 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
1221 main.hostsData[ host ][ 'location' ] = \
1222 hostj[ 'location' ][ 'elementId' ] + '/' + \
1223 hostj[ 'location' ][ 'port' ]
1224 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
1225
1226 main.log.info( "Deactivating reactive forwarding app " )
1227 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
1228 if activateResult and deactivateResult and main.hostsData:
1229 main.log.info( "Successfully used fwd app to discover hosts " )
1230 getDataResult = main.TRUE
1231 else:
1232 main.log.info( "Failed to use fwd app to discover hosts " )
1233 getDataResult = main.FALSE
1234
1235 print main.hostsData
1236
1237 return getDataResult
1238
1239def checkTopology( main, expectedLink ):
1240 statusResult = main.TRUE
1241 # Check onos topology
1242 main.log.info( itemName + ": Checking ONOS topology " )
1243
1244 for i in range( main.numCtrls ):
1245 topologyResult = main.CLIs[ i ].topology()
1246 statusResult = main.ONOSbench.checkStatus( topologyResult,
1247 main.numSwitch,
1248 expectedLink )\
1249 and statusResult
1250 if not statusResult:
1251 main.log.error( itemName + ": Topology mismatch" )
1252 else:
1253 main.log.info( itemName + ": Topology match" )
1254 return statusResult
1255
1256def checkIntentState( main, intentsId ):
1257 """
1258 This function will check intent state to make sure all the intents
1259 are in INSTALLED state
1260 """
1261
1262 intentResult = main.TRUE
1263 results = []
1264
1265 main.log.info( itemName + ": Checking intents state" )
1266 # First check of intents
1267 for i in range( main.numCtrls ):
1268 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
1269 results.append( tempResult )
1270
1271 expectedState = [ 'INSTALLED', 'INSTALLING' ]
1272
1273 if all( result == main.TRUE for result in results ):
1274 main.log.info( itemName + ": Intents are installed correctly" )
1275 else:
1276 # Wait for at least 5 second before checking the intents again
1277 time.sleep( 5 )
1278 results = []
1279 # Second check of intents since some of the intents may be in
1280 # INSTALLING state, they should be in INSTALLED at this time
1281 for i in range( main.numCtrls ):
1282 tempResult = main.CLIs[ i ].checkIntentState(
1283 intentsId=intentsId )
1284 results.append( tempResult )
1285 if all( result == main.TRUE for result in results ):
1286 main.log.info( itemName + ": Intents are installed correctly" )
1287 else:
1288 main.log.error( itemName + ": Intents are NOT installed correctly" )
1289 intentResult = main.FALSE
1290
1291 return intentResult
1292
1293def checkFlowsState( main ):
1294
1295 main.log.info( itemName + ": Check flows state" )
1296 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState()
1297 return checkFlowsResult
1298
1299def link( main, sw1, sw2, option):
1300
1301 # link down
1302 main.log.info( itemName + ": Bring link " + option + "between " +
1303 sw1 + " and " + sw2 )
1304 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
1305 return linkResult
1306
1307def removeAllIntents( main, intentsId ):
1308 """
1309 Remove all intents in the intentsId
1310 """
1311
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001312 onosSummary = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001313 removeIntentResult = main.TRUE
1314 # Remove intents
1315 for intent in intentsId:
1316 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
1317
acsmarscfa52272015-08-06 15:21:45 -07001318 time.sleep( main.removeIntentSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001319
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001320 # If there is remianing intents then remove intents should fail
1321 for i in range( main.numCtrls ):
1322 onosSummary.append( json.loads( main.CLIs[ i ].summary() ) )
1323
1324 for summary in onosSummary:
1325 if summary.get( 'intents' ) != 0:
1326 main.log.warn( itemName + ": There are " +
1327 str( summary.get( 'intents' ) ) +
1328 " intents remaining in node " +
1329 str( summary.get( 'node' ) ) +
1330 ", failed to remove all the intents " )
1331 removeIntentResult = main.FALSE
1332
1333 if removeIntentResult:
1334 main.log.info( itemName + ": There are no more intents remaining, " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001335 "successfully removed all the intents." )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001336
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001337 return removeIntentResult
1338
1339def checkFlowsCount( main ):
1340 """
1341 Check flows count in each node
1342 """
1343
1344 flowsCount = []
1345 main.log.info( itemName + ": Checking flows count in each ONOS node" )
1346 for i in range( main.numCtrls ):
1347 summaryResult = main.CLIs[ i ].summary()
1348 if not summaryResult:
1349 main.log.error( itemName + ": There is something wrong with " +
1350 "summary command" )
1351 return main.FALSE
1352 else:
1353 summaryJson = json.loads( summaryResult )
1354 flowsCount.append( summaryJson.get( 'flows' ) )
1355
1356 if flowsCount:
1357 if all( flows==flowsCount[ 0 ] for flows in flowsCount ):
1358 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
1359 " flows in all ONOS node" )
1360 else:
1361 for i in range( main.numCtrls ):
1362 main.log.debug( itemName + ": ONOS node " + str( i ) + " has " +
kelvin-onlab6dea6e62015-07-23 13:07:26 -07001363 str( flowsCount[ i ] ) + " flows" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001364 else:
1365 main.log.error( "Checking flows count failed, check summary command" )
1366 return main.FALSE
1367
1368 return main.TRUE
1369
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001370def checkLeaderChange( leaders1, leaders2 ):
acsmarse6b410f2015-07-17 14:39:34 -07001371 """
1372 Checks for a change in intent partition leadership.
1373
1374 Takes the output of leaders -c in json string format before and after
1375 a potential change as input
1376
1377 Returns main.TRUE if no mismatches are detected
1378 Returns main.FALSE if there is a mismatch or on error loading the input
1379 """
1380 try:
1381 leaders1 = json.loads( leaders1 )
1382 leaders2 = json.loads( leaders2 )
1383 except ( AttributeError, TypeError):
1384 main.log.exception( self.name + ": Object not as expected" )
1385 return main.FALSE
1386 except Exception:
1387 main.log.exception( self.name + ": Uncaught exception!" )
1388 main.cleanup()
1389 main.exit()
1390 main.log.info( "Checking Intent Paritions for Change in Leadership" )
1391 mismatch = False
1392 for dict1 in leaders1:
1393 if "intent" in dict1.get( "topic", [] ):
1394 for dict2 in leaders2:
1395 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \
1396 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
1397 mismatch = True
1398 main.log.error( "{0} changed leader from {1} to {2}".\
1399 format( dict1.get( "topic", "no-topic" ),\
1400 dict1.get( "leader", "no-leader" ),\
1401 dict2.get( "leader", "no-leader" ) ) )
1402 if mismatch:
1403 return main.FALSE
1404 else:
1405 return main.TRUE
kelvin-onlab016dce22015-08-10 09:54:11 -07001406
1407def report( main ):
1408 """
1409 Report errors/warnings/exceptions
1410 """
1411
1412 main.ONOSbench.logReport( main.ONOSip[ 0 ],
1413 [ "INFO",
1414 "FOLLOWER",
1415 "WARN",
1416 "flow",
1417 "ERROR",
1418 "Except" ],
1419 "s" )
1420
1421 main.log.info( "ERROR report: \n" )
1422 for i in range( main.numCtrls ):
1423 main.ONOSbench.logReport( main.ONOSip[ i ],
1424 [ "ERROR" ],
1425 "d" )
1426
1427 main.log.info( "EXCEPTIONS report: \n" )
1428 for i in range( main.numCtrls ):
1429 main.ONOSbench.logReport( main.ONOSip[ i ],
1430 [ "Except" ],
1431 "d" )
1432
1433 main.log.info( "WARNING report: \n" )
1434 for i in range( main.numCtrls ):
1435 main.ONOSbench.logReport( main.ONOSip[ i ],
1436 [ "WARN" ],
1437 "d" )