blob: 0164c68bbaebef18da9e034d806b1a0bb48ebc15 [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 ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -070094 main.assertReturnString += 'Install Intent State Passed\n'
95 if flowDuration( main ):
96 main.assertReturnString += 'Flow duration check Passed\n'
97 return intentId
98 else:
99 main.assertReturnString += 'Flow duration check failed\n'
100 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800101 else:
Jeremy2f190ca2016-01-29 15:23:57 -0800102 main.log.error( "Host Intent did not install correctly" )
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700103 main.assertReturnString += 'Install Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800104 return main.FALSE
105
106def testHostIntent( main,
107 name,
108 intentId,
109 host1,
110 host2,
111 onosNode=0,
112 sw1="s5",
113 sw2="s2",
114 expectedLink=0):
115 """
116 Test a Host Intent
117
118 Description:
119 Test a host intent of given ID between given hosts
120
121 Steps:
122 - Fetch host data if not given
123 - Check Intent State
124 - Check Flow State
125 - Check Connectivity
126 - Check Lack of Connectivity Between Hosts not in the Intent
127 - Reroute
128 - Take Expected Link Down
129 - Check Intent State
130 - Check Flow State
131 - Check Topology
132 - Check Connectivity
133 - Bring Expected Link Up
134 - Check Intent State
135 - Check Flow State
136 - Check Topology
137 - Check Connectivity
138 - Remove Topology
139
140 Required:
141 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
142 intentId - intent ID to be tested ( and removed )
143 host1 - Dictionary for host1
144 { "name":"h8", "id":"of:0000000000000005/8" }
145 host2 - Dictionary for host2
146 { "name":"h16", "id":"of:0000000000000006/8" }
147 Optional:
148 onosNode - ONOS node to install the intents in main.CLIs[ ]
149 0 by default so that it will always use the first
150 ONOS node
151 sw1 - First switch to bring down & up for rerouting purpose
152 sw2 - Second switch to bring down & up for rerouting purpose
153 expectedLink - Expected link when the switches are down, it should
154 be two links lower than the links before the two
155 switches are down
156
157 """
158
159 # Parameter Validity Check
160 assert main, "There is no main variable"
161 assert host1, "You must specify host1"
162 assert host2, "You must specify host2"
163
164 global itemName
165 itemName = name
166 tempHostsData = {}
167 onosNode = int( onosNode )
168
Jeremy2f190ca2016-01-29 15:23:57 -0800169 main.log.info( itemName + ": Testing Host Intent" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800170
Jeremyd9e4eb12016-04-13 12:09:06 -0700171 try:
172 if not host1.get( "id" ):
173 main.log.warn( "Id not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
174 host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800175
Jeremyd9e4eb12016-04-13 12:09:06 -0700176 if not host2.get( "id" ):
177 main.log.warn( "Id not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
178 host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800179
Jeremyd9e4eb12016-04-13 12:09:06 -0700180 senderNames = [ host1.get( "name" ), host2.get( "name" ) ]
181 recipientNames = [ host1.get( "name" ), host2.get( "name" ) ]
Jeremy Songster832f9e92016-05-05 14:30:49 -0700182 vlanId = host1.get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800183
Jeremyd9e4eb12016-04-13 12:09:06 -0700184 testResult = main.TRUE
185 except (KeyError, TypeError):
186 main.log.error( "There was a problem loading the hosts data." )
187 return main.FALSE
188
189 main.log.info( itemName + ": Testing Host to Host intents" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800190
191 # Check intent state
192 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
193 main.assertReturnString += 'Initial Intent State Passed\n'
194 else:
195 main.assertReturnString += 'Initial Intent State Failed\n'
196 testResult = main.FALSE
197
198 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -0700199 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 -0800200 main.assertReturnString += 'Initial Flow State Passed\n'
201 else:
202 main.assertReturnString += 'Intial Flow State Failed\n'
203 testResult = main.FALSE
204
205 # Check Connectivity
Jeremy Songster832f9e92016-05-05 14:30:49 -0700206 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800207 main.assertReturnString += 'Initial Ping Passed\n'
208 else:
209 main.assertReturnString += 'Initial Ping Failed\n'
210 testResult = main.FALSE
211
212 # Test rerouting if these variables exist
213 if sw1 and sw2 and expectedLink:
214 # Take link down
215 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
216 main.assertReturnString += 'Link Down Passed\n'
217 else:
218 main.assertReturnString += 'Link Down Failed\n'
219 testResult = main.FALSE
220
221 # Check intent state
222 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
223 main.assertReturnString += 'Link Down Intent State Passed\n'
224 else:
225 main.assertReturnString += 'Link Down Intent State Failed\n'
226 testResult = main.FALSE
227
228 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -0700229 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 -0800230 main.assertReturnString += 'Link Down Flow State Passed\n'
231 else:
232 main.assertReturnString += 'Link Down Flow State Failed\n'
233 testResult = main.FALSE
234
235 # Check OnosTopology
236 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink ) ):
237 main.assertReturnString += 'Link Down Topology State Passed\n'
238 else:
239 main.assertReturnString += 'Link Down Topology State Failed\n'
240 testResult = main.FALSE
241
242 # Check Connection
Jeremy Songster832f9e92016-05-05 14:30:49 -0700243 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800244 main.assertReturnString += 'Link Down Pingall Passed\n'
245 else:
246 main.assertReturnString += 'Link Down Pingall Failed\n'
247 testResult = main.FALSE
248
249 # Bring link up
250 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
251 main.assertReturnString += 'Link Up Passed\n'
252 else:
253 main.assertReturnString += 'Link Up Failed\n'
254 testResult = main.FALSE
255
256 # Wait for reroute
257 time.sleep( main.rerouteSleep )
258
259 # Check Intents
260 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
261 main.assertReturnString += 'Link Up Intent State Passed\n'
262 else:
263 main.assertReturnString += 'Link Up Intent State Failed\n'
264 testResult = main.FALSE
265
266 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -0700267 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 -0800268 main.assertReturnString += 'Link Up Flow State Passed\n'
269 else:
270 main.assertReturnString += 'Link Up Flow State Failed\n'
271 testResult = main.FALSE
272
273 # Check OnosTopology
274 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
275 main.assertReturnString += 'Link Up Topology State Passed\n'
276 else:
277 main.assertReturnString += 'Link Up Topology State Failed\n'
278 testResult = main.FALSE
279
280 # Check Connection
Jeremy Songster832f9e92016-05-05 14:30:49 -0700281 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800282 main.assertReturnString += 'Link Up Pingall Passed\n'
283 else:
284 main.assertReturnString += 'Link Up Pingall Failed\n'
285 testResult = main.FALSE
286
287 # Remove all intents
288 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ):
289 main.assertReturnString += 'Remove Intents Passed'
290 else:
291 main.assertReturnString += 'Remove Intents Failed'
292 testResult = main.FALSE
293
294 return testResult
295
296def installPointIntent( main,
297 name,
298 senders,
299 recipients,
300 onosNode=0,
301 ethType="",
302 bandwidth="",
303 lambdaAlloc=False,
304 ipProto="",
305 ipSrc="",
306 ipDst="",
307 tcpSrc="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700308 tcpDst="",
309 setVlan=""):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800310 """
311 Installs a Single to Single Point Intent
312
313 Description:
314 Install a single to single point intent
315
316 Steps:
317 - Fetch host data if not given
318 - Add point intent
319 - Ingress device is the first sender device
320 - Egress device is the first recipient device
321 - Ports if defined in senders or recipients
322 - MAC address ethSrc loaded from Ingress device
323 - Check intent state with retry
324 Required:
325 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
326 senders - List of host dictionaries i.e.
327 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
328 recipients - List of host dictionaries i.e.
329 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
330 Optional:
331 onosNode - ONOS node to install the intents in main.CLIs[ ]
332 0 by default so that it will always use the first
333 ONOS node
334 ethType - Ethernet type eg. IPV4, IPV6
335 bandwidth - Bandwidth capacity
336 lambdaAlloc - Allocate lambda, defaults to False
337 ipProto - IP protocol
338 tcp - TCP ports in the same order as the hosts in hostNames
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700339 sw1 - First switch to bring down & up for rerouting purpose
340 sw2 - Second switch to bring down & up for rerouting purpose
341 expectedLink - Expected link when the switches are down, it should
342 be two links lower than the links before the two
343 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700344 """
345
346 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800347 assert senders, "You must specify a sender"
348 assert recipients, "You must specify a recipient"
349 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700350
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800351 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700352 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700353 onosNode = int( onosNode )
354
Jeremy6f000c62016-02-25 17:02:28 -0800355 main.log.info( itemName + ": Adding point to point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700356
Jeremyd9e4eb12016-04-13 12:09:06 -0700357 try:
358 for sender in senders:
359 if not sender.get( "device" ):
360 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
361 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800362
Jeremyd9e4eb12016-04-13 12:09:06 -0700363 for recipient in recipients:
364 if not recipient.get( "device" ):
365 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
366 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800367
368
Jeremyd9e4eb12016-04-13 12:09:06 -0700369 ingressDevice = senders[ 0 ].get( "device" )
370 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800371
Jeremyd9e4eb12016-04-13 12:09:06 -0700372 portIngress = senders[ 0 ].get( "port", "" )
373 portEgress = recipients[ 0 ].get( "port", "" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800374
Jeremyd9e4eb12016-04-13 12:09:06 -0700375 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800376
Jeremyd9e4eb12016-04-13 12:09:06 -0700377 ipSrc = senders[ 0 ].get( "ip" )
378 ipDst = recipients[ 0 ].get( "ip" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800379
Jeremy Songster832f9e92016-05-05 14:30:49 -0700380 vlanId = senders[ 0 ].get( "vlan" )
381
Jeremyd9e4eb12016-04-13 12:09:06 -0700382 # Adding point intent
383 intentId = main.CLIs[ onosNode ].addPointIntent(
384 ingressDevice=ingressDevice,
385 egressDevice=egressDevice,
386 portIngress=portIngress,
387 portEgress=portEgress,
388 ethType=ethType,
389 ethDst=dstMac,
390 bandwidth=bandwidth,
391 lambdaAlloc=lambdaAlloc,
392 ipProto=ipProto,
393 ipSrc=ipSrc,
394 ipDst=ipDst,
395 tcpSrc=tcpSrc,
Jeremy Songster832f9e92016-05-05 14:30:49 -0700396 tcpDst=tcpDst,
Jeremy Songsterff553672016-05-12 17:06:23 -0700397 vlanId=vlanId,
398 setVlan=setVlan )
Jeremyd9e4eb12016-04-13 12:09:06 -0700399 except (KeyError, TypeError):
400 errorMsg = "There was a problem loading the hosts data."
401 if intentId:
402 errorMsg += " There was a problem installing Point to Point intent."
403 main.log.error( errorMsg )
404 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700405
406 # Check intents state
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700407 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
408 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
409 main.assertReturnString += 'Install Intent State Passed\n'
410 if flowDuration( main ):
411 main.assertReturnString += 'Flow duration check Passed\n'
412 return intentId
413 else:
414 main.assertReturnString += 'Flow duration check failed\n'
415 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -0700416 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800417 main.log.error( "Point Intent did not install correctly" )
418 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700419
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700420def pointIntentTcp( main,
421 name,
422 host1,
423 host2,
424 onosNode=0,
425 deviceId1="",
426 deviceId2="",
427 port1="",
428 port2="",
429 ethType="",
430 mac1="",
431 mac2="",
432 bandwidth="",
433 lambdaAlloc=False,
434 ipProto="",
435 ip1="",
436 ip2="",
437 tcp1="",
438 tcp2="",
439 sw1="",
440 sw2="",
441 expectedLink=0 ):
442
443 """
444 Description:
445 Verify add-point-intent only for TCP
446 Steps:
447 - Get device ids | ports
448 - Add point intents
449 - Check intents
450 - Verify flows
451 - Ping hosts
452 - Reroute
453 - Link down
454 - Verify flows
455 - Check topology
456 - Ping hosts
457 - Link up
458 - Verify flows
459 - Check topology
460 - Ping hosts
461 - Remove intents
462 Required:
463 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
464 host1 - Name of first host
465 host2 - Name of second host
466 Optional:
467 onosNode - ONOS node to install the intents in main.CLIs[ ]
468 0 by default so that it will always use the first
469 ONOS node
470 deviceId1 - ONOS device id of the first switch, the same as the
471 location of the first host eg. of:0000000000000001/1,
472 located at device 1 port 1
473 deviceId2 - ONOS device id of the second switch
474 port1 - The port number where the first host is attached
475 port2 - The port number where the second host is attached
476 ethType - Ethernet type eg. IPV4, IPV6
477 mac1 - Mac address of first host
478 mac2 - Mac address of the second host
479 bandwidth - Bandwidth capacity
480 lambdaAlloc - Allocate lambda, defaults to False
481 ipProto - IP protocol
482 ip1 - IP address of first host
483 ip2 - IP address of second host
484 tcp1 - TCP port of first host
485 tcp2 - TCP port of second host
486 sw1 - First switch to bring down & up for rerouting purpose
487 sw2 - Second switch to bring down & up for rerouting purpose
488 expectedLink - Expected link when the switches are down, it should
489 be two links lower than the links before the two
490 switches are down
491 """
492
493 assert main, "There is no main variable"
494 assert name, "variable name is empty"
495 assert host1 and host2, "You must specify hosts"
496
497 global itemName
498 itemName = name
499 host1 = host1
500 host2 = host2
501 hostNames = [ host1, host2 ]
502 intentsId = []
503
504 iperfResult = main.TRUE
505 intentResult = main.TRUE
506 removeIntentResult = main.TRUE
507 flowResult = main.TRUE
508 topoResult = main.TRUE
509 linkDownResult = main.TRUE
510 linkUpResult = main.TRUE
511 onosNode = int( onosNode )
512
513 # Adding bidirectional point intents
514 main.log.info( itemName + ": Adding point intents" )
515 intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
516 egressDevice=deviceId2,
517 portIngress=port1,
518 portEgress=port2,
519 ethType=ethType,
520 ethSrc=mac1,
521 ethDst=mac2,
522 bandwidth=bandwidth,
523 lambdaAlloc=lambdaAlloc,
524 ipProto=ipProto,
525 ipSrc=ip1,
526 ipDst=ip2,
527 tcpSrc=tcp1,
528 tcpDst="" )
529
530 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
531 egressDevice=deviceId1,
532 portIngress=port2,
533 portEgress=port1,
534 ethType=ethType,
535 ethSrc=mac2,
536 ethDst=mac1,
537 bandwidth=bandwidth,
538 lambdaAlloc=lambdaAlloc,
539 ipProto=ipProto,
540 ipSrc=ip2,
541 ipDst=ip1,
542 tcpSrc=tcp2,
543 tcpDst="" )
544
545 intent3 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
546 egressDevice=deviceId2,
547 portIngress=port1,
548 portEgress=port2,
549 ethType=ethType,
550 ethSrc=mac1,
551 ethDst=mac2,
552 bandwidth=bandwidth,
553 lambdaAlloc=lambdaAlloc,
554 ipProto=ipProto,
555 ipSrc=ip1,
556 ipDst=ip2,
557 tcpSrc="",
558 tcpDst=tcp2 )
559
560 intent4 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
561 egressDevice=deviceId1,
562 portIngress=port2,
563 portEgress=port1,
564 ethType=ethType,
565 ethSrc=mac2,
566 ethDst=mac1,
567 bandwidth=bandwidth,
568 lambdaAlloc=lambdaAlloc,
569 ipProto=ipProto,
570 ipSrc=ip2,
571 ipDst=ip1,
572 tcpSrc="",
573 tcpDst=tcp1 )
574 intentsId.append( intent1 )
575 intentsId.append( intent2 )
576 intentsId.append( intent3 )
577 intentsId.append( intent4 )
578
579 # Check intents state
580 time.sleep( main.checkIntentSleep )
581 intentResult = checkIntentState( main, intentsId )
582 # Check flows count in each node
583 checkFlowsCount( main )
584
585 # Check intents state again if first check fails...
586 if not intentResult:
587 intentResult = checkIntentState( main, intentsId )
588
589 # Check flows count in each node
590 checkFlowsCount( main )
591
592 # Verify flows
593 checkFlowsState( main )
594
595 # Run iperf to both host
acsmarsd4862d12015-10-06 17:57:34 -0700596 iperfTemp = main.Mininet1.iperftcp( host1,host2,10 )
597 iperfResult = iperfResult and iperfTemp
598 if iperfTemp:
599 main.assertReturnString += 'Initial Iperf Passed\n'
600 else:
601 main.assertReturnString += 'Initial Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700602
603 # Test rerouting if these variables exist
604 if sw1 and sw2 and expectedLink:
605 # link down
606 linkDownResult = link( main, sw1, sw2, "down" )
acsmarsd4862d12015-10-06 17:57:34 -0700607
608 if linkDownResult:
609 main.assertReturnString += 'Link Down Passed\n'
610 else:
611 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700612
613 # Check flows count in each node
614 checkFlowsCount( main )
615 # Verify flows
616 checkFlowsState( main )
617
618 # Check OnosTopology
619 topoResult = checkTopology( main, expectedLink )
acsmarsd4862d12015-10-06 17:57:34 -0700620 if topoResult:
621 main.assertReturnString += 'Link Down Topology State Passed\n'
622 else:
623 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700624
625 # Run iperf to both host
acsmarsd4862d12015-10-06 17:57:34 -0700626 iperfTemp = main.Mininet1.iperftcp( host1,host2,10 )
627 iperfResult = iperfResult and iperfTemp
628 if iperfTemp:
629 main.assertReturnString += 'Link Down Iperf Passed\n'
630 else:
631 main.assertReturnString += 'Link Down Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700632
acsmarsd4862d12015-10-06 17:57:34 -0700633 # Check intent state
634 intentTemp = checkIntentState( main, intentsId )
635 intentResult = intentResult and intentTemp
636 if intentTemp:
637 main.assertReturnString += 'Link Down Intent State Passed\n'
638 else:
639 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700640
641 # Checks ONOS state in link down
642 if linkDownResult and topoResult and iperfResult and intentResult:
643 main.log.info( itemName + ": Successfully brought link down" )
644 else:
645 main.log.error( itemName + ": Failed to bring link down" )
646
647 # link up
648 linkUpResult = link( main, sw1, sw2, "up" )
acsmarsd4862d12015-10-06 17:57:34 -0700649 if linkUpTemp:
650 main.assertReturnString += 'Link Up Passed\n'
651 else:
652 main.assertReturnString += 'Link Up Failed\n'
653
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700654 time.sleep( main.rerouteSleep )
655
656 # Check flows count in each node
657 checkFlowsCount( main )
658 # Verify flows
659 checkFlowsState( main )
660
661 # Check OnosTopology
662 topoResult = checkTopology( main, main.numLinks )
663
acsmarsd4862d12015-10-06 17:57:34 -0700664 if topoResult:
665 main.assertReturnString += 'Link Up Topology State Passed\n'
666 else:
667 main.assertReturnString += 'Link Up Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700668
acsmarsd4862d12015-10-06 17:57:34 -0700669 # Run iperf to both host
670 iperfTemp = main.Mininet1.iperftcp( host1,host2,10 )
671 iperfResult = iperfResult and iperfTemp
672 if iperfTemp:
673 main.assertReturnString += 'Link Up Iperf Passed\n'
674 else:
675 main.assertReturnString += 'Link Up Iperf Failed\n'
676
677 # Check intent state
678 intentTemp = checkIntentState( main, intentsId )
679 intentResult = intentResult and intentTemp
680 if intentTemp:
681 main.assertReturnString += 'Link Down Intent State Passed\n'
682 else:
683 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700684
685 # Checks ONOS state in link up
686 if linkUpResult and topoResult and iperfResult and intentResult:
687 main.log.info( itemName + ": Successfully brought link back up" )
688 else:
689 main.log.error( itemName + ": Failed to bring link back up" )
690
691 # Remove all intents
692 removeIntentResult = removeAllIntents( main, intentsId )
acsmarsd4862d12015-10-06 17:57:34 -0700693 if removeIntentResult:
694 main.assertReturnString += 'Remove Intents Passed'
695 else:
696 main.assertReturnString += 'Remove Intents Failed'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700697
698 stepResult = iperfResult and linkDownResult and linkUpResult \
699 and intentResult and removeIntentResult
700
701 return stepResult
702
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800703def installSingleToMultiIntent( main,
704 name,
705 senders,
706 recipients,
707 onosNode=0,
708 ethType="",
709 bandwidth="",
710 lambdaAlloc=False,
711 ipProto="",
712 ipAddresses="",
713 tcp="",
714 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700715 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -0700716 setVlan="",
717 partial=False ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700718 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800719 Installs a Single to Multi Point Intent
720
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700721 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800722 Install a single to multi point intent using
723 add-single-to-multi-intent
724
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700725 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800726 - Fetch host data if not given
727 - Add single to multi intent
728 - Ingress device is the first sender host
729 - Egress devices are the recipient devices
730 - Ports if defined in senders or recipients
731 - MAC address ethSrc loaded from Ingress device
732 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700733 Required:
734 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800735 senders - List of host dictionaries i.e.
736 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
737 recipients - List of host dictionaries i.e.
738 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700739 Optional:
740 onosNode - ONOS node to install the intents in main.CLIs[ ]
741 0 by default so that it will always use the first
742 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700743 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700744 bandwidth - Bandwidth capacity
745 lambdaAlloc - Allocate lambda, defaults to False
746 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700747 tcp - TCP ports in the same order as the hosts in hostNames
748 sw1 - First switch to bring down & up for rerouting purpose
749 sw2 - Second switch to bring down & up for rerouting purpose
750 expectedLink - Expected link when the switches are down, it should
751 be two links lower than the links before the two
752 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700753 """
754
755 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800756 assert senders, "You must specify a sender"
757 assert recipients, "You must specify a recipient"
758 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700759
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800760 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700761 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700762 onosNode = int( onosNode )
763
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700764 main.log.info( itemName + ": Adding single point to multi point intents" )
765
Jeremyd9e4eb12016-04-13 12:09:06 -0700766 try:
767 for sender in senders:
768 if not sender.get( "device" ):
769 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
770 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700771
Jeremyd9e4eb12016-04-13 12:09:06 -0700772 for recipient in recipients:
773 if not recipient.get( "device" ):
774 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
775 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700776
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700777
Jeremyd9e4eb12016-04-13 12:09:06 -0700778 ingressDevice = senders[ 0 ].get( "device" )
779 egressDeviceList = [ x.get( "device" ) for x in recipients if x.get( "device" ) ]
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800780
Jeremyd9e4eb12016-04-13 12:09:06 -0700781 portIngress = senders[ 0 ].get( "port", "" )
782 portEgressList = [ x.get( "port" ) for x in recipients if x.get( "port" ) ]
783 if not portEgressList:
784 portEgressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800785
Jeremyd9e4eb12016-04-13 12:09:06 -0700786 srcMac = senders[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700787 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800788
Jeremyd9e4eb12016-04-13 12:09:06 -0700789 # Adding point intent
790 intentId = main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
791 ingressDevice=ingressDevice,
792 egressDeviceList=egressDeviceList,
793 portIngress=portIngress,
794 portEgressList=portEgressList,
795 ethType=ethType,
796 ethSrc=srcMac,
797 bandwidth=bandwidth,
798 lambdaAlloc=lambdaAlloc,
799 ipProto=ipProto,
800 ipSrc="",
801 ipDst="",
802 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -0700803 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700804 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -0700805 setVlan=setVlan,
806 partial=partial )
Jeremyd9e4eb12016-04-13 12:09:06 -0700807 except (KeyError, TypeError):
808 errorMsg = "There was a problem loading the hosts data."
809 if intentId:
810 errorMsg += " There was a problem installing Singlepoint to Multipoint intent."
811 main.log.error( errorMsg )
812 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700813
814 # Check intents state
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700815 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
816 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
817 main.assertReturnString += 'Install Intent State Passed\n'
818 if flowDuration( main ):
819 main.assertReturnString += 'Flow duration check Passed\n'
820 return intentId
821 else:
822 main.assertReturnString += 'Flow duration check failed\n'
823 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -0700824 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800825 main.log.error( "Single to Multi Intent did not install correctly" )
826 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700827
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800828def installMultiToSingleIntent( main,
829 name,
830 senders,
831 recipients,
832 onosNode=0,
833 ethType="",
834 bandwidth="",
835 lambdaAlloc=False,
836 ipProto="",
837 ipAddresses="",
838 tcp="",
839 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700840 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -0700841 setVlan="",
842 partial=False ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700843 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800844 Installs a Multi to Single Point Intent
845
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700846 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800847 Install a multi to single point intent using
848 add-multi-to-single-intent
849
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700850 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800851 - Fetch host data if not given
852 - Add multi to single intent
853 - Ingress devices are the senders devices
854 - Egress device is the first recipient host
855 - Ports if defined in senders or recipients
856 - MAC address ethSrc loaded from Ingress device
857 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700858 Required:
859 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800860 senders - List of host dictionaries i.e.
861 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
862 recipients - List of host dictionaries i.e.
863 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700864 Optional:
865 onosNode - ONOS node to install the intents in main.CLIs[ ]
866 0 by default so that it will always use the first
867 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700868 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700869 bandwidth - Bandwidth capacity
870 lambdaAlloc - Allocate lambda, defaults to False
871 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700872 tcp - TCP ports in the same order as the hosts in hostNames
873 sw1 - First switch to bring down & up for rerouting purpose
874 sw2 - Second switch to bring down & up for rerouting purpose
875 expectedLink - Expected link when the switches are down, it should
876 be two links lower than the links before the two
877 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700878 """
879
880 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800881 assert senders, "You must specify a sender"
882 assert recipients, "You must specify a recipient"
883 # Assert devices or main.hostsData, "You must specify devices"
884
885 global itemName # The name of this run. Used for logs.
886 itemName = name
887 onosNode = int( onosNode )
888
889 main.log.info( itemName + ": Adding mutli to single point intents" )
890
Jeremyd9e4eb12016-04-13 12:09:06 -0700891 try:
892 for sender in senders:
893 if not sender.get( "device" ):
894 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
895 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800896
Jeremyd9e4eb12016-04-13 12:09:06 -0700897 for recipient in recipients:
898 if not recipient.get( "device" ):
899 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
900 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800901
Jeremyd9e4eb12016-04-13 12:09:06 -0700902 ingressDeviceList = [ x.get( "device" ) for x in senders if x.get( "device" ) ]
903 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800904
Jeremyd9e4eb12016-04-13 12:09:06 -0700905 portIngressList = [ x.get( "port" ) for x in senders if x.get( "port" ) ]
906 portEgress = recipients[ 0 ].get( "port", "" )
907 if not portIngressList:
908 portIngressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800909
Jeremyd9e4eb12016-04-13 12:09:06 -0700910 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700911 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800912
Jeremyd9e4eb12016-04-13 12:09:06 -0700913 # Adding point intent
914 intentId = main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
915 ingressDeviceList=ingressDeviceList,
916 egressDevice=egressDevice,
917 portIngressList=portIngressList,
918 portEgress=portEgress,
919 ethType=ethType,
920 ethDst=dstMac,
921 bandwidth=bandwidth,
922 lambdaAlloc=lambdaAlloc,
923 ipProto=ipProto,
924 ipSrc="",
925 ipDst="",
926 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -0700927 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700928 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -0700929 setVlan=setVlan,
930 partial=partial )
Jeremyd9e4eb12016-04-13 12:09:06 -0700931 except (KeyError, TypeError):
932 errorMsg = "There was a problem loading the hosts data."
933 if intentId:
934 errorMsg += " There was a problem installing Multipoint to Singlepoint intent."
935 main.log.error( errorMsg )
936 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800937
938 # Check intents state
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700939 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
940 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
941 main.assertReturnString += 'Install Intent State Passed\n'
942 if flowDuration( main ):
943 main.assertReturnString += 'Flow duration check Passed\n'
944 return intentId
945 else:
946 main.assertReturnString += 'Flow duration check failed\n'
947 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800948 else:
949 main.log.error( "Multi to Single Intent did not install correctly" )
950 return main.FALSE
951
952def testPointIntent( main,
Jeremye0cb5eb2016-01-27 17:39:09 -0800953 name,
954 intentId,
955 senders,
956 recipients,
957 badSenders={},
958 badRecipients={},
959 onosNode=0,
960 ethType="",
961 bandwidth="",
962 lambdaAlloc=False,
963 ipProto="",
964 ipAddresses="",
965 tcp="",
966 sw1="s5",
967 sw2="s2",
Jeremy Songstere405d3d2016-05-17 11:18:57 -0700968 expectedLink=0,
969 useTCP=False):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800970 """
971 Test a Point Intent
972
973 Description:
974 Test a point intent
975
976 Steps:
977 - Fetch host data if not given
978 - Check Intent State
979 - Check Flow State
980 - Check Connectivity
981 - Check Lack of Connectivity Between Hosts not in the Intent
982 - Reroute
983 - Take Expected Link Down
984 - Check Intent State
985 - Check Flow State
986 - Check Topology
987 - Check Connectivity
988 - Bring Expected Link Up
989 - Check Intent State
990 - Check Flow State
991 - Check Topology
992 - Check Connectivity
993 - Remove Topology
994
995 Required:
996 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
997
998 senders - List of host dictionaries i.e.
999 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
1000 recipients - List of host dictionaries i.e.
1001 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
1002 Optional:
1003 onosNode - ONOS node to install the intents in main.CLIs[ ]
1004 0 by default so that it will always use the first
1005 ONOS node
1006 ethType - Ethernet type eg. IPV4, IPV6
1007 bandwidth - Bandwidth capacity
1008 lambdaAlloc - Allocate lambda, defaults to False
1009 ipProto - IP protocol
1010 tcp - TCP ports in the same order as the hosts in hostNames
1011 sw1 - First switch to bring down & up for rerouting purpose
1012 sw2 - Second switch to bring down & up for rerouting purpose
1013 expectedLink - Expected link when the switches are down, it should
1014 be two links lower than the links before the two
1015 switches are down
1016
1017 """
1018
1019 # Parameter Validity Check
1020 assert main, "There is no main variable"
1021 assert senders, "You must specify a sender"
1022 assert recipients, "You must specify a recipient"
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001023
1024 global itemName
1025 itemName = name
1026 tempHostsData = {}
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001027 onosNode = int( onosNode )
1028
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001029 main.log.info( itemName + ": Testing Point Intent" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001030
Jeremyd9e4eb12016-04-13 12:09:06 -07001031 try:
1032 # Names for scapy
1033 senderNames = [ x.get( "name" ) for x in senders ]
1034 recipientNames = [ x.get( "name" ) for x in recipients ]
1035 badSenderNames = [ x.get( "name" ) for x in badSenders ]
1036 badRecipientNames = [ x.get( "name" ) for x in badRecipients ]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001037
Jeremyd9e4eb12016-04-13 12:09:06 -07001038 for sender in senders:
1039 if not sender.get( "device" ):
1040 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1041 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001042
Jeremyd9e4eb12016-04-13 12:09:06 -07001043 for recipient in recipients:
1044 if not recipient.get( "device" ):
1045 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1046 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001047 vlanId = senders[ 0 ].get( "vlan" )
Jeremyd9e4eb12016-04-13 12:09:06 -07001048 except (KeyError, TypeError):
1049 main.log.error( "There was a problem loading the hosts data." )
1050 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001051
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001052 testResult = main.TRUE
1053 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001054
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001055 # Check intent state
1056 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1057 main.assertReturnString += 'Initial Intent State Passed\n'
acsmarsd4862d12015-10-06 17:57:34 -07001058 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001059 main.assertReturnString += 'Initial Intent State Failed\n'
1060 testResult = main.FALSE
1061
1062 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -07001063 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 -08001064 main.assertReturnString += 'Initial Flow State Passed\n'
1065 else:
1066 main.assertReturnString += 'Intial Flow State Failed\n'
1067 testResult = main.FALSE
1068
1069 # Check Connectivity
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001070 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 -08001071 main.assertReturnString += 'Initial Ping Passed\n'
1072 else:
1073 main.assertReturnString += 'Initial Ping Failed\n'
1074 testResult = main.FALSE
1075
1076 # Check connections that shouldn't work
1077 if badSenderNames:
1078 main.log.info( "Checking that packets from incorrect sender do not go through" )
1079 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, badSenderNames, recipientNames ), kwargs={ "expectFailure":True } ):
1080 main.assertReturnString += 'Bad Sender Ping Passed\n'
1081 else:
1082 main.assertReturnString += 'Bad Sender Ping Failed\n'
1083 testResult = main.FALSE
1084
1085 if badRecipientNames:
1086 main.log.info( "Checking that packets to incorrect recipients do not go through" )
1087 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, badRecipientNames ), kwargs={ "expectFailure":True } ):
1088 main.assertReturnString += 'Bad Recipient Ping Passed\n'
1089 else:
1090 main.assertReturnString += 'Bad Recipient Ping Failed\n'
1091 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001092
1093 # Test rerouting if these variables exist
1094 if sw1 and sw2 and expectedLink:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001095 # Take link down
1096 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001097 main.assertReturnString += 'Link Down Passed\n'
1098 else:
1099 main.assertReturnString += 'Link Down Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001100 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001101
acsmarsd4862d12015-10-06 17:57:34 -07001102 # Check intent state
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001103 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001104 main.assertReturnString += 'Link Down Intent State Passed\n'
1105 else:
1106 main.assertReturnString += 'Link Down Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001107 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001108
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001109 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -07001110 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 -08001111 main.assertReturnString += 'Link Down Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001112 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001113 main.assertReturnString += 'Link Down Flow State Failed\n'
1114 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001115
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001116 # Check OnosTopology
1117 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink ) ):
1118 main.assertReturnString += 'Link Down Topology State Passed\n'
1119 else:
1120 main.assertReturnString += 'Link Down Topology State Failed\n'
1121 testResult = main.FALSE
1122
1123 # Check Connection
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001124 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001125 main.assertReturnString += 'Link Down Pingall Passed\n'
1126 else:
1127 main.assertReturnString += 'Link Down Pingall Failed\n'
1128 testResult = main.FALSE
1129
1130 # Bring link up
1131 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001132 main.assertReturnString += 'Link Up Passed\n'
1133 else:
1134 main.assertReturnString += 'Link Up Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001135 testResult = main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -07001136
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001137 # Wait for reroute
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001138 time.sleep( main.rerouteSleep )
1139
acsmarsd4862d12015-10-06 17:57:34 -07001140 # Check Intents
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001141 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001142 main.assertReturnString += 'Link Up Intent State Passed\n'
1143 else:
1144 main.assertReturnString += 'Link Up Intent State Failed\n'
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 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -07001148 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 -08001149 main.assertReturnString += 'Link Up Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001150 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001151 main.assertReturnString += 'Link Up Flow State Failed\n'
1152 testResult = main.FALSE
1153
1154 # Check OnosTopology
1155 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
1156 main.assertReturnString += 'Link Up Topology State Passed\n'
1157 else:
1158 main.assertReturnString += 'Link Up Topology State Failed\n'
1159 testResult = main.FALSE
1160
1161 # Check Connection
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001162 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001163 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1164 else:
1165 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1166 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001167
1168 # Remove all intents
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001169 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001170 main.assertReturnString += 'Remove Intents Passed'
1171 else:
1172 main.assertReturnString += 'Remove Intents Failed'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001173 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001174
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001175 return testResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001176
Jeremye0cb5eb2016-01-27 17:39:09 -08001177def testEndPointFail( main,
1178 name,
1179 intentId,
1180 senders,
1181 recipients,
1182 isolatedSenders,
1183 isolatedRecipients,
1184 onosNode=0,
1185 ethType="",
1186 bandwidth="",
1187 lambdaAlloc=False,
1188 ipProto="",
1189 ipAddresses="",
1190 tcp="",
1191 sw1="",
1192 sw2="",
1193 sw3="",
1194 sw4="",
1195 sw5="",
1196 expectedLink1=0,
Jeremy Songster9385d412016-06-02 17:57:36 -07001197 expectedLink2=0,
1198 partial=False ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001199 """
1200 Test Single to Multipoint Topology for Endpoint failures
1201 """
1202
1203 # Parameter Validity Check
1204 assert main, "There is no main variable"
1205 assert senders, "You must specify a sender"
1206 assert recipients, "You must specify a recipient"
1207
1208 global itemName
1209 itemName = name
1210 tempHostsData = {}
1211 onosNode = int( onosNode )
1212
1213 main.log.info( itemName + ": Testing Point Intent" )
1214
Jeremyd9e4eb12016-04-13 12:09:06 -07001215 try:
1216 # Names for scapy
1217 senderNames = [ x.get( "name" ) for x in senders ]
1218 recipientNames = [ x.get( "name" ) for x in recipients ]
1219 isolatedSenderNames = [ x.get( "name" ) for x in isolatedSenders ]
1220 isolatedRecipientNames = [ x.get( "name" ) for x in isolatedRecipients ]
1221 connectedSenderNames = [x.get("name") for x in senders if x.get("name") not in isolatedSenderNames]
1222 connectedRecipientNames = [x.get("name") for x in recipients if x.get("name") not in isolatedRecipientNames]
Jeremye0cb5eb2016-01-27 17:39:09 -08001223
Jeremyd9e4eb12016-04-13 12:09:06 -07001224 for sender in senders:
1225 if not sender.get( "device" ):
1226 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1227 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremye0cb5eb2016-01-27 17:39:09 -08001228
Jeremyd9e4eb12016-04-13 12:09:06 -07001229 for recipient in recipients:
1230 if not recipient.get( "device" ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001231 main.log.warn( "Device not given for recipient {0}. Loading from " +\
1232 main.hostData.format( recipient.get( "name" ) ) )
Jeremyd9e4eb12016-04-13 12:09:06 -07001233 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
1234 except (KeyError, TypeError):
1235 main.log.error( "There was a problem loading the hosts data." )
1236 return main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001237
1238 testResult = main.TRUE
1239 main.log.info( itemName + ": Adding multi point to single point intents" )
1240
1241 # Check intent state
1242 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1243 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1244 main.assertReturnString += 'Initial Intent State Passed\n'
1245 else:
1246 main.assertReturnString += 'Initial Intent State Failed\n'
1247 testResult = main.FALSE
1248
1249 # Check flows count in each node
1250 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
Jeremy Songster9385d412016-06-02 17:57:36 -07001251 args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState,
1252 retValue=main.FALSE,
1253 args=[ main ], attempts=5 ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001254 main.assertReturnString += 'Initial Flow State Passed\n'
1255 else:
1256 main.assertReturnString += 'Intial Flow State Failed\n'
1257 testResult = main.FALSE
1258
1259 # Check Connectivity
1260 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1261 args=( main, senderNames, recipientNames ) ):
1262 main.assertReturnString += 'Initial Connectivity Check Passed\n'
1263 else:
1264 main.assertReturnString += 'Initial Connectivity Check Failed\n'
1265 testResult = main.FALSE
1266
1267 # Take two links down
1268 # Take first link down
1269 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
1270 main.assertReturnString += 'Link Down Passed\n'
1271 else:
1272 main.assertReturnString += 'Link Down Failed\n'
1273 testResult = main.FALSE
1274
1275 # Take second link down
1276 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw4, "down" ) ):
1277 main.assertReturnString += 'Link Down Passed\n'
1278 else:
1279 main.assertReturnString += 'Link Down Failed\n'
1280 testResult = main.FALSE
1281
1282 # Check intent state
1283 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1284 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1285 main.assertReturnString += 'Link Down Intent State Passed\n'
1286 else:
1287 main.assertReturnString += 'Link Down Intent State Failed\n'
1288 testResult = main.FALSE
1289
1290 # Check flows count in each node
1291 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1292 args=[ main ] ) and utilities.retry( f=checkFlowsState,
1293 retValue=main.FALSE, args=[ main ] ):
1294 main.assertReturnString += 'Link Down Flow State Passed\n'
1295 else:
1296 main.assertReturnString += 'Link Down Flow State Failed\n'
1297 testResult = main.FALSE
1298
1299 # Check OnosTopology
1300 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink1 ) ):
1301 main.assertReturnString += 'Link Down Topology State Passed\n'
1302 else:
1303 main.assertReturnString += 'Link Down Topology State Failed\n'
1304 testResult = main.FALSE
1305
1306 # Check Connection
1307 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1308 args=( main, senderNames, recipientNames ) ):
1309 main.assertReturnString += 'Link Down Connectivity Check Passed\n'
1310 else:
1311 main.assertReturnString += 'Link Down Connectivity Check Failed\n'
1312 testResult = main.FALSE
1313
1314 # Take a third link down to isolate one node
1315 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw5, "down" ) ):
1316 main.assertReturnString += 'Isolation link Down Passed\n'
1317 else:
1318 main.assertReturnString += 'Isolation link Down Failed\n'
1319 testResult = main.FALSE
1320
Jeremy Songster9385d412016-06-02 17:57:36 -07001321 if partial:
1322 # Check intent state
1323 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1324 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1325 main.assertReturnString += 'Partial failure isolation link Down Intent State Passed\n'
1326 else:
1327 main.assertReturnString += 'Partial failure isolation link Down Intent State Failed\n'
1328 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001329
Jeremy Songster9385d412016-06-02 17:57:36 -07001330 # Check flows count in each node
1331 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1332 args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState,
1333 retValue=main.FALSE,
1334 args=[ main ], attempts=5 ):
1335 main.assertReturnString += 'Partial failure isolation link Down Flow State Passed\n'
1336 else:
1337 main.assertReturnString += 'Partial failure isolation link Down Flow State Failed\n'
1338 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001339
Jeremy Songster9385d412016-06-02 17:57:36 -07001340 # Check OnosTopology
1341 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink2 ) ):
1342 main.assertReturnString += 'Partial failure isolation link Down Topology State Passed\n'
1343 else:
1344 main.assertReturnString += 'Partial failure isolation link Down Topology State Failed\n'
1345 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001346
Jeremy Songster9385d412016-06-02 17:57:36 -07001347 # Check Connectivity
1348 # First check connectivity of any isolated senders to recipients
1349 if isolatedSenderNames:
1350 if scapyCheckConnection( main, isolatedSenderNames, recipientNames, None, None, None, None, main.TRUE ):
1351 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1352 else:
1353 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1354 testResult = main.FALSE
1355
1356 # Next check connectivity of senders to any isolated recipients
1357 if isolatedRecipientNames:
1358 if scapyCheckConnection( main, senderNames, isolatedRecipientNames, None, None, None, None, main.TRUE ):
1359 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1360 else:
1361 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1362 testResult = main.FALSE
1363
1364 # Next check connectivity of connected senders and recipients
1365 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1366 args=( main, connectedSenderNames , connectedRecipientNames ) ):
1367 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1368 else:
1369 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1370 testResult = main.FALSE
1371 else:
1372 # Check intent state
1373 if not utilities.retry( f=checkIntentState, retValue=main.TRUE,
1374 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1375 main.assertReturnString += 'Isolation link Down Intent State Passed\n'
1376 else:
1377 main.assertReturnString += 'Isolation link Down Intent State Failed\n'
1378 testResult = main.FALSE
1379
1380 # Check flows count in each node
1381 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1382 args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState,
1383 retValue=main.FALSE,
1384 args=[ main ], attempts=5 ):
1385 main.assertReturnString += 'Isolation link Down Flow State Passed\n'
1386 else:
1387 main.assertReturnString += 'Isolation link Down Flow State Failed\n'
1388 testResult = main.FALSE
1389
1390 # Check OnosTopology
1391 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink2 ) ):
1392 main.assertReturnString += 'Isolation link Down Topology State Passed\n'
1393 else:
1394 main.assertReturnString += 'Isolation link Down Topology State Failed\n'
1395 testResult = main.FALSE
1396
1397 # Check Connectivity
1398 # First check connectivity of any isolated senders to recipients
1399 if isolatedSenderNames:
1400 if scapyCheckConnection( main, isolatedSenderNames, recipientNames, None, None, None, None, main.TRUE ):
1401 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1402 else:
1403 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1404 testResult = main.FALSE
1405
1406 # Next check connectivity of senders to any isolated recipients
1407 if isolatedRecipientNames:
1408 if scapyCheckConnection( main, senderNames, isolatedRecipientNames, None, None, None, None, main.TRUE ):
1409 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1410 else:
1411 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1412 testResult = main.FALSE
1413
1414 # Next check connectivity of connected senders and recipients
1415 if utilities.retry( f=scapyCheckConnection, retValue=main.TRUE,
1416 args=( main, connectedSenderNames , connectedRecipientNames, None, None, None, None, main.TRUE ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001417 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1418 else:
1419 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1420 testResult = main.FALSE
1421
Jeremye0cb5eb2016-01-27 17:39:09 -08001422 # Bring the links back up
1423 # Bring first link up
1424 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
1425 main.assertReturnString += 'Link Up Passed\n'
1426 else:
1427 main.assertReturnString += 'Link Up Failed\n'
1428 testResult = main.FALSE
1429
1430 # Bring second link up
1431 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw5, "up" ) ):
1432 main.assertReturnString += 'Link Up Passed\n'
1433 else:
1434 main.assertReturnString += 'Link Up Failed\n'
1435 testResult = main.FALSE
1436
1437 # Bring third link up
1438 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw4, "up" ) ):
1439 main.assertReturnString += 'Link Up Passed\n'
1440 else:
1441 main.assertReturnString += 'Link Up Failed\n'
1442 testResult = main.FALSE
1443
1444 # Wait for reroute
1445 time.sleep( main.rerouteSleep )
1446
1447 # Check Intents
1448 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1449 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1450 main.assertReturnString += 'Link Up Intent State Passed\n'
1451 else:
1452 main.assertReturnString += 'Link Up Intent State Failed\n'
1453 testResult = main.FALSE
1454
1455 # Check flows count in each node
1456 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
Jeremy Songster9385d412016-06-02 17:57:36 -07001457 args=[ main ], sleep=5, attempts=5 ) and utilities.retry( f=checkFlowsState,
1458 retValue=main.FALSE,
1459 args=[ main ], sleep=5, attempts=5 ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001460 main.assertReturnString += 'Link Up Flow State Passed\n'
1461 else:
1462 main.assertReturnString += 'Link Up Flow State Failed\n'
1463 testResult = main.FALSE
1464
1465 # Check OnosTopology
1466 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
1467 main.assertReturnString += 'Link Up Topology State Passed\n'
1468 else:
1469 main.assertReturnString += 'Link Up Topology State Failed\n'
1470 testResult = main.FALSE
1471
1472 # Check Connection
1473 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1474 args=( main, senderNames, recipientNames ) ):
1475 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1476 else:
1477 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1478 testResult = main.FALSE
1479
1480 # Remove all intents
1481 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ):
1482 main.assertReturnString += 'Remove Intents Passed'
1483 else:
1484 main.assertReturnString += 'Remove Intents Failed'
1485 testResult = main.FALSE
1486
1487 return testResult
1488
1489
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001490def pingallHosts( main, hostList ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001491 """
1492 Ping all host in the hosts list variable
1493 """
Jon Halla5cb3412015-08-18 14:08:22 -07001494 main.log.info( "Pinging: " + str( hostList ) )
1495 return main.Mininet1.pingallHosts( hostList )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001496
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001497def fwdPingall( main ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001498 """
1499 Use fwd app and pingall to discover all the hosts
1500 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001501 activateResult = main.TRUE
1502 appCheck = main.TRUE
1503 getDataResult = main.TRUE
1504 main.log.info( "Activating reactive forwarding app " )
1505 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001506
1507 # Wait for forward app activation to propagate
kelvin-onlab0ad05d12015-07-23 14:21:15 -07001508 time.sleep( main.fwdSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001509
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001510 # Check that forwarding is enabled on all nodes
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001511 for i in range( main.numCtrls ):
1512 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
1513 if appCheck != main.TRUE:
1514 main.log.warn( main.CLIs[ i ].apps() )
1515 main.log.warn( main.CLIs[ i ].appIDs() )
1516
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001517 # Send pingall in mininet
1518 main.log.info( "Run Pingall" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001519 pingResult = main.Mininet1.pingall( timeout = 600 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001520
1521 main.log.info( "Deactivating reactive forwarding app " )
1522 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001523 if activateResult and deactivateResult:
1524 main.log.info( "Successfully used fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001525 getDataResult = main.TRUE
1526 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001527 main.log.info( "Failed to use fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001528 getDataResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001529 return getDataResult
1530
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001531def confirmHostDiscovery( main ):
1532 """
1533 Confirms that all ONOS nodes have discovered all scapy hosts
1534 """
1535 import collections
1536 scapyHostCount = len( main.scapyHosts )
1537 hosts = main.topo.getAllHosts( main ) # Get host data from each ONOS node
1538 hostFails = [] # Reset for each failed attempt
1539
1540 # Check for matching hosts on each node
1541 scapyHostIPs = [ x.hostIp for x in main.scapyHosts if x.hostIp != "0.0.0.0" ]
1542 for controller in range( main.numCtrls ):
1543 controllerStr = str( controller + 1 ) # ONOS node number
1544 # Compare Hosts
1545 # Load hosts data for controller node
Jeremyd9e4eb12016-04-13 12:09:06 -07001546 try:
1547 if hosts[ controller ]:
1548 main.log.info( "Hosts discovered" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001549 else:
Jeremyd9e4eb12016-04-13 12:09:06 -07001550 main.log.error( "Problem discovering hosts" )
1551 if hosts[ controller ] and "Error" not in hosts[ controller ]:
1552 try:
1553 hostData = json.loads( hosts[ controller ] )
1554 except ( TypeError, ValueError ):
1555 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001556 hostFails.append( controllerStr )
Jeremyd9e4eb12016-04-13 12:09:06 -07001557 else:
1558 onosHostIPs = [ x.get( "ipAddresses" )[ 0 ]
1559 for x in hostData
1560 if len( x.get( "ipAddresses" ) ) > 0 ]
1561 if not set( collections.Counter( scapyHostIPs ) ).issubset( set ( collections.Counter( onosHostIPs ) ) ):
1562 main.log.warn( "Controller {0} only sees nodes with {1} IPs. It should see all of the following: {2}".format( controllerStr, onosHostIPs, scapyHostIPs ) )
1563 hostFails.append( controllerStr )
1564 else:
1565 main.log.error( "Hosts returned nothing or an error." )
1566 hostFails.append( controllerStr )
1567 except IndexError:
1568 main.log.error( "Hosts returned nothing, Failed to discover hosts." )
1569 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001570
1571 if hostFails:
1572 main.log.error( "List of failed ONOS Nodes:" + ', '.join(map(str, hostFails )) )
1573 return main.FALSE
1574 else:
1575 return main.TRUE
1576
1577def sendDiscoveryArp( main, hosts=None ):
1578 """
1579 Sends Discovery ARP packets from each host provided
1580 Defaults to each host in main.scapyHosts
1581 """
1582 # Send an arp ping from each host
1583 if not hosts:
1584 hosts = main.scapyHosts
1585 for host in hosts:
1586 pkt = 'Ether( src="{0}")/ARP( psrc="{1}")'.format( host.hostMac ,host.hostIp )
1587 # Send from the VLAN interface if there is one so ONOS discovers the VLAN correctly
1588 iface = None
1589 for interface in host.getIfList():
1590 if '.' in interface:
1591 main.log.debug( "Detected VLAN interface {0}. Sending ARP packet from {0}".format( interface ) )
1592 iface = interface
1593 break
1594 host.sendPacket( packet=pkt, iface=iface )
1595 main.log.info( "Sending ARP packet from {0}".format( host.name ) )
1596
1597def populateHostData( main ):
1598 """
1599 Populates hostsData
1600 """
1601 import json
1602 try:
1603 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
1604 hosts = main.Mininet1.getHosts().keys()
1605 # TODO: Make better use of new getHosts function
1606 for host in hosts:
1607 main.hostsData[ host ] = {}
1608 main.hostsData[ host ][ 'mac' ] = \
1609 main.Mininet1.getMacAddress( host ).upper()
1610 for hostj in hostsJson:
1611 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
1612 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
1613 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
1614 main.hostsData[ host ][ 'location' ] = \
1615 hostj[ 'location' ][ 'elementId' ] + '/' + \
1616 hostj[ 'location' ][ 'port' ]
1617 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
1618 return main.TRUE
Jeremyd9e4eb12016-04-13 12:09:06 -07001619 except ValueError:
1620 main.log.error( "ValueError while populating hostsData" )
1621 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001622 except KeyError:
1623 main.log.error( "KeyError while populating hostsData")
1624 return main.FALSE
Jeremyd9e4eb12016-04-13 12:09:06 -07001625 except IndexError:
1626 main.log.error( "IndexError while populating hostsData" )
1627 return main.FALSE
1628 except TypeError:
1629 main.log.error( "TypeError while populating hostsData" )
1630 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001631
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001632def checkTopology( main, expectedLink ):
1633 statusResult = main.TRUE
1634 # Check onos topology
1635 main.log.info( itemName + ": Checking ONOS topology " )
1636
1637 for i in range( main.numCtrls ):
Flavio Castro82ee2f62016-06-07 15:04:12 -07001638 statusResult = main.CLIs[ i ].checkStatus( main.numSwitch,
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001639 expectedLink )\
1640 and statusResult
1641 if not statusResult:
1642 main.log.error( itemName + ": Topology mismatch" )
1643 else:
1644 main.log.info( itemName + ": Topology match" )
1645 return statusResult
1646
1647def checkIntentState( main, intentsId ):
1648 """
1649 This function will check intent state to make sure all the intents
1650 are in INSTALLED state
1651 """
1652
1653 intentResult = main.TRUE
1654 results = []
1655
1656 main.log.info( itemName + ": Checking intents state" )
1657 # First check of intents
1658 for i in range( main.numCtrls ):
1659 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
1660 results.append( tempResult )
1661
1662 expectedState = [ 'INSTALLED', 'INSTALLING' ]
1663
1664 if all( result == main.TRUE for result in results ):
1665 main.log.info( itemName + ": Intents are installed correctly" )
1666 else:
1667 # Wait for at least 5 second before checking the intents again
acsmarsb9a92692015-10-08 16:43:01 -07001668 main.log.error( "Intents are not installed correctly. Waiting 5 sec" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001669 time.sleep( 5 )
1670 results = []
1671 # Second check of intents since some of the intents may be in
1672 # INSTALLING state, they should be in INSTALLED at this time
1673 for i in range( main.numCtrls ):
Jeremy2f190ca2016-01-29 15:23:57 -08001674 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001675 results.append( tempResult )
1676 if all( result == main.TRUE for result in results ):
1677 main.log.info( itemName + ": Intents are installed correctly" )
acsmarsb9a92692015-10-08 16:43:01 -07001678 intentResult = main.TRUE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001679 else:
1680 main.log.error( itemName + ": Intents are NOT installed correctly" )
1681 intentResult = main.FALSE
1682
1683 return intentResult
1684
1685def checkFlowsState( main ):
1686
1687 main.log.info( itemName + ": Check flows state" )
Jeremy Songsterff553672016-05-12 17:06:23 -07001688 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState( isPENDING=False )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001689 return checkFlowsResult
1690
1691def link( main, sw1, sw2, option):
1692
1693 # link down
1694 main.log.info( itemName + ": Bring link " + option + "between " +
1695 sw1 + " and " + sw2 )
1696 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
1697 return linkResult
1698
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001699def scapyCheckConnection( main, senders, recipients, vlanId=None, useTCP=False, packet=None, packetFilter=None, expectFailure=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001700 """
1701 Checks the connectivity between all given sender hosts and all given recipient hosts
1702 Packet may be specified. Defaults to Ether/IP packet
1703 Packet Filter may be specified. Defaults to Ether/IP from current sender MAC
1704 Todo: Optional packet and packet filter attributes for sender and recipients
1705 Expect Failure when the sender and recipient are not supposed to have connectivity
1706 Timeout of 1 second, returns main.TRUE if the filter is not triggered and kills the filter
1707
1708 """
1709 connectionsFunctional = main.TRUE
1710
1711 if not packetFilter:
1712 packetFilter = 'ether host {}'
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001713 if useTCP:
1714 packetFilter += ' ip proto \\tcp tcp port {}'.format(main.params[ 'SDNIP' ][ 'dstPort' ])
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001715 if expectFailure:
1716 timeout = 1
1717 else:
1718 timeout = 10
1719
1720 for sender in senders:
1721 try:
1722 senderComp = getattr( main, sender )
1723 except AttributeError:
1724 main.log.error( "main has no attribute {}".format( sender ) )
1725 connectionsFunctional = main.FALSE
1726 continue
1727
1728 for recipient in recipients:
1729 # Do not send packets to self since recipient CLI will already be busy
1730 if recipient == sender:
1731 continue
1732 try:
1733 recipientComp = getattr( main, recipient )
1734 except AttributeError:
1735 main.log.error( "main has no attribute {}".format( recipient ) )
1736 connectionsFunctional = main.FALSE
1737 continue
1738
Jeremy Songster832f9e92016-05-05 14:30:49 -07001739 if vlanId:
1740 recipientComp.startFilter( pktFilter = ( "vlan {}".format( vlanId ) + " && " + packetFilter.format( senderComp.hostMac ) ) )
1741 else:
1742 recipientComp.startFilter( pktFilter = packetFilter.format( senderComp.hostMac ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001743
1744 if not packet:
Jeremy Songster832f9e92016-05-05 14:30:49 -07001745 if vlanId:
1746 pkt = 'Ether( src="{0}", dst="{2}" )/Dot1Q(vlan={4})/IP( src="{1}", dst="{3}" )'.format(
1747 senderComp.hostMac,
1748 senderComp.hostIp,
1749 recipientComp.hostMac,
1750 recipientComp.hostIp,
1751 vlanId )
1752 else:
1753 pkt = 'Ether( src="{0}", dst="{2}" )/IP( src="{1}", dst="{3}" )'.format(
1754 senderComp.hostMac,
1755 senderComp.hostIp,
1756 recipientComp.hostMac,
1757 recipientComp.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001758 else:
1759 pkt = packet
Jeremy Songster832f9e92016-05-05 14:30:49 -07001760 if vlanId:
1761 senderComp.sendPacket( iface=( "{0}-eth0.{1}".format( sender, vlanId ) ), packet = pkt )
1762 else:
1763 senderComp.sendPacket( packet = pkt )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001764
1765 if recipientComp.checkFilter( timeout ):
1766 if expectFailure:
1767 main.log.error( "Packet from {0} successfully received by {1} when it should not have been".format( sender , recipient ) )
1768 connectionsFunctional = main.FALSE
1769 else:
1770 main.log.info( "Packet from {0} successfully received by {1}".format( sender , recipient ) )
1771 else:
1772 recipientComp.killFilter()
1773 if expectFailure:
1774 main.log.info( "As expected, packet from {0} was not received by {1}".format( sender , recipient ) )
1775 else:
1776 main.log.error( "Packet from {0} was not received by {1}".format( sender , recipient ) )
1777 connectionsFunctional = main.FALSE
1778
1779 return connectionsFunctional
1780
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001781def removeAllIntents( main, intentsId ):
1782 """
1783 Remove all intents in the intentsId
1784 """
1785
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001786 onosSummary = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001787 removeIntentResult = main.TRUE
1788 # Remove intents
1789 for intent in intentsId:
1790 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
1791
acsmarscfa52272015-08-06 15:21:45 -07001792 time.sleep( main.removeIntentSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001793
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001794 # If there is remianing intents then remove intents should fail
1795 for i in range( main.numCtrls ):
1796 onosSummary.append( json.loads( main.CLIs[ i ].summary() ) )
1797
1798 for summary in onosSummary:
1799 if summary.get( 'intents' ) != 0:
1800 main.log.warn( itemName + ": There are " +
1801 str( summary.get( 'intents' ) ) +
1802 " intents remaining in node " +
1803 str( summary.get( 'node' ) ) +
1804 ", failed to remove all the intents " )
1805 removeIntentResult = main.FALSE
1806
1807 if removeIntentResult:
1808 main.log.info( itemName + ": There are no more intents remaining, " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001809 "successfully removed all the intents." )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001810
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001811 return removeIntentResult
1812
1813def checkFlowsCount( main ):
1814 """
1815 Check flows count in each node
1816 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001817 flowsCount = []
1818 main.log.info( itemName + ": Checking flows count in each ONOS node" )
1819 for i in range( main.numCtrls ):
1820 summaryResult = main.CLIs[ i ].summary()
1821 if not summaryResult:
1822 main.log.error( itemName + ": There is something wrong with " +
1823 "summary command" )
1824 return main.FALSE
1825 else:
1826 summaryJson = json.loads( summaryResult )
1827 flowsCount.append( summaryJson.get( 'flows' ) )
1828
1829 if flowsCount:
1830 if all( flows==flowsCount[ 0 ] for flows in flowsCount ):
1831 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
1832 " flows in all ONOS node" )
1833 else:
1834 for i in range( main.numCtrls ):
1835 main.log.debug( itemName + ": ONOS node " + str( i ) + " has " +
kelvin-onlab6dea6e62015-07-23 13:07:26 -07001836 str( flowsCount[ i ] ) + " flows" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001837 else:
1838 main.log.error( "Checking flows count failed, check summary command" )
1839 return main.FALSE
1840
1841 return main.TRUE
1842
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001843def checkLeaderChange( leaders1, leaders2 ):
acsmarse6b410f2015-07-17 14:39:34 -07001844 """
1845 Checks for a change in intent partition leadership.
1846
1847 Takes the output of leaders -c in json string format before and after
1848 a potential change as input
1849
1850 Returns main.TRUE if no mismatches are detected
1851 Returns main.FALSE if there is a mismatch or on error loading the input
1852 """
1853 try:
1854 leaders1 = json.loads( leaders1 )
1855 leaders2 = json.loads( leaders2 )
1856 except ( AttributeError, TypeError):
1857 main.log.exception( self.name + ": Object not as expected" )
1858 return main.FALSE
1859 except Exception:
1860 main.log.exception( self.name + ": Uncaught exception!" )
1861 main.cleanup()
1862 main.exit()
1863 main.log.info( "Checking Intent Paritions for Change in Leadership" )
1864 mismatch = False
1865 for dict1 in leaders1:
1866 if "intent" in dict1.get( "topic", [] ):
1867 for dict2 in leaders2:
1868 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \
1869 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
1870 mismatch = True
1871 main.log.error( "{0} changed leader from {1} to {2}".\
1872 format( dict1.get( "topic", "no-topic" ),\
1873 dict1.get( "leader", "no-leader" ),\
1874 dict2.get( "leader", "no-leader" ) ) )
1875 if mismatch:
1876 return main.FALSE
1877 else:
1878 return main.TRUE
kelvin-onlab016dce22015-08-10 09:54:11 -07001879
1880def report( main ):
1881 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001882 Report errors/warnings/exceptions
kelvin-onlab016dce22015-08-10 09:54:11 -07001883 """
kelvin-onlab016dce22015-08-10 09:54:11 -07001884 main.ONOSbench.logReport( main.ONOSip[ 0 ],
1885 [ "INFO",
1886 "FOLLOWER",
1887 "WARN",
1888 "flow",
1889 "ERROR",
1890 "Except" ],
1891 "s" )
1892
1893 main.log.info( "ERROR report: \n" )
1894 for i in range( main.numCtrls ):
1895 main.ONOSbench.logReport( main.ONOSip[ i ],
1896 [ "ERROR" ],
1897 "d" )
1898
1899 main.log.info( "EXCEPTIONS report: \n" )
1900 for i in range( main.numCtrls ):
1901 main.ONOSbench.logReport( main.ONOSip[ i ],
1902 [ "Except" ],
1903 "d" )
1904
1905 main.log.info( "WARNING report: \n" )
1906 for i in range( main.numCtrls ):
1907 main.ONOSbench.logReport( main.ONOSip[ i ],
1908 [ "WARN" ],
1909 "d" )
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001910
1911def flowDuration( main ):
1912 """
1913 Check age of flows to see if flows are being overwritten
1914 """
1915 import time
1916 main.log.info( "Getting current flow durations" )
1917 flowsJson1 = main.CLIs[ 0 ].flows( noCore=True )
1918 try:
1919 flowsJson1 = json.loads( flowsJson1 )
1920 except ValueError:
1921 main.log.error( "Unable to read flows" )
1922 return main.FALSE
1923 flowLife = []
1924 waitFlowLife = []
1925 for device in flowsJson1:
1926 if device.get( 'flowcount', 0 ) > 0:
1927 for i in range( device[ 'flowCount' ] ):
1928 flowLife.append( device[ 'flows' ][ i ][ 'life' ] )
1929 main.log.info( "Sleeping for {} seconds".format( main.flowDurationSleep ) )
1930 time.sleep( main.flowDurationSleep )
1931 main.log.info( "Getting new flow durations" )
1932 flowsJson2 = main.CLIs[ 0 ].flows( noCore=True )
1933 try:
1934 flowsJson2 = json.loads( flowsJson2 )
1935 except ValueError:
1936 main.log.error( "Unable to read flows" )
1937 return main.FALSE
1938 for device in flowsJson2:
1939 if device.get( 'flowcount', 0 ) > 0:
1940 for i in range( device[ 'flowCount' ] ):
1941 waitFlowLife.append( device[ 'flows' ][ i ][ 'life' ] )
1942 main.log.info( "Determining whether flows where overwritten" )
1943 if len( flowLife ) == len( waitFlowLife ):
1944 for i in range( len( flowLife) ):
1945 if waitFlowLife[ i ] - flowLife[ i ] < main.flowDurationSleep:
1946 return main.FALSE
1947 else:
1948 return main.FALSE
1949 return main.TRUE