blob: 51b282f24771fa83772a62dad8894f58aedfd894 [file] [log] [blame]
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07002Copyright 2015 Open Networking Foundation (ONF)
3
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
12
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20
21
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080022 Wrapper functions for FuncIntent
23 This functions include Onosclidriver and Mininetclidriver driver functions
24 Author: subhash_singh@criterionnetworks.com
25"""
26import time
27import copy
28import json
29
Jon Hall314b74a2017-05-24 16:25:52 -070030
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080031def __init__( self ):
32 self.default = ''
33
Jon Hall314b74a2017-05-24 16:25:52 -070034
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080035def hostIntent( main,
36 name,
37 host1,
38 host2,
39 onosNode=0,
40 host1Id="",
41 host2Id="",
42 mac1="",
43 mac2="",
44 vlan1="-1",
45 vlan2="-1",
46 sw1="",
47 sw2="",
48 expectedLink=0 ):
49 """
50 Description:
51 Verify add-host-intent
52 Steps:
53 - Discover hosts
54 - Add host intents
55 - Check intents
56 - Verify flows
57 - Ping hosts
58 - Reroute
59 - Link down
60 - Verify flows
61 - Check topology
62 - Ping hosts
63 - Link up
64 - Verify flows
65 - Check topology
66 - Ping hosts
67 - Remove intents
68 Required:
69 name - Type of host intent to add eg. IPV4 | VLAN | Dualstack
70 host1 - Name of first host
71 host2 - Name of second host
72 Optional:
73 onosNode - ONOS node to install the intents in main.CLIs[ ]
74 0 by default so that it will always use the first
75 ONOS node
76 host1Id - ONOS id of the first host eg. 00:00:00:00:00:01/-1
77 host2Id - ONOS id of the second host
78 mac1 - Mac address of first host
79 mac2 - Mac address of the second host
80 vlan1 - Vlan tag of first host, defaults to -1
81 vlan2 - Vlan tag of second host, defaults to -1
82 sw1 - First switch to bring down & up for rerouting purpose
83 sw2 - Second switch to bring down & up for rerouting purpose
84 expectedLink - Expected link when the switches are down, it should
85 be two links lower than the links before the two
86 switches are down
87 Return:
88 Returns main.TRUE if all verification passed, otherwise return
89 main.FALSE; returns main.FALSE if there is a key error
90 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080091 # Assert variables
92 assert main, "There is no main variable"
93 assert name, "variable name is empty"
94 assert host1 and host2, "You must specify hosts"
95
96 global itemName
97 itemName = name
98 h1Id = host1Id
99 h2Id = host2Id
100 h1Mac = mac1
101 h2Mac = mac2
102 vlan1 = vlan1
103 vlan2 = vlan2
Jon Hall314b74a2017-05-24 16:25:52 -0700104 hostNames = [ host1, host2 ]
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800105 intentsId = []
106 stepResult = main.TRUE
107 pingResult = main.TRUE
108 intentResult = main.TRUE
109 removeIntentResult = main.TRUE
110 flowResult = main.TRUE
111 topoResult = main.TRUE
112 linkDownResult = main.TRUE
113 linkUpResult = main.TRUE
114 onosNode = int( onosNode )
115
116 try:
117 if main.hostsData:
118 if not h1Mac:
119 h1Mac = main.hostsData[ host1 ][ 'mac' ]
120 if not h2Mac:
121 h2Mac = main.hostsData[ host2 ][ 'mac' ]
122 if main.hostsData[ host1 ].get( 'vlan' ):
123 vlan1 = main.hostsData[ host1 ][ 'vlan' ]
124 if main.hostsData[ host1 ].get( 'vlan' ):
125 vlan2 = main.hostsData[ host2 ][ 'vlan' ]
126 if not h1Id:
127 h1Id = main.hostsData[ host1 ][ 'id' ]
128 if not h2Id:
129 h2Id = main.hostsData[ host2 ][ 'id' ]
130
131 assert h1Id and h2Id, "You must specify host IDs"
132 if not ( h1Id and h2Id ):
133 main.log.info( "There are no host IDs" )
134 return main.FALSE
135
136 except KeyError:
137 main.log.error( itemName + ": Key error Exception" )
138 return main.FALSE
139
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800140 # Check flows count in each node
141 checkFlowsCount( main )
142
143 # Adding host intents
144 main.log.info( itemName + ": Adding host intents" )
145 intent1 = main.CLIs[ onosNode ].addHostIntent( hostIdOne=h1Id,
146 hostIdTwo=h2Id )
147 intentsId.append( intent1 )
148
149 # Check intents state
150 time.sleep( main.checkIntentSleep )
151 intentResult = checkIntentState( main, intentsId )
152 checkFlowsCount( main )
153
154 # Check intents state again if first check fails...
155 if not intentResult:
156 intentResult = checkIntentState( main, intentsId )
sathishmc4362252016-04-20 18:29:48 +0530157 if intentResult:
158 main.assertReturnString += 'Initial Intent State Passed\n'
159 else:
160 main.assertReturnString += 'Initial Intent State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800161
162 # Check flows count in each node
sathishmc4362252016-04-20 18:29:48 +0530163 FlowResult = checkFlowsCount( main )
164 if FlowResult:
165 main.assertReturnString += 'Initial Flow Count Passed\n'
166 else:
167 main.assertReturnString += 'Initial Flow Count Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800168 # Verify flows
sathishmc4362252016-04-20 18:29:48 +0530169 StateResult = checkFlowsState( main )
170 if StateResult:
171 main.assertReturnString += 'Initial Flow State Passed\n'
172 else:
173 main.assertReturnString += 'Initial Flow State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800174
175 # Ping hosts
Jon Hall314b74a2017-05-24 16:25:52 -0700176 firstPingResult = main.Mininet1.ping6pair( SRC=hostNames[ 0 ], TARGET=main.hostsData[ host2 ][ 'ipAddresses' ][ 0 ] )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800177 if not firstPingResult:
178 main.log.debug( "First ping failed, there must be" +
Jon Hall314b74a2017-05-24 16:25:52 -0700179 " something wrong with ONOS performance" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800180
181 # Ping hosts again...
Jon Hall439c8912016-04-15 02:22:03 -0700182 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800183 pingResult = pingResult and pingTemp
184 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700185 main.assertReturnString += 'Initial Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800186 else:
Jon Hall439c8912016-04-15 02:22:03 -0700187 main.assertReturnString += 'Initial Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800188
189 # Test rerouting if these variables exist
190 if sw1 and sw2 and expectedLink:
191 # Link down
192 linkDownResult = link( main, sw1, sw2, "down" )
193
194 if linkDownResult:
195 main.assertReturnString += 'Link Down Passed\n'
196 else:
197 main.assertReturnString += 'Link Down Failed\n'
198
199 # Check flows count in each node
200 checkFlowsCount( main )
201 # Verify flows
202 checkFlowsState( main )
203
204 # Check OnosTopology
205 topoResult = checkTopology( main, expectedLink )
206 if topoResult:
207 main.assertReturnString += 'Link Down Topology State Passed\n'
208 else:
209 main.assertReturnString += 'Link Down Topology State Failed\n'
210
211 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -0700212 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800213 pingResult = pingResult and pingTemp
214
215 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700216 main.assertReturnString += 'Link Down Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800217 else:
Jon Hall439c8912016-04-15 02:22:03 -0700218 main.assertReturnString += 'Link Down Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800219
220 # Check intent states
221 intentTemp = checkIntentState( main, intentsId )
222 intentResult = intentResult and intentTemp
223 if intentTemp:
224 main.assertReturnString += 'Link Down Intent State Passed\n'
225 else:
226 main.assertReturnString += 'Link Down Intent State Failed\n'
227
228 # Checks ONOS state in link down
229 if linkDownResult and topoResult and pingResult and intentResult:
230 main.log.info( itemName + ": Successfully brought link down" )
231 else:
232 main.log.error( itemName + ": Failed to bring link down" )
233
234 # Link up
235 linkUpResult = link( main, sw1, sw2, "up" )
236 time.sleep( main.rerouteSleep )
237
238 if linkUpResult:
239 main.assertReturnString += 'Link Up Passed\n'
240 else:
241 main.assertReturnString += 'Link Up Failed\n'
242
243 # Check flows count in each node
244 checkFlowsCount( main )
245 # Verify flows
246 checkFlowsState( main )
247
248 # Check OnosTopology
249 topoResult = checkTopology( main, main.numLinks )
250
251 if topoResult:
252 main.assertReturnString += 'Link Up Topology State Passed\n'
253 else:
254 main.assertReturnString += 'Link Up Topology State Failed\n'
255
256 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -0700257 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800258 pingResult = pingResult and pingTemp
259
260 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700261 main.assertReturnString += 'Link Up Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800262 else:
Jon Hall439c8912016-04-15 02:22:03 -0700263 main.assertReturnString += 'Link Up Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800264
265 intentTemp = checkIntentState( main, intentsId )
266 intentResult = intentResult and intentTemp
267 if intentTemp:
268 main.assertReturnString += 'Link Up Intent State Passed\n'
269 else:
270 main.assertReturnString += 'Link Up Intent State Failed\n'
271
272 # Checks ONOS state in link up
273 if linkUpResult and topoResult and pingResult and intentResult:
274 main.log.info( itemName + ": Successfully brought link back up" )
275 else:
276 main.log.error( itemName + ": Failed to bring link back up" )
277
278 # Remove all intents
279 removeIntentResult = removeAllIntents( main, intentsId )
280
281 if removeIntentResult:
282 main.assertReturnString += 'Remove Intents Passed'
283 else:
284 main.assertReturnString += 'Remove Intents Failed'
285
286 stepResult = pingResult and linkDownResult and linkUpResult \
287 and intentResult and removeIntentResult
288
289 return stepResult
290
Jon Hall314b74a2017-05-24 16:25:52 -0700291
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800292def pointIntent( main,
293 name,
294 host1,
295 host2,
296 onosNode=0,
297 deviceId1="",
298 deviceId2="",
299 port1="",
300 port2="",
301 ethType="",
302 mac1="",
303 mac2="",
304 bandwidth="",
305 lambdaAlloc=False,
306 ipProto="",
307 ip1="",
308 ip2="",
309 tcp1="",
310 tcp2="",
311 sw1="",
312 sw2="",
313 expectedLink=0 ):
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800314 """
315 Description:
316 Verify add-point-intent
317 Steps:
318 - Get device ids | ports
319 - Add point intents
320 - Check intents
321 - Verify flows
322 - Ping hosts
323 - Reroute
324 - Link down
325 - Verify flows
326 - Check topology
327 - Ping hosts
328 - Link up
329 - Verify flows
330 - Check topology
331 - Ping hosts
332 - Remove intents
333 Required:
334 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
335 host1 - Name of first host
336 host2 - Name of second host
337 Optional:
338 onosNode - ONOS node to install the intents in main.CLIs[ ]
339 0 by default so that it will always use the first
340 ONOS node
341 deviceId1 - ONOS device id of the first switch, the same as the
342 location of the first host eg. of:0000000000000001/1,
343 located at device 1 port 1
344 deviceId2 - ONOS device id of the second switch
345 port1 - The port number where the first host is attached
346 port2 - The port number where the second host is attached
347 ethType - Ethernet type eg. IPV4, IPV6
348 mac1 - Mac address of first host
349 mac2 - Mac address of the second host
350 bandwidth - Bandwidth capacity
351 lambdaAlloc - Allocate lambda, defaults to False
352 ipProto - IP protocol
353 ip1 - IP address of first host
354 ip2 - IP address of second host
355 tcp1 - TCP port of first host
356 tcp2 - TCP port of second host
357 sw1 - First switch to bring down & up for rerouting purpose
358 sw2 - Second switch to bring down & up for rerouting purpose
359 expectedLink - Expected link when the switches are down, it should
360 be two links lower than the links before the two
361 switches are down
362 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800363 assert main, "There is no main variable"
364 assert name, "variable name is empty"
365 assert host1 and host2, "You must specify hosts"
366
367 global itemName
368 itemName = name
369 host1 = host1
370 host2 = host2
371 hostNames = [ host1, host2 ]
372 intentsId = []
373
374 pingResult = main.TRUE
375 intentResult = main.TRUE
376 removeIntentResult = main.TRUE
377 flowResult = main.TRUE
378 topoResult = main.TRUE
379 linkDownResult = main.TRUE
380 linkUpResult = main.TRUE
381 onosNode = int( onosNode )
382
383 # Adding bidirectional point intents
384 main.log.info( itemName + ": Adding point intents" )
385 intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
Jon Hall314b74a2017-05-24 16:25:52 -0700386 egressDevice=deviceId2,
387 portIngress=port1,
388 portEgress=port2,
389 ethType=ethType,
390 ethSrc=mac1,
391 ethDst=mac2,
392 bandwidth=bandwidth,
393 lambdaAlloc=lambdaAlloc,
394 ipProto=ipProto,
395 ipSrc=ip1,
396 ipDst=ip2,
397 tcpSrc=tcp1,
398 tcpDst=tcp2 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800399
400 intentsId.append( intent1 )
401 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
Jon Hall314b74a2017-05-24 16:25:52 -0700402 egressDevice=deviceId1,
403 portIngress=port2,
404 portEgress=port1,
405 ethType=ethType,
406 ethSrc=mac2,
407 ethDst=mac1,
408 bandwidth=bandwidth,
409 lambdaAlloc=lambdaAlloc,
410 ipProto=ipProto,
411 ipSrc=ip2,
412 ipDst=ip1,
413 tcpSrc=tcp2,
414 tcpDst=tcp1 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800415 intentsId.append( intent2 )
416
417 # Check intents state
418 time.sleep( main.checkIntentSleep )
419 intentResult = checkIntentState( main, intentsId )
420 # Check flows count in each node
421 checkFlowsCount( main )
422
423 # Check intents state again if first check fails...
424 if not intentResult:
425 intentResult = checkIntentState( main, intentsId )
sathishmc4362252016-04-20 18:29:48 +0530426 if intentResult:
427 main.assertReturnString += 'Initial Intent State Passed\n'
428 else:
429 main.assertReturnString += 'Initial Intent State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800430
431 # Check flows count in each node
sathishmc4362252016-04-20 18:29:48 +0530432 FlowResult = checkFlowsCount( main )
433 if FlowResult:
434 main.assertReturnString += 'Initial Flow Count Passed\n'
435 else:
436 main.assertReturnString += 'Initial Flow Count Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800437 # Verify flows
sathishmc4362252016-04-20 18:29:48 +0530438 StateResult = checkFlowsState( main )
439 if StateResult:
440 main.assertReturnString += 'Initial Flow State Passed\n'
441 else:
442 main.assertReturnString += 'Initial Flow State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800443
444 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -0700445 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800446 pingResult = pingResult and pingTemp
447 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700448 main.assertReturnString += 'Initial Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800449 else:
Jon Hall439c8912016-04-15 02:22:03 -0700450 main.assertReturnString += 'Initial Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800451
452 # Test rerouting if these variables exist
453 if sw1 and sw2 and expectedLink:
454 # link down
455 linkDownResult = link( main, sw1, sw2, "down" )
456
457 if linkDownResult:
458 main.assertReturnString += 'Link Down Passed\n'
459 else:
460 main.assertReturnString += 'Link Down Failed\n'
461
462 # Check flows count in each node
463 checkFlowsCount( main )
464 # Verify flows
465 checkFlowsState( main )
466
467 # Check OnosTopology
468 topoResult = checkTopology( main, expectedLink )
469 if topoResult:
470 main.assertReturnString += 'Link Down Topology State Passed\n'
471 else:
472 main.assertReturnString += 'Link Down Topology State Failed\n'
473
474 # Ping hosts
Subhash Kumar Singh5ea4d302015-11-05 14:36:52 +0530475 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800476 pingResult = pingResult and pingTemp
477 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700478 main.assertReturnString += 'Link Down Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800479 else:
Jon Hall439c8912016-04-15 02:22:03 -0700480 main.assertReturnString += 'Link Down Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800481
482 # Check intent state
483 intentTemp = checkIntentState( main, intentsId )
484 intentResult = intentResult and intentTemp
485 if intentTemp:
486 main.assertReturnString += 'Link Down Intent State Passed\n'
487 else:
488 main.assertReturnString += 'Link Down Intent State Failed\n'
489
490 # Checks ONOS state in link down
491 if linkDownResult and topoResult and pingResult and intentResult:
492 main.log.info( itemName + ": Successfully brought link down" )
493 else:
494 main.log.error( itemName + ": Failed to bring link down" )
495
496 # link up
497 linkUpResult = link( main, sw1, sw2, "up" )
498 if linkUpResult:
499 main.assertReturnString += 'Link Up Passed\n'
500 else:
501 main.assertReturnString += 'Link Up Failed\n'
502
503 time.sleep( main.rerouteSleep )
504
505 # Check flows count in each node
506 checkFlowsCount( main )
507 # Verify flows
508 checkFlowsState( main )
509
510 # Check OnosTopology
511 topoResult = checkTopology( main, main.numLinks )
512 if topoResult:
513 main.assertReturnString += 'Link Up Topology State Passed\n'
514 else:
515 main.assertReturnString += 'Link Up Topology State Failed\n'
516
517 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -0700518 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800519 pingResult = pingResult and pingTemp
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800520 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700521 main.assertReturnString += 'Link Up Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800522 else:
Jon Hall439c8912016-04-15 02:22:03 -0700523 main.assertReturnString += 'Link Up Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800524
525 intentTemp = checkIntentState( main, intentsId )
526 intentResult = intentResult and intentTemp
527 if intentTemp:
528 main.assertReturnString += 'Link Up Intent State Passed\n'
529 else:
530 main.assertReturnString += 'Link Up Intent State Failed\n'
531
532 # Checks ONOS state in link up
533 if linkUpResult and topoResult and pingResult and intentResult:
534 main.log.info( itemName + ": Successfully brought link back up" )
535 else:
536 main.log.error( itemName + ": Failed to bring link back up" )
537
538 # Remove all intents
539 removeIntentResult = removeAllIntents( main, intentsId )
540 if removeIntentResult:
541 main.assertReturnString += 'Remove Intents Passed'
542 else:
543 main.assertReturnString += 'Remove Intents Failed'
544
545 stepResult = pingResult and linkDownResult and linkUpResult \
546 and intentResult and removeIntentResult
547
548 return stepResult
549
Jon Hall314b74a2017-05-24 16:25:52 -0700550
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800551def pointIntentTcp( main,
552 name,
553 host1,
554 host2,
555 onosNode=0,
556 deviceId1="",
557 deviceId2="",
558 port1="",
559 port2="",
560 ethType="",
561 mac1="",
562 mac2="",
563 bandwidth="",
564 lambdaAlloc=False,
565 ipProto="",
566 ip1="",
567 ip2="",
568 tcp1="",
569 tcp2="",
570 sw1="",
571 sw2="",
572 expectedLink=0 ):
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800573 """
574 Description:
575 Verify add-point-intent only for TCP
576 Steps:
577 - Get device ids | ports
578 - Add point intents
579 - Check intents
580 - Verify flows
581 - Ping hosts
582 - Reroute
583 - Link down
584 - Verify flows
585 - Check topology
586 - Ping hosts
587 - Link up
588 - Verify flows
589 - Check topology
590 - Ping hosts
591 - Remove intents
592 Required:
593 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
594 host1 - Name of first host
595 host2 - Name of second host
596 Optional:
597 onosNode - ONOS node to install the intents in main.CLIs[ ]
598 0 by default so that it will always use the first
599 ONOS node
600 deviceId1 - ONOS device id of the first switch, the same as the
601 location of the first host eg. of:0000000000000001/1,
602 located at device 1 port 1
603 deviceId2 - ONOS device id of the second switch
604 port1 - The port number where the first host is attached
605 port2 - The port number where the second host is attached
606 ethType - Ethernet type eg. IPV4, IPV6
607 mac1 - Mac address of first host
608 mac2 - Mac address of the second host
609 bandwidth - Bandwidth capacity
610 lambdaAlloc - Allocate lambda, defaults to False
611 ipProto - IP protocol
612 ip1 - IP address of first host
613 ip2 - IP address of second host
614 tcp1 - TCP port of first host
615 tcp2 - TCP port of second host
616 sw1 - First switch to bring down & up for rerouting purpose
617 sw2 - Second switch to bring down & up for rerouting purpose
618 expectedLink - Expected link when the switches are down, it should
619 be two links lower than the links before the two
620 switches are down
621 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800622 assert main, "There is no main variable"
623 assert name, "variable name is empty"
624 assert host1 and host2, "You must specify hosts"
625
626 global itemName
627 itemName = name
628 host1 = host1
629 host2 = host2
630 hostNames = [ host1, host2 ]
631 intentsId = []
632
633 iperfResult = main.TRUE
634 intentResult = main.TRUE
635 removeIntentResult = main.TRUE
636 flowResult = main.TRUE
637 topoResult = main.TRUE
638 linkDownResult = main.TRUE
639 linkUpResult = main.TRUE
640 onosNode = int( onosNode )
641
642 # Adding bidirectional point intents
643 main.log.info( itemName + ": Adding point intents" )
644 intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
645 egressDevice=deviceId2,
646 portIngress=port1,
647 portEgress=port2,
648 ethType=ethType,
649 ethSrc=mac1,
650 ethDst=mac2,
651 bandwidth=bandwidth,
652 lambdaAlloc=lambdaAlloc,
653 ipProto=ipProto,
654 ipSrc=ip1,
655 ipDst=ip2,
656 tcpSrc=tcp1,
657 tcpDst="" )
658
659 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
660 egressDevice=deviceId1,
661 portIngress=port2,
662 portEgress=port1,
663 ethType=ethType,
664 ethSrc=mac2,
665 ethDst=mac1,
666 bandwidth=bandwidth,
667 lambdaAlloc=lambdaAlloc,
668 ipProto=ipProto,
669 ipSrc=ip2,
670 ipDst=ip1,
671 tcpSrc=tcp2,
672 tcpDst="" )
673
674 intent3 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
675 egressDevice=deviceId2,
676 portIngress=port1,
677 portEgress=port2,
678 ethType=ethType,
679 ethSrc=mac1,
680 ethDst=mac2,
681 bandwidth=bandwidth,
682 lambdaAlloc=lambdaAlloc,
683 ipProto=ipProto,
684 ipSrc=ip1,
685 ipDst=ip2,
686 tcpSrc="",
687 tcpDst=tcp2 )
688
689 intent4 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
690 egressDevice=deviceId1,
691 portIngress=port2,
692 portEgress=port1,
693 ethType=ethType,
694 ethSrc=mac2,
695 ethDst=mac1,
696 bandwidth=bandwidth,
697 lambdaAlloc=lambdaAlloc,
698 ipProto=ipProto,
699 ipSrc=ip2,
700 ipDst=ip1,
701 tcpSrc="",
702 tcpDst=tcp1 )
703 intentsId.append( intent1 )
704 intentsId.append( intent2 )
705 intentsId.append( intent3 )
706 intentsId.append( intent4 )
707
708 # Check intents state
709 time.sleep( main.checkIntentSleep )
710 intentResult = checkIntentState( main, intentsId )
711 # Check flows count in each node
712 checkFlowsCount( main )
713
714 # Check intents state again if first check fails...
715 if not intentResult:
716 intentResult = checkIntentState( main, intentsId )
sathishmc4362252016-04-20 18:29:48 +0530717 if intentResult:
718 main.assertReturnString += 'Initial Intent State Passed\n'
719 else:
720 main.assertReturnString += 'Initial Intent State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800721
722 # Check flows count in each node
sathishmc4362252016-04-20 18:29:48 +0530723 FlowResult = checkFlowsCount( main )
724 if FlowResult:
725 main.assertReturnString += 'Initial Flow Count Passed\n'
726 else:
727 main.assertReturnString += 'Initial Flow Count Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800728 # Verify flows
sathishmc4362252016-04-20 18:29:48 +0530729 StateResult = checkFlowsState( main )
730 if StateResult:
731 main.assertReturnString += 'Initial Flow State Passed\n'
732 else:
733 main.assertReturnString += 'Initial Flow State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800734
sathishmc4362252016-04-20 18:29:48 +0530735 # Run iperf to both host
Jon Hall314b74a2017-05-24 16:25:52 -0700736 iperfTemp = main.Mininet1.iperftcpipv6( host1, host2 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800737 iperfResult = iperfResult and iperfTemp
738 if iperfTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700739 main.assertReturnString += 'Initial Iperf6 Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800740 else:
Jon Hall439c8912016-04-15 02:22:03 -0700741 main.assertReturnString += 'Initial Iperf6 Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800742
743 # Test rerouting if these variables exist
744 if sw1 and sw2 and expectedLink:
745 # link down
746 linkDownResult = link( main, sw1, sw2, "down" )
747
748 if linkDownResult:
749 main.assertReturnString += 'Link Down Passed\n'
750 else:
751 main.assertReturnString += 'Link Down Failed\n'
752
753 # Check flows count in each node
754 checkFlowsCount( main )
755 # Verify flows
756 checkFlowsState( main )
757
758 # Check OnosTopology
759 topoResult = checkTopology( main, expectedLink )
760 if topoResult:
761 main.assertReturnString += 'Link Down Topology State Passed\n'
762 else:
763 main.assertReturnString += 'Link Down Topology State Failed\n'
764
765 # Run iperf to both host
Jon Hall314b74a2017-05-24 16:25:52 -0700766 iperfTemp = main.Mininet1.iperftcpipv6( host1, host2 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800767 iperfResult = iperfResult and iperfTemp
768 if iperfTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700769 main.assertReturnString += 'Link Down Iperf6 Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800770 else:
Jon Hall439c8912016-04-15 02:22:03 -0700771 main.assertReturnString += 'Link Down Iperf6 Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800772
773 # Check intent state
774 intentTemp = checkIntentState( main, intentsId )
775 intentResult = intentResult and intentTemp
776 if intentTemp:
777 main.assertReturnString += 'Link Down Intent State Passed\n'
778 else:
779 main.assertReturnString += 'Link Down Intent State Failed\n'
780
781 # Checks ONOS state in link down
782 if linkDownResult and topoResult and iperfResult and intentResult:
783 main.log.info( itemName + ": Successfully brought link down" )
784 else:
785 main.log.error( itemName + ": Failed to bring link down" )
786
787 # link up
788 linkUpResult = link( main, sw1, sw2, "up" )
Jon Hall439c8912016-04-15 02:22:03 -0700789 if linkUpResult:
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800790 main.assertReturnString += 'Link Up Passed\n'
791 else:
792 main.assertReturnString += 'Link Up Failed\n'
793
794 time.sleep( main.rerouteSleep )
795
796 # Check flows count in each node
797 checkFlowsCount( main )
798 # Verify flows
799 checkFlowsState( main )
800
801 # Check OnosTopology
802 topoResult = checkTopology( main, main.numLinks )
803
804 if topoResult:
805 main.assertReturnString += 'Link Up Topology State Passed\n'
806 else:
807 main.assertReturnString += 'Link Up Topology State Failed\n'
808
809 # Run iperf to both host
Jon Hall314b74a2017-05-24 16:25:52 -0700810 iperfTemp = main.Mininet1.iperftcpipv6( host1, host2, timeout=10 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800811 iperfResult = iperfResult and iperfTemp
812 if iperfTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700813 main.assertReturnString += 'Link Up Iperf6 Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800814 else:
Jon Hall439c8912016-04-15 02:22:03 -0700815 main.assertReturnString += 'Link Up Iperf6 Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800816
817 # Check intent state
818 intentTemp = checkIntentState( main, intentsId )
819 intentResult = intentResult and intentTemp
820 if intentTemp:
821 main.assertReturnString += 'Link Down Intent State Passed\n'
822 else:
823 main.assertReturnString += 'Link Down Intent State Failed\n'
824
825 # Checks ONOS state in link up
826 if linkUpResult and topoResult and iperfResult and intentResult:
827 main.log.info( itemName + ": Successfully brought link back up" )
828 else:
829 main.log.error( itemName + ": Failed to bring link back up" )
830
831 # Remove all intents
832 removeIntentResult = removeAllIntents( main, intentsId )
833 if removeIntentResult:
834 main.assertReturnString += 'Remove Intents Passed'
835 else:
836 main.assertReturnString += 'Remove Intents Failed'
837
838 stepResult = iperfResult and linkDownResult and linkUpResult \
839 and intentResult and removeIntentResult
840
841 return stepResult
842
Jon Hall314b74a2017-05-24 16:25:52 -0700843
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800844def singleToMultiIntent( main,
845 name,
Jon Hall439c8912016-04-15 02:22:03 -0700846 hostNames="",
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800847 onosNode=0,
848 devices="",
Jon Hall439c8912016-04-15 02:22:03 -0700849 ports="",
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800850 ethType="",
Jon Hall439c8912016-04-15 02:22:03 -0700851 macs="",
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800852 bandwidth="",
853 lambdaAlloc=False,
854 ipProto="",
855 ipAddresses="",
856 tcp="",
857 sw1="",
858 sw2="",
859 expectedLink=0 ):
860 """
861 Verify Single to Multi Point intents
862 NOTE:If main.hostsData is not defined, variables data should be passed
863 in the same order index wise. All devices in the list should have the same
864 format, either all the devices have its port or it doesn't.
865 eg. hostName = [ 'h1', 'h2' ,.. ]
Jon Hall314b74a2017-05-24 16:25:52 -0700866 devices = [ 'of:0000000000000001', 'of:0000000000000002', ... ]
867 ports = [ '1', '1', .. ]
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800868 ...
869 Description:
870 Verify add-single-to-multi-intent iterates through the list of given
871 host | devices and add intents
872 Steps:
873 - Get device ids | ports
874 - Add single to multi point intents
875 - Check intents
876 - Verify flows
877 - Ping hosts
878 - Reroute
879 - Link down
880 - Verify flows
881 - Check topology
882 - Ping hosts
883 - Link up
884 - Verify flows
885 - Check topology
886 - Ping hosts
887 - Remove intents
888 Required:
889 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
890 hostNames - List of host names
891 Optional:
892 onosNode - ONOS node to install the intents in main.CLIs[ ]
893 0 by default so that it will always use the first
894 ONOS node
895 devices - List of device ids in the same order as the hosts
896 in hostNames
897 ports - List of port numbers in the same order as the device in
898 devices
899 ethType - Ethernet type eg. IPV4, IPV6
900 macs - List of hosts mac address in the same order as the hosts in
901 hostNames
902 bandwidth - Bandwidth capacity
903 lambdaAlloc - Allocate lambda, defaults to False
904 ipProto - IP protocol
905 ipAddresses - IP addresses of host in the same order as the hosts in
906 hostNames
907 tcp - TCP ports in the same order as the hosts in hostNames
908 sw1 - First switch to bring down & up for rerouting purpose
909 sw2 - Second switch to bring down & up for rerouting purpose
910 expectedLink - Expected link when the switches are down, it should
911 be two links lower than the links before the two
912 switches are down
913 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800914 assert main, "There is no main variable"
915 assert hostNames, "You must specify hosts"
916 assert devices or main.hostsData, "You must specify devices"
917
918 global itemName
919 itemName = name
920 tempHostsData = {}
921 intentsId = []
922 onosNode = int( onosNode )
923
924 macsDict = {}
925 ipDict = {}
926 if hostNames and devices:
927 if len( hostNames ) != len( devices ):
928 main.log.debug( "hosts and devices does not have the same length" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800929 return main.FALSE
930 if ports:
931 if len( ports ) != len( devices ):
932 main.log.error( "Ports and devices does " +
933 "not have the same length" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800934 return main.FALSE
935 else:
936 main.log.info( "Device Ports are not specified" )
937 if macs:
938 for i in range( len( devices ) ):
939 macsDict[ devices[ i ] ] = macs[ i ]
940
941 elif hostNames and not devices and main.hostsData:
942 devices = []
943 main.log.info( "singleToMultiIntent function is using main.hostsData" )
944 for host in hostNames:
Jon Hall314b74a2017-05-24 16:25:52 -0700945 devices.append( main.hostsData.get( host ).get( 'location' ) )
946 macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \
947 main.hostsData.get( host ).get( 'mac' )
948 ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \
949 main.hostsData.get( host ).get( 'ipAddresses' )
sathishmc4362252016-04-20 18:29:48 +0530950
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800951 pingResult = main.TRUE
952 intentResult = main.TRUE
953 removeIntentResult = main.TRUE
954 flowResult = main.TRUE
955 topoResult = main.TRUE
956 linkDownResult = main.TRUE
957 linkUpResult = main.TRUE
958
959 devicesCopy = copy.copy( devices )
960 if ports:
961 portsCopy = copy.copy( ports )
962 main.log.info( itemName + ": Adding single point to multi point intents" )
963
964 # Check flows count in each node
965 checkFlowsCount( main )
966
967 # Adding bidirectional point intents
968 for i in range( len( devices ) ):
969 ingressDevice = devicesCopy[ i ]
970 egressDeviceList = copy.copy( devicesCopy )
971 egressDeviceList.remove( ingressDevice )
972 if ports:
973 portIngress = portsCopy[ i ]
974 portEgressList = copy.copy( portsCopy )
975 del portEgressList[ i ]
976 else:
977 portIngress = ""
978 portEgressList = None
979 if not macsDict:
980 srcMac = ""
981 else:
982 srcMac = macsDict[ ingressDevice ]
Jon Hall314b74a2017-05-24 16:25:52 -0700983 if srcMac is None:
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800984 main.log.debug( "There is no MAC in device - " + ingressDevice )
985 srcMac = ""
986
987 intentsId.append(
988 main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
989 ingressDevice=ingressDevice,
990 egressDeviceList=egressDeviceList,
991 portIngress=portIngress,
992 portEgressList=portEgressList,
993 ethType=ethType,
994 ethSrc=srcMac,
995 bandwidth=bandwidth,
996 lambdaAlloc=lambdaAlloc,
997 ipProto=ipProto,
998 ipSrc="",
999 ipDst="",
1000 tcpSrc="",
1001 tcpDst="" ) )
1002
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001003 # Check intents state
1004 time.sleep( main.checkIntentSleep )
1005 intentResult = checkIntentState( main, intentsId )
1006
1007 # Check intents state again if first check fails...
1008 if not intentResult:
1009 intentResult = checkIntentState( main, intentsId )
sathishmc4362252016-04-20 18:29:48 +05301010 if intentResult:
1011 main.assertReturnString += 'Initial Intent State Passed\n'
1012 else:
1013 main.assertReturnString += 'Initial Intent State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001014
1015 # Check flows count in each node
sathishmc4362252016-04-20 18:29:48 +05301016 FlowResult = checkFlowsCount( main )
1017 if FlowResult:
1018 main.assertReturnString += 'Initial Flow Count Passed\n'
1019 else:
1020 main.assertReturnString += 'Initial Flow Count Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001021 # Verify flows
sathishmc4362252016-04-20 18:29:48 +05301022 StateResult = checkFlowsState( main )
1023 if StateResult:
1024 main.assertReturnString += 'Initial Flow State Passed\n'
1025 else:
1026 main.assertReturnString += 'Initial Flow State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001027
Jon Hall314b74a2017-05-24 16:25:52 -07001028 firstPingResult = main.Mininet1.ping6pair( SRC=hostNames[ 0 ], TARGET=main.hostsData[ hostNames[ 1 ] ][ 'ipAddresses' ][ 0 ] )
Jon Hall439c8912016-04-15 02:22:03 -07001029 if not firstPingResult:
1030 main.log.debug( "First ping failed, there must be" +
Jon Hall314b74a2017-05-24 16:25:52 -07001031 " something wrong with ONOS performance" )
Jon Hall439c8912016-04-15 02:22:03 -07001032
1033 # Ping hosts again...
1034 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001035 pingResult = pingResult and pingTemp
1036 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001037 main.assertReturnString += 'Initial Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001038 else:
Jon Hall439c8912016-04-15 02:22:03 -07001039 main.assertReturnString += 'Initial Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001040
1041 # Test rerouting if these variables exist
1042 if sw1 and sw2 and expectedLink:
1043 # link down
1044 linkDownResult = link( main, sw1, sw2, "down" )
1045
1046 if linkDownResult:
1047 main.assertReturnString += 'Link Down Passed\n'
1048 else:
1049 main.assertReturnString += 'Link Down Failed\n'
1050
1051 # Check flows count in each node
1052 checkFlowsCount( main )
1053 # Verify flows
1054 checkFlowsState( main )
1055
1056 # Check OnosTopology
1057 topoResult = checkTopology( main, expectedLink )
1058 if topoResult:
1059 main.assertReturnString += 'Link Down Topology State Passed\n'
1060 else:
1061 main.assertReturnString += 'Link Down Topology State Failed\n'
1062
1063 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -07001064 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001065 pingResult = pingResult and pingTemp
1066 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001067 main.assertReturnString += 'Link Down Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001068 else:
Jon Hall439c8912016-04-15 02:22:03 -07001069 main.assertReturnString += 'Link Down Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001070
1071 # Check intent state
1072 intentTemp = checkIntentState( main, intentsId )
1073 intentResult = intentResult and intentTemp
1074 if intentTemp:
1075 main.assertReturnString += 'Link Down Intent State Passed\n'
1076 else:
1077 main.assertReturnString += 'Link Down Intent State Failed\n'
1078
1079 # Checks ONOS state in link down
1080 if linkDownResult and topoResult and pingResult and intentResult:
1081 main.log.info( itemName + ": Successfully brought link down" )
1082 else:
1083 main.log.error( itemName + ": Failed to bring link down" )
1084
1085 # link up
1086 linkUpResult = link( main, sw1, sw2, "up" )
1087 if linkUpResult:
1088 main.assertReturnString += 'Link Up Passed\n'
1089 else:
1090 main.assertReturnString += 'Link Up Failed\n'
1091
1092 time.sleep( main.rerouteSleep )
1093
1094 # Check flows count in each node
1095 checkFlowsCount( main )
1096 # Verify flows
1097 checkFlowsState( main )
1098
1099 # Check OnosTopology
1100 topoResult = checkTopology( main, main.numLinks )
1101 if topoResult:
1102 main.assertReturnString += 'Link Up Topology State Passed\n'
1103 else:
1104 main.assertReturnString += 'Link Up Topology State Failed\n'
1105
1106 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -07001107 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001108 pingResult = pingResult and pingTemp
1109 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001110 main.assertReturnString += 'Link Up Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001111 else:
Jon Hall439c8912016-04-15 02:22:03 -07001112 main.assertReturnString += 'Link Up Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001113
1114 # Check Intents
1115 intentTemp = checkIntentState( main, intentsId )
1116 intentResult = intentResult and intentTemp
1117 if intentTemp:
1118 main.assertReturnString += 'Link Up Intent State Passed\n'
1119 else:
1120 main.assertReturnString += 'Link Up Intent State Failed\n'
1121
1122 # Checks ONOS state in link up
1123 if linkUpResult and topoResult and pingResult and intentResult:
1124 main.log.info( itemName + ": Successfully brought link back up" )
1125 else:
1126 main.log.error( itemName + ": Failed to bring link back up" )
1127
1128 # Remove all intents
1129 removeIntentResult = removeAllIntents( main, intentsId )
1130 if removeIntentResult:
1131 main.assertReturnString += 'Remove Intents Passed'
1132 else:
1133 main.assertReturnString += 'Remove Intents Failed'
1134
1135 stepResult = pingResult and linkDownResult and linkUpResult \
1136 and intentResult and removeIntentResult
1137
1138 return stepResult
1139
Jon Hall314b74a2017-05-24 16:25:52 -07001140
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001141def multiToSingleIntent( main,
1142 name,
Jon Hall439c8912016-04-15 02:22:03 -07001143 hostNames="",
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001144 onosNode=0,
1145 devices="",
Jon Hall439c8912016-04-15 02:22:03 -07001146 ports="",
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001147 ethType="",
Jon Hall439c8912016-04-15 02:22:03 -07001148 macs="",
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001149 bandwidth="",
1150 lambdaAlloc=False,
1151 ipProto="",
1152 ipAddresses="",
1153 tcp="",
1154 sw1="",
1155 sw2="",
1156 expectedLink=0 ):
1157 """
1158 Verify Single to Multi Point intents
1159 NOTE:If main.hostsData is not defined, variables data should be passed in the
1160 same order index wise. All devices in the list should have the same
1161 format, either all the devices have its port or it doesn't.
1162 eg. hostName = [ 'h1', 'h2' ,.. ]
Jon Hall314b74a2017-05-24 16:25:52 -07001163 devices = [ 'of:0000000000000001', 'of:0000000000000002', ... ]
1164 ports = [ '1', '1', .. ]
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001165 ...
1166 Description:
1167 Verify add-multi-to-single-intent
1168 Steps:
1169 - Get device ids | ports
1170 - Add multi to single point intents
1171 - Check intents
1172 - Verify flows
1173 - Ping hosts
1174 - Reroute
1175 - Link down
1176 - Verify flows
1177 - Check topology
1178 - Ping hosts
1179 - Link up
1180 - Verify flows
1181 - Check topology
1182 - Ping hosts
1183 - Remove intents
1184 Required:
1185 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
1186 hostNames - List of host names
1187 Optional:
1188 onosNode - ONOS node to install the intents in main.CLIs[ ]
1189 0 by default so that it will always use the first
1190 ONOS node
1191 devices - List of device ids in the same order as the hosts
1192 in hostNames
1193 ports - List of port numbers in the same order as the device in
1194 devices
1195 ethType - Ethernet type eg. IPV4, IPV6
1196 macs - List of hosts mac address in the same order as the hosts in
1197 hostNames
1198 bandwidth - Bandwidth capacity
1199 lambdaAlloc - Allocate lambda, defaults to False
1200 ipProto - IP protocol
1201 ipAddresses - IP addresses of host in the same order as the hosts in
1202 hostNames
1203 tcp - TCP ports in the same order as the hosts in hostNames
1204 sw1 - First switch to bring down & up for rerouting purpose
1205 sw2 - Second switch to bring down & up for rerouting purpose
1206 expectedLink - Expected link when the switches are down, it should
1207 be two links lower than the links before the two
1208 switches are down
sathishmc4362252016-04-20 18:29:48 +05301209 Note - Don't use more than 2 hosts for MultiToSingle Intent with no mac address option.
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001210 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001211 assert main, "There is no main variable"
1212 assert hostNames, "You must specify hosts"
1213 assert devices or main.hostsData, "You must specify devices"
1214
1215 global itemName
1216 itemName = name
1217 tempHostsData = {}
1218 intentsId = []
1219 onosNode = int( onosNode )
1220
1221 macsDict = {}
1222 ipDict = {}
1223 if hostNames and devices:
1224 if len( hostNames ) != len( devices ):
1225 main.log.debug( "hosts and devices does not have the same length" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001226 return main.FALSE
1227 if ports:
1228 if len( ports ) != len( devices ):
1229 main.log.error( "Ports and devices does " +
1230 "not have the same length" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001231 return main.FALSE
1232 else:
1233 main.log.info( "Device Ports are not specified" )
1234 if macs:
1235 for i in range( len( devices ) ):
1236 macsDict[ devices[ i ] ] = macs[ i ]
1237 elif hostNames and not devices and main.hostsData:
1238 devices = []
1239 main.log.info( "multiToSingleIntent function is using main.hostsData" )
1240 for host in hostNames:
Jon Hall314b74a2017-05-24 16:25:52 -07001241 devices.append( main.hostsData.get( host ).get( 'location' ) )
1242 macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \
1243 main.hostsData.get( host ).get( 'mac' )
1244 ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \
1245 main.hostsData.get( host ).get( 'ipAddresses' )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001246
1247 pingResult = main.TRUE
1248 intentResult = main.TRUE
1249 removeIntentResult = main.TRUE
1250 flowResult = main.TRUE
1251 topoResult = main.TRUE
1252 linkDownResult = main.TRUE
1253 linkUpResult = main.TRUE
1254
1255 devicesCopy = copy.copy( devices )
1256 if ports:
1257 portsCopy = copy.copy( ports )
1258 main.log.info( itemName + ": Adding multi point to single point intents" )
1259
1260 # Check flows count in each node
1261 checkFlowsCount( main )
1262
1263 # Adding bidirectional point intents
1264 for i in range( len( devices ) ):
1265 egressDevice = devicesCopy[ i ]
1266 ingressDeviceList = copy.copy( devicesCopy )
1267 ingressDeviceList.remove( egressDevice )
1268 if ports:
1269 portEgress = portsCopy[ i ]
1270 portIngressList = copy.copy( portsCopy )
1271 del portIngressList[ i ]
1272 else:
1273 portEgress = ""
1274 portIngressList = None
1275 if not macsDict:
1276 dstMac = ""
1277 else:
1278 dstMac = macsDict[ egressDevice ]
Jon Hall314b74a2017-05-24 16:25:52 -07001279 if dstMac is None:
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001280 main.log.debug( "There is no MAC in device - " + egressDevice )
1281 dstMac = ""
1282
1283 intentsId.append(
1284 main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
1285 ingressDeviceList=ingressDeviceList,
1286 egressDevice=egressDevice,
1287 portIngressList=portIngressList,
1288 portEgress=portEgress,
1289 ethType=ethType,
1290 ethDst=dstMac,
1291 bandwidth=bandwidth,
1292 lambdaAlloc=lambdaAlloc,
1293 ipProto=ipProto,
1294 ipSrc="",
1295 ipDst="",
1296 tcpSrc="",
1297 tcpDst="" ) )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001298 # Check intents state
1299 time.sleep( main.checkIntentSleep )
1300 intentResult = checkIntentState( main, intentsId )
1301
1302 # Check intents state again if first check fails...
1303 if not intentResult:
1304 intentResult = checkIntentState( main, intentsId )
sathishmc4362252016-04-20 18:29:48 +05301305 if intentResult:
1306 main.assertReturnString += 'Initial Intent State Passed\n'
1307 else:
1308 main.assertReturnString += 'Initial Intent State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001309
1310 # Check flows count in each node
sathishmc4362252016-04-20 18:29:48 +05301311 FlowResult = checkFlowsCount( main )
1312 if FlowResult:
1313 main.assertReturnString += 'Initial Flow Count Passed\n'
1314 else:
1315 main.assertReturnString += 'Initial Flow Count Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001316 # Verify flows
sathishmc4362252016-04-20 18:29:48 +05301317 StateResult = checkFlowsState( main )
1318 if StateResult:
1319 main.assertReturnString += 'Initial Flow State Passed\n'
1320 else:
1321 main.assertReturnString += 'Initial Flow State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001322
Jon Hall439c8912016-04-15 02:22:03 -07001323 # Ping hosts...
1324 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001325 pingResult = pingResult and pingTemp
1326 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001327 main.assertReturnString += 'Initial Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001328 else:
Jon Hall439c8912016-04-15 02:22:03 -07001329 main.assertReturnString += 'Initial Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001330
1331 # Test rerouting if these variables exist
1332 if sw1 and sw2 and expectedLink:
1333 # link down
1334 linkDownResult = link( main, sw1, sw2, "down" )
1335
1336 if linkDownResult:
1337 main.assertReturnString += 'Link Down Passed\n'
1338 else:
1339 main.assertReturnString += 'Link Down Failed\n'
1340
1341 # Check flows count in each node
1342 checkFlowsCount( main )
1343 # Verify flows
1344 checkFlowsState( main )
1345
1346 # Check OnosTopology
1347 topoResult = checkTopology( main, expectedLink )
1348 if topoResult:
1349 main.assertReturnString += 'Link Down Topology State Passed\n'
1350 else:
1351 main.assertReturnString += 'Link Down Topology State Failed\n'
1352
1353 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -07001354 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001355 pingResult = pingResult and pingTemp
1356 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001357 main.assertReturnString += 'Link Down Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001358 else:
Jon Hall439c8912016-04-15 02:22:03 -07001359 main.assertReturnString += 'Link Down Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001360
1361 # Check intent state
1362 intentTemp = checkIntentState( main, intentsId )
1363 intentResult = intentResult and intentTemp
1364 if intentTemp:
1365 main.assertReturnString += 'Link Down Intent State Passed\n'
1366 else:
1367 main.assertReturnString += 'Link Down Intent State Failed\n'
1368
1369 # Checks ONOS state in link down
1370 if linkDownResult and topoResult and pingResult and intentResult:
1371 main.log.info( itemName + ": Successfully brought link down" )
1372 else:
1373 main.log.error( itemName + ": Failed to bring link down" )
1374
1375 # link up
1376 linkUpResult = link( main, sw1, sw2, "up" )
1377 if linkUpResult:
1378 main.assertReturnString += 'Link Up Passed\n'
1379 else:
1380 main.assertReturnString += 'Link Up Failed\n'
1381
1382 time.sleep( main.rerouteSleep )
1383
1384 # Check flows count in each node
1385 checkFlowsCount( main )
1386 # Verify flows
1387 checkFlowsState( main )
1388
1389 # Check OnosTopology
1390 topoResult = checkTopology( main, main.numLinks )
1391 if topoResult:
1392 main.assertReturnString += 'Link Up Topology State Passed\n'
1393 else:
1394 main.assertReturnString += 'Link Up Topology State Failed\n'
1395
1396 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -07001397 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001398 pingResult = pingResult and pingTemp
1399 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001400 main.assertReturnString += 'Link Up Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001401 else:
Jon Hall439c8912016-04-15 02:22:03 -07001402 main.assertReturnString += 'Link Up Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001403
1404 # Check Intents
1405 intentTemp = checkIntentState( main, intentsId )
1406 intentResult = intentResult and intentTemp
1407 if intentTemp:
1408 main.assertReturnString += 'Link Up Intent State Passed\n'
1409 else:
1410 main.assertReturnString += 'Link Up Intent State Failed\n'
1411
1412 # Checks ONOS state in link up
1413 if linkUpResult and topoResult and pingResult and intentResult:
1414 main.log.info( itemName + ": Successfully brought link back up" )
1415 else:
1416 main.log.error( itemName + ": Failed to bring link back up" )
1417
1418 # Remove all intents
1419 removeIntentResult = removeAllIntents( main, intentsId )
1420 if removeIntentResult:
1421 main.assertReturnString += 'Remove Intents Passed'
1422 else:
1423 main.assertReturnString += 'Remove Intents Failed'
1424
1425 stepResult = pingResult and linkDownResult and linkUpResult \
1426 and intentResult and removeIntentResult
1427
1428 return stepResult
1429
Jon Hall314b74a2017-05-24 16:25:52 -07001430
sathishmc4362252016-04-20 18:29:48 +05301431def testEndPointFail( main,
1432 name,
1433 test="",
1434 hostNames="",
1435 devices="",
1436 macs="",
1437 ports="",
1438 onosNode=0,
1439 ethType="",
1440 bandwidth="",
1441 lambdaAlloc=False,
1442 ipProto="",
1443 ipAddresses="",
1444 tcp="",
1445 sw1="",
1446 sw2="",
1447 sw3="",
1448 sw4="",
1449 sw5="",
1450 expectedLink1=0,
1451 expectedLink2=0 ):
1452 """
1453 Test Multipoint Topology for Endpoint failures
1454 """
sathishmc4362252016-04-20 18:29:48 +05301455 assert main, "There is no main variable"
1456 assert hostNames, "You must specify hosts"
1457 assert devices or main.hostsData, "You must specify devices"
1458
1459 global itemName
1460 itemName = name
1461 tempHostsData = {}
1462 intentsId = []
1463 onosNode = int( onosNode )
1464
1465 macsDict = {}
1466 ipDict = {}
1467 if hostNames and devices:
1468 if len( hostNames ) != len( devices ):
1469 main.log.debug( "hosts and devices does not have the same length" )
1470 return main.FALSE
1471 if ports:
1472 if len( ports ) != len( devices ):
1473 main.log.error( "Ports and devices does " +
1474 "not have the same length" )
1475 return main.FALSE
1476 else:
1477 main.log.info( "Device Ports are not specified" )
1478 if macs:
1479 for i in range( len( devices ) ):
1480 macsDict[ devices[ i ] ] = macs[ i ]
1481 elif hostNames and not devices and main.hostsData:
1482 devices = []
1483 main.log.info( "multiIntent function is using main.hostsData" )
1484 for host in hostNames:
Jon Hall314b74a2017-05-24 16:25:52 -07001485 devices.append( main.hostsData.get( host ).get( 'location' ) )
1486 macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \
1487 main.hostsData.get( host ).get( 'mac' )
1488 ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \
1489 main.hostsData.get( host ).get( 'ipAddresses' )
sathishmc4362252016-04-20 18:29:48 +05301490
1491 pingResult = main.TRUE
1492 intentResult = main.TRUE
1493 removeIntentResult = main.TRUE
1494 flowResult = main.TRUE
1495 topoResult = main.TRUE
1496 linkDownResult = main.TRUE
1497 linkUpResult = main.TRUE
1498
1499 devicesCopy = copy.copy( devices )
1500 if ports:
1501 portsCopy = copy.copy( ports )
1502 main.log.info( itemName + ": Adding intents" )
1503
1504 # Check flows count in each node
1505 checkFlowsCount( main )
1506
Jon Hall314b74a2017-05-24 16:25:52 -07001507 if test == "MultipletoSingle":
sathishmc4362252016-04-20 18:29:48 +05301508 for i in range( len( devices ) ):
1509 egressDevice = devicesCopy[ i ]
1510 ingressDeviceList = copy.copy( devicesCopy )
1511 ingressDeviceList.remove( egressDevice )
1512 if ports:
1513 portEgress = portsCopy[ i ]
1514 portIngressList = copy.copy( portsCopy )
1515 del portIngressList[ i ]
1516 else:
1517 portEgress = ""
1518 portIngressList = None
1519 if not macsDict:
1520 dstMac = ""
1521 else:
1522 dstMac = macsDict[ egressDevice ]
Jon Hall314b74a2017-05-24 16:25:52 -07001523 if dstMac is None:
sathishmc4362252016-04-20 18:29:48 +05301524 main.log.debug( "There is no MAC in device - " + egressDevice )
1525 dstMac = ""
1526
1527 intentsId.append(
1528 main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
1529 ingressDeviceList=ingressDeviceList,
1530 egressDevice=egressDevice,
1531 portIngressList=portIngressList,
1532 portEgress=portEgress,
1533 ethType=ethType,
1534 ethDst=dstMac,
1535 bandwidth=bandwidth,
1536 lambdaAlloc=lambdaAlloc,
1537 ipProto=ipProto,
1538 ipSrc="",
1539 ipDst="",
1540 tcpSrc="",
1541 tcpDst="" ) )
1542
Jon Hall314b74a2017-05-24 16:25:52 -07001543 elif test == "SingletoMultiple":
sathishmc4362252016-04-20 18:29:48 +05301544 for i in range( len( devices ) ):
1545 ingressDevice = devicesCopy[ i ]
1546 egressDeviceList = copy.copy( devicesCopy )
1547 egressDeviceList.remove( ingressDevice )
1548 if ports:
1549 portIngress = portsCopy[ i ]
1550 portEgressList = copy.copy( portsCopy )
1551 del portEgressList[ i ]
1552 else:
1553 portIngress = ""
1554 portEgressList = None
1555 if not macsDict:
1556 srcMac = ""
1557 else:
1558 srcMac = macsDict[ ingressDevice ]
Jon Hall314b74a2017-05-24 16:25:52 -07001559 if srcMac is None:
sathishmc4362252016-04-20 18:29:48 +05301560 main.log.debug( "There is no MAC in device - " + ingressDevice )
1561 srcMac = ""
1562
1563 intentsId.append(
1564 main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
1565 ingressDevice=ingressDevice,
1566 egressDeviceList=egressDeviceList,
1567 portIngress=portIngress,
1568 portEgressList=portEgressList,
1569 ethType=ethType,
1570 ethSrc=srcMac,
1571 bandwidth=bandwidth,
1572 lambdaAlloc=lambdaAlloc,
1573 ipProto=ipProto,
1574 ipSrc="",
1575 ipDst="",
1576 tcpSrc="",
1577 tcpDst="" ) )
1578
1579 else:
Jon Hall314b74a2017-05-24 16:25:52 -07001580 main.log.info( "Invalid test Name - Type either SingletoMultiple or MultipletoSingle" )
sathishmc4362252016-04-20 18:29:48 +05301581 return main.FALSE
1582
1583 # Check intents state
1584 time.sleep( main.checkIntentSleep )
1585 intentResult = checkIntentState( main, intentsId )
1586
1587 # Check intents state again if first check fails...
1588 if not intentResult:
1589 intentResult = checkIntentState( main, intentsId )
1590 if intentResult:
1591 main.assertReturnString += 'Initial Intent State Passed\n'
1592 else:
1593 main.assertReturnString += 'Initial Intent State Failed\n'
1594
1595 # Check flows count in each node
1596 FlowResult = checkFlowsCount( main )
1597 if FlowResult:
1598 main.assertReturnString += 'Initial Flow Count Passed\n'
1599 else:
1600 main.assertReturnString += 'Initial Flow Count Failed\n'
1601 # Verify flows
1602 StateResult = checkFlowsState( main )
1603 if StateResult:
1604 main.assertReturnString += 'Initial Flow State Passed\n'
1605 else:
1606 main.assertReturnString += 'Initial Flow State Failed\n'
1607
1608 # Ping hosts...
1609 pingTemp = ping6allHosts( main, hostNames )
1610 pingResult = pingResult and pingTemp
1611 if pingTemp:
1612 main.assertReturnString += 'Initial Pingall Passed\n'
1613 else:
1614 main.assertReturnString += 'Initial Pingall Failed\n'
1615
1616 # Test rerouting if these variables exist
1617 if sw1 and sw2 and sw3 and sw4 and sw5 and expectedLink1 and expectedLink2:
Jon Hall314b74a2017-05-24 16:25:52 -07001618 # Take two links down
sathishmc4362252016-04-20 18:29:48 +05301619 # Take first link down
1620 linkDownResult1 = link( main, sw1, sw2, "down" )
1621 if linkDownResult1:
1622 main.assertReturnString += 'First Link Down Passed\n'
1623 else:
1624 main.assertReturnString += 'First Link Down Failed\n'
1625
1626 # Take second link down
1627 linkDownResult2 = link( main, sw3, sw4, "down" )
1628 if linkDownResult2:
1629 main.assertReturnString += 'Second Link Down Passed\n'
1630 else:
1631 main.assertReturnString += 'Second Link Down Failed\n'
1632
1633 # Check flows count in each node
1634 FlowResult = checkFlowsCount( main )
1635 if FlowResult:
1636 main.assertReturnString += 'Link Down Flow Count Passed\n'
1637 else:
1638 main.assertReturnString += 'Link Down Flow Count Failed\n'
1639 # Verify flows
1640 StateResult = checkFlowsState( main )
1641 if StateResult:
1642 main.assertReturnString += 'Link Down Flow State Passed\n'
1643 else:
1644 main.assertReturnString += 'Link Down Flow State Failed\n'
1645
1646 # Check OnosTopology
1647 topoResult = checkTopology( main, expectedLink1 )
1648 if topoResult:
1649 main.assertReturnString += 'Link Down Topology State Passed\n'
1650 else:
1651 main.assertReturnString += 'Link Down Topology State Failed\n'
1652
1653 # Ping hosts
1654 pingTemp = ping6allHosts( main, hostNames )
1655 pingResult = pingResult and pingTemp
1656 if pingTemp:
1657 main.assertReturnString += 'Link Down Ping6all Passed\n'
1658 else:
1659 main.assertReturnString += 'Link Down Ping6all Failed\n'
1660
1661 # Check intent state
1662 intentTemp = checkIntentState( main, intentsId )
1663 intentResult = intentResult and intentTemp
1664 if intentTemp:
1665 main.assertReturnString += 'Link Down Intent State Passed\n'
1666 else:
1667 main.assertReturnString += 'Link Down Intent State Failed\n'
1668
1669 # Take third link down to isolate the node
1670 linkDownResult3 = link( main, sw3, sw5, "down" )
1671 if linkDownResult3:
1672 main.assertReturnString += 'Isolation Third Link Down Passed\n'
1673 else:
1674 main.assertReturnString += 'Isolation Third Link Down Failed\n'
1675
1676 # Check flows count in each node
1677 FlowResult = checkFlowsCount( main )
1678 if FlowResult:
1679 main.assertReturnString += 'Isolation Link Down Flow Count Passed\n'
1680 else:
1681 main.assertReturnString += 'Isolation Link Down Flow Count Failed\n'
1682
1683 # Verify flows
1684 StateResult = checkFlowsState( main )
1685 if StateResult:
1686 main.assertReturnString += 'Isolation Link Down Flow State Passed\n'
1687 else:
1688 main.assertReturnString += 'Isolation Link Down Flow State Failed\n'
1689
1690 # Check OnosTopology
1691 topoResult = checkTopology( main, expectedLink2 )
1692 if topoResult:
1693 main.assertReturnString += 'Isolation Link Down Topology State Passed\n'
1694 else:
1695 main.assertReturnString += 'Isolation Link Down Topology State Failed\n'
1696
1697 # Ping hosts after isolation
Jon Hall314b74a2017-05-24 16:25:52 -07001698 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 +05301699 pingIsolation = ping6allHosts( main, hostNames )
1700 if pingIsolation:
1701 main.assertReturnString += 'Isolation Link Down Ping6all Passed\n'
1702 else:
1703 main.assertReturnString += 'Isolation Link Down Ping6all Failed\n'
1704
1705 # Check intent state after isolation
Jon Hall314b74a2017-05-24 16:25:52 -07001706 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 +05301707 intentIsolation = checkIntentState( main, intentsId )
1708 if intentIsolation:
1709 main.assertReturnString += 'Isolation Link Down Intent State Passed\n'
1710 else:
1711 main.assertReturnString += 'Isolation Link Down Intent State Failed\n'
1712
1713 linkDownResult = linkDownResult1 and linkDownResult2 and linkDownResult3
1714
1715 # Checks ONOS state in link down
1716 if linkDownResult and topoResult and pingResult and intentResult:
1717 main.log.info( itemName + ": Successfully brought link down" )
1718 else:
1719 main.log.error( itemName + ": Failed to bring link down" )
1720
1721 # Bring the links back up
1722 # Bring first link up
1723 linkUpResult1 = link( main, sw1, sw2, "up" )
1724 if linkUpResult1:
1725 main.assertReturnString += 'First Link Up Passed\n'
1726 else:
1727 main.assertReturnString += 'First Link Up Failed\n'
1728
1729 # Bring second link up
1730 linkUpResult2 = link( main, sw3, sw4, "up" )
1731 if linkUpResult2:
1732 main.assertReturnString += 'Second Link Up Passed\n'
1733 else:
1734 main.assertReturnString += 'Second Link Up Failed\n'
1735 # Bring third link up
1736 linkUpResult3 = link( main, sw3, sw5, "up" )
1737 if linkUpResult3:
1738 main.assertReturnString += 'Third Link Up Passed\n'
1739 else:
1740 main.assertReturnString += 'Third Link Up Failed\n'
1741
1742 linkUpResult = linkUpResult1 and linkUpResult2 and linkUpResult3
1743 time.sleep( main.rerouteSleep )
1744
1745 # Check flows count in each node
1746 FlowResult = checkFlowsCount( main )
1747 if FlowResult:
1748 main.assertReturnString += 'Link Up Flow Count Passed\n'
1749 else:
1750 main.assertReturnString += 'Link Up Flow Count Failed\n'
1751 # Verify flows
1752 StateResult = checkFlowsState( main )
1753 if StateResult:
1754 main.assertReturnString += 'Link Up Flow State Passed\n'
1755 else:
1756 main.assertReturnString += 'Link Up Flow State Failed\n'
1757
1758 # Check OnosTopology
1759 topoResult = checkTopology( main, main.numLinks )
1760 if topoResult:
1761 main.assertReturnString += 'Link Up Topology State Passed\n'
1762 else:
1763 main.assertReturnString += 'Link Up Topology State Failed\n'
1764
1765 # Ping hosts
1766 pingTemp = ping6allHosts( main, hostNames )
1767 pingResult = pingResult and pingTemp
1768 if pingTemp:
1769 main.assertReturnString += 'Link Up Pingall Passed\n'
1770 else:
1771 main.assertReturnString += 'Link Up Pingall Failed\n'
1772
1773 # Check Intents
1774 intentTemp = checkIntentState( main, intentsId )
1775 intentResult = intentResult and intentTemp
1776 if intentTemp:
1777 main.assertReturnString += 'Link Up Intent State Passed\n'
1778 else:
1779 main.assertReturnString += 'Link Up Intent State Failed\n'
1780
1781 # Checks ONOS state in link up
1782 if linkUpResult and topoResult and pingResult and intentResult:
1783 main.log.info( itemName + ": Successfully brought link back up" )
1784 else:
1785 main.log.error( itemName + ": Failed to bring link back up" )
1786
1787 # Remove all intents
1788 removeIntentResult = removeAllIntents( main, intentsId )
1789 if removeIntentResult:
1790 main.assertReturnString += 'Remove Intents Passed'
1791 else:
1792 main.assertReturnString += 'Remove Intents Failed'
1793
1794 testResult = pingResult and linkDownResult and linkUpResult \
1795 and intentResult and removeIntentResult
1796
1797 return testResult
1798
Jon Hall314b74a2017-05-24 16:25:52 -07001799
Subhash Kumar Singh5ea4d302015-11-05 14:36:52 +05301800def ping6allHosts( main, hostList ):
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001801 # Ping all host in the hosts list variable
1802 main.log.info( "Pinging: " + str( hostList ) )
Subhash Kumar Singh5ea4d302015-11-05 14:36:52 +05301803 return main.Mininet1.pingIpv6Hosts( hostList )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001804
Jon Hall314b74a2017-05-24 16:25:52 -07001805
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001806def getHostsData( main ):
1807 """
1808 Use fwd app and pingall to discover all the hosts
1809 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001810 activateResult = main.TRUE
1811 appCheck = main.TRUE
1812 getDataResult = main.TRUE
1813 main.log.info( "Activating reactive forwarding app " )
1814 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
Jon Hall314b74a2017-05-24 16:25:52 -07001815 main.CLIs[ 0 ].setCfg( "org.onosproject.provider.host.impl.HostLocationProvider", "useIpv6ND", "true" )
alisona2905c12016-09-19 15:18:07 -07001816 main.CLIs[ 0 ].setCfg( "org.onosproject.incubator.net.neighbour.impl.NeighbourResolutionManager", "ndpEnabled", "true" )
Jon Hall314b74a2017-05-24 16:25:52 -07001817 main.CLIs[ 0 ].setCfg( "org.onosproject.fwd.ReactiveForwarding", "ipv6Forwarding", "true" )
1818 main.CLIs[ 0 ].setCfg( "org.onosproject.fwd.ReactiveForwarding", "matchIpv6Address", "true" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001819 time.sleep( main.fwdSleep )
1820
1821 for i in range( main.numCtrls ):
1822 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
1823 if appCheck != main.TRUE:
1824 main.log.warn( main.CLIs[ i ].apps() )
1825 main.log.warn( main.CLIs[ i ].appIDs() )
1826
Jon Hall314b74a2017-05-24 16:25:52 -07001827 pingResult = main.Mininet1.pingall( protocol="IPv6", timeout=600 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001828 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
1829 hosts = main.Mininet1.getHosts().keys()
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001830 for host in hosts:
1831 main.hostsData[ host ] = {}
1832 main.hostsData[ host ][ 'mac' ] = \
1833 main.Mininet1.getMacAddress( host ).upper()
1834 for hostj in hostsJson:
1835 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
1836 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
1837 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
1838 main.hostsData[ host ][ 'location' ] = \
Jeremy Ronquillo0e538bc2017-06-13 15:16:09 -07001839 hostj[ 'locations' ][ 0 ][ 'elementId' ] + '/' + \
1840 hostj[ 'locations' ][ 0 ][ 'port' ]
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001841 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
1842
1843 main.log.info( "Deactivating reactive forwarding app " )
1844 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
1845 if activateResult and deactivateResult and main.hostsData:
1846 main.log.info( "Successfully used fwd app to discover hosts " )
1847 getDataResult = main.TRUE
1848 else:
1849 main.log.info( "Failed to use fwd app to discover hosts " )
1850 getDataResult = main.FALSE
1851
Jon Hall439c8912016-04-15 02:22:03 -07001852 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' " )
1853 for host in main.hostsData.keys():
Jon Hall314b74a2017-05-24 16:25:52 -07001854 if main.hostsData[ host ].get( 'ipAddresses' ) is not None:
1855 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 -08001856 print main.hostsData
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001857 return getDataResult
1858
Jon Hall314b74a2017-05-24 16:25:52 -07001859
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001860def checkTopology( main, expectedLink ):
1861 statusResult = main.TRUE
1862 # Check onos topology
1863 main.log.info( itemName + ": Checking ONOS topology " )
1864
1865 for i in range( main.numCtrls ):
Flavio Castro82ee2f62016-06-07 15:04:12 -07001866 statusResult = main.CLIs[ i ].checkStatus( main.numSwitch,
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001867 expectedLink )\
1868 and statusResult
1869 if not statusResult:
1870 main.log.error( itemName + ": Topology mismatch" )
1871 else:
1872 main.log.info( itemName + ": Topology match" )
1873 return statusResult
1874
Jon Hall314b74a2017-05-24 16:25:52 -07001875
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001876def checkIntentState( main, intentsId ):
1877 """
1878 This function will check intent state to make sure all the intents
1879 are in INSTALLED state
1880 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001881 intentResult = main.TRUE
1882 results = []
1883
1884 main.log.info( itemName + ": Checking intents state" )
1885 # First check of intents
1886 for i in range( main.numCtrls ):
1887 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
1888 results.append( tempResult )
1889
1890 expectedState = [ 'INSTALLED', 'INSTALLING' ]
1891
1892 if all( result == main.TRUE for result in results ):
1893 main.log.info( itemName + ": Intents are installed correctly" )
1894 else:
1895 # Wait for at least 5 second before checking the intents again
1896 main.log.error( "Intents are not installed correctly. Waiting 5 sec" )
1897 time.sleep( 5 )
1898 results = []
1899 # Second check of intents since some of the intents may be in
1900 # INSTALLING state, they should be in INSTALLED at this time
1901 for i in range( main.numCtrls ):
1902 tempResult = main.CLIs[ i ].checkIntentState(
1903 intentsId=intentsId )
1904 results.append( tempResult )
1905 if all( result == main.TRUE for result in results ):
1906 main.log.info( itemName + ": Intents are installed correctly" )
1907 intentResult = main.TRUE
1908 else:
1909 main.log.error( itemName + ": Intents are NOT installed correctly" )
1910 intentResult = main.FALSE
1911
1912 return intentResult
1913
Jon Hall314b74a2017-05-24 16:25:52 -07001914
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001915def checkFlowsState( main ):
1916
1917 main.log.info( itemName + ": Check flows state" )
1918 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState()
1919 return checkFlowsResult
1920
Jon Hall314b74a2017-05-24 16:25:52 -07001921
1922def link( main, sw1, sw2, option ):
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001923
1924 # link down
1925 main.log.info( itemName + ": Bring link " + option + "between " +
1926 sw1 + " and " + sw2 )
1927 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
1928 return linkResult
1929
Jon Hall314b74a2017-05-24 16:25:52 -07001930
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001931def removeAllIntents( main, intentsId ):
1932 """
1933 Remove all intents in the intentsId
1934 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001935 onosSummary = []
1936 removeIntentResult = main.TRUE
1937 # Remove intents
1938 for intent in intentsId:
1939 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
1940
1941 time.sleep( main.removeIntentSleep )
1942
1943 # If there is remianing intents then remove intents should fail
1944 for i in range( main.numCtrls ):
1945 onosSummary.append( json.loads( main.CLIs[ i ].summary() ) )
1946
1947 for summary in onosSummary:
1948 if summary.get( 'intents' ) != 0:
1949 main.log.warn( itemName + ": There are " +
1950 str( summary.get( 'intents' ) ) +
1951 " intents remaining in node " +
1952 str( summary.get( 'node' ) ) +
1953 ", failed to remove all the intents " )
1954 removeIntentResult = main.FALSE
1955
1956 if removeIntentResult:
1957 main.log.info( itemName + ": There are no more intents remaining, " +
1958 "successfully removed all the intents." )
1959
1960 return removeIntentResult
1961
Jon Hall314b74a2017-05-24 16:25:52 -07001962
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001963def checkFlowsCount( main ):
1964 """
1965 Check flows count in each node
1966 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001967 flowsCount = []
1968 main.log.info( itemName + ": Checking flows count in each ONOS node" )
1969 for i in range( main.numCtrls ):
1970 summaryResult = main.CLIs[ i ].summary()
1971 if not summaryResult:
1972 main.log.error( itemName + ": There is something wrong with " +
1973 "summary command" )
1974 return main.FALSE
1975 else:
1976 summaryJson = json.loads( summaryResult )
1977 flowsCount.append( summaryJson.get( 'flows' ) )
1978
1979 if flowsCount:
Jon Hall314b74a2017-05-24 16:25:52 -07001980 if all( flows == flowsCount[ 0 ] for flows in flowsCount ):
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001981 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
1982 " flows in all ONOS node" )
1983 else:
1984 for i in range( main.numCtrls ):
1985 main.log.debug( itemName + ": ONOS node " + str( i ) + " has " +
1986 str( flowsCount[ i ] ) + " flows" )
1987 else:
1988 main.log.error( "Checking flows count failed, check summary command" )
1989 return main.FALSE
1990
1991 return main.TRUE
1992
Jon Hall314b74a2017-05-24 16:25:52 -07001993
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001994def checkLeaderChange( leaders1, leaders2 ):
1995 """
1996 Checks for a change in intent partition leadership.
1997
1998 Takes the output of leaders -c in json string format before and after
1999 a potential change as input
2000
2001 Returns main.TRUE if no mismatches are detected
2002 Returns main.FALSE if there is a mismatch or on error loading the input
2003 """
2004 try:
2005 leaders1 = json.loads( leaders1 )
2006 leaders2 = json.loads( leaders2 )
Jon Hall314b74a2017-05-24 16:25:52 -07002007 except ( AttributeError, TypeError ):
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08002008 main.log.exception( self.name + ": Object not as expected" )
2009 return main.FALSE
2010 except Exception:
2011 main.log.exception( self.name + ": Uncaught exception!" )
2012 main.cleanup()
2013 main.exit()
2014 main.log.info( "Checking Intent Paritions for Change in Leadership" )
2015 mismatch = False
2016 for dict1 in leaders1:
2017 if "intent" in dict1.get( "topic", [] ):
2018 for dict2 in leaders2:
2019 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \
Jon Hall314b74a2017-05-24 16:25:52 -07002020 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08002021 mismatch = True
Jon Hall314b74a2017-05-24 16:25:52 -07002022 main.log.error( "{0} changed leader from {1} to {2}".
2023 format( dict1.get( "topic", "no-topic" ),
2024 dict1.get( "leader", "no-leader" ),
2025 dict2.get( "leader", "no-leader" ) ) )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08002026 if mismatch:
2027 return main.FALSE
2028 else:
2029 return main.TRUE
2030
Jon Hall314b74a2017-05-24 16:25:52 -07002031
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08002032def report( main ):
2033 """
2034 Report errors/warnings/exceptions
2035 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08002036 main.ONOSbench.logReport( main.ONOSip[ 0 ],
2037 [ "INFO",
2038 "FOLLOWER",
2039 "WARN",
2040 "flow",
2041 "ERROR",
2042 "Except" ],
2043 "s" )
2044
2045 main.log.info( "ERROR report: \n" )
2046 for i in range( main.numCtrls ):
2047 main.ONOSbench.logReport( main.ONOSip[ i ],
Jon Hall314b74a2017-05-24 16:25:52 -07002048 [ "ERROR" ],
2049 "d" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08002050
2051 main.log.info( "EXCEPTIONS report: \n" )
2052 for i in range( main.numCtrls ):
2053 main.ONOSbench.logReport( main.ONOSip[ i ],
Jon Hall314b74a2017-05-24 16:25:52 -07002054 [ "Except" ],
2055 "d" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08002056
2057 main.log.info( "WARNING report: \n" )
2058 for i in range( main.numCtrls ):
2059 main.ONOSbench.logReport( main.ONOSip[ i ],
Jon Hall314b74a2017-05-24 16:25:52 -07002060 [ "WARN" ],
2061 "d" )