blob: dede2c850728149c7abd6c26816f786546479200 [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="",
Jeremy Songster832f9e92016-05-05 14:30:49 -070025 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" )
Jeremyd9e4eb12016-04-13 12:09:06 -070067 try:
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" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -080072
Jeremyd9e4eb12016-04-13 12:09:06 -070073 if not host2.get( "id" ):
74 main.log.warn( "ID not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
75 host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "id" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -080076
Jeremyd9e4eb12016-04-13 12:09:06 -070077 # Adding point intent
Jeremy Songster832f9e92016-05-05 14:30:49 -070078 vlanId = host1.get( "vlan" )
Jeremyd9e4eb12016-04-13 12:09:06 -070079 intentId = main.CLIs[ onosNode ].addHostIntent( hostIdOne=host1.get( "id" ),
Jeremy Songster832f9e92016-05-05 14:30:49 -070080 hostIdTwo=host2.get( "id" ),
81 vlanId=vlanId )
Jeremyd9e4eb12016-04-13 12:09:06 -070082 except (KeyError, TypeError):
83 errorMsg = "There was a problem loading the hosts data."
84 if intentId:
85 errorMsg += " There was a problem installing host to host intent."
86 main.log.error( errorMsg )
87 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -080088
89 # Check intents state
90 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
91 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
92 return intentId
93 else:
Jeremy2f190ca2016-01-29 15:23:57 -080094 main.log.error( "Host Intent did not install correctly" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -080095 return main.FALSE
96
97def testHostIntent( main,
98 name,
99 intentId,
100 host1,
101 host2,
102 onosNode=0,
103 sw1="s5",
104 sw2="s2",
105 expectedLink=0):
106 """
107 Test a Host Intent
108
109 Description:
110 Test a host intent of given ID between given hosts
111
112 Steps:
113 - Fetch host data if not given
114 - Check Intent State
115 - Check Flow State
116 - Check Connectivity
117 - Check Lack of Connectivity Between Hosts not in the Intent
118 - Reroute
119 - Take Expected Link Down
120 - Check Intent State
121 - Check Flow State
122 - Check Topology
123 - Check Connectivity
124 - Bring Expected Link Up
125 - Check Intent State
126 - Check Flow State
127 - Check Topology
128 - Check Connectivity
129 - Remove Topology
130
131 Required:
132 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
133 intentId - intent ID to be tested ( and removed )
134 host1 - Dictionary for host1
135 { "name":"h8", "id":"of:0000000000000005/8" }
136 host2 - Dictionary for host2
137 { "name":"h16", "id":"of:0000000000000006/8" }
138 Optional:
139 onosNode - ONOS node to install the intents in main.CLIs[ ]
140 0 by default so that it will always use the first
141 ONOS node
142 sw1 - First switch to bring down & up for rerouting purpose
143 sw2 - Second switch to bring down & up for rerouting purpose
144 expectedLink - Expected link when the switches are down, it should
145 be two links lower than the links before the two
146 switches are down
147
148 """
149
150 # Parameter Validity Check
151 assert main, "There is no main variable"
152 assert host1, "You must specify host1"
153 assert host2, "You must specify host2"
154
155 global itemName
156 itemName = name
157 tempHostsData = {}
158 onosNode = int( onosNode )
159
Jeremy2f190ca2016-01-29 15:23:57 -0800160 main.log.info( itemName + ": Testing Host Intent" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800161
Jeremyd9e4eb12016-04-13 12:09:06 -0700162 try:
163 if not host1.get( "id" ):
164 main.log.warn( "Id not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
165 host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800166
Jeremyd9e4eb12016-04-13 12:09:06 -0700167 if not host2.get( "id" ):
168 main.log.warn( "Id not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
169 host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800170
Jeremyd9e4eb12016-04-13 12:09:06 -0700171 senderNames = [ host1.get( "name" ), host2.get( "name" ) ]
172 recipientNames = [ host1.get( "name" ), host2.get( "name" ) ]
Jeremy Songster832f9e92016-05-05 14:30:49 -0700173 vlanId = host1.get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800174
Jeremyd9e4eb12016-04-13 12:09:06 -0700175 testResult = main.TRUE
176 except (KeyError, TypeError):
177 main.log.error( "There was a problem loading the hosts data." )
178 return main.FALSE
179
180 main.log.info( itemName + ": Testing Host to Host intents" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800181
182 # Check intent state
183 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
184 main.assertReturnString += 'Initial Intent State Passed\n'
185 else:
186 main.assertReturnString += 'Initial Intent State Failed\n'
187 testResult = main.FALSE
188
189 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -0700190 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800191 main.assertReturnString += 'Initial Flow State Passed\n'
192 else:
193 main.assertReturnString += 'Intial Flow State Failed\n'
194 testResult = main.FALSE
195
196 # Check Connectivity
Jeremy Songster832f9e92016-05-05 14:30:49 -0700197 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800198 main.assertReturnString += 'Initial Ping Passed\n'
199 else:
200 main.assertReturnString += 'Initial Ping Failed\n'
201 testResult = main.FALSE
202
203 # Test rerouting if these variables exist
204 if sw1 and sw2 and expectedLink:
205 # Take link down
206 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
207 main.assertReturnString += 'Link Down Passed\n'
208 else:
209 main.assertReturnString += 'Link Down Failed\n'
210 testResult = main.FALSE
211
212 # Check intent state
213 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
214 main.assertReturnString += 'Link Down Intent State Passed\n'
215 else:
216 main.assertReturnString += 'Link Down Intent State Failed\n'
217 testResult = main.FALSE
218
219 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -0700220 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800221 main.assertReturnString += 'Link Down Flow State Passed\n'
222 else:
223 main.assertReturnString += 'Link Down Flow State Failed\n'
224 testResult = main.FALSE
225
226 # Check OnosTopology
227 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink ) ):
228 main.assertReturnString += 'Link Down Topology State Passed\n'
229 else:
230 main.assertReturnString += 'Link Down Topology State Failed\n'
231 testResult = main.FALSE
232
233 # Check Connection
Jeremy Songster832f9e92016-05-05 14:30:49 -0700234 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800235 main.assertReturnString += 'Link Down Pingall Passed\n'
236 else:
237 main.assertReturnString += 'Link Down Pingall Failed\n'
238 testResult = main.FALSE
239
240 # Bring link up
241 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
242 main.assertReturnString += 'Link Up Passed\n'
243 else:
244 main.assertReturnString += 'Link Up Failed\n'
245 testResult = main.FALSE
246
247 # Wait for reroute
248 time.sleep( main.rerouteSleep )
249
250 # Check Intents
251 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
252 main.assertReturnString += 'Link Up Intent State Passed\n'
253 else:
254 main.assertReturnString += 'Link Up Intent State Failed\n'
255 testResult = main.FALSE
256
257 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -0700258 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800259 main.assertReturnString += 'Link Up Flow State Passed\n'
260 else:
261 main.assertReturnString += 'Link Up Flow State Failed\n'
262 testResult = main.FALSE
263
264 # Check OnosTopology
265 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
266 main.assertReturnString += 'Link Up Topology State Passed\n'
267 else:
268 main.assertReturnString += 'Link Up Topology State Failed\n'
269 testResult = main.FALSE
270
271 # Check Connection
Jeremy Songster832f9e92016-05-05 14:30:49 -0700272 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800273 main.assertReturnString += 'Link Up Pingall Passed\n'
274 else:
275 main.assertReturnString += 'Link Up Pingall Failed\n'
276 testResult = main.FALSE
277
278 # Remove all intents
279 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ):
280 main.assertReturnString += 'Remove Intents Passed'
281 else:
282 main.assertReturnString += 'Remove Intents Failed'
283 testResult = main.FALSE
284
285 return testResult
286
287def installPointIntent( main,
288 name,
289 senders,
290 recipients,
291 onosNode=0,
292 ethType="",
293 bandwidth="",
294 lambdaAlloc=False,
295 ipProto="",
296 ipSrc="",
297 ipDst="",
298 tcpSrc="",
299 tcpDst=""):
300 """
301 Installs a Single to Single Point Intent
302
303 Description:
304 Install a single to single point intent
305
306 Steps:
307 - Fetch host data if not given
308 - Add point intent
309 - Ingress device is the first sender device
310 - Egress device is the first recipient device
311 - Ports if defined in senders or recipients
312 - MAC address ethSrc loaded from Ingress device
313 - Check intent state with retry
314 Required:
315 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
316 senders - List of host dictionaries i.e.
317 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
318 recipients - List of host dictionaries i.e.
319 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
320 Optional:
321 onosNode - ONOS node to install the intents in main.CLIs[ ]
322 0 by default so that it will always use the first
323 ONOS node
324 ethType - Ethernet type eg. IPV4, IPV6
325 bandwidth - Bandwidth capacity
326 lambdaAlloc - Allocate lambda, defaults to False
327 ipProto - IP protocol
328 tcp - TCP ports in the same order as the hosts in hostNames
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700329 sw1 - First switch to bring down & up for rerouting purpose
330 sw2 - Second switch to bring down & up for rerouting purpose
331 expectedLink - Expected link when the switches are down, it should
332 be two links lower than the links before the two
333 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700334 """
335
336 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800337 assert senders, "You must specify a sender"
338 assert recipients, "You must specify a recipient"
339 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700340
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800341 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700342 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700343 onosNode = int( onosNode )
344
Jeremy6f000c62016-02-25 17:02:28 -0800345 main.log.info( itemName + ": Adding point to point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700346
Jeremyd9e4eb12016-04-13 12:09:06 -0700347 try:
348 for sender in senders:
349 if not sender.get( "device" ):
350 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
351 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800352
Jeremyd9e4eb12016-04-13 12:09:06 -0700353 for recipient in recipients:
354 if not recipient.get( "device" ):
355 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
356 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800357
358
Jeremyd9e4eb12016-04-13 12:09:06 -0700359 ingressDevice = senders[ 0 ].get( "device" )
360 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800361
Jeremyd9e4eb12016-04-13 12:09:06 -0700362 portIngress = senders[ 0 ].get( "port", "" )
363 portEgress = recipients[ 0 ].get( "port", "" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800364
Jeremyd9e4eb12016-04-13 12:09:06 -0700365 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800366
Jeremyd9e4eb12016-04-13 12:09:06 -0700367 ipSrc = senders[ 0 ].get( "ip" )
368 ipDst = recipients[ 0 ].get( "ip" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800369
Jeremy Songster832f9e92016-05-05 14:30:49 -0700370 vlanId = senders[ 0 ].get( "vlan" )
371
Jeremyd9e4eb12016-04-13 12:09:06 -0700372 # Adding point intent
373 intentId = main.CLIs[ onosNode ].addPointIntent(
374 ingressDevice=ingressDevice,
375 egressDevice=egressDevice,
376 portIngress=portIngress,
377 portEgress=portEgress,
378 ethType=ethType,
379 ethDst=dstMac,
380 bandwidth=bandwidth,
381 lambdaAlloc=lambdaAlloc,
382 ipProto=ipProto,
383 ipSrc=ipSrc,
384 ipDst=ipDst,
385 tcpSrc=tcpSrc,
Jeremy Songster832f9e92016-05-05 14:30:49 -0700386 tcpDst=tcpDst,
387 vlanId=vlanId )
Jeremyd9e4eb12016-04-13 12:09:06 -0700388 except (KeyError, TypeError):
389 errorMsg = "There was a problem loading the hosts data."
390 if intentId:
391 errorMsg += " There was a problem installing Point to Point intent."
392 main.log.error( errorMsg )
393 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700394
395 # Check intents state
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800396 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
397 return intentId
acsmarsd4862d12015-10-06 17:57:34 -0700398 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800399 main.log.error( "Point Intent did not install correctly" )
400 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700401
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700402def pointIntentTcp( main,
403 name,
404 host1,
405 host2,
406 onosNode=0,
407 deviceId1="",
408 deviceId2="",
409 port1="",
410 port2="",
411 ethType="",
412 mac1="",
413 mac2="",
414 bandwidth="",
415 lambdaAlloc=False,
416 ipProto="",
417 ip1="",
418 ip2="",
419 tcp1="",
420 tcp2="",
421 sw1="",
422 sw2="",
423 expectedLink=0 ):
424
425 """
426 Description:
427 Verify add-point-intent only for TCP
428 Steps:
429 - Get device ids | ports
430 - Add point intents
431 - Check intents
432 - Verify flows
433 - Ping hosts
434 - Reroute
435 - Link down
436 - Verify flows
437 - Check topology
438 - Ping hosts
439 - Link up
440 - Verify flows
441 - Check topology
442 - Ping hosts
443 - Remove intents
444 Required:
445 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
446 host1 - Name of first host
447 host2 - Name of second host
448 Optional:
449 onosNode - ONOS node to install the intents in main.CLIs[ ]
450 0 by default so that it will always use the first
451 ONOS node
452 deviceId1 - ONOS device id of the first switch, the same as the
453 location of the first host eg. of:0000000000000001/1,
454 located at device 1 port 1
455 deviceId2 - ONOS device id of the second switch
456 port1 - The port number where the first host is attached
457 port2 - The port number where the second host is attached
458 ethType - Ethernet type eg. IPV4, IPV6
459 mac1 - Mac address of first host
460 mac2 - Mac address of the second host
461 bandwidth - Bandwidth capacity
462 lambdaAlloc - Allocate lambda, defaults to False
463 ipProto - IP protocol
464 ip1 - IP address of first host
465 ip2 - IP address of second host
466 tcp1 - TCP port of first host
467 tcp2 - TCP port of second host
468 sw1 - First switch to bring down & up for rerouting purpose
469 sw2 - Second switch to bring down & up for rerouting purpose
470 expectedLink - Expected link when the switches are down, it should
471 be two links lower than the links before the two
472 switches are down
473 """
474
475 assert main, "There is no main variable"
476 assert name, "variable name is empty"
477 assert host1 and host2, "You must specify hosts"
478
479 global itemName
480 itemName = name
481 host1 = host1
482 host2 = host2
483 hostNames = [ host1, host2 ]
484 intentsId = []
485
486 iperfResult = main.TRUE
487 intentResult = main.TRUE
488 removeIntentResult = main.TRUE
489 flowResult = main.TRUE
490 topoResult = main.TRUE
491 linkDownResult = main.TRUE
492 linkUpResult = main.TRUE
493 onosNode = int( onosNode )
494
495 # Adding bidirectional point intents
496 main.log.info( itemName + ": Adding point intents" )
497 intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
498 egressDevice=deviceId2,
499 portIngress=port1,
500 portEgress=port2,
501 ethType=ethType,
502 ethSrc=mac1,
503 ethDst=mac2,
504 bandwidth=bandwidth,
505 lambdaAlloc=lambdaAlloc,
506 ipProto=ipProto,
507 ipSrc=ip1,
508 ipDst=ip2,
509 tcpSrc=tcp1,
510 tcpDst="" )
511
512 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
513 egressDevice=deviceId1,
514 portIngress=port2,
515 portEgress=port1,
516 ethType=ethType,
517 ethSrc=mac2,
518 ethDst=mac1,
519 bandwidth=bandwidth,
520 lambdaAlloc=lambdaAlloc,
521 ipProto=ipProto,
522 ipSrc=ip2,
523 ipDst=ip1,
524 tcpSrc=tcp2,
525 tcpDst="" )
526
527 intent3 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
528 egressDevice=deviceId2,
529 portIngress=port1,
530 portEgress=port2,
531 ethType=ethType,
532 ethSrc=mac1,
533 ethDst=mac2,
534 bandwidth=bandwidth,
535 lambdaAlloc=lambdaAlloc,
536 ipProto=ipProto,
537 ipSrc=ip1,
538 ipDst=ip2,
539 tcpSrc="",
540 tcpDst=tcp2 )
541
542 intent4 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
543 egressDevice=deviceId1,
544 portIngress=port2,
545 portEgress=port1,
546 ethType=ethType,
547 ethSrc=mac2,
548 ethDst=mac1,
549 bandwidth=bandwidth,
550 lambdaAlloc=lambdaAlloc,
551 ipProto=ipProto,
552 ipSrc=ip2,
553 ipDst=ip1,
554 tcpSrc="",
555 tcpDst=tcp1 )
556 intentsId.append( intent1 )
557 intentsId.append( intent2 )
558 intentsId.append( intent3 )
559 intentsId.append( intent4 )
560
561 # Check intents state
562 time.sleep( main.checkIntentSleep )
563 intentResult = checkIntentState( main, intentsId )
564 # Check flows count in each node
565 checkFlowsCount( main )
566
567 # Check intents state again if first check fails...
568 if not intentResult:
569 intentResult = checkIntentState( main, intentsId )
570
571 # Check flows count in each node
572 checkFlowsCount( main )
573
574 # Verify flows
575 checkFlowsState( main )
576
577 # Run iperf to both host
acsmarsd4862d12015-10-06 17:57:34 -0700578 iperfTemp = main.Mininet1.iperftcp( host1,host2,10 )
579 iperfResult = iperfResult and iperfTemp
580 if iperfTemp:
581 main.assertReturnString += 'Initial Iperf Passed\n'
582 else:
583 main.assertReturnString += 'Initial Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700584
585 # Test rerouting if these variables exist
586 if sw1 and sw2 and expectedLink:
587 # link down
588 linkDownResult = link( main, sw1, sw2, "down" )
acsmarsd4862d12015-10-06 17:57:34 -0700589
590 if linkDownResult:
591 main.assertReturnString += 'Link Down Passed\n'
592 else:
593 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700594
595 # Check flows count in each node
596 checkFlowsCount( main )
597 # Verify flows
598 checkFlowsState( main )
599
600 # Check OnosTopology
601 topoResult = checkTopology( main, expectedLink )
acsmarsd4862d12015-10-06 17:57:34 -0700602 if topoResult:
603 main.assertReturnString += 'Link Down Topology State Passed\n'
604 else:
605 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700606
607 # Run iperf to both host
acsmarsd4862d12015-10-06 17:57:34 -0700608 iperfTemp = main.Mininet1.iperftcp( host1,host2,10 )
609 iperfResult = iperfResult and iperfTemp
610 if iperfTemp:
611 main.assertReturnString += 'Link Down Iperf Passed\n'
612 else:
613 main.assertReturnString += 'Link Down Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700614
acsmarsd4862d12015-10-06 17:57:34 -0700615 # Check intent state
616 intentTemp = checkIntentState( main, intentsId )
617 intentResult = intentResult and intentTemp
618 if intentTemp:
619 main.assertReturnString += 'Link Down Intent State Passed\n'
620 else:
621 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700622
623 # Checks ONOS state in link down
624 if linkDownResult and topoResult and iperfResult and intentResult:
625 main.log.info( itemName + ": Successfully brought link down" )
626 else:
627 main.log.error( itemName + ": Failed to bring link down" )
628
629 # link up
630 linkUpResult = link( main, sw1, sw2, "up" )
acsmarsd4862d12015-10-06 17:57:34 -0700631 if linkUpTemp:
632 main.assertReturnString += 'Link Up Passed\n'
633 else:
634 main.assertReturnString += 'Link Up Failed\n'
635
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700636 time.sleep( main.rerouteSleep )
637
638 # Check flows count in each node
639 checkFlowsCount( main )
640 # Verify flows
641 checkFlowsState( main )
642
643 # Check OnosTopology
644 topoResult = checkTopology( main, main.numLinks )
645
acsmarsd4862d12015-10-06 17:57:34 -0700646 if topoResult:
647 main.assertReturnString += 'Link Up Topology State Passed\n'
648 else:
649 main.assertReturnString += 'Link Up Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700650
acsmarsd4862d12015-10-06 17:57:34 -0700651 # Run iperf to both host
652 iperfTemp = main.Mininet1.iperftcp( host1,host2,10 )
653 iperfResult = iperfResult and iperfTemp
654 if iperfTemp:
655 main.assertReturnString += 'Link Up Iperf Passed\n'
656 else:
657 main.assertReturnString += 'Link Up Iperf Failed\n'
658
659 # Check intent state
660 intentTemp = checkIntentState( main, intentsId )
661 intentResult = intentResult and intentTemp
662 if intentTemp:
663 main.assertReturnString += 'Link Down Intent State Passed\n'
664 else:
665 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700666
667 # Checks ONOS state in link up
668 if linkUpResult and topoResult and iperfResult and intentResult:
669 main.log.info( itemName + ": Successfully brought link back up" )
670 else:
671 main.log.error( itemName + ": Failed to bring link back up" )
672
673 # Remove all intents
674 removeIntentResult = removeAllIntents( main, intentsId )
acsmarsd4862d12015-10-06 17:57:34 -0700675 if removeIntentResult:
676 main.assertReturnString += 'Remove Intents Passed'
677 else:
678 main.assertReturnString += 'Remove Intents Failed'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700679
680 stepResult = iperfResult and linkDownResult and linkUpResult \
681 and intentResult and removeIntentResult
682
683 return stepResult
684
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800685def installSingleToMultiIntent( main,
686 name,
687 senders,
688 recipients,
689 onosNode=0,
690 ethType="",
691 bandwidth="",
692 lambdaAlloc=False,
693 ipProto="",
694 ipAddresses="",
695 tcp="",
696 sw1="",
697 sw2=""):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700698 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800699 Installs a Single to Multi Point Intent
700
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700701 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800702 Install a single to multi point intent using
703 add-single-to-multi-intent
704
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700705 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800706 - Fetch host data if not given
707 - Add single to multi intent
708 - Ingress device is the first sender host
709 - Egress devices are the recipient devices
710 - Ports if defined in senders or recipients
711 - MAC address ethSrc loaded from Ingress device
712 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700713 Required:
714 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800715 senders - List of host dictionaries i.e.
716 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
717 recipients - List of host dictionaries i.e.
718 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700719 Optional:
720 onosNode - ONOS node to install the intents in main.CLIs[ ]
721 0 by default so that it will always use the first
722 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700723 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700724 bandwidth - Bandwidth capacity
725 lambdaAlloc - Allocate lambda, defaults to False
726 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700727 tcp - TCP ports in the same order as the hosts in hostNames
728 sw1 - First switch to bring down & up for rerouting purpose
729 sw2 - Second switch to bring down & up for rerouting purpose
730 expectedLink - Expected link when the switches are down, it should
731 be two links lower than the links before the two
732 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700733 """
734
735 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800736 assert senders, "You must specify a sender"
737 assert recipients, "You must specify a recipient"
738 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700739
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800740 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700741 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700742 onosNode = int( onosNode )
743
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700744 main.log.info( itemName + ": Adding single point to multi point intents" )
745
Jeremyd9e4eb12016-04-13 12:09:06 -0700746 try:
747 for sender in senders:
748 if not sender.get( "device" ):
749 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
750 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700751
Jeremyd9e4eb12016-04-13 12:09:06 -0700752 for recipient in recipients:
753 if not recipient.get( "device" ):
754 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
755 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700756
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700757
Jeremyd9e4eb12016-04-13 12:09:06 -0700758 ingressDevice = senders[ 0 ].get( "device" )
759 egressDeviceList = [ x.get( "device" ) for x in recipients if x.get( "device" ) ]
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800760
Jeremyd9e4eb12016-04-13 12:09:06 -0700761 portIngress = senders[ 0 ].get( "port", "" )
762 portEgressList = [ x.get( "port" ) for x in recipients if x.get( "port" ) ]
763 if not portEgressList:
764 portEgressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800765
Jeremyd9e4eb12016-04-13 12:09:06 -0700766 srcMac = senders[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700767 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800768
Jeremyd9e4eb12016-04-13 12:09:06 -0700769 # Adding point intent
770 intentId = main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
771 ingressDevice=ingressDevice,
772 egressDeviceList=egressDeviceList,
773 portIngress=portIngress,
774 portEgressList=portEgressList,
775 ethType=ethType,
776 ethSrc=srcMac,
777 bandwidth=bandwidth,
778 lambdaAlloc=lambdaAlloc,
779 ipProto=ipProto,
780 ipSrc="",
781 ipDst="",
782 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -0700783 tcpDst="",
784 vlanId=vlanId )
Jeremyd9e4eb12016-04-13 12:09:06 -0700785 except (KeyError, TypeError):
786 errorMsg = "There was a problem loading the hosts data."
787 if intentId:
788 errorMsg += " There was a problem installing Singlepoint to Multipoint intent."
789 main.log.error( errorMsg )
790 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700791
792 # Check intents state
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800793 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
794 return intentId
acsmarsd4862d12015-10-06 17:57:34 -0700795 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800796 main.log.error( "Single to Multi Intent did not install correctly" )
797 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700798
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800799def installMultiToSingleIntent( main,
800 name,
801 senders,
802 recipients,
803 onosNode=0,
804 ethType="",
805 bandwidth="",
806 lambdaAlloc=False,
807 ipProto="",
808 ipAddresses="",
809 tcp="",
810 sw1="",
811 sw2=""):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700812 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800813 Installs a Multi to Single Point Intent
814
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700815 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800816 Install a multi to single point intent using
817 add-multi-to-single-intent
818
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700819 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800820 - Fetch host data if not given
821 - Add multi to single intent
822 - Ingress devices are the senders devices
823 - Egress device is the first recipient host
824 - Ports if defined in senders or recipients
825 - MAC address ethSrc loaded from Ingress device
826 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700827 Required:
828 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800829 senders - List of host dictionaries i.e.
830 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
831 recipients - List of host dictionaries i.e.
832 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700833 Optional:
834 onosNode - ONOS node to install the intents in main.CLIs[ ]
835 0 by default so that it will always use the first
836 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700837 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700838 bandwidth - Bandwidth capacity
839 lambdaAlloc - Allocate lambda, defaults to False
840 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700841 tcp - TCP ports in the same order as the hosts in hostNames
842 sw1 - First switch to bring down & up for rerouting purpose
843 sw2 - Second switch to bring down & up for rerouting purpose
844 expectedLink - Expected link when the switches are down, it should
845 be two links lower than the links before the two
846 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700847 """
848
849 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800850 assert senders, "You must specify a sender"
851 assert recipients, "You must specify a recipient"
852 # Assert devices or main.hostsData, "You must specify devices"
853
854 global itemName # The name of this run. Used for logs.
855 itemName = name
856 onosNode = int( onosNode )
857
858 main.log.info( itemName + ": Adding mutli to single point intents" )
859
Jeremyd9e4eb12016-04-13 12:09:06 -0700860 try:
861 for sender in senders:
862 if not sender.get( "device" ):
863 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
864 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800865
Jeremyd9e4eb12016-04-13 12:09:06 -0700866 for recipient in recipients:
867 if not recipient.get( "device" ):
868 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
869 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800870
Jeremyd9e4eb12016-04-13 12:09:06 -0700871 ingressDeviceList = [ x.get( "device" ) for x in senders if x.get( "device" ) ]
872 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800873
Jeremyd9e4eb12016-04-13 12:09:06 -0700874 portIngressList = [ x.get( "port" ) for x in senders if x.get( "port" ) ]
875 portEgress = recipients[ 0 ].get( "port", "" )
876 if not portIngressList:
877 portIngressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800878
Jeremyd9e4eb12016-04-13 12:09:06 -0700879 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700880 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800881
Jeremyd9e4eb12016-04-13 12:09:06 -0700882 # Adding point intent
883 intentId = main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
884 ingressDeviceList=ingressDeviceList,
885 egressDevice=egressDevice,
886 portIngressList=portIngressList,
887 portEgress=portEgress,
888 ethType=ethType,
889 ethDst=dstMac,
890 bandwidth=bandwidth,
891 lambdaAlloc=lambdaAlloc,
892 ipProto=ipProto,
893 ipSrc="",
894 ipDst="",
895 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -0700896 tcpDst="",
897 vlanId=vlanId )
Jeremyd9e4eb12016-04-13 12:09:06 -0700898 except (KeyError, TypeError):
899 errorMsg = "There was a problem loading the hosts data."
900 if intentId:
901 errorMsg += " There was a problem installing Multipoint to Singlepoint intent."
902 main.log.error( errorMsg )
903 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800904
905 # Check intents state
906 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
907 return intentId
908 else:
909 main.log.error( "Multi to Single Intent did not install correctly" )
910 return main.FALSE
911
912def testPointIntent( main,
Jeremye0cb5eb2016-01-27 17:39:09 -0800913 name,
914 intentId,
915 senders,
916 recipients,
917 badSenders={},
918 badRecipients={},
919 onosNode=0,
920 ethType="",
921 bandwidth="",
922 lambdaAlloc=False,
923 ipProto="",
924 ipAddresses="",
925 tcp="",
926 sw1="s5",
927 sw2="s2",
928 expectedLink=0):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800929 """
930 Test a Point Intent
931
932 Description:
933 Test a point intent
934
935 Steps:
936 - Fetch host data if not given
937 - Check Intent State
938 - Check Flow State
939 - Check Connectivity
940 - Check Lack of Connectivity Between Hosts not in the Intent
941 - Reroute
942 - Take Expected Link Down
943 - Check Intent State
944 - Check Flow State
945 - Check Topology
946 - Check Connectivity
947 - Bring Expected Link Up
948 - Check Intent State
949 - Check Flow State
950 - Check Topology
951 - Check Connectivity
952 - Remove Topology
953
954 Required:
955 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
956
957 senders - List of host dictionaries i.e.
958 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
959 recipients - List of host dictionaries i.e.
960 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
961 Optional:
962 onosNode - ONOS node to install the intents in main.CLIs[ ]
963 0 by default so that it will always use the first
964 ONOS node
965 ethType - Ethernet type eg. IPV4, IPV6
966 bandwidth - Bandwidth capacity
967 lambdaAlloc - Allocate lambda, defaults to False
968 ipProto - IP protocol
969 tcp - TCP ports in the same order as the hosts in hostNames
970 sw1 - First switch to bring down & up for rerouting purpose
971 sw2 - Second switch to bring down & up for rerouting purpose
972 expectedLink - Expected link when the switches are down, it should
973 be two links lower than the links before the two
974 switches are down
975
976 """
977
978 # Parameter Validity Check
979 assert main, "There is no main variable"
980 assert senders, "You must specify a sender"
981 assert recipients, "You must specify a recipient"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700982
983 global itemName
984 itemName = name
985 tempHostsData = {}
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700986 onosNode = int( onosNode )
987
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800988 main.log.info( itemName + ": Testing Point Intent" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700989
Jeremyd9e4eb12016-04-13 12:09:06 -0700990 try:
991 # Names for scapy
992 senderNames = [ x.get( "name" ) for x in senders ]
993 recipientNames = [ x.get( "name" ) for x in recipients ]
994 badSenderNames = [ x.get( "name" ) for x in badSenders ]
995 badRecipientNames = [ x.get( "name" ) for x in badRecipients ]
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700996
Jeremyd9e4eb12016-04-13 12:09:06 -0700997 for sender in senders:
998 if not sender.get( "device" ):
999 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1000 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001001
Jeremyd9e4eb12016-04-13 12:09:06 -07001002 for recipient in recipients:
1003 if not recipient.get( "device" ):
1004 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1005 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001006 vlanId = senders[ 0 ].get( "vlan" )
Jeremyd9e4eb12016-04-13 12:09:06 -07001007 except (KeyError, TypeError):
1008 main.log.error( "There was a problem loading the hosts data." )
1009 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001010
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001011 testResult = main.TRUE
1012 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001013
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001014 # Check intent state
1015 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1016 main.assertReturnString += 'Initial Intent State Passed\n'
acsmarsd4862d12015-10-06 17:57:34 -07001017 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001018 main.assertReturnString += 'Initial Intent State Failed\n'
1019 testResult = main.FALSE
1020
1021 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -07001022 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001023 main.assertReturnString += 'Initial Flow State Passed\n'
1024 else:
1025 main.assertReturnString += 'Intial Flow State Failed\n'
1026 testResult = main.FALSE
1027
1028 # Check Connectivity
Jeremy Songster832f9e92016-05-05 14:30:49 -07001029 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ), attempts=3, sleep=5 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001030 main.assertReturnString += 'Initial Ping Passed\n'
1031 else:
1032 main.assertReturnString += 'Initial Ping Failed\n'
1033 testResult = main.FALSE
1034
1035 # Check connections that shouldn't work
1036 if badSenderNames:
1037 main.log.info( "Checking that packets from incorrect sender do not go through" )
1038 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, badSenderNames, recipientNames ), kwargs={ "expectFailure":True } ):
1039 main.assertReturnString += 'Bad Sender Ping Passed\n'
1040 else:
1041 main.assertReturnString += 'Bad Sender Ping Failed\n'
1042 testResult = main.FALSE
1043
1044 if badRecipientNames:
1045 main.log.info( "Checking that packets to incorrect recipients do not go through" )
1046 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, badRecipientNames ), kwargs={ "expectFailure":True } ):
1047 main.assertReturnString += 'Bad Recipient Ping Passed\n'
1048 else:
1049 main.assertReturnString += 'Bad Recipient Ping Failed\n'
1050 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001051
1052 # Test rerouting if these variables exist
1053 if sw1 and sw2 and expectedLink:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001054 # Take link down
1055 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001056 main.assertReturnString += 'Link Down Passed\n'
1057 else:
1058 main.assertReturnString += 'Link Down Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001059 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001060
acsmarsd4862d12015-10-06 17:57:34 -07001061 # Check intent state
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001062 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001063 main.assertReturnString += 'Link Down Intent State Passed\n'
1064 else:
1065 main.assertReturnString += 'Link Down Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001066 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001067
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001068 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -07001069 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001070 main.assertReturnString += 'Link Down Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001071 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001072 main.assertReturnString += 'Link Down Flow State Failed\n'
1073 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001074
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001075 # Check OnosTopology
1076 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink ) ):
1077 main.assertReturnString += 'Link Down Topology State Passed\n'
1078 else:
1079 main.assertReturnString += 'Link Down Topology State Failed\n'
1080 testResult = main.FALSE
1081
1082 # Check Connection
Jeremy Songster832f9e92016-05-05 14:30:49 -07001083 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001084 main.assertReturnString += 'Link Down Pingall Passed\n'
1085 else:
1086 main.assertReturnString += 'Link Down Pingall Failed\n'
1087 testResult = main.FALSE
1088
1089 # Bring link up
1090 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001091 main.assertReturnString += 'Link Up Passed\n'
1092 else:
1093 main.assertReturnString += 'Link Up Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001094 testResult = main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -07001095
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001096 # Wait for reroute
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001097 time.sleep( main.rerouteSleep )
1098
acsmarsd4862d12015-10-06 17:57:34 -07001099 # Check Intents
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001100 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001101 main.assertReturnString += 'Link Up Intent State Passed\n'
1102 else:
1103 main.assertReturnString += 'Link Up Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001104 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001105
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001106 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -07001107 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001108 main.assertReturnString += 'Link Up Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001109 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001110 main.assertReturnString += 'Link Up Flow State Failed\n'
1111 testResult = main.FALSE
1112
1113 # Check OnosTopology
1114 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
1115 main.assertReturnString += 'Link Up Topology State Passed\n'
1116 else:
1117 main.assertReturnString += 'Link Up Topology State Failed\n'
1118 testResult = main.FALSE
1119
1120 # Check Connection
Jeremy Songster832f9e92016-05-05 14:30:49 -07001121 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001122 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1123 else:
1124 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1125 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001126
1127 # Remove all intents
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001128 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001129 main.assertReturnString += 'Remove Intents Passed'
1130 else:
1131 main.assertReturnString += 'Remove Intents Failed'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001132 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001133
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001134 return testResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001135
Jeremye0cb5eb2016-01-27 17:39:09 -08001136def testEndPointFail( main,
1137 name,
1138 intentId,
1139 senders,
1140 recipients,
1141 isolatedSenders,
1142 isolatedRecipients,
1143 onosNode=0,
1144 ethType="",
1145 bandwidth="",
1146 lambdaAlloc=False,
1147 ipProto="",
1148 ipAddresses="",
1149 tcp="",
1150 sw1="",
1151 sw2="",
1152 sw3="",
1153 sw4="",
1154 sw5="",
1155 expectedLink1=0,
1156 expectedLink2=0 ):
1157 """
1158 Test Single to Multipoint Topology for Endpoint failures
1159 """
1160
1161 # Parameter Validity Check
1162 assert main, "There is no main variable"
1163 assert senders, "You must specify a sender"
1164 assert recipients, "You must specify a recipient"
1165
1166 global itemName
1167 itemName = name
1168 tempHostsData = {}
1169 onosNode = int( onosNode )
1170
1171 main.log.info( itemName + ": Testing Point Intent" )
1172
Jeremyd9e4eb12016-04-13 12:09:06 -07001173 try:
1174 # Names for scapy
1175 senderNames = [ x.get( "name" ) for x in senders ]
1176 recipientNames = [ x.get( "name" ) for x in recipients ]
1177 isolatedSenderNames = [ x.get( "name" ) for x in isolatedSenders ]
1178 isolatedRecipientNames = [ x.get( "name" ) for x in isolatedRecipients ]
1179 connectedSenderNames = [x.get("name") for x in senders if x.get("name") not in isolatedSenderNames]
1180 connectedRecipientNames = [x.get("name") for x in recipients if x.get("name") not in isolatedRecipientNames]
Jeremye0cb5eb2016-01-27 17:39:09 -08001181
Jeremyd9e4eb12016-04-13 12:09:06 -07001182 for sender in senders:
1183 if not sender.get( "device" ):
1184 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1185 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremye0cb5eb2016-01-27 17:39:09 -08001186
Jeremyd9e4eb12016-04-13 12:09:06 -07001187 for recipient in recipients:
1188 if not recipient.get( "device" ):
1189 main.log.warn( "Device not given for recipient {0}. Loading from\
1190 main.hostData".format( recipient.get( "name" ) ) )
1191 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
1192 except (KeyError, TypeError):
1193 main.log.error( "There was a problem loading the hosts data." )
1194 return main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001195
1196 testResult = main.TRUE
1197 main.log.info( itemName + ": Adding multi point to single point intents" )
1198
1199 # Check intent state
1200 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1201 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1202 main.assertReturnString += 'Initial Intent State Passed\n'
1203 else:
1204 main.assertReturnString += 'Initial Intent State Failed\n'
1205 testResult = main.FALSE
1206
1207 # Check flows count in each node
1208 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1209 args=[ main ] ) and utilities.retry( f=checkFlowsState,
1210 retValue=main.FALSE,
1211 args=[ main ] ):
1212 main.assertReturnString += 'Initial Flow State Passed\n'
1213 else:
1214 main.assertReturnString += 'Intial Flow State Failed\n'
1215 testResult = main.FALSE
1216
1217 # Check Connectivity
1218 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1219 args=( main, senderNames, recipientNames ) ):
1220 main.assertReturnString += 'Initial Connectivity Check Passed\n'
1221 else:
1222 main.assertReturnString += 'Initial Connectivity Check Failed\n'
1223 testResult = main.FALSE
1224
1225 # Take two links down
1226 # Take first link down
1227 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
1228 main.assertReturnString += 'Link Down Passed\n'
1229 else:
1230 main.assertReturnString += 'Link Down Failed\n'
1231 testResult = main.FALSE
1232
1233 # Take second link down
1234 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw4, "down" ) ):
1235 main.assertReturnString += 'Link Down Passed\n'
1236 else:
1237 main.assertReturnString += 'Link Down Failed\n'
1238 testResult = main.FALSE
1239
1240 # Check intent state
1241 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1242 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1243 main.assertReturnString += 'Link Down Intent State Passed\n'
1244 else:
1245 main.assertReturnString += 'Link Down Intent State Failed\n'
1246 testResult = main.FALSE
1247
1248 # Check flows count in each node
1249 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1250 args=[ main ] ) and utilities.retry( f=checkFlowsState,
1251 retValue=main.FALSE, args=[ main ] ):
1252 main.assertReturnString += 'Link Down Flow State Passed\n'
1253 else:
1254 main.assertReturnString += 'Link Down Flow State Failed\n'
1255 testResult = main.FALSE
1256
1257 # Check OnosTopology
1258 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink1 ) ):
1259 main.assertReturnString += 'Link Down Topology State Passed\n'
1260 else:
1261 main.assertReturnString += 'Link Down Topology State Failed\n'
1262 testResult = main.FALSE
1263
1264 # Check Connection
1265 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1266 args=( main, senderNames, recipientNames ) ):
1267 main.assertReturnString += 'Link Down Connectivity Check Passed\n'
1268 else:
1269 main.assertReturnString += 'Link Down Connectivity Check Failed\n'
1270 testResult = main.FALSE
1271
1272 # Take a third link down to isolate one node
1273 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw5, "down" ) ):
1274 main.assertReturnString += 'Isolation link Down Passed\n'
1275 else:
1276 main.assertReturnString += 'Isolation link Down Failed\n'
1277 testResult = main.FALSE
1278
1279 # Check intent state
1280 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1281 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1282 main.assertReturnString += 'Isolation link Down Intent State Passed\n'
1283 else:
1284 main.assertReturnString += 'Isolation link Down Intent State Failed\n'
1285 testResult = main.FALSE
1286
1287 # Check flows count in each node
1288 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1289 args=[ main ] ) and utilities.retry( f=checkFlowsState,
1290 retValue=main.FALSE, args=[ main ] ):
1291 main.assertReturnString += 'Isolation link Down Flow State Passed\n'
1292 else:
1293 main.assertReturnString += 'Isolation link Down Flow State Failed\n'
1294 testResult = main.FALSE
1295
1296 # Check OnosTopology
1297 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink2 ) ):
1298 main.assertReturnString += 'Isolation link Down Topology State Passed\n'
1299 else:
1300 main.assertReturnString += 'Isolation link Down Topology State Failed\n'
1301 testResult = main.FALSE
1302
1303 # Check Connectivity
1304 # First check connectivity of any isolated senders to recipients
1305 if isolatedSenderNames:
Jeremy Songster832f9e92016-05-05 14:30:49 -07001306 if scapyCheckConnection( main, isolatedSenderNames, recipientNames, None, None, None, main.TRUE ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001307 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1308 else:
1309 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1310 testResult = main.FALSE
1311
1312 # Next check connectivity of senders to any isolated recipients
1313 if isolatedRecipientNames:
Jeremy Songster832f9e92016-05-05 14:30:49 -07001314 if scapyCheckConnection( main, senderNames, isolatedRecipientNames, None, None, None, main.TRUE ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001315 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1316 else:
1317 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1318 testResult = main.FALSE
1319
1320 # Next check connectivity of connected senders and recipients
1321 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1322 args=( main, connectedSenderNames , connectedRecipientNames ) ):
1323 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1324 else:
1325 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1326 testResult = main.FALSE
1327
1328 # Bring the links back up
1329 # Bring first link up
1330 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
1331 main.assertReturnString += 'Link Up Passed\n'
1332 else:
1333 main.assertReturnString += 'Link Up Failed\n'
1334 testResult = main.FALSE
1335
1336 # Bring second link up
1337 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw5, "up" ) ):
1338 main.assertReturnString += 'Link Up Passed\n'
1339 else:
1340 main.assertReturnString += 'Link Up Failed\n'
1341 testResult = main.FALSE
1342
1343 # Bring third link up
1344 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw4, "up" ) ):
1345 main.assertReturnString += 'Link Up Passed\n'
1346 else:
1347 main.assertReturnString += 'Link Up Failed\n'
1348 testResult = main.FALSE
1349
1350 # Wait for reroute
1351 time.sleep( main.rerouteSleep )
1352
1353 # Check Intents
1354 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1355 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1356 main.assertReturnString += 'Link Up Intent State Passed\n'
1357 else:
1358 main.assertReturnString += 'Link Up Intent State Failed\n'
1359 testResult = main.FALSE
1360
1361 # Check flows count in each node
1362 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1363 args=[ main ] ) and utilities.retry( f=checkFlowsState,
1364 retValue=main.FALSE, args=[ main ] ):
1365 main.assertReturnString += 'Link Up Flow State Passed\n'
1366 else:
1367 main.assertReturnString += 'Link Up Flow State Failed\n'
1368 testResult = main.FALSE
1369
1370 # Check OnosTopology
1371 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
1372 main.assertReturnString += 'Link Up Topology State Passed\n'
1373 else:
1374 main.assertReturnString += 'Link Up Topology State Failed\n'
1375 testResult = main.FALSE
1376
1377 # Check Connection
1378 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1379 args=( main, senderNames, recipientNames ) ):
1380 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1381 else:
1382 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1383 testResult = main.FALSE
1384
1385 # Remove all intents
1386 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ):
1387 main.assertReturnString += 'Remove Intents Passed'
1388 else:
1389 main.assertReturnString += 'Remove Intents Failed'
1390 testResult = main.FALSE
1391
1392 return testResult
1393
1394
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001395def pingallHosts( main, hostList ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001396 """
1397 Ping all host in the hosts list variable
1398 """
Jon Halla5cb3412015-08-18 14:08:22 -07001399 main.log.info( "Pinging: " + str( hostList ) )
1400 return main.Mininet1.pingallHosts( hostList )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001401
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001402def fwdPingall( main ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001403 """
1404 Use fwd app and pingall to discover all the hosts
1405 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001406 activateResult = main.TRUE
1407 appCheck = main.TRUE
1408 getDataResult = main.TRUE
1409 main.log.info( "Activating reactive forwarding app " )
1410 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001411
1412 # Wait for forward app activation to propagate
kelvin-onlab0ad05d12015-07-23 14:21:15 -07001413 time.sleep( main.fwdSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001414
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001415 # Check that forwarding is enabled on all nodes
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001416 for i in range( main.numCtrls ):
1417 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
1418 if appCheck != main.TRUE:
1419 main.log.warn( main.CLIs[ i ].apps() )
1420 main.log.warn( main.CLIs[ i ].appIDs() )
1421
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001422 # Send pingall in mininet
1423 main.log.info( "Run Pingall" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001424 pingResult = main.Mininet1.pingall( timeout = 600 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001425
1426 main.log.info( "Deactivating reactive forwarding app " )
1427 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001428 if activateResult and deactivateResult:
1429 main.log.info( "Successfully used fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001430 getDataResult = main.TRUE
1431 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001432 main.log.info( "Failed to use fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001433 getDataResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001434 return getDataResult
1435
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001436def confirmHostDiscovery( main ):
1437 """
1438 Confirms that all ONOS nodes have discovered all scapy hosts
1439 """
1440 import collections
1441 scapyHostCount = len( main.scapyHosts )
1442 hosts = main.topo.getAllHosts( main ) # Get host data from each ONOS node
1443 hostFails = [] # Reset for each failed attempt
1444
1445 # Check for matching hosts on each node
1446 scapyHostIPs = [ x.hostIp for x in main.scapyHosts if x.hostIp != "0.0.0.0" ]
1447 for controller in range( main.numCtrls ):
1448 controllerStr = str( controller + 1 ) # ONOS node number
1449 # Compare Hosts
1450 # Load hosts data for controller node
Jeremyd9e4eb12016-04-13 12:09:06 -07001451 try:
1452 if hosts[ controller ]:
1453 main.log.info( "Hosts discovered" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001454 else:
Jeremyd9e4eb12016-04-13 12:09:06 -07001455 main.log.error( "Problem discovering hosts" )
1456 if hosts[ controller ] and "Error" not in hosts[ controller ]:
1457 try:
1458 hostData = json.loads( hosts[ controller ] )
1459 except ( TypeError, ValueError ):
1460 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001461 hostFails.append( controllerStr )
Jeremyd9e4eb12016-04-13 12:09:06 -07001462 else:
1463 onosHostIPs = [ x.get( "ipAddresses" )[ 0 ]
1464 for x in hostData
1465 if len( x.get( "ipAddresses" ) ) > 0 ]
1466 if not set( collections.Counter( scapyHostIPs ) ).issubset( set ( collections.Counter( onosHostIPs ) ) ):
1467 main.log.warn( "Controller {0} only sees nodes with {1} IPs. It should see all of the following: {2}".format( controllerStr, onosHostIPs, scapyHostIPs ) )
1468 hostFails.append( controllerStr )
1469 else:
1470 main.log.error( "Hosts returned nothing or an error." )
1471 hostFails.append( controllerStr )
1472 except IndexError:
1473 main.log.error( "Hosts returned nothing, Failed to discover hosts." )
1474 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001475
1476 if hostFails:
1477 main.log.error( "List of failed ONOS Nodes:" + ', '.join(map(str, hostFails )) )
1478 return main.FALSE
1479 else:
1480 return main.TRUE
1481
1482def sendDiscoveryArp( main, hosts=None ):
1483 """
1484 Sends Discovery ARP packets from each host provided
1485 Defaults to each host in main.scapyHosts
1486 """
1487 # Send an arp ping from each host
1488 if not hosts:
1489 hosts = main.scapyHosts
1490 for host in hosts:
1491 pkt = 'Ether( src="{0}")/ARP( psrc="{1}")'.format( host.hostMac ,host.hostIp )
1492 # Send from the VLAN interface if there is one so ONOS discovers the VLAN correctly
1493 iface = None
1494 for interface in host.getIfList():
1495 if '.' in interface:
1496 main.log.debug( "Detected VLAN interface {0}. Sending ARP packet from {0}".format( interface ) )
1497 iface = interface
1498 break
1499 host.sendPacket( packet=pkt, iface=iface )
1500 main.log.info( "Sending ARP packet from {0}".format( host.name ) )
1501
1502def populateHostData( main ):
1503 """
1504 Populates hostsData
1505 """
1506 import json
1507 try:
1508 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
1509 hosts = main.Mininet1.getHosts().keys()
1510 # TODO: Make better use of new getHosts function
1511 for host in hosts:
1512 main.hostsData[ host ] = {}
1513 main.hostsData[ host ][ 'mac' ] = \
1514 main.Mininet1.getMacAddress( host ).upper()
1515 for hostj in hostsJson:
1516 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
1517 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
1518 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
1519 main.hostsData[ host ][ 'location' ] = \
1520 hostj[ 'location' ][ 'elementId' ] + '/' + \
1521 hostj[ 'location' ][ 'port' ]
1522 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
1523 return main.TRUE
Jeremyd9e4eb12016-04-13 12:09:06 -07001524 except ValueError:
1525 main.log.error( "ValueError while populating hostsData" )
1526 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001527 except KeyError:
1528 main.log.error( "KeyError while populating hostsData")
1529 return main.FALSE
Jeremyd9e4eb12016-04-13 12:09:06 -07001530 except IndexError:
1531 main.log.error( "IndexError while populating hostsData" )
1532 return main.FALSE
1533 except TypeError:
1534 main.log.error( "TypeError while populating hostsData" )
1535 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001536
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001537def checkTopology( main, expectedLink ):
1538 statusResult = main.TRUE
1539 # Check onos topology
1540 main.log.info( itemName + ": Checking ONOS topology " )
1541
1542 for i in range( main.numCtrls ):
1543 topologyResult = main.CLIs[ i ].topology()
You Wang24139872016-05-03 11:48:47 -07001544 statusResult = main.CLIs[ i ].checkStatus( topologyResult,
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001545 main.numSwitch,
1546 expectedLink )\
1547 and statusResult
1548 if not statusResult:
1549 main.log.error( itemName + ": Topology mismatch" )
1550 else:
1551 main.log.info( itemName + ": Topology match" )
1552 return statusResult
1553
1554def checkIntentState( main, intentsId ):
1555 """
1556 This function will check intent state to make sure all the intents
1557 are in INSTALLED state
1558 """
1559
1560 intentResult = main.TRUE
1561 results = []
1562
1563 main.log.info( itemName + ": Checking intents state" )
1564 # First check of intents
1565 for i in range( main.numCtrls ):
1566 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
1567 results.append( tempResult )
1568
1569 expectedState = [ 'INSTALLED', 'INSTALLING' ]
1570
1571 if all( result == main.TRUE for result in results ):
1572 main.log.info( itemName + ": Intents are installed correctly" )
1573 else:
1574 # Wait for at least 5 second before checking the intents again
acsmarsb9a92692015-10-08 16:43:01 -07001575 main.log.error( "Intents are not installed correctly. Waiting 5 sec" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001576 time.sleep( 5 )
1577 results = []
1578 # Second check of intents since some of the intents may be in
1579 # INSTALLING state, they should be in INSTALLED at this time
1580 for i in range( main.numCtrls ):
Jeremy2f190ca2016-01-29 15:23:57 -08001581 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001582 results.append( tempResult )
1583 if all( result == main.TRUE for result in results ):
1584 main.log.info( itemName + ": Intents are installed correctly" )
acsmarsb9a92692015-10-08 16:43:01 -07001585 intentResult = main.TRUE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001586 else:
1587 main.log.error( itemName + ": Intents are NOT installed correctly" )
1588 intentResult = main.FALSE
1589
1590 return intentResult
1591
1592def checkFlowsState( main ):
1593
1594 main.log.info( itemName + ": Check flows state" )
1595 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState()
1596 return checkFlowsResult
1597
1598def link( main, sw1, sw2, option):
1599
1600 # link down
1601 main.log.info( itemName + ": Bring link " + option + "between " +
1602 sw1 + " and " + sw2 )
1603 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
1604 return linkResult
1605
Jeremy Songster832f9e92016-05-05 14:30:49 -07001606def scapyCheckConnection( main, senders, recipients, vlanId=None, packet=None, packetFilter=None, expectFailure=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001607 """
1608 Checks the connectivity between all given sender hosts and all given recipient hosts
1609 Packet may be specified. Defaults to Ether/IP packet
1610 Packet Filter may be specified. Defaults to Ether/IP from current sender MAC
1611 Todo: Optional packet and packet filter attributes for sender and recipients
1612 Expect Failure when the sender and recipient are not supposed to have connectivity
1613 Timeout of 1 second, returns main.TRUE if the filter is not triggered and kills the filter
1614
1615 """
1616 connectionsFunctional = main.TRUE
1617
1618 if not packetFilter:
1619 packetFilter = 'ether host {}'
1620
1621 if expectFailure:
1622 timeout = 1
1623 else:
1624 timeout = 10
1625
1626 for sender in senders:
1627 try:
1628 senderComp = getattr( main, sender )
1629 except AttributeError:
1630 main.log.error( "main has no attribute {}".format( sender ) )
1631 connectionsFunctional = main.FALSE
1632 continue
1633
1634 for recipient in recipients:
1635 # Do not send packets to self since recipient CLI will already be busy
1636 if recipient == sender:
1637 continue
1638 try:
1639 recipientComp = getattr( main, recipient )
1640 except AttributeError:
1641 main.log.error( "main has no attribute {}".format( recipient ) )
1642 connectionsFunctional = main.FALSE
1643 continue
1644
Jeremy Songster832f9e92016-05-05 14:30:49 -07001645 if vlanId:
1646 recipientComp.startFilter( pktFilter = ( "vlan {}".format( vlanId ) + " && " + packetFilter.format( senderComp.hostMac ) ) )
1647 else:
1648 recipientComp.startFilter( pktFilter = packetFilter.format( senderComp.hostMac ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001649
1650 if not packet:
Jeremy Songster832f9e92016-05-05 14:30:49 -07001651 if vlanId:
1652 pkt = 'Ether( src="{0}", dst="{2}" )/Dot1Q(vlan={4})/IP( src="{1}", dst="{3}" )'.format(
1653 senderComp.hostMac,
1654 senderComp.hostIp,
1655 recipientComp.hostMac,
1656 recipientComp.hostIp,
1657 vlanId )
1658 else:
1659 pkt = 'Ether( src="{0}", dst="{2}" )/IP( src="{1}", dst="{3}" )'.format(
1660 senderComp.hostMac,
1661 senderComp.hostIp,
1662 recipientComp.hostMac,
1663 recipientComp.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001664 else:
1665 pkt = packet
Jeremy Songster832f9e92016-05-05 14:30:49 -07001666 if vlanId:
1667 senderComp.sendPacket( iface=( "{0}-eth0.{1}".format( sender, vlanId ) ), packet = pkt )
1668 else:
1669 senderComp.sendPacket( packet = pkt )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001670
1671 if recipientComp.checkFilter( timeout ):
1672 if expectFailure:
1673 main.log.error( "Packet from {0} successfully received by {1} when it should not have been".format( sender , recipient ) )
1674 connectionsFunctional = main.FALSE
1675 else:
1676 main.log.info( "Packet from {0} successfully received by {1}".format( sender , recipient ) )
1677 else:
1678 recipientComp.killFilter()
1679 if expectFailure:
1680 main.log.info( "As expected, packet from {0} was not received by {1}".format( sender , recipient ) )
1681 else:
1682 main.log.error( "Packet from {0} was not received by {1}".format( sender , recipient ) )
1683 connectionsFunctional = main.FALSE
1684
1685 return connectionsFunctional
1686
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001687def removeAllIntents( main, intentsId ):
1688 """
1689 Remove all intents in the intentsId
1690 """
1691
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001692 onosSummary = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001693 removeIntentResult = main.TRUE
1694 # Remove intents
1695 for intent in intentsId:
1696 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
1697
acsmarscfa52272015-08-06 15:21:45 -07001698 time.sleep( main.removeIntentSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001699
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001700 # If there is remianing intents then remove intents should fail
1701 for i in range( main.numCtrls ):
1702 onosSummary.append( json.loads( main.CLIs[ i ].summary() ) )
1703
1704 for summary in onosSummary:
1705 if summary.get( 'intents' ) != 0:
1706 main.log.warn( itemName + ": There are " +
1707 str( summary.get( 'intents' ) ) +
1708 " intents remaining in node " +
1709 str( summary.get( 'node' ) ) +
1710 ", failed to remove all the intents " )
1711 removeIntentResult = main.FALSE
1712
1713 if removeIntentResult:
1714 main.log.info( itemName + ": There are no more intents remaining, " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001715 "successfully removed all the intents." )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001716
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001717 return removeIntentResult
1718
1719def checkFlowsCount( main ):
1720 """
1721 Check flows count in each node
1722 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001723 flowsCount = []
1724 main.log.info( itemName + ": Checking flows count in each ONOS node" )
1725 for i in range( main.numCtrls ):
1726 summaryResult = main.CLIs[ i ].summary()
1727 if not summaryResult:
1728 main.log.error( itemName + ": There is something wrong with " +
1729 "summary command" )
1730 return main.FALSE
1731 else:
1732 summaryJson = json.loads( summaryResult )
1733 flowsCount.append( summaryJson.get( 'flows' ) )
1734
1735 if flowsCount:
1736 if all( flows==flowsCount[ 0 ] for flows in flowsCount ):
1737 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
1738 " flows in all ONOS node" )
1739 else:
1740 for i in range( main.numCtrls ):
1741 main.log.debug( itemName + ": ONOS node " + str( i ) + " has " +
kelvin-onlab6dea6e62015-07-23 13:07:26 -07001742 str( flowsCount[ i ] ) + " flows" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001743 else:
1744 main.log.error( "Checking flows count failed, check summary command" )
1745 return main.FALSE
1746
1747 return main.TRUE
1748
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001749def checkLeaderChange( leaders1, leaders2 ):
acsmarse6b410f2015-07-17 14:39:34 -07001750 """
1751 Checks for a change in intent partition leadership.
1752
1753 Takes the output of leaders -c in json string format before and after
1754 a potential change as input
1755
1756 Returns main.TRUE if no mismatches are detected
1757 Returns main.FALSE if there is a mismatch or on error loading the input
1758 """
1759 try:
1760 leaders1 = json.loads( leaders1 )
1761 leaders2 = json.loads( leaders2 )
1762 except ( AttributeError, TypeError):
1763 main.log.exception( self.name + ": Object not as expected" )
1764 return main.FALSE
1765 except Exception:
1766 main.log.exception( self.name + ": Uncaught exception!" )
1767 main.cleanup()
1768 main.exit()
1769 main.log.info( "Checking Intent Paritions for Change in Leadership" )
1770 mismatch = False
1771 for dict1 in leaders1:
1772 if "intent" in dict1.get( "topic", [] ):
1773 for dict2 in leaders2:
1774 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \
1775 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
1776 mismatch = True
1777 main.log.error( "{0} changed leader from {1} to {2}".\
1778 format( dict1.get( "topic", "no-topic" ),\
1779 dict1.get( "leader", "no-leader" ),\
1780 dict2.get( "leader", "no-leader" ) ) )
1781 if mismatch:
1782 return main.FALSE
1783 else:
1784 return main.TRUE
kelvin-onlab016dce22015-08-10 09:54:11 -07001785
1786def report( main ):
1787 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001788 Report errors/warnings/exceptions
kelvin-onlab016dce22015-08-10 09:54:11 -07001789 """
kelvin-onlab016dce22015-08-10 09:54:11 -07001790 main.ONOSbench.logReport( main.ONOSip[ 0 ],
1791 [ "INFO",
1792 "FOLLOWER",
1793 "WARN",
1794 "flow",
1795 "ERROR",
1796 "Except" ],
1797 "s" )
1798
1799 main.log.info( "ERROR report: \n" )
1800 for i in range( main.numCtrls ):
1801 main.ONOSbench.logReport( main.ONOSip[ i ],
1802 [ "ERROR" ],
1803 "d" )
1804
1805 main.log.info( "EXCEPTIONS report: \n" )
1806 for i in range( main.numCtrls ):
1807 main.ONOSbench.logReport( main.ONOSip[ i ],
1808 [ "Except" ],
1809 "d" )
1810
1811 main.log.info( "WARNING report: \n" )
1812 for i in range( main.numCtrls ):
1813 main.ONOSbench.logReport( main.ONOSip[ i ],
1814 [ "WARN" ],
1815 "d" )