blob: f295b1186898616ef776cf468ced3fa96e9b889c [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
kelvin-onlabd48a68c2015-07-13 16:01:36 -07007import json
Jon Hallf539eb92017-05-22 17:18:42 -07008import os
kelvin-onlabd48a68c2015-07-13 16:01:36 -07009
Jon Hall78be4962017-05-23 14:53:53 -070010
kelvin-onlabd48a68c2015-07-13 16:01:36 -070011def __init__( self ):
12 self.default = ''
13
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -070014hostIntentFailFlag = False
15pointIntentFailFlag = False
16singleToMultiFailFlag = False
17multiToSingleFailFlag = False
18
Jon Hall78be4962017-05-23 14:53:53 -070019
Jeremy Songster1f39bf02016-01-20 17:17:25 -080020def installHostIntent( main,
Jeremy2f190ca2016-01-29 15:23:57 -080021 name,
22 host1,
23 host2,
24 onosNode=0,
25 ethType="",
26 bandwidth="",
27 lambdaAlloc=False,
28 ipProto="",
29 ipAddresses="",
30 tcp="",
31 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -070032 sw2="",
Jeremy Songsterc032f162016-08-04 17:14:49 -070033 setVlan="",
Jon Hallf539eb92017-05-22 17:18:42 -070034 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -070035 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -080036 Installs a Host Intent
37
kelvin-onlab58dc39e2015-08-06 08:11:09 -070038 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -080039 Install a host intent using
40 add-host-intent
41
kelvin-onlab58dc39e2015-08-06 08:11:09 -070042 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -080043 - Fetch host data if not given
44 - Add host intent
45 - Ingress device is the first sender host
46 - Egress devices are the recipient devices
47 - Ports if defined in senders or recipients
48 - MAC address ethSrc loaded from Ingress device
49 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -070050 Required:
51 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -080052 host1 - Dictionary for host1
53 { "name":"h8", "id":"of:0000000000000005/8" }
54 host2 - Dictionary for host2
55 { "name":"h16", "id":"of:0000000000000006/8" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -070056 Optional:
57 onosNode - ONOS node to install the intents in main.CLIs[ ]
58 0 by default so that it will always use the first
59 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -070060 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -070061 bandwidth - Bandwidth capacity
62 lambdaAlloc - Allocate lambda, defaults to False
63 ipProto - IP protocol
Jeremy Songster1f39bf02016-01-20 17:17:25 -080064 tcp - TCP ports in the same order as the hosts in hostNames
65 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -080066 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,
Jon Hallf539eb92017-05-22 17:18:42 -0700104 args=( main, [ intentId ] ),
Jon Hallaf95c3e2017-05-16 13:20:37 -0700105 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
Jon Hall78be4962017-05-23 14:53:53 -0700109 # Check VLAN if test encapsulation
alison52b25892016-09-19 10:53:48 -0700110 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'
Jon Hallf539eb92017-05-22 17:18:42 -0700115 if bandwidth != "":
116 allocationsFile = open( os.path.dirname( main.testFile ) + main.params[ 'DEPENDENCY' ][ 'filePath' ], 'r' )
117 expectedFormat = allocationsFile.read()
118 bandwidthCheck = checkBandwidthAllocations( main, expectedFormat )
119 allocationsFile.close()
120 if bandwidthCheck:
121 main.assertReturnString += 'Bandwidth Allocation check Passed\n'
122 else:
123 main.assertReturnString += 'Bandwidth Allocation check Failed\n'
Jon Hallc3f88af2017-05-23 11:25:54 -0700124 return main.FALSE
Jon Hallf539eb92017-05-22 17:18:42 -0700125
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700126 if flowDuration( main ):
127 main.assertReturnString += 'Flow duration check Passed\n'
128 return intentId
129 else:
Jon Hallf539eb92017-05-22 17:18:42 -0700130 main.assertReturnString += 'Flow duration check Failed\n'
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700131 return main.FALSE
alison52b25892016-09-19 10:53:48 -0700132
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800133 else:
Jeremy2f190ca2016-01-29 15:23:57 -0800134 main.log.error( "Host Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700135 hostIntentFailFlag = True
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700136 main.assertReturnString += 'Install Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800137 return main.FALSE
138
Jon Hall78be4962017-05-23 14:53:53 -0700139
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800140def testHostIntent( main,
141 name,
142 intentId,
143 host1,
144 host2,
145 onosNode=0,
146 sw1="s5",
147 sw2="s2",
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700148 expectedLink=0 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800149 """
150 Test a Host Intent
151
152 Description:
153 Test a host intent of given ID between given hosts
154
155 Steps:
156 - Fetch host data if not given
157 - Check Intent State
158 - Check Flow State
159 - Check Connectivity
160 - Check Lack of Connectivity Between Hosts not in the Intent
161 - Reroute
162 - Take Expected Link Down
163 - Check Intent State
164 - Check Flow State
165 - Check Topology
166 - Check Connectivity
167 - Bring Expected Link Up
168 - Check Intent State
169 - Check Flow State
170 - Check Topology
171 - Check Connectivity
172 - Remove Topology
173
174 Required:
175 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
176 intentId - intent ID to be tested ( and removed )
177 host1 - Dictionary for host1
178 { "name":"h8", "id":"of:0000000000000005/8" }
179 host2 - Dictionary for host2
180 { "name":"h16", "id":"of:0000000000000006/8" }
181 Optional:
182 onosNode - ONOS node to install the intents in main.CLIs[ ]
183 0 by default so that it will always use the first
184 ONOS node
185 sw1 - First switch to bring down & up for rerouting purpose
186 sw2 - Second switch to bring down & up for rerouting purpose
187 expectedLink - Expected link when the switches are down, it should
188 be two links lower than the links before the two
189 switches are down
190
191 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800192 # Parameter Validity Check
193 assert main, "There is no main variable"
194 assert host1, "You must specify host1"
195 assert host2, "You must specify host2"
196
197 global itemName
198 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800199
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700200 global hostIntentFailFlag
201
Jeremy2f190ca2016-01-29 15:23:57 -0800202 main.log.info( itemName + ": Testing Host Intent" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800203
Jeremyd9e4eb12016-04-13 12:09:06 -0700204 try:
205 if not host1.get( "id" ):
206 main.log.warn( "Id not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
207 host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800208
Jeremyd9e4eb12016-04-13 12:09:06 -0700209 if not host2.get( "id" ):
210 main.log.warn( "Id not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
211 host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800212
Jeremyd9e4eb12016-04-13 12:09:06 -0700213 senderNames = [ host1.get( "name" ), host2.get( "name" ) ]
214 recipientNames = [ host1.get( "name" ), host2.get( "name" ) ]
Jeremy Songster832f9e92016-05-05 14:30:49 -0700215 vlanId = host1.get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800216
Jeremyd9e4eb12016-04-13 12:09:06 -0700217 testResult = main.TRUE
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700218 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700219 main.log.error( "There was a problem loading the hosts data." )
220 return main.FALSE
221
222 main.log.info( itemName + ": Testing Host to Host intents" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800223
224 # Check intent state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700225 if hostIntentFailFlag:
226 attempts = 1
227 else:
228 attempts = 50
Jon Hallaf95c3e2017-05-16 13:20:37 -0700229 if utilities.retry( f=checkIntentState,
230 retValue=main.FALSE,
231 args=( main, [ intentId ] ),
232 sleep=main.checkIntentSleep,
233 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800234 main.assertReturnString += 'Initial Intent State Passed\n'
235 else:
236 main.assertReturnString += 'Initial Intent State Failed\n'
237 testResult = main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700238 attempts = 1
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800239
240 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -0700241 if utilities.retry( f=checkFlowsCount,
242 retValue=main.FALSE,
243 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -0700244 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -0700245 attempts=3 ) and utilities.retry( f=checkFlowsState,
246 retValue=main.FALSE,
247 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -0700248 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -0700249 attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800250 main.assertReturnString += 'Initial Flow State Passed\n'
251 else:
252 main.assertReturnString += 'Intial Flow State Failed\n'
253 testResult = main.FALSE
254
255 # Check Connectivity
Jon Hallaf95c3e2017-05-16 13:20:37 -0700256 if utilities.retry( f=scapyCheckConnection,
257 retValue=main.FALSE,
258 attempts=attempts,
259 sleep=main.checkConnectionSleep,
Shreyaca8990f2017-03-16 11:43:11 -0700260 args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800261 main.assertReturnString += 'Initial Ping Passed\n'
262 else:
263 main.assertReturnString += 'Initial Ping Failed\n'
264 testResult = main.FALSE
265
266 # Test rerouting if these variables exist
267 if sw1 and sw2 and expectedLink:
268 # Take link down
Jon Hallaf95c3e2017-05-16 13:20:37 -0700269 if utilities.retry( f=link,
270 retValue=main.FALSE,
271 args=( main, sw1, sw2, "down" ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800272 main.assertReturnString += 'Link Down Passed\n'
273 else:
274 main.assertReturnString += 'Link Down Failed\n'
275 testResult = main.FALSE
276
277 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700278 if utilities.retry( f=checkIntentState,
279 retValue=main.FALSE,
280 args=( main, [ intentId ] ),
281 sleep=main.checkIntentHostSleep,
282 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800283 main.assertReturnString += 'Link Down Intent State Passed\n'
284 else:
285 main.assertReturnString += 'Link Down Intent State Failed\n'
286 testResult = main.FALSE
287
288 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -0700289 if utilities.retry( f=checkFlowsCount,
290 retValue=main.FALSE,
291 args=[ main ],
292 sleep=main.checkFlowCountSleep,
293 attempts=attempts ) and utilities.retry( f=checkFlowsState,
294 retValue=main.FALSE,
295 args=[ main ],
296 sleep=main.checkFlowCountSleep,
297 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800298 main.assertReturnString += 'Link Down Flow State Passed\n'
299 else:
300 main.assertReturnString += 'Link Down Flow State Failed\n'
301 testResult = main.FALSE
302
303 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -0700304 if utilities.retry( f=checkTopology,
305 retValue=main.FALSE,
306 args=( main, expectedLink ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800307 main.assertReturnString += 'Link Down Topology State Passed\n'
308 else:
309 main.assertReturnString += 'Link Down Topology State Failed\n'
310 testResult = main.FALSE
311
312 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -0700313 if utilities.retry( f=scapyCheckConnection,
314 retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -0700315 args=( main, senderNames, recipientNames, vlanId ),
Jon Hallaf95c3e2017-05-16 13:20:37 -0700316 sleep=main.checkConnectionSleep,
317 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800318 main.assertReturnString += 'Link Down Pingall Passed\n'
319 else:
320 main.assertReturnString += 'Link Down Pingall Failed\n'
321 testResult = main.FALSE
322
323 # Bring link up
Jon Hallaf95c3e2017-05-16 13:20:37 -0700324 if utilities.retry( f=link,
325 retValue=main.FALSE,
326 args=( main, sw1, sw2, "up" ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800327 main.assertReturnString += 'Link Up Passed\n'
328 else:
329 main.assertReturnString += 'Link Up Failed\n'
330 testResult = main.FALSE
331
332 # Wait for reroute
Jon Hallf539eb92017-05-22 17:18:42 -0700333 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800334 time.sleep( main.rerouteSleep )
335
336 # Check Intents
Jon Hallaf95c3e2017-05-16 13:20:37 -0700337 if utilities.retry( f=checkIntentState,
338 retValue=main.FALSE,
339 attempts=attempts * 2,
340 args=( main, [ intentId ] ),
341 sleep=main.checkIntentSleep ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800342 main.assertReturnString += 'Link Up Intent State Passed\n'
343 else:
344 main.assertReturnString += 'Link Up Intent State Failed\n'
345 testResult = main.FALSE
346
347 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -0700348 if utilities.retry( f=checkFlowsCount,
349 retValue=main.FALSE,
350 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -0700351 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -0700352 attempts=3 ) and utilities.retry( f=checkFlowsState,
353 retValue=main.FALSE,
354 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -0700355 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -0700356 attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800357 main.assertReturnString += 'Link Up Flow State Passed\n'
358 else:
359 main.assertReturnString += 'Link Up Flow State Failed\n'
360 testResult = main.FALSE
361
362 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -0700363 if utilities.retry( f=checkTopology,
364 retValue=main.FALSE,
365 args=( main, main.numLinks ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800366 main.assertReturnString += 'Link Up Topology State Passed\n'
367 else:
368 main.assertReturnString += 'Link Up Topology State Failed\n'
369 testResult = main.FALSE
370
371 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -0700372 if utilities.retry( f=scapyCheckConnection,
373 retValue=main.FALSE,
374 args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800375 main.assertReturnString += 'Link Up Pingall Passed\n'
376 else:
377 main.assertReturnString += 'Link Up Pingall Failed\n'
378 testResult = main.FALSE
379
380 # Remove all intents
Jon Hallaf95c3e2017-05-16 13:20:37 -0700381 if utilities.retry( f=removeAllIntents,
382 retValue=main.FALSE,
383 attempts=10,
384 args=( main, [ intentId ] ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800385 main.assertReturnString += 'Remove Intents Passed'
386 else:
387 main.assertReturnString += 'Remove Intents Failed'
388 testResult = main.FALSE
389
390 return testResult
391
Jon Hall78be4962017-05-23 14:53:53 -0700392
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800393def installPointIntent( main,
394 name,
395 senders,
396 recipients,
397 onosNode=0,
398 ethType="",
399 bandwidth="",
400 lambdaAlloc=False,
alisonda157272016-12-22 01:13:21 -0800401 protected=False,
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800402 ipProto="",
403 ipSrc="",
404 ipDst="",
405 tcpSrc="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700406 tcpDst="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700407 setVlan="",
Jon Hallf539eb92017-05-22 17:18:42 -0700408 encap="" ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800409 """
410 Installs a Single to Single Point Intent
411
412 Description:
413 Install a single to single point intent
414
415 Steps:
416 - Fetch host data if not given
417 - Add point intent
418 - Ingress device is the first sender device
419 - Egress device is the first recipient device
420 - Ports if defined in senders or recipients
421 - MAC address ethSrc loaded from Ingress device
422 - Check intent state with retry
423 Required:
424 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
425 senders - List of host dictionaries i.e.
426 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
427 recipients - List of host dictionaries i.e.
428 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
429 Optional:
430 onosNode - ONOS node to install the intents in main.CLIs[ ]
431 0 by default so that it will always use the first
432 ONOS node
433 ethType - Ethernet type eg. IPV4, IPV6
434 bandwidth - Bandwidth capacity
435 lambdaAlloc - Allocate lambda, defaults to False
436 ipProto - IP protocol
437 tcp - TCP ports in the same order as the hosts in hostNames
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700438 sw1 - First switch to bring down & up for rerouting purpose
439 sw2 - Second switch to bring down & up for rerouting purpose
440 expectedLink - Expected link when the switches are down, it should
441 be two links lower than the links before the two
442 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700443 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700444 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800445 assert senders, "You must specify a sender"
446 assert recipients, "You must specify a recipient"
447 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700448
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800449 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700450 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700451
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700452 global pointIntentFailFlag
453 pointIntentFailFlag = False
454
Jeremy6f000c62016-02-25 17:02:28 -0800455 main.log.info( itemName + ": Adding point to point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700456
Jeremyd9e4eb12016-04-13 12:09:06 -0700457 try:
458 for sender in senders:
459 if not sender.get( "device" ):
460 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
461 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800462
Jeremyd9e4eb12016-04-13 12:09:06 -0700463 for recipient in recipients:
464 if not recipient.get( "device" ):
465 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
466 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800467
Jeremyd9e4eb12016-04-13 12:09:06 -0700468 ingressDevice = senders[ 0 ].get( "device" )
469 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800470
Jeremyd9e4eb12016-04-13 12:09:06 -0700471 portIngress = senders[ 0 ].get( "port", "" )
472 portEgress = recipients[ 0 ].get( "port", "" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800473
Jeremyd9e4eb12016-04-13 12:09:06 -0700474 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800475
Jeremyd9e4eb12016-04-13 12:09:06 -0700476 ipSrc = senders[ 0 ].get( "ip" )
477 ipDst = recipients[ 0 ].get( "ip" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800478
Jeremy Songster832f9e92016-05-05 14:30:49 -0700479 vlanId = senders[ 0 ].get( "vlan" )
480
Jeremyd9e4eb12016-04-13 12:09:06 -0700481 # Adding point intent
482 intentId = main.CLIs[ onosNode ].addPointIntent(
483 ingressDevice=ingressDevice,
484 egressDevice=egressDevice,
485 portIngress=portIngress,
486 portEgress=portEgress,
487 ethType=ethType,
488 ethDst=dstMac,
489 bandwidth=bandwidth,
490 lambdaAlloc=lambdaAlloc,
alisonda157272016-12-22 01:13:21 -0800491 protected=protected,
Jeremyd9e4eb12016-04-13 12:09:06 -0700492 ipProto=ipProto,
493 ipSrc=ipSrc,
494 ipDst=ipDst,
495 tcpSrc=tcpSrc,
Jeremy Songster832f9e92016-05-05 14:30:49 -0700496 tcpDst=tcpDst,
Jeremy Songsterff553672016-05-12 17:06:23 -0700497 vlanId=vlanId,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700498 setVlan=setVlan,
499 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700500 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700501 errorMsg = "There was a problem loading the hosts data."
502 if intentId:
503 errorMsg += " There was a problem installing Point to Point intent."
504 main.log.error( errorMsg )
505 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700506
507 # Check intents state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700508 if utilities.retry( f=checkIntentState,
509 retValue=main.FALSE,
Jon Hallf539eb92017-05-22 17:18:42 -0700510 args=( main, [ intentId ] ),
511 sleep=main.checkIntentSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -0700512 attempts=50 ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700513 main.assertReturnString += 'Install Intent State Passed\n'
alison52b25892016-09-19 10:53:48 -0700514
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700515 if bandwidth != "":
Jon Hallf539eb92017-05-22 17:18:42 -0700516 allocationsFile = open( os.path.dirname( main.testFile ) + main.params[ 'DEPENDENCY' ][ 'filePath' ], 'r' )
517 expectedFormat = allocationsFile.read()
518 bandwidthCheck = checkBandwidthAllocations( main, expectedFormat )
519 allocationsFile.close()
520 if bandwidthCheck:
521 main.assertReturnString += 'Bandwidth Allocation check Passed\n'
522 else:
523 main.assertReturnString += 'Bandwidth Allocation check Failed\n'
Jon Hallc3f88af2017-05-23 11:25:54 -0700524 return main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700525
alison52b25892016-09-19 10:53:48 -0700526 # Check VLAN if test encapsulation
527 if encap != "":
528 if EncapsulatedIntentCheck( main, tag=encap ):
529 main.assertReturnString += 'Encapsulation intents check Passed\n'
530 else:
531 main.assertReturnString += 'Encapsulation intents check failed\n'
alisonda157272016-12-22 01:13:21 -0800532
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700533 if flowDuration( main ):
534 main.assertReturnString += 'Flow duration check Passed\n'
535 return intentId
536 else:
537 main.assertReturnString += 'Flow duration check failed\n'
538 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -0700539 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800540 main.log.error( "Point Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700541 pointIntentFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800542 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700543
Jon Hall78be4962017-05-23 14:53:53 -0700544
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700545def pointIntentTcp( main,
546 name,
547 host1,
548 host2,
549 onosNode=0,
550 deviceId1="",
551 deviceId2="",
552 port1="",
553 port2="",
554 ethType="",
555 mac1="",
556 mac2="",
557 bandwidth="",
558 lambdaAlloc=False,
559 ipProto="",
560 ip1="",
561 ip2="",
562 tcp1="",
563 tcp2="",
564 sw1="",
565 sw2="",
566 expectedLink=0 ):
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700567 """
568 Description:
569 Verify add-point-intent only for TCP
570 Steps:
571 - Get device ids | ports
572 - Add point intents
573 - Check intents
574 - Verify flows
575 - Ping hosts
576 - Reroute
577 - Link down
578 - Verify flows
579 - Check topology
580 - Ping hosts
581 - Link up
582 - Verify flows
583 - Check topology
584 - Ping hosts
585 - Remove intents
586 Required:
587 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
588 host1 - Name of first host
589 host2 - Name of second host
590 Optional:
591 onosNode - ONOS node to install the intents in main.CLIs[ ]
592 0 by default so that it will always use the first
593 ONOS node
594 deviceId1 - ONOS device id of the first switch, the same as the
595 location of the first host eg. of:0000000000000001/1,
596 located at device 1 port 1
597 deviceId2 - ONOS device id of the second switch
598 port1 - The port number where the first host is attached
599 port2 - The port number where the second host is attached
600 ethType - Ethernet type eg. IPV4, IPV6
601 mac1 - Mac address of first host
602 mac2 - Mac address of the second host
603 bandwidth - Bandwidth capacity
604 lambdaAlloc - Allocate lambda, defaults to False
605 ipProto - IP protocol
606 ip1 - IP address of first host
607 ip2 - IP address of second host
608 tcp1 - TCP port of first host
609 tcp2 - TCP port of second host
610 sw1 - First switch to bring down & up for rerouting purpose
611 sw2 - Second switch to bring down & up for rerouting purpose
612 expectedLink - Expected link when the switches are down, it should
613 be two links lower than the links before the two
614 switches are down
615 """
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700616 assert main, "There is no main variable"
617 assert name, "variable name is empty"
618 assert host1 and host2, "You must specify hosts"
619
620 global itemName
621 itemName = name
622 host1 = host1
623 host2 = host2
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700624 intentsId = []
625
626 iperfResult = main.TRUE
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700627 linkDownResult = main.TRUE
628 linkUpResult = main.TRUE
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700629
630 # Adding bidirectional point intents
631 main.log.info( itemName + ": Adding point intents" )
632 intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
633 egressDevice=deviceId2,
634 portIngress=port1,
635 portEgress=port2,
636 ethType=ethType,
637 ethSrc=mac1,
638 ethDst=mac2,
639 bandwidth=bandwidth,
640 lambdaAlloc=lambdaAlloc,
641 ipProto=ipProto,
642 ipSrc=ip1,
643 ipDst=ip2,
644 tcpSrc=tcp1,
645 tcpDst="" )
646
647 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
648 egressDevice=deviceId1,
649 portIngress=port2,
650 portEgress=port1,
651 ethType=ethType,
652 ethSrc=mac2,
653 ethDst=mac1,
654 bandwidth=bandwidth,
655 lambdaAlloc=lambdaAlloc,
656 ipProto=ipProto,
657 ipSrc=ip2,
658 ipDst=ip1,
659 tcpSrc=tcp2,
660 tcpDst="" )
661
662 intent3 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
663 egressDevice=deviceId2,
664 portIngress=port1,
665 portEgress=port2,
666 ethType=ethType,
667 ethSrc=mac1,
668 ethDst=mac2,
669 bandwidth=bandwidth,
670 lambdaAlloc=lambdaAlloc,
671 ipProto=ipProto,
672 ipSrc=ip1,
673 ipDst=ip2,
674 tcpSrc="",
675 tcpDst=tcp2 )
676
677 intent4 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
678 egressDevice=deviceId1,
679 portIngress=port2,
680 portEgress=port1,
681 ethType=ethType,
682 ethSrc=mac2,
683 ethDst=mac1,
684 bandwidth=bandwidth,
685 lambdaAlloc=lambdaAlloc,
686 ipProto=ipProto,
687 ipSrc=ip2,
688 ipDst=ip1,
689 tcpSrc="",
690 tcpDst=tcp1 )
691 intentsId.append( intent1 )
692 intentsId.append( intent2 )
693 intentsId.append( intent3 )
694 intentsId.append( intent4 )
695
696 # Check intents state
Jon Hallf539eb92017-05-22 17:18:42 -0700697 main.log.info( "Sleeping {} seconds".format( main.checkIntentSleep ) )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700698 time.sleep( main.checkIntentSleep )
Jon Hallaf95c3e2017-05-16 13:20:37 -0700699 intentResult = utilities.retry( f=checkIntentState,
700 retValue=main.FALSE,
701 args=( main, intentsId ),
702 sleep=1,
703 attempts=50 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700704 # Check flows count in each node
705 checkFlowsCount( main )
706
707 # Check intents state again if first check fails...
708 if not intentResult:
Jon Hallaf95c3e2017-05-16 13:20:37 -0700709 intentResult = utilities.retry( f=checkIntentState,
710 retValue=main.FALSE,
711 args=( main, intentsId ),
712 sleep=1,
713 attempts=50 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700714
715 # Check flows count in each node
716 checkFlowsCount( main )
717
718 # Verify flows
719 checkFlowsState( main )
720
721 # Run iperf to both host
Jon Hall78be4962017-05-23 14:53:53 -0700722 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700723 iperfResult = iperfResult and iperfTemp
724 if iperfTemp:
725 main.assertReturnString += 'Initial Iperf Passed\n'
726 else:
727 main.assertReturnString += 'Initial Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700728
729 # Test rerouting if these variables exist
730 if sw1 and sw2 and expectedLink:
731 # link down
732 linkDownResult = link( main, sw1, sw2, "down" )
acsmarsd4862d12015-10-06 17:57:34 -0700733
734 if linkDownResult:
735 main.assertReturnString += 'Link Down Passed\n'
736 else:
737 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700738
739 # Check flows count in each node
740 checkFlowsCount( main )
741 # Verify flows
742 checkFlowsState( main )
743
744 # Check OnosTopology
745 topoResult = checkTopology( main, expectedLink )
acsmarsd4862d12015-10-06 17:57:34 -0700746 if topoResult:
747 main.assertReturnString += 'Link Down Topology State Passed\n'
748 else:
749 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700750
751 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700752 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700753 iperfResult = iperfResult and iperfTemp
754 if iperfTemp:
755 main.assertReturnString += 'Link Down Iperf Passed\n'
756 else:
757 main.assertReturnString += 'Link Down Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700758
acsmarsd4862d12015-10-06 17:57:34 -0700759 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700760 intentTemp = utilities.retry( f=checkIntentState,
761 retValue=main.FALSE,
762 args=( main, intentsId ),
763 sleep=1,
764 attempts=50 )
acsmarsd4862d12015-10-06 17:57:34 -0700765 intentResult = intentResult and intentTemp
766 if intentTemp:
767 main.assertReturnString += 'Link Down Intent State Passed\n'
768 else:
769 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700770
771 # Checks ONOS state in link down
772 if linkDownResult and topoResult and iperfResult and intentResult:
773 main.log.info( itemName + ": Successfully brought link down" )
774 else:
775 main.log.error( itemName + ": Failed to bring link down" )
776
777 # link up
778 linkUpResult = link( main, sw1, sw2, "up" )
alison52b25892016-09-19 10:53:48 -0700779 if linkUpResult:
acsmarsd4862d12015-10-06 17:57:34 -0700780 main.assertReturnString += 'Link Up Passed\n'
781 else:
782 main.assertReturnString += 'Link Up Failed\n'
783
Jon Hallf539eb92017-05-22 17:18:42 -0700784 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700785 time.sleep( main.rerouteSleep )
786
787 # Check flows count in each node
788 checkFlowsCount( main )
789 # Verify flows
790 checkFlowsState( main )
791
792 # Check OnosTopology
793 topoResult = checkTopology( main, main.numLinks )
794
acsmarsd4862d12015-10-06 17:57:34 -0700795 if topoResult:
796 main.assertReturnString += 'Link Up Topology State Passed\n'
797 else:
798 main.assertReturnString += 'Link Up Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700799
acsmarsd4862d12015-10-06 17:57:34 -0700800 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700801 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700802 iperfResult = iperfResult and iperfTemp
803 if iperfTemp:
804 main.assertReturnString += 'Link Up Iperf Passed\n'
805 else:
806 main.assertReturnString += 'Link Up Iperf Failed\n'
807
808 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700809 intentTemp = utilities.retry( f=checkIntentState,
810 retValue=main.FALSE,
811 args=( main, intentsId ),
812 sleep=1,
813 attempts=50 )
acsmarsd4862d12015-10-06 17:57:34 -0700814 intentResult = intentResult and intentTemp
815 if intentTemp:
816 main.assertReturnString += 'Link Down Intent State Passed\n'
817 else:
818 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700819
820 # Checks ONOS state in link up
821 if linkUpResult and topoResult and iperfResult and intentResult:
822 main.log.info( itemName + ": Successfully brought link back up" )
823 else:
824 main.log.error( itemName + ": Failed to bring link back up" )
825
826 # Remove all intents
827 removeIntentResult = removeAllIntents( main, intentsId )
acsmarsd4862d12015-10-06 17:57:34 -0700828 if removeIntentResult:
829 main.assertReturnString += 'Remove Intents Passed'
830 else:
831 main.assertReturnString += 'Remove Intents Failed'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700832
833 stepResult = iperfResult and linkDownResult and linkUpResult \
834 and intentResult and removeIntentResult
835
836 return stepResult
837
Jon Hall78be4962017-05-23 14:53:53 -0700838
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800839def installSingleToMultiIntent( main,
840 name,
841 senders,
842 recipients,
843 onosNode=0,
844 ethType="",
845 bandwidth="",
846 lambdaAlloc=False,
847 ipProto="",
848 ipAddresses="",
849 tcp="",
850 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700851 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -0700852 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700853 partial=False,
Jon Hallf539eb92017-05-22 17:18:42 -0700854 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700855 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800856 Installs a Single to Multi Point Intent
857
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700858 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800859 Install a single to multi point intent using
860 add-single-to-multi-intent
861
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700862 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800863 - Fetch host data if not given
864 - Add single to multi intent
865 - Ingress device is the first sender host
866 - Egress devices are the recipient devices
867 - Ports if defined in senders or recipients
868 - MAC address ethSrc loaded from Ingress device
869 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700870 Required:
871 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800872 senders - List of host dictionaries i.e.
873 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
874 recipients - List of host dictionaries i.e.
875 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700876 Optional:
877 onosNode - ONOS node to install the intents in main.CLIs[ ]
878 0 by default so that it will always use the first
879 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700880 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700881 bandwidth - Bandwidth capacity
882 lambdaAlloc - Allocate lambda, defaults to False
883 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700884 tcp - TCP ports in the same order as the hosts in hostNames
885 sw1 - First switch to bring down & up for rerouting purpose
886 sw2 - Second switch to bring down & up for rerouting purpose
887 expectedLink - Expected link when the switches are down, it should
888 be two links lower than the links before the two
889 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700890 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700891 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800892 assert senders, "You must specify a sender"
893 assert recipients, "You must specify a recipient"
894 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700895
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800896 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700897 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700898
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700899 global singleToMultiFailFlag
900 singleToMultiFailFlag = False
901
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700902 main.log.info( itemName + ": Adding single point to multi point intents" )
903
Jeremyd9e4eb12016-04-13 12:09:06 -0700904 try:
905 for sender in senders:
906 if not sender.get( "device" ):
907 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
908 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700909
Jeremyd9e4eb12016-04-13 12:09:06 -0700910 for recipient in recipients:
911 if not recipient.get( "device" ):
912 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
913 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700914
Jeremyd9e4eb12016-04-13 12:09:06 -0700915 ingressDevice = senders[ 0 ].get( "device" )
916 egressDeviceList = [ x.get( "device" ) for x in recipients if x.get( "device" ) ]
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800917
Jeremyd9e4eb12016-04-13 12:09:06 -0700918 portIngress = senders[ 0 ].get( "port", "" )
919 portEgressList = [ x.get( "port" ) for x in recipients if x.get( "port" ) ]
920 if not portEgressList:
921 portEgressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800922
Jeremyd9e4eb12016-04-13 12:09:06 -0700923 srcMac = senders[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700924 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800925
Jeremyd9e4eb12016-04-13 12:09:06 -0700926 # Adding point intent
927 intentId = main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
928 ingressDevice=ingressDevice,
929 egressDeviceList=egressDeviceList,
930 portIngress=portIngress,
931 portEgressList=portEgressList,
932 ethType=ethType,
933 ethSrc=srcMac,
934 bandwidth=bandwidth,
935 lambdaAlloc=lambdaAlloc,
936 ipProto=ipProto,
937 ipSrc="",
938 ipDst="",
939 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -0700940 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700941 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -0700942 setVlan=setVlan,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700943 partial=partial,
944 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700945 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700946 errorMsg = "There was a problem loading the hosts data."
947 if intentId:
948 errorMsg += " There was a problem installing Singlepoint to Multipoint intent."
949 main.log.error( errorMsg )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700950 singleToMultiFailFlag = True
Jeremyd9e4eb12016-04-13 12:09:06 -0700951 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700952
953 # Check intents state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700954 if singleToMultiFailFlag:
955 attempts = 5
956 else:
957 attempts = 50
958
Jon Hallaf95c3e2017-05-16 13:20:37 -0700959 if utilities.retry( f=checkIntentState,
960 retValue=main.FALSE,
Jon Hallf539eb92017-05-22 17:18:42 -0700961 args=( main, [ intentId ] ),
Jon Hallaf95c3e2017-05-16 13:20:37 -0700962 sleep=main.checkIntentSleep,
963 attempts=attempts ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700964 main.assertReturnString += 'Install Intent State Passed\n'
Jon Hallf539eb92017-05-22 17:18:42 -0700965 if bandwidth != "":
966 allocationsFile = open( os.path.dirname( main.testFile ) + main.params[ 'DEPENDENCY' ][ 'filePath' ], 'r' )
967 expectedFormat = allocationsFile.read()
968 bandwidthCheck = checkBandwidthAllocations( main, expectedFormat )
969 allocationsFile.close()
970 if bandwidthCheck:
971 main.assertReturnString += 'Bandwidth Allocation check Passed\n'
972 else:
973 main.assertReturnString += 'Bandwidth Allocation check Failed\n'
Jon Hallc3f88af2017-05-23 11:25:54 -0700974 return main.FALSE
975
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700976 if flowDuration( main ):
977 main.assertReturnString += 'Flow duration check Passed\n'
978 return intentId
979 else:
980 main.assertReturnString += 'Flow duration check failed\n'
981 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -0700982 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800983 main.log.error( "Single to Multi Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700984 singleToMultiFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800985 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700986
Jon Hall78be4962017-05-23 14:53:53 -0700987
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800988def installMultiToSingleIntent( main,
989 name,
990 senders,
991 recipients,
992 onosNode=0,
993 ethType="",
994 bandwidth="",
995 lambdaAlloc=False,
996 ipProto="",
997 ipAddresses="",
998 tcp="",
999 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -07001000 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -07001001 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -07001002 partial=False,
Jon Hallf539eb92017-05-22 17:18:42 -07001003 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001004 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001005 Installs a Multi to Single Point Intent
1006
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001007 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001008 Install a multi to single point intent using
1009 add-multi-to-single-intent
1010
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001011 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001012 - Fetch host data if not given
1013 - Add multi to single intent
1014 - Ingress devices are the senders devices
1015 - Egress device is the first recipient host
1016 - Ports if defined in senders or recipients
1017 - MAC address ethSrc loaded from Ingress device
1018 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001019 Required:
1020 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001021 senders - List of host dictionaries i.e.
1022 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
1023 recipients - List of host dictionaries i.e.
1024 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001025 Optional:
1026 onosNode - ONOS node to install the intents in main.CLIs[ ]
1027 0 by default so that it will always use the first
1028 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001029 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001030 bandwidth - Bandwidth capacity
1031 lambdaAlloc - Allocate lambda, defaults to False
1032 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001033 tcp - TCP ports in the same order as the hosts in hostNames
1034 sw1 - First switch to bring down & up for rerouting purpose
1035 sw2 - Second switch to bring down & up for rerouting purpose
1036 expectedLink - Expected link when the switches are down, it should
1037 be two links lower than the links before the two
1038 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001039 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001040 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001041 assert senders, "You must specify a sender"
1042 assert recipients, "You must specify a recipient"
1043 # Assert devices or main.hostsData, "You must specify devices"
1044
1045 global itemName # The name of this run. Used for logs.
1046 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001047
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001048 global multiToSingleFailFlag
1049 multiToSingleFailFlag = False
1050
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001051 main.log.info( itemName + ": Adding mutli to single point intents" )
1052
Jeremyd9e4eb12016-04-13 12:09:06 -07001053 try:
1054 for sender in senders:
1055 if not sender.get( "device" ):
1056 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1057 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001058
Jeremyd9e4eb12016-04-13 12:09:06 -07001059 for recipient in recipients:
1060 if not recipient.get( "device" ):
1061 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1062 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001063
Jeremyd9e4eb12016-04-13 12:09:06 -07001064 ingressDeviceList = [ x.get( "device" ) for x in senders if x.get( "device" ) ]
1065 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001066
Jeremyd9e4eb12016-04-13 12:09:06 -07001067 portIngressList = [ x.get( "port" ) for x in senders if x.get( "port" ) ]
1068 portEgress = recipients[ 0 ].get( "port", "" )
1069 if not portIngressList:
1070 portIngressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001071
Jeremyd9e4eb12016-04-13 12:09:06 -07001072 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001073 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001074
Jeremyd9e4eb12016-04-13 12:09:06 -07001075 # Adding point intent
1076 intentId = main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
1077 ingressDeviceList=ingressDeviceList,
1078 egressDevice=egressDevice,
1079 portIngressList=portIngressList,
1080 portEgress=portEgress,
1081 ethType=ethType,
1082 ethDst=dstMac,
1083 bandwidth=bandwidth,
1084 lambdaAlloc=lambdaAlloc,
1085 ipProto=ipProto,
1086 ipSrc="",
1087 ipDst="",
1088 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -07001089 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -07001090 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -07001091 setVlan=setVlan,
Jeremy Songsterc032f162016-08-04 17:14:49 -07001092 partial=partial,
1093 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001094 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001095 errorMsg = "There was a problem loading the hosts data."
1096 if intentId:
1097 errorMsg += " There was a problem installing Multipoint to Singlepoint intent."
1098 main.log.error( errorMsg )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001099 multiToSingleFailFlag = True
Jeremyd9e4eb12016-04-13 12:09:06 -07001100 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001101
1102 # Check intents state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001103 if multiToSingleFailFlag:
1104 attempts = 5
1105 else:
1106 attempts = 50
1107
Jon Hallaf95c3e2017-05-16 13:20:37 -07001108 if utilities.retry( f=checkIntentState,
1109 retValue=main.FALSE,
Jon Hallf539eb92017-05-22 17:18:42 -07001110 args=( main, [ intentId ] ),
Jon Hallaf95c3e2017-05-16 13:20:37 -07001111 sleep=main.checkIntentSleep,
1112 attempts=attempts ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001113 main.assertReturnString += 'Install Intent State Passed\n'
Jon Hallf539eb92017-05-22 17:18:42 -07001114 if bandwidth != "":
1115 allocationsFile = open( os.path.dirname( main.testFile ) + main.params[ 'DEPENDENCY' ][ 'filePath' ], 'r' )
1116 expectedFormat = allocationsFile.read()
1117 bandwidthCheck = checkBandwidthAllocations( main, expectedFormat )
1118 allocationsFile.close()
1119 if bandwidthCheck:
1120 main.assertReturnString += 'Bandwidth Allocation check Passed\n'
1121 else:
1122 main.assertReturnString += 'Bandwidth Allocation check Failed\n'
Jon Hallc3f88af2017-05-23 11:25:54 -07001123 return main.FALSE
1124
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001125 if flowDuration( main ):
1126 main.assertReturnString += 'Flow duration check Passed\n'
1127 return intentId
1128 else:
1129 main.assertReturnString += 'Flow duration check failed\n'
1130 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001131 else:
1132 main.log.error( "Multi to Single Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001133 multiToSingleFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001134 return main.FALSE
1135
Jon Hall78be4962017-05-23 14:53:53 -07001136
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001137def testPointIntent( main,
Jeremye0cb5eb2016-01-27 17:39:09 -08001138 name,
1139 intentId,
1140 senders,
1141 recipients,
1142 badSenders={},
1143 badRecipients={},
1144 onosNode=0,
1145 ethType="",
1146 bandwidth="",
1147 lambdaAlloc=False,
alisonda157272016-12-22 01:13:21 -08001148 protected=False,
Jeremye0cb5eb2016-01-27 17:39:09 -08001149 ipProto="",
1150 ipAddresses="",
1151 tcp="",
1152 sw1="s5",
1153 sw2="s2",
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001154 expectedLink=0,
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001155 useTCP=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001156 """
1157 Test a Point Intent
1158
1159 Description:
1160 Test a point intent
1161
1162 Steps:
1163 - Fetch host data if not given
1164 - Check Intent State
1165 - Check Flow State
1166 - Check Connectivity
1167 - Check Lack of Connectivity Between Hosts not in the Intent
1168 - Reroute
1169 - Take Expected Link Down
1170 - Check Intent State
1171 - Check Flow State
1172 - Check Topology
1173 - Check Connectivity
1174 - Bring Expected Link Up
1175 - Check Intent State
1176 - Check Flow State
1177 - Check Topology
1178 - Check Connectivity
1179 - Remove Topology
1180
1181 Required:
1182 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
1183
1184 senders - List of host dictionaries i.e.
1185 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
1186 recipients - List of host dictionaries i.e.
1187 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
1188 Optional:
1189 onosNode - ONOS node to install the intents in main.CLIs[ ]
1190 0 by default so that it will always use the first
1191 ONOS node
1192 ethType - Ethernet type eg. IPV4, IPV6
1193 bandwidth - Bandwidth capacity
1194 lambdaAlloc - Allocate lambda, defaults to False
1195 ipProto - IP protocol
1196 tcp - TCP ports in the same order as the hosts in hostNames
1197 sw1 - First switch to bring down & up for rerouting purpose
1198 sw2 - Second switch to bring down & up for rerouting purpose
1199 expectedLink - Expected link when the switches are down, it should
1200 be two links lower than the links before the two
1201 switches are down
1202
1203 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001204 # Parameter Validity Check
1205 assert main, "There is no main variable"
1206 assert senders, "You must specify a sender"
1207 assert recipients, "You must specify a recipient"
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001208
1209 global itemName
1210 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001211
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001212 global pointIntentFailFlag
1213 global singleToMultiFailFlag
1214 global multiToSingleFailFlag
1215
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001216 main.log.info( itemName + ": Testing Point Intent" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001217
Jeremyd9e4eb12016-04-13 12:09:06 -07001218 try:
1219 # Names for scapy
1220 senderNames = [ x.get( "name" ) for x in senders ]
1221 recipientNames = [ x.get( "name" ) for x in recipients ]
1222 badSenderNames = [ x.get( "name" ) for x in badSenders ]
1223 badRecipientNames = [ x.get( "name" ) for x in badRecipients ]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001224
Jeremyd9e4eb12016-04-13 12:09:06 -07001225 for sender in senders:
1226 if not sender.get( "device" ):
1227 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1228 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001229
Jeremyd9e4eb12016-04-13 12:09:06 -07001230 for recipient in recipients:
1231 if not recipient.get( "device" ):
1232 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1233 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001234 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001235 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001236 main.log.error( "There was a problem loading the hosts data." )
1237 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001238
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001239 testResult = main.TRUE
1240 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001241
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001242 if pointIntentFailFlag or singleToMultiFailFlag or multiToSingleFailFlag:
1243 attempts = 1
1244 else:
1245 attempts = 50
1246
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001247 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001248 if utilities.retry( f=checkIntentState,
1249 retValue=main.FALSE,
1250 args=( main, [ intentId ] ),
1251 sleep=main.checkIntentSleep,
1252 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001253 main.assertReturnString += 'Initial Intent State Passed\n'
acsmarsd4862d12015-10-06 17:57:34 -07001254 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001255 main.assertReturnString += 'Initial Intent State Failed\n'
1256 testResult = main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001257 attempts = 1
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001258
1259 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001260 if utilities.retry( f=checkFlowsCount,
1261 retValue=main.FALSE,
1262 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001263 sleep=main.checkFlowCountSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001264 attempts=attempts ) and utilities.retry( f=checkFlowsState,
1265 retValue=main.FALSE,
1266 args=[ main ],
1267 sleep=main.checkFlowCountSleep,
1268 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001269 main.assertReturnString += 'Initial Flow State Passed\n'
1270 else:
1271 main.assertReturnString += 'Intial Flow State Failed\n'
1272 testResult = main.FALSE
1273
1274 # Check Connectivity
Jon Hallaf95c3e2017-05-16 13:20:37 -07001275 if utilities.retry( f=scapyCheckConnection,
1276 retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -07001277 args=( main, senderNames, recipientNames, vlanId, useTCP ),
Jon Hallaf95c3e2017-05-16 13:20:37 -07001278 attempts=attempts,
1279 sleep=main.checkConnectionSleep ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001280 main.assertReturnString += 'Initial Ping Passed\n'
1281 else:
1282 main.assertReturnString += 'Initial Ping Failed\n'
1283 testResult = main.FALSE
1284
1285 # Check connections that shouldn't work
1286 if badSenderNames:
1287 main.log.info( "Checking that packets from incorrect sender do not go through" )
Jon Hallaf95c3e2017-05-16 13:20:37 -07001288 if utilities.retry( f=scapyCheckConnection,
1289 retValue=main.FALSE,
1290 args=( main, badSenderNames, recipientNames ),
Jon Hall78be4962017-05-23 14:53:53 -07001291 kwargs={ "expectFailure": True } ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001292 main.assertReturnString += 'Bad Sender Ping Passed\n'
1293 else:
1294 main.assertReturnString += 'Bad Sender Ping Failed\n'
1295 testResult = main.FALSE
1296
1297 if badRecipientNames:
1298 main.log.info( "Checking that packets to incorrect recipients do not go through" )
Jon Hallaf95c3e2017-05-16 13:20:37 -07001299 if utilities.retry( f=scapyCheckConnection,
1300 retValue=main.FALSE,
1301 args=( main, senderNames, badRecipientNames ),
Jon Hall78be4962017-05-23 14:53:53 -07001302 kwargs={ "expectFailure": True } ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001303 main.assertReturnString += 'Bad Recipient Ping Passed\n'
1304 else:
1305 main.assertReturnString += 'Bad Recipient Ping Failed\n'
1306 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001307
1308 # Test rerouting if these variables exist
1309 if sw1 and sw2 and expectedLink:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001310 # Take link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001311 if utilities.retry( f=link,
1312 retValue=main.FALSE,
1313 args=( main, sw1, sw2, "down" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001314 main.assertReturnString += 'Link Down Passed\n'
1315 else:
1316 main.assertReturnString += 'Link Down Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001317 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001318
alisonda157272016-12-22 01:13:21 -08001319 if protected:
1320 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001321 if utilities.retry( f=scapyCheckConnection,
1322 retValue=main.FALSE,
1323 args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
alisonda157272016-12-22 01:13:21 -08001324 main.assertReturnString += 'Link down Scapy Packet Received Passed\n'
1325 else:
1326 main.assertReturnString += 'Link down Scapy Packet Recieved Failed\n'
1327 testResult = main.FALSE
1328
1329 if ProtectedIntentCheck( main ):
1330 main.assertReturnString += 'Protected Intent Check Passed\n'
1331 else:
1332 main.assertReturnString += 'Protected Intent Check Failed\n'
1333 testResult = main.FALSE
1334
acsmarsd4862d12015-10-06 17:57:34 -07001335 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001336 if utilities.retry( f=checkIntentState,
1337 retValue=main.FALSE,
1338 args=( main, [ intentId ] ),
1339 sleep=main.checkIntentPointSleep,
1340 attempts=attempts ):
acsmarsd4862d12015-10-06 17:57:34 -07001341 main.assertReturnString += 'Link Down Intent State Passed\n'
1342 else:
1343 main.assertReturnString += 'Link Down Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001344 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001345
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001346 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001347 if utilities.retry( f=checkFlowsCount,
1348 retValue=main.FALSE,
1349 args=[ main ],
1350 sleep=main.checkFlowCountSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001351 attempts=attempts ) and utilities.retry( f=checkFlowsState,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001352 retValue=main.FALSE,
1353 args=[ main ],
1354 sleep=main.checkFlowCountSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001355 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001356 main.assertReturnString += 'Link Down Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001357 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001358 main.assertReturnString += 'Link Down Flow State Failed\n'
1359 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001360
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001361 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001362 if utilities.retry( f=checkTopology,
1363 retValue=main.FALSE,
1364 args=( main, expectedLink ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001365 main.assertReturnString += 'Link Down Topology State Passed\n'
1366 else:
1367 main.assertReturnString += 'Link Down Topology State Failed\n'
1368 testResult = main.FALSE
1369
1370 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001371 if utilities.retry( f=scapyCheckConnection,
1372 retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -07001373 args=( main, senderNames, recipientNames, vlanId, useTCP ),
Jon Hallaf95c3e2017-05-16 13:20:37 -07001374 sleep=main.checkConnectionSleep,
1375 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001376 main.assertReturnString += 'Link Down Pingall Passed\n'
1377 else:
1378 main.assertReturnString += 'Link Down Pingall Failed\n'
1379 testResult = main.FALSE
1380
1381 # Bring link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001382 if utilities.retry( f=link,
1383 retValue=main.FALSE,
1384 args=( main, sw1, sw2, "up" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001385 main.assertReturnString += 'Link Up Passed\n'
1386 else:
1387 main.assertReturnString += 'Link Up Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001388 testResult = main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -07001389
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001390 # Wait for reroute
Jon Hallf539eb92017-05-22 17:18:42 -07001391 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001392 time.sleep( main.rerouteSleep )
1393
acsmarsd4862d12015-10-06 17:57:34 -07001394 # Check Intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001395 if utilities.retry( f=checkIntentState,
1396 retValue=main.FALSE,
1397 attempts=attempts * 2,
1398 args=( main, [ intentId ] ),
Shreyaca8990f2017-03-16 11:43:11 -07001399 sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001400 main.assertReturnString += 'Link Up Intent State Passed\n'
1401 else:
1402 main.assertReturnString += 'Link Up Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001403 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001404
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001405 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001406 if utilities.retry( f=checkFlowsCount,
1407 retValue=main.FALSE,
1408 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001409 sleep=main.checkFlowCountSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001410 attempts=attempts ) and utilities.retry( f=checkFlowsState,
1411 retValue=main.FALSE,
1412 args=[ main ],
1413 sleep=main.checkFlowCountSleep,
1414 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001415 main.assertReturnString += 'Link Up Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001416 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001417 main.assertReturnString += 'Link Up Flow State Failed\n'
1418 testResult = main.FALSE
1419
1420 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001421 if utilities.retry( f=checkTopology,
1422 retValue=main.FALSE,
1423 args=( main, main.numLinks ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001424 main.assertReturnString += 'Link Up Topology State Passed\n'
1425 else:
1426 main.assertReturnString += 'Link Up Topology State Failed\n'
1427 testResult = main.FALSE
1428
1429 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001430 if utilities.retry( f=scapyCheckConnection,
1431 retValue=main.FALSE,
1432 sleep=main.checkConnectionSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001433 attempts=attempts,
Shreyaca8990f2017-03-16 11:43:11 -07001434 args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001435 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1436 else:
1437 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1438 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001439
1440 # Remove all intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001441 if utilities.retry( f=removeAllIntents,
1442 retValue=main.FALSE,
1443 attempts=10,
1444 args=( main, [ intentId ] ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001445 main.assertReturnString += 'Remove Intents Passed'
1446 else:
1447 main.assertReturnString += 'Remove Intents Failed'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001448 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001449
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001450 return testResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001451
Jon Hall78be4962017-05-23 14:53:53 -07001452
Jeremye0cb5eb2016-01-27 17:39:09 -08001453def testEndPointFail( main,
1454 name,
1455 intentId,
1456 senders,
1457 recipients,
1458 isolatedSenders,
1459 isolatedRecipients,
1460 onosNode=0,
1461 ethType="",
1462 bandwidth="",
1463 lambdaAlloc=False,
1464 ipProto="",
1465 ipAddresses="",
1466 tcp="",
1467 sw1="",
1468 sw2="",
1469 sw3="",
1470 sw4="",
1471 sw5="",
1472 expectedLink1=0,
Jeremy Songster9385d412016-06-02 17:57:36 -07001473 expectedLink2=0,
1474 partial=False ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001475 """
Shreyaca8990f2017-03-16 11:43:11 -07001476 Test Multi point to single point intent Topology for Endpoint failures
Jeremye0cb5eb2016-01-27 17:39:09 -08001477 """
Jeremye0cb5eb2016-01-27 17:39:09 -08001478 # Parameter Validity Check
1479 assert main, "There is no main variable"
1480 assert senders, "You must specify a sender"
1481 assert recipients, "You must specify a recipient"
1482
1483 global itemName
1484 itemName = name
Jeremye0cb5eb2016-01-27 17:39:09 -08001485
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001486 global singleToMultiFailFlag
1487 global multiToSingleFailFlag
1488
Jeremye0cb5eb2016-01-27 17:39:09 -08001489 main.log.info( itemName + ": Testing Point Intent" )
1490
Jeremyd9e4eb12016-04-13 12:09:06 -07001491 try:
1492 # Names for scapy
1493 senderNames = [ x.get( "name" ) for x in senders ]
1494 recipientNames = [ x.get( "name" ) for x in recipients ]
1495 isolatedSenderNames = [ x.get( "name" ) for x in isolatedSenders ]
1496 isolatedRecipientNames = [ x.get( "name" ) for x in isolatedRecipients ]
Jon Hall78be4962017-05-23 14:53:53 -07001497 connectedSenderNames = [ x.get( "name" ) for x in senders if x.get( "name" ) not in isolatedSenderNames ]
1498 connectedRecipientNames = [ x.get( "name" ) for x in recipients if x.get( "name" ) not in isolatedRecipientNames ]
Jeremye0cb5eb2016-01-27 17:39:09 -08001499
Jeremyd9e4eb12016-04-13 12:09:06 -07001500 for sender in senders:
1501 if not sender.get( "device" ):
1502 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1503 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremye0cb5eb2016-01-27 17:39:09 -08001504
Jeremyd9e4eb12016-04-13 12:09:06 -07001505 for recipient in recipients:
1506 if not recipient.get( "device" ):
Jon Hall78be4962017-05-23 14:53:53 -07001507 main.log.warn( "Device not given for recipient {0}. Loading from " +
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001508 main.hostData.format( recipient.get( "name" ) ) )
Jeremyd9e4eb12016-04-13 12:09:06 -07001509 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001510 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001511 main.log.error( "There was a problem loading the hosts data." )
1512 return main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001513
1514 testResult = main.TRUE
1515 main.log.info( itemName + ": Adding multi point to single point intents" )
1516
1517 # Check intent state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001518 if singleToMultiFailFlag or multiToSingleFailFlag:
1519 attempts = 1
1520 else:
1521 attempts = 50
1522
Jon Hallaf95c3e2017-05-16 13:20:37 -07001523 if utilities.retry( f=checkIntentState,
1524 retValue=main.FALSE,
1525 args=( main, [ intentId ] ),
1526 sleep=main.checkIntentSleep,
1527 attempts=attempts ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001528 main.assertReturnString += 'Initial Intent State Passed\n'
1529 else:
1530 main.assertReturnString += 'Initial Intent State Failed\n'
1531 testResult = main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001532 attempts = 1
Jeremye0cb5eb2016-01-27 17:39:09 -08001533
1534 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001535 if utilities.retry( f=checkFlowsCount,
1536 retValue=main.FALSE,
1537 args=[ main ],
1538 attempts=5 ) and utilities.retry( f=checkFlowsState,
1539 retValue=main.FALSE,
1540 args=[ main ],
1541 attempts=5 ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001542 main.assertReturnString += 'Initial Flow State Passed\n'
1543 else:
1544 main.assertReturnString += 'Intial Flow State Failed\n'
1545 testResult = main.FALSE
1546
1547 # Check Connectivity
Jon Hallaf95c3e2017-05-16 13:20:37 -07001548 if utilities.retry( f=scapyCheckConnection,
1549 retValue=main.FALSE,
Jeremye0cb5eb2016-01-27 17:39:09 -08001550 args=( main, senderNames, recipientNames ) ):
1551 main.assertReturnString += 'Initial Connectivity Check Passed\n'
1552 else:
1553 main.assertReturnString += 'Initial Connectivity Check Failed\n'
1554 testResult = main.FALSE
1555
1556 # Take two links down
1557 # Take first link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001558 if utilities.retry( f=link,
1559 retValue=main.FALSE,
1560 args=( main, sw1, sw2, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001561 main.assertReturnString += 'Link Down Passed\n'
1562 else:
1563 main.assertReturnString += 'Link Down Failed\n'
1564 testResult = main.FALSE
1565
1566 # Take second link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001567 if utilities.retry( f=link,
1568 retValue=main.FALSE,
1569 args=( main, sw3, sw4, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001570 main.assertReturnString += 'Link Down Passed\n'
1571 else:
1572 main.assertReturnString += 'Link Down Failed\n'
1573 testResult = main.FALSE
1574
1575 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001576 if utilities.retry( f=checkIntentState,
1577 retValue=main.FALSE,
1578 attempts=attempts,
1579 args=( main, [ intentId ] ),
1580 sleep=main.checkIntentSleep ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001581 main.assertReturnString += 'Link Down Intent State Passed\n'
1582 else:
1583 main.assertReturnString += 'Link Down Intent State Failed\n'
1584 testResult = main.FALSE
1585
1586 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001587 if utilities.retry( f=checkFlowsCount,
1588 retValue=main.FALSE,
1589 sleep=1,
1590 attempts=attempts,
Jeremye0cb5eb2016-01-27 17:39:09 -08001591 args=[ main ] ) and utilities.retry( f=checkFlowsState,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001592 retValue=main.FALSE,
1593 sleep=1,
1594 attempts=attempts,
1595 args=[ main ] ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001596 main.assertReturnString += 'Link Down Flow State Passed\n'
1597 else:
1598 main.assertReturnString += 'Link Down Flow State Failed\n'
1599 testResult = main.FALSE
1600
1601 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001602 if utilities.retry( f=checkTopology,
1603 retValue=main.FALSE,
1604 args=( main, expectedLink1 ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001605 main.assertReturnString += 'Link Down Topology State Passed\n'
1606 else:
1607 main.assertReturnString += 'Link Down Topology State Failed\n'
1608 testResult = main.FALSE
1609
1610 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001611 if utilities.retry( f=scapyCheckConnection,
1612 retValue=main.FALSE,
Jeremye0cb5eb2016-01-27 17:39:09 -08001613 args=( main, senderNames, recipientNames ) ):
1614 main.assertReturnString += 'Link Down Connectivity Check Passed\n'
1615 else:
1616 main.assertReturnString += 'Link Down Connectivity Check Failed\n'
1617 testResult = main.FALSE
1618
1619 # Take a third link down to isolate one node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001620 if utilities.retry( f=link,
1621 retValue=main.FALSE,
1622 args=( main, sw3, sw5, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001623 main.assertReturnString += 'Isolation link Down Passed\n'
1624 else:
1625 main.assertReturnString += 'Isolation link Down Failed\n'
1626 testResult = main.FALSE
1627
Jeremy Songster9385d412016-06-02 17:57:36 -07001628 if partial:
1629 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001630 if utilities.retry( f=checkIntentState,
1631 retValue=main.FALSE,
1632 args=( main, [ intentId ] ),
1633 sleep=main.checkIntentSleep,
1634 attempts=attempts ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001635 main.assertReturnString += 'Partial failure isolation link Down Intent State Passed\n'
1636 else:
1637 main.assertReturnString += 'Partial failure isolation link Down Intent State Failed\n'
1638 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001639
Jeremy Songster9385d412016-06-02 17:57:36 -07001640 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001641 if utilities.retry( f=checkFlowsCount,
1642 retValue=main.FALSE,
1643 args=[ main ],
1644 attempts=5 ) and utilities.retry( f=checkFlowsState,
1645 retValue=main.FALSE,
1646 args=[ main ],
1647 attempts=5 ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001648 main.assertReturnString += 'Partial failure isolation link Down Flow State Passed\n'
1649 else:
1650 main.assertReturnString += 'Partial failure isolation link Down Flow State Failed\n'
1651 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001652
Jeremy Songster9385d412016-06-02 17:57:36 -07001653 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001654 if utilities.retry( f=checkTopology,
1655 retValue=main.FALSE,
1656 args=( main, expectedLink2 ) ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001657 main.assertReturnString += 'Partial failure isolation link Down Topology State Passed\n'
1658 else:
1659 main.assertReturnString += 'Partial failure isolation link Down Topology State Failed\n'
1660 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001661
Jeremy Songster9385d412016-06-02 17:57:36 -07001662 # Check Connectivity
1663 # First check connectivity of any isolated senders to recipients
1664 if isolatedSenderNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001665 if scapyCheckConnection( main,
1666 isolatedSenderNames,
1667 recipientNames,
1668 None,
1669 None,
1670 None,
1671 None,
1672 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001673 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1674 else:
1675 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1676 testResult = main.FALSE
1677
1678 # Next check connectivity of senders to any isolated recipients
1679 if isolatedRecipientNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001680 if scapyCheckConnection( main,
1681 senderNames,
1682 isolatedRecipientNames,
1683 None,
1684 None,
1685 None,
1686 None,
1687 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001688 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1689 else:
1690 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1691 testResult = main.FALSE
1692
1693 # Next check connectivity of connected senders and recipients
Jon Hallaf95c3e2017-05-16 13:20:37 -07001694 if utilities.retry( f=scapyCheckConnection,
1695 retValue=main.FALSE,
1696 attempts=attempts,
Jon Hall78be4962017-05-23 14:53:53 -07001697 args=( main, connectedSenderNames, connectedRecipientNames ) ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001698 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1699 else:
1700 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1701 testResult = main.FALSE
1702 else:
1703 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001704 if not utilities.retry( f=checkIntentState,
1705 retValue=main.TRUE,
1706 args=( main, [ intentId ] ),
1707 sleep=main.checkIntentSleep,
1708 attempts=attempts ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001709 main.assertReturnString += 'Isolation link Down Intent State Passed\n'
1710 else:
1711 main.assertReturnString += 'Isolation link Down Intent State Failed\n'
1712 testResult = main.FALSE
1713
1714 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001715 if utilities.retry( f=checkFlowsCount,
1716 retValue=main.FALSE,
1717 args=[ main ],
1718 attempts=5 ) and utilities.retry( f=checkFlowsState,
1719 retValue=main.FALSE,
1720 args=[ main ],
1721 attempts=5 ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001722 main.assertReturnString += 'Isolation link Down Flow State Passed\n'
1723 else:
1724 main.assertReturnString += 'Isolation link Down Flow State Failed\n'
1725 testResult = main.FALSE
1726
1727 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001728 if utilities.retry( f=checkTopology,
1729 retValue=main.FALSE,
1730 args=( main, expectedLink2 ) ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001731 main.assertReturnString += 'Isolation link Down Topology State Passed\n'
1732 else:
1733 main.assertReturnString += 'Isolation link Down Topology State Failed\n'
1734 testResult = main.FALSE
1735
1736 # Check Connectivity
1737 # First check connectivity of any isolated senders to recipients
1738 if isolatedSenderNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001739 if scapyCheckConnection( main,
1740 isolatedSenderNames,
1741 recipientNames,
1742 None,
1743 None,
1744 None,
1745 None,
1746 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001747 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1748 else:
1749 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1750 testResult = main.FALSE
1751
1752 # Next check connectivity of senders to any isolated recipients
1753 if isolatedRecipientNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001754 if scapyCheckConnection( main,
1755 senderNames,
1756 isolatedRecipientNames,
1757 None,
1758 None,
1759 None,
1760 None,
1761 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001762 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1763 else:
1764 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1765 testResult = main.FALSE
1766
1767 # Next check connectivity of connected senders and recipients
Jon Hallaf95c3e2017-05-16 13:20:37 -07001768 if utilities.retry( f=scapyCheckConnection,
1769 retValue=main.TRUE,
1770 args=( main, connectedSenderNames, connectedRecipientNames, None, None, None, None, main.TRUE ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001771 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1772 else:
1773 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1774 testResult = main.FALSE
1775
Jeremye0cb5eb2016-01-27 17:39:09 -08001776 # Bring the links back up
1777 # Bring first link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001778 if utilities.retry( f=link,
1779 retValue=main.FALSE,
1780 args=( main, sw1, sw2, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001781 main.assertReturnString += 'Link Up Passed\n'
1782 else:
1783 main.assertReturnString += 'Link Up Failed\n'
1784 testResult = main.FALSE
1785
1786 # Bring second link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001787 if utilities.retry( f=link,
1788 retValue=main.FALSE,
1789 args=( main, sw3, sw5, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001790 main.assertReturnString += 'Link Up Passed\n'
1791 else:
1792 main.assertReturnString += 'Link Up Failed\n'
1793 testResult = main.FALSE
1794
1795 # Bring third link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001796 if utilities.retry( f=link,
1797 retValue=main.FALSE,
1798 args=( main, sw3, sw4, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001799 main.assertReturnString += 'Link Up Passed\n'
1800 else:
1801 main.assertReturnString += 'Link Up Failed\n'
1802 testResult = main.FALSE
1803
1804 # Wait for reroute
Jon Hallf539eb92017-05-22 17:18:42 -07001805 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
Jeremye0cb5eb2016-01-27 17:39:09 -08001806 time.sleep( main.rerouteSleep )
1807
1808 # Check Intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001809 if utilities.retry( f=checkIntentState,
1810 retValue=main.FALSE,
1811 attempts=attempts,
1812 args=( main, [ intentId ] ),
1813 sleep=main.checkIntentHostSleep ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001814 main.assertReturnString += 'Link Up Intent State Passed\n'
1815 else:
1816 main.assertReturnString += 'Link Up Intent State Failed\n'
1817 testResult = main.FALSE
1818
1819 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001820 if utilities.retry( f=checkFlowsCount,
1821 retValue=main.FALSE,
1822 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001823 sleep=main.checkFlowCountSleep,
1824 attempts=attempts ) and utilities.retry( f=checkFlowsState,
Jon Hall78be4962017-05-23 14:53:53 -07001825 retValue=main.FALSE,
1826 args=[ main ],
1827 sleep=main.checkFlowCountSleep,
1828 attempts=attempts ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001829 main.assertReturnString += 'Link Up Flow State Passed\n'
1830 else:
1831 main.assertReturnString += 'Link Up Flow State Failed\n'
1832 testResult = main.FALSE
1833
1834 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001835 if utilities.retry( f=checkTopology,
1836 retValue=main.FALSE,
1837 args=( main, main.numLinks ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001838 main.assertReturnString += 'Link Up Topology State Passed\n'
1839 else:
1840 main.assertReturnString += 'Link Up Topology State Failed\n'
1841 testResult = main.FALSE
1842
1843 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001844 if utilities.retry( f=scapyCheckConnection,
1845 retValue=main.FALSE,
1846 sleep=main.checkConnectionSleep,
1847 attempts=attempts,
Jeremye0cb5eb2016-01-27 17:39:09 -08001848 args=( main, senderNames, recipientNames ) ):
1849 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1850 else:
1851 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1852 testResult = main.FALSE
1853
1854 # Remove all intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001855 if utilities.retry( f=removeAllIntents,
1856 retValue=main.FALSE,
1857 attempts=10,
1858 args=( main, [ intentId ] ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001859 main.assertReturnString += 'Remove Intents Passed'
1860 else:
1861 main.assertReturnString += 'Remove Intents Failed'
1862 testResult = main.FALSE
1863
1864 return testResult
1865
1866
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001867def pingallHosts( main, hostList ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001868 """
1869 Ping all host in the hosts list variable
1870 """
Jon Halla5cb3412015-08-18 14:08:22 -07001871 main.log.info( "Pinging: " + str( hostList ) )
1872 return main.Mininet1.pingallHosts( hostList )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001873
Jon Hall78be4962017-05-23 14:53:53 -07001874
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001875def fwdPingall( main ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001876 """
1877 Use fwd app and pingall to discover all the hosts
1878 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001879 appCheck = main.TRUE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001880 main.log.info( "Activating reactive forwarding app " )
1881 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001882
1883 # Wait for forward app activation to propagate
Jon Hallf539eb92017-05-22 17:18:42 -07001884 main.log.info( "Sleeping {} seconds".format( main.fwdSleep ) )
kelvin-onlab0ad05d12015-07-23 14:21:15 -07001885 time.sleep( main.fwdSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001886
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001887 # Check that forwarding is enabled on all nodes
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001888 for i in range( main.numCtrls ):
1889 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
1890 if appCheck != main.TRUE:
1891 main.log.warn( main.CLIs[ i ].apps() )
1892 main.log.warn( main.CLIs[ i ].appIDs() )
1893
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001894 # Send pingall in mininet
1895 main.log.info( "Run Pingall" )
Jon Hall78be4962017-05-23 14:53:53 -07001896 pingResult = main.Mininet1.pingall( timeout=600 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001897
1898 main.log.info( "Deactivating reactive forwarding app " )
1899 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001900 if activateResult and deactivateResult:
1901 main.log.info( "Successfully used fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001902 getDataResult = main.TRUE
1903 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001904 main.log.info( "Failed to use fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001905 getDataResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001906 return getDataResult
1907
Jon Hall78be4962017-05-23 14:53:53 -07001908
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001909def confirmHostDiscovery( main ):
1910 """
1911 Confirms that all ONOS nodes have discovered all scapy hosts
1912 """
1913 import collections
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001914 hosts = main.topo.getAllHosts( main ) # Get host data from each ONOS node
1915 hostFails = [] # Reset for each failed attempt
1916
1917 # Check for matching hosts on each node
1918 scapyHostIPs = [ x.hostIp for x in main.scapyHosts if x.hostIp != "0.0.0.0" ]
1919 for controller in range( main.numCtrls ):
1920 controllerStr = str( controller + 1 ) # ONOS node number
1921 # Compare Hosts
1922 # Load hosts data for controller node
Jeremyd9e4eb12016-04-13 12:09:06 -07001923 try:
1924 if hosts[ controller ]:
1925 main.log.info( "Hosts discovered" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001926 else:
Jeremyd9e4eb12016-04-13 12:09:06 -07001927 main.log.error( "Problem discovering hosts" )
1928 if hosts[ controller ] and "Error" not in hosts[ controller ]:
1929 try:
1930 hostData = json.loads( hosts[ controller ] )
1931 except ( TypeError, ValueError ):
1932 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001933 hostFails.append( controllerStr )
Jeremyd9e4eb12016-04-13 12:09:06 -07001934 else:
1935 onosHostIPs = [ x.get( "ipAddresses" )[ 0 ]
1936 for x in hostData
1937 if len( x.get( "ipAddresses" ) ) > 0 ]
Jon Hall78be4962017-05-23 14:53:53 -07001938 if not set( collections.Counter( scapyHostIPs ) ).issubset(
1939 set( collections.Counter( onosHostIPs ) ) ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001940 main.log.warn( "Controller {0} only sees nodes with {1} IPs. It should see all of the following: {2}".format( controllerStr, onosHostIPs, scapyHostIPs ) )
1941 hostFails.append( controllerStr )
1942 else:
1943 main.log.error( "Hosts returned nothing or an error." )
1944 hostFails.append( controllerStr )
1945 except IndexError:
1946 main.log.error( "Hosts returned nothing, Failed to discover hosts." )
1947 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001948
1949 if hostFails:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001950 main.log.error( "List of failed ONOS Nodes:" + ', '.join( map( str, hostFails ) ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001951 return main.FALSE
1952 else:
1953 return main.TRUE
1954
Jon Hall78be4962017-05-23 14:53:53 -07001955
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001956def sendDiscoveryArp( main, hosts=None ):
1957 """
1958 Sends Discovery ARP packets from each host provided
1959 Defaults to each host in main.scapyHosts
1960 """
1961 # Send an arp ping from each host
1962 if not hosts:
1963 hosts = main.scapyHosts
1964 for host in hosts:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001965 pkt = 'Ether( src="{0}")/ARP( psrc="{1}")'.format( host.hostMac, host.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001966 # Send from the VLAN interface if there is one so ONOS discovers the VLAN correctly
1967 iface = None
1968 for interface in host.getIfList():
1969 if '.' in interface:
1970 main.log.debug( "Detected VLAN interface {0}. Sending ARP packet from {0}".format( interface ) )
1971 iface = interface
1972 break
1973 host.sendPacket( packet=pkt, iface=iface )
1974 main.log.info( "Sending ARP packet from {0}".format( host.name ) )
1975
Jon Hall78be4962017-05-23 14:53:53 -07001976
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001977def populateHostData( main ):
1978 """
1979 Populates hostsData
1980 """
1981 import json
1982 try:
1983 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
1984 hosts = main.Mininet1.getHosts().keys()
1985 # TODO: Make better use of new getHosts function
1986 for host in hosts:
1987 main.hostsData[ host ] = {}
1988 main.hostsData[ host ][ 'mac' ] = \
1989 main.Mininet1.getMacAddress( host ).upper()
1990 for hostj in hostsJson:
1991 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
1992 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
1993 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
1994 main.hostsData[ host ][ 'location' ] = \
1995 hostj[ 'location' ][ 'elementId' ] + '/' + \
1996 hostj[ 'location' ][ 'port' ]
1997 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
1998 return main.TRUE
Jeremyd9e4eb12016-04-13 12:09:06 -07001999 except ValueError:
2000 main.log.error( "ValueError while populating hostsData" )
2001 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002002 except KeyError:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002003 main.log.error( "KeyError while populating hostsData" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002004 return main.FALSE
Jeremyd9e4eb12016-04-13 12:09:06 -07002005 except IndexError:
2006 main.log.error( "IndexError while populating hostsData" )
2007 return main.FALSE
2008 except TypeError:
2009 main.log.error( "TypeError while populating hostsData" )
2010 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002011
Jon Hall78be4962017-05-23 14:53:53 -07002012
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002013def checkTopology( main, expectedLink ):
2014 statusResult = main.TRUE
2015 # Check onos topology
2016 main.log.info( itemName + ": Checking ONOS topology " )
2017
2018 for i in range( main.numCtrls ):
Flavio Castro82ee2f62016-06-07 15:04:12 -07002019 statusResult = main.CLIs[ i ].checkStatus( main.numSwitch,
Jon Hallaf95c3e2017-05-16 13:20:37 -07002020 expectedLink ) and statusResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002021 if not statusResult:
2022 main.log.error( itemName + ": Topology mismatch" )
2023 else:
2024 main.log.info( itemName + ": Topology match" )
2025 return statusResult
2026
Jon Hall78be4962017-05-23 14:53:53 -07002027
Jon Hallf539eb92017-05-22 17:18:42 -07002028def checkIntentState( main, intentsId ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002029 """
2030 This function will check intent state to make sure all the intents
2031 are in INSTALLED state
Jon Hallf539eb92017-05-22 17:18:42 -07002032 Returns main.TRUE or main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002033 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002034 intentResult = main.TRUE
Jon Hallf539eb92017-05-22 17:18:42 -07002035 stateCheckResults = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002036 for i in range( main.numCtrls ):
Jon Hallf539eb92017-05-22 17:18:42 -07002037 output = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
2038 stateCheckResults.append( output )
2039 if all( result == main.TRUE for result in stateCheckResults ):
2040 main.log.info( itemName + ": Intents state check passed" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002041 else:
Jon Hallf539eb92017-05-22 17:18:42 -07002042 main.log.warn( "Intents state check failed" )
Shreyaca8990f2017-03-16 11:43:11 -07002043 intentResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002044 return intentResult
2045
Jon Hall78be4962017-05-23 14:53:53 -07002046
Jon Hallf539eb92017-05-22 17:18:42 -07002047def checkBandwidthAllocations( main, bandwidth ):
2048 """
2049 Compare the given bandwith allocation output to the cli output on each node
2050 Returns main.TRUE or main.FALSE
2051 """
2052 bandwidthResults = []
2053 for i in range( main.numCtrls ):
2054 output = main.CLIs[ i ].compareBandwidthAllocations( bandwidth )
2055 bandwidthResults.append( output )
2056 if all( result == main.TRUE for result in bandwidthResults ):
2057 main.log.info( itemName + ": bandwidth check passed" )
2058 bandwidthResult = main.TRUE
2059 else:
2060 main.log.warn( itemName + ": bandwidth check failed" )
2061 bandwidthResult = main.FALSE
2062 return bandwidthResult
2063
Jon Hall78be4962017-05-23 14:53:53 -07002064
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002065def checkFlowsState( main ):
2066
2067 main.log.info( itemName + ": Check flows state" )
Jeremy Songsterff553672016-05-12 17:06:23 -07002068 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState( isPENDING=False )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002069 return checkFlowsResult
2070
Jon Hall78be4962017-05-23 14:53:53 -07002071
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002072def link( main, sw1, sw2, option ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002073
2074 # link down
alison52b25892016-09-19 10:53:48 -07002075 main.log.info( itemName + ": Bring link " + option + " between " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002076 sw1 + " and " + sw2 )
2077 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
2078 return linkResult
2079
Jon Hall78be4962017-05-23 14:53:53 -07002080
Jon Hallaf95c3e2017-05-16 13:20:37 -07002081def scapyCheckConnection( main,
2082 senders,
2083 recipients,
2084 vlanId=None,
2085 useTCP=False,
2086 packet=None,
2087 packetFilter=None,
2088 expectFailure=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002089 """
2090 Checks the connectivity between all given sender hosts and all given recipient hosts
2091 Packet may be specified. Defaults to Ether/IP packet
2092 Packet Filter may be specified. Defaults to Ether/IP from current sender MAC
2093 Todo: Optional packet and packet filter attributes for sender and recipients
2094 Expect Failure when the sender and recipient are not supposed to have connectivity
2095 Timeout of 1 second, returns main.TRUE if the filter is not triggered and kills the filter
2096
2097 """
2098 connectionsFunctional = main.TRUE
2099
2100 if not packetFilter:
2101 packetFilter = 'ether host {}'
Jeremy Songstere405d3d2016-05-17 11:18:57 -07002102 if useTCP:
Jon Hall78be4962017-05-23 14:53:53 -07002103 packetFilter += ' ip proto \\tcp tcp port {}'.format( main.params[ 'SDNIP' ][ 'dstPort' ] )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002104 if expectFailure:
2105 timeout = 1
2106 else:
2107 timeout = 10
2108
2109 for sender in senders:
2110 try:
2111 senderComp = getattr( main, sender )
2112 except AttributeError:
2113 main.log.error( "main has no attribute {}".format( sender ) )
2114 connectionsFunctional = main.FALSE
2115 continue
2116
2117 for recipient in recipients:
2118 # Do not send packets to self since recipient CLI will already be busy
2119 if recipient == sender:
2120 continue
2121 try:
2122 recipientComp = getattr( main, recipient )
2123 except AttributeError:
2124 main.log.error( "main has no attribute {}".format( recipient ) )
2125 connectionsFunctional = main.FALSE
2126 continue
2127
Jeremy Songster832f9e92016-05-05 14:30:49 -07002128 if vlanId:
Jon Hall78be4962017-05-23 14:53:53 -07002129 recipientComp.startFilter( pktFilter=( "vlan {}".format( vlanId ) + " && " + packetFilter.format( senderComp.hostMac ) ) )
Jeremy Songster832f9e92016-05-05 14:30:49 -07002130 else:
Jon Hall78be4962017-05-23 14:53:53 -07002131 recipientComp.startFilter( pktFilter=packetFilter.format( senderComp.hostMac ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002132
2133 if not packet:
Jeremy Songster832f9e92016-05-05 14:30:49 -07002134 if vlanId:
2135 pkt = 'Ether( src="{0}", dst="{2}" )/Dot1Q(vlan={4})/IP( src="{1}", dst="{3}" )'.format(
2136 senderComp.hostMac,
2137 senderComp.hostIp,
2138 recipientComp.hostMac,
2139 recipientComp.hostIp,
2140 vlanId )
2141 else:
2142 pkt = 'Ether( src="{0}", dst="{2}" )/IP( src="{1}", dst="{3}" )'.format(
2143 senderComp.hostMac,
2144 senderComp.hostIp,
2145 recipientComp.hostMac,
2146 recipientComp.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002147 else:
2148 pkt = packet
Jeremy Songster832f9e92016-05-05 14:30:49 -07002149 if vlanId:
2150 senderComp.sendPacket( iface=( "{0}-eth0.{1}".format( sender, vlanId ) ), packet = pkt )
2151 else:
Jon Hall78be4962017-05-23 14:53:53 -07002152 senderComp.sendPacket( packet=pkt )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002153
2154 if recipientComp.checkFilter( timeout ):
2155 if expectFailure:
Jon Hall78be4962017-05-23 14:53:53 -07002156 main.log.error( "Packet from {0} successfully received by {1} when it should not have been".format( sender, recipient ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002157 connectionsFunctional = main.FALSE
2158 else:
Jon Hall78be4962017-05-23 14:53:53 -07002159 main.log.info( "Packet from {0} successfully received by {1}".format( sender, recipient ) )
alison52b25892016-09-19 10:53:48 -07002160 connectionsFunctional = main.TRUE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002161 else:
2162 recipientComp.killFilter()
2163 if expectFailure:
Jon Hall78be4962017-05-23 14:53:53 -07002164 main.log.info( "As expected, packet from {0} was not received by {1}".format( sender, recipient ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002165 else:
Jon Hall78be4962017-05-23 14:53:53 -07002166 main.log.error( "Packet from {0} was not received by {1}".format( sender, recipient ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002167 connectionsFunctional = main.FALSE
2168
2169 return connectionsFunctional
2170
alison52b25892016-09-19 10:53:48 -07002171
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002172def removeAllIntents( main, intentsId ):
2173 """
2174 Remove all intents in the intentsId
2175 """
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002176 onosSummary = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002177 removeIntentResult = main.TRUE
2178 # Remove intents
2179 for intent in intentsId:
2180 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
2181
Jon Hallf539eb92017-05-22 17:18:42 -07002182 main.log.info( "Sleeping {} seconds".format( main.removeIntentSleep ) )
acsmarscfa52272015-08-06 15:21:45 -07002183 time.sleep( main.removeIntentSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002184
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002185 # If there is remianing intents then remove intents should fail
2186 for i in range( main.numCtrls ):
2187 onosSummary.append( json.loads( main.CLIs[ i ].summary() ) )
2188
2189 for summary in onosSummary:
2190 if summary.get( 'intents' ) != 0:
2191 main.log.warn( itemName + ": There are " +
2192 str( summary.get( 'intents' ) ) +
2193 " intents remaining in node " +
2194 str( summary.get( 'node' ) ) +
2195 ", failed to remove all the intents " )
2196 removeIntentResult = main.FALSE
2197
2198 if removeIntentResult:
2199 main.log.info( itemName + ": There are no more intents remaining, " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002200 "successfully removed all the intents." )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002201
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002202 return removeIntentResult
2203
Jon Hall78be4962017-05-23 14:53:53 -07002204
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002205def checkFlowsCount( main ):
2206 """
2207 Check flows count in each node
2208 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002209 flowsCount = []
2210 main.log.info( itemName + ": Checking flows count in each ONOS node" )
2211 for i in range( main.numCtrls ):
2212 summaryResult = main.CLIs[ i ].summary()
2213 if not summaryResult:
2214 main.log.error( itemName + ": There is something wrong with " +
2215 "summary command" )
2216 return main.FALSE
2217 else:
2218 summaryJson = json.loads( summaryResult )
2219 flowsCount.append( summaryJson.get( 'flows' ) )
2220
2221 if flowsCount:
Jon Hall78be4962017-05-23 14:53:53 -07002222 if all( flows == flowsCount[ 0 ] for flows in flowsCount ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002223 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
2224 " flows in all ONOS node" )
2225 else:
2226 for i in range( main.numCtrls ):
2227 main.log.debug( itemName + ": ONOS node " + str( i ) + " has " +
kelvin-onlab6dea6e62015-07-23 13:07:26 -07002228 str( flowsCount[ i ] ) + " flows" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002229 else:
2230 main.log.error( "Checking flows count failed, check summary command" )
2231 return main.FALSE
2232
2233 return main.TRUE
2234
Jon Hall78be4962017-05-23 14:53:53 -07002235
kelvin-onlab58dc39e2015-08-06 08:11:09 -07002236def checkLeaderChange( leaders1, leaders2 ):
acsmarse6b410f2015-07-17 14:39:34 -07002237 """
2238 Checks for a change in intent partition leadership.
2239
2240 Takes the output of leaders -c in json string format before and after
2241 a potential change as input
2242
2243 Returns main.TRUE if no mismatches are detected
2244 Returns main.FALSE if there is a mismatch or on error loading the input
2245 """
2246 try:
2247 leaders1 = json.loads( leaders1 )
2248 leaders2 = json.loads( leaders2 )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002249 except( AttributeError, TypeError ):
Jon Halld970abf2017-05-23 10:20:28 -07002250 main.log.exception( "checkLeaderChange: Object not as expected" )
acsmarse6b410f2015-07-17 14:39:34 -07002251 return main.FALSE
2252 except Exception:
Jon Halld970abf2017-05-23 10:20:28 -07002253 main.log.exception( "checkLeaderChange: Uncaught exception!" )
acsmarse6b410f2015-07-17 14:39:34 -07002254 main.cleanup()
2255 main.exit()
2256 main.log.info( "Checking Intent Paritions for Change in Leadership" )
2257 mismatch = False
2258 for dict1 in leaders1:
2259 if "intent" in dict1.get( "topic", [] ):
2260 for dict2 in leaders2:
Jon Hall78be4962017-05-23 14:53:53 -07002261 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and\
2262 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
acsmarse6b410f2015-07-17 14:39:34 -07002263 mismatch = True
Jon Hall78be4962017-05-23 14:53:53 -07002264 main.log.error( "%s changed leader from %s to %s",
2265 dict1.get( "topic", "no-topic" ),
2266 dict1.get( "leader", "no-leader" ),
2267 dict2.get( "leader", "no-leader" ) )
acsmarse6b410f2015-07-17 14:39:34 -07002268 if mismatch:
2269 return main.FALSE
2270 else:
2271 return main.TRUE
kelvin-onlab016dce22015-08-10 09:54:11 -07002272
Jon Hall78be4962017-05-23 14:53:53 -07002273
kelvin-onlab016dce22015-08-10 09:54:11 -07002274def report( main ):
2275 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002276 Report errors/warnings/exceptions
kelvin-onlab016dce22015-08-10 09:54:11 -07002277 """
kelvin-onlab016dce22015-08-10 09:54:11 -07002278 main.ONOSbench.logReport( main.ONOSip[ 0 ],
2279 [ "INFO",
2280 "FOLLOWER",
2281 "WARN",
2282 "flow",
2283 "ERROR",
2284 "Except" ],
2285 "s" )
2286
2287 main.log.info( "ERROR report: \n" )
2288 for i in range( main.numCtrls ):
2289 main.ONOSbench.logReport( main.ONOSip[ i ],
Jon Hall78be4962017-05-23 14:53:53 -07002290 [ "ERROR" ],
2291 "d" )
kelvin-onlab016dce22015-08-10 09:54:11 -07002292
2293 main.log.info( "EXCEPTIONS report: \n" )
2294 for i in range( main.numCtrls ):
2295 main.ONOSbench.logReport( main.ONOSip[ i ],
Jon Hall78be4962017-05-23 14:53:53 -07002296 [ "Except" ],
2297 "d" )
kelvin-onlab016dce22015-08-10 09:54:11 -07002298
2299 main.log.info( "WARNING report: \n" )
2300 for i in range( main.numCtrls ):
2301 main.ONOSbench.logReport( main.ONOSip[ i ],
Jon Hall78be4962017-05-23 14:53:53 -07002302 [ "WARN" ],
2303 "d" )
2304
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002305
2306def flowDuration( main ):
2307 """
2308 Check age of flows to see if flows are being overwritten
2309 """
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002310 main.log.info( "Getting current flow durations" )
2311 flowsJson1 = main.CLIs[ 0 ].flows( noCore=True )
2312 try:
2313 flowsJson1 = json.loads( flowsJson1 )
2314 except ValueError:
2315 main.log.error( "Unable to read flows" )
2316 return main.FALSE
2317 flowLife = []
2318 waitFlowLife = []
2319 for device in flowsJson1:
2320 if device.get( 'flowcount', 0 ) > 0:
2321 for i in range( device[ 'flowCount' ] ):
2322 flowLife.append( device[ 'flows' ][ i ][ 'life' ] )
2323 main.log.info( "Sleeping for {} seconds".format( main.flowDurationSleep ) )
2324 time.sleep( main.flowDurationSleep )
2325 main.log.info( "Getting new flow durations" )
2326 flowsJson2 = main.CLIs[ 0 ].flows( noCore=True )
2327 try:
2328 flowsJson2 = json.loads( flowsJson2 )
2329 except ValueError:
2330 main.log.error( "Unable to read flows" )
2331 return main.FALSE
2332 for device in flowsJson2:
2333 if device.get( 'flowcount', 0 ) > 0:
2334 for i in range( device[ 'flowCount' ] ):
2335 waitFlowLife.append( device[ 'flows' ][ i ][ 'life' ] )
2336 main.log.info( "Determining whether flows where overwritten" )
2337 if len( flowLife ) == len( waitFlowLife ):
alison52b25892016-09-19 10:53:48 -07002338 for i in range( len( flowLife ) ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002339 if waitFlowLife[ i ] - flowLife[ i ] < main.flowDurationSleep:
2340 return main.FALSE
2341 else:
2342 return main.FALSE
2343 return main.TRUE
alison52b25892016-09-19 10:53:48 -07002344
2345
2346def EncapsulatedIntentCheck( main, tag="" ):
2347 """
2348 Check encapsulated intents
Jon Hall78be4962017-05-23 14:53:53 -07002349 tag: encapsulation tag ( e.g. VLAN, MPLS )
alison52b25892016-09-19 10:53:48 -07002350
2351 Getting added flows
2352 Check tags on each flows
2353 If each direction has push or pop, passed
2354 else failed
2355
2356 """
alison52b25892016-09-19 10:53:48 -07002357 HostJson = []
2358 Jflows = main.CLIs[ 0 ].flows( noCore=True )
2359 try:
2360 Jflows = json.loads( Jflows )
2361 except ValueError:
2362 main.log.error( "Unable to read flows" )
2363 return main.FALSE
2364
2365 for flow in Jflows:
Jon Hall78be4962017-05-23 14:53:53 -07002366 if len( flow[ "flows" ] ) != 0:
alison52b25892016-09-19 10:53:48 -07002367 HostJson.append( flow[ "flows" ] )
2368
Jon Hall78be4962017-05-23 14:53:53 -07002369 totalflows = len( HostJson[ 0 ] )
alison52b25892016-09-19 10:53:48 -07002370
2371 pop = 0
2372 push = 0
2373
2374 PopTag = tag + "_POP"
2375 PushTag = tag + "_PUSH"
2376
2377 for EachHostJson in HostJson:
2378 for i in range( totalflows ):
2379 if EachHostJson[ i ][ "treatment" ][ "instructions" ][ 0 ][ "subtype" ] == PopTag:
2380 pop += 1
2381 elif EachHostJson[ i ][ "treatment" ][ "instructions" ][ 0 ][ "subtype" ] == PushTag:
2382 push += 1
2383
2384 if pop == totalflows and push == totalflows:
2385 return main.TRUE
2386 else:
alisonda157272016-12-22 01:13:21 -08002387 return main.FALSE
2388
Jon Hall78be4962017-05-23 14:53:53 -07002389
alisonda157272016-12-22 01:13:21 -08002390def ProtectedIntentCheck( main ):
alisonda157272016-12-22 01:13:21 -08002391 intent = main.CLIs[ 0 ].intents( jsonFormat=False )
2392 if "Protection" in intent:
2393 return main.TRUE
Shreyaca8990f2017-03-16 11:43:11 -07002394 return main.FALSE