blob: 305165850143e39c58804cab364daedab12b7655 [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'
Jon Hallc3f88af2017-05-23 11:25:54 -0700124 return main.FALSE
Jon Hallf539eb92017-05-22 17:18:42 -0700125
alison52b25892016-09-19 10:53:48 -0700126
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700127 if flowDuration( main ):
128 main.assertReturnString += 'Flow duration check Passed\n'
129 return intentId
130 else:
Jon Hallf539eb92017-05-22 17:18:42 -0700131 main.assertReturnString += 'Flow duration check Failed\n'
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700132 return main.FALSE
alison52b25892016-09-19 10:53:48 -0700133
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800134 else:
Jeremy2f190ca2016-01-29 15:23:57 -0800135 main.log.error( "Host Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700136 hostIntentFailFlag = True
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700137 main.assertReturnString += 'Install Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800138 return main.FALSE
139
140def testHostIntent( main,
141 name,
142 intentId,
143 host1,
144 host2,
145 onosNode=0,
146 sw1="s5",
147 sw2="s2",
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700148 expectedLink=0 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800149 """
150 Test a Host Intent
151
152 Description:
153 Test a host intent of given ID between given hosts
154
155 Steps:
156 - Fetch host data if not given
157 - Check Intent State
158 - Check Flow State
159 - Check Connectivity
160 - Check Lack of Connectivity Between Hosts not in the Intent
161 - Reroute
162 - Take Expected Link Down
163 - Check Intent State
164 - Check Flow State
165 - Check Topology
166 - Check Connectivity
167 - Bring Expected Link Up
168 - Check Intent State
169 - Check Flow State
170 - Check Topology
171 - Check Connectivity
172 - Remove Topology
173
174 Required:
175 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
176 intentId - intent ID to be tested ( and removed )
177 host1 - Dictionary for host1
178 { "name":"h8", "id":"of:0000000000000005/8" }
179 host2 - Dictionary for host2
180 { "name":"h16", "id":"of:0000000000000006/8" }
181 Optional:
182 onosNode - ONOS node to install the intents in main.CLIs[ ]
183 0 by default so that it will always use the first
184 ONOS node
185 sw1 - First switch to bring down & up for rerouting purpose
186 sw2 - Second switch to bring down & up for rerouting purpose
187 expectedLink - Expected link when the switches are down, it should
188 be two links lower than the links before the two
189 switches are down
190
191 """
192
193 # Parameter Validity Check
194 assert main, "There is no main variable"
195 assert host1, "You must specify host1"
196 assert host2, "You must specify host2"
197
198 global itemName
199 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800200
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700201 global hostIntentFailFlag
202
Jeremy2f190ca2016-01-29 15:23:57 -0800203 main.log.info( itemName + ": Testing Host Intent" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800204
Jeremyd9e4eb12016-04-13 12:09:06 -0700205 try:
206 if not host1.get( "id" ):
207 main.log.warn( "Id not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
208 host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800209
Jeremyd9e4eb12016-04-13 12:09:06 -0700210 if not host2.get( "id" ):
211 main.log.warn( "Id not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
212 host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800213
Jeremyd9e4eb12016-04-13 12:09:06 -0700214 senderNames = [ host1.get( "name" ), host2.get( "name" ) ]
215 recipientNames = [ host1.get( "name" ), host2.get( "name" ) ]
Jeremy Songster832f9e92016-05-05 14:30:49 -0700216 vlanId = host1.get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800217
Jeremyd9e4eb12016-04-13 12:09:06 -0700218 testResult = main.TRUE
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700219 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700220 main.log.error( "There was a problem loading the hosts data." )
221 return main.FALSE
222
223 main.log.info( itemName + ": Testing Host to Host intents" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800224
225 # Check intent state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700226 if hostIntentFailFlag:
227 attempts = 1
228 else:
229 attempts = 50
Jon Hallaf95c3e2017-05-16 13:20:37 -0700230 if utilities.retry( f=checkIntentState,
231 retValue=main.FALSE,
232 args=( main, [ intentId ] ),
233 sleep=main.checkIntentSleep,
234 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800235 main.assertReturnString += 'Initial Intent State Passed\n'
236 else:
237 main.assertReturnString += 'Initial Intent State Failed\n'
238 testResult = main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700239 attempts = 1
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800240
241 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -0700242 if utilities.retry( f=checkFlowsCount,
243 retValue=main.FALSE,
244 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -0700245 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -0700246 attempts=3 ) and utilities.retry( f=checkFlowsState,
247 retValue=main.FALSE,
248 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -0700249 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -0700250 attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800251 main.assertReturnString += 'Initial Flow State Passed\n'
252 else:
253 main.assertReturnString += 'Intial Flow State Failed\n'
254 testResult = main.FALSE
255
256 # Check Connectivity
Jon Hallaf95c3e2017-05-16 13:20:37 -0700257 if utilities.retry( f=scapyCheckConnection,
258 retValue=main.FALSE,
259 attempts=attempts,
260 sleep=main.checkConnectionSleep,
Shreyaca8990f2017-03-16 11:43:11 -0700261 args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800262 main.assertReturnString += 'Initial Ping Passed\n'
263 else:
264 main.assertReturnString += 'Initial Ping Failed\n'
265 testResult = main.FALSE
266
267 # Test rerouting if these variables exist
268 if sw1 and sw2 and expectedLink:
269 # Take link down
Jon Hallaf95c3e2017-05-16 13:20:37 -0700270 if utilities.retry( f=link,
271 retValue=main.FALSE,
272 args=( main, sw1, sw2, "down" ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800273 main.assertReturnString += 'Link Down Passed\n'
274 else:
275 main.assertReturnString += 'Link Down Failed\n'
276 testResult = main.FALSE
277
278 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700279 if utilities.retry( f=checkIntentState,
280 retValue=main.FALSE,
281 args=( main, [ intentId ] ),
282 sleep=main.checkIntentHostSleep,
283 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800284 main.assertReturnString += 'Link Down Intent State Passed\n'
285 else:
286 main.assertReturnString += 'Link Down Intent State Failed\n'
287 testResult = main.FALSE
288
289 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -0700290 if utilities.retry( f=checkFlowsCount,
291 retValue=main.FALSE,
292 args=[ main ],
293 sleep=main.checkFlowCountSleep,
294 attempts=attempts ) and utilities.retry( f=checkFlowsState,
295 retValue=main.FALSE,
296 args=[ main ],
297 sleep=main.checkFlowCountSleep,
298 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800299 main.assertReturnString += 'Link Down Flow State Passed\n'
300 else:
301 main.assertReturnString += 'Link Down Flow State Failed\n'
302 testResult = main.FALSE
303
304 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -0700305 if utilities.retry( f=checkTopology,
306 retValue=main.FALSE,
307 args=( main, expectedLink ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800308 main.assertReturnString += 'Link Down Topology State Passed\n'
309 else:
310 main.assertReturnString += 'Link Down Topology State Failed\n'
311 testResult = main.FALSE
312
313 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -0700314 if utilities.retry( f=scapyCheckConnection,
315 retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -0700316 args=( main, senderNames, recipientNames, vlanId ),
Jon Hallaf95c3e2017-05-16 13:20:37 -0700317 sleep=main.checkConnectionSleep,
318 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800319 main.assertReturnString += 'Link Down Pingall Passed\n'
320 else:
321 main.assertReturnString += 'Link Down Pingall Failed\n'
322 testResult = main.FALSE
323
324 # Bring link up
Jon Hallaf95c3e2017-05-16 13:20:37 -0700325 if utilities.retry( f=link,
326 retValue=main.FALSE,
327 args=( main, sw1, sw2, "up" ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800328 main.assertReturnString += 'Link Up Passed\n'
329 else:
330 main.assertReturnString += 'Link Up Failed\n'
331 testResult = main.FALSE
332
333 # Wait for reroute
Jon Hallf539eb92017-05-22 17:18:42 -0700334 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800335 time.sleep( main.rerouteSleep )
336
337 # Check Intents
Jon Hallaf95c3e2017-05-16 13:20:37 -0700338 if utilities.retry( f=checkIntentState,
339 retValue=main.FALSE,
340 attempts=attempts * 2,
341 args=( main, [ intentId ] ),
342 sleep=main.checkIntentSleep ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800343 main.assertReturnString += 'Link Up Intent State Passed\n'
344 else:
345 main.assertReturnString += 'Link Up Intent State Failed\n'
346 testResult = main.FALSE
347
348 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -0700349 if utilities.retry( f=checkFlowsCount,
350 retValue=main.FALSE,
351 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -0700352 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -0700353 attempts=3 ) and utilities.retry( f=checkFlowsState,
354 retValue=main.FALSE,
355 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -0700356 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -0700357 attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800358 main.assertReturnString += 'Link Up Flow State Passed\n'
359 else:
360 main.assertReturnString += 'Link Up Flow State Failed\n'
361 testResult = main.FALSE
362
363 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -0700364 if utilities.retry( f=checkTopology,
365 retValue=main.FALSE,
366 args=( main, main.numLinks ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800367 main.assertReturnString += 'Link Up Topology State Passed\n'
368 else:
369 main.assertReturnString += 'Link Up Topology State Failed\n'
370 testResult = main.FALSE
371
372 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -0700373 if utilities.retry( f=scapyCheckConnection,
374 retValue=main.FALSE,
375 args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800376 main.assertReturnString += 'Link Up Pingall Passed\n'
377 else:
378 main.assertReturnString += 'Link Up Pingall Failed\n'
379 testResult = main.FALSE
380
381 # Remove all intents
Jon Hallaf95c3e2017-05-16 13:20:37 -0700382 if utilities.retry( f=removeAllIntents,
383 retValue=main.FALSE,
384 attempts=10,
385 args=( main, [ intentId ] ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800386 main.assertReturnString += 'Remove Intents Passed'
387 else:
388 main.assertReturnString += 'Remove Intents Failed'
389 testResult = main.FALSE
390
391 return testResult
392
393def installPointIntent( main,
394 name,
395 senders,
396 recipients,
397 onosNode=0,
398 ethType="",
399 bandwidth="",
400 lambdaAlloc=False,
alisonda157272016-12-22 01:13:21 -0800401 protected=False,
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800402 ipProto="",
403 ipSrc="",
404 ipDst="",
405 tcpSrc="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700406 tcpDst="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700407 setVlan="",
Jon Hallf539eb92017-05-22 17:18:42 -0700408 encap="" ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800409 """
410 Installs a Single to Single Point Intent
411
412 Description:
413 Install a single to single point intent
414
415 Steps:
416 - Fetch host data if not given
417 - Add point intent
418 - Ingress device is the first sender device
419 - Egress device is the first recipient device
420 - Ports if defined in senders or recipients
421 - MAC address ethSrc loaded from Ingress device
422 - Check intent state with retry
423 Required:
424 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
425 senders - List of host dictionaries i.e.
426 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
427 recipients - List of host dictionaries i.e.
428 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
429 Optional:
430 onosNode - ONOS node to install the intents in main.CLIs[ ]
431 0 by default so that it will always use the first
432 ONOS node
433 ethType - Ethernet type eg. IPV4, IPV6
434 bandwidth - Bandwidth capacity
435 lambdaAlloc - Allocate lambda, defaults to False
436 ipProto - IP protocol
437 tcp - TCP ports in the same order as the hosts in hostNames
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700438 sw1 - First switch to bring down & up for rerouting purpose
439 sw2 - Second switch to bring down & up for rerouting purpose
440 expectedLink - Expected link when the switches are down, it should
441 be two links lower than the links before the two
442 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700443 """
444
445 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800446 assert senders, "You must specify a sender"
447 assert recipients, "You must specify a recipient"
448 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700449
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800450 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700451 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700452
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700453 global pointIntentFailFlag
454 pointIntentFailFlag = False
455
Jeremy6f000c62016-02-25 17:02:28 -0800456 main.log.info( itemName + ": Adding point to point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700457
Jeremyd9e4eb12016-04-13 12:09:06 -0700458 try:
459 for sender in senders:
460 if not sender.get( "device" ):
461 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
462 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800463
Jeremyd9e4eb12016-04-13 12:09:06 -0700464 for recipient in recipients:
465 if not recipient.get( "device" ):
466 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
467 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800468
469
Jeremyd9e4eb12016-04-13 12:09:06 -0700470 ingressDevice = senders[ 0 ].get( "device" )
471 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800472
Jeremyd9e4eb12016-04-13 12:09:06 -0700473 portIngress = senders[ 0 ].get( "port", "" )
474 portEgress = recipients[ 0 ].get( "port", "" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800475
Jeremyd9e4eb12016-04-13 12:09:06 -0700476 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800477
Jeremyd9e4eb12016-04-13 12:09:06 -0700478 ipSrc = senders[ 0 ].get( "ip" )
479 ipDst = recipients[ 0 ].get( "ip" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800480
Jeremy Songster832f9e92016-05-05 14:30:49 -0700481 vlanId = senders[ 0 ].get( "vlan" )
482
Jeremyd9e4eb12016-04-13 12:09:06 -0700483 # Adding point intent
484 intentId = main.CLIs[ onosNode ].addPointIntent(
485 ingressDevice=ingressDevice,
486 egressDevice=egressDevice,
487 portIngress=portIngress,
488 portEgress=portEgress,
489 ethType=ethType,
490 ethDst=dstMac,
491 bandwidth=bandwidth,
492 lambdaAlloc=lambdaAlloc,
alisonda157272016-12-22 01:13:21 -0800493 protected=protected,
Jeremyd9e4eb12016-04-13 12:09:06 -0700494 ipProto=ipProto,
495 ipSrc=ipSrc,
496 ipDst=ipDst,
497 tcpSrc=tcpSrc,
Jeremy Songster832f9e92016-05-05 14:30:49 -0700498 tcpDst=tcpDst,
Jeremy Songsterff553672016-05-12 17:06:23 -0700499 vlanId=vlanId,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700500 setVlan=setVlan,
501 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700502 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700503 errorMsg = "There was a problem loading the hosts data."
504 if intentId:
505 errorMsg += " There was a problem installing Point to Point intent."
506 main.log.error( errorMsg )
507 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700508
509 # Check intents state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700510 if utilities.retry( f=checkIntentState,
511 retValue=main.FALSE,
Jon Hallf539eb92017-05-22 17:18:42 -0700512 args=( main, [ intentId ] ),
513 sleep=main.checkIntentSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -0700514 attempts=50 ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700515 main.assertReturnString += 'Install Intent State Passed\n'
alison52b25892016-09-19 10:53:48 -0700516
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700517 if bandwidth != "":
Jon Hallf539eb92017-05-22 17:18:42 -0700518 allocationsFile = open( os.path.dirname( main.testFile ) + main.params[ 'DEPENDENCY' ][ 'filePath' ], 'r' )
519 expectedFormat = allocationsFile.read()
520 bandwidthCheck = checkBandwidthAllocations( main, expectedFormat )
521 allocationsFile.close()
522 if bandwidthCheck:
523 main.assertReturnString += 'Bandwidth Allocation check Passed\n'
524 else:
525 main.assertReturnString += 'Bandwidth Allocation check Failed\n'
Jon Hallc3f88af2017-05-23 11:25:54 -0700526 return main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700527
alison52b25892016-09-19 10:53:48 -0700528 # Check VLAN if test encapsulation
529 if encap != "":
530 if EncapsulatedIntentCheck( main, tag=encap ):
531 main.assertReturnString += 'Encapsulation intents check Passed\n'
532 else:
533 main.assertReturnString += 'Encapsulation intents check failed\n'
alisonda157272016-12-22 01:13:21 -0800534
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700535 if flowDuration( main ):
536 main.assertReturnString += 'Flow duration check Passed\n'
537 return intentId
538 else:
539 main.assertReturnString += 'Flow duration check failed\n'
540 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -0700541 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800542 main.log.error( "Point Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700543 pointIntentFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800544 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700545
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700546def pointIntentTcp( main,
547 name,
548 host1,
549 host2,
550 onosNode=0,
551 deviceId1="",
552 deviceId2="",
553 port1="",
554 port2="",
555 ethType="",
556 mac1="",
557 mac2="",
558 bandwidth="",
559 lambdaAlloc=False,
560 ipProto="",
561 ip1="",
562 ip2="",
563 tcp1="",
564 tcp2="",
565 sw1="",
566 sw2="",
567 expectedLink=0 ):
568
569 """
570 Description:
571 Verify add-point-intent only for TCP
572 Steps:
573 - Get device ids | ports
574 - Add point intents
575 - Check intents
576 - Verify flows
577 - Ping hosts
578 - Reroute
579 - Link down
580 - Verify flows
581 - Check topology
582 - Ping hosts
583 - Link up
584 - Verify flows
585 - Check topology
586 - Ping hosts
587 - Remove intents
588 Required:
589 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
590 host1 - Name of first host
591 host2 - Name of second host
592 Optional:
593 onosNode - ONOS node to install the intents in main.CLIs[ ]
594 0 by default so that it will always use the first
595 ONOS node
596 deviceId1 - ONOS device id of the first switch, the same as the
597 location of the first host eg. of:0000000000000001/1,
598 located at device 1 port 1
599 deviceId2 - ONOS device id of the second switch
600 port1 - The port number where the first host is attached
601 port2 - The port number where the second host is attached
602 ethType - Ethernet type eg. IPV4, IPV6
603 mac1 - Mac address of first host
604 mac2 - Mac address of the second host
605 bandwidth - Bandwidth capacity
606 lambdaAlloc - Allocate lambda, defaults to False
607 ipProto - IP protocol
608 ip1 - IP address of first host
609 ip2 - IP address of second host
610 tcp1 - TCP port of first host
611 tcp2 - TCP port of second host
612 sw1 - First switch to bring down & up for rerouting purpose
613 sw2 - Second switch to bring down & up for rerouting purpose
614 expectedLink - Expected link when the switches are down, it should
615 be two links lower than the links before the two
616 switches are down
617 """
618
619 assert main, "There is no main variable"
620 assert name, "variable name is empty"
621 assert host1 and host2, "You must specify hosts"
622
623 global itemName
624 itemName = name
625 host1 = host1
626 host2 = host2
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700627 intentsId = []
628
629 iperfResult = main.TRUE
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700630 linkDownResult = main.TRUE
631 linkUpResult = main.TRUE
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700632
633 # Adding bidirectional point intents
634 main.log.info( itemName + ": Adding point intents" )
635 intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
636 egressDevice=deviceId2,
637 portIngress=port1,
638 portEgress=port2,
639 ethType=ethType,
640 ethSrc=mac1,
641 ethDst=mac2,
642 bandwidth=bandwidth,
643 lambdaAlloc=lambdaAlloc,
644 ipProto=ipProto,
645 ipSrc=ip1,
646 ipDst=ip2,
647 tcpSrc=tcp1,
648 tcpDst="" )
649
650 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
651 egressDevice=deviceId1,
652 portIngress=port2,
653 portEgress=port1,
654 ethType=ethType,
655 ethSrc=mac2,
656 ethDst=mac1,
657 bandwidth=bandwidth,
658 lambdaAlloc=lambdaAlloc,
659 ipProto=ipProto,
660 ipSrc=ip2,
661 ipDst=ip1,
662 tcpSrc=tcp2,
663 tcpDst="" )
664
665 intent3 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
666 egressDevice=deviceId2,
667 portIngress=port1,
668 portEgress=port2,
669 ethType=ethType,
670 ethSrc=mac1,
671 ethDst=mac2,
672 bandwidth=bandwidth,
673 lambdaAlloc=lambdaAlloc,
674 ipProto=ipProto,
675 ipSrc=ip1,
676 ipDst=ip2,
677 tcpSrc="",
678 tcpDst=tcp2 )
679
680 intent4 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
681 egressDevice=deviceId1,
682 portIngress=port2,
683 portEgress=port1,
684 ethType=ethType,
685 ethSrc=mac2,
686 ethDst=mac1,
687 bandwidth=bandwidth,
688 lambdaAlloc=lambdaAlloc,
689 ipProto=ipProto,
690 ipSrc=ip2,
691 ipDst=ip1,
692 tcpSrc="",
693 tcpDst=tcp1 )
694 intentsId.append( intent1 )
695 intentsId.append( intent2 )
696 intentsId.append( intent3 )
697 intentsId.append( intent4 )
698
699 # Check intents state
Jon Hallf539eb92017-05-22 17:18:42 -0700700 main.log.info( "Sleeping {} seconds".format( main.checkIntentSleep ) )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700701 time.sleep( main.checkIntentSleep )
Jon Hallaf95c3e2017-05-16 13:20:37 -0700702 intentResult = utilities.retry( f=checkIntentState,
703 retValue=main.FALSE,
704 args=( main, intentsId ),
705 sleep=1,
706 attempts=50 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700707 # Check flows count in each node
708 checkFlowsCount( main )
709
710 # Check intents state again if first check fails...
711 if not intentResult:
Jon Hallaf95c3e2017-05-16 13:20:37 -0700712 intentResult = utilities.retry( f=checkIntentState,
713 retValue=main.FALSE,
714 args=( main, intentsId ),
715 sleep=1,
716 attempts=50 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700717
718 # Check flows count in each node
719 checkFlowsCount( main )
720
721 # Verify flows
722 checkFlowsState( main )
723
724 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700725 iperfTemp = main.Mininet1.iperftcp( host1, host2 ,10 )
acsmarsd4862d12015-10-06 17:57:34 -0700726 iperfResult = iperfResult and iperfTemp
727 if iperfTemp:
728 main.assertReturnString += 'Initial Iperf Passed\n'
729 else:
730 main.assertReturnString += 'Initial Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700731
732 # Test rerouting if these variables exist
733 if sw1 and sw2 and expectedLink:
734 # link down
735 linkDownResult = link( main, sw1, sw2, "down" )
acsmarsd4862d12015-10-06 17:57:34 -0700736
737 if linkDownResult:
738 main.assertReturnString += 'Link Down Passed\n'
739 else:
740 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700741
742 # Check flows count in each node
743 checkFlowsCount( main )
744 # Verify flows
745 checkFlowsState( main )
746
747 # Check OnosTopology
748 topoResult = checkTopology( main, expectedLink )
acsmarsd4862d12015-10-06 17:57:34 -0700749 if topoResult:
750 main.assertReturnString += 'Link Down Topology State Passed\n'
751 else:
752 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700753
754 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700755 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700756 iperfResult = iperfResult and iperfTemp
757 if iperfTemp:
758 main.assertReturnString += 'Link Down Iperf Passed\n'
759 else:
760 main.assertReturnString += 'Link Down Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700761
acsmarsd4862d12015-10-06 17:57:34 -0700762 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700763 intentTemp = utilities.retry( f=checkIntentState,
764 retValue=main.FALSE,
765 args=( main, intentsId ),
766 sleep=1,
767 attempts=50 )
acsmarsd4862d12015-10-06 17:57:34 -0700768 intentResult = intentResult and intentTemp
769 if intentTemp:
770 main.assertReturnString += 'Link Down Intent State Passed\n'
771 else:
772 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700773
774 # Checks ONOS state in link down
775 if linkDownResult and topoResult and iperfResult and intentResult:
776 main.log.info( itemName + ": Successfully brought link down" )
777 else:
778 main.log.error( itemName + ": Failed to bring link down" )
779
780 # link up
781 linkUpResult = link( main, sw1, sw2, "up" )
alison52b25892016-09-19 10:53:48 -0700782 if linkUpResult:
acsmarsd4862d12015-10-06 17:57:34 -0700783 main.assertReturnString += 'Link Up Passed\n'
784 else:
785 main.assertReturnString += 'Link Up Failed\n'
786
Jon Hallf539eb92017-05-22 17:18:42 -0700787 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700788 time.sleep( main.rerouteSleep )
789
790 # Check flows count in each node
791 checkFlowsCount( main )
792 # Verify flows
793 checkFlowsState( main )
794
795 # Check OnosTopology
796 topoResult = checkTopology( main, main.numLinks )
797
acsmarsd4862d12015-10-06 17:57:34 -0700798 if topoResult:
799 main.assertReturnString += 'Link Up Topology State Passed\n'
800 else:
801 main.assertReturnString += 'Link Up Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700802
acsmarsd4862d12015-10-06 17:57:34 -0700803 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700804 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700805 iperfResult = iperfResult and iperfTemp
806 if iperfTemp:
807 main.assertReturnString += 'Link Up Iperf Passed\n'
808 else:
809 main.assertReturnString += 'Link Up Iperf Failed\n'
810
811 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700812 intentTemp = utilities.retry( f=checkIntentState,
813 retValue=main.FALSE,
814 args=( main, intentsId ),
815 sleep=1,
816 attempts=50 )
acsmarsd4862d12015-10-06 17:57:34 -0700817 intentResult = intentResult and intentTemp
818 if intentTemp:
819 main.assertReturnString += 'Link Down Intent State Passed\n'
820 else:
821 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700822
823 # Checks ONOS state in link up
824 if linkUpResult and topoResult and iperfResult and intentResult:
825 main.log.info( itemName + ": Successfully brought link back up" )
826 else:
827 main.log.error( itemName + ": Failed to bring link back up" )
828
829 # Remove all intents
830 removeIntentResult = removeAllIntents( main, intentsId )
acsmarsd4862d12015-10-06 17:57:34 -0700831 if removeIntentResult:
832 main.assertReturnString += 'Remove Intents Passed'
833 else:
834 main.assertReturnString += 'Remove Intents Failed'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700835
836 stepResult = iperfResult and linkDownResult and linkUpResult \
837 and intentResult and removeIntentResult
838
839 return stepResult
840
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800841def installSingleToMultiIntent( main,
842 name,
843 senders,
844 recipients,
845 onosNode=0,
846 ethType="",
847 bandwidth="",
848 lambdaAlloc=False,
849 ipProto="",
850 ipAddresses="",
851 tcp="",
852 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700853 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -0700854 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700855 partial=False,
Jon Hallf539eb92017-05-22 17:18:42 -0700856 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700857 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800858 Installs a Single to Multi Point Intent
859
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700860 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800861 Install a single to multi point intent using
862 add-single-to-multi-intent
863
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700864 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800865 - Fetch host data if not given
866 - Add single to multi intent
867 - Ingress device is the first sender host
868 - Egress devices are the recipient devices
869 - Ports if defined in senders or recipients
870 - MAC address ethSrc loaded from Ingress device
871 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700872 Required:
873 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800874 senders - List of host dictionaries i.e.
875 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
876 recipients - List of host dictionaries i.e.
877 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700878 Optional:
879 onosNode - ONOS node to install the intents in main.CLIs[ ]
880 0 by default so that it will always use the first
881 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700882 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700883 bandwidth - Bandwidth capacity
884 lambdaAlloc - Allocate lambda, defaults to False
885 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700886 tcp - TCP ports in the same order as the hosts in hostNames
887 sw1 - First switch to bring down & up for rerouting purpose
888 sw2 - Second switch to bring down & up for rerouting purpose
889 expectedLink - Expected link when the switches are down, it should
890 be two links lower than the links before the two
891 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700892 """
893
894 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800895 assert senders, "You must specify a sender"
896 assert recipients, "You must specify a recipient"
897 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700898
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800899 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700900 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700901
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700902 global singleToMultiFailFlag
903 singleToMultiFailFlag = False
904
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700905 main.log.info( itemName + ": Adding single point to multi point intents" )
906
Jeremyd9e4eb12016-04-13 12:09:06 -0700907 try:
908 for sender in senders:
909 if not sender.get( "device" ):
910 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
911 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700912
Jeremyd9e4eb12016-04-13 12:09:06 -0700913 for recipient in recipients:
914 if not recipient.get( "device" ):
915 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
916 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700917
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700918
Jeremyd9e4eb12016-04-13 12:09:06 -0700919 ingressDevice = senders[ 0 ].get( "device" )
920 egressDeviceList = [ x.get( "device" ) for x in recipients if x.get( "device" ) ]
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800921
Jeremyd9e4eb12016-04-13 12:09:06 -0700922 portIngress = senders[ 0 ].get( "port", "" )
923 portEgressList = [ x.get( "port" ) for x in recipients if x.get( "port" ) ]
924 if not portEgressList:
925 portEgressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800926
Jeremyd9e4eb12016-04-13 12:09:06 -0700927 srcMac = senders[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700928 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800929
Jeremyd9e4eb12016-04-13 12:09:06 -0700930 # Adding point intent
931 intentId = main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
932 ingressDevice=ingressDevice,
933 egressDeviceList=egressDeviceList,
934 portIngress=portIngress,
935 portEgressList=portEgressList,
936 ethType=ethType,
937 ethSrc=srcMac,
938 bandwidth=bandwidth,
939 lambdaAlloc=lambdaAlloc,
940 ipProto=ipProto,
941 ipSrc="",
942 ipDst="",
943 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -0700944 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700945 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -0700946 setVlan=setVlan,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700947 partial=partial,
948 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700949 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700950 errorMsg = "There was a problem loading the hosts data."
951 if intentId:
952 errorMsg += " There was a problem installing Singlepoint to Multipoint intent."
953 main.log.error( errorMsg )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700954 singleToMultiFailFlag = True
Jeremyd9e4eb12016-04-13 12:09:06 -0700955 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700956
957 # Check intents state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700958 if singleToMultiFailFlag:
959 attempts = 5
960 else:
961 attempts = 50
962
Jon Hallaf95c3e2017-05-16 13:20:37 -0700963 if utilities.retry( f=checkIntentState,
964 retValue=main.FALSE,
Jon Hallf539eb92017-05-22 17:18:42 -0700965 args=( main, [ intentId ] ),
Jon Hallaf95c3e2017-05-16 13:20:37 -0700966 sleep=main.checkIntentSleep,
967 attempts=attempts ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700968 main.assertReturnString += 'Install Intent State Passed\n'
Jon Hallf539eb92017-05-22 17:18:42 -0700969 if bandwidth != "":
970 allocationsFile = open( os.path.dirname( main.testFile ) + main.params[ 'DEPENDENCY' ][ 'filePath' ], 'r' )
971 expectedFormat = allocationsFile.read()
972 bandwidthCheck = checkBandwidthAllocations( main, expectedFormat )
973 allocationsFile.close()
974 if bandwidthCheck:
975 main.assertReturnString += 'Bandwidth Allocation check Passed\n'
976 else:
977 main.assertReturnString += 'Bandwidth Allocation check Failed\n'
Jon Hallc3f88af2017-05-23 11:25:54 -0700978 return main.FALSE
979
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700980 if flowDuration( main ):
981 main.assertReturnString += 'Flow duration check Passed\n'
982 return intentId
983 else:
984 main.assertReturnString += 'Flow duration check failed\n'
985 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -0700986 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800987 main.log.error( "Single to Multi Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700988 singleToMultiFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800989 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700990
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800991def installMultiToSingleIntent( main,
992 name,
993 senders,
994 recipients,
995 onosNode=0,
996 ethType="",
997 bandwidth="",
998 lambdaAlloc=False,
999 ipProto="",
1000 ipAddresses="",
1001 tcp="",
1002 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -07001003 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -07001004 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -07001005 partial=False,
Jon Hallf539eb92017-05-22 17:18:42 -07001006 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001007 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001008 Installs a Multi to Single Point Intent
1009
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001010 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001011 Install a multi to single point intent using
1012 add-multi-to-single-intent
1013
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001014 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001015 - Fetch host data if not given
1016 - Add multi to single intent
1017 - Ingress devices are the senders devices
1018 - Egress device is the first recipient host
1019 - Ports if defined in senders or recipients
1020 - MAC address ethSrc loaded from Ingress device
1021 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001022 Required:
1023 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001024 senders - List of host dictionaries i.e.
1025 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
1026 recipients - List of host dictionaries i.e.
1027 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001028 Optional:
1029 onosNode - ONOS node to install the intents in main.CLIs[ ]
1030 0 by default so that it will always use the first
1031 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001032 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001033 bandwidth - Bandwidth capacity
1034 lambdaAlloc - Allocate lambda, defaults to False
1035 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001036 tcp - TCP ports in the same order as the hosts in hostNames
1037 sw1 - First switch to bring down & up for rerouting purpose
1038 sw2 - Second switch to bring down & up for rerouting purpose
1039 expectedLink - Expected link when the switches are down, it should
1040 be two links lower than the links before the two
1041 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001042 """
1043
1044 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001045 assert senders, "You must specify a sender"
1046 assert recipients, "You must specify a recipient"
1047 # Assert devices or main.hostsData, "You must specify devices"
1048
1049 global itemName # The name of this run. Used for logs.
1050 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001051
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001052 global multiToSingleFailFlag
1053 multiToSingleFailFlag = False
1054
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001055 main.log.info( itemName + ": Adding mutli to single point intents" )
1056
Jeremyd9e4eb12016-04-13 12:09:06 -07001057 try:
1058 for sender in senders:
1059 if not sender.get( "device" ):
1060 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1061 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001062
Jeremyd9e4eb12016-04-13 12:09:06 -07001063 for recipient in recipients:
1064 if not recipient.get( "device" ):
1065 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1066 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001067
Jeremyd9e4eb12016-04-13 12:09:06 -07001068 ingressDeviceList = [ x.get( "device" ) for x in senders if x.get( "device" ) ]
1069 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001070
Jeremyd9e4eb12016-04-13 12:09:06 -07001071 portIngressList = [ x.get( "port" ) for x in senders if x.get( "port" ) ]
1072 portEgress = recipients[ 0 ].get( "port", "" )
1073 if not portIngressList:
1074 portIngressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001075
Jeremyd9e4eb12016-04-13 12:09:06 -07001076 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001077 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001078
Jeremyd9e4eb12016-04-13 12:09:06 -07001079 # Adding point intent
1080 intentId = main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
1081 ingressDeviceList=ingressDeviceList,
1082 egressDevice=egressDevice,
1083 portIngressList=portIngressList,
1084 portEgress=portEgress,
1085 ethType=ethType,
1086 ethDst=dstMac,
1087 bandwidth=bandwidth,
1088 lambdaAlloc=lambdaAlloc,
1089 ipProto=ipProto,
1090 ipSrc="",
1091 ipDst="",
1092 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -07001093 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -07001094 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -07001095 setVlan=setVlan,
Jeremy Songsterc032f162016-08-04 17:14:49 -07001096 partial=partial,
1097 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001098 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001099 errorMsg = "There was a problem loading the hosts data."
1100 if intentId:
1101 errorMsg += " There was a problem installing Multipoint to Singlepoint intent."
1102 main.log.error( errorMsg )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001103 multiToSingleFailFlag = True
Jeremyd9e4eb12016-04-13 12:09:06 -07001104 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001105
1106 # Check intents state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001107 if multiToSingleFailFlag:
1108 attempts = 5
1109 else:
1110 attempts = 50
1111
Jon Hallaf95c3e2017-05-16 13:20:37 -07001112 if utilities.retry( f=checkIntentState,
1113 retValue=main.FALSE,
Jon Hallf539eb92017-05-22 17:18:42 -07001114 args=( main, [ intentId ] ),
Jon Hallaf95c3e2017-05-16 13:20:37 -07001115 sleep=main.checkIntentSleep,
1116 attempts=attempts ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001117 main.assertReturnString += 'Install Intent State Passed\n'
Jon Hallf539eb92017-05-22 17:18:42 -07001118 if bandwidth != "":
1119 allocationsFile = open( os.path.dirname( main.testFile ) + main.params[ 'DEPENDENCY' ][ 'filePath' ], 'r' )
1120 expectedFormat = allocationsFile.read()
1121 bandwidthCheck = checkBandwidthAllocations( main, expectedFormat )
1122 allocationsFile.close()
1123 if bandwidthCheck:
1124 main.assertReturnString += 'Bandwidth Allocation check Passed\n'
1125 else:
1126 main.assertReturnString += 'Bandwidth Allocation check Failed\n'
Jon Hallc3f88af2017-05-23 11:25:54 -07001127 return main.FALSE
1128
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001129 if flowDuration( main ):
1130 main.assertReturnString += 'Flow duration check Passed\n'
1131 return intentId
1132 else:
1133 main.assertReturnString += 'Flow duration check failed\n'
1134 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001135 else:
1136 main.log.error( "Multi to Single Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001137 multiToSingleFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001138 return main.FALSE
1139
1140def testPointIntent( main,
Jeremye0cb5eb2016-01-27 17:39:09 -08001141 name,
1142 intentId,
1143 senders,
1144 recipients,
1145 badSenders={},
1146 badRecipients={},
1147 onosNode=0,
1148 ethType="",
1149 bandwidth="",
1150 lambdaAlloc=False,
alisonda157272016-12-22 01:13:21 -08001151 protected=False,
Jeremye0cb5eb2016-01-27 17:39:09 -08001152 ipProto="",
1153 ipAddresses="",
1154 tcp="",
1155 sw1="s5",
1156 sw2="s2",
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001157 expectedLink=0,
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001158 useTCP=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001159 """
1160 Test a Point Intent
1161
1162 Description:
1163 Test a point intent
1164
1165 Steps:
1166 - Fetch host data if not given
1167 - Check Intent State
1168 - Check Flow State
1169 - Check Connectivity
1170 - Check Lack of Connectivity Between Hosts not in the Intent
1171 - Reroute
1172 - Take Expected Link Down
1173 - Check Intent State
1174 - Check Flow State
1175 - Check Topology
1176 - Check Connectivity
1177 - Bring Expected Link Up
1178 - Check Intent State
1179 - Check Flow State
1180 - Check Topology
1181 - Check Connectivity
1182 - Remove Topology
1183
1184 Required:
1185 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
1186
1187 senders - List of host dictionaries i.e.
1188 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
1189 recipients - List of host dictionaries i.e.
1190 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
1191 Optional:
1192 onosNode - ONOS node to install the intents in main.CLIs[ ]
1193 0 by default so that it will always use the first
1194 ONOS node
1195 ethType - Ethernet type eg. IPV4, IPV6
1196 bandwidth - Bandwidth capacity
1197 lambdaAlloc - Allocate lambda, defaults to False
1198 ipProto - IP protocol
1199 tcp - TCP ports in the same order as the hosts in hostNames
1200 sw1 - First switch to bring down & up for rerouting purpose
1201 sw2 - Second switch to bring down & up for rerouting purpose
1202 expectedLink - Expected link when the switches are down, it should
1203 be two links lower than the links before the two
1204 switches are down
1205
1206 """
1207
1208 # Parameter Validity Check
1209 assert main, "There is no main variable"
1210 assert senders, "You must specify a sender"
1211 assert recipients, "You must specify a recipient"
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001212
1213 global itemName
1214 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001215
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001216 global pointIntentFailFlag
1217 global singleToMultiFailFlag
1218 global multiToSingleFailFlag
1219
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001220 main.log.info( itemName + ": Testing Point Intent" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001221
Jeremyd9e4eb12016-04-13 12:09:06 -07001222 try:
1223 # Names for scapy
1224 senderNames = [ x.get( "name" ) for x in senders ]
1225 recipientNames = [ x.get( "name" ) for x in recipients ]
1226 badSenderNames = [ x.get( "name" ) for x in badSenders ]
1227 badRecipientNames = [ x.get( "name" ) for x in badRecipients ]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001228
Jeremyd9e4eb12016-04-13 12:09:06 -07001229 for sender in senders:
1230 if not sender.get( "device" ):
1231 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1232 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001233
Jeremyd9e4eb12016-04-13 12:09:06 -07001234 for recipient in recipients:
1235 if not recipient.get( "device" ):
1236 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1237 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001238 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001239 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001240 main.log.error( "There was a problem loading the hosts data." )
1241 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001242
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001243 testResult = main.TRUE
1244 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001245
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001246 if pointIntentFailFlag or singleToMultiFailFlag or multiToSingleFailFlag:
1247 attempts = 1
1248 else:
1249 attempts = 50
1250
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001251 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001252 if utilities.retry( f=checkIntentState,
1253 retValue=main.FALSE,
1254 args=( main, [ intentId ] ),
1255 sleep=main.checkIntentSleep,
1256 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001257 main.assertReturnString += 'Initial Intent State Passed\n'
acsmarsd4862d12015-10-06 17:57:34 -07001258 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001259 main.assertReturnString += 'Initial Intent State Failed\n'
1260 testResult = main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001261 attempts = 1
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001262
1263 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001264 if utilities.retry( f=checkFlowsCount,
1265 retValue=main.FALSE,
1266 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001267 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001268 attempts=3 ) and utilities.retry( f=checkFlowsState,
1269 retValue=main.FALSE,
1270 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001271 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001272 attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001273 main.assertReturnString += 'Initial Flow State Passed\n'
1274 else:
1275 main.assertReturnString += 'Intial Flow State Failed\n'
1276 testResult = main.FALSE
1277
1278 # Check Connectivity
Jon Hallaf95c3e2017-05-16 13:20:37 -07001279 if utilities.retry( f=scapyCheckConnection,
1280 retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -07001281 args=( main, senderNames, recipientNames, vlanId, useTCP ),
Jon Hallaf95c3e2017-05-16 13:20:37 -07001282 attempts=attempts,
1283 sleep=main.checkConnectionSleep ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001284 main.assertReturnString += 'Initial Ping Passed\n'
1285 else:
1286 main.assertReturnString += 'Initial Ping Failed\n'
1287 testResult = main.FALSE
1288
1289 # Check connections that shouldn't work
1290 if badSenderNames:
1291 main.log.info( "Checking that packets from incorrect sender do not go through" )
Jon Hallaf95c3e2017-05-16 13:20:37 -07001292 if utilities.retry( f=scapyCheckConnection,
1293 retValue=main.FALSE,
1294 args=( main, badSenderNames, recipientNames ),
1295 kwargs={ "expectFailure":True } ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001296 main.assertReturnString += 'Bad Sender Ping Passed\n'
1297 else:
1298 main.assertReturnString += 'Bad Sender Ping Failed\n'
1299 testResult = main.FALSE
1300
1301 if badRecipientNames:
1302 main.log.info( "Checking that packets to incorrect recipients do not go through" )
Jon Hallaf95c3e2017-05-16 13:20:37 -07001303 if utilities.retry( f=scapyCheckConnection,
1304 retValue=main.FALSE,
1305 args=( main, senderNames, badRecipientNames ),
1306 kwargs={ "expectFailure":True } ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001307 main.assertReturnString += 'Bad Recipient Ping Passed\n'
1308 else:
1309 main.assertReturnString += 'Bad Recipient Ping Failed\n'
1310 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001311
1312 # Test rerouting if these variables exist
1313 if sw1 and sw2 and expectedLink:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001314 # Take link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001315 if utilities.retry( f=link,
1316 retValue=main.FALSE,
1317 args=( main, sw1, sw2, "down" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001318 main.assertReturnString += 'Link Down Passed\n'
1319 else:
1320 main.assertReturnString += 'Link Down Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001321 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001322
alisonda157272016-12-22 01:13:21 -08001323 if protected:
1324 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001325 if utilities.retry( f=scapyCheckConnection,
1326 retValue=main.FALSE,
1327 args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
alisonda157272016-12-22 01:13:21 -08001328 main.assertReturnString += 'Link down Scapy Packet Received Passed\n'
1329 else:
1330 main.assertReturnString += 'Link down Scapy Packet Recieved Failed\n'
1331 testResult = main.FALSE
1332
1333 if ProtectedIntentCheck( main ):
1334 main.assertReturnString += 'Protected Intent Check Passed\n'
1335 else:
1336 main.assertReturnString += 'Protected Intent Check Failed\n'
1337 testResult = main.FALSE
1338
acsmarsd4862d12015-10-06 17:57:34 -07001339 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001340 if utilities.retry( f=checkIntentState,
1341 retValue=main.FALSE,
1342 args=( main, [ intentId ] ),
1343 sleep=main.checkIntentPointSleep,
1344 attempts=attempts ):
acsmarsd4862d12015-10-06 17:57:34 -07001345 main.assertReturnString += 'Link Down Intent State Passed\n'
1346 else:
1347 main.assertReturnString += 'Link Down Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001348 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001349
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001350 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001351 if utilities.retry( f=checkFlowsCount,
1352 retValue=main.FALSE,
1353 args=[ main ],
1354 sleep=main.checkFlowCountSleep,
1355 attempts=attempts * 2 ) and utilities.retry( f=checkFlowsState,
1356 retValue=main.FALSE,
1357 args=[ main ],
1358 sleep=main.checkFlowCountSleep,
1359 attempts=attempts * 2 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001360 main.assertReturnString += 'Link Down Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001361 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001362 main.assertReturnString += 'Link Down Flow State Failed\n'
1363 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001364
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001365 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001366 if utilities.retry( f=checkTopology,
1367 retValue=main.FALSE,
1368 args=( main, expectedLink ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001369 main.assertReturnString += 'Link Down Topology State Passed\n'
1370 else:
1371 main.assertReturnString += 'Link Down Topology State Failed\n'
1372 testResult = main.FALSE
1373
1374 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001375 if utilities.retry( f=scapyCheckConnection,
1376 retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -07001377 args=( main, senderNames, recipientNames, vlanId, useTCP ),
Jon Hallaf95c3e2017-05-16 13:20:37 -07001378 sleep=main.checkConnectionSleep,
1379 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001380 main.assertReturnString += 'Link Down Pingall Passed\n'
1381 else:
1382 main.assertReturnString += 'Link Down Pingall Failed\n'
1383 testResult = main.FALSE
1384
1385 # Bring link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001386 if utilities.retry( f=link,
1387 retValue=main.FALSE,
1388 args=( main, sw1, sw2, "up" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001389 main.assertReturnString += 'Link Up Passed\n'
1390 else:
1391 main.assertReturnString += 'Link Up Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001392 testResult = main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -07001393
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001394 # Wait for reroute
Jon Hallf539eb92017-05-22 17:18:42 -07001395 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001396 time.sleep( main.rerouteSleep )
1397
acsmarsd4862d12015-10-06 17:57:34 -07001398 # Check Intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001399 if utilities.retry( f=checkIntentState,
1400 retValue=main.FALSE,
1401 attempts=attempts * 2,
1402 args=( main, [ intentId ] ),
Shreyaca8990f2017-03-16 11:43:11 -07001403 sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001404 main.assertReturnString += 'Link Up Intent State Passed\n'
1405 else:
1406 main.assertReturnString += 'Link Up Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001407 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001408
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001409 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001410 if utilities.retry( f=checkFlowsCount,
1411 retValue=main.FALSE,
1412 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001413 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001414 attempts=3 ) and utilities.retry( f=checkFlowsState,
1415 retValue=main.FALSE,
1416 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001417 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001418 attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001419 main.assertReturnString += 'Link Up Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001420 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001421 main.assertReturnString += 'Link Up Flow State Failed\n'
1422 testResult = main.FALSE
1423
1424 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001425 if utilities.retry( f=checkTopology,
1426 retValue=main.FALSE,
1427 args=( main, main.numLinks ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001428 main.assertReturnString += 'Link Up Topology State Passed\n'
1429 else:
1430 main.assertReturnString += 'Link Up Topology State Failed\n'
1431 testResult = main.FALSE
1432
1433 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001434 if utilities.retry( f=scapyCheckConnection,
1435 retValue=main.FALSE,
1436 sleep=main.checkConnectionSleep,
1437 attempts=100,
Shreyaca8990f2017-03-16 11:43:11 -07001438 args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001439 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1440 else:
1441 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1442 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001443
1444 # Remove all intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001445 if utilities.retry( f=removeAllIntents,
1446 retValue=main.FALSE,
1447 attempts=10,
1448 args=( main, [ intentId ] ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001449 main.assertReturnString += 'Remove Intents Passed'
1450 else:
1451 main.assertReturnString += 'Remove Intents Failed'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001452 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001453
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001454 return testResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001455
Jeremye0cb5eb2016-01-27 17:39:09 -08001456def testEndPointFail( main,
1457 name,
1458 intentId,
1459 senders,
1460 recipients,
1461 isolatedSenders,
1462 isolatedRecipients,
1463 onosNode=0,
1464 ethType="",
1465 bandwidth="",
1466 lambdaAlloc=False,
1467 ipProto="",
1468 ipAddresses="",
1469 tcp="",
1470 sw1="",
1471 sw2="",
1472 sw3="",
1473 sw4="",
1474 sw5="",
1475 expectedLink1=0,
Jeremy Songster9385d412016-06-02 17:57:36 -07001476 expectedLink2=0,
1477 partial=False ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001478 """
Shreyaca8990f2017-03-16 11:43:11 -07001479 Test Multi point to single point intent Topology for Endpoint failures
Jeremye0cb5eb2016-01-27 17:39:09 -08001480 """
1481
1482 # Parameter Validity Check
1483 assert main, "There is no main variable"
1484 assert senders, "You must specify a sender"
1485 assert recipients, "You must specify a recipient"
1486
1487 global itemName
1488 itemName = name
Jeremye0cb5eb2016-01-27 17:39:09 -08001489
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001490 global singleToMultiFailFlag
1491 global multiToSingleFailFlag
1492
Jeremye0cb5eb2016-01-27 17:39:09 -08001493 main.log.info( itemName + ": Testing Point Intent" )
1494
Jeremyd9e4eb12016-04-13 12:09:06 -07001495 try:
1496 # Names for scapy
1497 senderNames = [ x.get( "name" ) for x in senders ]
1498 recipientNames = [ x.get( "name" ) for x in recipients ]
1499 isolatedSenderNames = [ x.get( "name" ) for x in isolatedSenders ]
1500 isolatedRecipientNames = [ x.get( "name" ) for x in isolatedRecipients ]
1501 connectedSenderNames = [x.get("name") for x in senders if x.get("name") not in isolatedSenderNames]
1502 connectedRecipientNames = [x.get("name") for x in recipients if x.get("name") not in isolatedRecipientNames]
Jeremye0cb5eb2016-01-27 17:39:09 -08001503
Jeremyd9e4eb12016-04-13 12:09:06 -07001504 for sender in senders:
1505 if not sender.get( "device" ):
1506 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1507 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremye0cb5eb2016-01-27 17:39:09 -08001508
Jeremyd9e4eb12016-04-13 12:09:06 -07001509 for recipient in recipients:
1510 if not recipient.get( "device" ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001511 main.log.warn( "Device not given for recipient {0}. Loading from " +\
1512 main.hostData.format( recipient.get( "name" ) ) )
Jeremyd9e4eb12016-04-13 12:09:06 -07001513 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001514 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001515 main.log.error( "There was a problem loading the hosts data." )
1516 return main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001517
1518 testResult = main.TRUE
1519 main.log.info( itemName + ": Adding multi point to single point intents" )
1520
1521 # Check intent state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001522 if singleToMultiFailFlag or multiToSingleFailFlag:
1523 attempts = 1
1524 else:
1525 attempts = 50
1526
Jon Hallaf95c3e2017-05-16 13:20:37 -07001527 if utilities.retry( f=checkIntentState,
1528 retValue=main.FALSE,
1529 args=( main, [ intentId ] ),
1530 sleep=main.checkIntentSleep,
1531 attempts=attempts ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001532 main.assertReturnString += 'Initial Intent State Passed\n'
1533 else:
1534 main.assertReturnString += 'Initial Intent State Failed\n'
1535 testResult = main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001536 attempts = 1
Jeremye0cb5eb2016-01-27 17:39:09 -08001537
1538 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001539 if utilities.retry( f=checkFlowsCount,
1540 retValue=main.FALSE,
1541 args=[ main ],
1542 attempts=5 ) and utilities.retry( f=checkFlowsState,
1543 retValue=main.FALSE,
1544 args=[ main ],
1545 attempts=5 ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001546 main.assertReturnString += 'Initial Flow State Passed\n'
1547 else:
1548 main.assertReturnString += 'Intial Flow State Failed\n'
1549 testResult = main.FALSE
1550
1551 # Check Connectivity
Jon Hallaf95c3e2017-05-16 13:20:37 -07001552 if utilities.retry( f=scapyCheckConnection,
1553 retValue=main.FALSE,
Jeremye0cb5eb2016-01-27 17:39:09 -08001554 args=( main, senderNames, recipientNames ) ):
1555 main.assertReturnString += 'Initial Connectivity Check Passed\n'
1556 else:
1557 main.assertReturnString += 'Initial Connectivity Check Failed\n'
1558 testResult = main.FALSE
1559
1560 # Take two links down
1561 # Take first link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001562 if utilities.retry( f=link,
1563 retValue=main.FALSE,
1564 args=( main, sw1, sw2, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001565 main.assertReturnString += 'Link Down Passed\n'
1566 else:
1567 main.assertReturnString += 'Link Down Failed\n'
1568 testResult = main.FALSE
1569
1570 # Take second link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001571 if utilities.retry( f=link,
1572 retValue=main.FALSE,
1573 args=( main, sw3, sw4, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001574 main.assertReturnString += 'Link Down Passed\n'
1575 else:
1576 main.assertReturnString += 'Link Down Failed\n'
1577 testResult = main.FALSE
1578
1579 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001580 if utilities.retry( f=checkIntentState,
1581 retValue=main.FALSE,
1582 attempts=attempts,
1583 args=( main, [ intentId ] ),
1584 sleep=main.checkIntentSleep ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001585 main.assertReturnString += 'Link Down Intent State Passed\n'
1586 else:
1587 main.assertReturnString += 'Link Down Intent State Failed\n'
1588 testResult = main.FALSE
1589
1590 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001591 if utilities.retry( f=checkFlowsCount,
1592 retValue=main.FALSE,
1593 sleep=1,
1594 attempts=attempts,
Jeremye0cb5eb2016-01-27 17:39:09 -08001595 args=[ main ] ) and utilities.retry( f=checkFlowsState,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001596 retValue=main.FALSE,
1597 sleep=1,
1598 attempts=attempts,
1599 args=[ main ] ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001600 main.assertReturnString += 'Link Down Flow State Passed\n'
1601 else:
1602 main.assertReturnString += 'Link Down Flow State Failed\n'
1603 testResult = main.FALSE
1604
1605 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001606 if utilities.retry( f=checkTopology,
1607 retValue=main.FALSE,
1608 args=( main, expectedLink1 ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001609 main.assertReturnString += 'Link Down Topology State Passed\n'
1610 else:
1611 main.assertReturnString += 'Link Down Topology State Failed\n'
1612 testResult = main.FALSE
1613
1614 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001615 if utilities.retry( f=scapyCheckConnection,
1616 retValue=main.FALSE,
Jeremye0cb5eb2016-01-27 17:39:09 -08001617 args=( main, senderNames, recipientNames ) ):
1618 main.assertReturnString += 'Link Down Connectivity Check Passed\n'
1619 else:
1620 main.assertReturnString += 'Link Down Connectivity Check Failed\n'
1621 testResult = main.FALSE
1622
1623 # Take a third link down to isolate one node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001624 if utilities.retry( f=link,
1625 retValue=main.FALSE,
1626 args=( main, sw3, sw5, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001627 main.assertReturnString += 'Isolation link Down Passed\n'
1628 else:
1629 main.assertReturnString += 'Isolation link Down Failed\n'
1630 testResult = main.FALSE
1631
Jeremy Songster9385d412016-06-02 17:57:36 -07001632 if partial:
1633 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001634 if utilities.retry( f=checkIntentState,
1635 retValue=main.FALSE,
1636 args=( main, [ intentId ] ),
1637 sleep=main.checkIntentSleep,
1638 attempts=attempts ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001639 main.assertReturnString += 'Partial failure isolation link Down Intent State Passed\n'
1640 else:
1641 main.assertReturnString += 'Partial failure isolation link Down Intent State Failed\n'
1642 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001643
Jeremy Songster9385d412016-06-02 17:57:36 -07001644 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001645 if utilities.retry( f=checkFlowsCount,
1646 retValue=main.FALSE,
1647 args=[ main ],
1648 attempts=5 ) and utilities.retry( f=checkFlowsState,
1649 retValue=main.FALSE,
1650 args=[ main ],
1651 attempts=5 ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001652 main.assertReturnString += 'Partial failure isolation link Down Flow State Passed\n'
1653 else:
1654 main.assertReturnString += 'Partial failure isolation link Down Flow State Failed\n'
1655 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001656
Jeremy Songster9385d412016-06-02 17:57:36 -07001657 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001658 if utilities.retry( f=checkTopology,
1659 retValue=main.FALSE,
1660 args=( main, expectedLink2 ) ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001661 main.assertReturnString += 'Partial failure isolation link Down Topology State Passed\n'
1662 else:
1663 main.assertReturnString += 'Partial failure isolation link Down Topology State Failed\n'
1664 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001665
Jeremy Songster9385d412016-06-02 17:57:36 -07001666 # Check Connectivity
1667 # First check connectivity of any isolated senders to recipients
1668 if isolatedSenderNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001669 if scapyCheckConnection( main,
1670 isolatedSenderNames,
1671 recipientNames,
1672 None,
1673 None,
1674 None,
1675 None,
1676 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001677 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1678 else:
1679 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1680 testResult = main.FALSE
1681
1682 # Next check connectivity of senders to any isolated recipients
1683 if isolatedRecipientNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001684 if scapyCheckConnection( main,
1685 senderNames,
1686 isolatedRecipientNames,
1687 None,
1688 None,
1689 None,
1690 None,
1691 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001692 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1693 else:
1694 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1695 testResult = main.FALSE
1696
1697 # Next check connectivity of connected senders and recipients
Jon Hallaf95c3e2017-05-16 13:20:37 -07001698 if utilities.retry( f=scapyCheckConnection,
1699 retValue=main.FALSE,
1700 attempts=attempts,
Jeremy Songster9385d412016-06-02 17:57:36 -07001701 args=( main, connectedSenderNames , connectedRecipientNames ) ):
1702 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1703 else:
1704 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1705 testResult = main.FALSE
1706 else:
1707 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001708 if not utilities.retry( f=checkIntentState,
1709 retValue=main.TRUE,
1710 args=( main, [ intentId ] ),
1711 sleep=main.checkIntentSleep,
1712 attempts=attempts ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001713 main.assertReturnString += 'Isolation link Down Intent State Passed\n'
1714 else:
1715 main.assertReturnString += 'Isolation link Down Intent State Failed\n'
1716 testResult = main.FALSE
1717
1718 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001719 if utilities.retry( f=checkFlowsCount,
1720 retValue=main.FALSE,
1721 args=[ main ],
1722 attempts=5 ) and utilities.retry( f=checkFlowsState,
1723 retValue=main.FALSE,
1724 args=[ main ],
1725 attempts=5 ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001726 main.assertReturnString += 'Isolation link Down Flow State Passed\n'
1727 else:
1728 main.assertReturnString += 'Isolation link Down Flow State Failed\n'
1729 testResult = main.FALSE
1730
1731 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001732 if utilities.retry( f=checkTopology,
1733 retValue=main.FALSE,
1734 args=( main, expectedLink2 ) ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001735 main.assertReturnString += 'Isolation link Down Topology State Passed\n'
1736 else:
1737 main.assertReturnString += 'Isolation link Down Topology State Failed\n'
1738 testResult = main.FALSE
1739
1740 # Check Connectivity
1741 # First check connectivity of any isolated senders to recipients
1742 if isolatedSenderNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001743 if scapyCheckConnection( main,
1744 isolatedSenderNames,
1745 recipientNames,
1746 None,
1747 None,
1748 None,
1749 None,
1750 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001751 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1752 else:
1753 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1754 testResult = main.FALSE
1755
1756 # Next check connectivity of senders to any isolated recipients
1757 if isolatedRecipientNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001758 if scapyCheckConnection( main,
1759 senderNames,
1760 isolatedRecipientNames,
1761 None,
1762 None,
1763 None,
1764 None,
1765 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001766 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1767 else:
1768 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1769 testResult = main.FALSE
1770
1771 # Next check connectivity of connected senders and recipients
Jon Hallaf95c3e2017-05-16 13:20:37 -07001772 if utilities.retry( f=scapyCheckConnection,
1773 retValue=main.TRUE,
1774 args=( main, connectedSenderNames, connectedRecipientNames, None, None, None, None, main.TRUE ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001775 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1776 else:
1777 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1778 testResult = main.FALSE
1779
Jeremye0cb5eb2016-01-27 17:39:09 -08001780 # Bring the links back up
1781 # Bring first link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001782 if utilities.retry( f=link,
1783 retValue=main.FALSE,
1784 args=( main, sw1, sw2, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001785 main.assertReturnString += 'Link Up Passed\n'
1786 else:
1787 main.assertReturnString += 'Link Up Failed\n'
1788 testResult = main.FALSE
1789
1790 # Bring second link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001791 if utilities.retry( f=link,
1792 retValue=main.FALSE,
1793 args=( main, sw3, sw5, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001794 main.assertReturnString += 'Link Up Passed\n'
1795 else:
1796 main.assertReturnString += 'Link Up Failed\n'
1797 testResult = main.FALSE
1798
1799 # Bring third link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001800 if utilities.retry( f=link,
1801 retValue=main.FALSE,
1802 args=( main, sw3, sw4, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001803 main.assertReturnString += 'Link Up Passed\n'
1804 else:
1805 main.assertReturnString += 'Link Up Failed\n'
1806 testResult = main.FALSE
1807
1808 # Wait for reroute
Jon Hallf539eb92017-05-22 17:18:42 -07001809 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
Jeremye0cb5eb2016-01-27 17:39:09 -08001810 time.sleep( main.rerouteSleep )
1811
1812 # Check Intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001813 if utilities.retry( f=checkIntentState,
1814 retValue=main.FALSE,
1815 attempts=attempts,
1816 args=( main, [ intentId ] ),
1817 sleep=main.checkIntentHostSleep ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001818 main.assertReturnString += 'Link Up Intent State Passed\n'
1819 else:
1820 main.assertReturnString += 'Link Up Intent State Failed\n'
1821 testResult = main.FALSE
1822
1823 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001824 if utilities.retry( f=checkFlowsCount,
1825 retValue=main.FALSE,
1826 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001827 sleep=main.checkFlowCountSleep,
1828 attempts=attempts ) and utilities.retry( f=checkFlowsState,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001829 retValue=main.FALSE,
1830 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001831 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001832 attempts=attempts ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001833 main.assertReturnString += 'Link Up Flow State Passed\n'
1834 else:
1835 main.assertReturnString += 'Link Up Flow State Failed\n'
1836 testResult = main.FALSE
1837
1838 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001839 if utilities.retry( f=checkTopology,
1840 retValue=main.FALSE,
1841 args=( main, main.numLinks ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001842 main.assertReturnString += 'Link Up Topology State Passed\n'
1843 else:
1844 main.assertReturnString += 'Link Up Topology State Failed\n'
1845 testResult = main.FALSE
1846
1847 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001848 if utilities.retry( f=scapyCheckConnection,
1849 retValue=main.FALSE,
1850 sleep=main.checkConnectionSleep,
1851 attempts=attempts,
Jeremye0cb5eb2016-01-27 17:39:09 -08001852 args=( main, senderNames, recipientNames ) ):
1853 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1854 else:
1855 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1856 testResult = main.FALSE
1857
1858 # Remove all intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001859 if utilities.retry( f=removeAllIntents,
1860 retValue=main.FALSE,
1861 attempts=10,
1862 args=( main, [ intentId ] ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001863 main.assertReturnString += 'Remove Intents Passed'
1864 else:
1865 main.assertReturnString += 'Remove Intents Failed'
1866 testResult = main.FALSE
1867
1868 return testResult
1869
1870
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001871def pingallHosts( main, hostList ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001872 """
1873 Ping all host in the hosts list variable
1874 """
Jon Halla5cb3412015-08-18 14:08:22 -07001875 main.log.info( "Pinging: " + str( hostList ) )
1876 return main.Mininet1.pingallHosts( hostList )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001877
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001878def fwdPingall( main ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001879 """
1880 Use fwd app and pingall to discover all the hosts
1881 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001882 appCheck = main.TRUE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001883 main.log.info( "Activating reactive forwarding app " )
1884 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001885
1886 # Wait for forward app activation to propagate
Jon Hallf539eb92017-05-22 17:18:42 -07001887 main.log.info( "Sleeping {} seconds".format( main.fwdSleep ) )
kelvin-onlab0ad05d12015-07-23 14:21:15 -07001888 time.sleep( main.fwdSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001889
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001890 # Check that forwarding is enabled on all nodes
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001891 for i in range( main.numCtrls ):
1892 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
1893 if appCheck != main.TRUE:
1894 main.log.warn( main.CLIs[ i ].apps() )
1895 main.log.warn( main.CLIs[ i ].appIDs() )
1896
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001897 # Send pingall in mininet
1898 main.log.info( "Run Pingall" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001899 pingResult = main.Mininet1.pingall( timeout = 600 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001900
1901 main.log.info( "Deactivating reactive forwarding app " )
1902 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001903 if activateResult and deactivateResult:
1904 main.log.info( "Successfully used fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001905 getDataResult = main.TRUE
1906 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001907 main.log.info( "Failed to use fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001908 getDataResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001909 return getDataResult
1910
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001911def confirmHostDiscovery( main ):
1912 """
1913 Confirms that all ONOS nodes have discovered all scapy hosts
1914 """
1915 import collections
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001916 hosts = main.topo.getAllHosts( main ) # Get host data from each ONOS node
1917 hostFails = [] # Reset for each failed attempt
1918
1919 # Check for matching hosts on each node
1920 scapyHostIPs = [ x.hostIp for x in main.scapyHosts if x.hostIp != "0.0.0.0" ]
1921 for controller in range( main.numCtrls ):
1922 controllerStr = str( controller + 1 ) # ONOS node number
1923 # Compare Hosts
1924 # Load hosts data for controller node
Jeremyd9e4eb12016-04-13 12:09:06 -07001925 try:
1926 if hosts[ controller ]:
1927 main.log.info( "Hosts discovered" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001928 else:
Jeremyd9e4eb12016-04-13 12:09:06 -07001929 main.log.error( "Problem discovering hosts" )
1930 if hosts[ controller ] and "Error" not in hosts[ controller ]:
1931 try:
1932 hostData = json.loads( hosts[ controller ] )
1933 except ( TypeError, ValueError ):
1934 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001935 hostFails.append( controllerStr )
Jeremyd9e4eb12016-04-13 12:09:06 -07001936 else:
1937 onosHostIPs = [ x.get( "ipAddresses" )[ 0 ]
1938 for x in hostData
1939 if len( x.get( "ipAddresses" ) ) > 0 ]
1940 if not set( collections.Counter( scapyHostIPs ) ).issubset( set ( collections.Counter( onosHostIPs ) ) ):
1941 main.log.warn( "Controller {0} only sees nodes with {1} IPs. It should see all of the following: {2}".format( controllerStr, onosHostIPs, scapyHostIPs ) )
1942 hostFails.append( controllerStr )
1943 else:
1944 main.log.error( "Hosts returned nothing or an error." )
1945 hostFails.append( controllerStr )
1946 except IndexError:
1947 main.log.error( "Hosts returned nothing, Failed to discover hosts." )
1948 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001949
1950 if hostFails:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001951 main.log.error( "List of failed ONOS Nodes:" + ', '.join( map( str, hostFails ) ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001952 return main.FALSE
1953 else:
1954 return main.TRUE
1955
1956def sendDiscoveryArp( main, hosts=None ):
1957 """
1958 Sends Discovery ARP packets from each host provided
1959 Defaults to each host in main.scapyHosts
1960 """
1961 # Send an arp ping from each host
1962 if not hosts:
1963 hosts = main.scapyHosts
1964 for host in hosts:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001965 pkt = 'Ether( src="{0}")/ARP( psrc="{1}")'.format( host.hostMac, host.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001966 # Send from the VLAN interface if there is one so ONOS discovers the VLAN correctly
1967 iface = None
1968 for interface in host.getIfList():
1969 if '.' in interface:
1970 main.log.debug( "Detected VLAN interface {0}. Sending ARP packet from {0}".format( interface ) )
1971 iface = interface
1972 break
1973 host.sendPacket( packet=pkt, iface=iface )
1974 main.log.info( "Sending ARP packet from {0}".format( host.name ) )
1975
1976def populateHostData( main ):
1977 """
1978 Populates hostsData
1979 """
1980 import json
1981 try:
1982 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
1983 hosts = main.Mininet1.getHosts().keys()
1984 # TODO: Make better use of new getHosts function
1985 for host in hosts:
1986 main.hostsData[ host ] = {}
1987 main.hostsData[ host ][ 'mac' ] = \
1988 main.Mininet1.getMacAddress( host ).upper()
1989 for hostj in hostsJson:
1990 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
1991 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
1992 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
1993 main.hostsData[ host ][ 'location' ] = \
1994 hostj[ 'location' ][ 'elementId' ] + '/' + \
1995 hostj[ 'location' ][ 'port' ]
1996 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
1997 return main.TRUE
Jeremyd9e4eb12016-04-13 12:09:06 -07001998 except ValueError:
1999 main.log.error( "ValueError while populating hostsData" )
2000 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002001 except KeyError:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002002 main.log.error( "KeyError while populating hostsData" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002003 return main.FALSE
Jeremyd9e4eb12016-04-13 12:09:06 -07002004 except IndexError:
2005 main.log.error( "IndexError while populating hostsData" )
2006 return main.FALSE
2007 except TypeError:
2008 main.log.error( "TypeError while populating hostsData" )
2009 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002010
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002011def checkTopology( main, expectedLink ):
2012 statusResult = main.TRUE
2013 # Check onos topology
2014 main.log.info( itemName + ": Checking ONOS topology " )
2015
2016 for i in range( main.numCtrls ):
Flavio Castro82ee2f62016-06-07 15:04:12 -07002017 statusResult = main.CLIs[ i ].checkStatus( main.numSwitch,
Jon Hallaf95c3e2017-05-16 13:20:37 -07002018 expectedLink ) and statusResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002019 if not statusResult:
2020 main.log.error( itemName + ": Topology mismatch" )
2021 else:
2022 main.log.info( itemName + ": Topology match" )
2023 return statusResult
2024
Jon Hallf539eb92017-05-22 17:18:42 -07002025def checkIntentState( main, intentsId ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002026 """
2027 This function will check intent state to make sure all the intents
2028 are in INSTALLED state
Jon Hallf539eb92017-05-22 17:18:42 -07002029 Returns main.TRUE or main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002030 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002031 intentResult = main.TRUE
Jon Hallf539eb92017-05-22 17:18:42 -07002032 stateCheckResults = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002033 for i in range( main.numCtrls ):
Jon Hallf539eb92017-05-22 17:18:42 -07002034 output = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
2035 stateCheckResults.append( output )
2036 if all( result == main.TRUE for result in stateCheckResults ):
2037 main.log.info( itemName + ": Intents state check passed" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002038 else:
Jon Hallf539eb92017-05-22 17:18:42 -07002039 main.log.warn( "Intents state check failed" )
Shreyaca8990f2017-03-16 11:43:11 -07002040 intentResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002041 return intentResult
2042
Jon Hallf539eb92017-05-22 17:18:42 -07002043def checkBandwidthAllocations( main, bandwidth ):
2044 """
2045 Compare the given bandwith allocation output to the cli output on each node
2046 Returns main.TRUE or main.FALSE
2047 """
2048 bandwidthResults = []
2049 for i in range( main.numCtrls ):
2050 output = main.CLIs[ i ].compareBandwidthAllocations( bandwidth )
2051 bandwidthResults.append( output )
2052 if all( result == main.TRUE for result in bandwidthResults ):
2053 main.log.info( itemName + ": bandwidth check passed" )
2054 bandwidthResult = main.TRUE
2055 else:
2056 main.log.warn( itemName + ": bandwidth check failed" )
2057 bandwidthResult = main.FALSE
2058 return bandwidthResult
2059
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002060def checkFlowsState( main ):
2061
2062 main.log.info( itemName + ": Check flows state" )
Jeremy Songsterff553672016-05-12 17:06:23 -07002063 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState( isPENDING=False )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002064 return checkFlowsResult
2065
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002066def link( main, sw1, sw2, option ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002067
2068 # link down
alison52b25892016-09-19 10:53:48 -07002069 main.log.info( itemName + ": Bring link " + option + " between " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002070 sw1 + " and " + sw2 )
2071 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
2072 return linkResult
2073
Jon Hallaf95c3e2017-05-16 13:20:37 -07002074def scapyCheckConnection( main,
2075 senders,
2076 recipients,
2077 vlanId=None,
2078 useTCP=False,
2079 packet=None,
2080 packetFilter=None,
2081 expectFailure=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002082 """
2083 Checks the connectivity between all given sender hosts and all given recipient hosts
2084 Packet may be specified. Defaults to Ether/IP packet
2085 Packet Filter may be specified. Defaults to Ether/IP from current sender MAC
2086 Todo: Optional packet and packet filter attributes for sender and recipients
2087 Expect Failure when the sender and recipient are not supposed to have connectivity
2088 Timeout of 1 second, returns main.TRUE if the filter is not triggered and kills the filter
2089
2090 """
2091 connectionsFunctional = main.TRUE
2092
2093 if not packetFilter:
2094 packetFilter = 'ether host {}'
Jeremy Songstere405d3d2016-05-17 11:18:57 -07002095 if useTCP:
2096 packetFilter += ' ip proto \\tcp tcp port {}'.format(main.params[ 'SDNIP' ][ 'dstPort' ])
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002097 if expectFailure:
2098 timeout = 1
2099 else:
2100 timeout = 10
2101
2102 for sender in senders:
2103 try:
2104 senderComp = getattr( main, sender )
2105 except AttributeError:
2106 main.log.error( "main has no attribute {}".format( sender ) )
2107 connectionsFunctional = main.FALSE
2108 continue
2109
2110 for recipient in recipients:
2111 # Do not send packets to self since recipient CLI will already be busy
2112 if recipient == sender:
2113 continue
2114 try:
2115 recipientComp = getattr( main, recipient )
2116 except AttributeError:
2117 main.log.error( "main has no attribute {}".format( recipient ) )
2118 connectionsFunctional = main.FALSE
2119 continue
2120
Jeremy Songster832f9e92016-05-05 14:30:49 -07002121 if vlanId:
2122 recipientComp.startFilter( pktFilter = ( "vlan {}".format( vlanId ) + " && " + packetFilter.format( senderComp.hostMac ) ) )
2123 else:
2124 recipientComp.startFilter( pktFilter = packetFilter.format( senderComp.hostMac ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002125
2126 if not packet:
Jeremy Songster832f9e92016-05-05 14:30:49 -07002127 if vlanId:
2128 pkt = 'Ether( src="{0}", dst="{2}" )/Dot1Q(vlan={4})/IP( src="{1}", dst="{3}" )'.format(
2129 senderComp.hostMac,
2130 senderComp.hostIp,
2131 recipientComp.hostMac,
2132 recipientComp.hostIp,
2133 vlanId )
2134 else:
2135 pkt = 'Ether( src="{0}", dst="{2}" )/IP( src="{1}", dst="{3}" )'.format(
2136 senderComp.hostMac,
2137 senderComp.hostIp,
2138 recipientComp.hostMac,
2139 recipientComp.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002140 else:
2141 pkt = packet
Jeremy Songster832f9e92016-05-05 14:30:49 -07002142 if vlanId:
2143 senderComp.sendPacket( iface=( "{0}-eth0.{1}".format( sender, vlanId ) ), packet = pkt )
2144 else:
2145 senderComp.sendPacket( packet = pkt )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002146
2147 if recipientComp.checkFilter( timeout ):
2148 if expectFailure:
2149 main.log.error( "Packet from {0} successfully received by {1} when it should not have been".format( sender , recipient ) )
2150 connectionsFunctional = main.FALSE
2151 else:
2152 main.log.info( "Packet from {0} successfully received by {1}".format( sender , recipient ) )
alison52b25892016-09-19 10:53:48 -07002153 connectionsFunctional = main.TRUE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002154 else:
2155 recipientComp.killFilter()
2156 if expectFailure:
2157 main.log.info( "As expected, packet from {0} was not received by {1}".format( sender , recipient ) )
2158 else:
2159 main.log.error( "Packet from {0} was not received by {1}".format( sender , recipient ) )
2160 connectionsFunctional = main.FALSE
2161
2162 return connectionsFunctional
2163
alison52b25892016-09-19 10:53:48 -07002164
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002165def removeAllIntents( main, intentsId ):
2166 """
2167 Remove all intents in the intentsId
2168 """
2169
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002170 onosSummary = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002171 removeIntentResult = main.TRUE
2172 # Remove intents
2173 for intent in intentsId:
2174 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
2175
Jon Hallf539eb92017-05-22 17:18:42 -07002176 main.log.info( "Sleeping {} seconds".format( main.removeIntentSleep ) )
acsmarscfa52272015-08-06 15:21:45 -07002177 time.sleep( main.removeIntentSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002178
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002179 # If there is remianing intents then remove intents should fail
2180 for i in range( main.numCtrls ):
2181 onosSummary.append( json.loads( main.CLIs[ i ].summary() ) )
2182
2183 for summary in onosSummary:
2184 if summary.get( 'intents' ) != 0:
2185 main.log.warn( itemName + ": There are " +
2186 str( summary.get( 'intents' ) ) +
2187 " intents remaining in node " +
2188 str( summary.get( 'node' ) ) +
2189 ", failed to remove all the intents " )
2190 removeIntentResult = main.FALSE
2191
2192 if removeIntentResult:
2193 main.log.info( itemName + ": There are no more intents remaining, " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002194 "successfully removed all the intents." )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002195
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002196 return removeIntentResult
2197
2198def checkFlowsCount( main ):
2199 """
2200 Check flows count in each node
2201 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002202 flowsCount = []
2203 main.log.info( itemName + ": Checking flows count in each ONOS node" )
2204 for i in range( main.numCtrls ):
2205 summaryResult = main.CLIs[ i ].summary()
2206 if not summaryResult:
2207 main.log.error( itemName + ": There is something wrong with " +
2208 "summary command" )
2209 return main.FALSE
2210 else:
2211 summaryJson = json.loads( summaryResult )
2212 flowsCount.append( summaryJson.get( 'flows' ) )
2213
2214 if flowsCount:
2215 if all( flows==flowsCount[ 0 ] for flows in flowsCount ):
2216 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
2217 " flows in all ONOS node" )
2218 else:
2219 for i in range( main.numCtrls ):
2220 main.log.debug( itemName + ": ONOS node " + str( i ) + " has " +
kelvin-onlab6dea6e62015-07-23 13:07:26 -07002221 str( flowsCount[ i ] ) + " flows" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002222 else:
2223 main.log.error( "Checking flows count failed, check summary command" )
2224 return main.FALSE
2225
2226 return main.TRUE
2227
kelvin-onlab58dc39e2015-08-06 08:11:09 -07002228def checkLeaderChange( leaders1, leaders2 ):
acsmarse6b410f2015-07-17 14:39:34 -07002229 """
2230 Checks for a change in intent partition leadership.
2231
2232 Takes the output of leaders -c in json string format before and after
2233 a potential change as input
2234
2235 Returns main.TRUE if no mismatches are detected
2236 Returns main.FALSE if there is a mismatch or on error loading the input
2237 """
2238 try:
2239 leaders1 = json.loads( leaders1 )
2240 leaders2 = json.loads( leaders2 )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002241 except( AttributeError, TypeError ):
Jon Halld970abf2017-05-23 10:20:28 -07002242 main.log.exception( "checkLeaderChange: Object not as expected" )
acsmarse6b410f2015-07-17 14:39:34 -07002243 return main.FALSE
2244 except Exception:
Jon Halld970abf2017-05-23 10:20:28 -07002245 main.log.exception( "checkLeaderChange: Uncaught exception!" )
acsmarse6b410f2015-07-17 14:39:34 -07002246 main.cleanup()
2247 main.exit()
2248 main.log.info( "Checking Intent Paritions for Change in Leadership" )
2249 mismatch = False
2250 for dict1 in leaders1:
2251 if "intent" in dict1.get( "topic", [] ):
2252 for dict2 in leaders2:
2253 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \
2254 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
2255 mismatch = True
2256 main.log.error( "{0} changed leader from {1} to {2}".\
2257 format( dict1.get( "topic", "no-topic" ),\
2258 dict1.get( "leader", "no-leader" ),\
2259 dict2.get( "leader", "no-leader" ) ) )
2260 if mismatch:
2261 return main.FALSE
2262 else:
2263 return main.TRUE
kelvin-onlab016dce22015-08-10 09:54:11 -07002264
2265def report( main ):
2266 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002267 Report errors/warnings/exceptions
kelvin-onlab016dce22015-08-10 09:54:11 -07002268 """
kelvin-onlab016dce22015-08-10 09:54:11 -07002269 main.ONOSbench.logReport( main.ONOSip[ 0 ],
2270 [ "INFO",
2271 "FOLLOWER",
2272 "WARN",
2273 "flow",
2274 "ERROR",
2275 "Except" ],
2276 "s" )
2277
2278 main.log.info( "ERROR report: \n" )
2279 for i in range( main.numCtrls ):
2280 main.ONOSbench.logReport( main.ONOSip[ i ],
2281 [ "ERROR" ],
2282 "d" )
2283
2284 main.log.info( "EXCEPTIONS report: \n" )
2285 for i in range( main.numCtrls ):
2286 main.ONOSbench.logReport( main.ONOSip[ i ],
2287 [ "Except" ],
2288 "d" )
2289
2290 main.log.info( "WARNING report: \n" )
2291 for i in range( main.numCtrls ):
2292 main.ONOSbench.logReport( main.ONOSip[ i ],
2293 [ "WARN" ],
2294 "d" )
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002295
2296def flowDuration( main ):
2297 """
2298 Check age of flows to see if flows are being overwritten
2299 """
2300 import time
2301 main.log.info( "Getting current flow durations" )
2302 flowsJson1 = main.CLIs[ 0 ].flows( noCore=True )
2303 try:
2304 flowsJson1 = json.loads( flowsJson1 )
2305 except ValueError:
2306 main.log.error( "Unable to read flows" )
2307 return main.FALSE
2308 flowLife = []
2309 waitFlowLife = []
2310 for device in flowsJson1:
2311 if device.get( 'flowcount', 0 ) > 0:
2312 for i in range( device[ 'flowCount' ] ):
2313 flowLife.append( device[ 'flows' ][ i ][ 'life' ] )
2314 main.log.info( "Sleeping for {} seconds".format( main.flowDurationSleep ) )
2315 time.sleep( main.flowDurationSleep )
2316 main.log.info( "Getting new flow durations" )
2317 flowsJson2 = main.CLIs[ 0 ].flows( noCore=True )
2318 try:
2319 flowsJson2 = json.loads( flowsJson2 )
2320 except ValueError:
2321 main.log.error( "Unable to read flows" )
2322 return main.FALSE
2323 for device in flowsJson2:
2324 if device.get( 'flowcount', 0 ) > 0:
2325 for i in range( device[ 'flowCount' ] ):
2326 waitFlowLife.append( device[ 'flows' ][ i ][ 'life' ] )
2327 main.log.info( "Determining whether flows where overwritten" )
2328 if len( flowLife ) == len( waitFlowLife ):
alison52b25892016-09-19 10:53:48 -07002329 for i in range( len( flowLife ) ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002330 if waitFlowLife[ i ] - flowLife[ i ] < main.flowDurationSleep:
2331 return main.FALSE
2332 else:
2333 return main.FALSE
2334 return main.TRUE
alison52b25892016-09-19 10:53:48 -07002335
2336
2337def EncapsulatedIntentCheck( main, tag="" ):
2338 """
2339 Check encapsulated intents
2340 tag: encapsulation tag (e.g. VLAN, MPLS)
2341
2342 Getting added flows
2343 Check tags on each flows
2344 If each direction has push or pop, passed
2345 else failed
2346
2347 """
2348 import json
2349 HostJson = []
2350 Jflows = main.CLIs[ 0 ].flows( noCore=True )
2351 try:
2352 Jflows = json.loads( Jflows )
2353 except ValueError:
2354 main.log.error( "Unable to read flows" )
2355 return main.FALSE
2356
2357 for flow in Jflows:
2358 if len(flow[ "flows" ]) != 0:
2359 HostJson.append( flow[ "flows" ] )
2360
2361 totalflows = len( HostJson[ 0 ])
2362
2363 pop = 0
2364 push = 0
2365
2366 PopTag = tag + "_POP"
2367 PushTag = tag + "_PUSH"
2368
2369 for EachHostJson in HostJson:
2370 for i in range( totalflows ):
2371 if EachHostJson[ i ][ "treatment" ][ "instructions" ][ 0 ][ "subtype" ] == PopTag:
2372 pop += 1
2373 elif EachHostJson[ i ][ "treatment" ][ "instructions" ][ 0 ][ "subtype" ] == PushTag:
2374 push += 1
2375
2376 if pop == totalflows and push == totalflows:
2377 return main.TRUE
2378 else:
alisonda157272016-12-22 01:13:21 -08002379 return main.FALSE
2380
2381def ProtectedIntentCheck( main ):
2382 import json
2383 intent = main.CLIs[ 0 ].intents( jsonFormat=False )
2384 if "Protection" in intent:
2385 return main.TRUE
Shreyaca8990f2017-03-16 11:43:11 -07002386 return main.FALSE