blob: d8a0e36512db74c8ed6ece42694b301861ae6433 [file] [log] [blame]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001"""
2 Wrapper functions for FuncIntent
3 This functions include Onosclidriver and Mininetclidriver driver functions
4 Author: kelvin@onlab.us
5"""
6import time
7import copy
8import json
9
10def __init__( self ):
11 self.default = ''
12
Jeremy Songster1f39bf02016-01-20 17:17:25 -080013def installHostIntent( main,
Jeremy2f190ca2016-01-29 15:23:57 -080014 name,
15 host1,
16 host2,
17 onosNode=0,
18 ethType="",
19 bandwidth="",
20 lambdaAlloc=False,
21 ipProto="",
22 ipAddresses="",
23 tcp="",
24 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -070025 sw2="",
Jeremy Songsterc032f162016-08-04 17:14:49 -070026 setVlan="",
27 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -070028 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -080029 Installs a Host Intent
30
kelvin-onlab58dc39e2015-08-06 08:11:09 -070031 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -080032 Install a host intent using
33 add-host-intent
34
kelvin-onlab58dc39e2015-08-06 08:11:09 -070035 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -080036 - Fetch host data if not given
37 - Add host intent
38 - Ingress device is the first sender host
39 - Egress devices are the recipient devices
40 - Ports if defined in senders or recipients
41 - MAC address ethSrc loaded from Ingress device
42 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -070043 Required:
44 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -080045 host1 - Dictionary for host1
46 { "name":"h8", "id":"of:0000000000000005/8" }
47 host2 - Dictionary for host2
48 { "name":"h16", "id":"of:0000000000000006/8" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -070049 Optional:
50 onosNode - ONOS node to install the intents in main.CLIs[ ]
51 0 by default so that it will always use the first
52 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -070053 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -070054 bandwidth - Bandwidth capacity
55 lambdaAlloc - Allocate lambda, defaults to False
56 ipProto - IP protocol
Jeremy Songster1f39bf02016-01-20 17:17:25 -080057 tcp - TCP ports in the same order as the hosts in hostNames
58 """
59
60 assert main, "There is no main variable"
61 assert host1, "You must specify host1"
62 assert host2, "You must specify host2"
63
64 global itemName # The name of this run. Used for logs.
65 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -080066
67 main.log.info( itemName + ": Adding single point to multi point intents" )
Jeremyd9e4eb12016-04-13 12:09:06 -070068 try:
69 if not host1.get( "id" ):
70 main.log.warn( "ID not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
71 main.log.debug( main.hostsData.get( host1.get( "name" ) ) )
72 host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "id" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -080073
Jeremyd9e4eb12016-04-13 12:09:06 -070074 if not host2.get( "id" ):
75 main.log.warn( "ID not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
76 host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "id" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -080077
Jeremyd9e4eb12016-04-13 12:09:06 -070078 # Adding point intent
Jeremy Songster832f9e92016-05-05 14:30:49 -070079 vlanId = host1.get( "vlan" )
Jeremyd9e4eb12016-04-13 12:09:06 -070080 intentId = main.CLIs[ onosNode ].addHostIntent( hostIdOne=host1.get( "id" ),
Jeremy Songster832f9e92016-05-05 14:30:49 -070081 hostIdTwo=host2.get( "id" ),
Jeremy Songsterff553672016-05-12 17:06:23 -070082 vlanId=vlanId,
Jeremy Songsterc032f162016-08-04 17:14:49 -070083 setVlan=setVlan,
84 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -070085 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -070086 errorMsg = "There was a problem loading the hosts data."
87 if intentId:
88 errorMsg += " There was a problem installing host to host intent."
89 main.log.error( errorMsg )
90 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -080091
92 # Check intents state
93 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
alison52b25892016-09-19 10:53:48 -070094 args=( main, [ intentId ] ), sleep=main.checkIntentSleep, attempts=5 ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -070095 main.assertReturnString += 'Install Intent State Passed\n'
alison52b25892016-09-19 10:53:48 -070096
97 #Check VLAN if test encapsulation
98 if encap != "":
99 if EncapsulatedIntentCheck( main, tag=encap ):
100 main.assertReturnString += 'Encapsulation intents check Passed\n'
101 else:
102 main.assertReturnString += 'Encapsulation intents check failed\n'
103
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700104 if flowDuration( main ):
105 main.assertReturnString += 'Flow duration check Passed\n'
106 return intentId
107 else:
108 main.assertReturnString += 'Flow duration check failed\n'
109 return main.FALSE
alison52b25892016-09-19 10:53:48 -0700110
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800111 else:
Jeremy2f190ca2016-01-29 15:23:57 -0800112 main.log.error( "Host Intent did not install correctly" )
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700113 main.assertReturnString += 'Install Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800114 return main.FALSE
115
116def testHostIntent( main,
117 name,
118 intentId,
119 host1,
120 host2,
121 onosNode=0,
122 sw1="s5",
123 sw2="s2",
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700124 expectedLink=0 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800125 """
126 Test a Host Intent
127
128 Description:
129 Test a host intent of given ID between given hosts
130
131 Steps:
132 - Fetch host data if not given
133 - Check Intent State
134 - Check Flow State
135 - Check Connectivity
136 - Check Lack of Connectivity Between Hosts not in the Intent
137 - Reroute
138 - Take Expected Link Down
139 - Check Intent State
140 - Check Flow State
141 - Check Topology
142 - Check Connectivity
143 - Bring Expected Link Up
144 - Check Intent State
145 - Check Flow State
146 - Check Topology
147 - Check Connectivity
148 - Remove Topology
149
150 Required:
151 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
152 intentId - intent ID to be tested ( and removed )
153 host1 - Dictionary for host1
154 { "name":"h8", "id":"of:0000000000000005/8" }
155 host2 - Dictionary for host2
156 { "name":"h16", "id":"of:0000000000000006/8" }
157 Optional:
158 onosNode - ONOS node to install the intents in main.CLIs[ ]
159 0 by default so that it will always use the first
160 ONOS node
161 sw1 - First switch to bring down & up for rerouting purpose
162 sw2 - Second switch to bring down & up for rerouting purpose
163 expectedLink - Expected link when the switches are down, it should
164 be two links lower than the links before the two
165 switches are down
166
167 """
168
169 # Parameter Validity Check
170 assert main, "There is no main variable"
171 assert host1, "You must specify host1"
172 assert host2, "You must specify host2"
173
174 global itemName
175 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800176
Jeremy2f190ca2016-01-29 15:23:57 -0800177 main.log.info( itemName + ": Testing Host Intent" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800178
Jeremyd9e4eb12016-04-13 12:09:06 -0700179 try:
180 if not host1.get( "id" ):
181 main.log.warn( "Id not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
182 host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800183
Jeremyd9e4eb12016-04-13 12:09:06 -0700184 if not host2.get( "id" ):
185 main.log.warn( "Id not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
186 host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800187
Jeremyd9e4eb12016-04-13 12:09:06 -0700188 senderNames = [ host1.get( "name" ), host2.get( "name" ) ]
189 recipientNames = [ host1.get( "name" ), host2.get( "name" ) ]
Jeremy Songster832f9e92016-05-05 14:30:49 -0700190 vlanId = host1.get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800191
Jeremyd9e4eb12016-04-13 12:09:06 -0700192 testResult = main.TRUE
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700193 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700194 main.log.error( "There was a problem loading the hosts data." )
195 return main.FALSE
196
197 main.log.info( itemName + ": Testing Host to Host intents" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800198
199 # Check intent state
200 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
201 main.assertReturnString += 'Initial Intent State Passed\n'
202 else:
203 main.assertReturnString += 'Initial Intent State Failed\n'
204 testResult = main.FALSE
205
206 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -0700207 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800208 main.assertReturnString += 'Initial Flow State Passed\n'
209 else:
210 main.assertReturnString += 'Intial Flow State Failed\n'
211 testResult = main.FALSE
212
213 # Check Connectivity
Jeremy Songster832f9e92016-05-05 14:30:49 -0700214 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800215 main.assertReturnString += 'Initial Ping Passed\n'
216 else:
217 main.assertReturnString += 'Initial Ping Failed\n'
218 testResult = main.FALSE
219
220 # Test rerouting if these variables exist
221 if sw1 and sw2 and expectedLink:
222 # Take link down
223 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
224 main.assertReturnString += 'Link Down Passed\n'
225 else:
226 main.assertReturnString += 'Link Down Failed\n'
227 testResult = main.FALSE
228
229 # Check intent state
230 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
231 main.assertReturnString += 'Link Down Intent State Passed\n'
232 else:
233 main.assertReturnString += 'Link Down Intent State Failed\n'
234 testResult = main.FALSE
235
236 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -0700237 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800238 main.assertReturnString += 'Link Down Flow State Passed\n'
239 else:
240 main.assertReturnString += 'Link Down Flow State Failed\n'
241 testResult = main.FALSE
242
243 # Check OnosTopology
244 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink ) ):
245 main.assertReturnString += 'Link Down Topology State Passed\n'
246 else:
247 main.assertReturnString += 'Link Down Topology State Failed\n'
248 testResult = main.FALSE
249
250 # Check Connection
alison52b25892016-09-19 10:53:48 -0700251 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ), sleep=5, attempts=5 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800252 main.assertReturnString += 'Link Down Pingall Passed\n'
253 else:
254 main.assertReturnString += 'Link Down Pingall Failed\n'
255 testResult = main.FALSE
256
257 # Bring link up
258 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
259 main.assertReturnString += 'Link Up Passed\n'
260 else:
261 main.assertReturnString += 'Link Up Failed\n'
262 testResult = main.FALSE
263
264 # Wait for reroute
265 time.sleep( main.rerouteSleep )
266
267 # Check Intents
268 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
269 main.assertReturnString += 'Link Up Intent State Passed\n'
270 else:
271 main.assertReturnString += 'Link Up Intent State Failed\n'
272 testResult = main.FALSE
273
274 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -0700275 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800276 main.assertReturnString += 'Link Up Flow State Passed\n'
277 else:
278 main.assertReturnString += 'Link Up Flow State Failed\n'
279 testResult = main.FALSE
280
281 # Check OnosTopology
282 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
283 main.assertReturnString += 'Link Up Topology State Passed\n'
284 else:
285 main.assertReturnString += 'Link Up Topology State Failed\n'
286 testResult = main.FALSE
287
288 # Check Connection
Jeremy Songster832f9e92016-05-05 14:30:49 -0700289 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800290 main.assertReturnString += 'Link Up Pingall Passed\n'
291 else:
292 main.assertReturnString += 'Link Up Pingall Failed\n'
293 testResult = main.FALSE
294
295 # Remove all intents
296 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ):
297 main.assertReturnString += 'Remove Intents Passed'
298 else:
299 main.assertReturnString += 'Remove Intents Failed'
300 testResult = main.FALSE
301
302 return testResult
303
304def installPointIntent( main,
305 name,
306 senders,
307 recipients,
308 onosNode=0,
309 ethType="",
310 bandwidth="",
311 lambdaAlloc=False,
alisonda157272016-12-22 01:13:21 -0800312 protected=False,
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800313 ipProto="",
314 ipSrc="",
315 ipDst="",
316 tcpSrc="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700317 tcpDst="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700318 setVlan="",
319 encap="" ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800320 """
321 Installs a Single to Single Point Intent
322
323 Description:
324 Install a single to single point intent
325
326 Steps:
327 - Fetch host data if not given
328 - Add point intent
329 - Ingress device is the first sender device
330 - Egress device is the first recipient device
331 - Ports if defined in senders or recipients
332 - MAC address ethSrc loaded from Ingress device
333 - Check intent state with retry
334 Required:
335 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
336 senders - List of host dictionaries i.e.
337 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
338 recipients - List of host dictionaries i.e.
339 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
340 Optional:
341 onosNode - ONOS node to install the intents in main.CLIs[ ]
342 0 by default so that it will always use the first
343 ONOS node
344 ethType - Ethernet type eg. IPV4, IPV6
345 bandwidth - Bandwidth capacity
346 lambdaAlloc - Allocate lambda, defaults to False
347 ipProto - IP protocol
348 tcp - TCP ports in the same order as the hosts in hostNames
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700349 sw1 - First switch to bring down & up for rerouting purpose
350 sw2 - Second switch to bring down & up for rerouting purpose
351 expectedLink - Expected link when the switches are down, it should
352 be two links lower than the links before the two
353 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700354 """
355
356 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800357 assert senders, "You must specify a sender"
358 assert recipients, "You must specify a recipient"
359 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700360
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800361 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700362 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700363
Jeremy6f000c62016-02-25 17:02:28 -0800364 main.log.info( itemName + ": Adding point to point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700365
Jeremyd9e4eb12016-04-13 12:09:06 -0700366 try:
367 for sender in senders:
368 if not sender.get( "device" ):
369 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
370 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800371
Jeremyd9e4eb12016-04-13 12:09:06 -0700372 for recipient in recipients:
373 if not recipient.get( "device" ):
374 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
375 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800376
377
Jeremyd9e4eb12016-04-13 12:09:06 -0700378 ingressDevice = senders[ 0 ].get( "device" )
379 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800380
Jeremyd9e4eb12016-04-13 12:09:06 -0700381 portIngress = senders[ 0 ].get( "port", "" )
382 portEgress = recipients[ 0 ].get( "port", "" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800383
Jeremyd9e4eb12016-04-13 12:09:06 -0700384 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800385
Jeremyd9e4eb12016-04-13 12:09:06 -0700386 ipSrc = senders[ 0 ].get( "ip" )
387 ipDst = recipients[ 0 ].get( "ip" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800388
Jeremy Songster832f9e92016-05-05 14:30:49 -0700389 vlanId = senders[ 0 ].get( "vlan" )
390
Jeremyd9e4eb12016-04-13 12:09:06 -0700391 # Adding point intent
392 intentId = main.CLIs[ onosNode ].addPointIntent(
393 ingressDevice=ingressDevice,
394 egressDevice=egressDevice,
395 portIngress=portIngress,
396 portEgress=portEgress,
397 ethType=ethType,
398 ethDst=dstMac,
399 bandwidth=bandwidth,
400 lambdaAlloc=lambdaAlloc,
alisonda157272016-12-22 01:13:21 -0800401 protected=protected,
Jeremyd9e4eb12016-04-13 12:09:06 -0700402 ipProto=ipProto,
403 ipSrc=ipSrc,
404 ipDst=ipDst,
405 tcpSrc=tcpSrc,
Jeremy Songster832f9e92016-05-05 14:30:49 -0700406 tcpDst=tcpDst,
Jeremy Songsterff553672016-05-12 17:06:23 -0700407 vlanId=vlanId,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700408 setVlan=setVlan,
409 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700410 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700411 errorMsg = "There was a problem loading the hosts data."
412 if intentId:
413 errorMsg += " There was a problem installing Point to Point intent."
414 main.log.error( errorMsg )
415 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700416
417 # Check intents state
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700418 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
alison52b25892016-09-19 10:53:48 -0700419 args=( main, [ intentId ] ), sleep=main.checkIntentSleep, attempts=5 ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700420 main.assertReturnString += 'Install Intent State Passed\n'
alison52b25892016-09-19 10:53:48 -0700421
422 # Check VLAN if test encapsulation
423 if encap != "":
424 if EncapsulatedIntentCheck( main, tag=encap ):
425 main.assertReturnString += 'Encapsulation intents check Passed\n'
426 else:
427 main.assertReturnString += 'Encapsulation intents check failed\n'
alisonda157272016-12-22 01:13:21 -0800428
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700429 if flowDuration( main ):
430 main.assertReturnString += 'Flow duration check Passed\n'
431 return intentId
432 else:
433 main.assertReturnString += 'Flow duration check failed\n'
434 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -0700435 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800436 main.log.error( "Point Intent did not install correctly" )
437 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700438
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700439def pointIntentTcp( main,
440 name,
441 host1,
442 host2,
443 onosNode=0,
444 deviceId1="",
445 deviceId2="",
446 port1="",
447 port2="",
448 ethType="",
449 mac1="",
450 mac2="",
451 bandwidth="",
452 lambdaAlloc=False,
453 ipProto="",
454 ip1="",
455 ip2="",
456 tcp1="",
457 tcp2="",
458 sw1="",
459 sw2="",
460 expectedLink=0 ):
461
462 """
463 Description:
464 Verify add-point-intent only for TCP
465 Steps:
466 - Get device ids | ports
467 - Add point intents
468 - Check intents
469 - Verify flows
470 - Ping hosts
471 - Reroute
472 - Link down
473 - Verify flows
474 - Check topology
475 - Ping hosts
476 - Link up
477 - Verify flows
478 - Check topology
479 - Ping hosts
480 - Remove intents
481 Required:
482 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
483 host1 - Name of first host
484 host2 - Name of second host
485 Optional:
486 onosNode - ONOS node to install the intents in main.CLIs[ ]
487 0 by default so that it will always use the first
488 ONOS node
489 deviceId1 - ONOS device id of the first switch, the same as the
490 location of the first host eg. of:0000000000000001/1,
491 located at device 1 port 1
492 deviceId2 - ONOS device id of the second switch
493 port1 - The port number where the first host is attached
494 port2 - The port number where the second host is attached
495 ethType - Ethernet type eg. IPV4, IPV6
496 mac1 - Mac address of first host
497 mac2 - Mac address of the second host
498 bandwidth - Bandwidth capacity
499 lambdaAlloc - Allocate lambda, defaults to False
500 ipProto - IP protocol
501 ip1 - IP address of first host
502 ip2 - IP address of second host
503 tcp1 - TCP port of first host
504 tcp2 - TCP port of second host
505 sw1 - First switch to bring down & up for rerouting purpose
506 sw2 - Second switch to bring down & up for rerouting purpose
507 expectedLink - Expected link when the switches are down, it should
508 be two links lower than the links before the two
509 switches are down
510 """
511
512 assert main, "There is no main variable"
513 assert name, "variable name is empty"
514 assert host1 and host2, "You must specify hosts"
515
516 global itemName
517 itemName = name
518 host1 = host1
519 host2 = host2
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700520 intentsId = []
521
522 iperfResult = main.TRUE
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700523 linkDownResult = main.TRUE
524 linkUpResult = main.TRUE
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700525
526 # Adding bidirectional point intents
527 main.log.info( itemName + ": Adding point intents" )
528 intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
529 egressDevice=deviceId2,
530 portIngress=port1,
531 portEgress=port2,
532 ethType=ethType,
533 ethSrc=mac1,
534 ethDst=mac2,
535 bandwidth=bandwidth,
536 lambdaAlloc=lambdaAlloc,
537 ipProto=ipProto,
538 ipSrc=ip1,
539 ipDst=ip2,
540 tcpSrc=tcp1,
541 tcpDst="" )
542
543 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
544 egressDevice=deviceId1,
545 portIngress=port2,
546 portEgress=port1,
547 ethType=ethType,
548 ethSrc=mac2,
549 ethDst=mac1,
550 bandwidth=bandwidth,
551 lambdaAlloc=lambdaAlloc,
552 ipProto=ipProto,
553 ipSrc=ip2,
554 ipDst=ip1,
555 tcpSrc=tcp2,
556 tcpDst="" )
557
558 intent3 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
559 egressDevice=deviceId2,
560 portIngress=port1,
561 portEgress=port2,
562 ethType=ethType,
563 ethSrc=mac1,
564 ethDst=mac2,
565 bandwidth=bandwidth,
566 lambdaAlloc=lambdaAlloc,
567 ipProto=ipProto,
568 ipSrc=ip1,
569 ipDst=ip2,
570 tcpSrc="",
571 tcpDst=tcp2 )
572
573 intent4 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
574 egressDevice=deviceId1,
575 portIngress=port2,
576 portEgress=port1,
577 ethType=ethType,
578 ethSrc=mac2,
579 ethDst=mac1,
580 bandwidth=bandwidth,
581 lambdaAlloc=lambdaAlloc,
582 ipProto=ipProto,
583 ipSrc=ip2,
584 ipDst=ip1,
585 tcpSrc="",
586 tcpDst=tcp1 )
587 intentsId.append( intent1 )
588 intentsId.append( intent2 )
589 intentsId.append( intent3 )
590 intentsId.append( intent4 )
591
592 # Check intents state
593 time.sleep( main.checkIntentSleep )
594 intentResult = checkIntentState( main, intentsId )
595 # Check flows count in each node
596 checkFlowsCount( main )
597
598 # Check intents state again if first check fails...
599 if not intentResult:
600 intentResult = checkIntentState( main, intentsId )
601
602 # Check flows count in each node
603 checkFlowsCount( main )
604
605 # Verify flows
606 checkFlowsState( main )
607
608 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700609 iperfTemp = main.Mininet1.iperftcp( host1, host2 ,10 )
acsmarsd4862d12015-10-06 17:57:34 -0700610 iperfResult = iperfResult and iperfTemp
611 if iperfTemp:
612 main.assertReturnString += 'Initial Iperf Passed\n'
613 else:
614 main.assertReturnString += 'Initial Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700615
616 # Test rerouting if these variables exist
617 if sw1 and sw2 and expectedLink:
618 # link down
619 linkDownResult = link( main, sw1, sw2, "down" )
acsmarsd4862d12015-10-06 17:57:34 -0700620
621 if linkDownResult:
622 main.assertReturnString += 'Link Down Passed\n'
623 else:
624 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700625
626 # Check flows count in each node
627 checkFlowsCount( main )
628 # Verify flows
629 checkFlowsState( main )
630
631 # Check OnosTopology
632 topoResult = checkTopology( main, expectedLink )
acsmarsd4862d12015-10-06 17:57:34 -0700633 if topoResult:
634 main.assertReturnString += 'Link Down Topology State Passed\n'
635 else:
636 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700637
638 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700639 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700640 iperfResult = iperfResult and iperfTemp
641 if iperfTemp:
642 main.assertReturnString += 'Link Down Iperf Passed\n'
643 else:
644 main.assertReturnString += 'Link Down Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700645
acsmarsd4862d12015-10-06 17:57:34 -0700646 # Check intent state
647 intentTemp = checkIntentState( main, intentsId )
648 intentResult = intentResult and intentTemp
649 if intentTemp:
650 main.assertReturnString += 'Link Down Intent State Passed\n'
651 else:
652 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700653
654 # Checks ONOS state in link down
655 if linkDownResult and topoResult and iperfResult and intentResult:
656 main.log.info( itemName + ": Successfully brought link down" )
657 else:
658 main.log.error( itemName + ": Failed to bring link down" )
659
660 # link up
661 linkUpResult = link( main, sw1, sw2, "up" )
alison52b25892016-09-19 10:53:48 -0700662 if linkUpResult:
acsmarsd4862d12015-10-06 17:57:34 -0700663 main.assertReturnString += 'Link Up Passed\n'
664 else:
665 main.assertReturnString += 'Link Up Failed\n'
666
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700667 time.sleep( main.rerouteSleep )
668
669 # Check flows count in each node
670 checkFlowsCount( main )
671 # Verify flows
672 checkFlowsState( main )
673
674 # Check OnosTopology
675 topoResult = checkTopology( main, main.numLinks )
676
acsmarsd4862d12015-10-06 17:57:34 -0700677 if topoResult:
678 main.assertReturnString += 'Link Up Topology State Passed\n'
679 else:
680 main.assertReturnString += 'Link Up Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700681
acsmarsd4862d12015-10-06 17:57:34 -0700682 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700683 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700684 iperfResult = iperfResult and iperfTemp
685 if iperfTemp:
686 main.assertReturnString += 'Link Up Iperf Passed\n'
687 else:
688 main.assertReturnString += 'Link Up Iperf Failed\n'
689
690 # Check intent state
691 intentTemp = checkIntentState( main, intentsId )
692 intentResult = intentResult and intentTemp
693 if intentTemp:
694 main.assertReturnString += 'Link Down Intent State Passed\n'
695 else:
696 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700697
698 # Checks ONOS state in link up
699 if linkUpResult and topoResult and iperfResult and intentResult:
700 main.log.info( itemName + ": Successfully brought link back up" )
701 else:
702 main.log.error( itemName + ": Failed to bring link back up" )
703
704 # Remove all intents
705 removeIntentResult = removeAllIntents( main, intentsId )
acsmarsd4862d12015-10-06 17:57:34 -0700706 if removeIntentResult:
707 main.assertReturnString += 'Remove Intents Passed'
708 else:
709 main.assertReturnString += 'Remove Intents Failed'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700710
711 stepResult = iperfResult and linkDownResult and linkUpResult \
712 and intentResult and removeIntentResult
713
714 return stepResult
715
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800716def installSingleToMultiIntent( main,
717 name,
718 senders,
719 recipients,
720 onosNode=0,
721 ethType="",
722 bandwidth="",
723 lambdaAlloc=False,
724 ipProto="",
725 ipAddresses="",
726 tcp="",
727 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700728 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -0700729 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700730 partial=False,
731 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700732 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800733 Installs a Single to Multi Point Intent
734
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700735 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800736 Install a single to multi point intent using
737 add-single-to-multi-intent
738
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700739 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800740 - Fetch host data if not given
741 - Add single to multi intent
742 - Ingress device is the first sender host
743 - Egress devices are the recipient devices
744 - Ports if defined in senders or recipients
745 - MAC address ethSrc loaded from Ingress device
746 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700747 Required:
748 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800749 senders - List of host dictionaries i.e.
750 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
751 recipients - List of host dictionaries i.e.
752 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700753 Optional:
754 onosNode - ONOS node to install the intents in main.CLIs[ ]
755 0 by default so that it will always use the first
756 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700757 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700758 bandwidth - Bandwidth capacity
759 lambdaAlloc - Allocate lambda, defaults to False
760 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700761 tcp - TCP ports in the same order as the hosts in hostNames
762 sw1 - First switch to bring down & up for rerouting purpose
763 sw2 - Second switch to bring down & up for rerouting purpose
764 expectedLink - Expected link when the switches are down, it should
765 be two links lower than the links before the two
766 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700767 """
768
769 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800770 assert senders, "You must specify a sender"
771 assert recipients, "You must specify a recipient"
772 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700773
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800774 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700775 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700776
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700777 main.log.info( itemName + ": Adding single point to multi point intents" )
778
Jeremyd9e4eb12016-04-13 12:09:06 -0700779 try:
780 for sender in senders:
781 if not sender.get( "device" ):
782 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
783 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700784
Jeremyd9e4eb12016-04-13 12:09:06 -0700785 for recipient in recipients:
786 if not recipient.get( "device" ):
787 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
788 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700789
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700790
Jeremyd9e4eb12016-04-13 12:09:06 -0700791 ingressDevice = senders[ 0 ].get( "device" )
792 egressDeviceList = [ x.get( "device" ) for x in recipients if x.get( "device" ) ]
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800793
Jeremyd9e4eb12016-04-13 12:09:06 -0700794 portIngress = senders[ 0 ].get( "port", "" )
795 portEgressList = [ x.get( "port" ) for x in recipients if x.get( "port" ) ]
796 if not portEgressList:
797 portEgressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800798
Jeremyd9e4eb12016-04-13 12:09:06 -0700799 srcMac = senders[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700800 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800801
Jeremyd9e4eb12016-04-13 12:09:06 -0700802 # Adding point intent
803 intentId = main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
804 ingressDevice=ingressDevice,
805 egressDeviceList=egressDeviceList,
806 portIngress=portIngress,
807 portEgressList=portEgressList,
808 ethType=ethType,
809 ethSrc=srcMac,
810 bandwidth=bandwidth,
811 lambdaAlloc=lambdaAlloc,
812 ipProto=ipProto,
813 ipSrc="",
814 ipDst="",
815 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -0700816 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700817 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -0700818 setVlan=setVlan,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700819 partial=partial,
820 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700821 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700822 errorMsg = "There was a problem loading the hosts data."
823 if intentId:
824 errorMsg += " There was a problem installing Singlepoint to Multipoint intent."
825 main.log.error( errorMsg )
826 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700827
828 # Check intents state
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700829 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
830 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
831 main.assertReturnString += 'Install Intent State Passed\n'
832 if flowDuration( main ):
833 main.assertReturnString += 'Flow duration check Passed\n'
834 return intentId
835 else:
836 main.assertReturnString += 'Flow duration check failed\n'
837 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -0700838 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800839 main.log.error( "Single to Multi Intent did not install correctly" )
840 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700841
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800842def installMultiToSingleIntent( main,
843 name,
844 senders,
845 recipients,
846 onosNode=0,
847 ethType="",
848 bandwidth="",
849 lambdaAlloc=False,
850 ipProto="",
851 ipAddresses="",
852 tcp="",
853 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700854 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -0700855 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700856 partial=False,
857 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700858 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800859 Installs a Multi to Single Point Intent
860
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700861 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800862 Install a multi to single point intent using
863 add-multi-to-single-intent
864
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700865 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800866 - Fetch host data if not given
867 - Add multi to single intent
868 - Ingress devices are the senders devices
869 - Egress device is the first recipient host
870 - Ports if defined in senders or recipients
871 - MAC address ethSrc loaded from Ingress device
872 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700873 Required:
874 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800875 senders - List of host dictionaries i.e.
876 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
877 recipients - List of host dictionaries i.e.
878 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700879 Optional:
880 onosNode - ONOS node to install the intents in main.CLIs[ ]
881 0 by default so that it will always use the first
882 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700883 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700884 bandwidth - Bandwidth capacity
885 lambdaAlloc - Allocate lambda, defaults to False
886 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700887 tcp - TCP ports in the same order as the hosts in hostNames
888 sw1 - First switch to bring down & up for rerouting purpose
889 sw2 - Second switch to bring down & up for rerouting purpose
890 expectedLink - Expected link when the switches are down, it should
891 be two links lower than the links before the two
892 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700893 """
894
895 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800896 assert senders, "You must specify a sender"
897 assert recipients, "You must specify a recipient"
898 # Assert devices or main.hostsData, "You must specify devices"
899
900 global itemName # The name of this run. Used for logs.
901 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800902
903 main.log.info( itemName + ": Adding mutli to single point intents" )
904
Jeremyd9e4eb12016-04-13 12:09:06 -0700905 try:
906 for sender in senders:
907 if not sender.get( "device" ):
908 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
909 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800910
Jeremyd9e4eb12016-04-13 12:09:06 -0700911 for recipient in recipients:
912 if not recipient.get( "device" ):
913 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
914 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800915
Jeremyd9e4eb12016-04-13 12:09:06 -0700916 ingressDeviceList = [ x.get( "device" ) for x in senders if x.get( "device" ) ]
917 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800918
Jeremyd9e4eb12016-04-13 12:09:06 -0700919 portIngressList = [ x.get( "port" ) for x in senders if x.get( "port" ) ]
920 portEgress = recipients[ 0 ].get( "port", "" )
921 if not portIngressList:
922 portIngressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800923
Jeremyd9e4eb12016-04-13 12:09:06 -0700924 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700925 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800926
Jeremyd9e4eb12016-04-13 12:09:06 -0700927 # Adding point intent
928 intentId = main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
929 ingressDeviceList=ingressDeviceList,
930 egressDevice=egressDevice,
931 portIngressList=portIngressList,
932 portEgress=portEgress,
933 ethType=ethType,
934 ethDst=dstMac,
935 bandwidth=bandwidth,
936 lambdaAlloc=lambdaAlloc,
937 ipProto=ipProto,
938 ipSrc="",
939 ipDst="",
940 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -0700941 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700942 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -0700943 setVlan=setVlan,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700944 partial=partial,
945 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700946 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700947 errorMsg = "There was a problem loading the hosts data."
948 if intentId:
949 errorMsg += " There was a problem installing Multipoint to Singlepoint intent."
950 main.log.error( errorMsg )
951 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800952
953 # Check intents state
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700954 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
955 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
956 main.assertReturnString += 'Install Intent State Passed\n'
957 if flowDuration( main ):
958 main.assertReturnString += 'Flow duration check Passed\n'
959 return intentId
960 else:
961 main.assertReturnString += 'Flow duration check failed\n'
962 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800963 else:
964 main.log.error( "Multi to Single Intent did not install correctly" )
965 return main.FALSE
966
967def testPointIntent( main,
Jeremye0cb5eb2016-01-27 17:39:09 -0800968 name,
969 intentId,
970 senders,
971 recipients,
972 badSenders={},
973 badRecipients={},
974 onosNode=0,
975 ethType="",
976 bandwidth="",
977 lambdaAlloc=False,
alisonda157272016-12-22 01:13:21 -0800978 protected=False,
Jeremye0cb5eb2016-01-27 17:39:09 -0800979 ipProto="",
980 ipAddresses="",
981 tcp="",
982 sw1="s5",
983 sw2="s2",
Jeremy Songstere405d3d2016-05-17 11:18:57 -0700984 expectedLink=0,
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700985 useTCP=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800986 """
987 Test a Point Intent
988
989 Description:
990 Test a point intent
991
992 Steps:
993 - Fetch host data if not given
994 - Check Intent State
995 - Check Flow State
996 - Check Connectivity
997 - Check Lack of Connectivity Between Hosts not in the Intent
998 - Reroute
999 - Take Expected Link Down
1000 - Check Intent State
1001 - Check Flow State
1002 - Check Topology
1003 - Check Connectivity
1004 - Bring Expected Link Up
1005 - Check Intent State
1006 - Check Flow State
1007 - Check Topology
1008 - Check Connectivity
1009 - Remove Topology
1010
1011 Required:
1012 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
1013
1014 senders - List of host dictionaries i.e.
1015 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
1016 recipients - List of host dictionaries i.e.
1017 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
1018 Optional:
1019 onosNode - ONOS node to install the intents in main.CLIs[ ]
1020 0 by default so that it will always use the first
1021 ONOS node
1022 ethType - Ethernet type eg. IPV4, IPV6
1023 bandwidth - Bandwidth capacity
1024 lambdaAlloc - Allocate lambda, defaults to False
1025 ipProto - IP protocol
1026 tcp - TCP ports in the same order as the hosts in hostNames
1027 sw1 - First switch to bring down & up for rerouting purpose
1028 sw2 - Second switch to bring down & up for rerouting purpose
1029 expectedLink - Expected link when the switches are down, it should
1030 be two links lower than the links before the two
1031 switches are down
1032
1033 """
1034
1035 # Parameter Validity Check
1036 assert main, "There is no main variable"
1037 assert senders, "You must specify a sender"
1038 assert recipients, "You must specify a recipient"
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001039
1040 global itemName
1041 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001042
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001043 main.log.info( itemName + ": Testing Point Intent" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001044
Jeremyd9e4eb12016-04-13 12:09:06 -07001045 try:
1046 # Names for scapy
1047 senderNames = [ x.get( "name" ) for x in senders ]
1048 recipientNames = [ x.get( "name" ) for x in recipients ]
1049 badSenderNames = [ x.get( "name" ) for x in badSenders ]
1050 badRecipientNames = [ x.get( "name" ) for x in badRecipients ]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001051
Jeremyd9e4eb12016-04-13 12:09:06 -07001052 for sender in senders:
1053 if not sender.get( "device" ):
1054 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1055 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001056
Jeremyd9e4eb12016-04-13 12:09:06 -07001057 for recipient in recipients:
1058 if not recipient.get( "device" ):
1059 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1060 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001061 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001062 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001063 main.log.error( "There was a problem loading the hosts data." )
1064 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001065
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001066 testResult = main.TRUE
1067 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001068
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001069 # Check intent state
1070 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1071 main.assertReturnString += 'Initial Intent State Passed\n'
acsmarsd4862d12015-10-06 17:57:34 -07001072 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001073 main.assertReturnString += 'Initial Intent State Failed\n'
1074 testResult = main.FALSE
1075
1076 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -07001077 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001078 main.assertReturnString += 'Initial Flow State Passed\n'
1079 else:
1080 main.assertReturnString += 'Intial Flow State Failed\n'
1081 testResult = main.FALSE
1082
1083 # Check Connectivity
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001084 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId, useTCP ), attempts=3, sleep=5 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001085 main.assertReturnString += 'Initial Ping Passed\n'
1086 else:
1087 main.assertReturnString += 'Initial Ping Failed\n'
1088 testResult = main.FALSE
1089
1090 # Check connections that shouldn't work
1091 if badSenderNames:
1092 main.log.info( "Checking that packets from incorrect sender do not go through" )
1093 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, badSenderNames, recipientNames ), kwargs={ "expectFailure":True } ):
1094 main.assertReturnString += 'Bad Sender Ping Passed\n'
1095 else:
1096 main.assertReturnString += 'Bad Sender Ping Failed\n'
1097 testResult = main.FALSE
1098
1099 if badRecipientNames:
1100 main.log.info( "Checking that packets to incorrect recipients do not go through" )
1101 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, badRecipientNames ), kwargs={ "expectFailure":True } ):
1102 main.assertReturnString += 'Bad Recipient Ping Passed\n'
1103 else:
1104 main.assertReturnString += 'Bad Recipient Ping Failed\n'
1105 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001106
1107 # Test rerouting if these variables exist
1108 if sw1 and sw2 and expectedLink:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001109 # Take link down
1110 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001111 main.assertReturnString += 'Link Down Passed\n'
1112 else:
1113 main.assertReturnString += 'Link Down Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001114 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001115
alisonda157272016-12-22 01:13:21 -08001116 if protected:
1117 # Check Connection
1118 if utilities.retry(f=scapyCheckConnection, retValue=main.FALSE,
1119 args=(main, senderNames, recipientNames, vlanId, useTCP) ):
1120 main.assertReturnString += 'Link down Scapy Packet Received Passed\n'
1121 else:
1122 main.assertReturnString += 'Link down Scapy Packet Recieved Failed\n'
1123 testResult = main.FALSE
1124
1125 if ProtectedIntentCheck( main ):
1126 main.assertReturnString += 'Protected Intent Check Passed\n'
1127 else:
1128 main.assertReturnString += 'Protected Intent Check Failed\n'
1129 testResult = main.FALSE
1130
acsmarsd4862d12015-10-06 17:57:34 -07001131 # Check intent state
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001132 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001133 main.assertReturnString += 'Link Down Intent State Passed\n'
1134 else:
1135 main.assertReturnString += 'Link Down Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001136 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001137
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001138 # Check flows count in each node
Jeremy Songsterc032f162016-08-04 17:14:49 -07001139 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=5 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=5 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001140 main.assertReturnString += 'Link Down Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001141 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001142 main.assertReturnString += 'Link Down Flow State Failed\n'
1143 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001144
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001145 # Check OnosTopology
1146 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink ) ):
1147 main.assertReturnString += 'Link Down Topology State Passed\n'
1148 else:
1149 main.assertReturnString += 'Link Down Topology State Failed\n'
1150 testResult = main.FALSE
1151
1152 # Check Connection
alison52b25892016-09-19 10:53:48 -07001153 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId, useTCP ), sleep=5, attempts=5 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001154 main.assertReturnString += 'Link Down Pingall Passed\n'
1155 else:
1156 main.assertReturnString += 'Link Down Pingall Failed\n'
1157 testResult = main.FALSE
1158
1159 # Bring link up
1160 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001161 main.assertReturnString += 'Link Up Passed\n'
1162 else:
1163 main.assertReturnString += 'Link Up Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001164 testResult = main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -07001165
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001166 # Wait for reroute
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001167 time.sleep( main.rerouteSleep )
1168
acsmarsd4862d12015-10-06 17:57:34 -07001169 # Check Intents
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001170 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001171 main.assertReturnString += 'Link Up Intent State Passed\n'
1172 else:
1173 main.assertReturnString += 'Link Up Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001174 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001175
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001176 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -07001177 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001178 main.assertReturnString += 'Link Up Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001179 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001180 main.assertReturnString += 'Link Up Flow State Failed\n'
1181 testResult = main.FALSE
1182
1183 # Check OnosTopology
1184 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
1185 main.assertReturnString += 'Link Up Topology State Passed\n'
1186 else:
1187 main.assertReturnString += 'Link Up Topology State Failed\n'
1188 testResult = main.FALSE
1189
1190 # Check Connection
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001191 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001192 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1193 else:
1194 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1195 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001196
1197 # Remove all intents
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001198 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001199 main.assertReturnString += 'Remove Intents Passed'
1200 else:
1201 main.assertReturnString += 'Remove Intents Failed'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001202 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001203
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001204 return testResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001205
Jeremye0cb5eb2016-01-27 17:39:09 -08001206def testEndPointFail( main,
1207 name,
1208 intentId,
1209 senders,
1210 recipients,
1211 isolatedSenders,
1212 isolatedRecipients,
1213 onosNode=0,
1214 ethType="",
1215 bandwidth="",
1216 lambdaAlloc=False,
1217 ipProto="",
1218 ipAddresses="",
1219 tcp="",
1220 sw1="",
1221 sw2="",
1222 sw3="",
1223 sw4="",
1224 sw5="",
1225 expectedLink1=0,
Jeremy Songster9385d412016-06-02 17:57:36 -07001226 expectedLink2=0,
1227 partial=False ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001228 """
1229 Test Single to Multipoint Topology for Endpoint failures
1230 """
1231
1232 # Parameter Validity Check
1233 assert main, "There is no main variable"
1234 assert senders, "You must specify a sender"
1235 assert recipients, "You must specify a recipient"
1236
1237 global itemName
1238 itemName = name
Jeremye0cb5eb2016-01-27 17:39:09 -08001239
1240 main.log.info( itemName + ": Testing Point Intent" )
1241
Jeremyd9e4eb12016-04-13 12:09:06 -07001242 try:
1243 # Names for scapy
1244 senderNames = [ x.get( "name" ) for x in senders ]
1245 recipientNames = [ x.get( "name" ) for x in recipients ]
1246 isolatedSenderNames = [ x.get( "name" ) for x in isolatedSenders ]
1247 isolatedRecipientNames = [ x.get( "name" ) for x in isolatedRecipients ]
1248 connectedSenderNames = [x.get("name") for x in senders if x.get("name") not in isolatedSenderNames]
1249 connectedRecipientNames = [x.get("name") for x in recipients if x.get("name") not in isolatedRecipientNames]
Jeremye0cb5eb2016-01-27 17:39:09 -08001250
Jeremyd9e4eb12016-04-13 12:09:06 -07001251 for sender in senders:
1252 if not sender.get( "device" ):
1253 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1254 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremye0cb5eb2016-01-27 17:39:09 -08001255
Jeremyd9e4eb12016-04-13 12:09:06 -07001256 for recipient in recipients:
1257 if not recipient.get( "device" ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001258 main.log.warn( "Device not given for recipient {0}. Loading from " +\
1259 main.hostData.format( recipient.get( "name" ) ) )
Jeremyd9e4eb12016-04-13 12:09:06 -07001260 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001261 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001262 main.log.error( "There was a problem loading the hosts data." )
1263 return main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001264
1265 testResult = main.TRUE
1266 main.log.info( itemName + ": Adding multi point to single point intents" )
1267
1268 # Check intent state
1269 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1270 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1271 main.assertReturnString += 'Initial Intent State Passed\n'
1272 else:
1273 main.assertReturnString += 'Initial Intent State Failed\n'
1274 testResult = main.FALSE
1275
1276 # Check flows count in each node
1277 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
Jeremy Songster9385d412016-06-02 17:57:36 -07001278 args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState,
1279 retValue=main.FALSE,
1280 args=[ main ], attempts=5 ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001281 main.assertReturnString += 'Initial Flow State Passed\n'
1282 else:
1283 main.assertReturnString += 'Intial Flow State Failed\n'
1284 testResult = main.FALSE
1285
1286 # Check Connectivity
1287 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1288 args=( main, senderNames, recipientNames ) ):
1289 main.assertReturnString += 'Initial Connectivity Check Passed\n'
1290 else:
1291 main.assertReturnString += 'Initial Connectivity Check Failed\n'
1292 testResult = main.FALSE
1293
1294 # Take two links down
1295 # Take first link down
1296 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
1297 main.assertReturnString += 'Link Down Passed\n'
1298 else:
1299 main.assertReturnString += 'Link Down Failed\n'
1300 testResult = main.FALSE
1301
1302 # Take second link down
1303 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw4, "down" ) ):
1304 main.assertReturnString += 'Link Down Passed\n'
1305 else:
1306 main.assertReturnString += 'Link Down Failed\n'
1307 testResult = main.FALSE
1308
1309 # Check intent state
1310 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1311 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1312 main.assertReturnString += 'Link Down Intent State Passed\n'
1313 else:
1314 main.assertReturnString += 'Link Down Intent State Failed\n'
1315 testResult = main.FALSE
1316
1317 # Check flows count in each node
1318 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1319 args=[ main ] ) and utilities.retry( f=checkFlowsState,
1320 retValue=main.FALSE, args=[ main ] ):
1321 main.assertReturnString += 'Link Down Flow State Passed\n'
1322 else:
1323 main.assertReturnString += 'Link Down Flow State Failed\n'
1324 testResult = main.FALSE
1325
1326 # Check OnosTopology
1327 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink1 ) ):
1328 main.assertReturnString += 'Link Down Topology State Passed\n'
1329 else:
1330 main.assertReturnString += 'Link Down Topology State Failed\n'
1331 testResult = main.FALSE
1332
1333 # Check Connection
1334 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1335 args=( main, senderNames, recipientNames ) ):
1336 main.assertReturnString += 'Link Down Connectivity Check Passed\n'
1337 else:
1338 main.assertReturnString += 'Link Down Connectivity Check Failed\n'
1339 testResult = main.FALSE
1340
1341 # Take a third link down to isolate one node
1342 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw5, "down" ) ):
1343 main.assertReturnString += 'Isolation link Down Passed\n'
1344 else:
1345 main.assertReturnString += 'Isolation link Down Failed\n'
1346 testResult = main.FALSE
1347
Jeremy Songster9385d412016-06-02 17:57:36 -07001348 if partial:
1349 # Check intent state
1350 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1351 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1352 main.assertReturnString += 'Partial failure isolation link Down Intent State Passed\n'
1353 else:
1354 main.assertReturnString += 'Partial failure isolation link Down Intent State Failed\n'
1355 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001356
Jeremy Songster9385d412016-06-02 17:57:36 -07001357 # Check flows count in each node
1358 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1359 args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState,
1360 retValue=main.FALSE,
1361 args=[ main ], attempts=5 ):
1362 main.assertReturnString += 'Partial failure isolation link Down Flow State Passed\n'
1363 else:
1364 main.assertReturnString += 'Partial failure isolation link Down Flow State Failed\n'
1365 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001366
Jeremy Songster9385d412016-06-02 17:57:36 -07001367 # Check OnosTopology
1368 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink2 ) ):
1369 main.assertReturnString += 'Partial failure isolation link Down Topology State Passed\n'
1370 else:
1371 main.assertReturnString += 'Partial failure isolation link Down Topology State Failed\n'
1372 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001373
Jeremy Songster9385d412016-06-02 17:57:36 -07001374 # Check Connectivity
1375 # First check connectivity of any isolated senders to recipients
1376 if isolatedSenderNames:
1377 if scapyCheckConnection( main, isolatedSenderNames, recipientNames, None, None, None, None, main.TRUE ):
1378 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1379 else:
1380 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1381 testResult = main.FALSE
1382
1383 # Next check connectivity of senders to any isolated recipients
1384 if isolatedRecipientNames:
1385 if scapyCheckConnection( main, senderNames, isolatedRecipientNames, None, None, None, None, main.TRUE ):
1386 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1387 else:
1388 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1389 testResult = main.FALSE
1390
1391 # Next check connectivity of connected senders and recipients
1392 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1393 args=( main, connectedSenderNames , connectedRecipientNames ) ):
1394 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1395 else:
1396 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1397 testResult = main.FALSE
1398 else:
1399 # Check intent state
1400 if not utilities.retry( f=checkIntentState, retValue=main.TRUE,
1401 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1402 main.assertReturnString += 'Isolation link Down Intent State Passed\n'
1403 else:
1404 main.assertReturnString += 'Isolation link Down Intent State Failed\n'
1405 testResult = main.FALSE
1406
1407 # Check flows count in each node
1408 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1409 args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState,
1410 retValue=main.FALSE,
1411 args=[ main ], attempts=5 ):
1412 main.assertReturnString += 'Isolation link Down Flow State Passed\n'
1413 else:
1414 main.assertReturnString += 'Isolation link Down Flow State Failed\n'
1415 testResult = main.FALSE
1416
1417 # Check OnosTopology
1418 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink2 ) ):
1419 main.assertReturnString += 'Isolation link Down Topology State Passed\n'
1420 else:
1421 main.assertReturnString += 'Isolation link Down Topology State Failed\n'
1422 testResult = main.FALSE
1423
1424 # Check Connectivity
1425 # First check connectivity of any isolated senders to recipients
1426 if isolatedSenderNames:
1427 if scapyCheckConnection( main, isolatedSenderNames, recipientNames, None, None, None, None, main.TRUE ):
1428 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1429 else:
1430 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1431 testResult = main.FALSE
1432
1433 # Next check connectivity of senders to any isolated recipients
1434 if isolatedRecipientNames:
1435 if scapyCheckConnection( main, senderNames, isolatedRecipientNames, None, None, None, None, main.TRUE ):
1436 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1437 else:
1438 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1439 testResult = main.FALSE
1440
1441 # Next check connectivity of connected senders and recipients
1442 if utilities.retry( f=scapyCheckConnection, retValue=main.TRUE,
1443 args=( main, connectedSenderNames , connectedRecipientNames, None, None, None, None, main.TRUE ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001444 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1445 else:
1446 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1447 testResult = main.FALSE
1448
Jeremye0cb5eb2016-01-27 17:39:09 -08001449 # Bring the links back up
1450 # Bring first link up
1451 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
1452 main.assertReturnString += 'Link Up Passed\n'
1453 else:
1454 main.assertReturnString += 'Link Up Failed\n'
1455 testResult = main.FALSE
1456
1457 # Bring second link up
1458 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw5, "up" ) ):
1459 main.assertReturnString += 'Link Up Passed\n'
1460 else:
1461 main.assertReturnString += 'Link Up Failed\n'
1462 testResult = main.FALSE
1463
1464 # Bring third link up
1465 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw4, "up" ) ):
1466 main.assertReturnString += 'Link Up Passed\n'
1467 else:
1468 main.assertReturnString += 'Link Up Failed\n'
1469 testResult = main.FALSE
1470
1471 # Wait for reroute
1472 time.sleep( main.rerouteSleep )
1473
1474 # Check Intents
1475 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1476 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1477 main.assertReturnString += 'Link Up Intent State Passed\n'
1478 else:
1479 main.assertReturnString += 'Link Up Intent State Failed\n'
1480 testResult = main.FALSE
1481
1482 # Check flows count in each node
1483 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
Jeremy Songster9385d412016-06-02 17:57:36 -07001484 args=[ main ], sleep=5, attempts=5 ) and utilities.retry( f=checkFlowsState,
1485 retValue=main.FALSE,
1486 args=[ main ], sleep=5, attempts=5 ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001487 main.assertReturnString += 'Link Up Flow State Passed\n'
1488 else:
1489 main.assertReturnString += 'Link Up Flow State Failed\n'
1490 testResult = main.FALSE
1491
1492 # Check OnosTopology
1493 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
1494 main.assertReturnString += 'Link Up Topology State Passed\n'
1495 else:
1496 main.assertReturnString += 'Link Up Topology State Failed\n'
1497 testResult = main.FALSE
1498
1499 # Check Connection
1500 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1501 args=( main, senderNames, recipientNames ) ):
1502 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1503 else:
1504 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1505 testResult = main.FALSE
1506
1507 # Remove all intents
1508 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ):
1509 main.assertReturnString += 'Remove Intents Passed'
1510 else:
1511 main.assertReturnString += 'Remove Intents Failed'
1512 testResult = main.FALSE
1513
1514 return testResult
1515
1516
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001517def pingallHosts( main, hostList ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001518 """
1519 Ping all host in the hosts list variable
1520 """
Jon Halla5cb3412015-08-18 14:08:22 -07001521 main.log.info( "Pinging: " + str( hostList ) )
1522 return main.Mininet1.pingallHosts( hostList )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001523
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001524def fwdPingall( main ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001525 """
1526 Use fwd app and pingall to discover all the hosts
1527 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001528 appCheck = main.TRUE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001529 main.log.info( "Activating reactive forwarding app " )
1530 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001531
1532 # Wait for forward app activation to propagate
kelvin-onlab0ad05d12015-07-23 14:21:15 -07001533 time.sleep( main.fwdSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001534
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001535 # Check that forwarding is enabled on all nodes
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001536 for i in range( main.numCtrls ):
1537 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
1538 if appCheck != main.TRUE:
1539 main.log.warn( main.CLIs[ i ].apps() )
1540 main.log.warn( main.CLIs[ i ].appIDs() )
1541
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001542 # Send pingall in mininet
1543 main.log.info( "Run Pingall" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001544 pingResult = main.Mininet1.pingall( timeout = 600 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001545
1546 main.log.info( "Deactivating reactive forwarding app " )
1547 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001548 if activateResult and deactivateResult:
1549 main.log.info( "Successfully used fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001550 getDataResult = main.TRUE
1551 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001552 main.log.info( "Failed to use fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001553 getDataResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001554 return getDataResult
1555
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001556def confirmHostDiscovery( main ):
1557 """
1558 Confirms that all ONOS nodes have discovered all scapy hosts
1559 """
1560 import collections
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001561 hosts = main.topo.getAllHosts( main ) # Get host data from each ONOS node
1562 hostFails = [] # Reset for each failed attempt
1563
1564 # Check for matching hosts on each node
1565 scapyHostIPs = [ x.hostIp for x in main.scapyHosts if x.hostIp != "0.0.0.0" ]
1566 for controller in range( main.numCtrls ):
1567 controllerStr = str( controller + 1 ) # ONOS node number
1568 # Compare Hosts
1569 # Load hosts data for controller node
Jeremyd9e4eb12016-04-13 12:09:06 -07001570 try:
1571 if hosts[ controller ]:
1572 main.log.info( "Hosts discovered" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001573 else:
Jeremyd9e4eb12016-04-13 12:09:06 -07001574 main.log.error( "Problem discovering hosts" )
1575 if hosts[ controller ] and "Error" not in hosts[ controller ]:
1576 try:
1577 hostData = json.loads( hosts[ controller ] )
1578 except ( TypeError, ValueError ):
1579 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001580 hostFails.append( controllerStr )
Jeremyd9e4eb12016-04-13 12:09:06 -07001581 else:
1582 onosHostIPs = [ x.get( "ipAddresses" )[ 0 ]
1583 for x in hostData
1584 if len( x.get( "ipAddresses" ) ) > 0 ]
1585 if not set( collections.Counter( scapyHostIPs ) ).issubset( set ( collections.Counter( onosHostIPs ) ) ):
1586 main.log.warn( "Controller {0} only sees nodes with {1} IPs. It should see all of the following: {2}".format( controllerStr, onosHostIPs, scapyHostIPs ) )
1587 hostFails.append( controllerStr )
1588 else:
1589 main.log.error( "Hosts returned nothing or an error." )
1590 hostFails.append( controllerStr )
1591 except IndexError:
1592 main.log.error( "Hosts returned nothing, Failed to discover hosts." )
1593 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001594
1595 if hostFails:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001596 main.log.error( "List of failed ONOS Nodes:" + ', '.join( map( str, hostFails ) ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001597 return main.FALSE
1598 else:
1599 return main.TRUE
1600
1601def sendDiscoveryArp( main, hosts=None ):
1602 """
1603 Sends Discovery ARP packets from each host provided
1604 Defaults to each host in main.scapyHosts
1605 """
1606 # Send an arp ping from each host
1607 if not hosts:
1608 hosts = main.scapyHosts
1609 for host in hosts:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001610 pkt = 'Ether( src="{0}")/ARP( psrc="{1}")'.format( host.hostMac, host.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001611 # Send from the VLAN interface if there is one so ONOS discovers the VLAN correctly
1612 iface = None
1613 for interface in host.getIfList():
1614 if '.' in interface:
1615 main.log.debug( "Detected VLAN interface {0}. Sending ARP packet from {0}".format( interface ) )
1616 iface = interface
1617 break
1618 host.sendPacket( packet=pkt, iface=iface )
1619 main.log.info( "Sending ARP packet from {0}".format( host.name ) )
1620
1621def populateHostData( main ):
1622 """
1623 Populates hostsData
1624 """
1625 import json
1626 try:
1627 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
1628 hosts = main.Mininet1.getHosts().keys()
1629 # TODO: Make better use of new getHosts function
1630 for host in hosts:
1631 main.hostsData[ host ] = {}
1632 main.hostsData[ host ][ 'mac' ] = \
1633 main.Mininet1.getMacAddress( host ).upper()
1634 for hostj in hostsJson:
1635 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
1636 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
1637 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
1638 main.hostsData[ host ][ 'location' ] = \
1639 hostj[ 'location' ][ 'elementId' ] + '/' + \
1640 hostj[ 'location' ][ 'port' ]
1641 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
1642 return main.TRUE
Jeremyd9e4eb12016-04-13 12:09:06 -07001643 except ValueError:
1644 main.log.error( "ValueError while populating hostsData" )
1645 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001646 except KeyError:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001647 main.log.error( "KeyError while populating hostsData" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001648 return main.FALSE
Jeremyd9e4eb12016-04-13 12:09:06 -07001649 except IndexError:
1650 main.log.error( "IndexError while populating hostsData" )
1651 return main.FALSE
1652 except TypeError:
1653 main.log.error( "TypeError while populating hostsData" )
1654 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001655
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001656def checkTopology( main, expectedLink ):
1657 statusResult = main.TRUE
1658 # Check onos topology
1659 main.log.info( itemName + ": Checking ONOS topology " )
1660
1661 for i in range( main.numCtrls ):
Flavio Castro82ee2f62016-06-07 15:04:12 -07001662 statusResult = main.CLIs[ i ].checkStatus( main.numSwitch,
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001663 expectedLink )\
1664 and statusResult
1665 if not statusResult:
1666 main.log.error( itemName + ": Topology mismatch" )
1667 else:
1668 main.log.info( itemName + ": Topology match" )
1669 return statusResult
1670
1671def checkIntentState( main, intentsId ):
1672 """
1673 This function will check intent state to make sure all the intents
1674 are in INSTALLED state
1675 """
1676
1677 intentResult = main.TRUE
1678 results = []
1679
1680 main.log.info( itemName + ": Checking intents state" )
1681 # First check of intents
1682 for i in range( main.numCtrls ):
1683 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
1684 results.append( tempResult )
1685
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001686 if all( result == main.TRUE for result in results ):
1687 main.log.info( itemName + ": Intents are installed correctly" )
1688 else:
1689 # Wait for at least 5 second before checking the intents again
acsmarsb9a92692015-10-08 16:43:01 -07001690 main.log.error( "Intents are not installed correctly. Waiting 5 sec" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001691 time.sleep( 5 )
1692 results = []
1693 # Second check of intents since some of the intents may be in
1694 # INSTALLING state, they should be in INSTALLED at this time
1695 for i in range( main.numCtrls ):
Jeremy2f190ca2016-01-29 15:23:57 -08001696 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001697 results.append( tempResult )
1698 if all( result == main.TRUE for result in results ):
1699 main.log.info( itemName + ": Intents are installed correctly" )
acsmarsb9a92692015-10-08 16:43:01 -07001700 intentResult = main.TRUE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001701 else:
1702 main.log.error( itemName + ": Intents are NOT installed correctly" )
1703 intentResult = main.FALSE
1704
1705 return intentResult
1706
1707def checkFlowsState( main ):
1708
1709 main.log.info( itemName + ": Check flows state" )
Jeremy Songsterff553672016-05-12 17:06:23 -07001710 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState( isPENDING=False )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001711 return checkFlowsResult
1712
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001713def link( main, sw1, sw2, option ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001714
1715 # link down
alison52b25892016-09-19 10:53:48 -07001716 main.log.info( itemName + ": Bring link " + option + " between " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001717 sw1 + " and " + sw2 )
1718 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
1719 return linkResult
1720
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001721def scapyCheckConnection( main, senders, recipients, vlanId=None, useTCP=False, packet=None, packetFilter=None, expectFailure=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001722 """
1723 Checks the connectivity between all given sender hosts and all given recipient hosts
1724 Packet may be specified. Defaults to Ether/IP packet
1725 Packet Filter may be specified. Defaults to Ether/IP from current sender MAC
1726 Todo: Optional packet and packet filter attributes for sender and recipients
1727 Expect Failure when the sender and recipient are not supposed to have connectivity
1728 Timeout of 1 second, returns main.TRUE if the filter is not triggered and kills the filter
1729
1730 """
1731 connectionsFunctional = main.TRUE
1732
1733 if not packetFilter:
1734 packetFilter = 'ether host {}'
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001735 if useTCP:
1736 packetFilter += ' ip proto \\tcp tcp port {}'.format(main.params[ 'SDNIP' ][ 'dstPort' ])
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001737 if expectFailure:
1738 timeout = 1
1739 else:
1740 timeout = 10
1741
1742 for sender in senders:
1743 try:
1744 senderComp = getattr( main, sender )
1745 except AttributeError:
1746 main.log.error( "main has no attribute {}".format( sender ) )
1747 connectionsFunctional = main.FALSE
1748 continue
1749
1750 for recipient in recipients:
1751 # Do not send packets to self since recipient CLI will already be busy
1752 if recipient == sender:
1753 continue
1754 try:
1755 recipientComp = getattr( main, recipient )
1756 except AttributeError:
1757 main.log.error( "main has no attribute {}".format( recipient ) )
1758 connectionsFunctional = main.FALSE
1759 continue
1760
Jeremy Songster832f9e92016-05-05 14:30:49 -07001761 if vlanId:
1762 recipientComp.startFilter( pktFilter = ( "vlan {}".format( vlanId ) + " && " + packetFilter.format( senderComp.hostMac ) ) )
1763 else:
1764 recipientComp.startFilter( pktFilter = packetFilter.format( senderComp.hostMac ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001765
1766 if not packet:
Jeremy Songster832f9e92016-05-05 14:30:49 -07001767 if vlanId:
1768 pkt = 'Ether( src="{0}", dst="{2}" )/Dot1Q(vlan={4})/IP( src="{1}", dst="{3}" )'.format(
1769 senderComp.hostMac,
1770 senderComp.hostIp,
1771 recipientComp.hostMac,
1772 recipientComp.hostIp,
1773 vlanId )
1774 else:
1775 pkt = 'Ether( src="{0}", dst="{2}" )/IP( src="{1}", dst="{3}" )'.format(
1776 senderComp.hostMac,
1777 senderComp.hostIp,
1778 recipientComp.hostMac,
1779 recipientComp.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001780 else:
1781 pkt = packet
Jeremy Songster832f9e92016-05-05 14:30:49 -07001782 if vlanId:
1783 senderComp.sendPacket( iface=( "{0}-eth0.{1}".format( sender, vlanId ) ), packet = pkt )
1784 else:
1785 senderComp.sendPacket( packet = pkt )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001786
1787 if recipientComp.checkFilter( timeout ):
1788 if expectFailure:
1789 main.log.error( "Packet from {0} successfully received by {1} when it should not have been".format( sender , recipient ) )
1790 connectionsFunctional = main.FALSE
1791 else:
1792 main.log.info( "Packet from {0} successfully received by {1}".format( sender , recipient ) )
alison52b25892016-09-19 10:53:48 -07001793 connectionsFunctional = main.TRUE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001794 else:
1795 recipientComp.killFilter()
1796 if expectFailure:
1797 main.log.info( "As expected, packet from {0} was not received by {1}".format( sender , recipient ) )
1798 else:
1799 main.log.error( "Packet from {0} was not received by {1}".format( sender , recipient ) )
1800 connectionsFunctional = main.FALSE
1801
1802 return connectionsFunctional
1803
alison52b25892016-09-19 10:53:48 -07001804
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001805def removeAllIntents( main, intentsId ):
1806 """
1807 Remove all intents in the intentsId
1808 """
1809
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001810 onosSummary = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001811 removeIntentResult = main.TRUE
1812 # Remove intents
1813 for intent in intentsId:
1814 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
1815
acsmarscfa52272015-08-06 15:21:45 -07001816 time.sleep( main.removeIntentSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001817
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001818 # If there is remianing intents then remove intents should fail
1819 for i in range( main.numCtrls ):
1820 onosSummary.append( json.loads( main.CLIs[ i ].summary() ) )
1821
1822 for summary in onosSummary:
1823 if summary.get( 'intents' ) != 0:
1824 main.log.warn( itemName + ": There are " +
1825 str( summary.get( 'intents' ) ) +
1826 " intents remaining in node " +
1827 str( summary.get( 'node' ) ) +
1828 ", failed to remove all the intents " )
1829 removeIntentResult = main.FALSE
1830
1831 if removeIntentResult:
1832 main.log.info( itemName + ": There are no more intents remaining, " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001833 "successfully removed all the intents." )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001834
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001835 return removeIntentResult
1836
1837def checkFlowsCount( main ):
1838 """
1839 Check flows count in each node
1840 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001841 flowsCount = []
1842 main.log.info( itemName + ": Checking flows count in each ONOS node" )
1843 for i in range( main.numCtrls ):
1844 summaryResult = main.CLIs[ i ].summary()
1845 if not summaryResult:
1846 main.log.error( itemName + ": There is something wrong with " +
1847 "summary command" )
1848 return main.FALSE
1849 else:
1850 summaryJson = json.loads( summaryResult )
1851 flowsCount.append( summaryJson.get( 'flows' ) )
1852
1853 if flowsCount:
1854 if all( flows==flowsCount[ 0 ] for flows in flowsCount ):
1855 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
1856 " flows in all ONOS node" )
1857 else:
1858 for i in range( main.numCtrls ):
1859 main.log.debug( itemName + ": ONOS node " + str( i ) + " has " +
kelvin-onlab6dea6e62015-07-23 13:07:26 -07001860 str( flowsCount[ i ] ) + " flows" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001861 else:
1862 main.log.error( "Checking flows count failed, check summary command" )
1863 return main.FALSE
1864
1865 return main.TRUE
1866
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001867def checkLeaderChange( leaders1, leaders2 ):
acsmarse6b410f2015-07-17 14:39:34 -07001868 """
1869 Checks for a change in intent partition leadership.
1870
1871 Takes the output of leaders -c in json string format before and after
1872 a potential change as input
1873
1874 Returns main.TRUE if no mismatches are detected
1875 Returns main.FALSE if there is a mismatch or on error loading the input
1876 """
1877 try:
1878 leaders1 = json.loads( leaders1 )
1879 leaders2 = json.loads( leaders2 )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001880 except( AttributeError, TypeError ):
acsmarse6b410f2015-07-17 14:39:34 -07001881 main.log.exception( self.name + ": Object not as expected" )
1882 return main.FALSE
1883 except Exception:
1884 main.log.exception( self.name + ": Uncaught exception!" )
1885 main.cleanup()
1886 main.exit()
1887 main.log.info( "Checking Intent Paritions for Change in Leadership" )
1888 mismatch = False
1889 for dict1 in leaders1:
1890 if "intent" in dict1.get( "topic", [] ):
1891 for dict2 in leaders2:
1892 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \
1893 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
1894 mismatch = True
1895 main.log.error( "{0} changed leader from {1} to {2}".\
1896 format( dict1.get( "topic", "no-topic" ),\
1897 dict1.get( "leader", "no-leader" ),\
1898 dict2.get( "leader", "no-leader" ) ) )
1899 if mismatch:
1900 return main.FALSE
1901 else:
1902 return main.TRUE
kelvin-onlab016dce22015-08-10 09:54:11 -07001903
1904def report( main ):
1905 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001906 Report errors/warnings/exceptions
kelvin-onlab016dce22015-08-10 09:54:11 -07001907 """
kelvin-onlab016dce22015-08-10 09:54:11 -07001908 main.ONOSbench.logReport( main.ONOSip[ 0 ],
1909 [ "INFO",
1910 "FOLLOWER",
1911 "WARN",
1912 "flow",
1913 "ERROR",
1914 "Except" ],
1915 "s" )
1916
1917 main.log.info( "ERROR report: \n" )
1918 for i in range( main.numCtrls ):
1919 main.ONOSbench.logReport( main.ONOSip[ i ],
1920 [ "ERROR" ],
1921 "d" )
1922
1923 main.log.info( "EXCEPTIONS report: \n" )
1924 for i in range( main.numCtrls ):
1925 main.ONOSbench.logReport( main.ONOSip[ i ],
1926 [ "Except" ],
1927 "d" )
1928
1929 main.log.info( "WARNING report: \n" )
1930 for i in range( main.numCtrls ):
1931 main.ONOSbench.logReport( main.ONOSip[ i ],
1932 [ "WARN" ],
1933 "d" )
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001934
1935def flowDuration( main ):
1936 """
1937 Check age of flows to see if flows are being overwritten
1938 """
1939 import time
1940 main.log.info( "Getting current flow durations" )
1941 flowsJson1 = main.CLIs[ 0 ].flows( noCore=True )
1942 try:
1943 flowsJson1 = json.loads( flowsJson1 )
1944 except ValueError:
1945 main.log.error( "Unable to read flows" )
1946 return main.FALSE
1947 flowLife = []
1948 waitFlowLife = []
1949 for device in flowsJson1:
1950 if device.get( 'flowcount', 0 ) > 0:
1951 for i in range( device[ 'flowCount' ] ):
1952 flowLife.append( device[ 'flows' ][ i ][ 'life' ] )
1953 main.log.info( "Sleeping for {} seconds".format( main.flowDurationSleep ) )
1954 time.sleep( main.flowDurationSleep )
1955 main.log.info( "Getting new flow durations" )
1956 flowsJson2 = main.CLIs[ 0 ].flows( noCore=True )
1957 try:
1958 flowsJson2 = json.loads( flowsJson2 )
1959 except ValueError:
1960 main.log.error( "Unable to read flows" )
1961 return main.FALSE
1962 for device in flowsJson2:
1963 if device.get( 'flowcount', 0 ) > 0:
1964 for i in range( device[ 'flowCount' ] ):
1965 waitFlowLife.append( device[ 'flows' ][ i ][ 'life' ] )
1966 main.log.info( "Determining whether flows where overwritten" )
1967 if len( flowLife ) == len( waitFlowLife ):
alison52b25892016-09-19 10:53:48 -07001968 for i in range( len( flowLife ) ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001969 if waitFlowLife[ i ] - flowLife[ i ] < main.flowDurationSleep:
1970 return main.FALSE
1971 else:
1972 return main.FALSE
1973 return main.TRUE
alison52b25892016-09-19 10:53:48 -07001974
1975
1976def EncapsulatedIntentCheck( main, tag="" ):
1977 """
1978 Check encapsulated intents
1979 tag: encapsulation tag (e.g. VLAN, MPLS)
1980
1981 Getting added flows
1982 Check tags on each flows
1983 If each direction has push or pop, passed
1984 else failed
1985
1986 """
1987 import json
1988 HostJson = []
1989 Jflows = main.CLIs[ 0 ].flows( noCore=True )
1990 try:
1991 Jflows = json.loads( Jflows )
1992 except ValueError:
1993 main.log.error( "Unable to read flows" )
1994 return main.FALSE
1995
1996 for flow in Jflows:
1997 if len(flow[ "flows" ]) != 0:
1998 HostJson.append( flow[ "flows" ] )
1999
2000 totalflows = len( HostJson[ 0 ])
2001
2002 pop = 0
2003 push = 0
2004
2005 PopTag = tag + "_POP"
2006 PushTag = tag + "_PUSH"
2007
2008 for EachHostJson in HostJson:
2009 for i in range( totalflows ):
2010 if EachHostJson[ i ][ "treatment" ][ "instructions" ][ 0 ][ "subtype" ] == PopTag:
2011 pop += 1
2012 elif EachHostJson[ i ][ "treatment" ][ "instructions" ][ 0 ][ "subtype" ] == PushTag:
2013 push += 1
2014
2015 if pop == totalflows and push == totalflows:
2016 return main.TRUE
2017 else:
alisonda157272016-12-22 01:13:21 -08002018 return main.FALSE
2019
2020def ProtectedIntentCheck( main ):
2021 import json
2022 intent = main.CLIs[ 0 ].intents( jsonFormat=False )
2023 if "Protection" in intent:
2024 return main.TRUE
2025 return main.FALSE