blob: 1d31f69e71bb5485ae485d60f5230815637fc231 [file] [log] [blame]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2015 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070011 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070012
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20
21
kelvin-onlabd48a68c2015-07-13 16:01:36 -070022 Wrapper functions for FuncIntent
23 This functions include Onosclidriver and Mininetclidriver driver functions
24 Author: kelvin@onlab.us
25"""
26import time
kelvin-onlabd48a68c2015-07-13 16:01:36 -070027import json
Jon Hallf539eb92017-05-22 17:18:42 -070028import os
kelvin-onlabd48a68c2015-07-13 16:01:36 -070029
Jon Hall78be4962017-05-23 14:53:53 -070030
kelvin-onlabd48a68c2015-07-13 16:01:36 -070031def __init__( self ):
32 self.default = ''
33
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -070034hostIntentFailFlag = False
35pointIntentFailFlag = False
36singleToMultiFailFlag = False
37multiToSingleFailFlag = False
38
Jon Hall78be4962017-05-23 14:53:53 -070039
Jeremy Songster1f39bf02016-01-20 17:17:25 -080040def installHostIntent( main,
Jeremy2f190ca2016-01-29 15:23:57 -080041 name,
42 host1,
43 host2,
44 onosNode=0,
45 ethType="",
46 bandwidth="",
47 lambdaAlloc=False,
48 ipProto="",
49 ipAddresses="",
50 tcp="",
51 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -070052 sw2="",
Jeremy Songsterc032f162016-08-04 17:14:49 -070053 setVlan="",
Jon Hallf539eb92017-05-22 17:18:42 -070054 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -070055 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -080056 Installs a Host Intent
57
kelvin-onlab58dc39e2015-08-06 08:11:09 -070058 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -080059 Install a host intent using
60 add-host-intent
61
kelvin-onlab58dc39e2015-08-06 08:11:09 -070062 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -080063 - Fetch host data if not given
64 - Add host intent
65 - Ingress device is the first sender host
66 - Egress devices are the recipient devices
67 - Ports if defined in senders or recipients
68 - MAC address ethSrc loaded from Ingress device
69 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -070070 Required:
71 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -080072 host1 - Dictionary for host1
73 { "name":"h8", "id":"of:0000000000000005/8" }
74 host2 - Dictionary for host2
75 { "name":"h16", "id":"of:0000000000000006/8" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -070076 Optional:
77 onosNode - ONOS node to install the intents in main.CLIs[ ]
78 0 by default so that it will always use the first
79 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -070080 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -070081 bandwidth - Bandwidth capacity
82 lambdaAlloc - Allocate lambda, defaults to False
83 ipProto - IP protocol
Jeremy Songster1f39bf02016-01-20 17:17:25 -080084 tcp - TCP ports in the same order as the hosts in hostNames
85 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -080086 assert main, "There is no main variable"
87 assert host1, "You must specify host1"
88 assert host2, "You must specify host2"
89
90 global itemName # The name of this run. Used for logs.
91 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -080092
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -070093 global hostIntentFailFlag
94 hostIntentFailFlag = False
95
Jeremy Songster1f39bf02016-01-20 17:17:25 -080096 main.log.info( itemName + ": Adding single point to multi point intents" )
Jeremyd9e4eb12016-04-13 12:09:06 -070097 try:
98 if not host1.get( "id" ):
99 main.log.warn( "ID not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
100 main.log.debug( main.hostsData.get( host1.get( "name" ) ) )
101 host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "id" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800102
Jeremyd9e4eb12016-04-13 12:09:06 -0700103 if not host2.get( "id" ):
104 main.log.warn( "ID not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
105 host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "id" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800106
Jeremyd9e4eb12016-04-13 12:09:06 -0700107 # Adding point intent
Jeremy Songster832f9e92016-05-05 14:30:49 -0700108 vlanId = host1.get( "vlan" )
Devin Lim142b5342017-07-20 15:22:39 -0700109 intentId = main.Cluster.active( onosNode ).CLI.addHostIntent( hostIdOne=host1.get( "id" ),
110 hostIdTwo=host2.get( "id" ),
111 vlanId=vlanId,
112 setVlan=setVlan,
113 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700114 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700115 errorMsg = "There was a problem loading the hosts data."
116 if intentId:
117 errorMsg += " There was a problem installing host to host intent."
118 main.log.error( errorMsg )
119 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800120
121 # Check intents state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700122 if utilities.retry( f=checkIntentState,
123 retValue=main.FALSE,
Jon Hallf539eb92017-05-22 17:18:42 -0700124 args=( main, [ intentId ] ),
Jon Hallaf95c3e2017-05-16 13:20:37 -0700125 sleep=main.checkIntentSleep,
126 attempts=50 ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700127 main.assertReturnString += 'Install Intent State Passed\n'
alison52b25892016-09-19 10:53:48 -0700128
Jon Hall78be4962017-05-23 14:53:53 -0700129 # Check VLAN if test encapsulation
alison52b25892016-09-19 10:53:48 -0700130 if encap != "":
131 if EncapsulatedIntentCheck( main, tag=encap ):
132 main.assertReturnString += 'Encapsulation intents check Passed\n'
133 else:
134 main.assertReturnString += 'Encapsulation intents check failed\n'
Jon Hallf539eb92017-05-22 17:18:42 -0700135 if bandwidth != "":
136 allocationsFile = open( os.path.dirname( main.testFile ) + main.params[ 'DEPENDENCY' ][ 'filePath' ], 'r' )
137 expectedFormat = allocationsFile.read()
138 bandwidthCheck = checkBandwidthAllocations( main, expectedFormat )
139 allocationsFile.close()
140 if bandwidthCheck:
141 main.assertReturnString += 'Bandwidth Allocation check Passed\n'
142 else:
143 main.assertReturnString += 'Bandwidth Allocation check Failed\n'
Jon Hallc3f88af2017-05-23 11:25:54 -0700144 return main.FALSE
Jon Hallf539eb92017-05-22 17:18:42 -0700145
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700146 if flowDuration( main ):
147 main.assertReturnString += 'Flow duration check Passed\n'
148 return intentId
149 else:
Jon Hallf539eb92017-05-22 17:18:42 -0700150 main.assertReturnString += 'Flow duration check Failed\n'
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700151 return main.FALSE
alison52b25892016-09-19 10:53:48 -0700152
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800153 else:
Jeremy2f190ca2016-01-29 15:23:57 -0800154 main.log.error( "Host Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700155 hostIntentFailFlag = True
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700156 main.assertReturnString += 'Install Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800157 return main.FALSE
158
Jon Hall78be4962017-05-23 14:53:53 -0700159
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800160def testHostIntent( main,
161 name,
162 intentId,
163 host1,
164 host2,
165 onosNode=0,
166 sw1="s5",
167 sw2="s2",
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700168 expectedLink=0 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800169 """
170 Test a Host Intent
171
172 Description:
173 Test a host intent of given ID between given hosts
174
175 Steps:
176 - Fetch host data if not given
177 - Check Intent State
178 - Check Flow State
179 - Check Connectivity
180 - Check Lack of Connectivity Between Hosts not in the Intent
181 - Reroute
182 - Take Expected Link Down
183 - Check Intent State
184 - Check Flow State
185 - Check Topology
186 - Check Connectivity
187 - Bring Expected Link Up
188 - Check Intent State
189 - Check Flow State
190 - Check Topology
191 - Check Connectivity
192 - Remove Topology
193
194 Required:
195 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
196 intentId - intent ID to be tested ( and removed )
197 host1 - Dictionary for host1
198 { "name":"h8", "id":"of:0000000000000005/8" }
199 host2 - Dictionary for host2
200 { "name":"h16", "id":"of:0000000000000006/8" }
201 Optional:
202 onosNode - ONOS node to install the intents in main.CLIs[ ]
203 0 by default so that it will always use the first
204 ONOS node
205 sw1 - First switch to bring down & up for rerouting purpose
206 sw2 - Second switch to bring down & up for rerouting purpose
207 expectedLink - Expected link when the switches are down, it should
208 be two links lower than the links before the two
209 switches are down
210
211 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800212 # Parameter Validity Check
213 assert main, "There is no main variable"
214 assert host1, "You must specify host1"
215 assert host2, "You must specify host2"
216
217 global itemName
218 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800219
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700220 global hostIntentFailFlag
221
Jeremy2f190ca2016-01-29 15:23:57 -0800222 main.log.info( itemName + ": Testing Host Intent" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800223
Jeremyd9e4eb12016-04-13 12:09:06 -0700224 try:
225 if not host1.get( "id" ):
226 main.log.warn( "Id not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
227 host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800228
Jeremyd9e4eb12016-04-13 12:09:06 -0700229 if not host2.get( "id" ):
230 main.log.warn( "Id not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
231 host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800232
Jeremyd9e4eb12016-04-13 12:09:06 -0700233 senderNames = [ host1.get( "name" ), host2.get( "name" ) ]
234 recipientNames = [ host1.get( "name" ), host2.get( "name" ) ]
Jeremy Songster832f9e92016-05-05 14:30:49 -0700235 vlanId = host1.get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800236
Jeremyd9e4eb12016-04-13 12:09:06 -0700237 testResult = main.TRUE
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700238 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700239 main.log.error( "There was a problem loading the hosts data." )
240 return main.FALSE
241
242 main.log.info( itemName + ": Testing Host to Host intents" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800243
244 # Check intent state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700245 if hostIntentFailFlag:
Devin Lima4f95bc2017-08-11 11:13:03 -0700246 attempts = main.minimumAttemptsNum
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700247 else:
Devin Lima4f95bc2017-08-11 11:13:03 -0700248 attempts = main.generalAttemptsNum
Jon Hallaf95c3e2017-05-16 13:20:37 -0700249 if utilities.retry( f=checkIntentState,
250 retValue=main.FALSE,
251 args=( main, [ intentId ] ),
252 sleep=main.checkIntentSleep,
253 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800254 main.assertReturnString += 'Initial Intent State Passed\n'
255 else:
256 main.assertReturnString += 'Initial Intent State Failed\n'
257 testResult = main.FALSE
Devin Lima4f95bc2017-08-11 11:13:03 -0700258 attempts = main.minimumAttemptsNum
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800259
260 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -0700261 if utilities.retry( f=checkFlowsCount,
262 retValue=main.FALSE,
263 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -0700264 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -0700265 attempts=3 ) and utilities.retry( f=checkFlowsState,
266 retValue=main.FALSE,
267 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -0700268 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -0700269 attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800270 main.assertReturnString += 'Initial Flow State Passed\n'
271 else:
272 main.assertReturnString += 'Intial Flow State Failed\n'
273 testResult = main.FALSE
274
275 # Check Connectivity
Jon Hallaf95c3e2017-05-16 13:20:37 -0700276 if utilities.retry( f=scapyCheckConnection,
277 retValue=main.FALSE,
Devin Lima4f95bc2017-08-11 11:13:03 -0700278 attempts=main.checkConnectionAttNum,
Jon Hallaf95c3e2017-05-16 13:20:37 -0700279 sleep=main.checkConnectionSleep,
Devin Lima4f95bc2017-08-11 11:13:03 -0700280 args=( main, senderNames, recipientNames, vlanId ),
281 getRetryingTime=True ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800282 main.assertReturnString += 'Initial Ping Passed\n'
283 else:
284 main.assertReturnString += 'Initial Ping Failed\n'
285 testResult = main.FALSE
286
287 # Test rerouting if these variables exist
288 if sw1 and sw2 and expectedLink:
289 # Take link down
Jon Hallaf95c3e2017-05-16 13:20:37 -0700290 if utilities.retry( f=link,
291 retValue=main.FALSE,
292 args=( main, sw1, sw2, "down" ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800293 main.assertReturnString += 'Link Down Passed\n'
294 else:
295 main.assertReturnString += 'Link Down Failed\n'
296 testResult = main.FALSE
297
298 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700299 if utilities.retry( f=checkIntentState,
300 retValue=main.FALSE,
301 args=( main, [ intentId ] ),
302 sleep=main.checkIntentHostSleep,
303 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800304 main.assertReturnString += 'Link Down Intent State Passed\n'
305 else:
306 main.assertReturnString += 'Link Down Intent State Failed\n'
307 testResult = main.FALSE
308
309 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -0700310 if utilities.retry( f=checkFlowsCount,
311 retValue=main.FALSE,
312 args=[ main ],
313 sleep=main.checkFlowCountSleep,
314 attempts=attempts ) and utilities.retry( f=checkFlowsState,
315 retValue=main.FALSE,
316 args=[ main ],
317 sleep=main.checkFlowCountSleep,
318 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800319 main.assertReturnString += 'Link Down Flow State Passed\n'
320 else:
321 main.assertReturnString += 'Link Down Flow State Failed\n'
322 testResult = main.FALSE
323
324 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -0700325 if utilities.retry( f=checkTopology,
326 retValue=main.FALSE,
327 args=( main, expectedLink ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800328 main.assertReturnString += 'Link Down Topology State Passed\n'
329 else:
330 main.assertReturnString += 'Link Down Topology State Failed\n'
331 testResult = main.FALSE
332
333 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -0700334 if utilities.retry( f=scapyCheckConnection,
335 retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -0700336 args=( main, senderNames, recipientNames, vlanId ),
Jon Hallaf95c3e2017-05-16 13:20:37 -0700337 sleep=main.checkConnectionSleep,
Devin Lima4f95bc2017-08-11 11:13:03 -0700338 attempts=main.checkConnectionAttNum,
339 getRetryingTime=True ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800340 main.assertReturnString += 'Link Down Pingall Passed\n'
341 else:
342 main.assertReturnString += 'Link Down Pingall Failed\n'
343 testResult = main.FALSE
344
345 # Bring link up
Jon Hallaf95c3e2017-05-16 13:20:37 -0700346 if utilities.retry( f=link,
347 retValue=main.FALSE,
348 args=( main, sw1, sw2, "up" ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800349 main.assertReturnString += 'Link Up Passed\n'
350 else:
351 main.assertReturnString += 'Link Up Failed\n'
352 testResult = main.FALSE
353
354 # Wait for reroute
Jon Hallf539eb92017-05-22 17:18:42 -0700355 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800356 time.sleep( main.rerouteSleep )
357
358 # Check Intents
Jon Hallaf95c3e2017-05-16 13:20:37 -0700359 if utilities.retry( f=checkIntentState,
360 retValue=main.FALSE,
361 attempts=attempts * 2,
362 args=( main, [ intentId ] ),
363 sleep=main.checkIntentSleep ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800364 main.assertReturnString += 'Link Up Intent State Passed\n'
365 else:
366 main.assertReturnString += 'Link Up Intent State Failed\n'
367 testResult = main.FALSE
368
369 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -0700370 if utilities.retry( f=checkFlowsCount,
371 retValue=main.FALSE,
372 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -0700373 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -0700374 attempts=3 ) and utilities.retry( f=checkFlowsState,
375 retValue=main.FALSE,
376 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -0700377 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -0700378 attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800379 main.assertReturnString += 'Link Up Flow State Passed\n'
380 else:
381 main.assertReturnString += 'Link Up Flow State Failed\n'
382 testResult = main.FALSE
383
384 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -0700385 if utilities.retry( f=checkTopology,
386 retValue=main.FALSE,
387 args=( main, main.numLinks ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800388 main.assertReturnString += 'Link Up Topology State Passed\n'
389 else:
390 main.assertReturnString += 'Link Up Topology State Failed\n'
391 testResult = main.FALSE
392
393 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -0700394 if utilities.retry( f=scapyCheckConnection,
395 retValue=main.FALSE,
Devin Lima4f95bc2017-08-11 11:13:03 -0700396 args=( main, senderNames, recipientNames, vlanId ),
397 getRetryingTime=True ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800398 main.assertReturnString += 'Link Up Pingall Passed\n'
399 else:
400 main.assertReturnString += 'Link Up Pingall Failed\n'
401 testResult = main.FALSE
402
403 # Remove all intents
Jon Hallaf95c3e2017-05-16 13:20:37 -0700404 if utilities.retry( f=removeAllIntents,
405 retValue=main.FALSE,
Devin Lima4f95bc2017-08-11 11:13:03 -0700406 attempts=main.removeIntentAttNum,
Jon Hallaf95c3e2017-05-16 13:20:37 -0700407 args=( main, [ intentId ] ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800408 main.assertReturnString += 'Remove Intents Passed'
409 else:
410 main.assertReturnString += 'Remove Intents Failed'
411 testResult = main.FALSE
412
Devin Lim8619b552018-04-13 00:40:43 -0700413 # Check flows count in each node
414 if utilities.retry( f=checkFlowsState,
415 retValue=main.FALSE,
416 args=[ main ],
417 sleep=main.checkFlowCountSleep,
418 attempts=3 ):
419 main.assertReturnString += 'After removing intents Flow State Passed\n'
420 else:
421 main.assertReturnString += 'After removing intents Flow State Failed\n'
422 testResult = main.FALSE
423
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800424 return testResult
425
Jon Hall78be4962017-05-23 14:53:53 -0700426
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800427def installPointIntent( main,
428 name,
429 senders,
430 recipients,
431 onosNode=0,
432 ethType="",
433 bandwidth="",
434 lambdaAlloc=False,
alisonda157272016-12-22 01:13:21 -0800435 protected=False,
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800436 ipProto="",
437 ipSrc="",
438 ipDst="",
439 tcpSrc="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700440 tcpDst="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700441 setVlan="",
Jon Hallf539eb92017-05-22 17:18:42 -0700442 encap="" ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800443 """
444 Installs a Single to Single Point Intent
445
446 Description:
447 Install a single to single point intent
448
449 Steps:
450 - Fetch host data if not given
451 - Add point intent
452 - Ingress device is the first sender device
453 - Egress device is the first recipient device
454 - Ports if defined in senders or recipients
455 - MAC address ethSrc loaded from Ingress device
456 - Check intent state with retry
457 Required:
458 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
459 senders - List of host dictionaries i.e.
460 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
461 recipients - List of host dictionaries i.e.
462 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
463 Optional:
464 onosNode - ONOS node to install the intents in main.CLIs[ ]
465 0 by default so that it will always use the first
466 ONOS node
467 ethType - Ethernet type eg. IPV4, IPV6
468 bandwidth - Bandwidth capacity
469 lambdaAlloc - Allocate lambda, defaults to False
470 ipProto - IP protocol
471 tcp - TCP ports in the same order as the hosts in hostNames
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700472 sw1 - First switch to bring down & up for rerouting purpose
473 sw2 - Second switch to bring down & up for rerouting purpose
474 expectedLink - Expected link when the switches are down, it should
475 be two links lower than the links before the two
476 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700477 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700478 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800479 assert senders, "You must specify a sender"
480 assert recipients, "You must specify a recipient"
481 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700482
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800483 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700484 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700485
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700486 global pointIntentFailFlag
487 pointIntentFailFlag = False
488
Jeremy6f000c62016-02-25 17:02:28 -0800489 main.log.info( itemName + ": Adding point to point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700490
Jeremyd9e4eb12016-04-13 12:09:06 -0700491 try:
492 for sender in senders:
493 if not sender.get( "device" ):
494 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
495 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800496
Jeremyd9e4eb12016-04-13 12:09:06 -0700497 for recipient in recipients:
498 if not recipient.get( "device" ):
499 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
500 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800501
Jeremyd9e4eb12016-04-13 12:09:06 -0700502 ingressDevice = senders[ 0 ].get( "device" )
503 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800504
Jeremyd9e4eb12016-04-13 12:09:06 -0700505 portIngress = senders[ 0 ].get( "port", "" )
506 portEgress = recipients[ 0 ].get( "port", "" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800507
Jeremyd9e4eb12016-04-13 12:09:06 -0700508 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800509
Jeremyd9e4eb12016-04-13 12:09:06 -0700510 ipSrc = senders[ 0 ].get( "ip" )
511 ipDst = recipients[ 0 ].get( "ip" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800512
Jeremy Songster832f9e92016-05-05 14:30:49 -0700513 vlanId = senders[ 0 ].get( "vlan" )
514
Jeremyd9e4eb12016-04-13 12:09:06 -0700515 # Adding point intent
Devin Lim142b5342017-07-20 15:22:39 -0700516 intentId = main.Cluster.active( onosNode ).CLI.addPointIntent(
517 ingressDevice=ingressDevice,
518 egressDevice=egressDevice,
519 portIngress=portIngress,
520 portEgress=portEgress,
521 ethType=ethType,
522 ethDst=dstMac,
523 bandwidth=bandwidth,
524 lambdaAlloc=lambdaAlloc,
525 protected=protected,
526 ipProto=ipProto,
527 ipSrc=ipSrc,
528 ipDst=ipDst,
529 tcpSrc=tcpSrc,
530 tcpDst=tcpDst,
531 vlanId=vlanId,
532 setVlan=setVlan,
533 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700534 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700535 errorMsg = "There was a problem loading the hosts data."
536 if intentId:
537 errorMsg += " There was a problem installing Point to Point intent."
538 main.log.error( errorMsg )
539 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700540
541 # Check intents state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700542 if utilities.retry( f=checkIntentState,
543 retValue=main.FALSE,
Jon Hallf539eb92017-05-22 17:18:42 -0700544 args=( main, [ intentId ] ),
545 sleep=main.checkIntentSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -0700546 attempts=50 ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700547 main.assertReturnString += 'Install Intent State Passed\n'
alison52b25892016-09-19 10:53:48 -0700548
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700549 if bandwidth != "":
Jon Hallf539eb92017-05-22 17:18:42 -0700550 allocationsFile = open( os.path.dirname( main.testFile ) + main.params[ 'DEPENDENCY' ][ 'filePath' ], 'r' )
551 expectedFormat = allocationsFile.read()
552 bandwidthCheck = checkBandwidthAllocations( main, expectedFormat )
553 allocationsFile.close()
554 if bandwidthCheck:
555 main.assertReturnString += 'Bandwidth Allocation check Passed\n'
556 else:
557 main.assertReturnString += 'Bandwidth Allocation check Failed\n'
Jon Hallc3f88af2017-05-23 11:25:54 -0700558 return main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700559
alison52b25892016-09-19 10:53:48 -0700560 # Check VLAN if test encapsulation
561 if encap != "":
562 if EncapsulatedIntentCheck( main, tag=encap ):
563 main.assertReturnString += 'Encapsulation intents check Passed\n'
564 else:
565 main.assertReturnString += 'Encapsulation intents check failed\n'
alisonda157272016-12-22 01:13:21 -0800566
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700567 if flowDuration( main ):
568 main.assertReturnString += 'Flow duration check Passed\n'
569 return intentId
570 else:
571 main.assertReturnString += 'Flow duration check failed\n'
572 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -0700573 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800574 main.log.error( "Point Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700575 pointIntentFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800576 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700577
Jon Hall78be4962017-05-23 14:53:53 -0700578
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700579def pointIntentTcp( main,
580 name,
581 host1,
582 host2,
583 onosNode=0,
584 deviceId1="",
585 deviceId2="",
586 port1="",
587 port2="",
588 ethType="",
589 mac1="",
590 mac2="",
591 bandwidth="",
592 lambdaAlloc=False,
593 ipProto="",
594 ip1="",
595 ip2="",
596 tcp1="",
597 tcp2="",
598 sw1="",
599 sw2="",
600 expectedLink=0 ):
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700601 """
602 Description:
603 Verify add-point-intent only for TCP
604 Steps:
605 - Get device ids | ports
606 - Add point intents
607 - Check intents
608 - Verify flows
609 - Ping hosts
610 - Reroute
611 - Link down
612 - Verify flows
613 - Check topology
614 - Ping hosts
615 - Link up
616 - Verify flows
617 - Check topology
618 - Ping hosts
619 - Remove intents
620 Required:
621 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
622 host1 - Name of first host
623 host2 - Name of second host
624 Optional:
625 onosNode - ONOS node to install the intents in main.CLIs[ ]
626 0 by default so that it will always use the first
627 ONOS node
628 deviceId1 - ONOS device id of the first switch, the same as the
629 location of the first host eg. of:0000000000000001/1,
630 located at device 1 port 1
631 deviceId2 - ONOS device id of the second switch
632 port1 - The port number where the first host is attached
633 port2 - The port number where the second host is attached
634 ethType - Ethernet type eg. IPV4, IPV6
635 mac1 - Mac address of first host
636 mac2 - Mac address of the second host
637 bandwidth - Bandwidth capacity
638 lambdaAlloc - Allocate lambda, defaults to False
639 ipProto - IP protocol
640 ip1 - IP address of first host
641 ip2 - IP address of second host
642 tcp1 - TCP port of first host
643 tcp2 - TCP port of second host
644 sw1 - First switch to bring down & up for rerouting purpose
645 sw2 - Second switch to bring down & up for rerouting purpose
646 expectedLink - Expected link when the switches are down, it should
647 be two links lower than the links before the two
648 switches are down
649 """
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700650 assert main, "There is no main variable"
651 assert name, "variable name is empty"
652 assert host1 and host2, "You must specify hosts"
653
654 global itemName
655 itemName = name
656 host1 = host1
657 host2 = host2
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700658 intentsId = []
659
660 iperfResult = main.TRUE
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700661 linkDownResult = main.TRUE
662 linkUpResult = main.TRUE
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700663
664 # Adding bidirectional point intents
665 main.log.info( itemName + ": Adding point intents" )
Devin Lim142b5342017-07-20 15:22:39 -0700666 ctrl = main.Cluster.active( onosNode )
667 intent1 = ctrl.CLI.addPointIntent( ingressDevice=deviceId1,
668 egressDevice=deviceId2,
669 portIngress=port1,
670 portEgress=port2,
671 ethType=ethType,
672 ethSrc=mac1,
673 ethDst=mac2,
674 bandwidth=bandwidth,
675 lambdaAlloc=lambdaAlloc,
676 ipProto=ipProto,
677 ipSrc=ip1,
678 ipDst=ip2,
679 tcpSrc=tcp1,
680 tcpDst="" )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700681
Devin Lim142b5342017-07-20 15:22:39 -0700682 intent2 = ctrl.CLI.addPointIntent( ingressDevice=deviceId2,
683 egressDevice=deviceId1,
684 portIngress=port2,
685 portEgress=port1,
686 ethType=ethType,
687 ethSrc=mac2,
688 ethDst=mac1,
689 bandwidth=bandwidth,
690 lambdaAlloc=lambdaAlloc,
691 ipProto=ipProto,
692 ipSrc=ip2,
693 ipDst=ip1,
694 tcpSrc=tcp2,
695 tcpDst="" )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700696
Devin Lim142b5342017-07-20 15:22:39 -0700697 intent3 = ctrl.CLI.addPointIntent( ingressDevice=deviceId1,
698 egressDevice=deviceId2,
699 portIngress=port1,
700 portEgress=port2,
701 ethType=ethType,
702 ethSrc=mac1,
703 ethDst=mac2,
704 bandwidth=bandwidth,
705 lambdaAlloc=lambdaAlloc,
706 ipProto=ipProto,
707 ipSrc=ip1,
708 ipDst=ip2,
709 tcpSrc="",
710 tcpDst=tcp2 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700711
Devin Lim142b5342017-07-20 15:22:39 -0700712 intent4 = ctrl.CLI.addPointIntent( ingressDevice=deviceId2,
713 egressDevice=deviceId1,
714 portIngress=port2,
715 portEgress=port1,
716 ethType=ethType,
717 ethSrc=mac2,
718 ethDst=mac1,
719 bandwidth=bandwidth,
720 lambdaAlloc=lambdaAlloc,
721 ipProto=ipProto,
722 ipSrc=ip2,
723 ipDst=ip1,
724 tcpSrc="",
725 tcpDst=tcp1 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700726 intentsId.append( intent1 )
727 intentsId.append( intent2 )
728 intentsId.append( intent3 )
729 intentsId.append( intent4 )
730
731 # Check intents state
Jon Hallf539eb92017-05-22 17:18:42 -0700732 main.log.info( "Sleeping {} seconds".format( main.checkIntentSleep ) )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700733 time.sleep( main.checkIntentSleep )
Jon Hallaf95c3e2017-05-16 13:20:37 -0700734 intentResult = utilities.retry( f=checkIntentState,
735 retValue=main.FALSE,
736 args=( main, intentsId ),
737 sleep=1,
738 attempts=50 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700739 # Check flows count in each node
740 checkFlowsCount( main )
741
742 # Check intents state again if first check fails...
743 if not intentResult:
Jon Hallaf95c3e2017-05-16 13:20:37 -0700744 intentResult = utilities.retry( f=checkIntentState,
745 retValue=main.FALSE,
746 args=( main, intentsId ),
747 sleep=1,
748 attempts=50 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700749
750 # Check flows count in each node
751 checkFlowsCount( main )
752
753 # Verify flows
754 checkFlowsState( main )
755
756 # Run iperf to both host
You Wanga0f6ff62018-01-11 15:46:30 -0800757 iperfTemp = main.Network.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700758 iperfResult = iperfResult and iperfTemp
759 if iperfTemp:
760 main.assertReturnString += 'Initial Iperf Passed\n'
761 else:
762 main.assertReturnString += 'Initial Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700763
764 # Test rerouting if these variables exist
765 if sw1 and sw2 and expectedLink:
766 # link down
767 linkDownResult = link( main, sw1, sw2, "down" )
acsmarsd4862d12015-10-06 17:57:34 -0700768
769 if linkDownResult:
770 main.assertReturnString += 'Link Down Passed\n'
771 else:
772 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700773
774 # Check flows count in each node
775 checkFlowsCount( main )
776 # Verify flows
777 checkFlowsState( main )
778
779 # Check OnosTopology
780 topoResult = checkTopology( main, expectedLink )
acsmarsd4862d12015-10-06 17:57:34 -0700781 if topoResult:
782 main.assertReturnString += 'Link Down Topology State Passed\n'
783 else:
784 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700785
786 # Run iperf to both host
You Wanga0f6ff62018-01-11 15:46:30 -0800787 iperfTemp = main.Network.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700788 iperfResult = iperfResult and iperfTemp
789 if iperfTemp:
790 main.assertReturnString += 'Link Down Iperf Passed\n'
791 else:
792 main.assertReturnString += 'Link Down Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700793
acsmarsd4862d12015-10-06 17:57:34 -0700794 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700795 intentTemp = utilities.retry( f=checkIntentState,
796 retValue=main.FALSE,
797 args=( main, intentsId ),
798 sleep=1,
799 attempts=50 )
acsmarsd4862d12015-10-06 17:57:34 -0700800 intentResult = intentResult and intentTemp
801 if intentTemp:
802 main.assertReturnString += 'Link Down Intent State Passed\n'
803 else:
804 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700805
806 # Checks ONOS state in link down
807 if linkDownResult and topoResult and iperfResult and intentResult:
808 main.log.info( itemName + ": Successfully brought link down" )
809 else:
810 main.log.error( itemName + ": Failed to bring link down" )
811
812 # link up
813 linkUpResult = link( main, sw1, sw2, "up" )
alison52b25892016-09-19 10:53:48 -0700814 if linkUpResult:
acsmarsd4862d12015-10-06 17:57:34 -0700815 main.assertReturnString += 'Link Up Passed\n'
816 else:
817 main.assertReturnString += 'Link Up Failed\n'
818
Jon Hallf539eb92017-05-22 17:18:42 -0700819 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700820 time.sleep( main.rerouteSleep )
821
822 # Check flows count in each node
823 checkFlowsCount( main )
824 # Verify flows
825 checkFlowsState( main )
826
827 # Check OnosTopology
828 topoResult = checkTopology( main, main.numLinks )
829
acsmarsd4862d12015-10-06 17:57:34 -0700830 if topoResult:
831 main.assertReturnString += 'Link Up Topology State Passed\n'
832 else:
833 main.assertReturnString += 'Link Up Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700834
acsmarsd4862d12015-10-06 17:57:34 -0700835 # Run iperf to both host
You Wanga0f6ff62018-01-11 15:46:30 -0800836 iperfTemp = main.Network.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700837 iperfResult = iperfResult and iperfTemp
838 if iperfTemp:
839 main.assertReturnString += 'Link Up Iperf Passed\n'
840 else:
841 main.assertReturnString += 'Link Up Iperf Failed\n'
842
843 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700844 intentTemp = utilities.retry( f=checkIntentState,
845 retValue=main.FALSE,
846 args=( main, intentsId ),
847 sleep=1,
848 attempts=50 )
acsmarsd4862d12015-10-06 17:57:34 -0700849 intentResult = intentResult and intentTemp
850 if intentTemp:
851 main.assertReturnString += 'Link Down Intent State Passed\n'
852 else:
853 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700854
855 # Checks ONOS state in link up
856 if linkUpResult and topoResult and iperfResult and intentResult:
857 main.log.info( itemName + ": Successfully brought link back up" )
858 else:
859 main.log.error( itemName + ": Failed to bring link back up" )
860
861 # Remove all intents
862 removeIntentResult = removeAllIntents( main, intentsId )
acsmarsd4862d12015-10-06 17:57:34 -0700863 if removeIntentResult:
864 main.assertReturnString += 'Remove Intents Passed'
865 else:
866 main.assertReturnString += 'Remove Intents Failed'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700867
868 stepResult = iperfResult and linkDownResult and linkUpResult \
869 and intentResult and removeIntentResult
870
871 return stepResult
872
Jon Hall78be4962017-05-23 14:53:53 -0700873
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800874def installSingleToMultiIntent( main,
875 name,
876 senders,
877 recipients,
878 onosNode=0,
879 ethType="",
880 bandwidth="",
881 lambdaAlloc=False,
882 ipProto="",
883 ipAddresses="",
884 tcp="",
885 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700886 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -0700887 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700888 partial=False,
Jon Hallf539eb92017-05-22 17:18:42 -0700889 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700890 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800891 Installs a Single to Multi Point Intent
892
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700893 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800894 Install a single to multi point intent using
895 add-single-to-multi-intent
896
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700897 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800898 - Fetch host data if not given
899 - Add single to multi intent
900 - Ingress device is the first sender host
901 - Egress devices are the recipient devices
902 - Ports if defined in senders or recipients
903 - MAC address ethSrc loaded from Ingress device
904 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700905 Required:
906 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800907 senders - List of host dictionaries i.e.
908 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
909 recipients - List of host dictionaries i.e.
910 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700911 Optional:
912 onosNode - ONOS node to install the intents in main.CLIs[ ]
913 0 by default so that it will always use the first
914 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700915 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700916 bandwidth - Bandwidth capacity
917 lambdaAlloc - Allocate lambda, defaults to False
918 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700919 tcp - TCP ports in the same order as the hosts in hostNames
920 sw1 - First switch to bring down & up for rerouting purpose
921 sw2 - Second switch to bring down & up for rerouting purpose
922 expectedLink - Expected link when the switches are down, it should
923 be two links lower than the links before the two
924 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700925 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700926 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800927 assert senders, "You must specify a sender"
928 assert recipients, "You must specify a recipient"
929 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700930
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800931 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700932 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700933
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700934 global singleToMultiFailFlag
935 singleToMultiFailFlag = False
936
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700937 main.log.info( itemName + ": Adding single point to multi point intents" )
938
Jeremyd9e4eb12016-04-13 12:09:06 -0700939 try:
940 for sender in senders:
941 if not sender.get( "device" ):
942 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
943 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700944
Jeremyd9e4eb12016-04-13 12:09:06 -0700945 for recipient in recipients:
946 if not recipient.get( "device" ):
947 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
948 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700949
Jeremyd9e4eb12016-04-13 12:09:06 -0700950 ingressDevice = senders[ 0 ].get( "device" )
951 egressDeviceList = [ x.get( "device" ) for x in recipients if x.get( "device" ) ]
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800952
Jeremyd9e4eb12016-04-13 12:09:06 -0700953 portIngress = senders[ 0 ].get( "port", "" )
954 portEgressList = [ x.get( "port" ) for x in recipients if x.get( "port" ) ]
955 if not portEgressList:
956 portEgressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800957
Jeremyd9e4eb12016-04-13 12:09:06 -0700958 srcMac = senders[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700959 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800960
Jeremyd9e4eb12016-04-13 12:09:06 -0700961 # Adding point intent
Devin Lim142b5342017-07-20 15:22:39 -0700962 intentId = main.Cluster.active( onosNode ).CLI.addSinglepointToMultipointIntent(
963 ingressDevice=ingressDevice,
964 egressDeviceList=egressDeviceList,
965 portIngress=portIngress,
966 portEgressList=portEgressList,
967 ethType=ethType,
968 ethSrc=srcMac,
969 bandwidth=bandwidth,
970 lambdaAlloc=lambdaAlloc,
971 ipProto=ipProto,
972 ipSrc="",
973 ipDst="",
974 tcpSrc="",
975 tcpDst="",
976 vlanId=vlanId,
977 setVlan=setVlan,
978 partial=partial,
979 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700980 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700981 errorMsg = "There was a problem loading the hosts data."
982 if intentId:
983 errorMsg += " There was a problem installing Singlepoint to Multipoint intent."
984 main.log.error( errorMsg )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700985 singleToMultiFailFlag = True
Jeremyd9e4eb12016-04-13 12:09:06 -0700986 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700987
988 # Check intents state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700989 if singleToMultiFailFlag:
Devin Lima4f95bc2017-08-11 11:13:03 -0700990 attempts = main.middleAttemptsNum
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700991 else:
Devin Lima4f95bc2017-08-11 11:13:03 -0700992 attempts = main.generalAttemptsNum
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700993
Jon Hallaf95c3e2017-05-16 13:20:37 -0700994 if utilities.retry( f=checkIntentState,
995 retValue=main.FALSE,
Jon Hallf539eb92017-05-22 17:18:42 -0700996 args=( main, [ intentId ] ),
Jon Hallaf95c3e2017-05-16 13:20:37 -0700997 sleep=main.checkIntentSleep,
998 attempts=attempts ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700999 main.assertReturnString += 'Install Intent State Passed\n'
Jon Hallf539eb92017-05-22 17:18:42 -07001000 if bandwidth != "":
1001 allocationsFile = open( os.path.dirname( main.testFile ) + main.params[ 'DEPENDENCY' ][ 'filePath' ], 'r' )
1002 expectedFormat = allocationsFile.read()
1003 bandwidthCheck = checkBandwidthAllocations( main, expectedFormat )
1004 allocationsFile.close()
1005 if bandwidthCheck:
1006 main.assertReturnString += 'Bandwidth Allocation check Passed\n'
1007 else:
1008 main.assertReturnString += 'Bandwidth Allocation check Failed\n'
Jon Hallc3f88af2017-05-23 11:25:54 -07001009 return main.FALSE
1010
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001011 if flowDuration( main ):
1012 main.assertReturnString += 'Flow duration check Passed\n'
1013 return intentId
1014 else:
1015 main.assertReturnString += 'Flow duration check failed\n'
1016 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -07001017 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001018 main.log.error( "Single to Multi Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001019 singleToMultiFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001020 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001021
Jon Hall78be4962017-05-23 14:53:53 -07001022
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001023def installMultiToSingleIntent( main,
1024 name,
1025 senders,
1026 recipients,
1027 onosNode=0,
1028 ethType="",
1029 bandwidth="",
1030 lambdaAlloc=False,
1031 ipProto="",
1032 ipAddresses="",
1033 tcp="",
1034 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -07001035 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -07001036 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -07001037 partial=False,
Jon Hallf539eb92017-05-22 17:18:42 -07001038 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001039 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001040 Installs a Multi to Single Point Intent
1041
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001042 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001043 Install a multi to single point intent using
1044 add-multi-to-single-intent
1045
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001046 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001047 - Fetch host data if not given
1048 - Add multi to single intent
1049 - Ingress devices are the senders devices
1050 - Egress device is the first recipient host
1051 - Ports if defined in senders or recipients
1052 - MAC address ethSrc loaded from Ingress device
1053 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001054 Required:
1055 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001056 senders - List of host dictionaries i.e.
1057 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
1058 recipients - List of host dictionaries i.e.
1059 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001060 Optional:
1061 onosNode - ONOS node to install the intents in main.CLIs[ ]
1062 0 by default so that it will always use the first
1063 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001064 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001065 bandwidth - Bandwidth capacity
1066 lambdaAlloc - Allocate lambda, defaults to False
1067 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001068 tcp - TCP ports in the same order as the hosts in hostNames
1069 sw1 - First switch to bring down & up for rerouting purpose
1070 sw2 - Second switch to bring down & up for rerouting purpose
1071 expectedLink - Expected link when the switches are down, it should
1072 be two links lower than the links before the two
1073 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001074 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001075 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001076 assert senders, "You must specify a sender"
1077 assert recipients, "You must specify a recipient"
1078 # Assert devices or main.hostsData, "You must specify devices"
1079
1080 global itemName # The name of this run. Used for logs.
1081 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001082
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001083 global multiToSingleFailFlag
1084 multiToSingleFailFlag = False
1085
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001086 main.log.info( itemName + ": Adding mutli to single point intents" )
1087
Jeremyd9e4eb12016-04-13 12:09:06 -07001088 try:
1089 for sender in senders:
1090 if not sender.get( "device" ):
1091 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1092 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001093
Jeremyd9e4eb12016-04-13 12:09:06 -07001094 for recipient in recipients:
1095 if not recipient.get( "device" ):
1096 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1097 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001098
Jeremyd9e4eb12016-04-13 12:09:06 -07001099 ingressDeviceList = [ x.get( "device" ) for x in senders if x.get( "device" ) ]
1100 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001101
Jeremyd9e4eb12016-04-13 12:09:06 -07001102 portIngressList = [ x.get( "port" ) for x in senders if x.get( "port" ) ]
1103 portEgress = recipients[ 0 ].get( "port", "" )
1104 if not portIngressList:
1105 portIngressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001106
Jeremyd9e4eb12016-04-13 12:09:06 -07001107 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001108 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001109
Jeremyd9e4eb12016-04-13 12:09:06 -07001110 # Adding point intent
Devin Lim142b5342017-07-20 15:22:39 -07001111 intentId = main.Cluster.active( onosNode ).CLI.addMultipointToSinglepointIntent(
1112 ingressDeviceList=ingressDeviceList,
1113 egressDevice=egressDevice,
1114 portIngressList=portIngressList,
1115 portEgress=portEgress,
1116 ethType=ethType,
1117 ethDst=dstMac,
1118 bandwidth=bandwidth,
1119 lambdaAlloc=lambdaAlloc,
1120 ipProto=ipProto,
1121 ipSrc="",
1122 ipDst="",
1123 tcpSrc="",
1124 tcpDst="",
1125 vlanId=vlanId,
1126 setVlan=setVlan,
1127 partial=partial,
1128 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001129 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001130 errorMsg = "There was a problem loading the hosts data."
1131 if intentId:
1132 errorMsg += " There was a problem installing Multipoint to Singlepoint intent."
1133 main.log.error( errorMsg )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001134 multiToSingleFailFlag = True
Jeremyd9e4eb12016-04-13 12:09:06 -07001135 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001136
1137 # Check intents state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001138 if multiToSingleFailFlag:
Devin Lima4f95bc2017-08-11 11:13:03 -07001139 attempts = main.middleAttemptsNum
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001140 else:
Devin Lima4f95bc2017-08-11 11:13:03 -07001141 attempts = main.generalAttemptsNum
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001142
Jon Hallaf95c3e2017-05-16 13:20:37 -07001143 if utilities.retry( f=checkIntentState,
1144 retValue=main.FALSE,
Jon Hallf539eb92017-05-22 17:18:42 -07001145 args=( main, [ intentId ] ),
Jon Hallaf95c3e2017-05-16 13:20:37 -07001146 sleep=main.checkIntentSleep,
1147 attempts=attempts ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001148 main.assertReturnString += 'Install Intent State Passed\n'
Jon Hallf539eb92017-05-22 17:18:42 -07001149 if bandwidth != "":
1150 allocationsFile = open( os.path.dirname( main.testFile ) + main.params[ 'DEPENDENCY' ][ 'filePath' ], 'r' )
1151 expectedFormat = allocationsFile.read()
1152 bandwidthCheck = checkBandwidthAllocations( main, expectedFormat )
1153 allocationsFile.close()
1154 if bandwidthCheck:
1155 main.assertReturnString += 'Bandwidth Allocation check Passed\n'
1156 else:
1157 main.assertReturnString += 'Bandwidth Allocation check Failed\n'
Jon Hallc3f88af2017-05-23 11:25:54 -07001158 return main.FALSE
1159
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001160 if flowDuration( main ):
1161 main.assertReturnString += 'Flow duration check Passed\n'
1162 return intentId
1163 else:
1164 main.assertReturnString += 'Flow duration check failed\n'
1165 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001166 else:
1167 main.log.error( "Multi to Single Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001168 multiToSingleFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001169 return main.FALSE
1170
Jon Hall78be4962017-05-23 14:53:53 -07001171
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001172def testPointIntent( main,
Jeremye0cb5eb2016-01-27 17:39:09 -08001173 name,
1174 intentId,
1175 senders,
1176 recipients,
1177 badSenders={},
1178 badRecipients={},
1179 onosNode=0,
1180 ethType="",
1181 bandwidth="",
1182 lambdaAlloc=False,
alisonda157272016-12-22 01:13:21 -08001183 protected=False,
Jeremye0cb5eb2016-01-27 17:39:09 -08001184 ipProto="",
1185 ipAddresses="",
1186 tcp="",
1187 sw1="s5",
1188 sw2="s2",
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001189 expectedLink=0,
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001190 useTCP=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001191 """
1192 Test a Point Intent
1193
1194 Description:
1195 Test a point intent
1196
1197 Steps:
1198 - Fetch host data if not given
1199 - Check Intent State
1200 - Check Flow State
1201 - Check Connectivity
1202 - Check Lack of Connectivity Between Hosts not in the Intent
1203 - Reroute
1204 - Take Expected Link Down
1205 - Check Intent State
1206 - Check Flow State
1207 - Check Topology
1208 - Check Connectivity
1209 - Bring Expected Link Up
1210 - Check Intent State
1211 - Check Flow State
1212 - Check Topology
1213 - Check Connectivity
1214 - Remove Topology
1215
1216 Required:
1217 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
1218
1219 senders - List of host dictionaries i.e.
1220 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
1221 recipients - List of host dictionaries i.e.
1222 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
1223 Optional:
1224 onosNode - ONOS node to install the intents in main.CLIs[ ]
1225 0 by default so that it will always use the first
1226 ONOS node
1227 ethType - Ethernet type eg. IPV4, IPV6
1228 bandwidth - Bandwidth capacity
1229 lambdaAlloc - Allocate lambda, defaults to False
1230 ipProto - IP protocol
1231 tcp - TCP ports in the same order as the hosts in hostNames
1232 sw1 - First switch to bring down & up for rerouting purpose
1233 sw2 - Second switch to bring down & up for rerouting purpose
1234 expectedLink - Expected link when the switches are down, it should
1235 be two links lower than the links before the two
1236 switches are down
1237
1238 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001239 # Parameter Validity Check
1240 assert main, "There is no main variable"
1241 assert senders, "You must specify a sender"
1242 assert recipients, "You must specify a recipient"
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001243
1244 global itemName
1245 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001246
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001247 global pointIntentFailFlag
1248 global singleToMultiFailFlag
1249 global multiToSingleFailFlag
1250
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001251 main.log.info( itemName + ": Testing Point Intent" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001252
Jeremyd9e4eb12016-04-13 12:09:06 -07001253 try:
1254 # Names for scapy
1255 senderNames = [ x.get( "name" ) for x in senders ]
1256 recipientNames = [ x.get( "name" ) for x in recipients ]
1257 badSenderNames = [ x.get( "name" ) for x in badSenders ]
1258 badRecipientNames = [ x.get( "name" ) for x in badRecipients ]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001259
Jeremyd9e4eb12016-04-13 12:09:06 -07001260 for sender in senders:
1261 if not sender.get( "device" ):
1262 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1263 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001264
Jeremyd9e4eb12016-04-13 12:09:06 -07001265 for recipient in recipients:
1266 if not recipient.get( "device" ):
1267 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1268 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001269 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001270 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001271 main.log.error( "There was a problem loading the hosts data." )
1272 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001273
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001274 testResult = main.TRUE
1275 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001276
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001277 if pointIntentFailFlag or singleToMultiFailFlag or multiToSingleFailFlag:
Devin Lima4f95bc2017-08-11 11:13:03 -07001278 attempts = main.minimumAttemptsNum
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001279 else:
Devin Lima4f95bc2017-08-11 11:13:03 -07001280 attempts = main.generalAttemptsNum
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001281
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001282 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001283 if utilities.retry( f=checkIntentState,
1284 retValue=main.FALSE,
1285 args=( main, [ intentId ] ),
1286 sleep=main.checkIntentSleep,
1287 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001288 main.assertReturnString += 'Initial Intent State Passed\n'
acsmarsd4862d12015-10-06 17:57:34 -07001289 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001290 main.assertReturnString += 'Initial Intent State Failed\n'
1291 testResult = main.FALSE
Devin Lima4f95bc2017-08-11 11:13:03 -07001292 attempts = main.minimumAttemptsNum
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001293
1294 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001295 if utilities.retry( f=checkFlowsCount,
1296 retValue=main.FALSE,
1297 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001298 sleep=main.checkFlowCountSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001299 attempts=attempts ) and utilities.retry( f=checkFlowsState,
1300 retValue=main.FALSE,
1301 args=[ main ],
1302 sleep=main.checkFlowCountSleep,
1303 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001304 main.assertReturnString += 'Initial Flow State Passed\n'
1305 else:
1306 main.assertReturnString += 'Intial Flow State Failed\n'
1307 testResult = main.FALSE
1308
1309 # Check Connectivity
Jon Hallaf95c3e2017-05-16 13:20:37 -07001310 if utilities.retry( f=scapyCheckConnection,
1311 retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -07001312 args=( main, senderNames, recipientNames, vlanId, useTCP ),
Devin Lima4f95bc2017-08-11 11:13:03 -07001313 attempts=main.checkConnectionAttNum,
1314 sleep=main.checkConnectionSleep,
1315 getRetryingTime=True ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001316 main.assertReturnString += 'Initial Ping Passed\n'
1317 else:
1318 main.assertReturnString += 'Initial Ping Failed\n'
1319 testResult = main.FALSE
1320
1321 # Check connections that shouldn't work
1322 if badSenderNames:
1323 main.log.info( "Checking that packets from incorrect sender do not go through" )
Jon Hallaf95c3e2017-05-16 13:20:37 -07001324 if utilities.retry( f=scapyCheckConnection,
1325 retValue=main.FALSE,
1326 args=( main, badSenderNames, recipientNames ),
Devin Lima4f95bc2017-08-11 11:13:03 -07001327 kwargs={ "expectFailure": True },
1328 getRetryingTime=True ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001329 main.assertReturnString += 'Bad Sender Ping Passed\n'
1330 else:
1331 main.assertReturnString += 'Bad Sender Ping Failed\n'
1332 testResult = main.FALSE
1333
1334 if badRecipientNames:
1335 main.log.info( "Checking that packets to incorrect recipients do not go through" )
Jon Hallaf95c3e2017-05-16 13:20:37 -07001336 if utilities.retry( f=scapyCheckConnection,
1337 retValue=main.FALSE,
1338 args=( main, senderNames, badRecipientNames ),
Devin Lima4f95bc2017-08-11 11:13:03 -07001339 kwargs={ "expectFailure": True },
1340 getRetryingTime=True ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001341 main.assertReturnString += 'Bad Recipient Ping Passed\n'
1342 else:
1343 main.assertReturnString += 'Bad Recipient Ping Failed\n'
1344 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001345
1346 # Test rerouting if these variables exist
1347 if sw1 and sw2 and expectedLink:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001348 # Take link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001349 if utilities.retry( f=link,
1350 retValue=main.FALSE,
1351 args=( main, sw1, sw2, "down" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001352 main.assertReturnString += 'Link Down Passed\n'
1353 else:
1354 main.assertReturnString += 'Link Down Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001355 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001356
alisonda157272016-12-22 01:13:21 -08001357 if protected:
1358 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001359 if utilities.retry( f=scapyCheckConnection,
1360 retValue=main.FALSE,
Devin Lima4f95bc2017-08-11 11:13:03 -07001361 args=( main, senderNames, recipientNames, vlanId, useTCP ),
1362 getRetryingTime=True ):
alisonda157272016-12-22 01:13:21 -08001363 main.assertReturnString += 'Link down Scapy Packet Received Passed\n'
1364 else:
1365 main.assertReturnString += 'Link down Scapy Packet Recieved Failed\n'
1366 testResult = main.FALSE
1367
1368 if ProtectedIntentCheck( main ):
1369 main.assertReturnString += 'Protected Intent Check Passed\n'
1370 else:
1371 main.assertReturnString += 'Protected Intent Check Failed\n'
1372 testResult = main.FALSE
1373
acsmarsd4862d12015-10-06 17:57:34 -07001374 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001375 if utilities.retry( f=checkIntentState,
1376 retValue=main.FALSE,
1377 args=( main, [ intentId ] ),
1378 sleep=main.checkIntentPointSleep,
1379 attempts=attempts ):
acsmarsd4862d12015-10-06 17:57:34 -07001380 main.assertReturnString += 'Link Down Intent State Passed\n'
1381 else:
1382 main.assertReturnString += 'Link Down Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001383 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001384
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001385 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001386 if utilities.retry( f=checkFlowsCount,
1387 retValue=main.FALSE,
1388 args=[ main ],
1389 sleep=main.checkFlowCountSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001390 attempts=attempts ) and utilities.retry( f=checkFlowsState,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001391 retValue=main.FALSE,
1392 args=[ main ],
1393 sleep=main.checkFlowCountSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001394 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001395 main.assertReturnString += 'Link Down Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001396 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001397 main.assertReturnString += 'Link Down Flow State Failed\n'
1398 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001399
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001400 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001401 if utilities.retry( f=checkTopology,
1402 retValue=main.FALSE,
1403 args=( main, expectedLink ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001404 main.assertReturnString += 'Link Down Topology State Passed\n'
1405 else:
1406 main.assertReturnString += 'Link Down Topology State Failed\n'
1407 testResult = main.FALSE
1408
1409 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001410 if utilities.retry( f=scapyCheckConnection,
1411 retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -07001412 args=( main, senderNames, recipientNames, vlanId, useTCP ),
Jon Hallaf95c3e2017-05-16 13:20:37 -07001413 sleep=main.checkConnectionSleep,
Devin Lima4f95bc2017-08-11 11:13:03 -07001414 attempts=main.checkConnectionAttNum,
1415 getRetryingTime=True ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001416 main.assertReturnString += 'Link Down Pingall Passed\n'
1417 else:
1418 main.assertReturnString += 'Link Down Pingall Failed\n'
1419 testResult = main.FALSE
1420
1421 # Bring link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001422 if utilities.retry( f=link,
1423 retValue=main.FALSE,
1424 args=( main, sw1, sw2, "up" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001425 main.assertReturnString += 'Link Up Passed\n'
1426 else:
1427 main.assertReturnString += 'Link Up Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001428 testResult = main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -07001429
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001430 # Wait for reroute
Jon Hallf539eb92017-05-22 17:18:42 -07001431 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001432 time.sleep( main.rerouteSleep )
1433
acsmarsd4862d12015-10-06 17:57:34 -07001434 # Check Intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001435 if utilities.retry( f=checkIntentState,
1436 retValue=main.FALSE,
1437 attempts=attempts * 2,
1438 args=( main, [ intentId ] ),
Shreyaca8990f2017-03-16 11:43:11 -07001439 sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001440 main.assertReturnString += 'Link Up Intent State Passed\n'
1441 else:
1442 main.assertReturnString += 'Link Up Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001443 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001444
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001445 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001446 if utilities.retry( f=checkFlowsCount,
1447 retValue=main.FALSE,
1448 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001449 sleep=main.checkFlowCountSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001450 attempts=attempts ) and utilities.retry( f=checkFlowsState,
1451 retValue=main.FALSE,
1452 args=[ main ],
1453 sleep=main.checkFlowCountSleep,
1454 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001455 main.assertReturnString += 'Link Up Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001456 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001457 main.assertReturnString += 'Link Up Flow State Failed\n'
1458 testResult = main.FALSE
1459
1460 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001461 if utilities.retry( f=checkTopology,
1462 retValue=main.FALSE,
1463 args=( main, main.numLinks ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001464 main.assertReturnString += 'Link Up Topology State Passed\n'
1465 else:
1466 main.assertReturnString += 'Link Up Topology State Failed\n'
1467 testResult = main.FALSE
1468
1469 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001470 if utilities.retry( f=scapyCheckConnection,
1471 retValue=main.FALSE,
1472 sleep=main.checkConnectionSleep,
Devin Lima4f95bc2017-08-11 11:13:03 -07001473 attempts=main.checkConnectionAttNum,
1474 args=( main, senderNames, recipientNames, vlanId, useTCP ),
1475 getRetryingTime=True ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001476 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1477 else:
1478 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1479 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001480
1481 # Remove all intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001482 if utilities.retry( f=removeAllIntents,
1483 retValue=main.FALSE,
Devin Lima4f95bc2017-08-11 11:13:03 -07001484 attempts=main.removeIntentAttNum,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001485 args=( main, [ intentId ] ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001486 main.assertReturnString += 'Remove Intents Passed'
1487 else:
1488 main.assertReturnString += 'Remove Intents Failed'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001489 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001490
Devin Lim8619b552018-04-13 00:40:43 -07001491 # Check flows count in each node
1492 if utilities.retry( f=checkFlowsState,
1493 retValue=main.FALSE,
1494 args=[ main ],
1495 sleep=main.checkFlowCountSleep,
1496 attempts=3 ):
1497 main.assertReturnString += 'After removing intents Flow State Passed\n'
1498 else:
1499 main.assertReturnString += 'After removing intents Flow State Failed\n'
1500 testResult = main.FALSE
1501
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001502 return testResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001503
Jon Hall78be4962017-05-23 14:53:53 -07001504
Jeremye0cb5eb2016-01-27 17:39:09 -08001505def testEndPointFail( main,
1506 name,
1507 intentId,
1508 senders,
1509 recipients,
1510 isolatedSenders,
1511 isolatedRecipients,
1512 onosNode=0,
1513 ethType="",
1514 bandwidth="",
1515 lambdaAlloc=False,
1516 ipProto="",
1517 ipAddresses="",
1518 tcp="",
1519 sw1="",
1520 sw2="",
1521 sw3="",
1522 sw4="",
1523 sw5="",
1524 expectedLink1=0,
Jeremy Songster9385d412016-06-02 17:57:36 -07001525 expectedLink2=0,
1526 partial=False ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001527 """
Shreyaca8990f2017-03-16 11:43:11 -07001528 Test Multi point to single point intent Topology for Endpoint failures
Jeremye0cb5eb2016-01-27 17:39:09 -08001529 """
Jeremye0cb5eb2016-01-27 17:39:09 -08001530 # Parameter Validity Check
1531 assert main, "There is no main variable"
1532 assert senders, "You must specify a sender"
1533 assert recipients, "You must specify a recipient"
1534
1535 global itemName
1536 itemName = name
Jeremye0cb5eb2016-01-27 17:39:09 -08001537
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001538 global singleToMultiFailFlag
1539 global multiToSingleFailFlag
1540
Jeremye0cb5eb2016-01-27 17:39:09 -08001541 main.log.info( itemName + ": Testing Point Intent" )
1542
Jeremyd9e4eb12016-04-13 12:09:06 -07001543 try:
1544 # Names for scapy
1545 senderNames = [ x.get( "name" ) for x in senders ]
1546 recipientNames = [ x.get( "name" ) for x in recipients ]
1547 isolatedSenderNames = [ x.get( "name" ) for x in isolatedSenders ]
1548 isolatedRecipientNames = [ x.get( "name" ) for x in isolatedRecipients ]
Jon Hall78be4962017-05-23 14:53:53 -07001549 connectedSenderNames = [ x.get( "name" ) for x in senders if x.get( "name" ) not in isolatedSenderNames ]
1550 connectedRecipientNames = [ x.get( "name" ) for x in recipients if x.get( "name" ) not in isolatedRecipientNames ]
Jeremye0cb5eb2016-01-27 17:39:09 -08001551
Jeremyd9e4eb12016-04-13 12:09:06 -07001552 for sender in senders:
1553 if not sender.get( "device" ):
1554 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1555 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremye0cb5eb2016-01-27 17:39:09 -08001556
Jeremyd9e4eb12016-04-13 12:09:06 -07001557 for recipient in recipients:
1558 if not recipient.get( "device" ):
Jon Hall78be4962017-05-23 14:53:53 -07001559 main.log.warn( "Device not given for recipient {0}. Loading from " +
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001560 main.hostData.format( recipient.get( "name" ) ) )
Jeremyd9e4eb12016-04-13 12:09:06 -07001561 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001562 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001563 main.log.error( "There was a problem loading the hosts data." )
1564 return main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001565
1566 testResult = main.TRUE
1567 main.log.info( itemName + ": Adding multi point to single point intents" )
1568
1569 # Check intent state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001570 if singleToMultiFailFlag or multiToSingleFailFlag:
Devin Lima4f95bc2017-08-11 11:13:03 -07001571 attempts = main.minimumAttemptsNum
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001572 else:
Devin Lima4f95bc2017-08-11 11:13:03 -07001573 attempts = main.generalAttemptsNum
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001574
Jon Hallaf95c3e2017-05-16 13:20:37 -07001575 if utilities.retry( f=checkIntentState,
1576 retValue=main.FALSE,
1577 args=( main, [ intentId ] ),
1578 sleep=main.checkIntentSleep,
1579 attempts=attempts ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001580 main.assertReturnString += 'Initial Intent State Passed\n'
1581 else:
1582 main.assertReturnString += 'Initial Intent State Failed\n'
1583 testResult = main.FALSE
Devin Lima4f95bc2017-08-11 11:13:03 -07001584 attempts = main.minimumAttemptsNum
Jeremye0cb5eb2016-01-27 17:39:09 -08001585
1586 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001587 if utilities.retry( f=checkFlowsCount,
1588 retValue=main.FALSE,
1589 args=[ main ],
1590 attempts=5 ) and utilities.retry( f=checkFlowsState,
1591 retValue=main.FALSE,
1592 args=[ main ],
1593 attempts=5 ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001594 main.assertReturnString += 'Initial Flow State Passed\n'
1595 else:
1596 main.assertReturnString += 'Intial Flow State Failed\n'
1597 testResult = main.FALSE
1598
1599 # Check Connectivity
Jon Hallaf95c3e2017-05-16 13:20:37 -07001600 if utilities.retry( f=scapyCheckConnection,
1601 retValue=main.FALSE,
Devin Lima4f95bc2017-08-11 11:13:03 -07001602 args=( main, senderNames, recipientNames ),
1603 getRetryingTime=True ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001604 main.assertReturnString += 'Initial Connectivity Check Passed\n'
1605 else:
1606 main.assertReturnString += 'Initial Connectivity Check Failed\n'
1607 testResult = main.FALSE
1608
1609 # Take two links down
1610 # Take first link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001611 if utilities.retry( f=link,
1612 retValue=main.FALSE,
1613 args=( main, sw1, sw2, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001614 main.assertReturnString += 'Link Down Passed\n'
1615 else:
1616 main.assertReturnString += 'Link Down Failed\n'
1617 testResult = main.FALSE
1618
1619 # Take second link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001620 if utilities.retry( f=link,
1621 retValue=main.FALSE,
1622 args=( main, sw3, sw4, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001623 main.assertReturnString += 'Link Down Passed\n'
1624 else:
1625 main.assertReturnString += 'Link Down Failed\n'
1626 testResult = main.FALSE
1627
1628 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001629 if utilities.retry( f=checkIntentState,
1630 retValue=main.FALSE,
1631 attempts=attempts,
1632 args=( main, [ intentId ] ),
1633 sleep=main.checkIntentSleep ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001634 main.assertReturnString += 'Link Down Intent State Passed\n'
1635 else:
1636 main.assertReturnString += 'Link Down Intent State Failed\n'
1637 testResult = main.FALSE
1638
1639 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001640 if utilities.retry( f=checkFlowsCount,
1641 retValue=main.FALSE,
1642 sleep=1,
1643 attempts=attempts,
Jeremye0cb5eb2016-01-27 17:39:09 -08001644 args=[ main ] ) and utilities.retry( f=checkFlowsState,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001645 retValue=main.FALSE,
1646 sleep=1,
1647 attempts=attempts,
1648 args=[ main ] ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001649 main.assertReturnString += 'Link Down Flow State Passed\n'
1650 else:
1651 main.assertReturnString += 'Link Down Flow State Failed\n'
1652 testResult = main.FALSE
1653
1654 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001655 if utilities.retry( f=checkTopology,
1656 retValue=main.FALSE,
1657 args=( main, expectedLink1 ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001658 main.assertReturnString += 'Link Down Topology State Passed\n'
1659 else:
1660 main.assertReturnString += 'Link Down Topology State Failed\n'
1661 testResult = main.FALSE
1662
1663 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001664 if utilities.retry( f=scapyCheckConnection,
1665 retValue=main.FALSE,
Devin Lima4f95bc2017-08-11 11:13:03 -07001666 args=( main, senderNames, recipientNames ),
1667 getRetryingTime=True ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001668 main.assertReturnString += 'Link Down Connectivity Check Passed\n'
1669 else:
1670 main.assertReturnString += 'Link Down Connectivity Check Failed\n'
1671 testResult = main.FALSE
1672
1673 # Take a third link down to isolate one node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001674 if utilities.retry( f=link,
1675 retValue=main.FALSE,
1676 args=( main, sw3, sw5, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001677 main.assertReturnString += 'Isolation link Down Passed\n'
1678 else:
1679 main.assertReturnString += 'Isolation link Down Failed\n'
1680 testResult = main.FALSE
1681
Jeremy Songster9385d412016-06-02 17:57:36 -07001682 if partial:
1683 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001684 if utilities.retry( f=checkIntentState,
1685 retValue=main.FALSE,
1686 args=( main, [ intentId ] ),
1687 sleep=main.checkIntentSleep,
1688 attempts=attempts ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001689 main.assertReturnString += 'Partial failure isolation link Down Intent State Passed\n'
1690 else:
1691 main.assertReturnString += 'Partial failure isolation link Down Intent State Failed\n'
1692 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001693
Jeremy Songster9385d412016-06-02 17:57:36 -07001694 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001695 if utilities.retry( f=checkFlowsCount,
1696 retValue=main.FALSE,
1697 args=[ main ],
1698 attempts=5 ) and utilities.retry( f=checkFlowsState,
1699 retValue=main.FALSE,
1700 args=[ main ],
1701 attempts=5 ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001702 main.assertReturnString += 'Partial failure isolation link Down Flow State Passed\n'
1703 else:
1704 main.assertReturnString += 'Partial failure isolation link Down Flow State Failed\n'
1705 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001706
Jeremy Songster9385d412016-06-02 17:57:36 -07001707 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001708 if utilities.retry( f=checkTopology,
1709 retValue=main.FALSE,
1710 args=( main, expectedLink2 ) ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001711 main.assertReturnString += 'Partial failure isolation link Down Topology State Passed\n'
1712 else:
1713 main.assertReturnString += 'Partial failure isolation link Down Topology State Failed\n'
1714 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001715
Jeremy Songster9385d412016-06-02 17:57:36 -07001716 # Check Connectivity
1717 # First check connectivity of any isolated senders to recipients
1718 if isolatedSenderNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001719 if scapyCheckConnection( main,
1720 isolatedSenderNames,
1721 recipientNames,
1722 None,
1723 None,
1724 None,
1725 None,
1726 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001727 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1728 else:
1729 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1730 testResult = main.FALSE
1731
1732 # Next check connectivity of senders to any isolated recipients
1733 if isolatedRecipientNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001734 if scapyCheckConnection( main,
1735 senderNames,
1736 isolatedRecipientNames,
1737 None,
1738 None,
1739 None,
1740 None,
1741 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001742 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1743 else:
1744 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1745 testResult = main.FALSE
1746
1747 # Next check connectivity of connected senders and recipients
Jon Hallaf95c3e2017-05-16 13:20:37 -07001748 if utilities.retry( f=scapyCheckConnection,
1749 retValue=main.FALSE,
Devin Lima4f95bc2017-08-11 11:13:03 -07001750 attempts=main.checkConnectionAttNum,
1751 args=( main, connectedSenderNames, connectedRecipientNames ),
1752 getRetryingTime=True ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001753 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1754 else:
1755 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1756 testResult = main.FALSE
1757 else:
1758 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001759 if not utilities.retry( f=checkIntentState,
1760 retValue=main.TRUE,
1761 args=( main, [ intentId ] ),
1762 sleep=main.checkIntentSleep,
1763 attempts=attempts ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001764 main.assertReturnString += 'Isolation link Down Intent State Passed\n'
1765 else:
1766 main.assertReturnString += 'Isolation link Down Intent State Failed\n'
1767 testResult = main.FALSE
1768
1769 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001770 if utilities.retry( f=checkFlowsCount,
1771 retValue=main.FALSE,
1772 args=[ main ],
1773 attempts=5 ) and utilities.retry( f=checkFlowsState,
1774 retValue=main.FALSE,
1775 args=[ main ],
1776 attempts=5 ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001777 main.assertReturnString += 'Isolation link Down Flow State Passed\n'
1778 else:
1779 main.assertReturnString += 'Isolation link Down Flow State Failed\n'
1780 testResult = main.FALSE
1781
1782 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001783 if utilities.retry( f=checkTopology,
1784 retValue=main.FALSE,
1785 args=( main, expectedLink2 ) ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001786 main.assertReturnString += 'Isolation link Down Topology State Passed\n'
1787 else:
1788 main.assertReturnString += 'Isolation link Down Topology State Failed\n'
1789 testResult = main.FALSE
1790
1791 # Check Connectivity
1792 # First check connectivity of any isolated senders to recipients
1793 if isolatedSenderNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001794 if scapyCheckConnection( main,
1795 isolatedSenderNames,
1796 recipientNames,
1797 None,
1798 None,
1799 None,
1800 None,
1801 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001802 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1803 else:
1804 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1805 testResult = main.FALSE
1806
1807 # Next check connectivity of senders to any isolated recipients
1808 if isolatedRecipientNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001809 if scapyCheckConnection( main,
1810 senderNames,
1811 isolatedRecipientNames,
1812 None,
1813 None,
1814 None,
1815 None,
1816 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001817 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1818 else:
1819 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1820 testResult = main.FALSE
1821
1822 # Next check connectivity of connected senders and recipients
Jon Hallaf95c3e2017-05-16 13:20:37 -07001823 if utilities.retry( f=scapyCheckConnection,
1824 retValue=main.TRUE,
Devin Lima4f95bc2017-08-11 11:13:03 -07001825 args=( main, connectedSenderNames, connectedRecipientNames, None, None, None, None, main.TRUE ),
1826 getRetryingTime=True ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001827 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1828 else:
1829 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1830 testResult = main.FALSE
1831
Jeremye0cb5eb2016-01-27 17:39:09 -08001832 # Bring the links back up
1833 # Bring first link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001834 if utilities.retry( f=link,
1835 retValue=main.FALSE,
1836 args=( main, sw1, sw2, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001837 main.assertReturnString += 'Link Up Passed\n'
1838 else:
1839 main.assertReturnString += 'Link Up Failed\n'
1840 testResult = main.FALSE
1841
1842 # Bring second link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001843 if utilities.retry( f=link,
1844 retValue=main.FALSE,
1845 args=( main, sw3, sw5, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001846 main.assertReturnString += 'Link Up Passed\n'
1847 else:
1848 main.assertReturnString += 'Link Up Failed\n'
1849 testResult = main.FALSE
1850
1851 # Bring third link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001852 if utilities.retry( f=link,
1853 retValue=main.FALSE,
1854 args=( main, sw3, sw4, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001855 main.assertReturnString += 'Link Up Passed\n'
1856 else:
1857 main.assertReturnString += 'Link Up Failed\n'
1858 testResult = main.FALSE
1859
1860 # Wait for reroute
Jon Hallf539eb92017-05-22 17:18:42 -07001861 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
Jeremye0cb5eb2016-01-27 17:39:09 -08001862 time.sleep( main.rerouteSleep )
1863
1864 # Check Intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001865 if utilities.retry( f=checkIntentState,
1866 retValue=main.FALSE,
1867 attempts=attempts,
1868 args=( main, [ intentId ] ),
1869 sleep=main.checkIntentHostSleep ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001870 main.assertReturnString += 'Link Up Intent State Passed\n'
1871 else:
1872 main.assertReturnString += 'Link Up Intent State Failed\n'
1873 testResult = main.FALSE
1874
1875 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001876 if utilities.retry( f=checkFlowsCount,
1877 retValue=main.FALSE,
1878 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001879 sleep=main.checkFlowCountSleep,
1880 attempts=attempts ) and utilities.retry( f=checkFlowsState,
Jon Hall78be4962017-05-23 14:53:53 -07001881 retValue=main.FALSE,
1882 args=[ main ],
1883 sleep=main.checkFlowCountSleep,
1884 attempts=attempts ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001885 main.assertReturnString += 'Link Up Flow State Passed\n'
1886 else:
1887 main.assertReturnString += 'Link Up Flow State Failed\n'
1888 testResult = main.FALSE
1889
1890 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001891 if utilities.retry( f=checkTopology,
1892 retValue=main.FALSE,
1893 args=( main, main.numLinks ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001894 main.assertReturnString += 'Link Up Topology State Passed\n'
1895 else:
1896 main.assertReturnString += 'Link Up Topology State Failed\n'
1897 testResult = main.FALSE
1898
1899 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001900 if utilities.retry( f=scapyCheckConnection,
1901 retValue=main.FALSE,
1902 sleep=main.checkConnectionSleep,
Devin Lima4f95bc2017-08-11 11:13:03 -07001903 attempts=main.checkConnectionAttNum,
1904 args=( main, senderNames, recipientNames ),
1905 getRetryingTime=True ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001906 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1907 else:
1908 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1909 testResult = main.FALSE
1910
1911 # Remove all intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001912 if utilities.retry( f=removeAllIntents,
1913 retValue=main.FALSE,
Devin Lima4f95bc2017-08-11 11:13:03 -07001914 attempts=main.removeIntentAttNum,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001915 args=( main, [ intentId ] ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001916 main.assertReturnString += 'Remove Intents Passed'
1917 else:
1918 main.assertReturnString += 'Remove Intents Failed'
1919 testResult = main.FALSE
1920
Devin Lim8619b552018-04-13 00:40:43 -07001921 # Check flows count in each node
1922 if utilities.retry( f=checkFlowsState,
1923 retValue=main.FALSE,
1924 args=[ main ],
1925 sleep=main.checkFlowCountSleep,
1926 attempts=3 ):
1927 main.assertReturnString += 'After removing intents Flow State Passed\n'
1928 else:
1929 main.assertReturnString += 'After removing intents Flow State Failed\n'
1930 testResult = main.FALSE
1931
Jeremye0cb5eb2016-01-27 17:39:09 -08001932 return testResult
1933
1934
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001935def pingallHosts( main, hostList ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001936 """
1937 Ping all host in the hosts list variable
1938 """
Jon Halla5cb3412015-08-18 14:08:22 -07001939 main.log.info( "Pinging: " + str( hostList ) )
You Wanga0f6ff62018-01-11 15:46:30 -08001940 return main.Network.pingallHosts( hostList )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001941
Jon Hall78be4962017-05-23 14:53:53 -07001942
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001943def fwdPingall( main ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001944 """
1945 Use fwd app and pingall to discover all the hosts
1946 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001947 appCheck = main.TRUE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001948 main.log.info( "Activating reactive forwarding app " )
Devin Lim142b5342017-07-20 15:22:39 -07001949 activateResult = main.Cluster.active( 0 ).CLI.activateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001950
1951 # Wait for forward app activation to propagate
Jon Hallf539eb92017-05-22 17:18:42 -07001952 main.log.info( "Sleeping {} seconds".format( main.fwdSleep ) )
kelvin-onlab0ad05d12015-07-23 14:21:15 -07001953 time.sleep( main.fwdSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001954
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001955 # Check that forwarding is enabled on all nodes
Devin Lim142b5342017-07-20 15:22:39 -07001956 for ctrl in main.Cluster.active():
1957 appCheck = appCheck and ctrl.CLI.appToIDCheck()
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001958 if appCheck != main.TRUE:
Devin Lim142b5342017-07-20 15:22:39 -07001959 main.log.warn( ctrl.CLI.apps() )
1960 main.log.warn( ctrl.CLI.appIDs() )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001961
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001962 # Send pingall in mininet
1963 main.log.info( "Run Pingall" )
You Wanga0f6ff62018-01-11 15:46:30 -08001964 pingResult = main.Network.pingall( timeout=600 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001965
1966 main.log.info( "Deactivating reactive forwarding app " )
Devin Lim142b5342017-07-20 15:22:39 -07001967 deactivateResult = main.Cluster.active( 0 ).CLI.deactivateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001968 if activateResult and deactivateResult:
1969 main.log.info( "Successfully used fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001970 getDataResult = main.TRUE
1971 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001972 main.log.info( "Failed to use fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001973 getDataResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001974 return getDataResult
1975
Jon Hall78be4962017-05-23 14:53:53 -07001976
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001977def confirmHostDiscovery( main ):
1978 """
1979 Confirms that all ONOS nodes have discovered all scapy hosts
1980 """
1981 import collections
Devin Lim58046fa2017-07-05 16:55:00 -07001982 try:
1983 from tests.dependencies.topology import Topology
1984 except Exception:
1985 main.log.error( "Topology not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -07001986 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -07001987 try:
1988 main.topoRelated
1989 except Exception:
1990 main.topoRelated = Topology()
Devin Lim142b5342017-07-20 15:22:39 -07001991 hosts = main.topoRelated.getAll( "hosts", False ) # Get host data from each ONOS node
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001992 hostFails = [] # Reset for each failed attempt
1993
1994 # Check for matching hosts on each node
1995 scapyHostIPs = [ x.hostIp for x in main.scapyHosts if x.hostIp != "0.0.0.0" ]
Devin Lim142b5342017-07-20 15:22:39 -07001996 for controller in range( main.Cluster.numCtrls ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001997 controllerStr = str( controller + 1 ) # ONOS node number
1998 # Compare Hosts
1999 # Load hosts data for controller node
Jeremyd9e4eb12016-04-13 12:09:06 -07002000 try:
2001 if hosts[ controller ]:
2002 main.log.info( "Hosts discovered" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002003 else:
Jeremyd9e4eb12016-04-13 12:09:06 -07002004 main.log.error( "Problem discovering hosts" )
2005 if hosts[ controller ] and "Error" not in hosts[ controller ]:
2006 try:
2007 hostData = json.loads( hosts[ controller ] )
2008 except ( TypeError, ValueError ):
2009 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002010 hostFails.append( controllerStr )
Jeremyd9e4eb12016-04-13 12:09:06 -07002011 else:
2012 onosHostIPs = [ x.get( "ipAddresses" )[ 0 ]
2013 for x in hostData
2014 if len( x.get( "ipAddresses" ) ) > 0 ]
Jon Hall78be4962017-05-23 14:53:53 -07002015 if not set( collections.Counter( scapyHostIPs ) ).issubset(
2016 set( collections.Counter( onosHostIPs ) ) ):
Jeremyd9e4eb12016-04-13 12:09:06 -07002017 main.log.warn( "Controller {0} only sees nodes with {1} IPs. It should see all of the following: {2}".format( controllerStr, onosHostIPs, scapyHostIPs ) )
2018 hostFails.append( controllerStr )
2019 else:
2020 main.log.error( "Hosts returned nothing or an error." )
2021 hostFails.append( controllerStr )
2022 except IndexError:
2023 main.log.error( "Hosts returned nothing, Failed to discover hosts." )
2024 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002025
2026 if hostFails:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002027 main.log.error( "List of failed ONOS Nodes:" + ', '.join( map( str, hostFails ) ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002028 return main.FALSE
2029 else:
2030 return main.TRUE
2031
Jon Hall78be4962017-05-23 14:53:53 -07002032
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002033def sendDiscoveryArp( main, hosts=None ):
2034 """
2035 Sends Discovery ARP packets from each host provided
2036 Defaults to each host in main.scapyHosts
2037 """
2038 # Send an arp ping from each host
2039 if not hosts:
2040 hosts = main.scapyHosts
2041 for host in hosts:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002042 pkt = 'Ether( src="{0}")/ARP( psrc="{1}")'.format( host.hostMac, host.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002043 # Send from the VLAN interface if there is one so ONOS discovers the VLAN correctly
2044 iface = None
2045 for interface in host.getIfList():
2046 if '.' in interface:
2047 main.log.debug( "Detected VLAN interface {0}. Sending ARP packet from {0}".format( interface ) )
2048 iface = interface
2049 break
2050 host.sendPacket( packet=pkt, iface=iface )
2051 main.log.info( "Sending ARP packet from {0}".format( host.name ) )
2052
Jon Hall78be4962017-05-23 14:53:53 -07002053
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002054def populateHostData( main ):
2055 """
2056 Populates hostsData
2057 """
2058 import json
2059 try:
Devin Lim142b5342017-07-20 15:22:39 -07002060 hostsJson = json.loads( main.Cluster.active( 0 ).CLI.hosts() )
You Wanga0f6ff62018-01-11 15:46:30 -08002061 hosts = main.Network.getHosts().keys()
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002062 # TODO: Make better use of new getHosts function
2063 for host in hosts:
2064 main.hostsData[ host ] = {}
2065 main.hostsData[ host ][ 'mac' ] = \
You Wanga0f6ff62018-01-11 15:46:30 -08002066 main.Network.getMacAddress( host ).upper()
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002067 for hostj in hostsJson:
2068 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
2069 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
2070 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
2071 main.hostsData[ host ][ 'location' ] = \
Jeremy Ronquillo0e538bc2017-06-13 15:16:09 -07002072 hostj[ 'locations' ][ 0 ][ 'elementId' ] + '/' + \
2073 hostj[ 'locations' ][ 0 ][ 'port' ]
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002074 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
2075 return main.TRUE
Jeremyd9e4eb12016-04-13 12:09:06 -07002076 except ValueError:
2077 main.log.error( "ValueError while populating hostsData" )
2078 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002079 except KeyError:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002080 main.log.error( "KeyError while populating hostsData" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002081 return main.FALSE
Jeremyd9e4eb12016-04-13 12:09:06 -07002082 except IndexError:
2083 main.log.error( "IndexError while populating hostsData" )
2084 return main.FALSE
2085 except TypeError:
2086 main.log.error( "TypeError while populating hostsData" )
2087 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002088
Jon Hall78be4962017-05-23 14:53:53 -07002089
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002090def checkTopology( main, expectedLink ):
2091 statusResult = main.TRUE
2092 # Check onos topology
2093 main.log.info( itemName + ": Checking ONOS topology " )
2094
Devin Lim142b5342017-07-20 15:22:39 -07002095 statusResult = main.Cluster.command( "checkStatus",
2096 args=[ main.numSwitch, expectedLink ],
2097 returnBool=True, specificDriver=2 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002098 if not statusResult:
2099 main.log.error( itemName + ": Topology mismatch" )
2100 else:
2101 main.log.info( itemName + ": Topology match" )
2102 return statusResult
2103
Jon Hall78be4962017-05-23 14:53:53 -07002104
Jon Hallf539eb92017-05-22 17:18:42 -07002105def checkIntentState( main, intentsId ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002106 """
2107 This function will check intent state to make sure all the intents
2108 are in INSTALLED state
Jon Hallf539eb92017-05-22 17:18:42 -07002109 Returns main.TRUE or main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002110 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002111 intentResult = main.TRUE
Devin Lim142b5342017-07-20 15:22:39 -07002112 stateCheckResults = main.Cluster.command( "checkIntentState",
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002113 kwargs={ "intentsId": intentsId },
2114 returnBool=True, specificDriver=2 )
Devin Lim142b5342017-07-20 15:22:39 -07002115 if stateCheckResults:
Jon Hallf539eb92017-05-22 17:18:42 -07002116 main.log.info( itemName + ": Intents state check passed" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002117 else:
Jon Hallf539eb92017-05-22 17:18:42 -07002118 main.log.warn( "Intents state check failed" )
Shreyaca8990f2017-03-16 11:43:11 -07002119 intentResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002120 return intentResult
2121
Jon Hall78be4962017-05-23 14:53:53 -07002122
Jon Hallf539eb92017-05-22 17:18:42 -07002123def checkBandwidthAllocations( main, bandwidth ):
2124 """
2125 Compare the given bandwith allocation output to the cli output on each node
2126 Returns main.TRUE or main.FALSE
2127 """
Devin Lim142b5342017-07-20 15:22:39 -07002128 stateCheckResults = main.Cluster.command( "compareBandwidthAllocations",
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002129 args=[ bandwidth ],
2130 returnBool=True, specificDriver=2 )
Devin Lim142b5342017-07-20 15:22:39 -07002131 if stateCheckResults:
Jon Hallf539eb92017-05-22 17:18:42 -07002132 main.log.info( itemName + ": bandwidth check passed" )
2133 bandwidthResult = main.TRUE
2134 else:
2135 main.log.warn( itemName + ": bandwidth check failed" )
2136 bandwidthResult = main.FALSE
2137 return bandwidthResult
2138
Jon Hall78be4962017-05-23 14:53:53 -07002139
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002140def checkFlowsState( main ):
2141
2142 main.log.info( itemName + ": Check flows state" )
Devin Lim142b5342017-07-20 15:22:39 -07002143 checkFlowsResult = main.Cluster.active( 0 ).CLI.checkFlowsState( isPENDING=False )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002144 return checkFlowsResult
2145
Jon Hall78be4962017-05-23 14:53:53 -07002146
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002147def link( main, sw1, sw2, option ):
You Wangf6574de2018-02-09 14:43:47 -08002148 if main.usePortstate:
2149 # port down
2150 dpid = main.params[ 'MININET' ][ 'dpids' ][ sw1 ]
2151 port = main.params[ 'MININET' ][ 'ports' ][ sw1 ][ sw2 ]
2152 main.log.info( itemName + ": Bring port " + sw1 + "/" + port + " " + option )
2153 state = "disable" if option == "down" else "enable"
2154 result = main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state=state )
2155 else:
2156 # link down
2157 main.log.info( itemName + ": Bring link " + option + " between " +
2158 sw1 + " and " + sw2 )
2159 result = main.Network.link( end1=sw1, end2=sw2, option=option )
2160 return result
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002161
Jon Hall78be4962017-05-23 14:53:53 -07002162
Jon Hallaf95c3e2017-05-16 13:20:37 -07002163def scapyCheckConnection( main,
2164 senders,
2165 recipients,
2166 vlanId=None,
2167 useTCP=False,
2168 packet=None,
2169 packetFilter=None,
2170 expectFailure=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002171 """
2172 Checks the connectivity between all given sender hosts and all given recipient hosts
2173 Packet may be specified. Defaults to Ether/IP packet
2174 Packet Filter may be specified. Defaults to Ether/IP from current sender MAC
2175 Todo: Optional packet and packet filter attributes for sender and recipients
2176 Expect Failure when the sender and recipient are not supposed to have connectivity
2177 Timeout of 1 second, returns main.TRUE if the filter is not triggered and kills the filter
2178
2179 """
2180 connectionsFunctional = main.TRUE
2181
2182 if not packetFilter:
2183 packetFilter = 'ether host {}'
Jeremy Songstere405d3d2016-05-17 11:18:57 -07002184 if useTCP:
Jon Hall78be4962017-05-23 14:53:53 -07002185 packetFilter += ' ip proto \\tcp tcp port {}'.format( main.params[ 'SDNIP' ][ 'dstPort' ] )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002186 if expectFailure:
2187 timeout = 1
2188 else:
2189 timeout = 10
2190
2191 for sender in senders:
2192 try:
2193 senderComp = getattr( main, sender )
2194 except AttributeError:
2195 main.log.error( "main has no attribute {}".format( sender ) )
2196 connectionsFunctional = main.FALSE
2197 continue
2198
2199 for recipient in recipients:
2200 # Do not send packets to self since recipient CLI will already be busy
2201 if recipient == sender:
2202 continue
2203 try:
2204 recipientComp = getattr( main, recipient )
2205 except AttributeError:
2206 main.log.error( "main has no attribute {}".format( recipient ) )
2207 connectionsFunctional = main.FALSE
2208 continue
2209
Jeremy Songster832f9e92016-05-05 14:30:49 -07002210 if vlanId:
Jon Hall78be4962017-05-23 14:53:53 -07002211 recipientComp.startFilter( pktFilter=( "vlan {}".format( vlanId ) + " && " + packetFilter.format( senderComp.hostMac ) ) )
Jeremy Songster832f9e92016-05-05 14:30:49 -07002212 else:
Jon Hall78be4962017-05-23 14:53:53 -07002213 recipientComp.startFilter( pktFilter=packetFilter.format( senderComp.hostMac ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002214
2215 if not packet:
Jeremy Songster832f9e92016-05-05 14:30:49 -07002216 if vlanId:
2217 pkt = 'Ether( src="{0}", dst="{2}" )/Dot1Q(vlan={4})/IP( src="{1}", dst="{3}" )'.format(
2218 senderComp.hostMac,
2219 senderComp.hostIp,
2220 recipientComp.hostMac,
2221 recipientComp.hostIp,
2222 vlanId )
2223 else:
2224 pkt = 'Ether( src="{0}", dst="{2}" )/IP( src="{1}", dst="{3}" )'.format(
2225 senderComp.hostMac,
2226 senderComp.hostIp,
2227 recipientComp.hostMac,
2228 recipientComp.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002229 else:
2230 pkt = packet
Jeremy Songster832f9e92016-05-05 14:30:49 -07002231 if vlanId:
2232 senderComp.sendPacket( iface=( "{0}-eth0.{1}".format( sender, vlanId ) ), packet = pkt )
2233 else:
Jon Hall78be4962017-05-23 14:53:53 -07002234 senderComp.sendPacket( packet=pkt )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002235
2236 if recipientComp.checkFilter( timeout ):
2237 if expectFailure:
Jon Hall78be4962017-05-23 14:53:53 -07002238 main.log.error( "Packet from {0} successfully received by {1} when it should not have been".format( sender, recipient ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002239 connectionsFunctional = main.FALSE
2240 else:
Jon Hall78be4962017-05-23 14:53:53 -07002241 main.log.info( "Packet from {0} successfully received by {1}".format( sender, recipient ) )
alison52b25892016-09-19 10:53:48 -07002242 connectionsFunctional = main.TRUE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002243 else:
2244 recipientComp.killFilter()
2245 if expectFailure:
Jon Hall78be4962017-05-23 14:53:53 -07002246 main.log.info( "As expected, packet from {0} was not received by {1}".format( sender, recipient ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002247 else:
Jon Hall78be4962017-05-23 14:53:53 -07002248 main.log.error( "Packet from {0} was not received by {1}".format( sender, recipient ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002249 connectionsFunctional = main.FALSE
2250
2251 return connectionsFunctional
2252
Devin Lim8619b552018-04-13 00:40:43 -07002253def removeAllExistIntents( main ):
2254 main.Cluster.active( 0 ).CLI.removeAllIntents()
2255 main.log.debug( str( main.Cluster.active( 0 ).CLI.intents() ) )
2256 main.log.info( "Sleeping {} seconds".format( main.removeIntentSleep ) )
2257 time.sleep( main.removeIntentSleep )
2258
Devin Limfc913172018-04-18 17:53:58 -07002259 main.Cluster.active( 0 ).CLI.purgeWithdrawnIntents()
Devin Lim8619b552018-04-13 00:40:43 -07002260 main.log.debug( str( main.Cluster.active( 0 ).CLI.intents() ) )
2261 main.log.info( "Sleeping {} seconds".format( main.removeIntentSleep ) )
2262 time.sleep( main.removeIntentSleep )
2263
2264 # Check flows count in each node
2265 if utilities.retry( f=checkFlowsState,
2266 retValue=main.FALSE,
2267 args=[ main ],
2268 sleep=main.checkFlowCountSleep,
2269 attempts=3 ):
2270 main.assertReturnString += 'After removing intents Flow State Passed\n'
2271 else:
2272 main.assertReturnString += 'After removing intents Flow State Failed\n'
alison52b25892016-09-19 10:53:48 -07002273
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002274def removeAllIntents( main, intentsId ):
2275 """
2276 Remove all intents in the intentsId
2277 """
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002278 onosSummary = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002279 removeIntentResult = main.TRUE
2280 # Remove intents
2281 for intent in intentsId:
Devin Lim8619b552018-04-13 00:40:43 -07002282 main.Cluster.active( 0 ).CLI.removeIntent( intentId=intent )
2283 main.log.debug( str( main.Cluster.active( 0 ).CLI.intents() ) )
2284 main.log.info( "Sleeping {} seconds".format( 15 ) )
2285 time.sleep( 15 )
2286 try:
2287 intents = json.loads( main.Cluster.active( 0 ).CLI.intents() )
2288 for eachIntent in intents:
2289 if eachIntent.get( 'id' ) == intent and eachIntent.get( 'state' ) == 'WITHDRAWN':
2290 main.Cluster.active( 0 ).CLI.purgeWithdrawnIntents()
2291 main.log.debug( str( main.Cluster.active( 0 ).CLI.intents() ) )
2292 main.log.info( "Sleeping {} seconds".format( 15 ) )
2293 time.sleep( 15 )
2294 except:
2295 main.log.warn( 'Intent does not exist' )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002296
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002297 # If there is remianing intents then remove intents should fail
Devin Lim142b5342017-07-20 15:22:39 -07002298 for ctrl in main.Cluster.active():
2299 onosSummary.append( json.loads( ctrl.CLI.summary() ) )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002300
2301 for summary in onosSummary:
2302 if summary.get( 'intents' ) != 0:
2303 main.log.warn( itemName + ": There are " +
2304 str( summary.get( 'intents' ) ) +
2305 " intents remaining in node " +
2306 str( summary.get( 'node' ) ) +
2307 ", failed to remove all the intents " )
2308 removeIntentResult = main.FALSE
2309
2310 if removeIntentResult:
2311 main.log.info( itemName + ": There are no more intents remaining, " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002312 "successfully removed all the intents." )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002313
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002314 return removeIntentResult
2315
Jon Hall78be4962017-05-23 14:53:53 -07002316
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002317def checkFlowsCount( main ):
2318 """
2319 Check flows count in each node
2320 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002321 flowsCount = []
2322 main.log.info( itemName + ": Checking flows count in each ONOS node" )
Devin Lim142b5342017-07-20 15:22:39 -07002323 for ctrl in main.Cluster.active():
2324 summaryResult = ctrl.CLI.summary()
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002325 if not summaryResult:
2326 main.log.error( itemName + ": There is something wrong with " +
2327 "summary command" )
2328 return main.FALSE
2329 else:
2330 summaryJson = json.loads( summaryResult )
2331 flowsCount.append( summaryJson.get( 'flows' ) )
2332
2333 if flowsCount:
Jon Hall78be4962017-05-23 14:53:53 -07002334 if all( flows == flowsCount[ 0 ] for flows in flowsCount ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002335 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
2336 " flows in all ONOS node" )
2337 else:
Devin Lim142b5342017-07-20 15:22:39 -07002338 for i in range( main.Cluster.numCtrls ):
2339 main.log.debug( itemName + ": " + ctrl.name + " has " +
2340 str( flowsCount[ ctrl.pos ] ) + " flows" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002341 else:
2342 main.log.error( "Checking flows count failed, check summary command" )
2343 return main.FALSE
2344
2345 return main.TRUE
2346
Jon Hall78be4962017-05-23 14:53:53 -07002347
kelvin-onlab58dc39e2015-08-06 08:11:09 -07002348def checkLeaderChange( leaders1, leaders2 ):
acsmarse6b410f2015-07-17 14:39:34 -07002349 """
2350 Checks for a change in intent partition leadership.
2351
2352 Takes the output of leaders -c in json string format before and after
2353 a potential change as input
2354
2355 Returns main.TRUE if no mismatches are detected
2356 Returns main.FALSE if there is a mismatch or on error loading the input
2357 """
2358 try:
2359 leaders1 = json.loads( leaders1 )
2360 leaders2 = json.loads( leaders2 )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002361 except( AttributeError, TypeError ):
Jon Halld970abf2017-05-23 10:20:28 -07002362 main.log.exception( "checkLeaderChange: Object not as expected" )
acsmarse6b410f2015-07-17 14:39:34 -07002363 return main.FALSE
2364 except Exception:
Jon Halld970abf2017-05-23 10:20:28 -07002365 main.log.exception( "checkLeaderChange: Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002366 main.cleanAndExit()
2367
acsmarse6b410f2015-07-17 14:39:34 -07002368 main.log.info( "Checking Intent Paritions for Change in Leadership" )
2369 mismatch = False
2370 for dict1 in leaders1:
2371 if "intent" in dict1.get( "topic", [] ):
2372 for dict2 in leaders2:
Jon Hall78be4962017-05-23 14:53:53 -07002373 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and\
2374 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
acsmarse6b410f2015-07-17 14:39:34 -07002375 mismatch = True
Jon Hall78be4962017-05-23 14:53:53 -07002376 main.log.error( "%s changed leader from %s to %s",
2377 dict1.get( "topic", "no-topic" ),
2378 dict1.get( "leader", "no-leader" ),
2379 dict2.get( "leader", "no-leader" ) )
acsmarse6b410f2015-07-17 14:39:34 -07002380 if mismatch:
2381 return main.FALSE
2382 else:
2383 return main.TRUE
kelvin-onlab016dce22015-08-10 09:54:11 -07002384
Jon Hall78be4962017-05-23 14:53:53 -07002385
kelvin-onlab016dce22015-08-10 09:54:11 -07002386def report( main ):
2387 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002388 Report errors/warnings/exceptions
kelvin-onlab016dce22015-08-10 09:54:11 -07002389 """
Devin Lim142b5342017-07-20 15:22:39 -07002390 main.ONOSbench.logReport( main.Cluster.active( 0 ).ipAddress,
kelvin-onlab016dce22015-08-10 09:54:11 -07002391 [ "INFO",
2392 "FOLLOWER",
2393 "WARN",
2394 "flow",
2395 "ERROR",
2396 "Except" ],
2397 "s" )
2398
2399 main.log.info( "ERROR report: \n" )
Devin Lim142b5342017-07-20 15:22:39 -07002400 for ctrl in main.Cluster.active():
2401 main.ONOSbench.logReport( ctrl.ipAddress,
Jon Hall78be4962017-05-23 14:53:53 -07002402 [ "ERROR" ],
2403 "d" )
kelvin-onlab016dce22015-08-10 09:54:11 -07002404
2405 main.log.info( "EXCEPTIONS report: \n" )
Devin Lim142b5342017-07-20 15:22:39 -07002406 for ctrl in main.Cluster.active():
2407 main.ONOSbench.logReport( ctrl.ipAddress,
Jon Hall78be4962017-05-23 14:53:53 -07002408 [ "Except" ],
2409 "d" )
kelvin-onlab016dce22015-08-10 09:54:11 -07002410
2411 main.log.info( "WARNING report: \n" )
Devin Lim142b5342017-07-20 15:22:39 -07002412 for ctrl in main.Cluster.active():
2413 main.ONOSbench.logReport( ctrl.ipAddress,
Jon Hall78be4962017-05-23 14:53:53 -07002414 [ "WARN" ],
2415 "d" )
2416
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002417
2418def flowDuration( main ):
2419 """
2420 Check age of flows to see if flows are being overwritten
2421 """
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002422 main.log.info( "Getting current flow durations" )
Devin Lim142b5342017-07-20 15:22:39 -07002423 flowsJson1 = main.Cluster.active( 0 ).CLI.flows( noCore=True )
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002424 try:
2425 flowsJson1 = json.loads( flowsJson1 )
2426 except ValueError:
2427 main.log.error( "Unable to read flows" )
2428 return main.FALSE
2429 flowLife = []
2430 waitFlowLife = []
2431 for device in flowsJson1:
2432 if device.get( 'flowcount', 0 ) > 0:
2433 for i in range( device[ 'flowCount' ] ):
2434 flowLife.append( device[ 'flows' ][ i ][ 'life' ] )
2435 main.log.info( "Sleeping for {} seconds".format( main.flowDurationSleep ) )
2436 time.sleep( main.flowDurationSleep )
2437 main.log.info( "Getting new flow durations" )
Devin Lim142b5342017-07-20 15:22:39 -07002438 flowsJson2 = main.Cluster.active( 0 ).CLI.flows( noCore=True )
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002439 try:
2440 flowsJson2 = json.loads( flowsJson2 )
2441 except ValueError:
2442 main.log.error( "Unable to read flows" )
2443 return main.FALSE
2444 for device in flowsJson2:
2445 if device.get( 'flowcount', 0 ) > 0:
2446 for i in range( device[ 'flowCount' ] ):
2447 waitFlowLife.append( device[ 'flows' ][ i ][ 'life' ] )
2448 main.log.info( "Determining whether flows where overwritten" )
2449 if len( flowLife ) == len( waitFlowLife ):
alison52b25892016-09-19 10:53:48 -07002450 for i in range( len( flowLife ) ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002451 if waitFlowLife[ i ] - flowLife[ i ] < main.flowDurationSleep:
2452 return main.FALSE
2453 else:
2454 return main.FALSE
2455 return main.TRUE
alison52b25892016-09-19 10:53:48 -07002456
2457
2458def EncapsulatedIntentCheck( main, tag="" ):
2459 """
2460 Check encapsulated intents
Jon Hall78be4962017-05-23 14:53:53 -07002461 tag: encapsulation tag ( e.g. VLAN, MPLS )
alison52b25892016-09-19 10:53:48 -07002462
2463 Getting added flows
2464 Check tags on each flows
2465 If each direction has push or pop, passed
2466 else failed
2467
2468 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002469 main.log.info( "Checking encapsulated intent for " + tag + "." )
alison52b25892016-09-19 10:53:48 -07002470 HostJson = []
Devin Lim142b5342017-07-20 15:22:39 -07002471 Jflows = main.Cluster.active( 0 ).CLI.flows( noCore=True )
alison52b25892016-09-19 10:53:48 -07002472 try:
2473 Jflows = json.loads( Jflows )
2474 except ValueError:
2475 main.log.error( "Unable to read flows" )
2476 return main.FALSE
2477
2478 for flow in Jflows:
Jon Hall78be4962017-05-23 14:53:53 -07002479 if len( flow[ "flows" ] ) != 0:
alison52b25892016-09-19 10:53:48 -07002480 HostJson.append( flow[ "flows" ] )
2481
Jon Hall78be4962017-05-23 14:53:53 -07002482 totalflows = len( HostJson[ 0 ] )
alison52b25892016-09-19 10:53:48 -07002483
2484 pop = 0
2485 push = 0
2486
2487 PopTag = tag + "_POP"
2488 PushTag = tag + "_PUSH"
Devin Limf6d287d2017-08-04 14:39:11 -07002489 main.log.info( "Host Json info :" )
alison52b25892016-09-19 10:53:48 -07002490 for EachHostJson in HostJson:
Devin Lim8619b552018-04-13 00:40:43 -07002491 for singleHostJson in EachHostJson:
2492 main.log.info( str( singleHostJson ) )
2493 checkJson = singleHostJson[ "treatment" ][ "instructions" ][ 0 ]
Devin Limf6d287d2017-08-04 14:39:11 -07002494 main.Cluster.active( 0 ).REST.pprint( checkJson )
2495 if 'subtype' in checkJson:
2496 if checkJson[ "subtype" ] == PopTag:
2497 pop += 1
2498 elif checkJson[ "subtype" ] == PushTag:
2499 push += 1
alison52b25892016-09-19 10:53:48 -07002500
2501 if pop == totalflows and push == totalflows:
2502 return main.TRUE
2503 else:
Devin Limf6d287d2017-08-04 14:39:11 -07002504 main.log.error( "Total " + PushTag + str( push ) )
2505 main.log.error( "Total " + PopTag + str( pop ) )
alisonda157272016-12-22 01:13:21 -08002506 return main.FALSE
2507
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002508
alisonda157272016-12-22 01:13:21 -08002509def ProtectedIntentCheck( main ):
Devin Lim142b5342017-07-20 15:22:39 -07002510 intent = main.Cluster.active( 0 ).CLI.intents( jsonFormat=False )
alisonda157272016-12-22 01:13:21 -08002511 if "Protection" in intent:
2512 return main.TRUE
Shreyaca8990f2017-03-16 11:43:11 -07002513 return main.FALSE