blob: d50d46456e406443ef559637075859538ec0d909 [file] [log] [blame]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07002Copyright 2015 Open Networking Foundation (ONF)
3
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
11 (at your option) any later version.
12
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" )
Jeremyd9e4eb12016-04-13 12:09:06 -0700109 intentId = main.CLIs[ onosNode ].addHostIntent( hostIdOne=host1.get( "id" ),
Jeremy Songster832f9e92016-05-05 14:30:49 -0700110 hostIdTwo=host2.get( "id" ),
Jeremy Songsterff553672016-05-12 17:06:23 -0700111 vlanId=vlanId,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700112 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:
246 attempts = 1
247 else:
248 attempts = 50
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
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700258 attempts = 1
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,
278 attempts=attempts,
279 sleep=main.checkConnectionSleep,
Shreyaca8990f2017-03-16 11:43:11 -0700280 args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800281 main.assertReturnString += 'Initial Ping Passed\n'
282 else:
283 main.assertReturnString += 'Initial Ping Failed\n'
284 testResult = main.FALSE
285
286 # Test rerouting if these variables exist
287 if sw1 and sw2 and expectedLink:
288 # Take link down
Jon Hallaf95c3e2017-05-16 13:20:37 -0700289 if utilities.retry( f=link,
290 retValue=main.FALSE,
291 args=( main, sw1, sw2, "down" ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800292 main.assertReturnString += 'Link Down Passed\n'
293 else:
294 main.assertReturnString += 'Link Down Failed\n'
295 testResult = main.FALSE
296
297 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700298 if utilities.retry( f=checkIntentState,
299 retValue=main.FALSE,
300 args=( main, [ intentId ] ),
301 sleep=main.checkIntentHostSleep,
302 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800303 main.assertReturnString += 'Link Down Intent State Passed\n'
304 else:
305 main.assertReturnString += 'Link Down Intent State Failed\n'
306 testResult = main.FALSE
307
308 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -0700309 if utilities.retry( f=checkFlowsCount,
310 retValue=main.FALSE,
311 args=[ main ],
312 sleep=main.checkFlowCountSleep,
313 attempts=attempts ) and utilities.retry( f=checkFlowsState,
314 retValue=main.FALSE,
315 args=[ main ],
316 sleep=main.checkFlowCountSleep,
317 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800318 main.assertReturnString += 'Link Down Flow State Passed\n'
319 else:
320 main.assertReturnString += 'Link Down Flow State Failed\n'
321 testResult = main.FALSE
322
323 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -0700324 if utilities.retry( f=checkTopology,
325 retValue=main.FALSE,
326 args=( main, expectedLink ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800327 main.assertReturnString += 'Link Down Topology State Passed\n'
328 else:
329 main.assertReturnString += 'Link Down Topology State Failed\n'
330 testResult = main.FALSE
331
332 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -0700333 if utilities.retry( f=scapyCheckConnection,
334 retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -0700335 args=( main, senderNames, recipientNames, vlanId ),
Jon Hallaf95c3e2017-05-16 13:20:37 -0700336 sleep=main.checkConnectionSleep,
337 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800338 main.assertReturnString += 'Link Down Pingall Passed\n'
339 else:
340 main.assertReturnString += 'Link Down Pingall Failed\n'
341 testResult = main.FALSE
342
343 # Bring link up
Jon Hallaf95c3e2017-05-16 13:20:37 -0700344 if utilities.retry( f=link,
345 retValue=main.FALSE,
346 args=( main, sw1, sw2, "up" ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800347 main.assertReturnString += 'Link Up Passed\n'
348 else:
349 main.assertReturnString += 'Link Up Failed\n'
350 testResult = main.FALSE
351
352 # Wait for reroute
Jon Hallf539eb92017-05-22 17:18:42 -0700353 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800354 time.sleep( main.rerouteSleep )
355
356 # Check Intents
Jon Hallaf95c3e2017-05-16 13:20:37 -0700357 if utilities.retry( f=checkIntentState,
358 retValue=main.FALSE,
359 attempts=attempts * 2,
360 args=( main, [ intentId ] ),
361 sleep=main.checkIntentSleep ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800362 main.assertReturnString += 'Link Up Intent State Passed\n'
363 else:
364 main.assertReturnString += 'Link Up Intent State Failed\n'
365 testResult = main.FALSE
366
367 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -0700368 if utilities.retry( f=checkFlowsCount,
369 retValue=main.FALSE,
370 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -0700371 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -0700372 attempts=3 ) and utilities.retry( f=checkFlowsState,
373 retValue=main.FALSE,
374 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -0700375 sleep=main.checkFlowCountSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -0700376 attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800377 main.assertReturnString += 'Link Up Flow State Passed\n'
378 else:
379 main.assertReturnString += 'Link Up Flow State Failed\n'
380 testResult = main.FALSE
381
382 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -0700383 if utilities.retry( f=checkTopology,
384 retValue=main.FALSE,
385 args=( main, main.numLinks ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800386 main.assertReturnString += 'Link Up Topology State Passed\n'
387 else:
388 main.assertReturnString += 'Link Up Topology State Failed\n'
389 testResult = main.FALSE
390
391 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -0700392 if utilities.retry( f=scapyCheckConnection,
393 retValue=main.FALSE,
394 args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800395 main.assertReturnString += 'Link Up Pingall Passed\n'
396 else:
397 main.assertReturnString += 'Link Up Pingall Failed\n'
398 testResult = main.FALSE
399
400 # Remove all intents
Jon Hallaf95c3e2017-05-16 13:20:37 -0700401 if utilities.retry( f=removeAllIntents,
402 retValue=main.FALSE,
403 attempts=10,
404 args=( main, [ intentId ] ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800405 main.assertReturnString += 'Remove Intents Passed'
406 else:
407 main.assertReturnString += 'Remove Intents Failed'
408 testResult = main.FALSE
409
410 return testResult
411
Jon Hall78be4962017-05-23 14:53:53 -0700412
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800413def installPointIntent( main,
414 name,
415 senders,
416 recipients,
417 onosNode=0,
418 ethType="",
419 bandwidth="",
420 lambdaAlloc=False,
alisonda157272016-12-22 01:13:21 -0800421 protected=False,
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800422 ipProto="",
423 ipSrc="",
424 ipDst="",
425 tcpSrc="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700426 tcpDst="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700427 setVlan="",
Jon Hallf539eb92017-05-22 17:18:42 -0700428 encap="" ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800429 """
430 Installs a Single to Single Point Intent
431
432 Description:
433 Install a single to single point intent
434
435 Steps:
436 - Fetch host data if not given
437 - Add point intent
438 - Ingress device is the first sender device
439 - Egress device is the first recipient device
440 - Ports if defined in senders or recipients
441 - MAC address ethSrc loaded from Ingress device
442 - Check intent state with retry
443 Required:
444 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
445 senders - List of host dictionaries i.e.
446 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
447 recipients - List of host dictionaries i.e.
448 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
449 Optional:
450 onosNode - ONOS node to install the intents in main.CLIs[ ]
451 0 by default so that it will always use the first
452 ONOS node
453 ethType - Ethernet type eg. IPV4, IPV6
454 bandwidth - Bandwidth capacity
455 lambdaAlloc - Allocate lambda, defaults to False
456 ipProto - IP protocol
457 tcp - TCP ports in the same order as the hosts in hostNames
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700458 sw1 - First switch to bring down & up for rerouting purpose
459 sw2 - Second switch to bring down & up for rerouting purpose
460 expectedLink - Expected link when the switches are down, it should
461 be two links lower than the links before the two
462 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700463 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700464 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800465 assert senders, "You must specify a sender"
466 assert recipients, "You must specify a recipient"
467 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700468
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800469 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700470 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700471
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700472 global pointIntentFailFlag
473 pointIntentFailFlag = False
474
Jeremy6f000c62016-02-25 17:02:28 -0800475 main.log.info( itemName + ": Adding point to point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700476
Jeremyd9e4eb12016-04-13 12:09:06 -0700477 try:
478 for sender in senders:
479 if not sender.get( "device" ):
480 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
481 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800482
Jeremyd9e4eb12016-04-13 12:09:06 -0700483 for recipient in recipients:
484 if not recipient.get( "device" ):
485 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
486 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800487
Jeremyd9e4eb12016-04-13 12:09:06 -0700488 ingressDevice = senders[ 0 ].get( "device" )
489 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800490
Jeremyd9e4eb12016-04-13 12:09:06 -0700491 portIngress = senders[ 0 ].get( "port", "" )
492 portEgress = recipients[ 0 ].get( "port", "" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800493
Jeremyd9e4eb12016-04-13 12:09:06 -0700494 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800495
Jeremyd9e4eb12016-04-13 12:09:06 -0700496 ipSrc = senders[ 0 ].get( "ip" )
497 ipDst = recipients[ 0 ].get( "ip" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800498
Jeremy Songster832f9e92016-05-05 14:30:49 -0700499 vlanId = senders[ 0 ].get( "vlan" )
500
Jeremyd9e4eb12016-04-13 12:09:06 -0700501 # Adding point intent
502 intentId = main.CLIs[ onosNode ].addPointIntent(
503 ingressDevice=ingressDevice,
504 egressDevice=egressDevice,
505 portIngress=portIngress,
506 portEgress=portEgress,
507 ethType=ethType,
508 ethDst=dstMac,
509 bandwidth=bandwidth,
510 lambdaAlloc=lambdaAlloc,
alisonda157272016-12-22 01:13:21 -0800511 protected=protected,
Jeremyd9e4eb12016-04-13 12:09:06 -0700512 ipProto=ipProto,
513 ipSrc=ipSrc,
514 ipDst=ipDst,
515 tcpSrc=tcpSrc,
Jeremy Songster832f9e92016-05-05 14:30:49 -0700516 tcpDst=tcpDst,
Jeremy Songsterff553672016-05-12 17:06:23 -0700517 vlanId=vlanId,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700518 setVlan=setVlan,
519 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700520 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700521 errorMsg = "There was a problem loading the hosts data."
522 if intentId:
523 errorMsg += " There was a problem installing Point to Point intent."
524 main.log.error( errorMsg )
525 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700526
527 # Check intents state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700528 if utilities.retry( f=checkIntentState,
529 retValue=main.FALSE,
Jon Hallf539eb92017-05-22 17:18:42 -0700530 args=( main, [ intentId ] ),
531 sleep=main.checkIntentSleep,
Jon Hallaf95c3e2017-05-16 13:20:37 -0700532 attempts=50 ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700533 main.assertReturnString += 'Install Intent State Passed\n'
alison52b25892016-09-19 10:53:48 -0700534
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700535 if bandwidth != "":
Jon Hallf539eb92017-05-22 17:18:42 -0700536 allocationsFile = open( os.path.dirname( main.testFile ) + main.params[ 'DEPENDENCY' ][ 'filePath' ], 'r' )
537 expectedFormat = allocationsFile.read()
538 bandwidthCheck = checkBandwidthAllocations( main, expectedFormat )
539 allocationsFile.close()
540 if bandwidthCheck:
541 main.assertReturnString += 'Bandwidth Allocation check Passed\n'
542 else:
543 main.assertReturnString += 'Bandwidth Allocation check Failed\n'
Jon Hallc3f88af2017-05-23 11:25:54 -0700544 return main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700545
alison52b25892016-09-19 10:53:48 -0700546 # Check VLAN if test encapsulation
547 if encap != "":
548 if EncapsulatedIntentCheck( main, tag=encap ):
549 main.assertReturnString += 'Encapsulation intents check Passed\n'
550 else:
551 main.assertReturnString += 'Encapsulation intents check failed\n'
alisonda157272016-12-22 01:13:21 -0800552
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700553 if flowDuration( main ):
554 main.assertReturnString += 'Flow duration check Passed\n'
555 return intentId
556 else:
557 main.assertReturnString += 'Flow duration check failed\n'
558 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -0700559 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800560 main.log.error( "Point Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700561 pointIntentFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800562 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700563
Jon Hall78be4962017-05-23 14:53:53 -0700564
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700565def pointIntentTcp( main,
566 name,
567 host1,
568 host2,
569 onosNode=0,
570 deviceId1="",
571 deviceId2="",
572 port1="",
573 port2="",
574 ethType="",
575 mac1="",
576 mac2="",
577 bandwidth="",
578 lambdaAlloc=False,
579 ipProto="",
580 ip1="",
581 ip2="",
582 tcp1="",
583 tcp2="",
584 sw1="",
585 sw2="",
586 expectedLink=0 ):
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700587 """
588 Description:
589 Verify add-point-intent only for TCP
590 Steps:
591 - Get device ids | ports
592 - Add point intents
593 - Check intents
594 - Verify flows
595 - Ping hosts
596 - Reroute
597 - Link down
598 - Verify flows
599 - Check topology
600 - Ping hosts
601 - Link up
602 - Verify flows
603 - Check topology
604 - Ping hosts
605 - Remove intents
606 Required:
607 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
608 host1 - Name of first host
609 host2 - Name of second host
610 Optional:
611 onosNode - ONOS node to install the intents in main.CLIs[ ]
612 0 by default so that it will always use the first
613 ONOS node
614 deviceId1 - ONOS device id of the first switch, the same as the
615 location of the first host eg. of:0000000000000001/1,
616 located at device 1 port 1
617 deviceId2 - ONOS device id of the second switch
618 port1 - The port number where the first host is attached
619 port2 - The port number where the second host is attached
620 ethType - Ethernet type eg. IPV4, IPV6
621 mac1 - Mac address of first host
622 mac2 - Mac address of the second host
623 bandwidth - Bandwidth capacity
624 lambdaAlloc - Allocate lambda, defaults to False
625 ipProto - IP protocol
626 ip1 - IP address of first host
627 ip2 - IP address of second host
628 tcp1 - TCP port of first host
629 tcp2 - TCP port of second host
630 sw1 - First switch to bring down & up for rerouting purpose
631 sw2 - Second switch to bring down & up for rerouting purpose
632 expectedLink - Expected link when the switches are down, it should
633 be two links lower than the links before the two
634 switches are down
635 """
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700636 assert main, "There is no main variable"
637 assert name, "variable name is empty"
638 assert host1 and host2, "You must specify hosts"
639
640 global itemName
641 itemName = name
642 host1 = host1
643 host2 = host2
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700644 intentsId = []
645
646 iperfResult = main.TRUE
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700647 linkDownResult = main.TRUE
648 linkUpResult = main.TRUE
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700649
650 # Adding bidirectional point intents
651 main.log.info( itemName + ": Adding point intents" )
652 intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
653 egressDevice=deviceId2,
654 portIngress=port1,
655 portEgress=port2,
656 ethType=ethType,
657 ethSrc=mac1,
658 ethDst=mac2,
659 bandwidth=bandwidth,
660 lambdaAlloc=lambdaAlloc,
661 ipProto=ipProto,
662 ipSrc=ip1,
663 ipDst=ip2,
664 tcpSrc=tcp1,
665 tcpDst="" )
666
667 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
668 egressDevice=deviceId1,
669 portIngress=port2,
670 portEgress=port1,
671 ethType=ethType,
672 ethSrc=mac2,
673 ethDst=mac1,
674 bandwidth=bandwidth,
675 lambdaAlloc=lambdaAlloc,
676 ipProto=ipProto,
677 ipSrc=ip2,
678 ipDst=ip1,
679 tcpSrc=tcp2,
680 tcpDst="" )
681
682 intent3 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
683 egressDevice=deviceId2,
684 portIngress=port1,
685 portEgress=port2,
686 ethType=ethType,
687 ethSrc=mac1,
688 ethDst=mac2,
689 bandwidth=bandwidth,
690 lambdaAlloc=lambdaAlloc,
691 ipProto=ipProto,
692 ipSrc=ip1,
693 ipDst=ip2,
694 tcpSrc="",
695 tcpDst=tcp2 )
696
697 intent4 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
698 egressDevice=deviceId1,
699 portIngress=port2,
700 portEgress=port1,
701 ethType=ethType,
702 ethSrc=mac2,
703 ethDst=mac1,
704 bandwidth=bandwidth,
705 lambdaAlloc=lambdaAlloc,
706 ipProto=ipProto,
707 ipSrc=ip2,
708 ipDst=ip1,
709 tcpSrc="",
710 tcpDst=tcp1 )
711 intentsId.append( intent1 )
712 intentsId.append( intent2 )
713 intentsId.append( intent3 )
714 intentsId.append( intent4 )
715
716 # Check intents state
Jon Hallf539eb92017-05-22 17:18:42 -0700717 main.log.info( "Sleeping {} seconds".format( main.checkIntentSleep ) )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700718 time.sleep( main.checkIntentSleep )
Jon Hallaf95c3e2017-05-16 13:20:37 -0700719 intentResult = utilities.retry( f=checkIntentState,
720 retValue=main.FALSE,
721 args=( main, intentsId ),
722 sleep=1,
723 attempts=50 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700724 # Check flows count in each node
725 checkFlowsCount( main )
726
727 # Check intents state again if first check fails...
728 if not intentResult:
Jon Hallaf95c3e2017-05-16 13:20:37 -0700729 intentResult = utilities.retry( f=checkIntentState,
730 retValue=main.FALSE,
731 args=( main, intentsId ),
732 sleep=1,
733 attempts=50 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700734
735 # Check flows count in each node
736 checkFlowsCount( main )
737
738 # Verify flows
739 checkFlowsState( main )
740
741 # Run iperf to both host
Jon Hall78be4962017-05-23 14:53:53 -0700742 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700743 iperfResult = iperfResult and iperfTemp
744 if iperfTemp:
745 main.assertReturnString += 'Initial Iperf Passed\n'
746 else:
747 main.assertReturnString += 'Initial Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700748
749 # Test rerouting if these variables exist
750 if sw1 and sw2 and expectedLink:
751 # link down
752 linkDownResult = link( main, sw1, sw2, "down" )
acsmarsd4862d12015-10-06 17:57:34 -0700753
754 if linkDownResult:
755 main.assertReturnString += 'Link Down Passed\n'
756 else:
757 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700758
759 # Check flows count in each node
760 checkFlowsCount( main )
761 # Verify flows
762 checkFlowsState( main )
763
764 # Check OnosTopology
765 topoResult = checkTopology( main, expectedLink )
acsmarsd4862d12015-10-06 17:57:34 -0700766 if topoResult:
767 main.assertReturnString += 'Link Down Topology State Passed\n'
768 else:
769 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700770
771 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700772 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700773 iperfResult = iperfResult and iperfTemp
774 if iperfTemp:
775 main.assertReturnString += 'Link Down Iperf Passed\n'
776 else:
777 main.assertReturnString += 'Link Down Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700778
acsmarsd4862d12015-10-06 17:57:34 -0700779 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700780 intentTemp = utilities.retry( f=checkIntentState,
781 retValue=main.FALSE,
782 args=( main, intentsId ),
783 sleep=1,
784 attempts=50 )
acsmarsd4862d12015-10-06 17:57:34 -0700785 intentResult = intentResult and intentTemp
786 if intentTemp:
787 main.assertReturnString += 'Link Down Intent State Passed\n'
788 else:
789 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700790
791 # Checks ONOS state in link down
792 if linkDownResult and topoResult and iperfResult and intentResult:
793 main.log.info( itemName + ": Successfully brought link down" )
794 else:
795 main.log.error( itemName + ": Failed to bring link down" )
796
797 # link up
798 linkUpResult = link( main, sw1, sw2, "up" )
alison52b25892016-09-19 10:53:48 -0700799 if linkUpResult:
acsmarsd4862d12015-10-06 17:57:34 -0700800 main.assertReturnString += 'Link Up Passed\n'
801 else:
802 main.assertReturnString += 'Link Up Failed\n'
803
Jon Hallf539eb92017-05-22 17:18:42 -0700804 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700805 time.sleep( main.rerouteSleep )
806
807 # Check flows count in each node
808 checkFlowsCount( main )
809 # Verify flows
810 checkFlowsState( main )
811
812 # Check OnosTopology
813 topoResult = checkTopology( main, main.numLinks )
814
acsmarsd4862d12015-10-06 17:57:34 -0700815 if topoResult:
816 main.assertReturnString += 'Link Up Topology State Passed\n'
817 else:
818 main.assertReturnString += 'Link Up Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700819
acsmarsd4862d12015-10-06 17:57:34 -0700820 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700821 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700822 iperfResult = iperfResult and iperfTemp
823 if iperfTemp:
824 main.assertReturnString += 'Link Up Iperf Passed\n'
825 else:
826 main.assertReturnString += 'Link Up Iperf Failed\n'
827
828 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700829 intentTemp = utilities.retry( f=checkIntentState,
830 retValue=main.FALSE,
831 args=( main, intentsId ),
832 sleep=1,
833 attempts=50 )
acsmarsd4862d12015-10-06 17:57:34 -0700834 intentResult = intentResult and intentTemp
835 if intentTemp:
836 main.assertReturnString += 'Link Down Intent State Passed\n'
837 else:
838 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700839
840 # Checks ONOS state in link up
841 if linkUpResult and topoResult and iperfResult and intentResult:
842 main.log.info( itemName + ": Successfully brought link back up" )
843 else:
844 main.log.error( itemName + ": Failed to bring link back up" )
845
846 # Remove all intents
847 removeIntentResult = removeAllIntents( main, intentsId )
acsmarsd4862d12015-10-06 17:57:34 -0700848 if removeIntentResult:
849 main.assertReturnString += 'Remove Intents Passed'
850 else:
851 main.assertReturnString += 'Remove Intents Failed'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700852
853 stepResult = iperfResult and linkDownResult and linkUpResult \
854 and intentResult and removeIntentResult
855
856 return stepResult
857
Jon Hall78be4962017-05-23 14:53:53 -0700858
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800859def installSingleToMultiIntent( main,
860 name,
861 senders,
862 recipients,
863 onosNode=0,
864 ethType="",
865 bandwidth="",
866 lambdaAlloc=False,
867 ipProto="",
868 ipAddresses="",
869 tcp="",
870 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700871 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -0700872 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700873 partial=False,
Jon Hallf539eb92017-05-22 17:18:42 -0700874 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700875 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800876 Installs a Single to Multi Point Intent
877
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700878 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800879 Install a single to multi point intent using
880 add-single-to-multi-intent
881
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700882 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800883 - Fetch host data if not given
884 - Add single to multi intent
885 - Ingress device is the first sender host
886 - Egress devices are the recipient devices
887 - Ports if defined in senders or recipients
888 - MAC address ethSrc loaded from Ingress device
889 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700890 Required:
891 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800892 senders - List of host dictionaries i.e.
893 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
894 recipients - List of host dictionaries i.e.
895 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700896 Optional:
897 onosNode - ONOS node to install the intents in main.CLIs[ ]
898 0 by default so that it will always use the first
899 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700900 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700901 bandwidth - Bandwidth capacity
902 lambdaAlloc - Allocate lambda, defaults to False
903 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700904 tcp - TCP ports in the same order as the hosts in hostNames
905 sw1 - First switch to bring down & up for rerouting purpose
906 sw2 - Second switch to bring down & up for rerouting purpose
907 expectedLink - Expected link when the switches are down, it should
908 be two links lower than the links before the two
909 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700910 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700911 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800912 assert senders, "You must specify a sender"
913 assert recipients, "You must specify a recipient"
914 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700915
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800916 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700917 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700918
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700919 global singleToMultiFailFlag
920 singleToMultiFailFlag = False
921
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700922 main.log.info( itemName + ": Adding single point to multi point intents" )
923
Jeremyd9e4eb12016-04-13 12:09:06 -0700924 try:
925 for sender in senders:
926 if not sender.get( "device" ):
927 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
928 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700929
Jeremyd9e4eb12016-04-13 12:09:06 -0700930 for recipient in recipients:
931 if not recipient.get( "device" ):
932 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
933 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700934
Jeremyd9e4eb12016-04-13 12:09:06 -0700935 ingressDevice = senders[ 0 ].get( "device" )
936 egressDeviceList = [ x.get( "device" ) for x in recipients if x.get( "device" ) ]
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800937
Jeremyd9e4eb12016-04-13 12:09:06 -0700938 portIngress = senders[ 0 ].get( "port", "" )
939 portEgressList = [ x.get( "port" ) for x in recipients if x.get( "port" ) ]
940 if not portEgressList:
941 portEgressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800942
Jeremyd9e4eb12016-04-13 12:09:06 -0700943 srcMac = senders[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700944 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800945
Jeremyd9e4eb12016-04-13 12:09:06 -0700946 # Adding point intent
947 intentId = main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
948 ingressDevice=ingressDevice,
949 egressDeviceList=egressDeviceList,
950 portIngress=portIngress,
951 portEgressList=portEgressList,
952 ethType=ethType,
953 ethSrc=srcMac,
954 bandwidth=bandwidth,
955 lambdaAlloc=lambdaAlloc,
956 ipProto=ipProto,
957 ipSrc="",
958 ipDst="",
959 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -0700960 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700961 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -0700962 setVlan=setVlan,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700963 partial=partial,
964 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700965 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700966 errorMsg = "There was a problem loading the hosts data."
967 if intentId:
968 errorMsg += " There was a problem installing Singlepoint to Multipoint intent."
969 main.log.error( errorMsg )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700970 singleToMultiFailFlag = True
Jeremyd9e4eb12016-04-13 12:09:06 -0700971 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700972
973 # Check intents state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700974 if singleToMultiFailFlag:
975 attempts = 5
976 else:
977 attempts = 50
978
Jon Hallaf95c3e2017-05-16 13:20:37 -0700979 if utilities.retry( f=checkIntentState,
980 retValue=main.FALSE,
Jon Hallf539eb92017-05-22 17:18:42 -0700981 args=( main, [ intentId ] ),
Jon Hallaf95c3e2017-05-16 13:20:37 -0700982 sleep=main.checkIntentSleep,
983 attempts=attempts ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700984 main.assertReturnString += 'Install Intent State Passed\n'
Jon Hallf539eb92017-05-22 17:18:42 -0700985 if bandwidth != "":
986 allocationsFile = open( os.path.dirname( main.testFile ) + main.params[ 'DEPENDENCY' ][ 'filePath' ], 'r' )
987 expectedFormat = allocationsFile.read()
988 bandwidthCheck = checkBandwidthAllocations( main, expectedFormat )
989 allocationsFile.close()
990 if bandwidthCheck:
991 main.assertReturnString += 'Bandwidth Allocation check Passed\n'
992 else:
993 main.assertReturnString += 'Bandwidth Allocation check Failed\n'
Jon Hallc3f88af2017-05-23 11:25:54 -0700994 return main.FALSE
995
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700996 if flowDuration( main ):
997 main.assertReturnString += 'Flow duration check Passed\n'
998 return intentId
999 else:
1000 main.assertReturnString += 'Flow duration check failed\n'
1001 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -07001002 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001003 main.log.error( "Single to Multi Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001004 singleToMultiFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001005 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001006
Jon Hall78be4962017-05-23 14:53:53 -07001007
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001008def installMultiToSingleIntent( main,
1009 name,
1010 senders,
1011 recipients,
1012 onosNode=0,
1013 ethType="",
1014 bandwidth="",
1015 lambdaAlloc=False,
1016 ipProto="",
1017 ipAddresses="",
1018 tcp="",
1019 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -07001020 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -07001021 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -07001022 partial=False,
Jon Hallf539eb92017-05-22 17:18:42 -07001023 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001024 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001025 Installs a Multi to Single Point Intent
1026
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001027 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001028 Install a multi to single point intent using
1029 add-multi-to-single-intent
1030
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001031 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001032 - Fetch host data if not given
1033 - Add multi to single intent
1034 - Ingress devices are the senders devices
1035 - Egress device is the first recipient host
1036 - Ports if defined in senders or recipients
1037 - MAC address ethSrc loaded from Ingress device
1038 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001039 Required:
1040 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001041 senders - List of host dictionaries i.e.
1042 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
1043 recipients - List of host dictionaries i.e.
1044 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001045 Optional:
1046 onosNode - ONOS node to install the intents in main.CLIs[ ]
1047 0 by default so that it will always use the first
1048 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001049 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001050 bandwidth - Bandwidth capacity
1051 lambdaAlloc - Allocate lambda, defaults to False
1052 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001053 tcp - TCP ports in the same order as the hosts in hostNames
1054 sw1 - First switch to bring down & up for rerouting purpose
1055 sw2 - Second switch to bring down & up for rerouting purpose
1056 expectedLink - Expected link when the switches are down, it should
1057 be two links lower than the links before the two
1058 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001059 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001060 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001061 assert senders, "You must specify a sender"
1062 assert recipients, "You must specify a recipient"
1063 # Assert devices or main.hostsData, "You must specify devices"
1064
1065 global itemName # The name of this run. Used for logs.
1066 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001067
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001068 global multiToSingleFailFlag
1069 multiToSingleFailFlag = False
1070
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001071 main.log.info( itemName + ": Adding mutli to single point intents" )
1072
Jeremyd9e4eb12016-04-13 12:09:06 -07001073 try:
1074 for sender in senders:
1075 if not sender.get( "device" ):
1076 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1077 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001078
Jeremyd9e4eb12016-04-13 12:09:06 -07001079 for recipient in recipients:
1080 if not recipient.get( "device" ):
1081 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1082 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001083
Jeremyd9e4eb12016-04-13 12:09:06 -07001084 ingressDeviceList = [ x.get( "device" ) for x in senders if x.get( "device" ) ]
1085 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001086
Jeremyd9e4eb12016-04-13 12:09:06 -07001087 portIngressList = [ x.get( "port" ) for x in senders if x.get( "port" ) ]
1088 portEgress = recipients[ 0 ].get( "port", "" )
1089 if not portIngressList:
1090 portIngressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001091
Jeremyd9e4eb12016-04-13 12:09:06 -07001092 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001093 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001094
Jeremyd9e4eb12016-04-13 12:09:06 -07001095 # Adding point intent
1096 intentId = main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
1097 ingressDeviceList=ingressDeviceList,
1098 egressDevice=egressDevice,
1099 portIngressList=portIngressList,
1100 portEgress=portEgress,
1101 ethType=ethType,
1102 ethDst=dstMac,
1103 bandwidth=bandwidth,
1104 lambdaAlloc=lambdaAlloc,
1105 ipProto=ipProto,
1106 ipSrc="",
1107 ipDst="",
1108 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -07001109 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -07001110 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -07001111 setVlan=setVlan,
Jeremy Songsterc032f162016-08-04 17:14:49 -07001112 partial=partial,
1113 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001114 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001115 errorMsg = "There was a problem loading the hosts data."
1116 if intentId:
1117 errorMsg += " There was a problem installing Multipoint to Singlepoint intent."
1118 main.log.error( errorMsg )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001119 multiToSingleFailFlag = True
Jeremyd9e4eb12016-04-13 12:09:06 -07001120 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001121
1122 # Check intents state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001123 if multiToSingleFailFlag:
1124 attempts = 5
1125 else:
1126 attempts = 50
1127
Jon Hallaf95c3e2017-05-16 13:20:37 -07001128 if utilities.retry( f=checkIntentState,
1129 retValue=main.FALSE,
Jon Hallf539eb92017-05-22 17:18:42 -07001130 args=( main, [ intentId ] ),
Jon Hallaf95c3e2017-05-16 13:20:37 -07001131 sleep=main.checkIntentSleep,
1132 attempts=attempts ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001133 main.assertReturnString += 'Install Intent State Passed\n'
Jon Hallf539eb92017-05-22 17:18:42 -07001134 if bandwidth != "":
1135 allocationsFile = open( os.path.dirname( main.testFile ) + main.params[ 'DEPENDENCY' ][ 'filePath' ], 'r' )
1136 expectedFormat = allocationsFile.read()
1137 bandwidthCheck = checkBandwidthAllocations( main, expectedFormat )
1138 allocationsFile.close()
1139 if bandwidthCheck:
1140 main.assertReturnString += 'Bandwidth Allocation check Passed\n'
1141 else:
1142 main.assertReturnString += 'Bandwidth Allocation check Failed\n'
Jon Hallc3f88af2017-05-23 11:25:54 -07001143 return main.FALSE
1144
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001145 if flowDuration( main ):
1146 main.assertReturnString += 'Flow duration check Passed\n'
1147 return intentId
1148 else:
1149 main.assertReturnString += 'Flow duration check failed\n'
1150 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001151 else:
1152 main.log.error( "Multi to Single Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001153 multiToSingleFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001154 return main.FALSE
1155
Jon Hall78be4962017-05-23 14:53:53 -07001156
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001157def testPointIntent( main,
Jeremye0cb5eb2016-01-27 17:39:09 -08001158 name,
1159 intentId,
1160 senders,
1161 recipients,
1162 badSenders={},
1163 badRecipients={},
1164 onosNode=0,
1165 ethType="",
1166 bandwidth="",
1167 lambdaAlloc=False,
alisonda157272016-12-22 01:13:21 -08001168 protected=False,
Jeremye0cb5eb2016-01-27 17:39:09 -08001169 ipProto="",
1170 ipAddresses="",
1171 tcp="",
1172 sw1="s5",
1173 sw2="s2",
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001174 expectedLink=0,
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001175 useTCP=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001176 """
1177 Test a Point Intent
1178
1179 Description:
1180 Test a point intent
1181
1182 Steps:
1183 - Fetch host data if not given
1184 - Check Intent State
1185 - Check Flow State
1186 - Check Connectivity
1187 - Check Lack of Connectivity Between Hosts not in the Intent
1188 - Reroute
1189 - Take Expected Link Down
1190 - Check Intent State
1191 - Check Flow State
1192 - Check Topology
1193 - Check Connectivity
1194 - Bring Expected Link Up
1195 - Check Intent State
1196 - Check Flow State
1197 - Check Topology
1198 - Check Connectivity
1199 - Remove Topology
1200
1201 Required:
1202 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
1203
1204 senders - List of host dictionaries i.e.
1205 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
1206 recipients - List of host dictionaries i.e.
1207 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
1208 Optional:
1209 onosNode - ONOS node to install the intents in main.CLIs[ ]
1210 0 by default so that it will always use the first
1211 ONOS node
1212 ethType - Ethernet type eg. IPV4, IPV6
1213 bandwidth - Bandwidth capacity
1214 lambdaAlloc - Allocate lambda, defaults to False
1215 ipProto - IP protocol
1216 tcp - TCP ports in the same order as the hosts in hostNames
1217 sw1 - First switch to bring down & up for rerouting purpose
1218 sw2 - Second switch to bring down & up for rerouting purpose
1219 expectedLink - Expected link when the switches are down, it should
1220 be two links lower than the links before the two
1221 switches are down
1222
1223 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001224 # Parameter Validity Check
1225 assert main, "There is no main variable"
1226 assert senders, "You must specify a sender"
1227 assert recipients, "You must specify a recipient"
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001228
1229 global itemName
1230 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001231
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001232 global pointIntentFailFlag
1233 global singleToMultiFailFlag
1234 global multiToSingleFailFlag
1235
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001236 main.log.info( itemName + ": Testing Point Intent" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001237
Jeremyd9e4eb12016-04-13 12:09:06 -07001238 try:
1239 # Names for scapy
1240 senderNames = [ x.get( "name" ) for x in senders ]
1241 recipientNames = [ x.get( "name" ) for x in recipients ]
1242 badSenderNames = [ x.get( "name" ) for x in badSenders ]
1243 badRecipientNames = [ x.get( "name" ) for x in badRecipients ]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001244
Jeremyd9e4eb12016-04-13 12:09:06 -07001245 for sender in senders:
1246 if not sender.get( "device" ):
1247 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1248 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001249
Jeremyd9e4eb12016-04-13 12:09:06 -07001250 for recipient in recipients:
1251 if not recipient.get( "device" ):
1252 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1253 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001254 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001255 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001256 main.log.error( "There was a problem loading the hosts data." )
1257 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001258
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001259 testResult = main.TRUE
1260 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001261
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001262 if pointIntentFailFlag or singleToMultiFailFlag or multiToSingleFailFlag:
1263 attempts = 1
1264 else:
1265 attempts = 50
1266
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001267 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001268 if utilities.retry( f=checkIntentState,
1269 retValue=main.FALSE,
1270 args=( main, [ intentId ] ),
1271 sleep=main.checkIntentSleep,
1272 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001273 main.assertReturnString += 'Initial Intent State Passed\n'
acsmarsd4862d12015-10-06 17:57:34 -07001274 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001275 main.assertReturnString += 'Initial Intent State Failed\n'
1276 testResult = main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001277 attempts = 1
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001278
1279 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001280 if utilities.retry( f=checkFlowsCount,
1281 retValue=main.FALSE,
1282 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001283 sleep=main.checkFlowCountSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001284 attempts=attempts ) and utilities.retry( f=checkFlowsState,
1285 retValue=main.FALSE,
1286 args=[ main ],
1287 sleep=main.checkFlowCountSleep,
1288 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001289 main.assertReturnString += 'Initial Flow State Passed\n'
1290 else:
1291 main.assertReturnString += 'Intial Flow State Failed\n'
1292 testResult = main.FALSE
1293
1294 # Check Connectivity
Jon Hallaf95c3e2017-05-16 13:20:37 -07001295 if utilities.retry( f=scapyCheckConnection,
1296 retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -07001297 args=( main, senderNames, recipientNames, vlanId, useTCP ),
Jon Hallaf95c3e2017-05-16 13:20:37 -07001298 attempts=attempts,
1299 sleep=main.checkConnectionSleep ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001300 main.assertReturnString += 'Initial Ping Passed\n'
1301 else:
1302 main.assertReturnString += 'Initial Ping Failed\n'
1303 testResult = main.FALSE
1304
1305 # Check connections that shouldn't work
1306 if badSenderNames:
1307 main.log.info( "Checking that packets from incorrect sender do not go through" )
Jon Hallaf95c3e2017-05-16 13:20:37 -07001308 if utilities.retry( f=scapyCheckConnection,
1309 retValue=main.FALSE,
1310 args=( main, badSenderNames, recipientNames ),
Jon Hall78be4962017-05-23 14:53:53 -07001311 kwargs={ "expectFailure": True } ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001312 main.assertReturnString += 'Bad Sender Ping Passed\n'
1313 else:
1314 main.assertReturnString += 'Bad Sender Ping Failed\n'
1315 testResult = main.FALSE
1316
1317 if badRecipientNames:
1318 main.log.info( "Checking that packets to incorrect recipients do not go through" )
Jon Hallaf95c3e2017-05-16 13:20:37 -07001319 if utilities.retry( f=scapyCheckConnection,
1320 retValue=main.FALSE,
1321 args=( main, senderNames, badRecipientNames ),
Jon Hall78be4962017-05-23 14:53:53 -07001322 kwargs={ "expectFailure": True } ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001323 main.assertReturnString += 'Bad Recipient Ping Passed\n'
1324 else:
1325 main.assertReturnString += 'Bad Recipient Ping Failed\n'
1326 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001327
1328 # Test rerouting if these variables exist
1329 if sw1 and sw2 and expectedLink:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001330 # Take link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001331 if utilities.retry( f=link,
1332 retValue=main.FALSE,
1333 args=( main, sw1, sw2, "down" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001334 main.assertReturnString += 'Link Down Passed\n'
1335 else:
1336 main.assertReturnString += 'Link Down Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001337 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001338
alisonda157272016-12-22 01:13:21 -08001339 if protected:
1340 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001341 if utilities.retry( f=scapyCheckConnection,
1342 retValue=main.FALSE,
1343 args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
alisonda157272016-12-22 01:13:21 -08001344 main.assertReturnString += 'Link down Scapy Packet Received Passed\n'
1345 else:
1346 main.assertReturnString += 'Link down Scapy Packet Recieved Failed\n'
1347 testResult = main.FALSE
1348
1349 if ProtectedIntentCheck( main ):
1350 main.assertReturnString += 'Protected Intent Check Passed\n'
1351 else:
1352 main.assertReturnString += 'Protected Intent Check Failed\n'
1353 testResult = main.FALSE
1354
acsmarsd4862d12015-10-06 17:57:34 -07001355 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001356 if utilities.retry( f=checkIntentState,
1357 retValue=main.FALSE,
1358 args=( main, [ intentId ] ),
1359 sleep=main.checkIntentPointSleep,
1360 attempts=attempts ):
acsmarsd4862d12015-10-06 17:57:34 -07001361 main.assertReturnString += 'Link Down Intent State Passed\n'
1362 else:
1363 main.assertReturnString += 'Link Down Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001364 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001365
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001366 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001367 if utilities.retry( f=checkFlowsCount,
1368 retValue=main.FALSE,
1369 args=[ main ],
1370 sleep=main.checkFlowCountSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001371 attempts=attempts ) and utilities.retry( f=checkFlowsState,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001372 retValue=main.FALSE,
1373 args=[ main ],
1374 sleep=main.checkFlowCountSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001375 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001376 main.assertReturnString += 'Link Down Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001377 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001378 main.assertReturnString += 'Link Down Flow State Failed\n'
1379 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001380
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001381 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001382 if utilities.retry( f=checkTopology,
1383 retValue=main.FALSE,
1384 args=( main, expectedLink ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001385 main.assertReturnString += 'Link Down Topology State Passed\n'
1386 else:
1387 main.assertReturnString += 'Link Down Topology State Failed\n'
1388 testResult = main.FALSE
1389
1390 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001391 if utilities.retry( f=scapyCheckConnection,
1392 retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -07001393 args=( main, senderNames, recipientNames, vlanId, useTCP ),
Jon Hallaf95c3e2017-05-16 13:20:37 -07001394 sleep=main.checkConnectionSleep,
1395 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001396 main.assertReturnString += 'Link Down Pingall Passed\n'
1397 else:
1398 main.assertReturnString += 'Link Down Pingall Failed\n'
1399 testResult = main.FALSE
1400
1401 # Bring link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001402 if utilities.retry( f=link,
1403 retValue=main.FALSE,
1404 args=( main, sw1, sw2, "up" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001405 main.assertReturnString += 'Link Up Passed\n'
1406 else:
1407 main.assertReturnString += 'Link Up Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001408 testResult = main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -07001409
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001410 # Wait for reroute
Jon Hallf539eb92017-05-22 17:18:42 -07001411 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001412 time.sleep( main.rerouteSleep )
1413
acsmarsd4862d12015-10-06 17:57:34 -07001414 # Check Intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001415 if utilities.retry( f=checkIntentState,
1416 retValue=main.FALSE,
1417 attempts=attempts * 2,
1418 args=( main, [ intentId ] ),
Shreyaca8990f2017-03-16 11:43:11 -07001419 sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001420 main.assertReturnString += 'Link Up Intent State Passed\n'
1421 else:
1422 main.assertReturnString += 'Link Up Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001423 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001424
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001425 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001426 if utilities.retry( f=checkFlowsCount,
1427 retValue=main.FALSE,
1428 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001429 sleep=main.checkFlowCountSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001430 attempts=attempts ) and utilities.retry( f=checkFlowsState,
1431 retValue=main.FALSE,
1432 args=[ main ],
1433 sleep=main.checkFlowCountSleep,
1434 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001435 main.assertReturnString += 'Link Up Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001436 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001437 main.assertReturnString += 'Link Up Flow State Failed\n'
1438 testResult = main.FALSE
1439
1440 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001441 if utilities.retry( f=checkTopology,
1442 retValue=main.FALSE,
1443 args=( main, main.numLinks ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001444 main.assertReturnString += 'Link Up Topology State Passed\n'
1445 else:
1446 main.assertReturnString += 'Link Up Topology State Failed\n'
1447 testResult = main.FALSE
1448
1449 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001450 if utilities.retry( f=scapyCheckConnection,
1451 retValue=main.FALSE,
1452 sleep=main.checkConnectionSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001453 attempts=attempts,
Shreyaca8990f2017-03-16 11:43:11 -07001454 args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001455 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1456 else:
1457 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1458 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001459
1460 # Remove all intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001461 if utilities.retry( f=removeAllIntents,
1462 retValue=main.FALSE,
1463 attempts=10,
1464 args=( main, [ intentId ] ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001465 main.assertReturnString += 'Remove Intents Passed'
1466 else:
1467 main.assertReturnString += 'Remove Intents Failed'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001468 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001469
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001470 return testResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001471
Jon Hall78be4962017-05-23 14:53:53 -07001472
Jeremye0cb5eb2016-01-27 17:39:09 -08001473def testEndPointFail( main,
1474 name,
1475 intentId,
1476 senders,
1477 recipients,
1478 isolatedSenders,
1479 isolatedRecipients,
1480 onosNode=0,
1481 ethType="",
1482 bandwidth="",
1483 lambdaAlloc=False,
1484 ipProto="",
1485 ipAddresses="",
1486 tcp="",
1487 sw1="",
1488 sw2="",
1489 sw3="",
1490 sw4="",
1491 sw5="",
1492 expectedLink1=0,
Jeremy Songster9385d412016-06-02 17:57:36 -07001493 expectedLink2=0,
1494 partial=False ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001495 """
Shreyaca8990f2017-03-16 11:43:11 -07001496 Test Multi point to single point intent Topology for Endpoint failures
Jeremye0cb5eb2016-01-27 17:39:09 -08001497 """
Jeremye0cb5eb2016-01-27 17:39:09 -08001498 # Parameter Validity Check
1499 assert main, "There is no main variable"
1500 assert senders, "You must specify a sender"
1501 assert recipients, "You must specify a recipient"
1502
1503 global itemName
1504 itemName = name
Jeremye0cb5eb2016-01-27 17:39:09 -08001505
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001506 global singleToMultiFailFlag
1507 global multiToSingleFailFlag
1508
Jeremye0cb5eb2016-01-27 17:39:09 -08001509 main.log.info( itemName + ": Testing Point Intent" )
1510
Jeremyd9e4eb12016-04-13 12:09:06 -07001511 try:
1512 # Names for scapy
1513 senderNames = [ x.get( "name" ) for x in senders ]
1514 recipientNames = [ x.get( "name" ) for x in recipients ]
1515 isolatedSenderNames = [ x.get( "name" ) for x in isolatedSenders ]
1516 isolatedRecipientNames = [ x.get( "name" ) for x in isolatedRecipients ]
Jon Hall78be4962017-05-23 14:53:53 -07001517 connectedSenderNames = [ x.get( "name" ) for x in senders if x.get( "name" ) not in isolatedSenderNames ]
1518 connectedRecipientNames = [ x.get( "name" ) for x in recipients if x.get( "name" ) not in isolatedRecipientNames ]
Jeremye0cb5eb2016-01-27 17:39:09 -08001519
Jeremyd9e4eb12016-04-13 12:09:06 -07001520 for sender in senders:
1521 if not sender.get( "device" ):
1522 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1523 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremye0cb5eb2016-01-27 17:39:09 -08001524
Jeremyd9e4eb12016-04-13 12:09:06 -07001525 for recipient in recipients:
1526 if not recipient.get( "device" ):
Jon Hall78be4962017-05-23 14:53:53 -07001527 main.log.warn( "Device not given for recipient {0}. Loading from " +
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001528 main.hostData.format( recipient.get( "name" ) ) )
Jeremyd9e4eb12016-04-13 12:09:06 -07001529 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001530 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001531 main.log.error( "There was a problem loading the hosts data." )
1532 return main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001533
1534 testResult = main.TRUE
1535 main.log.info( itemName + ": Adding multi point to single point intents" )
1536
1537 # Check intent state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001538 if singleToMultiFailFlag or multiToSingleFailFlag:
1539 attempts = 1
1540 else:
1541 attempts = 50
1542
Jon Hallaf95c3e2017-05-16 13:20:37 -07001543 if utilities.retry( f=checkIntentState,
1544 retValue=main.FALSE,
1545 args=( main, [ intentId ] ),
1546 sleep=main.checkIntentSleep,
1547 attempts=attempts ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001548 main.assertReturnString += 'Initial Intent State Passed\n'
1549 else:
1550 main.assertReturnString += 'Initial Intent State Failed\n'
1551 testResult = main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001552 attempts = 1
Jeremye0cb5eb2016-01-27 17:39:09 -08001553
1554 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001555 if utilities.retry( f=checkFlowsCount,
1556 retValue=main.FALSE,
1557 args=[ main ],
1558 attempts=5 ) and utilities.retry( f=checkFlowsState,
1559 retValue=main.FALSE,
1560 args=[ main ],
1561 attempts=5 ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001562 main.assertReturnString += 'Initial Flow State Passed\n'
1563 else:
1564 main.assertReturnString += 'Intial Flow State Failed\n'
1565 testResult = main.FALSE
1566
1567 # Check Connectivity
Jon Hallaf95c3e2017-05-16 13:20:37 -07001568 if utilities.retry( f=scapyCheckConnection,
1569 retValue=main.FALSE,
Jeremye0cb5eb2016-01-27 17:39:09 -08001570 args=( main, senderNames, recipientNames ) ):
1571 main.assertReturnString += 'Initial Connectivity Check Passed\n'
1572 else:
1573 main.assertReturnString += 'Initial Connectivity Check Failed\n'
1574 testResult = main.FALSE
1575
1576 # Take two links down
1577 # Take first link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001578 if utilities.retry( f=link,
1579 retValue=main.FALSE,
1580 args=( main, sw1, sw2, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001581 main.assertReturnString += 'Link Down Passed\n'
1582 else:
1583 main.assertReturnString += 'Link Down Failed\n'
1584 testResult = main.FALSE
1585
1586 # Take second link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001587 if utilities.retry( f=link,
1588 retValue=main.FALSE,
1589 args=( main, sw3, sw4, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001590 main.assertReturnString += 'Link Down Passed\n'
1591 else:
1592 main.assertReturnString += 'Link Down Failed\n'
1593 testResult = main.FALSE
1594
1595 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001596 if utilities.retry( f=checkIntentState,
1597 retValue=main.FALSE,
1598 attempts=attempts,
1599 args=( main, [ intentId ] ),
1600 sleep=main.checkIntentSleep ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001601 main.assertReturnString += 'Link Down Intent State Passed\n'
1602 else:
1603 main.assertReturnString += 'Link Down Intent State Failed\n'
1604 testResult = main.FALSE
1605
1606 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001607 if utilities.retry( f=checkFlowsCount,
1608 retValue=main.FALSE,
1609 sleep=1,
1610 attempts=attempts,
Jeremye0cb5eb2016-01-27 17:39:09 -08001611 args=[ main ] ) and utilities.retry( f=checkFlowsState,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001612 retValue=main.FALSE,
1613 sleep=1,
1614 attempts=attempts,
1615 args=[ main ] ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001616 main.assertReturnString += 'Link Down Flow State Passed\n'
1617 else:
1618 main.assertReturnString += 'Link Down Flow State Failed\n'
1619 testResult = main.FALSE
1620
1621 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001622 if utilities.retry( f=checkTopology,
1623 retValue=main.FALSE,
1624 args=( main, expectedLink1 ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001625 main.assertReturnString += 'Link Down Topology State Passed\n'
1626 else:
1627 main.assertReturnString += 'Link Down Topology State Failed\n'
1628 testResult = main.FALSE
1629
1630 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001631 if utilities.retry( f=scapyCheckConnection,
1632 retValue=main.FALSE,
Jeremye0cb5eb2016-01-27 17:39:09 -08001633 args=( main, senderNames, recipientNames ) ):
1634 main.assertReturnString += 'Link Down Connectivity Check Passed\n'
1635 else:
1636 main.assertReturnString += 'Link Down Connectivity Check Failed\n'
1637 testResult = main.FALSE
1638
1639 # Take a third link down to isolate one node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001640 if utilities.retry( f=link,
1641 retValue=main.FALSE,
1642 args=( main, sw3, sw5, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001643 main.assertReturnString += 'Isolation link Down Passed\n'
1644 else:
1645 main.assertReturnString += 'Isolation link Down Failed\n'
1646 testResult = main.FALSE
1647
Jeremy Songster9385d412016-06-02 17:57:36 -07001648 if partial:
1649 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001650 if utilities.retry( f=checkIntentState,
1651 retValue=main.FALSE,
1652 args=( main, [ intentId ] ),
1653 sleep=main.checkIntentSleep,
1654 attempts=attempts ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001655 main.assertReturnString += 'Partial failure isolation link Down Intent State Passed\n'
1656 else:
1657 main.assertReturnString += 'Partial failure isolation link Down Intent State Failed\n'
1658 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001659
Jeremy Songster9385d412016-06-02 17:57:36 -07001660 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001661 if utilities.retry( f=checkFlowsCount,
1662 retValue=main.FALSE,
1663 args=[ main ],
1664 attempts=5 ) and utilities.retry( f=checkFlowsState,
1665 retValue=main.FALSE,
1666 args=[ main ],
1667 attempts=5 ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001668 main.assertReturnString += 'Partial failure isolation link Down Flow State Passed\n'
1669 else:
1670 main.assertReturnString += 'Partial failure isolation link Down Flow State Failed\n'
1671 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001672
Jeremy Songster9385d412016-06-02 17:57:36 -07001673 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001674 if utilities.retry( f=checkTopology,
1675 retValue=main.FALSE,
1676 args=( main, expectedLink2 ) ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001677 main.assertReturnString += 'Partial failure isolation link Down Topology State Passed\n'
1678 else:
1679 main.assertReturnString += 'Partial failure isolation link Down Topology State Failed\n'
1680 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001681
Jeremy Songster9385d412016-06-02 17:57:36 -07001682 # Check Connectivity
1683 # First check connectivity of any isolated senders to recipients
1684 if isolatedSenderNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001685 if scapyCheckConnection( main,
1686 isolatedSenderNames,
1687 recipientNames,
1688 None,
1689 None,
1690 None,
1691 None,
1692 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001693 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1694 else:
1695 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1696 testResult = main.FALSE
1697
1698 # Next check connectivity of senders to any isolated recipients
1699 if isolatedRecipientNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001700 if scapyCheckConnection( main,
1701 senderNames,
1702 isolatedRecipientNames,
1703 None,
1704 None,
1705 None,
1706 None,
1707 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001708 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1709 else:
1710 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1711 testResult = main.FALSE
1712
1713 # Next check connectivity of connected senders and recipients
Jon Hallaf95c3e2017-05-16 13:20:37 -07001714 if utilities.retry( f=scapyCheckConnection,
1715 retValue=main.FALSE,
1716 attempts=attempts,
Jon Hall78be4962017-05-23 14:53:53 -07001717 args=( main, connectedSenderNames, connectedRecipientNames ) ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001718 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1719 else:
1720 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1721 testResult = main.FALSE
1722 else:
1723 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001724 if not utilities.retry( f=checkIntentState,
1725 retValue=main.TRUE,
1726 args=( main, [ intentId ] ),
1727 sleep=main.checkIntentSleep,
1728 attempts=attempts ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001729 main.assertReturnString += 'Isolation link Down Intent State Passed\n'
1730 else:
1731 main.assertReturnString += 'Isolation link Down Intent State Failed\n'
1732 testResult = main.FALSE
1733
1734 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001735 if utilities.retry( f=checkFlowsCount,
1736 retValue=main.FALSE,
1737 args=[ main ],
1738 attempts=5 ) and utilities.retry( f=checkFlowsState,
1739 retValue=main.FALSE,
1740 args=[ main ],
1741 attempts=5 ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001742 main.assertReturnString += 'Isolation link Down Flow State Passed\n'
1743 else:
1744 main.assertReturnString += 'Isolation link Down Flow State Failed\n'
1745 testResult = main.FALSE
1746
1747 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001748 if utilities.retry( f=checkTopology,
1749 retValue=main.FALSE,
1750 args=( main, expectedLink2 ) ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001751 main.assertReturnString += 'Isolation link Down Topology State Passed\n'
1752 else:
1753 main.assertReturnString += 'Isolation link Down Topology State Failed\n'
1754 testResult = main.FALSE
1755
1756 # Check Connectivity
1757 # First check connectivity of any isolated senders to recipients
1758 if isolatedSenderNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001759 if scapyCheckConnection( main,
1760 isolatedSenderNames,
1761 recipientNames,
1762 None,
1763 None,
1764 None,
1765 None,
1766 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001767 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1768 else:
1769 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1770 testResult = main.FALSE
1771
1772 # Next check connectivity of senders to any isolated recipients
1773 if isolatedRecipientNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001774 if scapyCheckConnection( main,
1775 senderNames,
1776 isolatedRecipientNames,
1777 None,
1778 None,
1779 None,
1780 None,
1781 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001782 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1783 else:
1784 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1785 testResult = main.FALSE
1786
1787 # Next check connectivity of connected senders and recipients
Jon Hallaf95c3e2017-05-16 13:20:37 -07001788 if utilities.retry( f=scapyCheckConnection,
1789 retValue=main.TRUE,
1790 args=( main, connectedSenderNames, connectedRecipientNames, None, None, None, None, main.TRUE ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001791 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1792 else:
1793 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1794 testResult = main.FALSE
1795
Jeremye0cb5eb2016-01-27 17:39:09 -08001796 # Bring the links back up
1797 # Bring first link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001798 if utilities.retry( f=link,
1799 retValue=main.FALSE,
1800 args=( main, sw1, sw2, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001801 main.assertReturnString += 'Link Up Passed\n'
1802 else:
1803 main.assertReturnString += 'Link Up Failed\n'
1804 testResult = main.FALSE
1805
1806 # Bring second link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001807 if utilities.retry( f=link,
1808 retValue=main.FALSE,
1809 args=( main, sw3, sw5, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001810 main.assertReturnString += 'Link Up Passed\n'
1811 else:
1812 main.assertReturnString += 'Link Up Failed\n'
1813 testResult = main.FALSE
1814
1815 # Bring third link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001816 if utilities.retry( f=link,
1817 retValue=main.FALSE,
1818 args=( main, sw3, sw4, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001819 main.assertReturnString += 'Link Up Passed\n'
1820 else:
1821 main.assertReturnString += 'Link Up Failed\n'
1822 testResult = main.FALSE
1823
1824 # Wait for reroute
Jon Hallf539eb92017-05-22 17:18:42 -07001825 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
Jeremye0cb5eb2016-01-27 17:39:09 -08001826 time.sleep( main.rerouteSleep )
1827
1828 # Check Intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001829 if utilities.retry( f=checkIntentState,
1830 retValue=main.FALSE,
1831 attempts=attempts,
1832 args=( main, [ intentId ] ),
1833 sleep=main.checkIntentHostSleep ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001834 main.assertReturnString += 'Link Up Intent State Passed\n'
1835 else:
1836 main.assertReturnString += 'Link Up Intent State Failed\n'
1837 testResult = main.FALSE
1838
1839 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001840 if utilities.retry( f=checkFlowsCount,
1841 retValue=main.FALSE,
1842 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001843 sleep=main.checkFlowCountSleep,
1844 attempts=attempts ) and utilities.retry( f=checkFlowsState,
Jon Hall78be4962017-05-23 14:53:53 -07001845 retValue=main.FALSE,
1846 args=[ main ],
1847 sleep=main.checkFlowCountSleep,
1848 attempts=attempts ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001849 main.assertReturnString += 'Link Up Flow State Passed\n'
1850 else:
1851 main.assertReturnString += 'Link Up Flow State Failed\n'
1852 testResult = main.FALSE
1853
1854 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001855 if utilities.retry( f=checkTopology,
1856 retValue=main.FALSE,
1857 args=( main, main.numLinks ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001858 main.assertReturnString += 'Link Up Topology State Passed\n'
1859 else:
1860 main.assertReturnString += 'Link Up Topology State Failed\n'
1861 testResult = main.FALSE
1862
1863 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001864 if utilities.retry( f=scapyCheckConnection,
1865 retValue=main.FALSE,
1866 sleep=main.checkConnectionSleep,
1867 attempts=attempts,
Jeremye0cb5eb2016-01-27 17:39:09 -08001868 args=( main, senderNames, recipientNames ) ):
1869 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1870 else:
1871 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1872 testResult = main.FALSE
1873
1874 # Remove all intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001875 if utilities.retry( f=removeAllIntents,
1876 retValue=main.FALSE,
1877 attempts=10,
1878 args=( main, [ intentId ] ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001879 main.assertReturnString += 'Remove Intents Passed'
1880 else:
1881 main.assertReturnString += 'Remove Intents Failed'
1882 testResult = main.FALSE
1883
1884 return testResult
1885
1886
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001887def pingallHosts( main, hostList ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001888 """
1889 Ping all host in the hosts list variable
1890 """
Jon Halla5cb3412015-08-18 14:08:22 -07001891 main.log.info( "Pinging: " + str( hostList ) )
1892 return main.Mininet1.pingallHosts( hostList )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001893
Jon Hall78be4962017-05-23 14:53:53 -07001894
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001895def fwdPingall( main ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001896 """
1897 Use fwd app and pingall to discover all the hosts
1898 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001899 appCheck = main.TRUE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001900 main.log.info( "Activating reactive forwarding app " )
1901 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001902
1903 # Wait for forward app activation to propagate
Jon Hallf539eb92017-05-22 17:18:42 -07001904 main.log.info( "Sleeping {} seconds".format( main.fwdSleep ) )
kelvin-onlab0ad05d12015-07-23 14:21:15 -07001905 time.sleep( main.fwdSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001906
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001907 # Check that forwarding is enabled on all nodes
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001908 for i in range( main.numCtrls ):
1909 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
1910 if appCheck != main.TRUE:
1911 main.log.warn( main.CLIs[ i ].apps() )
1912 main.log.warn( main.CLIs[ i ].appIDs() )
1913
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001914 # Send pingall in mininet
1915 main.log.info( "Run Pingall" )
Jon Hall78be4962017-05-23 14:53:53 -07001916 pingResult = main.Mininet1.pingall( timeout=600 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001917
1918 main.log.info( "Deactivating reactive forwarding app " )
1919 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001920 if activateResult and deactivateResult:
1921 main.log.info( "Successfully used fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001922 getDataResult = main.TRUE
1923 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001924 main.log.info( "Failed to use fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001925 getDataResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001926 return getDataResult
1927
Jon Hall78be4962017-05-23 14:53:53 -07001928
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001929def confirmHostDiscovery( main ):
1930 """
1931 Confirms that all ONOS nodes have discovered all scapy hosts
1932 """
1933 import collections
Devin Lim58046fa2017-07-05 16:55:00 -07001934 try:
1935 from tests.dependencies.topology import Topology
1936 except Exception:
1937 main.log.error( "Topology not found exiting the test" )
1938 main.exit()
1939 try:
1940 main.topoRelated
1941 except Exception:
1942 main.topoRelated = Topology()
1943 hosts = main.topoRelated.getAllHosts( main.numCtrls, False ) # Get host data from each ONOS node
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001944 hostFails = [] # Reset for each failed attempt
1945
1946 # Check for matching hosts on each node
1947 scapyHostIPs = [ x.hostIp for x in main.scapyHosts if x.hostIp != "0.0.0.0" ]
1948 for controller in range( main.numCtrls ):
1949 controllerStr = str( controller + 1 ) # ONOS node number
1950 # Compare Hosts
1951 # Load hosts data for controller node
Jeremyd9e4eb12016-04-13 12:09:06 -07001952 try:
1953 if hosts[ controller ]:
1954 main.log.info( "Hosts discovered" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001955 else:
Jeremyd9e4eb12016-04-13 12:09:06 -07001956 main.log.error( "Problem discovering hosts" )
1957 if hosts[ controller ] and "Error" not in hosts[ controller ]:
1958 try:
1959 hostData = json.loads( hosts[ controller ] )
1960 except ( TypeError, ValueError ):
1961 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001962 hostFails.append( controllerStr )
Jeremyd9e4eb12016-04-13 12:09:06 -07001963 else:
1964 onosHostIPs = [ x.get( "ipAddresses" )[ 0 ]
1965 for x in hostData
1966 if len( x.get( "ipAddresses" ) ) > 0 ]
Jon Hall78be4962017-05-23 14:53:53 -07001967 if not set( collections.Counter( scapyHostIPs ) ).issubset(
1968 set( collections.Counter( onosHostIPs ) ) ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001969 main.log.warn( "Controller {0} only sees nodes with {1} IPs. It should see all of the following: {2}".format( controllerStr, onosHostIPs, scapyHostIPs ) )
1970 hostFails.append( controllerStr )
1971 else:
1972 main.log.error( "Hosts returned nothing or an error." )
1973 hostFails.append( controllerStr )
1974 except IndexError:
1975 main.log.error( "Hosts returned nothing, Failed to discover hosts." )
1976 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001977
1978 if hostFails:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001979 main.log.error( "List of failed ONOS Nodes:" + ', '.join( map( str, hostFails ) ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001980 return main.FALSE
1981 else:
1982 return main.TRUE
1983
Jon Hall78be4962017-05-23 14:53:53 -07001984
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001985def sendDiscoveryArp( main, hosts=None ):
1986 """
1987 Sends Discovery ARP packets from each host provided
1988 Defaults to each host in main.scapyHosts
1989 """
1990 # Send an arp ping from each host
1991 if not hosts:
1992 hosts = main.scapyHosts
1993 for host in hosts:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001994 pkt = 'Ether( src="{0}")/ARP( psrc="{1}")'.format( host.hostMac, host.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001995 # Send from the VLAN interface if there is one so ONOS discovers the VLAN correctly
1996 iface = None
1997 for interface in host.getIfList():
1998 if '.' in interface:
1999 main.log.debug( "Detected VLAN interface {0}. Sending ARP packet from {0}".format( interface ) )
2000 iface = interface
2001 break
2002 host.sendPacket( packet=pkt, iface=iface )
2003 main.log.info( "Sending ARP packet from {0}".format( host.name ) )
2004
Jon Hall78be4962017-05-23 14:53:53 -07002005
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002006def populateHostData( main ):
2007 """
2008 Populates hostsData
2009 """
2010 import json
2011 try:
2012 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
2013 hosts = main.Mininet1.getHosts().keys()
2014 # TODO: Make better use of new getHosts function
2015 for host in hosts:
2016 main.hostsData[ host ] = {}
2017 main.hostsData[ host ][ 'mac' ] = \
2018 main.Mininet1.getMacAddress( host ).upper()
2019 for hostj in hostsJson:
2020 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
2021 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
2022 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
2023 main.hostsData[ host ][ 'location' ] = \
Jeremy Ronquillo0e538bc2017-06-13 15:16:09 -07002024 hostj[ 'locations' ][ 0 ][ 'elementId' ] + '/' + \
2025 hostj[ 'locations' ][ 0 ][ 'port' ]
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002026 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
2027 return main.TRUE
Jeremyd9e4eb12016-04-13 12:09:06 -07002028 except ValueError:
2029 main.log.error( "ValueError while populating hostsData" )
2030 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002031 except KeyError:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002032 main.log.error( "KeyError while populating hostsData" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002033 return main.FALSE
Jeremyd9e4eb12016-04-13 12:09:06 -07002034 except IndexError:
2035 main.log.error( "IndexError while populating hostsData" )
2036 return main.FALSE
2037 except TypeError:
2038 main.log.error( "TypeError while populating hostsData" )
2039 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002040
Jon Hall78be4962017-05-23 14:53:53 -07002041
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002042def checkTopology( main, expectedLink ):
2043 statusResult = main.TRUE
2044 # Check onos topology
2045 main.log.info( itemName + ": Checking ONOS topology " )
2046
2047 for i in range( main.numCtrls ):
Flavio Castro82ee2f62016-06-07 15:04:12 -07002048 statusResult = main.CLIs[ i ].checkStatus( main.numSwitch,
Jon Hallaf95c3e2017-05-16 13:20:37 -07002049 expectedLink ) and statusResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002050 if not statusResult:
2051 main.log.error( itemName + ": Topology mismatch" )
2052 else:
2053 main.log.info( itemName + ": Topology match" )
2054 return statusResult
2055
Jon Hall78be4962017-05-23 14:53:53 -07002056
Jon Hallf539eb92017-05-22 17:18:42 -07002057def checkIntentState( main, intentsId ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002058 """
2059 This function will check intent state to make sure all the intents
2060 are in INSTALLED state
Jon Hallf539eb92017-05-22 17:18:42 -07002061 Returns main.TRUE or main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002062 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002063 intentResult = main.TRUE
Jon Hallf539eb92017-05-22 17:18:42 -07002064 stateCheckResults = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002065 for i in range( main.numCtrls ):
Jon Hallf539eb92017-05-22 17:18:42 -07002066 output = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
2067 stateCheckResults.append( output )
2068 if all( result == main.TRUE for result in stateCheckResults ):
2069 main.log.info( itemName + ": Intents state check passed" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002070 else:
Jon Hallf539eb92017-05-22 17:18:42 -07002071 main.log.warn( "Intents state check failed" )
Shreyaca8990f2017-03-16 11:43:11 -07002072 intentResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002073 return intentResult
2074
Jon Hall78be4962017-05-23 14:53:53 -07002075
Jon Hallf539eb92017-05-22 17:18:42 -07002076def checkBandwidthAllocations( main, bandwidth ):
2077 """
2078 Compare the given bandwith allocation output to the cli output on each node
2079 Returns main.TRUE or main.FALSE
2080 """
2081 bandwidthResults = []
2082 for i in range( main.numCtrls ):
2083 output = main.CLIs[ i ].compareBandwidthAllocations( bandwidth )
2084 bandwidthResults.append( output )
2085 if all( result == main.TRUE for result in bandwidthResults ):
2086 main.log.info( itemName + ": bandwidth check passed" )
2087 bandwidthResult = main.TRUE
2088 else:
2089 main.log.warn( itemName + ": bandwidth check failed" )
2090 bandwidthResult = main.FALSE
2091 return bandwidthResult
2092
Jon Hall78be4962017-05-23 14:53:53 -07002093
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002094def checkFlowsState( main ):
2095
2096 main.log.info( itemName + ": Check flows state" )
Jeremy Songsterff553672016-05-12 17:06:23 -07002097 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState( isPENDING=False )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002098 return checkFlowsResult
2099
Jon Hall78be4962017-05-23 14:53:53 -07002100
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002101def link( main, sw1, sw2, option ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002102
2103 # link down
alison52b25892016-09-19 10:53:48 -07002104 main.log.info( itemName + ": Bring link " + option + " between " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002105 sw1 + " and " + sw2 )
2106 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
2107 return linkResult
2108
Jon Hall78be4962017-05-23 14:53:53 -07002109
Jon Hallaf95c3e2017-05-16 13:20:37 -07002110def scapyCheckConnection( main,
2111 senders,
2112 recipients,
2113 vlanId=None,
2114 useTCP=False,
2115 packet=None,
2116 packetFilter=None,
2117 expectFailure=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002118 """
2119 Checks the connectivity between all given sender hosts and all given recipient hosts
2120 Packet may be specified. Defaults to Ether/IP packet
2121 Packet Filter may be specified. Defaults to Ether/IP from current sender MAC
2122 Todo: Optional packet and packet filter attributes for sender and recipients
2123 Expect Failure when the sender and recipient are not supposed to have connectivity
2124 Timeout of 1 second, returns main.TRUE if the filter is not triggered and kills the filter
2125
2126 """
2127 connectionsFunctional = main.TRUE
2128
2129 if not packetFilter:
2130 packetFilter = 'ether host {}'
Jeremy Songstere405d3d2016-05-17 11:18:57 -07002131 if useTCP:
Jon Hall78be4962017-05-23 14:53:53 -07002132 packetFilter += ' ip proto \\tcp tcp port {}'.format( main.params[ 'SDNIP' ][ 'dstPort' ] )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002133 if expectFailure:
2134 timeout = 1
2135 else:
2136 timeout = 10
2137
2138 for sender in senders:
2139 try:
2140 senderComp = getattr( main, sender )
2141 except AttributeError:
2142 main.log.error( "main has no attribute {}".format( sender ) )
2143 connectionsFunctional = main.FALSE
2144 continue
2145
2146 for recipient in recipients:
2147 # Do not send packets to self since recipient CLI will already be busy
2148 if recipient == sender:
2149 continue
2150 try:
2151 recipientComp = getattr( main, recipient )
2152 except AttributeError:
2153 main.log.error( "main has no attribute {}".format( recipient ) )
2154 connectionsFunctional = main.FALSE
2155 continue
2156
Jeremy Songster832f9e92016-05-05 14:30:49 -07002157 if vlanId:
Jon Hall78be4962017-05-23 14:53:53 -07002158 recipientComp.startFilter( pktFilter=( "vlan {}".format( vlanId ) + " && " + packetFilter.format( senderComp.hostMac ) ) )
Jeremy Songster832f9e92016-05-05 14:30:49 -07002159 else:
Jon Hall78be4962017-05-23 14:53:53 -07002160 recipientComp.startFilter( pktFilter=packetFilter.format( senderComp.hostMac ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002161
2162 if not packet:
Jeremy Songster832f9e92016-05-05 14:30:49 -07002163 if vlanId:
2164 pkt = 'Ether( src="{0}", dst="{2}" )/Dot1Q(vlan={4})/IP( src="{1}", dst="{3}" )'.format(
2165 senderComp.hostMac,
2166 senderComp.hostIp,
2167 recipientComp.hostMac,
2168 recipientComp.hostIp,
2169 vlanId )
2170 else:
2171 pkt = 'Ether( src="{0}", dst="{2}" )/IP( src="{1}", dst="{3}" )'.format(
2172 senderComp.hostMac,
2173 senderComp.hostIp,
2174 recipientComp.hostMac,
2175 recipientComp.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002176 else:
2177 pkt = packet
Jeremy Songster832f9e92016-05-05 14:30:49 -07002178 if vlanId:
2179 senderComp.sendPacket( iface=( "{0}-eth0.{1}".format( sender, vlanId ) ), packet = pkt )
2180 else:
Jon Hall78be4962017-05-23 14:53:53 -07002181 senderComp.sendPacket( packet=pkt )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002182
2183 if recipientComp.checkFilter( timeout ):
2184 if expectFailure:
Jon Hall78be4962017-05-23 14:53:53 -07002185 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 -08002186 connectionsFunctional = main.FALSE
2187 else:
Jon Hall78be4962017-05-23 14:53:53 -07002188 main.log.info( "Packet from {0} successfully received by {1}".format( sender, recipient ) )
alison52b25892016-09-19 10:53:48 -07002189 connectionsFunctional = main.TRUE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002190 else:
2191 recipientComp.killFilter()
2192 if expectFailure:
Jon Hall78be4962017-05-23 14:53:53 -07002193 main.log.info( "As expected, packet from {0} was not received by {1}".format( sender, recipient ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002194 else:
Jon Hall78be4962017-05-23 14:53:53 -07002195 main.log.error( "Packet from {0} was not received by {1}".format( sender, recipient ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002196 connectionsFunctional = main.FALSE
2197
2198 return connectionsFunctional
2199
alison52b25892016-09-19 10:53:48 -07002200
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002201def removeAllIntents( main, intentsId ):
2202 """
2203 Remove all intents in the intentsId
2204 """
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002205 onosSummary = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002206 removeIntentResult = main.TRUE
2207 # Remove intents
2208 for intent in intentsId:
2209 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
2210
Jon Hallf539eb92017-05-22 17:18:42 -07002211 main.log.info( "Sleeping {} seconds".format( main.removeIntentSleep ) )
acsmarscfa52272015-08-06 15:21:45 -07002212 time.sleep( main.removeIntentSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002213
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002214 # If there is remianing intents then remove intents should fail
2215 for i in range( main.numCtrls ):
2216 onosSummary.append( json.loads( main.CLIs[ i ].summary() ) )
2217
2218 for summary in onosSummary:
2219 if summary.get( 'intents' ) != 0:
2220 main.log.warn( itemName + ": There are " +
2221 str( summary.get( 'intents' ) ) +
2222 " intents remaining in node " +
2223 str( summary.get( 'node' ) ) +
2224 ", failed to remove all the intents " )
2225 removeIntentResult = main.FALSE
2226
2227 if removeIntentResult:
2228 main.log.info( itemName + ": There are no more intents remaining, " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002229 "successfully removed all the intents." )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002230
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002231 return removeIntentResult
2232
Jon Hall78be4962017-05-23 14:53:53 -07002233
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002234def checkFlowsCount( main ):
2235 """
2236 Check flows count in each node
2237 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002238 flowsCount = []
2239 main.log.info( itemName + ": Checking flows count in each ONOS node" )
2240 for i in range( main.numCtrls ):
2241 summaryResult = main.CLIs[ i ].summary()
2242 if not summaryResult:
2243 main.log.error( itemName + ": There is something wrong with " +
2244 "summary command" )
2245 return main.FALSE
2246 else:
2247 summaryJson = json.loads( summaryResult )
2248 flowsCount.append( summaryJson.get( 'flows' ) )
2249
2250 if flowsCount:
Jon Hall78be4962017-05-23 14:53:53 -07002251 if all( flows == flowsCount[ 0 ] for flows in flowsCount ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002252 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
2253 " flows in all ONOS node" )
2254 else:
2255 for i in range( main.numCtrls ):
2256 main.log.debug( itemName + ": ONOS node " + str( i ) + " has " +
kelvin-onlab6dea6e62015-07-23 13:07:26 -07002257 str( flowsCount[ i ] ) + " flows" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002258 else:
2259 main.log.error( "Checking flows count failed, check summary command" )
2260 return main.FALSE
2261
2262 return main.TRUE
2263
Jon Hall78be4962017-05-23 14:53:53 -07002264
kelvin-onlab58dc39e2015-08-06 08:11:09 -07002265def checkLeaderChange( leaders1, leaders2 ):
acsmarse6b410f2015-07-17 14:39:34 -07002266 """
2267 Checks for a change in intent partition leadership.
2268
2269 Takes the output of leaders -c in json string format before and after
2270 a potential change as input
2271
2272 Returns main.TRUE if no mismatches are detected
2273 Returns main.FALSE if there is a mismatch or on error loading the input
2274 """
2275 try:
2276 leaders1 = json.loads( leaders1 )
2277 leaders2 = json.loads( leaders2 )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002278 except( AttributeError, TypeError ):
Jon Halld970abf2017-05-23 10:20:28 -07002279 main.log.exception( "checkLeaderChange: Object not as expected" )
acsmarse6b410f2015-07-17 14:39:34 -07002280 return main.FALSE
2281 except Exception:
Jon Halld970abf2017-05-23 10:20:28 -07002282 main.log.exception( "checkLeaderChange: Uncaught exception!" )
acsmarse6b410f2015-07-17 14:39:34 -07002283 main.cleanup()
2284 main.exit()
2285 main.log.info( "Checking Intent Paritions for Change in Leadership" )
2286 mismatch = False
2287 for dict1 in leaders1:
2288 if "intent" in dict1.get( "topic", [] ):
2289 for dict2 in leaders2:
Jon Hall78be4962017-05-23 14:53:53 -07002290 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and\
2291 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
acsmarse6b410f2015-07-17 14:39:34 -07002292 mismatch = True
Jon Hall78be4962017-05-23 14:53:53 -07002293 main.log.error( "%s changed leader from %s to %s",
2294 dict1.get( "topic", "no-topic" ),
2295 dict1.get( "leader", "no-leader" ),
2296 dict2.get( "leader", "no-leader" ) )
acsmarse6b410f2015-07-17 14:39:34 -07002297 if mismatch:
2298 return main.FALSE
2299 else:
2300 return main.TRUE
kelvin-onlab016dce22015-08-10 09:54:11 -07002301
Jon Hall78be4962017-05-23 14:53:53 -07002302
kelvin-onlab016dce22015-08-10 09:54:11 -07002303def report( main ):
2304 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002305 Report errors/warnings/exceptions
kelvin-onlab016dce22015-08-10 09:54:11 -07002306 """
kelvin-onlab016dce22015-08-10 09:54:11 -07002307 main.ONOSbench.logReport( main.ONOSip[ 0 ],
2308 [ "INFO",
2309 "FOLLOWER",
2310 "WARN",
2311 "flow",
2312 "ERROR",
2313 "Except" ],
2314 "s" )
2315
2316 main.log.info( "ERROR report: \n" )
2317 for i in range( main.numCtrls ):
2318 main.ONOSbench.logReport( main.ONOSip[ i ],
Jon Hall78be4962017-05-23 14:53:53 -07002319 [ "ERROR" ],
2320 "d" )
kelvin-onlab016dce22015-08-10 09:54:11 -07002321
2322 main.log.info( "EXCEPTIONS report: \n" )
2323 for i in range( main.numCtrls ):
2324 main.ONOSbench.logReport( main.ONOSip[ i ],
Jon Hall78be4962017-05-23 14:53:53 -07002325 [ "Except" ],
2326 "d" )
kelvin-onlab016dce22015-08-10 09:54:11 -07002327
2328 main.log.info( "WARNING report: \n" )
2329 for i in range( main.numCtrls ):
2330 main.ONOSbench.logReport( main.ONOSip[ i ],
Jon Hall78be4962017-05-23 14:53:53 -07002331 [ "WARN" ],
2332 "d" )
2333
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002334
2335def flowDuration( main ):
2336 """
2337 Check age of flows to see if flows are being overwritten
2338 """
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002339 main.log.info( "Getting current flow durations" )
2340 flowsJson1 = main.CLIs[ 0 ].flows( noCore=True )
2341 try:
2342 flowsJson1 = json.loads( flowsJson1 )
2343 except ValueError:
2344 main.log.error( "Unable to read flows" )
2345 return main.FALSE
2346 flowLife = []
2347 waitFlowLife = []
2348 for device in flowsJson1:
2349 if device.get( 'flowcount', 0 ) > 0:
2350 for i in range( device[ 'flowCount' ] ):
2351 flowLife.append( device[ 'flows' ][ i ][ 'life' ] )
2352 main.log.info( "Sleeping for {} seconds".format( main.flowDurationSleep ) )
2353 time.sleep( main.flowDurationSleep )
2354 main.log.info( "Getting new flow durations" )
2355 flowsJson2 = main.CLIs[ 0 ].flows( noCore=True )
2356 try:
2357 flowsJson2 = json.loads( flowsJson2 )
2358 except ValueError:
2359 main.log.error( "Unable to read flows" )
2360 return main.FALSE
2361 for device in flowsJson2:
2362 if device.get( 'flowcount', 0 ) > 0:
2363 for i in range( device[ 'flowCount' ] ):
2364 waitFlowLife.append( device[ 'flows' ][ i ][ 'life' ] )
2365 main.log.info( "Determining whether flows where overwritten" )
2366 if len( flowLife ) == len( waitFlowLife ):
alison52b25892016-09-19 10:53:48 -07002367 for i in range( len( flowLife ) ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002368 if waitFlowLife[ i ] - flowLife[ i ] < main.flowDurationSleep:
2369 return main.FALSE
2370 else:
2371 return main.FALSE
2372 return main.TRUE
alison52b25892016-09-19 10:53:48 -07002373
2374
2375def EncapsulatedIntentCheck( main, tag="" ):
2376 """
2377 Check encapsulated intents
Jon Hall78be4962017-05-23 14:53:53 -07002378 tag: encapsulation tag ( e.g. VLAN, MPLS )
alison52b25892016-09-19 10:53:48 -07002379
2380 Getting added flows
2381 Check tags on each flows
2382 If each direction has push or pop, passed
2383 else failed
2384
2385 """
alison52b25892016-09-19 10:53:48 -07002386 HostJson = []
2387 Jflows = main.CLIs[ 0 ].flows( noCore=True )
2388 try:
2389 Jflows = json.loads( Jflows )
2390 except ValueError:
2391 main.log.error( "Unable to read flows" )
2392 return main.FALSE
2393
2394 for flow in Jflows:
Jon Hall78be4962017-05-23 14:53:53 -07002395 if len( flow[ "flows" ] ) != 0:
alison52b25892016-09-19 10:53:48 -07002396 HostJson.append( flow[ "flows" ] )
2397
Jon Hall78be4962017-05-23 14:53:53 -07002398 totalflows = len( HostJson[ 0 ] )
alison52b25892016-09-19 10:53:48 -07002399
2400 pop = 0
2401 push = 0
2402
2403 PopTag = tag + "_POP"
2404 PushTag = tag + "_PUSH"
2405
2406 for EachHostJson in HostJson:
2407 for i in range( totalflows ):
2408 if EachHostJson[ i ][ "treatment" ][ "instructions" ][ 0 ][ "subtype" ] == PopTag:
2409 pop += 1
2410 elif EachHostJson[ i ][ "treatment" ][ "instructions" ][ 0 ][ "subtype" ] == PushTag:
2411 push += 1
2412
2413 if pop == totalflows and push == totalflows:
2414 return main.TRUE
2415 else:
alisonda157272016-12-22 01:13:21 -08002416 return main.FALSE
2417
Jon Hall78be4962017-05-23 14:53:53 -07002418
alisonda157272016-12-22 01:13:21 -08002419def ProtectedIntentCheck( main ):
alisonda157272016-12-22 01:13:21 -08002420 intent = main.CLIs[ 0 ].intents( jsonFormat=False )
2421 if "Protection" in intent:
2422 return main.TRUE
Shreyaca8990f2017-03-16 11:43:11 -07002423 return main.FALSE