blob: 0d71604e6d0e4f83f2aef6850f4a4a992afaf12c [file] [log] [blame]
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001"""
2 Wrapper functions for FuncIntent
3 This functions include Onosclidriver and Mininetclidriver driver functions
4 Author: subhash_singh@criterionnetworks.com
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 """
28 Description:
29 Verify add-host-intent
30 Steps:
31 - Discover hosts
32 - Add host intents
33 - Check intents
34 - Verify flows
35 - Ping hosts
36 - Reroute
37 - Link down
38 - Verify flows
39 - Check topology
40 - Ping hosts
41 - Link up
42 - Verify flows
43 - Check topology
44 - Ping hosts
45 - Remove intents
46 Required:
47 name - Type of host intent to add eg. IPV4 | VLAN | Dualstack
48 host1 - Name of first host
49 host2 - Name of second host
50 Optional:
51 onosNode - ONOS node to install the intents in main.CLIs[ ]
52 0 by default so that it will always use the first
53 ONOS node
54 host1Id - ONOS id of the first host eg. 00:00:00:00:00:01/-1
55 host2Id - ONOS id of the second host
56 mac1 - Mac address of first host
57 mac2 - Mac address of the second host
58 vlan1 - Vlan tag of first host, defaults to -1
59 vlan2 - Vlan tag of second host, defaults to -1
60 sw1 - First switch to bring down & up for rerouting purpose
61 sw2 - Second switch to bring down & up for rerouting purpose
62 expectedLink - Expected link when the switches are down, it should
63 be two links lower than the links before the two
64 switches are down
65 Return:
66 Returns main.TRUE if all verification passed, otherwise return
67 main.FALSE; returns main.FALSE if there is a key error
68 """
69
70 # Assert variables
71 assert main, "There is no main variable"
72 assert name, "variable name is empty"
73 assert host1 and host2, "You must specify hosts"
74
75 global itemName
76 itemName = name
77 h1Id = host1Id
78 h2Id = host2Id
79 h1Mac = mac1
80 h2Mac = mac2
81 vlan1 = vlan1
82 vlan2 = vlan2
83 hostNames = [ host1 , host2 ]
84 intentsId = []
85 stepResult = main.TRUE
86 pingResult = main.TRUE
87 intentResult = main.TRUE
88 removeIntentResult = main.TRUE
89 flowResult = main.TRUE
90 topoResult = main.TRUE
91 linkDownResult = main.TRUE
92 linkUpResult = main.TRUE
93 onosNode = int( onosNode )
94
95 try:
96 if main.hostsData:
97 if not h1Mac:
98 h1Mac = main.hostsData[ host1 ][ 'mac' ]
99 if not h2Mac:
100 h2Mac = main.hostsData[ host2 ][ 'mac' ]
101 if main.hostsData[ host1 ].get( 'vlan' ):
102 vlan1 = main.hostsData[ host1 ][ 'vlan' ]
103 if main.hostsData[ host1 ].get( 'vlan' ):
104 vlan2 = main.hostsData[ host2 ][ 'vlan' ]
105 if not h1Id:
106 h1Id = main.hostsData[ host1 ][ 'id' ]
107 if not h2Id:
108 h2Id = main.hostsData[ host2 ][ 'id' ]
109
110 assert h1Id and h2Id, "You must specify host IDs"
111 if not ( h1Id and h2Id ):
112 main.log.info( "There are no host IDs" )
113 return main.FALSE
114
115 except KeyError:
116 main.log.error( itemName + ": Key error Exception" )
117 return main.FALSE
118
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800119 # Check flows count in each node
120 checkFlowsCount( main )
121
122 # Adding host intents
123 main.log.info( itemName + ": Adding host intents" )
124 intent1 = main.CLIs[ onosNode ].addHostIntent( hostIdOne=h1Id,
125 hostIdTwo=h2Id )
126 intentsId.append( intent1 )
127
128 # Check intents state
129 time.sleep( main.checkIntentSleep )
130 intentResult = checkIntentState( main, intentsId )
131 checkFlowsCount( main )
132
133 # Check intents state again if first check fails...
134 if not intentResult:
135 intentResult = checkIntentState( main, intentsId )
sathishmc4362252016-04-20 18:29:48 +0530136 if intentResult:
137 main.assertReturnString += 'Initial Intent State Passed\n'
138 else:
139 main.assertReturnString += 'Initial Intent State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800140
141 # Check flows count in each node
sathishmc4362252016-04-20 18:29:48 +0530142 FlowResult = checkFlowsCount( main )
143 if FlowResult:
144 main.assertReturnString += 'Initial Flow Count Passed\n'
145 else:
146 main.assertReturnString += 'Initial Flow Count Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800147 # Verify flows
sathishmc4362252016-04-20 18:29:48 +0530148 StateResult = checkFlowsState( main )
149 if StateResult:
150 main.assertReturnString += 'Initial Flow State Passed\n'
151 else:
152 main.assertReturnString += 'Initial Flow State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800153
154 # Ping hosts
sathishmad953462015-12-03 17:42:07 +0530155 firstPingResult = main.Mininet1.ping6pair(SRC=hostNames[0], TARGET=main.hostsData[ host2 ][ 'ipAddresses' ][ 0 ])
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800156 if not firstPingResult:
157 main.log.debug( "First ping failed, there must be" +
158 " something wrong with ONOS performance" )
159
160 # Ping hosts again...
Jon Hall439c8912016-04-15 02:22:03 -0700161 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800162 pingResult = pingResult and pingTemp
163 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700164 main.assertReturnString += 'Initial Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800165 else:
Jon Hall439c8912016-04-15 02:22:03 -0700166 main.assertReturnString += 'Initial Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800167
168 # Test rerouting if these variables exist
169 if sw1 and sw2 and expectedLink:
170 # Link down
171 linkDownResult = link( main, sw1, sw2, "down" )
172
173 if linkDownResult:
174 main.assertReturnString += 'Link Down Passed\n'
175 else:
176 main.assertReturnString += 'Link Down Failed\n'
177
178 # Check flows count in each node
179 checkFlowsCount( main )
180 # Verify flows
181 checkFlowsState( main )
182
183 # Check OnosTopology
184 topoResult = checkTopology( main, expectedLink )
185 if topoResult:
186 main.assertReturnString += 'Link Down Topology State Passed\n'
187 else:
188 main.assertReturnString += 'Link Down Topology State Failed\n'
189
190 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -0700191 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800192 pingResult = pingResult and pingTemp
193
194 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700195 main.assertReturnString += 'Link Down Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800196 else:
Jon Hall439c8912016-04-15 02:22:03 -0700197 main.assertReturnString += 'Link Down Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800198
199 # Check intent states
200 intentTemp = checkIntentState( main, intentsId )
201 intentResult = intentResult and intentTemp
202 if intentTemp:
203 main.assertReturnString += 'Link Down Intent State Passed\n'
204 else:
205 main.assertReturnString += 'Link Down Intent State Failed\n'
206
207 # Checks ONOS state in link down
208 if linkDownResult and topoResult and pingResult and intentResult:
209 main.log.info( itemName + ": Successfully brought link down" )
210 else:
211 main.log.error( itemName + ": Failed to bring link down" )
212
213 # Link up
214 linkUpResult = link( main, sw1, sw2, "up" )
215 time.sleep( main.rerouteSleep )
216
217 if linkUpResult:
218 main.assertReturnString += 'Link Up Passed\n'
219 else:
220 main.assertReturnString += 'Link Up Failed\n'
221
222 # Check flows count in each node
223 checkFlowsCount( main )
224 # Verify flows
225 checkFlowsState( main )
226
227 # Check OnosTopology
228 topoResult = checkTopology( main, main.numLinks )
229
230 if topoResult:
231 main.assertReturnString += 'Link Up Topology State Passed\n'
232 else:
233 main.assertReturnString += 'Link Up Topology State Failed\n'
234
235 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -0700236 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800237 pingResult = pingResult and pingTemp
238
239 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700240 main.assertReturnString += 'Link Up Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800241 else:
Jon Hall439c8912016-04-15 02:22:03 -0700242 main.assertReturnString += 'Link Up Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800243
244 intentTemp = checkIntentState( main, intentsId )
245 intentResult = intentResult and intentTemp
246 if intentTemp:
247 main.assertReturnString += 'Link Up Intent State Passed\n'
248 else:
249 main.assertReturnString += 'Link Up Intent State Failed\n'
250
251 # Checks ONOS state in link up
252 if linkUpResult and topoResult and pingResult and intentResult:
253 main.log.info( itemName + ": Successfully brought link back up" )
254 else:
255 main.log.error( itemName + ": Failed to bring link back up" )
256
257 # Remove all intents
258 removeIntentResult = removeAllIntents( main, intentsId )
259
260 if removeIntentResult:
261 main.assertReturnString += 'Remove Intents Passed'
262 else:
263 main.assertReturnString += 'Remove Intents Failed'
264
265 stepResult = pingResult and linkDownResult and linkUpResult \
266 and intentResult and removeIntentResult
267
268 return stepResult
269
270def pointIntent( main,
271 name,
272 host1,
273 host2,
274 onosNode=0,
275 deviceId1="",
276 deviceId2="",
277 port1="",
278 port2="",
279 ethType="",
280 mac1="",
281 mac2="",
282 bandwidth="",
283 lambdaAlloc=False,
284 ipProto="",
285 ip1="",
286 ip2="",
287 tcp1="",
288 tcp2="",
289 sw1="",
290 sw2="",
291 expectedLink=0 ):
292
293 """
294 Description:
295 Verify add-point-intent
296 Steps:
297 - Get device ids | ports
298 - Add point intents
299 - Check intents
300 - Verify flows
301 - Ping hosts
302 - Reroute
303 - Link down
304 - Verify flows
305 - Check topology
306 - Ping hosts
307 - Link up
308 - Verify flows
309 - Check topology
310 - Ping hosts
311 - Remove intents
312 Required:
313 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
314 host1 - Name of first host
315 host2 - Name of second host
316 Optional:
317 onosNode - ONOS node to install the intents in main.CLIs[ ]
318 0 by default so that it will always use the first
319 ONOS node
320 deviceId1 - ONOS device id of the first switch, the same as the
321 location of the first host eg. of:0000000000000001/1,
322 located at device 1 port 1
323 deviceId2 - ONOS device id of the second switch
324 port1 - The port number where the first host is attached
325 port2 - The port number where the second host is attached
326 ethType - Ethernet type eg. IPV4, IPV6
327 mac1 - Mac address of first host
328 mac2 - Mac address of the second host
329 bandwidth - Bandwidth capacity
330 lambdaAlloc - Allocate lambda, defaults to False
331 ipProto - IP protocol
332 ip1 - IP address of first host
333 ip2 - IP address of second host
334 tcp1 - TCP port of first host
335 tcp2 - TCP port of second host
336 sw1 - First switch to bring down & up for rerouting purpose
337 sw2 - Second switch to bring down & up for rerouting purpose
338 expectedLink - Expected link when the switches are down, it should
339 be two links lower than the links before the two
340 switches are down
341 """
342
343 assert main, "There is no main variable"
344 assert name, "variable name is empty"
345 assert host1 and host2, "You must specify hosts"
346
347 global itemName
348 itemName = name
349 host1 = host1
350 host2 = host2
351 hostNames = [ host1, host2 ]
352 intentsId = []
353
354 pingResult = main.TRUE
355 intentResult = main.TRUE
356 removeIntentResult = main.TRUE
357 flowResult = main.TRUE
358 topoResult = main.TRUE
359 linkDownResult = main.TRUE
360 linkUpResult = main.TRUE
361 onosNode = int( onosNode )
362
363 # Adding bidirectional point intents
364 main.log.info( itemName + ": Adding point intents" )
365 intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
366 egressDevice=deviceId2,
367 portIngress=port1,
368 portEgress=port2,
369 ethType=ethType,
370 ethSrc=mac1,
371 ethDst=mac2,
372 bandwidth=bandwidth,
373 lambdaAlloc=lambdaAlloc,
374 ipProto=ipProto,
375 ipSrc=ip1,
376 ipDst=ip2,
377 tcpSrc=tcp1,
378 tcpDst=tcp2 )
379
380 intentsId.append( intent1 )
381 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
382 egressDevice=deviceId1,
383 portIngress=port2,
384 portEgress=port1,
385 ethType=ethType,
386 ethSrc=mac2,
387 ethDst=mac1,
388 bandwidth=bandwidth,
389 lambdaAlloc=lambdaAlloc,
390 ipProto=ipProto,
391 ipSrc=ip2,
392 ipDst=ip1,
393 tcpSrc=tcp2,
394 tcpDst=tcp1 )
395 intentsId.append( intent2 )
396
397 # Check intents state
398 time.sleep( main.checkIntentSleep )
399 intentResult = checkIntentState( main, intentsId )
400 # Check flows count in each node
401 checkFlowsCount( main )
402
403 # Check intents state again if first check fails...
404 if not intentResult:
405 intentResult = checkIntentState( main, intentsId )
sathishmc4362252016-04-20 18:29:48 +0530406 if intentResult:
407 main.assertReturnString += 'Initial Intent State Passed\n'
408 else:
409 main.assertReturnString += 'Initial Intent State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800410
411 # Check flows count in each node
sathishmc4362252016-04-20 18:29:48 +0530412 FlowResult = checkFlowsCount( main )
413 if FlowResult:
414 main.assertReturnString += 'Initial Flow Count Passed\n'
415 else:
416 main.assertReturnString += 'Initial Flow Count Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800417 # Verify flows
sathishmc4362252016-04-20 18:29:48 +0530418 StateResult = checkFlowsState( main )
419 if StateResult:
420 main.assertReturnString += 'Initial Flow State Passed\n'
421 else:
422 main.assertReturnString += 'Initial Flow State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800423
424 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -0700425 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800426 pingResult = pingResult and pingTemp
427 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700428 main.assertReturnString += 'Initial Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800429 else:
Jon Hall439c8912016-04-15 02:22:03 -0700430 main.assertReturnString += 'Initial Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800431
432 # Test rerouting if these variables exist
433 if sw1 and sw2 and expectedLink:
434 # link down
435 linkDownResult = link( main, sw1, sw2, "down" )
436
437 if linkDownResult:
438 main.assertReturnString += 'Link Down Passed\n'
439 else:
440 main.assertReturnString += 'Link Down Failed\n'
441
442 # Check flows count in each node
443 checkFlowsCount( main )
444 # Verify flows
445 checkFlowsState( main )
446
447 # Check OnosTopology
448 topoResult = checkTopology( main, expectedLink )
449 if topoResult:
450 main.assertReturnString += 'Link Down Topology State Passed\n'
451 else:
452 main.assertReturnString += 'Link Down Topology State Failed\n'
453
454 # Ping hosts
Subhash Kumar Singh5ea4d302015-11-05 14:36:52 +0530455 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800456 pingResult = pingResult and pingTemp
457 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700458 main.assertReturnString += 'Link Down Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800459 else:
Jon Hall439c8912016-04-15 02:22:03 -0700460 main.assertReturnString += 'Link Down Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800461
462 # Check intent state
463 intentTemp = checkIntentState( main, intentsId )
464 intentResult = intentResult and intentTemp
465 if intentTemp:
466 main.assertReturnString += 'Link Down Intent State Passed\n'
467 else:
468 main.assertReturnString += 'Link Down Intent State Failed\n'
469
470 # Checks ONOS state in link down
471 if linkDownResult and topoResult and pingResult and intentResult:
472 main.log.info( itemName + ": Successfully brought link down" )
473 else:
474 main.log.error( itemName + ": Failed to bring link down" )
475
476 # link up
477 linkUpResult = link( main, sw1, sw2, "up" )
478 if linkUpResult:
479 main.assertReturnString += 'Link Up Passed\n'
480 else:
481 main.assertReturnString += 'Link Up Failed\n'
482
483 time.sleep( main.rerouteSleep )
484
485 # Check flows count in each node
486 checkFlowsCount( main )
487 # Verify flows
488 checkFlowsState( main )
489
490 # Check OnosTopology
491 topoResult = checkTopology( main, main.numLinks )
492 if topoResult:
493 main.assertReturnString += 'Link Up Topology State Passed\n'
494 else:
495 main.assertReturnString += 'Link Up Topology State Failed\n'
496
497 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -0700498 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800499 pingResult = pingResult and pingTemp
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800500 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700501 main.assertReturnString += 'Link Up Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800502 else:
Jon Hall439c8912016-04-15 02:22:03 -0700503 main.assertReturnString += 'Link Up Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800504
505 intentTemp = checkIntentState( main, intentsId )
506 intentResult = intentResult and intentTemp
507 if intentTemp:
508 main.assertReturnString += 'Link Up Intent State Passed\n'
509 else:
510 main.assertReturnString += 'Link Up Intent State Failed\n'
511
512 # Checks ONOS state in link up
513 if linkUpResult and topoResult and pingResult and intentResult:
514 main.log.info( itemName + ": Successfully brought link back up" )
515 else:
516 main.log.error( itemName + ": Failed to bring link back up" )
517
518 # Remove all intents
519 removeIntentResult = removeAllIntents( main, intentsId )
520 if removeIntentResult:
521 main.assertReturnString += 'Remove Intents Passed'
522 else:
523 main.assertReturnString += 'Remove Intents Failed'
524
525 stepResult = pingResult and linkDownResult and linkUpResult \
526 and intentResult and removeIntentResult
527
528 return stepResult
529
530def pointIntentTcp( main,
531 name,
532 host1,
533 host2,
534 onosNode=0,
535 deviceId1="",
536 deviceId2="",
537 port1="",
538 port2="",
539 ethType="",
540 mac1="",
541 mac2="",
542 bandwidth="",
543 lambdaAlloc=False,
544 ipProto="",
545 ip1="",
546 ip2="",
547 tcp1="",
548 tcp2="",
549 sw1="",
550 sw2="",
551 expectedLink=0 ):
552
553 """
554 Description:
555 Verify add-point-intent only for TCP
556 Steps:
557 - Get device ids | ports
558 - Add point intents
559 - Check intents
560 - Verify flows
561 - Ping hosts
562 - Reroute
563 - Link down
564 - Verify flows
565 - Check topology
566 - Ping hosts
567 - Link up
568 - Verify flows
569 - Check topology
570 - Ping hosts
571 - Remove intents
572 Required:
573 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
574 host1 - Name of first host
575 host2 - Name of second host
576 Optional:
577 onosNode - ONOS node to install the intents in main.CLIs[ ]
578 0 by default so that it will always use the first
579 ONOS node
580 deviceId1 - ONOS device id of the first switch, the same as the
581 location of the first host eg. of:0000000000000001/1,
582 located at device 1 port 1
583 deviceId2 - ONOS device id of the second switch
584 port1 - The port number where the first host is attached
585 port2 - The port number where the second host is attached
586 ethType - Ethernet type eg. IPV4, IPV6
587 mac1 - Mac address of first host
588 mac2 - Mac address of the second host
589 bandwidth - Bandwidth capacity
590 lambdaAlloc - Allocate lambda, defaults to False
591 ipProto - IP protocol
592 ip1 - IP address of first host
593 ip2 - IP address of second host
594 tcp1 - TCP port of first host
595 tcp2 - TCP port of second host
596 sw1 - First switch to bring down & up for rerouting purpose
597 sw2 - Second switch to bring down & up for rerouting purpose
598 expectedLink - Expected link when the switches are down, it should
599 be two links lower than the links before the two
600 switches are down
601 """
602
603 assert main, "There is no main variable"
604 assert name, "variable name is empty"
605 assert host1 and host2, "You must specify hosts"
606
607 global itemName
608 itemName = name
609 host1 = host1
610 host2 = host2
611 hostNames = [ host1, host2 ]
612 intentsId = []
613
614 iperfResult = main.TRUE
615 intentResult = main.TRUE
616 removeIntentResult = main.TRUE
617 flowResult = main.TRUE
618 topoResult = main.TRUE
619 linkDownResult = main.TRUE
620 linkUpResult = main.TRUE
621 onosNode = int( onosNode )
622
623 # Adding bidirectional point intents
624 main.log.info( itemName + ": Adding point intents" )
625 intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
626 egressDevice=deviceId2,
627 portIngress=port1,
628 portEgress=port2,
629 ethType=ethType,
630 ethSrc=mac1,
631 ethDst=mac2,
632 bandwidth=bandwidth,
633 lambdaAlloc=lambdaAlloc,
634 ipProto=ipProto,
635 ipSrc=ip1,
636 ipDst=ip2,
637 tcpSrc=tcp1,
638 tcpDst="" )
639
640 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
641 egressDevice=deviceId1,
642 portIngress=port2,
643 portEgress=port1,
644 ethType=ethType,
645 ethSrc=mac2,
646 ethDst=mac1,
647 bandwidth=bandwidth,
648 lambdaAlloc=lambdaAlloc,
649 ipProto=ipProto,
650 ipSrc=ip2,
651 ipDst=ip1,
652 tcpSrc=tcp2,
653 tcpDst="" )
654
655 intent3 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
656 egressDevice=deviceId2,
657 portIngress=port1,
658 portEgress=port2,
659 ethType=ethType,
660 ethSrc=mac1,
661 ethDst=mac2,
662 bandwidth=bandwidth,
663 lambdaAlloc=lambdaAlloc,
664 ipProto=ipProto,
665 ipSrc=ip1,
666 ipDst=ip2,
667 tcpSrc="",
668 tcpDst=tcp2 )
669
670 intent4 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
671 egressDevice=deviceId1,
672 portIngress=port2,
673 portEgress=port1,
674 ethType=ethType,
675 ethSrc=mac2,
676 ethDst=mac1,
677 bandwidth=bandwidth,
678 lambdaAlloc=lambdaAlloc,
679 ipProto=ipProto,
680 ipSrc=ip2,
681 ipDst=ip1,
682 tcpSrc="",
683 tcpDst=tcp1 )
684 intentsId.append( intent1 )
685 intentsId.append( intent2 )
686 intentsId.append( intent3 )
687 intentsId.append( intent4 )
688
689 # Check intents state
690 time.sleep( main.checkIntentSleep )
691 intentResult = checkIntentState( main, intentsId )
692 # Check flows count in each node
693 checkFlowsCount( main )
694
695 # Check intents state again if first check fails...
696 if not intentResult:
697 intentResult = checkIntentState( main, intentsId )
sathishmc4362252016-04-20 18:29:48 +0530698 if intentResult:
699 main.assertReturnString += 'Initial Intent State Passed\n'
700 else:
701 main.assertReturnString += 'Initial Intent State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800702
703 # Check flows count in each node
sathishmc4362252016-04-20 18:29:48 +0530704 FlowResult = checkFlowsCount( main )
705 if FlowResult:
706 main.assertReturnString += 'Initial Flow Count Passed\n'
707 else:
708 main.assertReturnString += 'Initial Flow Count Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800709 # Verify flows
sathishmc4362252016-04-20 18:29:48 +0530710 StateResult = checkFlowsState( main )
711 if StateResult:
712 main.assertReturnString += 'Initial Flow State Passed\n'
713 else:
714 main.assertReturnString += 'Initial Flow State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800715
sathishmc4362252016-04-20 18:29:48 +0530716 # Run iperf to both host
Jon Hall439c8912016-04-15 02:22:03 -0700717 iperfTemp = main.Mininet1.iperftcpipv6( host1,host2 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800718 iperfResult = iperfResult and iperfTemp
719 if iperfTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700720 main.assertReturnString += 'Initial Iperf6 Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800721 else:
Jon Hall439c8912016-04-15 02:22:03 -0700722 main.assertReturnString += 'Initial Iperf6 Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800723
724 # Test rerouting if these variables exist
725 if sw1 and sw2 and expectedLink:
726 # link down
727 linkDownResult = link( main, sw1, sw2, "down" )
728
729 if linkDownResult:
730 main.assertReturnString += 'Link Down Passed\n'
731 else:
732 main.assertReturnString += 'Link Down Failed\n'
733
734 # Check flows count in each node
735 checkFlowsCount( main )
736 # Verify flows
737 checkFlowsState( main )
738
739 # Check OnosTopology
740 topoResult = checkTopology( main, expectedLink )
741 if topoResult:
742 main.assertReturnString += 'Link Down Topology State Passed\n'
743 else:
744 main.assertReturnString += 'Link Down Topology State Failed\n'
745
746 # Run iperf to both host
Jon Hall439c8912016-04-15 02:22:03 -0700747 iperfTemp = main.Mininet1.iperftcpipv6( host1,host2 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800748 iperfResult = iperfResult and iperfTemp
749 if iperfTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700750 main.assertReturnString += 'Link Down Iperf6 Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800751 else:
Jon Hall439c8912016-04-15 02:22:03 -0700752 main.assertReturnString += 'Link Down Iperf6 Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800753
754 # Check intent state
755 intentTemp = checkIntentState( main, intentsId )
756 intentResult = intentResult and intentTemp
757 if intentTemp:
758 main.assertReturnString += 'Link Down Intent State Passed\n'
759 else:
760 main.assertReturnString += 'Link Down Intent State Failed\n'
761
762 # Checks ONOS state in link down
763 if linkDownResult and topoResult and iperfResult and intentResult:
764 main.log.info( itemName + ": Successfully brought link down" )
765 else:
766 main.log.error( itemName + ": Failed to bring link down" )
767
768 # link up
769 linkUpResult = link( main, sw1, sw2, "up" )
Jon Hall439c8912016-04-15 02:22:03 -0700770 if linkUpResult:
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800771 main.assertReturnString += 'Link Up Passed\n'
772 else:
773 main.assertReturnString += 'Link Up Failed\n'
774
775 time.sleep( main.rerouteSleep )
776
777 # Check flows count in each node
778 checkFlowsCount( main )
779 # Verify flows
780 checkFlowsState( main )
781
782 # Check OnosTopology
783 topoResult = checkTopology( main, main.numLinks )
784
785 if topoResult:
786 main.assertReturnString += 'Link Up Topology State Passed\n'
787 else:
788 main.assertReturnString += 'Link Up Topology State Failed\n'
789
790 # Run iperf to both host
Jon Hall439c8912016-04-15 02:22:03 -0700791 iperfTemp = main.Mininet1.iperftcpipv6( host1,host2,timeout=10 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800792 iperfResult = iperfResult and iperfTemp
793 if iperfTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700794 main.assertReturnString += 'Link Up Iperf6 Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800795 else:
Jon Hall439c8912016-04-15 02:22:03 -0700796 main.assertReturnString += 'Link Up Iperf6 Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800797
798 # Check intent state
799 intentTemp = checkIntentState( main, intentsId )
800 intentResult = intentResult and intentTemp
801 if intentTemp:
802 main.assertReturnString += 'Link Down Intent State Passed\n'
803 else:
804 main.assertReturnString += 'Link Down Intent State Failed\n'
805
806 # Checks ONOS state in link up
807 if linkUpResult and topoResult and iperfResult and intentResult:
808 main.log.info( itemName + ": Successfully brought link back up" )
809 else:
810 main.log.error( itemName + ": Failed to bring link back up" )
811
812 # Remove all intents
813 removeIntentResult = removeAllIntents( main, intentsId )
814 if removeIntentResult:
815 main.assertReturnString += 'Remove Intents Passed'
816 else:
817 main.assertReturnString += 'Remove Intents Failed'
818
819 stepResult = iperfResult and linkDownResult and linkUpResult \
820 and intentResult and removeIntentResult
821
822 return stepResult
823
824def singleToMultiIntent( main,
825 name,
Jon Hall439c8912016-04-15 02:22:03 -0700826 hostNames="",
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800827 onosNode=0,
828 devices="",
Jon Hall439c8912016-04-15 02:22:03 -0700829 ports="",
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800830 ethType="",
Jon Hall439c8912016-04-15 02:22:03 -0700831 macs="",
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800832 bandwidth="",
833 lambdaAlloc=False,
834 ipProto="",
835 ipAddresses="",
836 tcp="",
837 sw1="",
838 sw2="",
839 expectedLink=0 ):
840 """
841 Verify Single to Multi Point intents
842 NOTE:If main.hostsData is not defined, variables data should be passed
843 in the same order index wise. All devices in the list should have the same
844 format, either all the devices have its port or it doesn't.
845 eg. hostName = [ 'h1', 'h2' ,.. ]
846 devices = [ 'of:0000000000000001', 'of:0000000000000002', ...]
847 ports = [ '1', '1', ..]
848 ...
849 Description:
850 Verify add-single-to-multi-intent iterates through the list of given
851 host | devices and add intents
852 Steps:
853 - Get device ids | ports
854 - Add single to multi point intents
855 - Check intents
856 - Verify flows
857 - Ping hosts
858 - Reroute
859 - Link down
860 - Verify flows
861 - Check topology
862 - Ping hosts
863 - Link up
864 - Verify flows
865 - Check topology
866 - Ping hosts
867 - Remove intents
868 Required:
869 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
870 hostNames - List of host names
871 Optional:
872 onosNode - ONOS node to install the intents in main.CLIs[ ]
873 0 by default so that it will always use the first
874 ONOS node
875 devices - List of device ids in the same order as the hosts
876 in hostNames
877 ports - List of port numbers in the same order as the device in
878 devices
879 ethType - Ethernet type eg. IPV4, IPV6
880 macs - List of hosts mac address in the same order as the hosts in
881 hostNames
882 bandwidth - Bandwidth capacity
883 lambdaAlloc - Allocate lambda, defaults to False
884 ipProto - IP protocol
885 ipAddresses - IP addresses of host in the same order as the hosts in
886 hostNames
887 tcp - TCP ports in the same order as the hosts in hostNames
888 sw1 - First switch to bring down & up for rerouting purpose
889 sw2 - Second switch to bring down & up for rerouting purpose
890 expectedLink - Expected link when the switches are down, it should
891 be two links lower than the links before the two
892 switches are down
893 """
894
895 assert main, "There is no main variable"
896 assert hostNames, "You must specify hosts"
897 assert devices or main.hostsData, "You must specify devices"
898
899 global itemName
900 itemName = name
901 tempHostsData = {}
902 intentsId = []
903 onosNode = int( onosNode )
904
905 macsDict = {}
906 ipDict = {}
907 if hostNames and devices:
908 if len( hostNames ) != len( devices ):
909 main.log.debug( "hosts and devices does not have the same length" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800910 return main.FALSE
911 if ports:
912 if len( ports ) != len( devices ):
913 main.log.error( "Ports and devices does " +
914 "not have the same length" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800915 return main.FALSE
916 else:
917 main.log.info( "Device Ports are not specified" )
918 if macs:
919 for i in range( len( devices ) ):
920 macsDict[ devices[ i ] ] = macs[ i ]
921
922 elif hostNames and not devices and main.hostsData:
923 devices = []
924 main.log.info( "singleToMultiIntent function is using main.hostsData" )
925 for host in hostNames:
926 devices.append( main.hostsData.get( host ).get( 'location' ) )
927 macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \
928 main.hostsData.get( host ).get( 'mac' )
929 ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \
930 main.hostsData.get( host ).get( 'ipAddresses' )
sathishmc4362252016-04-20 18:29:48 +0530931
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800932 pingResult = main.TRUE
933 intentResult = main.TRUE
934 removeIntentResult = main.TRUE
935 flowResult = main.TRUE
936 topoResult = main.TRUE
937 linkDownResult = main.TRUE
938 linkUpResult = main.TRUE
939
940 devicesCopy = copy.copy( devices )
941 if ports:
942 portsCopy = copy.copy( ports )
943 main.log.info( itemName + ": Adding single point to multi point intents" )
944
945 # Check flows count in each node
946 checkFlowsCount( main )
947
948 # Adding bidirectional point intents
949 for i in range( len( devices ) ):
950 ingressDevice = devicesCopy[ i ]
951 egressDeviceList = copy.copy( devicesCopy )
952 egressDeviceList.remove( ingressDevice )
953 if ports:
954 portIngress = portsCopy[ i ]
955 portEgressList = copy.copy( portsCopy )
956 del portEgressList[ i ]
957 else:
958 portIngress = ""
959 portEgressList = None
960 if not macsDict:
961 srcMac = ""
962 else:
963 srcMac = macsDict[ ingressDevice ]
964 if srcMac == None:
965 main.log.debug( "There is no MAC in device - " + ingressDevice )
966 srcMac = ""
967
968 intentsId.append(
969 main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
970 ingressDevice=ingressDevice,
971 egressDeviceList=egressDeviceList,
972 portIngress=portIngress,
973 portEgressList=portEgressList,
974 ethType=ethType,
975 ethSrc=srcMac,
976 bandwidth=bandwidth,
977 lambdaAlloc=lambdaAlloc,
978 ipProto=ipProto,
979 ipSrc="",
980 ipDst="",
981 tcpSrc="",
982 tcpDst="" ) )
983
sathishmc4362252016-04-20 18:29:48 +0530984
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800985 # Check intents state
986 time.sleep( main.checkIntentSleep )
987 intentResult = checkIntentState( main, intentsId )
988
989 # Check intents state again if first check fails...
990 if not intentResult:
991 intentResult = checkIntentState( main, intentsId )
sathishmc4362252016-04-20 18:29:48 +0530992 if intentResult:
993 main.assertReturnString += 'Initial Intent State Passed\n'
994 else:
995 main.assertReturnString += 'Initial Intent State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800996
997 # Check flows count in each node
sathishmc4362252016-04-20 18:29:48 +0530998 FlowResult = checkFlowsCount( main )
999 if FlowResult:
1000 main.assertReturnString += 'Initial Flow Count Passed\n'
1001 else:
1002 main.assertReturnString += 'Initial Flow Count Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001003 # Verify flows
sathishmc4362252016-04-20 18:29:48 +05301004 StateResult = checkFlowsState( main )
1005 if StateResult:
1006 main.assertReturnString += 'Initial Flow State Passed\n'
1007 else:
1008 main.assertReturnString += 'Initial Flow State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001009
Jon Hall439c8912016-04-15 02:22:03 -07001010 firstPingResult = main.Mininet1.ping6pair(SRC=hostNames[0], TARGET=main.hostsData[ hostNames[1] ][ 'ipAddresses' ][0])
1011 if not firstPingResult:
1012 main.log.debug( "First ping failed, there must be" +
1013 " something wrong with ONOS performance" )
1014
1015 # Ping hosts again...
1016 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001017 pingResult = pingResult and pingTemp
1018 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001019 main.assertReturnString += 'Initial Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001020 else:
Jon Hall439c8912016-04-15 02:22:03 -07001021 main.assertReturnString += 'Initial Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001022
1023 # Test rerouting if these variables exist
1024 if sw1 and sw2 and expectedLink:
1025 # link down
1026 linkDownResult = link( main, sw1, sw2, "down" )
1027
1028 if linkDownResult:
1029 main.assertReturnString += 'Link Down Passed\n'
1030 else:
1031 main.assertReturnString += 'Link Down Failed\n'
1032
1033 # Check flows count in each node
1034 checkFlowsCount( main )
1035 # Verify flows
1036 checkFlowsState( main )
1037
1038 # Check OnosTopology
1039 topoResult = checkTopology( main, expectedLink )
1040 if topoResult:
1041 main.assertReturnString += 'Link Down Topology State Passed\n'
1042 else:
1043 main.assertReturnString += 'Link Down Topology State Failed\n'
1044
1045 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -07001046 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001047 pingResult = pingResult and pingTemp
1048 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001049 main.assertReturnString += 'Link Down Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001050 else:
Jon Hall439c8912016-04-15 02:22:03 -07001051 main.assertReturnString += 'Link Down Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001052
1053 # Check intent state
1054 intentTemp = checkIntentState( main, intentsId )
1055 intentResult = intentResult and intentTemp
1056 if intentTemp:
1057 main.assertReturnString += 'Link Down Intent State Passed\n'
1058 else:
1059 main.assertReturnString += 'Link Down Intent State Failed\n'
1060
1061 # Checks ONOS state in link down
1062 if linkDownResult and topoResult and pingResult and intentResult:
1063 main.log.info( itemName + ": Successfully brought link down" )
1064 else:
1065 main.log.error( itemName + ": Failed to bring link down" )
1066
1067 # link up
1068 linkUpResult = link( main, sw1, sw2, "up" )
1069 if linkUpResult:
1070 main.assertReturnString += 'Link Up Passed\n'
1071 else:
1072 main.assertReturnString += 'Link Up Failed\n'
1073
1074 time.sleep( main.rerouteSleep )
1075
1076 # Check flows count in each node
1077 checkFlowsCount( main )
1078 # Verify flows
1079 checkFlowsState( main )
1080
1081 # Check OnosTopology
1082 topoResult = checkTopology( main, main.numLinks )
1083 if topoResult:
1084 main.assertReturnString += 'Link Up Topology State Passed\n'
1085 else:
1086 main.assertReturnString += 'Link Up Topology State Failed\n'
1087
1088 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -07001089 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001090 pingResult = pingResult and pingTemp
1091 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001092 main.assertReturnString += 'Link Up Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001093 else:
Jon Hall439c8912016-04-15 02:22:03 -07001094 main.assertReturnString += 'Link Up Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001095
1096 # Check Intents
1097 intentTemp = checkIntentState( main, intentsId )
1098 intentResult = intentResult and intentTemp
1099 if intentTemp:
1100 main.assertReturnString += 'Link Up Intent State Passed\n'
1101 else:
1102 main.assertReturnString += 'Link Up Intent State Failed\n'
1103
1104 # Checks ONOS state in link up
1105 if linkUpResult and topoResult and pingResult and intentResult:
1106 main.log.info( itemName + ": Successfully brought link back up" )
1107 else:
1108 main.log.error( itemName + ": Failed to bring link back up" )
1109
1110 # Remove all intents
1111 removeIntentResult = removeAllIntents( main, intentsId )
1112 if removeIntentResult:
1113 main.assertReturnString += 'Remove Intents Passed'
1114 else:
1115 main.assertReturnString += 'Remove Intents Failed'
1116
1117 stepResult = pingResult and linkDownResult and linkUpResult \
1118 and intentResult and removeIntentResult
1119
1120 return stepResult
1121
1122def multiToSingleIntent( main,
1123 name,
Jon Hall439c8912016-04-15 02:22:03 -07001124 hostNames="",
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001125 onosNode=0,
1126 devices="",
Jon Hall439c8912016-04-15 02:22:03 -07001127 ports="",
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001128 ethType="",
Jon Hall439c8912016-04-15 02:22:03 -07001129 macs="",
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001130 bandwidth="",
1131 lambdaAlloc=False,
1132 ipProto="",
1133 ipAddresses="",
1134 tcp="",
1135 sw1="",
1136 sw2="",
1137 expectedLink=0 ):
1138 """
1139 Verify Single to Multi Point intents
1140 NOTE:If main.hostsData is not defined, variables data should be passed in the
1141 same order index wise. All devices in the list should have the same
1142 format, either all the devices have its port or it doesn't.
1143 eg. hostName = [ 'h1', 'h2' ,.. ]
1144 devices = [ 'of:0000000000000001', 'of:0000000000000002', ...]
1145 ports = [ '1', '1', ..]
1146 ...
1147 Description:
1148 Verify add-multi-to-single-intent
1149 Steps:
1150 - Get device ids | ports
1151 - Add multi to single point intents
1152 - Check intents
1153 - Verify flows
1154 - Ping hosts
1155 - Reroute
1156 - Link down
1157 - Verify flows
1158 - Check topology
1159 - Ping hosts
1160 - Link up
1161 - Verify flows
1162 - Check topology
1163 - Ping hosts
1164 - Remove intents
1165 Required:
1166 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
1167 hostNames - List of host names
1168 Optional:
1169 onosNode - ONOS node to install the intents in main.CLIs[ ]
1170 0 by default so that it will always use the first
1171 ONOS node
1172 devices - List of device ids in the same order as the hosts
1173 in hostNames
1174 ports - List of port numbers in the same order as the device in
1175 devices
1176 ethType - Ethernet type eg. IPV4, IPV6
1177 macs - List of hosts mac address in the same order as the hosts in
1178 hostNames
1179 bandwidth - Bandwidth capacity
1180 lambdaAlloc - Allocate lambda, defaults to False
1181 ipProto - IP protocol
1182 ipAddresses - IP addresses of host in the same order as the hosts in
1183 hostNames
1184 tcp - TCP ports in the same order as the hosts in hostNames
1185 sw1 - First switch to bring down & up for rerouting purpose
1186 sw2 - Second switch to bring down & up for rerouting purpose
1187 expectedLink - Expected link when the switches are down, it should
1188 be two links lower than the links before the two
1189 switches are down
sathishmc4362252016-04-20 18:29:48 +05301190 Note - Don't use more than 2 hosts for MultiToSingle Intent with no mac address option.
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001191 """
1192
1193 assert main, "There is no main variable"
1194 assert hostNames, "You must specify hosts"
1195 assert devices or main.hostsData, "You must specify devices"
1196
1197 global itemName
1198 itemName = name
1199 tempHostsData = {}
1200 intentsId = []
1201 onosNode = int( onosNode )
1202
1203 macsDict = {}
1204 ipDict = {}
1205 if hostNames and devices:
1206 if len( hostNames ) != len( devices ):
1207 main.log.debug( "hosts and devices does not have the same length" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001208 return main.FALSE
1209 if ports:
1210 if len( ports ) != len( devices ):
1211 main.log.error( "Ports and devices does " +
1212 "not have the same length" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001213 return main.FALSE
1214 else:
1215 main.log.info( "Device Ports are not specified" )
1216 if macs:
1217 for i in range( len( devices ) ):
1218 macsDict[ devices[ i ] ] = macs[ i ]
1219 elif hostNames and not devices and main.hostsData:
1220 devices = []
1221 main.log.info( "multiToSingleIntent function is using main.hostsData" )
1222 for host in hostNames:
1223 devices.append( main.hostsData.get( host ).get( 'location' ) )
1224 macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \
1225 main.hostsData.get( host ).get( 'mac' )
1226 ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \
1227 main.hostsData.get( host ).get( 'ipAddresses' )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001228
1229 pingResult = main.TRUE
1230 intentResult = main.TRUE
1231 removeIntentResult = main.TRUE
1232 flowResult = main.TRUE
1233 topoResult = main.TRUE
1234 linkDownResult = main.TRUE
1235 linkUpResult = main.TRUE
1236
1237 devicesCopy = copy.copy( devices )
1238 if ports:
1239 portsCopy = copy.copy( ports )
1240 main.log.info( itemName + ": Adding multi point to single point intents" )
1241
1242 # Check flows count in each node
1243 checkFlowsCount( main )
1244
1245 # Adding bidirectional point intents
1246 for i in range( len( devices ) ):
1247 egressDevice = devicesCopy[ i ]
1248 ingressDeviceList = copy.copy( devicesCopy )
1249 ingressDeviceList.remove( egressDevice )
1250 if ports:
1251 portEgress = portsCopy[ i ]
1252 portIngressList = copy.copy( portsCopy )
1253 del portIngressList[ i ]
1254 else:
1255 portEgress = ""
1256 portIngressList = None
1257 if not macsDict:
1258 dstMac = ""
1259 else:
1260 dstMac = macsDict[ egressDevice ]
1261 if dstMac == None:
1262 main.log.debug( "There is no MAC in device - " + egressDevice )
1263 dstMac = ""
1264
1265 intentsId.append(
1266 main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
1267 ingressDeviceList=ingressDeviceList,
1268 egressDevice=egressDevice,
1269 portIngressList=portIngressList,
1270 portEgress=portEgress,
1271 ethType=ethType,
1272 ethDst=dstMac,
1273 bandwidth=bandwidth,
1274 lambdaAlloc=lambdaAlloc,
1275 ipProto=ipProto,
1276 ipSrc="",
1277 ipDst="",
1278 tcpSrc="",
1279 tcpDst="" ) )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001280 # Check intents state
1281 time.sleep( main.checkIntentSleep )
1282 intentResult = checkIntentState( main, intentsId )
1283
1284 # Check intents state again if first check fails...
1285 if not intentResult:
1286 intentResult = checkIntentState( main, intentsId )
sathishmc4362252016-04-20 18:29:48 +05301287 if intentResult:
1288 main.assertReturnString += 'Initial Intent State Passed\n'
1289 else:
1290 main.assertReturnString += 'Initial Intent State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001291
1292 # Check flows count in each node
sathishmc4362252016-04-20 18:29:48 +05301293 FlowResult = checkFlowsCount( main )
1294 if FlowResult:
1295 main.assertReturnString += 'Initial Flow Count Passed\n'
1296 else:
1297 main.assertReturnString += 'Initial Flow Count Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001298 # Verify flows
sathishmc4362252016-04-20 18:29:48 +05301299 StateResult = checkFlowsState( main )
1300 if StateResult:
1301 main.assertReturnString += 'Initial Flow State Passed\n'
1302 else:
1303 main.assertReturnString += 'Initial Flow State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001304
Jon Hall439c8912016-04-15 02:22:03 -07001305 # Ping hosts...
1306 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001307 pingResult = pingResult and pingTemp
1308 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001309 main.assertReturnString += 'Initial Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001310 else:
Jon Hall439c8912016-04-15 02:22:03 -07001311 main.assertReturnString += 'Initial Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001312
1313 # Test rerouting if these variables exist
1314 if sw1 and sw2 and expectedLink:
1315 # link down
1316 linkDownResult = link( main, sw1, sw2, "down" )
1317
1318 if linkDownResult:
1319 main.assertReturnString += 'Link Down Passed\n'
1320 else:
1321 main.assertReturnString += 'Link Down Failed\n'
1322
1323 # Check flows count in each node
1324 checkFlowsCount( main )
1325 # Verify flows
1326 checkFlowsState( main )
1327
1328 # Check OnosTopology
1329 topoResult = checkTopology( main, expectedLink )
1330 if topoResult:
1331 main.assertReturnString += 'Link Down Topology State Passed\n'
1332 else:
1333 main.assertReturnString += 'Link Down Topology State Failed\n'
1334
1335 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -07001336 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001337 pingResult = pingResult and pingTemp
1338 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001339 main.assertReturnString += 'Link Down Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001340 else:
Jon Hall439c8912016-04-15 02:22:03 -07001341 main.assertReturnString += 'Link Down Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001342
1343 # Check intent state
1344 intentTemp = checkIntentState( main, intentsId )
1345 intentResult = intentResult and intentTemp
1346 if intentTemp:
1347 main.assertReturnString += 'Link Down Intent State Passed\n'
1348 else:
1349 main.assertReturnString += 'Link Down Intent State Failed\n'
1350
1351 # Checks ONOS state in link down
1352 if linkDownResult and topoResult and pingResult and intentResult:
1353 main.log.info( itemName + ": Successfully brought link down" )
1354 else:
1355 main.log.error( itemName + ": Failed to bring link down" )
1356
1357 # link up
1358 linkUpResult = link( main, sw1, sw2, "up" )
1359 if linkUpResult:
1360 main.assertReturnString += 'Link Up Passed\n'
1361 else:
1362 main.assertReturnString += 'Link Up Failed\n'
1363
1364 time.sleep( main.rerouteSleep )
1365
1366 # Check flows count in each node
1367 checkFlowsCount( main )
1368 # Verify flows
1369 checkFlowsState( main )
1370
1371 # Check OnosTopology
1372 topoResult = checkTopology( main, main.numLinks )
1373 if topoResult:
1374 main.assertReturnString += 'Link Up Topology State Passed\n'
1375 else:
1376 main.assertReturnString += 'Link Up Topology State Failed\n'
1377
1378 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -07001379 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001380 pingResult = pingResult and pingTemp
1381 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001382 main.assertReturnString += 'Link Up Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001383 else:
Jon Hall439c8912016-04-15 02:22:03 -07001384 main.assertReturnString += 'Link Up Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001385
1386 # Check Intents
1387 intentTemp = checkIntentState( main, intentsId )
1388 intentResult = intentResult and intentTemp
1389 if intentTemp:
1390 main.assertReturnString += 'Link Up Intent State Passed\n'
1391 else:
1392 main.assertReturnString += 'Link Up Intent State Failed\n'
1393
1394 # Checks ONOS state in link up
1395 if linkUpResult and topoResult and pingResult and intentResult:
1396 main.log.info( itemName + ": Successfully brought link back up" )
1397 else:
1398 main.log.error( itemName + ": Failed to bring link back up" )
1399
1400 # Remove all intents
1401 removeIntentResult = removeAllIntents( main, intentsId )
1402 if removeIntentResult:
1403 main.assertReturnString += 'Remove Intents Passed'
1404 else:
1405 main.assertReturnString += 'Remove Intents Failed'
1406
1407 stepResult = pingResult and linkDownResult and linkUpResult \
1408 and intentResult and removeIntentResult
1409
1410 return stepResult
1411
sathishmc4362252016-04-20 18:29:48 +05301412def testEndPointFail( main,
1413 name,
1414 test="",
1415 hostNames="",
1416 devices="",
1417 macs="",
1418 ports="",
1419 onosNode=0,
1420 ethType="",
1421 bandwidth="",
1422 lambdaAlloc=False,
1423 ipProto="",
1424 ipAddresses="",
1425 tcp="",
1426 sw1="",
1427 sw2="",
1428 sw3="",
1429 sw4="",
1430 sw5="",
1431 expectedLink1=0,
1432 expectedLink2=0 ):
1433 """
1434 Test Multipoint Topology for Endpoint failures
1435 """
1436
1437 assert main, "There is no main variable"
1438 assert hostNames, "You must specify hosts"
1439 assert devices or main.hostsData, "You must specify devices"
1440
1441 global itemName
1442 itemName = name
1443 tempHostsData = {}
1444 intentsId = []
1445 onosNode = int( onosNode )
1446
1447 macsDict = {}
1448 ipDict = {}
1449 if hostNames and devices:
1450 if len( hostNames ) != len( devices ):
1451 main.log.debug( "hosts and devices does not have the same length" )
1452 return main.FALSE
1453 if ports:
1454 if len( ports ) != len( devices ):
1455 main.log.error( "Ports and devices does " +
1456 "not have the same length" )
1457 return main.FALSE
1458 else:
1459 main.log.info( "Device Ports are not specified" )
1460 if macs:
1461 for i in range( len( devices ) ):
1462 macsDict[ devices[ i ] ] = macs[ i ]
1463 elif hostNames and not devices and main.hostsData:
1464 devices = []
1465 main.log.info( "multiIntent function is using main.hostsData" )
1466 for host in hostNames:
1467 devices.append( main.hostsData.get( host ).get( 'location' ) )
1468 macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \
1469 main.hostsData.get( host ).get( 'mac' )
1470 ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \
1471 main.hostsData.get( host ).get( 'ipAddresses' )
1472
1473 pingResult = main.TRUE
1474 intentResult = main.TRUE
1475 removeIntentResult = main.TRUE
1476 flowResult = main.TRUE
1477 topoResult = main.TRUE
1478 linkDownResult = main.TRUE
1479 linkUpResult = main.TRUE
1480
1481 devicesCopy = copy.copy( devices )
1482 if ports:
1483 portsCopy = copy.copy( ports )
1484 main.log.info( itemName + ": Adding intents" )
1485
1486 # Check flows count in each node
1487 checkFlowsCount( main )
1488
1489 if test=="MultipletoSingle":
1490 for i in range( len( devices ) ):
1491 egressDevice = devicesCopy[ i ]
1492 ingressDeviceList = copy.copy( devicesCopy )
1493 ingressDeviceList.remove( egressDevice )
1494 if ports:
1495 portEgress = portsCopy[ i ]
1496 portIngressList = copy.copy( portsCopy )
1497 del portIngressList[ i ]
1498 else:
1499 portEgress = ""
1500 portIngressList = None
1501 if not macsDict:
1502 dstMac = ""
1503 else:
1504 dstMac = macsDict[ egressDevice ]
1505 if dstMac == None:
1506 main.log.debug( "There is no MAC in device - " + egressDevice )
1507 dstMac = ""
1508
1509 intentsId.append(
1510 main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
1511 ingressDeviceList=ingressDeviceList,
1512 egressDevice=egressDevice,
1513 portIngressList=portIngressList,
1514 portEgress=portEgress,
1515 ethType=ethType,
1516 ethDst=dstMac,
1517 bandwidth=bandwidth,
1518 lambdaAlloc=lambdaAlloc,
1519 ipProto=ipProto,
1520 ipSrc="",
1521 ipDst="",
1522 tcpSrc="",
1523 tcpDst="" ) )
1524
1525
1526 elif test=="SingletoMultiple":
1527 for i in range( len( devices ) ):
1528 ingressDevice = devicesCopy[ i ]
1529 egressDeviceList = copy.copy( devicesCopy )
1530 egressDeviceList.remove( ingressDevice )
1531 if ports:
1532 portIngress = portsCopy[ i ]
1533 portEgressList = copy.copy( portsCopy )
1534 del portEgressList[ i ]
1535 else:
1536 portIngress = ""
1537 portEgressList = None
1538 if not macsDict:
1539 srcMac = ""
1540 else:
1541 srcMac = macsDict[ ingressDevice ]
1542 if srcMac == None:
1543 main.log.debug( "There is no MAC in device - " + ingressDevice )
1544 srcMac = ""
1545
1546 intentsId.append(
1547 main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
1548 ingressDevice=ingressDevice,
1549 egressDeviceList=egressDeviceList,
1550 portIngress=portIngress,
1551 portEgressList=portEgressList,
1552 ethType=ethType,
1553 ethSrc=srcMac,
1554 bandwidth=bandwidth,
1555 lambdaAlloc=lambdaAlloc,
1556 ipProto=ipProto,
1557 ipSrc="",
1558 ipDst="",
1559 tcpSrc="",
1560 tcpDst="" ) )
1561
1562 else:
1563 main.log.info("Invalid test Name - Type either SingletoMultiple or MultipletoSingle")
1564 return main.FALSE
1565
1566 # Check intents state
1567 time.sleep( main.checkIntentSleep )
1568 intentResult = checkIntentState( main, intentsId )
1569
1570 # Check intents state again if first check fails...
1571 if not intentResult:
1572 intentResult = checkIntentState( main, intentsId )
1573 if intentResult:
1574 main.assertReturnString += 'Initial Intent State Passed\n'
1575 else:
1576 main.assertReturnString += 'Initial Intent State Failed\n'
1577
1578 # Check flows count in each node
1579 FlowResult = checkFlowsCount( main )
1580 if FlowResult:
1581 main.assertReturnString += 'Initial Flow Count Passed\n'
1582 else:
1583 main.assertReturnString += 'Initial Flow Count Failed\n'
1584 # Verify flows
1585 StateResult = checkFlowsState( main )
1586 if StateResult:
1587 main.assertReturnString += 'Initial Flow State Passed\n'
1588 else:
1589 main.assertReturnString += 'Initial Flow State Failed\n'
1590
1591 # Ping hosts...
1592 pingTemp = ping6allHosts( main, hostNames )
1593 pingResult = pingResult and pingTemp
1594 if pingTemp:
1595 main.assertReturnString += 'Initial Pingall Passed\n'
1596 else:
1597 main.assertReturnString += 'Initial Pingall Failed\n'
1598
1599 # Test rerouting if these variables exist
1600 if sw1 and sw2 and sw3 and sw4 and sw5 and expectedLink1 and expectedLink2:
1601 # Take two links down
1602 # Take first link down
1603 linkDownResult1 = link( main, sw1, sw2, "down" )
1604 if linkDownResult1:
1605 main.assertReturnString += 'First Link Down Passed\n'
1606 else:
1607 main.assertReturnString += 'First Link Down Failed\n'
1608
1609 # Take second link down
1610 linkDownResult2 = link( main, sw3, sw4, "down" )
1611 if linkDownResult2:
1612 main.assertReturnString += 'Second Link Down Passed\n'
1613 else:
1614 main.assertReturnString += 'Second Link Down Failed\n'
1615
1616 # Check flows count in each node
1617 FlowResult = checkFlowsCount( main )
1618 if FlowResult:
1619 main.assertReturnString += 'Link Down Flow Count Passed\n'
1620 else:
1621 main.assertReturnString += 'Link Down Flow Count Failed\n'
1622 # Verify flows
1623 StateResult = checkFlowsState( main )
1624 if StateResult:
1625 main.assertReturnString += 'Link Down Flow State Passed\n'
1626 else:
1627 main.assertReturnString += 'Link Down Flow State Failed\n'
1628
1629 # Check OnosTopology
1630 topoResult = checkTopology( main, expectedLink1 )
1631 if topoResult:
1632 main.assertReturnString += 'Link Down Topology State Passed\n'
1633 else:
1634 main.assertReturnString += 'Link Down Topology State Failed\n'
1635
1636 # Ping hosts
1637 pingTemp = ping6allHosts( main, hostNames )
1638 pingResult = pingResult and pingTemp
1639 if pingTemp:
1640 main.assertReturnString += 'Link Down Ping6all Passed\n'
1641 else:
1642 main.assertReturnString += 'Link Down Ping6all Failed\n'
1643
1644 # Check intent state
1645 intentTemp = checkIntentState( main, intentsId )
1646 intentResult = intentResult and intentTemp
1647 if intentTemp:
1648 main.assertReturnString += 'Link Down Intent State Passed\n'
1649 else:
1650 main.assertReturnString += 'Link Down Intent State Failed\n'
1651
1652 # Take third link down to isolate the node
1653 linkDownResult3 = link( main, sw3, sw5, "down" )
1654 if linkDownResult3:
1655 main.assertReturnString += 'Isolation Third Link Down Passed\n'
1656 else:
1657 main.assertReturnString += 'Isolation Third Link Down Failed\n'
1658
1659 # Check flows count in each node
1660 FlowResult = checkFlowsCount( main )
1661 if FlowResult:
1662 main.assertReturnString += 'Isolation Link Down Flow Count Passed\n'
1663 else:
1664 main.assertReturnString += 'Isolation Link Down Flow Count Failed\n'
1665
1666 # Verify flows
1667 StateResult = checkFlowsState( main )
1668 if StateResult:
1669 main.assertReturnString += 'Isolation Link Down Flow State Passed\n'
1670 else:
1671 main.assertReturnString += 'Isolation Link Down Flow State Failed\n'
1672
1673 # Check OnosTopology
1674 topoResult = checkTopology( main, expectedLink2 )
1675 if topoResult:
1676 main.assertReturnString += 'Isolation Link Down Topology State Passed\n'
1677 else:
1678 main.assertReturnString += 'Isolation Link Down Topology State Failed\n'
1679
1680 # Ping hosts after isolation
1681 main.log.info("Ping will fail if the node is isolated correctly.It will ping only after bringing up the isolation link")
1682 pingIsolation = ping6allHosts( main, hostNames )
1683 if pingIsolation:
1684 main.assertReturnString += 'Isolation Link Down Ping6all Passed\n'
1685 else:
1686 main.assertReturnString += 'Isolation Link Down Ping6all Failed\n'
1687
1688 # Check intent state after isolation
1689 main.log.info("Intent will be in FAILED state if the node is isolated correctly.It will be in INSTALLED state only after bringing up isolation link")
1690 intentIsolation = checkIntentState( main, intentsId )
1691 if intentIsolation:
1692 main.assertReturnString += 'Isolation Link Down Intent State Passed\n'
1693 else:
1694 main.assertReturnString += 'Isolation Link Down Intent State Failed\n'
1695
1696 linkDownResult = linkDownResult1 and linkDownResult2 and linkDownResult3
1697
1698 # Checks ONOS state in link down
1699 if linkDownResult and topoResult and pingResult and intentResult:
1700 main.log.info( itemName + ": Successfully brought link down" )
1701 else:
1702 main.log.error( itemName + ": Failed to bring link down" )
1703
1704 # Bring the links back up
1705 # Bring first link up
1706 linkUpResult1 = link( main, sw1, sw2, "up" )
1707 if linkUpResult1:
1708 main.assertReturnString += 'First Link Up Passed\n'
1709 else:
1710 main.assertReturnString += 'First Link Up Failed\n'
1711
1712 # Bring second link up
1713 linkUpResult2 = link( main, sw3, sw4, "up" )
1714 if linkUpResult2:
1715 main.assertReturnString += 'Second Link Up Passed\n'
1716 else:
1717 main.assertReturnString += 'Second Link Up Failed\n'
1718 # Bring third link up
1719 linkUpResult3 = link( main, sw3, sw5, "up" )
1720 if linkUpResult3:
1721 main.assertReturnString += 'Third Link Up Passed\n'
1722 else:
1723 main.assertReturnString += 'Third Link Up Failed\n'
1724
1725 linkUpResult = linkUpResult1 and linkUpResult2 and linkUpResult3
1726 time.sleep( main.rerouteSleep )
1727
1728 # Check flows count in each node
1729 FlowResult = checkFlowsCount( main )
1730 if FlowResult:
1731 main.assertReturnString += 'Link Up Flow Count Passed\n'
1732 else:
1733 main.assertReturnString += 'Link Up Flow Count Failed\n'
1734 # Verify flows
1735 StateResult = checkFlowsState( main )
1736 if StateResult:
1737 main.assertReturnString += 'Link Up Flow State Passed\n'
1738 else:
1739 main.assertReturnString += 'Link Up Flow State Failed\n'
1740
1741 # Check OnosTopology
1742 topoResult = checkTopology( main, main.numLinks )
1743 if topoResult:
1744 main.assertReturnString += 'Link Up Topology State Passed\n'
1745 else:
1746 main.assertReturnString += 'Link Up Topology State Failed\n'
1747
1748 # Ping hosts
1749 pingTemp = ping6allHosts( main, hostNames )
1750 pingResult = pingResult and pingTemp
1751 if pingTemp:
1752 main.assertReturnString += 'Link Up Pingall Passed\n'
1753 else:
1754 main.assertReturnString += 'Link Up Pingall Failed\n'
1755
1756 # Check Intents
1757 intentTemp = checkIntentState( main, intentsId )
1758 intentResult = intentResult and intentTemp
1759 if intentTemp:
1760 main.assertReturnString += 'Link Up Intent State Passed\n'
1761 else:
1762 main.assertReturnString += 'Link Up Intent State Failed\n'
1763
1764 # Checks ONOS state in link up
1765 if linkUpResult and topoResult and pingResult and intentResult:
1766 main.log.info( itemName + ": Successfully brought link back up" )
1767 else:
1768 main.log.error( itemName + ": Failed to bring link back up" )
1769
1770 # Remove all intents
1771 removeIntentResult = removeAllIntents( main, intentsId )
1772 if removeIntentResult:
1773 main.assertReturnString += 'Remove Intents Passed'
1774 else:
1775 main.assertReturnString += 'Remove Intents Failed'
1776
1777 testResult = pingResult and linkDownResult and linkUpResult \
1778 and intentResult and removeIntentResult
1779
1780 return testResult
1781
Subhash Kumar Singh5ea4d302015-11-05 14:36:52 +05301782def ping6allHosts( main, hostList ):
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001783 # Ping all host in the hosts list variable
1784 main.log.info( "Pinging: " + str( hostList ) )
Subhash Kumar Singh5ea4d302015-11-05 14:36:52 +05301785 return main.Mininet1.pingIpv6Hosts( hostList )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001786
1787def getHostsData( main ):
1788 """
1789 Use fwd app and pingall to discover all the hosts
1790 """
1791
1792 activateResult = main.TRUE
1793 appCheck = main.TRUE
1794 getDataResult = main.TRUE
1795 main.log.info( "Activating reactive forwarding app " )
1796 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
Jon Hall439c8912016-04-15 02:22:03 -07001797 main.CLIs[ 0 ].setCfg( "org.onosproject.provider.host.impl.HostLocationProvider", "ipv6NeighborDiscovery", "true")
1798 main.CLIs[ 0 ].setCfg( "org.onosproject.proxyarp.ProxyArp", "ipv6NeighborDiscovery", "true")
sathishmad953462015-12-03 17:42:07 +05301799 main.CLIs[ 0 ].setCfg( "org.onosproject.fwd.ReactiveForwarding", "ipv6Forwarding", "true")
1800 main.CLIs[ 0 ].setCfg( "org.onosproject.fwd.ReactiveForwarding", "matchIpv6Address", "true")
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001801 time.sleep( main.fwdSleep )
1802
1803 for i in range( main.numCtrls ):
1804 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
1805 if appCheck != main.TRUE:
1806 main.log.warn( main.CLIs[ i ].apps() )
1807 main.log.warn( main.CLIs[ i ].appIDs() )
1808
sathishmad953462015-12-03 17:42:07 +05301809 pingResult = main.Mininet1.pingall( protocol="IPv6", timeout = 600 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001810 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
1811 hosts = main.Mininet1.getHosts().keys()
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001812 for host in hosts:
1813 main.hostsData[ host ] = {}
1814 main.hostsData[ host ][ 'mac' ] = \
1815 main.Mininet1.getMacAddress( host ).upper()
1816 for hostj in hostsJson:
1817 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
1818 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
1819 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
1820 main.hostsData[ host ][ 'location' ] = \
1821 hostj[ 'location' ][ 'elementId' ] + '/' + \
1822 hostj[ 'location' ][ 'port' ]
1823 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
1824
1825 main.log.info( "Deactivating reactive forwarding app " )
1826 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
1827 if activateResult and deactivateResult and main.hostsData:
1828 main.log.info( "Successfully used fwd app to discover hosts " )
1829 getDataResult = main.TRUE
1830 else:
1831 main.log.info( "Failed to use fwd app to discover hosts " )
1832 getDataResult = main.FALSE
1833
Jon Hall439c8912016-04-15 02:22:03 -07001834 main.log.info( "Removing the automatically configured ipv6 link-local addresses in hostsData to avoid unnecessary ping with these addresses during initial ping test - link-local starts with 'fe' " )
1835 for host in main.hostsData.keys():
1836 if main.hostsData[ host ].get( 'ipAddresses' ) != None:
1837 main.hostsData[ host ][ 'ipAddresses' ] = [ v for v in main.hostsData[ host ][ 'ipAddresses' ] if not v.startswith('fe') ]
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001838 print main.hostsData
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001839 return getDataResult
1840
1841def checkTopology( main, expectedLink ):
1842 statusResult = main.TRUE
1843 # Check onos topology
1844 main.log.info( itemName + ": Checking ONOS topology " )
1845
1846 for i in range( main.numCtrls ):
Flavio Castro82ee2f62016-06-07 15:04:12 -07001847 statusResult = main.CLIs[ i ].checkStatus( main.numSwitch,
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001848 expectedLink )\
1849 and statusResult
1850 if not statusResult:
1851 main.log.error( itemName + ": Topology mismatch" )
1852 else:
1853 main.log.info( itemName + ": Topology match" )
1854 return statusResult
1855
1856def checkIntentState( main, intentsId ):
1857 """
1858 This function will check intent state to make sure all the intents
1859 are in INSTALLED state
1860 """
1861
1862 intentResult = main.TRUE
1863 results = []
1864
1865 main.log.info( itemName + ": Checking intents state" )
1866 # First check of intents
1867 for i in range( main.numCtrls ):
1868 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
1869 results.append( tempResult )
1870
1871 expectedState = [ 'INSTALLED', 'INSTALLING' ]
1872
1873 if all( result == main.TRUE for result in results ):
1874 main.log.info( itemName + ": Intents are installed correctly" )
1875 else:
1876 # Wait for at least 5 second before checking the intents again
1877 main.log.error( "Intents are not installed correctly. Waiting 5 sec" )
1878 time.sleep( 5 )
1879 results = []
1880 # Second check of intents since some of the intents may be in
1881 # INSTALLING state, they should be in INSTALLED at this time
1882 for i in range( main.numCtrls ):
1883 tempResult = main.CLIs[ i ].checkIntentState(
1884 intentsId=intentsId )
1885 results.append( tempResult )
1886 if all( result == main.TRUE for result in results ):
1887 main.log.info( itemName + ": Intents are installed correctly" )
1888 intentResult = main.TRUE
1889 else:
1890 main.log.error( itemName + ": Intents are NOT installed correctly" )
1891 intentResult = main.FALSE
1892
1893 return intentResult
1894
1895def checkFlowsState( main ):
1896
1897 main.log.info( itemName + ": Check flows state" )
1898 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState()
1899 return checkFlowsResult
1900
1901def link( main, sw1, sw2, option):
1902
1903 # link down
1904 main.log.info( itemName + ": Bring link " + option + "between " +
1905 sw1 + " and " + sw2 )
1906 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
1907 return linkResult
1908
1909def removeAllIntents( main, intentsId ):
1910 """
1911 Remove all intents in the intentsId
1912 """
1913
1914 onosSummary = []
1915 removeIntentResult = main.TRUE
1916 # Remove intents
1917 for intent in intentsId:
1918 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
1919
1920 time.sleep( main.removeIntentSleep )
1921
1922 # If there is remianing intents then remove intents should fail
1923 for i in range( main.numCtrls ):
1924 onosSummary.append( json.loads( main.CLIs[ i ].summary() ) )
1925
1926 for summary in onosSummary:
1927 if summary.get( 'intents' ) != 0:
1928 main.log.warn( itemName + ": There are " +
1929 str( summary.get( 'intents' ) ) +
1930 " intents remaining in node " +
1931 str( summary.get( 'node' ) ) +
1932 ", failed to remove all the intents " )
1933 removeIntentResult = main.FALSE
1934
1935 if removeIntentResult:
1936 main.log.info( itemName + ": There are no more intents remaining, " +
1937 "successfully removed all the intents." )
1938
1939 return removeIntentResult
1940
1941def checkFlowsCount( main ):
1942 """
1943 Check flows count in each node
1944 """
1945
1946 flowsCount = []
1947 main.log.info( itemName + ": Checking flows count in each ONOS node" )
1948 for i in range( main.numCtrls ):
1949 summaryResult = main.CLIs[ i ].summary()
1950 if not summaryResult:
1951 main.log.error( itemName + ": There is something wrong with " +
1952 "summary command" )
1953 return main.FALSE
1954 else:
1955 summaryJson = json.loads( summaryResult )
1956 flowsCount.append( summaryJson.get( 'flows' ) )
1957
1958 if flowsCount:
1959 if all( flows==flowsCount[ 0 ] for flows in flowsCount ):
1960 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
1961 " flows in all ONOS node" )
1962 else:
1963 for i in range( main.numCtrls ):
1964 main.log.debug( itemName + ": ONOS node " + str( i ) + " has " +
1965 str( flowsCount[ i ] ) + " flows" )
1966 else:
1967 main.log.error( "Checking flows count failed, check summary command" )
1968 return main.FALSE
1969
1970 return main.TRUE
1971
1972def checkLeaderChange( leaders1, leaders2 ):
1973 """
1974 Checks for a change in intent partition leadership.
1975
1976 Takes the output of leaders -c in json string format before and after
1977 a potential change as input
1978
1979 Returns main.TRUE if no mismatches are detected
1980 Returns main.FALSE if there is a mismatch or on error loading the input
1981 """
1982 try:
1983 leaders1 = json.loads( leaders1 )
1984 leaders2 = json.loads( leaders2 )
1985 except ( AttributeError, TypeError):
1986 main.log.exception( self.name + ": Object not as expected" )
1987 return main.FALSE
1988 except Exception:
1989 main.log.exception( self.name + ": Uncaught exception!" )
1990 main.cleanup()
1991 main.exit()
1992 main.log.info( "Checking Intent Paritions for Change in Leadership" )
1993 mismatch = False
1994 for dict1 in leaders1:
1995 if "intent" in dict1.get( "topic", [] ):
1996 for dict2 in leaders2:
1997 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \
1998 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
1999 mismatch = True
2000 main.log.error( "{0} changed leader from {1} to {2}".\
2001 format( dict1.get( "topic", "no-topic" ),\
2002 dict1.get( "leader", "no-leader" ),\
2003 dict2.get( "leader", "no-leader" ) ) )
2004 if mismatch:
2005 return main.FALSE
2006 else:
2007 return main.TRUE
2008
2009def report( main ):
2010 """
2011 Report errors/warnings/exceptions
2012 """
2013
2014 main.ONOSbench.logReport( main.ONOSip[ 0 ],
2015 [ "INFO",
2016 "FOLLOWER",
2017 "WARN",
2018 "flow",
2019 "ERROR",
2020 "Except" ],
2021 "s" )
2022
2023 main.log.info( "ERROR report: \n" )
2024 for i in range( main.numCtrls ):
2025 main.ONOSbench.logReport( main.ONOSip[ i ],
2026 [ "ERROR" ],
2027 "d" )
2028
2029 main.log.info( "EXCEPTIONS report: \n" )
2030 for i in range( main.numCtrls ):
2031 main.ONOSbench.logReport( main.ONOSip[ i ],
2032 [ "Except" ],
2033 "d" )
2034
2035 main.log.info( "WARNING report: \n" )
2036 for i in range( main.numCtrls ):
2037 main.ONOSbench.logReport( main.ONOSip[ i ],
2038 [ "WARN" ],
2039 "d" )