blob: d4670b8a14401ebe76bd814caa47ef74cbdd39bb [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
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -070013hostIntentFailFlag = False
14pointIntentFailFlag = False
15singleToMultiFailFlag = False
16multiToSingleFailFlag = False
17
Jeremy Songster1f39bf02016-01-20 17:17:25 -080018def installHostIntent( main,
Jeremy2f190ca2016-01-29 15:23:57 -080019 name,
20 host1,
21 host2,
22 onosNode=0,
23 ethType="",
24 bandwidth="",
25 lambdaAlloc=False,
26 ipProto="",
27 ipAddresses="",
28 tcp="",
29 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -070030 sw2="",
Jeremy Songsterc032f162016-08-04 17:14:49 -070031 setVlan="",
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -070032 encap="",
33 bandwidthFlag=False ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -070034 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -080035 Installs a Host Intent
36
kelvin-onlab58dc39e2015-08-06 08:11:09 -070037 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -080038 Install a host intent using
39 add-host-intent
40
kelvin-onlab58dc39e2015-08-06 08:11:09 -070041 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -080042 - Fetch host data if not given
43 - Add host intent
44 - Ingress device is the first sender host
45 - Egress devices are the recipient devices
46 - Ports if defined in senders or recipients
47 - MAC address ethSrc loaded from Ingress device
48 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -070049 Required:
50 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -080051 host1 - Dictionary for host1
52 { "name":"h8", "id":"of:0000000000000005/8" }
53 host2 - Dictionary for host2
54 { "name":"h16", "id":"of:0000000000000006/8" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -070055 Optional:
56 onosNode - ONOS node to install the intents in main.CLIs[ ]
57 0 by default so that it will always use the first
58 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -070059 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -070060 bandwidth - Bandwidth capacity
61 lambdaAlloc - Allocate lambda, defaults to False
62 ipProto - IP protocol
Jeremy Songster1f39bf02016-01-20 17:17:25 -080063 tcp - TCP ports in the same order as the hosts in hostNames
64 """
65
66 assert main, "There is no main variable"
67 assert host1, "You must specify host1"
68 assert host2, "You must specify host2"
69
70 global itemName # The name of this run. Used for logs.
71 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -080072
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -070073 global hostIntentFailFlag
74 hostIntentFailFlag = False
75
Jeremy Songster1f39bf02016-01-20 17:17:25 -080076 main.log.info( itemName + ": Adding single point to multi point intents" )
Jeremyd9e4eb12016-04-13 12:09:06 -070077 try:
78 if not host1.get( "id" ):
79 main.log.warn( "ID not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
80 main.log.debug( main.hostsData.get( host1.get( "name" ) ) )
81 host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "id" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -080082
Jeremyd9e4eb12016-04-13 12:09:06 -070083 if not host2.get( "id" ):
84 main.log.warn( "ID not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
85 host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "id" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -080086
Jeremyd9e4eb12016-04-13 12:09:06 -070087 # Adding point intent
Jeremy Songster832f9e92016-05-05 14:30:49 -070088 vlanId = host1.get( "vlan" )
Jeremyd9e4eb12016-04-13 12:09:06 -070089 intentId = main.CLIs[ onosNode ].addHostIntent( hostIdOne=host1.get( "id" ),
Jeremy Songster832f9e92016-05-05 14:30:49 -070090 hostIdTwo=host2.get( "id" ),
Jeremy Songsterff553672016-05-12 17:06:23 -070091 vlanId=vlanId,
Jeremy Songsterc032f162016-08-04 17:14:49 -070092 setVlan=setVlan,
93 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -070094 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -070095 errorMsg = "There was a problem loading the hosts data."
96 if intentId:
97 errorMsg += " There was a problem installing host to host intent."
98 main.log.error( errorMsg )
99 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800100
101 # Check intents state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700102 if utilities.retry( f=checkIntentState,
103 retValue=main.FALSE,
104 args=( main, [ intentId ], bandwidthFlag ),
105 sleep=main.checkIntentSleep,
106 attempts=50 ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700107 main.assertReturnString += 'Install Intent State Passed\n'
alison52b25892016-09-19 10:53:48 -0700108
109 #Check VLAN if test encapsulation
110 if encap != "":
111 if EncapsulatedIntentCheck( main, tag=encap ):
112 main.assertReturnString += 'Encapsulation intents check Passed\n'
113 else:
114 main.assertReturnString += 'Encapsulation intents check failed\n'
115
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700116 if flowDuration( main ):
117 main.assertReturnString += 'Flow duration check Passed\n'
118 return intentId
119 else:
120 main.assertReturnString += 'Flow duration check failed\n'
121 return main.FALSE
alison52b25892016-09-19 10:53:48 -0700122
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800123 else:
Jeremy2f190ca2016-01-29 15:23:57 -0800124 main.log.error( "Host Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700125 hostIntentFailFlag = True
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700126 main.assertReturnString += 'Install Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800127 return main.FALSE
128
129def testHostIntent( main,
130 name,
131 intentId,
132 host1,
133 host2,
134 onosNode=0,
135 sw1="s5",
136 sw2="s2",
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700137 expectedLink=0 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800138 """
139 Test a Host Intent
140
141 Description:
142 Test a host intent of given ID between given hosts
143
144 Steps:
145 - Fetch host data if not given
146 - Check Intent State
147 - Check Flow State
148 - Check Connectivity
149 - Check Lack of Connectivity Between Hosts not in the Intent
150 - Reroute
151 - Take Expected Link Down
152 - Check Intent State
153 - Check Flow State
154 - Check Topology
155 - Check Connectivity
156 - Bring Expected Link Up
157 - Check Intent State
158 - Check Flow State
159 - Check Topology
160 - Check Connectivity
161 - Remove Topology
162
163 Required:
164 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
165 intentId - intent ID to be tested ( and removed )
166 host1 - Dictionary for host1
167 { "name":"h8", "id":"of:0000000000000005/8" }
168 host2 - Dictionary for host2
169 { "name":"h16", "id":"of:0000000000000006/8" }
170 Optional:
171 onosNode - ONOS node to install the intents in main.CLIs[ ]
172 0 by default so that it will always use the first
173 ONOS node
174 sw1 - First switch to bring down & up for rerouting purpose
175 sw2 - Second switch to bring down & up for rerouting purpose
176 expectedLink - Expected link when the switches are down, it should
177 be two links lower than the links before the two
178 switches are down
179
180 """
181
182 # Parameter Validity Check
183 assert main, "There is no main variable"
184 assert host1, "You must specify host1"
185 assert host2, "You must specify host2"
186
187 global itemName
188 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800189
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700190 global hostIntentFailFlag
191
Jeremy2f190ca2016-01-29 15:23:57 -0800192 main.log.info( itemName + ": Testing Host Intent" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800193
Jeremyd9e4eb12016-04-13 12:09:06 -0700194 try:
195 if not host1.get( "id" ):
196 main.log.warn( "Id not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
197 host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800198
Jeremyd9e4eb12016-04-13 12:09:06 -0700199 if not host2.get( "id" ):
200 main.log.warn( "Id not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
201 host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800202
Jeremyd9e4eb12016-04-13 12:09:06 -0700203 senderNames = [ host1.get( "name" ), host2.get( "name" ) ]
204 recipientNames = [ host1.get( "name" ), host2.get( "name" ) ]
Jeremy Songster832f9e92016-05-05 14:30:49 -0700205 vlanId = host1.get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800206
Jeremyd9e4eb12016-04-13 12:09:06 -0700207 testResult = main.TRUE
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700208 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700209 main.log.error( "There was a problem loading the hosts data." )
210 return main.FALSE
211
212 main.log.info( itemName + ": Testing Host to Host intents" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800213
214 # Check intent state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700215 if hostIntentFailFlag:
216 attempts = 1
217 else:
218 attempts = 50
Jon Hallaf95c3e2017-05-16 13:20:37 -0700219 if utilities.retry( f=checkIntentState,
220 retValue=main.FALSE,
221 args=( main, [ intentId ] ),
222 sleep=main.checkIntentSleep,
223 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800224 main.assertReturnString += 'Initial Intent State Passed\n'
225 else:
226 main.assertReturnString += 'Initial Intent State Failed\n'
227 testResult = main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700228 attempts = 1
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800229
230 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -0700231 if utilities.retry( f=checkFlowsCount,
232 retValue=main.FALSE,
233 args=[ main ],
234 sleep=20,
235 attempts=3 ) and utilities.retry( f=checkFlowsState,
236 retValue=main.FALSE,
237 args=[ main ],
238 sleep=20,
239 attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800240 main.assertReturnString += 'Initial Flow State Passed\n'
241 else:
242 main.assertReturnString += 'Intial Flow State Failed\n'
243 testResult = main.FALSE
244
245 # Check Connectivity
Jon Hallaf95c3e2017-05-16 13:20:37 -0700246 if utilities.retry( f=scapyCheckConnection,
247 retValue=main.FALSE,
248 attempts=attempts,
249 sleep=main.checkConnectionSleep,
Shreyaca8990f2017-03-16 11:43:11 -0700250 args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800251 main.assertReturnString += 'Initial Ping Passed\n'
252 else:
253 main.assertReturnString += 'Initial Ping Failed\n'
254 testResult = main.FALSE
255
256 # Test rerouting if these variables exist
257 if sw1 and sw2 and expectedLink:
258 # Take link down
Jon Hallaf95c3e2017-05-16 13:20:37 -0700259 if utilities.retry( f=link,
260 retValue=main.FALSE,
261 args=( main, sw1, sw2, "down" ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800262 main.assertReturnString += 'Link Down Passed\n'
263 else:
264 main.assertReturnString += 'Link Down Failed\n'
265 testResult = main.FALSE
266
267 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700268 if utilities.retry( f=checkIntentState,
269 retValue=main.FALSE,
270 args=( main, [ intentId ] ),
271 sleep=main.checkIntentHostSleep,
272 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800273 main.assertReturnString += 'Link Down Intent State Passed\n'
274 else:
275 main.assertReturnString += 'Link Down Intent State Failed\n'
276 testResult = main.FALSE
277
278 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -0700279 if utilities.retry( f=checkFlowsCount,
280 retValue=main.FALSE,
281 args=[ main ],
282 sleep=main.checkFlowCountSleep,
283 attempts=attempts ) and utilities.retry( f=checkFlowsState,
284 retValue=main.FALSE,
285 args=[ main ],
286 sleep=main.checkFlowCountSleep,
287 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800288 main.assertReturnString += 'Link Down Flow State Passed\n'
289 else:
290 main.assertReturnString += 'Link Down Flow State Failed\n'
291 testResult = main.FALSE
292
293 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -0700294 if utilities.retry( f=checkTopology,
295 retValue=main.FALSE,
296 args=( main, expectedLink ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800297 main.assertReturnString += 'Link Down Topology State Passed\n'
298 else:
299 main.assertReturnString += 'Link Down Topology State Failed\n'
300 testResult = main.FALSE
301
302 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -0700303 if utilities.retry( f=scapyCheckConnection,
304 retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -0700305 args=( main, senderNames, recipientNames, vlanId ),
Jon Hallaf95c3e2017-05-16 13:20:37 -0700306 sleep=main.checkConnectionSleep,
307 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800308 main.assertReturnString += 'Link Down Pingall Passed\n'
309 else:
310 main.assertReturnString += 'Link Down Pingall Failed\n'
311 testResult = main.FALSE
312
313 # Bring link up
Jon Hallaf95c3e2017-05-16 13:20:37 -0700314 if utilities.retry( f=link,
315 retValue=main.FALSE,
316 args=( main, sw1, sw2, "up" ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800317 main.assertReturnString += 'Link Up Passed\n'
318 else:
319 main.assertReturnString += 'Link Up Failed\n'
320 testResult = main.FALSE
321
322 # Wait for reroute
323 time.sleep( main.rerouteSleep )
324
325 # Check Intents
Jon Hallaf95c3e2017-05-16 13:20:37 -0700326 if utilities.retry( f=checkIntentState,
327 retValue=main.FALSE,
328 attempts=attempts * 2,
329 args=( main, [ intentId ] ),
330 sleep=main.checkIntentSleep ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800331 main.assertReturnString += 'Link Up Intent State Passed\n'
332 else:
333 main.assertReturnString += 'Link Up Intent State Failed\n'
334 testResult = main.FALSE
335
336 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -0700337 if utilities.retry( f=checkFlowsCount,
338 retValue=main.FALSE,
339 args=[ main ],
340 sleep=20,
341 attempts=3 ) and utilities.retry( f=checkFlowsState,
342 retValue=main.FALSE,
343 args=[ main ],
344 sleep=20,
345 attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800346 main.assertReturnString += 'Link Up Flow State Passed\n'
347 else:
348 main.assertReturnString += 'Link Up Flow State Failed\n'
349 testResult = main.FALSE
350
351 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -0700352 if utilities.retry( f=checkTopology,
353 retValue=main.FALSE,
354 args=( main, main.numLinks ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800355 main.assertReturnString += 'Link Up Topology State Passed\n'
356 else:
357 main.assertReturnString += 'Link Up Topology State Failed\n'
358 testResult = main.FALSE
359
360 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -0700361 if utilities.retry( f=scapyCheckConnection,
362 retValue=main.FALSE,
363 args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800364 main.assertReturnString += 'Link Up Pingall Passed\n'
365 else:
366 main.assertReturnString += 'Link Up Pingall Failed\n'
367 testResult = main.FALSE
368
369 # Remove all intents
Jon Hallaf95c3e2017-05-16 13:20:37 -0700370 if utilities.retry( f=removeAllIntents,
371 retValue=main.FALSE,
372 attempts=10,
373 args=( main, [ intentId ] ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800374 main.assertReturnString += 'Remove Intents Passed'
375 else:
376 main.assertReturnString += 'Remove Intents Failed'
377 testResult = main.FALSE
378
379 return testResult
380
381def installPointIntent( main,
382 name,
383 senders,
384 recipients,
385 onosNode=0,
386 ethType="",
387 bandwidth="",
388 lambdaAlloc=False,
alisonda157272016-12-22 01:13:21 -0800389 protected=False,
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800390 ipProto="",
391 ipSrc="",
392 ipDst="",
393 tcpSrc="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700394 tcpDst="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700395 setVlan="",
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700396 encap="",
397 bandwidthFlag=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800398 """
399 Installs a Single to Single Point Intent
400
401 Description:
402 Install a single to single point intent
403
404 Steps:
405 - Fetch host data if not given
406 - Add point intent
407 - Ingress device is the first sender device
408 - Egress device is the first recipient device
409 - Ports if defined in senders or recipients
410 - MAC address ethSrc loaded from Ingress device
411 - Check intent state with retry
412 Required:
413 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
414 senders - List of host dictionaries i.e.
415 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
416 recipients - List of host dictionaries i.e.
417 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
418 Optional:
419 onosNode - ONOS node to install the intents in main.CLIs[ ]
420 0 by default so that it will always use the first
421 ONOS node
422 ethType - Ethernet type eg. IPV4, IPV6
423 bandwidth - Bandwidth capacity
424 lambdaAlloc - Allocate lambda, defaults to False
425 ipProto - IP protocol
426 tcp - TCP ports in the same order as the hosts in hostNames
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700427 sw1 - First switch to bring down & up for rerouting purpose
428 sw2 - Second switch to bring down & up for rerouting purpose
429 expectedLink - Expected link when the switches are down, it should
430 be two links lower than the links before the two
431 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700432 """
433
434 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800435 assert senders, "You must specify a sender"
436 assert recipients, "You must specify a recipient"
437 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700438
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800439 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700440 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700441
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700442 global pointIntentFailFlag
443 pointIntentFailFlag = False
444
Jeremy6f000c62016-02-25 17:02:28 -0800445 main.log.info( itemName + ": Adding point to point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700446
Jeremyd9e4eb12016-04-13 12:09:06 -0700447 try:
448 for sender in senders:
449 if not sender.get( "device" ):
450 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
451 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800452
Jeremyd9e4eb12016-04-13 12:09:06 -0700453 for recipient in recipients:
454 if not recipient.get( "device" ):
455 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
456 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800457
458
Jeremyd9e4eb12016-04-13 12:09:06 -0700459 ingressDevice = senders[ 0 ].get( "device" )
460 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800461
Jeremyd9e4eb12016-04-13 12:09:06 -0700462 portIngress = senders[ 0 ].get( "port", "" )
463 portEgress = recipients[ 0 ].get( "port", "" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800464
Jeremyd9e4eb12016-04-13 12:09:06 -0700465 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800466
Jeremyd9e4eb12016-04-13 12:09:06 -0700467 ipSrc = senders[ 0 ].get( "ip" )
468 ipDst = recipients[ 0 ].get( "ip" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800469
Jeremy Songster832f9e92016-05-05 14:30:49 -0700470 vlanId = senders[ 0 ].get( "vlan" )
471
Jeremyd9e4eb12016-04-13 12:09:06 -0700472 # Adding point intent
473 intentId = main.CLIs[ onosNode ].addPointIntent(
474 ingressDevice=ingressDevice,
475 egressDevice=egressDevice,
476 portIngress=portIngress,
477 portEgress=portEgress,
478 ethType=ethType,
479 ethDst=dstMac,
480 bandwidth=bandwidth,
481 lambdaAlloc=lambdaAlloc,
alisonda157272016-12-22 01:13:21 -0800482 protected=protected,
Jeremyd9e4eb12016-04-13 12:09:06 -0700483 ipProto=ipProto,
484 ipSrc=ipSrc,
485 ipDst=ipDst,
486 tcpSrc=tcpSrc,
Jeremy Songster832f9e92016-05-05 14:30:49 -0700487 tcpDst=tcpDst,
Jeremy Songsterff553672016-05-12 17:06:23 -0700488 vlanId=vlanId,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700489 setVlan=setVlan,
490 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700491 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700492 errorMsg = "There was a problem loading the hosts data."
493 if intentId:
494 errorMsg += " There was a problem installing Point to Point intent."
495 main.log.error( errorMsg )
496 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700497
498 # Check intents state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700499 if utilities.retry( f=checkIntentState,
500 retValue=main.FALSE,
501 args=( main, [ intentId ], bandwidthFlag ),
502 sleep=main.checkIntentSleep * 2,
503 attempts=50 ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700504 main.assertReturnString += 'Install Intent State Passed\n'
alison52b25892016-09-19 10:53:48 -0700505
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700506 if bandwidth != "":
507 main.assertReturnString += 'Bandwidth Allocation Passed\n'
508
alison52b25892016-09-19 10:53:48 -0700509 # Check VLAN if test encapsulation
510 if encap != "":
511 if EncapsulatedIntentCheck( main, tag=encap ):
512 main.assertReturnString += 'Encapsulation intents check Passed\n'
513 else:
514 main.assertReturnString += 'Encapsulation intents check failed\n'
alisonda157272016-12-22 01:13:21 -0800515
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700516 if flowDuration( main ):
517 main.assertReturnString += 'Flow duration check Passed\n'
518 return intentId
519 else:
520 main.assertReturnString += 'Flow duration check failed\n'
521 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -0700522 else:
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700523 if bandwidth != "":
524 main.assertReturnString += 'Bandwidth Allocation Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800525 main.log.error( "Point Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700526 pointIntentFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800527 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700528
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700529def pointIntentTcp( main,
530 name,
531 host1,
532 host2,
533 onosNode=0,
534 deviceId1="",
535 deviceId2="",
536 port1="",
537 port2="",
538 ethType="",
539 mac1="",
540 mac2="",
541 bandwidth="",
542 lambdaAlloc=False,
543 ipProto="",
544 ip1="",
545 ip2="",
546 tcp1="",
547 tcp2="",
548 sw1="",
549 sw2="",
550 expectedLink=0 ):
551
552 """
553 Description:
554 Verify add-point-intent only for TCP
555 Steps:
556 - Get device ids | ports
557 - Add point intents
558 - Check intents
559 - Verify flows
560 - Ping hosts
561 - Reroute
562 - Link down
563 - Verify flows
564 - Check topology
565 - Ping hosts
566 - Link up
567 - Verify flows
568 - Check topology
569 - Ping hosts
570 - Remove intents
571 Required:
572 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
573 host1 - Name of first host
574 host2 - Name of second host
575 Optional:
576 onosNode - ONOS node to install the intents in main.CLIs[ ]
577 0 by default so that it will always use the first
578 ONOS node
579 deviceId1 - ONOS device id of the first switch, the same as the
580 location of the first host eg. of:0000000000000001/1,
581 located at device 1 port 1
582 deviceId2 - ONOS device id of the second switch
583 port1 - The port number where the first host is attached
584 port2 - The port number where the second host is attached
585 ethType - Ethernet type eg. IPV4, IPV6
586 mac1 - Mac address of first host
587 mac2 - Mac address of the second host
588 bandwidth - Bandwidth capacity
589 lambdaAlloc - Allocate lambda, defaults to False
590 ipProto - IP protocol
591 ip1 - IP address of first host
592 ip2 - IP address of second host
593 tcp1 - TCP port of first host
594 tcp2 - TCP port of second host
595 sw1 - First switch to bring down & up for rerouting purpose
596 sw2 - Second switch to bring down & up for rerouting purpose
597 expectedLink - Expected link when the switches are down, it should
598 be two links lower than the links before the two
599 switches are down
600 """
601
602 assert main, "There is no main variable"
603 assert name, "variable name is empty"
604 assert host1 and host2, "You must specify hosts"
605
606 global itemName
607 itemName = name
608 host1 = host1
609 host2 = host2
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700610 intentsId = []
611
612 iperfResult = main.TRUE
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700613 linkDownResult = main.TRUE
614 linkUpResult = main.TRUE
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700615
616 # Adding bidirectional point intents
617 main.log.info( itemName + ": Adding point intents" )
618 intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
619 egressDevice=deviceId2,
620 portIngress=port1,
621 portEgress=port2,
622 ethType=ethType,
623 ethSrc=mac1,
624 ethDst=mac2,
625 bandwidth=bandwidth,
626 lambdaAlloc=lambdaAlloc,
627 ipProto=ipProto,
628 ipSrc=ip1,
629 ipDst=ip2,
630 tcpSrc=tcp1,
631 tcpDst="" )
632
633 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
634 egressDevice=deviceId1,
635 portIngress=port2,
636 portEgress=port1,
637 ethType=ethType,
638 ethSrc=mac2,
639 ethDst=mac1,
640 bandwidth=bandwidth,
641 lambdaAlloc=lambdaAlloc,
642 ipProto=ipProto,
643 ipSrc=ip2,
644 ipDst=ip1,
645 tcpSrc=tcp2,
646 tcpDst="" )
647
648 intent3 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
649 egressDevice=deviceId2,
650 portIngress=port1,
651 portEgress=port2,
652 ethType=ethType,
653 ethSrc=mac1,
654 ethDst=mac2,
655 bandwidth=bandwidth,
656 lambdaAlloc=lambdaAlloc,
657 ipProto=ipProto,
658 ipSrc=ip1,
659 ipDst=ip2,
660 tcpSrc="",
661 tcpDst=tcp2 )
662
663 intent4 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
664 egressDevice=deviceId1,
665 portIngress=port2,
666 portEgress=port1,
667 ethType=ethType,
668 ethSrc=mac2,
669 ethDst=mac1,
670 bandwidth=bandwidth,
671 lambdaAlloc=lambdaAlloc,
672 ipProto=ipProto,
673 ipSrc=ip2,
674 ipDst=ip1,
675 tcpSrc="",
676 tcpDst=tcp1 )
677 intentsId.append( intent1 )
678 intentsId.append( intent2 )
679 intentsId.append( intent3 )
680 intentsId.append( intent4 )
681
682 # Check intents state
683 time.sleep( main.checkIntentSleep )
Jon Hallaf95c3e2017-05-16 13:20:37 -0700684 intentResult = utilities.retry( f=checkIntentState,
685 retValue=main.FALSE,
686 args=( main, intentsId ),
687 sleep=1,
688 attempts=50 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700689 # Check flows count in each node
690 checkFlowsCount( main )
691
692 # Check intents state again if first check fails...
693 if not intentResult:
Jon Hallaf95c3e2017-05-16 13:20:37 -0700694 intentResult = utilities.retry( f=checkIntentState,
695 retValue=main.FALSE,
696 args=( main, intentsId ),
697 sleep=1,
698 attempts=50 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700699
700 # Check flows count in each node
701 checkFlowsCount( main )
702
703 # Verify flows
704 checkFlowsState( main )
705
706 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700707 iperfTemp = main.Mininet1.iperftcp( host1, host2 ,10 )
acsmarsd4862d12015-10-06 17:57:34 -0700708 iperfResult = iperfResult and iperfTemp
709 if iperfTemp:
710 main.assertReturnString += 'Initial Iperf Passed\n'
711 else:
712 main.assertReturnString += 'Initial Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700713
714 # Test rerouting if these variables exist
715 if sw1 and sw2 and expectedLink:
716 # link down
717 linkDownResult = link( main, sw1, sw2, "down" )
acsmarsd4862d12015-10-06 17:57:34 -0700718
719 if linkDownResult:
720 main.assertReturnString += 'Link Down Passed\n'
721 else:
722 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700723
724 # Check flows count in each node
725 checkFlowsCount( main )
726 # Verify flows
727 checkFlowsState( main )
728
729 # Check OnosTopology
730 topoResult = checkTopology( main, expectedLink )
acsmarsd4862d12015-10-06 17:57:34 -0700731 if topoResult:
732 main.assertReturnString += 'Link Down Topology State Passed\n'
733 else:
734 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700735
736 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700737 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700738 iperfResult = iperfResult and iperfTemp
739 if iperfTemp:
740 main.assertReturnString += 'Link Down Iperf Passed\n'
741 else:
742 main.assertReturnString += 'Link Down Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700743
acsmarsd4862d12015-10-06 17:57:34 -0700744 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700745 intentTemp = utilities.retry( f=checkIntentState,
746 retValue=main.FALSE,
747 args=( main, intentsId ),
748 sleep=1,
749 attempts=50 )
acsmarsd4862d12015-10-06 17:57:34 -0700750 intentResult = intentResult and intentTemp
751 if intentTemp:
752 main.assertReturnString += 'Link Down Intent State Passed\n'
753 else:
754 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700755
756 # Checks ONOS state in link down
757 if linkDownResult and topoResult and iperfResult and intentResult:
758 main.log.info( itemName + ": Successfully brought link down" )
759 else:
760 main.log.error( itemName + ": Failed to bring link down" )
761
762 # link up
763 linkUpResult = link( main, sw1, sw2, "up" )
alison52b25892016-09-19 10:53:48 -0700764 if linkUpResult:
acsmarsd4862d12015-10-06 17:57:34 -0700765 main.assertReturnString += 'Link Up Passed\n'
766 else:
767 main.assertReturnString += 'Link Up Failed\n'
768
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700769 time.sleep( main.rerouteSleep )
770
771 # Check flows count in each node
772 checkFlowsCount( main )
773 # Verify flows
774 checkFlowsState( main )
775
776 # Check OnosTopology
777 topoResult = checkTopology( main, main.numLinks )
778
acsmarsd4862d12015-10-06 17:57:34 -0700779 if topoResult:
780 main.assertReturnString += 'Link Up Topology State Passed\n'
781 else:
782 main.assertReturnString += 'Link Up Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700783
acsmarsd4862d12015-10-06 17:57:34 -0700784 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700785 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700786 iperfResult = iperfResult and iperfTemp
787 if iperfTemp:
788 main.assertReturnString += 'Link Up Iperf Passed\n'
789 else:
790 main.assertReturnString += 'Link Up Iperf Failed\n'
791
792 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700793 intentTemp = utilities.retry( f=checkIntentState,
794 retValue=main.FALSE,
795 args=( main, intentsId ),
796 sleep=1,
797 attempts=50 )
acsmarsd4862d12015-10-06 17:57:34 -0700798 intentResult = intentResult and intentTemp
799 if intentTemp:
800 main.assertReturnString += 'Link Down Intent State Passed\n'
801 else:
802 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700803
804 # Checks ONOS state in link up
805 if linkUpResult and topoResult and iperfResult and intentResult:
806 main.log.info( itemName + ": Successfully brought link back up" )
807 else:
808 main.log.error( itemName + ": Failed to bring link back up" )
809
810 # Remove all intents
811 removeIntentResult = removeAllIntents( main, intentsId )
acsmarsd4862d12015-10-06 17:57:34 -0700812 if removeIntentResult:
813 main.assertReturnString += 'Remove Intents Passed'
814 else:
815 main.assertReturnString += 'Remove Intents Failed'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700816
817 stepResult = iperfResult and linkDownResult and linkUpResult \
818 and intentResult and removeIntentResult
819
820 return stepResult
821
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800822def installSingleToMultiIntent( main,
823 name,
824 senders,
825 recipients,
826 onosNode=0,
827 ethType="",
828 bandwidth="",
829 lambdaAlloc=False,
830 ipProto="",
831 ipAddresses="",
832 tcp="",
833 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700834 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -0700835 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700836 partial=False,
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700837 encap="",
838 bandwidthFlag=False ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700839 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800840 Installs a Single to Multi Point Intent
841
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700842 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800843 Install a single to multi point intent using
844 add-single-to-multi-intent
845
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700846 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800847 - Fetch host data if not given
848 - Add single to multi intent
849 - Ingress device is the first sender host
850 - Egress devices are the recipient devices
851 - Ports if defined in senders or recipients
852 - MAC address ethSrc loaded from Ingress device
853 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700854 Required:
855 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800856 senders - List of host dictionaries i.e.
857 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
858 recipients - List of host dictionaries i.e.
859 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700860 Optional:
861 onosNode - ONOS node to install the intents in main.CLIs[ ]
862 0 by default so that it will always use the first
863 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700864 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700865 bandwidth - Bandwidth capacity
866 lambdaAlloc - Allocate lambda, defaults to False
867 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700868 tcp - TCP ports in the same order as the hosts in hostNames
869 sw1 - First switch to bring down & up for rerouting purpose
870 sw2 - Second switch to bring down & up for rerouting purpose
871 expectedLink - Expected link when the switches are down, it should
872 be two links lower than the links before the two
873 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700874 """
875
876 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800877 assert senders, "You must specify a sender"
878 assert recipients, "You must specify a recipient"
879 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700880
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800881 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700882 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700883
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700884 global singleToMultiFailFlag
885 singleToMultiFailFlag = False
886
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700887 main.log.info( itemName + ": Adding single point to multi point intents" )
888
Jeremyd9e4eb12016-04-13 12:09:06 -0700889 try:
890 for sender in senders:
891 if not sender.get( "device" ):
892 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
893 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700894
Jeremyd9e4eb12016-04-13 12:09:06 -0700895 for recipient in recipients:
896 if not recipient.get( "device" ):
897 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
898 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700899
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700900
Jeremyd9e4eb12016-04-13 12:09:06 -0700901 ingressDevice = senders[ 0 ].get( "device" )
902 egressDeviceList = [ x.get( "device" ) for x in recipients if x.get( "device" ) ]
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800903
Jeremyd9e4eb12016-04-13 12:09:06 -0700904 portIngress = senders[ 0 ].get( "port", "" )
905 portEgressList = [ x.get( "port" ) for x in recipients if x.get( "port" ) ]
906 if not portEgressList:
907 portEgressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800908
Jeremyd9e4eb12016-04-13 12:09:06 -0700909 srcMac = senders[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700910 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800911
Jeremyd9e4eb12016-04-13 12:09:06 -0700912 # Adding point intent
913 intentId = main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
914 ingressDevice=ingressDevice,
915 egressDeviceList=egressDeviceList,
916 portIngress=portIngress,
917 portEgressList=portEgressList,
918 ethType=ethType,
919 ethSrc=srcMac,
920 bandwidth=bandwidth,
921 lambdaAlloc=lambdaAlloc,
922 ipProto=ipProto,
923 ipSrc="",
924 ipDst="",
925 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -0700926 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700927 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -0700928 setVlan=setVlan,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700929 partial=partial,
930 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700931 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700932 errorMsg = "There was a problem loading the hosts data."
933 if intentId:
934 errorMsg += " There was a problem installing Singlepoint to Multipoint intent."
935 main.log.error( errorMsg )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700936 singleToMultiFailFlag = True
Jeremyd9e4eb12016-04-13 12:09:06 -0700937 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700938
939 # Check intents state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700940 if singleToMultiFailFlag:
941 attempts = 5
942 else:
943 attempts = 50
944
Jon Hallaf95c3e2017-05-16 13:20:37 -0700945 if utilities.retry( f=checkIntentState,
946 retValue=main.FALSE,
947 args=( main, [ intentId ], bandwidthFlag ),
948 sleep=main.checkIntentSleep,
949 attempts=attempts ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700950 main.assertReturnString += 'Install Intent State Passed\n'
951 if flowDuration( main ):
952 main.assertReturnString += 'Flow duration check Passed\n'
953 return intentId
954 else:
955 main.assertReturnString += 'Flow duration check failed\n'
956 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -0700957 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800958 main.log.error( "Single to Multi Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700959 singleToMultiFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800960 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700961
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800962def installMultiToSingleIntent( main,
963 name,
964 senders,
965 recipients,
966 onosNode=0,
967 ethType="",
968 bandwidth="",
969 lambdaAlloc=False,
970 ipProto="",
971 ipAddresses="",
972 tcp="",
973 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700974 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -0700975 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700976 partial=False,
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700977 encap="",
978 bandwidthFlag=False ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700979 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800980 Installs a Multi to Single Point Intent
981
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700982 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800983 Install a multi to single point intent using
984 add-multi-to-single-intent
985
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700986 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800987 - Fetch host data if not given
988 - Add multi to single intent
989 - Ingress devices are the senders devices
990 - Egress device is the first recipient host
991 - Ports if defined in senders or recipients
992 - MAC address ethSrc loaded from Ingress device
993 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700994 Required:
995 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800996 senders - List of host dictionaries i.e.
997 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
998 recipients - List of host dictionaries i.e.
999 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001000 Optional:
1001 onosNode - ONOS node to install the intents in main.CLIs[ ]
1002 0 by default so that it will always use the first
1003 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001004 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001005 bandwidth - Bandwidth capacity
1006 lambdaAlloc - Allocate lambda, defaults to False
1007 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001008 tcp - TCP ports in the same order as the hosts in hostNames
1009 sw1 - First switch to bring down & up for rerouting purpose
1010 sw2 - Second switch to bring down & up for rerouting purpose
1011 expectedLink - Expected link when the switches are down, it should
1012 be two links lower than the links before the two
1013 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001014 """
1015
1016 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001017 assert senders, "You must specify a sender"
1018 assert recipients, "You must specify a recipient"
1019 # Assert devices or main.hostsData, "You must specify devices"
1020
1021 global itemName # The name of this run. Used for logs.
1022 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001023
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001024 global multiToSingleFailFlag
1025 multiToSingleFailFlag = False
1026
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001027 main.log.info( itemName + ": Adding mutli to single point intents" )
1028
Jeremyd9e4eb12016-04-13 12:09:06 -07001029 try:
1030 for sender in senders:
1031 if not sender.get( "device" ):
1032 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1033 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001034
Jeremyd9e4eb12016-04-13 12:09:06 -07001035 for recipient in recipients:
1036 if not recipient.get( "device" ):
1037 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1038 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001039
Jeremyd9e4eb12016-04-13 12:09:06 -07001040 ingressDeviceList = [ x.get( "device" ) for x in senders if x.get( "device" ) ]
1041 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001042
Jeremyd9e4eb12016-04-13 12:09:06 -07001043 portIngressList = [ x.get( "port" ) for x in senders if x.get( "port" ) ]
1044 portEgress = recipients[ 0 ].get( "port", "" )
1045 if not portIngressList:
1046 portIngressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001047
Jeremyd9e4eb12016-04-13 12:09:06 -07001048 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001049 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001050
Jeremyd9e4eb12016-04-13 12:09:06 -07001051 # Adding point intent
1052 intentId = main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
1053 ingressDeviceList=ingressDeviceList,
1054 egressDevice=egressDevice,
1055 portIngressList=portIngressList,
1056 portEgress=portEgress,
1057 ethType=ethType,
1058 ethDst=dstMac,
1059 bandwidth=bandwidth,
1060 lambdaAlloc=lambdaAlloc,
1061 ipProto=ipProto,
1062 ipSrc="",
1063 ipDst="",
1064 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -07001065 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -07001066 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -07001067 setVlan=setVlan,
Jeremy Songsterc032f162016-08-04 17:14:49 -07001068 partial=partial,
1069 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001070 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001071 errorMsg = "There was a problem loading the hosts data."
1072 if intentId:
1073 errorMsg += " There was a problem installing Multipoint to Singlepoint intent."
1074 main.log.error( errorMsg )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001075 multiToSingleFailFlag = True
Jeremyd9e4eb12016-04-13 12:09:06 -07001076 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001077
1078 # Check intents state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001079 if multiToSingleFailFlag:
1080 attempts = 5
1081 else:
1082 attempts = 50
1083
Jon Hallaf95c3e2017-05-16 13:20:37 -07001084 if utilities.retry( f=checkIntentState,
1085 retValue=main.FALSE,
1086 args=( main, [ intentId ], bandwidthFlag ),
1087 sleep=main.checkIntentSleep,
1088 attempts=attempts ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001089 main.assertReturnString += 'Install Intent State Passed\n'
1090 if flowDuration( main ):
1091 main.assertReturnString += 'Flow duration check Passed\n'
1092 return intentId
1093 else:
1094 main.assertReturnString += 'Flow duration check failed\n'
1095 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001096 else:
1097 main.log.error( "Multi to Single Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001098 multiToSingleFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001099 return main.FALSE
1100
1101def testPointIntent( main,
Jeremye0cb5eb2016-01-27 17:39:09 -08001102 name,
1103 intentId,
1104 senders,
1105 recipients,
1106 badSenders={},
1107 badRecipients={},
1108 onosNode=0,
1109 ethType="",
1110 bandwidth="",
1111 lambdaAlloc=False,
alisonda157272016-12-22 01:13:21 -08001112 protected=False,
Jeremye0cb5eb2016-01-27 17:39:09 -08001113 ipProto="",
1114 ipAddresses="",
1115 tcp="",
1116 sw1="s5",
1117 sw2="s2",
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001118 expectedLink=0,
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001119 useTCP=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001120 """
1121 Test a Point Intent
1122
1123 Description:
1124 Test a point intent
1125
1126 Steps:
1127 - Fetch host data if not given
1128 - Check Intent State
1129 - Check Flow State
1130 - Check Connectivity
1131 - Check Lack of Connectivity Between Hosts not in the Intent
1132 - Reroute
1133 - Take Expected Link Down
1134 - Check Intent State
1135 - Check Flow State
1136 - Check Topology
1137 - Check Connectivity
1138 - Bring Expected Link Up
1139 - Check Intent State
1140 - Check Flow State
1141 - Check Topology
1142 - Check Connectivity
1143 - Remove Topology
1144
1145 Required:
1146 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
1147
1148 senders - List of host dictionaries i.e.
1149 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
1150 recipients - List of host dictionaries i.e.
1151 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
1152 Optional:
1153 onosNode - ONOS node to install the intents in main.CLIs[ ]
1154 0 by default so that it will always use the first
1155 ONOS node
1156 ethType - Ethernet type eg. IPV4, IPV6
1157 bandwidth - Bandwidth capacity
1158 lambdaAlloc - Allocate lambda, defaults to False
1159 ipProto - IP protocol
1160 tcp - TCP ports in the same order as the hosts in hostNames
1161 sw1 - First switch to bring down & up for rerouting purpose
1162 sw2 - Second switch to bring down & up for rerouting purpose
1163 expectedLink - Expected link when the switches are down, it should
1164 be two links lower than the links before the two
1165 switches are down
1166
1167 """
1168
1169 # Parameter Validity Check
1170 assert main, "There is no main variable"
1171 assert senders, "You must specify a sender"
1172 assert recipients, "You must specify a recipient"
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001173
1174 global itemName
1175 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001176
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001177 global pointIntentFailFlag
1178 global singleToMultiFailFlag
1179 global multiToSingleFailFlag
1180
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001181 main.log.info( itemName + ": Testing Point Intent" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001182
Jeremyd9e4eb12016-04-13 12:09:06 -07001183 try:
1184 # Names for scapy
1185 senderNames = [ x.get( "name" ) for x in senders ]
1186 recipientNames = [ x.get( "name" ) for x in recipients ]
1187 badSenderNames = [ x.get( "name" ) for x in badSenders ]
1188 badRecipientNames = [ x.get( "name" ) for x in badRecipients ]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001189
Jeremyd9e4eb12016-04-13 12:09:06 -07001190 for sender in senders:
1191 if not sender.get( "device" ):
1192 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1193 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001194
Jeremyd9e4eb12016-04-13 12:09:06 -07001195 for recipient in recipients:
1196 if not recipient.get( "device" ):
1197 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1198 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001199 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001200 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001201 main.log.error( "There was a problem loading the hosts data." )
1202 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001203
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001204 testResult = main.TRUE
1205 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001206
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001207 if pointIntentFailFlag or singleToMultiFailFlag or multiToSingleFailFlag:
1208 attempts = 1
1209 else:
1210 attempts = 50
1211
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001212 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001213 if utilities.retry( f=checkIntentState,
1214 retValue=main.FALSE,
1215 args=( main, [ intentId ] ),
1216 sleep=main.checkIntentSleep,
1217 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001218 main.assertReturnString += 'Initial Intent State Passed\n'
acsmarsd4862d12015-10-06 17:57:34 -07001219 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001220 main.assertReturnString += 'Initial Intent State Failed\n'
1221 testResult = main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001222 attempts = 1
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001223
1224 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001225 if utilities.retry( f=checkFlowsCount,
1226 retValue=main.FALSE,
1227 args=[ main ],
1228 sleep=20,
1229 attempts=3 ) and utilities.retry( f=checkFlowsState,
1230 retValue=main.FALSE,
1231 args=[ main ],
1232 sleep=20,
1233 attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001234 main.assertReturnString += 'Initial Flow State Passed\n'
1235 else:
1236 main.assertReturnString += 'Intial Flow State Failed\n'
1237 testResult = main.FALSE
1238
1239 # Check Connectivity
Jon Hallaf95c3e2017-05-16 13:20:37 -07001240 if utilities.retry( f=scapyCheckConnection,
1241 retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -07001242 args=( main, senderNames, recipientNames, vlanId, useTCP ),
Jon Hallaf95c3e2017-05-16 13:20:37 -07001243 attempts=attempts,
1244 sleep=main.checkConnectionSleep ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001245 main.assertReturnString += 'Initial Ping Passed\n'
1246 else:
1247 main.assertReturnString += 'Initial Ping Failed\n'
1248 testResult = main.FALSE
1249
1250 # Check connections that shouldn't work
1251 if badSenderNames:
1252 main.log.info( "Checking that packets from incorrect sender do not go through" )
Jon Hallaf95c3e2017-05-16 13:20:37 -07001253 if utilities.retry( f=scapyCheckConnection,
1254 retValue=main.FALSE,
1255 args=( main, badSenderNames, recipientNames ),
1256 kwargs={ "expectFailure":True } ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001257 main.assertReturnString += 'Bad Sender Ping Passed\n'
1258 else:
1259 main.assertReturnString += 'Bad Sender Ping Failed\n'
1260 testResult = main.FALSE
1261
1262 if badRecipientNames:
1263 main.log.info( "Checking that packets to incorrect recipients do not go through" )
Jon Hallaf95c3e2017-05-16 13:20:37 -07001264 if utilities.retry( f=scapyCheckConnection,
1265 retValue=main.FALSE,
1266 args=( main, senderNames, badRecipientNames ),
1267 kwargs={ "expectFailure":True } ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001268 main.assertReturnString += 'Bad Recipient Ping Passed\n'
1269 else:
1270 main.assertReturnString += 'Bad Recipient Ping Failed\n'
1271 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001272
1273 # Test rerouting if these variables exist
1274 if sw1 and sw2 and expectedLink:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001275 # Take link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001276 if utilities.retry( f=link,
1277 retValue=main.FALSE,
1278 args=( main, sw1, sw2, "down" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001279 main.assertReturnString += 'Link Down Passed\n'
1280 else:
1281 main.assertReturnString += 'Link Down Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001282 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001283
alisonda157272016-12-22 01:13:21 -08001284 if protected:
1285 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001286 if utilities.retry( f=scapyCheckConnection,
1287 retValue=main.FALSE,
1288 args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
alisonda157272016-12-22 01:13:21 -08001289 main.assertReturnString += 'Link down Scapy Packet Received Passed\n'
1290 else:
1291 main.assertReturnString += 'Link down Scapy Packet Recieved Failed\n'
1292 testResult = main.FALSE
1293
1294 if ProtectedIntentCheck( main ):
1295 main.assertReturnString += 'Protected Intent Check Passed\n'
1296 else:
1297 main.assertReturnString += 'Protected Intent Check Failed\n'
1298 testResult = main.FALSE
1299
acsmarsd4862d12015-10-06 17:57:34 -07001300 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001301 if utilities.retry( f=checkIntentState,
1302 retValue=main.FALSE,
1303 args=( main, [ intentId ] ),
1304 sleep=main.checkIntentPointSleep,
1305 attempts=attempts ):
acsmarsd4862d12015-10-06 17:57:34 -07001306 main.assertReturnString += 'Link Down Intent State Passed\n'
1307 else:
1308 main.assertReturnString += 'Link Down Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001309 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001310
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001311 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001312 if utilities.retry( f=checkFlowsCount,
1313 retValue=main.FALSE,
1314 args=[ main ],
1315 sleep=main.checkFlowCountSleep,
1316 attempts=attempts * 2 ) and utilities.retry( f=checkFlowsState,
1317 retValue=main.FALSE,
1318 args=[ main ],
1319 sleep=main.checkFlowCountSleep,
1320 attempts=attempts * 2 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001321 main.assertReturnString += 'Link Down Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001322 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001323 main.assertReturnString += 'Link Down Flow State Failed\n'
1324 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001325
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001326 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001327 if utilities.retry( f=checkTopology,
1328 retValue=main.FALSE,
1329 args=( main, expectedLink ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001330 main.assertReturnString += 'Link Down Topology State Passed\n'
1331 else:
1332 main.assertReturnString += 'Link Down Topology State Failed\n'
1333 testResult = main.FALSE
1334
1335 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001336 if utilities.retry( f=scapyCheckConnection,
1337 retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -07001338 args=( main, senderNames, recipientNames, vlanId, useTCP ),
Jon Hallaf95c3e2017-05-16 13:20:37 -07001339 sleep=main.checkConnectionSleep,
1340 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001341 main.assertReturnString += 'Link Down Pingall Passed\n'
1342 else:
1343 main.assertReturnString += 'Link Down Pingall Failed\n'
1344 testResult = main.FALSE
1345
1346 # Bring link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001347 if utilities.retry( f=link,
1348 retValue=main.FALSE,
1349 args=( main, sw1, sw2, "up" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001350 main.assertReturnString += 'Link Up Passed\n'
1351 else:
1352 main.assertReturnString += 'Link Up Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001353 testResult = main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -07001354
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001355 # Wait for reroute
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001356 time.sleep( main.rerouteSleep )
1357
acsmarsd4862d12015-10-06 17:57:34 -07001358 # Check Intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001359 if utilities.retry( f=checkIntentState,
1360 retValue=main.FALSE,
1361 attempts=attempts * 2,
1362 args=( main, [ intentId ] ),
Shreyaca8990f2017-03-16 11:43:11 -07001363 sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001364 main.assertReturnString += 'Link Up Intent State Passed\n'
1365 else:
1366 main.assertReturnString += 'Link Up Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001367 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001368
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001369 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001370 if utilities.retry( f=checkFlowsCount,
1371 retValue=main.FALSE,
1372 args=[ main ],
1373 sleep=20,
1374 attempts=3 ) and utilities.retry( f=checkFlowsState,
1375 retValue=main.FALSE,
1376 args=[ main ],
1377 sleep=20,
1378 attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001379 main.assertReturnString += 'Link Up Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001380 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001381 main.assertReturnString += 'Link Up Flow State Failed\n'
1382 testResult = main.FALSE
1383
1384 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001385 if utilities.retry( f=checkTopology,
1386 retValue=main.FALSE,
1387 args=( main, main.numLinks ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001388 main.assertReturnString += 'Link Up Topology State Passed\n'
1389 else:
1390 main.assertReturnString += 'Link Up Topology State Failed\n'
1391 testResult = main.FALSE
1392
1393 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001394 if utilities.retry( f=scapyCheckConnection,
1395 retValue=main.FALSE,
1396 sleep=main.checkConnectionSleep,
1397 attempts=100,
Shreyaca8990f2017-03-16 11:43:11 -07001398 args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001399 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1400 else:
1401 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1402 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001403
1404 # Remove all intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001405 if utilities.retry( f=removeAllIntents,
1406 retValue=main.FALSE,
1407 attempts=10,
1408 args=( main, [ intentId ] ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001409 main.assertReturnString += 'Remove Intents Passed'
1410 else:
1411 main.assertReturnString += 'Remove Intents Failed'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001412 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001413
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001414 return testResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001415
Jeremye0cb5eb2016-01-27 17:39:09 -08001416def testEndPointFail( main,
1417 name,
1418 intentId,
1419 senders,
1420 recipients,
1421 isolatedSenders,
1422 isolatedRecipients,
1423 onosNode=0,
1424 ethType="",
1425 bandwidth="",
1426 lambdaAlloc=False,
1427 ipProto="",
1428 ipAddresses="",
1429 tcp="",
1430 sw1="",
1431 sw2="",
1432 sw3="",
1433 sw4="",
1434 sw5="",
1435 expectedLink1=0,
Jeremy Songster9385d412016-06-02 17:57:36 -07001436 expectedLink2=0,
1437 partial=False ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001438 """
Shreyaca8990f2017-03-16 11:43:11 -07001439 Test Multi point to single point intent Topology for Endpoint failures
Jeremye0cb5eb2016-01-27 17:39:09 -08001440 """
1441
1442 # Parameter Validity Check
1443 assert main, "There is no main variable"
1444 assert senders, "You must specify a sender"
1445 assert recipients, "You must specify a recipient"
1446
1447 global itemName
1448 itemName = name
Jeremye0cb5eb2016-01-27 17:39:09 -08001449
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001450 global singleToMultiFailFlag
1451 global multiToSingleFailFlag
1452
Jeremye0cb5eb2016-01-27 17:39:09 -08001453 main.log.info( itemName + ": Testing Point Intent" )
1454
Jeremyd9e4eb12016-04-13 12:09:06 -07001455 try:
1456 # Names for scapy
1457 senderNames = [ x.get( "name" ) for x in senders ]
1458 recipientNames = [ x.get( "name" ) for x in recipients ]
1459 isolatedSenderNames = [ x.get( "name" ) for x in isolatedSenders ]
1460 isolatedRecipientNames = [ x.get( "name" ) for x in isolatedRecipients ]
1461 connectedSenderNames = [x.get("name") for x in senders if x.get("name") not in isolatedSenderNames]
1462 connectedRecipientNames = [x.get("name") for x in recipients if x.get("name") not in isolatedRecipientNames]
Jeremye0cb5eb2016-01-27 17:39:09 -08001463
Jeremyd9e4eb12016-04-13 12:09:06 -07001464 for sender in senders:
1465 if not sender.get( "device" ):
1466 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1467 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremye0cb5eb2016-01-27 17:39:09 -08001468
Jeremyd9e4eb12016-04-13 12:09:06 -07001469 for recipient in recipients:
1470 if not recipient.get( "device" ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001471 main.log.warn( "Device not given for recipient {0}. Loading from " +\
1472 main.hostData.format( recipient.get( "name" ) ) )
Jeremyd9e4eb12016-04-13 12:09:06 -07001473 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001474 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001475 main.log.error( "There was a problem loading the hosts data." )
1476 return main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001477
1478 testResult = main.TRUE
1479 main.log.info( itemName + ": Adding multi point to single point intents" )
1480
1481 # Check intent state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001482 if singleToMultiFailFlag or multiToSingleFailFlag:
1483 attempts = 1
1484 else:
1485 attempts = 50
1486
Jon Hallaf95c3e2017-05-16 13:20:37 -07001487 if utilities.retry( f=checkIntentState,
1488 retValue=main.FALSE,
1489 args=( main, [ intentId ] ),
1490 sleep=main.checkIntentSleep,
1491 attempts=attempts ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001492 main.assertReturnString += 'Initial Intent State Passed\n'
1493 else:
1494 main.assertReturnString += 'Initial Intent State Failed\n'
1495 testResult = main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001496 attempts = 1
Jeremye0cb5eb2016-01-27 17:39:09 -08001497
1498 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001499 if utilities.retry( f=checkFlowsCount,
1500 retValue=main.FALSE,
1501 args=[ main ],
1502 attempts=5 ) and utilities.retry( f=checkFlowsState,
1503 retValue=main.FALSE,
1504 args=[ main ],
1505 attempts=5 ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001506 main.assertReturnString += 'Initial Flow State Passed\n'
1507 else:
1508 main.assertReturnString += 'Intial Flow State Failed\n'
1509 testResult = main.FALSE
1510
1511 # Check Connectivity
Jon Hallaf95c3e2017-05-16 13:20:37 -07001512 if utilities.retry( f=scapyCheckConnection,
1513 retValue=main.FALSE,
Jeremye0cb5eb2016-01-27 17:39:09 -08001514 args=( main, senderNames, recipientNames ) ):
1515 main.assertReturnString += 'Initial Connectivity Check Passed\n'
1516 else:
1517 main.assertReturnString += 'Initial Connectivity Check Failed\n'
1518 testResult = main.FALSE
1519
1520 # Take two links down
1521 # Take first link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001522 if utilities.retry( f=link,
1523 retValue=main.FALSE,
1524 args=( main, sw1, sw2, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001525 main.assertReturnString += 'Link Down Passed\n'
1526 else:
1527 main.assertReturnString += 'Link Down Failed\n'
1528 testResult = main.FALSE
1529
1530 # Take second link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001531 if utilities.retry( f=link,
1532 retValue=main.FALSE,
1533 args=( main, sw3, sw4, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001534 main.assertReturnString += 'Link Down Passed\n'
1535 else:
1536 main.assertReturnString += 'Link Down Failed\n'
1537 testResult = main.FALSE
1538
1539 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001540 if utilities.retry( f=checkIntentState,
1541 retValue=main.FALSE,
1542 attempts=attempts,
1543 args=( main, [ intentId ] ),
1544 sleep=main.checkIntentSleep ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001545 main.assertReturnString += 'Link Down Intent State Passed\n'
1546 else:
1547 main.assertReturnString += 'Link Down Intent State Failed\n'
1548 testResult = main.FALSE
1549
1550 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001551 if utilities.retry( f=checkFlowsCount,
1552 retValue=main.FALSE,
1553 sleep=1,
1554 attempts=attempts,
Jeremye0cb5eb2016-01-27 17:39:09 -08001555 args=[ main ] ) and utilities.retry( f=checkFlowsState,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001556 retValue=main.FALSE,
1557 sleep=1,
1558 attempts=attempts,
1559 args=[ main ] ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001560 main.assertReturnString += 'Link Down Flow State Passed\n'
1561 else:
1562 main.assertReturnString += 'Link Down Flow State Failed\n'
1563 testResult = main.FALSE
1564
1565 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001566 if utilities.retry( f=checkTopology,
1567 retValue=main.FALSE,
1568 args=( main, expectedLink1 ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001569 main.assertReturnString += 'Link Down Topology State Passed\n'
1570 else:
1571 main.assertReturnString += 'Link Down Topology State Failed\n'
1572 testResult = main.FALSE
1573
1574 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001575 if utilities.retry( f=scapyCheckConnection,
1576 retValue=main.FALSE,
Jeremye0cb5eb2016-01-27 17:39:09 -08001577 args=( main, senderNames, recipientNames ) ):
1578 main.assertReturnString += 'Link Down Connectivity Check Passed\n'
1579 else:
1580 main.assertReturnString += 'Link Down Connectivity Check Failed\n'
1581 testResult = main.FALSE
1582
1583 # Take a third link down to isolate one node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001584 if utilities.retry( f=link,
1585 retValue=main.FALSE,
1586 args=( main, sw3, sw5, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001587 main.assertReturnString += 'Isolation link Down Passed\n'
1588 else:
1589 main.assertReturnString += 'Isolation link Down Failed\n'
1590 testResult = main.FALSE
1591
Jeremy Songster9385d412016-06-02 17:57:36 -07001592 if partial:
1593 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001594 if utilities.retry( f=checkIntentState,
1595 retValue=main.FALSE,
1596 args=( main, [ intentId ] ),
1597 sleep=main.checkIntentSleep,
1598 attempts=attempts ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001599 main.assertReturnString += 'Partial failure isolation link Down Intent State Passed\n'
1600 else:
1601 main.assertReturnString += 'Partial failure isolation link Down Intent State Failed\n'
1602 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001603
Jeremy Songster9385d412016-06-02 17:57:36 -07001604 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001605 if utilities.retry( f=checkFlowsCount,
1606 retValue=main.FALSE,
1607 args=[ main ],
1608 attempts=5 ) and utilities.retry( f=checkFlowsState,
1609 retValue=main.FALSE,
1610 args=[ main ],
1611 attempts=5 ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001612 main.assertReturnString += 'Partial failure isolation link Down Flow State Passed\n'
1613 else:
1614 main.assertReturnString += 'Partial failure isolation link Down Flow State Failed\n'
1615 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001616
Jeremy Songster9385d412016-06-02 17:57:36 -07001617 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001618 if utilities.retry( f=checkTopology,
1619 retValue=main.FALSE,
1620 args=( main, expectedLink2 ) ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001621 main.assertReturnString += 'Partial failure isolation link Down Topology State Passed\n'
1622 else:
1623 main.assertReturnString += 'Partial failure isolation link Down Topology State Failed\n'
1624 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001625
Jeremy Songster9385d412016-06-02 17:57:36 -07001626 # Check Connectivity
1627 # First check connectivity of any isolated senders to recipients
1628 if isolatedSenderNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001629 if scapyCheckConnection( main,
1630 isolatedSenderNames,
1631 recipientNames,
1632 None,
1633 None,
1634 None,
1635 None,
1636 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001637 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1638 else:
1639 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1640 testResult = main.FALSE
1641
1642 # Next check connectivity of senders to any isolated recipients
1643 if isolatedRecipientNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001644 if scapyCheckConnection( main,
1645 senderNames,
1646 isolatedRecipientNames,
1647 None,
1648 None,
1649 None,
1650 None,
1651 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001652 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1653 else:
1654 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1655 testResult = main.FALSE
1656
1657 # Next check connectivity of connected senders and recipients
Jon Hallaf95c3e2017-05-16 13:20:37 -07001658 if utilities.retry( f=scapyCheckConnection,
1659 retValue=main.FALSE,
1660 attempts=attempts,
Jeremy Songster9385d412016-06-02 17:57:36 -07001661 args=( main, connectedSenderNames , connectedRecipientNames ) ):
1662 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1663 else:
1664 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1665 testResult = main.FALSE
1666 else:
1667 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001668 if not utilities.retry( f=checkIntentState,
1669 retValue=main.TRUE,
1670 args=( main, [ intentId ] ),
1671 sleep=main.checkIntentSleep,
1672 attempts=attempts ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001673 main.assertReturnString += 'Isolation link Down Intent State Passed\n'
1674 else:
1675 main.assertReturnString += 'Isolation link Down Intent State Failed\n'
1676 testResult = main.FALSE
1677
1678 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001679 if utilities.retry( f=checkFlowsCount,
1680 retValue=main.FALSE,
1681 args=[ main ],
1682 attempts=5 ) and utilities.retry( f=checkFlowsState,
1683 retValue=main.FALSE,
1684 args=[ main ],
1685 attempts=5 ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001686 main.assertReturnString += 'Isolation link Down Flow State Passed\n'
1687 else:
1688 main.assertReturnString += 'Isolation link Down Flow State Failed\n'
1689 testResult = main.FALSE
1690
1691 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001692 if utilities.retry( f=checkTopology,
1693 retValue=main.FALSE,
1694 args=( main, expectedLink2 ) ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001695 main.assertReturnString += 'Isolation link Down Topology State Passed\n'
1696 else:
1697 main.assertReturnString += 'Isolation link Down Topology State Failed\n'
1698 testResult = main.FALSE
1699
1700 # Check Connectivity
1701 # First check connectivity of any isolated senders to recipients
1702 if isolatedSenderNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001703 if scapyCheckConnection( main,
1704 isolatedSenderNames,
1705 recipientNames,
1706 None,
1707 None,
1708 None,
1709 None,
1710 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001711 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1712 else:
1713 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1714 testResult = main.FALSE
1715
1716 # Next check connectivity of senders to any isolated recipients
1717 if isolatedRecipientNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001718 if scapyCheckConnection( main,
1719 senderNames,
1720 isolatedRecipientNames,
1721 None,
1722 None,
1723 None,
1724 None,
1725 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001726 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1727 else:
1728 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1729 testResult = main.FALSE
1730
1731 # Next check connectivity of connected senders and recipients
Jon Hallaf95c3e2017-05-16 13:20:37 -07001732 if utilities.retry( f=scapyCheckConnection,
1733 retValue=main.TRUE,
1734 args=( main, connectedSenderNames, connectedRecipientNames, None, None, None, None, main.TRUE ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001735 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1736 else:
1737 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1738 testResult = main.FALSE
1739
Jeremye0cb5eb2016-01-27 17:39:09 -08001740 # Bring the links back up
1741 # Bring first link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001742 if utilities.retry( f=link,
1743 retValue=main.FALSE,
1744 args=( main, sw1, sw2, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001745 main.assertReturnString += 'Link Up Passed\n'
1746 else:
1747 main.assertReturnString += 'Link Up Failed\n'
1748 testResult = main.FALSE
1749
1750 # Bring second link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001751 if utilities.retry( f=link,
1752 retValue=main.FALSE,
1753 args=( main, sw3, sw5, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001754 main.assertReturnString += 'Link Up Passed\n'
1755 else:
1756 main.assertReturnString += 'Link Up Failed\n'
1757 testResult = main.FALSE
1758
1759 # Bring third link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001760 if utilities.retry( f=link,
1761 retValue=main.FALSE,
1762 args=( main, sw3, sw4, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001763 main.assertReturnString += 'Link Up Passed\n'
1764 else:
1765 main.assertReturnString += 'Link Up Failed\n'
1766 testResult = main.FALSE
1767
1768 # Wait for reroute
1769 time.sleep( main.rerouteSleep )
1770
1771 # Check Intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001772 if utilities.retry( f=checkIntentState,
1773 retValue=main.FALSE,
1774 attempts=attempts,
1775 args=( main, [ intentId ] ),
1776 sleep=main.checkIntentHostSleep ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001777 main.assertReturnString += 'Link Up Intent State Passed\n'
1778 else:
1779 main.assertReturnString += 'Link Up Intent State Failed\n'
1780 testResult = main.FALSE
1781
1782 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001783 if utilities.retry( f=checkFlowsCount,
1784 retValue=main.FALSE,
1785 args=[ main ],
1786 sleep=5,
1787 attempts=5*20 ) and utilities.retry( f=checkFlowsState,
1788 retValue=main.FALSE,
1789 args=[ main ],
1790 sleep=5,
1791 attempts=attempts ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001792 main.assertReturnString += 'Link Up Flow State Passed\n'
1793 else:
1794 main.assertReturnString += 'Link Up Flow State Failed\n'
1795 testResult = main.FALSE
1796
1797 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001798 if utilities.retry( f=checkTopology,
1799 retValue=main.FALSE,
1800 args=( main, main.numLinks ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001801 main.assertReturnString += 'Link Up Topology State Passed\n'
1802 else:
1803 main.assertReturnString += 'Link Up Topology State Failed\n'
1804 testResult = main.FALSE
1805
1806 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001807 if utilities.retry( f=scapyCheckConnection,
1808 retValue=main.FALSE,
1809 sleep=main.checkConnectionSleep,
1810 attempts=attempts,
Jeremye0cb5eb2016-01-27 17:39:09 -08001811 args=( main, senderNames, recipientNames ) ):
1812 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1813 else:
1814 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1815 testResult = main.FALSE
1816
1817 # Remove all intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001818 if utilities.retry( f=removeAllIntents,
1819 retValue=main.FALSE,
1820 attempts=10,
1821 args=( main, [ intentId ] ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001822 main.assertReturnString += 'Remove Intents Passed'
1823 else:
1824 main.assertReturnString += 'Remove Intents Failed'
1825 testResult = main.FALSE
1826
1827 return testResult
1828
1829
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001830def pingallHosts( main, hostList ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001831 """
1832 Ping all host in the hosts list variable
1833 """
Jon Halla5cb3412015-08-18 14:08:22 -07001834 main.log.info( "Pinging: " + str( hostList ) )
1835 return main.Mininet1.pingallHosts( hostList )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001836
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001837def fwdPingall( main ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001838 """
1839 Use fwd app and pingall to discover all the hosts
1840 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001841 appCheck = main.TRUE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001842 main.log.info( "Activating reactive forwarding app " )
1843 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001844
1845 # Wait for forward app activation to propagate
kelvin-onlab0ad05d12015-07-23 14:21:15 -07001846 time.sleep( main.fwdSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001847
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001848 # Check that forwarding is enabled on all nodes
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001849 for i in range( main.numCtrls ):
1850 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
1851 if appCheck != main.TRUE:
1852 main.log.warn( main.CLIs[ i ].apps() )
1853 main.log.warn( main.CLIs[ i ].appIDs() )
1854
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001855 # Send pingall in mininet
1856 main.log.info( "Run Pingall" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001857 pingResult = main.Mininet1.pingall( timeout = 600 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001858
1859 main.log.info( "Deactivating reactive forwarding app " )
1860 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001861 if activateResult and deactivateResult:
1862 main.log.info( "Successfully used fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001863 getDataResult = main.TRUE
1864 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001865 main.log.info( "Failed to use fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001866 getDataResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001867 return getDataResult
1868
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001869def confirmHostDiscovery( main ):
1870 """
1871 Confirms that all ONOS nodes have discovered all scapy hosts
1872 """
1873 import collections
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001874 hosts = main.topo.getAllHosts( main ) # Get host data from each ONOS node
1875 hostFails = [] # Reset for each failed attempt
1876
1877 # Check for matching hosts on each node
1878 scapyHostIPs = [ x.hostIp for x in main.scapyHosts if x.hostIp != "0.0.0.0" ]
1879 for controller in range( main.numCtrls ):
1880 controllerStr = str( controller + 1 ) # ONOS node number
1881 # Compare Hosts
1882 # Load hosts data for controller node
Jeremyd9e4eb12016-04-13 12:09:06 -07001883 try:
1884 if hosts[ controller ]:
1885 main.log.info( "Hosts discovered" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001886 else:
Jeremyd9e4eb12016-04-13 12:09:06 -07001887 main.log.error( "Problem discovering hosts" )
1888 if hosts[ controller ] and "Error" not in hosts[ controller ]:
1889 try:
1890 hostData = json.loads( hosts[ controller ] )
1891 except ( TypeError, ValueError ):
1892 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001893 hostFails.append( controllerStr )
Jeremyd9e4eb12016-04-13 12:09:06 -07001894 else:
1895 onosHostIPs = [ x.get( "ipAddresses" )[ 0 ]
1896 for x in hostData
1897 if len( x.get( "ipAddresses" ) ) > 0 ]
1898 if not set( collections.Counter( scapyHostIPs ) ).issubset( set ( collections.Counter( onosHostIPs ) ) ):
1899 main.log.warn( "Controller {0} only sees nodes with {1} IPs. It should see all of the following: {2}".format( controllerStr, onosHostIPs, scapyHostIPs ) )
1900 hostFails.append( controllerStr )
1901 else:
1902 main.log.error( "Hosts returned nothing or an error." )
1903 hostFails.append( controllerStr )
1904 except IndexError:
1905 main.log.error( "Hosts returned nothing, Failed to discover hosts." )
1906 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001907
1908 if hostFails:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001909 main.log.error( "List of failed ONOS Nodes:" + ', '.join( map( str, hostFails ) ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001910 return main.FALSE
1911 else:
1912 return main.TRUE
1913
1914def sendDiscoveryArp( main, hosts=None ):
1915 """
1916 Sends Discovery ARP packets from each host provided
1917 Defaults to each host in main.scapyHosts
1918 """
1919 # Send an arp ping from each host
1920 if not hosts:
1921 hosts = main.scapyHosts
1922 for host in hosts:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001923 pkt = 'Ether( src="{0}")/ARP( psrc="{1}")'.format( host.hostMac, host.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001924 # Send from the VLAN interface if there is one so ONOS discovers the VLAN correctly
1925 iface = None
1926 for interface in host.getIfList():
1927 if '.' in interface:
1928 main.log.debug( "Detected VLAN interface {0}. Sending ARP packet from {0}".format( interface ) )
1929 iface = interface
1930 break
1931 host.sendPacket( packet=pkt, iface=iface )
1932 main.log.info( "Sending ARP packet from {0}".format( host.name ) )
1933
1934def populateHostData( main ):
1935 """
1936 Populates hostsData
1937 """
1938 import json
1939 try:
1940 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
1941 hosts = main.Mininet1.getHosts().keys()
1942 # TODO: Make better use of new getHosts function
1943 for host in hosts:
1944 main.hostsData[ host ] = {}
1945 main.hostsData[ host ][ 'mac' ] = \
1946 main.Mininet1.getMacAddress( host ).upper()
1947 for hostj in hostsJson:
1948 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
1949 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
1950 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
1951 main.hostsData[ host ][ 'location' ] = \
1952 hostj[ 'location' ][ 'elementId' ] + '/' + \
1953 hostj[ 'location' ][ 'port' ]
1954 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
1955 return main.TRUE
Jeremyd9e4eb12016-04-13 12:09:06 -07001956 except ValueError:
1957 main.log.error( "ValueError while populating hostsData" )
1958 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001959 except KeyError:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001960 main.log.error( "KeyError while populating hostsData" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001961 return main.FALSE
Jeremyd9e4eb12016-04-13 12:09:06 -07001962 except IndexError:
1963 main.log.error( "IndexError while populating hostsData" )
1964 return main.FALSE
1965 except TypeError:
1966 main.log.error( "TypeError while populating hostsData" )
1967 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001968
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001969def checkTopology( main, expectedLink ):
1970 statusResult = main.TRUE
1971 # Check onos topology
1972 main.log.info( itemName + ": Checking ONOS topology " )
1973
1974 for i in range( main.numCtrls ):
Flavio Castro82ee2f62016-06-07 15:04:12 -07001975 statusResult = main.CLIs[ i ].checkStatus( main.numSwitch,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001976 expectedLink ) and statusResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001977 if not statusResult:
1978 main.log.error( itemName + ": Topology mismatch" )
1979 else:
1980 main.log.info( itemName + ": Topology match" )
1981 return statusResult
1982
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001983def checkIntentState( main, intentsId, bandwidthFlag=False ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001984 """
1985 This function will check intent state to make sure all the intents
1986 are in INSTALLED state
1987 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001988 intentResult = main.TRUE
1989 results = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001990 for i in range( main.numCtrls ):
Jon Hallaf95c3e2017-05-16 13:20:37 -07001991 output = main.CLIs[ i ].checkIntentState( intentsId=intentsId, bandwidthFlag=bandwidthFlag )
1992 results.append( output )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001993 if all( result == main.TRUE for result in results ):
1994 main.log.info( itemName + ": Intents are installed correctly" )
1995 else:
Shreyaca8990f2017-03-16 11:43:11 -07001996 main.log.warn( "Intents are not installed correctly" )
1997 intentResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001998 return intentResult
1999
2000def checkFlowsState( main ):
2001
2002 main.log.info( itemName + ": Check flows state" )
Jeremy Songsterff553672016-05-12 17:06:23 -07002003 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState( isPENDING=False )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002004 return checkFlowsResult
2005
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002006def link( main, sw1, sw2, option ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002007
2008 # link down
alison52b25892016-09-19 10:53:48 -07002009 main.log.info( itemName + ": Bring link " + option + " between " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002010 sw1 + " and " + sw2 )
2011 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
2012 return linkResult
2013
Jon Hallaf95c3e2017-05-16 13:20:37 -07002014def scapyCheckConnection( main,
2015 senders,
2016 recipients,
2017 vlanId=None,
2018 useTCP=False,
2019 packet=None,
2020 packetFilter=None,
2021 expectFailure=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002022 """
2023 Checks the connectivity between all given sender hosts and all given recipient hosts
2024 Packet may be specified. Defaults to Ether/IP packet
2025 Packet Filter may be specified. Defaults to Ether/IP from current sender MAC
2026 Todo: Optional packet and packet filter attributes for sender and recipients
2027 Expect Failure when the sender and recipient are not supposed to have connectivity
2028 Timeout of 1 second, returns main.TRUE if the filter is not triggered and kills the filter
2029
2030 """
2031 connectionsFunctional = main.TRUE
2032
2033 if not packetFilter:
2034 packetFilter = 'ether host {}'
Jeremy Songstere405d3d2016-05-17 11:18:57 -07002035 if useTCP:
2036 packetFilter += ' ip proto \\tcp tcp port {}'.format(main.params[ 'SDNIP' ][ 'dstPort' ])
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002037 if expectFailure:
2038 timeout = 1
2039 else:
2040 timeout = 10
2041
2042 for sender in senders:
2043 try:
2044 senderComp = getattr( main, sender )
2045 except AttributeError:
2046 main.log.error( "main has no attribute {}".format( sender ) )
2047 connectionsFunctional = main.FALSE
2048 continue
2049
2050 for recipient in recipients:
2051 # Do not send packets to self since recipient CLI will already be busy
2052 if recipient == sender:
2053 continue
2054 try:
2055 recipientComp = getattr( main, recipient )
2056 except AttributeError:
2057 main.log.error( "main has no attribute {}".format( recipient ) )
2058 connectionsFunctional = main.FALSE
2059 continue
2060
Jeremy Songster832f9e92016-05-05 14:30:49 -07002061 if vlanId:
2062 recipientComp.startFilter( pktFilter = ( "vlan {}".format( vlanId ) + " && " + packetFilter.format( senderComp.hostMac ) ) )
2063 else:
2064 recipientComp.startFilter( pktFilter = packetFilter.format( senderComp.hostMac ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002065
2066 if not packet:
Jeremy Songster832f9e92016-05-05 14:30:49 -07002067 if vlanId:
2068 pkt = 'Ether( src="{0}", dst="{2}" )/Dot1Q(vlan={4})/IP( src="{1}", dst="{3}" )'.format(
2069 senderComp.hostMac,
2070 senderComp.hostIp,
2071 recipientComp.hostMac,
2072 recipientComp.hostIp,
2073 vlanId )
2074 else:
2075 pkt = 'Ether( src="{0}", dst="{2}" )/IP( src="{1}", dst="{3}" )'.format(
2076 senderComp.hostMac,
2077 senderComp.hostIp,
2078 recipientComp.hostMac,
2079 recipientComp.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002080 else:
2081 pkt = packet
Jeremy Songster832f9e92016-05-05 14:30:49 -07002082 if vlanId:
2083 senderComp.sendPacket( iface=( "{0}-eth0.{1}".format( sender, vlanId ) ), packet = pkt )
2084 else:
2085 senderComp.sendPacket( packet = pkt )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002086
2087 if recipientComp.checkFilter( timeout ):
2088 if expectFailure:
2089 main.log.error( "Packet from {0} successfully received by {1} when it should not have been".format( sender , recipient ) )
2090 connectionsFunctional = main.FALSE
2091 else:
2092 main.log.info( "Packet from {0} successfully received by {1}".format( sender , recipient ) )
alison52b25892016-09-19 10:53:48 -07002093 connectionsFunctional = main.TRUE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002094 else:
2095 recipientComp.killFilter()
2096 if expectFailure:
2097 main.log.info( "As expected, packet from {0} was not received by {1}".format( sender , recipient ) )
2098 else:
2099 main.log.error( "Packet from {0} was not received by {1}".format( sender , recipient ) )
2100 connectionsFunctional = main.FALSE
2101
2102 return connectionsFunctional
2103
alison52b25892016-09-19 10:53:48 -07002104
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002105def removeAllIntents( main, intentsId ):
2106 """
2107 Remove all intents in the intentsId
2108 """
2109
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002110 onosSummary = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002111 removeIntentResult = main.TRUE
2112 # Remove intents
2113 for intent in intentsId:
2114 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
2115
acsmarscfa52272015-08-06 15:21:45 -07002116 time.sleep( main.removeIntentSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002117
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002118 # If there is remianing intents then remove intents should fail
2119 for i in range( main.numCtrls ):
2120 onosSummary.append( json.loads( main.CLIs[ i ].summary() ) )
2121
2122 for summary in onosSummary:
2123 if summary.get( 'intents' ) != 0:
2124 main.log.warn( itemName + ": There are " +
2125 str( summary.get( 'intents' ) ) +
2126 " intents remaining in node " +
2127 str( summary.get( 'node' ) ) +
2128 ", failed to remove all the intents " )
2129 removeIntentResult = main.FALSE
2130
2131 if removeIntentResult:
2132 main.log.info( itemName + ": There are no more intents remaining, " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002133 "successfully removed all the intents." )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002134
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002135 return removeIntentResult
2136
2137def checkFlowsCount( main ):
2138 """
2139 Check flows count in each node
2140 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002141 flowsCount = []
2142 main.log.info( itemName + ": Checking flows count in each ONOS node" )
2143 for i in range( main.numCtrls ):
2144 summaryResult = main.CLIs[ i ].summary()
2145 if not summaryResult:
2146 main.log.error( itemName + ": There is something wrong with " +
2147 "summary command" )
2148 return main.FALSE
2149 else:
2150 summaryJson = json.loads( summaryResult )
2151 flowsCount.append( summaryJson.get( 'flows' ) )
2152
2153 if flowsCount:
2154 if all( flows==flowsCount[ 0 ] for flows in flowsCount ):
2155 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
2156 " flows in all ONOS node" )
2157 else:
2158 for i in range( main.numCtrls ):
2159 main.log.debug( itemName + ": ONOS node " + str( i ) + " has " +
kelvin-onlab6dea6e62015-07-23 13:07:26 -07002160 str( flowsCount[ i ] ) + " flows" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002161 else:
2162 main.log.error( "Checking flows count failed, check summary command" )
2163 return main.FALSE
2164
2165 return main.TRUE
2166
kelvin-onlab58dc39e2015-08-06 08:11:09 -07002167def checkLeaderChange( leaders1, leaders2 ):
acsmarse6b410f2015-07-17 14:39:34 -07002168 """
2169 Checks for a change in intent partition leadership.
2170
2171 Takes the output of leaders -c in json string format before and after
2172 a potential change as input
2173
2174 Returns main.TRUE if no mismatches are detected
2175 Returns main.FALSE if there is a mismatch or on error loading the input
2176 """
2177 try:
2178 leaders1 = json.loads( leaders1 )
2179 leaders2 = json.loads( leaders2 )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002180 except( AttributeError, TypeError ):
acsmarse6b410f2015-07-17 14:39:34 -07002181 main.log.exception( self.name + ": Object not as expected" )
2182 return main.FALSE
2183 except Exception:
2184 main.log.exception( self.name + ": Uncaught exception!" )
2185 main.cleanup()
2186 main.exit()
2187 main.log.info( "Checking Intent Paritions for Change in Leadership" )
2188 mismatch = False
2189 for dict1 in leaders1:
2190 if "intent" in dict1.get( "topic", [] ):
2191 for dict2 in leaders2:
2192 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \
2193 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
2194 mismatch = True
2195 main.log.error( "{0} changed leader from {1} to {2}".\
2196 format( dict1.get( "topic", "no-topic" ),\
2197 dict1.get( "leader", "no-leader" ),\
2198 dict2.get( "leader", "no-leader" ) ) )
2199 if mismatch:
2200 return main.FALSE
2201 else:
2202 return main.TRUE
kelvin-onlab016dce22015-08-10 09:54:11 -07002203
2204def report( main ):
2205 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002206 Report errors/warnings/exceptions
kelvin-onlab016dce22015-08-10 09:54:11 -07002207 """
kelvin-onlab016dce22015-08-10 09:54:11 -07002208 main.ONOSbench.logReport( main.ONOSip[ 0 ],
2209 [ "INFO",
2210 "FOLLOWER",
2211 "WARN",
2212 "flow",
2213 "ERROR",
2214 "Except" ],
2215 "s" )
2216
2217 main.log.info( "ERROR report: \n" )
2218 for i in range( main.numCtrls ):
2219 main.ONOSbench.logReport( main.ONOSip[ i ],
2220 [ "ERROR" ],
2221 "d" )
2222
2223 main.log.info( "EXCEPTIONS report: \n" )
2224 for i in range( main.numCtrls ):
2225 main.ONOSbench.logReport( main.ONOSip[ i ],
2226 [ "Except" ],
2227 "d" )
2228
2229 main.log.info( "WARNING report: \n" )
2230 for i in range( main.numCtrls ):
2231 main.ONOSbench.logReport( main.ONOSip[ i ],
2232 [ "WARN" ],
2233 "d" )
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002234
2235def flowDuration( main ):
2236 """
2237 Check age of flows to see if flows are being overwritten
2238 """
2239 import time
2240 main.log.info( "Getting current flow durations" )
2241 flowsJson1 = main.CLIs[ 0 ].flows( noCore=True )
2242 try:
2243 flowsJson1 = json.loads( flowsJson1 )
2244 except ValueError:
2245 main.log.error( "Unable to read flows" )
2246 return main.FALSE
2247 flowLife = []
2248 waitFlowLife = []
2249 for device in flowsJson1:
2250 if device.get( 'flowcount', 0 ) > 0:
2251 for i in range( device[ 'flowCount' ] ):
2252 flowLife.append( device[ 'flows' ][ i ][ 'life' ] )
2253 main.log.info( "Sleeping for {} seconds".format( main.flowDurationSleep ) )
2254 time.sleep( main.flowDurationSleep )
2255 main.log.info( "Getting new flow durations" )
2256 flowsJson2 = main.CLIs[ 0 ].flows( noCore=True )
2257 try:
2258 flowsJson2 = json.loads( flowsJson2 )
2259 except ValueError:
2260 main.log.error( "Unable to read flows" )
2261 return main.FALSE
2262 for device in flowsJson2:
2263 if device.get( 'flowcount', 0 ) > 0:
2264 for i in range( device[ 'flowCount' ] ):
2265 waitFlowLife.append( device[ 'flows' ][ i ][ 'life' ] )
2266 main.log.info( "Determining whether flows where overwritten" )
2267 if len( flowLife ) == len( waitFlowLife ):
alison52b25892016-09-19 10:53:48 -07002268 for i in range( len( flowLife ) ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002269 if waitFlowLife[ i ] - flowLife[ i ] < main.flowDurationSleep:
2270 return main.FALSE
2271 else:
2272 return main.FALSE
2273 return main.TRUE
alison52b25892016-09-19 10:53:48 -07002274
2275
2276def EncapsulatedIntentCheck( main, tag="" ):
2277 """
2278 Check encapsulated intents
2279 tag: encapsulation tag (e.g. VLAN, MPLS)
2280
2281 Getting added flows
2282 Check tags on each flows
2283 If each direction has push or pop, passed
2284 else failed
2285
2286 """
2287 import json
2288 HostJson = []
2289 Jflows = main.CLIs[ 0 ].flows( noCore=True )
2290 try:
2291 Jflows = json.loads( Jflows )
2292 except ValueError:
2293 main.log.error( "Unable to read flows" )
2294 return main.FALSE
2295
2296 for flow in Jflows:
2297 if len(flow[ "flows" ]) != 0:
2298 HostJson.append( flow[ "flows" ] )
2299
2300 totalflows = len( HostJson[ 0 ])
2301
2302 pop = 0
2303 push = 0
2304
2305 PopTag = tag + "_POP"
2306 PushTag = tag + "_PUSH"
2307
2308 for EachHostJson in HostJson:
2309 for i in range( totalflows ):
2310 if EachHostJson[ i ][ "treatment" ][ "instructions" ][ 0 ][ "subtype" ] == PopTag:
2311 pop += 1
2312 elif EachHostJson[ i ][ "treatment" ][ "instructions" ][ 0 ][ "subtype" ] == PushTag:
2313 push += 1
2314
2315 if pop == totalflows and push == totalflows:
2316 return main.TRUE
2317 else:
alisonda157272016-12-22 01:13:21 -08002318 return main.FALSE
2319
2320def ProtectedIntentCheck( main ):
2321 import json
2322 intent = main.CLIs[ 0 ].intents( jsonFormat=False )
2323 if "Protection" in intent:
2324 return main.TRUE
Shreyaca8990f2017-03-16 11:43:11 -07002325 return main.FALSE