blob: afe882946c53e760bf7d9d02048ec519bb5ce6c4 [file] [log] [blame]
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2015 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003
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
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070011 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070012
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" )
Devin Lim142b5342017-07-20 15:22:39 -0700145 intent1 = main.Cluster.active( onosNode ).CLI.addHostIntent( hostIdOne=h1Id,
146 hostIdTwo=h2Id )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800147 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" )
Devin Lim142b5342017-07-20 15:22:39 -0700385 intent1 = main.Cluster.active( onosNode ).CLI.addPointIntent( ingressDevice=deviceId1,
386 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 )
Devin Lim142b5342017-07-20 15:22:39 -0700401 intent2 = main.Cluster.active( onosNode ).CLI.addPointIntent( ingressDevice=deviceId2,
402 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
Devin Lim142b5342017-07-20 15:22:39 -0700643 ctrl = main.Cluster.active( onosNode )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800644 main.log.info( itemName + ": Adding point intents" )
Devin Lim142b5342017-07-20 15:22:39 -0700645 intent1 = ctrl.CLI.addPointIntent( ingressDevice=deviceId1,
646 egressDevice=deviceId2,
647 portIngress=port1,
648 portEgress=port2,
649 ethType=ethType,
650 ethSrc=mac1,
651 ethDst=mac2,
652 bandwidth=bandwidth,
653 lambdaAlloc=lambdaAlloc,
654 ipProto=ipProto,
655 ipSrc=ip1,
656 ipDst=ip2,
657 tcpSrc=tcp1,
658 tcpDst="" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800659
Devin Lim142b5342017-07-20 15:22:39 -0700660 intent2 = ctrl.CLI.addPointIntent( ingressDevice=deviceId2,
661 egressDevice=deviceId1,
662 portIngress=port2,
663 portEgress=port1,
664 ethType=ethType,
665 ethSrc=mac2,
666 ethDst=mac1,
667 bandwidth=bandwidth,
668 lambdaAlloc=lambdaAlloc,
669 ipProto=ipProto,
670 ipSrc=ip2,
671 ipDst=ip1,
672 tcpSrc=tcp2,
673 tcpDst="" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800674
Devin Lim142b5342017-07-20 15:22:39 -0700675 intent3 = ctrl.CLI.addPointIntent( ingressDevice=deviceId1,
676 egressDevice=deviceId2,
677 portIngress=port1,
678 portEgress=port2,
679 ethType=ethType,
680 ethSrc=mac1,
681 ethDst=mac2,
682 bandwidth=bandwidth,
683 lambdaAlloc=lambdaAlloc,
684 ipProto=ipProto,
685 ipSrc=ip1,
686 ipDst=ip2,
687 tcpSrc="",
688 tcpDst=tcp2 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800689
Devin Lim142b5342017-07-20 15:22:39 -0700690 intent4 = ctrl.CLI.addPointIntent( ingressDevice=deviceId2,
691 egressDevice=deviceId1,
692 portIngress=port2,
693 portEgress=port1,
694 ethType=ethType,
695 ethSrc=mac2,
696 ethDst=mac1,
697 bandwidth=bandwidth,
698 lambdaAlloc=lambdaAlloc,
699 ipProto=ipProto,
700 ipSrc=ip2,
701 ipDst=ip1,
702 tcpSrc="",
703 tcpDst=tcp1 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800704 intentsId.append( intent1 )
705 intentsId.append( intent2 )
706 intentsId.append( intent3 )
707 intentsId.append( intent4 )
708
709 # Check intents state
710 time.sleep( main.checkIntentSleep )
711 intentResult = checkIntentState( main, intentsId )
712 # Check flows count in each node
713 checkFlowsCount( main )
714
715 # Check intents state again if first check fails...
716 if not intentResult:
717 intentResult = checkIntentState( main, intentsId )
sathishmc4362252016-04-20 18:29:48 +0530718 if intentResult:
719 main.assertReturnString += 'Initial Intent State Passed\n'
720 else:
721 main.assertReturnString += 'Initial Intent State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800722
723 # Check flows count in each node
sathishmc4362252016-04-20 18:29:48 +0530724 FlowResult = checkFlowsCount( main )
725 if FlowResult:
726 main.assertReturnString += 'Initial Flow Count Passed\n'
727 else:
728 main.assertReturnString += 'Initial Flow Count Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800729 # Verify flows
sathishmc4362252016-04-20 18:29:48 +0530730 StateResult = checkFlowsState( main )
731 if StateResult:
732 main.assertReturnString += 'Initial Flow State Passed\n'
733 else:
734 main.assertReturnString += 'Initial Flow State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800735
sathishmc4362252016-04-20 18:29:48 +0530736 # Run iperf to both host
Jon Hall314b74a2017-05-24 16:25:52 -0700737 iperfTemp = main.Mininet1.iperftcpipv6( host1, host2 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800738 iperfResult = iperfResult and iperfTemp
739 if iperfTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700740 main.assertReturnString += 'Initial Iperf6 Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800741 else:
Jon Hall439c8912016-04-15 02:22:03 -0700742 main.assertReturnString += 'Initial Iperf6 Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800743
744 # Test rerouting if these variables exist
745 if sw1 and sw2 and expectedLink:
746 # link down
747 linkDownResult = link( main, sw1, sw2, "down" )
748
749 if linkDownResult:
750 main.assertReturnString += 'Link Down Passed\n'
751 else:
752 main.assertReturnString += 'Link Down Failed\n'
753
754 # Check flows count in each node
755 checkFlowsCount( main )
756 # Verify flows
757 checkFlowsState( main )
758
759 # Check OnosTopology
760 topoResult = checkTopology( main, expectedLink )
761 if topoResult:
762 main.assertReturnString += 'Link Down Topology State Passed\n'
763 else:
764 main.assertReturnString += 'Link Down Topology State Failed\n'
765
766 # Run iperf to both host
Jon Hall314b74a2017-05-24 16:25:52 -0700767 iperfTemp = main.Mininet1.iperftcpipv6( host1, host2 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800768 iperfResult = iperfResult and iperfTemp
769 if iperfTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700770 main.assertReturnString += 'Link Down Iperf6 Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800771 else:
Jon Hall439c8912016-04-15 02:22:03 -0700772 main.assertReturnString += 'Link Down Iperf6 Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800773
774 # Check intent state
775 intentTemp = checkIntentState( main, intentsId )
776 intentResult = intentResult and intentTemp
777 if intentTemp:
778 main.assertReturnString += 'Link Down Intent State Passed\n'
779 else:
780 main.assertReturnString += 'Link Down Intent State Failed\n'
781
782 # Checks ONOS state in link down
783 if linkDownResult and topoResult and iperfResult and intentResult:
784 main.log.info( itemName + ": Successfully brought link down" )
785 else:
786 main.log.error( itemName + ": Failed to bring link down" )
787
788 # link up
789 linkUpResult = link( main, sw1, sw2, "up" )
Jon Hall439c8912016-04-15 02:22:03 -0700790 if linkUpResult:
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800791 main.assertReturnString += 'Link Up Passed\n'
792 else:
793 main.assertReturnString += 'Link Up Failed\n'
794
795 time.sleep( main.rerouteSleep )
796
797 # Check flows count in each node
798 checkFlowsCount( main )
799 # Verify flows
800 checkFlowsState( main )
801
802 # Check OnosTopology
803 topoResult = checkTopology( main, main.numLinks )
804
805 if topoResult:
806 main.assertReturnString += 'Link Up Topology State Passed\n'
807 else:
808 main.assertReturnString += 'Link Up Topology State Failed\n'
809
810 # Run iperf to both host
Jon Hall314b74a2017-05-24 16:25:52 -0700811 iperfTemp = main.Mininet1.iperftcpipv6( host1, host2, timeout=10 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800812 iperfResult = iperfResult and iperfTemp
813 if iperfTemp:
Jon Hall439c8912016-04-15 02:22:03 -0700814 main.assertReturnString += 'Link Up Iperf6 Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800815 else:
Jon Hall439c8912016-04-15 02:22:03 -0700816 main.assertReturnString += 'Link Up Iperf6 Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800817
818 # Check intent state
819 intentTemp = checkIntentState( main, intentsId )
820 intentResult = intentResult and intentTemp
821 if intentTemp:
822 main.assertReturnString += 'Link Down Intent State Passed\n'
823 else:
824 main.assertReturnString += 'Link Down Intent State Failed\n'
825
826 # Checks ONOS state in link up
827 if linkUpResult and topoResult and iperfResult and intentResult:
828 main.log.info( itemName + ": Successfully brought link back up" )
829 else:
830 main.log.error( itemName + ": Failed to bring link back up" )
831
832 # Remove all intents
833 removeIntentResult = removeAllIntents( main, intentsId )
834 if removeIntentResult:
835 main.assertReturnString += 'Remove Intents Passed'
836 else:
837 main.assertReturnString += 'Remove Intents Failed'
838
839 stepResult = iperfResult and linkDownResult and linkUpResult \
840 and intentResult and removeIntentResult
841
842 return stepResult
843
Jon Hall314b74a2017-05-24 16:25:52 -0700844
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800845def singleToMultiIntent( main,
846 name,
Jon Hall439c8912016-04-15 02:22:03 -0700847 hostNames="",
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800848 onosNode=0,
849 devices="",
Jon Hall439c8912016-04-15 02:22:03 -0700850 ports="",
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800851 ethType="",
Jon Hall439c8912016-04-15 02:22:03 -0700852 macs="",
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800853 bandwidth="",
854 lambdaAlloc=False,
855 ipProto="",
856 ipAddresses="",
857 tcp="",
858 sw1="",
859 sw2="",
860 expectedLink=0 ):
861 """
862 Verify Single to Multi Point intents
863 NOTE:If main.hostsData is not defined, variables data should be passed
864 in the same order index wise. All devices in the list should have the same
865 format, either all the devices have its port or it doesn't.
866 eg. hostName = [ 'h1', 'h2' ,.. ]
Jon Hall314b74a2017-05-24 16:25:52 -0700867 devices = [ 'of:0000000000000001', 'of:0000000000000002', ... ]
868 ports = [ '1', '1', .. ]
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800869 ...
870 Description:
871 Verify add-single-to-multi-intent iterates through the list of given
872 host | devices and add intents
873 Steps:
874 - Get device ids | ports
875 - Add single to multi point intents
876 - Check intents
877 - Verify flows
878 - Ping hosts
879 - Reroute
880 - Link down
881 - Verify flows
882 - Check topology
883 - Ping hosts
884 - Link up
885 - Verify flows
886 - Check topology
887 - Ping hosts
888 - Remove intents
889 Required:
890 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
891 hostNames - List of host names
892 Optional:
893 onosNode - ONOS node to install the intents in main.CLIs[ ]
894 0 by default so that it will always use the first
895 ONOS node
896 devices - List of device ids in the same order as the hosts
897 in hostNames
898 ports - List of port numbers in the same order as the device in
899 devices
900 ethType - Ethernet type eg. IPV4, IPV6
901 macs - List of hosts mac address in the same order as the hosts in
902 hostNames
903 bandwidth - Bandwidth capacity
904 lambdaAlloc - Allocate lambda, defaults to False
905 ipProto - IP protocol
906 ipAddresses - IP addresses of host in the same order as the hosts in
907 hostNames
908 tcp - TCP ports in the same order as the hosts in hostNames
909 sw1 - First switch to bring down & up for rerouting purpose
910 sw2 - Second switch to bring down & up for rerouting purpose
911 expectedLink - Expected link when the switches are down, it should
912 be two links lower than the links before the two
913 switches are down
914 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800915 assert main, "There is no main variable"
916 assert hostNames, "You must specify hosts"
917 assert devices or main.hostsData, "You must specify devices"
918
919 global itemName
920 itemName = name
921 tempHostsData = {}
922 intentsId = []
923 onosNode = int( onosNode )
924
925 macsDict = {}
926 ipDict = {}
927 if hostNames and devices:
928 if len( hostNames ) != len( devices ):
929 main.log.debug( "hosts and devices does not have the same length" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800930 return main.FALSE
931 if ports:
932 if len( ports ) != len( devices ):
933 main.log.error( "Ports and devices does " +
934 "not have the same length" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800935 return main.FALSE
936 else:
937 main.log.info( "Device Ports are not specified" )
938 if macs:
939 for i in range( len( devices ) ):
940 macsDict[ devices[ i ] ] = macs[ i ]
941
942 elif hostNames and not devices and main.hostsData:
943 devices = []
944 main.log.info( "singleToMultiIntent function is using main.hostsData" )
945 for host in hostNames:
Jon Hall314b74a2017-05-24 16:25:52 -0700946 devices.append( main.hostsData.get( host ).get( 'location' ) )
947 macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \
948 main.hostsData.get( host ).get( 'mac' )
949 ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \
950 main.hostsData.get( host ).get( 'ipAddresses' )
sathishmc4362252016-04-20 18:29:48 +0530951
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800952 pingResult = main.TRUE
953 intentResult = main.TRUE
954 removeIntentResult = main.TRUE
955 flowResult = main.TRUE
956 topoResult = main.TRUE
957 linkDownResult = main.TRUE
958 linkUpResult = main.TRUE
959
960 devicesCopy = copy.copy( devices )
961 if ports:
962 portsCopy = copy.copy( ports )
963 main.log.info( itemName + ": Adding single point to multi point intents" )
964
965 # Check flows count in each node
966 checkFlowsCount( main )
967
968 # Adding bidirectional point intents
969 for i in range( len( devices ) ):
970 ingressDevice = devicesCopy[ i ]
971 egressDeviceList = copy.copy( devicesCopy )
972 egressDeviceList.remove( ingressDevice )
973 if ports:
974 portIngress = portsCopy[ i ]
975 portEgressList = copy.copy( portsCopy )
976 del portEgressList[ i ]
977 else:
978 portIngress = ""
979 portEgressList = None
980 if not macsDict:
981 srcMac = ""
982 else:
983 srcMac = macsDict[ ingressDevice ]
Jon Hall314b74a2017-05-24 16:25:52 -0700984 if srcMac is None:
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -0800985 main.log.debug( "There is no MAC in device - " + ingressDevice )
986 srcMac = ""
987
988 intentsId.append(
Devin Lim142b5342017-07-20 15:22:39 -0700989 main.Cluster.active( onosNode ).CLI.addSinglepointToMultipointIntent(
990 ingressDevice=ingressDevice,
991 egressDeviceList=egressDeviceList,
992 portIngress=portIngress,
993 portEgressList=portEgressList,
994 ethType=ethType,
995 ethSrc=srcMac,
996 bandwidth=bandwidth,
997 lambdaAlloc=lambdaAlloc,
998 ipProto=ipProto,
999 ipSrc="",
1000 ipDst="",
1001 tcpSrc="",
1002 tcpDst="" ) )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001003
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001004 # Check intents state
1005 time.sleep( main.checkIntentSleep )
1006 intentResult = checkIntentState( main, intentsId )
1007
1008 # Check intents state again if first check fails...
1009 if not intentResult:
1010 intentResult = checkIntentState( main, intentsId )
sathishmc4362252016-04-20 18:29:48 +05301011 if intentResult:
1012 main.assertReturnString += 'Initial Intent State Passed\n'
1013 else:
1014 main.assertReturnString += 'Initial Intent State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001015
1016 # Check flows count in each node
sathishmc4362252016-04-20 18:29:48 +05301017 FlowResult = checkFlowsCount( main )
1018 if FlowResult:
1019 main.assertReturnString += 'Initial Flow Count Passed\n'
1020 else:
1021 main.assertReturnString += 'Initial Flow Count Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001022 # Verify flows
sathishmc4362252016-04-20 18:29:48 +05301023 StateResult = checkFlowsState( main )
1024 if StateResult:
1025 main.assertReturnString += 'Initial Flow State Passed\n'
1026 else:
1027 main.assertReturnString += 'Initial Flow State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001028
Jon Hall314b74a2017-05-24 16:25:52 -07001029 firstPingResult = main.Mininet1.ping6pair( SRC=hostNames[ 0 ], TARGET=main.hostsData[ hostNames[ 1 ] ][ 'ipAddresses' ][ 0 ] )
Jon Hall439c8912016-04-15 02:22:03 -07001030 if not firstPingResult:
1031 main.log.debug( "First ping failed, there must be" +
Jon Hall314b74a2017-05-24 16:25:52 -07001032 " something wrong with ONOS performance" )
Jon Hall439c8912016-04-15 02:22:03 -07001033
1034 # Ping hosts again...
1035 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001036 pingResult = pingResult and pingTemp
1037 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001038 main.assertReturnString += 'Initial Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001039 else:
Jon Hall439c8912016-04-15 02:22:03 -07001040 main.assertReturnString += 'Initial Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001041
1042 # Test rerouting if these variables exist
1043 if sw1 and sw2 and expectedLink:
1044 # link down
1045 linkDownResult = link( main, sw1, sw2, "down" )
1046
1047 if linkDownResult:
1048 main.assertReturnString += 'Link Down Passed\n'
1049 else:
1050 main.assertReturnString += 'Link Down Failed\n'
1051
1052 # Check flows count in each node
1053 checkFlowsCount( main )
1054 # Verify flows
1055 checkFlowsState( main )
1056
1057 # Check OnosTopology
1058 topoResult = checkTopology( main, expectedLink )
1059 if topoResult:
1060 main.assertReturnString += 'Link Down Topology State Passed\n'
1061 else:
1062 main.assertReturnString += 'Link Down Topology State Failed\n'
1063
1064 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -07001065 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001066 pingResult = pingResult and pingTemp
1067 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001068 main.assertReturnString += 'Link Down Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001069 else:
Jon Hall439c8912016-04-15 02:22:03 -07001070 main.assertReturnString += 'Link Down Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001071
1072 # Check intent state
1073 intentTemp = checkIntentState( main, intentsId )
1074 intentResult = intentResult and intentTemp
1075 if intentTemp:
1076 main.assertReturnString += 'Link Down Intent State Passed\n'
1077 else:
1078 main.assertReturnString += 'Link Down Intent State Failed\n'
1079
1080 # Checks ONOS state in link down
1081 if linkDownResult and topoResult and pingResult and intentResult:
1082 main.log.info( itemName + ": Successfully brought link down" )
1083 else:
1084 main.log.error( itemName + ": Failed to bring link down" )
1085
1086 # link up
1087 linkUpResult = link( main, sw1, sw2, "up" )
1088 if linkUpResult:
1089 main.assertReturnString += 'Link Up Passed\n'
1090 else:
1091 main.assertReturnString += 'Link Up Failed\n'
1092
1093 time.sleep( main.rerouteSleep )
1094
1095 # Check flows count in each node
1096 checkFlowsCount( main )
1097 # Verify flows
1098 checkFlowsState( main )
1099
1100 # Check OnosTopology
1101 topoResult = checkTopology( main, main.numLinks )
1102 if topoResult:
1103 main.assertReturnString += 'Link Up Topology State Passed\n'
1104 else:
1105 main.assertReturnString += 'Link Up Topology State Failed\n'
1106
1107 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -07001108 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001109 pingResult = pingResult and pingTemp
1110 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001111 main.assertReturnString += 'Link Up Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001112 else:
Jon Hall439c8912016-04-15 02:22:03 -07001113 main.assertReturnString += 'Link Up Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001114
1115 # Check Intents
1116 intentTemp = checkIntentState( main, intentsId )
1117 intentResult = intentResult and intentTemp
1118 if intentTemp:
1119 main.assertReturnString += 'Link Up Intent State Passed\n'
1120 else:
1121 main.assertReturnString += 'Link Up Intent State Failed\n'
1122
1123 # Checks ONOS state in link up
1124 if linkUpResult and topoResult and pingResult and intentResult:
1125 main.log.info( itemName + ": Successfully brought link back up" )
1126 else:
1127 main.log.error( itemName + ": Failed to bring link back up" )
1128
1129 # Remove all intents
1130 removeIntentResult = removeAllIntents( main, intentsId )
1131 if removeIntentResult:
1132 main.assertReturnString += 'Remove Intents Passed'
1133 else:
1134 main.assertReturnString += 'Remove Intents Failed'
1135
1136 stepResult = pingResult and linkDownResult and linkUpResult \
1137 and intentResult and removeIntentResult
1138
1139 return stepResult
1140
Jon Hall314b74a2017-05-24 16:25:52 -07001141
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001142def multiToSingleIntent( main,
1143 name,
Jon Hall439c8912016-04-15 02:22:03 -07001144 hostNames="",
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001145 onosNode=0,
1146 devices="",
Jon Hall439c8912016-04-15 02:22:03 -07001147 ports="",
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001148 ethType="",
Jon Hall439c8912016-04-15 02:22:03 -07001149 macs="",
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001150 bandwidth="",
1151 lambdaAlloc=False,
1152 ipProto="",
1153 ipAddresses="",
1154 tcp="",
1155 sw1="",
1156 sw2="",
1157 expectedLink=0 ):
1158 """
1159 Verify Single to Multi Point intents
1160 NOTE:If main.hostsData is not defined, variables data should be passed in the
1161 same order index wise. All devices in the list should have the same
1162 format, either all the devices have its port or it doesn't.
1163 eg. hostName = [ 'h1', 'h2' ,.. ]
Jon Hall314b74a2017-05-24 16:25:52 -07001164 devices = [ 'of:0000000000000001', 'of:0000000000000002', ... ]
1165 ports = [ '1', '1', .. ]
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001166 ...
1167 Description:
1168 Verify add-multi-to-single-intent
1169 Steps:
1170 - Get device ids | ports
1171 - Add multi to single point intents
1172 - Check intents
1173 - Verify flows
1174 - Ping hosts
1175 - Reroute
1176 - Link down
1177 - Verify flows
1178 - Check topology
1179 - Ping hosts
1180 - Link up
1181 - Verify flows
1182 - Check topology
1183 - Ping hosts
1184 - Remove intents
1185 Required:
1186 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
1187 hostNames - List of host names
1188 Optional:
1189 onosNode - ONOS node to install the intents in main.CLIs[ ]
1190 0 by default so that it will always use the first
1191 ONOS node
1192 devices - List of device ids in the same order as the hosts
1193 in hostNames
1194 ports - List of port numbers in the same order as the device in
1195 devices
1196 ethType - Ethernet type eg. IPV4, IPV6
1197 macs - List of hosts mac address in the same order as the hosts in
1198 hostNames
1199 bandwidth - Bandwidth capacity
1200 lambdaAlloc - Allocate lambda, defaults to False
1201 ipProto - IP protocol
1202 ipAddresses - IP addresses of host in the same order as the hosts in
1203 hostNames
1204 tcp - TCP ports in the same order as the hosts in hostNames
1205 sw1 - First switch to bring down & up for rerouting purpose
1206 sw2 - Second switch to bring down & up for rerouting purpose
1207 expectedLink - Expected link when the switches are down, it should
1208 be two links lower than the links before the two
1209 switches are down
sathishmc4362252016-04-20 18:29:48 +05301210 Note - Don't use more than 2 hosts for MultiToSingle Intent with no mac address option.
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001211 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001212 assert main, "There is no main variable"
1213 assert hostNames, "You must specify hosts"
1214 assert devices or main.hostsData, "You must specify devices"
1215
1216 global itemName
1217 itemName = name
1218 tempHostsData = {}
1219 intentsId = []
1220 onosNode = int( onosNode )
1221
1222 macsDict = {}
1223 ipDict = {}
1224 if hostNames and devices:
1225 if len( hostNames ) != len( devices ):
1226 main.log.debug( "hosts and devices does not have the same length" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001227 return main.FALSE
1228 if ports:
1229 if len( ports ) != len( devices ):
1230 main.log.error( "Ports and devices does " +
1231 "not have the same length" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001232 return main.FALSE
1233 else:
1234 main.log.info( "Device Ports are not specified" )
1235 if macs:
1236 for i in range( len( devices ) ):
1237 macsDict[ devices[ i ] ] = macs[ i ]
1238 elif hostNames and not devices and main.hostsData:
1239 devices = []
1240 main.log.info( "multiToSingleIntent function is using main.hostsData" )
1241 for host in hostNames:
Jon Hall314b74a2017-05-24 16:25:52 -07001242 devices.append( main.hostsData.get( host ).get( 'location' ) )
1243 macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \
1244 main.hostsData.get( host ).get( 'mac' )
1245 ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \
1246 main.hostsData.get( host ).get( 'ipAddresses' )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001247
1248 pingResult = main.TRUE
1249 intentResult = main.TRUE
1250 removeIntentResult = main.TRUE
1251 flowResult = main.TRUE
1252 topoResult = main.TRUE
1253 linkDownResult = main.TRUE
1254 linkUpResult = main.TRUE
1255
1256 devicesCopy = copy.copy( devices )
1257 if ports:
1258 portsCopy = copy.copy( ports )
1259 main.log.info( itemName + ": Adding multi point to single point intents" )
1260
1261 # Check flows count in each node
1262 checkFlowsCount( main )
1263
1264 # Adding bidirectional point intents
1265 for i in range( len( devices ) ):
1266 egressDevice = devicesCopy[ i ]
1267 ingressDeviceList = copy.copy( devicesCopy )
1268 ingressDeviceList.remove( egressDevice )
1269 if ports:
1270 portEgress = portsCopy[ i ]
1271 portIngressList = copy.copy( portsCopy )
1272 del portIngressList[ i ]
1273 else:
1274 portEgress = ""
1275 portIngressList = None
1276 if not macsDict:
1277 dstMac = ""
1278 else:
1279 dstMac = macsDict[ egressDevice ]
Jon Hall314b74a2017-05-24 16:25:52 -07001280 if dstMac is None:
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001281 main.log.debug( "There is no MAC in device - " + egressDevice )
1282 dstMac = ""
1283
1284 intentsId.append(
Devin Lim142b5342017-07-20 15:22:39 -07001285 main.Cluster.active( onosNode ).CLI.addMultipointToSinglepointIntent(
1286 ingressDeviceList=ingressDeviceList,
1287 egressDevice=egressDevice,
1288 portIngressList=portIngressList,
1289 portEgress=portEgress,
1290 ethType=ethType,
1291 ethDst=dstMac,
1292 bandwidth=bandwidth,
1293 lambdaAlloc=lambdaAlloc,
1294 ipProto=ipProto,
1295 ipSrc="",
1296 ipDst="",
1297 tcpSrc="",
1298 tcpDst="" ) )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001299 # Check intents state
1300 time.sleep( main.checkIntentSleep )
1301 intentResult = checkIntentState( main, intentsId )
1302
1303 # Check intents state again if first check fails...
1304 if not intentResult:
1305 intentResult = checkIntentState( main, intentsId )
sathishmc4362252016-04-20 18:29:48 +05301306 if intentResult:
1307 main.assertReturnString += 'Initial Intent State Passed\n'
1308 else:
1309 main.assertReturnString += 'Initial Intent State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001310
1311 # Check flows count in each node
sathishmc4362252016-04-20 18:29:48 +05301312 FlowResult = checkFlowsCount( main )
1313 if FlowResult:
1314 main.assertReturnString += 'Initial Flow Count Passed\n'
1315 else:
1316 main.assertReturnString += 'Initial Flow Count Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001317 # Verify flows
sathishmc4362252016-04-20 18:29:48 +05301318 StateResult = checkFlowsState( main )
1319 if StateResult:
1320 main.assertReturnString += 'Initial Flow State Passed\n'
1321 else:
1322 main.assertReturnString += 'Initial Flow State Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001323
Jon Hall439c8912016-04-15 02:22:03 -07001324 # Ping hosts...
1325 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001326 pingResult = pingResult and pingTemp
1327 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001328 main.assertReturnString += 'Initial Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001329 else:
Jon Hall439c8912016-04-15 02:22:03 -07001330 main.assertReturnString += 'Initial Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001331
1332 # Test rerouting if these variables exist
1333 if sw1 and sw2 and expectedLink:
1334 # link down
1335 linkDownResult = link( main, sw1, sw2, "down" )
1336
1337 if linkDownResult:
1338 main.assertReturnString += 'Link Down Passed\n'
1339 else:
1340 main.assertReturnString += 'Link Down Failed\n'
1341
1342 # Check flows count in each node
1343 checkFlowsCount( main )
1344 # Verify flows
1345 checkFlowsState( main )
1346
1347 # Check OnosTopology
1348 topoResult = checkTopology( main, expectedLink )
1349 if topoResult:
1350 main.assertReturnString += 'Link Down Topology State Passed\n'
1351 else:
1352 main.assertReturnString += 'Link Down Topology State Failed\n'
1353
1354 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -07001355 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001356 pingResult = pingResult and pingTemp
1357 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001358 main.assertReturnString += 'Link Down Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001359 else:
Jon Hall439c8912016-04-15 02:22:03 -07001360 main.assertReturnString += 'Link Down Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001361
1362 # Check intent state
1363 intentTemp = checkIntentState( main, intentsId )
1364 intentResult = intentResult and intentTemp
1365 if intentTemp:
1366 main.assertReturnString += 'Link Down Intent State Passed\n'
1367 else:
1368 main.assertReturnString += 'Link Down Intent State Failed\n'
1369
1370 # Checks ONOS state in link down
1371 if linkDownResult and topoResult and pingResult and intentResult:
1372 main.log.info( itemName + ": Successfully brought link down" )
1373 else:
1374 main.log.error( itemName + ": Failed to bring link down" )
1375
1376 # link up
1377 linkUpResult = link( main, sw1, sw2, "up" )
1378 if linkUpResult:
1379 main.assertReturnString += 'Link Up Passed\n'
1380 else:
1381 main.assertReturnString += 'Link Up Failed\n'
1382
1383 time.sleep( main.rerouteSleep )
1384
1385 # Check flows count in each node
1386 checkFlowsCount( main )
1387 # Verify flows
1388 checkFlowsState( main )
1389
1390 # Check OnosTopology
1391 topoResult = checkTopology( main, main.numLinks )
1392 if topoResult:
1393 main.assertReturnString += 'Link Up Topology State Passed\n'
1394 else:
1395 main.assertReturnString += 'Link Up Topology State Failed\n'
1396
1397 # Ping hosts
Jon Hall439c8912016-04-15 02:22:03 -07001398 pingTemp = ping6allHosts( main, hostNames )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001399 pingResult = pingResult and pingTemp
1400 if pingTemp:
Jon Hall439c8912016-04-15 02:22:03 -07001401 main.assertReturnString += 'Link Up Ping6all Passed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001402 else:
Jon Hall439c8912016-04-15 02:22:03 -07001403 main.assertReturnString += 'Link Up Ping6all Failed\n'
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001404
1405 # Check Intents
1406 intentTemp = checkIntentState( main, intentsId )
1407 intentResult = intentResult and intentTemp
1408 if intentTemp:
1409 main.assertReturnString += 'Link Up Intent State Passed\n'
1410 else:
1411 main.assertReturnString += 'Link Up Intent State Failed\n'
1412
1413 # Checks ONOS state in link up
1414 if linkUpResult and topoResult and pingResult and intentResult:
1415 main.log.info( itemName + ": Successfully brought link back up" )
1416 else:
1417 main.log.error( itemName + ": Failed to bring link back up" )
1418
1419 # Remove all intents
1420 removeIntentResult = removeAllIntents( main, intentsId )
1421 if removeIntentResult:
1422 main.assertReturnString += 'Remove Intents Passed'
1423 else:
1424 main.assertReturnString += 'Remove Intents Failed'
1425
1426 stepResult = pingResult and linkDownResult and linkUpResult \
1427 and intentResult and removeIntentResult
1428
1429 return stepResult
1430
Jon Hall314b74a2017-05-24 16:25:52 -07001431
sathishmc4362252016-04-20 18:29:48 +05301432def testEndPointFail( main,
1433 name,
1434 test="",
1435 hostNames="",
1436 devices="",
1437 macs="",
1438 ports="",
1439 onosNode=0,
1440 ethType="",
1441 bandwidth="",
1442 lambdaAlloc=False,
1443 ipProto="",
1444 ipAddresses="",
1445 tcp="",
1446 sw1="",
1447 sw2="",
1448 sw3="",
1449 sw4="",
1450 sw5="",
1451 expectedLink1=0,
1452 expectedLink2=0 ):
1453 """
1454 Test Multipoint Topology for Endpoint failures
1455 """
sathishmc4362252016-04-20 18:29:48 +05301456 assert main, "There is no main variable"
1457 assert hostNames, "You must specify hosts"
1458 assert devices or main.hostsData, "You must specify devices"
1459
1460 global itemName
1461 itemName = name
1462 tempHostsData = {}
1463 intentsId = []
1464 onosNode = int( onosNode )
1465
1466 macsDict = {}
1467 ipDict = {}
1468 if hostNames and devices:
1469 if len( hostNames ) != len( devices ):
1470 main.log.debug( "hosts and devices does not have the same length" )
1471 return main.FALSE
1472 if ports:
1473 if len( ports ) != len( devices ):
1474 main.log.error( "Ports and devices does " +
1475 "not have the same length" )
1476 return main.FALSE
1477 else:
1478 main.log.info( "Device Ports are not specified" )
1479 if macs:
1480 for i in range( len( devices ) ):
1481 macsDict[ devices[ i ] ] = macs[ i ]
1482 elif hostNames and not devices and main.hostsData:
1483 devices = []
1484 main.log.info( "multiIntent function is using main.hostsData" )
1485 for host in hostNames:
Jon Hall314b74a2017-05-24 16:25:52 -07001486 devices.append( main.hostsData.get( host ).get( 'location' ) )
1487 macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \
1488 main.hostsData.get( host ).get( 'mac' )
1489 ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \
1490 main.hostsData.get( host ).get( 'ipAddresses' )
sathishmc4362252016-04-20 18:29:48 +05301491
1492 pingResult = main.TRUE
1493 intentResult = main.TRUE
1494 removeIntentResult = main.TRUE
1495 flowResult = main.TRUE
1496 topoResult = main.TRUE
1497 linkDownResult = main.TRUE
1498 linkUpResult = main.TRUE
1499
1500 devicesCopy = copy.copy( devices )
1501 if ports:
1502 portsCopy = copy.copy( ports )
1503 main.log.info( itemName + ": Adding intents" )
1504
1505 # Check flows count in each node
1506 checkFlowsCount( main )
1507
Jon Hall314b74a2017-05-24 16:25:52 -07001508 if test == "MultipletoSingle":
sathishmc4362252016-04-20 18:29:48 +05301509 for i in range( len( devices ) ):
1510 egressDevice = devicesCopy[ i ]
1511 ingressDeviceList = copy.copy( devicesCopy )
1512 ingressDeviceList.remove( egressDevice )
1513 if ports:
1514 portEgress = portsCopy[ i ]
1515 portIngressList = copy.copy( portsCopy )
1516 del portIngressList[ i ]
1517 else:
1518 portEgress = ""
1519 portIngressList = None
1520 if not macsDict:
1521 dstMac = ""
1522 else:
1523 dstMac = macsDict[ egressDevice ]
Jon Hall314b74a2017-05-24 16:25:52 -07001524 if dstMac is None:
sathishmc4362252016-04-20 18:29:48 +05301525 main.log.debug( "There is no MAC in device - " + egressDevice )
1526 dstMac = ""
1527
1528 intentsId.append(
Devin Lim142b5342017-07-20 15:22:39 -07001529 main.Cluster.active( onosNode ).CLI.addMultipointToSinglepointIntent(
1530 ingressDeviceList=ingressDeviceList,
1531 egressDevice=egressDevice,
1532 portIngressList=portIngressList,
1533 portEgress=portEgress,
1534 ethType=ethType,
1535 ethDst=dstMac,
1536 bandwidth=bandwidth,
1537 lambdaAlloc=lambdaAlloc,
1538 ipProto=ipProto,
1539 ipSrc="",
1540 ipDst="",
1541 tcpSrc="",
1542 tcpDst="" ) )
sathishmc4362252016-04-20 18:29:48 +05301543
Jon Hall314b74a2017-05-24 16:25:52 -07001544 elif test == "SingletoMultiple":
sathishmc4362252016-04-20 18:29:48 +05301545 for i in range( len( devices ) ):
1546 ingressDevice = devicesCopy[ i ]
1547 egressDeviceList = copy.copy( devicesCopy )
1548 egressDeviceList.remove( ingressDevice )
1549 if ports:
1550 portIngress = portsCopy[ i ]
1551 portEgressList = copy.copy( portsCopy )
1552 del portEgressList[ i ]
1553 else:
1554 portIngress = ""
1555 portEgressList = None
1556 if not macsDict:
1557 srcMac = ""
1558 else:
1559 srcMac = macsDict[ ingressDevice ]
Jon Hall314b74a2017-05-24 16:25:52 -07001560 if srcMac is None:
sathishmc4362252016-04-20 18:29:48 +05301561 main.log.debug( "There is no MAC in device - " + ingressDevice )
1562 srcMac = ""
1563
1564 intentsId.append(
Devin Lim142b5342017-07-20 15:22:39 -07001565 main.Cluster.active( onosNode ).CLI.addSinglepointToMultipointIntent(
1566 ingressDevice=ingressDevice,
1567 egressDeviceList=egressDeviceList,
1568 portIngress=portIngress,
1569 portEgressList=portEgressList,
1570 ethType=ethType,
1571 ethSrc=srcMac,
1572 bandwidth=bandwidth,
1573 lambdaAlloc=lambdaAlloc,
1574 ipProto=ipProto,
1575 ipSrc="",
1576 ipDst="",
1577 tcpSrc="",
1578 tcpDst="" ) )
sathishmc4362252016-04-20 18:29:48 +05301579
1580 else:
Jon Hall314b74a2017-05-24 16:25:52 -07001581 main.log.info( "Invalid test Name - Type either SingletoMultiple or MultipletoSingle" )
sathishmc4362252016-04-20 18:29:48 +05301582 return main.FALSE
1583
1584 # Check intents state
1585 time.sleep( main.checkIntentSleep )
1586 intentResult = checkIntentState( main, intentsId )
1587
1588 # Check intents state again if first check fails...
1589 if not intentResult:
1590 intentResult = checkIntentState( main, intentsId )
1591 if intentResult:
1592 main.assertReturnString += 'Initial Intent State Passed\n'
1593 else:
1594 main.assertReturnString += 'Initial Intent State Failed\n'
1595
1596 # Check flows count in each node
1597 FlowResult = checkFlowsCount( main )
1598 if FlowResult:
1599 main.assertReturnString += 'Initial Flow Count Passed\n'
1600 else:
1601 main.assertReturnString += 'Initial Flow Count Failed\n'
1602 # Verify flows
1603 StateResult = checkFlowsState( main )
1604 if StateResult:
1605 main.assertReturnString += 'Initial Flow State Passed\n'
1606 else:
1607 main.assertReturnString += 'Initial Flow State Failed\n'
1608
1609 # Ping hosts...
1610 pingTemp = ping6allHosts( main, hostNames )
1611 pingResult = pingResult and pingTemp
1612 if pingTemp:
1613 main.assertReturnString += 'Initial Pingall Passed\n'
1614 else:
1615 main.assertReturnString += 'Initial Pingall Failed\n'
1616
1617 # Test rerouting if these variables exist
1618 if sw1 and sw2 and sw3 and sw4 and sw5 and expectedLink1 and expectedLink2:
Jon Hall314b74a2017-05-24 16:25:52 -07001619 # Take two links down
sathishmc4362252016-04-20 18:29:48 +05301620 # Take first link down
1621 linkDownResult1 = link( main, sw1, sw2, "down" )
1622 if linkDownResult1:
1623 main.assertReturnString += 'First Link Down Passed\n'
1624 else:
1625 main.assertReturnString += 'First Link Down Failed\n'
1626
1627 # Take second link down
1628 linkDownResult2 = link( main, sw3, sw4, "down" )
1629 if linkDownResult2:
1630 main.assertReturnString += 'Second Link Down Passed\n'
1631 else:
1632 main.assertReturnString += 'Second Link Down Failed\n'
1633
1634 # Check flows count in each node
1635 FlowResult = checkFlowsCount( main )
1636 if FlowResult:
1637 main.assertReturnString += 'Link Down Flow Count Passed\n'
1638 else:
1639 main.assertReturnString += 'Link Down Flow Count Failed\n'
1640 # Verify flows
1641 StateResult = checkFlowsState( main )
1642 if StateResult:
1643 main.assertReturnString += 'Link Down Flow State Passed\n'
1644 else:
1645 main.assertReturnString += 'Link Down Flow State Failed\n'
1646
1647 # Check OnosTopology
1648 topoResult = checkTopology( main, expectedLink1 )
1649 if topoResult:
1650 main.assertReturnString += 'Link Down Topology State Passed\n'
1651 else:
1652 main.assertReturnString += 'Link Down Topology State Failed\n'
1653
1654 # Ping hosts
1655 pingTemp = ping6allHosts( main, hostNames )
1656 pingResult = pingResult and pingTemp
1657 if pingTemp:
1658 main.assertReturnString += 'Link Down Ping6all Passed\n'
1659 else:
1660 main.assertReturnString += 'Link Down Ping6all Failed\n'
1661
1662 # Check intent state
1663 intentTemp = checkIntentState( main, intentsId )
1664 intentResult = intentResult and intentTemp
1665 if intentTemp:
1666 main.assertReturnString += 'Link Down Intent State Passed\n'
1667 else:
1668 main.assertReturnString += 'Link Down Intent State Failed\n'
1669
1670 # Take third link down to isolate the node
1671 linkDownResult3 = link( main, sw3, sw5, "down" )
1672 if linkDownResult3:
1673 main.assertReturnString += 'Isolation Third Link Down Passed\n'
1674 else:
1675 main.assertReturnString += 'Isolation Third Link Down Failed\n'
1676
1677 # Check flows count in each node
1678 FlowResult = checkFlowsCount( main )
1679 if FlowResult:
1680 main.assertReturnString += 'Isolation Link Down Flow Count Passed\n'
1681 else:
1682 main.assertReturnString += 'Isolation Link Down Flow Count Failed\n'
1683
1684 # Verify flows
1685 StateResult = checkFlowsState( main )
1686 if StateResult:
1687 main.assertReturnString += 'Isolation Link Down Flow State Passed\n'
1688 else:
1689 main.assertReturnString += 'Isolation Link Down Flow State Failed\n'
1690
1691 # Check OnosTopology
1692 topoResult = checkTopology( main, expectedLink2 )
1693 if topoResult:
1694 main.assertReturnString += 'Isolation Link Down Topology State Passed\n'
1695 else:
1696 main.assertReturnString += 'Isolation Link Down Topology State Failed\n'
1697
1698 # Ping hosts after isolation
Jon Hall314b74a2017-05-24 16:25:52 -07001699 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 +05301700 pingIsolation = ping6allHosts( main, hostNames )
1701 if pingIsolation:
1702 main.assertReturnString += 'Isolation Link Down Ping6all Passed\n'
1703 else:
1704 main.assertReturnString += 'Isolation Link Down Ping6all Failed\n'
1705
1706 # Check intent state after isolation
Jon Hall314b74a2017-05-24 16:25:52 -07001707 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 +05301708 intentIsolation = checkIntentState( main, intentsId )
1709 if intentIsolation:
1710 main.assertReturnString += 'Isolation Link Down Intent State Passed\n'
1711 else:
1712 main.assertReturnString += 'Isolation Link Down Intent State Failed\n'
1713
1714 linkDownResult = linkDownResult1 and linkDownResult2 and linkDownResult3
1715
1716 # Checks ONOS state in link down
1717 if linkDownResult and topoResult and pingResult and intentResult:
1718 main.log.info( itemName + ": Successfully brought link down" )
1719 else:
1720 main.log.error( itemName + ": Failed to bring link down" )
1721
1722 # Bring the links back up
1723 # Bring first link up
1724 linkUpResult1 = link( main, sw1, sw2, "up" )
1725 if linkUpResult1:
1726 main.assertReturnString += 'First Link Up Passed\n'
1727 else:
1728 main.assertReturnString += 'First Link Up Failed\n'
1729
1730 # Bring second link up
1731 linkUpResult2 = link( main, sw3, sw4, "up" )
1732 if linkUpResult2:
1733 main.assertReturnString += 'Second Link Up Passed\n'
1734 else:
1735 main.assertReturnString += 'Second Link Up Failed\n'
1736 # Bring third link up
1737 linkUpResult3 = link( main, sw3, sw5, "up" )
1738 if linkUpResult3:
1739 main.assertReturnString += 'Third Link Up Passed\n'
1740 else:
1741 main.assertReturnString += 'Third Link Up Failed\n'
1742
1743 linkUpResult = linkUpResult1 and linkUpResult2 and linkUpResult3
1744 time.sleep( main.rerouteSleep )
1745
1746 # Check flows count in each node
1747 FlowResult = checkFlowsCount( main )
1748 if FlowResult:
1749 main.assertReturnString += 'Link Up Flow Count Passed\n'
1750 else:
1751 main.assertReturnString += 'Link Up Flow Count Failed\n'
1752 # Verify flows
1753 StateResult = checkFlowsState( main )
1754 if StateResult:
1755 main.assertReturnString += 'Link Up Flow State Passed\n'
1756 else:
1757 main.assertReturnString += 'Link Up Flow State Failed\n'
1758
1759 # Check OnosTopology
1760 topoResult = checkTopology( main, main.numLinks )
1761 if topoResult:
1762 main.assertReturnString += 'Link Up Topology State Passed\n'
1763 else:
1764 main.assertReturnString += 'Link Up Topology State Failed\n'
1765
1766 # Ping hosts
1767 pingTemp = ping6allHosts( main, hostNames )
1768 pingResult = pingResult and pingTemp
1769 if pingTemp:
1770 main.assertReturnString += 'Link Up Pingall Passed\n'
1771 else:
1772 main.assertReturnString += 'Link Up Pingall Failed\n'
1773
1774 # Check Intents
1775 intentTemp = checkIntentState( main, intentsId )
1776 intentResult = intentResult and intentTemp
1777 if intentTemp:
1778 main.assertReturnString += 'Link Up Intent State Passed\n'
1779 else:
1780 main.assertReturnString += 'Link Up Intent State Failed\n'
1781
1782 # Checks ONOS state in link up
1783 if linkUpResult and topoResult and pingResult and intentResult:
1784 main.log.info( itemName + ": Successfully brought link back up" )
1785 else:
1786 main.log.error( itemName + ": Failed to bring link back up" )
1787
1788 # Remove all intents
1789 removeIntentResult = removeAllIntents( main, intentsId )
1790 if removeIntentResult:
1791 main.assertReturnString += 'Remove Intents Passed'
1792 else:
1793 main.assertReturnString += 'Remove Intents Failed'
1794
1795 testResult = pingResult and linkDownResult and linkUpResult \
1796 and intentResult and removeIntentResult
1797
1798 return testResult
1799
Jon Hall314b74a2017-05-24 16:25:52 -07001800
Subhash Kumar Singh5ea4d302015-11-05 14:36:52 +05301801def ping6allHosts( main, hostList ):
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001802 # Ping all host in the hosts list variable
1803 main.log.info( "Pinging: " + str( hostList ) )
Subhash Kumar Singh5ea4d302015-11-05 14:36:52 +05301804 return main.Mininet1.pingIpv6Hosts( hostList )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001805
Jon Hall314b74a2017-05-24 16:25:52 -07001806
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001807def getHostsData( main ):
1808 """
1809 Use fwd app and pingall to discover all the hosts
1810 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001811 activateResult = main.TRUE
1812 appCheck = main.TRUE
1813 getDataResult = main.TRUE
1814 main.log.info( "Activating reactive forwarding app " )
Devin Lim142b5342017-07-20 15:22:39 -07001815 activateResult = main.Cluster.active( 0 ).CLI.activateApp( "org.onosproject.fwd" )
You Wang6ce33b02017-08-08 13:05:09 -07001816 main.Cluster.active( 0 ).CLI.setCfg( "org.onosproject.provider.host.impl.HostLocationProvider", "requestIpv6ND", "true" )
1817 main.Cluster.active( 0 ).CLI.setCfg( "org.onosproject.net.neighbour.impl.NeighbourResolutionManager", "ndpEnabled", "true" )
Devin Lim142b5342017-07-20 15:22:39 -07001818 main.Cluster.active( 0 ).CLI.setCfg( "org.onosproject.fwd.ReactiveForwarding", "ipv6Forwarding", "true" )
1819 main.Cluster.active( 0 ).CLI.setCfg( "org.onosproject.fwd.ReactiveForwarding", "matchIpv6Address", "true" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001820 time.sleep( main.fwdSleep )
1821
Devin Lim142b5342017-07-20 15:22:39 -07001822 for ctrl in main.Cluster.active():
1823 appCheck = appCheck and ctrl.CLI.appToIDCheck()
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001824 if appCheck != main.TRUE:
Devin Lim142b5342017-07-20 15:22:39 -07001825 main.log.warn( ctrl.CLI.apps() )
1826 main.log.warn( ctrl.CLI.appIDs() )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001827
Jon Hall314b74a2017-05-24 16:25:52 -07001828 pingResult = main.Mininet1.pingall( protocol="IPv6", timeout=600 )
Devin Lim142b5342017-07-20 15:22:39 -07001829 hostsJson = json.loads( main.Cluster.active( 0 ).CLI.hosts() )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001830 hosts = main.Mininet1.getHosts().keys()
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001831 for host in hosts:
1832 main.hostsData[ host ] = {}
1833 main.hostsData[ host ][ 'mac' ] = \
1834 main.Mininet1.getMacAddress( host ).upper()
1835 for hostj in hostsJson:
1836 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
1837 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
1838 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
1839 main.hostsData[ host ][ 'location' ] = \
Jeremy Ronquillo0e538bc2017-06-13 15:16:09 -07001840 hostj[ 'locations' ][ 0 ][ 'elementId' ] + '/' + \
1841 hostj[ 'locations' ][ 0 ][ 'port' ]
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001842 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
1843
1844 main.log.info( "Deactivating reactive forwarding app " )
Devin Lim142b5342017-07-20 15:22:39 -07001845 deactivateResult = main.Cluster.active( 0 ).CLI.deactivateApp( "org.onosproject.fwd" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001846 if activateResult and deactivateResult and main.hostsData:
1847 main.log.info( "Successfully used fwd app to discover hosts " )
1848 getDataResult = main.TRUE
1849 else:
1850 main.log.info( "Failed to use fwd app to discover hosts " )
1851 getDataResult = main.FALSE
1852
Jon Hall439c8912016-04-15 02:22:03 -07001853 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' " )
1854 for host in main.hostsData.keys():
Jon Hall314b74a2017-05-24 16:25:52 -07001855 if main.hostsData[ host ].get( 'ipAddresses' ) is not None:
1856 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 -08001857 print main.hostsData
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001858 return getDataResult
1859
Jon Hall314b74a2017-05-24 16:25:52 -07001860
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001861def checkTopology( main, expectedLink ):
1862 statusResult = main.TRUE
1863 # Check onos topology
1864 main.log.info( itemName + ": Checking ONOS topology " )
1865
Devin Lim142b5342017-07-20 15:22:39 -07001866 statusResult = main.Cluster.command( "checkStatus",
1867 args=[ main.numSwitch, expectedLink ],
1868 returnBool=True, specificDriver=2 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001869 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
Devin Lim142b5342017-07-20 15:22:39 -07001886 stateResult = main.Cluster.command( "checkIntentState",
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07001887 kwargs={ "intentsId": intentsId },
Devin Lim142b5342017-07-20 15:22:39 -07001888 returnBool=True, specificDriver=2 )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001889
1890 expectedState = [ 'INSTALLED', 'INSTALLING' ]
1891
Devin Lim142b5342017-07-20 15:22:39 -07001892 if stateResult:
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001893 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
Devin Lim142b5342017-07-20 15:22:39 -07001901 stateResult = main.Cluster.command( "checkIntentState",
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07001902 kwargs={ "intentsId": intentsId },
1903 returnBool=True, specificDriver=2 )
Devin Lim142b5342017-07-20 15:22:39 -07001904 if stateResult:
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001905 main.log.info( itemName + ": Intents are installed correctly" )
1906 intentResult = main.TRUE
1907 else:
1908 main.log.error( itemName + ": Intents are NOT installed correctly" )
1909 intentResult = main.FALSE
1910
1911 return intentResult
1912
Jon Hall314b74a2017-05-24 16:25:52 -07001913
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001914def checkFlowsState( main ):
1915
1916 main.log.info( itemName + ": Check flows state" )
Devin Lim142b5342017-07-20 15:22:39 -07001917 checkFlowsResult = main.Cluster.active( 0 ).CLI.checkFlowsState()
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001918 return checkFlowsResult
1919
Jon Hall314b74a2017-05-24 16:25:52 -07001920
1921def link( main, sw1, sw2, option ):
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001922
1923 # link down
1924 main.log.info( itemName + ": Bring link " + option + "between " +
1925 sw1 + " and " + sw2 )
1926 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
1927 return linkResult
1928
Jon Hall314b74a2017-05-24 16:25:52 -07001929
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001930def removeAllIntents( main, intentsId ):
1931 """
1932 Remove all intents in the intentsId
1933 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001934 onosSummary = []
1935 removeIntentResult = main.TRUE
1936 # Remove intents
1937 for intent in intentsId:
Devin Lim142b5342017-07-20 15:22:39 -07001938 main.Cluster.active( 0 ).CLI.removeIntent( intentId=intent, purge=True )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001939
1940 time.sleep( main.removeIntentSleep )
1941
1942 # If there is remianing intents then remove intents should fail
Devin Lim142b5342017-07-20 15:22:39 -07001943 for ctrl in main.Cluster.active():
1944 onosSummary.append( json.loads( ctrl.CLI.summary() ) )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001945
1946 for summary in onosSummary:
1947 if summary.get( 'intents' ) != 0:
1948 main.log.warn( itemName + ": There are " +
1949 str( summary.get( 'intents' ) ) +
1950 " intents remaining in node " +
1951 str( summary.get( 'node' ) ) +
1952 ", failed to remove all the intents " )
1953 removeIntentResult = main.FALSE
1954
1955 if removeIntentResult:
1956 main.log.info( itemName + ": There are no more intents remaining, " +
1957 "successfully removed all the intents." )
1958
1959 return removeIntentResult
1960
Jon Hall314b74a2017-05-24 16:25:52 -07001961
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001962def checkFlowsCount( main ):
1963 """
1964 Check flows count in each node
1965 """
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001966 flowsCount = []
1967 main.log.info( itemName + ": Checking flows count in each ONOS node" )
Devin Lim142b5342017-07-20 15:22:39 -07001968 for ctrl in main.Cluster.active():
1969 summaryResult = ctrl.CLI.summary()
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001970 if not summaryResult:
1971 main.log.error( itemName + ": There is something wrong with " +
1972 "summary command" )
1973 return main.FALSE
1974 else:
1975 summaryJson = json.loads( summaryResult )
1976 flowsCount.append( summaryJson.get( 'flows' ) )
1977
1978 if flowsCount:
Jon Hall314b74a2017-05-24 16:25:52 -07001979 if all( flows == flowsCount[ 0 ] for flows in flowsCount ):
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001980 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
1981 " flows in all ONOS node" )
1982 else:
Devin Lim142b5342017-07-20 15:22:39 -07001983 for i in range( main.Cluster.numCtrls ):
1984 main.log.debug( itemName + ": " + main.Cluster.active( i ).name + " has " +
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001985 str( flowsCount[ i ] ) + " flows" )
1986 else:
1987 main.log.error( "Checking flows count failed, check summary command" )
1988 return main.FALSE
1989
1990 return main.TRUE
1991
Jon Hall314b74a2017-05-24 16:25:52 -07001992
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001993def checkLeaderChange( leaders1, leaders2 ):
1994 """
1995 Checks for a change in intent partition leadership.
1996
1997 Takes the output of leaders -c in json string format before and after
1998 a potential change as input
1999
2000 Returns main.TRUE if no mismatches are detected
2001 Returns main.FALSE if there is a mismatch or on error loading the input
2002 """
2003 try:
2004 leaders1 = json.loads( leaders1 )
2005 leaders2 = json.loads( leaders2 )
Jon Hall314b74a2017-05-24 16:25:52 -07002006 except ( AttributeError, TypeError ):
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08002007 main.log.exception( self.name + ": Object not as expected" )
2008 return main.FALSE
2009 except Exception:
2010 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002011 main.cleanAndExit()
2012
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08002013 main.log.info( "Checking Intent Paritions for Change in Leadership" )
2014 mismatch = False
2015 for dict1 in leaders1:
2016 if "intent" in dict1.get( "topic", [] ):
2017 for dict2 in leaders2:
2018 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \
Jon Hall314b74a2017-05-24 16:25:52 -07002019 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08002020 mismatch = True
Jon Hall314b74a2017-05-24 16:25:52 -07002021 main.log.error( "{0} changed leader from {1} to {2}".
2022 format( dict1.get( "topic", "no-topic" ),
2023 dict1.get( "leader", "no-leader" ),
2024 dict2.get( "leader", "no-leader" ) ) )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08002025 if mismatch:
2026 return main.FALSE
2027 else:
2028 return main.TRUE
2029
Jon Hall314b74a2017-05-24 16:25:52 -07002030
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08002031def report( main ):
2032 """
2033 Report errors/warnings/exceptions
2034 """
Devin Lim142b5342017-07-20 15:22:39 -07002035 main.ONOSbench.logReport( main.Cluster.active( 0 ).ipAddress,
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08002036 [ "INFO",
2037 "FOLLOWER",
2038 "WARN",
2039 "flow",
2040 "ERROR",
2041 "Except" ],
2042 "s" )
2043
2044 main.log.info( "ERROR report: \n" )
Devin Lim142b5342017-07-20 15:22:39 -07002045 for ctrl in main.Cluster.active():
2046 main.ONOSbench.logReport( ctrl.ipAddress,
Jon Hall314b74a2017-05-24 16:25:52 -07002047 [ "ERROR" ],
2048 "d" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08002049
2050 main.log.info( "EXCEPTIONS report: \n" )
Devin Lim142b5342017-07-20 15:22:39 -07002051 for ctrl in main.Cluster.active():
2052 main.ONOSbench.logReport( ctrl.ipAddress,
Jon Hall314b74a2017-05-24 16:25:52 -07002053 [ "Except" ],
2054 "d" )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08002055
2056 main.log.info( "WARNING report: \n" )
Devin Lim142b5342017-07-20 15:22:39 -07002057 for ctrl in main.Cluster.active():
2058 main.ONOSbench.logReport( ctrl.ipAddress,
Jon Hall314b74a2017-05-24 16:25:52 -07002059 [ "WARN" ],
2060 "d" )