blob: 7418965c6987d6154fc8ea718a38521794892fda [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" )
Devin Lim142b5342017-07-20 15:22:39 -0700109 intentId = main.Cluster.active( onosNode ).CLI.addHostIntent( hostIdOne=host1.get( "id" ),
110 hostIdTwo=host2.get( "id" ),
111 vlanId=vlanId,
112 setVlan=setVlan,
113 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700114 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700115 errorMsg = "There was a problem loading the hosts data."
116 if intentId:
117 errorMsg += " There was a problem installing host to host intent."
118 main.log.error( errorMsg )
119 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800120
121 # Check intents state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700122 if utilities.retry( f=checkIntentState,
123 retValue=main.FALSE,
Jon Hallf539eb92017-05-22 17:18:42 -0700124 args=( main, [ intentId ] ),
Jon Hallaf95c3e2017-05-16 13:20:37 -0700125 sleep=main.checkIntentSleep,
126 attempts=50 ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700127 main.assertReturnString += 'Install Intent State Passed\n'
alison52b25892016-09-19 10:53:48 -0700128
Jon Hall78be4962017-05-23 14:53:53 -0700129 # Check VLAN if test encapsulation
alison52b25892016-09-19 10:53:48 -0700130 if encap != "":
131 if EncapsulatedIntentCheck( main, tag=encap ):
132 main.assertReturnString += 'Encapsulation intents check Passed\n'
133 else:
134 main.assertReturnString += 'Encapsulation intents check failed\n'
Jon Hallf539eb92017-05-22 17:18:42 -0700135 if bandwidth != "":
136 allocationsFile = open( os.path.dirname( main.testFile ) + main.params[ 'DEPENDENCY' ][ 'filePath' ], 'r' )
137 expectedFormat = allocationsFile.read()
138 bandwidthCheck = checkBandwidthAllocations( main, expectedFormat )
139 allocationsFile.close()
140 if bandwidthCheck:
141 main.assertReturnString += 'Bandwidth Allocation check Passed\n'
142 else:
143 main.assertReturnString += 'Bandwidth Allocation check Failed\n'
Jon Hallc3f88af2017-05-23 11:25:54 -0700144 return main.FALSE
Jon Hallf539eb92017-05-22 17:18:42 -0700145
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700146 if flowDuration( main ):
147 main.assertReturnString += 'Flow duration check Passed\n'
148 return intentId
149 else:
Jon Hallf539eb92017-05-22 17:18:42 -0700150 main.assertReturnString += 'Flow duration check Failed\n'
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700151 return main.FALSE
alison52b25892016-09-19 10:53:48 -0700152
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800153 else:
Jeremy2f190ca2016-01-29 15:23:57 -0800154 main.log.error( "Host Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700155 hostIntentFailFlag = True
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700156 main.assertReturnString += 'Install Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800157 return main.FALSE
158
Jon Hall78be4962017-05-23 14:53:53 -0700159
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800160def testHostIntent( main,
161 name,
162 intentId,
163 host1,
164 host2,
165 onosNode=0,
166 sw1="s5",
167 sw2="s2",
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700168 expectedLink=0 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800169 """
170 Test a Host Intent
171
172 Description:
173 Test a host intent of given ID between given hosts
174
175 Steps:
176 - Fetch host data if not given
177 - Check Intent State
178 - Check Flow State
179 - Check Connectivity
180 - Check Lack of Connectivity Between Hosts not in the Intent
181 - Reroute
182 - Take Expected Link Down
183 - Check Intent State
184 - Check Flow State
185 - Check Topology
186 - Check Connectivity
187 - Bring Expected Link Up
188 - Check Intent State
189 - Check Flow State
190 - Check Topology
191 - Check Connectivity
192 - Remove Topology
193
194 Required:
195 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
196 intentId - intent ID to be tested ( and removed )
197 host1 - Dictionary for host1
198 { "name":"h8", "id":"of:0000000000000005/8" }
199 host2 - Dictionary for host2
200 { "name":"h16", "id":"of:0000000000000006/8" }
201 Optional:
202 onosNode - ONOS node to install the intents in main.CLIs[ ]
203 0 by default so that it will always use the first
204 ONOS node
205 sw1 - First switch to bring down & up for rerouting purpose
206 sw2 - Second switch to bring down & up for rerouting purpose
207 expectedLink - Expected link when the switches are down, it should
208 be two links lower than the links before the two
209 switches are down
210
211 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800212 # Parameter Validity Check
213 assert main, "There is no main variable"
214 assert host1, "You must specify host1"
215 assert host2, "You must specify host2"
216
217 global itemName
218 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800219
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700220 global hostIntentFailFlag
221
Jeremy2f190ca2016-01-29 15:23:57 -0800222 main.log.info( itemName + ": Testing Host Intent" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800223
Jeremyd9e4eb12016-04-13 12:09:06 -0700224 try:
225 if not host1.get( "id" ):
226 main.log.warn( "Id not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
227 host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800228
Jeremyd9e4eb12016-04-13 12:09:06 -0700229 if not host2.get( "id" ):
230 main.log.warn( "Id not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
231 host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800232
Jeremyd9e4eb12016-04-13 12:09:06 -0700233 senderNames = [ host1.get( "name" ), host2.get( "name" ) ]
234 recipientNames = [ host1.get( "name" ), host2.get( "name" ) ]
Jeremy Songster832f9e92016-05-05 14:30:49 -0700235 vlanId = host1.get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800236
Jeremyd9e4eb12016-04-13 12:09:06 -0700237 testResult = main.TRUE
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700238 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700239 main.log.error( "There was a problem loading the hosts data." )
240 return main.FALSE
241
242 main.log.info( itemName + ": Testing Host to Host intents" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800243
244 # Check intent state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700245 if hostIntentFailFlag:
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
Devin Lim142b5342017-07-20 15:22:39 -0700502 intentId = main.Cluster.active( onosNode ).CLI.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,
511 protected=protected,
512 ipProto=ipProto,
513 ipSrc=ipSrc,
514 ipDst=ipDst,
515 tcpSrc=tcpSrc,
516 tcpDst=tcpDst,
517 vlanId=vlanId,
518 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" )
Devin Lim142b5342017-07-20 15:22:39 -0700652 ctrl = main.Cluster.active( onosNode )
653 intent1 = ctrl.CLI.addPointIntent( ingressDevice=deviceId1,
654 egressDevice=deviceId2,
655 portIngress=port1,
656 portEgress=port2,
657 ethType=ethType,
658 ethSrc=mac1,
659 ethDst=mac2,
660 bandwidth=bandwidth,
661 lambdaAlloc=lambdaAlloc,
662 ipProto=ipProto,
663 ipSrc=ip1,
664 ipDst=ip2,
665 tcpSrc=tcp1,
666 tcpDst="" )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700667
Devin Lim142b5342017-07-20 15:22:39 -0700668 intent2 = ctrl.CLI.addPointIntent( ingressDevice=deviceId2,
669 egressDevice=deviceId1,
670 portIngress=port2,
671 portEgress=port1,
672 ethType=ethType,
673 ethSrc=mac2,
674 ethDst=mac1,
675 bandwidth=bandwidth,
676 lambdaAlloc=lambdaAlloc,
677 ipProto=ipProto,
678 ipSrc=ip2,
679 ipDst=ip1,
680 tcpSrc=tcp2,
681 tcpDst="" )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700682
Devin Lim142b5342017-07-20 15:22:39 -0700683 intent3 = ctrl.CLI.addPointIntent( ingressDevice=deviceId1,
684 egressDevice=deviceId2,
685 portIngress=port1,
686 portEgress=port2,
687 ethType=ethType,
688 ethSrc=mac1,
689 ethDst=mac2,
690 bandwidth=bandwidth,
691 lambdaAlloc=lambdaAlloc,
692 ipProto=ipProto,
693 ipSrc=ip1,
694 ipDst=ip2,
695 tcpSrc="",
696 tcpDst=tcp2 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700697
Devin Lim142b5342017-07-20 15:22:39 -0700698 intent4 = ctrl.CLI.addPointIntent( ingressDevice=deviceId2,
699 egressDevice=deviceId1,
700 portIngress=port2,
701 portEgress=port1,
702 ethType=ethType,
703 ethSrc=mac2,
704 ethDst=mac1,
705 bandwidth=bandwidth,
706 lambdaAlloc=lambdaAlloc,
707 ipProto=ipProto,
708 ipSrc=ip2,
709 ipDst=ip1,
710 tcpSrc="",
711 tcpDst=tcp1 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700712 intentsId.append( intent1 )
713 intentsId.append( intent2 )
714 intentsId.append( intent3 )
715 intentsId.append( intent4 )
716
717 # Check intents state
Jon Hallf539eb92017-05-22 17:18:42 -0700718 main.log.info( "Sleeping {} seconds".format( main.checkIntentSleep ) )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700719 time.sleep( main.checkIntentSleep )
Jon Hallaf95c3e2017-05-16 13:20:37 -0700720 intentResult = utilities.retry( f=checkIntentState,
721 retValue=main.FALSE,
722 args=( main, intentsId ),
723 sleep=1,
724 attempts=50 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700725 # Check flows count in each node
726 checkFlowsCount( main )
727
728 # Check intents state again if first check fails...
729 if not intentResult:
Jon Hallaf95c3e2017-05-16 13:20:37 -0700730 intentResult = utilities.retry( f=checkIntentState,
731 retValue=main.FALSE,
732 args=( main, intentsId ),
733 sleep=1,
734 attempts=50 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700735
736 # Check flows count in each node
737 checkFlowsCount( main )
738
739 # Verify flows
740 checkFlowsState( main )
741
742 # Run iperf to both host
Jon Hall78be4962017-05-23 14:53:53 -0700743 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700744 iperfResult = iperfResult and iperfTemp
745 if iperfTemp:
746 main.assertReturnString += 'Initial Iperf Passed\n'
747 else:
748 main.assertReturnString += 'Initial Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700749
750 # Test rerouting if these variables exist
751 if sw1 and sw2 and expectedLink:
752 # link down
753 linkDownResult = link( main, sw1, sw2, "down" )
acsmarsd4862d12015-10-06 17:57:34 -0700754
755 if linkDownResult:
756 main.assertReturnString += 'Link Down Passed\n'
757 else:
758 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700759
760 # Check flows count in each node
761 checkFlowsCount( main )
762 # Verify flows
763 checkFlowsState( main )
764
765 # Check OnosTopology
766 topoResult = checkTopology( main, expectedLink )
acsmarsd4862d12015-10-06 17:57:34 -0700767 if topoResult:
768 main.assertReturnString += 'Link Down Topology State Passed\n'
769 else:
770 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700771
772 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700773 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700774 iperfResult = iperfResult and iperfTemp
775 if iperfTemp:
776 main.assertReturnString += 'Link Down Iperf Passed\n'
777 else:
778 main.assertReturnString += 'Link Down Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700779
acsmarsd4862d12015-10-06 17:57:34 -0700780 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700781 intentTemp = utilities.retry( f=checkIntentState,
782 retValue=main.FALSE,
783 args=( main, intentsId ),
784 sleep=1,
785 attempts=50 )
acsmarsd4862d12015-10-06 17:57:34 -0700786 intentResult = intentResult and intentTemp
787 if intentTemp:
788 main.assertReturnString += 'Link Down Intent State Passed\n'
789 else:
790 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700791
792 # Checks ONOS state in link down
793 if linkDownResult and topoResult and iperfResult and intentResult:
794 main.log.info( itemName + ": Successfully brought link down" )
795 else:
796 main.log.error( itemName + ": Failed to bring link down" )
797
798 # link up
799 linkUpResult = link( main, sw1, sw2, "up" )
alison52b25892016-09-19 10:53:48 -0700800 if linkUpResult:
acsmarsd4862d12015-10-06 17:57:34 -0700801 main.assertReturnString += 'Link Up Passed\n'
802 else:
803 main.assertReturnString += 'Link Up Failed\n'
804
Jon Hallf539eb92017-05-22 17:18:42 -0700805 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700806 time.sleep( main.rerouteSleep )
807
808 # Check flows count in each node
809 checkFlowsCount( main )
810 # Verify flows
811 checkFlowsState( main )
812
813 # Check OnosTopology
814 topoResult = checkTopology( main, main.numLinks )
815
acsmarsd4862d12015-10-06 17:57:34 -0700816 if topoResult:
817 main.assertReturnString += 'Link Up Topology State Passed\n'
818 else:
819 main.assertReturnString += 'Link Up Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700820
acsmarsd4862d12015-10-06 17:57:34 -0700821 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700822 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700823 iperfResult = iperfResult and iperfTemp
824 if iperfTemp:
825 main.assertReturnString += 'Link Up Iperf Passed\n'
826 else:
827 main.assertReturnString += 'Link Up Iperf Failed\n'
828
829 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -0700830 intentTemp = utilities.retry( f=checkIntentState,
831 retValue=main.FALSE,
832 args=( main, intentsId ),
833 sleep=1,
834 attempts=50 )
acsmarsd4862d12015-10-06 17:57:34 -0700835 intentResult = intentResult and intentTemp
836 if intentTemp:
837 main.assertReturnString += 'Link Down Intent State Passed\n'
838 else:
839 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700840
841 # Checks ONOS state in link up
842 if linkUpResult and topoResult and iperfResult and intentResult:
843 main.log.info( itemName + ": Successfully brought link back up" )
844 else:
845 main.log.error( itemName + ": Failed to bring link back up" )
846
847 # Remove all intents
848 removeIntentResult = removeAllIntents( main, intentsId )
acsmarsd4862d12015-10-06 17:57:34 -0700849 if removeIntentResult:
850 main.assertReturnString += 'Remove Intents Passed'
851 else:
852 main.assertReturnString += 'Remove Intents Failed'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700853
854 stepResult = iperfResult and linkDownResult and linkUpResult \
855 and intentResult and removeIntentResult
856
857 return stepResult
858
Jon Hall78be4962017-05-23 14:53:53 -0700859
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800860def installSingleToMultiIntent( main,
861 name,
862 senders,
863 recipients,
864 onosNode=0,
865 ethType="",
866 bandwidth="",
867 lambdaAlloc=False,
868 ipProto="",
869 ipAddresses="",
870 tcp="",
871 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700872 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -0700873 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700874 partial=False,
Jon Hallf539eb92017-05-22 17:18:42 -0700875 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700876 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800877 Installs a Single to Multi Point Intent
878
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700879 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800880 Install a single to multi point intent using
881 add-single-to-multi-intent
882
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700883 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800884 - Fetch host data if not given
885 - Add single to multi intent
886 - Ingress device is the first sender host
887 - Egress devices are the recipient devices
888 - Ports if defined in senders or recipients
889 - MAC address ethSrc loaded from Ingress device
890 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700891 Required:
892 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800893 senders - List of host dictionaries i.e.
894 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
895 recipients - List of host dictionaries i.e.
896 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700897 Optional:
898 onosNode - ONOS node to install the intents in main.CLIs[ ]
899 0 by default so that it will always use the first
900 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700901 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700902 bandwidth - Bandwidth capacity
903 lambdaAlloc - Allocate lambda, defaults to False
904 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700905 tcp - TCP ports in the same order as the hosts in hostNames
906 sw1 - First switch to bring down & up for rerouting purpose
907 sw2 - Second switch to bring down & up for rerouting purpose
908 expectedLink - Expected link when the switches are down, it should
909 be two links lower than the links before the two
910 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700911 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700912 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800913 assert senders, "You must specify a sender"
914 assert recipients, "You must specify a recipient"
915 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700916
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800917 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700918 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700919
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700920 global singleToMultiFailFlag
921 singleToMultiFailFlag = False
922
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700923 main.log.info( itemName + ": Adding single point to multi point intents" )
924
Jeremyd9e4eb12016-04-13 12:09:06 -0700925 try:
926 for sender in senders:
927 if not sender.get( "device" ):
928 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
929 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700930
Jeremyd9e4eb12016-04-13 12:09:06 -0700931 for recipient in recipients:
932 if not recipient.get( "device" ):
933 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
934 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700935
Jeremyd9e4eb12016-04-13 12:09:06 -0700936 ingressDevice = senders[ 0 ].get( "device" )
937 egressDeviceList = [ x.get( "device" ) for x in recipients if x.get( "device" ) ]
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800938
Jeremyd9e4eb12016-04-13 12:09:06 -0700939 portIngress = senders[ 0 ].get( "port", "" )
940 portEgressList = [ x.get( "port" ) for x in recipients if x.get( "port" ) ]
941 if not portEgressList:
942 portEgressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800943
Jeremyd9e4eb12016-04-13 12:09:06 -0700944 srcMac = senders[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700945 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800946
Jeremyd9e4eb12016-04-13 12:09:06 -0700947 # Adding point intent
Devin Lim142b5342017-07-20 15:22:39 -0700948 intentId = main.Cluster.active( onosNode ).CLI.addSinglepointToMultipointIntent(
949 ingressDevice=ingressDevice,
950 egressDeviceList=egressDeviceList,
951 portIngress=portIngress,
952 portEgressList=portEgressList,
953 ethType=ethType,
954 ethSrc=srcMac,
955 bandwidth=bandwidth,
956 lambdaAlloc=lambdaAlloc,
957 ipProto=ipProto,
958 ipSrc="",
959 ipDst="",
960 tcpSrc="",
961 tcpDst="",
962 vlanId=vlanId,
963 setVlan=setVlan,
964 partial=partial,
965 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700966 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700967 errorMsg = "There was a problem loading the hosts data."
968 if intentId:
969 errorMsg += " There was a problem installing Singlepoint to Multipoint intent."
970 main.log.error( errorMsg )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700971 singleToMultiFailFlag = True
Jeremyd9e4eb12016-04-13 12:09:06 -0700972 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700973
974 # Check intents state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700975 if singleToMultiFailFlag:
976 attempts = 5
977 else:
978 attempts = 50
979
Jon Hallaf95c3e2017-05-16 13:20:37 -0700980 if utilities.retry( f=checkIntentState,
981 retValue=main.FALSE,
Jon Hallf539eb92017-05-22 17:18:42 -0700982 args=( main, [ intentId ] ),
Jon Hallaf95c3e2017-05-16 13:20:37 -0700983 sleep=main.checkIntentSleep,
984 attempts=attempts ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700985 main.assertReturnString += 'Install Intent State Passed\n'
Jon Hallf539eb92017-05-22 17:18:42 -0700986 if bandwidth != "":
987 allocationsFile = open( os.path.dirname( main.testFile ) + main.params[ 'DEPENDENCY' ][ 'filePath' ], 'r' )
988 expectedFormat = allocationsFile.read()
989 bandwidthCheck = checkBandwidthAllocations( main, expectedFormat )
990 allocationsFile.close()
991 if bandwidthCheck:
992 main.assertReturnString += 'Bandwidth Allocation check Passed\n'
993 else:
994 main.assertReturnString += 'Bandwidth Allocation check Failed\n'
Jon Hallc3f88af2017-05-23 11:25:54 -0700995 return main.FALSE
996
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700997 if flowDuration( main ):
998 main.assertReturnString += 'Flow duration check Passed\n'
999 return intentId
1000 else:
1001 main.assertReturnString += 'Flow duration check failed\n'
1002 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -07001003 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001004 main.log.error( "Single to Multi Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001005 singleToMultiFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001006 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001007
Jon Hall78be4962017-05-23 14:53:53 -07001008
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001009def installMultiToSingleIntent( main,
1010 name,
1011 senders,
1012 recipients,
1013 onosNode=0,
1014 ethType="",
1015 bandwidth="",
1016 lambdaAlloc=False,
1017 ipProto="",
1018 ipAddresses="",
1019 tcp="",
1020 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -07001021 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -07001022 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -07001023 partial=False,
Jon Hallf539eb92017-05-22 17:18:42 -07001024 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001025 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001026 Installs a Multi to Single Point Intent
1027
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001028 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001029 Install a multi to single point intent using
1030 add-multi-to-single-intent
1031
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001032 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001033 - Fetch host data if not given
1034 - Add multi to single intent
1035 - Ingress devices are the senders devices
1036 - Egress device is the first recipient host
1037 - Ports if defined in senders or recipients
1038 - MAC address ethSrc loaded from Ingress device
1039 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001040 Required:
1041 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001042 senders - List of host dictionaries i.e.
1043 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
1044 recipients - List of host dictionaries i.e.
1045 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001046 Optional:
1047 onosNode - ONOS node to install the intents in main.CLIs[ ]
1048 0 by default so that it will always use the first
1049 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001050 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001051 bandwidth - Bandwidth capacity
1052 lambdaAlloc - Allocate lambda, defaults to False
1053 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001054 tcp - TCP ports in the same order as the hosts in hostNames
1055 sw1 - First switch to bring down & up for rerouting purpose
1056 sw2 - Second switch to bring down & up for rerouting purpose
1057 expectedLink - Expected link when the switches are down, it should
1058 be two links lower than the links before the two
1059 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001060 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001061 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001062 assert senders, "You must specify a sender"
1063 assert recipients, "You must specify a recipient"
1064 # Assert devices or main.hostsData, "You must specify devices"
1065
1066 global itemName # The name of this run. Used for logs.
1067 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001068
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001069 global multiToSingleFailFlag
1070 multiToSingleFailFlag = False
1071
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001072 main.log.info( itemName + ": Adding mutli to single point intents" )
1073
Jeremyd9e4eb12016-04-13 12:09:06 -07001074 try:
1075 for sender in senders:
1076 if not sender.get( "device" ):
1077 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1078 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001079
Jeremyd9e4eb12016-04-13 12:09:06 -07001080 for recipient in recipients:
1081 if not recipient.get( "device" ):
1082 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1083 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001084
Jeremyd9e4eb12016-04-13 12:09:06 -07001085 ingressDeviceList = [ x.get( "device" ) for x in senders if x.get( "device" ) ]
1086 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001087
Jeremyd9e4eb12016-04-13 12:09:06 -07001088 portIngressList = [ x.get( "port" ) for x in senders if x.get( "port" ) ]
1089 portEgress = recipients[ 0 ].get( "port", "" )
1090 if not portIngressList:
1091 portIngressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001092
Jeremyd9e4eb12016-04-13 12:09:06 -07001093 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001094 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001095
Jeremyd9e4eb12016-04-13 12:09:06 -07001096 # Adding point intent
Devin Lim142b5342017-07-20 15:22:39 -07001097 intentId = main.Cluster.active( onosNode ).CLI.addMultipointToSinglepointIntent(
1098 ingressDeviceList=ingressDeviceList,
1099 egressDevice=egressDevice,
1100 portIngressList=portIngressList,
1101 portEgress=portEgress,
1102 ethType=ethType,
1103 ethDst=dstMac,
1104 bandwidth=bandwidth,
1105 lambdaAlloc=lambdaAlloc,
1106 ipProto=ipProto,
1107 ipSrc="",
1108 ipDst="",
1109 tcpSrc="",
1110 tcpDst="",
1111 vlanId=vlanId,
1112 setVlan=setVlan,
1113 partial=partial,
1114 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001115 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001116 errorMsg = "There was a problem loading the hosts data."
1117 if intentId:
1118 errorMsg += " There was a problem installing Multipoint to Singlepoint intent."
1119 main.log.error( errorMsg )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001120 multiToSingleFailFlag = True
Jeremyd9e4eb12016-04-13 12:09:06 -07001121 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001122
1123 # Check intents state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001124 if multiToSingleFailFlag:
1125 attempts = 5
1126 else:
1127 attempts = 50
1128
Jon Hallaf95c3e2017-05-16 13:20:37 -07001129 if utilities.retry( f=checkIntentState,
1130 retValue=main.FALSE,
Jon Hallf539eb92017-05-22 17:18:42 -07001131 args=( main, [ intentId ] ),
Jon Hallaf95c3e2017-05-16 13:20:37 -07001132 sleep=main.checkIntentSleep,
1133 attempts=attempts ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001134 main.assertReturnString += 'Install Intent State Passed\n'
Jon Hallf539eb92017-05-22 17:18:42 -07001135 if bandwidth != "":
1136 allocationsFile = open( os.path.dirname( main.testFile ) + main.params[ 'DEPENDENCY' ][ 'filePath' ], 'r' )
1137 expectedFormat = allocationsFile.read()
1138 bandwidthCheck = checkBandwidthAllocations( main, expectedFormat )
1139 allocationsFile.close()
1140 if bandwidthCheck:
1141 main.assertReturnString += 'Bandwidth Allocation check Passed\n'
1142 else:
1143 main.assertReturnString += 'Bandwidth Allocation check Failed\n'
Jon Hallc3f88af2017-05-23 11:25:54 -07001144 return main.FALSE
1145
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001146 if flowDuration( main ):
1147 main.assertReturnString += 'Flow duration check Passed\n'
1148 return intentId
1149 else:
1150 main.assertReturnString += 'Flow duration check failed\n'
1151 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001152 else:
1153 main.log.error( "Multi to Single Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001154 multiToSingleFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001155 return main.FALSE
1156
Jon Hall78be4962017-05-23 14:53:53 -07001157
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001158def testPointIntent( main,
Jeremye0cb5eb2016-01-27 17:39:09 -08001159 name,
1160 intentId,
1161 senders,
1162 recipients,
1163 badSenders={},
1164 badRecipients={},
1165 onosNode=0,
1166 ethType="",
1167 bandwidth="",
1168 lambdaAlloc=False,
alisonda157272016-12-22 01:13:21 -08001169 protected=False,
Jeremye0cb5eb2016-01-27 17:39:09 -08001170 ipProto="",
1171 ipAddresses="",
1172 tcp="",
1173 sw1="s5",
1174 sw2="s2",
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001175 expectedLink=0,
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001176 useTCP=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001177 """
1178 Test a Point Intent
1179
1180 Description:
1181 Test a point intent
1182
1183 Steps:
1184 - Fetch host data if not given
1185 - Check Intent State
1186 - Check Flow State
1187 - Check Connectivity
1188 - Check Lack of Connectivity Between Hosts not in the Intent
1189 - Reroute
1190 - Take Expected Link Down
1191 - Check Intent State
1192 - Check Flow State
1193 - Check Topology
1194 - Check Connectivity
1195 - Bring Expected Link Up
1196 - Check Intent State
1197 - Check Flow State
1198 - Check Topology
1199 - Check Connectivity
1200 - Remove Topology
1201
1202 Required:
1203 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
1204
1205 senders - List of host dictionaries i.e.
1206 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
1207 recipients - List of host dictionaries i.e.
1208 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
1209 Optional:
1210 onosNode - ONOS node to install the intents in main.CLIs[ ]
1211 0 by default so that it will always use the first
1212 ONOS node
1213 ethType - Ethernet type eg. IPV4, IPV6
1214 bandwidth - Bandwidth capacity
1215 lambdaAlloc - Allocate lambda, defaults to False
1216 ipProto - IP protocol
1217 tcp - TCP ports in the same order as the hosts in hostNames
1218 sw1 - First switch to bring down & up for rerouting purpose
1219 sw2 - Second switch to bring down & up for rerouting purpose
1220 expectedLink - Expected link when the switches are down, it should
1221 be two links lower than the links before the two
1222 switches are down
1223
1224 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001225 # Parameter Validity Check
1226 assert main, "There is no main variable"
1227 assert senders, "You must specify a sender"
1228 assert recipients, "You must specify a recipient"
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001229
1230 global itemName
1231 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001232
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001233 global pointIntentFailFlag
1234 global singleToMultiFailFlag
1235 global multiToSingleFailFlag
1236
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001237 main.log.info( itemName + ": Testing Point Intent" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001238
Jeremyd9e4eb12016-04-13 12:09:06 -07001239 try:
1240 # Names for scapy
1241 senderNames = [ x.get( "name" ) for x in senders ]
1242 recipientNames = [ x.get( "name" ) for x in recipients ]
1243 badSenderNames = [ x.get( "name" ) for x in badSenders ]
1244 badRecipientNames = [ x.get( "name" ) for x in badRecipients ]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001245
Jeremyd9e4eb12016-04-13 12:09:06 -07001246 for sender in senders:
1247 if not sender.get( "device" ):
1248 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1249 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001250
Jeremyd9e4eb12016-04-13 12:09:06 -07001251 for recipient in recipients:
1252 if not recipient.get( "device" ):
1253 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1254 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001255 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001256 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001257 main.log.error( "There was a problem loading the hosts data." )
1258 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001259
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001260 testResult = main.TRUE
1261 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001262
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001263 if pointIntentFailFlag or singleToMultiFailFlag or multiToSingleFailFlag:
1264 attempts = 1
1265 else:
1266 attempts = 50
1267
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001268 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001269 if utilities.retry( f=checkIntentState,
1270 retValue=main.FALSE,
1271 args=( main, [ intentId ] ),
1272 sleep=main.checkIntentSleep,
1273 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001274 main.assertReturnString += 'Initial Intent State Passed\n'
acsmarsd4862d12015-10-06 17:57:34 -07001275 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001276 main.assertReturnString += 'Initial Intent State Failed\n'
1277 testResult = main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001278 attempts = 1
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001279
1280 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001281 if utilities.retry( f=checkFlowsCount,
1282 retValue=main.FALSE,
1283 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001284 sleep=main.checkFlowCountSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001285 attempts=attempts ) and utilities.retry( f=checkFlowsState,
1286 retValue=main.FALSE,
1287 args=[ main ],
1288 sleep=main.checkFlowCountSleep,
1289 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001290 main.assertReturnString += 'Initial Flow State Passed\n'
1291 else:
1292 main.assertReturnString += 'Intial Flow State Failed\n'
1293 testResult = main.FALSE
1294
1295 # Check Connectivity
Jon Hallaf95c3e2017-05-16 13:20:37 -07001296 if utilities.retry( f=scapyCheckConnection,
1297 retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -07001298 args=( main, senderNames, recipientNames, vlanId, useTCP ),
Jon Hallaf95c3e2017-05-16 13:20:37 -07001299 attempts=attempts,
1300 sleep=main.checkConnectionSleep ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001301 main.assertReturnString += 'Initial Ping Passed\n'
1302 else:
1303 main.assertReturnString += 'Initial Ping Failed\n'
1304 testResult = main.FALSE
1305
1306 # Check connections that shouldn't work
1307 if badSenderNames:
1308 main.log.info( "Checking that packets from incorrect sender do not go through" )
Jon Hallaf95c3e2017-05-16 13:20:37 -07001309 if utilities.retry( f=scapyCheckConnection,
1310 retValue=main.FALSE,
1311 args=( main, badSenderNames, recipientNames ),
Jon Hall78be4962017-05-23 14:53:53 -07001312 kwargs={ "expectFailure": True } ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001313 main.assertReturnString += 'Bad Sender Ping Passed\n'
1314 else:
1315 main.assertReturnString += 'Bad Sender Ping Failed\n'
1316 testResult = main.FALSE
1317
1318 if badRecipientNames:
1319 main.log.info( "Checking that packets to incorrect recipients do not go through" )
Jon Hallaf95c3e2017-05-16 13:20:37 -07001320 if utilities.retry( f=scapyCheckConnection,
1321 retValue=main.FALSE,
1322 args=( main, senderNames, badRecipientNames ),
Jon Hall78be4962017-05-23 14:53:53 -07001323 kwargs={ "expectFailure": True } ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001324 main.assertReturnString += 'Bad Recipient Ping Passed\n'
1325 else:
1326 main.assertReturnString += 'Bad Recipient Ping Failed\n'
1327 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001328
1329 # Test rerouting if these variables exist
1330 if sw1 and sw2 and expectedLink:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001331 # Take link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001332 if utilities.retry( f=link,
1333 retValue=main.FALSE,
1334 args=( main, sw1, sw2, "down" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001335 main.assertReturnString += 'Link Down Passed\n'
1336 else:
1337 main.assertReturnString += 'Link Down Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001338 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001339
alisonda157272016-12-22 01:13:21 -08001340 if protected:
1341 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001342 if utilities.retry( f=scapyCheckConnection,
1343 retValue=main.FALSE,
1344 args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
alisonda157272016-12-22 01:13:21 -08001345 main.assertReturnString += 'Link down Scapy Packet Received Passed\n'
1346 else:
1347 main.assertReturnString += 'Link down Scapy Packet Recieved Failed\n'
1348 testResult = main.FALSE
1349
1350 if ProtectedIntentCheck( main ):
1351 main.assertReturnString += 'Protected Intent Check Passed\n'
1352 else:
1353 main.assertReturnString += 'Protected Intent Check Failed\n'
1354 testResult = main.FALSE
1355
acsmarsd4862d12015-10-06 17:57:34 -07001356 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001357 if utilities.retry( f=checkIntentState,
1358 retValue=main.FALSE,
1359 args=( main, [ intentId ] ),
1360 sleep=main.checkIntentPointSleep,
1361 attempts=attempts ):
acsmarsd4862d12015-10-06 17:57:34 -07001362 main.assertReturnString += 'Link Down Intent State Passed\n'
1363 else:
1364 main.assertReturnString += 'Link Down Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001365 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001366
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001367 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001368 if utilities.retry( f=checkFlowsCount,
1369 retValue=main.FALSE,
1370 args=[ main ],
1371 sleep=main.checkFlowCountSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001372 attempts=attempts ) and utilities.retry( f=checkFlowsState,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001373 retValue=main.FALSE,
1374 args=[ main ],
1375 sleep=main.checkFlowCountSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001376 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001377 main.assertReturnString += 'Link Down Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001378 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001379 main.assertReturnString += 'Link Down Flow State Failed\n'
1380 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001381
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001382 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001383 if utilities.retry( f=checkTopology,
1384 retValue=main.FALSE,
1385 args=( main, expectedLink ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001386 main.assertReturnString += 'Link Down Topology State Passed\n'
1387 else:
1388 main.assertReturnString += 'Link Down Topology State Failed\n'
1389 testResult = main.FALSE
1390
1391 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001392 if utilities.retry( f=scapyCheckConnection,
1393 retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -07001394 args=( main, senderNames, recipientNames, vlanId, useTCP ),
Jon Hallaf95c3e2017-05-16 13:20:37 -07001395 sleep=main.checkConnectionSleep,
1396 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001397 main.assertReturnString += 'Link Down Pingall Passed\n'
1398 else:
1399 main.assertReturnString += 'Link Down Pingall Failed\n'
1400 testResult = main.FALSE
1401
1402 # Bring link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001403 if utilities.retry( f=link,
1404 retValue=main.FALSE,
1405 args=( main, sw1, sw2, "up" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001406 main.assertReturnString += 'Link Up Passed\n'
1407 else:
1408 main.assertReturnString += 'Link Up Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001409 testResult = main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -07001410
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001411 # Wait for reroute
Jon Hallf539eb92017-05-22 17:18:42 -07001412 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001413 time.sleep( main.rerouteSleep )
1414
acsmarsd4862d12015-10-06 17:57:34 -07001415 # Check Intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001416 if utilities.retry( f=checkIntentState,
1417 retValue=main.FALSE,
1418 attempts=attempts * 2,
1419 args=( main, [ intentId ] ),
Shreyaca8990f2017-03-16 11:43:11 -07001420 sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001421 main.assertReturnString += 'Link Up Intent State Passed\n'
1422 else:
1423 main.assertReturnString += 'Link Up Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001424 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001425
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001426 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001427 if utilities.retry( f=checkFlowsCount,
1428 retValue=main.FALSE,
1429 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001430 sleep=main.checkFlowCountSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001431 attempts=attempts ) and utilities.retry( f=checkFlowsState,
1432 retValue=main.FALSE,
1433 args=[ main ],
1434 sleep=main.checkFlowCountSleep,
1435 attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001436 main.assertReturnString += 'Link Up Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001437 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001438 main.assertReturnString += 'Link Up Flow State Failed\n'
1439 testResult = main.FALSE
1440
1441 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001442 if utilities.retry( f=checkTopology,
1443 retValue=main.FALSE,
1444 args=( main, main.numLinks ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001445 main.assertReturnString += 'Link Up Topology State Passed\n'
1446 else:
1447 main.assertReturnString += 'Link Up Topology State Failed\n'
1448 testResult = main.FALSE
1449
1450 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001451 if utilities.retry( f=scapyCheckConnection,
1452 retValue=main.FALSE,
1453 sleep=main.checkConnectionSleep,
Jon Hall78be4962017-05-23 14:53:53 -07001454 attempts=attempts,
Shreyaca8990f2017-03-16 11:43:11 -07001455 args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001456 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1457 else:
1458 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1459 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001460
1461 # Remove all intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001462 if utilities.retry( f=removeAllIntents,
1463 retValue=main.FALSE,
1464 attempts=10,
1465 args=( main, [ intentId ] ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001466 main.assertReturnString += 'Remove Intents Passed'
1467 else:
1468 main.assertReturnString += 'Remove Intents Failed'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001469 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001470
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001471 return testResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001472
Jon Hall78be4962017-05-23 14:53:53 -07001473
Jeremye0cb5eb2016-01-27 17:39:09 -08001474def testEndPointFail( main,
1475 name,
1476 intentId,
1477 senders,
1478 recipients,
1479 isolatedSenders,
1480 isolatedRecipients,
1481 onosNode=0,
1482 ethType="",
1483 bandwidth="",
1484 lambdaAlloc=False,
1485 ipProto="",
1486 ipAddresses="",
1487 tcp="",
1488 sw1="",
1489 sw2="",
1490 sw3="",
1491 sw4="",
1492 sw5="",
1493 expectedLink1=0,
Jeremy Songster9385d412016-06-02 17:57:36 -07001494 expectedLink2=0,
1495 partial=False ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001496 """
Shreyaca8990f2017-03-16 11:43:11 -07001497 Test Multi point to single point intent Topology for Endpoint failures
Jeremye0cb5eb2016-01-27 17:39:09 -08001498 """
Jeremye0cb5eb2016-01-27 17:39:09 -08001499 # Parameter Validity Check
1500 assert main, "There is no main variable"
1501 assert senders, "You must specify a sender"
1502 assert recipients, "You must specify a recipient"
1503
1504 global itemName
1505 itemName = name
Jeremye0cb5eb2016-01-27 17:39:09 -08001506
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001507 global singleToMultiFailFlag
1508 global multiToSingleFailFlag
1509
Jeremye0cb5eb2016-01-27 17:39:09 -08001510 main.log.info( itemName + ": Testing Point Intent" )
1511
Jeremyd9e4eb12016-04-13 12:09:06 -07001512 try:
1513 # Names for scapy
1514 senderNames = [ x.get( "name" ) for x in senders ]
1515 recipientNames = [ x.get( "name" ) for x in recipients ]
1516 isolatedSenderNames = [ x.get( "name" ) for x in isolatedSenders ]
1517 isolatedRecipientNames = [ x.get( "name" ) for x in isolatedRecipients ]
Jon Hall78be4962017-05-23 14:53:53 -07001518 connectedSenderNames = [ x.get( "name" ) for x in senders if x.get( "name" ) not in isolatedSenderNames ]
1519 connectedRecipientNames = [ x.get( "name" ) for x in recipients if x.get( "name" ) not in isolatedRecipientNames ]
Jeremye0cb5eb2016-01-27 17:39:09 -08001520
Jeremyd9e4eb12016-04-13 12:09:06 -07001521 for sender in senders:
1522 if not sender.get( "device" ):
1523 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1524 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremye0cb5eb2016-01-27 17:39:09 -08001525
Jeremyd9e4eb12016-04-13 12:09:06 -07001526 for recipient in recipients:
1527 if not recipient.get( "device" ):
Jon Hall78be4962017-05-23 14:53:53 -07001528 main.log.warn( "Device not given for recipient {0}. Loading from " +
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001529 main.hostData.format( recipient.get( "name" ) ) )
Jeremyd9e4eb12016-04-13 12:09:06 -07001530 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001531 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001532 main.log.error( "There was a problem loading the hosts data." )
1533 return main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001534
1535 testResult = main.TRUE
1536 main.log.info( itemName + ": Adding multi point to single point intents" )
1537
1538 # Check intent state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001539 if singleToMultiFailFlag or multiToSingleFailFlag:
1540 attempts = 1
1541 else:
1542 attempts = 50
1543
Jon Hallaf95c3e2017-05-16 13:20:37 -07001544 if utilities.retry( f=checkIntentState,
1545 retValue=main.FALSE,
1546 args=( main, [ intentId ] ),
1547 sleep=main.checkIntentSleep,
1548 attempts=attempts ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001549 main.assertReturnString += 'Initial Intent State Passed\n'
1550 else:
1551 main.assertReturnString += 'Initial Intent State Failed\n'
1552 testResult = main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001553 attempts = 1
Jeremye0cb5eb2016-01-27 17:39:09 -08001554
1555 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001556 if utilities.retry( f=checkFlowsCount,
1557 retValue=main.FALSE,
1558 args=[ main ],
1559 attempts=5 ) and utilities.retry( f=checkFlowsState,
1560 retValue=main.FALSE,
1561 args=[ main ],
1562 attempts=5 ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001563 main.assertReturnString += 'Initial Flow State Passed\n'
1564 else:
1565 main.assertReturnString += 'Intial Flow State Failed\n'
1566 testResult = main.FALSE
1567
1568 # Check Connectivity
Jon Hallaf95c3e2017-05-16 13:20:37 -07001569 if utilities.retry( f=scapyCheckConnection,
1570 retValue=main.FALSE,
Jeremye0cb5eb2016-01-27 17:39:09 -08001571 args=( main, senderNames, recipientNames ) ):
1572 main.assertReturnString += 'Initial Connectivity Check Passed\n'
1573 else:
1574 main.assertReturnString += 'Initial Connectivity Check Failed\n'
1575 testResult = main.FALSE
1576
1577 # Take two links down
1578 # Take first link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001579 if utilities.retry( f=link,
1580 retValue=main.FALSE,
1581 args=( main, sw1, sw2, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001582 main.assertReturnString += 'Link Down Passed\n'
1583 else:
1584 main.assertReturnString += 'Link Down Failed\n'
1585 testResult = main.FALSE
1586
1587 # Take second link down
Jon Hallaf95c3e2017-05-16 13:20:37 -07001588 if utilities.retry( f=link,
1589 retValue=main.FALSE,
1590 args=( main, sw3, sw4, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001591 main.assertReturnString += 'Link Down Passed\n'
1592 else:
1593 main.assertReturnString += 'Link Down Failed\n'
1594 testResult = main.FALSE
1595
1596 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001597 if utilities.retry( f=checkIntentState,
1598 retValue=main.FALSE,
1599 attempts=attempts,
1600 args=( main, [ intentId ] ),
1601 sleep=main.checkIntentSleep ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001602 main.assertReturnString += 'Link Down Intent State Passed\n'
1603 else:
1604 main.assertReturnString += 'Link Down Intent State Failed\n'
1605 testResult = main.FALSE
1606
1607 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001608 if utilities.retry( f=checkFlowsCount,
1609 retValue=main.FALSE,
1610 sleep=1,
1611 attempts=attempts,
Jeremye0cb5eb2016-01-27 17:39:09 -08001612 args=[ main ] ) and utilities.retry( f=checkFlowsState,
Jon Hallaf95c3e2017-05-16 13:20:37 -07001613 retValue=main.FALSE,
1614 sleep=1,
1615 attempts=attempts,
1616 args=[ main ] ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001617 main.assertReturnString += 'Link Down Flow State Passed\n'
1618 else:
1619 main.assertReturnString += 'Link Down Flow State Failed\n'
1620 testResult = main.FALSE
1621
1622 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001623 if utilities.retry( f=checkTopology,
1624 retValue=main.FALSE,
1625 args=( main, expectedLink1 ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001626 main.assertReturnString += 'Link Down Topology State Passed\n'
1627 else:
1628 main.assertReturnString += 'Link Down Topology State Failed\n'
1629 testResult = main.FALSE
1630
1631 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001632 if utilities.retry( f=scapyCheckConnection,
1633 retValue=main.FALSE,
Jeremye0cb5eb2016-01-27 17:39:09 -08001634 args=( main, senderNames, recipientNames ) ):
1635 main.assertReturnString += 'Link Down Connectivity Check Passed\n'
1636 else:
1637 main.assertReturnString += 'Link Down Connectivity Check Failed\n'
1638 testResult = main.FALSE
1639
1640 # Take a third link down to isolate one node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001641 if utilities.retry( f=link,
1642 retValue=main.FALSE,
1643 args=( main, sw3, sw5, "down" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001644 main.assertReturnString += 'Isolation link Down Passed\n'
1645 else:
1646 main.assertReturnString += 'Isolation link Down Failed\n'
1647 testResult = main.FALSE
1648
Jeremy Songster9385d412016-06-02 17:57:36 -07001649 if partial:
1650 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001651 if utilities.retry( f=checkIntentState,
1652 retValue=main.FALSE,
1653 args=( main, [ intentId ] ),
1654 sleep=main.checkIntentSleep,
1655 attempts=attempts ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001656 main.assertReturnString += 'Partial failure isolation link Down Intent State Passed\n'
1657 else:
1658 main.assertReturnString += 'Partial failure isolation link Down Intent State Failed\n'
1659 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001660
Jeremy Songster9385d412016-06-02 17:57:36 -07001661 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001662 if utilities.retry( f=checkFlowsCount,
1663 retValue=main.FALSE,
1664 args=[ main ],
1665 attempts=5 ) and utilities.retry( f=checkFlowsState,
1666 retValue=main.FALSE,
1667 args=[ main ],
1668 attempts=5 ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001669 main.assertReturnString += 'Partial failure isolation link Down Flow State Passed\n'
1670 else:
1671 main.assertReturnString += 'Partial failure isolation link Down Flow State Failed\n'
1672 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001673
Jeremy Songster9385d412016-06-02 17:57:36 -07001674 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001675 if utilities.retry( f=checkTopology,
1676 retValue=main.FALSE,
1677 args=( main, expectedLink2 ) ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001678 main.assertReturnString += 'Partial failure isolation link Down Topology State Passed\n'
1679 else:
1680 main.assertReturnString += 'Partial failure isolation link Down Topology State Failed\n'
1681 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001682
Jeremy Songster9385d412016-06-02 17:57:36 -07001683 # Check Connectivity
1684 # First check connectivity of any isolated senders to recipients
1685 if isolatedSenderNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001686 if scapyCheckConnection( main,
1687 isolatedSenderNames,
1688 recipientNames,
1689 None,
1690 None,
1691 None,
1692 None,
1693 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001694 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1695 else:
1696 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1697 testResult = main.FALSE
1698
1699 # Next check connectivity of senders to any isolated recipients
1700 if isolatedRecipientNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001701 if scapyCheckConnection( main,
1702 senderNames,
1703 isolatedRecipientNames,
1704 None,
1705 None,
1706 None,
1707 None,
1708 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001709 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1710 else:
1711 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1712 testResult = main.FALSE
1713
1714 # Next check connectivity of connected senders and recipients
Jon Hallaf95c3e2017-05-16 13:20:37 -07001715 if utilities.retry( f=scapyCheckConnection,
1716 retValue=main.FALSE,
1717 attempts=attempts,
Jon Hall78be4962017-05-23 14:53:53 -07001718 args=( main, connectedSenderNames, connectedRecipientNames ) ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001719 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1720 else:
1721 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1722 testResult = main.FALSE
1723 else:
1724 # Check intent state
Jon Hallaf95c3e2017-05-16 13:20:37 -07001725 if not utilities.retry( f=checkIntentState,
1726 retValue=main.TRUE,
1727 args=( main, [ intentId ] ),
1728 sleep=main.checkIntentSleep,
1729 attempts=attempts ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001730 main.assertReturnString += 'Isolation link Down Intent State Passed\n'
1731 else:
1732 main.assertReturnString += 'Isolation link Down Intent State Failed\n'
1733 testResult = main.FALSE
1734
1735 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001736 if utilities.retry( f=checkFlowsCount,
1737 retValue=main.FALSE,
1738 args=[ main ],
1739 attempts=5 ) and utilities.retry( f=checkFlowsState,
1740 retValue=main.FALSE,
1741 args=[ main ],
1742 attempts=5 ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001743 main.assertReturnString += 'Isolation link Down Flow State Passed\n'
1744 else:
1745 main.assertReturnString += 'Isolation link Down Flow State Failed\n'
1746 testResult = main.FALSE
1747
1748 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001749 if utilities.retry( f=checkTopology,
1750 retValue=main.FALSE,
1751 args=( main, expectedLink2 ) ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001752 main.assertReturnString += 'Isolation link Down Topology State Passed\n'
1753 else:
1754 main.assertReturnString += 'Isolation link Down Topology State Failed\n'
1755 testResult = main.FALSE
1756
1757 # Check Connectivity
1758 # First check connectivity of any isolated senders to recipients
1759 if isolatedSenderNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001760 if scapyCheckConnection( main,
1761 isolatedSenderNames,
1762 recipientNames,
1763 None,
1764 None,
1765 None,
1766 None,
1767 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001768 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1769 else:
1770 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1771 testResult = main.FALSE
1772
1773 # Next check connectivity of senders to any isolated recipients
1774 if isolatedRecipientNames:
Jon Hallaf95c3e2017-05-16 13:20:37 -07001775 if scapyCheckConnection( main,
1776 senderNames,
1777 isolatedRecipientNames,
1778 None,
1779 None,
1780 None,
1781 None,
1782 main.TRUE ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001783 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1784 else:
1785 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1786 testResult = main.FALSE
1787
1788 # Next check connectivity of connected senders and recipients
Jon Hallaf95c3e2017-05-16 13:20:37 -07001789 if utilities.retry( f=scapyCheckConnection,
1790 retValue=main.TRUE,
1791 args=( main, connectedSenderNames, connectedRecipientNames, None, None, None, None, main.TRUE ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001792 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1793 else:
1794 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1795 testResult = main.FALSE
1796
Jeremye0cb5eb2016-01-27 17:39:09 -08001797 # Bring the links back up
1798 # Bring first link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001799 if utilities.retry( f=link,
1800 retValue=main.FALSE,
1801 args=( main, sw1, sw2, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001802 main.assertReturnString += 'Link Up Passed\n'
1803 else:
1804 main.assertReturnString += 'Link Up Failed\n'
1805 testResult = main.FALSE
1806
1807 # Bring second link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001808 if utilities.retry( f=link,
1809 retValue=main.FALSE,
1810 args=( main, sw3, sw5, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001811 main.assertReturnString += 'Link Up Passed\n'
1812 else:
1813 main.assertReturnString += 'Link Up Failed\n'
1814 testResult = main.FALSE
1815
1816 # Bring third link up
Jon Hallaf95c3e2017-05-16 13:20:37 -07001817 if utilities.retry( f=link,
1818 retValue=main.FALSE,
1819 args=( main, sw3, sw4, "up" ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001820 main.assertReturnString += 'Link Up Passed\n'
1821 else:
1822 main.assertReturnString += 'Link Up Failed\n'
1823 testResult = main.FALSE
1824
1825 # Wait for reroute
Jon Hallf539eb92017-05-22 17:18:42 -07001826 main.log.info( "Sleeping {} seconds".format( main.rerouteSleep ) )
Jeremye0cb5eb2016-01-27 17:39:09 -08001827 time.sleep( main.rerouteSleep )
1828
1829 # Check Intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001830 if utilities.retry( f=checkIntentState,
1831 retValue=main.FALSE,
1832 attempts=attempts,
1833 args=( main, [ intentId ] ),
1834 sleep=main.checkIntentHostSleep ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001835 main.assertReturnString += 'Link Up Intent State Passed\n'
1836 else:
1837 main.assertReturnString += 'Link Up Intent State Failed\n'
1838 testResult = main.FALSE
1839
1840 # Check flows count in each node
Jon Hallaf95c3e2017-05-16 13:20:37 -07001841 if utilities.retry( f=checkFlowsCount,
1842 retValue=main.FALSE,
1843 args=[ main ],
Jon Hallf539eb92017-05-22 17:18:42 -07001844 sleep=main.checkFlowCountSleep,
1845 attempts=attempts ) and utilities.retry( f=checkFlowsState,
Jon Hall78be4962017-05-23 14:53:53 -07001846 retValue=main.FALSE,
1847 args=[ main ],
1848 sleep=main.checkFlowCountSleep,
1849 attempts=attempts ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001850 main.assertReturnString += 'Link Up Flow State Passed\n'
1851 else:
1852 main.assertReturnString += 'Link Up Flow State Failed\n'
1853 testResult = main.FALSE
1854
1855 # Check OnosTopology
Jon Hallaf95c3e2017-05-16 13:20:37 -07001856 if utilities.retry( f=checkTopology,
1857 retValue=main.FALSE,
1858 args=( main, main.numLinks ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001859 main.assertReturnString += 'Link Up Topology State Passed\n'
1860 else:
1861 main.assertReturnString += 'Link Up Topology State Failed\n'
1862 testResult = main.FALSE
1863
1864 # Check Connection
Jon Hallaf95c3e2017-05-16 13:20:37 -07001865 if utilities.retry( f=scapyCheckConnection,
1866 retValue=main.FALSE,
1867 sleep=main.checkConnectionSleep,
1868 attempts=attempts,
Jeremye0cb5eb2016-01-27 17:39:09 -08001869 args=( main, senderNames, recipientNames ) ):
1870 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1871 else:
1872 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1873 testResult = main.FALSE
1874
1875 # Remove all intents
Jon Hallaf95c3e2017-05-16 13:20:37 -07001876 if utilities.retry( f=removeAllIntents,
1877 retValue=main.FALSE,
1878 attempts=10,
1879 args=( main, [ intentId ] ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001880 main.assertReturnString += 'Remove Intents Passed'
1881 else:
1882 main.assertReturnString += 'Remove Intents Failed'
1883 testResult = main.FALSE
1884
1885 return testResult
1886
1887
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001888def pingallHosts( main, hostList ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001889 """
1890 Ping all host in the hosts list variable
1891 """
Jon Halla5cb3412015-08-18 14:08:22 -07001892 main.log.info( "Pinging: " + str( hostList ) )
1893 return main.Mininet1.pingallHosts( hostList )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001894
Jon Hall78be4962017-05-23 14:53:53 -07001895
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001896def fwdPingall( main ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001897 """
1898 Use fwd app and pingall to discover all the hosts
1899 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001900 appCheck = main.TRUE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001901 main.log.info( "Activating reactive forwarding app " )
Devin Lim142b5342017-07-20 15:22:39 -07001902 activateResult = main.Cluster.active( 0 ).CLI.activateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001903
1904 # Wait for forward app activation to propagate
Jon Hallf539eb92017-05-22 17:18:42 -07001905 main.log.info( "Sleeping {} seconds".format( main.fwdSleep ) )
kelvin-onlab0ad05d12015-07-23 14:21:15 -07001906 time.sleep( main.fwdSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001907
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001908 # Check that forwarding is enabled on all nodes
Devin Lim142b5342017-07-20 15:22:39 -07001909 for ctrl in main.Cluster.active():
1910 appCheck = appCheck and ctrl.CLI.appToIDCheck()
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001911 if appCheck != main.TRUE:
Devin Lim142b5342017-07-20 15:22:39 -07001912 main.log.warn( ctrl.CLI.apps() )
1913 main.log.warn( ctrl.CLI.appIDs() )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001914
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001915 # Send pingall in mininet
1916 main.log.info( "Run Pingall" )
Jon Hall78be4962017-05-23 14:53:53 -07001917 pingResult = main.Mininet1.pingall( timeout=600 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001918
1919 main.log.info( "Deactivating reactive forwarding app " )
Devin Lim142b5342017-07-20 15:22:39 -07001920 deactivateResult = main.Cluster.active( 0 ).CLI.deactivateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001921 if activateResult and deactivateResult:
1922 main.log.info( "Successfully used fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001923 getDataResult = main.TRUE
1924 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001925 main.log.info( "Failed to use fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001926 getDataResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001927 return getDataResult
1928
Jon Hall78be4962017-05-23 14:53:53 -07001929
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001930def confirmHostDiscovery( main ):
1931 """
1932 Confirms that all ONOS nodes have discovered all scapy hosts
1933 """
1934 import collections
Devin Lim58046fa2017-07-05 16:55:00 -07001935 try:
1936 from tests.dependencies.topology import Topology
1937 except Exception:
1938 main.log.error( "Topology not found exiting the test" )
1939 main.exit()
1940 try:
1941 main.topoRelated
1942 except Exception:
1943 main.topoRelated = Topology()
Devin Lim142b5342017-07-20 15:22:39 -07001944 hosts = main.topoRelated.getAll( "hosts", False ) # Get host data from each ONOS node
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001945 hostFails = [] # Reset for each failed attempt
1946
1947 # Check for matching hosts on each node
1948 scapyHostIPs = [ x.hostIp for x in main.scapyHosts if x.hostIp != "0.0.0.0" ]
Devin Lim142b5342017-07-20 15:22:39 -07001949 for controller in range( main.Cluster.numCtrls ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001950 controllerStr = str( controller + 1 ) # ONOS node number
1951 # Compare Hosts
1952 # Load hosts data for controller node
Jeremyd9e4eb12016-04-13 12:09:06 -07001953 try:
1954 if hosts[ controller ]:
1955 main.log.info( "Hosts discovered" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001956 else:
Jeremyd9e4eb12016-04-13 12:09:06 -07001957 main.log.error( "Problem discovering hosts" )
1958 if hosts[ controller ] and "Error" not in hosts[ controller ]:
1959 try:
1960 hostData = json.loads( hosts[ controller ] )
1961 except ( TypeError, ValueError ):
1962 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001963 hostFails.append( controllerStr )
Jeremyd9e4eb12016-04-13 12:09:06 -07001964 else:
1965 onosHostIPs = [ x.get( "ipAddresses" )[ 0 ]
1966 for x in hostData
1967 if len( x.get( "ipAddresses" ) ) > 0 ]
Jon Hall78be4962017-05-23 14:53:53 -07001968 if not set( collections.Counter( scapyHostIPs ) ).issubset(
1969 set( collections.Counter( onosHostIPs ) ) ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001970 main.log.warn( "Controller {0} only sees nodes with {1} IPs. It should see all of the following: {2}".format( controllerStr, onosHostIPs, scapyHostIPs ) )
1971 hostFails.append( controllerStr )
1972 else:
1973 main.log.error( "Hosts returned nothing or an error." )
1974 hostFails.append( controllerStr )
1975 except IndexError:
1976 main.log.error( "Hosts returned nothing, Failed to discover hosts." )
1977 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001978
1979 if hostFails:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001980 main.log.error( "List of failed ONOS Nodes:" + ', '.join( map( str, hostFails ) ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001981 return main.FALSE
1982 else:
1983 return main.TRUE
1984
Jon Hall78be4962017-05-23 14:53:53 -07001985
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001986def sendDiscoveryArp( main, hosts=None ):
1987 """
1988 Sends Discovery ARP packets from each host provided
1989 Defaults to each host in main.scapyHosts
1990 """
1991 # Send an arp ping from each host
1992 if not hosts:
1993 hosts = main.scapyHosts
1994 for host in hosts:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001995 pkt = 'Ether( src="{0}")/ARP( psrc="{1}")'.format( host.hostMac, host.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001996 # Send from the VLAN interface if there is one so ONOS discovers the VLAN correctly
1997 iface = None
1998 for interface in host.getIfList():
1999 if '.' in interface:
2000 main.log.debug( "Detected VLAN interface {0}. Sending ARP packet from {0}".format( interface ) )
2001 iface = interface
2002 break
2003 host.sendPacket( packet=pkt, iface=iface )
2004 main.log.info( "Sending ARP packet from {0}".format( host.name ) )
2005
Jon Hall78be4962017-05-23 14:53:53 -07002006
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002007def populateHostData( main ):
2008 """
2009 Populates hostsData
2010 """
2011 import json
2012 try:
Devin Lim142b5342017-07-20 15:22:39 -07002013 hostsJson = json.loads( main.Cluster.active( 0 ).CLI.hosts() )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002014 hosts = main.Mininet1.getHosts().keys()
2015 # TODO: Make better use of new getHosts function
2016 for host in hosts:
2017 main.hostsData[ host ] = {}
2018 main.hostsData[ host ][ 'mac' ] = \
2019 main.Mininet1.getMacAddress( host ).upper()
2020 for hostj in hostsJson:
2021 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
2022 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
2023 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
2024 main.hostsData[ host ][ 'location' ] = \
Jeremy Ronquillo0e538bc2017-06-13 15:16:09 -07002025 hostj[ 'locations' ][ 0 ][ 'elementId' ] + '/' + \
2026 hostj[ 'locations' ][ 0 ][ 'port' ]
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002027 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
2028 return main.TRUE
Jeremyd9e4eb12016-04-13 12:09:06 -07002029 except ValueError:
2030 main.log.error( "ValueError while populating hostsData" )
2031 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002032 except KeyError:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002033 main.log.error( "KeyError while populating hostsData" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002034 return main.FALSE
Jeremyd9e4eb12016-04-13 12:09:06 -07002035 except IndexError:
2036 main.log.error( "IndexError while populating hostsData" )
2037 return main.FALSE
2038 except TypeError:
2039 main.log.error( "TypeError while populating hostsData" )
2040 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002041
Jon Hall78be4962017-05-23 14:53:53 -07002042
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002043def checkTopology( main, expectedLink ):
2044 statusResult = main.TRUE
2045 # Check onos topology
2046 main.log.info( itemName + ": Checking ONOS topology " )
2047
Devin Lim142b5342017-07-20 15:22:39 -07002048 statusResult = main.Cluster.command( "checkStatus",
2049 args=[ main.numSwitch, expectedLink ],
2050 returnBool=True, specificDriver=2 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002051 if not statusResult:
2052 main.log.error( itemName + ": Topology mismatch" )
2053 else:
2054 main.log.info( itemName + ": Topology match" )
2055 return statusResult
2056
Jon Hall78be4962017-05-23 14:53:53 -07002057
Jon Hallf539eb92017-05-22 17:18:42 -07002058def checkIntentState( main, intentsId ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002059 """
2060 This function will check intent state to make sure all the intents
2061 are in INSTALLED state
Jon Hallf539eb92017-05-22 17:18:42 -07002062 Returns main.TRUE or main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002063 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002064 intentResult = main.TRUE
Devin Lim142b5342017-07-20 15:22:39 -07002065 stateCheckResults = main.Cluster.command( "checkIntentState",
2066 kwargs={ "intentsId":intentsId },
2067 returnBool=True, specificDriver=2 )
2068 if stateCheckResults:
Jon Hallf539eb92017-05-22 17:18:42 -07002069 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 """
Devin Lim142b5342017-07-20 15:22:39 -07002081 stateCheckResults = main.Cluster.command( "compareBandwidthAllocations",
2082 args=[ bandwidth ],
2083 returnBool=True, specificDriver=2 )
2084 if stateCheckResults:
Jon Hallf539eb92017-05-22 17:18:42 -07002085 main.log.info( itemName + ": bandwidth check passed" )
2086 bandwidthResult = main.TRUE
2087 else:
2088 main.log.warn( itemName + ": bandwidth check failed" )
2089 bandwidthResult = main.FALSE
2090 return bandwidthResult
2091
Jon Hall78be4962017-05-23 14:53:53 -07002092
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002093def checkFlowsState( main ):
2094
2095 main.log.info( itemName + ": Check flows state" )
Devin Lim142b5342017-07-20 15:22:39 -07002096 checkFlowsResult = main.Cluster.active( 0 ).CLI.checkFlowsState( isPENDING=False )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002097 return checkFlowsResult
2098
Jon Hall78be4962017-05-23 14:53:53 -07002099
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002100def link( main, sw1, sw2, option ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002101
2102 # link down
alison52b25892016-09-19 10:53:48 -07002103 main.log.info( itemName + ": Bring link " + option + " between " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002104 sw1 + " and " + sw2 )
2105 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
2106 return linkResult
2107
Jon Hall78be4962017-05-23 14:53:53 -07002108
Jon Hallaf95c3e2017-05-16 13:20:37 -07002109def scapyCheckConnection( main,
2110 senders,
2111 recipients,
2112 vlanId=None,
2113 useTCP=False,
2114 packet=None,
2115 packetFilter=None,
2116 expectFailure=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002117 """
2118 Checks the connectivity between all given sender hosts and all given recipient hosts
2119 Packet may be specified. Defaults to Ether/IP packet
2120 Packet Filter may be specified. Defaults to Ether/IP from current sender MAC
2121 Todo: Optional packet and packet filter attributes for sender and recipients
2122 Expect Failure when the sender and recipient are not supposed to have connectivity
2123 Timeout of 1 second, returns main.TRUE if the filter is not triggered and kills the filter
2124
2125 """
2126 connectionsFunctional = main.TRUE
2127
2128 if not packetFilter:
2129 packetFilter = 'ether host {}'
Jeremy Songstere405d3d2016-05-17 11:18:57 -07002130 if useTCP:
Jon Hall78be4962017-05-23 14:53:53 -07002131 packetFilter += ' ip proto \\tcp tcp port {}'.format( main.params[ 'SDNIP' ][ 'dstPort' ] )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002132 if expectFailure:
2133 timeout = 1
2134 else:
2135 timeout = 10
2136
2137 for sender in senders:
2138 try:
2139 senderComp = getattr( main, sender )
2140 except AttributeError:
2141 main.log.error( "main has no attribute {}".format( sender ) )
2142 connectionsFunctional = main.FALSE
2143 continue
2144
2145 for recipient in recipients:
2146 # Do not send packets to self since recipient CLI will already be busy
2147 if recipient == sender:
2148 continue
2149 try:
2150 recipientComp = getattr( main, recipient )
2151 except AttributeError:
2152 main.log.error( "main has no attribute {}".format( recipient ) )
2153 connectionsFunctional = main.FALSE
2154 continue
2155
Jeremy Songster832f9e92016-05-05 14:30:49 -07002156 if vlanId:
Jon Hall78be4962017-05-23 14:53:53 -07002157 recipientComp.startFilter( pktFilter=( "vlan {}".format( vlanId ) + " && " + packetFilter.format( senderComp.hostMac ) ) )
Jeremy Songster832f9e92016-05-05 14:30:49 -07002158 else:
Jon Hall78be4962017-05-23 14:53:53 -07002159 recipientComp.startFilter( pktFilter=packetFilter.format( senderComp.hostMac ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002160
2161 if not packet:
Jeremy Songster832f9e92016-05-05 14:30:49 -07002162 if vlanId:
2163 pkt = 'Ether( src="{0}", dst="{2}" )/Dot1Q(vlan={4})/IP( src="{1}", dst="{3}" )'.format(
2164 senderComp.hostMac,
2165 senderComp.hostIp,
2166 recipientComp.hostMac,
2167 recipientComp.hostIp,
2168 vlanId )
2169 else:
2170 pkt = 'Ether( src="{0}", dst="{2}" )/IP( src="{1}", dst="{3}" )'.format(
2171 senderComp.hostMac,
2172 senderComp.hostIp,
2173 recipientComp.hostMac,
2174 recipientComp.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002175 else:
2176 pkt = packet
Jeremy Songster832f9e92016-05-05 14:30:49 -07002177 if vlanId:
2178 senderComp.sendPacket( iface=( "{0}-eth0.{1}".format( sender, vlanId ) ), packet = pkt )
2179 else:
Jon Hall78be4962017-05-23 14:53:53 -07002180 senderComp.sendPacket( packet=pkt )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002181
2182 if recipientComp.checkFilter( timeout ):
2183 if expectFailure:
Jon Hall78be4962017-05-23 14:53:53 -07002184 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 -08002185 connectionsFunctional = main.FALSE
2186 else:
Jon Hall78be4962017-05-23 14:53:53 -07002187 main.log.info( "Packet from {0} successfully received by {1}".format( sender, recipient ) )
alison52b25892016-09-19 10:53:48 -07002188 connectionsFunctional = main.TRUE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002189 else:
2190 recipientComp.killFilter()
2191 if expectFailure:
Jon Hall78be4962017-05-23 14:53:53 -07002192 main.log.info( "As expected, packet from {0} was not received by {1}".format( sender, recipient ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002193 else:
Jon Hall78be4962017-05-23 14:53:53 -07002194 main.log.error( "Packet from {0} was not received by {1}".format( sender, recipient ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002195 connectionsFunctional = main.FALSE
2196
2197 return connectionsFunctional
2198
alison52b25892016-09-19 10:53:48 -07002199
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002200def removeAllIntents( main, intentsId ):
2201 """
2202 Remove all intents in the intentsId
2203 """
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002204 onosSummary = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002205 removeIntentResult = main.TRUE
2206 # Remove intents
2207 for intent in intentsId:
Devin Lim142b5342017-07-20 15:22:39 -07002208 main.Cluster.active( 0 ).CLI.removeIntent( intentId=intent, purge=True )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002209
Jon Hallf539eb92017-05-22 17:18:42 -07002210 main.log.info( "Sleeping {} seconds".format( main.removeIntentSleep ) )
acsmarscfa52272015-08-06 15:21:45 -07002211 time.sleep( main.removeIntentSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002212
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002213 # If there is remianing intents then remove intents should fail
Devin Lim142b5342017-07-20 15:22:39 -07002214 for ctrl in main.Cluster.active():
2215 onosSummary.append( json.loads( ctrl.CLI.summary() ) )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002216
2217 for summary in onosSummary:
2218 if summary.get( 'intents' ) != 0:
2219 main.log.warn( itemName + ": There are " +
2220 str( summary.get( 'intents' ) ) +
2221 " intents remaining in node " +
2222 str( summary.get( 'node' ) ) +
2223 ", failed to remove all the intents " )
2224 removeIntentResult = main.FALSE
2225
2226 if removeIntentResult:
2227 main.log.info( itemName + ": There are no more intents remaining, " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002228 "successfully removed all the intents." )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07002229
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002230 return removeIntentResult
2231
Jon Hall78be4962017-05-23 14:53:53 -07002232
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002233def checkFlowsCount( main ):
2234 """
2235 Check flows count in each node
2236 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002237 flowsCount = []
2238 main.log.info( itemName + ": Checking flows count in each ONOS node" )
Devin Lim142b5342017-07-20 15:22:39 -07002239 for ctrl in main.Cluster.active():
2240 summaryResult = ctrl.CLI.summary()
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002241 if not summaryResult:
2242 main.log.error( itemName + ": There is something wrong with " +
2243 "summary command" )
2244 return main.FALSE
2245 else:
2246 summaryJson = json.loads( summaryResult )
2247 flowsCount.append( summaryJson.get( 'flows' ) )
2248
2249 if flowsCount:
Jon Hall78be4962017-05-23 14:53:53 -07002250 if all( flows == flowsCount[ 0 ] for flows in flowsCount ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002251 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
2252 " flows in all ONOS node" )
2253 else:
Devin Lim142b5342017-07-20 15:22:39 -07002254 for i in range( main.Cluster.numCtrls ):
2255 main.log.debug( itemName + ": " + ctrl.name + " has " +
2256 str( flowsCount[ ctrl.pos ] ) + " flows" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07002257 else:
2258 main.log.error( "Checking flows count failed, check summary command" )
2259 return main.FALSE
2260
2261 return main.TRUE
2262
Jon Hall78be4962017-05-23 14:53:53 -07002263
kelvin-onlab58dc39e2015-08-06 08:11:09 -07002264def checkLeaderChange( leaders1, leaders2 ):
acsmarse6b410f2015-07-17 14:39:34 -07002265 """
2266 Checks for a change in intent partition leadership.
2267
2268 Takes the output of leaders -c in json string format before and after
2269 a potential change as input
2270
2271 Returns main.TRUE if no mismatches are detected
2272 Returns main.FALSE if there is a mismatch or on error loading the input
2273 """
2274 try:
2275 leaders1 = json.loads( leaders1 )
2276 leaders2 = json.loads( leaders2 )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07002277 except( AttributeError, TypeError ):
Jon Halld970abf2017-05-23 10:20:28 -07002278 main.log.exception( "checkLeaderChange: Object not as expected" )
acsmarse6b410f2015-07-17 14:39:34 -07002279 return main.FALSE
2280 except Exception:
Jon Halld970abf2017-05-23 10:20:28 -07002281 main.log.exception( "checkLeaderChange: Uncaught exception!" )
acsmarse6b410f2015-07-17 14:39:34 -07002282 main.cleanup()
2283 main.exit()
2284 main.log.info( "Checking Intent Paritions for Change in Leadership" )
2285 mismatch = False
2286 for dict1 in leaders1:
2287 if "intent" in dict1.get( "topic", [] ):
2288 for dict2 in leaders2:
Jon Hall78be4962017-05-23 14:53:53 -07002289 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and\
2290 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
acsmarse6b410f2015-07-17 14:39:34 -07002291 mismatch = True
Jon Hall78be4962017-05-23 14:53:53 -07002292 main.log.error( "%s changed leader from %s to %s",
2293 dict1.get( "topic", "no-topic" ),
2294 dict1.get( "leader", "no-leader" ),
2295 dict2.get( "leader", "no-leader" ) )
acsmarse6b410f2015-07-17 14:39:34 -07002296 if mismatch:
2297 return main.FALSE
2298 else:
2299 return main.TRUE
kelvin-onlab016dce22015-08-10 09:54:11 -07002300
Jon Hall78be4962017-05-23 14:53:53 -07002301
kelvin-onlab016dce22015-08-10 09:54:11 -07002302def report( main ):
2303 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08002304 Report errors/warnings/exceptions
kelvin-onlab016dce22015-08-10 09:54:11 -07002305 """
Devin Lim142b5342017-07-20 15:22:39 -07002306 main.ONOSbench.logReport( main.Cluster.active( 0 ).ipAddress,
kelvin-onlab016dce22015-08-10 09:54:11 -07002307 [ "INFO",
2308 "FOLLOWER",
2309 "WARN",
2310 "flow",
2311 "ERROR",
2312 "Except" ],
2313 "s" )
2314
2315 main.log.info( "ERROR report: \n" )
Devin Lim142b5342017-07-20 15:22:39 -07002316 for ctrl in main.Cluster.active():
2317 main.ONOSbench.logReport( ctrl.ipAddress,
Jon Hall78be4962017-05-23 14:53:53 -07002318 [ "ERROR" ],
2319 "d" )
kelvin-onlab016dce22015-08-10 09:54:11 -07002320
2321 main.log.info( "EXCEPTIONS report: \n" )
Devin Lim142b5342017-07-20 15:22:39 -07002322 for ctrl in main.Cluster.active():
2323 main.ONOSbench.logReport( ctrl.ipAddress,
Jon Hall78be4962017-05-23 14:53:53 -07002324 [ "Except" ],
2325 "d" )
kelvin-onlab016dce22015-08-10 09:54:11 -07002326
2327 main.log.info( "WARNING report: \n" )
Devin Lim142b5342017-07-20 15:22:39 -07002328 for ctrl in main.Cluster.active():
2329 main.ONOSbench.logReport( ctrl.ipAddress,
Jon Hall78be4962017-05-23 14:53:53 -07002330 [ "WARN" ],
2331 "d" )
2332
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002333
2334def flowDuration( main ):
2335 """
2336 Check age of flows to see if flows are being overwritten
2337 """
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002338 main.log.info( "Getting current flow durations" )
Devin Lim142b5342017-07-20 15:22:39 -07002339 flowsJson1 = main.Cluster.active( 0 ).CLI.flows( noCore=True )
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002340 try:
2341 flowsJson1 = json.loads( flowsJson1 )
2342 except ValueError:
2343 main.log.error( "Unable to read flows" )
2344 return main.FALSE
2345 flowLife = []
2346 waitFlowLife = []
2347 for device in flowsJson1:
2348 if device.get( 'flowcount', 0 ) > 0:
2349 for i in range( device[ 'flowCount' ] ):
2350 flowLife.append( device[ 'flows' ][ i ][ 'life' ] )
2351 main.log.info( "Sleeping for {} seconds".format( main.flowDurationSleep ) )
2352 time.sleep( main.flowDurationSleep )
2353 main.log.info( "Getting new flow durations" )
Devin Lim142b5342017-07-20 15:22:39 -07002354 flowsJson2 = main.Cluster.active( 0 ).CLI.flows( noCore=True )
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002355 try:
2356 flowsJson2 = json.loads( flowsJson2 )
2357 except ValueError:
2358 main.log.error( "Unable to read flows" )
2359 return main.FALSE
2360 for device in flowsJson2:
2361 if device.get( 'flowcount', 0 ) > 0:
2362 for i in range( device[ 'flowCount' ] ):
2363 waitFlowLife.append( device[ 'flows' ][ i ][ 'life' ] )
2364 main.log.info( "Determining whether flows where overwritten" )
2365 if len( flowLife ) == len( waitFlowLife ):
alison52b25892016-09-19 10:53:48 -07002366 for i in range( len( flowLife ) ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002367 if waitFlowLife[ i ] - flowLife[ i ] < main.flowDurationSleep:
2368 return main.FALSE
2369 else:
2370 return main.FALSE
2371 return main.TRUE
alison52b25892016-09-19 10:53:48 -07002372
2373
2374def EncapsulatedIntentCheck( main, tag="" ):
2375 """
2376 Check encapsulated intents
Jon Hall78be4962017-05-23 14:53:53 -07002377 tag: encapsulation tag ( e.g. VLAN, MPLS )
alison52b25892016-09-19 10:53:48 -07002378
2379 Getting added flows
2380 Check tags on each flows
2381 If each direction has push or pop, passed
2382 else failed
2383
2384 """
Devin Limf6d287d2017-08-04 14:39:11 -07002385 main.log.info( "Checking encapsulated intent for " + tag + ".")
alison52b25892016-09-19 10:53:48 -07002386 HostJson = []
Devin Lim142b5342017-07-20 15:22:39 -07002387 Jflows = main.Cluster.active( 0 ).CLI.flows( noCore=True )
alison52b25892016-09-19 10:53:48 -07002388 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"
Devin Limf6d287d2017-08-04 14:39:11 -07002405 main.log.info( "Host Json info :" )
alison52b25892016-09-19 10:53:48 -07002406 for EachHostJson in HostJson:
2407 for i in range( totalflows ):
Devin Limf6d287d2017-08-04 14:39:11 -07002408 main.log.info( str( EachHostJson[ i ] ) )
2409 checkJson = EachHostJson[ i ][ "treatment" ][ "instructions" ][ 0 ]
2410 main.Cluster.active( 0 ).REST.pprint( checkJson )
2411 if 'subtype' in checkJson:
2412 if checkJson[ "subtype" ] == PopTag:
2413 pop += 1
2414 elif checkJson[ "subtype" ] == PushTag:
2415 push += 1
alison52b25892016-09-19 10:53:48 -07002416
2417 if pop == totalflows and push == totalflows:
2418 return main.TRUE
2419 else:
Devin Limf6d287d2017-08-04 14:39:11 -07002420 main.log.error( "Total " + PushTag + str( push ) )
2421 main.log.error( "Total " + PopTag + str( pop ) )
alisonda157272016-12-22 01:13:21 -08002422 return main.FALSE
2423
2424def ProtectedIntentCheck( main ):
Devin Lim142b5342017-07-20 15:22:39 -07002425 intent = main.Cluster.active( 0 ).CLI.intents( jsonFormat=False )
alisonda157272016-12-22 01:13:21 -08002426 if "Protection" in intent:
2427 return main.TRUE
Shreyaca8990f2017-03-16 11:43:11 -07002428 return main.FALSE