blob: 5b4bee17a76ecbecfae3e1fe1981dfa98c2426fe [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="",
Jeremy Songster9385d412016-06-02 17:57:36 -0700702 setVlan="",
703 partial=False ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700704 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800705 Installs a Single to Multi Point Intent
706
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700707 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800708 Install a single to multi point intent using
709 add-single-to-multi-intent
710
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700711 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800712 - Fetch host data if not given
713 - Add single to multi intent
714 - Ingress device is the first sender host
715 - Egress devices are the recipient devices
716 - Ports if defined in senders or recipients
717 - MAC address ethSrc loaded from Ingress device
718 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700719 Required:
720 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800721 senders - List of host dictionaries i.e.
722 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
723 recipients - List of host dictionaries i.e.
724 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700725 Optional:
726 onosNode - ONOS node to install the intents in main.CLIs[ ]
727 0 by default so that it will always use the first
728 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700729 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700730 bandwidth - Bandwidth capacity
731 lambdaAlloc - Allocate lambda, defaults to False
732 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700733 tcp - TCP ports in the same order as the hosts in hostNames
734 sw1 - First switch to bring down & up for rerouting purpose
735 sw2 - Second switch to bring down & up for rerouting purpose
736 expectedLink - Expected link when the switches are down, it should
737 be two links lower than the links before the two
738 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700739 """
740
741 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800742 assert senders, "You must specify a sender"
743 assert recipients, "You must specify a recipient"
744 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700745
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800746 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700747 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700748 onosNode = int( onosNode )
749
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700750 main.log.info( itemName + ": Adding single point to multi point intents" )
751
Jeremyd9e4eb12016-04-13 12:09:06 -0700752 try:
753 for sender in senders:
754 if not sender.get( "device" ):
755 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
756 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700757
Jeremyd9e4eb12016-04-13 12:09:06 -0700758 for recipient in recipients:
759 if not recipient.get( "device" ):
760 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
761 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700762
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700763
Jeremyd9e4eb12016-04-13 12:09:06 -0700764 ingressDevice = senders[ 0 ].get( "device" )
765 egressDeviceList = [ x.get( "device" ) for x in recipients if x.get( "device" ) ]
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800766
Jeremyd9e4eb12016-04-13 12:09:06 -0700767 portIngress = senders[ 0 ].get( "port", "" )
768 portEgressList = [ x.get( "port" ) for x in recipients if x.get( "port" ) ]
769 if not portEgressList:
770 portEgressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800771
Jeremyd9e4eb12016-04-13 12:09:06 -0700772 srcMac = senders[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700773 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800774
Jeremyd9e4eb12016-04-13 12:09:06 -0700775 # Adding point intent
776 intentId = main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
777 ingressDevice=ingressDevice,
778 egressDeviceList=egressDeviceList,
779 portIngress=portIngress,
780 portEgressList=portEgressList,
781 ethType=ethType,
782 ethSrc=srcMac,
783 bandwidth=bandwidth,
784 lambdaAlloc=lambdaAlloc,
785 ipProto=ipProto,
786 ipSrc="",
787 ipDst="",
788 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -0700789 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700790 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -0700791 setVlan=setVlan,
792 partial=partial )
Jeremyd9e4eb12016-04-13 12:09:06 -0700793 except (KeyError, TypeError):
794 errorMsg = "There was a problem loading the hosts data."
795 if intentId:
796 errorMsg += " There was a problem installing Singlepoint to Multipoint intent."
797 main.log.error( errorMsg )
798 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700799
800 # Check intents state
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800801 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
802 return intentId
acsmarsd4862d12015-10-06 17:57:34 -0700803 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800804 main.log.error( "Single to Multi Intent did not install correctly" )
805 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700806
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800807def installMultiToSingleIntent( main,
808 name,
809 senders,
810 recipients,
811 onosNode=0,
812 ethType="",
813 bandwidth="",
814 lambdaAlloc=False,
815 ipProto="",
816 ipAddresses="",
817 tcp="",
818 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700819 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -0700820 setVlan="",
821 partial=False ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700822 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800823 Installs a Multi to Single Point Intent
824
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700825 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800826 Install a multi to single point intent using
827 add-multi-to-single-intent
828
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700829 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800830 - Fetch host data if not given
831 - Add multi to single intent
832 - Ingress devices are the senders devices
833 - Egress device is the first recipient host
834 - Ports if defined in senders or recipients
835 - MAC address ethSrc loaded from Ingress device
836 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700837 Required:
838 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800839 senders - List of host dictionaries i.e.
840 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
841 recipients - List of host dictionaries i.e.
842 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700843 Optional:
844 onosNode - ONOS node to install the intents in main.CLIs[ ]
845 0 by default so that it will always use the first
846 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700847 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700848 bandwidth - Bandwidth capacity
849 lambdaAlloc - Allocate lambda, defaults to False
850 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700851 tcp - TCP ports in the same order as the hosts in hostNames
852 sw1 - First switch to bring down & up for rerouting purpose
853 sw2 - Second switch to bring down & up for rerouting purpose
854 expectedLink - Expected link when the switches are down, it should
855 be two links lower than the links before the two
856 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700857 """
858
859 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800860 assert senders, "You must specify a sender"
861 assert recipients, "You must specify a recipient"
862 # Assert devices or main.hostsData, "You must specify devices"
863
864 global itemName # The name of this run. Used for logs.
865 itemName = name
866 onosNode = int( onosNode )
867
868 main.log.info( itemName + ": Adding mutli to single point intents" )
869
Jeremyd9e4eb12016-04-13 12:09:06 -0700870 try:
871 for sender in senders:
872 if not sender.get( "device" ):
873 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
874 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800875
Jeremyd9e4eb12016-04-13 12:09:06 -0700876 for recipient in recipients:
877 if not recipient.get( "device" ):
878 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
879 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800880
Jeremyd9e4eb12016-04-13 12:09:06 -0700881 ingressDeviceList = [ x.get( "device" ) for x in senders if x.get( "device" ) ]
882 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800883
Jeremyd9e4eb12016-04-13 12:09:06 -0700884 portIngressList = [ x.get( "port" ) for x in senders if x.get( "port" ) ]
885 portEgress = recipients[ 0 ].get( "port", "" )
886 if not portIngressList:
887 portIngressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800888
Jeremyd9e4eb12016-04-13 12:09:06 -0700889 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700890 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800891
Jeremyd9e4eb12016-04-13 12:09:06 -0700892 # Adding point intent
893 intentId = main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
894 ingressDeviceList=ingressDeviceList,
895 egressDevice=egressDevice,
896 portIngressList=portIngressList,
897 portEgress=portEgress,
898 ethType=ethType,
899 ethDst=dstMac,
900 bandwidth=bandwidth,
901 lambdaAlloc=lambdaAlloc,
902 ipProto=ipProto,
903 ipSrc="",
904 ipDst="",
905 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -0700906 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700907 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -0700908 setVlan=setVlan,
909 partial=partial )
Jeremyd9e4eb12016-04-13 12:09:06 -0700910 except (KeyError, TypeError):
911 errorMsg = "There was a problem loading the hosts data."
912 if intentId:
913 errorMsg += " There was a problem installing Multipoint to Singlepoint intent."
914 main.log.error( errorMsg )
915 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800916
917 # Check intents state
918 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
919 return intentId
920 else:
921 main.log.error( "Multi to Single Intent did not install correctly" )
922 return main.FALSE
923
924def testPointIntent( main,
Jeremye0cb5eb2016-01-27 17:39:09 -0800925 name,
926 intentId,
927 senders,
928 recipients,
929 badSenders={},
930 badRecipients={},
931 onosNode=0,
932 ethType="",
933 bandwidth="",
934 lambdaAlloc=False,
935 ipProto="",
936 ipAddresses="",
937 tcp="",
938 sw1="s5",
939 sw2="s2",
Jeremy Songstere405d3d2016-05-17 11:18:57 -0700940 expectedLink=0,
941 useTCP=False):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800942 """
943 Test a Point Intent
944
945 Description:
946 Test a point intent
947
948 Steps:
949 - Fetch host data if not given
950 - Check Intent State
951 - Check Flow State
952 - Check Connectivity
953 - Check Lack of Connectivity Between Hosts not in the Intent
954 - Reroute
955 - Take Expected Link Down
956 - Check Intent State
957 - Check Flow State
958 - Check Topology
959 - Check Connectivity
960 - Bring Expected Link Up
961 - Check Intent State
962 - Check Flow State
963 - Check Topology
964 - Check Connectivity
965 - Remove Topology
966
967 Required:
968 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
969
970 senders - List of host dictionaries i.e.
971 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
972 recipients - List of host dictionaries i.e.
973 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
974 Optional:
975 onosNode - ONOS node to install the intents in main.CLIs[ ]
976 0 by default so that it will always use the first
977 ONOS node
978 ethType - Ethernet type eg. IPV4, IPV6
979 bandwidth - Bandwidth capacity
980 lambdaAlloc - Allocate lambda, defaults to False
981 ipProto - IP protocol
982 tcp - TCP ports in the same order as the hosts in hostNames
983 sw1 - First switch to bring down & up for rerouting purpose
984 sw2 - Second switch to bring down & up for rerouting purpose
985 expectedLink - Expected link when the switches are down, it should
986 be two links lower than the links before the two
987 switches are down
988
989 """
990
991 # Parameter Validity Check
992 assert main, "There is no main variable"
993 assert senders, "You must specify a sender"
994 assert recipients, "You must specify a recipient"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700995
996 global itemName
997 itemName = name
998 tempHostsData = {}
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700999 onosNode = int( onosNode )
1000
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001001 main.log.info( itemName + ": Testing Point Intent" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001002
Jeremyd9e4eb12016-04-13 12:09:06 -07001003 try:
1004 # Names for scapy
1005 senderNames = [ x.get( "name" ) for x in senders ]
1006 recipientNames = [ x.get( "name" ) for x in recipients ]
1007 badSenderNames = [ x.get( "name" ) for x in badSenders ]
1008 badRecipientNames = [ x.get( "name" ) for x in badRecipients ]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001009
Jeremyd9e4eb12016-04-13 12:09:06 -07001010 for sender in senders:
1011 if not sender.get( "device" ):
1012 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1013 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001014
Jeremyd9e4eb12016-04-13 12:09:06 -07001015 for recipient in recipients:
1016 if not recipient.get( "device" ):
1017 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1018 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001019 vlanId = senders[ 0 ].get( "vlan" )
Jeremyd9e4eb12016-04-13 12:09:06 -07001020 except (KeyError, TypeError):
1021 main.log.error( "There was a problem loading the hosts data." )
1022 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001023
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001024 testResult = main.TRUE
1025 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001026
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001027 # Check intent state
1028 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1029 main.assertReturnString += 'Initial Intent State Passed\n'
acsmarsd4862d12015-10-06 17:57:34 -07001030 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001031 main.assertReturnString += 'Initial Intent State Failed\n'
1032 testResult = main.FALSE
1033
1034 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -07001035 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 -08001036 main.assertReturnString += 'Initial Flow State Passed\n'
1037 else:
1038 main.assertReturnString += 'Intial Flow State Failed\n'
1039 testResult = main.FALSE
1040
1041 # Check Connectivity
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001042 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId, useTCP ), attempts=3, sleep=5 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001043 main.assertReturnString += 'Initial Ping Passed\n'
1044 else:
1045 main.assertReturnString += 'Initial Ping Failed\n'
1046 testResult = main.FALSE
1047
1048 # Check connections that shouldn't work
1049 if badSenderNames:
1050 main.log.info( "Checking that packets from incorrect sender do not go through" )
1051 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, badSenderNames, recipientNames ), kwargs={ "expectFailure":True } ):
1052 main.assertReturnString += 'Bad Sender Ping Passed\n'
1053 else:
1054 main.assertReturnString += 'Bad Sender Ping Failed\n'
1055 testResult = main.FALSE
1056
1057 if badRecipientNames:
1058 main.log.info( "Checking that packets to incorrect recipients do not go through" )
1059 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, badRecipientNames ), kwargs={ "expectFailure":True } ):
1060 main.assertReturnString += 'Bad Recipient Ping Passed\n'
1061 else:
1062 main.assertReturnString += 'Bad Recipient Ping Failed\n'
1063 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001064
1065 # Test rerouting if these variables exist
1066 if sw1 and sw2 and expectedLink:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001067 # Take link down
1068 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001069 main.assertReturnString += 'Link Down Passed\n'
1070 else:
1071 main.assertReturnString += 'Link Down Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001072 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001073
acsmarsd4862d12015-10-06 17:57:34 -07001074 # Check intent state
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001075 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001076 main.assertReturnString += 'Link Down Intent State Passed\n'
1077 else:
1078 main.assertReturnString += 'Link Down Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001079 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001080
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001081 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -07001082 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 -08001083 main.assertReturnString += 'Link Down Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001084 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001085 main.assertReturnString += 'Link Down Flow State Failed\n'
1086 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001087
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001088 # Check OnosTopology
1089 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink ) ):
1090 main.assertReturnString += 'Link Down Topology State Passed\n'
1091 else:
1092 main.assertReturnString += 'Link Down Topology State Failed\n'
1093 testResult = main.FALSE
1094
1095 # Check Connection
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001096 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001097 main.assertReturnString += 'Link Down Pingall Passed\n'
1098 else:
1099 main.assertReturnString += 'Link Down Pingall Failed\n'
1100 testResult = main.FALSE
1101
1102 # Bring link up
1103 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001104 main.assertReturnString += 'Link Up Passed\n'
1105 else:
1106 main.assertReturnString += 'Link Up Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001107 testResult = main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -07001108
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001109 # Wait for reroute
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001110 time.sleep( main.rerouteSleep )
1111
acsmarsd4862d12015-10-06 17:57:34 -07001112 # Check Intents
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001113 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001114 main.assertReturnString += 'Link Up Intent State Passed\n'
1115 else:
1116 main.assertReturnString += 'Link Up Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001117 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001118
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001119 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -07001120 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 -08001121 main.assertReturnString += 'Link Up Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001122 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001123 main.assertReturnString += 'Link Up Flow State Failed\n'
1124 testResult = main.FALSE
1125
1126 # Check OnosTopology
1127 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
1128 main.assertReturnString += 'Link Up Topology State Passed\n'
1129 else:
1130 main.assertReturnString += 'Link Up Topology State Failed\n'
1131 testResult = main.FALSE
1132
1133 # Check Connection
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001134 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001135 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1136 else:
1137 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1138 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001139
1140 # Remove all intents
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001141 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001142 main.assertReturnString += 'Remove Intents Passed'
1143 else:
1144 main.assertReturnString += 'Remove Intents Failed'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001145 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001146
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001147 return testResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001148
Jeremye0cb5eb2016-01-27 17:39:09 -08001149def testEndPointFail( main,
1150 name,
1151 intentId,
1152 senders,
1153 recipients,
1154 isolatedSenders,
1155 isolatedRecipients,
1156 onosNode=0,
1157 ethType="",
1158 bandwidth="",
1159 lambdaAlloc=False,
1160 ipProto="",
1161 ipAddresses="",
1162 tcp="",
1163 sw1="",
1164 sw2="",
1165 sw3="",
1166 sw4="",
1167 sw5="",
1168 expectedLink1=0,
Jeremy Songster9385d412016-06-02 17:57:36 -07001169 expectedLink2=0,
1170 partial=False ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001171 """
1172 Test Single to Multipoint Topology for Endpoint failures
1173 """
1174
1175 # Parameter Validity Check
1176 assert main, "There is no main variable"
1177 assert senders, "You must specify a sender"
1178 assert recipients, "You must specify a recipient"
1179
1180 global itemName
1181 itemName = name
1182 tempHostsData = {}
1183 onosNode = int( onosNode )
1184
1185 main.log.info( itemName + ": Testing Point Intent" )
1186
Jeremyd9e4eb12016-04-13 12:09:06 -07001187 try:
1188 # Names for scapy
1189 senderNames = [ x.get( "name" ) for x in senders ]
1190 recipientNames = [ x.get( "name" ) for x in recipients ]
1191 isolatedSenderNames = [ x.get( "name" ) for x in isolatedSenders ]
1192 isolatedRecipientNames = [ x.get( "name" ) for x in isolatedRecipients ]
1193 connectedSenderNames = [x.get("name") for x in senders if x.get("name") not in isolatedSenderNames]
1194 connectedRecipientNames = [x.get("name") for x in recipients if x.get("name") not in isolatedRecipientNames]
Jeremye0cb5eb2016-01-27 17:39:09 -08001195
Jeremyd9e4eb12016-04-13 12:09:06 -07001196 for sender in senders:
1197 if not sender.get( "device" ):
1198 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1199 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremye0cb5eb2016-01-27 17:39:09 -08001200
Jeremyd9e4eb12016-04-13 12:09:06 -07001201 for recipient in recipients:
1202 if not recipient.get( "device" ):
1203 main.log.warn( "Device not given for recipient {0}. Loading from\
1204 main.hostData".format( recipient.get( "name" ) ) )
1205 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
1206 except (KeyError, TypeError):
1207 main.log.error( "There was a problem loading the hosts data." )
1208 return main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001209
1210 testResult = main.TRUE
1211 main.log.info( itemName + ": Adding multi point to single point intents" )
1212
1213 # Check intent state
1214 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1215 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1216 main.assertReturnString += 'Initial Intent State Passed\n'
1217 else:
1218 main.assertReturnString += 'Initial Intent State Failed\n'
1219 testResult = main.FALSE
1220
1221 # Check flows count in each node
1222 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
Jeremy Songster9385d412016-06-02 17:57:36 -07001223 args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState,
1224 retValue=main.FALSE,
1225 args=[ main ], attempts=5 ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001226 main.assertReturnString += 'Initial Flow State Passed\n'
1227 else:
1228 main.assertReturnString += 'Intial Flow State Failed\n'
1229 testResult = main.FALSE
1230
1231 # Check Connectivity
1232 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1233 args=( main, senderNames, recipientNames ) ):
1234 main.assertReturnString += 'Initial Connectivity Check Passed\n'
1235 else:
1236 main.assertReturnString += 'Initial Connectivity Check Failed\n'
1237 testResult = main.FALSE
1238
1239 # Take two links down
1240 # Take first link down
1241 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
1242 main.assertReturnString += 'Link Down Passed\n'
1243 else:
1244 main.assertReturnString += 'Link Down Failed\n'
1245 testResult = main.FALSE
1246
1247 # Take second link down
1248 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw4, "down" ) ):
1249 main.assertReturnString += 'Link Down Passed\n'
1250 else:
1251 main.assertReturnString += 'Link Down Failed\n'
1252 testResult = main.FALSE
1253
1254 # Check intent state
1255 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1256 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1257 main.assertReturnString += 'Link Down Intent State Passed\n'
1258 else:
1259 main.assertReturnString += 'Link Down Intent State Failed\n'
1260 testResult = main.FALSE
1261
1262 # Check flows count in each node
1263 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1264 args=[ main ] ) and utilities.retry( f=checkFlowsState,
1265 retValue=main.FALSE, args=[ main ] ):
1266 main.assertReturnString += 'Link Down Flow State Passed\n'
1267 else:
1268 main.assertReturnString += 'Link Down Flow State Failed\n'
1269 testResult = main.FALSE
1270
1271 # Check OnosTopology
1272 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink1 ) ):
1273 main.assertReturnString += 'Link Down Topology State Passed\n'
1274 else:
1275 main.assertReturnString += 'Link Down Topology State Failed\n'
1276 testResult = main.FALSE
1277
1278 # Check Connection
1279 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1280 args=( main, senderNames, recipientNames ) ):
1281 main.assertReturnString += 'Link Down Connectivity Check Passed\n'
1282 else:
1283 main.assertReturnString += 'Link Down Connectivity Check Failed\n'
1284 testResult = main.FALSE
1285
1286 # Take a third link down to isolate one node
1287 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw5, "down" ) ):
1288 main.assertReturnString += 'Isolation link Down Passed\n'
1289 else:
1290 main.assertReturnString += 'Isolation link Down Failed\n'
1291 testResult = main.FALSE
1292
Jeremy Songster9385d412016-06-02 17:57:36 -07001293 if partial:
1294 # Check intent state
1295 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1296 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1297 main.assertReturnString += 'Partial failure isolation link Down Intent State Passed\n'
1298 else:
1299 main.assertReturnString += 'Partial failure isolation link Down Intent State Failed\n'
1300 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001301
Jeremy Songster9385d412016-06-02 17:57:36 -07001302 # Check flows count in each node
1303 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1304 args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState,
1305 retValue=main.FALSE,
1306 args=[ main ], attempts=5 ):
1307 main.assertReturnString += 'Partial failure isolation link Down Flow State Passed\n'
1308 else:
1309 main.assertReturnString += 'Partial failure isolation link Down Flow State Failed\n'
1310 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001311
Jeremy Songster9385d412016-06-02 17:57:36 -07001312 # Check OnosTopology
1313 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink2 ) ):
1314 main.assertReturnString += 'Partial failure isolation link Down Topology State Passed\n'
1315 else:
1316 main.assertReturnString += 'Partial failure isolation link Down Topology State Failed\n'
1317 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001318
Jeremy Songster9385d412016-06-02 17:57:36 -07001319 # Check Connectivity
1320 # First check connectivity of any isolated senders to recipients
1321 if isolatedSenderNames:
1322 if scapyCheckConnection( main, isolatedSenderNames, recipientNames, None, None, None, None, main.TRUE ):
1323 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1324 else:
1325 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1326 testResult = main.FALSE
1327
1328 # Next check connectivity of senders to any isolated recipients
1329 if isolatedRecipientNames:
1330 if scapyCheckConnection( main, senderNames, isolatedRecipientNames, None, None, None, None, main.TRUE ):
1331 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1332 else:
1333 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1334 testResult = main.FALSE
1335
1336 # Next check connectivity of connected senders and recipients
1337 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1338 args=( main, connectedSenderNames , connectedRecipientNames ) ):
1339 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1340 else:
1341 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1342 testResult = main.FALSE
1343 else:
1344 # Check intent state
1345 if not utilities.retry( f=checkIntentState, retValue=main.TRUE,
1346 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1347 main.assertReturnString += 'Isolation link Down Intent State Passed\n'
1348 else:
1349 main.assertReturnString += 'Isolation link Down Intent State Failed\n'
1350 testResult = main.FALSE
1351
1352 # Check flows count in each node
1353 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1354 args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState,
1355 retValue=main.FALSE,
1356 args=[ main ], attempts=5 ):
1357 main.assertReturnString += 'Isolation link Down Flow State Passed\n'
1358 else:
1359 main.assertReturnString += 'Isolation link Down Flow State Failed\n'
1360 testResult = main.FALSE
1361
1362 # Check OnosTopology
1363 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink2 ) ):
1364 main.assertReturnString += 'Isolation link Down Topology State Passed\n'
1365 else:
1366 main.assertReturnString += 'Isolation link Down Topology State Failed\n'
1367 testResult = main.FALSE
1368
1369 # Check Connectivity
1370 # First check connectivity of any isolated senders to recipients
1371 if isolatedSenderNames:
1372 if scapyCheckConnection( main, isolatedSenderNames, recipientNames, None, None, None, None, main.TRUE ):
1373 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1374 else:
1375 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1376 testResult = main.FALSE
1377
1378 # Next check connectivity of senders to any isolated recipients
1379 if isolatedRecipientNames:
1380 if scapyCheckConnection( main, senderNames, isolatedRecipientNames, None, None, None, None, main.TRUE ):
1381 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1382 else:
1383 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1384 testResult = main.FALSE
1385
1386 # Next check connectivity of connected senders and recipients
1387 if utilities.retry( f=scapyCheckConnection, retValue=main.TRUE,
1388 args=( main, connectedSenderNames , connectedRecipientNames, None, None, None, None, main.TRUE ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001389 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1390 else:
1391 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1392 testResult = main.FALSE
1393
Jeremye0cb5eb2016-01-27 17:39:09 -08001394 # Bring the links back up
1395 # Bring first link up
1396 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
1397 main.assertReturnString += 'Link Up Passed\n'
1398 else:
1399 main.assertReturnString += 'Link Up Failed\n'
1400 testResult = main.FALSE
1401
1402 # Bring second link up
1403 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw5, "up" ) ):
1404 main.assertReturnString += 'Link Up Passed\n'
1405 else:
1406 main.assertReturnString += 'Link Up Failed\n'
1407 testResult = main.FALSE
1408
1409 # Bring third link up
1410 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw4, "up" ) ):
1411 main.assertReturnString += 'Link Up Passed\n'
1412 else:
1413 main.assertReturnString += 'Link Up Failed\n'
1414 testResult = main.FALSE
1415
1416 # Wait for reroute
1417 time.sleep( main.rerouteSleep )
1418
1419 # Check Intents
1420 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1421 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1422 main.assertReturnString += 'Link Up Intent State Passed\n'
1423 else:
1424 main.assertReturnString += 'Link Up Intent State Failed\n'
1425 testResult = main.FALSE
1426
1427 # Check flows count in each node
1428 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
Jeremy Songster9385d412016-06-02 17:57:36 -07001429 args=[ main ], sleep=5, attempts=5 ) and utilities.retry( f=checkFlowsState,
1430 retValue=main.FALSE,
1431 args=[ main ], sleep=5, attempts=5 ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001432 main.assertReturnString += 'Link Up Flow State Passed\n'
1433 else:
1434 main.assertReturnString += 'Link Up Flow State Failed\n'
1435 testResult = main.FALSE
1436
1437 # Check OnosTopology
1438 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
1439 main.assertReturnString += 'Link Up Topology State Passed\n'
1440 else:
1441 main.assertReturnString += 'Link Up Topology State Failed\n'
1442 testResult = main.FALSE
1443
1444 # Check Connection
1445 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1446 args=( main, senderNames, recipientNames ) ):
1447 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1448 else:
1449 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1450 testResult = main.FALSE
1451
1452 # Remove all intents
1453 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ):
1454 main.assertReturnString += 'Remove Intents Passed'
1455 else:
1456 main.assertReturnString += 'Remove Intents Failed'
1457 testResult = main.FALSE
1458
1459 return testResult
1460
1461
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001462def pingallHosts( main, hostList ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001463 """
1464 Ping all host in the hosts list variable
1465 """
Jon Halla5cb3412015-08-18 14:08:22 -07001466 main.log.info( "Pinging: " + str( hostList ) )
1467 return main.Mininet1.pingallHosts( hostList )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001468
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001469def fwdPingall( main ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001470 """
1471 Use fwd app and pingall to discover all the hosts
1472 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001473 activateResult = main.TRUE
1474 appCheck = main.TRUE
1475 getDataResult = main.TRUE
1476 main.log.info( "Activating reactive forwarding app " )
1477 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001478
1479 # Wait for forward app activation to propagate
kelvin-onlab0ad05d12015-07-23 14:21:15 -07001480 time.sleep( main.fwdSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001481
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001482 # Check that forwarding is enabled on all nodes
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001483 for i in range( main.numCtrls ):
1484 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
1485 if appCheck != main.TRUE:
1486 main.log.warn( main.CLIs[ i ].apps() )
1487 main.log.warn( main.CLIs[ i ].appIDs() )
1488
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001489 # Send pingall in mininet
1490 main.log.info( "Run Pingall" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001491 pingResult = main.Mininet1.pingall( timeout = 600 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001492
1493 main.log.info( "Deactivating reactive forwarding app " )
1494 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001495 if activateResult and deactivateResult:
1496 main.log.info( "Successfully used fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001497 getDataResult = main.TRUE
1498 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001499 main.log.info( "Failed to use fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001500 getDataResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001501 return getDataResult
1502
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001503def confirmHostDiscovery( main ):
1504 """
1505 Confirms that all ONOS nodes have discovered all scapy hosts
1506 """
1507 import collections
1508 scapyHostCount = len( main.scapyHosts )
1509 hosts = main.topo.getAllHosts( main ) # Get host data from each ONOS node
1510 hostFails = [] # Reset for each failed attempt
1511
1512 # Check for matching hosts on each node
1513 scapyHostIPs = [ x.hostIp for x in main.scapyHosts if x.hostIp != "0.0.0.0" ]
1514 for controller in range( main.numCtrls ):
1515 controllerStr = str( controller + 1 ) # ONOS node number
1516 # Compare Hosts
1517 # Load hosts data for controller node
Jeremyd9e4eb12016-04-13 12:09:06 -07001518 try:
1519 if hosts[ controller ]:
1520 main.log.info( "Hosts discovered" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001521 else:
Jeremyd9e4eb12016-04-13 12:09:06 -07001522 main.log.error( "Problem discovering hosts" )
1523 if hosts[ controller ] and "Error" not in hosts[ controller ]:
1524 try:
1525 hostData = json.loads( hosts[ controller ] )
1526 except ( TypeError, ValueError ):
1527 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001528 hostFails.append( controllerStr )
Jeremyd9e4eb12016-04-13 12:09:06 -07001529 else:
1530 onosHostIPs = [ x.get( "ipAddresses" )[ 0 ]
1531 for x in hostData
1532 if len( x.get( "ipAddresses" ) ) > 0 ]
1533 if not set( collections.Counter( scapyHostIPs ) ).issubset( set ( collections.Counter( onosHostIPs ) ) ):
1534 main.log.warn( "Controller {0} only sees nodes with {1} IPs. It should see all of the following: {2}".format( controllerStr, onosHostIPs, scapyHostIPs ) )
1535 hostFails.append( controllerStr )
1536 else:
1537 main.log.error( "Hosts returned nothing or an error." )
1538 hostFails.append( controllerStr )
1539 except IndexError:
1540 main.log.error( "Hosts returned nothing, Failed to discover hosts." )
1541 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001542
1543 if hostFails:
1544 main.log.error( "List of failed ONOS Nodes:" + ', '.join(map(str, hostFails )) )
1545 return main.FALSE
1546 else:
1547 return main.TRUE
1548
1549def sendDiscoveryArp( main, hosts=None ):
1550 """
1551 Sends Discovery ARP packets from each host provided
1552 Defaults to each host in main.scapyHosts
1553 """
1554 # Send an arp ping from each host
1555 if not hosts:
1556 hosts = main.scapyHosts
1557 for host in hosts:
1558 pkt = 'Ether( src="{0}")/ARP( psrc="{1}")'.format( host.hostMac ,host.hostIp )
1559 # Send from the VLAN interface if there is one so ONOS discovers the VLAN correctly
1560 iface = None
1561 for interface in host.getIfList():
1562 if '.' in interface:
1563 main.log.debug( "Detected VLAN interface {0}. Sending ARP packet from {0}".format( interface ) )
1564 iface = interface
1565 break
1566 host.sendPacket( packet=pkt, iface=iface )
1567 main.log.info( "Sending ARP packet from {0}".format( host.name ) )
1568
1569def populateHostData( main ):
1570 """
1571 Populates hostsData
1572 """
1573 import json
1574 try:
1575 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
1576 hosts = main.Mininet1.getHosts().keys()
1577 # TODO: Make better use of new getHosts function
1578 for host in hosts:
1579 main.hostsData[ host ] = {}
1580 main.hostsData[ host ][ 'mac' ] = \
1581 main.Mininet1.getMacAddress( host ).upper()
1582 for hostj in hostsJson:
1583 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
1584 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
1585 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
1586 main.hostsData[ host ][ 'location' ] = \
1587 hostj[ 'location' ][ 'elementId' ] + '/' + \
1588 hostj[ 'location' ][ 'port' ]
1589 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
1590 return main.TRUE
Jeremyd9e4eb12016-04-13 12:09:06 -07001591 except ValueError:
1592 main.log.error( "ValueError while populating hostsData" )
1593 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001594 except KeyError:
1595 main.log.error( "KeyError while populating hostsData")
1596 return main.FALSE
Jeremyd9e4eb12016-04-13 12:09:06 -07001597 except IndexError:
1598 main.log.error( "IndexError while populating hostsData" )
1599 return main.FALSE
1600 except TypeError:
1601 main.log.error( "TypeError while populating hostsData" )
1602 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001603
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001604def checkTopology( main, expectedLink ):
1605 statusResult = main.TRUE
1606 # Check onos topology
1607 main.log.info( itemName + ": Checking ONOS topology " )
1608
1609 for i in range( main.numCtrls ):
Flavio Castro82ee2f62016-06-07 15:04:12 -07001610 statusResult = main.CLIs[ i ].checkStatus( main.numSwitch,
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001611 expectedLink )\
1612 and statusResult
1613 if not statusResult:
1614 main.log.error( itemName + ": Topology mismatch" )
1615 else:
1616 main.log.info( itemName + ": Topology match" )
1617 return statusResult
1618
1619def checkIntentState( main, intentsId ):
1620 """
1621 This function will check intent state to make sure all the intents
1622 are in INSTALLED state
1623 """
1624
1625 intentResult = main.TRUE
1626 results = []
1627
1628 main.log.info( itemName + ": Checking intents state" )
1629 # First check of intents
1630 for i in range( main.numCtrls ):
1631 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
1632 results.append( tempResult )
1633
1634 expectedState = [ 'INSTALLED', 'INSTALLING' ]
1635
1636 if all( result == main.TRUE for result in results ):
1637 main.log.info( itemName + ": Intents are installed correctly" )
1638 else:
1639 # Wait for at least 5 second before checking the intents again
acsmarsb9a92692015-10-08 16:43:01 -07001640 main.log.error( "Intents are not installed correctly. Waiting 5 sec" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001641 time.sleep( 5 )
1642 results = []
1643 # Second check of intents since some of the intents may be in
1644 # INSTALLING state, they should be in INSTALLED at this time
1645 for i in range( main.numCtrls ):
Jeremy2f190ca2016-01-29 15:23:57 -08001646 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001647 results.append( tempResult )
1648 if all( result == main.TRUE for result in results ):
1649 main.log.info( itemName + ": Intents are installed correctly" )
acsmarsb9a92692015-10-08 16:43:01 -07001650 intentResult = main.TRUE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001651 else:
1652 main.log.error( itemName + ": Intents are NOT installed correctly" )
1653 intentResult = main.FALSE
1654
1655 return intentResult
1656
1657def checkFlowsState( main ):
1658
1659 main.log.info( itemName + ": Check flows state" )
Jeremy Songsterff553672016-05-12 17:06:23 -07001660 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState( isPENDING=False )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001661 return checkFlowsResult
1662
1663def link( main, sw1, sw2, option):
1664
1665 # link down
1666 main.log.info( itemName + ": Bring link " + option + "between " +
1667 sw1 + " and " + sw2 )
1668 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
1669 return linkResult
1670
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001671def scapyCheckConnection( main, senders, recipients, vlanId=None, useTCP=False, packet=None, packetFilter=None, expectFailure=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001672 """
1673 Checks the connectivity between all given sender hosts and all given recipient hosts
1674 Packet may be specified. Defaults to Ether/IP packet
1675 Packet Filter may be specified. Defaults to Ether/IP from current sender MAC
1676 Todo: Optional packet and packet filter attributes for sender and recipients
1677 Expect Failure when the sender and recipient are not supposed to have connectivity
1678 Timeout of 1 second, returns main.TRUE if the filter is not triggered and kills the filter
1679
1680 """
1681 connectionsFunctional = main.TRUE
1682
1683 if not packetFilter:
1684 packetFilter = 'ether host {}'
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001685 if useTCP:
1686 packetFilter += ' ip proto \\tcp tcp port {}'.format(main.params[ 'SDNIP' ][ 'dstPort' ])
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001687 if expectFailure:
1688 timeout = 1
1689 else:
1690 timeout = 10
1691
1692 for sender in senders:
1693 try:
1694 senderComp = getattr( main, sender )
1695 except AttributeError:
1696 main.log.error( "main has no attribute {}".format( sender ) )
1697 connectionsFunctional = main.FALSE
1698 continue
1699
1700 for recipient in recipients:
1701 # Do not send packets to self since recipient CLI will already be busy
1702 if recipient == sender:
1703 continue
1704 try:
1705 recipientComp = getattr( main, recipient )
1706 except AttributeError:
1707 main.log.error( "main has no attribute {}".format( recipient ) )
1708 connectionsFunctional = main.FALSE
1709 continue
1710
Jeremy Songster832f9e92016-05-05 14:30:49 -07001711 if vlanId:
1712 recipientComp.startFilter( pktFilter = ( "vlan {}".format( vlanId ) + " && " + packetFilter.format( senderComp.hostMac ) ) )
1713 else:
1714 recipientComp.startFilter( pktFilter = packetFilter.format( senderComp.hostMac ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001715
1716 if not packet:
Jeremy Songster832f9e92016-05-05 14:30:49 -07001717 if vlanId:
1718 pkt = 'Ether( src="{0}", dst="{2}" )/Dot1Q(vlan={4})/IP( src="{1}", dst="{3}" )'.format(
1719 senderComp.hostMac,
1720 senderComp.hostIp,
1721 recipientComp.hostMac,
1722 recipientComp.hostIp,
1723 vlanId )
1724 else:
1725 pkt = 'Ether( src="{0}", dst="{2}" )/IP( src="{1}", dst="{3}" )'.format(
1726 senderComp.hostMac,
1727 senderComp.hostIp,
1728 recipientComp.hostMac,
1729 recipientComp.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001730 else:
1731 pkt = packet
Jeremy Songster832f9e92016-05-05 14:30:49 -07001732 if vlanId:
1733 senderComp.sendPacket( iface=( "{0}-eth0.{1}".format( sender, vlanId ) ), packet = pkt )
1734 else:
1735 senderComp.sendPacket( packet = pkt )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001736
1737 if recipientComp.checkFilter( timeout ):
1738 if expectFailure:
1739 main.log.error( "Packet from {0} successfully received by {1} when it should not have been".format( sender , recipient ) )
1740 connectionsFunctional = main.FALSE
1741 else:
1742 main.log.info( "Packet from {0} successfully received by {1}".format( sender , recipient ) )
1743 else:
1744 recipientComp.killFilter()
1745 if expectFailure:
1746 main.log.info( "As expected, packet from {0} was not received by {1}".format( sender , recipient ) )
1747 else:
1748 main.log.error( "Packet from {0} was not received by {1}".format( sender , recipient ) )
1749 connectionsFunctional = main.FALSE
1750
1751 return connectionsFunctional
1752
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001753def removeAllIntents( main, intentsId ):
1754 """
1755 Remove all intents in the intentsId
1756 """
1757
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001758 onosSummary = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001759 removeIntentResult = main.TRUE
1760 # Remove intents
1761 for intent in intentsId:
1762 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
1763
acsmarscfa52272015-08-06 15:21:45 -07001764 time.sleep( main.removeIntentSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001765
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001766 # If there is remianing intents then remove intents should fail
1767 for i in range( main.numCtrls ):
1768 onosSummary.append( json.loads( main.CLIs[ i ].summary() ) )
1769
1770 for summary in onosSummary:
1771 if summary.get( 'intents' ) != 0:
1772 main.log.warn( itemName + ": There are " +
1773 str( summary.get( 'intents' ) ) +
1774 " intents remaining in node " +
1775 str( summary.get( 'node' ) ) +
1776 ", failed to remove all the intents " )
1777 removeIntentResult = main.FALSE
1778
1779 if removeIntentResult:
1780 main.log.info( itemName + ": There are no more intents remaining, " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001781 "successfully removed all the intents." )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001782
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001783 return removeIntentResult
1784
1785def checkFlowsCount( main ):
1786 """
1787 Check flows count in each node
1788 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001789 flowsCount = []
1790 main.log.info( itemName + ": Checking flows count in each ONOS node" )
1791 for i in range( main.numCtrls ):
1792 summaryResult = main.CLIs[ i ].summary()
1793 if not summaryResult:
1794 main.log.error( itemName + ": There is something wrong with " +
1795 "summary command" )
1796 return main.FALSE
1797 else:
1798 summaryJson = json.loads( summaryResult )
1799 flowsCount.append( summaryJson.get( 'flows' ) )
1800
1801 if flowsCount:
1802 if all( flows==flowsCount[ 0 ] for flows in flowsCount ):
1803 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
1804 " flows in all ONOS node" )
1805 else:
1806 for i in range( main.numCtrls ):
1807 main.log.debug( itemName + ": ONOS node " + str( i ) + " has " +
kelvin-onlab6dea6e62015-07-23 13:07:26 -07001808 str( flowsCount[ i ] ) + " flows" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001809 else:
1810 main.log.error( "Checking flows count failed, check summary command" )
1811 return main.FALSE
1812
1813 return main.TRUE
1814
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001815def checkLeaderChange( leaders1, leaders2 ):
acsmarse6b410f2015-07-17 14:39:34 -07001816 """
1817 Checks for a change in intent partition leadership.
1818
1819 Takes the output of leaders -c in json string format before and after
1820 a potential change as input
1821
1822 Returns main.TRUE if no mismatches are detected
1823 Returns main.FALSE if there is a mismatch or on error loading the input
1824 """
1825 try:
1826 leaders1 = json.loads( leaders1 )
1827 leaders2 = json.loads( leaders2 )
1828 except ( AttributeError, TypeError):
1829 main.log.exception( self.name + ": Object not as expected" )
1830 return main.FALSE
1831 except Exception:
1832 main.log.exception( self.name + ": Uncaught exception!" )
1833 main.cleanup()
1834 main.exit()
1835 main.log.info( "Checking Intent Paritions for Change in Leadership" )
1836 mismatch = False
1837 for dict1 in leaders1:
1838 if "intent" in dict1.get( "topic", [] ):
1839 for dict2 in leaders2:
1840 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \
1841 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
1842 mismatch = True
1843 main.log.error( "{0} changed leader from {1} to {2}".\
1844 format( dict1.get( "topic", "no-topic" ),\
1845 dict1.get( "leader", "no-leader" ),\
1846 dict2.get( "leader", "no-leader" ) ) )
1847 if mismatch:
1848 return main.FALSE
1849 else:
1850 return main.TRUE
kelvin-onlab016dce22015-08-10 09:54:11 -07001851
1852def report( main ):
1853 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001854 Report errors/warnings/exceptions
kelvin-onlab016dce22015-08-10 09:54:11 -07001855 """
kelvin-onlab016dce22015-08-10 09:54:11 -07001856 main.ONOSbench.logReport( main.ONOSip[ 0 ],
1857 [ "INFO",
1858 "FOLLOWER",
1859 "WARN",
1860 "flow",
1861 "ERROR",
1862 "Except" ],
1863 "s" )
1864
1865 main.log.info( "ERROR report: \n" )
1866 for i in range( main.numCtrls ):
1867 main.ONOSbench.logReport( main.ONOSip[ i ],
1868 [ "ERROR" ],
1869 "d" )
1870
1871 main.log.info( "EXCEPTIONS report: \n" )
1872 for i in range( main.numCtrls ):
1873 main.ONOSbench.logReport( main.ONOSip[ i ],
1874 [ "Except" ],
1875 "d" )
1876
1877 main.log.info( "WARNING report: \n" )
1878 for i in range( main.numCtrls ):
1879 main.ONOSbench.logReport( main.ONOSip[ i ],
1880 [ "WARN" ],
1881 "d" )