blob: 2a2330dc5c610c52a5317f8bb10e30ec8cbd3a39 [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
Jon Hall314b74a2017-05-24 16:25:52 -070010
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080011def __init__( self ):
12 self.default = ''
13
Jon Hall314b74a2017-05-24 16:25:52 -070014
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080015def hostIntent( main,
16 name,
17 host1,
18 host2,
19 onosNode=0,
20 host1Id="",
21 host2Id="",
22 mac1="",
23 mac2="",
24 vlan1="-1",
25 vlan2="-1",
26 sw1="",
27 sw2="",
28 expectedLink=0 ):
29 """
30 Description:
31 Verify add-host-intent
32 Steps:
33 - Discover hosts
34 - Add host intents
35 - Check intents
36 - Verify flows
37 - Ping hosts
38 - Reroute
39 - Link down
40 - Verify flows
41 - Check topology
42 - Ping hosts
43 - Link up
44 - Verify flows
45 - Check topology
46 - Ping hosts
47 - Remove intents
48 Required:
49 name - Type of host intent to add eg. IPV4 | VLAN | Dualstack
50 host1 - Name of first host
51 host2 - Name of second host
52 Optional:
53 onosNode - ONOS node to install the intents in main.CLIs[ ]
54 0 by default so that it will always use the first
55 ONOS node
56 host1Id - ONOS id of the first host eg. 00:00:00:00:00:01/-1
57 host2Id - ONOS id of the second host
58 mac1 - Mac address of first host
59 mac2 - Mac address of the second host
60 vlan1 - Vlan tag of first host, defaults to -1
61 vlan2 - Vlan tag of second host, defaults to -1
62 sw1 - First switch to bring down & up for rerouting purpose
63 sw2 - Second switch to bring down & up for rerouting purpose
64 expectedLink - Expected link when the switches are down, it should
65 be two links lower than the links before the two
66 switches are down
67 Return:
68 Returns main.TRUE if all verification passed, otherwise return
69 main.FALSE; returns main.FALSE if there is a key error
70 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080071 # Assert variables
72 assert main, "There is no main variable"
73 assert name, "variable name is empty"
74 assert host1 and host2, "You must specify hosts"
75
76 global itemName
77 itemName = name
78 h1Id = host1Id
79 h2Id = host2Id
80 h1Mac = mac1
81 h2Mac = mac2
82 vlan1 = vlan1
83 vlan2 = vlan2
Jon Hall314b74a2017-05-24 16:25:52 -070084 hostNames = [ host1, host2 ]
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080085 intentsId = []
86 stepResult = main.TRUE
87 pingResult = main.TRUE
88 intentResult = main.TRUE
89 removeIntentResult = main.TRUE
90 flowResult = main.TRUE
91 topoResult = main.TRUE
92 linkDownResult = main.TRUE
93 linkUpResult = main.TRUE
94 onosNode = int( onosNode )
95
96 try:
97 if main.hostsData:
98 if not h1Mac:
99 h1Mac = main.hostsData[ host1 ][ 'mac' ]
100 if not h2Mac:
101 h2Mac = main.hostsData[ host2 ][ 'mac' ]
102 if main.hostsData[ host1 ].get( 'vlan' ):
103 vlan1 = main.hostsData[ host1 ][ 'vlan' ]
104 if main.hostsData[ host1 ].get( 'vlan' ):
105 vlan2 = main.hostsData[ host2 ][ 'vlan' ]
106 if not h1Id:
107 h1Id = main.hostsData[ host1 ][ 'id' ]
108 if not h2Id:
109 h2Id = main.hostsData[ host2 ][ 'id' ]
110
111 assert h1Id and h2Id, "You must specify host IDs"
112 if not ( h1Id and h2Id ):
113 main.log.info( "There are no host IDs" )
114 return main.FALSE
115
116 except KeyError:
117 main.log.error( itemName + ": Key error Exception" )
118 return main.FALSE
119
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800120 # Check flows count in each node
121 checkFlowsCount( main )
122
123 # Adding host intents
124 main.log.info( itemName + ": Adding host intents" )
125 intent1 = main.CLIs[ onosNode ].addHostIntent( hostIdOne=h1Id,
126 hostIdTwo=h2Id )
127 intentsId.append( intent1 )
128
129 # Check intents state
130 time.sleep( main.checkIntentSleep )
131 intentResult = checkIntentState( main, intentsId )
132 checkFlowsCount( main )
133
134 # Check intents state again if first check fails...
135 if not intentResult:
136 intentResult = checkIntentState( main, intentsId )
sathishmc4362252016-04-20 18:29:48 +0530137 if intentResult:
138 main.assertReturnString += 'Initial Intent State Passed\n'
139 else:
140 main.assertReturnString += 'Initial Intent State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800141
142 # Check flows count in each node
sathishmc4362252016-04-20 18:29:48 +0530143 FlowResult = checkFlowsCount( main )
144 if FlowResult:
145 main.assertReturnString += 'Initial Flow Count Passed\n'
146 else:
147 main.assertReturnString += 'Initial Flow Count Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800148 # Verify flows
sathishmc4362252016-04-20 18:29:48 +0530149 StateResult = checkFlowsState( main )
150 if StateResult:
151 main.assertReturnString += 'Initial Flow State Passed\n'
152 else:
153 main.assertReturnString += 'Initial Flow State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800154
155 # Ping hosts
Jon Hall314b74a2017-05-24 16:25:52 -0700156 firstPingResult = main.Mininet1.ping6pair( SRC=hostNames[ 0 ], TARGET=main.hostsData[ host2 ][ 'ipAddresses' ][ 0 ] )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800157 if not firstPingResult:
158 main.log.debug( "First ping failed, there must be" +
Jon Hall314b74a2017-05-24 16:25:52 -0700159 " something wrong with ONOS performance" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800160
161 # Ping hosts again...
Jon Hall439c8912016-04-15 02:22:03 -0700162 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800163 pingResult = pingResult and pingTemp
164 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700165 main.assertReturnString += 'Initial Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800166 else:
Jon Hall439c8912016-04-15 02:22:03 -0700167 main.assertReturnString += 'Initial Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800168
169 # Test rerouting if these variables exist
170 if sw1 and sw2 and expectedLink:
171 # Link down
172 linkDownResult = link( main, sw1, sw2, "down" )
173
174 if linkDownResult:
175 main.assertReturnString += 'Link Down Passed\n'
176 else:
177 main.assertReturnString += 'Link Down Failed\n'
178
179 # Check flows count in each node
180 checkFlowsCount( main )
181 # Verify flows
182 checkFlowsState( main )
183
184 # Check OnosTopology
185 topoResult = checkTopology( main, expectedLink )
186 if topoResult:
187 main.assertReturnString += 'Link Down Topology State Passed\n'
188 else:
189 main.assertReturnString += 'Link Down Topology State Failed\n'
190
191 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -0700192 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800193 pingResult = pingResult and pingTemp
194
195 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700196 main.assertReturnString += 'Link Down Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800197 else:
Jon Hall439c8912016-04-15 02:22:03 -0700198 main.assertReturnString += 'Link Down Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800199
200 # Check intent states
201 intentTemp = checkIntentState( main, intentsId )
202 intentResult = intentResult and intentTemp
203 if intentTemp:
204 main.assertReturnString += 'Link Down Intent State Passed\n'
205 else:
206 main.assertReturnString += 'Link Down Intent State Failed\n'
207
208 # Checks ONOS state in link down
209 if linkDownResult and topoResult and pingResult and intentResult:
210 main.log.info( itemName + ": Successfully brought link down" )
211 else:
212 main.log.error( itemName + ": Failed to bring link down" )
213
214 # Link up
215 linkUpResult = link( main, sw1, sw2, "up" )
216 time.sleep( main.rerouteSleep )
217
218 if linkUpResult:
219 main.assertReturnString += 'Link Up Passed\n'
220 else:
221 main.assertReturnString += 'Link Up Failed\n'
222
223 # Check flows count in each node
224 checkFlowsCount( main )
225 # Verify flows
226 checkFlowsState( main )
227
228 # Check OnosTopology
229 topoResult = checkTopology( main, main.numLinks )
230
231 if topoResult:
232 main.assertReturnString += 'Link Up Topology State Passed\n'
233 else:
234 main.assertReturnString += 'Link Up Topology State Failed\n'
235
236 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -0700237 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800238 pingResult = pingResult and pingTemp
239
240 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700241 main.assertReturnString += 'Link Up Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800242 else:
Jon Hall439c8912016-04-15 02:22:03 -0700243 main.assertReturnString += 'Link Up Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800244
245 intentTemp = checkIntentState( main, intentsId )
246 intentResult = intentResult and intentTemp
247 if intentTemp:
248 main.assertReturnString += 'Link Up Intent State Passed\n'
249 else:
250 main.assertReturnString += 'Link Up Intent State Failed\n'
251
252 # Checks ONOS state in link up
253 if linkUpResult and topoResult and pingResult and intentResult:
254 main.log.info( itemName + ": Successfully brought link back up" )
255 else:
256 main.log.error( itemName + ": Failed to bring link back up" )
257
258 # Remove all intents
259 removeIntentResult = removeAllIntents( main, intentsId )
260
261 if removeIntentResult:
262 main.assertReturnString += 'Remove Intents Passed'
263 else:
264 main.assertReturnString += 'Remove Intents Failed'
265
266 stepResult = pingResult and linkDownResult and linkUpResult \
267 and intentResult and removeIntentResult
268
269 return stepResult
270
Jon Hall314b74a2017-05-24 16:25:52 -0700271
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800272def pointIntent( main,
273 name,
274 host1,
275 host2,
276 onosNode=0,
277 deviceId1="",
278 deviceId2="",
279 port1="",
280 port2="",
281 ethType="",
282 mac1="",
283 mac2="",
284 bandwidth="",
285 lambdaAlloc=False,
286 ipProto="",
287 ip1="",
288 ip2="",
289 tcp1="",
290 tcp2="",
291 sw1="",
292 sw2="",
293 expectedLink=0 ):
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800294 """
295 Description:
296 Verify add-point-intent
297 Steps:
298 - Get device ids | ports
299 - Add point intents
300 - Check intents
301 - Verify flows
302 - Ping hosts
303 - Reroute
304 - Link down
305 - Verify flows
306 - Check topology
307 - Ping hosts
308 - Link up
309 - Verify flows
310 - Check topology
311 - Ping hosts
312 - Remove intents
313 Required:
314 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
315 host1 - Name of first host
316 host2 - Name of second host
317 Optional:
318 onosNode - ONOS node to install the intents in main.CLIs[ ]
319 0 by default so that it will always use the first
320 ONOS node
321 deviceId1 - ONOS device id of the first switch, the same as the
322 location of the first host eg. of:0000000000000001/1,
323 located at device 1 port 1
324 deviceId2 - ONOS device id of the second switch
325 port1 - The port number where the first host is attached
326 port2 - The port number where the second host is attached
327 ethType - Ethernet type eg. IPV4, IPV6
328 mac1 - Mac address of first host
329 mac2 - Mac address of the second host
330 bandwidth - Bandwidth capacity
331 lambdaAlloc - Allocate lambda, defaults to False
332 ipProto - IP protocol
333 ip1 - IP address of first host
334 ip2 - IP address of second host
335 tcp1 - TCP port of first host
336 tcp2 - TCP port of second host
337 sw1 - First switch to bring down & up for rerouting purpose
338 sw2 - Second switch to bring down & up for rerouting purpose
339 expectedLink - Expected link when the switches are down, it should
340 be two links lower than the links before the two
341 switches are down
342 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800343 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,
Jon Hall314b74a2017-05-24 16:25:52 -0700366 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 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800379
380 intentsId.append( intent1 )
381 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
Jon Hall314b74a2017-05-24 16:25:52 -0700382 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 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800395 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
Jon Hall314b74a2017-05-24 16:25:52 -0700530
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800531def pointIntentTcp( main,
532 name,
533 host1,
534 host2,
535 onosNode=0,
536 deviceId1="",
537 deviceId2="",
538 port1="",
539 port2="",
540 ethType="",
541 mac1="",
542 mac2="",
543 bandwidth="",
544 lambdaAlloc=False,
545 ipProto="",
546 ip1="",
547 ip2="",
548 tcp1="",
549 tcp2="",
550 sw1="",
551 sw2="",
552 expectedLink=0 ):
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800553 """
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 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800602 assert main, "There is no main variable"
603 assert name, "variable name is empty"
604 assert host1 and host2, "You must specify hosts"
605
606 global itemName
607 itemName = name
608 host1 = host1
609 host2 = host2
610 hostNames = [ host1, host2 ]
611 intentsId = []
612
613 iperfResult = main.TRUE
614 intentResult = main.TRUE
615 removeIntentResult = main.TRUE
616 flowResult = main.TRUE
617 topoResult = main.TRUE
618 linkDownResult = main.TRUE
619 linkUpResult = main.TRUE
620 onosNode = int( onosNode )
621
622 # Adding bidirectional point intents
623 main.log.info( itemName + ": Adding point intents" )
624 intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
625 egressDevice=deviceId2,
626 portIngress=port1,
627 portEgress=port2,
628 ethType=ethType,
629 ethSrc=mac1,
630 ethDst=mac2,
631 bandwidth=bandwidth,
632 lambdaAlloc=lambdaAlloc,
633 ipProto=ipProto,
634 ipSrc=ip1,
635 ipDst=ip2,
636 tcpSrc=tcp1,
637 tcpDst="" )
638
639 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
640 egressDevice=deviceId1,
641 portIngress=port2,
642 portEgress=port1,
643 ethType=ethType,
644 ethSrc=mac2,
645 ethDst=mac1,
646 bandwidth=bandwidth,
647 lambdaAlloc=lambdaAlloc,
648 ipProto=ipProto,
649 ipSrc=ip2,
650 ipDst=ip1,
651 tcpSrc=tcp2,
652 tcpDst="" )
653
654 intent3 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
655 egressDevice=deviceId2,
656 portIngress=port1,
657 portEgress=port2,
658 ethType=ethType,
659 ethSrc=mac1,
660 ethDst=mac2,
661 bandwidth=bandwidth,
662 lambdaAlloc=lambdaAlloc,
663 ipProto=ipProto,
664 ipSrc=ip1,
665 ipDst=ip2,
666 tcpSrc="",
667 tcpDst=tcp2 )
668
669 intent4 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
670 egressDevice=deviceId1,
671 portIngress=port2,
672 portEgress=port1,
673 ethType=ethType,
674 ethSrc=mac2,
675 ethDst=mac1,
676 bandwidth=bandwidth,
677 lambdaAlloc=lambdaAlloc,
678 ipProto=ipProto,
679 ipSrc=ip2,
680 ipDst=ip1,
681 tcpSrc="",
682 tcpDst=tcp1 )
683 intentsId.append( intent1 )
684 intentsId.append( intent2 )
685 intentsId.append( intent3 )
686 intentsId.append( intent4 )
687
688 # Check intents state
689 time.sleep( main.checkIntentSleep )
690 intentResult = checkIntentState( main, intentsId )
691 # Check flows count in each node
692 checkFlowsCount( main )
693
694 # Check intents state again if first check fails...
695 if not intentResult:
696 intentResult = checkIntentState( main, intentsId )
sathishmc4362252016-04-20 18:29:48 +0530697 if intentResult:
698 main.assertReturnString += 'Initial Intent State Passed\n'
699 else:
700 main.assertReturnString += 'Initial Intent State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800701
702 # Check flows count in each node
sathishmc4362252016-04-20 18:29:48 +0530703 FlowResult = checkFlowsCount( main )
704 if FlowResult:
705 main.assertReturnString += 'Initial Flow Count Passed\n'
706 else:
707 main.assertReturnString += 'Initial Flow Count Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800708 # Verify flows
sathishmc4362252016-04-20 18:29:48 +0530709 StateResult = checkFlowsState( main )
710 if StateResult:
711 main.assertReturnString += 'Initial Flow State Passed\n'
712 else:
713 main.assertReturnString += 'Initial Flow State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800714
sathishmc4362252016-04-20 18:29:48 +0530715 # Run iperf to both host
Jon Hall314b74a2017-05-24 16:25:52 -0700716 iperfTemp = main.Mininet1.iperftcpipv6( host1, host2 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800717 iperfResult = iperfResult and iperfTemp
718 if iperfTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700719 main.assertReturnString += 'Initial Iperf6 Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800720 else:
Jon Hall439c8912016-04-15 02:22:03 -0700721 main.assertReturnString += 'Initial Iperf6 Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800722
723 # Test rerouting if these variables exist
724 if sw1 and sw2 and expectedLink:
725 # link down
726 linkDownResult = link( main, sw1, sw2, "down" )
727
728 if linkDownResult:
729 main.assertReturnString += 'Link Down Passed\n'
730 else:
731 main.assertReturnString += 'Link Down Failed\n'
732
733 # Check flows count in each node
734 checkFlowsCount( main )
735 # Verify flows
736 checkFlowsState( main )
737
738 # Check OnosTopology
739 topoResult = checkTopology( main, expectedLink )
740 if topoResult:
741 main.assertReturnString += 'Link Down Topology State Passed\n'
742 else:
743 main.assertReturnString += 'Link Down Topology State Failed\n'
744
745 # Run iperf to both host
Jon Hall314b74a2017-05-24 16:25:52 -0700746 iperfTemp = main.Mininet1.iperftcpipv6( host1, host2 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800747 iperfResult = iperfResult and iperfTemp
748 if iperfTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700749 main.assertReturnString += 'Link Down Iperf6 Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800750 else:
Jon Hall439c8912016-04-15 02:22:03 -0700751 main.assertReturnString += 'Link Down Iperf6 Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800752
753 # Check intent state
754 intentTemp = checkIntentState( main, intentsId )
755 intentResult = intentResult and intentTemp
756 if intentTemp:
757 main.assertReturnString += 'Link Down Intent State Passed\n'
758 else:
759 main.assertReturnString += 'Link Down Intent State Failed\n'
760
761 # Checks ONOS state in link down
762 if linkDownResult and topoResult and iperfResult and intentResult:
763 main.log.info( itemName + ": Successfully brought link down" )
764 else:
765 main.log.error( itemName + ": Failed to bring link down" )
766
767 # link up
768 linkUpResult = link( main, sw1, sw2, "up" )
Jon Hall439c8912016-04-15 02:22:03 -0700769 if linkUpResult:
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800770 main.assertReturnString += 'Link Up Passed\n'
771 else:
772 main.assertReturnString += 'Link Up Failed\n'
773
774 time.sleep( main.rerouteSleep )
775
776 # Check flows count in each node
777 checkFlowsCount( main )
778 # Verify flows
779 checkFlowsState( main )
780
781 # Check OnosTopology
782 topoResult = checkTopology( main, main.numLinks )
783
784 if topoResult:
785 main.assertReturnString += 'Link Up Topology State Passed\n'
786 else:
787 main.assertReturnString += 'Link Up Topology State Failed\n'
788
789 # Run iperf to both host
Jon Hall314b74a2017-05-24 16:25:52 -0700790 iperfTemp = main.Mininet1.iperftcpipv6( host1, host2, timeout=10 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800791 iperfResult = iperfResult and iperfTemp
792 if iperfTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700793 main.assertReturnString += 'Link Up Iperf6 Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800794 else:
Jon Hall439c8912016-04-15 02:22:03 -0700795 main.assertReturnString += 'Link Up Iperf6 Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800796
797 # Check intent state
798 intentTemp = checkIntentState( main, intentsId )
799 intentResult = intentResult and intentTemp
800 if intentTemp:
801 main.assertReturnString += 'Link Down Intent State Passed\n'
802 else:
803 main.assertReturnString += 'Link Down Intent State Failed\n'
804
805 # Checks ONOS state in link up
806 if linkUpResult and topoResult and iperfResult and intentResult:
807 main.log.info( itemName + ": Successfully brought link back up" )
808 else:
809 main.log.error( itemName + ": Failed to bring link back up" )
810
811 # Remove all intents
812 removeIntentResult = removeAllIntents( main, intentsId )
813 if removeIntentResult:
814 main.assertReturnString += 'Remove Intents Passed'
815 else:
816 main.assertReturnString += 'Remove Intents Failed'
817
818 stepResult = iperfResult and linkDownResult and linkUpResult \
819 and intentResult and removeIntentResult
820
821 return stepResult
822
Jon Hall314b74a2017-05-24 16:25:52 -0700823
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800824def 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' ,.. ]
Jon Hall314b74a2017-05-24 16:25:52 -0700846 devices = [ 'of:0000000000000001', 'of:0000000000000002', ... ]
847 ports = [ '1', '1', .. ]
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800848 ...
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 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800894 assert main, "There is no main variable"
895 assert hostNames, "You must specify hosts"
896 assert devices or main.hostsData, "You must specify devices"
897
898 global itemName
899 itemName = name
900 tempHostsData = {}
901 intentsId = []
902 onosNode = int( onosNode )
903
904 macsDict = {}
905 ipDict = {}
906 if hostNames and devices:
907 if len( hostNames ) != len( devices ):
908 main.log.debug( "hosts and devices does not have the same length" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800909 return main.FALSE
910 if ports:
911 if len( ports ) != len( devices ):
912 main.log.error( "Ports and devices does " +
913 "not have the same length" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800914 return main.FALSE
915 else:
916 main.log.info( "Device Ports are not specified" )
917 if macs:
918 for i in range( len( devices ) ):
919 macsDict[ devices[ i ] ] = macs[ i ]
920
921 elif hostNames and not devices and main.hostsData:
922 devices = []
923 main.log.info( "singleToMultiIntent function is using main.hostsData" )
924 for host in hostNames:
Jon Hall314b74a2017-05-24 16:25:52 -0700925 devices.append( main.hostsData.get( host ).get( 'location' ) )
926 macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \
927 main.hostsData.get( host ).get( 'mac' )
928 ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \
929 main.hostsData.get( host ).get( 'ipAddresses' )
sathishmc4362252016-04-20 18:29:48 +0530930
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800931 pingResult = main.TRUE
932 intentResult = main.TRUE
933 removeIntentResult = main.TRUE
934 flowResult = main.TRUE
935 topoResult = main.TRUE
936 linkDownResult = main.TRUE
937 linkUpResult = main.TRUE
938
939 devicesCopy = copy.copy( devices )
940 if ports:
941 portsCopy = copy.copy( ports )
942 main.log.info( itemName + ": Adding single point to multi point intents" )
943
944 # Check flows count in each node
945 checkFlowsCount( main )
946
947 # Adding bidirectional point intents
948 for i in range( len( devices ) ):
949 ingressDevice = devicesCopy[ i ]
950 egressDeviceList = copy.copy( devicesCopy )
951 egressDeviceList.remove( ingressDevice )
952 if ports:
953 portIngress = portsCopy[ i ]
954 portEgressList = copy.copy( portsCopy )
955 del portEgressList[ i ]
956 else:
957 portIngress = ""
958 portEgressList = None
959 if not macsDict:
960 srcMac = ""
961 else:
962 srcMac = macsDict[ ingressDevice ]
Jon Hall314b74a2017-05-24 16:25:52 -0700963 if srcMac is None:
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800964 main.log.debug( "There is no MAC in device - " + ingressDevice )
965 srcMac = ""
966
967 intentsId.append(
968 main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
969 ingressDevice=ingressDevice,
970 egressDeviceList=egressDeviceList,
971 portIngress=portIngress,
972 portEgressList=portEgressList,
973 ethType=ethType,
974 ethSrc=srcMac,
975 bandwidth=bandwidth,
976 lambdaAlloc=lambdaAlloc,
977 ipProto=ipProto,
978 ipSrc="",
979 ipDst="",
980 tcpSrc="",
981 tcpDst="" ) )
982
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800983 # Check intents state
984 time.sleep( main.checkIntentSleep )
985 intentResult = checkIntentState( main, intentsId )
986
987 # Check intents state again if first check fails...
988 if not intentResult:
989 intentResult = checkIntentState( main, intentsId )
sathishmc4362252016-04-20 18:29:48 +0530990 if intentResult:
991 main.assertReturnString += 'Initial Intent State Passed\n'
992 else:
993 main.assertReturnString += 'Initial Intent State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800994
995 # Check flows count in each node
sathishmc4362252016-04-20 18:29:48 +0530996 FlowResult = checkFlowsCount( main )
997 if FlowResult:
998 main.assertReturnString += 'Initial Flow Count Passed\n'
999 else:
1000 main.assertReturnString += 'Initial Flow Count Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001001 # Verify flows
sathishmc4362252016-04-20 18:29:48 +05301002 StateResult = checkFlowsState( main )
1003 if StateResult:
1004 main.assertReturnString += 'Initial Flow State Passed\n'
1005 else:
1006 main.assertReturnString += 'Initial Flow State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001007
Jon Hall314b74a2017-05-24 16:25:52 -07001008 firstPingResult = main.Mininet1.ping6pair( SRC=hostNames[ 0 ], TARGET=main.hostsData[ hostNames[ 1 ] ][ 'ipAddresses' ][ 0 ] )
Jon Hall439c8912016-04-15 02:22:03 -07001009 if not firstPingResult:
1010 main.log.debug( "First ping failed, there must be" +
Jon Hall314b74a2017-05-24 16:25:52 -07001011 " something wrong with ONOS performance" )
Jon Hall439c8912016-04-15 02:22:03 -07001012
1013 # Ping hosts again...
1014 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001015 pingResult = pingResult and pingTemp
1016 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001017 main.assertReturnString += 'Initial Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001018 else:
Jon Hall439c8912016-04-15 02:22:03 -07001019 main.assertReturnString += 'Initial Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001020
1021 # Test rerouting if these variables exist
1022 if sw1 and sw2 and expectedLink:
1023 # link down
1024 linkDownResult = link( main, sw1, sw2, "down" )
1025
1026 if linkDownResult:
1027 main.assertReturnString += 'Link Down Passed\n'
1028 else:
1029 main.assertReturnString += 'Link Down Failed\n'
1030
1031 # Check flows count in each node
1032 checkFlowsCount( main )
1033 # Verify flows
1034 checkFlowsState( main )
1035
1036 # Check OnosTopology
1037 topoResult = checkTopology( main, expectedLink )
1038 if topoResult:
1039 main.assertReturnString += 'Link Down Topology State Passed\n'
1040 else:
1041 main.assertReturnString += 'Link Down Topology State Failed\n'
1042
1043 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -07001044 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001045 pingResult = pingResult and pingTemp
1046 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001047 main.assertReturnString += 'Link Down Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001048 else:
Jon Hall439c8912016-04-15 02:22:03 -07001049 main.assertReturnString += 'Link Down Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001050
1051 # Check intent state
1052 intentTemp = checkIntentState( main, intentsId )
1053 intentResult = intentResult and intentTemp
1054 if intentTemp:
1055 main.assertReturnString += 'Link Down Intent State Passed\n'
1056 else:
1057 main.assertReturnString += 'Link Down Intent State Failed\n'
1058
1059 # Checks ONOS state in link down
1060 if linkDownResult and topoResult and pingResult and intentResult:
1061 main.log.info( itemName + ": Successfully brought link down" )
1062 else:
1063 main.log.error( itemName + ": Failed to bring link down" )
1064
1065 # link up
1066 linkUpResult = link( main, sw1, sw2, "up" )
1067 if linkUpResult:
1068 main.assertReturnString += 'Link Up Passed\n'
1069 else:
1070 main.assertReturnString += 'Link Up Failed\n'
1071
1072 time.sleep( main.rerouteSleep )
1073
1074 # Check flows count in each node
1075 checkFlowsCount( main )
1076 # Verify flows
1077 checkFlowsState( main )
1078
1079 # Check OnosTopology
1080 topoResult = checkTopology( main, main.numLinks )
1081 if topoResult:
1082 main.assertReturnString += 'Link Up Topology State Passed\n'
1083 else:
1084 main.assertReturnString += 'Link Up Topology State Failed\n'
1085
1086 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -07001087 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001088 pingResult = pingResult and pingTemp
1089 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001090 main.assertReturnString += 'Link Up Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001091 else:
Jon Hall439c8912016-04-15 02:22:03 -07001092 main.assertReturnString += 'Link Up Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001093
1094 # Check Intents
1095 intentTemp = checkIntentState( main, intentsId )
1096 intentResult = intentResult and intentTemp
1097 if intentTemp:
1098 main.assertReturnString += 'Link Up Intent State Passed\n'
1099 else:
1100 main.assertReturnString += 'Link Up Intent State Failed\n'
1101
1102 # Checks ONOS state in link up
1103 if linkUpResult and topoResult and pingResult and intentResult:
1104 main.log.info( itemName + ": Successfully brought link back up" )
1105 else:
1106 main.log.error( itemName + ": Failed to bring link back up" )
1107
1108 # Remove all intents
1109 removeIntentResult = removeAllIntents( main, intentsId )
1110 if removeIntentResult:
1111 main.assertReturnString += 'Remove Intents Passed'
1112 else:
1113 main.assertReturnString += 'Remove Intents Failed'
1114
1115 stepResult = pingResult and linkDownResult and linkUpResult \
1116 and intentResult and removeIntentResult
1117
1118 return stepResult
1119
Jon Hall314b74a2017-05-24 16:25:52 -07001120
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001121def multiToSingleIntent( main,
1122 name,
Jon Hall439c8912016-04-15 02:22:03 -07001123 hostNames="",
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001124 onosNode=0,
1125 devices="",
Jon Hall439c8912016-04-15 02:22:03 -07001126 ports="",
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001127 ethType="",
Jon Hall439c8912016-04-15 02:22:03 -07001128 macs="",
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001129 bandwidth="",
1130 lambdaAlloc=False,
1131 ipProto="",
1132 ipAddresses="",
1133 tcp="",
1134 sw1="",
1135 sw2="",
1136 expectedLink=0 ):
1137 """
1138 Verify Single to Multi Point intents
1139 NOTE:If main.hostsData is not defined, variables data should be passed in the
1140 same order index wise. All devices in the list should have the same
1141 format, either all the devices have its port or it doesn't.
1142 eg. hostName = [ 'h1', 'h2' ,.. ]
Jon Hall314b74a2017-05-24 16:25:52 -07001143 devices = [ 'of:0000000000000001', 'of:0000000000000002', ... ]
1144 ports = [ '1', '1', .. ]
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001145 ...
1146 Description:
1147 Verify add-multi-to-single-intent
1148 Steps:
1149 - Get device ids | ports
1150 - Add multi to single point intents
1151 - Check intents
1152 - Verify flows
1153 - Ping hosts
1154 - Reroute
1155 - Link down
1156 - Verify flows
1157 - Check topology
1158 - Ping hosts
1159 - Link up
1160 - Verify flows
1161 - Check topology
1162 - Ping hosts
1163 - Remove intents
1164 Required:
1165 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
1166 hostNames - List of host names
1167 Optional:
1168 onosNode - ONOS node to install the intents in main.CLIs[ ]
1169 0 by default so that it will always use the first
1170 ONOS node
1171 devices - List of device ids in the same order as the hosts
1172 in hostNames
1173 ports - List of port numbers in the same order as the device in
1174 devices
1175 ethType - Ethernet type eg. IPV4, IPV6
1176 macs - List of hosts mac address in the same order as the hosts in
1177 hostNames
1178 bandwidth - Bandwidth capacity
1179 lambdaAlloc - Allocate lambda, defaults to False
1180 ipProto - IP protocol
1181 ipAddresses - IP addresses of host in the same order as the hosts in
1182 hostNames
1183 tcp - TCP ports in the same order as the hosts in hostNames
1184 sw1 - First switch to bring down & up for rerouting purpose
1185 sw2 - Second switch to bring down & up for rerouting purpose
1186 expectedLink - Expected link when the switches are down, it should
1187 be two links lower than the links before the two
1188 switches are down
sathishmc4362252016-04-20 18:29:48 +05301189 Note - Don't use more than 2 hosts for MultiToSingle Intent with no mac address option.
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001190 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001191 assert main, "There is no main variable"
1192 assert hostNames, "You must specify hosts"
1193 assert devices or main.hostsData, "You must specify devices"
1194
1195 global itemName
1196 itemName = name
1197 tempHostsData = {}
1198 intentsId = []
1199 onosNode = int( onosNode )
1200
1201 macsDict = {}
1202 ipDict = {}
1203 if hostNames and devices:
1204 if len( hostNames ) != len( devices ):
1205 main.log.debug( "hosts and devices does not have the same length" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001206 return main.FALSE
1207 if ports:
1208 if len( ports ) != len( devices ):
1209 main.log.error( "Ports and devices does " +
1210 "not have the same length" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001211 return main.FALSE
1212 else:
1213 main.log.info( "Device Ports are not specified" )
1214 if macs:
1215 for i in range( len( devices ) ):
1216 macsDict[ devices[ i ] ] = macs[ i ]
1217 elif hostNames and not devices and main.hostsData:
1218 devices = []
1219 main.log.info( "multiToSingleIntent function is using main.hostsData" )
1220 for host in hostNames:
Jon Hall314b74a2017-05-24 16:25:52 -07001221 devices.append( main.hostsData.get( host ).get( 'location' ) )
1222 macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \
1223 main.hostsData.get( host ).get( 'mac' )
1224 ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \
1225 main.hostsData.get( host ).get( 'ipAddresses' )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001226
1227 pingResult = main.TRUE
1228 intentResult = main.TRUE
1229 removeIntentResult = main.TRUE
1230 flowResult = main.TRUE
1231 topoResult = main.TRUE
1232 linkDownResult = main.TRUE
1233 linkUpResult = main.TRUE
1234
1235 devicesCopy = copy.copy( devices )
1236 if ports:
1237 portsCopy = copy.copy( ports )
1238 main.log.info( itemName + ": Adding multi point to single point intents" )
1239
1240 # Check flows count in each node
1241 checkFlowsCount( main )
1242
1243 # Adding bidirectional point intents
1244 for i in range( len( devices ) ):
1245 egressDevice = devicesCopy[ i ]
1246 ingressDeviceList = copy.copy( devicesCopy )
1247 ingressDeviceList.remove( egressDevice )
1248 if ports:
1249 portEgress = portsCopy[ i ]
1250 portIngressList = copy.copy( portsCopy )
1251 del portIngressList[ i ]
1252 else:
1253 portEgress = ""
1254 portIngressList = None
1255 if not macsDict:
1256 dstMac = ""
1257 else:
1258 dstMac = macsDict[ egressDevice ]
Jon Hall314b74a2017-05-24 16:25:52 -07001259 if dstMac is None:
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001260 main.log.debug( "There is no MAC in device - " + egressDevice )
1261 dstMac = ""
1262
1263 intentsId.append(
1264 main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
1265 ingressDeviceList=ingressDeviceList,
1266 egressDevice=egressDevice,
1267 portIngressList=portIngressList,
1268 portEgress=portEgress,
1269 ethType=ethType,
1270 ethDst=dstMac,
1271 bandwidth=bandwidth,
1272 lambdaAlloc=lambdaAlloc,
1273 ipProto=ipProto,
1274 ipSrc="",
1275 ipDst="",
1276 tcpSrc="",
1277 tcpDst="" ) )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001278 # Check intents state
1279 time.sleep( main.checkIntentSleep )
1280 intentResult = checkIntentState( main, intentsId )
1281
1282 # Check intents state again if first check fails...
1283 if not intentResult:
1284 intentResult = checkIntentState( main, intentsId )
sathishmc4362252016-04-20 18:29:48 +05301285 if intentResult:
1286 main.assertReturnString += 'Initial Intent State Passed\n'
1287 else:
1288 main.assertReturnString += 'Initial Intent State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001289
1290 # Check flows count in each node
sathishmc4362252016-04-20 18:29:48 +05301291 FlowResult = checkFlowsCount( main )
1292 if FlowResult:
1293 main.assertReturnString += 'Initial Flow Count Passed\n'
1294 else:
1295 main.assertReturnString += 'Initial Flow Count Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001296 # Verify flows
sathishmc4362252016-04-20 18:29:48 +05301297 StateResult = checkFlowsState( main )
1298 if StateResult:
1299 main.assertReturnString += 'Initial Flow State Passed\n'
1300 else:
1301 main.assertReturnString += 'Initial Flow State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001302
Jon Hall439c8912016-04-15 02:22:03 -07001303 # Ping hosts...
1304 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001305 pingResult = pingResult and pingTemp
1306 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001307 main.assertReturnString += 'Initial Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001308 else:
Jon Hall439c8912016-04-15 02:22:03 -07001309 main.assertReturnString += 'Initial Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001310
1311 # Test rerouting if these variables exist
1312 if sw1 and sw2 and expectedLink:
1313 # link down
1314 linkDownResult = link( main, sw1, sw2, "down" )
1315
1316 if linkDownResult:
1317 main.assertReturnString += 'Link Down Passed\n'
1318 else:
1319 main.assertReturnString += 'Link Down Failed\n'
1320
1321 # Check flows count in each node
1322 checkFlowsCount( main )
1323 # Verify flows
1324 checkFlowsState( main )
1325
1326 # Check OnosTopology
1327 topoResult = checkTopology( main, expectedLink )
1328 if topoResult:
1329 main.assertReturnString += 'Link Down Topology State Passed\n'
1330 else:
1331 main.assertReturnString += 'Link Down Topology State Failed\n'
1332
1333 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -07001334 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001335 pingResult = pingResult and pingTemp
1336 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001337 main.assertReturnString += 'Link Down Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001338 else:
Jon Hall439c8912016-04-15 02:22:03 -07001339 main.assertReturnString += 'Link Down Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001340
1341 # Check intent state
1342 intentTemp = checkIntentState( main, intentsId )
1343 intentResult = intentResult and intentTemp
1344 if intentTemp:
1345 main.assertReturnString += 'Link Down Intent State Passed\n'
1346 else:
1347 main.assertReturnString += 'Link Down Intent State Failed\n'
1348
1349 # Checks ONOS state in link down
1350 if linkDownResult and topoResult and pingResult and intentResult:
1351 main.log.info( itemName + ": Successfully brought link down" )
1352 else:
1353 main.log.error( itemName + ": Failed to bring link down" )
1354
1355 # link up
1356 linkUpResult = link( main, sw1, sw2, "up" )
1357 if linkUpResult:
1358 main.assertReturnString += 'Link Up Passed\n'
1359 else:
1360 main.assertReturnString += 'Link Up Failed\n'
1361
1362 time.sleep( main.rerouteSleep )
1363
1364 # Check flows count in each node
1365 checkFlowsCount( main )
1366 # Verify flows
1367 checkFlowsState( main )
1368
1369 # Check OnosTopology
1370 topoResult = checkTopology( main, main.numLinks )
1371 if topoResult:
1372 main.assertReturnString += 'Link Up Topology State Passed\n'
1373 else:
1374 main.assertReturnString += 'Link Up Topology State Failed\n'
1375
1376 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -07001377 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001378 pingResult = pingResult and pingTemp
1379 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001380 main.assertReturnString += 'Link Up Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001381 else:
Jon Hall439c8912016-04-15 02:22:03 -07001382 main.assertReturnString += 'Link Up Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001383
1384 # Check Intents
1385 intentTemp = checkIntentState( main, intentsId )
1386 intentResult = intentResult and intentTemp
1387 if intentTemp:
1388 main.assertReturnString += 'Link Up Intent State Passed\n'
1389 else:
1390 main.assertReturnString += 'Link Up Intent State Failed\n'
1391
1392 # Checks ONOS state in link up
1393 if linkUpResult and topoResult and pingResult and intentResult:
1394 main.log.info( itemName + ": Successfully brought link back up" )
1395 else:
1396 main.log.error( itemName + ": Failed to bring link back up" )
1397
1398 # Remove all intents
1399 removeIntentResult = removeAllIntents( main, intentsId )
1400 if removeIntentResult:
1401 main.assertReturnString += 'Remove Intents Passed'
1402 else:
1403 main.assertReturnString += 'Remove Intents Failed'
1404
1405 stepResult = pingResult and linkDownResult and linkUpResult \
1406 and intentResult and removeIntentResult
1407
1408 return stepResult
1409
Jon Hall314b74a2017-05-24 16:25:52 -07001410
sathishmc4362252016-04-20 18:29:48 +05301411def testEndPointFail( main,
1412 name,
1413 test="",
1414 hostNames="",
1415 devices="",
1416 macs="",
1417 ports="",
1418 onosNode=0,
1419 ethType="",
1420 bandwidth="",
1421 lambdaAlloc=False,
1422 ipProto="",
1423 ipAddresses="",
1424 tcp="",
1425 sw1="",
1426 sw2="",
1427 sw3="",
1428 sw4="",
1429 sw5="",
1430 expectedLink1=0,
1431 expectedLink2=0 ):
1432 """
1433 Test Multipoint Topology for Endpoint failures
1434 """
sathishmc4362252016-04-20 18:29:48 +05301435 assert main, "There is no main variable"
1436 assert hostNames, "You must specify hosts"
1437 assert devices or main.hostsData, "You must specify devices"
1438
1439 global itemName
1440 itemName = name
1441 tempHostsData = {}
1442 intentsId = []
1443 onosNode = int( onosNode )
1444
1445 macsDict = {}
1446 ipDict = {}
1447 if hostNames and devices:
1448 if len( hostNames ) != len( devices ):
1449 main.log.debug( "hosts and devices does not have the same length" )
1450 return main.FALSE
1451 if ports:
1452 if len( ports ) != len( devices ):
1453 main.log.error( "Ports and devices does " +
1454 "not have the same length" )
1455 return main.FALSE
1456 else:
1457 main.log.info( "Device Ports are not specified" )
1458 if macs:
1459 for i in range( len( devices ) ):
1460 macsDict[ devices[ i ] ] = macs[ i ]
1461 elif hostNames and not devices and main.hostsData:
1462 devices = []
1463 main.log.info( "multiIntent function is using main.hostsData" )
1464 for host in hostNames:
Jon Hall314b74a2017-05-24 16:25:52 -07001465 devices.append( main.hostsData.get( host ).get( 'location' ) )
1466 macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \
1467 main.hostsData.get( host ).get( 'mac' )
1468 ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \
1469 main.hostsData.get( host ).get( 'ipAddresses' )
sathishmc4362252016-04-20 18:29:48 +05301470
1471 pingResult = main.TRUE
1472 intentResult = main.TRUE
1473 removeIntentResult = main.TRUE
1474 flowResult = main.TRUE
1475 topoResult = main.TRUE
1476 linkDownResult = main.TRUE
1477 linkUpResult = main.TRUE
1478
1479 devicesCopy = copy.copy( devices )
1480 if ports:
1481 portsCopy = copy.copy( ports )
1482 main.log.info( itemName + ": Adding intents" )
1483
1484 # Check flows count in each node
1485 checkFlowsCount( main )
1486
Jon Hall314b74a2017-05-24 16:25:52 -07001487 if test == "MultipletoSingle":
sathishmc4362252016-04-20 18:29:48 +05301488 for i in range( len( devices ) ):
1489 egressDevice = devicesCopy[ i ]
1490 ingressDeviceList = copy.copy( devicesCopy )
1491 ingressDeviceList.remove( egressDevice )
1492 if ports:
1493 portEgress = portsCopy[ i ]
1494 portIngressList = copy.copy( portsCopy )
1495 del portIngressList[ i ]
1496 else:
1497 portEgress = ""
1498 portIngressList = None
1499 if not macsDict:
1500 dstMac = ""
1501 else:
1502 dstMac = macsDict[ egressDevice ]
Jon Hall314b74a2017-05-24 16:25:52 -07001503 if dstMac is None:
sathishmc4362252016-04-20 18:29:48 +05301504 main.log.debug( "There is no MAC in device - " + egressDevice )
1505 dstMac = ""
1506
1507 intentsId.append(
1508 main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
1509 ingressDeviceList=ingressDeviceList,
1510 egressDevice=egressDevice,
1511 portIngressList=portIngressList,
1512 portEgress=portEgress,
1513 ethType=ethType,
1514 ethDst=dstMac,
1515 bandwidth=bandwidth,
1516 lambdaAlloc=lambdaAlloc,
1517 ipProto=ipProto,
1518 ipSrc="",
1519 ipDst="",
1520 tcpSrc="",
1521 tcpDst="" ) )
1522
Jon Hall314b74a2017-05-24 16:25:52 -07001523 elif test == "SingletoMultiple":
sathishmc4362252016-04-20 18:29:48 +05301524 for i in range( len( devices ) ):
1525 ingressDevice = devicesCopy[ i ]
1526 egressDeviceList = copy.copy( devicesCopy )
1527 egressDeviceList.remove( ingressDevice )
1528 if ports:
1529 portIngress = portsCopy[ i ]
1530 portEgressList = copy.copy( portsCopy )
1531 del portEgressList[ i ]
1532 else:
1533 portIngress = ""
1534 portEgressList = None
1535 if not macsDict:
1536 srcMac = ""
1537 else:
1538 srcMac = macsDict[ ingressDevice ]
Jon Hall314b74a2017-05-24 16:25:52 -07001539 if srcMac is None:
sathishmc4362252016-04-20 18:29:48 +05301540 main.log.debug( "There is no MAC in device - " + ingressDevice )
1541 srcMac = ""
1542
1543 intentsId.append(
1544 main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
1545 ingressDevice=ingressDevice,
1546 egressDeviceList=egressDeviceList,
1547 portIngress=portIngress,
1548 portEgressList=portEgressList,
1549 ethType=ethType,
1550 ethSrc=srcMac,
1551 bandwidth=bandwidth,
1552 lambdaAlloc=lambdaAlloc,
1553 ipProto=ipProto,
1554 ipSrc="",
1555 ipDst="",
1556 tcpSrc="",
1557 tcpDst="" ) )
1558
1559 else:
Jon Hall314b74a2017-05-24 16:25:52 -07001560 main.log.info( "Invalid test Name - Type either SingletoMultiple or MultipletoSingle" )
sathishmc4362252016-04-20 18:29:48 +05301561 return main.FALSE
1562
1563 # Check intents state
1564 time.sleep( main.checkIntentSleep )
1565 intentResult = checkIntentState( main, intentsId )
1566
1567 # Check intents state again if first check fails...
1568 if not intentResult:
1569 intentResult = checkIntentState( main, intentsId )
1570 if intentResult:
1571 main.assertReturnString += 'Initial Intent State Passed\n'
1572 else:
1573 main.assertReturnString += 'Initial Intent State Failed\n'
1574
1575 # Check flows count in each node
1576 FlowResult = checkFlowsCount( main )
1577 if FlowResult:
1578 main.assertReturnString += 'Initial Flow Count Passed\n'
1579 else:
1580 main.assertReturnString += 'Initial Flow Count Failed\n'
1581 # Verify flows
1582 StateResult = checkFlowsState( main )
1583 if StateResult:
1584 main.assertReturnString += 'Initial Flow State Passed\n'
1585 else:
1586 main.assertReturnString += 'Initial Flow State Failed\n'
1587
1588 # Ping hosts...
1589 pingTemp = ping6allHosts( main, hostNames )
1590 pingResult = pingResult and pingTemp
1591 if pingTemp:
1592 main.assertReturnString += 'Initial Pingall Passed\n'
1593 else:
1594 main.assertReturnString += 'Initial Pingall Failed\n'
1595
1596 # Test rerouting if these variables exist
1597 if sw1 and sw2 and sw3 and sw4 and sw5 and expectedLink1 and expectedLink2:
Jon Hall314b74a2017-05-24 16:25:52 -07001598 # Take two links down
sathishmc4362252016-04-20 18:29:48 +05301599 # Take first link down
1600 linkDownResult1 = link( main, sw1, sw2, "down" )
1601 if linkDownResult1:
1602 main.assertReturnString += 'First Link Down Passed\n'
1603 else:
1604 main.assertReturnString += 'First Link Down Failed\n'
1605
1606 # Take second link down
1607 linkDownResult2 = link( main, sw3, sw4, "down" )
1608 if linkDownResult2:
1609 main.assertReturnString += 'Second Link Down Passed\n'
1610 else:
1611 main.assertReturnString += 'Second Link Down Failed\n'
1612
1613 # Check flows count in each node
1614 FlowResult = checkFlowsCount( main )
1615 if FlowResult:
1616 main.assertReturnString += 'Link Down Flow Count Passed\n'
1617 else:
1618 main.assertReturnString += 'Link Down Flow Count Failed\n'
1619 # Verify flows
1620 StateResult = checkFlowsState( main )
1621 if StateResult:
1622 main.assertReturnString += 'Link Down Flow State Passed\n'
1623 else:
1624 main.assertReturnString += 'Link Down Flow State Failed\n'
1625
1626 # Check OnosTopology
1627 topoResult = checkTopology( main, expectedLink1 )
1628 if topoResult:
1629 main.assertReturnString += 'Link Down Topology State Passed\n'
1630 else:
1631 main.assertReturnString += 'Link Down Topology State Failed\n'
1632
1633 # Ping hosts
1634 pingTemp = ping6allHosts( main, hostNames )
1635 pingResult = pingResult and pingTemp
1636 if pingTemp:
1637 main.assertReturnString += 'Link Down Ping6all Passed\n'
1638 else:
1639 main.assertReturnString += 'Link Down Ping6all Failed\n'
1640
1641 # Check intent state
1642 intentTemp = checkIntentState( main, intentsId )
1643 intentResult = intentResult and intentTemp
1644 if intentTemp:
1645 main.assertReturnString += 'Link Down Intent State Passed\n'
1646 else:
1647 main.assertReturnString += 'Link Down Intent State Failed\n'
1648
1649 # Take third link down to isolate the node
1650 linkDownResult3 = link( main, sw3, sw5, "down" )
1651 if linkDownResult3:
1652 main.assertReturnString += 'Isolation Third Link Down Passed\n'
1653 else:
1654 main.assertReturnString += 'Isolation Third Link Down Failed\n'
1655
1656 # Check flows count in each node
1657 FlowResult = checkFlowsCount( main )
1658 if FlowResult:
1659 main.assertReturnString += 'Isolation Link Down Flow Count Passed\n'
1660 else:
1661 main.assertReturnString += 'Isolation Link Down Flow Count Failed\n'
1662
1663 # Verify flows
1664 StateResult = checkFlowsState( main )
1665 if StateResult:
1666 main.assertReturnString += 'Isolation Link Down Flow State Passed\n'
1667 else:
1668 main.assertReturnString += 'Isolation Link Down Flow State Failed\n'
1669
1670 # Check OnosTopology
1671 topoResult = checkTopology( main, expectedLink2 )
1672 if topoResult:
1673 main.assertReturnString += 'Isolation Link Down Topology State Passed\n'
1674 else:
1675 main.assertReturnString += 'Isolation Link Down Topology State Failed\n'
1676
1677 # Ping hosts after isolation
Jon Hall314b74a2017-05-24 16:25:52 -07001678 main.log.info( "Ping will fail if the node is isolated correctly.It will ping only after bringing up the isolation link" )
sathishmc4362252016-04-20 18:29:48 +05301679 pingIsolation = ping6allHosts( main, hostNames )
1680 if pingIsolation:
1681 main.assertReturnString += 'Isolation Link Down Ping6all Passed\n'
1682 else:
1683 main.assertReturnString += 'Isolation Link Down Ping6all Failed\n'
1684
1685 # Check intent state after isolation
Jon Hall314b74a2017-05-24 16:25:52 -07001686 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" )
sathishmc4362252016-04-20 18:29:48 +05301687 intentIsolation = checkIntentState( main, intentsId )
1688 if intentIsolation:
1689 main.assertReturnString += 'Isolation Link Down Intent State Passed\n'
1690 else:
1691 main.assertReturnString += 'Isolation Link Down Intent State Failed\n'
1692
1693 linkDownResult = linkDownResult1 and linkDownResult2 and linkDownResult3
1694
1695 # Checks ONOS state in link down
1696 if linkDownResult and topoResult and pingResult and intentResult:
1697 main.log.info( itemName + ": Successfully brought link down" )
1698 else:
1699 main.log.error( itemName + ": Failed to bring link down" )
1700
1701 # Bring the links back up
1702 # Bring first link up
1703 linkUpResult1 = link( main, sw1, sw2, "up" )
1704 if linkUpResult1:
1705 main.assertReturnString += 'First Link Up Passed\n'
1706 else:
1707 main.assertReturnString += 'First Link Up Failed\n'
1708
1709 # Bring second link up
1710 linkUpResult2 = link( main, sw3, sw4, "up" )
1711 if linkUpResult2:
1712 main.assertReturnString += 'Second Link Up Passed\n'
1713 else:
1714 main.assertReturnString += 'Second Link Up Failed\n'
1715 # Bring third link up
1716 linkUpResult3 = link( main, sw3, sw5, "up" )
1717 if linkUpResult3:
1718 main.assertReturnString += 'Third Link Up Passed\n'
1719 else:
1720 main.assertReturnString += 'Third Link Up Failed\n'
1721
1722 linkUpResult = linkUpResult1 and linkUpResult2 and linkUpResult3
1723 time.sleep( main.rerouteSleep )
1724
1725 # Check flows count in each node
1726 FlowResult = checkFlowsCount( main )
1727 if FlowResult:
1728 main.assertReturnString += 'Link Up Flow Count Passed\n'
1729 else:
1730 main.assertReturnString += 'Link Up Flow Count Failed\n'
1731 # Verify flows
1732 StateResult = checkFlowsState( main )
1733 if StateResult:
1734 main.assertReturnString += 'Link Up Flow State Passed\n'
1735 else:
1736 main.assertReturnString += 'Link Up Flow State Failed\n'
1737
1738 # Check OnosTopology
1739 topoResult = checkTopology( main, main.numLinks )
1740 if topoResult:
1741 main.assertReturnString += 'Link Up Topology State Passed\n'
1742 else:
1743 main.assertReturnString += 'Link Up Topology State Failed\n'
1744
1745 # Ping hosts
1746 pingTemp = ping6allHosts( main, hostNames )
1747 pingResult = pingResult and pingTemp
1748 if pingTemp:
1749 main.assertReturnString += 'Link Up Pingall Passed\n'
1750 else:
1751 main.assertReturnString += 'Link Up Pingall Failed\n'
1752
1753 # Check Intents
1754 intentTemp = checkIntentState( main, intentsId )
1755 intentResult = intentResult and intentTemp
1756 if intentTemp:
1757 main.assertReturnString += 'Link Up Intent State Passed\n'
1758 else:
1759 main.assertReturnString += 'Link Up Intent State Failed\n'
1760
1761 # Checks ONOS state in link up
1762 if linkUpResult and topoResult and pingResult and intentResult:
1763 main.log.info( itemName + ": Successfully brought link back up" )
1764 else:
1765 main.log.error( itemName + ": Failed to bring link back up" )
1766
1767 # Remove all intents
1768 removeIntentResult = removeAllIntents( main, intentsId )
1769 if removeIntentResult:
1770 main.assertReturnString += 'Remove Intents Passed'
1771 else:
1772 main.assertReturnString += 'Remove Intents Failed'
1773
1774 testResult = pingResult and linkDownResult and linkUpResult \
1775 and intentResult and removeIntentResult
1776
1777 return testResult
1778
Jon Hall314b74a2017-05-24 16:25:52 -07001779
Subhash Kumar Singh5ea4d302015-11-05 14:36:52 +05301780def ping6allHosts( main, hostList ):
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001781 # Ping all host in the hosts list variable
1782 main.log.info( "Pinging: " + str( hostList ) )
Subhash Kumar Singh5ea4d302015-11-05 14:36:52 +05301783 return main.Mininet1.pingIpv6Hosts( hostList )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001784
Jon Hall314b74a2017-05-24 16:25:52 -07001785
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001786def getHostsData( main ):
1787 """
1788 Use fwd app and pingall to discover all the hosts
1789 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001790 activateResult = main.TRUE
1791 appCheck = main.TRUE
1792 getDataResult = main.TRUE
1793 main.log.info( "Activating reactive forwarding app " )
1794 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
Jon Hall314b74a2017-05-24 16:25:52 -07001795 main.CLIs[ 0 ].setCfg( "org.onosproject.provider.host.impl.HostLocationProvider", "useIpv6ND", "true" )
alisona2905c12016-09-19 15:18:07 -07001796 main.CLIs[ 0 ].setCfg( "org.onosproject.incubator.net.neighbour.impl.NeighbourResolutionManager", "ndpEnabled", "true" )
Jon Hall314b74a2017-05-24 16:25:52 -07001797 main.CLIs[ 0 ].setCfg( "org.onosproject.fwd.ReactiveForwarding", "ipv6Forwarding", "true" )
1798 main.CLIs[ 0 ].setCfg( "org.onosproject.fwd.ReactiveForwarding", "matchIpv6Address", "true" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001799 time.sleep( main.fwdSleep )
1800
1801 for i in range( main.numCtrls ):
1802 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
1803 if appCheck != main.TRUE:
1804 main.log.warn( main.CLIs[ i ].apps() )
1805 main.log.warn( main.CLIs[ i ].appIDs() )
1806
Jon Hall314b74a2017-05-24 16:25:52 -07001807 pingResult = main.Mininet1.pingall( protocol="IPv6", timeout=600 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001808 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
1809 hosts = main.Mininet1.getHosts().keys()
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001810 for host in hosts:
1811 main.hostsData[ host ] = {}
1812 main.hostsData[ host ][ 'mac' ] = \
1813 main.Mininet1.getMacAddress( host ).upper()
1814 for hostj in hostsJson:
1815 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
1816 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
1817 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
1818 main.hostsData[ host ][ 'location' ] = \
Jeremy Ronquillo0e538bc2017-06-13 15:16:09 -07001819 hostj[ 'locations' ][ 0 ][ 'elementId' ] + '/' + \
1820 hostj[ 'locations' ][ 0 ][ 'port' ]
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001821 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
1822
1823 main.log.info( "Deactivating reactive forwarding app " )
1824 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
1825 if activateResult and deactivateResult and main.hostsData:
1826 main.log.info( "Successfully used fwd app to discover hosts " )
1827 getDataResult = main.TRUE
1828 else:
1829 main.log.info( "Failed to use fwd app to discover hosts " )
1830 getDataResult = main.FALSE
1831
Jon Hall439c8912016-04-15 02:22:03 -07001832 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' " )
1833 for host in main.hostsData.keys():
Jon Hall314b74a2017-05-24 16:25:52 -07001834 if main.hostsData[ host ].get( 'ipAddresses' ) is not None:
1835 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 -08001836 print main.hostsData
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001837 return getDataResult
1838
Jon Hall314b74a2017-05-24 16:25:52 -07001839
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001840def checkTopology( main, expectedLink ):
1841 statusResult = main.TRUE
1842 # Check onos topology
1843 main.log.info( itemName + ": Checking ONOS topology " )
1844
1845 for i in range( main.numCtrls ):
Flavio Castro82ee2f62016-06-07 15:04:12 -07001846 statusResult = main.CLIs[ i ].checkStatus( main.numSwitch,
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001847 expectedLink )\
1848 and statusResult
1849 if not statusResult:
1850 main.log.error( itemName + ": Topology mismatch" )
1851 else:
1852 main.log.info( itemName + ": Topology match" )
1853 return statusResult
1854
Jon Hall314b74a2017-05-24 16:25:52 -07001855
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001856def checkIntentState( main, intentsId ):
1857 """
1858 This function will check intent state to make sure all the intents
1859 are in INSTALLED state
1860 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001861 intentResult = main.TRUE
1862 results = []
1863
1864 main.log.info( itemName + ": Checking intents state" )
1865 # First check of intents
1866 for i in range( main.numCtrls ):
1867 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
1868 results.append( tempResult )
1869
1870 expectedState = [ 'INSTALLED', 'INSTALLING' ]
1871
1872 if all( result == main.TRUE for result in results ):
1873 main.log.info( itemName + ": Intents are installed correctly" )
1874 else:
1875 # Wait for at least 5 second before checking the intents again
1876 main.log.error( "Intents are not installed correctly. Waiting 5 sec" )
1877 time.sleep( 5 )
1878 results = []
1879 # Second check of intents since some of the intents may be in
1880 # INSTALLING state, they should be in INSTALLED at this time
1881 for i in range( main.numCtrls ):
1882 tempResult = main.CLIs[ i ].checkIntentState(
1883 intentsId=intentsId )
1884 results.append( tempResult )
1885 if all( result == main.TRUE for result in results ):
1886 main.log.info( itemName + ": Intents are installed correctly" )
1887 intentResult = main.TRUE
1888 else:
1889 main.log.error( itemName + ": Intents are NOT installed correctly" )
1890 intentResult = main.FALSE
1891
1892 return intentResult
1893
Jon Hall314b74a2017-05-24 16:25:52 -07001894
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001895def checkFlowsState( main ):
1896
1897 main.log.info( itemName + ": Check flows state" )
1898 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState()
1899 return checkFlowsResult
1900
Jon Hall314b74a2017-05-24 16:25:52 -07001901
1902def link( main, sw1, sw2, option ):
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001903
1904 # link down
1905 main.log.info( itemName + ": Bring link " + option + "between " +
1906 sw1 + " and " + sw2 )
1907 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
1908 return linkResult
1909
Jon Hall314b74a2017-05-24 16:25:52 -07001910
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001911def removeAllIntents( main, intentsId ):
1912 """
1913 Remove all intents in the intentsId
1914 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001915 onosSummary = []
1916 removeIntentResult = main.TRUE
1917 # Remove intents
1918 for intent in intentsId:
1919 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
1920
1921 time.sleep( main.removeIntentSleep )
1922
1923 # If there is remianing intents then remove intents should fail
1924 for i in range( main.numCtrls ):
1925 onosSummary.append( json.loads( main.CLIs[ i ].summary() ) )
1926
1927 for summary in onosSummary:
1928 if summary.get( 'intents' ) != 0:
1929 main.log.warn( itemName + ": There are " +
1930 str( summary.get( 'intents' ) ) +
1931 " intents remaining in node " +
1932 str( summary.get( 'node' ) ) +
1933 ", failed to remove all the intents " )
1934 removeIntentResult = main.FALSE
1935
1936 if removeIntentResult:
1937 main.log.info( itemName + ": There are no more intents remaining, " +
1938 "successfully removed all the intents." )
1939
1940 return removeIntentResult
1941
Jon Hall314b74a2017-05-24 16:25:52 -07001942
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001943def checkFlowsCount( main ):
1944 """
1945 Check flows count in each node
1946 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001947 flowsCount = []
1948 main.log.info( itemName + ": Checking flows count in each ONOS node" )
1949 for i in range( main.numCtrls ):
1950 summaryResult = main.CLIs[ i ].summary()
1951 if not summaryResult:
1952 main.log.error( itemName + ": There is something wrong with " +
1953 "summary command" )
1954 return main.FALSE
1955 else:
1956 summaryJson = json.loads( summaryResult )
1957 flowsCount.append( summaryJson.get( 'flows' ) )
1958
1959 if flowsCount:
Jon Hall314b74a2017-05-24 16:25:52 -07001960 if all( flows == flowsCount[ 0 ] for flows in flowsCount ):
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001961 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
1962 " flows in all ONOS node" )
1963 else:
1964 for i in range( main.numCtrls ):
1965 main.log.debug( itemName + ": ONOS node " + str( i ) + " has " +
1966 str( flowsCount[ i ] ) + " flows" )
1967 else:
1968 main.log.error( "Checking flows count failed, check summary command" )
1969 return main.FALSE
1970
1971 return main.TRUE
1972
Jon Hall314b74a2017-05-24 16:25:52 -07001973
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001974def checkLeaderChange( leaders1, leaders2 ):
1975 """
1976 Checks for a change in intent partition leadership.
1977
1978 Takes the output of leaders -c in json string format before and after
1979 a potential change as input
1980
1981 Returns main.TRUE if no mismatches are detected
1982 Returns main.FALSE if there is a mismatch or on error loading the input
1983 """
1984 try:
1985 leaders1 = json.loads( leaders1 )
1986 leaders2 = json.loads( leaders2 )
Jon Hall314b74a2017-05-24 16:25:52 -07001987 except ( AttributeError, TypeError ):
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001988 main.log.exception( self.name + ": Object not as expected" )
1989 return main.FALSE
1990 except Exception:
1991 main.log.exception( self.name + ": Uncaught exception!" )
1992 main.cleanup()
1993 main.exit()
1994 main.log.info( "Checking Intent Paritions for Change in Leadership" )
1995 mismatch = False
1996 for dict1 in leaders1:
1997 if "intent" in dict1.get( "topic", [] ):
1998 for dict2 in leaders2:
1999 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \
Jon Hall314b74a2017-05-24 16:25:52 -07002000 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08002001 mismatch = True
Jon Hall314b74a2017-05-24 16:25:52 -07002002 main.log.error( "{0} changed leader from {1} to {2}".
2003 format( dict1.get( "topic", "no-topic" ),
2004 dict1.get( "leader", "no-leader" ),
2005 dict2.get( "leader", "no-leader" ) ) )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08002006 if mismatch:
2007 return main.FALSE
2008 else:
2009 return main.TRUE
2010
Jon Hall314b74a2017-05-24 16:25:52 -07002011
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08002012def report( main ):
2013 """
2014 Report errors/warnings/exceptions
2015 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08002016 main.ONOSbench.logReport( main.ONOSip[ 0 ],
2017 [ "INFO",
2018 "FOLLOWER",
2019 "WARN",
2020 "flow",
2021 "ERROR",
2022 "Except" ],
2023 "s" )
2024
2025 main.log.info( "ERROR report: \n" )
2026 for i in range( main.numCtrls ):
2027 main.ONOSbench.logReport( main.ONOSip[ i ],
Jon Hall314b74a2017-05-24 16:25:52 -07002028 [ "ERROR" ],
2029 "d" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08002030
2031 main.log.info( "EXCEPTIONS report: \n" )
2032 for i in range( main.numCtrls ):
2033 main.ONOSbench.logReport( main.ONOSip[ i ],
Jon Hall314b74a2017-05-24 16:25:52 -07002034 [ "Except" ],
2035 "d" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08002036
2037 main.log.info( "WARNING report: \n" )
2038 for i in range( main.numCtrls ):
2039 main.ONOSbench.logReport( main.ONOSip[ i ],
Jon Hall314b74a2017-05-24 16:25:52 -07002040 [ "WARN" ],
2041 "d" )