blob: 27bb5e3d6fa65d30a6aac405a7067d8d1efb505c [file] [log] [blame]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001"""
2 Wrapper functions for FuncIntent
3 This functions include Onosclidriver and Mininetclidriver driver functions
4 Author: kelvin@onlab.us
5"""
6import time
7import copy
8import json
Jon Hallf539eb92017-05-22 17:18:42 -07009import os
kelvin-onlabd48a68c2015-07-13 16:01:36 -070010
11def __init__( self ):
12 self.default = ''
13
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -070014hostIntentFailFlag = False
15pointIntentFailFlag = False
16singleToMultiFailFlag = False
17multiToSingleFailFlag = False
18
Jeremy Songster1f39bf02016-01-20 17:17:25 -080019def installHostIntent( main,
Jeremy2f190ca2016-01-29 15:23:57 -080020 name,
21 host1,
22 host2,
23 onosNode=0,
24 ethType="",
25 bandwidth="",
26 lambdaAlloc=False,
27 ipProto="",
28 ipAddresses="",
29 tcp="",
30 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -070031 sw2="",
Jeremy Songsterc032f162016-08-04 17:14:49 -070032 setVlan="",
Jon Hallf539eb92017-05-22 17:18:42 -070033 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -070034 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -080035 Installs a Host Intent
36
kelvin-onlab58dc39e2015-08-06 08:11:09 -070037 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -080038 Install a host intent using
39 add-host-intent
40
kelvin-onlab58dc39e2015-08-06 08:11:09 -070041 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -080042 - Fetch host data if not given
43 - Add host intent
44 - Ingress device is the first sender host
45 - Egress devices are the recipient devices
46 - Ports if defined in senders or recipients
47 - MAC address ethSrc loaded from Ingress device
48 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -070049 Required:
50 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -080051 host1 - Dictionary for host1
52 { "name":"h8", "id":"of:0000000000000005/8" }
53 host2 - Dictionary for host2
54 { "name":"h16", "id":"of:0000000000000006/8" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -070055 Optional:
56 onosNode - ONOS node to install the intents in main.CLIs[ ]
57 0 by default so that it will always use the first
58 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -070059 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -070060 bandwidth - Bandwidth capacity
61 lambdaAlloc - Allocate lambda, defaults to False
62 ipProto - IP protocol
Jeremy Songster1f39bf02016-01-20 17:17:25 -080063 tcp - TCP ports in the same order as the hosts in hostNames
64 """
65
66 assert main, "There is no main variable"
67 assert host1, "You must specify host1"
68 assert host2, "You must specify host2"
69
70 global itemName # The name of this run. Used for logs.
71 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -080072
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -070073 global hostIntentFailFlag
74 hostIntentFailFlag = False
75
Jeremy Songster1f39bf02016-01-20 17:17:25 -080076 main.log.info( itemName + ": Adding single point to multi point intents" )
Jeremyd9e4eb12016-04-13 12:09:06 -070077 try:
78 if not host1.get( "id" ):
79 main.log.warn( "ID not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
80 main.log.debug( main.hostsData.get( host1.get( "name" ) ) )
81 host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "id" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -080082
Jeremyd9e4eb12016-04-13 12:09:06 -070083 if not host2.get( "id" ):
84 main.log.warn( "ID not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
85 host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "id" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -080086
Jeremyd9e4eb12016-04-13 12:09:06 -070087 # Adding point intent
Jeremy Songster832f9e92016-05-05 14:30:49 -070088 vlanId = host1.get( "vlan" )
Jeremyd9e4eb12016-04-13 12:09:06 -070089 intentId = main.CLIs[ onosNode ].addHostIntent( hostIdOne=host1.get( "id" ),
Jeremy Songster832f9e92016-05-05 14:30:49 -070090 hostIdTwo=host2.get( "id" ),
Jeremy Songsterff553672016-05-12 17:06:23 -070091 vlanId=vlanId,
Jeremy Songsterc032f162016-08-04 17:14:49 -070092 setVlan=setVlan,
93 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -070094 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -070095 errorMsg = "There was a problem loading the hosts data."
96 if intentId:
97 errorMsg += " There was a problem installing host to host intent."
98 main.log.error( errorMsg )
99 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800100
101 # Check intents state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700102 if utilities.retry( f=checkIntentState,
103 retValue=main.FALSE,
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
109 #Check VLAN if test encapsulation
110 if encap != "":
111 if EncapsulatedIntentCheck( main, tag=encap ):
112 main.assertReturnString += 'Encapsulation intents check Passed\n'
113 else:
114 main.assertReturnString += 'Encapsulation intents check failed\n'
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'
124
alison52b25892016-09-19 10:53:48 -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
139def testHostIntent( main,
140 name,
141 intentId,
142 host1,
143 host2,
144 onosNode=0,
145 sw1="s5",
146 sw2="s2",
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700147 expectedLink=0 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800148 """
149 Test a Host Intent
150
151 Description:
152 Test a host intent of given ID between given hosts
153
154 Steps:
155 - Fetch host data if not given
156 - Check Intent State
157 - Check Flow State
158 - Check Connectivity
159 - Check Lack of Connectivity Between Hosts not in the Intent
160 - Reroute
161 - Take Expected Link Down
162 - Check Intent State
163 - Check Flow State
164 - Check Topology
165 - Check Connectivity
166 - Bring Expected Link Up
167 - Check Intent State
168 - Check Flow State
169 - Check Topology
170 - Check Connectivity
171 - Remove Topology
172
173 Required:
174 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
175 intentId - intent ID to be tested ( and removed )
176 host1 - Dictionary for host1
177 { "name":"h8", "id":"of:0000000000000005/8" }
178 host2 - Dictionary for host2
179 { "name":"h16", "id":"of:0000000000000006/8" }
180 Optional:
181 onosNode - ONOS node to install the intents in main.CLIs[ ]
182 0 by default so that it will always use the first
183 ONOS node
184 sw1 - First switch to bring down & up for rerouting purpose
185 sw2 - Second switch to bring down & up for rerouting purpose
186 expectedLink - Expected link when the switches are down, it should
187 be two links lower than the links before the two
188 switches are down
189
190 """
191
192 # 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
392def installPointIntent( main,
393 name,
394 senders,
395 recipients,
396 onosNode=0,
397 ethType="",
398 bandwidth="",
399 lambdaAlloc=False,
alisonda157272016-12-22 01:13:21 -0800400 protected=False,
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800401 ipProto="",
402 ipSrc="",
403 ipDst="",
404 tcpSrc="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700405 tcpDst="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700406 setVlan="",
Jon Hallf539eb92017-05-22 17:18:42 -0700407 encap="" ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800408 """
409 Installs a Single to Single Point Intent
410
411 Description:
412 Install a single to single point intent
413
414 Steps:
415 - Fetch host data if not given
416 - Add point intent
417 - Ingress device is the first sender device
418 - Egress device is the first recipient device
419 - Ports if defined in senders or recipients
420 - MAC address ethSrc loaded from Ingress device
421 - Check intent state with retry
422 Required:
423 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
424 senders - List of host dictionaries i.e.
425 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
426 recipients - List of host dictionaries i.e.
427 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
428 Optional:
429 onosNode - ONOS node to install the intents in main.CLIs[ ]
430 0 by default so that it will always use the first
431 ONOS node
432 ethType - Ethernet type eg. IPV4, IPV6
433 bandwidth - Bandwidth capacity
434 lambdaAlloc - Allocate lambda, defaults to False
435 ipProto - IP protocol
436 tcp - TCP ports in the same order as the hosts in hostNames
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700437 sw1 - First switch to bring down & up for rerouting purpose
438 sw2 - Second switch to bring down & up for rerouting purpose
439 expectedLink - Expected link when the switches are down, it should
440 be two links lower than the links before the two
441 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700442 """
443
444 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
468
Jeremyd9e4eb12016-04-13 12:09:06 -0700469 ingressDevice = senders[ 0 ].get( "device" )
470 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800471
Jeremyd9e4eb12016-04-13 12:09:06 -0700472 portIngress = senders[ 0 ].get( "port", "" )
473 portEgress = recipients[ 0 ].get( "port", "" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800474
Jeremyd9e4eb12016-04-13 12:09:06 -0700475 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800476
Jeremyd9e4eb12016-04-13 12:09:06 -0700477 ipSrc = senders[ 0 ].get( "ip" )
478 ipDst = recipients[ 0 ].get( "ip" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800479
Jeremy Songster832f9e92016-05-05 14:30:49 -0700480 vlanId = senders[ 0 ].get( "vlan" )
481
Jeremyd9e4eb12016-04-13 12:09:06 -0700482 # Adding point intent
483 intentId = main.CLIs[ onosNode ].addPointIntent(
484 ingressDevice=ingressDevice,
485 egressDevice=egressDevice,
486 portIngress=portIngress,
487 portEgress=portEgress,
488 ethType=ethType,
489 ethDst=dstMac,
490 bandwidth=bandwidth,
491 lambdaAlloc=lambdaAlloc,
alisonda157272016-12-22 01:13:21 -0800492 protected=protected,
Jeremyd9e4eb12016-04-13 12:09:06 -0700493 ipProto=ipProto,
494 ipSrc=ipSrc,
495 ipDst=ipDst,
496 tcpSrc=tcpSrc,
Jeremy Songster832f9e92016-05-05 14:30:49 -0700497 tcpDst=tcpDst,
Jeremy Songsterff553672016-05-12 17:06:23 -0700498 vlanId=vlanId,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700499 setVlan=setVlan,
500 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700501 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700502 errorMsg = "There was a problem loading the hosts data."
503 if intentId:
504 errorMsg += " There was a problem installing Point to Point intent."
505 main.log.error( errorMsg )
506 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700507
508 # Check intents state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700509 if utilities.retry( f=checkIntentState,
510 retValue=main.FALSE,
Jon Hallf539eb92017-05-22 17:18:42 -0700511 args=( main, [ intentId ] ),
512 sleep=main.checkIntentSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -0700513 attempts=50 ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700514 main.assertReturnString += 'Install Intent State Passed\n'
alison52b25892016-09-19 10:53:48 -0700515
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700516 if bandwidth != "":
Jon Hallf539eb92017-05-22 17:18:42 -0700517 allocationsFile = open( os.path.dirname( main.testFile ) + main.params[ 'DEPENDENCY' ][ 'filePath' ], 'r' )
518 expectedFormat = allocationsFile.read()
519 bandwidthCheck = checkBandwidthAllocations( main, expectedFormat )
520 allocationsFile.close()
521 if bandwidthCheck:
522 main.assertReturnString += 'Bandwidth Allocation check Passed\n'
523 else:
524 main.assertReturnString += 'Bandwidth Allocation check Failed\n'
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
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700544def pointIntentTcp( main,
545 name,
546 host1,
547 host2,
548 onosNode=0,
549 deviceId1="",
550 deviceId2="",
551 port1="",
552 port2="",
553 ethType="",
554 mac1="",
555 mac2="",
556 bandwidth="",
557 lambdaAlloc=False,
558 ipProto="",
559 ip1="",
560 ip2="",
561 tcp1="",
562 tcp2="",
563 sw1="",
564 sw2="",
565 expectedLink=0 ):
566
567 """
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 """
616
617 assert main, "There is no main variable"
618 assert name, "variable name is empty"
619 assert host1 and host2, "You must specify hosts"
620
621 global itemName
622 itemName = name
623 host1 = host1
624 host2 = host2
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700625 intentsId = []
626
627 iperfResult = main.TRUE
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700628 linkDownResult = main.TRUE
629 linkUpResult = main.TRUE
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700630
631 # Adding bidirectional point intents
632 main.log.info( itemName + ": Adding point intents" )
633 intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
634 egressDevice=deviceId2,
635 portIngress=port1,
636 portEgress=port2,
637 ethType=ethType,
638 ethSrc=mac1,
639 ethDst=mac2,
640 bandwidth=bandwidth,
641 lambdaAlloc=lambdaAlloc,
642 ipProto=ipProto,
643 ipSrc=ip1,
644 ipDst=ip2,
645 tcpSrc=tcp1,
646 tcpDst="" )
647
648 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
649 egressDevice=deviceId1,
650 portIngress=port2,
651 portEgress=port1,
652 ethType=ethType,
653 ethSrc=mac2,
654 ethDst=mac1,
655 bandwidth=bandwidth,
656 lambdaAlloc=lambdaAlloc,
657 ipProto=ipProto,
658 ipSrc=ip2,
659 ipDst=ip1,
660 tcpSrc=tcp2,
661 tcpDst="" )
662
663 intent3 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
664 egressDevice=deviceId2,
665 portIngress=port1,
666 portEgress=port2,
667 ethType=ethType,
668 ethSrc=mac1,
669 ethDst=mac2,
670 bandwidth=bandwidth,
671 lambdaAlloc=lambdaAlloc,
672 ipProto=ipProto,
673 ipSrc=ip1,
674 ipDst=ip2,
675 tcpSrc="",
676 tcpDst=tcp2 )
677
678 intent4 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
679 egressDevice=deviceId1,
680 portIngress=port2,
681 portEgress=port1,
682 ethType=ethType,
683 ethSrc=mac2,
684 ethDst=mac1,
685 bandwidth=bandwidth,
686 lambdaAlloc=lambdaAlloc,
687 ipProto=ipProto,
688 ipSrc=ip2,
689 ipDst=ip1,
690 tcpSrc="",
691 tcpDst=tcp1 )
692 intentsId.append( intent1 )
693 intentsId.append( intent2 )
694 intentsId.append( intent3 )
695 intentsId.append( intent4 )
696
697 # Check intents state
Jon Hallf539eb92017-05-22 17:18:42 -0700698 main.log.info( "Sleeping {} seconds".format( main.checkIntentSleep ) )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700699 time.sleep( main.checkIntentSleep )
Jon Hallaf95c3e2017-05-16 13:20:37 -0700700 intentResult = utilities.retry( f=checkIntentState,
701 retValue=main.FALSE,
702 args=( main, intentsId ),
703 sleep=1,
704 attempts=50 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700705 # Check flows count in each node
706 checkFlowsCount( main )
707
708 # Check intents state again if first check fails...
709 if not intentResult:
Jon Hallaf95c3e2017-05-16 13:20:37 -0700710 intentResult = utilities.retry( f=checkIntentState,
711 retValue=main.FALSE,
712 args=( main, intentsId ),
713 sleep=1,
714 attempts=50 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700715
716 # Check flows count in each node
717 checkFlowsCount( main )
718
719 # Verify flows
720 checkFlowsState( main )
721
722 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700723 iperfTemp = main.Mininet1.iperftcp( host1, host2 ,10 )
acsmarsd4862d12015-10-06 17:57:34 -0700724 iperfResult = iperfResult and iperfTemp
725 if iperfTemp:
726 main.assertReturnString += 'Initial Iperf Passed\n'
727 else:
728 main.assertReturnString += 'Initial Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700729
730 # Test rerouting if these variables exist
731 if sw1 and sw2 and expectedLink:
732 # link down
733 linkDownResult = link( main, sw1, sw2, "down" )
acsmarsd4862d12015-10-06 17:57:34 -0700734
735 if linkDownResult:
736 main.assertReturnString += 'Link Down Passed\n'
737 else:
738 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700739
740 # Check flows count in each node
741 checkFlowsCount( main )
742 # Verify flows
743 checkFlowsState( main )
744
745 # Check OnosTopology
746 topoResult = checkTopology( main, expectedLink )
acsmarsd4862d12015-10-06 17:57:34 -0700747 if topoResult:
748 main.assertReturnString += 'Link Down Topology State Passed\n'
749 else:
750 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700751
752 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700753 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700754 iperfResult = iperfResult and iperfTemp
755 if iperfTemp:
756 main.assertReturnString += 'Link Down Iperf Passed\n'
757 else:
758 main.assertReturnString += 'Link Down Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700759
acsmarsd4862d12015-10-06 17:57:34 -0700760 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700761 intentTemp = utilities.retry( f=checkIntentState,
762 retValue=main.FALSE,
763 args=( main, intentsId ),
764 sleep=1,
765 attempts=50 )
acsmarsd4862d12015-10-06 17:57:34 -0700766 intentResult = intentResult and intentTemp
767 if intentTemp:
768 main.assertReturnString += 'Link Down Intent State Passed\n'
769 else:
770 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700771
772 # Checks ONOS state in link down
773 if linkDownResult and topoResult and iperfResult and intentResult:
774 main.log.info( itemName + ": Successfully brought link down" )
775 else:
776 main.log.error( itemName + ": Failed to bring link down" )
777
778 # link up
779 linkUpResult = link( main, sw1, sw2, "up" )
alison52b25892016-09-19 10:53:48 -0700780 if linkUpResult:
acsmarsd4862d12015-10-06 17:57:34 -0700781 main.assertReturnString += 'Link Up Passed\n'
782 else:
783 main.assertReturnString += 'Link Up Failed\n'
784
Jon Hallf539eb92017-05-22 17:18:42 -0700785 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700786 time.sleep( main.rerouteSleep )
787
788 # Check flows count in each node
789 checkFlowsCount( main )
790 # Verify flows
791 checkFlowsState( main )
792
793 # Check OnosTopology
794 topoResult = checkTopology( main, main.numLinks )
795
acsmarsd4862d12015-10-06 17:57:34 -0700796 if topoResult:
797 main.assertReturnString += 'Link Up Topology State Passed\n'
798 else:
799 main.assertReturnString += 'Link Up Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700800
acsmarsd4862d12015-10-06 17:57:34 -0700801 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700802 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700803 iperfResult = iperfResult and iperfTemp
804 if iperfTemp:
805 main.assertReturnString += 'Link Up Iperf Passed\n'
806 else:
807 main.assertReturnString += 'Link Up Iperf Failed\n'
808
809 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700810 intentTemp = utilities.retry( f=checkIntentState,
811 retValue=main.FALSE,
812 args=( main, intentsId ),
813 sleep=1,
814 attempts=50 )
acsmarsd4862d12015-10-06 17:57:34 -0700815 intentResult = intentResult and intentTemp
816 if intentTemp:
817 main.assertReturnString += 'Link Down Intent State Passed\n'
818 else:
819 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700820
821 # Checks ONOS state in link up
822 if linkUpResult and topoResult and iperfResult and intentResult:
823 main.log.info( itemName + ": Successfully brought link back up" )
824 else:
825 main.log.error( itemName + ": Failed to bring link back up" )
826
827 # Remove all intents
828 removeIntentResult = removeAllIntents( main, intentsId )
acsmarsd4862d12015-10-06 17:57:34 -0700829 if removeIntentResult:
830 main.assertReturnString += 'Remove Intents Passed'
831 else:
832 main.assertReturnString += 'Remove Intents Failed'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700833
834 stepResult = iperfResult and linkDownResult and linkUpResult \
835 and intentResult and removeIntentResult
836
837 return stepResult
838
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 """
891
892 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800893 assert senders, "You must specify a sender"
894 assert recipients, "You must specify a recipient"
895 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700896
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800897 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700898 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700899
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700900 global singleToMultiFailFlag
901 singleToMultiFailFlag = False
902
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700903 main.log.info( itemName + ": Adding single point to multi point intents" )
904
Jeremyd9e4eb12016-04-13 12:09:06 -0700905 try:
906 for sender in senders:
907 if not sender.get( "device" ):
908 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
909 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700910
Jeremyd9e4eb12016-04-13 12:09:06 -0700911 for recipient in recipients:
912 if not recipient.get( "device" ):
913 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
914 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700915
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700916
Jeremyd9e4eb12016-04-13 12:09:06 -0700917 ingressDevice = senders[ 0 ].get( "device" )
918 egressDeviceList = [ x.get( "device" ) for x in recipients if x.get( "device" ) ]
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800919
Jeremyd9e4eb12016-04-13 12:09:06 -0700920 portIngress = senders[ 0 ].get( "port", "" )
921 portEgressList = [ x.get( "port" ) for x in recipients if x.get( "port" ) ]
922 if not portEgressList:
923 portEgressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800924
Jeremyd9e4eb12016-04-13 12:09:06 -0700925 srcMac = senders[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700926 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800927
Jeremyd9e4eb12016-04-13 12:09:06 -0700928 # Adding point intent
929 intentId = main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
930 ingressDevice=ingressDevice,
931 egressDeviceList=egressDeviceList,
932 portIngress=portIngress,
933 portEgressList=portEgressList,
934 ethType=ethType,
935 ethSrc=srcMac,
936 bandwidth=bandwidth,
937 lambdaAlloc=lambdaAlloc,
938 ipProto=ipProto,
939 ipSrc="",
940 ipDst="",
941 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -0700942 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700943 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -0700944 setVlan=setVlan,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700945 partial=partial,
946 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700947 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700948 errorMsg = "There was a problem loading the hosts data."
949 if intentId:
950 errorMsg += " There was a problem installing Singlepoint to Multipoint intent."
951 main.log.error( errorMsg )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700952 singleToMultiFailFlag = True
Jeremyd9e4eb12016-04-13 12:09:06 -0700953 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700954
955 # Check intents state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700956 if singleToMultiFailFlag:
957 attempts = 5
958 else:
959 attempts = 50
960
Jon Hallaf95c3e2017-05-16 13:20:37 -0700961 if utilities.retry( f=checkIntentState,
962 retValue=main.FALSE,
Jon Hallf539eb92017-05-22 17:18:42 -0700963 args=( main, [ intentId ] ),
Jon Hallaf95c3e2017-05-16 13:20:37 -0700964 sleep=main.checkIntentSleep,
965 attempts=attempts ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700966 main.assertReturnString += 'Install Intent State Passed\n'
Jon Hallf539eb92017-05-22 17:18:42 -0700967 if bandwidth != "":
968 allocationsFile = open( os.path.dirname( main.testFile ) + main.params[ 'DEPENDENCY' ][ 'filePath' ], 'r' )
969 expectedFormat = allocationsFile.read()
970 bandwidthCheck = checkBandwidthAllocations( main, expectedFormat )
971 allocationsFile.close()
972 if bandwidthCheck:
973 main.assertReturnString += 'Bandwidth Allocation check Passed\n'
974 else:
975 main.assertReturnString += 'Bandwidth Allocation check Failed\n'
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
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800987def installMultiToSingleIntent( main,
988 name,
989 senders,
990 recipients,
991 onosNode=0,
992 ethType="",
993 bandwidth="",
994 lambdaAlloc=False,
995 ipProto="",
996 ipAddresses="",
997 tcp="",
998 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700999 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -07001000 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -07001001 partial=False,
Jon Hallf539eb92017-05-22 17:18:42 -07001002 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001003 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001004 Installs a Multi to Single Point Intent
1005
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001006 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001007 Install a multi to single point intent using
1008 add-multi-to-single-intent
1009
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001010 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001011 - Fetch host data if not given
1012 - Add multi to single intent
1013 - Ingress devices are the senders devices
1014 - Egress device is the first recipient host
1015 - Ports if defined in senders or recipients
1016 - MAC address ethSrc loaded from Ingress device
1017 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001018 Required:
1019 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001020 senders - List of host dictionaries i.e.
1021 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
1022 recipients - List of host dictionaries i.e.
1023 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001024 Optional:
1025 onosNode - ONOS node to install the intents in main.CLIs[ ]
1026 0 by default so that it will always use the first
1027 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001028 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001029 bandwidth - Bandwidth capacity
1030 lambdaAlloc - Allocate lambda, defaults to False
1031 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001032 tcp - TCP ports in the same order as the hosts in hostNames
1033 sw1 - First switch to bring down & up for rerouting purpose
1034 sw2 - Second switch to bring down & up for rerouting purpose
1035 expectedLink - Expected link when the switches are down, it should
1036 be two links lower than the links before the two
1037 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001038 """
1039
1040 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'
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001123 if flowDuration( main ):
1124 main.assertReturnString += 'Flow duration check Passed\n'
1125 return intentId
1126 else:
1127 main.assertReturnString += 'Flow duration check failed\n'
1128 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001129 else:
1130 main.log.error( "Multi to Single Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001131 multiToSingleFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001132 return main.FALSE
1133
1134def testPointIntent( main,
Jeremye0cb5eb2016-01-27 17:39:09 -08001135 name,
1136 intentId,
1137 senders,
1138 recipients,
1139 badSenders={},
1140 badRecipients={},
1141 onosNode=0,
1142 ethType="",
1143 bandwidth="",
1144 lambdaAlloc=False,
alisonda157272016-12-22 01:13:21 -08001145 protected=False,
Jeremye0cb5eb2016-01-27 17:39:09 -08001146 ipProto="",
1147 ipAddresses="",
1148 tcp="",
1149 sw1="s5",
1150 sw2="s2",
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001151 expectedLink=0,
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001152 useTCP=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001153 """
1154 Test a Point Intent
1155
1156 Description:
1157 Test a point intent
1158
1159 Steps:
1160 - Fetch host data if not given
1161 - Check Intent State
1162 - Check Flow State
1163 - Check Connectivity
1164 - Check Lack of Connectivity Between Hosts not in the Intent
1165 - Reroute
1166 - Take Expected Link Down
1167 - Check Intent State
1168 - Check Flow State
1169 - Check Topology
1170 - Check Connectivity
1171 - Bring Expected Link Up
1172 - Check Intent State
1173 - Check Flow State
1174 - Check Topology
1175 - Check Connectivity
1176 - Remove Topology
1177
1178 Required:
1179 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
1180
1181 senders - List of host dictionaries i.e.
1182 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
1183 recipients - List of host dictionaries i.e.
1184 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
1185 Optional:
1186 onosNode - ONOS node to install the intents in main.CLIs[ ]
1187 0 by default so that it will always use the first
1188 ONOS node
1189 ethType - Ethernet type eg. IPV4, IPV6
1190 bandwidth - Bandwidth capacity
1191 lambdaAlloc - Allocate lambda, defaults to False
1192 ipProto - IP protocol
1193 tcp - TCP ports in the same order as the hosts in hostNames
1194 sw1 - First switch to bring down & up for rerouting purpose
1195 sw2 - Second switch to bring down & up for rerouting purpose
1196 expectedLink - Expected link when the switches are down, it should
1197 be two links lower than the links before the two
1198 switches are down
1199
1200 """
1201
1202 # Parameter Validity Check
1203 assert main, "There is no main variable"
1204 assert senders, "You must specify a sender"
1205 assert recipients, "You must specify a recipient"
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001206
1207 global itemName
1208 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001209
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001210 global pointIntentFailFlag
1211 global singleToMultiFailFlag
1212 global multiToSingleFailFlag
1213
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001214 main.log.info( itemName + ": Testing Point Intent" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001215
Jeremyd9e4eb12016-04-13 12:09:06 -07001216 try:
1217 # Names for scapy
1218 senderNames = [ x.get( "name" ) for x in senders ]
1219 recipientNames = [ x.get( "name" ) for x in recipients ]
1220 badSenderNames = [ x.get( "name" ) for x in badSenders ]
1221 badRecipientNames = [ x.get( "name" ) for x in badRecipients ]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001222
Jeremyd9e4eb12016-04-13 12:09:06 -07001223 for sender in senders:
1224 if not sender.get( "device" ):
1225 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1226 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001227
Jeremyd9e4eb12016-04-13 12:09:06 -07001228 for recipient in recipients:
1229 if not recipient.get( "device" ):
1230 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1231 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001232 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001233 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001234 main.log.error( "There was a problem loading the hosts data." )
1235 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001236
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001237 testResult = main.TRUE
1238 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001239
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001240 if pointIntentFailFlag or singleToMultiFailFlag or multiToSingleFailFlag:
1241 attempts = 1
1242 else:
1243 attempts = 50
1244
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001245 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001246 if utilities.retry( f=checkIntentState,
1247 retValue=main.FALSE,
1248 args=( main, [ intentId ] ),
1249 sleep=main.checkIntentSleep,
1250 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001251 main.assertReturnString += 'Initial Intent State Passed\n'
acsmarsd4862d12015-10-06 17:57:34 -07001252 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001253 main.assertReturnString += 'Initial Intent State Failed\n'
1254 testResult = main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001255 attempts = 1
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001256
1257 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001258 if utilities.retry( f=checkFlowsCount,
1259 retValue=main.FALSE,
1260 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001261 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001262 attempts=3 ) and utilities.retry( f=checkFlowsState,
1263 retValue=main.FALSE,
1264 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001265 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001266 attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001267 main.assertReturnString += 'Initial Flow State Passed\n'
1268 else:
1269 main.assertReturnString += 'Intial Flow State Failed\n'
1270 testResult = main.FALSE
1271
1272 # Check Connectivity
Jon Hallaf95c3e2017-05-16 13:20:37 -07001273 if utilities.retry( f=scapyCheckConnection,
1274 retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -07001275 args=( main, senderNames, recipientNames, vlanId, useTCP ),
Jon Hallaf95c3e2017-05-16 13:20:37 -07001276 attempts=attempts,
1277 sleep=main.checkConnectionSleep ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001278 main.assertReturnString += 'Initial Ping Passed\n'
1279 else:
1280 main.assertReturnString += 'Initial Ping Failed\n'
1281 testResult = main.FALSE
1282
1283 # Check connections that shouldn't work
1284 if badSenderNames:
1285 main.log.info( "Checking that packets from incorrect sender do not go through" )
Jon Hallaf95c3e2017-05-16 13:20:37 -07001286 if utilities.retry( f=scapyCheckConnection,
1287 retValue=main.FALSE,
1288 args=( main, badSenderNames, recipientNames ),
1289 kwargs={ "expectFailure":True } ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001290 main.assertReturnString += 'Bad Sender Ping Passed\n'
1291 else:
1292 main.assertReturnString += 'Bad Sender Ping Failed\n'
1293 testResult = main.FALSE
1294
1295 if badRecipientNames:
1296 main.log.info( "Checking that packets to incorrect recipients do not go through" )
Jon Hallaf95c3e2017-05-16 13:20:37 -07001297 if utilities.retry( f=scapyCheckConnection,
1298 retValue=main.FALSE,
1299 args=( main, senderNames, badRecipientNames ),
1300 kwargs={ "expectFailure":True } ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001301 main.assertReturnString += 'Bad Recipient Ping Passed\n'
1302 else:
1303 main.assertReturnString += 'Bad Recipient Ping Failed\n'
1304 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001305
1306 # Test rerouting if these variables exist
1307 if sw1 and sw2 and expectedLink:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001308 # Take link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001309 if utilities.retry( f=link,
1310 retValue=main.FALSE,
1311 args=( main, sw1, sw2, "down" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001312 main.assertReturnString += 'Link Down Passed\n'
1313 else:
1314 main.assertReturnString += 'Link Down Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001315 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001316
alisonda157272016-12-22 01:13:21 -08001317 if protected:
1318 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001319 if utilities.retry( f=scapyCheckConnection,
1320 retValue=main.FALSE,
1321 args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
alisonda157272016-12-22 01:13:21 -08001322 main.assertReturnString += 'Link down Scapy Packet Received Passed\n'
1323 else:
1324 main.assertReturnString += 'Link down Scapy Packet Recieved Failed\n'
1325 testResult = main.FALSE
1326
1327 if ProtectedIntentCheck( main ):
1328 main.assertReturnString += 'Protected Intent Check Passed\n'
1329 else:
1330 main.assertReturnString += 'Protected Intent Check Failed\n'
1331 testResult = main.FALSE
1332
acsmarsd4862d12015-10-06 17:57:34 -07001333 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001334 if utilities.retry( f=checkIntentState,
1335 retValue=main.FALSE,
1336 args=( main, [ intentId ] ),
1337 sleep=main.checkIntentPointSleep,
1338 attempts=attempts ):
acsmarsd4862d12015-10-06 17:57:34 -07001339 main.assertReturnString += 'Link Down Intent State Passed\n'
1340 else:
1341 main.assertReturnString += 'Link Down Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001342 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001343
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001344 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001345 if utilities.retry( f=checkFlowsCount,
1346 retValue=main.FALSE,
1347 args=[ main ],
1348 sleep=main.checkFlowCountSleep,
1349 attempts=attempts * 2 ) and utilities.retry( f=checkFlowsState,
1350 retValue=main.FALSE,
1351 args=[ main ],
1352 sleep=main.checkFlowCountSleep,
1353 attempts=attempts * 2 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001354 main.assertReturnString += 'Link Down Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001355 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001356 main.assertReturnString += 'Link Down Flow State Failed\n'
1357 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001358
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001359 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001360 if utilities.retry( f=checkTopology,
1361 retValue=main.FALSE,
1362 args=( main, expectedLink ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001363 main.assertReturnString += 'Link Down Topology State Passed\n'
1364 else:
1365 main.assertReturnString += 'Link Down Topology State Failed\n'
1366 testResult = main.FALSE
1367
1368 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001369 if utilities.retry( f=scapyCheckConnection,
1370 retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -07001371 args=( main, senderNames, recipientNames, vlanId, useTCP ),
Jon Hallaf95c3e2017-05-16 13:20:37 -07001372 sleep=main.checkConnectionSleep,
1373 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001374 main.assertReturnString += 'Link Down Pingall Passed\n'
1375 else:
1376 main.assertReturnString += 'Link Down Pingall Failed\n'
1377 testResult = main.FALSE
1378
1379 # Bring link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001380 if utilities.retry( f=link,
1381 retValue=main.FALSE,
1382 args=( main, sw1, sw2, "up" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001383 main.assertReturnString += 'Link Up Passed\n'
1384 else:
1385 main.assertReturnString += 'Link Up Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001386 testResult = main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -07001387
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001388 # Wait for reroute
Jon Hallf539eb92017-05-22 17:18:42 -07001389 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001390 time.sleep( main.rerouteSleep )
1391
acsmarsd4862d12015-10-06 17:57:34 -07001392 # Check Intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001393 if utilities.retry( f=checkIntentState,
1394 retValue=main.FALSE,
1395 attempts=attempts * 2,
1396 args=( main, [ intentId ] ),
Shreyaca8990f2017-03-16 11:43:11 -07001397 sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001398 main.assertReturnString += 'Link Up Intent State Passed\n'
1399 else:
1400 main.assertReturnString += 'Link Up Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001401 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001402
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001403 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001404 if utilities.retry( f=checkFlowsCount,
1405 retValue=main.FALSE,
1406 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001407 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001408 attempts=3 ) and utilities.retry( f=checkFlowsState,
1409 retValue=main.FALSE,
1410 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001411 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001412 attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001413 main.assertReturnString += 'Link Up Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001414 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001415 main.assertReturnString += 'Link Up Flow State Failed\n'
1416 testResult = main.FALSE
1417
1418 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001419 if utilities.retry( f=checkTopology,
1420 retValue=main.FALSE,
1421 args=( main, main.numLinks ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001422 main.assertReturnString += 'Link Up Topology State Passed\n'
1423 else:
1424 main.assertReturnString += 'Link Up Topology State Failed\n'
1425 testResult = main.FALSE
1426
1427 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001428 if utilities.retry( f=scapyCheckConnection,
1429 retValue=main.FALSE,
1430 sleep=main.checkConnectionSleep,
1431 attempts=100,
Shreyaca8990f2017-03-16 11:43:11 -07001432 args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001433 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1434 else:
1435 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1436 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001437
1438 # Remove all intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001439 if utilities.retry( f=removeAllIntents,
1440 retValue=main.FALSE,
1441 attempts=10,
1442 args=( main, [ intentId ] ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001443 main.assertReturnString += 'Remove Intents Passed'
1444 else:
1445 main.assertReturnString += 'Remove Intents Failed'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001446 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001447
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001448 return testResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001449
Jeremye0cb5eb2016-01-27 17:39:09 -08001450def testEndPointFail( main,
1451 name,
1452 intentId,
1453 senders,
1454 recipients,
1455 isolatedSenders,
1456 isolatedRecipients,
1457 onosNode=0,
1458 ethType="",
1459 bandwidth="",
1460 lambdaAlloc=False,
1461 ipProto="",
1462 ipAddresses="",
1463 tcp="",
1464 sw1="",
1465 sw2="",
1466 sw3="",
1467 sw4="",
1468 sw5="",
1469 expectedLink1=0,
Jeremy Songster9385d412016-06-02 17:57:36 -07001470 expectedLink2=0,
1471 partial=False ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001472 """
Shreyaca8990f2017-03-16 11:43:11 -07001473 Test Multi point to single point intent Topology for Endpoint failures
Jeremye0cb5eb2016-01-27 17:39:09 -08001474 """
1475
1476 # Parameter Validity Check
1477 assert main, "There is no main variable"
1478 assert senders, "You must specify a sender"
1479 assert recipients, "You must specify a recipient"
1480
1481 global itemName
1482 itemName = name
Jeremye0cb5eb2016-01-27 17:39:09 -08001483
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001484 global singleToMultiFailFlag
1485 global multiToSingleFailFlag
1486
Jeremye0cb5eb2016-01-27 17:39:09 -08001487 main.log.info( itemName + ": Testing Point Intent" )
1488
Jeremyd9e4eb12016-04-13 12:09:06 -07001489 try:
1490 # Names for scapy
1491 senderNames = [ x.get( "name" ) for x in senders ]
1492 recipientNames = [ x.get( "name" ) for x in recipients ]
1493 isolatedSenderNames = [ x.get( "name" ) for x in isolatedSenders ]
1494 isolatedRecipientNames = [ x.get( "name" ) for x in isolatedRecipients ]
1495 connectedSenderNames = [x.get("name") for x in senders if x.get("name") not in isolatedSenderNames]
1496 connectedRecipientNames = [x.get("name") for x in recipients if x.get("name") not in isolatedRecipientNames]
Jeremye0cb5eb2016-01-27 17:39:09 -08001497
Jeremyd9e4eb12016-04-13 12:09:06 -07001498 for sender in senders:
1499 if not sender.get( "device" ):
1500 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1501 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremye0cb5eb2016-01-27 17:39:09 -08001502
Jeremyd9e4eb12016-04-13 12:09:06 -07001503 for recipient in recipients:
1504 if not recipient.get( "device" ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001505 main.log.warn( "Device not given for recipient {0}. Loading from " +\
1506 main.hostData.format( recipient.get( "name" ) ) )
Jeremyd9e4eb12016-04-13 12:09:06 -07001507 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001508 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001509 main.log.error( "There was a problem loading the hosts data." )
1510 return main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001511
1512 testResult = main.TRUE
1513 main.log.info( itemName + ": Adding multi point to single point intents" )
1514
1515 # Check intent state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001516 if singleToMultiFailFlag or multiToSingleFailFlag:
1517 attempts = 1
1518 else:
1519 attempts = 50
1520
Jon Hallaf95c3e2017-05-16 13:20:37 -07001521 if utilities.retry( f=checkIntentState,
1522 retValue=main.FALSE,
1523 args=( main, [ intentId ] ),
1524 sleep=main.checkIntentSleep,
1525 attempts=attempts ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001526 main.assertReturnString += 'Initial Intent State Passed\n'
1527 else:
1528 main.assertReturnString += 'Initial Intent State Failed\n'
1529 testResult = main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001530 attempts = 1
Jeremye0cb5eb2016-01-27 17:39:09 -08001531
1532 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001533 if utilities.retry( f=checkFlowsCount,
1534 retValue=main.FALSE,
1535 args=[ main ],
1536 attempts=5 ) and utilities.retry( f=checkFlowsState,
1537 retValue=main.FALSE,
1538 args=[ main ],
1539 attempts=5 ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001540 main.assertReturnString += 'Initial Flow State Passed\n'
1541 else:
1542 main.assertReturnString += 'Intial Flow State Failed\n'
1543 testResult = main.FALSE
1544
1545 # Check Connectivity
Jon Hallaf95c3e2017-05-16 13:20:37 -07001546 if utilities.retry( f=scapyCheckConnection,
1547 retValue=main.FALSE,
Jeremye0cb5eb2016-01-27 17:39:09 -08001548 args=( main, senderNames, recipientNames ) ):
1549 main.assertReturnString += 'Initial Connectivity Check Passed\n'
1550 else:
1551 main.assertReturnString += 'Initial Connectivity Check Failed\n'
1552 testResult = main.FALSE
1553
1554 # Take two links down
1555 # Take first link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001556 if utilities.retry( f=link,
1557 retValue=main.FALSE,
1558 args=( main, sw1, sw2, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001559 main.assertReturnString += 'Link Down Passed\n'
1560 else:
1561 main.assertReturnString += 'Link Down Failed\n'
1562 testResult = main.FALSE
1563
1564 # Take second link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001565 if utilities.retry( f=link,
1566 retValue=main.FALSE,
1567 args=( main, sw3, sw4, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001568 main.assertReturnString += 'Link Down Passed\n'
1569 else:
1570 main.assertReturnString += 'Link Down Failed\n'
1571 testResult = main.FALSE
1572
1573 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001574 if utilities.retry( f=checkIntentState,
1575 retValue=main.FALSE,
1576 attempts=attempts,
1577 args=( main, [ intentId ] ),
1578 sleep=main.checkIntentSleep ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001579 main.assertReturnString += 'Link Down Intent State Passed\n'
1580 else:
1581 main.assertReturnString += 'Link Down Intent State Failed\n'
1582 testResult = main.FALSE
1583
1584 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001585 if utilities.retry( f=checkFlowsCount,
1586 retValue=main.FALSE,
1587 sleep=1,
1588 attempts=attempts,
Jeremye0cb5eb2016-01-27 17:39:09 -08001589 args=[ main ] ) and utilities.retry( f=checkFlowsState,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001590 retValue=main.FALSE,
1591 sleep=1,
1592 attempts=attempts,
1593 args=[ main ] ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001594 main.assertReturnString += 'Link Down Flow State Passed\n'
1595 else:
1596 main.assertReturnString += 'Link Down Flow State Failed\n'
1597 testResult = main.FALSE
1598
1599 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001600 if utilities.retry( f=checkTopology,
1601 retValue=main.FALSE,
1602 args=( main, expectedLink1 ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001603 main.assertReturnString += 'Link Down Topology State Passed\n'
1604 else:
1605 main.assertReturnString += 'Link Down Topology State Failed\n'
1606 testResult = main.FALSE
1607
1608 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001609 if utilities.retry( f=scapyCheckConnection,
1610 retValue=main.FALSE,
Jeremye0cb5eb2016-01-27 17:39:09 -08001611 args=( main, senderNames, recipientNames ) ):
1612 main.assertReturnString += 'Link Down Connectivity Check Passed\n'
1613 else:
1614 main.assertReturnString += 'Link Down Connectivity Check Failed\n'
1615 testResult = main.FALSE
1616
1617 # Take a third link down to isolate one node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001618 if utilities.retry( f=link,
1619 retValue=main.FALSE,
1620 args=( main, sw3, sw5, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001621 main.assertReturnString += 'Isolation link Down Passed\n'
1622 else:
1623 main.assertReturnString += 'Isolation link Down Failed\n'
1624 testResult = main.FALSE
1625
Jeremy Songster9385d412016-06-02 17:57:36 -07001626 if partial:
1627 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001628 if utilities.retry( f=checkIntentState,
1629 retValue=main.FALSE,
1630 args=( main, [ intentId ] ),
1631 sleep=main.checkIntentSleep,
1632 attempts=attempts ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001633 main.assertReturnString += 'Partial failure isolation link Down Intent State Passed\n'
1634 else:
1635 main.assertReturnString += 'Partial failure isolation link Down Intent State Failed\n'
1636 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001637
Jeremy Songster9385d412016-06-02 17:57:36 -07001638 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001639 if utilities.retry( f=checkFlowsCount,
1640 retValue=main.FALSE,
1641 args=[ main ],
1642 attempts=5 ) and utilities.retry( f=checkFlowsState,
1643 retValue=main.FALSE,
1644 args=[ main ],
1645 attempts=5 ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001646 main.assertReturnString += 'Partial failure isolation link Down Flow State Passed\n'
1647 else:
1648 main.assertReturnString += 'Partial failure isolation link Down Flow State Failed\n'
1649 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001650
Jeremy Songster9385d412016-06-02 17:57:36 -07001651 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001652 if utilities.retry( f=checkTopology,
1653 retValue=main.FALSE,
1654 args=( main, expectedLink2 ) ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001655 main.assertReturnString += 'Partial failure isolation link Down Topology State Passed\n'
1656 else:
1657 main.assertReturnString += 'Partial failure isolation link Down Topology State Failed\n'
1658 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001659
Jeremy Songster9385d412016-06-02 17:57:36 -07001660 # Check Connectivity
1661 # First check connectivity of any isolated senders to recipients
1662 if isolatedSenderNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001663 if scapyCheckConnection( main,
1664 isolatedSenderNames,
1665 recipientNames,
1666 None,
1667 None,
1668 None,
1669 None,
1670 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001671 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1672 else:
1673 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1674 testResult = main.FALSE
1675
1676 # Next check connectivity of senders to any isolated recipients
1677 if isolatedRecipientNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001678 if scapyCheckConnection( main,
1679 senderNames,
1680 isolatedRecipientNames,
1681 None,
1682 None,
1683 None,
1684 None,
1685 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001686 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1687 else:
1688 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1689 testResult = main.FALSE
1690
1691 # Next check connectivity of connected senders and recipients
Jon Hallaf95c3e2017-05-16 13:20:37 -07001692 if utilities.retry( f=scapyCheckConnection,
1693 retValue=main.FALSE,
1694 attempts=attempts,
Jeremy Songster9385d412016-06-02 17:57:36 -07001695 args=( main, connectedSenderNames , connectedRecipientNames ) ):
1696 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1697 else:
1698 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1699 testResult = main.FALSE
1700 else:
1701 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001702 if not utilities.retry( f=checkIntentState,
1703 retValue=main.TRUE,
1704 args=( main, [ intentId ] ),
1705 sleep=main.checkIntentSleep,
1706 attempts=attempts ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001707 main.assertReturnString += 'Isolation link Down Intent State Passed\n'
1708 else:
1709 main.assertReturnString += 'Isolation link Down Intent State Failed\n'
1710 testResult = main.FALSE
1711
1712 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001713 if utilities.retry( f=checkFlowsCount,
1714 retValue=main.FALSE,
1715 args=[ main ],
1716 attempts=5 ) and utilities.retry( f=checkFlowsState,
1717 retValue=main.FALSE,
1718 args=[ main ],
1719 attempts=5 ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001720 main.assertReturnString += 'Isolation link Down Flow State Passed\n'
1721 else:
1722 main.assertReturnString += 'Isolation link Down Flow State Failed\n'
1723 testResult = main.FALSE
1724
1725 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001726 if utilities.retry( f=checkTopology,
1727 retValue=main.FALSE,
1728 args=( main, expectedLink2 ) ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001729 main.assertReturnString += 'Isolation link Down Topology State Passed\n'
1730 else:
1731 main.assertReturnString += 'Isolation link Down Topology State Failed\n'
1732 testResult = main.FALSE
1733
1734 # Check Connectivity
1735 # First check connectivity of any isolated senders to recipients
1736 if isolatedSenderNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001737 if scapyCheckConnection( main,
1738 isolatedSenderNames,
1739 recipientNames,
1740 None,
1741 None,
1742 None,
1743 None,
1744 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001745 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1746 else:
1747 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1748 testResult = main.FALSE
1749
1750 # Next check connectivity of senders to any isolated recipients
1751 if isolatedRecipientNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001752 if scapyCheckConnection( main,
1753 senderNames,
1754 isolatedRecipientNames,
1755 None,
1756 None,
1757 None,
1758 None,
1759 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001760 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1761 else:
1762 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1763 testResult = main.FALSE
1764
1765 # Next check connectivity of connected senders and recipients
Jon Hallaf95c3e2017-05-16 13:20:37 -07001766 if utilities.retry( f=scapyCheckConnection,
1767 retValue=main.TRUE,
1768 args=( main, connectedSenderNames, connectedRecipientNames, None, None, None, None, main.TRUE ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001769 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1770 else:
1771 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1772 testResult = main.FALSE
1773
Jeremye0cb5eb2016-01-27 17:39:09 -08001774 # Bring the links back up
1775 # Bring first link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001776 if utilities.retry( f=link,
1777 retValue=main.FALSE,
1778 args=( main, sw1, sw2, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001779 main.assertReturnString += 'Link Up Passed\n'
1780 else:
1781 main.assertReturnString += 'Link Up Failed\n'
1782 testResult = main.FALSE
1783
1784 # Bring second link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001785 if utilities.retry( f=link,
1786 retValue=main.FALSE,
1787 args=( main, sw3, sw5, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001788 main.assertReturnString += 'Link Up Passed\n'
1789 else:
1790 main.assertReturnString += 'Link Up Failed\n'
1791 testResult = main.FALSE
1792
1793 # Bring third link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001794 if utilities.retry( f=link,
1795 retValue=main.FALSE,
1796 args=( main, sw3, sw4, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001797 main.assertReturnString += 'Link Up Passed\n'
1798 else:
1799 main.assertReturnString += 'Link Up Failed\n'
1800 testResult = main.FALSE
1801
1802 # Wait for reroute
Jon Hallf539eb92017-05-22 17:18:42 -07001803 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
Jeremye0cb5eb2016-01-27 17:39:09 -08001804 time.sleep( main.rerouteSleep )
1805
1806 # Check Intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001807 if utilities.retry( f=checkIntentState,
1808 retValue=main.FALSE,
1809 attempts=attempts,
1810 args=( main, [ intentId ] ),
1811 sleep=main.checkIntentHostSleep ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001812 main.assertReturnString += 'Link Up Intent State Passed\n'
1813 else:
1814 main.assertReturnString += 'Link Up Intent State Failed\n'
1815 testResult = main.FALSE
1816
1817 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001818 if utilities.retry( f=checkFlowsCount,
1819 retValue=main.FALSE,
1820 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001821 sleep=main.checkFlowCountSleep,
1822 attempts=attempts ) and utilities.retry( f=checkFlowsState,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001823 retValue=main.FALSE,
1824 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001825 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001826 attempts=attempts ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001827 main.assertReturnString += 'Link Up Flow State Passed\n'
1828 else:
1829 main.assertReturnString += 'Link Up Flow State Failed\n'
1830 testResult = main.FALSE
1831
1832 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001833 if utilities.retry( f=checkTopology,
1834 retValue=main.FALSE,
1835 args=( main, main.numLinks ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001836 main.assertReturnString += 'Link Up Topology State Passed\n'
1837 else:
1838 main.assertReturnString += 'Link Up Topology State Failed\n'
1839 testResult = main.FALSE
1840
1841 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001842 if utilities.retry( f=scapyCheckConnection,
1843 retValue=main.FALSE,
1844 sleep=main.checkConnectionSleep,
1845 attempts=attempts,
Jeremye0cb5eb2016-01-27 17:39:09 -08001846 args=( main, senderNames, recipientNames ) ):
1847 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1848 else:
1849 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1850 testResult = main.FALSE
1851
1852 # Remove all intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001853 if utilities.retry( f=removeAllIntents,
1854 retValue=main.FALSE,
1855 attempts=10,
1856 args=( main, [ intentId ] ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001857 main.assertReturnString += 'Remove Intents Passed'
1858 else:
1859 main.assertReturnString += 'Remove Intents Failed'
1860 testResult = main.FALSE
1861
1862 return testResult
1863
1864
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001865def pingallHosts( main, hostList ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001866 """
1867 Ping all host in the hosts list variable
1868 """
Jon Halla5cb3412015-08-18 14:08:22 -07001869 main.log.info( "Pinging: " + str( hostList ) )
1870 return main.Mininet1.pingallHosts( hostList )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001871
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001872def fwdPingall( main ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001873 """
1874 Use fwd app and pingall to discover all the hosts
1875 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001876 appCheck = main.TRUE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001877 main.log.info( "Activating reactive forwarding app " )
1878 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001879
1880 # Wait for forward app activation to propagate
Jon Hallf539eb92017-05-22 17:18:42 -07001881 main.log.info( "Sleeping {} seconds".format( main.fwdSleep ) )
kelvin-onlab0ad05d12015-07-23 14:21:15 -07001882 time.sleep( main.fwdSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001883
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001884 # Check that forwarding is enabled on all nodes
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001885 for i in range( main.numCtrls ):
1886 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
1887 if appCheck != main.TRUE:
1888 main.log.warn( main.CLIs[ i ].apps() )
1889 main.log.warn( main.CLIs[ i ].appIDs() )
1890
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001891 # Send pingall in mininet
1892 main.log.info( "Run Pingall" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001893 pingResult = main.Mininet1.pingall( timeout = 600 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001894
1895 main.log.info( "Deactivating reactive forwarding app " )
1896 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001897 if activateResult and deactivateResult:
1898 main.log.info( "Successfully used fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001899 getDataResult = main.TRUE
1900 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001901 main.log.info( "Failed to use fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001902 getDataResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001903 return getDataResult
1904
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001905def confirmHostDiscovery( main ):
1906 """
1907 Confirms that all ONOS nodes have discovered all scapy hosts
1908 """
1909 import collections
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001910 hosts = main.topo.getAllHosts( main ) # Get host data from each ONOS node
1911 hostFails = [] # Reset for each failed attempt
1912
1913 # Check for matching hosts on each node
1914 scapyHostIPs = [ x.hostIp for x in main.scapyHosts if x.hostIp != "0.0.0.0" ]
1915 for controller in range( main.numCtrls ):
1916 controllerStr = str( controller + 1 ) # ONOS node number
1917 # Compare Hosts
1918 # Load hosts data for controller node
Jeremyd9e4eb12016-04-13 12:09:06 -07001919 try:
1920 if hosts[ controller ]:
1921 main.log.info( "Hosts discovered" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001922 else:
Jeremyd9e4eb12016-04-13 12:09:06 -07001923 main.log.error( "Problem discovering hosts" )
1924 if hosts[ controller ] and "Error" not in hosts[ controller ]:
1925 try:
1926 hostData = json.loads( hosts[ controller ] )
1927 except ( TypeError, ValueError ):
1928 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001929 hostFails.append( controllerStr )
Jeremyd9e4eb12016-04-13 12:09:06 -07001930 else:
1931 onosHostIPs = [ x.get( "ipAddresses" )[ 0 ]
1932 for x in hostData
1933 if len( x.get( "ipAddresses" ) ) > 0 ]
1934 if not set( collections.Counter( scapyHostIPs ) ).issubset( set ( collections.Counter( onosHostIPs ) ) ):
1935 main.log.warn( "Controller {0} only sees nodes with {1} IPs. It should see all of the following: {2}".format( controllerStr, onosHostIPs, scapyHostIPs ) )
1936 hostFails.append( controllerStr )
1937 else:
1938 main.log.error( "Hosts returned nothing or an error." )
1939 hostFails.append( controllerStr )
1940 except IndexError:
1941 main.log.error( "Hosts returned nothing, Failed to discover hosts." )
1942 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001943
1944 if hostFails:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001945 main.log.error( "List of failed ONOS Nodes:" + ', '.join( map( str, hostFails ) ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001946 return main.FALSE
1947 else:
1948 return main.TRUE
1949
1950def sendDiscoveryArp( main, hosts=None ):
1951 """
1952 Sends Discovery ARP packets from each host provided
1953 Defaults to each host in main.scapyHosts
1954 """
1955 # Send an arp ping from each host
1956 if not hosts:
1957 hosts = main.scapyHosts
1958 for host in hosts:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001959 pkt = 'Ether( src="{0}")/ARP( psrc="{1}")'.format( host.hostMac, host.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001960 # Send from the VLAN interface if there is one so ONOS discovers the VLAN correctly
1961 iface = None
1962 for interface in host.getIfList():
1963 if '.' in interface:
1964 main.log.debug( "Detected VLAN interface {0}. Sending ARP packet from {0}".format( interface ) )
1965 iface = interface
1966 break
1967 host.sendPacket( packet=pkt, iface=iface )
1968 main.log.info( "Sending ARP packet from {0}".format( host.name ) )
1969
1970def populateHostData( main ):
1971 """
1972 Populates hostsData
1973 """
1974 import json
1975 try:
1976 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
1977 hosts = main.Mininet1.getHosts().keys()
1978 # TODO: Make better use of new getHosts function
1979 for host in hosts:
1980 main.hostsData[ host ] = {}
1981 main.hostsData[ host ][ 'mac' ] = \
1982 main.Mininet1.getMacAddress( host ).upper()
1983 for hostj in hostsJson:
1984 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
1985 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
1986 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
1987 main.hostsData[ host ][ 'location' ] = \
1988 hostj[ 'location' ][ 'elementId' ] + '/' + \
1989 hostj[ 'location' ][ 'port' ]
1990 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
1991 return main.TRUE
Jeremyd9e4eb12016-04-13 12:09:06 -07001992 except ValueError:
1993 main.log.error( "ValueError while populating hostsData" )
1994 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001995 except KeyError:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001996 main.log.error( "KeyError while populating hostsData" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001997 return main.FALSE
Jeremyd9e4eb12016-04-13 12:09:06 -07001998 except IndexError:
1999 main.log.error( "IndexError while populating hostsData" )
2000 return main.FALSE
2001 except TypeError:
2002 main.log.error( "TypeError while populating hostsData" )
2003 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002004
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002005def checkTopology( main, expectedLink ):
2006 statusResult = main.TRUE
2007 # Check onos topology
2008 main.log.info( itemName + ": Checking ONOS topology " )
2009
2010 for i in range( main.numCtrls ):
Flavio Castro82ee2f62016-06-07 15:04:12 -07002011 statusResult = main.CLIs[ i ].checkStatus( main.numSwitch,
Jon Hallaf95c3e2017-05-16 13:20:37 -07002012 expectedLink ) and statusResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002013 if not statusResult:
2014 main.log.error( itemName + ": Topology mismatch" )
2015 else:
2016 main.log.info( itemName + ": Topology match" )
2017 return statusResult
2018
Jon Hallf539eb92017-05-22 17:18:42 -07002019def checkIntentState( main, intentsId ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002020 """
2021 This function will check intent state to make sure all the intents
2022 are in INSTALLED state
Jon Hallf539eb92017-05-22 17:18:42 -07002023 Returns main.TRUE or main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002024 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002025 intentResult = main.TRUE
Jon Hallf539eb92017-05-22 17:18:42 -07002026 stateCheckResults = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002027 for i in range( main.numCtrls ):
Jon Hallf539eb92017-05-22 17:18:42 -07002028 output = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
2029 stateCheckResults.append( output )
2030 if all( result == main.TRUE for result in stateCheckResults ):
2031 main.log.info( itemName + ": Intents state check passed" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002032 else:
Jon Hallf539eb92017-05-22 17:18:42 -07002033 main.log.warn( "Intents state check failed" )
Shreyaca8990f2017-03-16 11:43:11 -07002034 intentResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002035 return intentResult
2036
Jon Hallf539eb92017-05-22 17:18:42 -07002037def checkBandwidthAllocations( main, bandwidth ):
2038 """
2039 Compare the given bandwith allocation output to the cli output on each node
2040 Returns main.TRUE or main.FALSE
2041 """
2042 bandwidthResults = []
2043 for i in range( main.numCtrls ):
2044 output = main.CLIs[ i ].compareBandwidthAllocations( bandwidth )
2045 bandwidthResults.append( output )
2046 if all( result == main.TRUE for result in bandwidthResults ):
2047 main.log.info( itemName + ": bandwidth check passed" )
2048 bandwidthResult = main.TRUE
2049 else:
2050 main.log.warn( itemName + ": bandwidth check failed" )
2051 bandwidthResult = main.FALSE
2052 return bandwidthResult
2053
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002054def checkFlowsState( main ):
2055
2056 main.log.info( itemName + ": Check flows state" )
Jeremy Songsterff553672016-05-12 17:06:23 -07002057 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState( isPENDING=False )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002058 return checkFlowsResult
2059
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002060def link( main, sw1, sw2, option ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002061
2062 # link down
alison52b25892016-09-19 10:53:48 -07002063 main.log.info( itemName + ": Bring link " + option + " between " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002064 sw1 + " and " + sw2 )
2065 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
2066 return linkResult
2067
Jon Hallaf95c3e2017-05-16 13:20:37 -07002068def scapyCheckConnection( main,
2069 senders,
2070 recipients,
2071 vlanId=None,
2072 useTCP=False,
2073 packet=None,
2074 packetFilter=None,
2075 expectFailure=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002076 """
2077 Checks the connectivity between all given sender hosts and all given recipient hosts
2078 Packet may be specified. Defaults to Ether/IP packet
2079 Packet Filter may be specified. Defaults to Ether/IP from current sender MAC
2080 Todo: Optional packet and packet filter attributes for sender and recipients
2081 Expect Failure when the sender and recipient are not supposed to have connectivity
2082 Timeout of 1 second, returns main.TRUE if the filter is not triggered and kills the filter
2083
2084 """
2085 connectionsFunctional = main.TRUE
2086
2087 if not packetFilter:
2088 packetFilter = 'ether host {}'
Jeremy Songstere405d3d2016-05-17 11:18:57 -07002089 if useTCP:
2090 packetFilter += ' ip proto \\tcp tcp port {}'.format(main.params[ 'SDNIP' ][ 'dstPort' ])
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002091 if expectFailure:
2092 timeout = 1
2093 else:
2094 timeout = 10
2095
2096 for sender in senders:
2097 try:
2098 senderComp = getattr( main, sender )
2099 except AttributeError:
2100 main.log.error( "main has no attribute {}".format( sender ) )
2101 connectionsFunctional = main.FALSE
2102 continue
2103
2104 for recipient in recipients:
2105 # Do not send packets to self since recipient CLI will already be busy
2106 if recipient == sender:
2107 continue
2108 try:
2109 recipientComp = getattr( main, recipient )
2110 except AttributeError:
2111 main.log.error( "main has no attribute {}".format( recipient ) )
2112 connectionsFunctional = main.FALSE
2113 continue
2114
Jeremy Songster832f9e92016-05-05 14:30:49 -07002115 if vlanId:
2116 recipientComp.startFilter( pktFilter = ( "vlan {}".format( vlanId ) + " && " + packetFilter.format( senderComp.hostMac ) ) )
2117 else:
2118 recipientComp.startFilter( pktFilter = packetFilter.format( senderComp.hostMac ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002119
2120 if not packet:
Jeremy Songster832f9e92016-05-05 14:30:49 -07002121 if vlanId:
2122 pkt = 'Ether( src="{0}", dst="{2}" )/Dot1Q(vlan={4})/IP( src="{1}", dst="{3}" )'.format(
2123 senderComp.hostMac,
2124 senderComp.hostIp,
2125 recipientComp.hostMac,
2126 recipientComp.hostIp,
2127 vlanId )
2128 else:
2129 pkt = 'Ether( src="{0}", dst="{2}" )/IP( src="{1}", dst="{3}" )'.format(
2130 senderComp.hostMac,
2131 senderComp.hostIp,
2132 recipientComp.hostMac,
2133 recipientComp.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002134 else:
2135 pkt = packet
Jeremy Songster832f9e92016-05-05 14:30:49 -07002136 if vlanId:
2137 senderComp.sendPacket( iface=( "{0}-eth0.{1}".format( sender, vlanId ) ), packet = pkt )
2138 else:
2139 senderComp.sendPacket( packet = pkt )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002140
2141 if recipientComp.checkFilter( timeout ):
2142 if expectFailure:
2143 main.log.error( "Packet from {0} successfully received by {1} when it should not have been".format( sender , recipient ) )
2144 connectionsFunctional = main.FALSE
2145 else:
2146 main.log.info( "Packet from {0} successfully received by {1}".format( sender , recipient ) )
alison52b25892016-09-19 10:53:48 -07002147 connectionsFunctional = main.TRUE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002148 else:
2149 recipientComp.killFilter()
2150 if expectFailure:
2151 main.log.info( "As expected, packet from {0} was not received by {1}".format( sender , recipient ) )
2152 else:
2153 main.log.error( "Packet from {0} was not received by {1}".format( sender , recipient ) )
2154 connectionsFunctional = main.FALSE
2155
2156 return connectionsFunctional
2157
alison52b25892016-09-19 10:53:48 -07002158
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002159def removeAllIntents( main, intentsId ):
2160 """
2161 Remove all intents in the intentsId
2162 """
2163
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002164 onosSummary = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002165 removeIntentResult = main.TRUE
2166 # Remove intents
2167 for intent in intentsId:
2168 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
2169
Jon Hallf539eb92017-05-22 17:18:42 -07002170 main.log.info( "Sleeping {} seconds".format( main.removeIntentSleep ) )
acsmarscfa52272015-08-06 15:21:45 -07002171 time.sleep( main.removeIntentSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002172
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002173 # If there is remianing intents then remove intents should fail
2174 for i in range( main.numCtrls ):
2175 onosSummary.append( json.loads( main.CLIs[ i ].summary() ) )
2176
2177 for summary in onosSummary:
2178 if summary.get( 'intents' ) != 0:
2179 main.log.warn( itemName + ": There are " +
2180 str( summary.get( 'intents' ) ) +
2181 " intents remaining in node " +
2182 str( summary.get( 'node' ) ) +
2183 ", failed to remove all the intents " )
2184 removeIntentResult = main.FALSE
2185
2186 if removeIntentResult:
2187 main.log.info( itemName + ": There are no more intents remaining, " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002188 "successfully removed all the intents." )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002189
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002190 return removeIntentResult
2191
2192def checkFlowsCount( main ):
2193 """
2194 Check flows count in each node
2195 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002196 flowsCount = []
2197 main.log.info( itemName + ": Checking flows count in each ONOS node" )
2198 for i in range( main.numCtrls ):
2199 summaryResult = main.CLIs[ i ].summary()
2200 if not summaryResult:
2201 main.log.error( itemName + ": There is something wrong with " +
2202 "summary command" )
2203 return main.FALSE
2204 else:
2205 summaryJson = json.loads( summaryResult )
2206 flowsCount.append( summaryJson.get( 'flows' ) )
2207
2208 if flowsCount:
2209 if all( flows==flowsCount[ 0 ] for flows in flowsCount ):
2210 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
2211 " flows in all ONOS node" )
2212 else:
2213 for i in range( main.numCtrls ):
2214 main.log.debug( itemName + ": ONOS node " + str( i ) + " has " +
kelvin-onlab6dea6e62015-07-23 13:07:26 -07002215 str( flowsCount[ i ] ) + " flows" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002216 else:
2217 main.log.error( "Checking flows count failed, check summary command" )
2218 return main.FALSE
2219
2220 return main.TRUE
2221
kelvin-onlab58dc39e2015-08-06 08:11:09 -07002222def checkLeaderChange( leaders1, leaders2 ):
acsmarse6b410f2015-07-17 14:39:34 -07002223 """
2224 Checks for a change in intent partition leadership.
2225
2226 Takes the output of leaders -c in json string format before and after
2227 a potential change as input
2228
2229 Returns main.TRUE if no mismatches are detected
2230 Returns main.FALSE if there is a mismatch or on error loading the input
2231 """
2232 try:
2233 leaders1 = json.loads( leaders1 )
2234 leaders2 = json.loads( leaders2 )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002235 except( AttributeError, TypeError ):
Jon Halld970abf2017-05-23 10:20:28 -07002236 main.log.exception( "checkLeaderChange: Object not as expected" )
acsmarse6b410f2015-07-17 14:39:34 -07002237 return main.FALSE
2238 except Exception:
Jon Halld970abf2017-05-23 10:20:28 -07002239 main.log.exception( "checkLeaderChange: Uncaught exception!" )
acsmarse6b410f2015-07-17 14:39:34 -07002240 main.cleanup()
2241 main.exit()
2242 main.log.info( "Checking Intent Paritions for Change in Leadership" )
2243 mismatch = False
2244 for dict1 in leaders1:
2245 if "intent" in dict1.get( "topic", [] ):
2246 for dict2 in leaders2:
2247 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \
2248 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
2249 mismatch = True
2250 main.log.error( "{0} changed leader from {1} to {2}".\
2251 format( dict1.get( "topic", "no-topic" ),\
2252 dict1.get( "leader", "no-leader" ),\
2253 dict2.get( "leader", "no-leader" ) ) )
2254 if mismatch:
2255 return main.FALSE
2256 else:
2257 return main.TRUE
kelvin-onlab016dce22015-08-10 09:54:11 -07002258
2259def report( main ):
2260 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002261 Report errors/warnings/exceptions
kelvin-onlab016dce22015-08-10 09:54:11 -07002262 """
kelvin-onlab016dce22015-08-10 09:54:11 -07002263 main.ONOSbench.logReport( main.ONOSip[ 0 ],
2264 [ "INFO",
2265 "FOLLOWER",
2266 "WARN",
2267 "flow",
2268 "ERROR",
2269 "Except" ],
2270 "s" )
2271
2272 main.log.info( "ERROR report: \n" )
2273 for i in range( main.numCtrls ):
2274 main.ONOSbench.logReport( main.ONOSip[ i ],
2275 [ "ERROR" ],
2276 "d" )
2277
2278 main.log.info( "EXCEPTIONS report: \n" )
2279 for i in range( main.numCtrls ):
2280 main.ONOSbench.logReport( main.ONOSip[ i ],
2281 [ "Except" ],
2282 "d" )
2283
2284 main.log.info( "WARNING report: \n" )
2285 for i in range( main.numCtrls ):
2286 main.ONOSbench.logReport( main.ONOSip[ i ],
2287 [ "WARN" ],
2288 "d" )
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002289
2290def flowDuration( main ):
2291 """
2292 Check age of flows to see if flows are being overwritten
2293 """
2294 import time
2295 main.log.info( "Getting current flow durations" )
2296 flowsJson1 = main.CLIs[ 0 ].flows( noCore=True )
2297 try:
2298 flowsJson1 = json.loads( flowsJson1 )
2299 except ValueError:
2300 main.log.error( "Unable to read flows" )
2301 return main.FALSE
2302 flowLife = []
2303 waitFlowLife = []
2304 for device in flowsJson1:
2305 if device.get( 'flowcount', 0 ) > 0:
2306 for i in range( device[ 'flowCount' ] ):
2307 flowLife.append( device[ 'flows' ][ i ][ 'life' ] )
2308 main.log.info( "Sleeping for {} seconds".format( main.flowDurationSleep ) )
2309 time.sleep( main.flowDurationSleep )
2310 main.log.info( "Getting new flow durations" )
2311 flowsJson2 = main.CLIs[ 0 ].flows( noCore=True )
2312 try:
2313 flowsJson2 = json.loads( flowsJson2 )
2314 except ValueError:
2315 main.log.error( "Unable to read flows" )
2316 return main.FALSE
2317 for device in flowsJson2:
2318 if device.get( 'flowcount', 0 ) > 0:
2319 for i in range( device[ 'flowCount' ] ):
2320 waitFlowLife.append( device[ 'flows' ][ i ][ 'life' ] )
2321 main.log.info( "Determining whether flows where overwritten" )
2322 if len( flowLife ) == len( waitFlowLife ):
alison52b25892016-09-19 10:53:48 -07002323 for i in range( len( flowLife ) ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002324 if waitFlowLife[ i ] - flowLife[ i ] < main.flowDurationSleep:
2325 return main.FALSE
2326 else:
2327 return main.FALSE
2328 return main.TRUE
alison52b25892016-09-19 10:53:48 -07002329
2330
2331def EncapsulatedIntentCheck( main, tag="" ):
2332 """
2333 Check encapsulated intents
2334 tag: encapsulation tag (e.g. VLAN, MPLS)
2335
2336 Getting added flows
2337 Check tags on each flows
2338 If each direction has push or pop, passed
2339 else failed
2340
2341 """
2342 import json
2343 HostJson = []
2344 Jflows = main.CLIs[ 0 ].flows( noCore=True )
2345 try:
2346 Jflows = json.loads( Jflows )
2347 except ValueError:
2348 main.log.error( "Unable to read flows" )
2349 return main.FALSE
2350
2351 for flow in Jflows:
2352 if len(flow[ "flows" ]) != 0:
2353 HostJson.append( flow[ "flows" ] )
2354
2355 totalflows = len( HostJson[ 0 ])
2356
2357 pop = 0
2358 push = 0
2359
2360 PopTag = tag + "_POP"
2361 PushTag = tag + "_PUSH"
2362
2363 for EachHostJson in HostJson:
2364 for i in range( totalflows ):
2365 if EachHostJson[ i ][ "treatment" ][ "instructions" ][ 0 ][ "subtype" ] == PopTag:
2366 pop += 1
2367 elif EachHostJson[ i ][ "treatment" ][ "instructions" ][ 0 ][ "subtype" ] == PushTag:
2368 push += 1
2369
2370 if pop == totalflows and push == totalflows:
2371 return main.TRUE
2372 else:
alisonda157272016-12-22 01:13:21 -08002373 return main.FALSE
2374
2375def ProtectedIntentCheck( main ):
2376 import json
2377 intent = main.CLIs[ 0 ].intents( jsonFormat=False )
2378 if "Protection" in intent:
2379 return main.TRUE
Shreyaca8990f2017-03-16 11:43:11 -07002380 return main.FALSE