blob: afe4c4ad2d6c90f8d8c70664982e9eb97537248b [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
413 return testResult
414
Jon Hall78be4962017-05-23 14:53:53 -0700415
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800416def installPointIntent( main,
417 name,
418 senders,
419 recipients,
420 onosNode=0,
421 ethType="",
422 bandwidth="",
423 lambdaAlloc=False,
alisonda157272016-12-22 01:13:21 -0800424 protected=False,
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800425 ipProto="",
426 ipSrc="",
427 ipDst="",
428 tcpSrc="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700429 tcpDst="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700430 setVlan="",
Jon Hallf539eb92017-05-22 17:18:42 -0700431 encap="" ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800432 """
433 Installs a Single to Single Point Intent
434
435 Description:
436 Install a single to single point intent
437
438 Steps:
439 - Fetch host data if not given
440 - Add point intent
441 - Ingress device is the first sender device
442 - Egress device is the first recipient device
443 - Ports if defined in senders or recipients
444 - MAC address ethSrc loaded from Ingress device
445 - Check intent state with retry
446 Required:
447 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
448 senders - List of host dictionaries i.e.
449 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
450 recipients - List of host dictionaries i.e.
451 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
452 Optional:
453 onosNode - ONOS node to install the intents in main.CLIs[ ]
454 0 by default so that it will always use the first
455 ONOS node
456 ethType - Ethernet type eg. IPV4, IPV6
457 bandwidth - Bandwidth capacity
458 lambdaAlloc - Allocate lambda, defaults to False
459 ipProto - IP protocol
460 tcp - TCP ports in the same order as the hosts in hostNames
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700461 sw1 - First switch to bring down & up for rerouting purpose
462 sw2 - Second switch to bring down & up for rerouting purpose
463 expectedLink - Expected link when the switches are down, it should
464 be two links lower than the links before the two
465 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700466 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700467 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800468 assert senders, "You must specify a sender"
469 assert recipients, "You must specify a recipient"
470 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700471
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800472 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700473 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700474
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700475 global pointIntentFailFlag
476 pointIntentFailFlag = False
477
Jeremy6f000c62016-02-25 17:02:28 -0800478 main.log.info( itemName + ": Adding point to point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700479
Jeremyd9e4eb12016-04-13 12:09:06 -0700480 try:
481 for sender in senders:
482 if not sender.get( "device" ):
483 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
484 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800485
Jeremyd9e4eb12016-04-13 12:09:06 -0700486 for recipient in recipients:
487 if not recipient.get( "device" ):
488 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
489 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800490
Jeremyd9e4eb12016-04-13 12:09:06 -0700491 ingressDevice = senders[ 0 ].get( "device" )
492 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800493
Jeremyd9e4eb12016-04-13 12:09:06 -0700494 portIngress = senders[ 0 ].get( "port", "" )
495 portEgress = recipients[ 0 ].get( "port", "" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800496
Jeremyd9e4eb12016-04-13 12:09:06 -0700497 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800498
Jeremyd9e4eb12016-04-13 12:09:06 -0700499 ipSrc = senders[ 0 ].get( "ip" )
500 ipDst = recipients[ 0 ].get( "ip" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800501
Jeremy Songster832f9e92016-05-05 14:30:49 -0700502 vlanId = senders[ 0 ].get( "vlan" )
503
Jeremyd9e4eb12016-04-13 12:09:06 -0700504 # Adding point intent
Devin Lim142b5342017-07-20 15:22:39 -0700505 intentId = main.Cluster.active( onosNode ).CLI.addPointIntent(
506 ingressDevice=ingressDevice,
507 egressDevice=egressDevice,
508 portIngress=portIngress,
509 portEgress=portEgress,
510 ethType=ethType,
511 ethDst=dstMac,
512 bandwidth=bandwidth,
513 lambdaAlloc=lambdaAlloc,
514 protected=protected,
515 ipProto=ipProto,
516 ipSrc=ipSrc,
517 ipDst=ipDst,
518 tcpSrc=tcpSrc,
519 tcpDst=tcpDst,
520 vlanId=vlanId,
521 setVlan=setVlan,
522 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700523 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700524 errorMsg = "There was a problem loading the hosts data."
525 if intentId:
526 errorMsg += " There was a problem installing Point to Point intent."
527 main.log.error( errorMsg )
528 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700529
530 # Check intents state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700531 if utilities.retry( f=checkIntentState,
532 retValue=main.FALSE,
Jon Hallf539eb92017-05-22 17:18:42 -0700533 args=( main, [ intentId ] ),
534 sleep=main.checkIntentSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -0700535 attempts=50 ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700536 main.assertReturnString += 'Install Intent State Passed\n'
alison52b25892016-09-19 10:53:48 -0700537
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700538 if bandwidth != "":
Jon Hallf539eb92017-05-22 17:18:42 -0700539 allocationsFile = open( os.path.dirname( main.testFile ) + main.params[ 'DEPENDENCY' ][ 'filePath' ], 'r' )
540 expectedFormat = allocationsFile.read()
541 bandwidthCheck = checkBandwidthAllocations( main, expectedFormat )
542 allocationsFile.close()
543 if bandwidthCheck:
544 main.assertReturnString += 'Bandwidth Allocation check Passed\n'
545 else:
546 main.assertReturnString += 'Bandwidth Allocation check Failed\n'
Jon Hallc3f88af2017-05-23 11:25:54 -0700547 return main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700548
alison52b25892016-09-19 10:53:48 -0700549 # Check VLAN if test encapsulation
550 if encap != "":
551 if EncapsulatedIntentCheck( main, tag=encap ):
552 main.assertReturnString += 'Encapsulation intents check Passed\n'
553 else:
554 main.assertReturnString += 'Encapsulation intents check failed\n'
alisonda157272016-12-22 01:13:21 -0800555
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700556 if flowDuration( main ):
557 main.assertReturnString += 'Flow duration check Passed\n'
558 return intentId
559 else:
560 main.assertReturnString += 'Flow duration check failed\n'
561 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -0700562 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800563 main.log.error( "Point Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700564 pointIntentFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800565 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700566
Jon Hall78be4962017-05-23 14:53:53 -0700567
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700568def pointIntentTcp( main,
569 name,
570 host1,
571 host2,
572 onosNode=0,
573 deviceId1="",
574 deviceId2="",
575 port1="",
576 port2="",
577 ethType="",
578 mac1="",
579 mac2="",
580 bandwidth="",
581 lambdaAlloc=False,
582 ipProto="",
583 ip1="",
584 ip2="",
585 tcp1="",
586 tcp2="",
587 sw1="",
588 sw2="",
589 expectedLink=0 ):
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700590 """
591 Description:
592 Verify add-point-intent only for TCP
593 Steps:
594 - Get device ids | ports
595 - Add point intents
596 - Check intents
597 - Verify flows
598 - Ping hosts
599 - Reroute
600 - Link down
601 - Verify flows
602 - Check topology
603 - Ping hosts
604 - Link up
605 - Verify flows
606 - Check topology
607 - Ping hosts
608 - Remove intents
609 Required:
610 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
611 host1 - Name of first host
612 host2 - Name of second host
613 Optional:
614 onosNode - ONOS node to install the intents in main.CLIs[ ]
615 0 by default so that it will always use the first
616 ONOS node
617 deviceId1 - ONOS device id of the first switch, the same as the
618 location of the first host eg. of:0000000000000001/1,
619 located at device 1 port 1
620 deviceId2 - ONOS device id of the second switch
621 port1 - The port number where the first host is attached
622 port2 - The port number where the second host is attached
623 ethType - Ethernet type eg. IPV4, IPV6
624 mac1 - Mac address of first host
625 mac2 - Mac address of the second host
626 bandwidth - Bandwidth capacity
627 lambdaAlloc - Allocate lambda, defaults to False
628 ipProto - IP protocol
629 ip1 - IP address of first host
630 ip2 - IP address of second host
631 tcp1 - TCP port of first host
632 tcp2 - TCP port of second host
633 sw1 - First switch to bring down & up for rerouting purpose
634 sw2 - Second switch to bring down & up for rerouting purpose
635 expectedLink - Expected link when the switches are down, it should
636 be two links lower than the links before the two
637 switches are down
638 """
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700639 assert main, "There is no main variable"
640 assert name, "variable name is empty"
641 assert host1 and host2, "You must specify hosts"
642
643 global itemName
644 itemName = name
645 host1 = host1
646 host2 = host2
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700647 intentsId = []
648
649 iperfResult = main.TRUE
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700650 linkDownResult = main.TRUE
651 linkUpResult = main.TRUE
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700652
653 # Adding bidirectional point intents
654 main.log.info( itemName + ": Adding point intents" )
Devin Lim142b5342017-07-20 15:22:39 -0700655 ctrl = main.Cluster.active( onosNode )
656 intent1 = ctrl.CLI.addPointIntent( ingressDevice=deviceId1,
657 egressDevice=deviceId2,
658 portIngress=port1,
659 portEgress=port2,
660 ethType=ethType,
661 ethSrc=mac1,
662 ethDst=mac2,
663 bandwidth=bandwidth,
664 lambdaAlloc=lambdaAlloc,
665 ipProto=ipProto,
666 ipSrc=ip1,
667 ipDst=ip2,
668 tcpSrc=tcp1,
669 tcpDst="" )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700670
Devin Lim142b5342017-07-20 15:22:39 -0700671 intent2 = ctrl.CLI.addPointIntent( ingressDevice=deviceId2,
672 egressDevice=deviceId1,
673 portIngress=port2,
674 portEgress=port1,
675 ethType=ethType,
676 ethSrc=mac2,
677 ethDst=mac1,
678 bandwidth=bandwidth,
679 lambdaAlloc=lambdaAlloc,
680 ipProto=ipProto,
681 ipSrc=ip2,
682 ipDst=ip1,
683 tcpSrc=tcp2,
684 tcpDst="" )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700685
Devin Lim142b5342017-07-20 15:22:39 -0700686 intent3 = ctrl.CLI.addPointIntent( ingressDevice=deviceId1,
687 egressDevice=deviceId2,
688 portIngress=port1,
689 portEgress=port2,
690 ethType=ethType,
691 ethSrc=mac1,
692 ethDst=mac2,
693 bandwidth=bandwidth,
694 lambdaAlloc=lambdaAlloc,
695 ipProto=ipProto,
696 ipSrc=ip1,
697 ipDst=ip2,
698 tcpSrc="",
699 tcpDst=tcp2 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700700
Devin Lim142b5342017-07-20 15:22:39 -0700701 intent4 = ctrl.CLI.addPointIntent( ingressDevice=deviceId2,
702 egressDevice=deviceId1,
703 portIngress=port2,
704 portEgress=port1,
705 ethType=ethType,
706 ethSrc=mac2,
707 ethDst=mac1,
708 bandwidth=bandwidth,
709 lambdaAlloc=lambdaAlloc,
710 ipProto=ipProto,
711 ipSrc=ip2,
712 ipDst=ip1,
713 tcpSrc="",
714 tcpDst=tcp1 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700715 intentsId.append( intent1 )
716 intentsId.append( intent2 )
717 intentsId.append( intent3 )
718 intentsId.append( intent4 )
719
720 # Check intents state
Jon Hallf539eb92017-05-22 17:18:42 -0700721 main.log.info( "Sleeping {} seconds".format( main.checkIntentSleep ) )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700722 time.sleep( main.checkIntentSleep )
Jon Hallaf95c3e2017-05-16 13:20:37 -0700723 intentResult = utilities.retry( f=checkIntentState,
724 retValue=main.FALSE,
725 args=( main, intentsId ),
726 sleep=1,
727 attempts=50 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700728 # Check flows count in each node
729 checkFlowsCount( main )
730
731 # Check intents state again if first check fails...
732 if not intentResult:
Jon Hallaf95c3e2017-05-16 13:20:37 -0700733 intentResult = utilities.retry( f=checkIntentState,
734 retValue=main.FALSE,
735 args=( main, intentsId ),
736 sleep=1,
737 attempts=50 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700738
739 # Check flows count in each node
740 checkFlowsCount( main )
741
742 # Verify flows
743 checkFlowsState( main )
744
745 # Run iperf to both host
You Wanga0f6ff62018-01-11 15:46:30 -0800746 iperfTemp = main.Network.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700747 iperfResult = iperfResult and iperfTemp
748 if iperfTemp:
749 main.assertReturnString += 'Initial Iperf Passed\n'
750 else:
751 main.assertReturnString += 'Initial Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700752
753 # Test rerouting if these variables exist
754 if sw1 and sw2 and expectedLink:
755 # link down
756 linkDownResult = link( main, sw1, sw2, "down" )
acsmarsd4862d12015-10-06 17:57:34 -0700757
758 if linkDownResult:
759 main.assertReturnString += 'Link Down Passed\n'
760 else:
761 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700762
763 # Check flows count in each node
764 checkFlowsCount( main )
765 # Verify flows
766 checkFlowsState( main )
767
768 # Check OnosTopology
769 topoResult = checkTopology( main, expectedLink )
acsmarsd4862d12015-10-06 17:57:34 -0700770 if topoResult:
771 main.assertReturnString += 'Link Down Topology State Passed\n'
772 else:
773 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700774
775 # Run iperf to both host
You Wanga0f6ff62018-01-11 15:46:30 -0800776 iperfTemp = main.Network.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700777 iperfResult = iperfResult and iperfTemp
778 if iperfTemp:
779 main.assertReturnString += 'Link Down Iperf Passed\n'
780 else:
781 main.assertReturnString += 'Link Down Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700782
acsmarsd4862d12015-10-06 17:57:34 -0700783 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700784 intentTemp = utilities.retry( f=checkIntentState,
785 retValue=main.FALSE,
786 args=( main, intentsId ),
787 sleep=1,
788 attempts=50 )
acsmarsd4862d12015-10-06 17:57:34 -0700789 intentResult = intentResult and intentTemp
790 if intentTemp:
791 main.assertReturnString += 'Link Down Intent State Passed\n'
792 else:
793 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700794
795 # Checks ONOS state in link down
796 if linkDownResult and topoResult and iperfResult and intentResult:
797 main.log.info( itemName + ": Successfully brought link down" )
798 else:
799 main.log.error( itemName + ": Failed to bring link down" )
800
801 # link up
802 linkUpResult = link( main, sw1, sw2, "up" )
alison52b25892016-09-19 10:53:48 -0700803 if linkUpResult:
acsmarsd4862d12015-10-06 17:57:34 -0700804 main.assertReturnString += 'Link Up Passed\n'
805 else:
806 main.assertReturnString += 'Link Up Failed\n'
807
Jon Hallf539eb92017-05-22 17:18:42 -0700808 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700809 time.sleep( main.rerouteSleep )
810
811 # Check flows count in each node
812 checkFlowsCount( main )
813 # Verify flows
814 checkFlowsState( main )
815
816 # Check OnosTopology
817 topoResult = checkTopology( main, main.numLinks )
818
acsmarsd4862d12015-10-06 17:57:34 -0700819 if topoResult:
820 main.assertReturnString += 'Link Up Topology State Passed\n'
821 else:
822 main.assertReturnString += 'Link Up Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700823
acsmarsd4862d12015-10-06 17:57:34 -0700824 # Run iperf to both host
You Wanga0f6ff62018-01-11 15:46:30 -0800825 iperfTemp = main.Network.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700826 iperfResult = iperfResult and iperfTemp
827 if iperfTemp:
828 main.assertReturnString += 'Link Up Iperf Passed\n'
829 else:
830 main.assertReturnString += 'Link Up Iperf Failed\n'
831
832 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700833 intentTemp = utilities.retry( f=checkIntentState,
834 retValue=main.FALSE,
835 args=( main, intentsId ),
836 sleep=1,
837 attempts=50 )
acsmarsd4862d12015-10-06 17:57:34 -0700838 intentResult = intentResult and intentTemp
839 if intentTemp:
840 main.assertReturnString += 'Link Down Intent State Passed\n'
841 else:
842 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700843
844 # Checks ONOS state in link up
845 if linkUpResult and topoResult and iperfResult and intentResult:
846 main.log.info( itemName + ": Successfully brought link back up" )
847 else:
848 main.log.error( itemName + ": Failed to bring link back up" )
849
850 # Remove all intents
851 removeIntentResult = removeAllIntents( main, intentsId )
acsmarsd4862d12015-10-06 17:57:34 -0700852 if removeIntentResult:
853 main.assertReturnString += 'Remove Intents Passed'
854 else:
855 main.assertReturnString += 'Remove Intents Failed'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700856
857 stepResult = iperfResult and linkDownResult and linkUpResult \
858 and intentResult and removeIntentResult
859
860 return stepResult
861
Jon Hall78be4962017-05-23 14:53:53 -0700862
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800863def installSingleToMultiIntent( main,
864 name,
865 senders,
866 recipients,
867 onosNode=0,
868 ethType="",
869 bandwidth="",
870 lambdaAlloc=False,
871 ipProto="",
872 ipAddresses="",
873 tcp="",
874 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700875 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -0700876 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700877 partial=False,
Jon Hallf539eb92017-05-22 17:18:42 -0700878 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700879 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800880 Installs a Single to Multi Point Intent
881
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700882 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800883 Install a single to multi point intent using
884 add-single-to-multi-intent
885
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700886 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800887 - Fetch host data if not given
888 - Add single to multi intent
889 - Ingress device is the first sender host
890 - Egress devices are the recipient devices
891 - Ports if defined in senders or recipients
892 - MAC address ethSrc loaded from Ingress device
893 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700894 Required:
895 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800896 senders - List of host dictionaries i.e.
897 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
898 recipients - List of host dictionaries i.e.
899 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700900 Optional:
901 onosNode - ONOS node to install the intents in main.CLIs[ ]
902 0 by default so that it will always use the first
903 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700904 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700905 bandwidth - Bandwidth capacity
906 lambdaAlloc - Allocate lambda, defaults to False
907 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700908 tcp - TCP ports in the same order as the hosts in hostNames
909 sw1 - First switch to bring down & up for rerouting purpose
910 sw2 - Second switch to bring down & up for rerouting purpose
911 expectedLink - Expected link when the switches are down, it should
912 be two links lower than the links before the two
913 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700914 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700915 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800916 assert senders, "You must specify a sender"
917 assert recipients, "You must specify a recipient"
918 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700919
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800920 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700921 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700922
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700923 global singleToMultiFailFlag
924 singleToMultiFailFlag = False
925
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700926 main.log.info( itemName + ": Adding single point to multi point intents" )
927
Jeremyd9e4eb12016-04-13 12:09:06 -0700928 try:
929 for sender in senders:
930 if not sender.get( "device" ):
931 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
932 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700933
Jeremyd9e4eb12016-04-13 12:09:06 -0700934 for recipient in recipients:
935 if not recipient.get( "device" ):
936 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
937 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700938
Jeremyd9e4eb12016-04-13 12:09:06 -0700939 ingressDevice = senders[ 0 ].get( "device" )
940 egressDeviceList = [ x.get( "device" ) for x in recipients if x.get( "device" ) ]
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800941
Jeremyd9e4eb12016-04-13 12:09:06 -0700942 portIngress = senders[ 0 ].get( "port", "" )
943 portEgressList = [ x.get( "port" ) for x in recipients if x.get( "port" ) ]
944 if not portEgressList:
945 portEgressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800946
Jeremyd9e4eb12016-04-13 12:09:06 -0700947 srcMac = senders[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700948 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800949
Jeremyd9e4eb12016-04-13 12:09:06 -0700950 # Adding point intent
Devin Lim142b5342017-07-20 15:22:39 -0700951 intentId = main.Cluster.active( onosNode ).CLI.addSinglepointToMultipointIntent(
952 ingressDevice=ingressDevice,
953 egressDeviceList=egressDeviceList,
954 portIngress=portIngress,
955 portEgressList=portEgressList,
956 ethType=ethType,
957 ethSrc=srcMac,
958 bandwidth=bandwidth,
959 lambdaAlloc=lambdaAlloc,
960 ipProto=ipProto,
961 ipSrc="",
962 ipDst="",
963 tcpSrc="",
964 tcpDst="",
965 vlanId=vlanId,
966 setVlan=setVlan,
967 partial=partial,
968 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700969 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700970 errorMsg = "There was a problem loading the hosts data."
971 if intentId:
972 errorMsg += " There was a problem installing Singlepoint to Multipoint intent."
973 main.log.error( errorMsg )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700974 singleToMultiFailFlag = True
Jeremyd9e4eb12016-04-13 12:09:06 -0700975 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700976
977 # Check intents state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700978 if singleToMultiFailFlag:
Devin Lima4f95bc2017-08-11 11:13:03 -0700979 attempts = main.middleAttemptsNum
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700980 else:
Devin Lima4f95bc2017-08-11 11:13:03 -0700981 attempts = main.generalAttemptsNum
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700982
Jon Hallaf95c3e2017-05-16 13:20:37 -0700983 if utilities.retry( f=checkIntentState,
984 retValue=main.FALSE,
Jon Hallf539eb92017-05-22 17:18:42 -0700985 args=( main, [ intentId ] ),
Jon Hallaf95c3e2017-05-16 13:20:37 -0700986 sleep=main.checkIntentSleep,
987 attempts=attempts ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700988 main.assertReturnString += 'Install Intent State Passed\n'
Jon Hallf539eb92017-05-22 17:18:42 -0700989 if bandwidth != "":
990 allocationsFile = open( os.path.dirname( main.testFile ) + main.params[ 'DEPENDENCY' ][ 'filePath' ], 'r' )
991 expectedFormat = allocationsFile.read()
992 bandwidthCheck = checkBandwidthAllocations( main, expectedFormat )
993 allocationsFile.close()
994 if bandwidthCheck:
995 main.assertReturnString += 'Bandwidth Allocation check Passed\n'
996 else:
997 main.assertReturnString += 'Bandwidth Allocation check Failed\n'
Jon Hallc3f88af2017-05-23 11:25:54 -0700998 return main.FALSE
999
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001000 if flowDuration( main ):
1001 main.assertReturnString += 'Flow duration check Passed\n'
1002 return intentId
1003 else:
1004 main.assertReturnString += 'Flow duration check failed\n'
1005 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -07001006 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001007 main.log.error( "Single to Multi Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001008 singleToMultiFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001009 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001010
Jon Hall78be4962017-05-23 14:53:53 -07001011
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001012def installMultiToSingleIntent( main,
1013 name,
1014 senders,
1015 recipients,
1016 onosNode=0,
1017 ethType="",
1018 bandwidth="",
1019 lambdaAlloc=False,
1020 ipProto="",
1021 ipAddresses="",
1022 tcp="",
1023 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -07001024 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -07001025 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -07001026 partial=False,
Jon Hallf539eb92017-05-22 17:18:42 -07001027 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001028 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001029 Installs a Multi to Single Point Intent
1030
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001031 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001032 Install a multi to single point intent using
1033 add-multi-to-single-intent
1034
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001035 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001036 - Fetch host data if not given
1037 - Add multi to single intent
1038 - Ingress devices are the senders devices
1039 - Egress device is the first recipient host
1040 - Ports if defined in senders or recipients
1041 - MAC address ethSrc loaded from Ingress device
1042 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001043 Required:
1044 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001045 senders - List of host dictionaries i.e.
1046 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
1047 recipients - List of host dictionaries i.e.
1048 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001049 Optional:
1050 onosNode - ONOS node to install the intents in main.CLIs[ ]
1051 0 by default so that it will always use the first
1052 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001053 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001054 bandwidth - Bandwidth capacity
1055 lambdaAlloc - Allocate lambda, defaults to False
1056 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001057 tcp - TCP ports in the same order as the hosts in hostNames
1058 sw1 - First switch to bring down & up for rerouting purpose
1059 sw2 - Second switch to bring down & up for rerouting purpose
1060 expectedLink - Expected link when the switches are down, it should
1061 be two links lower than the links before the two
1062 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001063 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001064 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001065 assert senders, "You must specify a sender"
1066 assert recipients, "You must specify a recipient"
1067 # Assert devices or main.hostsData, "You must specify devices"
1068
1069 global itemName # The name of this run. Used for logs.
1070 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001071
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001072 global multiToSingleFailFlag
1073 multiToSingleFailFlag = False
1074
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001075 main.log.info( itemName + ": Adding mutli to single point intents" )
1076
Jeremyd9e4eb12016-04-13 12:09:06 -07001077 try:
1078 for sender in senders:
1079 if not sender.get( "device" ):
1080 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1081 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001082
Jeremyd9e4eb12016-04-13 12:09:06 -07001083 for recipient in recipients:
1084 if not recipient.get( "device" ):
1085 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1086 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001087
Jeremyd9e4eb12016-04-13 12:09:06 -07001088 ingressDeviceList = [ x.get( "device" ) for x in senders if x.get( "device" ) ]
1089 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001090
Jeremyd9e4eb12016-04-13 12:09:06 -07001091 portIngressList = [ x.get( "port" ) for x in senders if x.get( "port" ) ]
1092 portEgress = recipients[ 0 ].get( "port", "" )
1093 if not portIngressList:
1094 portIngressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001095
Jeremyd9e4eb12016-04-13 12:09:06 -07001096 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001097 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001098
Jeremyd9e4eb12016-04-13 12:09:06 -07001099 # Adding point intent
Devin Lim142b5342017-07-20 15:22:39 -07001100 intentId = main.Cluster.active( onosNode ).CLI.addMultipointToSinglepointIntent(
1101 ingressDeviceList=ingressDeviceList,
1102 egressDevice=egressDevice,
1103 portIngressList=portIngressList,
1104 portEgress=portEgress,
1105 ethType=ethType,
1106 ethDst=dstMac,
1107 bandwidth=bandwidth,
1108 lambdaAlloc=lambdaAlloc,
1109 ipProto=ipProto,
1110 ipSrc="",
1111 ipDst="",
1112 tcpSrc="",
1113 tcpDst="",
1114 vlanId=vlanId,
1115 setVlan=setVlan,
1116 partial=partial,
1117 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001118 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001119 errorMsg = "There was a problem loading the hosts data."
1120 if intentId:
1121 errorMsg += " There was a problem installing Multipoint to Singlepoint intent."
1122 main.log.error( errorMsg )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001123 multiToSingleFailFlag = True
Jeremyd9e4eb12016-04-13 12:09:06 -07001124 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001125
1126 # Check intents state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001127 if multiToSingleFailFlag:
Devin Lima4f95bc2017-08-11 11:13:03 -07001128 attempts = main.middleAttemptsNum
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001129 else:
Devin Lima4f95bc2017-08-11 11:13:03 -07001130 attempts = main.generalAttemptsNum
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001131
Jon Hallaf95c3e2017-05-16 13:20:37 -07001132 if utilities.retry( f=checkIntentState,
1133 retValue=main.FALSE,
Jon Hallf539eb92017-05-22 17:18:42 -07001134 args=( main, [ intentId ] ),
Jon Hallaf95c3e2017-05-16 13:20:37 -07001135 sleep=main.checkIntentSleep,
1136 attempts=attempts ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001137 main.assertReturnString += 'Install Intent State Passed\n'
Jon Hallf539eb92017-05-22 17:18:42 -07001138 if bandwidth != "":
1139 allocationsFile = open( os.path.dirname( main.testFile ) + main.params[ 'DEPENDENCY' ][ 'filePath' ], 'r' )
1140 expectedFormat = allocationsFile.read()
1141 bandwidthCheck = checkBandwidthAllocations( main, expectedFormat )
1142 allocationsFile.close()
1143 if bandwidthCheck:
1144 main.assertReturnString += 'Bandwidth Allocation check Passed\n'
1145 else:
1146 main.assertReturnString += 'Bandwidth Allocation check Failed\n'
Jon Hallc3f88af2017-05-23 11:25:54 -07001147 return main.FALSE
1148
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001149 if flowDuration( main ):
1150 main.assertReturnString += 'Flow duration check Passed\n'
1151 return intentId
1152 else:
1153 main.assertReturnString += 'Flow duration check failed\n'
1154 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001155 else:
1156 main.log.error( "Multi to Single Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001157 multiToSingleFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001158 return main.FALSE
1159
Jon Hall78be4962017-05-23 14:53:53 -07001160
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001161def testPointIntent( main,
Jeremye0cb5eb2016-01-27 17:39:09 -08001162 name,
1163 intentId,
1164 senders,
1165 recipients,
1166 badSenders={},
1167 badRecipients={},
1168 onosNode=0,
1169 ethType="",
1170 bandwidth="",
1171 lambdaAlloc=False,
alisonda157272016-12-22 01:13:21 -08001172 protected=False,
Jeremye0cb5eb2016-01-27 17:39:09 -08001173 ipProto="",
1174 ipAddresses="",
1175 tcp="",
1176 sw1="s5",
1177 sw2="s2",
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001178 expectedLink=0,
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001179 useTCP=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001180 """
1181 Test a Point Intent
1182
1183 Description:
1184 Test a point intent
1185
1186 Steps:
1187 - Fetch host data if not given
1188 - Check Intent State
1189 - Check Flow State
1190 - Check Connectivity
1191 - Check Lack of Connectivity Between Hosts not in the Intent
1192 - Reroute
1193 - Take Expected Link Down
1194 - Check Intent State
1195 - Check Flow State
1196 - Check Topology
1197 - Check Connectivity
1198 - Bring Expected Link Up
1199 - Check Intent State
1200 - Check Flow State
1201 - Check Topology
1202 - Check Connectivity
1203 - Remove Topology
1204
1205 Required:
1206 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
1207
1208 senders - List of host dictionaries i.e.
1209 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
1210 recipients - List of host dictionaries i.e.
1211 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
1212 Optional:
1213 onosNode - ONOS node to install the intents in main.CLIs[ ]
1214 0 by default so that it will always use the first
1215 ONOS node
1216 ethType - Ethernet type eg. IPV4, IPV6
1217 bandwidth - Bandwidth capacity
1218 lambdaAlloc - Allocate lambda, defaults to False
1219 ipProto - IP protocol
1220 tcp - TCP ports in the same order as the hosts in hostNames
1221 sw1 - First switch to bring down & up for rerouting purpose
1222 sw2 - Second switch to bring down & up for rerouting purpose
1223 expectedLink - Expected link when the switches are down, it should
1224 be two links lower than the links before the two
1225 switches are down
1226
1227 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001228 # Parameter Validity Check
1229 assert main, "There is no main variable"
1230 assert senders, "You must specify a sender"
1231 assert recipients, "You must specify a recipient"
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001232
1233 global itemName
1234 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001235
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001236 global pointIntentFailFlag
1237 global singleToMultiFailFlag
1238 global multiToSingleFailFlag
1239
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001240 main.log.info( itemName + ": Testing Point Intent" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001241
Jeremyd9e4eb12016-04-13 12:09:06 -07001242 try:
1243 # Names for scapy
1244 senderNames = [ x.get( "name" ) for x in senders ]
1245 recipientNames = [ x.get( "name" ) for x in recipients ]
1246 badSenderNames = [ x.get( "name" ) for x in badSenders ]
1247 badRecipientNames = [ x.get( "name" ) for x in badRecipients ]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001248
Jeremyd9e4eb12016-04-13 12:09:06 -07001249 for sender in senders:
1250 if not sender.get( "device" ):
1251 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1252 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001253
Jeremyd9e4eb12016-04-13 12:09:06 -07001254 for recipient in recipients:
1255 if not recipient.get( "device" ):
1256 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1257 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001258 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001259 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001260 main.log.error( "There was a problem loading the hosts data." )
1261 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001262
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001263 testResult = main.TRUE
1264 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001265
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001266 if pointIntentFailFlag or singleToMultiFailFlag or multiToSingleFailFlag:
Devin Lima4f95bc2017-08-11 11:13:03 -07001267 attempts = main.minimumAttemptsNum
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001268 else:
Devin Lima4f95bc2017-08-11 11:13:03 -07001269 attempts = main.generalAttemptsNum
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001270
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001271 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001272 if utilities.retry( f=checkIntentState,
1273 retValue=main.FALSE,
1274 args=( main, [ intentId ] ),
1275 sleep=main.checkIntentSleep,
1276 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001277 main.assertReturnString += 'Initial Intent State Passed\n'
acsmarsd4862d12015-10-06 17:57:34 -07001278 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001279 main.assertReturnString += 'Initial Intent State Failed\n'
1280 testResult = main.FALSE
Devin Lima4f95bc2017-08-11 11:13:03 -07001281 attempts = main.minimumAttemptsNum
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001282
1283 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001284 if utilities.retry( f=checkFlowsCount,
1285 retValue=main.FALSE,
1286 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001287 sleep=main.checkFlowCountSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001288 attempts=attempts ) and utilities.retry( f=checkFlowsState,
1289 retValue=main.FALSE,
1290 args=[ main ],
1291 sleep=main.checkFlowCountSleep,
1292 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001293 main.assertReturnString += 'Initial Flow State Passed\n'
1294 else:
1295 main.assertReturnString += 'Intial Flow State Failed\n'
1296 testResult = main.FALSE
1297
1298 # Check Connectivity
Jon Hallaf95c3e2017-05-16 13:20:37 -07001299 if utilities.retry( f=scapyCheckConnection,
1300 retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -07001301 args=( main, senderNames, recipientNames, vlanId, useTCP ),
Devin Lima4f95bc2017-08-11 11:13:03 -07001302 attempts=main.checkConnectionAttNum,
1303 sleep=main.checkConnectionSleep,
1304 getRetryingTime=True ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001305 main.assertReturnString += 'Initial Ping Passed\n'
1306 else:
1307 main.assertReturnString += 'Initial Ping Failed\n'
1308 testResult = main.FALSE
1309
1310 # Check connections that shouldn't work
1311 if badSenderNames:
1312 main.log.info( "Checking that packets from incorrect sender do not go through" )
Jon Hallaf95c3e2017-05-16 13:20:37 -07001313 if utilities.retry( f=scapyCheckConnection,
1314 retValue=main.FALSE,
1315 args=( main, badSenderNames, recipientNames ),
Devin Lima4f95bc2017-08-11 11:13:03 -07001316 kwargs={ "expectFailure": True },
1317 getRetryingTime=True ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001318 main.assertReturnString += 'Bad Sender Ping Passed\n'
1319 else:
1320 main.assertReturnString += 'Bad Sender Ping Failed\n'
1321 testResult = main.FALSE
1322
1323 if badRecipientNames:
1324 main.log.info( "Checking that packets to incorrect recipients do not go through" )
Jon Hallaf95c3e2017-05-16 13:20:37 -07001325 if utilities.retry( f=scapyCheckConnection,
1326 retValue=main.FALSE,
1327 args=( main, senderNames, badRecipientNames ),
Devin Lima4f95bc2017-08-11 11:13:03 -07001328 kwargs={ "expectFailure": True },
1329 getRetryingTime=True ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001330 main.assertReturnString += 'Bad Recipient Ping Passed\n'
1331 else:
1332 main.assertReturnString += 'Bad Recipient Ping Failed\n'
1333 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001334
1335 # Test rerouting if these variables exist
1336 if sw1 and sw2 and expectedLink:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001337 # Take link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001338 if utilities.retry( f=link,
1339 retValue=main.FALSE,
1340 args=( main, sw1, sw2, "down" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001341 main.assertReturnString += 'Link Down Passed\n'
1342 else:
1343 main.assertReturnString += 'Link Down Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001344 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001345
alisonda157272016-12-22 01:13:21 -08001346 if protected:
1347 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001348 if utilities.retry( f=scapyCheckConnection,
1349 retValue=main.FALSE,
Devin Lima4f95bc2017-08-11 11:13:03 -07001350 args=( main, senderNames, recipientNames, vlanId, useTCP ),
1351 getRetryingTime=True ):
alisonda157272016-12-22 01:13:21 -08001352 main.assertReturnString += 'Link down Scapy Packet Received Passed\n'
1353 else:
1354 main.assertReturnString += 'Link down Scapy Packet Recieved Failed\n'
1355 testResult = main.FALSE
1356
1357 if ProtectedIntentCheck( main ):
1358 main.assertReturnString += 'Protected Intent Check Passed\n'
1359 else:
1360 main.assertReturnString += 'Protected Intent Check Failed\n'
1361 testResult = main.FALSE
1362
acsmarsd4862d12015-10-06 17:57:34 -07001363 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001364 if utilities.retry( f=checkIntentState,
1365 retValue=main.FALSE,
1366 args=( main, [ intentId ] ),
1367 sleep=main.checkIntentPointSleep,
1368 attempts=attempts ):
acsmarsd4862d12015-10-06 17:57:34 -07001369 main.assertReturnString += 'Link Down Intent State Passed\n'
1370 else:
1371 main.assertReturnString += 'Link Down Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001372 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001373
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001374 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001375 if utilities.retry( f=checkFlowsCount,
1376 retValue=main.FALSE,
1377 args=[ main ],
1378 sleep=main.checkFlowCountSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001379 attempts=attempts ) and utilities.retry( f=checkFlowsState,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001380 retValue=main.FALSE,
1381 args=[ main ],
1382 sleep=main.checkFlowCountSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001383 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001384 main.assertReturnString += 'Link Down Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001385 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001386 main.assertReturnString += 'Link Down Flow State Failed\n'
1387 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001388
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001389 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001390 if utilities.retry( f=checkTopology,
1391 retValue=main.FALSE,
1392 args=( main, expectedLink ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001393 main.assertReturnString += 'Link Down Topology State Passed\n'
1394 else:
1395 main.assertReturnString += 'Link Down Topology State Failed\n'
1396 testResult = main.FALSE
1397
1398 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001399 if utilities.retry( f=scapyCheckConnection,
1400 retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -07001401 args=( main, senderNames, recipientNames, vlanId, useTCP ),
Jon Hallaf95c3e2017-05-16 13:20:37 -07001402 sleep=main.checkConnectionSleep,
Devin Lima4f95bc2017-08-11 11:13:03 -07001403 attempts=main.checkConnectionAttNum,
1404 getRetryingTime=True ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001405 main.assertReturnString += 'Link Down Pingall Passed\n'
1406 else:
1407 main.assertReturnString += 'Link Down Pingall Failed\n'
1408 testResult = main.FALSE
1409
1410 # Bring link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001411 if utilities.retry( f=link,
1412 retValue=main.FALSE,
1413 args=( main, sw1, sw2, "up" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001414 main.assertReturnString += 'Link Up Passed\n'
1415 else:
1416 main.assertReturnString += 'Link Up Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001417 testResult = main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -07001418
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001419 # Wait for reroute
Jon Hallf539eb92017-05-22 17:18:42 -07001420 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001421 time.sleep( main.rerouteSleep )
1422
acsmarsd4862d12015-10-06 17:57:34 -07001423 # Check Intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001424 if utilities.retry( f=checkIntentState,
1425 retValue=main.FALSE,
1426 attempts=attempts * 2,
1427 args=( main, [ intentId ] ),
Shreyaca8990f2017-03-16 11:43:11 -07001428 sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001429 main.assertReturnString += 'Link Up Intent State Passed\n'
1430 else:
1431 main.assertReturnString += 'Link Up Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001432 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001433
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001434 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001435 if utilities.retry( f=checkFlowsCount,
1436 retValue=main.FALSE,
1437 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001438 sleep=main.checkFlowCountSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001439 attempts=attempts ) and utilities.retry( f=checkFlowsState,
1440 retValue=main.FALSE,
1441 args=[ main ],
1442 sleep=main.checkFlowCountSleep,
1443 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001444 main.assertReturnString += 'Link Up Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001445 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001446 main.assertReturnString += 'Link Up Flow State Failed\n'
1447 testResult = main.FALSE
1448
1449 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001450 if utilities.retry( f=checkTopology,
1451 retValue=main.FALSE,
1452 args=( main, main.numLinks ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001453 main.assertReturnString += 'Link Up Topology State Passed\n'
1454 else:
1455 main.assertReturnString += 'Link Up Topology State Failed\n'
1456 testResult = main.FALSE
1457
1458 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001459 if utilities.retry( f=scapyCheckConnection,
1460 retValue=main.FALSE,
1461 sleep=main.checkConnectionSleep,
Devin Lima4f95bc2017-08-11 11:13:03 -07001462 attempts=main.checkConnectionAttNum,
1463 args=( main, senderNames, recipientNames, vlanId, useTCP ),
1464 getRetryingTime=True ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001465 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1466 else:
1467 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1468 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001469
1470 # Remove all intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001471 if utilities.retry( f=removeAllIntents,
1472 retValue=main.FALSE,
Devin Lima4f95bc2017-08-11 11:13:03 -07001473 attempts=main.removeIntentAttNum,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001474 args=( main, [ intentId ] ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001475 main.assertReturnString += 'Remove Intents Passed'
1476 else:
1477 main.assertReturnString += 'Remove Intents Failed'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001478 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001479
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001480 return testResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001481
Jon Hall78be4962017-05-23 14:53:53 -07001482
Jeremye0cb5eb2016-01-27 17:39:09 -08001483def testEndPointFail( main,
1484 name,
1485 intentId,
1486 senders,
1487 recipients,
1488 isolatedSenders,
1489 isolatedRecipients,
1490 onosNode=0,
1491 ethType="",
1492 bandwidth="",
1493 lambdaAlloc=False,
1494 ipProto="",
1495 ipAddresses="",
1496 tcp="",
1497 sw1="",
1498 sw2="",
1499 sw3="",
1500 sw4="",
1501 sw5="",
1502 expectedLink1=0,
Jeremy Songster9385d412016-06-02 17:57:36 -07001503 expectedLink2=0,
1504 partial=False ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001505 """
Shreyaca8990f2017-03-16 11:43:11 -07001506 Test Multi point to single point intent Topology for Endpoint failures
Jeremye0cb5eb2016-01-27 17:39:09 -08001507 """
Jeremye0cb5eb2016-01-27 17:39:09 -08001508 # Parameter Validity Check
1509 assert main, "There is no main variable"
1510 assert senders, "You must specify a sender"
1511 assert recipients, "You must specify a recipient"
1512
1513 global itemName
1514 itemName = name
Jeremye0cb5eb2016-01-27 17:39:09 -08001515
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001516 global singleToMultiFailFlag
1517 global multiToSingleFailFlag
1518
Jeremye0cb5eb2016-01-27 17:39:09 -08001519 main.log.info( itemName + ": Testing Point Intent" )
1520
Jeremyd9e4eb12016-04-13 12:09:06 -07001521 try:
1522 # Names for scapy
1523 senderNames = [ x.get( "name" ) for x in senders ]
1524 recipientNames = [ x.get( "name" ) for x in recipients ]
1525 isolatedSenderNames = [ x.get( "name" ) for x in isolatedSenders ]
1526 isolatedRecipientNames = [ x.get( "name" ) for x in isolatedRecipients ]
Jon Hall78be4962017-05-23 14:53:53 -07001527 connectedSenderNames = [ x.get( "name" ) for x in senders if x.get( "name" ) not in isolatedSenderNames ]
1528 connectedRecipientNames = [ x.get( "name" ) for x in recipients if x.get( "name" ) not in isolatedRecipientNames ]
Jeremye0cb5eb2016-01-27 17:39:09 -08001529
Jeremyd9e4eb12016-04-13 12:09:06 -07001530 for sender in senders:
1531 if not sender.get( "device" ):
1532 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1533 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremye0cb5eb2016-01-27 17:39:09 -08001534
Jeremyd9e4eb12016-04-13 12:09:06 -07001535 for recipient in recipients:
1536 if not recipient.get( "device" ):
Jon Hall78be4962017-05-23 14:53:53 -07001537 main.log.warn( "Device not given for recipient {0}. Loading from " +
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001538 main.hostData.format( recipient.get( "name" ) ) )
Jeremyd9e4eb12016-04-13 12:09:06 -07001539 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001540 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001541 main.log.error( "There was a problem loading the hosts data." )
1542 return main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001543
1544 testResult = main.TRUE
1545 main.log.info( itemName + ": Adding multi point to single point intents" )
1546
1547 # Check intent state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001548 if singleToMultiFailFlag or multiToSingleFailFlag:
Devin Lima4f95bc2017-08-11 11:13:03 -07001549 attempts = main.minimumAttemptsNum
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001550 else:
Devin Lima4f95bc2017-08-11 11:13:03 -07001551 attempts = main.generalAttemptsNum
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001552
Jon Hallaf95c3e2017-05-16 13:20:37 -07001553 if utilities.retry( f=checkIntentState,
1554 retValue=main.FALSE,
1555 args=( main, [ intentId ] ),
1556 sleep=main.checkIntentSleep,
1557 attempts=attempts ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001558 main.assertReturnString += 'Initial Intent State Passed\n'
1559 else:
1560 main.assertReturnString += 'Initial Intent State Failed\n'
1561 testResult = main.FALSE
Devin Lima4f95bc2017-08-11 11:13:03 -07001562 attempts = main.minimumAttemptsNum
Jeremye0cb5eb2016-01-27 17:39:09 -08001563
1564 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001565 if utilities.retry( f=checkFlowsCount,
1566 retValue=main.FALSE,
1567 args=[ main ],
1568 attempts=5 ) and utilities.retry( f=checkFlowsState,
1569 retValue=main.FALSE,
1570 args=[ main ],
1571 attempts=5 ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001572 main.assertReturnString += 'Initial Flow State Passed\n'
1573 else:
1574 main.assertReturnString += 'Intial Flow State Failed\n'
1575 testResult = main.FALSE
1576
1577 # Check Connectivity
Jon Hallaf95c3e2017-05-16 13:20:37 -07001578 if utilities.retry( f=scapyCheckConnection,
1579 retValue=main.FALSE,
Devin Lima4f95bc2017-08-11 11:13:03 -07001580 args=( main, senderNames, recipientNames ),
1581 getRetryingTime=True ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001582 main.assertReturnString += 'Initial Connectivity Check Passed\n'
1583 else:
1584 main.assertReturnString += 'Initial Connectivity Check Failed\n'
1585 testResult = main.FALSE
1586
1587 # Take two links down
1588 # Take first link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001589 if utilities.retry( f=link,
1590 retValue=main.FALSE,
1591 args=( main, sw1, sw2, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001592 main.assertReturnString += 'Link Down Passed\n'
1593 else:
1594 main.assertReturnString += 'Link Down Failed\n'
1595 testResult = main.FALSE
1596
1597 # Take second link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001598 if utilities.retry( f=link,
1599 retValue=main.FALSE,
1600 args=( main, sw3, sw4, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001601 main.assertReturnString += 'Link Down Passed\n'
1602 else:
1603 main.assertReturnString += 'Link Down Failed\n'
1604 testResult = main.FALSE
1605
1606 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001607 if utilities.retry( f=checkIntentState,
1608 retValue=main.FALSE,
1609 attempts=attempts,
1610 args=( main, [ intentId ] ),
1611 sleep=main.checkIntentSleep ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001612 main.assertReturnString += 'Link Down Intent State Passed\n'
1613 else:
1614 main.assertReturnString += 'Link Down Intent State Failed\n'
1615 testResult = main.FALSE
1616
1617 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001618 if utilities.retry( f=checkFlowsCount,
1619 retValue=main.FALSE,
1620 sleep=1,
1621 attempts=attempts,
Jeremye0cb5eb2016-01-27 17:39:09 -08001622 args=[ main ] ) and utilities.retry( f=checkFlowsState,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001623 retValue=main.FALSE,
1624 sleep=1,
1625 attempts=attempts,
1626 args=[ main ] ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001627 main.assertReturnString += 'Link Down Flow State Passed\n'
1628 else:
1629 main.assertReturnString += 'Link Down Flow State Failed\n'
1630 testResult = main.FALSE
1631
1632 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001633 if utilities.retry( f=checkTopology,
1634 retValue=main.FALSE,
1635 args=( main, expectedLink1 ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001636 main.assertReturnString += 'Link Down Topology State Passed\n'
1637 else:
1638 main.assertReturnString += 'Link Down Topology State Failed\n'
1639 testResult = main.FALSE
1640
1641 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001642 if utilities.retry( f=scapyCheckConnection,
1643 retValue=main.FALSE,
Devin Lima4f95bc2017-08-11 11:13:03 -07001644 args=( main, senderNames, recipientNames ),
1645 getRetryingTime=True ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001646 main.assertReturnString += 'Link Down Connectivity Check Passed\n'
1647 else:
1648 main.assertReturnString += 'Link Down Connectivity Check Failed\n'
1649 testResult = main.FALSE
1650
1651 # Take a third link down to isolate one node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001652 if utilities.retry( f=link,
1653 retValue=main.FALSE,
1654 args=( main, sw3, sw5, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001655 main.assertReturnString += 'Isolation link Down Passed\n'
1656 else:
1657 main.assertReturnString += 'Isolation link Down Failed\n'
1658 testResult = main.FALSE
1659
Jeremy Songster9385d412016-06-02 17:57:36 -07001660 if partial:
1661 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001662 if utilities.retry( f=checkIntentState,
1663 retValue=main.FALSE,
1664 args=( main, [ intentId ] ),
1665 sleep=main.checkIntentSleep,
1666 attempts=attempts ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001667 main.assertReturnString += 'Partial failure isolation link Down Intent State Passed\n'
1668 else:
1669 main.assertReturnString += 'Partial failure isolation link Down Intent State Failed\n'
1670 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001671
Jeremy Songster9385d412016-06-02 17:57:36 -07001672 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001673 if utilities.retry( f=checkFlowsCount,
1674 retValue=main.FALSE,
1675 args=[ main ],
1676 attempts=5 ) and utilities.retry( f=checkFlowsState,
1677 retValue=main.FALSE,
1678 args=[ main ],
1679 attempts=5 ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001680 main.assertReturnString += 'Partial failure isolation link Down Flow State Passed\n'
1681 else:
1682 main.assertReturnString += 'Partial failure isolation link Down Flow State Failed\n'
1683 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001684
Jeremy Songster9385d412016-06-02 17:57:36 -07001685 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001686 if utilities.retry( f=checkTopology,
1687 retValue=main.FALSE,
1688 args=( main, expectedLink2 ) ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001689 main.assertReturnString += 'Partial failure isolation link Down Topology State Passed\n'
1690 else:
1691 main.assertReturnString += 'Partial failure isolation link Down Topology State Failed\n'
1692 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001693
Jeremy Songster9385d412016-06-02 17:57:36 -07001694 # Check Connectivity
1695 # First check connectivity of any isolated senders to recipients
1696 if isolatedSenderNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001697 if scapyCheckConnection( main,
1698 isolatedSenderNames,
1699 recipientNames,
1700 None,
1701 None,
1702 None,
1703 None,
1704 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001705 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1706 else:
1707 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1708 testResult = main.FALSE
1709
1710 # Next check connectivity of senders to any isolated recipients
1711 if isolatedRecipientNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001712 if scapyCheckConnection( main,
1713 senderNames,
1714 isolatedRecipientNames,
1715 None,
1716 None,
1717 None,
1718 None,
1719 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001720 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1721 else:
1722 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1723 testResult = main.FALSE
1724
1725 # Next check connectivity of connected senders and recipients
Jon Hallaf95c3e2017-05-16 13:20:37 -07001726 if utilities.retry( f=scapyCheckConnection,
1727 retValue=main.FALSE,
Devin Lima4f95bc2017-08-11 11:13:03 -07001728 attempts=main.checkConnectionAttNum,
1729 args=( main, connectedSenderNames, connectedRecipientNames ),
1730 getRetryingTime=True ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001731 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1732 else:
1733 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1734 testResult = main.FALSE
1735 else:
1736 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001737 if not utilities.retry( f=checkIntentState,
1738 retValue=main.TRUE,
1739 args=( main, [ intentId ] ),
1740 sleep=main.checkIntentSleep,
1741 attempts=attempts ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001742 main.assertReturnString += 'Isolation link Down Intent State Passed\n'
1743 else:
1744 main.assertReturnString += 'Isolation link Down Intent State Failed\n'
1745 testResult = main.FALSE
1746
1747 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001748 if utilities.retry( f=checkFlowsCount,
1749 retValue=main.FALSE,
1750 args=[ main ],
1751 attempts=5 ) and utilities.retry( f=checkFlowsState,
1752 retValue=main.FALSE,
1753 args=[ main ],
1754 attempts=5 ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001755 main.assertReturnString += 'Isolation link Down Flow State Passed\n'
1756 else:
1757 main.assertReturnString += 'Isolation link Down Flow State Failed\n'
1758 testResult = main.FALSE
1759
1760 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001761 if utilities.retry( f=checkTopology,
1762 retValue=main.FALSE,
1763 args=( main, expectedLink2 ) ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001764 main.assertReturnString += 'Isolation link Down Topology State Passed\n'
1765 else:
1766 main.assertReturnString += 'Isolation link Down Topology State Failed\n'
1767 testResult = main.FALSE
1768
1769 # Check Connectivity
1770 # First check connectivity of any isolated senders to recipients
1771 if isolatedSenderNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001772 if scapyCheckConnection( main,
1773 isolatedSenderNames,
1774 recipientNames,
1775 None,
1776 None,
1777 None,
1778 None,
1779 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001780 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1781 else:
1782 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1783 testResult = main.FALSE
1784
1785 # Next check connectivity of senders to any isolated recipients
1786 if isolatedRecipientNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001787 if scapyCheckConnection( main,
1788 senderNames,
1789 isolatedRecipientNames,
1790 None,
1791 None,
1792 None,
1793 None,
1794 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001795 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1796 else:
1797 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1798 testResult = main.FALSE
1799
1800 # Next check connectivity of connected senders and recipients
Jon Hallaf95c3e2017-05-16 13:20:37 -07001801 if utilities.retry( f=scapyCheckConnection,
1802 retValue=main.TRUE,
Devin Lima4f95bc2017-08-11 11:13:03 -07001803 args=( main, connectedSenderNames, connectedRecipientNames, None, None, None, None, main.TRUE ),
1804 getRetryingTime=True ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001805 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1806 else:
1807 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1808 testResult = main.FALSE
1809
Jeremye0cb5eb2016-01-27 17:39:09 -08001810 # Bring the links back up
1811 # Bring first link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001812 if utilities.retry( f=link,
1813 retValue=main.FALSE,
1814 args=( main, sw1, sw2, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001815 main.assertReturnString += 'Link Up Passed\n'
1816 else:
1817 main.assertReturnString += 'Link Up Failed\n'
1818 testResult = main.FALSE
1819
1820 # Bring second link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001821 if utilities.retry( f=link,
1822 retValue=main.FALSE,
1823 args=( main, sw3, sw5, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001824 main.assertReturnString += 'Link Up Passed\n'
1825 else:
1826 main.assertReturnString += 'Link Up Failed\n'
1827 testResult = main.FALSE
1828
1829 # Bring third link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001830 if utilities.retry( f=link,
1831 retValue=main.FALSE,
1832 args=( main, sw3, sw4, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001833 main.assertReturnString += 'Link Up Passed\n'
1834 else:
1835 main.assertReturnString += 'Link Up Failed\n'
1836 testResult = main.FALSE
1837
1838 # Wait for reroute
Jon Hallf539eb92017-05-22 17:18:42 -07001839 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
Jeremye0cb5eb2016-01-27 17:39:09 -08001840 time.sleep( main.rerouteSleep )
1841
1842 # Check Intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001843 if utilities.retry( f=checkIntentState,
1844 retValue=main.FALSE,
1845 attempts=attempts,
1846 args=( main, [ intentId ] ),
1847 sleep=main.checkIntentHostSleep ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001848 main.assertReturnString += 'Link Up Intent State Passed\n'
1849 else:
1850 main.assertReturnString += 'Link Up Intent State Failed\n'
1851 testResult = main.FALSE
1852
1853 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001854 if utilities.retry( f=checkFlowsCount,
1855 retValue=main.FALSE,
1856 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001857 sleep=main.checkFlowCountSleep,
1858 attempts=attempts ) and utilities.retry( f=checkFlowsState,
Jon Hall78be4962017-05-23 14:53:53 -07001859 retValue=main.FALSE,
1860 args=[ main ],
1861 sleep=main.checkFlowCountSleep,
1862 attempts=attempts ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001863 main.assertReturnString += 'Link Up Flow State Passed\n'
1864 else:
1865 main.assertReturnString += 'Link Up Flow State Failed\n'
1866 testResult = main.FALSE
1867
1868 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001869 if utilities.retry( f=checkTopology,
1870 retValue=main.FALSE,
1871 args=( main, main.numLinks ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001872 main.assertReturnString += 'Link Up Topology State Passed\n'
1873 else:
1874 main.assertReturnString += 'Link Up Topology State Failed\n'
1875 testResult = main.FALSE
1876
1877 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001878 if utilities.retry( f=scapyCheckConnection,
1879 retValue=main.FALSE,
1880 sleep=main.checkConnectionSleep,
Devin Lima4f95bc2017-08-11 11:13:03 -07001881 attempts=main.checkConnectionAttNum,
1882 args=( main, senderNames, recipientNames ),
1883 getRetryingTime=True ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001884 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1885 else:
1886 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1887 testResult = main.FALSE
1888
1889 # Remove all intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001890 if utilities.retry( f=removeAllIntents,
1891 retValue=main.FALSE,
Devin Lima4f95bc2017-08-11 11:13:03 -07001892 attempts=main.removeIntentAttNum,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001893 args=( main, [ intentId ] ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001894 main.assertReturnString += 'Remove Intents Passed'
1895 else:
1896 main.assertReturnString += 'Remove Intents Failed'
1897 testResult = main.FALSE
1898
1899 return testResult
1900
1901
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001902def pingallHosts( main, hostList ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001903 """
1904 Ping all host in the hosts list variable
1905 """
Jon Halla5cb3412015-08-18 14:08:22 -07001906 main.log.info( "Pinging: " + str( hostList ) )
You Wanga0f6ff62018-01-11 15:46:30 -08001907 return main.Network.pingallHosts( hostList )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001908
Jon Hall78be4962017-05-23 14:53:53 -07001909
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001910def fwdPingall( main ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001911 """
1912 Use fwd app and pingall to discover all the hosts
1913 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001914 appCheck = main.TRUE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001915 main.log.info( "Activating reactive forwarding app " )
Devin Lim142b5342017-07-20 15:22:39 -07001916 activateResult = main.Cluster.active( 0 ).CLI.activateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001917
1918 # Wait for forward app activation to propagate
Jon Hallf539eb92017-05-22 17:18:42 -07001919 main.log.info( "Sleeping {} seconds".format( main.fwdSleep ) )
kelvin-onlab0ad05d12015-07-23 14:21:15 -07001920 time.sleep( main.fwdSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001921
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001922 # Check that forwarding is enabled on all nodes
Devin Lim142b5342017-07-20 15:22:39 -07001923 for ctrl in main.Cluster.active():
1924 appCheck = appCheck and ctrl.CLI.appToIDCheck()
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001925 if appCheck != main.TRUE:
Devin Lim142b5342017-07-20 15:22:39 -07001926 main.log.warn( ctrl.CLI.apps() )
1927 main.log.warn( ctrl.CLI.appIDs() )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001928
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001929 # Send pingall in mininet
1930 main.log.info( "Run Pingall" )
You Wanga0f6ff62018-01-11 15:46:30 -08001931 pingResult = main.Network.pingall( timeout=600 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001932
1933 main.log.info( "Deactivating reactive forwarding app " )
Devin Lim142b5342017-07-20 15:22:39 -07001934 deactivateResult = main.Cluster.active( 0 ).CLI.deactivateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001935 if activateResult and deactivateResult:
1936 main.log.info( "Successfully used fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001937 getDataResult = main.TRUE
1938 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001939 main.log.info( "Failed to use fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001940 getDataResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001941 return getDataResult
1942
Jon Hall78be4962017-05-23 14:53:53 -07001943
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001944def confirmHostDiscovery( main ):
1945 """
1946 Confirms that all ONOS nodes have discovered all scapy hosts
1947 """
1948 import collections
Devin Lim58046fa2017-07-05 16:55:00 -07001949 try:
1950 from tests.dependencies.topology import Topology
1951 except Exception:
1952 main.log.error( "Topology not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -07001953 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -07001954 try:
1955 main.topoRelated
1956 except Exception:
1957 main.topoRelated = Topology()
Devin Lim142b5342017-07-20 15:22:39 -07001958 hosts = main.topoRelated.getAll( "hosts", False ) # Get host data from each ONOS node
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001959 hostFails = [] # Reset for each failed attempt
1960
1961 # Check for matching hosts on each node
1962 scapyHostIPs = [ x.hostIp for x in main.scapyHosts if x.hostIp != "0.0.0.0" ]
Devin Lim142b5342017-07-20 15:22:39 -07001963 for controller in range( main.Cluster.numCtrls ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001964 controllerStr = str( controller + 1 ) # ONOS node number
1965 # Compare Hosts
1966 # Load hosts data for controller node
Jeremyd9e4eb12016-04-13 12:09:06 -07001967 try:
1968 if hosts[ controller ]:
1969 main.log.info( "Hosts discovered" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001970 else:
Jeremyd9e4eb12016-04-13 12:09:06 -07001971 main.log.error( "Problem discovering hosts" )
1972 if hosts[ controller ] and "Error" not in hosts[ controller ]:
1973 try:
1974 hostData = json.loads( hosts[ controller ] )
1975 except ( TypeError, ValueError ):
1976 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001977 hostFails.append( controllerStr )
Jeremyd9e4eb12016-04-13 12:09:06 -07001978 else:
1979 onosHostIPs = [ x.get( "ipAddresses" )[ 0 ]
1980 for x in hostData
1981 if len( x.get( "ipAddresses" ) ) > 0 ]
Jon Hall78be4962017-05-23 14:53:53 -07001982 if not set( collections.Counter( scapyHostIPs ) ).issubset(
1983 set( collections.Counter( onosHostIPs ) ) ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001984 main.log.warn( "Controller {0} only sees nodes with {1} IPs. It should see all of the following: {2}".format( controllerStr, onosHostIPs, scapyHostIPs ) )
1985 hostFails.append( controllerStr )
1986 else:
1987 main.log.error( "Hosts returned nothing or an error." )
1988 hostFails.append( controllerStr )
1989 except IndexError:
1990 main.log.error( "Hosts returned nothing, Failed to discover hosts." )
1991 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001992
1993 if hostFails:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001994 main.log.error( "List of failed ONOS Nodes:" + ', '.join( map( str, hostFails ) ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001995 return main.FALSE
1996 else:
1997 return main.TRUE
1998
Jon Hall78be4962017-05-23 14:53:53 -07001999
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002000def sendDiscoveryArp( main, hosts=None ):
2001 """
2002 Sends Discovery ARP packets from each host provided
2003 Defaults to each host in main.scapyHosts
2004 """
2005 # Send an arp ping from each host
2006 if not hosts:
2007 hosts = main.scapyHosts
2008 for host in hosts:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002009 pkt = 'Ether( src="{0}")/ARP( psrc="{1}")'.format( host.hostMac, host.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002010 # Send from the VLAN interface if there is one so ONOS discovers the VLAN correctly
2011 iface = None
2012 for interface in host.getIfList():
2013 if '.' in interface:
2014 main.log.debug( "Detected VLAN interface {0}. Sending ARP packet from {0}".format( interface ) )
2015 iface = interface
2016 break
2017 host.sendPacket( packet=pkt, iface=iface )
2018 main.log.info( "Sending ARP packet from {0}".format( host.name ) )
2019
Jon Hall78be4962017-05-23 14:53:53 -07002020
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002021def populateHostData( main ):
2022 """
2023 Populates hostsData
2024 """
2025 import json
2026 try:
Devin Lim142b5342017-07-20 15:22:39 -07002027 hostsJson = json.loads( main.Cluster.active( 0 ).CLI.hosts() )
You Wanga0f6ff62018-01-11 15:46:30 -08002028 hosts = main.Network.getHosts().keys()
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002029 # TODO: Make better use of new getHosts function
2030 for host in hosts:
2031 main.hostsData[ host ] = {}
2032 main.hostsData[ host ][ 'mac' ] = \
You Wanga0f6ff62018-01-11 15:46:30 -08002033 main.Network.getMacAddress( host ).upper()
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002034 for hostj in hostsJson:
2035 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
2036 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
2037 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
2038 main.hostsData[ host ][ 'location' ] = \
Jeremy Ronquillo0e538bc2017-06-13 15:16:09 -07002039 hostj[ 'locations' ][ 0 ][ 'elementId' ] + '/' + \
2040 hostj[ 'locations' ][ 0 ][ 'port' ]
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002041 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
2042 return main.TRUE
Jeremyd9e4eb12016-04-13 12:09:06 -07002043 except ValueError:
2044 main.log.error( "ValueError while populating hostsData" )
2045 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002046 except KeyError:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002047 main.log.error( "KeyError while populating hostsData" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002048 return main.FALSE
Jeremyd9e4eb12016-04-13 12:09:06 -07002049 except IndexError:
2050 main.log.error( "IndexError while populating hostsData" )
2051 return main.FALSE
2052 except TypeError:
2053 main.log.error( "TypeError while populating hostsData" )
2054 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002055
Jon Hall78be4962017-05-23 14:53:53 -07002056
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002057def checkTopology( main, expectedLink ):
2058 statusResult = main.TRUE
2059 # Check onos topology
2060 main.log.info( itemName + ": Checking ONOS topology " )
2061
Devin Lim142b5342017-07-20 15:22:39 -07002062 statusResult = main.Cluster.command( "checkStatus",
2063 args=[ main.numSwitch, expectedLink ],
2064 returnBool=True, specificDriver=2 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002065 if not statusResult:
2066 main.log.error( itemName + ": Topology mismatch" )
2067 else:
2068 main.log.info( itemName + ": Topology match" )
2069 return statusResult
2070
Jon Hall78be4962017-05-23 14:53:53 -07002071
Jon Hallf539eb92017-05-22 17:18:42 -07002072def checkIntentState( main, intentsId ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002073 """
2074 This function will check intent state to make sure all the intents
2075 are in INSTALLED state
Jon Hallf539eb92017-05-22 17:18:42 -07002076 Returns main.TRUE or main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002077 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002078 intentResult = main.TRUE
Devin Lim142b5342017-07-20 15:22:39 -07002079 stateCheckResults = main.Cluster.command( "checkIntentState",
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002080 kwargs={ "intentsId": intentsId },
2081 returnBool=True, specificDriver=2 )
Devin Lim142b5342017-07-20 15:22:39 -07002082 if stateCheckResults:
Jon Hallf539eb92017-05-22 17:18:42 -07002083 main.log.info( itemName + ": Intents state check passed" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002084 else:
Jon Hallf539eb92017-05-22 17:18:42 -07002085 main.log.warn( "Intents state check failed" )
Shreyaca8990f2017-03-16 11:43:11 -07002086 intentResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002087 return intentResult
2088
Jon Hall78be4962017-05-23 14:53:53 -07002089
Jon Hallf539eb92017-05-22 17:18:42 -07002090def checkBandwidthAllocations( main, bandwidth ):
2091 """
2092 Compare the given bandwith allocation output to the cli output on each node
2093 Returns main.TRUE or main.FALSE
2094 """
Devin Lim142b5342017-07-20 15:22:39 -07002095 stateCheckResults = main.Cluster.command( "compareBandwidthAllocations",
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002096 args=[ bandwidth ],
2097 returnBool=True, specificDriver=2 )
Devin Lim142b5342017-07-20 15:22:39 -07002098 if stateCheckResults:
Jon Hallf539eb92017-05-22 17:18:42 -07002099 main.log.info( itemName + ": bandwidth check passed" )
2100 bandwidthResult = main.TRUE
2101 else:
2102 main.log.warn( itemName + ": bandwidth check failed" )
2103 bandwidthResult = main.FALSE
2104 return bandwidthResult
2105
Jon Hall78be4962017-05-23 14:53:53 -07002106
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002107def checkFlowsState( main ):
2108
2109 main.log.info( itemName + ": Check flows state" )
Devin Lim142b5342017-07-20 15:22:39 -07002110 checkFlowsResult = main.Cluster.active( 0 ).CLI.checkFlowsState( isPENDING=False )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002111 return checkFlowsResult
2112
Jon Hall78be4962017-05-23 14:53:53 -07002113
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002114def link( main, sw1, sw2, option ):
You Wangf6574de2018-02-09 14:43:47 -08002115 if main.usePortstate:
2116 # port down
2117 dpid = main.params[ 'MININET' ][ 'dpids' ][ sw1 ]
2118 port = main.params[ 'MININET' ][ 'ports' ][ sw1 ][ sw2 ]
2119 main.log.info( itemName + ": Bring port " + sw1 + "/" + port + " " + option )
2120 state = "disable" if option == "down" else "enable"
2121 result = main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state=state )
2122 else:
2123 # link down
2124 main.log.info( itemName + ": Bring link " + option + " between " +
2125 sw1 + " and " + sw2 )
2126 result = main.Network.link( end1=sw1, end2=sw2, option=option )
2127 return result
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002128
Jon Hall78be4962017-05-23 14:53:53 -07002129
Jon Hallaf95c3e2017-05-16 13:20:37 -07002130def scapyCheckConnection( main,
2131 senders,
2132 recipients,
2133 vlanId=None,
2134 useTCP=False,
2135 packet=None,
2136 packetFilter=None,
2137 expectFailure=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002138 """
2139 Checks the connectivity between all given sender hosts and all given recipient hosts
2140 Packet may be specified. Defaults to Ether/IP packet
2141 Packet Filter may be specified. Defaults to Ether/IP from current sender MAC
2142 Todo: Optional packet and packet filter attributes for sender and recipients
2143 Expect Failure when the sender and recipient are not supposed to have connectivity
2144 Timeout of 1 second, returns main.TRUE if the filter is not triggered and kills the filter
2145
2146 """
2147 connectionsFunctional = main.TRUE
2148
2149 if not packetFilter:
2150 packetFilter = 'ether host {}'
Jeremy Songstere405d3d2016-05-17 11:18:57 -07002151 if useTCP:
Jon Hall78be4962017-05-23 14:53:53 -07002152 packetFilter += ' ip proto \\tcp tcp port {}'.format( main.params[ 'SDNIP' ][ 'dstPort' ] )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002153 if expectFailure:
2154 timeout = 1
2155 else:
2156 timeout = 10
2157
2158 for sender in senders:
2159 try:
2160 senderComp = getattr( main, sender )
2161 except AttributeError:
2162 main.log.error( "main has no attribute {}".format( sender ) )
2163 connectionsFunctional = main.FALSE
2164 continue
2165
2166 for recipient in recipients:
2167 # Do not send packets to self since recipient CLI will already be busy
2168 if recipient == sender:
2169 continue
2170 try:
2171 recipientComp = getattr( main, recipient )
2172 except AttributeError:
2173 main.log.error( "main has no attribute {}".format( recipient ) )
2174 connectionsFunctional = main.FALSE
2175 continue
2176
Jeremy Songster832f9e92016-05-05 14:30:49 -07002177 if vlanId:
Jon Hall78be4962017-05-23 14:53:53 -07002178 recipientComp.startFilter( pktFilter=( "vlan {}".format( vlanId ) + " && " + packetFilter.format( senderComp.hostMac ) ) )
Jeremy Songster832f9e92016-05-05 14:30:49 -07002179 else:
Jon Hall78be4962017-05-23 14:53:53 -07002180 recipientComp.startFilter( pktFilter=packetFilter.format( senderComp.hostMac ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002181
2182 if not packet:
Jeremy Songster832f9e92016-05-05 14:30:49 -07002183 if vlanId:
2184 pkt = 'Ether( src="{0}", dst="{2}" )/Dot1Q(vlan={4})/IP( src="{1}", dst="{3}" )'.format(
2185 senderComp.hostMac,
2186 senderComp.hostIp,
2187 recipientComp.hostMac,
2188 recipientComp.hostIp,
2189 vlanId )
2190 else:
2191 pkt = 'Ether( src="{0}", dst="{2}" )/IP( src="{1}", dst="{3}" )'.format(
2192 senderComp.hostMac,
2193 senderComp.hostIp,
2194 recipientComp.hostMac,
2195 recipientComp.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002196 else:
2197 pkt = packet
Jeremy Songster832f9e92016-05-05 14:30:49 -07002198 if vlanId:
2199 senderComp.sendPacket( iface=( "{0}-eth0.{1}".format( sender, vlanId ) ), packet = pkt )
2200 else:
Jon Hall78be4962017-05-23 14:53:53 -07002201 senderComp.sendPacket( packet=pkt )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002202
2203 if recipientComp.checkFilter( timeout ):
2204 if expectFailure:
Jon Hall78be4962017-05-23 14:53:53 -07002205 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 -08002206 connectionsFunctional = main.FALSE
2207 else:
Jon Hall78be4962017-05-23 14:53:53 -07002208 main.log.info( "Packet from {0} successfully received by {1}".format( sender, recipient ) )
alison52b25892016-09-19 10:53:48 -07002209 connectionsFunctional = main.TRUE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002210 else:
2211 recipientComp.killFilter()
2212 if expectFailure:
Jon Hall78be4962017-05-23 14:53:53 -07002213 main.log.info( "As expected, packet from {0} was not received by {1}".format( sender, recipient ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002214 else:
Jon Hall78be4962017-05-23 14:53:53 -07002215 main.log.error( "Packet from {0} was not received by {1}".format( sender, recipient ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002216 connectionsFunctional = main.FALSE
2217
2218 return connectionsFunctional
2219
alison52b25892016-09-19 10:53:48 -07002220
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002221def removeAllIntents( main, intentsId ):
2222 """
2223 Remove all intents in the intentsId
2224 """
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002225 onosSummary = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002226 removeIntentResult = main.TRUE
2227 # Remove intents
2228 for intent in intentsId:
Devin Lim142b5342017-07-20 15:22:39 -07002229 main.Cluster.active( 0 ).CLI.removeIntent( intentId=intent, purge=True )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002230
Jon Hallf539eb92017-05-22 17:18:42 -07002231 main.log.info( "Sleeping {} seconds".format( main.removeIntentSleep ) )
acsmarscfa52272015-08-06 15:21:45 -07002232 time.sleep( main.removeIntentSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002233
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002234 # If there is remianing intents then remove intents should fail
Devin Lim142b5342017-07-20 15:22:39 -07002235 for ctrl in main.Cluster.active():
2236 onosSummary.append( json.loads( ctrl.CLI.summary() ) )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002237
2238 for summary in onosSummary:
2239 if summary.get( 'intents' ) != 0:
2240 main.log.warn( itemName + ": There are " +
2241 str( summary.get( 'intents' ) ) +
2242 " intents remaining in node " +
2243 str( summary.get( 'node' ) ) +
2244 ", failed to remove all the intents " )
2245 removeIntentResult = main.FALSE
2246
2247 if removeIntentResult:
2248 main.log.info( itemName + ": There are no more intents remaining, " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002249 "successfully removed all the intents." )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002250
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002251 return removeIntentResult
2252
Jon Hall78be4962017-05-23 14:53:53 -07002253
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002254def checkFlowsCount( main ):
2255 """
2256 Check flows count in each node
2257 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002258 flowsCount = []
2259 main.log.info( itemName + ": Checking flows count in each ONOS node" )
Devin Lim142b5342017-07-20 15:22:39 -07002260 for ctrl in main.Cluster.active():
2261 summaryResult = ctrl.CLI.summary()
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002262 if not summaryResult:
2263 main.log.error( itemName + ": There is something wrong with " +
2264 "summary command" )
2265 return main.FALSE
2266 else:
2267 summaryJson = json.loads( summaryResult )
2268 flowsCount.append( summaryJson.get( 'flows' ) )
2269
2270 if flowsCount:
Jon Hall78be4962017-05-23 14:53:53 -07002271 if all( flows == flowsCount[ 0 ] for flows in flowsCount ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002272 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
2273 " flows in all ONOS node" )
2274 else:
Devin Lim142b5342017-07-20 15:22:39 -07002275 for i in range( main.Cluster.numCtrls ):
2276 main.log.debug( itemName + ": " + ctrl.name + " has " +
2277 str( flowsCount[ ctrl.pos ] ) + " flows" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002278 else:
2279 main.log.error( "Checking flows count failed, check summary command" )
2280 return main.FALSE
2281
2282 return main.TRUE
2283
Jon Hall78be4962017-05-23 14:53:53 -07002284
kelvin-onlab58dc39e2015-08-06 08:11:09 -07002285def checkLeaderChange( leaders1, leaders2 ):
acsmarse6b410f2015-07-17 14:39:34 -07002286 """
2287 Checks for a change in intent partition leadership.
2288
2289 Takes the output of leaders -c in json string format before and after
2290 a potential change as input
2291
2292 Returns main.TRUE if no mismatches are detected
2293 Returns main.FALSE if there is a mismatch or on error loading the input
2294 """
2295 try:
2296 leaders1 = json.loads( leaders1 )
2297 leaders2 = json.loads( leaders2 )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002298 except( AttributeError, TypeError ):
Jon Halld970abf2017-05-23 10:20:28 -07002299 main.log.exception( "checkLeaderChange: Object not as expected" )
acsmarse6b410f2015-07-17 14:39:34 -07002300 return main.FALSE
2301 except Exception:
Jon Halld970abf2017-05-23 10:20:28 -07002302 main.log.exception( "checkLeaderChange: Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002303 main.cleanAndExit()
2304
acsmarse6b410f2015-07-17 14:39:34 -07002305 main.log.info( "Checking Intent Paritions for Change in Leadership" )
2306 mismatch = False
2307 for dict1 in leaders1:
2308 if "intent" in dict1.get( "topic", [] ):
2309 for dict2 in leaders2:
Jon Hall78be4962017-05-23 14:53:53 -07002310 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and\
2311 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
acsmarse6b410f2015-07-17 14:39:34 -07002312 mismatch = True
Jon Hall78be4962017-05-23 14:53:53 -07002313 main.log.error( "%s changed leader from %s to %s",
2314 dict1.get( "topic", "no-topic" ),
2315 dict1.get( "leader", "no-leader" ),
2316 dict2.get( "leader", "no-leader" ) )
acsmarse6b410f2015-07-17 14:39:34 -07002317 if mismatch:
2318 return main.FALSE
2319 else:
2320 return main.TRUE
kelvin-onlab016dce22015-08-10 09:54:11 -07002321
Jon Hall78be4962017-05-23 14:53:53 -07002322
kelvin-onlab016dce22015-08-10 09:54:11 -07002323def report( main ):
2324 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002325 Report errors/warnings/exceptions
kelvin-onlab016dce22015-08-10 09:54:11 -07002326 """
Devin Lim142b5342017-07-20 15:22:39 -07002327 main.ONOSbench.logReport( main.Cluster.active( 0 ).ipAddress,
kelvin-onlab016dce22015-08-10 09:54:11 -07002328 [ "INFO",
2329 "FOLLOWER",
2330 "WARN",
2331 "flow",
2332 "ERROR",
2333 "Except" ],
2334 "s" )
2335
2336 main.log.info( "ERROR report: \n" )
Devin Lim142b5342017-07-20 15:22:39 -07002337 for ctrl in main.Cluster.active():
2338 main.ONOSbench.logReport( ctrl.ipAddress,
Jon Hall78be4962017-05-23 14:53:53 -07002339 [ "ERROR" ],
2340 "d" )
kelvin-onlab016dce22015-08-10 09:54:11 -07002341
2342 main.log.info( "EXCEPTIONS report: \n" )
Devin Lim142b5342017-07-20 15:22:39 -07002343 for ctrl in main.Cluster.active():
2344 main.ONOSbench.logReport( ctrl.ipAddress,
Jon Hall78be4962017-05-23 14:53:53 -07002345 [ "Except" ],
2346 "d" )
kelvin-onlab016dce22015-08-10 09:54:11 -07002347
2348 main.log.info( "WARNING report: \n" )
Devin Lim142b5342017-07-20 15:22:39 -07002349 for ctrl in main.Cluster.active():
2350 main.ONOSbench.logReport( ctrl.ipAddress,
Jon Hall78be4962017-05-23 14:53:53 -07002351 [ "WARN" ],
2352 "d" )
2353
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002354
2355def flowDuration( main ):
2356 """
2357 Check age of flows to see if flows are being overwritten
2358 """
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002359 main.log.info( "Getting current flow durations" )
Devin Lim142b5342017-07-20 15:22:39 -07002360 flowsJson1 = main.Cluster.active( 0 ).CLI.flows( noCore=True )
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002361 try:
2362 flowsJson1 = json.loads( flowsJson1 )
2363 except ValueError:
2364 main.log.error( "Unable to read flows" )
2365 return main.FALSE
2366 flowLife = []
2367 waitFlowLife = []
2368 for device in flowsJson1:
2369 if device.get( 'flowcount', 0 ) > 0:
2370 for i in range( device[ 'flowCount' ] ):
2371 flowLife.append( device[ 'flows' ][ i ][ 'life' ] )
2372 main.log.info( "Sleeping for {} seconds".format( main.flowDurationSleep ) )
2373 time.sleep( main.flowDurationSleep )
2374 main.log.info( "Getting new flow durations" )
Devin Lim142b5342017-07-20 15:22:39 -07002375 flowsJson2 = main.Cluster.active( 0 ).CLI.flows( noCore=True )
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002376 try:
2377 flowsJson2 = json.loads( flowsJson2 )
2378 except ValueError:
2379 main.log.error( "Unable to read flows" )
2380 return main.FALSE
2381 for device in flowsJson2:
2382 if device.get( 'flowcount', 0 ) > 0:
2383 for i in range( device[ 'flowCount' ] ):
2384 waitFlowLife.append( device[ 'flows' ][ i ][ 'life' ] )
2385 main.log.info( "Determining whether flows where overwritten" )
2386 if len( flowLife ) == len( waitFlowLife ):
alison52b25892016-09-19 10:53:48 -07002387 for i in range( len( flowLife ) ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002388 if waitFlowLife[ i ] - flowLife[ i ] < main.flowDurationSleep:
2389 return main.FALSE
2390 else:
2391 return main.FALSE
2392 return main.TRUE
alison52b25892016-09-19 10:53:48 -07002393
2394
2395def EncapsulatedIntentCheck( main, tag="" ):
2396 """
2397 Check encapsulated intents
Jon Hall78be4962017-05-23 14:53:53 -07002398 tag: encapsulation tag ( e.g. VLAN, MPLS )
alison52b25892016-09-19 10:53:48 -07002399
2400 Getting added flows
2401 Check tags on each flows
2402 If each direction has push or pop, passed
2403 else failed
2404
2405 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002406 main.log.info( "Checking encapsulated intent for " + tag + "." )
alison52b25892016-09-19 10:53:48 -07002407 HostJson = []
Devin Lim142b5342017-07-20 15:22:39 -07002408 Jflows = main.Cluster.active( 0 ).CLI.flows( noCore=True )
alison52b25892016-09-19 10:53:48 -07002409 try:
2410 Jflows = json.loads( Jflows )
2411 except ValueError:
2412 main.log.error( "Unable to read flows" )
2413 return main.FALSE
2414
2415 for flow in Jflows:
Jon Hall78be4962017-05-23 14:53:53 -07002416 if len( flow[ "flows" ] ) != 0:
alison52b25892016-09-19 10:53:48 -07002417 HostJson.append( flow[ "flows" ] )
2418
Jon Hall78be4962017-05-23 14:53:53 -07002419 totalflows = len( HostJson[ 0 ] )
alison52b25892016-09-19 10:53:48 -07002420
2421 pop = 0
2422 push = 0
2423
2424 PopTag = tag + "_POP"
2425 PushTag = tag + "_PUSH"
Devin Limf6d287d2017-08-04 14:39:11 -07002426 main.log.info( "Host Json info :" )
alison52b25892016-09-19 10:53:48 -07002427 for EachHostJson in HostJson:
2428 for i in range( totalflows ):
Devin Limf6d287d2017-08-04 14:39:11 -07002429 main.log.info( str( EachHostJson[ i ] ) )
2430 checkJson = EachHostJson[ i ][ "treatment" ][ "instructions" ][ 0 ]
2431 main.Cluster.active( 0 ).REST.pprint( checkJson )
2432 if 'subtype' in checkJson:
2433 if checkJson[ "subtype" ] == PopTag:
2434 pop += 1
2435 elif checkJson[ "subtype" ] == PushTag:
2436 push += 1
alison52b25892016-09-19 10:53:48 -07002437
2438 if pop == totalflows and push == totalflows:
2439 return main.TRUE
2440 else:
Devin Limf6d287d2017-08-04 14:39:11 -07002441 main.log.error( "Total " + PushTag + str( push ) )
2442 main.log.error( "Total " + PopTag + str( pop ) )
alisonda157272016-12-22 01:13:21 -08002443 return main.FALSE
2444
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002445
alisonda157272016-12-22 01:13:21 -08002446def ProtectedIntentCheck( main ):
Devin Lim142b5342017-07-20 15:22:39 -07002447 intent = main.Cluster.active( 0 ).CLI.intents( jsonFormat=False )
alisonda157272016-12-22 01:13:21 -08002448 if "Protection" in intent:
2449 return main.TRUE
Shreyaca8990f2017-03-16 11:43:11 -07002450 return main.FALSE