blob: 17603242b40d2f77ba059e0eb532cbb8bf24d098 [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,
312 ipProto="",
313 ipSrc="",
314 ipDst="",
315 tcpSrc="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700316 tcpDst="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700317 setVlan="",
318 encap="" ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800319 """
320 Installs a Single to Single Point Intent
321
322 Description:
323 Install a single to single point intent
324
325 Steps:
326 - Fetch host data if not given
327 - Add point intent
328 - Ingress device is the first sender device
329 - Egress device is the first recipient device
330 - Ports if defined in senders or recipients
331 - MAC address ethSrc loaded from Ingress device
332 - Check intent state with retry
333 Required:
334 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
335 senders - List of host dictionaries i.e.
336 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
337 recipients - List of host dictionaries i.e.
338 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
339 Optional:
340 onosNode - ONOS node to install the intents in main.CLIs[ ]
341 0 by default so that it will always use the first
342 ONOS node
343 ethType - Ethernet type eg. IPV4, IPV6
344 bandwidth - Bandwidth capacity
345 lambdaAlloc - Allocate lambda, defaults to False
346 ipProto - IP protocol
347 tcp - TCP ports in the same order as the hosts in hostNames
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700348 sw1 - First switch to bring down & up for rerouting purpose
349 sw2 - Second switch to bring down & up for rerouting purpose
350 expectedLink - Expected link when the switches are down, it should
351 be two links lower than the links before the two
352 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700353 """
354
355 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800356 assert senders, "You must specify a sender"
357 assert recipients, "You must specify a recipient"
358 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700359
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800360 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700361 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700362
Jeremy6f000c62016-02-25 17:02:28 -0800363 main.log.info( itemName + ": Adding point to point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700364
Jeremyd9e4eb12016-04-13 12:09:06 -0700365 try:
366 for sender in senders:
367 if not sender.get( "device" ):
368 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
369 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800370
Jeremyd9e4eb12016-04-13 12:09:06 -0700371 for recipient in recipients:
372 if not recipient.get( "device" ):
373 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
374 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800375
376
Jeremyd9e4eb12016-04-13 12:09:06 -0700377 ingressDevice = senders[ 0 ].get( "device" )
378 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800379
Jeremyd9e4eb12016-04-13 12:09:06 -0700380 portIngress = senders[ 0 ].get( "port", "" )
381 portEgress = recipients[ 0 ].get( "port", "" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800382
Jeremyd9e4eb12016-04-13 12:09:06 -0700383 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800384
Jeremyd9e4eb12016-04-13 12:09:06 -0700385 ipSrc = senders[ 0 ].get( "ip" )
386 ipDst = recipients[ 0 ].get( "ip" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800387
Jeremy Songster832f9e92016-05-05 14:30:49 -0700388 vlanId = senders[ 0 ].get( "vlan" )
389
Jeremyd9e4eb12016-04-13 12:09:06 -0700390 # Adding point intent
391 intentId = main.CLIs[ onosNode ].addPointIntent(
392 ingressDevice=ingressDevice,
393 egressDevice=egressDevice,
394 portIngress=portIngress,
395 portEgress=portEgress,
396 ethType=ethType,
397 ethDst=dstMac,
398 bandwidth=bandwidth,
399 lambdaAlloc=lambdaAlloc,
400 ipProto=ipProto,
401 ipSrc=ipSrc,
402 ipDst=ipDst,
403 tcpSrc=tcpSrc,
Jeremy Songster832f9e92016-05-05 14:30:49 -0700404 tcpDst=tcpDst,
Jeremy Songsterff553672016-05-12 17:06:23 -0700405 vlanId=vlanId,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700406 setVlan=setVlan,
407 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700408 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700409 errorMsg = "There was a problem loading the hosts data."
410 if intentId:
411 errorMsg += " There was a problem installing Point to Point intent."
412 main.log.error( errorMsg )
413 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700414
415 # Check intents state
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700416 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
alison52b25892016-09-19 10:53:48 -0700417 args=( main, [ intentId ] ), sleep=main.checkIntentSleep, attempts=5 ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700418 main.assertReturnString += 'Install Intent State Passed\n'
alison52b25892016-09-19 10:53:48 -0700419
420 # Check VLAN if test encapsulation
421 if encap != "":
422 if EncapsulatedIntentCheck( main, tag=encap ):
423 main.assertReturnString += 'Encapsulation intents check Passed\n'
424 else:
425 main.assertReturnString += 'Encapsulation intents check failed\n'
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700426 if flowDuration( main ):
427 main.assertReturnString += 'Flow duration check Passed\n'
428 return intentId
429 else:
430 main.assertReturnString += 'Flow duration check failed\n'
431 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -0700432 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800433 main.log.error( "Point Intent did not install correctly" )
434 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700435
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700436def pointIntentTcp( main,
437 name,
438 host1,
439 host2,
440 onosNode=0,
441 deviceId1="",
442 deviceId2="",
443 port1="",
444 port2="",
445 ethType="",
446 mac1="",
447 mac2="",
448 bandwidth="",
449 lambdaAlloc=False,
450 ipProto="",
451 ip1="",
452 ip2="",
453 tcp1="",
454 tcp2="",
455 sw1="",
456 sw2="",
457 expectedLink=0 ):
458
459 """
460 Description:
461 Verify add-point-intent only for TCP
462 Steps:
463 - Get device ids | ports
464 - Add point intents
465 - Check intents
466 - Verify flows
467 - Ping hosts
468 - Reroute
469 - Link down
470 - Verify flows
471 - Check topology
472 - Ping hosts
473 - Link up
474 - Verify flows
475 - Check topology
476 - Ping hosts
477 - Remove intents
478 Required:
479 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
480 host1 - Name of first host
481 host2 - Name of second host
482 Optional:
483 onosNode - ONOS node to install the intents in main.CLIs[ ]
484 0 by default so that it will always use the first
485 ONOS node
486 deviceId1 - ONOS device id of the first switch, the same as the
487 location of the first host eg. of:0000000000000001/1,
488 located at device 1 port 1
489 deviceId2 - ONOS device id of the second switch
490 port1 - The port number where the first host is attached
491 port2 - The port number where the second host is attached
492 ethType - Ethernet type eg. IPV4, IPV6
493 mac1 - Mac address of first host
494 mac2 - Mac address of the second host
495 bandwidth - Bandwidth capacity
496 lambdaAlloc - Allocate lambda, defaults to False
497 ipProto - IP protocol
498 ip1 - IP address of first host
499 ip2 - IP address of second host
500 tcp1 - TCP port of first host
501 tcp2 - TCP port of second host
502 sw1 - First switch to bring down & up for rerouting purpose
503 sw2 - Second switch to bring down & up for rerouting purpose
504 expectedLink - Expected link when the switches are down, it should
505 be two links lower than the links before the two
506 switches are down
507 """
508
509 assert main, "There is no main variable"
510 assert name, "variable name is empty"
511 assert host1 and host2, "You must specify hosts"
512
513 global itemName
514 itemName = name
515 host1 = host1
516 host2 = host2
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700517 intentsId = []
518
519 iperfResult = main.TRUE
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700520 linkDownResult = main.TRUE
521 linkUpResult = main.TRUE
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700522
523 # Adding bidirectional point intents
524 main.log.info( itemName + ": Adding point intents" )
525 intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
526 egressDevice=deviceId2,
527 portIngress=port1,
528 portEgress=port2,
529 ethType=ethType,
530 ethSrc=mac1,
531 ethDst=mac2,
532 bandwidth=bandwidth,
533 lambdaAlloc=lambdaAlloc,
534 ipProto=ipProto,
535 ipSrc=ip1,
536 ipDst=ip2,
537 tcpSrc=tcp1,
538 tcpDst="" )
539
540 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
541 egressDevice=deviceId1,
542 portIngress=port2,
543 portEgress=port1,
544 ethType=ethType,
545 ethSrc=mac2,
546 ethDst=mac1,
547 bandwidth=bandwidth,
548 lambdaAlloc=lambdaAlloc,
549 ipProto=ipProto,
550 ipSrc=ip2,
551 ipDst=ip1,
552 tcpSrc=tcp2,
553 tcpDst="" )
554
555 intent3 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
556 egressDevice=deviceId2,
557 portIngress=port1,
558 portEgress=port2,
559 ethType=ethType,
560 ethSrc=mac1,
561 ethDst=mac2,
562 bandwidth=bandwidth,
563 lambdaAlloc=lambdaAlloc,
564 ipProto=ipProto,
565 ipSrc=ip1,
566 ipDst=ip2,
567 tcpSrc="",
568 tcpDst=tcp2 )
569
570 intent4 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
571 egressDevice=deviceId1,
572 portIngress=port2,
573 portEgress=port1,
574 ethType=ethType,
575 ethSrc=mac2,
576 ethDst=mac1,
577 bandwidth=bandwidth,
578 lambdaAlloc=lambdaAlloc,
579 ipProto=ipProto,
580 ipSrc=ip2,
581 ipDst=ip1,
582 tcpSrc="",
583 tcpDst=tcp1 )
584 intentsId.append( intent1 )
585 intentsId.append( intent2 )
586 intentsId.append( intent3 )
587 intentsId.append( intent4 )
588
589 # Check intents state
590 time.sleep( main.checkIntentSleep )
591 intentResult = checkIntentState( main, intentsId )
592 # Check flows count in each node
593 checkFlowsCount( main )
594
595 # Check intents state again if first check fails...
596 if not intentResult:
597 intentResult = checkIntentState( main, intentsId )
598
599 # Check flows count in each node
600 checkFlowsCount( main )
601
602 # Verify flows
603 checkFlowsState( main )
604
605 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700606 iperfTemp = main.Mininet1.iperftcp( host1, host2 ,10 )
acsmarsd4862d12015-10-06 17:57:34 -0700607 iperfResult = iperfResult and iperfTemp
608 if iperfTemp:
609 main.assertReturnString += 'Initial Iperf Passed\n'
610 else:
611 main.assertReturnString += 'Initial Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700612
613 # Test rerouting if these variables exist
614 if sw1 and sw2 and expectedLink:
615 # link down
616 linkDownResult = link( main, sw1, sw2, "down" )
acsmarsd4862d12015-10-06 17:57:34 -0700617
618 if linkDownResult:
619 main.assertReturnString += 'Link Down Passed\n'
620 else:
621 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700622
623 # Check flows count in each node
624 checkFlowsCount( main )
625 # Verify flows
626 checkFlowsState( main )
627
628 # Check OnosTopology
629 topoResult = checkTopology( main, expectedLink )
acsmarsd4862d12015-10-06 17:57:34 -0700630 if topoResult:
631 main.assertReturnString += 'Link Down Topology State Passed\n'
632 else:
633 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700634
635 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700636 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700637 iperfResult = iperfResult and iperfTemp
638 if iperfTemp:
639 main.assertReturnString += 'Link Down Iperf Passed\n'
640 else:
641 main.assertReturnString += 'Link Down Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700642
acsmarsd4862d12015-10-06 17:57:34 -0700643 # Check intent state
644 intentTemp = checkIntentState( main, intentsId )
645 intentResult = intentResult and intentTemp
646 if intentTemp:
647 main.assertReturnString += 'Link Down Intent State Passed\n'
648 else:
649 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700650
651 # Checks ONOS state in link down
652 if linkDownResult and topoResult and iperfResult and intentResult:
653 main.log.info( itemName + ": Successfully brought link down" )
654 else:
655 main.log.error( itemName + ": Failed to bring link down" )
656
657 # link up
658 linkUpResult = link( main, sw1, sw2, "up" )
alison52b25892016-09-19 10:53:48 -0700659 if linkUpResult:
acsmarsd4862d12015-10-06 17:57:34 -0700660 main.assertReturnString += 'Link Up Passed\n'
661 else:
662 main.assertReturnString += 'Link Up Failed\n'
663
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700664 time.sleep( main.rerouteSleep )
665
666 # Check flows count in each node
667 checkFlowsCount( main )
668 # Verify flows
669 checkFlowsState( main )
670
671 # Check OnosTopology
672 topoResult = checkTopology( main, main.numLinks )
673
acsmarsd4862d12015-10-06 17:57:34 -0700674 if topoResult:
675 main.assertReturnString += 'Link Up Topology State Passed\n'
676 else:
677 main.assertReturnString += 'Link Up Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700678
acsmarsd4862d12015-10-06 17:57:34 -0700679 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700680 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700681 iperfResult = iperfResult and iperfTemp
682 if iperfTemp:
683 main.assertReturnString += 'Link Up Iperf Passed\n'
684 else:
685 main.assertReturnString += 'Link Up Iperf Failed\n'
686
687 # Check intent state
688 intentTemp = checkIntentState( main, intentsId )
689 intentResult = intentResult and intentTemp
690 if intentTemp:
691 main.assertReturnString += 'Link Down Intent State Passed\n'
692 else:
693 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700694
695 # Checks ONOS state in link up
696 if linkUpResult and topoResult and iperfResult and intentResult:
697 main.log.info( itemName + ": Successfully brought link back up" )
698 else:
699 main.log.error( itemName + ": Failed to bring link back up" )
700
701 # Remove all intents
702 removeIntentResult = removeAllIntents( main, intentsId )
acsmarsd4862d12015-10-06 17:57:34 -0700703 if removeIntentResult:
704 main.assertReturnString += 'Remove Intents Passed'
705 else:
706 main.assertReturnString += 'Remove Intents Failed'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700707
708 stepResult = iperfResult and linkDownResult and linkUpResult \
709 and intentResult and removeIntentResult
710
711 return stepResult
712
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800713def installSingleToMultiIntent( main,
714 name,
715 senders,
716 recipients,
717 onosNode=0,
718 ethType="",
719 bandwidth="",
720 lambdaAlloc=False,
721 ipProto="",
722 ipAddresses="",
723 tcp="",
724 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700725 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -0700726 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700727 partial=False,
728 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700729 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800730 Installs a Single to Multi Point Intent
731
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700732 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800733 Install a single to multi point intent using
734 add-single-to-multi-intent
735
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700736 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800737 - Fetch host data if not given
738 - Add single to multi intent
739 - Ingress device is the first sender host
740 - Egress devices are the recipient devices
741 - Ports if defined in senders or recipients
742 - MAC address ethSrc loaded from Ingress device
743 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700744 Required:
745 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800746 senders - List of host dictionaries i.e.
747 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
748 recipients - List of host dictionaries i.e.
749 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700750 Optional:
751 onosNode - ONOS node to install the intents in main.CLIs[ ]
752 0 by default so that it will always use the first
753 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700754 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700755 bandwidth - Bandwidth capacity
756 lambdaAlloc - Allocate lambda, defaults to False
757 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700758 tcp - TCP ports in the same order as the hosts in hostNames
759 sw1 - First switch to bring down & up for rerouting purpose
760 sw2 - Second switch to bring down & up for rerouting purpose
761 expectedLink - Expected link when the switches are down, it should
762 be two links lower than the links before the two
763 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700764 """
765
766 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800767 assert senders, "You must specify a sender"
768 assert recipients, "You must specify a recipient"
769 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700770
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800771 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700772 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700773
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700774 main.log.info( itemName + ": Adding single point to multi point intents" )
775
Jeremyd9e4eb12016-04-13 12:09:06 -0700776 try:
777 for sender in senders:
778 if not sender.get( "device" ):
779 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
780 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700781
Jeremyd9e4eb12016-04-13 12:09:06 -0700782 for recipient in recipients:
783 if not recipient.get( "device" ):
784 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
785 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700786
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700787
Jeremyd9e4eb12016-04-13 12:09:06 -0700788 ingressDevice = senders[ 0 ].get( "device" )
789 egressDeviceList = [ x.get( "device" ) for x in recipients if x.get( "device" ) ]
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800790
Jeremyd9e4eb12016-04-13 12:09:06 -0700791 portIngress = senders[ 0 ].get( "port", "" )
792 portEgressList = [ x.get( "port" ) for x in recipients if x.get( "port" ) ]
793 if not portEgressList:
794 portEgressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800795
Jeremyd9e4eb12016-04-13 12:09:06 -0700796 srcMac = senders[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700797 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800798
Jeremyd9e4eb12016-04-13 12:09:06 -0700799 # Adding point intent
800 intentId = main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
801 ingressDevice=ingressDevice,
802 egressDeviceList=egressDeviceList,
803 portIngress=portIngress,
804 portEgressList=portEgressList,
805 ethType=ethType,
806 ethSrc=srcMac,
807 bandwidth=bandwidth,
808 lambdaAlloc=lambdaAlloc,
809 ipProto=ipProto,
810 ipSrc="",
811 ipDst="",
812 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -0700813 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700814 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -0700815 setVlan=setVlan,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700816 partial=partial,
817 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700818 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700819 errorMsg = "There was a problem loading the hosts data."
820 if intentId:
821 errorMsg += " There was a problem installing Singlepoint to Multipoint intent."
822 main.log.error( errorMsg )
823 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700824
825 # Check intents state
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700826 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
827 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
828 main.assertReturnString += 'Install Intent State Passed\n'
829 if flowDuration( main ):
830 main.assertReturnString += 'Flow duration check Passed\n'
831 return intentId
832 else:
833 main.assertReturnString += 'Flow duration check failed\n'
834 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -0700835 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800836 main.log.error( "Single to Multi Intent did not install correctly" )
837 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700838
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800839def installMultiToSingleIntent( main,
840 name,
841 senders,
842 recipients,
843 onosNode=0,
844 ethType="",
845 bandwidth="",
846 lambdaAlloc=False,
847 ipProto="",
848 ipAddresses="",
849 tcp="",
850 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700851 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -0700852 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700853 partial=False,
854 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700855 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800856 Installs a Multi to Single Point Intent
857
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700858 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800859 Install a multi to single point intent using
860 add-multi-to-single-intent
861
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700862 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800863 - Fetch host data if not given
864 - Add multi to single intent
865 - Ingress devices are the senders devices
866 - Egress device is the first recipient host
867 - Ports if defined in senders or recipients
868 - MAC address ethSrc loaded from Ingress device
869 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700870 Required:
871 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800872 senders - List of host dictionaries i.e.
873 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
874 recipients - List of host dictionaries i.e.
875 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700876 Optional:
877 onosNode - ONOS node to install the intents in main.CLIs[ ]
878 0 by default so that it will always use the first
879 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700880 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700881 bandwidth - Bandwidth capacity
882 lambdaAlloc - Allocate lambda, defaults to False
883 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700884 tcp - TCP ports in the same order as the hosts in hostNames
885 sw1 - First switch to bring down & up for rerouting purpose
886 sw2 - Second switch to bring down & up for rerouting purpose
887 expectedLink - Expected link when the switches are down, it should
888 be two links lower than the links before the two
889 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700890 """
891
892 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800893 assert senders, "You must specify a sender"
894 assert recipients, "You must specify a recipient"
895 # Assert devices or main.hostsData, "You must specify devices"
896
897 global itemName # The name of this run. Used for logs.
898 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800899
900 main.log.info( itemName + ": Adding mutli to single point intents" )
901
Jeremyd9e4eb12016-04-13 12:09:06 -0700902 try:
903 for sender in senders:
904 if not sender.get( "device" ):
905 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
906 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800907
Jeremyd9e4eb12016-04-13 12:09:06 -0700908 for recipient in recipients:
909 if not recipient.get( "device" ):
910 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
911 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800912
Jeremyd9e4eb12016-04-13 12:09:06 -0700913 ingressDeviceList = [ x.get( "device" ) for x in senders if x.get( "device" ) ]
914 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800915
Jeremyd9e4eb12016-04-13 12:09:06 -0700916 portIngressList = [ x.get( "port" ) for x in senders if x.get( "port" ) ]
917 portEgress = recipients[ 0 ].get( "port", "" )
918 if not portIngressList:
919 portIngressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800920
Jeremyd9e4eb12016-04-13 12:09:06 -0700921 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700922 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800923
Jeremyd9e4eb12016-04-13 12:09:06 -0700924 # Adding point intent
925 intentId = main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
926 ingressDeviceList=ingressDeviceList,
927 egressDevice=egressDevice,
928 portIngressList=portIngressList,
929 portEgress=portEgress,
930 ethType=ethType,
931 ethDst=dstMac,
932 bandwidth=bandwidth,
933 lambdaAlloc=lambdaAlloc,
934 ipProto=ipProto,
935 ipSrc="",
936 ipDst="",
937 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -0700938 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700939 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -0700940 setVlan=setVlan,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700941 partial=partial,
942 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700943 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700944 errorMsg = "There was a problem loading the hosts data."
945 if intentId:
946 errorMsg += " There was a problem installing Multipoint to Singlepoint intent."
947 main.log.error( errorMsg )
948 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800949
950 # Check intents state
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700951 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
952 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
953 main.assertReturnString += 'Install Intent State Passed\n'
954 if flowDuration( main ):
955 main.assertReturnString += 'Flow duration check Passed\n'
956 return intentId
957 else:
958 main.assertReturnString += 'Flow duration check failed\n'
959 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800960 else:
961 main.log.error( "Multi to Single Intent did not install correctly" )
962 return main.FALSE
963
964def testPointIntent( main,
Jeremye0cb5eb2016-01-27 17:39:09 -0800965 name,
966 intentId,
967 senders,
968 recipients,
969 badSenders={},
970 badRecipients={},
971 onosNode=0,
972 ethType="",
973 bandwidth="",
974 lambdaAlloc=False,
975 ipProto="",
976 ipAddresses="",
977 tcp="",
978 sw1="s5",
979 sw2="s2",
Jeremy Songstere405d3d2016-05-17 11:18:57 -0700980 expectedLink=0,
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700981 useTCP=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800982 """
983 Test a Point Intent
984
985 Description:
986 Test a point intent
987
988 Steps:
989 - Fetch host data if not given
990 - Check Intent State
991 - Check Flow State
992 - Check Connectivity
993 - Check Lack of Connectivity Between Hosts not in the Intent
994 - Reroute
995 - Take Expected Link Down
996 - Check Intent State
997 - Check Flow State
998 - Check Topology
999 - Check Connectivity
1000 - Bring Expected Link Up
1001 - Check Intent State
1002 - Check Flow State
1003 - Check Topology
1004 - Check Connectivity
1005 - Remove Topology
1006
1007 Required:
1008 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
1009
1010 senders - List of host dictionaries i.e.
1011 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
1012 recipients - List of host dictionaries i.e.
1013 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
1014 Optional:
1015 onosNode - ONOS node to install the intents in main.CLIs[ ]
1016 0 by default so that it will always use the first
1017 ONOS node
1018 ethType - Ethernet type eg. IPV4, IPV6
1019 bandwidth - Bandwidth capacity
1020 lambdaAlloc - Allocate lambda, defaults to False
1021 ipProto - IP protocol
1022 tcp - TCP ports in the same order as the hosts in hostNames
1023 sw1 - First switch to bring down & up for rerouting purpose
1024 sw2 - Second switch to bring down & up for rerouting purpose
1025 expectedLink - Expected link when the switches are down, it should
1026 be two links lower than the links before the two
1027 switches are down
1028
1029 """
1030
1031 # Parameter Validity Check
1032 assert main, "There is no main variable"
1033 assert senders, "You must specify a sender"
1034 assert recipients, "You must specify a recipient"
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001035
1036 global itemName
1037 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001038
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001039 main.log.info( itemName + ": Testing Point Intent" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001040
Jeremyd9e4eb12016-04-13 12:09:06 -07001041 try:
1042 # Names for scapy
1043 senderNames = [ x.get( "name" ) for x in senders ]
1044 recipientNames = [ x.get( "name" ) for x in recipients ]
1045 badSenderNames = [ x.get( "name" ) for x in badSenders ]
1046 badRecipientNames = [ x.get( "name" ) for x in badRecipients ]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001047
Jeremyd9e4eb12016-04-13 12:09:06 -07001048 for sender in senders:
1049 if not sender.get( "device" ):
1050 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1051 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001052
Jeremyd9e4eb12016-04-13 12:09:06 -07001053 for recipient in recipients:
1054 if not recipient.get( "device" ):
1055 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1056 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001057 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001058 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001059 main.log.error( "There was a problem loading the hosts data." )
1060 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001061
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001062 testResult = main.TRUE
1063 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001064
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001065 # Check intent state
1066 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1067 main.assertReturnString += 'Initial Intent State Passed\n'
acsmarsd4862d12015-10-06 17:57:34 -07001068 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001069 main.assertReturnString += 'Initial Intent State Failed\n'
1070 testResult = main.FALSE
1071
1072 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -07001073 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 -08001074 main.assertReturnString += 'Initial Flow State Passed\n'
1075 else:
1076 main.assertReturnString += 'Intial Flow State Failed\n'
1077 testResult = main.FALSE
1078
1079 # Check Connectivity
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001080 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 -08001081 main.assertReturnString += 'Initial Ping Passed\n'
1082 else:
1083 main.assertReturnString += 'Initial Ping Failed\n'
1084 testResult = main.FALSE
1085
1086 # Check connections that shouldn't work
1087 if badSenderNames:
1088 main.log.info( "Checking that packets from incorrect sender do not go through" )
1089 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, badSenderNames, recipientNames ), kwargs={ "expectFailure":True } ):
1090 main.assertReturnString += 'Bad Sender Ping Passed\n'
1091 else:
1092 main.assertReturnString += 'Bad Sender Ping Failed\n'
1093 testResult = main.FALSE
1094
1095 if badRecipientNames:
1096 main.log.info( "Checking that packets to incorrect recipients do not go through" )
1097 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, badRecipientNames ), kwargs={ "expectFailure":True } ):
1098 main.assertReturnString += 'Bad Recipient Ping Passed\n'
1099 else:
1100 main.assertReturnString += 'Bad Recipient Ping Failed\n'
1101 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001102
1103 # Test rerouting if these variables exist
1104 if sw1 and sw2 and expectedLink:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001105 # Take link down
1106 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001107 main.assertReturnString += 'Link Down Passed\n'
1108 else:
1109 main.assertReturnString += 'Link Down Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001110 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001111
acsmarsd4862d12015-10-06 17:57:34 -07001112 # Check intent state
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001113 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001114 main.assertReturnString += 'Link Down Intent State Passed\n'
1115 else:
1116 main.assertReturnString += 'Link Down Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001117 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001118
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001119 # Check flows count in each node
Jeremy Songsterc032f162016-08-04 17:14:49 -07001120 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 -08001121 main.assertReturnString += 'Link Down Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001122 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001123 main.assertReturnString += 'Link Down Flow State Failed\n'
1124 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001125
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001126 # Check OnosTopology
1127 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink ) ):
1128 main.assertReturnString += 'Link Down Topology State Passed\n'
1129 else:
1130 main.assertReturnString += 'Link Down Topology State Failed\n'
1131 testResult = main.FALSE
1132
1133 # Check Connection
alison52b25892016-09-19 10:53:48 -07001134 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 -08001135 main.assertReturnString += 'Link Down Pingall Passed\n'
1136 else:
1137 main.assertReturnString += 'Link Down Pingall Failed\n'
1138 testResult = main.FALSE
1139
1140 # Bring link up
1141 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001142 main.assertReturnString += 'Link Up Passed\n'
1143 else:
1144 main.assertReturnString += 'Link Up Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001145 testResult = main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -07001146
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001147 # Wait for reroute
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001148 time.sleep( main.rerouteSleep )
1149
acsmarsd4862d12015-10-06 17:57:34 -07001150 # Check Intents
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001151 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001152 main.assertReturnString += 'Link Up Intent State Passed\n'
1153 else:
1154 main.assertReturnString += 'Link Up Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001155 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001156
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001157 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -07001158 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 -08001159 main.assertReturnString += 'Link Up Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001160 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001161 main.assertReturnString += 'Link Up Flow State Failed\n'
1162 testResult = main.FALSE
1163
1164 # Check OnosTopology
1165 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
1166 main.assertReturnString += 'Link Up Topology State Passed\n'
1167 else:
1168 main.assertReturnString += 'Link Up Topology State Failed\n'
1169 testResult = main.FALSE
1170
1171 # Check Connection
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001172 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001173 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1174 else:
1175 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1176 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001177
1178 # Remove all intents
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001179 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001180 main.assertReturnString += 'Remove Intents Passed'
1181 else:
1182 main.assertReturnString += 'Remove Intents Failed'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001183 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001184
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001185 return testResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001186
Jeremye0cb5eb2016-01-27 17:39:09 -08001187def testEndPointFail( main,
1188 name,
1189 intentId,
1190 senders,
1191 recipients,
1192 isolatedSenders,
1193 isolatedRecipients,
1194 onosNode=0,
1195 ethType="",
1196 bandwidth="",
1197 lambdaAlloc=False,
1198 ipProto="",
1199 ipAddresses="",
1200 tcp="",
1201 sw1="",
1202 sw2="",
1203 sw3="",
1204 sw4="",
1205 sw5="",
1206 expectedLink1=0,
Jeremy Songster9385d412016-06-02 17:57:36 -07001207 expectedLink2=0,
1208 partial=False ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001209 """
1210 Test Single to Multipoint Topology for Endpoint failures
1211 """
1212
1213 # Parameter Validity Check
1214 assert main, "There is no main variable"
1215 assert senders, "You must specify a sender"
1216 assert recipients, "You must specify a recipient"
1217
1218 global itemName
1219 itemName = name
Jeremye0cb5eb2016-01-27 17:39:09 -08001220
1221 main.log.info( itemName + ": Testing Point Intent" )
1222
Jeremyd9e4eb12016-04-13 12:09:06 -07001223 try:
1224 # Names for scapy
1225 senderNames = [ x.get( "name" ) for x in senders ]
1226 recipientNames = [ x.get( "name" ) for x in recipients ]
1227 isolatedSenderNames = [ x.get( "name" ) for x in isolatedSenders ]
1228 isolatedRecipientNames = [ x.get( "name" ) for x in isolatedRecipients ]
1229 connectedSenderNames = [x.get("name") for x in senders if x.get("name") not in isolatedSenderNames]
1230 connectedRecipientNames = [x.get("name") for x in recipients if x.get("name") not in isolatedRecipientNames]
Jeremye0cb5eb2016-01-27 17:39:09 -08001231
Jeremyd9e4eb12016-04-13 12:09:06 -07001232 for sender in senders:
1233 if not sender.get( "device" ):
1234 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1235 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremye0cb5eb2016-01-27 17:39:09 -08001236
Jeremyd9e4eb12016-04-13 12:09:06 -07001237 for recipient in recipients:
1238 if not recipient.get( "device" ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001239 main.log.warn( "Device not given for recipient {0}. Loading from " +\
1240 main.hostData.format( recipient.get( "name" ) ) )
Jeremyd9e4eb12016-04-13 12:09:06 -07001241 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001242 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001243 main.log.error( "There was a problem loading the hosts data." )
1244 return main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001245
1246 testResult = main.TRUE
1247 main.log.info( itemName + ": Adding multi point to single point intents" )
1248
1249 # Check intent state
1250 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1251 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1252 main.assertReturnString += 'Initial Intent State Passed\n'
1253 else:
1254 main.assertReturnString += 'Initial Intent State Failed\n'
1255 testResult = main.FALSE
1256
1257 # Check flows count in each node
1258 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
Jeremy Songster9385d412016-06-02 17:57:36 -07001259 args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState,
1260 retValue=main.FALSE,
1261 args=[ main ], attempts=5 ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001262 main.assertReturnString += 'Initial Flow State Passed\n'
1263 else:
1264 main.assertReturnString += 'Intial Flow State Failed\n'
1265 testResult = main.FALSE
1266
1267 # Check Connectivity
1268 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1269 args=( main, senderNames, recipientNames ) ):
1270 main.assertReturnString += 'Initial Connectivity Check Passed\n'
1271 else:
1272 main.assertReturnString += 'Initial Connectivity Check Failed\n'
1273 testResult = main.FALSE
1274
1275 # Take two links down
1276 # Take first link down
1277 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
1278 main.assertReturnString += 'Link Down Passed\n'
1279 else:
1280 main.assertReturnString += 'Link Down Failed\n'
1281 testResult = main.FALSE
1282
1283 # Take second link down
1284 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw4, "down" ) ):
1285 main.assertReturnString += 'Link Down Passed\n'
1286 else:
1287 main.assertReturnString += 'Link Down Failed\n'
1288 testResult = main.FALSE
1289
1290 # Check intent state
1291 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1292 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1293 main.assertReturnString += 'Link Down Intent State Passed\n'
1294 else:
1295 main.assertReturnString += 'Link Down Intent State Failed\n'
1296 testResult = main.FALSE
1297
1298 # Check flows count in each node
1299 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1300 args=[ main ] ) and utilities.retry( f=checkFlowsState,
1301 retValue=main.FALSE, args=[ main ] ):
1302 main.assertReturnString += 'Link Down Flow State Passed\n'
1303 else:
1304 main.assertReturnString += 'Link Down Flow State Failed\n'
1305 testResult = main.FALSE
1306
1307 # Check OnosTopology
1308 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink1 ) ):
1309 main.assertReturnString += 'Link Down Topology State Passed\n'
1310 else:
1311 main.assertReturnString += 'Link Down Topology State Failed\n'
1312 testResult = main.FALSE
1313
1314 # Check Connection
1315 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1316 args=( main, senderNames, recipientNames ) ):
1317 main.assertReturnString += 'Link Down Connectivity Check Passed\n'
1318 else:
1319 main.assertReturnString += 'Link Down Connectivity Check Failed\n'
1320 testResult = main.FALSE
1321
1322 # Take a third link down to isolate one node
1323 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw5, "down" ) ):
1324 main.assertReturnString += 'Isolation link Down Passed\n'
1325 else:
1326 main.assertReturnString += 'Isolation link Down Failed\n'
1327 testResult = main.FALSE
1328
Jeremy Songster9385d412016-06-02 17:57:36 -07001329 if partial:
1330 # Check intent state
1331 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1332 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1333 main.assertReturnString += 'Partial failure isolation link Down Intent State Passed\n'
1334 else:
1335 main.assertReturnString += 'Partial failure isolation link Down Intent State Failed\n'
1336 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001337
Jeremy Songster9385d412016-06-02 17:57:36 -07001338 # Check flows count in each node
1339 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1340 args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState,
1341 retValue=main.FALSE,
1342 args=[ main ], attempts=5 ):
1343 main.assertReturnString += 'Partial failure isolation link Down Flow State Passed\n'
1344 else:
1345 main.assertReturnString += 'Partial failure isolation link Down Flow State Failed\n'
1346 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001347
Jeremy Songster9385d412016-06-02 17:57:36 -07001348 # Check OnosTopology
1349 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink2 ) ):
1350 main.assertReturnString += 'Partial failure isolation link Down Topology State Passed\n'
1351 else:
1352 main.assertReturnString += 'Partial failure isolation link Down Topology State Failed\n'
1353 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001354
Jeremy Songster9385d412016-06-02 17:57:36 -07001355 # Check Connectivity
1356 # First check connectivity of any isolated senders to recipients
1357 if isolatedSenderNames:
1358 if scapyCheckConnection( main, isolatedSenderNames, recipientNames, None, None, None, None, main.TRUE ):
1359 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1360 else:
1361 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1362 testResult = main.FALSE
1363
1364 # Next check connectivity of senders to any isolated recipients
1365 if isolatedRecipientNames:
1366 if scapyCheckConnection( main, senderNames, isolatedRecipientNames, None, None, None, None, main.TRUE ):
1367 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1368 else:
1369 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1370 testResult = main.FALSE
1371
1372 # Next check connectivity of connected senders and recipients
1373 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1374 args=( main, connectedSenderNames , connectedRecipientNames ) ):
1375 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1376 else:
1377 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1378 testResult = main.FALSE
1379 else:
1380 # Check intent state
1381 if not utilities.retry( f=checkIntentState, retValue=main.TRUE,
1382 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1383 main.assertReturnString += 'Isolation link Down Intent State Passed\n'
1384 else:
1385 main.assertReturnString += 'Isolation link Down Intent State Failed\n'
1386 testResult = main.FALSE
1387
1388 # Check flows count in each node
1389 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1390 args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState,
1391 retValue=main.FALSE,
1392 args=[ main ], attempts=5 ):
1393 main.assertReturnString += 'Isolation link Down Flow State Passed\n'
1394 else:
1395 main.assertReturnString += 'Isolation link Down Flow State Failed\n'
1396 testResult = main.FALSE
1397
1398 # Check OnosTopology
1399 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink2 ) ):
1400 main.assertReturnString += 'Isolation link Down Topology State Passed\n'
1401 else:
1402 main.assertReturnString += 'Isolation link Down Topology State Failed\n'
1403 testResult = main.FALSE
1404
1405 # Check Connectivity
1406 # First check connectivity of any isolated senders to recipients
1407 if isolatedSenderNames:
1408 if scapyCheckConnection( main, isolatedSenderNames, recipientNames, None, None, None, None, main.TRUE ):
1409 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1410 else:
1411 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1412 testResult = main.FALSE
1413
1414 # Next check connectivity of senders to any isolated recipients
1415 if isolatedRecipientNames:
1416 if scapyCheckConnection( main, senderNames, isolatedRecipientNames, None, None, None, None, main.TRUE ):
1417 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1418 else:
1419 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1420 testResult = main.FALSE
1421
1422 # Next check connectivity of connected senders and recipients
1423 if utilities.retry( f=scapyCheckConnection, retValue=main.TRUE,
1424 args=( main, connectedSenderNames , connectedRecipientNames, None, None, None, None, main.TRUE ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001425 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1426 else:
1427 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1428 testResult = main.FALSE
1429
Jeremye0cb5eb2016-01-27 17:39:09 -08001430 # Bring the links back up
1431 # Bring first link up
1432 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
1433 main.assertReturnString += 'Link Up Passed\n'
1434 else:
1435 main.assertReturnString += 'Link Up Failed\n'
1436 testResult = main.FALSE
1437
1438 # Bring second link up
1439 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw5, "up" ) ):
1440 main.assertReturnString += 'Link Up Passed\n'
1441 else:
1442 main.assertReturnString += 'Link Up Failed\n'
1443 testResult = main.FALSE
1444
1445 # Bring third link up
1446 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw4, "up" ) ):
1447 main.assertReturnString += 'Link Up Passed\n'
1448 else:
1449 main.assertReturnString += 'Link Up Failed\n'
1450 testResult = main.FALSE
1451
1452 # Wait for reroute
1453 time.sleep( main.rerouteSleep )
1454
1455 # Check Intents
1456 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1457 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1458 main.assertReturnString += 'Link Up Intent State Passed\n'
1459 else:
1460 main.assertReturnString += 'Link Up Intent State Failed\n'
1461 testResult = main.FALSE
1462
1463 # Check flows count in each node
1464 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
Jeremy Songster9385d412016-06-02 17:57:36 -07001465 args=[ main ], sleep=5, attempts=5 ) and utilities.retry( f=checkFlowsState,
1466 retValue=main.FALSE,
1467 args=[ main ], sleep=5, attempts=5 ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001468 main.assertReturnString += 'Link Up Flow State Passed\n'
1469 else:
1470 main.assertReturnString += 'Link Up Flow State Failed\n'
1471 testResult = main.FALSE
1472
1473 # Check OnosTopology
1474 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
1475 main.assertReturnString += 'Link Up Topology State Passed\n'
1476 else:
1477 main.assertReturnString += 'Link Up Topology State Failed\n'
1478 testResult = main.FALSE
1479
1480 # Check Connection
1481 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1482 args=( main, senderNames, recipientNames ) ):
1483 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1484 else:
1485 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1486 testResult = main.FALSE
1487
1488 # Remove all intents
1489 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ):
1490 main.assertReturnString += 'Remove Intents Passed'
1491 else:
1492 main.assertReturnString += 'Remove Intents Failed'
1493 testResult = main.FALSE
1494
1495 return testResult
1496
1497
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001498def pingallHosts( main, hostList ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001499 """
1500 Ping all host in the hosts list variable
1501 """
Jon Halla5cb3412015-08-18 14:08:22 -07001502 main.log.info( "Pinging: " + str( hostList ) )
1503 return main.Mininet1.pingallHosts( hostList )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001504
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001505def fwdPingall( main ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001506 """
1507 Use fwd app and pingall to discover all the hosts
1508 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001509 appCheck = main.TRUE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001510 main.log.info( "Activating reactive forwarding app " )
1511 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001512
1513 # Wait for forward app activation to propagate
kelvin-onlab0ad05d12015-07-23 14:21:15 -07001514 time.sleep( main.fwdSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001515
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001516 # Check that forwarding is enabled on all nodes
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001517 for i in range( main.numCtrls ):
1518 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
1519 if appCheck != main.TRUE:
1520 main.log.warn( main.CLIs[ i ].apps() )
1521 main.log.warn( main.CLIs[ i ].appIDs() )
1522
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001523 # Send pingall in mininet
1524 main.log.info( "Run Pingall" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001525 pingResult = main.Mininet1.pingall( timeout = 600 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001526
1527 main.log.info( "Deactivating reactive forwarding app " )
1528 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001529 if activateResult and deactivateResult:
1530 main.log.info( "Successfully used fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001531 getDataResult = main.TRUE
1532 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001533 main.log.info( "Failed to use fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001534 getDataResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001535 return getDataResult
1536
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001537def confirmHostDiscovery( main ):
1538 """
1539 Confirms that all ONOS nodes have discovered all scapy hosts
1540 """
1541 import collections
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001542 hosts = main.topo.getAllHosts( main ) # Get host data from each ONOS node
1543 hostFails = [] # Reset for each failed attempt
1544
1545 # Check for matching hosts on each node
1546 scapyHostIPs = [ x.hostIp for x in main.scapyHosts if x.hostIp != "0.0.0.0" ]
1547 for controller in range( main.numCtrls ):
1548 controllerStr = str( controller + 1 ) # ONOS node number
1549 # Compare Hosts
1550 # Load hosts data for controller node
Jeremyd9e4eb12016-04-13 12:09:06 -07001551 try:
1552 if hosts[ controller ]:
1553 main.log.info( "Hosts discovered" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001554 else:
Jeremyd9e4eb12016-04-13 12:09:06 -07001555 main.log.error( "Problem discovering hosts" )
1556 if hosts[ controller ] and "Error" not in hosts[ controller ]:
1557 try:
1558 hostData = json.loads( hosts[ controller ] )
1559 except ( TypeError, ValueError ):
1560 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001561 hostFails.append( controllerStr )
Jeremyd9e4eb12016-04-13 12:09:06 -07001562 else:
1563 onosHostIPs = [ x.get( "ipAddresses" )[ 0 ]
1564 for x in hostData
1565 if len( x.get( "ipAddresses" ) ) > 0 ]
1566 if not set( collections.Counter( scapyHostIPs ) ).issubset( set ( collections.Counter( onosHostIPs ) ) ):
1567 main.log.warn( "Controller {0} only sees nodes with {1} IPs. It should see all of the following: {2}".format( controllerStr, onosHostIPs, scapyHostIPs ) )
1568 hostFails.append( controllerStr )
1569 else:
1570 main.log.error( "Hosts returned nothing or an error." )
1571 hostFails.append( controllerStr )
1572 except IndexError:
1573 main.log.error( "Hosts returned nothing, Failed to discover hosts." )
1574 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001575
1576 if hostFails:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001577 main.log.error( "List of failed ONOS Nodes:" + ', '.join( map( str, hostFails ) ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001578 return main.FALSE
1579 else:
1580 return main.TRUE
1581
1582def sendDiscoveryArp( main, hosts=None ):
1583 """
1584 Sends Discovery ARP packets from each host provided
1585 Defaults to each host in main.scapyHosts
1586 """
1587 # Send an arp ping from each host
1588 if not hosts:
1589 hosts = main.scapyHosts
1590 for host in hosts:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001591 pkt = 'Ether( src="{0}")/ARP( psrc="{1}")'.format( host.hostMac, host.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001592 # Send from the VLAN interface if there is one so ONOS discovers the VLAN correctly
1593 iface = None
1594 for interface in host.getIfList():
1595 if '.' in interface:
1596 main.log.debug( "Detected VLAN interface {0}. Sending ARP packet from {0}".format( interface ) )
1597 iface = interface
1598 break
1599 host.sendPacket( packet=pkt, iface=iface )
1600 main.log.info( "Sending ARP packet from {0}".format( host.name ) )
1601
1602def populateHostData( main ):
1603 """
1604 Populates hostsData
1605 """
1606 import json
1607 try:
1608 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
1609 hosts = main.Mininet1.getHosts().keys()
1610 # TODO: Make better use of new getHosts function
1611 for host in hosts:
1612 main.hostsData[ host ] = {}
1613 main.hostsData[ host ][ 'mac' ] = \
1614 main.Mininet1.getMacAddress( host ).upper()
1615 for hostj in hostsJson:
1616 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
1617 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
1618 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
1619 main.hostsData[ host ][ 'location' ] = \
1620 hostj[ 'location' ][ 'elementId' ] + '/' + \
1621 hostj[ 'location' ][ 'port' ]
1622 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
1623 return main.TRUE
Jeremyd9e4eb12016-04-13 12:09:06 -07001624 except ValueError:
1625 main.log.error( "ValueError while populating hostsData" )
1626 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001627 except KeyError:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001628 main.log.error( "KeyError while populating hostsData" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001629 return main.FALSE
Jeremyd9e4eb12016-04-13 12:09:06 -07001630 except IndexError:
1631 main.log.error( "IndexError while populating hostsData" )
1632 return main.FALSE
1633 except TypeError:
1634 main.log.error( "TypeError while populating hostsData" )
1635 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001636
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001637def checkTopology( main, expectedLink ):
1638 statusResult = main.TRUE
1639 # Check onos topology
1640 main.log.info( itemName + ": Checking ONOS topology " )
1641
1642 for i in range( main.numCtrls ):
Flavio Castro82ee2f62016-06-07 15:04:12 -07001643 statusResult = main.CLIs[ i ].checkStatus( main.numSwitch,
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001644 expectedLink )\
1645 and statusResult
1646 if not statusResult:
1647 main.log.error( itemName + ": Topology mismatch" )
1648 else:
1649 main.log.info( itemName + ": Topology match" )
1650 return statusResult
1651
1652def checkIntentState( main, intentsId ):
1653 """
1654 This function will check intent state to make sure all the intents
1655 are in INSTALLED state
1656 """
1657
1658 intentResult = main.TRUE
1659 results = []
1660
1661 main.log.info( itemName + ": Checking intents state" )
1662 # First check of intents
1663 for i in range( main.numCtrls ):
1664 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
1665 results.append( tempResult )
1666
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001667 if all( result == main.TRUE for result in results ):
1668 main.log.info( itemName + ": Intents are installed correctly" )
1669 else:
1670 # Wait for at least 5 second before checking the intents again
acsmarsb9a92692015-10-08 16:43:01 -07001671 main.log.error( "Intents are not installed correctly. Waiting 5 sec" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001672 time.sleep( 5 )
1673 results = []
1674 # Second check of intents since some of the intents may be in
1675 # INSTALLING state, they should be in INSTALLED at this time
1676 for i in range( main.numCtrls ):
Jeremy2f190ca2016-01-29 15:23:57 -08001677 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001678 results.append( tempResult )
1679 if all( result == main.TRUE for result in results ):
1680 main.log.info( itemName + ": Intents are installed correctly" )
acsmarsb9a92692015-10-08 16:43:01 -07001681 intentResult = main.TRUE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001682 else:
1683 main.log.error( itemName + ": Intents are NOT installed correctly" )
1684 intentResult = main.FALSE
1685
1686 return intentResult
1687
1688def checkFlowsState( main ):
1689
1690 main.log.info( itemName + ": Check flows state" )
Jeremy Songsterff553672016-05-12 17:06:23 -07001691 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState( isPENDING=False )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001692 return checkFlowsResult
1693
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001694def link( main, sw1, sw2, option ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001695
1696 # link down
alison52b25892016-09-19 10:53:48 -07001697 main.log.info( itemName + ": Bring link " + option + " between " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001698 sw1 + " and " + sw2 )
1699 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
1700 return linkResult
1701
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001702def scapyCheckConnection( main, senders, recipients, vlanId=None, useTCP=False, packet=None, packetFilter=None, expectFailure=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001703 """
1704 Checks the connectivity between all given sender hosts and all given recipient hosts
1705 Packet may be specified. Defaults to Ether/IP packet
1706 Packet Filter may be specified. Defaults to Ether/IP from current sender MAC
1707 Todo: Optional packet and packet filter attributes for sender and recipients
1708 Expect Failure when the sender and recipient are not supposed to have connectivity
1709 Timeout of 1 second, returns main.TRUE if the filter is not triggered and kills the filter
1710
1711 """
1712 connectionsFunctional = main.TRUE
1713
1714 if not packetFilter:
1715 packetFilter = 'ether host {}'
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001716 if useTCP:
1717 packetFilter += ' ip proto \\tcp tcp port {}'.format(main.params[ 'SDNIP' ][ 'dstPort' ])
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001718 if expectFailure:
1719 timeout = 1
1720 else:
1721 timeout = 10
1722
1723 for sender in senders:
1724 try:
1725 senderComp = getattr( main, sender )
1726 except AttributeError:
1727 main.log.error( "main has no attribute {}".format( sender ) )
1728 connectionsFunctional = main.FALSE
1729 continue
1730
1731 for recipient in recipients:
1732 # Do not send packets to self since recipient CLI will already be busy
1733 if recipient == sender:
1734 continue
1735 try:
1736 recipientComp = getattr( main, recipient )
1737 except AttributeError:
1738 main.log.error( "main has no attribute {}".format( recipient ) )
1739 connectionsFunctional = main.FALSE
1740 continue
1741
Jeremy Songster832f9e92016-05-05 14:30:49 -07001742 if vlanId:
1743 recipientComp.startFilter( pktFilter = ( "vlan {}".format( vlanId ) + " && " + packetFilter.format( senderComp.hostMac ) ) )
1744 else:
1745 recipientComp.startFilter( pktFilter = packetFilter.format( senderComp.hostMac ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001746
1747 if not packet:
Jeremy Songster832f9e92016-05-05 14:30:49 -07001748 if vlanId:
1749 pkt = 'Ether( src="{0}", dst="{2}" )/Dot1Q(vlan={4})/IP( src="{1}", dst="{3}" )'.format(
1750 senderComp.hostMac,
1751 senderComp.hostIp,
1752 recipientComp.hostMac,
1753 recipientComp.hostIp,
1754 vlanId )
1755 else:
1756 pkt = 'Ether( src="{0}", dst="{2}" )/IP( src="{1}", dst="{3}" )'.format(
1757 senderComp.hostMac,
1758 senderComp.hostIp,
1759 recipientComp.hostMac,
1760 recipientComp.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001761 else:
1762 pkt = packet
Jeremy Songster832f9e92016-05-05 14:30:49 -07001763 if vlanId:
1764 senderComp.sendPacket( iface=( "{0}-eth0.{1}".format( sender, vlanId ) ), packet = pkt )
1765 else:
1766 senderComp.sendPacket( packet = pkt )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001767
1768 if recipientComp.checkFilter( timeout ):
1769 if expectFailure:
1770 main.log.error( "Packet from {0} successfully received by {1} when it should not have been".format( sender , recipient ) )
1771 connectionsFunctional = main.FALSE
1772 else:
1773 main.log.info( "Packet from {0} successfully received by {1}".format( sender , recipient ) )
alison52b25892016-09-19 10:53:48 -07001774 connectionsFunctional = main.TRUE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001775 else:
1776 recipientComp.killFilter()
1777 if expectFailure:
1778 main.log.info( "As expected, packet from {0} was not received by {1}".format( sender , recipient ) )
1779 else:
1780 main.log.error( "Packet from {0} was not received by {1}".format( sender , recipient ) )
1781 connectionsFunctional = main.FALSE
1782
1783 return connectionsFunctional
1784
alison52b25892016-09-19 10:53:48 -07001785
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001786def removeAllIntents( main, intentsId ):
1787 """
1788 Remove all intents in the intentsId
1789 """
1790
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001791 onosSummary = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001792 removeIntentResult = main.TRUE
1793 # Remove intents
1794 for intent in intentsId:
1795 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
1796
acsmarscfa52272015-08-06 15:21:45 -07001797 time.sleep( main.removeIntentSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001798
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001799 # If there is remianing intents then remove intents should fail
1800 for i in range( main.numCtrls ):
1801 onosSummary.append( json.loads( main.CLIs[ i ].summary() ) )
1802
1803 for summary in onosSummary:
1804 if summary.get( 'intents' ) != 0:
1805 main.log.warn( itemName + ": There are " +
1806 str( summary.get( 'intents' ) ) +
1807 " intents remaining in node " +
1808 str( summary.get( 'node' ) ) +
1809 ", failed to remove all the intents " )
1810 removeIntentResult = main.FALSE
1811
1812 if removeIntentResult:
1813 main.log.info( itemName + ": There are no more intents remaining, " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001814 "successfully removed all the intents." )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001815
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001816 return removeIntentResult
1817
1818def checkFlowsCount( main ):
1819 """
1820 Check flows count in each node
1821 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001822 flowsCount = []
1823 main.log.info( itemName + ": Checking flows count in each ONOS node" )
1824 for i in range( main.numCtrls ):
1825 summaryResult = main.CLIs[ i ].summary()
1826 if not summaryResult:
1827 main.log.error( itemName + ": There is something wrong with " +
1828 "summary command" )
1829 return main.FALSE
1830 else:
1831 summaryJson = json.loads( summaryResult )
1832 flowsCount.append( summaryJson.get( 'flows' ) )
1833
1834 if flowsCount:
1835 if all( flows==flowsCount[ 0 ] for flows in flowsCount ):
1836 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
1837 " flows in all ONOS node" )
1838 else:
1839 for i in range( main.numCtrls ):
1840 main.log.debug( itemName + ": ONOS node " + str( i ) + " has " +
kelvin-onlab6dea6e62015-07-23 13:07:26 -07001841 str( flowsCount[ i ] ) + " flows" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001842 else:
1843 main.log.error( "Checking flows count failed, check summary command" )
1844 return main.FALSE
1845
1846 return main.TRUE
1847
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001848def checkLeaderChange( leaders1, leaders2 ):
acsmarse6b410f2015-07-17 14:39:34 -07001849 """
1850 Checks for a change in intent partition leadership.
1851
1852 Takes the output of leaders -c in json string format before and after
1853 a potential change as input
1854
1855 Returns main.TRUE if no mismatches are detected
1856 Returns main.FALSE if there is a mismatch or on error loading the input
1857 """
1858 try:
1859 leaders1 = json.loads( leaders1 )
1860 leaders2 = json.loads( leaders2 )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001861 except( AttributeError, TypeError ):
acsmarse6b410f2015-07-17 14:39:34 -07001862 main.log.exception( self.name + ": Object not as expected" )
1863 return main.FALSE
1864 except Exception:
1865 main.log.exception( self.name + ": Uncaught exception!" )
1866 main.cleanup()
1867 main.exit()
1868 main.log.info( "Checking Intent Paritions for Change in Leadership" )
1869 mismatch = False
1870 for dict1 in leaders1:
1871 if "intent" in dict1.get( "topic", [] ):
1872 for dict2 in leaders2:
1873 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \
1874 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
1875 mismatch = True
1876 main.log.error( "{0} changed leader from {1} to {2}".\
1877 format( dict1.get( "topic", "no-topic" ),\
1878 dict1.get( "leader", "no-leader" ),\
1879 dict2.get( "leader", "no-leader" ) ) )
1880 if mismatch:
1881 return main.FALSE
1882 else:
1883 return main.TRUE
kelvin-onlab016dce22015-08-10 09:54:11 -07001884
1885def report( main ):
1886 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001887 Report errors/warnings/exceptions
kelvin-onlab016dce22015-08-10 09:54:11 -07001888 """
kelvin-onlab016dce22015-08-10 09:54:11 -07001889 main.ONOSbench.logReport( main.ONOSip[ 0 ],
1890 [ "INFO",
1891 "FOLLOWER",
1892 "WARN",
1893 "flow",
1894 "ERROR",
1895 "Except" ],
1896 "s" )
1897
1898 main.log.info( "ERROR report: \n" )
1899 for i in range( main.numCtrls ):
1900 main.ONOSbench.logReport( main.ONOSip[ i ],
1901 [ "ERROR" ],
1902 "d" )
1903
1904 main.log.info( "EXCEPTIONS report: \n" )
1905 for i in range( main.numCtrls ):
1906 main.ONOSbench.logReport( main.ONOSip[ i ],
1907 [ "Except" ],
1908 "d" )
1909
1910 main.log.info( "WARNING report: \n" )
1911 for i in range( main.numCtrls ):
1912 main.ONOSbench.logReport( main.ONOSip[ i ],
1913 [ "WARN" ],
1914 "d" )
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001915
1916def flowDuration( main ):
1917 """
1918 Check age of flows to see if flows are being overwritten
1919 """
1920 import time
1921 main.log.info( "Getting current flow durations" )
1922 flowsJson1 = main.CLIs[ 0 ].flows( noCore=True )
1923 try:
1924 flowsJson1 = json.loads( flowsJson1 )
1925 except ValueError:
1926 main.log.error( "Unable to read flows" )
1927 return main.FALSE
1928 flowLife = []
1929 waitFlowLife = []
1930 for device in flowsJson1:
1931 if device.get( 'flowcount', 0 ) > 0:
1932 for i in range( device[ 'flowCount' ] ):
1933 flowLife.append( device[ 'flows' ][ i ][ 'life' ] )
1934 main.log.info( "Sleeping for {} seconds".format( main.flowDurationSleep ) )
1935 time.sleep( main.flowDurationSleep )
1936 main.log.info( "Getting new flow durations" )
1937 flowsJson2 = main.CLIs[ 0 ].flows( noCore=True )
1938 try:
1939 flowsJson2 = json.loads( flowsJson2 )
1940 except ValueError:
1941 main.log.error( "Unable to read flows" )
1942 return main.FALSE
1943 for device in flowsJson2:
1944 if device.get( 'flowcount', 0 ) > 0:
1945 for i in range( device[ 'flowCount' ] ):
1946 waitFlowLife.append( device[ 'flows' ][ i ][ 'life' ] )
1947 main.log.info( "Determining whether flows where overwritten" )
1948 if len( flowLife ) == len( waitFlowLife ):
alison52b25892016-09-19 10:53:48 -07001949 for i in range( len( flowLife ) ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001950 if waitFlowLife[ i ] - flowLife[ i ] < main.flowDurationSleep:
1951 return main.FALSE
1952 else:
1953 return main.FALSE
1954 return main.TRUE
alison52b25892016-09-19 10:53:48 -07001955
1956
1957def EncapsulatedIntentCheck( main, tag="" ):
1958 """
1959 Check encapsulated intents
1960 tag: encapsulation tag (e.g. VLAN, MPLS)
1961
1962 Getting added flows
1963 Check tags on each flows
1964 If each direction has push or pop, passed
1965 else failed
1966
1967 """
1968 import json
1969 HostJson = []
1970 Jflows = main.CLIs[ 0 ].flows( noCore=True )
1971 try:
1972 Jflows = json.loads( Jflows )
1973 except ValueError:
1974 main.log.error( "Unable to read flows" )
1975 return main.FALSE
1976
1977 for flow in Jflows:
1978 if len(flow[ "flows" ]) != 0:
1979 HostJson.append( flow[ "flows" ] )
1980
1981 totalflows = len( HostJson[ 0 ])
1982
1983 pop = 0
1984 push = 0
1985
1986 PopTag = tag + "_POP"
1987 PushTag = tag + "_PUSH"
1988
1989 for EachHostJson in HostJson:
1990 for i in range( totalflows ):
1991 if EachHostJson[ i ][ "treatment" ][ "instructions" ][ 0 ][ "subtype" ] == PopTag:
1992 pop += 1
1993 elif EachHostJson[ i ][ "treatment" ][ "instructions" ][ 0 ][ "subtype" ] == PushTag:
1994 push += 1
1995
1996 if pop == totalflows and push == totalflows:
1997 return main.TRUE
1998 else:
1999 return main.FALSE