blob: ee0492da6d7d5d6f7647bde319946ff91dc5ef9d [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 Songsterff553672016-05-12 17:06:23 -070025 sw2="",
26 setVlan="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -070027 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -080028 Installs a Host Intent
29
kelvin-onlab58dc39e2015-08-06 08:11:09 -070030 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -080031 Install a host intent using
32 add-host-intent
33
kelvin-onlab58dc39e2015-08-06 08:11:09 -070034 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -080035 - Fetch host data if not given
36 - Add host intent
37 - Ingress device is the first sender host
38 - Egress devices are the recipient devices
39 - Ports if defined in senders or recipients
40 - MAC address ethSrc loaded from Ingress device
41 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -070042 Required:
43 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -080044 host1 - Dictionary for host1
45 { "name":"h8", "id":"of:0000000000000005/8" }
46 host2 - Dictionary for host2
47 { "name":"h16", "id":"of:0000000000000006/8" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -070048 Optional:
49 onosNode - ONOS node to install the intents in main.CLIs[ ]
50 0 by default so that it will always use the first
51 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -070052 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -070053 bandwidth - Bandwidth capacity
54 lambdaAlloc - Allocate lambda, defaults to False
55 ipProto - IP protocol
Jeremy Songster1f39bf02016-01-20 17:17:25 -080056 tcp - TCP ports in the same order as the hosts in hostNames
57 """
58
59 assert main, "There is no main variable"
60 assert host1, "You must specify host1"
61 assert host2, "You must specify host2"
62
63 global itemName # The name of this run. Used for logs.
64 itemName = name
65 onosNode = int( onosNode )
66
67 main.log.info( itemName + ": Adding single point to multi point intents" )
Jeremyd9e4eb12016-04-13 12:09:06 -070068 try:
69 if not host1.get( "id" ):
70 main.log.warn( "ID not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
71 main.log.debug( main.hostsData.get( host1.get( "name" ) ) )
72 host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "id" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -080073
Jeremyd9e4eb12016-04-13 12:09:06 -070074 if not host2.get( "id" ):
75 main.log.warn( "ID not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
76 host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "id" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -080077
Jeremyd9e4eb12016-04-13 12:09:06 -070078 # Adding point intent
Jeremy Songster832f9e92016-05-05 14:30:49 -070079 vlanId = host1.get( "vlan" )
Jeremyd9e4eb12016-04-13 12:09:06 -070080 intentId = main.CLIs[ onosNode ].addHostIntent( hostIdOne=host1.get( "id" ),
Jeremy Songster832f9e92016-05-05 14:30:49 -070081 hostIdTwo=host2.get( "id" ),
Jeremy Songsterff553672016-05-12 17:06:23 -070082 vlanId=vlanId,
83 setVlan=setVlan )
Jeremyd9e4eb12016-04-13 12:09:06 -070084 except (KeyError, TypeError):
85 errorMsg = "There was a problem loading the hosts data."
86 if intentId:
87 errorMsg += " There was a problem installing host to host intent."
88 main.log.error( errorMsg )
89 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -080090
91 # Check intents state
92 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
93 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
94 return intentId
95 else:
Jeremy2f190ca2016-01-29 15:23:57 -080096 main.log.error( "Host Intent did not install correctly" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -080097 return main.FALSE
98
99def testHostIntent( main,
100 name,
101 intentId,
102 host1,
103 host2,
104 onosNode=0,
105 sw1="s5",
106 sw2="s2",
107 expectedLink=0):
108 """
109 Test a Host Intent
110
111 Description:
112 Test a host intent of given ID between given hosts
113
114 Steps:
115 - Fetch host data if not given
116 - Check Intent State
117 - Check Flow State
118 - Check Connectivity
119 - Check Lack of Connectivity Between Hosts not in the Intent
120 - Reroute
121 - Take Expected Link Down
122 - Check Intent State
123 - Check Flow State
124 - Check Topology
125 - Check Connectivity
126 - Bring Expected Link Up
127 - Check Intent State
128 - Check Flow State
129 - Check Topology
130 - Check Connectivity
131 - Remove Topology
132
133 Required:
134 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
135 intentId - intent ID to be tested ( and removed )
136 host1 - Dictionary for host1
137 { "name":"h8", "id":"of:0000000000000005/8" }
138 host2 - Dictionary for host2
139 { "name":"h16", "id":"of:0000000000000006/8" }
140 Optional:
141 onosNode - ONOS node to install the intents in main.CLIs[ ]
142 0 by default so that it will always use the first
143 ONOS node
144 sw1 - First switch to bring down & up for rerouting purpose
145 sw2 - Second switch to bring down & up for rerouting purpose
146 expectedLink - Expected link when the switches are down, it should
147 be two links lower than the links before the two
148 switches are down
149
150 """
151
152 # Parameter Validity Check
153 assert main, "There is no main variable"
154 assert host1, "You must specify host1"
155 assert host2, "You must specify host2"
156
157 global itemName
158 itemName = name
159 tempHostsData = {}
160 onosNode = int( onosNode )
161
Jeremy2f190ca2016-01-29 15:23:57 -0800162 main.log.info( itemName + ": Testing Host Intent" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800163
Jeremyd9e4eb12016-04-13 12:09:06 -0700164 try:
165 if not host1.get( "id" ):
166 main.log.warn( "Id not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
167 host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800168
Jeremyd9e4eb12016-04-13 12:09:06 -0700169 if not host2.get( "id" ):
170 main.log.warn( "Id not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
171 host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800172
Jeremyd9e4eb12016-04-13 12:09:06 -0700173 senderNames = [ host1.get( "name" ), host2.get( "name" ) ]
174 recipientNames = [ host1.get( "name" ), host2.get( "name" ) ]
Jeremy Songster832f9e92016-05-05 14:30:49 -0700175 vlanId = host1.get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800176
Jeremyd9e4eb12016-04-13 12:09:06 -0700177 testResult = main.TRUE
178 except (KeyError, TypeError):
179 main.log.error( "There was a problem loading the hosts data." )
180 return main.FALSE
181
182 main.log.info( itemName + ": Testing Host to Host intents" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800183
184 # Check intent state
185 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
186 main.assertReturnString += 'Initial Intent State Passed\n'
187 else:
188 main.assertReturnString += 'Initial Intent State Failed\n'
189 testResult = main.FALSE
190
191 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -0700192 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 -0800193 main.assertReturnString += 'Initial Flow State Passed\n'
194 else:
195 main.assertReturnString += 'Intial Flow State Failed\n'
196 testResult = main.FALSE
197
198 # Check Connectivity
Jeremy Songster832f9e92016-05-05 14:30:49 -0700199 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800200 main.assertReturnString += 'Initial Ping Passed\n'
201 else:
202 main.assertReturnString += 'Initial Ping Failed\n'
203 testResult = main.FALSE
204
205 # Test rerouting if these variables exist
206 if sw1 and sw2 and expectedLink:
207 # Take link down
208 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
209 main.assertReturnString += 'Link Down Passed\n'
210 else:
211 main.assertReturnString += 'Link Down Failed\n'
212 testResult = main.FALSE
213
214 # Check intent state
215 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
216 main.assertReturnString += 'Link Down Intent State Passed\n'
217 else:
218 main.assertReturnString += 'Link Down Intent State Failed\n'
219 testResult = main.FALSE
220
221 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -0700222 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 -0800223 main.assertReturnString += 'Link Down Flow State Passed\n'
224 else:
225 main.assertReturnString += 'Link Down Flow State Failed\n'
226 testResult = main.FALSE
227
228 # Check OnosTopology
229 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink ) ):
230 main.assertReturnString += 'Link Down Topology State Passed\n'
231 else:
232 main.assertReturnString += 'Link Down Topology State Failed\n'
233 testResult = main.FALSE
234
235 # Check Connection
Jeremy Songster832f9e92016-05-05 14:30:49 -0700236 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800237 main.assertReturnString += 'Link Down Pingall Passed\n'
238 else:
239 main.assertReturnString += 'Link Down Pingall Failed\n'
240 testResult = main.FALSE
241
242 # Bring link up
243 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
244 main.assertReturnString += 'Link Up Passed\n'
245 else:
246 main.assertReturnString += 'Link Up Failed\n'
247 testResult = main.FALSE
248
249 # Wait for reroute
250 time.sleep( main.rerouteSleep )
251
252 # Check Intents
253 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
254 main.assertReturnString += 'Link Up Intent State Passed\n'
255 else:
256 main.assertReturnString += 'Link Up Intent State Failed\n'
257 testResult = main.FALSE
258
259 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -0700260 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 -0800261 main.assertReturnString += 'Link Up Flow State Passed\n'
262 else:
263 main.assertReturnString += 'Link Up Flow State Failed\n'
264 testResult = main.FALSE
265
266 # Check OnosTopology
267 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
268 main.assertReturnString += 'Link Up Topology State Passed\n'
269 else:
270 main.assertReturnString += 'Link Up Topology State Failed\n'
271 testResult = main.FALSE
272
273 # Check Connection
Jeremy Songster832f9e92016-05-05 14:30:49 -0700274 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800275 main.assertReturnString += 'Link Up Pingall Passed\n'
276 else:
277 main.assertReturnString += 'Link Up Pingall Failed\n'
278 testResult = main.FALSE
279
280 # Remove all intents
281 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ):
282 main.assertReturnString += 'Remove Intents Passed'
283 else:
284 main.assertReturnString += 'Remove Intents Failed'
285 testResult = main.FALSE
286
287 return testResult
288
289def installPointIntent( main,
290 name,
291 senders,
292 recipients,
293 onosNode=0,
294 ethType="",
295 bandwidth="",
296 lambdaAlloc=False,
297 ipProto="",
298 ipSrc="",
299 ipDst="",
300 tcpSrc="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700301 tcpDst="",
302 setVlan=""):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800303 """
304 Installs a Single to Single Point Intent
305
306 Description:
307 Install a single to single point intent
308
309 Steps:
310 - Fetch host data if not given
311 - Add point intent
312 - Ingress device is the first sender device
313 - Egress device is the first recipient device
314 - Ports if defined in senders or recipients
315 - MAC address ethSrc loaded from Ingress device
316 - Check intent state with retry
317 Required:
318 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
319 senders - List of host dictionaries i.e.
320 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
321 recipients - List of host dictionaries i.e.
322 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
323 Optional:
324 onosNode - ONOS node to install the intents in main.CLIs[ ]
325 0 by default so that it will always use the first
326 ONOS node
327 ethType - Ethernet type eg. IPV4, IPV6
328 bandwidth - Bandwidth capacity
329 lambdaAlloc - Allocate lambda, defaults to False
330 ipProto - IP protocol
331 tcp - TCP ports in the same order as the hosts in hostNames
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700332 sw1 - First switch to bring down & up for rerouting purpose
333 sw2 - Second switch to bring down & up for rerouting purpose
334 expectedLink - Expected link when the switches are down, it should
335 be two links lower than the links before the two
336 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700337 """
338
339 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800340 assert senders, "You must specify a sender"
341 assert recipients, "You must specify a recipient"
342 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700343
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800344 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700345 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700346 onosNode = int( onosNode )
347
Jeremy6f000c62016-02-25 17:02:28 -0800348 main.log.info( itemName + ": Adding point to point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700349
Jeremyd9e4eb12016-04-13 12:09:06 -0700350 try:
351 for sender in senders:
352 if not sender.get( "device" ):
353 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
354 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800355
Jeremyd9e4eb12016-04-13 12:09:06 -0700356 for recipient in recipients:
357 if not recipient.get( "device" ):
358 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
359 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800360
361
Jeremyd9e4eb12016-04-13 12:09:06 -0700362 ingressDevice = senders[ 0 ].get( "device" )
363 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800364
Jeremyd9e4eb12016-04-13 12:09:06 -0700365 portIngress = senders[ 0 ].get( "port", "" )
366 portEgress = recipients[ 0 ].get( "port", "" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800367
Jeremyd9e4eb12016-04-13 12:09:06 -0700368 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800369
Jeremyd9e4eb12016-04-13 12:09:06 -0700370 ipSrc = senders[ 0 ].get( "ip" )
371 ipDst = recipients[ 0 ].get( "ip" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800372
Jeremy Songster832f9e92016-05-05 14:30:49 -0700373 vlanId = senders[ 0 ].get( "vlan" )
374
Jeremyd9e4eb12016-04-13 12:09:06 -0700375 # Adding point intent
376 intentId = main.CLIs[ onosNode ].addPointIntent(
377 ingressDevice=ingressDevice,
378 egressDevice=egressDevice,
379 portIngress=portIngress,
380 portEgress=portEgress,
381 ethType=ethType,
382 ethDst=dstMac,
383 bandwidth=bandwidth,
384 lambdaAlloc=lambdaAlloc,
385 ipProto=ipProto,
386 ipSrc=ipSrc,
387 ipDst=ipDst,
388 tcpSrc=tcpSrc,
Jeremy Songster832f9e92016-05-05 14:30:49 -0700389 tcpDst=tcpDst,
Jeremy Songsterff553672016-05-12 17:06:23 -0700390 vlanId=vlanId,
391 setVlan=setVlan )
Jeremyd9e4eb12016-04-13 12:09:06 -0700392 except (KeyError, TypeError):
393 errorMsg = "There was a problem loading the hosts data."
394 if intentId:
395 errorMsg += " There was a problem installing Point to Point intent."
396 main.log.error( errorMsg )
397 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700398
399 # Check intents state
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800400 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
401 return intentId
acsmarsd4862d12015-10-06 17:57:34 -0700402 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800403 main.log.error( "Point Intent did not install correctly" )
404 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700405
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700406def pointIntentTcp( main,
407 name,
408 host1,
409 host2,
410 onosNode=0,
411 deviceId1="",
412 deviceId2="",
413 port1="",
414 port2="",
415 ethType="",
416 mac1="",
417 mac2="",
418 bandwidth="",
419 lambdaAlloc=False,
420 ipProto="",
421 ip1="",
422 ip2="",
423 tcp1="",
424 tcp2="",
425 sw1="",
426 sw2="",
427 expectedLink=0 ):
428
429 """
430 Description:
431 Verify add-point-intent only for TCP
432 Steps:
433 - Get device ids | ports
434 - Add point intents
435 - Check intents
436 - Verify flows
437 - Ping hosts
438 - Reroute
439 - Link down
440 - Verify flows
441 - Check topology
442 - Ping hosts
443 - Link up
444 - Verify flows
445 - Check topology
446 - Ping hosts
447 - Remove intents
448 Required:
449 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
450 host1 - Name of first host
451 host2 - Name of second host
452 Optional:
453 onosNode - ONOS node to install the intents in main.CLIs[ ]
454 0 by default so that it will always use the first
455 ONOS node
456 deviceId1 - ONOS device id of the first switch, the same as the
457 location of the first host eg. of:0000000000000001/1,
458 located at device 1 port 1
459 deviceId2 - ONOS device id of the second switch
460 port1 - The port number where the first host is attached
461 port2 - The port number where the second host is attached
462 ethType - Ethernet type eg. IPV4, IPV6
463 mac1 - Mac address of first host
464 mac2 - Mac address of the second host
465 bandwidth - Bandwidth capacity
466 lambdaAlloc - Allocate lambda, defaults to False
467 ipProto - IP protocol
468 ip1 - IP address of first host
469 ip2 - IP address of second host
470 tcp1 - TCP port of first host
471 tcp2 - TCP port of second host
472 sw1 - First switch to bring down & up for rerouting purpose
473 sw2 - Second switch to bring down & up for rerouting purpose
474 expectedLink - Expected link when the switches are down, it should
475 be two links lower than the links before the two
476 switches are down
477 """
478
479 assert main, "There is no main variable"
480 assert name, "variable name is empty"
481 assert host1 and host2, "You must specify hosts"
482
483 global itemName
484 itemName = name
485 host1 = host1
486 host2 = host2
487 hostNames = [ host1, host2 ]
488 intentsId = []
489
490 iperfResult = main.TRUE
491 intentResult = main.TRUE
492 removeIntentResult = main.TRUE
493 flowResult = main.TRUE
494 topoResult = main.TRUE
495 linkDownResult = main.TRUE
496 linkUpResult = main.TRUE
497 onosNode = int( onosNode )
498
499 # Adding bidirectional point intents
500 main.log.info( itemName + ": Adding point intents" )
501 intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
502 egressDevice=deviceId2,
503 portIngress=port1,
504 portEgress=port2,
505 ethType=ethType,
506 ethSrc=mac1,
507 ethDst=mac2,
508 bandwidth=bandwidth,
509 lambdaAlloc=lambdaAlloc,
510 ipProto=ipProto,
511 ipSrc=ip1,
512 ipDst=ip2,
513 tcpSrc=tcp1,
514 tcpDst="" )
515
516 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
517 egressDevice=deviceId1,
518 portIngress=port2,
519 portEgress=port1,
520 ethType=ethType,
521 ethSrc=mac2,
522 ethDst=mac1,
523 bandwidth=bandwidth,
524 lambdaAlloc=lambdaAlloc,
525 ipProto=ipProto,
526 ipSrc=ip2,
527 ipDst=ip1,
528 tcpSrc=tcp2,
529 tcpDst="" )
530
531 intent3 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
532 egressDevice=deviceId2,
533 portIngress=port1,
534 portEgress=port2,
535 ethType=ethType,
536 ethSrc=mac1,
537 ethDst=mac2,
538 bandwidth=bandwidth,
539 lambdaAlloc=lambdaAlloc,
540 ipProto=ipProto,
541 ipSrc=ip1,
542 ipDst=ip2,
543 tcpSrc="",
544 tcpDst=tcp2 )
545
546 intent4 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
547 egressDevice=deviceId1,
548 portIngress=port2,
549 portEgress=port1,
550 ethType=ethType,
551 ethSrc=mac2,
552 ethDst=mac1,
553 bandwidth=bandwidth,
554 lambdaAlloc=lambdaAlloc,
555 ipProto=ipProto,
556 ipSrc=ip2,
557 ipDst=ip1,
558 tcpSrc="",
559 tcpDst=tcp1 )
560 intentsId.append( intent1 )
561 intentsId.append( intent2 )
562 intentsId.append( intent3 )
563 intentsId.append( intent4 )
564
565 # Check intents state
566 time.sleep( main.checkIntentSleep )
567 intentResult = checkIntentState( main, intentsId )
568 # Check flows count in each node
569 checkFlowsCount( main )
570
571 # Check intents state again if first check fails...
572 if not intentResult:
573 intentResult = checkIntentState( main, intentsId )
574
575 # Check flows count in each node
576 checkFlowsCount( main )
577
578 # Verify flows
579 checkFlowsState( main )
580
581 # Run iperf to both host
acsmarsd4862d12015-10-06 17:57:34 -0700582 iperfTemp = main.Mininet1.iperftcp( host1,host2,10 )
583 iperfResult = iperfResult and iperfTemp
584 if iperfTemp:
585 main.assertReturnString += 'Initial Iperf Passed\n'
586 else:
587 main.assertReturnString += 'Initial Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700588
589 # Test rerouting if these variables exist
590 if sw1 and sw2 and expectedLink:
591 # link down
592 linkDownResult = link( main, sw1, sw2, "down" )
acsmarsd4862d12015-10-06 17:57:34 -0700593
594 if linkDownResult:
595 main.assertReturnString += 'Link Down Passed\n'
596 else:
597 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700598
599 # Check flows count in each node
600 checkFlowsCount( main )
601 # Verify flows
602 checkFlowsState( main )
603
604 # Check OnosTopology
605 topoResult = checkTopology( main, expectedLink )
acsmarsd4862d12015-10-06 17:57:34 -0700606 if topoResult:
607 main.assertReturnString += 'Link Down Topology State Passed\n'
608 else:
609 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700610
611 # Run iperf to both host
acsmarsd4862d12015-10-06 17:57:34 -0700612 iperfTemp = main.Mininet1.iperftcp( host1,host2,10 )
613 iperfResult = iperfResult and iperfTemp
614 if iperfTemp:
615 main.assertReturnString += 'Link Down Iperf Passed\n'
616 else:
617 main.assertReturnString += 'Link Down Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700618
acsmarsd4862d12015-10-06 17:57:34 -0700619 # Check intent state
620 intentTemp = checkIntentState( main, intentsId )
621 intentResult = intentResult and intentTemp
622 if intentTemp:
623 main.assertReturnString += 'Link Down Intent State Passed\n'
624 else:
625 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700626
627 # Checks ONOS state in link down
628 if linkDownResult and topoResult and iperfResult and intentResult:
629 main.log.info( itemName + ": Successfully brought link down" )
630 else:
631 main.log.error( itemName + ": Failed to bring link down" )
632
633 # link up
634 linkUpResult = link( main, sw1, sw2, "up" )
acsmarsd4862d12015-10-06 17:57:34 -0700635 if linkUpTemp:
636 main.assertReturnString += 'Link Up Passed\n'
637 else:
638 main.assertReturnString += 'Link Up Failed\n'
639
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700640 time.sleep( main.rerouteSleep )
641
642 # Check flows count in each node
643 checkFlowsCount( main )
644 # Verify flows
645 checkFlowsState( main )
646
647 # Check OnosTopology
648 topoResult = checkTopology( main, main.numLinks )
649
acsmarsd4862d12015-10-06 17:57:34 -0700650 if topoResult:
651 main.assertReturnString += 'Link Up Topology State Passed\n'
652 else:
653 main.assertReturnString += 'Link Up Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700654
acsmarsd4862d12015-10-06 17:57:34 -0700655 # Run iperf to both host
656 iperfTemp = main.Mininet1.iperftcp( host1,host2,10 )
657 iperfResult = iperfResult and iperfTemp
658 if iperfTemp:
659 main.assertReturnString += 'Link Up Iperf Passed\n'
660 else:
661 main.assertReturnString += 'Link Up Iperf Failed\n'
662
663 # Check intent state
664 intentTemp = checkIntentState( main, intentsId )
665 intentResult = intentResult and intentTemp
666 if intentTemp:
667 main.assertReturnString += 'Link Down Intent State Passed\n'
668 else:
669 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700670
671 # Checks ONOS state in link up
672 if linkUpResult and topoResult and iperfResult and intentResult:
673 main.log.info( itemName + ": Successfully brought link back up" )
674 else:
675 main.log.error( itemName + ": Failed to bring link back up" )
676
677 # Remove all intents
678 removeIntentResult = removeAllIntents( main, intentsId )
acsmarsd4862d12015-10-06 17:57:34 -0700679 if removeIntentResult:
680 main.assertReturnString += 'Remove Intents Passed'
681 else:
682 main.assertReturnString += 'Remove Intents Failed'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700683
684 stepResult = iperfResult and linkDownResult and linkUpResult \
685 and intentResult and removeIntentResult
686
687 return stepResult
688
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800689def installSingleToMultiIntent( main,
690 name,
691 senders,
692 recipients,
693 onosNode=0,
694 ethType="",
695 bandwidth="",
696 lambdaAlloc=False,
697 ipProto="",
698 ipAddresses="",
699 tcp="",
700 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700701 sw2="",
702 setVlan=""):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700703 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800704 Installs a Single to Multi Point Intent
705
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700706 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800707 Install a single to multi point intent using
708 add-single-to-multi-intent
709
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700710 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800711 - Fetch host data if not given
712 - Add single to multi intent
713 - Ingress device is the first sender host
714 - Egress devices are the recipient devices
715 - Ports if defined in senders or recipients
716 - MAC address ethSrc loaded from Ingress device
717 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700718 Required:
719 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800720 senders - List of host dictionaries i.e.
721 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
722 recipients - List of host dictionaries i.e.
723 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700724 Optional:
725 onosNode - ONOS node to install the intents in main.CLIs[ ]
726 0 by default so that it will always use the first
727 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700728 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700729 bandwidth - Bandwidth capacity
730 lambdaAlloc - Allocate lambda, defaults to False
731 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700732 tcp - TCP ports in the same order as the hosts in hostNames
733 sw1 - First switch to bring down & up for rerouting purpose
734 sw2 - Second switch to bring down & up for rerouting purpose
735 expectedLink - Expected link when the switches are down, it should
736 be two links lower than the links before the two
737 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700738 """
739
740 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800741 assert senders, "You must specify a sender"
742 assert recipients, "You must specify a recipient"
743 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700744
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800745 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700746 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700747 onosNode = int( onosNode )
748
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700749 main.log.info( itemName + ": Adding single point to multi point intents" )
750
Jeremyd9e4eb12016-04-13 12:09:06 -0700751 try:
752 for sender in senders:
753 if not sender.get( "device" ):
754 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
755 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700756
Jeremyd9e4eb12016-04-13 12:09:06 -0700757 for recipient in recipients:
758 if not recipient.get( "device" ):
759 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
760 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700761
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700762
Jeremyd9e4eb12016-04-13 12:09:06 -0700763 ingressDevice = senders[ 0 ].get( "device" )
764 egressDeviceList = [ x.get( "device" ) for x in recipients if x.get( "device" ) ]
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800765
Jeremyd9e4eb12016-04-13 12:09:06 -0700766 portIngress = senders[ 0 ].get( "port", "" )
767 portEgressList = [ x.get( "port" ) for x in recipients if x.get( "port" ) ]
768 if not portEgressList:
769 portEgressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800770
Jeremyd9e4eb12016-04-13 12:09:06 -0700771 srcMac = senders[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700772 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800773
Jeremyd9e4eb12016-04-13 12:09:06 -0700774 # Adding point intent
775 intentId = main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
776 ingressDevice=ingressDevice,
777 egressDeviceList=egressDeviceList,
778 portIngress=portIngress,
779 portEgressList=portEgressList,
780 ethType=ethType,
781 ethSrc=srcMac,
782 bandwidth=bandwidth,
783 lambdaAlloc=lambdaAlloc,
784 ipProto=ipProto,
785 ipSrc="",
786 ipDst="",
787 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -0700788 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700789 vlanId=vlanId,
790 setVlan=setVlan )
Jeremyd9e4eb12016-04-13 12:09:06 -0700791 except (KeyError, TypeError):
792 errorMsg = "There was a problem loading the hosts data."
793 if intentId:
794 errorMsg += " There was a problem installing Singlepoint to Multipoint intent."
795 main.log.error( errorMsg )
796 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700797
798 # Check intents state
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800799 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
800 return intentId
acsmarsd4862d12015-10-06 17:57:34 -0700801 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800802 main.log.error( "Single to Multi Intent did not install correctly" )
803 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700804
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800805def installMultiToSingleIntent( main,
806 name,
807 senders,
808 recipients,
809 onosNode=0,
810 ethType="",
811 bandwidth="",
812 lambdaAlloc=False,
813 ipProto="",
814 ipAddresses="",
815 tcp="",
816 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700817 sw2="",
818 setVlan=""):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700819 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800820 Installs a Multi to Single Point Intent
821
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700822 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800823 Install a multi to single point intent using
824 add-multi-to-single-intent
825
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700826 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800827 - Fetch host data if not given
828 - Add multi to single intent
829 - Ingress devices are the senders devices
830 - Egress device is the first recipient host
831 - Ports if defined in senders or recipients
832 - MAC address ethSrc loaded from Ingress device
833 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700834 Required:
835 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800836 senders - List of host dictionaries i.e.
837 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
838 recipients - List of host dictionaries i.e.
839 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700840 Optional:
841 onosNode - ONOS node to install the intents in main.CLIs[ ]
842 0 by default so that it will always use the first
843 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700844 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700845 bandwidth - Bandwidth capacity
846 lambdaAlloc - Allocate lambda, defaults to False
847 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700848 tcp - TCP ports in the same order as the hosts in hostNames
849 sw1 - First switch to bring down & up for rerouting purpose
850 sw2 - Second switch to bring down & up for rerouting purpose
851 expectedLink - Expected link when the switches are down, it should
852 be two links lower than the links before the two
853 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700854 """
855
856 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800857 assert senders, "You must specify a sender"
858 assert recipients, "You must specify a recipient"
859 # Assert devices or main.hostsData, "You must specify devices"
860
861 global itemName # The name of this run. Used for logs.
862 itemName = name
863 onosNode = int( onosNode )
864
865 main.log.info( itemName + ": Adding mutli to single point intents" )
866
Jeremyd9e4eb12016-04-13 12:09:06 -0700867 try:
868 for sender in senders:
869 if not sender.get( "device" ):
870 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
871 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800872
Jeremyd9e4eb12016-04-13 12:09:06 -0700873 for recipient in recipients:
874 if not recipient.get( "device" ):
875 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
876 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800877
Jeremyd9e4eb12016-04-13 12:09:06 -0700878 ingressDeviceList = [ x.get( "device" ) for x in senders if x.get( "device" ) ]
879 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800880
Jeremyd9e4eb12016-04-13 12:09:06 -0700881 portIngressList = [ x.get( "port" ) for x in senders if x.get( "port" ) ]
882 portEgress = recipients[ 0 ].get( "port", "" )
883 if not portIngressList:
884 portIngressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800885
Jeremyd9e4eb12016-04-13 12:09:06 -0700886 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700887 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800888
Jeremyd9e4eb12016-04-13 12:09:06 -0700889 # Adding point intent
890 intentId = main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
891 ingressDeviceList=ingressDeviceList,
892 egressDevice=egressDevice,
893 portIngressList=portIngressList,
894 portEgress=portEgress,
895 ethType=ethType,
896 ethDst=dstMac,
897 bandwidth=bandwidth,
898 lambdaAlloc=lambdaAlloc,
899 ipProto=ipProto,
900 ipSrc="",
901 ipDst="",
902 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -0700903 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700904 vlanId=vlanId,
905 setVlan=setVlan )
Jeremyd9e4eb12016-04-13 12:09:06 -0700906 except (KeyError, TypeError):
907 errorMsg = "There was a problem loading the hosts data."
908 if intentId:
909 errorMsg += " There was a problem installing Multipoint to Singlepoint intent."
910 main.log.error( errorMsg )
911 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800912
913 # Check intents state
914 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
915 return intentId
916 else:
917 main.log.error( "Multi to Single Intent did not install correctly" )
918 return main.FALSE
919
920def testPointIntent( main,
Jeremye0cb5eb2016-01-27 17:39:09 -0800921 name,
922 intentId,
923 senders,
924 recipients,
925 badSenders={},
926 badRecipients={},
927 onosNode=0,
928 ethType="",
929 bandwidth="",
930 lambdaAlloc=False,
931 ipProto="",
932 ipAddresses="",
933 tcp="",
934 sw1="s5",
935 sw2="s2",
936 expectedLink=0):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800937 """
938 Test a Point Intent
939
940 Description:
941 Test a point intent
942
943 Steps:
944 - Fetch host data if not given
945 - Check Intent State
946 - Check Flow State
947 - Check Connectivity
948 - Check Lack of Connectivity Between Hosts not in the Intent
949 - Reroute
950 - Take Expected Link Down
951 - Check Intent State
952 - Check Flow State
953 - Check Topology
954 - Check Connectivity
955 - Bring Expected Link Up
956 - Check Intent State
957 - Check Flow State
958 - Check Topology
959 - Check Connectivity
960 - Remove Topology
961
962 Required:
963 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
964
965 senders - List of host dictionaries i.e.
966 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
967 recipients - List of host dictionaries i.e.
968 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
969 Optional:
970 onosNode - ONOS node to install the intents in main.CLIs[ ]
971 0 by default so that it will always use the first
972 ONOS node
973 ethType - Ethernet type eg. IPV4, IPV6
974 bandwidth - Bandwidth capacity
975 lambdaAlloc - Allocate lambda, defaults to False
976 ipProto - IP protocol
977 tcp - TCP ports in the same order as the hosts in hostNames
978 sw1 - First switch to bring down & up for rerouting purpose
979 sw2 - Second switch to bring down & up for rerouting purpose
980 expectedLink - Expected link when the switches are down, it should
981 be two links lower than the links before the two
982 switches are down
983
984 """
985
986 # Parameter Validity Check
987 assert main, "There is no main variable"
988 assert senders, "You must specify a sender"
989 assert recipients, "You must specify a recipient"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700990
991 global itemName
992 itemName = name
993 tempHostsData = {}
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700994 onosNode = int( onosNode )
995
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800996 main.log.info( itemName + ": Testing Point Intent" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700997
Jeremyd9e4eb12016-04-13 12:09:06 -0700998 try:
999 # Names for scapy
1000 senderNames = [ x.get( "name" ) for x in senders ]
1001 recipientNames = [ x.get( "name" ) for x in recipients ]
1002 badSenderNames = [ x.get( "name" ) for x in badSenders ]
1003 badRecipientNames = [ x.get( "name" ) for x in badRecipients ]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001004
Jeremyd9e4eb12016-04-13 12:09:06 -07001005 for sender in senders:
1006 if not sender.get( "device" ):
1007 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1008 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001009
Jeremyd9e4eb12016-04-13 12:09:06 -07001010 for recipient in recipients:
1011 if not recipient.get( "device" ):
1012 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1013 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001014 vlanId = senders[ 0 ].get( "vlan" )
Jeremyd9e4eb12016-04-13 12:09:06 -07001015 except (KeyError, TypeError):
1016 main.log.error( "There was a problem loading the hosts data." )
1017 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001018
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001019 testResult = main.TRUE
1020 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001021
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001022 # Check intent state
1023 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1024 main.assertReturnString += 'Initial Intent State Passed\n'
acsmarsd4862d12015-10-06 17:57:34 -07001025 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001026 main.assertReturnString += 'Initial Intent State Failed\n'
1027 testResult = main.FALSE
1028
1029 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -07001030 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 -08001031 main.assertReturnString += 'Initial Flow State Passed\n'
1032 else:
1033 main.assertReturnString += 'Intial Flow State Failed\n'
1034 testResult = main.FALSE
1035
1036 # Check Connectivity
Jeremy Songster832f9e92016-05-05 14:30:49 -07001037 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ), attempts=3, sleep=5 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001038 main.assertReturnString += 'Initial Ping Passed\n'
1039 else:
1040 main.assertReturnString += 'Initial Ping Failed\n'
1041 testResult = main.FALSE
1042
1043 # Check connections that shouldn't work
1044 if badSenderNames:
1045 main.log.info( "Checking that packets from incorrect sender do not go through" )
1046 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, badSenderNames, recipientNames ), kwargs={ "expectFailure":True } ):
1047 main.assertReturnString += 'Bad Sender Ping Passed\n'
1048 else:
1049 main.assertReturnString += 'Bad Sender Ping Failed\n'
1050 testResult = main.FALSE
1051
1052 if badRecipientNames:
1053 main.log.info( "Checking that packets to incorrect recipients do not go through" )
1054 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, badRecipientNames ), kwargs={ "expectFailure":True } ):
1055 main.assertReturnString += 'Bad Recipient Ping Passed\n'
1056 else:
1057 main.assertReturnString += 'Bad Recipient Ping Failed\n'
1058 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001059
1060 # Test rerouting if these variables exist
1061 if sw1 and sw2 and expectedLink:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001062 # Take link down
1063 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001064 main.assertReturnString += 'Link Down Passed\n'
1065 else:
1066 main.assertReturnString += 'Link Down Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001067 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001068
acsmarsd4862d12015-10-06 17:57:34 -07001069 # Check intent state
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001070 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001071 main.assertReturnString += 'Link Down Intent State Passed\n'
1072 else:
1073 main.assertReturnString += 'Link Down Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001074 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001075
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001076 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -07001077 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 -08001078 main.assertReturnString += 'Link Down Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001079 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001080 main.assertReturnString += 'Link Down Flow State Failed\n'
1081 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001082
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001083 # Check OnosTopology
1084 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink ) ):
1085 main.assertReturnString += 'Link Down Topology State Passed\n'
1086 else:
1087 main.assertReturnString += 'Link Down Topology State Failed\n'
1088 testResult = main.FALSE
1089
1090 # Check Connection
Jeremy Songster832f9e92016-05-05 14:30:49 -07001091 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001092 main.assertReturnString += 'Link Down Pingall Passed\n'
1093 else:
1094 main.assertReturnString += 'Link Down Pingall Failed\n'
1095 testResult = main.FALSE
1096
1097 # Bring link up
1098 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001099 main.assertReturnString += 'Link Up Passed\n'
1100 else:
1101 main.assertReturnString += 'Link Up Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001102 testResult = main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -07001103
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001104 # Wait for reroute
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001105 time.sleep( main.rerouteSleep )
1106
acsmarsd4862d12015-10-06 17:57:34 -07001107 # Check Intents
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001108 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001109 main.assertReturnString += 'Link Up Intent State Passed\n'
1110 else:
1111 main.assertReturnString += 'Link Up Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001112 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001113
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001114 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -07001115 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 -08001116 main.assertReturnString += 'Link Up Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001117 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001118 main.assertReturnString += 'Link Up Flow State Failed\n'
1119 testResult = main.FALSE
1120
1121 # Check OnosTopology
1122 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
1123 main.assertReturnString += 'Link Up Topology State Passed\n'
1124 else:
1125 main.assertReturnString += 'Link Up Topology State Failed\n'
1126 testResult = main.FALSE
1127
1128 # Check Connection
Jeremy Songster832f9e92016-05-05 14:30:49 -07001129 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001130 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1131 else:
1132 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1133 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001134
1135 # Remove all intents
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001136 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001137 main.assertReturnString += 'Remove Intents Passed'
1138 else:
1139 main.assertReturnString += 'Remove Intents Failed'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001140 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001141
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001142 return testResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001143
Jeremye0cb5eb2016-01-27 17:39:09 -08001144def testEndPointFail( main,
1145 name,
1146 intentId,
1147 senders,
1148 recipients,
1149 isolatedSenders,
1150 isolatedRecipients,
1151 onosNode=0,
1152 ethType="",
1153 bandwidth="",
1154 lambdaAlloc=False,
1155 ipProto="",
1156 ipAddresses="",
1157 tcp="",
1158 sw1="",
1159 sw2="",
1160 sw3="",
1161 sw4="",
1162 sw5="",
1163 expectedLink1=0,
1164 expectedLink2=0 ):
1165 """
1166 Test Single to Multipoint Topology for Endpoint failures
1167 """
1168
1169 # Parameter Validity Check
1170 assert main, "There is no main variable"
1171 assert senders, "You must specify a sender"
1172 assert recipients, "You must specify a recipient"
1173
1174 global itemName
1175 itemName = name
1176 tempHostsData = {}
1177 onosNode = int( onosNode )
1178
1179 main.log.info( itemName + ": Testing Point Intent" )
1180
Jeremyd9e4eb12016-04-13 12:09:06 -07001181 try:
1182 # Names for scapy
1183 senderNames = [ x.get( "name" ) for x in senders ]
1184 recipientNames = [ x.get( "name" ) for x in recipients ]
1185 isolatedSenderNames = [ x.get( "name" ) for x in isolatedSenders ]
1186 isolatedRecipientNames = [ x.get( "name" ) for x in isolatedRecipients ]
1187 connectedSenderNames = [x.get("name") for x in senders if x.get("name") not in isolatedSenderNames]
1188 connectedRecipientNames = [x.get("name") for x in recipients if x.get("name") not in isolatedRecipientNames]
Jeremye0cb5eb2016-01-27 17:39:09 -08001189
Jeremyd9e4eb12016-04-13 12:09:06 -07001190 for sender in senders:
1191 if not sender.get( "device" ):
1192 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1193 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremye0cb5eb2016-01-27 17:39:09 -08001194
Jeremyd9e4eb12016-04-13 12:09:06 -07001195 for recipient in recipients:
1196 if not recipient.get( "device" ):
1197 main.log.warn( "Device not given for recipient {0}. Loading from\
1198 main.hostData".format( recipient.get( "name" ) ) )
1199 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
1200 except (KeyError, TypeError):
1201 main.log.error( "There was a problem loading the hosts data." )
1202 return main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001203
1204 testResult = main.TRUE
1205 main.log.info( itemName + ": Adding multi point to single point intents" )
1206
1207 # Check intent state
1208 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1209 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1210 main.assertReturnString += 'Initial Intent State Passed\n'
1211 else:
1212 main.assertReturnString += 'Initial Intent State Failed\n'
1213 testResult = main.FALSE
1214
1215 # Check flows count in each node
1216 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1217 args=[ main ] ) and utilities.retry( f=checkFlowsState,
1218 retValue=main.FALSE,
1219 args=[ main ] ):
1220 main.assertReturnString += 'Initial Flow State Passed\n'
1221 else:
1222 main.assertReturnString += 'Intial Flow State Failed\n'
1223 testResult = main.FALSE
1224
1225 # Check Connectivity
1226 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1227 args=( main, senderNames, recipientNames ) ):
1228 main.assertReturnString += 'Initial Connectivity Check Passed\n'
1229 else:
1230 main.assertReturnString += 'Initial Connectivity Check Failed\n'
1231 testResult = main.FALSE
1232
1233 # Take two links down
1234 # Take first link down
1235 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
1236 main.assertReturnString += 'Link Down Passed\n'
1237 else:
1238 main.assertReturnString += 'Link Down Failed\n'
1239 testResult = main.FALSE
1240
1241 # Take second link down
1242 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw4, "down" ) ):
1243 main.assertReturnString += 'Link Down Passed\n'
1244 else:
1245 main.assertReturnString += 'Link Down Failed\n'
1246 testResult = main.FALSE
1247
1248 # Check intent state
1249 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1250 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1251 main.assertReturnString += 'Link Down Intent State Passed\n'
1252 else:
1253 main.assertReturnString += 'Link Down Intent State Failed\n'
1254 testResult = main.FALSE
1255
1256 # Check flows count in each node
1257 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1258 args=[ main ] ) and utilities.retry( f=checkFlowsState,
1259 retValue=main.FALSE, args=[ main ] ):
1260 main.assertReturnString += 'Link Down Flow State Passed\n'
1261 else:
1262 main.assertReturnString += 'Link Down Flow State Failed\n'
1263 testResult = main.FALSE
1264
1265 # Check OnosTopology
1266 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink1 ) ):
1267 main.assertReturnString += 'Link Down Topology State Passed\n'
1268 else:
1269 main.assertReturnString += 'Link Down Topology State Failed\n'
1270 testResult = main.FALSE
1271
1272 # Check Connection
1273 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1274 args=( main, senderNames, recipientNames ) ):
1275 main.assertReturnString += 'Link Down Connectivity Check Passed\n'
1276 else:
1277 main.assertReturnString += 'Link Down Connectivity Check Failed\n'
1278 testResult = main.FALSE
1279
1280 # Take a third link down to isolate one node
1281 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw5, "down" ) ):
1282 main.assertReturnString += 'Isolation link Down Passed\n'
1283 else:
1284 main.assertReturnString += 'Isolation link Down Failed\n'
1285 testResult = main.FALSE
1286
1287 # Check intent state
1288 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1289 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1290 main.assertReturnString += 'Isolation link Down Intent State Passed\n'
1291 else:
1292 main.assertReturnString += 'Isolation link Down Intent State Failed\n'
1293 testResult = main.FALSE
1294
1295 # Check flows count in each node
1296 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1297 args=[ main ] ) and utilities.retry( f=checkFlowsState,
1298 retValue=main.FALSE, args=[ main ] ):
1299 main.assertReturnString += 'Isolation link Down Flow State Passed\n'
1300 else:
1301 main.assertReturnString += 'Isolation link Down Flow State Failed\n'
1302 testResult = main.FALSE
1303
1304 # Check OnosTopology
1305 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink2 ) ):
1306 main.assertReturnString += 'Isolation link Down Topology State Passed\n'
1307 else:
1308 main.assertReturnString += 'Isolation link Down Topology State Failed\n'
1309 testResult = main.FALSE
1310
1311 # Check Connectivity
1312 # First check connectivity of any isolated senders to recipients
1313 if isolatedSenderNames:
Jeremy Songster832f9e92016-05-05 14:30:49 -07001314 if scapyCheckConnection( main, isolatedSenderNames, recipientNames, 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 senders to any isolated recipients
1321 if isolatedRecipientNames:
Jeremy Songster832f9e92016-05-05 14:30:49 -07001322 if scapyCheckConnection( main, senderNames, isolatedRecipientNames, None, None, None, main.TRUE ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001323 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 # Next check connectivity of connected senders and recipients
1329 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1330 args=( main, connectedSenderNames , connectedRecipientNames ) ):
1331 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1332 else:
1333 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1334 testResult = main.FALSE
1335
1336 # Bring the links back up
1337 # Bring first link up
1338 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
1339 main.assertReturnString += 'Link Up Passed\n'
1340 else:
1341 main.assertReturnString += 'Link Up Failed\n'
1342 testResult = main.FALSE
1343
1344 # Bring second link up
1345 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw5, "up" ) ):
1346 main.assertReturnString += 'Link Up Passed\n'
1347 else:
1348 main.assertReturnString += 'Link Up Failed\n'
1349 testResult = main.FALSE
1350
1351 # Bring third link up
1352 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw4, "up" ) ):
1353 main.assertReturnString += 'Link Up Passed\n'
1354 else:
1355 main.assertReturnString += 'Link Up Failed\n'
1356 testResult = main.FALSE
1357
1358 # Wait for reroute
1359 time.sleep( main.rerouteSleep )
1360
1361 # Check Intents
1362 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1363 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1364 main.assertReturnString += 'Link Up Intent State Passed\n'
1365 else:
1366 main.assertReturnString += 'Link Up Intent State Failed\n'
1367 testResult = main.FALSE
1368
1369 # Check flows count in each node
1370 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1371 args=[ main ] ) and utilities.retry( f=checkFlowsState,
1372 retValue=main.FALSE, args=[ main ] ):
1373 main.assertReturnString += 'Link Up Flow State Passed\n'
1374 else:
1375 main.assertReturnString += 'Link Up Flow State Failed\n'
1376 testResult = main.FALSE
1377
1378 # Check OnosTopology
1379 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
1380 main.assertReturnString += 'Link Up Topology State Passed\n'
1381 else:
1382 main.assertReturnString += 'Link Up Topology State Failed\n'
1383 testResult = main.FALSE
1384
1385 # Check Connection
1386 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1387 args=( main, senderNames, recipientNames ) ):
1388 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1389 else:
1390 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1391 testResult = main.FALSE
1392
1393 # Remove all intents
1394 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ):
1395 main.assertReturnString += 'Remove Intents Passed'
1396 else:
1397 main.assertReturnString += 'Remove Intents Failed'
1398 testResult = main.FALSE
1399
1400 return testResult
1401
1402
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001403def pingallHosts( main, hostList ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001404 """
1405 Ping all host in the hosts list variable
1406 """
Jon Halla5cb3412015-08-18 14:08:22 -07001407 main.log.info( "Pinging: " + str( hostList ) )
1408 return main.Mininet1.pingallHosts( hostList )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001409
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001410def fwdPingall( main ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001411 """
1412 Use fwd app and pingall to discover all the hosts
1413 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001414 activateResult = main.TRUE
1415 appCheck = main.TRUE
1416 getDataResult = main.TRUE
1417 main.log.info( "Activating reactive forwarding app " )
1418 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001419
1420 # Wait for forward app activation to propagate
kelvin-onlab0ad05d12015-07-23 14:21:15 -07001421 time.sleep( main.fwdSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001422
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001423 # Check that forwarding is enabled on all nodes
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001424 for i in range( main.numCtrls ):
1425 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
1426 if appCheck != main.TRUE:
1427 main.log.warn( main.CLIs[ i ].apps() )
1428 main.log.warn( main.CLIs[ i ].appIDs() )
1429
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001430 # Send pingall in mininet
1431 main.log.info( "Run Pingall" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001432 pingResult = main.Mininet1.pingall( timeout = 600 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001433
1434 main.log.info( "Deactivating reactive forwarding app " )
1435 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001436 if activateResult and deactivateResult:
1437 main.log.info( "Successfully used fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001438 getDataResult = main.TRUE
1439 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001440 main.log.info( "Failed to use fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001441 getDataResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001442 return getDataResult
1443
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001444def confirmHostDiscovery( main ):
1445 """
1446 Confirms that all ONOS nodes have discovered all scapy hosts
1447 """
1448 import collections
1449 scapyHostCount = len( main.scapyHosts )
1450 hosts = main.topo.getAllHosts( main ) # Get host data from each ONOS node
1451 hostFails = [] # Reset for each failed attempt
1452
1453 # Check for matching hosts on each node
1454 scapyHostIPs = [ x.hostIp for x in main.scapyHosts if x.hostIp != "0.0.0.0" ]
1455 for controller in range( main.numCtrls ):
1456 controllerStr = str( controller + 1 ) # ONOS node number
1457 # Compare Hosts
1458 # Load hosts data for controller node
Jeremyd9e4eb12016-04-13 12:09:06 -07001459 try:
1460 if hosts[ controller ]:
1461 main.log.info( "Hosts discovered" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001462 else:
Jeremyd9e4eb12016-04-13 12:09:06 -07001463 main.log.error( "Problem discovering hosts" )
1464 if hosts[ controller ] and "Error" not in hosts[ controller ]:
1465 try:
1466 hostData = json.loads( hosts[ controller ] )
1467 except ( TypeError, ValueError ):
1468 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001469 hostFails.append( controllerStr )
Jeremyd9e4eb12016-04-13 12:09:06 -07001470 else:
1471 onosHostIPs = [ x.get( "ipAddresses" )[ 0 ]
1472 for x in hostData
1473 if len( x.get( "ipAddresses" ) ) > 0 ]
1474 if not set( collections.Counter( scapyHostIPs ) ).issubset( set ( collections.Counter( onosHostIPs ) ) ):
1475 main.log.warn( "Controller {0} only sees nodes with {1} IPs. It should see all of the following: {2}".format( controllerStr, onosHostIPs, scapyHostIPs ) )
1476 hostFails.append( controllerStr )
1477 else:
1478 main.log.error( "Hosts returned nothing or an error." )
1479 hostFails.append( controllerStr )
1480 except IndexError:
1481 main.log.error( "Hosts returned nothing, Failed to discover hosts." )
1482 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001483
1484 if hostFails:
1485 main.log.error( "List of failed ONOS Nodes:" + ', '.join(map(str, hostFails )) )
1486 return main.FALSE
1487 else:
1488 return main.TRUE
1489
1490def sendDiscoveryArp( main, hosts=None ):
1491 """
1492 Sends Discovery ARP packets from each host provided
1493 Defaults to each host in main.scapyHosts
1494 """
1495 # Send an arp ping from each host
1496 if not hosts:
1497 hosts = main.scapyHosts
1498 for host in hosts:
1499 pkt = 'Ether( src="{0}")/ARP( psrc="{1}")'.format( host.hostMac ,host.hostIp )
1500 # Send from the VLAN interface if there is one so ONOS discovers the VLAN correctly
1501 iface = None
1502 for interface in host.getIfList():
1503 if '.' in interface:
1504 main.log.debug( "Detected VLAN interface {0}. Sending ARP packet from {0}".format( interface ) )
1505 iface = interface
1506 break
1507 host.sendPacket( packet=pkt, iface=iface )
1508 main.log.info( "Sending ARP packet from {0}".format( host.name ) )
1509
1510def populateHostData( main ):
1511 """
1512 Populates hostsData
1513 """
1514 import json
1515 try:
1516 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
1517 hosts = main.Mininet1.getHosts().keys()
1518 # TODO: Make better use of new getHosts function
1519 for host in hosts:
1520 main.hostsData[ host ] = {}
1521 main.hostsData[ host ][ 'mac' ] = \
1522 main.Mininet1.getMacAddress( host ).upper()
1523 for hostj in hostsJson:
1524 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
1525 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
1526 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
1527 main.hostsData[ host ][ 'location' ] = \
1528 hostj[ 'location' ][ 'elementId' ] + '/' + \
1529 hostj[ 'location' ][ 'port' ]
1530 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
1531 return main.TRUE
Jeremyd9e4eb12016-04-13 12:09:06 -07001532 except ValueError:
1533 main.log.error( "ValueError while populating hostsData" )
1534 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001535 except KeyError:
1536 main.log.error( "KeyError while populating hostsData")
1537 return main.FALSE
Jeremyd9e4eb12016-04-13 12:09:06 -07001538 except IndexError:
1539 main.log.error( "IndexError while populating hostsData" )
1540 return main.FALSE
1541 except TypeError:
1542 main.log.error( "TypeError while populating hostsData" )
1543 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001544
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001545def checkTopology( main, expectedLink ):
1546 statusResult = main.TRUE
1547 # Check onos topology
1548 main.log.info( itemName + ": Checking ONOS topology " )
1549
1550 for i in range( main.numCtrls ):
1551 topologyResult = main.CLIs[ i ].topology()
You Wang24139872016-05-03 11:48:47 -07001552 statusResult = main.CLIs[ i ].checkStatus( topologyResult,
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001553 main.numSwitch,
1554 expectedLink )\
1555 and statusResult
1556 if not statusResult:
1557 main.log.error( itemName + ": Topology mismatch" )
1558 else:
1559 main.log.info( itemName + ": Topology match" )
1560 return statusResult
1561
1562def checkIntentState( main, intentsId ):
1563 """
1564 This function will check intent state to make sure all the intents
1565 are in INSTALLED state
1566 """
1567
1568 intentResult = main.TRUE
1569 results = []
1570
1571 main.log.info( itemName + ": Checking intents state" )
1572 # First check of intents
1573 for i in range( main.numCtrls ):
1574 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
1575 results.append( tempResult )
1576
1577 expectedState = [ 'INSTALLED', 'INSTALLING' ]
1578
1579 if all( result == main.TRUE for result in results ):
1580 main.log.info( itemName + ": Intents are installed correctly" )
1581 else:
1582 # Wait for at least 5 second before checking the intents again
acsmarsb9a92692015-10-08 16:43:01 -07001583 main.log.error( "Intents are not installed correctly. Waiting 5 sec" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001584 time.sleep( 5 )
1585 results = []
1586 # Second check of intents since some of the intents may be in
1587 # INSTALLING state, they should be in INSTALLED at this time
1588 for i in range( main.numCtrls ):
Jeremy2f190ca2016-01-29 15:23:57 -08001589 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001590 results.append( tempResult )
1591 if all( result == main.TRUE for result in results ):
1592 main.log.info( itemName + ": Intents are installed correctly" )
acsmarsb9a92692015-10-08 16:43:01 -07001593 intentResult = main.TRUE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001594 else:
1595 main.log.error( itemName + ": Intents are NOT installed correctly" )
1596 intentResult = main.FALSE
1597
1598 return intentResult
1599
1600def checkFlowsState( main ):
1601
1602 main.log.info( itemName + ": Check flows state" )
Jeremy Songsterff553672016-05-12 17:06:23 -07001603 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState( isPENDING=False )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001604 return checkFlowsResult
1605
1606def link( main, sw1, sw2, option):
1607
1608 # link down
1609 main.log.info( itemName + ": Bring link " + option + "between " +
1610 sw1 + " and " + sw2 )
1611 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
1612 return linkResult
1613
Jeremy Songster832f9e92016-05-05 14:30:49 -07001614def scapyCheckConnection( main, senders, recipients, vlanId=None, packet=None, packetFilter=None, expectFailure=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001615 """
1616 Checks the connectivity between all given sender hosts and all given recipient hosts
1617 Packet may be specified. Defaults to Ether/IP packet
1618 Packet Filter may be specified. Defaults to Ether/IP from current sender MAC
1619 Todo: Optional packet and packet filter attributes for sender and recipients
1620 Expect Failure when the sender and recipient are not supposed to have connectivity
1621 Timeout of 1 second, returns main.TRUE if the filter is not triggered and kills the filter
1622
1623 """
1624 connectionsFunctional = main.TRUE
1625
1626 if not packetFilter:
1627 packetFilter = 'ether host {}'
1628
1629 if expectFailure:
1630 timeout = 1
1631 else:
1632 timeout = 10
1633
1634 for sender in senders:
1635 try:
1636 senderComp = getattr( main, sender )
1637 except AttributeError:
1638 main.log.error( "main has no attribute {}".format( sender ) )
1639 connectionsFunctional = main.FALSE
1640 continue
1641
1642 for recipient in recipients:
1643 # Do not send packets to self since recipient CLI will already be busy
1644 if recipient == sender:
1645 continue
1646 try:
1647 recipientComp = getattr( main, recipient )
1648 except AttributeError:
1649 main.log.error( "main has no attribute {}".format( recipient ) )
1650 connectionsFunctional = main.FALSE
1651 continue
1652
Jeremy Songster832f9e92016-05-05 14:30:49 -07001653 if vlanId:
1654 recipientComp.startFilter( pktFilter = ( "vlan {}".format( vlanId ) + " && " + packetFilter.format( senderComp.hostMac ) ) )
1655 else:
1656 recipientComp.startFilter( pktFilter = packetFilter.format( senderComp.hostMac ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001657
1658 if not packet:
Jeremy Songster832f9e92016-05-05 14:30:49 -07001659 if vlanId:
1660 pkt = 'Ether( src="{0}", dst="{2}" )/Dot1Q(vlan={4})/IP( src="{1}", dst="{3}" )'.format(
1661 senderComp.hostMac,
1662 senderComp.hostIp,
1663 recipientComp.hostMac,
1664 recipientComp.hostIp,
1665 vlanId )
1666 else:
1667 pkt = 'Ether( src="{0}", dst="{2}" )/IP( src="{1}", dst="{3}" )'.format(
1668 senderComp.hostMac,
1669 senderComp.hostIp,
1670 recipientComp.hostMac,
1671 recipientComp.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001672 else:
1673 pkt = packet
Jeremy Songster832f9e92016-05-05 14:30:49 -07001674 if vlanId:
1675 senderComp.sendPacket( iface=( "{0}-eth0.{1}".format( sender, vlanId ) ), packet = pkt )
1676 else:
1677 senderComp.sendPacket( packet = pkt )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001678
1679 if recipientComp.checkFilter( timeout ):
1680 if expectFailure:
1681 main.log.error( "Packet from {0} successfully received by {1} when it should not have been".format( sender , recipient ) )
1682 connectionsFunctional = main.FALSE
1683 else:
1684 main.log.info( "Packet from {0} successfully received by {1}".format( sender , recipient ) )
1685 else:
1686 recipientComp.killFilter()
1687 if expectFailure:
1688 main.log.info( "As expected, packet from {0} was not received by {1}".format( sender , recipient ) )
1689 else:
1690 main.log.error( "Packet from {0} was not received by {1}".format( sender , recipient ) )
1691 connectionsFunctional = main.FALSE
1692
1693 return connectionsFunctional
1694
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001695def removeAllIntents( main, intentsId ):
1696 """
1697 Remove all intents in the intentsId
1698 """
1699
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001700 onosSummary = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001701 removeIntentResult = main.TRUE
1702 # Remove intents
1703 for intent in intentsId:
1704 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
1705
acsmarscfa52272015-08-06 15:21:45 -07001706 time.sleep( main.removeIntentSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001707
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001708 # If there is remianing intents then remove intents should fail
1709 for i in range( main.numCtrls ):
1710 onosSummary.append( json.loads( main.CLIs[ i ].summary() ) )
1711
1712 for summary in onosSummary:
1713 if summary.get( 'intents' ) != 0:
1714 main.log.warn( itemName + ": There are " +
1715 str( summary.get( 'intents' ) ) +
1716 " intents remaining in node " +
1717 str( summary.get( 'node' ) ) +
1718 ", failed to remove all the intents " )
1719 removeIntentResult = main.FALSE
1720
1721 if removeIntentResult:
1722 main.log.info( itemName + ": There are no more intents remaining, " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001723 "successfully removed all the intents." )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001724
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001725 return removeIntentResult
1726
1727def checkFlowsCount( main ):
1728 """
1729 Check flows count in each node
1730 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001731 flowsCount = []
1732 main.log.info( itemName + ": Checking flows count in each ONOS node" )
1733 for i in range( main.numCtrls ):
1734 summaryResult = main.CLIs[ i ].summary()
1735 if not summaryResult:
1736 main.log.error( itemName + ": There is something wrong with " +
1737 "summary command" )
1738 return main.FALSE
1739 else:
1740 summaryJson = json.loads( summaryResult )
1741 flowsCount.append( summaryJson.get( 'flows' ) )
1742
1743 if flowsCount:
1744 if all( flows==flowsCount[ 0 ] for flows in flowsCount ):
1745 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
1746 " flows in all ONOS node" )
1747 else:
1748 for i in range( main.numCtrls ):
1749 main.log.debug( itemName + ": ONOS node " + str( i ) + " has " +
kelvin-onlab6dea6e62015-07-23 13:07:26 -07001750 str( flowsCount[ i ] ) + " flows" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001751 else:
1752 main.log.error( "Checking flows count failed, check summary command" )
1753 return main.FALSE
1754
1755 return main.TRUE
1756
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001757def checkLeaderChange( leaders1, leaders2 ):
acsmarse6b410f2015-07-17 14:39:34 -07001758 """
1759 Checks for a change in intent partition leadership.
1760
1761 Takes the output of leaders -c in json string format before and after
1762 a potential change as input
1763
1764 Returns main.TRUE if no mismatches are detected
1765 Returns main.FALSE if there is a mismatch or on error loading the input
1766 """
1767 try:
1768 leaders1 = json.loads( leaders1 )
1769 leaders2 = json.loads( leaders2 )
1770 except ( AttributeError, TypeError):
1771 main.log.exception( self.name + ": Object not as expected" )
1772 return main.FALSE
1773 except Exception:
1774 main.log.exception( self.name + ": Uncaught exception!" )
1775 main.cleanup()
1776 main.exit()
1777 main.log.info( "Checking Intent Paritions for Change in Leadership" )
1778 mismatch = False
1779 for dict1 in leaders1:
1780 if "intent" in dict1.get( "topic", [] ):
1781 for dict2 in leaders2:
1782 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \
1783 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
1784 mismatch = True
1785 main.log.error( "{0} changed leader from {1} to {2}".\
1786 format( dict1.get( "topic", "no-topic" ),\
1787 dict1.get( "leader", "no-leader" ),\
1788 dict2.get( "leader", "no-leader" ) ) )
1789 if mismatch:
1790 return main.FALSE
1791 else:
1792 return main.TRUE
kelvin-onlab016dce22015-08-10 09:54:11 -07001793
1794def report( main ):
1795 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001796 Report errors/warnings/exceptions
kelvin-onlab016dce22015-08-10 09:54:11 -07001797 """
kelvin-onlab016dce22015-08-10 09:54:11 -07001798 main.ONOSbench.logReport( main.ONOSip[ 0 ],
1799 [ "INFO",
1800 "FOLLOWER",
1801 "WARN",
1802 "flow",
1803 "ERROR",
1804 "Except" ],
1805 "s" )
1806
1807 main.log.info( "ERROR report: \n" )
1808 for i in range( main.numCtrls ):
1809 main.ONOSbench.logReport( main.ONOSip[ i ],
1810 [ "ERROR" ],
1811 "d" )
1812
1813 main.log.info( "EXCEPTIONS report: \n" )
1814 for i in range( main.numCtrls ):
1815 main.ONOSbench.logReport( main.ONOSip[ i ],
1816 [ "Except" ],
1817 "d" )
1818
1819 main.log.info( "WARNING report: \n" )
1820 for i in range( main.numCtrls ):
1821 main.ONOSbench.logReport( main.ONOSip[ i ],
1822 [ "WARN" ],
1823 "d" )