blob: fe26d5af2cf7138717b7fdc20c8a15a3d112b0de [file] [log] [blame]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001"""
2 Wrapper functions for FuncIntent
3 This functions include Onosclidriver and Mininetclidriver driver functions
4 Author: kelvin@onlab.us
5"""
6import time
7import copy
8import json
9
10def __init__( self ):
11 self.default = ''
12
Jeremy Songster1f39bf02016-01-20 17:17:25 -080013def installHostIntent( main,
Jeremy2f190ca2016-01-29 15:23:57 -080014 name,
15 host1,
16 host2,
17 onosNode=0,
18 ethType="",
19 bandwidth="",
20 lambdaAlloc=False,
21 ipProto="",
22 ipAddresses="",
23 tcp="",
24 sw1="",
25 sw2=""):
kelvin-onlabd48a68c2015-07-13 16:01:36 -070026 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -080027 Installs a Host Intent
28
kelvin-onlab58dc39e2015-08-06 08:11:09 -070029 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -080030 Install a host intent using
31 add-host-intent
32
kelvin-onlab58dc39e2015-08-06 08:11:09 -070033 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -080034 - Fetch host data if not given
35 - Add host intent
36 - Ingress device is the first sender host
37 - Egress devices are the recipient devices
38 - Ports if defined in senders or recipients
39 - MAC address ethSrc loaded from Ingress device
40 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -070041 Required:
42 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -080043 host1 - Dictionary for host1
44 { "name":"h8", "id":"of:0000000000000005/8" }
45 host2 - Dictionary for host2
46 { "name":"h16", "id":"of:0000000000000006/8" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -070047 Optional:
48 onosNode - ONOS node to install the intents in main.CLIs[ ]
49 0 by default so that it will always use the first
50 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -070051 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -070052 bandwidth - Bandwidth capacity
53 lambdaAlloc - Allocate lambda, defaults to False
54 ipProto - IP protocol
Jeremy Songster1f39bf02016-01-20 17:17:25 -080055 tcp - TCP ports in the same order as the hosts in hostNames
56 """
57
58 assert main, "There is no main variable"
59 assert host1, "You must specify host1"
60 assert host2, "You must specify host2"
61
62 global itemName # The name of this run. Used for logs.
63 itemName = name
64 onosNode = int( onosNode )
65
66 main.log.info( itemName + ": Adding single point to multi point intents" )
67
68 if not host1.get( "id" ):
69 main.log.warn( "ID not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
70 main.log.debug( main.hostsData.get( host1.get( "name" ) ) )
71 host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "id" )
72
73 if not host2.get( "id" ):
74 main.log.warn( "ID not given for host2 {0}. Loading from main.h ostData".format( host2.get( "name" ) ) )
75 host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "id" )
76
77 # Adding point intent
78 intentId = main.CLIs[ onosNode ].addHostIntent( hostIdOne=host1.get( "id" ),
79 hostIdTwo=host2.get( "id" ) )
80
81 # Check intents state
82 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
83 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
84 return intentId
85 else:
Jeremy2f190ca2016-01-29 15:23:57 -080086 main.log.error( "Host Intent did not install correctly" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -080087 return main.FALSE
88
89def testHostIntent( main,
90 name,
91 intentId,
92 host1,
93 host2,
94 onosNode=0,
95 sw1="s5",
96 sw2="s2",
97 expectedLink=0):
98 """
99 Test a Host Intent
100
101 Description:
102 Test a host intent of given ID between given hosts
103
104 Steps:
105 - Fetch host data if not given
106 - Check Intent State
107 - Check Flow State
108 - Check Connectivity
109 - Check Lack of Connectivity Between Hosts not in the Intent
110 - Reroute
111 - Take Expected Link Down
112 - Check Intent State
113 - Check Flow State
114 - Check Topology
115 - Check Connectivity
116 - Bring Expected Link Up
117 - Check Intent State
118 - Check Flow State
119 - Check Topology
120 - Check Connectivity
121 - Remove Topology
122
123 Required:
124 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
125 intentId - intent ID to be tested ( and removed )
126 host1 - Dictionary for host1
127 { "name":"h8", "id":"of:0000000000000005/8" }
128 host2 - Dictionary for host2
129 { "name":"h16", "id":"of:0000000000000006/8" }
130 Optional:
131 onosNode - ONOS node to install the intents in main.CLIs[ ]
132 0 by default so that it will always use the first
133 ONOS node
134 sw1 - First switch to bring down & up for rerouting purpose
135 sw2 - Second switch to bring down & up for rerouting purpose
136 expectedLink - Expected link when the switches are down, it should
137 be two links lower than the links before the two
138 switches are down
139
140 """
141
142 # Parameter Validity Check
143 assert main, "There is no main variable"
144 assert host1, "You must specify host1"
145 assert host2, "You must specify host2"
146
147 global itemName
148 itemName = name
149 tempHostsData = {}
150 onosNode = int( onosNode )
151
Jeremy2f190ca2016-01-29 15:23:57 -0800152 main.log.info( itemName + ": Testing Host Intent" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800153
154 if not host1.get( "id" ):
155 main.log.warn( "Id not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
156 host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "location" )
157
158 if not host2.get( "id" ):
159 main.log.warn( "Id not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
160 host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "location" )
161
162 senderNames = [ host1.get( "name" ), host2.get( "name" ) ]
163 recipientNames = [ host1.get( "name" ), host2.get( "name" ) ]
164
165 testResult = main.TRUE
166 main.log.info( itemName + ": Adding single point to multi point intents" )
167
168 # Check intent state
169 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
170 main.assertReturnString += 'Initial Intent State Passed\n'
171 else:
172 main.assertReturnString += 'Initial Intent State Failed\n'
173 testResult = main.FALSE
174
175 # Check flows count in each node
176 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ] ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ] ):
177 main.assertReturnString += 'Initial Flow State Passed\n'
178 else:
179 main.assertReturnString += 'Intial Flow State Failed\n'
180 testResult = main.FALSE
181
182 # Check Connectivity
183 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames ) ):
184 main.assertReturnString += 'Initial Ping Passed\n'
185 else:
186 main.assertReturnString += 'Initial Ping Failed\n'
187 testResult = main.FALSE
188
189 # Test rerouting if these variables exist
190 if sw1 and sw2 and expectedLink:
191 # Take link down
192 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
193 main.assertReturnString += 'Link Down Passed\n'
194 else:
195 main.assertReturnString += 'Link Down Failed\n'
196 testResult = main.FALSE
197
198 # Check intent state
199 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
200 main.assertReturnString += 'Link Down Intent State Passed\n'
201 else:
202 main.assertReturnString += 'Link Down Intent State Failed\n'
203 testResult = main.FALSE
204
205 # Check flows count in each node
206 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ] ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ] ):
207 main.assertReturnString += 'Link Down Flow State Passed\n'
208 else:
209 main.assertReturnString += 'Link Down Flow State Failed\n'
210 testResult = main.FALSE
211
212 # Check OnosTopology
213 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink ) ):
214 main.assertReturnString += 'Link Down Topology State Passed\n'
215 else:
216 main.assertReturnString += 'Link Down Topology State Failed\n'
217 testResult = main.FALSE
218
219 # Check Connection
220 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames ) ):
221 main.assertReturnString += 'Link Down Pingall Passed\n'
222 else:
223 main.assertReturnString += 'Link Down Pingall Failed\n'
224 testResult = main.FALSE
225
226 # Bring link up
227 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
228 main.assertReturnString += 'Link Up Passed\n'
229 else:
230 main.assertReturnString += 'Link Up Failed\n'
231 testResult = main.FALSE
232
233 # Wait for reroute
234 time.sleep( main.rerouteSleep )
235
236 # Check Intents
237 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
238 main.assertReturnString += 'Link Up Intent State Passed\n'
239 else:
240 main.assertReturnString += 'Link Up Intent State Failed\n'
241 testResult = main.FALSE
242
243 # Check flows count in each node
244 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ] ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ] ):
245 main.assertReturnString += 'Link Up Flow State Passed\n'
246 else:
247 main.assertReturnString += 'Link Up Flow State Failed\n'
248 testResult = main.FALSE
249
250 # Check OnosTopology
251 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
252 main.assertReturnString += 'Link Up Topology State Passed\n'
253 else:
254 main.assertReturnString += 'Link Up Topology State Failed\n'
255 testResult = main.FALSE
256
257 # Check Connection
258 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames ) ):
259 main.assertReturnString += 'Link Up Pingall Passed\n'
260 else:
261 main.assertReturnString += 'Link Up Pingall Failed\n'
262 testResult = main.FALSE
263
264 # Remove all intents
265 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ):
266 main.assertReturnString += 'Remove Intents Passed'
267 else:
268 main.assertReturnString += 'Remove Intents Failed'
269 testResult = main.FALSE
270
271 return testResult
272
273def installPointIntent( main,
274 name,
275 senders,
276 recipients,
277 onosNode=0,
278 ethType="",
279 bandwidth="",
280 lambdaAlloc=False,
281 ipProto="",
282 ipSrc="",
283 ipDst="",
284 tcpSrc="",
285 tcpDst=""):
286 """
287 Installs a Single to Single Point Intent
288
289 Description:
290 Install a single to single point intent
291
292 Steps:
293 - Fetch host data if not given
294 - Add point intent
295 - Ingress device is the first sender device
296 - Egress device is the first recipient device
297 - Ports if defined in senders or recipients
298 - MAC address ethSrc loaded from Ingress device
299 - Check intent state with retry
300 Required:
301 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
302 senders - List of host dictionaries i.e.
303 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
304 recipients - List of host dictionaries i.e.
305 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
306 Optional:
307 onosNode - ONOS node to install the intents in main.CLIs[ ]
308 0 by default so that it will always use the first
309 ONOS node
310 ethType - Ethernet type eg. IPV4, IPV6
311 bandwidth - Bandwidth capacity
312 lambdaAlloc - Allocate lambda, defaults to False
313 ipProto - IP protocol
314 tcp - TCP ports in the same order as the hosts in hostNames
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700315 sw1 - First switch to bring down & up for rerouting purpose
316 sw2 - Second switch to bring down & up for rerouting purpose
317 expectedLink - Expected link when the switches are down, it should
318 be two links lower than the links before the two
319 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700320 """
321
322 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800323 assert senders, "You must specify a sender"
324 assert recipients, "You must specify a recipient"
325 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700326
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800327 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700328 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700329 onosNode = int( onosNode )
330
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800331 main.log.info( itemName + ": Adding mutli to single point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700332
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800333 for sender in senders:
334 if not sender.get( "device" ):
335 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
336 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
337
338 for recipient in recipients:
339 if not recipient.get( "device" ):
340 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
341 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
342
343
344 ingressDevice = senders[ 0 ].get( "device" )
345 egressDevice = recipients[ 0 ].get( "device" )
346
347 portIngress = senders[ 0 ].get( "port", "" )
348 portEgress = recipients[ 0 ].get( "port", "" )
349
350 dstMac = recipients[ 0 ].get( "mac" )
351
352 ipSrc = senders[ 0 ].get( "ip" )
353 ipDst = recipients[ 0 ].get( "ip" )
354
355 # Adding point intent
356 intentId = main.CLIs[ onosNode ].addPointIntent(
357 ingressDevice=ingressDevice,
358 egressDevice=egressDevice,
359 portIngress=portIngress,
360 portEgress=portEgress,
361 ethType=ethType,
362 ethDst=dstMac,
363 bandwidth=bandwidth,
364 lambdaAlloc=lambdaAlloc,
365 ipProto=ipProto,
366 ipSrc=ipSrc,
367 ipDst=ipDst,
368 tcpSrc=tcpSrc,
369 tcpDst=tcpDst )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700370
371 # Check intents state
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800372 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
373 return intentId
acsmarsd4862d12015-10-06 17:57:34 -0700374 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800375 main.log.error( "Point Intent did not install correctly" )
376 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700377
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700378def pointIntentTcp( main,
379 name,
380 host1,
381 host2,
382 onosNode=0,
383 deviceId1="",
384 deviceId2="",
385 port1="",
386 port2="",
387 ethType="",
388 mac1="",
389 mac2="",
390 bandwidth="",
391 lambdaAlloc=False,
392 ipProto="",
393 ip1="",
394 ip2="",
395 tcp1="",
396 tcp2="",
397 sw1="",
398 sw2="",
399 expectedLink=0 ):
400
401 """
402 Description:
403 Verify add-point-intent only for TCP
404 Steps:
405 - Get device ids | ports
406 - Add point intents
407 - Check intents
408 - Verify flows
409 - Ping hosts
410 - Reroute
411 - Link down
412 - Verify flows
413 - Check topology
414 - Ping hosts
415 - Link up
416 - Verify flows
417 - Check topology
418 - Ping hosts
419 - Remove intents
420 Required:
421 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
422 host1 - Name of first host
423 host2 - Name of second host
424 Optional:
425 onosNode - ONOS node to install the intents in main.CLIs[ ]
426 0 by default so that it will always use the first
427 ONOS node
428 deviceId1 - ONOS device id of the first switch, the same as the
429 location of the first host eg. of:0000000000000001/1,
430 located at device 1 port 1
431 deviceId2 - ONOS device id of the second switch
432 port1 - The port number where the first host is attached
433 port2 - The port number where the second host is attached
434 ethType - Ethernet type eg. IPV4, IPV6
435 mac1 - Mac address of first host
436 mac2 - Mac address of the second host
437 bandwidth - Bandwidth capacity
438 lambdaAlloc - Allocate lambda, defaults to False
439 ipProto - IP protocol
440 ip1 - IP address of first host
441 ip2 - IP address of second host
442 tcp1 - TCP port of first host
443 tcp2 - TCP port of second host
444 sw1 - First switch to bring down & up for rerouting purpose
445 sw2 - Second switch to bring down & up for rerouting purpose
446 expectedLink - Expected link when the switches are down, it should
447 be two links lower than the links before the two
448 switches are down
449 """
450
451 assert main, "There is no main variable"
452 assert name, "variable name is empty"
453 assert host1 and host2, "You must specify hosts"
454
455 global itemName
456 itemName = name
457 host1 = host1
458 host2 = host2
459 hostNames = [ host1, host2 ]
460 intentsId = []
461
462 iperfResult = main.TRUE
463 intentResult = main.TRUE
464 removeIntentResult = main.TRUE
465 flowResult = main.TRUE
466 topoResult = main.TRUE
467 linkDownResult = main.TRUE
468 linkUpResult = main.TRUE
469 onosNode = int( onosNode )
470
471 # Adding bidirectional point intents
472 main.log.info( itemName + ": Adding point intents" )
473 intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
474 egressDevice=deviceId2,
475 portIngress=port1,
476 portEgress=port2,
477 ethType=ethType,
478 ethSrc=mac1,
479 ethDst=mac2,
480 bandwidth=bandwidth,
481 lambdaAlloc=lambdaAlloc,
482 ipProto=ipProto,
483 ipSrc=ip1,
484 ipDst=ip2,
485 tcpSrc=tcp1,
486 tcpDst="" )
487
488 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
489 egressDevice=deviceId1,
490 portIngress=port2,
491 portEgress=port1,
492 ethType=ethType,
493 ethSrc=mac2,
494 ethDst=mac1,
495 bandwidth=bandwidth,
496 lambdaAlloc=lambdaAlloc,
497 ipProto=ipProto,
498 ipSrc=ip2,
499 ipDst=ip1,
500 tcpSrc=tcp2,
501 tcpDst="" )
502
503 intent3 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
504 egressDevice=deviceId2,
505 portIngress=port1,
506 portEgress=port2,
507 ethType=ethType,
508 ethSrc=mac1,
509 ethDst=mac2,
510 bandwidth=bandwidth,
511 lambdaAlloc=lambdaAlloc,
512 ipProto=ipProto,
513 ipSrc=ip1,
514 ipDst=ip2,
515 tcpSrc="",
516 tcpDst=tcp2 )
517
518 intent4 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
519 egressDevice=deviceId1,
520 portIngress=port2,
521 portEgress=port1,
522 ethType=ethType,
523 ethSrc=mac2,
524 ethDst=mac1,
525 bandwidth=bandwidth,
526 lambdaAlloc=lambdaAlloc,
527 ipProto=ipProto,
528 ipSrc=ip2,
529 ipDst=ip1,
530 tcpSrc="",
531 tcpDst=tcp1 )
532 intentsId.append( intent1 )
533 intentsId.append( intent2 )
534 intentsId.append( intent3 )
535 intentsId.append( intent4 )
536
537 # Check intents state
538 time.sleep( main.checkIntentSleep )
539 intentResult = checkIntentState( main, intentsId )
540 # Check flows count in each node
541 checkFlowsCount( main )
542
543 # Check intents state again if first check fails...
544 if not intentResult:
545 intentResult = checkIntentState( main, intentsId )
546
547 # Check flows count in each node
548 checkFlowsCount( main )
549
550 # Verify flows
551 checkFlowsState( main )
552
553 # Run iperf to both host
acsmarsd4862d12015-10-06 17:57:34 -0700554 iperfTemp = main.Mininet1.iperftcp( host1,host2,10 )
555 iperfResult = iperfResult and iperfTemp
556 if iperfTemp:
557 main.assertReturnString += 'Initial Iperf Passed\n'
558 else:
559 main.assertReturnString += 'Initial Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700560
561 # Test rerouting if these variables exist
562 if sw1 and sw2 and expectedLink:
563 # link down
564 linkDownResult = link( main, sw1, sw2, "down" )
acsmarsd4862d12015-10-06 17:57:34 -0700565
566 if linkDownResult:
567 main.assertReturnString += 'Link Down Passed\n'
568 else:
569 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700570
571 # Check flows count in each node
572 checkFlowsCount( main )
573 # Verify flows
574 checkFlowsState( main )
575
576 # Check OnosTopology
577 topoResult = checkTopology( main, expectedLink )
acsmarsd4862d12015-10-06 17:57:34 -0700578 if topoResult:
579 main.assertReturnString += 'Link Down Topology State Passed\n'
580 else:
581 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700582
583 # Run iperf to both host
acsmarsd4862d12015-10-06 17:57:34 -0700584 iperfTemp = main.Mininet1.iperftcp( host1,host2,10 )
585 iperfResult = iperfResult and iperfTemp
586 if iperfTemp:
587 main.assertReturnString += 'Link Down Iperf Passed\n'
588 else:
589 main.assertReturnString += 'Link Down Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700590
acsmarsd4862d12015-10-06 17:57:34 -0700591 # Check intent state
592 intentTemp = checkIntentState( main, intentsId )
593 intentResult = intentResult and intentTemp
594 if intentTemp:
595 main.assertReturnString += 'Link Down Intent State Passed\n'
596 else:
597 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700598
599 # Checks ONOS state in link down
600 if linkDownResult and topoResult and iperfResult and intentResult:
601 main.log.info( itemName + ": Successfully brought link down" )
602 else:
603 main.log.error( itemName + ": Failed to bring link down" )
604
605 # link up
606 linkUpResult = link( main, sw1, sw2, "up" )
acsmarsd4862d12015-10-06 17:57:34 -0700607 if linkUpTemp:
608 main.assertReturnString += 'Link Up Passed\n'
609 else:
610 main.assertReturnString += 'Link Up Failed\n'
611
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700612 time.sleep( main.rerouteSleep )
613
614 # Check flows count in each node
615 checkFlowsCount( main )
616 # Verify flows
617 checkFlowsState( main )
618
619 # Check OnosTopology
620 topoResult = checkTopology( main, main.numLinks )
621
acsmarsd4862d12015-10-06 17:57:34 -0700622 if topoResult:
623 main.assertReturnString += 'Link Up Topology State Passed\n'
624 else:
625 main.assertReturnString += 'Link Up Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700626
acsmarsd4862d12015-10-06 17:57:34 -0700627 # Run iperf to both host
628 iperfTemp = main.Mininet1.iperftcp( host1,host2,10 )
629 iperfResult = iperfResult and iperfTemp
630 if iperfTemp:
631 main.assertReturnString += 'Link Up Iperf Passed\n'
632 else:
633 main.assertReturnString += 'Link Up Iperf Failed\n'
634
635 # Check intent state
636 intentTemp = checkIntentState( main, intentsId )
637 intentResult = intentResult and intentTemp
638 if intentTemp:
639 main.assertReturnString += 'Link Down Intent State Passed\n'
640 else:
641 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700642
643 # Checks ONOS state in link up
644 if linkUpResult and topoResult and iperfResult and intentResult:
645 main.log.info( itemName + ": Successfully brought link back up" )
646 else:
647 main.log.error( itemName + ": Failed to bring link back up" )
648
649 # Remove all intents
650 removeIntentResult = removeAllIntents( main, intentsId )
acsmarsd4862d12015-10-06 17:57:34 -0700651 if removeIntentResult:
652 main.assertReturnString += 'Remove Intents Passed'
653 else:
654 main.assertReturnString += 'Remove Intents Failed'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700655
656 stepResult = iperfResult and linkDownResult and linkUpResult \
657 and intentResult and removeIntentResult
658
659 return stepResult
660
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800661def installSingleToMultiIntent( main,
662 name,
663 senders,
664 recipients,
665 onosNode=0,
666 ethType="",
667 bandwidth="",
668 lambdaAlloc=False,
669 ipProto="",
670 ipAddresses="",
671 tcp="",
672 sw1="",
673 sw2=""):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700674 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800675 Installs a Single to Multi Point Intent
676
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700677 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800678 Install a single to multi point intent using
679 add-single-to-multi-intent
680
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700681 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800682 - Fetch host data if not given
683 - Add single to multi intent
684 - Ingress device is the first sender host
685 - Egress devices are the recipient devices
686 - Ports if defined in senders or recipients
687 - MAC address ethSrc loaded from Ingress device
688 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700689 Required:
690 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800691 senders - List of host dictionaries i.e.
692 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
693 recipients - List of host dictionaries i.e.
694 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700695 Optional:
696 onosNode - ONOS node to install the intents in main.CLIs[ ]
697 0 by default so that it will always use the first
698 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700699 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700700 bandwidth - Bandwidth capacity
701 lambdaAlloc - Allocate lambda, defaults to False
702 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700703 tcp - TCP ports in the same order as the hosts in hostNames
704 sw1 - First switch to bring down & up for rerouting purpose
705 sw2 - Second switch to bring down & up for rerouting purpose
706 expectedLink - Expected link when the switches are down, it should
707 be two links lower than the links before the two
708 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700709 """
710
711 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800712 assert senders, "You must specify a sender"
713 assert recipients, "You must specify a recipient"
714 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700715
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800716 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700717 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700718 onosNode = int( onosNode )
719
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700720 main.log.info( itemName + ": Adding single point to multi point intents" )
721
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800722 for sender in senders:
723 if not sender.get( "device" ):
724 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
725 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700726
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800727 for recipient in recipients:
728 if not recipient.get( "device" ):
729 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
730 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700731
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700732
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800733 ingressDevice = senders[ 0 ].get( "device" )
734 egressDeviceList = [ x.get( "device" ) for x in recipients if x.get( "device" ) ]
735
736 portIngress = senders[ 0 ].get( "port", "" )
737 portEgressList = [ x.get( "port" ) for x in recipients if x.get( "port" ) ]
738 if not portEgressList:
739 portEgressList = None
740
741 srcMac = senders[ 0 ].get( "mac" )
742
743 # Adding point intent
744 intentId = main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
745 ingressDevice=ingressDevice,
746 egressDeviceList=egressDeviceList,
747 portIngress=portIngress,
748 portEgressList=portEgressList,
749 ethType=ethType,
750 ethSrc=srcMac,
751 bandwidth=bandwidth,
752 lambdaAlloc=lambdaAlloc,
753 ipProto=ipProto,
754 ipSrc="",
755 ipDst="",
756 tcpSrc="",
757 tcpDst="" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700758
759 # Check intents state
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800760 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
761 return intentId
acsmarsd4862d12015-10-06 17:57:34 -0700762 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800763 main.log.error( "Single to Multi Intent did not install correctly" )
764 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700765
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800766def installMultiToSingleIntent( main,
767 name,
768 senders,
769 recipients,
770 onosNode=0,
771 ethType="",
772 bandwidth="",
773 lambdaAlloc=False,
774 ipProto="",
775 ipAddresses="",
776 tcp="",
777 sw1="",
778 sw2=""):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700779 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800780 Installs a Multi to Single Point Intent
781
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700782 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800783 Install a multi to single point intent using
784 add-multi-to-single-intent
785
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700786 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800787 - Fetch host data if not given
788 - Add multi to single intent
789 - Ingress devices are the senders devices
790 - Egress device is the first recipient host
791 - Ports if defined in senders or recipients
792 - MAC address ethSrc loaded from Ingress device
793 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700794 Required:
795 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800796 senders - List of host dictionaries i.e.
797 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
798 recipients - List of host dictionaries i.e.
799 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700800 Optional:
801 onosNode - ONOS node to install the intents in main.CLIs[ ]
802 0 by default so that it will always use the first
803 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700804 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700805 bandwidth - Bandwidth capacity
806 lambdaAlloc - Allocate lambda, defaults to False
807 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700808 tcp - TCP ports in the same order as the hosts in hostNames
809 sw1 - First switch to bring down & up for rerouting purpose
810 sw2 - Second switch to bring down & up for rerouting purpose
811 expectedLink - Expected link when the switches are down, it should
812 be two links lower than the links before the two
813 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700814 """
815
816 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800817 assert senders, "You must specify a sender"
818 assert recipients, "You must specify a recipient"
819 # Assert devices or main.hostsData, "You must specify devices"
820
821 global itemName # The name of this run. Used for logs.
822 itemName = name
823 onosNode = int( onosNode )
824
825 main.log.info( itemName + ": Adding mutli to single point intents" )
826
827 for sender in senders:
828 if not sender.get( "device" ):
829 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
830 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
831
832 for recipient in recipients:
833 if not recipient.get( "device" ):
834 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
835 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
836
837
838 ingressDeviceList = [ x.get( "device" ) for x in senders if x.get( "device" ) ]
839 egressDevice = recipients[ 0 ].get( "device" )
840
841 portIngressList = [ x.get( "port" ) for x in senders if x.get( "port" ) ]
842 portEgress = recipients[ 0 ].get( "port", "" )
843 if not portIngressList:
844 portIngressList = None
845
846 dstMac = recipients[ 0 ].get( "mac" )
847
848 # Adding point intent
849 intentId = main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
850 ingressDeviceList=ingressDeviceList,
851 egressDevice=egressDevice,
852 portIngressList=portIngressList,
853 portEgress=portEgress,
854 ethType=ethType,
855 ethDst=dstMac,
856 bandwidth=bandwidth,
857 lambdaAlloc=lambdaAlloc,
858 ipProto=ipProto,
859 ipSrc="",
860 ipDst="",
861 tcpSrc="",
862 tcpDst="" )
863
864 # Check intents state
865 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
866 return intentId
867 else:
868 main.log.error( "Multi to Single Intent did not install correctly" )
869 return main.FALSE
870
871def testPointIntent( main,
Jeremye0cb5eb2016-01-27 17:39:09 -0800872 name,
873 intentId,
874 senders,
875 recipients,
876 badSenders={},
877 badRecipients={},
878 onosNode=0,
879 ethType="",
880 bandwidth="",
881 lambdaAlloc=False,
882 ipProto="",
883 ipAddresses="",
884 tcp="",
885 sw1="s5",
886 sw2="s2",
887 expectedLink=0):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800888 """
889 Test a Point Intent
890
891 Description:
892 Test a point intent
893
894 Steps:
895 - Fetch host data if not given
896 - Check Intent State
897 - Check Flow State
898 - Check Connectivity
899 - Check Lack of Connectivity Between Hosts not in the Intent
900 - Reroute
901 - Take Expected Link Down
902 - Check Intent State
903 - Check Flow State
904 - Check Topology
905 - Check Connectivity
906 - Bring Expected Link Up
907 - Check Intent State
908 - Check Flow State
909 - Check Topology
910 - Check Connectivity
911 - Remove Topology
912
913 Required:
914 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
915
916 senders - List of host dictionaries i.e.
917 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
918 recipients - List of host dictionaries i.e.
919 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
920 Optional:
921 onosNode - ONOS node to install the intents in main.CLIs[ ]
922 0 by default so that it will always use the first
923 ONOS node
924 ethType - Ethernet type eg. IPV4, IPV6
925 bandwidth - Bandwidth capacity
926 lambdaAlloc - Allocate lambda, defaults to False
927 ipProto - IP protocol
928 tcp - TCP ports in the same order as the hosts in hostNames
929 sw1 - First switch to bring down & up for rerouting purpose
930 sw2 - Second switch to bring down & up for rerouting purpose
931 expectedLink - Expected link when the switches are down, it should
932 be two links lower than the links before the two
933 switches are down
934
935 """
936
937 # Parameter Validity Check
938 assert main, "There is no main variable"
939 assert senders, "You must specify a sender"
940 assert recipients, "You must specify a recipient"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700941
942 global itemName
943 itemName = name
944 tempHostsData = {}
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700945 onosNode = int( onosNode )
946
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800947 main.log.info( itemName + ": Testing Point Intent" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700948
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800949 # Names for scapy
950 senderNames = [ x.get( "name" ) for x in senders ]
951 recipientNames = [ x.get( "name" ) for x in recipients ]
952 badSenderNames = [ x.get( "name" ) for x in badSenders ]
953 badRecipientNames = [ x.get( "name" ) for x in badRecipients ]
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700954
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800955 for sender in senders:
956 if not sender.get( "device" ):
957 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
958 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700959
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800960 for recipient in recipients:
961 if not recipient.get( "device" ):
962 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
963 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700964
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800965 testResult = main.TRUE
966 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700967
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800968 # Check intent state
969 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
970 main.assertReturnString += 'Initial Intent State Passed\n'
acsmarsd4862d12015-10-06 17:57:34 -0700971 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800972 main.assertReturnString += 'Initial Intent State Failed\n'
973 testResult = main.FALSE
974
975 # Check flows count in each node
976 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ] ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ] ):
977 main.assertReturnString += 'Initial Flow State Passed\n'
978 else:
979 main.assertReturnString += 'Intial Flow State Failed\n'
980 testResult = main.FALSE
981
982 # Check Connectivity
983 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames ) ):
984 main.assertReturnString += 'Initial Ping Passed\n'
985 else:
986 main.assertReturnString += 'Initial Ping Failed\n'
987 testResult = main.FALSE
988
989 # Check connections that shouldn't work
990 if badSenderNames:
991 main.log.info( "Checking that packets from incorrect sender do not go through" )
992 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, badSenderNames, recipientNames ), kwargs={ "expectFailure":True } ):
993 main.assertReturnString += 'Bad Sender Ping Passed\n'
994 else:
995 main.assertReturnString += 'Bad Sender Ping Failed\n'
996 testResult = main.FALSE
997
998 if badRecipientNames:
999 main.log.info( "Checking that packets to incorrect recipients do not go through" )
1000 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, badRecipientNames ), kwargs={ "expectFailure":True } ):
1001 main.assertReturnString += 'Bad Recipient Ping Passed\n'
1002 else:
1003 main.assertReturnString += 'Bad Recipient Ping Failed\n'
1004 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001005
1006 # Test rerouting if these variables exist
1007 if sw1 and sw2 and expectedLink:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001008 # Take link down
1009 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001010 main.assertReturnString += 'Link Down Passed\n'
1011 else:
1012 main.assertReturnString += 'Link Down Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001013 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001014
acsmarsd4862d12015-10-06 17:57:34 -07001015 # Check intent state
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001016 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001017 main.assertReturnString += 'Link Down Intent State Passed\n'
1018 else:
1019 main.assertReturnString += 'Link Down Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001020 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001021
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001022 # Check flows count in each node
1023 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ] ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ] ):
1024 main.assertReturnString += 'Link Down Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001025 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001026 main.assertReturnString += 'Link Down Flow State Failed\n'
1027 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001028
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001029 # Check OnosTopology
1030 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink ) ):
1031 main.assertReturnString += 'Link Down Topology State Passed\n'
1032 else:
1033 main.assertReturnString += 'Link Down Topology State Failed\n'
1034 testResult = main.FALSE
1035
1036 # Check Connection
1037 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames ) ):
1038 main.assertReturnString += 'Link Down Pingall Passed\n'
1039 else:
1040 main.assertReturnString += 'Link Down Pingall Failed\n'
1041 testResult = main.FALSE
1042
1043 # Bring link up
1044 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001045 main.assertReturnString += 'Link Up Passed\n'
1046 else:
1047 main.assertReturnString += 'Link Up Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001048 testResult = main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -07001049
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001050 # Wait for reroute
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001051 time.sleep( main.rerouteSleep )
1052
acsmarsd4862d12015-10-06 17:57:34 -07001053 # Check Intents
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001054 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001055 main.assertReturnString += 'Link Up Intent State Passed\n'
1056 else:
1057 main.assertReturnString += 'Link Up Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001058 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001059
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001060 # Check flows count in each node
1061 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ] ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ] ):
1062 main.assertReturnString += 'Link Up Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001063 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001064 main.assertReturnString += 'Link Up Flow State Failed\n'
1065 testResult = main.FALSE
1066
1067 # Check OnosTopology
1068 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
1069 main.assertReturnString += 'Link Up Topology State Passed\n'
1070 else:
1071 main.assertReturnString += 'Link Up Topology State Failed\n'
1072 testResult = main.FALSE
1073
1074 # Check Connection
1075 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames ) ):
1076 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1077 else:
1078 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1079 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001080
1081 # Remove all intents
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001082 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001083 main.assertReturnString += 'Remove Intents Passed'
1084 else:
1085 main.assertReturnString += 'Remove Intents Failed'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001086 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001087
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001088 return testResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001089
Jeremye0cb5eb2016-01-27 17:39:09 -08001090def testEndPointFail( main,
1091 name,
1092 intentId,
1093 senders,
1094 recipients,
1095 isolatedSenders,
1096 isolatedRecipients,
1097 onosNode=0,
1098 ethType="",
1099 bandwidth="",
1100 lambdaAlloc=False,
1101 ipProto="",
1102 ipAddresses="",
1103 tcp="",
1104 sw1="",
1105 sw2="",
1106 sw3="",
1107 sw4="",
1108 sw5="",
1109 expectedLink1=0,
1110 expectedLink2=0 ):
1111 """
1112 Test Single to Multipoint Topology for Endpoint failures
1113 """
1114
1115 # Parameter Validity Check
1116 assert main, "There is no main variable"
1117 assert senders, "You must specify a sender"
1118 assert recipients, "You must specify a recipient"
1119
1120 global itemName
1121 itemName = name
1122 tempHostsData = {}
1123 onosNode = int( onosNode )
1124
1125 main.log.info( itemName + ": Testing Point Intent" )
1126
1127 # Names for scapy
1128 senderNames = [ x.get( "name" ) for x in senders ]
1129 recipientNames = [ x.get( "name" ) for x in recipients ]
1130 isolatedSenderNames = [ x.get( "name" ) for x in isolatedSenders ]
1131 isolatedRecipientNames = [ x.get( "name" ) for x in isolatedRecipients ]
1132 connectedSenderNames = [x.get("name") for x in senders if x.get("name") not in isolatedSenderNames]
1133 connectedRecipientNames = [x.get("name") for x in recipients if x.get("name") not in isolatedRecipientNames]
1134
1135 for sender in senders:
1136 if not sender.get( "device" ):
1137 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1138 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
1139
1140 for recipient in recipients:
1141 if not recipient.get( "device" ):
1142 main.log.warn( "Device not given for recipient {0}. Loading from\
1143 main.hostData".format( recipient.get( "name" ) ) )
1144 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
1145
1146 testResult = main.TRUE
1147 main.log.info( itemName + ": Adding multi point to single point intents" )
1148
1149 # Check intent state
1150 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1151 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1152 main.assertReturnString += 'Initial Intent State Passed\n'
1153 else:
1154 main.assertReturnString += 'Initial Intent State Failed\n'
1155 testResult = main.FALSE
1156
1157 # Check flows count in each node
1158 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1159 args=[ main ] ) and utilities.retry( f=checkFlowsState,
1160 retValue=main.FALSE,
1161 args=[ main ] ):
1162 main.assertReturnString += 'Initial Flow State Passed\n'
1163 else:
1164 main.assertReturnString += 'Intial Flow State Failed\n'
1165 testResult = main.FALSE
1166
1167 # Check Connectivity
1168 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1169 args=( main, senderNames, recipientNames ) ):
1170 main.assertReturnString += 'Initial Connectivity Check Passed\n'
1171 else:
1172 main.assertReturnString += 'Initial Connectivity Check Failed\n'
1173 testResult = main.FALSE
1174
1175 # Take two links down
1176 # Take first link down
1177 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
1178 main.assertReturnString += 'Link Down Passed\n'
1179 else:
1180 main.assertReturnString += 'Link Down Failed\n'
1181 testResult = main.FALSE
1182
1183 # Take second link down
1184 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw4, "down" ) ):
1185 main.assertReturnString += 'Link Down Passed\n'
1186 else:
1187 main.assertReturnString += 'Link Down Failed\n'
1188 testResult = main.FALSE
1189
1190 # Check intent state
1191 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1192 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1193 main.assertReturnString += 'Link Down Intent State Passed\n'
1194 else:
1195 main.assertReturnString += 'Link Down Intent State Failed\n'
1196 testResult = main.FALSE
1197
1198 # Check flows count in each node
1199 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1200 args=[ main ] ) and utilities.retry( f=checkFlowsState,
1201 retValue=main.FALSE, args=[ main ] ):
1202 main.assertReturnString += 'Link Down Flow State Passed\n'
1203 else:
1204 main.assertReturnString += 'Link Down Flow State Failed\n'
1205 testResult = main.FALSE
1206
1207 # Check OnosTopology
1208 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink1 ) ):
1209 main.assertReturnString += 'Link Down Topology State Passed\n'
1210 else:
1211 main.assertReturnString += 'Link Down Topology State Failed\n'
1212 testResult = main.FALSE
1213
1214 # Check Connection
1215 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1216 args=( main, senderNames, recipientNames ) ):
1217 main.assertReturnString += 'Link Down Connectivity Check Passed\n'
1218 else:
1219 main.assertReturnString += 'Link Down Connectivity Check Failed\n'
1220 testResult = main.FALSE
1221
1222 # Take a third link down to isolate one node
1223 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw5, "down" ) ):
1224 main.assertReturnString += 'Isolation link Down Passed\n'
1225 else:
1226 main.assertReturnString += 'Isolation link Down Failed\n'
1227 testResult = main.FALSE
1228
1229 # Check intent state
1230 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1231 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1232 main.assertReturnString += 'Isolation link Down Intent State Passed\n'
1233 else:
1234 main.assertReturnString += 'Isolation link Down Intent State Failed\n'
1235 testResult = main.FALSE
1236
1237 # Check flows count in each node
1238 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1239 args=[ main ] ) and utilities.retry( f=checkFlowsState,
1240 retValue=main.FALSE, args=[ main ] ):
1241 main.assertReturnString += 'Isolation link Down Flow State Passed\n'
1242 else:
1243 main.assertReturnString += 'Isolation link Down Flow State Failed\n'
1244 testResult = main.FALSE
1245
1246 # Check OnosTopology
1247 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink2 ) ):
1248 main.assertReturnString += 'Isolation link Down Topology State Passed\n'
1249 else:
1250 main.assertReturnString += 'Isolation link Down Topology State Failed\n'
1251 testResult = main.FALSE
1252
1253 # Check Connectivity
1254 # First check connectivity of any isolated senders to recipients
1255 if isolatedSenderNames:
1256 if scapyCheckConnection( main, isolatedSenderNames, recipientNames, None, None, main.TRUE ):
1257 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1258 else:
1259 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1260 testResult = main.FALSE
1261
1262 # Next check connectivity of senders to any isolated recipients
1263 if isolatedRecipientNames:
1264 if scapyCheckConnection( main, senderNames, isolatedRecipientNames, None, None, main.TRUE ):
1265 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1266 else:
1267 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1268 testResult = main.FALSE
1269
1270 # Next check connectivity of connected senders and recipients
1271 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1272 args=( main, connectedSenderNames , connectedRecipientNames ) ):
1273 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1274 else:
1275 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1276 testResult = main.FALSE
1277
1278 # Bring the links back up
1279 # Bring first link up
1280 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
1281 main.assertReturnString += 'Link Up Passed\n'
1282 else:
1283 main.assertReturnString += 'Link Up Failed\n'
1284 testResult = main.FALSE
1285
1286 # Bring second link up
1287 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw5, "up" ) ):
1288 main.assertReturnString += 'Link Up Passed\n'
1289 else:
1290 main.assertReturnString += 'Link Up Failed\n'
1291 testResult = main.FALSE
1292
1293 # Bring third link up
1294 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw4, "up" ) ):
1295 main.assertReturnString += 'Link Up Passed\n'
1296 else:
1297 main.assertReturnString += 'Link Up Failed\n'
1298 testResult = main.FALSE
1299
1300 # Wait for reroute
1301 time.sleep( main.rerouteSleep )
1302
1303 # Check Intents
1304 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1305 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1306 main.assertReturnString += 'Link Up Intent State Passed\n'
1307 else:
1308 main.assertReturnString += 'Link Up Intent State Failed\n'
1309 testResult = main.FALSE
1310
1311 # Check flows count in each node
1312 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1313 args=[ main ] ) and utilities.retry( f=checkFlowsState,
1314 retValue=main.FALSE, args=[ main ] ):
1315 main.assertReturnString += 'Link Up Flow State Passed\n'
1316 else:
1317 main.assertReturnString += 'Link Up Flow State Failed\n'
1318 testResult = main.FALSE
1319
1320 # Check OnosTopology
1321 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
1322 main.assertReturnString += 'Link Up Topology State Passed\n'
1323 else:
1324 main.assertReturnString += 'Link Up Topology State Failed\n'
1325 testResult = main.FALSE
1326
1327 # Check Connection
1328 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1329 args=( main, senderNames, recipientNames ) ):
1330 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1331 else:
1332 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1333 testResult = main.FALSE
1334
1335 # Remove all intents
1336 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ):
1337 main.assertReturnString += 'Remove Intents Passed'
1338 else:
1339 main.assertReturnString += 'Remove Intents Failed'
1340 testResult = main.FALSE
1341
1342 return testResult
1343
1344
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001345def pingallHosts( main, hostList ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001346 """
1347 Ping all host in the hosts list variable
1348 """
Jon Halla5cb3412015-08-18 14:08:22 -07001349 main.log.info( "Pinging: " + str( hostList ) )
1350 return main.Mininet1.pingallHosts( hostList )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001351
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001352def fwdPingall( main ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001353 """
1354 Use fwd app and pingall to discover all the hosts
1355 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001356 activateResult = main.TRUE
1357 appCheck = main.TRUE
1358 getDataResult = main.TRUE
1359 main.log.info( "Activating reactive forwarding app " )
1360 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001361
1362 # Wait for forward app activation to propagate
kelvin-onlab0ad05d12015-07-23 14:21:15 -07001363 time.sleep( main.fwdSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001364
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001365 # Check that forwarding is enabled on all nodes
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001366 for i in range( main.numCtrls ):
1367 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
1368 if appCheck != main.TRUE:
1369 main.log.warn( main.CLIs[ i ].apps() )
1370 main.log.warn( main.CLIs[ i ].appIDs() )
1371
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001372 # Send pingall in mininet
1373 main.log.info( "Run Pingall" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001374 pingResult = main.Mininet1.pingall( timeout = 600 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001375
1376 main.log.info( "Deactivating reactive forwarding app " )
1377 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001378 if activateResult and deactivateResult:
1379 main.log.info( "Successfully used fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001380 getDataResult = main.TRUE
1381 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001382 main.log.info( "Failed to use fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001383 getDataResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001384 return getDataResult
1385
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001386def confirmHostDiscovery( main ):
1387 """
1388 Confirms that all ONOS nodes have discovered all scapy hosts
1389 """
1390 import collections
1391 scapyHostCount = len( main.scapyHosts )
1392 hosts = main.topo.getAllHosts( main ) # Get host data from each ONOS node
1393 hostFails = [] # Reset for each failed attempt
1394
1395 # Check for matching hosts on each node
1396 scapyHostIPs = [ x.hostIp for x in main.scapyHosts if x.hostIp != "0.0.0.0" ]
1397 for controller in range( main.numCtrls ):
1398 controllerStr = str( controller + 1 ) # ONOS node number
1399 # Compare Hosts
1400 # Load hosts data for controller node
1401 if hosts[ controller ] and "Error" not in hosts[ controller ]:
1402 try:
1403 hostData = json.loads( hosts[ controller ] )
1404 except ( TypeError, ValueError ):
1405 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
1406 hostFails.append( controllerStr )
1407 else:
1408 onosHostIPs = [ x.get( "ipAddresses" )[ 0 ]
1409 for x in hostData
1410 if len( x.get( "ipAddresses" ) ) > 0 ]
1411 if not set( collections.Counter( scapyHostIPs ) ).issubset( set ( collections.Counter( onosHostIPs ) ) ):
1412 main.log.warn( "Controller {0} only sees nodes with {1} IPs. It should see all of the following: {2}".format( controllerStr, onosHostIPs, scapyHostIPs ) )
1413 hostFails.append( controllerStr )
1414 else:
1415 main.log.error( "Hosts returned nothing or an error." )
1416 hostFails.append( controllerStr )
1417
1418 if hostFails:
1419 main.log.error( "List of failed ONOS Nodes:" + ', '.join(map(str, hostFails )) )
1420 return main.FALSE
1421 else:
1422 return main.TRUE
1423
1424def sendDiscoveryArp( main, hosts=None ):
1425 """
1426 Sends Discovery ARP packets from each host provided
1427 Defaults to each host in main.scapyHosts
1428 """
1429 # Send an arp ping from each host
1430 if not hosts:
1431 hosts = main.scapyHosts
1432 for host in hosts:
1433 pkt = 'Ether( src="{0}")/ARP( psrc="{1}")'.format( host.hostMac ,host.hostIp )
1434 # Send from the VLAN interface if there is one so ONOS discovers the VLAN correctly
1435 iface = None
1436 for interface in host.getIfList():
1437 if '.' in interface:
1438 main.log.debug( "Detected VLAN interface {0}. Sending ARP packet from {0}".format( interface ) )
1439 iface = interface
1440 break
1441 host.sendPacket( packet=pkt, iface=iface )
1442 main.log.info( "Sending ARP packet from {0}".format( host.name ) )
1443
1444def populateHostData( main ):
1445 """
1446 Populates hostsData
1447 """
1448 import json
1449 try:
1450 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
1451 hosts = main.Mininet1.getHosts().keys()
1452 # TODO: Make better use of new getHosts function
1453 for host in hosts:
1454 main.hostsData[ host ] = {}
1455 main.hostsData[ host ][ 'mac' ] = \
1456 main.Mininet1.getMacAddress( host ).upper()
1457 for hostj in hostsJson:
1458 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
1459 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
1460 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
1461 main.hostsData[ host ][ 'location' ] = \
1462 hostj[ 'location' ][ 'elementId' ] + '/' + \
1463 hostj[ 'location' ][ 'port' ]
1464 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
1465 return main.TRUE
1466 except KeyError:
1467 main.log.error( "KeyError while populating hostsData")
1468 return main.FALSE
1469
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001470def checkTopology( main, expectedLink ):
1471 statusResult = main.TRUE
1472 # Check onos topology
1473 main.log.info( itemName + ": Checking ONOS topology " )
1474
1475 for i in range( main.numCtrls ):
1476 topologyResult = main.CLIs[ i ].topology()
1477 statusResult = main.ONOSbench.checkStatus( topologyResult,
1478 main.numSwitch,
1479 expectedLink )\
1480 and statusResult
1481 if not statusResult:
1482 main.log.error( itemName + ": Topology mismatch" )
1483 else:
1484 main.log.info( itemName + ": Topology match" )
1485 return statusResult
1486
1487def checkIntentState( main, intentsId ):
1488 """
1489 This function will check intent state to make sure all the intents
1490 are in INSTALLED state
1491 """
1492
1493 intentResult = main.TRUE
1494 results = []
1495
1496 main.log.info( itemName + ": Checking intents state" )
1497 # First check of intents
1498 for i in range( main.numCtrls ):
1499 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
1500 results.append( tempResult )
1501
1502 expectedState = [ 'INSTALLED', 'INSTALLING' ]
1503
1504 if all( result == main.TRUE for result in results ):
1505 main.log.info( itemName + ": Intents are installed correctly" )
1506 else:
1507 # Wait for at least 5 second before checking the intents again
acsmarsb9a92692015-10-08 16:43:01 -07001508 main.log.error( "Intents are not installed correctly. Waiting 5 sec" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001509 time.sleep( 5 )
1510 results = []
1511 # Second check of intents since some of the intents may be in
1512 # INSTALLING state, they should be in INSTALLED at this time
1513 for i in range( main.numCtrls ):
Jeremy2f190ca2016-01-29 15:23:57 -08001514 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001515 results.append( tempResult )
1516 if all( result == main.TRUE for result in results ):
1517 main.log.info( itemName + ": Intents are installed correctly" )
acsmarsb9a92692015-10-08 16:43:01 -07001518 intentResult = main.TRUE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001519 else:
1520 main.log.error( itemName + ": Intents are NOT installed correctly" )
1521 intentResult = main.FALSE
1522
1523 return intentResult
1524
1525def checkFlowsState( main ):
1526
1527 main.log.info( itemName + ": Check flows state" )
1528 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState()
1529 return checkFlowsResult
1530
1531def link( main, sw1, sw2, option):
1532
1533 # link down
1534 main.log.info( itemName + ": Bring link " + option + "between " +
1535 sw1 + " and " + sw2 )
1536 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
1537 return linkResult
1538
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001539def scapyCheckConnection( main, senders, recipients, packet=None, packetFilter=None, expectFailure=False ):
1540 """
1541 Checks the connectivity between all given sender hosts and all given recipient hosts
1542 Packet may be specified. Defaults to Ether/IP packet
1543 Packet Filter may be specified. Defaults to Ether/IP from current sender MAC
1544 Todo: Optional packet and packet filter attributes for sender and recipients
1545 Expect Failure when the sender and recipient are not supposed to have connectivity
1546 Timeout of 1 second, returns main.TRUE if the filter is not triggered and kills the filter
1547
1548 """
1549 connectionsFunctional = main.TRUE
1550
1551 if not packetFilter:
1552 packetFilter = 'ether host {}'
1553
1554 if expectFailure:
1555 timeout = 1
1556 else:
1557 timeout = 10
1558
1559 for sender in senders:
1560 try:
1561 senderComp = getattr( main, sender )
1562 except AttributeError:
1563 main.log.error( "main has no attribute {}".format( sender ) )
1564 connectionsFunctional = main.FALSE
1565 continue
1566
1567 for recipient in recipients:
1568 # Do not send packets to self since recipient CLI will already be busy
1569 if recipient == sender:
1570 continue
1571 try:
1572 recipientComp = getattr( main, recipient )
1573 except AttributeError:
1574 main.log.error( "main has no attribute {}".format( recipient ) )
1575 connectionsFunctional = main.FALSE
1576 continue
1577
1578 recipientComp.startFilter( pktFilter = packetFilter.format( senderComp.hostMac ) )
1579
1580 if not packet:
1581 pkt = 'Ether( src="{0}", dst="{2}" )/IP( src="{1}", dst="{3}" )'.format(
1582 senderComp.hostMac,
1583 senderComp.hostIp,
1584 recipientComp.hostMac,
1585 recipientComp.hostIp )
1586 else:
1587 pkt = packet
1588 senderComp.sendPacket( packet = pkt )
1589
1590 if recipientComp.checkFilter( timeout ):
1591 if expectFailure:
1592 main.log.error( "Packet from {0} successfully received by {1} when it should not have been".format( sender , recipient ) )
1593 connectionsFunctional = main.FALSE
1594 else:
1595 main.log.info( "Packet from {0} successfully received by {1}".format( sender , recipient ) )
1596 else:
1597 recipientComp.killFilter()
1598 if expectFailure:
1599 main.log.info( "As expected, packet from {0} was not received by {1}".format( sender , recipient ) )
1600 else:
1601 main.log.error( "Packet from {0} was not received by {1}".format( sender , recipient ) )
1602 connectionsFunctional = main.FALSE
1603
1604 return connectionsFunctional
1605
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001606def removeAllIntents( main, intentsId ):
1607 """
1608 Remove all intents in the intentsId
1609 """
1610
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001611 onosSummary = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001612 removeIntentResult = main.TRUE
1613 # Remove intents
1614 for intent in intentsId:
1615 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
1616
acsmarscfa52272015-08-06 15:21:45 -07001617 time.sleep( main.removeIntentSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001618
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001619 # If there is remianing intents then remove intents should fail
1620 for i in range( main.numCtrls ):
1621 onosSummary.append( json.loads( main.CLIs[ i ].summary() ) )
1622
1623 for summary in onosSummary:
1624 if summary.get( 'intents' ) != 0:
1625 main.log.warn( itemName + ": There are " +
1626 str( summary.get( 'intents' ) ) +
1627 " intents remaining in node " +
1628 str( summary.get( 'node' ) ) +
1629 ", failed to remove all the intents " )
1630 removeIntentResult = main.FALSE
1631
1632 if removeIntentResult:
1633 main.log.info( itemName + ": There are no more intents remaining, " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001634 "successfully removed all the intents." )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001635
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001636 return removeIntentResult
1637
1638def checkFlowsCount( main ):
1639 """
1640 Check flows count in each node
1641 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001642 flowsCount = []
1643 main.log.info( itemName + ": Checking flows count in each ONOS node" )
1644 for i in range( main.numCtrls ):
1645 summaryResult = main.CLIs[ i ].summary()
1646 if not summaryResult:
1647 main.log.error( itemName + ": There is something wrong with " +
1648 "summary command" )
1649 return main.FALSE
1650 else:
1651 summaryJson = json.loads( summaryResult )
1652 flowsCount.append( summaryJson.get( 'flows' ) )
1653
1654 if flowsCount:
1655 if all( flows==flowsCount[ 0 ] for flows in flowsCount ):
1656 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
1657 " flows in all ONOS node" )
1658 else:
1659 for i in range( main.numCtrls ):
1660 main.log.debug( itemName + ": ONOS node " + str( i ) + " has " +
kelvin-onlab6dea6e62015-07-23 13:07:26 -07001661 str( flowsCount[ i ] ) + " flows" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001662 else:
1663 main.log.error( "Checking flows count failed, check summary command" )
1664 return main.FALSE
1665
1666 return main.TRUE
1667
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001668def checkLeaderChange( leaders1, leaders2 ):
acsmarse6b410f2015-07-17 14:39:34 -07001669 """
1670 Checks for a change in intent partition leadership.
1671
1672 Takes the output of leaders -c in json string format before and after
1673 a potential change as input
1674
1675 Returns main.TRUE if no mismatches are detected
1676 Returns main.FALSE if there is a mismatch or on error loading the input
1677 """
1678 try:
1679 leaders1 = json.loads( leaders1 )
1680 leaders2 = json.loads( leaders2 )
1681 except ( AttributeError, TypeError):
1682 main.log.exception( self.name + ": Object not as expected" )
1683 return main.FALSE
1684 except Exception:
1685 main.log.exception( self.name + ": Uncaught exception!" )
1686 main.cleanup()
1687 main.exit()
1688 main.log.info( "Checking Intent Paritions for Change in Leadership" )
1689 mismatch = False
1690 for dict1 in leaders1:
1691 if "intent" in dict1.get( "topic", [] ):
1692 for dict2 in leaders2:
1693 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \
1694 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
1695 mismatch = True
1696 main.log.error( "{0} changed leader from {1} to {2}".\
1697 format( dict1.get( "topic", "no-topic" ),\
1698 dict1.get( "leader", "no-leader" ),\
1699 dict2.get( "leader", "no-leader" ) ) )
1700 if mismatch:
1701 return main.FALSE
1702 else:
1703 return main.TRUE
kelvin-onlab016dce22015-08-10 09:54:11 -07001704
1705def report( main ):
1706 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001707 Report errors/warnings/exceptions
kelvin-onlab016dce22015-08-10 09:54:11 -07001708 """
kelvin-onlab016dce22015-08-10 09:54:11 -07001709 main.ONOSbench.logReport( main.ONOSip[ 0 ],
1710 [ "INFO",
1711 "FOLLOWER",
1712 "WARN",
1713 "flow",
1714 "ERROR",
1715 "Except" ],
1716 "s" )
1717
1718 main.log.info( "ERROR report: \n" )
1719 for i in range( main.numCtrls ):
1720 main.ONOSbench.logReport( main.ONOSip[ i ],
1721 [ "ERROR" ],
1722 "d" )
1723
1724 main.log.info( "EXCEPTIONS report: \n" )
1725 for i in range( main.numCtrls ):
1726 main.ONOSbench.logReport( main.ONOSip[ i ],
1727 [ "Except" ],
1728 "d" )
1729
1730 main.log.info( "WARNING report: \n" )
1731 for i in range( main.numCtrls ):
1732 main.ONOSbench.logReport( main.ONOSip[ i ],
1733 [ "WARN" ],
1734 "d" )