blob: 48c0f276aa573d468d4eb84d6ebc6f52478d14f6 [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,
Shreyaca8990f2017-03-16 11:43:11 -070094 args=( main, [ intentId ] ), sleep=main.checkIntentSleep, attempts=50 ):
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
Shreyaca8990f2017-03-16 11:43:11 -0700200 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
201 args=( main, [ intentId ] ), sleep=main.checkIntentSleep, attempts=50 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800202 main.assertReturnString += 'Initial Intent State Passed\n'
203 else:
204 main.assertReturnString += 'Initial Intent State Failed\n'
205 testResult = main.FALSE
206
207 # Check flows count in each node
Shreyaca8990f2017-03-16 11:43:11 -0700208 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
209 args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState,
210 retValue=main.FALSE,
211 args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800212 main.assertReturnString += 'Initial Flow State Passed\n'
213 else:
214 main.assertReturnString += 'Intial Flow State Failed\n'
215 testResult = main.FALSE
216
217 # Check Connectivity
Shreyaca8990f2017-03-16 11:43:11 -0700218 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, attempts=50, sleep=main.checkConnectionSleep,
219 args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800220 main.assertReturnString += 'Initial Ping Passed\n'
221 else:
222 main.assertReturnString += 'Initial Ping Failed\n'
223 testResult = main.FALSE
224
225 # Test rerouting if these variables exist
226 if sw1 and sw2 and expectedLink:
227 # Take link down
228 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
229 main.assertReturnString += 'Link Down Passed\n'
230 else:
231 main.assertReturnString += 'Link Down Failed\n'
232 testResult = main.FALSE
233
234 # Check intent state
Shreyaca8990f2017-03-16 11:43:11 -0700235 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
236 args=( main, [ intentId ] ), sleep=main.checkIntentHostSleep, attempts=5 * 20 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800237 main.assertReturnString += 'Link Down Intent State Passed\n'
238 else:
239 main.assertReturnString += 'Link Down Intent State Failed\n'
240 testResult = main.FALSE
241
242 # Check flows count in each node
Shreyaca8990f2017-03-16 11:43:11 -0700243 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=main.checkFlowCountSleep,
244 attempts=200 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ],
245 sleep=main.checkFlowCountSleep, attempts=200 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800246 main.assertReturnString += 'Link Down Flow State Passed\n'
247 else:
248 main.assertReturnString += 'Link Down Flow State Failed\n'
249 testResult = main.FALSE
250
251 # Check OnosTopology
252 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink ) ):
253 main.assertReturnString += 'Link Down Topology State Passed\n'
254 else:
255 main.assertReturnString += 'Link Down Topology State Failed\n'
256 testResult = main.FALSE
257
258 # Check Connection
Shreyaca8990f2017-03-16 11:43:11 -0700259 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
260 args=( main, senderNames, recipientNames, vlanId ),
261 sleep=main.checkConnectionSleep, attempts=5 * 20 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800262 main.assertReturnString += 'Link Down Pingall Passed\n'
263 else:
264 main.assertReturnString += 'Link Down Pingall Failed\n'
265 testResult = main.FALSE
266
267 # Bring link up
268 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
269 main.assertReturnString += 'Link Up Passed\n'
270 else:
271 main.assertReturnString += 'Link Up Failed\n'
272 testResult = main.FALSE
273
274 # Wait for reroute
275 time.sleep( main.rerouteSleep )
276
277 # Check Intents
Shreyaca8990f2017-03-16 11:43:11 -0700278 if utilities.retry( f=checkIntentState, retValue=main.FALSE, attempts=100,
279 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800280 main.assertReturnString += 'Link Up Intent State Passed\n'
281 else:
282 main.assertReturnString += 'Link Up Intent State Failed\n'
283 testResult = main.FALSE
284
285 # Check flows count in each node
Shreyaca8990f2017-03-16 11:43:11 -0700286 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ],
287 sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE,
288 args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800289 main.assertReturnString += 'Link Up Flow State Passed\n'
290 else:
291 main.assertReturnString += 'Link Up Flow State Failed\n'
292 testResult = main.FALSE
293
294 # Check OnosTopology
295 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
296 main.assertReturnString += 'Link Up Topology State Passed\n'
297 else:
298 main.assertReturnString += 'Link Up Topology State Failed\n'
299 testResult = main.FALSE
300
301 # Check Connection
Jeremy Songster832f9e92016-05-05 14:30:49 -0700302 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800303 main.assertReturnString += 'Link Up Pingall Passed\n'
304 else:
305 main.assertReturnString += 'Link Up Pingall Failed\n'
306 testResult = main.FALSE
307
308 # Remove all intents
Shreyaca8990f2017-03-16 11:43:11 -0700309 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, attempts=10, args=( main, [ intentId ] ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800310 main.assertReturnString += 'Remove Intents Passed'
311 else:
312 main.assertReturnString += 'Remove Intents Failed'
313 testResult = main.FALSE
314
315 return testResult
316
317def installPointIntent( main,
318 name,
319 senders,
320 recipients,
321 onosNode=0,
322 ethType="",
323 bandwidth="",
324 lambdaAlloc=False,
alisonda157272016-12-22 01:13:21 -0800325 protected=False,
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800326 ipProto="",
327 ipSrc="",
328 ipDst="",
329 tcpSrc="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700330 tcpDst="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700331 setVlan="",
332 encap="" ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800333 """
334 Installs a Single to Single Point Intent
335
336 Description:
337 Install a single to single point intent
338
339 Steps:
340 - Fetch host data if not given
341 - Add point intent
342 - Ingress device is the first sender device
343 - Egress device is the first recipient device
344 - Ports if defined in senders or recipients
345 - MAC address ethSrc loaded from Ingress device
346 - Check intent state with retry
347 Required:
348 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
349 senders - List of host dictionaries i.e.
350 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
351 recipients - List of host dictionaries i.e.
352 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
353 Optional:
354 onosNode - ONOS node to install the intents in main.CLIs[ ]
355 0 by default so that it will always use the first
356 ONOS node
357 ethType - Ethernet type eg. IPV4, IPV6
358 bandwidth - Bandwidth capacity
359 lambdaAlloc - Allocate lambda, defaults to False
360 ipProto - IP protocol
361 tcp - TCP ports in the same order as the hosts in hostNames
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700362 sw1 - First switch to bring down & up for rerouting purpose
363 sw2 - Second switch to bring down & up for rerouting purpose
364 expectedLink - Expected link when the switches are down, it should
365 be two links lower than the links before the two
366 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700367 """
368
369 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800370 assert senders, "You must specify a sender"
371 assert recipients, "You must specify a recipient"
372 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700373
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800374 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700375 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700376
Jeremy6f000c62016-02-25 17:02:28 -0800377 main.log.info( itemName + ": Adding point to point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700378
Jeremyd9e4eb12016-04-13 12:09:06 -0700379 try:
380 for sender in senders:
381 if not sender.get( "device" ):
382 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
383 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800384
Jeremyd9e4eb12016-04-13 12:09:06 -0700385 for recipient in recipients:
386 if not recipient.get( "device" ):
387 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
388 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800389
390
Jeremyd9e4eb12016-04-13 12:09:06 -0700391 ingressDevice = senders[ 0 ].get( "device" )
392 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800393
Jeremyd9e4eb12016-04-13 12:09:06 -0700394 portIngress = senders[ 0 ].get( "port", "" )
395 portEgress = recipients[ 0 ].get( "port", "" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800396
Jeremyd9e4eb12016-04-13 12:09:06 -0700397 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800398
Jeremyd9e4eb12016-04-13 12:09:06 -0700399 ipSrc = senders[ 0 ].get( "ip" )
400 ipDst = recipients[ 0 ].get( "ip" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800401
Jeremy Songster832f9e92016-05-05 14:30:49 -0700402 vlanId = senders[ 0 ].get( "vlan" )
403
Jeremyd9e4eb12016-04-13 12:09:06 -0700404 # Adding point intent
405 intentId = main.CLIs[ onosNode ].addPointIntent(
406 ingressDevice=ingressDevice,
407 egressDevice=egressDevice,
408 portIngress=portIngress,
409 portEgress=portEgress,
410 ethType=ethType,
411 ethDst=dstMac,
412 bandwidth=bandwidth,
413 lambdaAlloc=lambdaAlloc,
alisonda157272016-12-22 01:13:21 -0800414 protected=protected,
Jeremyd9e4eb12016-04-13 12:09:06 -0700415 ipProto=ipProto,
416 ipSrc=ipSrc,
417 ipDst=ipDst,
418 tcpSrc=tcpSrc,
Jeremy Songster832f9e92016-05-05 14:30:49 -0700419 tcpDst=tcpDst,
Jeremy Songsterff553672016-05-12 17:06:23 -0700420 vlanId=vlanId,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700421 setVlan=setVlan,
422 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700423 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700424 errorMsg = "There was a problem loading the hosts data."
425 if intentId:
426 errorMsg += " There was a problem installing Point to Point intent."
427 main.log.error( errorMsg )
428 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700429
430 # Check intents state
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700431 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -0700432 args=( main, [ intentId ] ), sleep=main.checkIntentSleep*2, attempts=50 ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700433 main.assertReturnString += 'Install Intent State Passed\n'
alison52b25892016-09-19 10:53:48 -0700434
435 # Check VLAN if test encapsulation
436 if encap != "":
437 if EncapsulatedIntentCheck( main, tag=encap ):
438 main.assertReturnString += 'Encapsulation intents check Passed\n'
439 else:
440 main.assertReturnString += 'Encapsulation intents check failed\n'
alisonda157272016-12-22 01:13:21 -0800441
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700442 if flowDuration( main ):
443 main.assertReturnString += 'Flow duration check Passed\n'
444 return intentId
445 else:
446 main.assertReturnString += 'Flow duration check failed\n'
447 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -0700448 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800449 main.log.error( "Point Intent did not install correctly" )
450 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700451
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700452def pointIntentTcp( main,
453 name,
454 host1,
455 host2,
456 onosNode=0,
457 deviceId1="",
458 deviceId2="",
459 port1="",
460 port2="",
461 ethType="",
462 mac1="",
463 mac2="",
464 bandwidth="",
465 lambdaAlloc=False,
466 ipProto="",
467 ip1="",
468 ip2="",
469 tcp1="",
470 tcp2="",
471 sw1="",
472 sw2="",
473 expectedLink=0 ):
474
475 """
476 Description:
477 Verify add-point-intent only for TCP
478 Steps:
479 - Get device ids | ports
480 - Add point intents
481 - Check intents
482 - Verify flows
483 - Ping hosts
484 - Reroute
485 - Link down
486 - Verify flows
487 - Check topology
488 - Ping hosts
489 - Link up
490 - Verify flows
491 - Check topology
492 - Ping hosts
493 - Remove intents
494 Required:
495 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
496 host1 - Name of first host
497 host2 - Name of second host
498 Optional:
499 onosNode - ONOS node to install the intents in main.CLIs[ ]
500 0 by default so that it will always use the first
501 ONOS node
502 deviceId1 - ONOS device id of the first switch, the same as the
503 location of the first host eg. of:0000000000000001/1,
504 located at device 1 port 1
505 deviceId2 - ONOS device id of the second switch
506 port1 - The port number where the first host is attached
507 port2 - The port number where the second host is attached
508 ethType - Ethernet type eg. IPV4, IPV6
509 mac1 - Mac address of first host
510 mac2 - Mac address of the second host
511 bandwidth - Bandwidth capacity
512 lambdaAlloc - Allocate lambda, defaults to False
513 ipProto - IP protocol
514 ip1 - IP address of first host
515 ip2 - IP address of second host
516 tcp1 - TCP port of first host
517 tcp2 - TCP port of second host
518 sw1 - First switch to bring down & up for rerouting purpose
519 sw2 - Second switch to bring down & up for rerouting purpose
520 expectedLink - Expected link when the switches are down, it should
521 be two links lower than the links before the two
522 switches are down
523 """
524
525 assert main, "There is no main variable"
526 assert name, "variable name is empty"
527 assert host1 and host2, "You must specify hosts"
528
529 global itemName
530 itemName = name
531 host1 = host1
532 host2 = host2
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700533 intentsId = []
534
535 iperfResult = main.TRUE
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700536 linkDownResult = main.TRUE
537 linkUpResult = main.TRUE
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700538
539 # Adding bidirectional point intents
540 main.log.info( itemName + ": Adding point intents" )
541 intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
542 egressDevice=deviceId2,
543 portIngress=port1,
544 portEgress=port2,
545 ethType=ethType,
546 ethSrc=mac1,
547 ethDst=mac2,
548 bandwidth=bandwidth,
549 lambdaAlloc=lambdaAlloc,
550 ipProto=ipProto,
551 ipSrc=ip1,
552 ipDst=ip2,
553 tcpSrc=tcp1,
554 tcpDst="" )
555
556 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
557 egressDevice=deviceId1,
558 portIngress=port2,
559 portEgress=port1,
560 ethType=ethType,
561 ethSrc=mac2,
562 ethDst=mac1,
563 bandwidth=bandwidth,
564 lambdaAlloc=lambdaAlloc,
565 ipProto=ipProto,
566 ipSrc=ip2,
567 ipDst=ip1,
568 tcpSrc=tcp2,
569 tcpDst="" )
570
571 intent3 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
572 egressDevice=deviceId2,
573 portIngress=port1,
574 portEgress=port2,
575 ethType=ethType,
576 ethSrc=mac1,
577 ethDst=mac2,
578 bandwidth=bandwidth,
579 lambdaAlloc=lambdaAlloc,
580 ipProto=ipProto,
581 ipSrc=ip1,
582 ipDst=ip2,
583 tcpSrc="",
584 tcpDst=tcp2 )
585
586 intent4 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
587 egressDevice=deviceId1,
588 portIngress=port2,
589 portEgress=port1,
590 ethType=ethType,
591 ethSrc=mac2,
592 ethDst=mac1,
593 bandwidth=bandwidth,
594 lambdaAlloc=lambdaAlloc,
595 ipProto=ipProto,
596 ipSrc=ip2,
597 ipDst=ip1,
598 tcpSrc="",
599 tcpDst=tcp1 )
600 intentsId.append( intent1 )
601 intentsId.append( intent2 )
602 intentsId.append( intent3 )
603 intentsId.append( intent4 )
604
605 # Check intents state
606 time.sleep( main.checkIntentSleep )
Shreyaca8990f2017-03-16 11:43:11 -0700607 intentResult = utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [intentsId ] ),
608 sleep=1, attempts=50 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700609 # Check flows count in each node
610 checkFlowsCount( main )
611
612 # Check intents state again if first check fails...
613 if not intentResult:
Shreyaca8990f2017-03-16 11:43:11 -0700614 intentResult = utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [intentsId ] ),
615 sleep=1, attempts=50 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700616
617 # Check flows count in each node
618 checkFlowsCount( main )
619
620 # Verify flows
621 checkFlowsState( main )
622
623 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700624 iperfTemp = main.Mininet1.iperftcp( host1, host2 ,10 )
acsmarsd4862d12015-10-06 17:57:34 -0700625 iperfResult = iperfResult and iperfTemp
626 if iperfTemp:
627 main.assertReturnString += 'Initial Iperf Passed\n'
628 else:
629 main.assertReturnString += 'Initial Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700630
631 # Test rerouting if these variables exist
632 if sw1 and sw2 and expectedLink:
633 # link down
634 linkDownResult = link( main, sw1, sw2, "down" )
acsmarsd4862d12015-10-06 17:57:34 -0700635
636 if linkDownResult:
637 main.assertReturnString += 'Link Down Passed\n'
638 else:
639 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700640
641 # Check flows count in each node
642 checkFlowsCount( main )
643 # Verify flows
644 checkFlowsState( main )
645
646 # Check OnosTopology
647 topoResult = checkTopology( main, expectedLink )
acsmarsd4862d12015-10-06 17:57:34 -0700648 if topoResult:
649 main.assertReturnString += 'Link Down Topology State Passed\n'
650 else:
651 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700652
653 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700654 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700655 iperfResult = iperfResult and iperfTemp
656 if iperfTemp:
657 main.assertReturnString += 'Link Down Iperf Passed\n'
658 else:
659 main.assertReturnString += 'Link Down Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700660
acsmarsd4862d12015-10-06 17:57:34 -0700661 # Check intent state
Shreyaca8990f2017-03-16 11:43:11 -0700662 intentTemp = utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [intentsId ] ),
663 sleep=1, attempts=50 )
acsmarsd4862d12015-10-06 17:57:34 -0700664 intentResult = intentResult and intentTemp
665 if intentTemp:
666 main.assertReturnString += 'Link Down Intent State Passed\n'
667 else:
668 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700669
670 # Checks ONOS state in link down
671 if linkDownResult and topoResult and iperfResult and intentResult:
672 main.log.info( itemName + ": Successfully brought link down" )
673 else:
674 main.log.error( itemName + ": Failed to bring link down" )
675
676 # link up
677 linkUpResult = link( main, sw1, sw2, "up" )
alison52b25892016-09-19 10:53:48 -0700678 if linkUpResult:
acsmarsd4862d12015-10-06 17:57:34 -0700679 main.assertReturnString += 'Link Up Passed\n'
680 else:
681 main.assertReturnString += 'Link Up Failed\n'
682
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700683 time.sleep( main.rerouteSleep )
684
685 # Check flows count in each node
686 checkFlowsCount( main )
687 # Verify flows
688 checkFlowsState( main )
689
690 # Check OnosTopology
691 topoResult = checkTopology( main, main.numLinks )
692
acsmarsd4862d12015-10-06 17:57:34 -0700693 if topoResult:
694 main.assertReturnString += 'Link Up Topology State Passed\n'
695 else:
696 main.assertReturnString += 'Link Up Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700697
acsmarsd4862d12015-10-06 17:57:34 -0700698 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700699 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700700 iperfResult = iperfResult and iperfTemp
701 if iperfTemp:
702 main.assertReturnString += 'Link Up Iperf Passed\n'
703 else:
704 main.assertReturnString += 'Link Up Iperf Failed\n'
705
706 # Check intent state
Shreyaca8990f2017-03-16 11:43:11 -0700707 intentTemp = utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [intentsId ] ),
708 sleep=1, attempts=50 )
acsmarsd4862d12015-10-06 17:57:34 -0700709 intentResult = intentResult and intentTemp
710 if intentTemp:
711 main.assertReturnString += 'Link Down Intent State Passed\n'
712 else:
713 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700714
715 # Checks ONOS state in link up
716 if linkUpResult and topoResult and iperfResult and intentResult:
717 main.log.info( itemName + ": Successfully brought link back up" )
718 else:
719 main.log.error( itemName + ": Failed to bring link back up" )
720
721 # Remove all intents
722 removeIntentResult = removeAllIntents( main, intentsId )
acsmarsd4862d12015-10-06 17:57:34 -0700723 if removeIntentResult:
724 main.assertReturnString += 'Remove Intents Passed'
725 else:
726 main.assertReturnString += 'Remove Intents Failed'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700727
728 stepResult = iperfResult and linkDownResult and linkUpResult \
729 and intentResult and removeIntentResult
730
731 return stepResult
732
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800733def installSingleToMultiIntent( main,
734 name,
735 senders,
736 recipients,
737 onosNode=0,
738 ethType="",
739 bandwidth="",
740 lambdaAlloc=False,
741 ipProto="",
742 ipAddresses="",
743 tcp="",
744 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700745 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -0700746 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700747 partial=False,
748 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700749 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800750 Installs a Single to Multi Point Intent
751
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700752 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800753 Install a single to multi point intent using
754 add-single-to-multi-intent
755
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700756 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800757 - Fetch host data if not given
758 - Add single to multi intent
759 - Ingress device is the first sender host
760 - Egress devices are the recipient devices
761 - Ports if defined in senders or recipients
762 - MAC address ethSrc loaded from Ingress device
763 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700764 Required:
765 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800766 senders - List of host dictionaries i.e.
767 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
768 recipients - List of host dictionaries i.e.
769 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700770 Optional:
771 onosNode - ONOS node to install the intents in main.CLIs[ ]
772 0 by default so that it will always use the first
773 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700774 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700775 bandwidth - Bandwidth capacity
776 lambdaAlloc - Allocate lambda, defaults to False
777 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700778 tcp - TCP ports in the same order as the hosts in hostNames
779 sw1 - First switch to bring down & up for rerouting purpose
780 sw2 - Second switch to bring down & up for rerouting purpose
781 expectedLink - Expected link when the switches are down, it should
782 be two links lower than the links before the two
783 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700784 """
785
786 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800787 assert senders, "You must specify a sender"
788 assert recipients, "You must specify a recipient"
789 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700790
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800791 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700792 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700793
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700794 main.log.info( itemName + ": Adding single point to multi point intents" )
795
Jeremyd9e4eb12016-04-13 12:09:06 -0700796 try:
797 for sender in senders:
798 if not sender.get( "device" ):
799 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
800 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700801
Jeremyd9e4eb12016-04-13 12:09:06 -0700802 for recipient in recipients:
803 if not recipient.get( "device" ):
804 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
805 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700806
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700807
Jeremyd9e4eb12016-04-13 12:09:06 -0700808 ingressDevice = senders[ 0 ].get( "device" )
809 egressDeviceList = [ x.get( "device" ) for x in recipients if x.get( "device" ) ]
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800810
Jeremyd9e4eb12016-04-13 12:09:06 -0700811 portIngress = senders[ 0 ].get( "port", "" )
812 portEgressList = [ x.get( "port" ) for x in recipients if x.get( "port" ) ]
813 if not portEgressList:
814 portEgressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800815
Jeremyd9e4eb12016-04-13 12:09:06 -0700816 srcMac = senders[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700817 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800818
Jeremyd9e4eb12016-04-13 12:09:06 -0700819 # Adding point intent
820 intentId = main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
821 ingressDevice=ingressDevice,
822 egressDeviceList=egressDeviceList,
823 portIngress=portIngress,
824 portEgressList=portEgressList,
825 ethType=ethType,
826 ethSrc=srcMac,
827 bandwidth=bandwidth,
828 lambdaAlloc=lambdaAlloc,
829 ipProto=ipProto,
830 ipSrc="",
831 ipDst="",
832 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -0700833 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700834 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -0700835 setVlan=setVlan,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700836 partial=partial,
837 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700838 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700839 errorMsg = "There was a problem loading the hosts data."
840 if intentId:
841 errorMsg += " There was a problem installing Singlepoint to Multipoint intent."
842 main.log.error( errorMsg )
843 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700844
845 # Check intents state
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700846 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -0700847 args=( main, [ intentId ] ), sleep=main.checkIntentSleep, attempts=50 ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700848 main.assertReturnString += 'Install Intent State Passed\n'
849 if flowDuration( main ):
850 main.assertReturnString += 'Flow duration check Passed\n'
851 return intentId
852 else:
853 main.assertReturnString += 'Flow duration check failed\n'
854 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -0700855 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800856 main.log.error( "Single to Multi Intent did not install correctly" )
857 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700858
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800859def installMultiToSingleIntent( main,
860 name,
861 senders,
862 recipients,
863 onosNode=0,
864 ethType="",
865 bandwidth="",
866 lambdaAlloc=False,
867 ipProto="",
868 ipAddresses="",
869 tcp="",
870 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700871 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -0700872 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700873 partial=False,
874 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700875 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800876 Installs a Multi to Single Point Intent
877
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700878 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800879 Install a multi to single point intent using
880 add-multi-to-single-intent
881
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700882 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800883 - Fetch host data if not given
884 - Add multi to single intent
885 - Ingress devices are the senders devices
886 - Egress device is the first recipient host
887 - Ports if defined in senders or recipients
888 - MAC address ethSrc loaded from Ingress device
889 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700890 Required:
891 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800892 senders - List of host dictionaries i.e.
893 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
894 recipients - List of host dictionaries i.e.
895 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700896 Optional:
897 onosNode - ONOS node to install the intents in main.CLIs[ ]
898 0 by default so that it will always use the first
899 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700900 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700901 bandwidth - Bandwidth capacity
902 lambdaAlloc - Allocate lambda, defaults to False
903 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700904 tcp - TCP ports in the same order as the hosts in hostNames
905 sw1 - First switch to bring down & up for rerouting purpose
906 sw2 - Second switch to bring down & up for rerouting purpose
907 expectedLink - Expected link when the switches are down, it should
908 be two links lower than the links before the two
909 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700910 """
911
912 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800913 assert senders, "You must specify a sender"
914 assert recipients, "You must specify a recipient"
915 # Assert devices or main.hostsData, "You must specify devices"
916
917 global itemName # The name of this run. Used for logs.
918 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800919
920 main.log.info( itemName + ": Adding mutli to single point intents" )
921
Jeremyd9e4eb12016-04-13 12:09:06 -0700922 try:
923 for sender in senders:
924 if not sender.get( "device" ):
925 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
926 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800927
Jeremyd9e4eb12016-04-13 12:09:06 -0700928 for recipient in recipients:
929 if not recipient.get( "device" ):
930 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
931 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800932
Jeremyd9e4eb12016-04-13 12:09:06 -0700933 ingressDeviceList = [ x.get( "device" ) for x in senders if x.get( "device" ) ]
934 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800935
Jeremyd9e4eb12016-04-13 12:09:06 -0700936 portIngressList = [ x.get( "port" ) for x in senders if x.get( "port" ) ]
937 portEgress = recipients[ 0 ].get( "port", "" )
938 if not portIngressList:
939 portIngressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800940
Jeremyd9e4eb12016-04-13 12:09:06 -0700941 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700942 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800943
Jeremyd9e4eb12016-04-13 12:09:06 -0700944 # Adding point intent
945 intentId = main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
946 ingressDeviceList=ingressDeviceList,
947 egressDevice=egressDevice,
948 portIngressList=portIngressList,
949 portEgress=portEgress,
950 ethType=ethType,
951 ethDst=dstMac,
952 bandwidth=bandwidth,
953 lambdaAlloc=lambdaAlloc,
954 ipProto=ipProto,
955 ipSrc="",
956 ipDst="",
957 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -0700958 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700959 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -0700960 setVlan=setVlan,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700961 partial=partial,
962 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700963 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700964 errorMsg = "There was a problem loading the hosts data."
965 if intentId:
966 errorMsg += " There was a problem installing Multipoint to Singlepoint intent."
967 main.log.error( errorMsg )
968 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800969
970 # Check intents state
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700971 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -0700972 args=( main, [ intentId ] ), sleep=main.checkIntentSleep, attempts=50 ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700973 main.assertReturnString += 'Install Intent State Passed\n'
974 if flowDuration( main ):
975 main.assertReturnString += 'Flow duration check Passed\n'
976 return intentId
977 else:
978 main.assertReturnString += 'Flow duration check failed\n'
979 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800980 else:
981 main.log.error( "Multi to Single Intent did not install correctly" )
982 return main.FALSE
983
984def testPointIntent( main,
Jeremye0cb5eb2016-01-27 17:39:09 -0800985 name,
986 intentId,
987 senders,
988 recipients,
989 badSenders={},
990 badRecipients={},
991 onosNode=0,
992 ethType="",
993 bandwidth="",
994 lambdaAlloc=False,
alisonda157272016-12-22 01:13:21 -0800995 protected=False,
Jeremye0cb5eb2016-01-27 17:39:09 -0800996 ipProto="",
997 ipAddresses="",
998 tcp="",
999 sw1="s5",
1000 sw2="s2",
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001001 expectedLink=0,
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001002 useTCP=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001003 """
1004 Test a Point Intent
1005
1006 Description:
1007 Test a point intent
1008
1009 Steps:
1010 - Fetch host data if not given
1011 - Check Intent State
1012 - Check Flow State
1013 - Check Connectivity
1014 - Check Lack of Connectivity Between Hosts not in the Intent
1015 - Reroute
1016 - Take Expected Link Down
1017 - Check Intent State
1018 - Check Flow State
1019 - Check Topology
1020 - Check Connectivity
1021 - Bring Expected Link Up
1022 - Check Intent State
1023 - Check Flow State
1024 - Check Topology
1025 - Check Connectivity
1026 - Remove Topology
1027
1028 Required:
1029 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
1030
1031 senders - List of host dictionaries i.e.
1032 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
1033 recipients - List of host dictionaries i.e.
1034 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
1035 Optional:
1036 onosNode - ONOS node to install the intents in main.CLIs[ ]
1037 0 by default so that it will always use the first
1038 ONOS node
1039 ethType - Ethernet type eg. IPV4, IPV6
1040 bandwidth - Bandwidth capacity
1041 lambdaAlloc - Allocate lambda, defaults to False
1042 ipProto - IP protocol
1043 tcp - TCP ports in the same order as the hosts in hostNames
1044 sw1 - First switch to bring down & up for rerouting purpose
1045 sw2 - Second switch to bring down & up for rerouting purpose
1046 expectedLink - Expected link when the switches are down, it should
1047 be two links lower than the links before the two
1048 switches are down
1049
1050 """
1051
1052 # Parameter Validity Check
1053 assert main, "There is no main variable"
1054 assert senders, "You must specify a sender"
1055 assert recipients, "You must specify a recipient"
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001056
1057 global itemName
1058 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001059
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001060 main.log.info( itemName + ": Testing Point Intent" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001061
Jeremyd9e4eb12016-04-13 12:09:06 -07001062 try:
1063 # Names for scapy
1064 senderNames = [ x.get( "name" ) for x in senders ]
1065 recipientNames = [ x.get( "name" ) for x in recipients ]
1066 badSenderNames = [ x.get( "name" ) for x in badSenders ]
1067 badRecipientNames = [ x.get( "name" ) for x in badRecipients ]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001068
Jeremyd9e4eb12016-04-13 12:09:06 -07001069 for sender in senders:
1070 if not sender.get( "device" ):
1071 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1072 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001073
Jeremyd9e4eb12016-04-13 12:09:06 -07001074 for recipient in recipients:
1075 if not recipient.get( "device" ):
1076 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1077 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001078 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001079 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001080 main.log.error( "There was a problem loading the hosts data." )
1081 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001082
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001083 testResult = main.TRUE
1084 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001085
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001086 # Check intent state
Shreyaca8990f2017-03-16 11:43:11 -07001087 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ),
1088 sleep=main.checkIntentSleep, attempts=50 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001089 main.assertReturnString += 'Initial Intent State Passed\n'
acsmarsd4862d12015-10-06 17:57:34 -07001090 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001091 main.assertReturnString += 'Initial Intent State Failed\n'
1092 testResult = main.FALSE
1093
1094 # Check flows count in each node
Shreyaca8990f2017-03-16 11:43:11 -07001095 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ],
1096 sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE,
1097 args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001098 main.assertReturnString += 'Initial Flow State Passed\n'
1099 else:
1100 main.assertReturnString += 'Intial Flow State Failed\n'
1101 testResult = main.FALSE
1102
1103 # Check Connectivity
Shreyaca8990f2017-03-16 11:43:11 -07001104 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1105 args=( main, senderNames, recipientNames, vlanId, useTCP ),
1106 attempts=50, sleep=main.checkConnectionSleep ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001107 main.assertReturnString += 'Initial Ping Passed\n'
1108 else:
1109 main.assertReturnString += 'Initial Ping Failed\n'
1110 testResult = main.FALSE
1111
1112 # Check connections that shouldn't work
1113 if badSenderNames:
1114 main.log.info( "Checking that packets from incorrect sender do not go through" )
1115 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, badSenderNames, recipientNames ), kwargs={ "expectFailure":True } ):
1116 main.assertReturnString += 'Bad Sender Ping Passed\n'
1117 else:
1118 main.assertReturnString += 'Bad Sender Ping Failed\n'
1119 testResult = main.FALSE
1120
1121 if badRecipientNames:
1122 main.log.info( "Checking that packets to incorrect recipients do not go through" )
1123 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, badRecipientNames ), kwargs={ "expectFailure":True } ):
1124 main.assertReturnString += 'Bad Recipient Ping Passed\n'
1125 else:
1126 main.assertReturnString += 'Bad Recipient Ping Failed\n'
1127 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001128
1129 # Test rerouting if these variables exist
1130 if sw1 and sw2 and expectedLink:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001131 # Take link down
1132 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001133 main.assertReturnString += 'Link Down Passed\n'
1134 else:
1135 main.assertReturnString += 'Link Down Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001136 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001137
alisonda157272016-12-22 01:13:21 -08001138 if protected:
1139 # Check Connection
1140 if utilities.retry(f=scapyCheckConnection, retValue=main.FALSE,
1141 args=(main, senderNames, recipientNames, vlanId, useTCP) ):
1142 main.assertReturnString += 'Link down Scapy Packet Received Passed\n'
1143 else:
1144 main.assertReturnString += 'Link down Scapy Packet Recieved Failed\n'
1145 testResult = main.FALSE
1146
1147 if ProtectedIntentCheck( main ):
1148 main.assertReturnString += 'Protected Intent Check Passed\n'
1149 else:
1150 main.assertReturnString += 'Protected Intent Check Failed\n'
1151 testResult = main.FALSE
1152
acsmarsd4862d12015-10-06 17:57:34 -07001153 # Check intent state
Shreyaca8990f2017-03-16 11:43:11 -07001154 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ),
1155 sleep=main.checkIntentPointSleep, attempts=5 * 20 ):
acsmarsd4862d12015-10-06 17:57:34 -07001156 main.assertReturnString += 'Link Down Intent State Passed\n'
1157 else:
1158 main.assertReturnString += 'Link Down Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001159 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001160
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001161 # Check flows count in each node
Shreyaca8990f2017-03-16 11:43:11 -07001162 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=main.checkFlowCountSleep,
1163 attempts=200 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ],
1164 sleep=main.checkFlowCountSleep, attempts=200 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001165 main.assertReturnString += 'Link Down Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001166 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001167 main.assertReturnString += 'Link Down Flow State Failed\n'
1168 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001169
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001170 # Check OnosTopology
1171 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink ) ):
1172 main.assertReturnString += 'Link Down Topology State Passed\n'
1173 else:
1174 main.assertReturnString += 'Link Down Topology State Failed\n'
1175 testResult = main.FALSE
1176
1177 # Check Connection
Shreyaca8990f2017-03-16 11:43:11 -07001178 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1179 args=( main, senderNames, recipientNames, vlanId, useTCP ),
1180 sleep=main.checkConnectionSleep, attempts=5 * 10 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001181 main.assertReturnString += 'Link Down Pingall Passed\n'
1182 else:
1183 main.assertReturnString += 'Link Down Pingall Failed\n'
1184 testResult = main.FALSE
1185
1186 # Bring link up
1187 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001188 main.assertReturnString += 'Link Up Passed\n'
1189 else:
1190 main.assertReturnString += 'Link Up Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001191 testResult = main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -07001192
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001193 # Wait for reroute
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001194 time.sleep( main.rerouteSleep )
1195
acsmarsd4862d12015-10-06 17:57:34 -07001196 # Check Intents
Shreyaca8990f2017-03-16 11:43:11 -07001197 if utilities.retry( f=checkIntentState, retValue=main.FALSE, attempts=100, args=( main, [ intentId ] ),
1198 sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001199 main.assertReturnString += 'Link Up Intent State Passed\n'
1200 else:
1201 main.assertReturnString += 'Link Up Intent State Failed\n'
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 # Check flows count in each node
Shreyaca8990f2017-03-16 11:43:11 -07001205 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ],
1206 sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE,
1207 args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001208 main.assertReturnString += 'Link Up Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001209 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001210 main.assertReturnString += 'Link Up Flow State Failed\n'
1211 testResult = main.FALSE
1212
1213 # Check OnosTopology
1214 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
1215 main.assertReturnString += 'Link Up Topology State Passed\n'
1216 else:
1217 main.assertReturnString += 'Link Up Topology State Failed\n'
1218 testResult = main.FALSE
1219
1220 # Check Connection
Shreyaca8990f2017-03-16 11:43:11 -07001221 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, sleep=main.checkConnectionSleep, attempts=100,
1222 args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001223 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1224 else:
1225 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1226 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001227
1228 # Remove all intents
Shreyaca8990f2017-03-16 11:43:11 -07001229 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, attempts=10, args=( main, [ intentId ] ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001230 main.assertReturnString += 'Remove Intents Passed'
1231 else:
1232 main.assertReturnString += 'Remove Intents Failed'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001233 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001234
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001235 return testResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001236
Jeremye0cb5eb2016-01-27 17:39:09 -08001237def testEndPointFail( main,
1238 name,
1239 intentId,
1240 senders,
1241 recipients,
1242 isolatedSenders,
1243 isolatedRecipients,
1244 onosNode=0,
1245 ethType="",
1246 bandwidth="",
1247 lambdaAlloc=False,
1248 ipProto="",
1249 ipAddresses="",
1250 tcp="",
1251 sw1="",
1252 sw2="",
1253 sw3="",
1254 sw4="",
1255 sw5="",
1256 expectedLink1=0,
Jeremy Songster9385d412016-06-02 17:57:36 -07001257 expectedLink2=0,
1258 partial=False ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001259 """
Shreyaca8990f2017-03-16 11:43:11 -07001260 Test Multi point to single point intent Topology for Endpoint failures
Jeremye0cb5eb2016-01-27 17:39:09 -08001261 """
1262
1263 # Parameter Validity Check
1264 assert main, "There is no main variable"
1265 assert senders, "You must specify a sender"
1266 assert recipients, "You must specify a recipient"
1267
1268 global itemName
1269 itemName = name
Jeremye0cb5eb2016-01-27 17:39:09 -08001270
1271 main.log.info( itemName + ": Testing Point Intent" )
1272
Jeremyd9e4eb12016-04-13 12:09:06 -07001273 try:
1274 # Names for scapy
1275 senderNames = [ x.get( "name" ) for x in senders ]
1276 recipientNames = [ x.get( "name" ) for x in recipients ]
1277 isolatedSenderNames = [ x.get( "name" ) for x in isolatedSenders ]
1278 isolatedRecipientNames = [ x.get( "name" ) for x in isolatedRecipients ]
1279 connectedSenderNames = [x.get("name") for x in senders if x.get("name") not in isolatedSenderNames]
1280 connectedRecipientNames = [x.get("name") for x in recipients if x.get("name") not in isolatedRecipientNames]
Jeremye0cb5eb2016-01-27 17:39:09 -08001281
Jeremyd9e4eb12016-04-13 12:09:06 -07001282 for sender in senders:
1283 if not sender.get( "device" ):
1284 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1285 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremye0cb5eb2016-01-27 17:39:09 -08001286
Jeremyd9e4eb12016-04-13 12:09:06 -07001287 for recipient in recipients:
1288 if not recipient.get( "device" ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001289 main.log.warn( "Device not given for recipient {0}. Loading from " +\
1290 main.hostData.format( recipient.get( "name" ) ) )
Jeremyd9e4eb12016-04-13 12:09:06 -07001291 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001292 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001293 main.log.error( "There was a problem loading the hosts data." )
1294 return main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001295
1296 testResult = main.TRUE
1297 main.log.info( itemName + ": Adding multi point to single point intents" )
1298
1299 # Check intent state
1300 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -07001301 args=( main, [ intentId ] ), sleep=main.checkIntentSleep, attempts=50 ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001302 main.assertReturnString += 'Initial Intent State Passed\n'
1303 else:
1304 main.assertReturnString += 'Initial Intent State Failed\n'
1305 testResult = main.FALSE
1306
1307 # Check flows count in each node
1308 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
Jeremy Songster9385d412016-06-02 17:57:36 -07001309 args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState,
1310 retValue=main.FALSE,
1311 args=[ main ], attempts=5 ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001312 main.assertReturnString += 'Initial Flow State Passed\n'
1313 else:
1314 main.assertReturnString += 'Intial Flow State Failed\n'
1315 testResult = main.FALSE
1316
1317 # Check Connectivity
1318 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1319 args=( main, senderNames, recipientNames ) ):
1320 main.assertReturnString += 'Initial Connectivity Check Passed\n'
1321 else:
1322 main.assertReturnString += 'Initial Connectivity Check Failed\n'
1323 testResult = main.FALSE
1324
1325 # Take two links down
1326 # Take first link down
1327 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
1328 main.assertReturnString += 'Link Down Passed\n'
1329 else:
1330 main.assertReturnString += 'Link Down Failed\n'
1331 testResult = main.FALSE
1332
1333 # Take second link down
1334 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw4, "down" ) ):
1335 main.assertReturnString += 'Link Down Passed\n'
1336 else:
1337 main.assertReturnString += 'Link Down Failed\n'
1338 testResult = main.FALSE
1339
1340 # Check intent state
Shreyaca8990f2017-03-16 11:43:11 -07001341 if utilities.retry( f=checkIntentState, retValue=main.FALSE, attempts=100,
Jeremye0cb5eb2016-01-27 17:39:09 -08001342 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1343 main.assertReturnString += 'Link Down Intent State Passed\n'
1344 else:
1345 main.assertReturnString += 'Link Down Intent State Failed\n'
1346 testResult = main.FALSE
1347
1348 # Check flows count in each node
Shreyaca8990f2017-03-16 11:43:11 -07001349 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, sleep=1, attempts=30,
Jeremye0cb5eb2016-01-27 17:39:09 -08001350 args=[ main ] ) and utilities.retry( f=checkFlowsState,
Shreyaca8990f2017-03-16 11:43:11 -07001351 retValue=main.FALSE, sleep=1, attempts=30, args=[ main ] ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001352 main.assertReturnString += 'Link Down Flow State Passed\n'
1353 else:
1354 main.assertReturnString += 'Link Down Flow State Failed\n'
1355 testResult = main.FALSE
1356
1357 # Check OnosTopology
1358 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink1 ) ):
1359 main.assertReturnString += 'Link Down Topology State Passed\n'
1360 else:
1361 main.assertReturnString += 'Link Down Topology State Failed\n'
1362 testResult = main.FALSE
1363
1364 # Check Connection
1365 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1366 args=( main, senderNames, recipientNames ) ):
1367 main.assertReturnString += 'Link Down Connectivity Check Passed\n'
1368 else:
1369 main.assertReturnString += 'Link Down Connectivity Check Failed\n'
1370 testResult = main.FALSE
1371
1372 # Take a third link down to isolate one node
1373 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw5, "down" ) ):
1374 main.assertReturnString += 'Isolation link Down Passed\n'
1375 else:
1376 main.assertReturnString += 'Isolation link Down Failed\n'
1377 testResult = main.FALSE
1378
Jeremy Songster9385d412016-06-02 17:57:36 -07001379 if partial:
1380 # Check intent state
1381 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -07001382 args=( main, [ intentId ] ), sleep=main.checkIntentSleep, attempts=50 ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001383 main.assertReturnString += 'Partial failure isolation link Down Intent State Passed\n'
1384 else:
1385 main.assertReturnString += 'Partial failure isolation link Down Intent State Failed\n'
1386 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001387
Jeremy Songster9385d412016-06-02 17:57:36 -07001388 # 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 += 'Partial failure isolation link Down Flow State Passed\n'
1394 else:
1395 main.assertReturnString += 'Partial failure isolation link Down Flow State Failed\n'
1396 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001397
Jeremy Songster9385d412016-06-02 17:57:36 -07001398 # Check OnosTopology
1399 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink2 ) ):
1400 main.assertReturnString += 'Partial failure isolation link Down Topology State Passed\n'
1401 else:
1402 main.assertReturnString += 'Partial failure isolation link Down Topology State Failed\n'
1403 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001404
Jeremy Songster9385d412016-06-02 17:57:36 -07001405 # 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 += 'Partial failure isolation link Down Connectivity Check Passed\n'
1410 else:
1411 main.assertReturnString += 'Partial failure 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 += 'Partial failure isolation link Down Connectivity Check Passed\n'
1418 else:
1419 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1420 testResult = main.FALSE
1421
1422 # Next check connectivity of connected senders and recipients
Shreyaca8990f2017-03-16 11:43:11 -07001423 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, attempts=50,
Jeremy Songster9385d412016-06-02 17:57:36 -07001424 args=( main, connectedSenderNames , connectedRecipientNames ) ):
1425 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1426 else:
1427 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1428 testResult = main.FALSE
1429 else:
1430 # Check intent state
1431 if not utilities.retry( f=checkIntentState, retValue=main.TRUE,
Shreyaca8990f2017-03-16 11:43:11 -07001432 args=( main, [ intentId ] ), sleep=main.checkIntentSleep, attempts=50 ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001433 main.assertReturnString += 'Isolation link Down Intent State Passed\n'
1434 else:
1435 main.assertReturnString += 'Isolation link Down Intent State Failed\n'
1436 testResult = main.FALSE
1437
1438 # Check flows count in each node
1439 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1440 args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState,
1441 retValue=main.FALSE,
1442 args=[ main ], attempts=5 ):
1443 main.assertReturnString += 'Isolation link Down Flow State Passed\n'
1444 else:
1445 main.assertReturnString += 'Isolation link Down Flow State Failed\n'
1446 testResult = main.FALSE
1447
1448 # Check OnosTopology
1449 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink2 ) ):
1450 main.assertReturnString += 'Isolation link Down Topology State Passed\n'
1451 else:
1452 main.assertReturnString += 'Isolation link Down Topology State Failed\n'
1453 testResult = main.FALSE
1454
1455 # Check Connectivity
1456 # First check connectivity of any isolated senders to recipients
1457 if isolatedSenderNames:
1458 if scapyCheckConnection( main, isolatedSenderNames, recipientNames, None, None, None, None, main.TRUE ):
1459 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1460 else:
1461 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1462 testResult = main.FALSE
1463
1464 # Next check connectivity of senders to any isolated recipients
1465 if isolatedRecipientNames:
1466 if scapyCheckConnection( main, senderNames, isolatedRecipientNames, None, None, None, None, main.TRUE ):
1467 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1468 else:
1469 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1470 testResult = main.FALSE
1471
1472 # Next check connectivity of connected senders and recipients
1473 if utilities.retry( f=scapyCheckConnection, retValue=main.TRUE,
1474 args=( main, connectedSenderNames , connectedRecipientNames, None, None, None, None, main.TRUE ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001475 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1476 else:
1477 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1478 testResult = main.FALSE
1479
Jeremye0cb5eb2016-01-27 17:39:09 -08001480 # Bring the links back up
1481 # Bring first link up
1482 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
1483 main.assertReturnString += 'Link Up Passed\n'
1484 else:
1485 main.assertReturnString += 'Link Up Failed\n'
1486 testResult = main.FALSE
1487
1488 # Bring second link up
1489 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw5, "up" ) ):
1490 main.assertReturnString += 'Link Up Passed\n'
1491 else:
1492 main.assertReturnString += 'Link Up Failed\n'
1493 testResult = main.FALSE
1494
1495 # Bring third link up
1496 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw4, "up" ) ):
1497 main.assertReturnString += 'Link Up Passed\n'
1498 else:
1499 main.assertReturnString += 'Link Up Failed\n'
1500 testResult = main.FALSE
1501
1502 # Wait for reroute
1503 time.sleep( main.rerouteSleep )
1504
1505 # Check Intents
Shreyaca8990f2017-03-16 11:43:11 -07001506 if utilities.retry( f=checkIntentState, retValue=main.FALSE, attempts=5 * 20,
1507 args=( main, [ intentId ] ), sleep=main.checkIntentHostSleep ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001508 main.assertReturnString += 'Link Up Intent State Passed\n'
1509 else:
1510 main.assertReturnString += 'Link Up Intent State Failed\n'
1511 testResult = main.FALSE
1512
1513 # Check flows count in each node
1514 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -07001515 args=[ main ], sleep=5, attempts=5*20 ) and utilities.retry( f=checkFlowsState,
Jeremy Songster9385d412016-06-02 17:57:36 -07001516 retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -07001517 args=[ main ], sleep=5, attempts=5*20 ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001518 main.assertReturnString += 'Link Up Flow State Passed\n'
1519 else:
1520 main.assertReturnString += 'Link Up Flow State Failed\n'
1521 testResult = main.FALSE
1522
1523 # Check OnosTopology
1524 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
1525 main.assertReturnString += 'Link Up Topology State Passed\n'
1526 else:
1527 main.assertReturnString += 'Link Up Topology State Failed\n'
1528 testResult = main.FALSE
1529
1530 # Check Connection
Shreyaca8990f2017-03-16 11:43:11 -07001531 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, sleep=main.checkConnectionSleep, attempts= 100,
Jeremye0cb5eb2016-01-27 17:39:09 -08001532 args=( main, senderNames, recipientNames ) ):
1533 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1534 else:
1535 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1536 testResult = main.FALSE
1537
1538 # Remove all intents
Shreyaca8990f2017-03-16 11:43:11 -07001539 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, attempts=10, args=( main, [ intentId ] ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001540 main.assertReturnString += 'Remove Intents Passed'
1541 else:
1542 main.assertReturnString += 'Remove Intents Failed'
1543 testResult = main.FALSE
1544
1545 return testResult
1546
1547
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001548def pingallHosts( main, hostList ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001549 """
1550 Ping all host in the hosts list variable
1551 """
Jon Halla5cb3412015-08-18 14:08:22 -07001552 main.log.info( "Pinging: " + str( hostList ) )
1553 return main.Mininet1.pingallHosts( hostList )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001554
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001555def fwdPingall( main ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001556 """
1557 Use fwd app and pingall to discover all the hosts
1558 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001559 appCheck = main.TRUE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001560 main.log.info( "Activating reactive forwarding app " )
1561 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001562
1563 # Wait for forward app activation to propagate
kelvin-onlab0ad05d12015-07-23 14:21:15 -07001564 time.sleep( main.fwdSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001565
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001566 # Check that forwarding is enabled on all nodes
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001567 for i in range( main.numCtrls ):
1568 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
1569 if appCheck != main.TRUE:
1570 main.log.warn( main.CLIs[ i ].apps() )
1571 main.log.warn( main.CLIs[ i ].appIDs() )
1572
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001573 # Send pingall in mininet
1574 main.log.info( "Run Pingall" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001575 pingResult = main.Mininet1.pingall( timeout = 600 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001576
1577 main.log.info( "Deactivating reactive forwarding app " )
1578 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001579 if activateResult and deactivateResult:
1580 main.log.info( "Successfully used fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001581 getDataResult = main.TRUE
1582 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001583 main.log.info( "Failed to use fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001584 getDataResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001585 return getDataResult
1586
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001587def confirmHostDiscovery( main ):
1588 """
1589 Confirms that all ONOS nodes have discovered all scapy hosts
1590 """
1591 import collections
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001592 hosts = main.topo.getAllHosts( main ) # Get host data from each ONOS node
1593 hostFails = [] # Reset for each failed attempt
1594
1595 # Check for matching hosts on each node
1596 scapyHostIPs = [ x.hostIp for x in main.scapyHosts if x.hostIp != "0.0.0.0" ]
1597 for controller in range( main.numCtrls ):
1598 controllerStr = str( controller + 1 ) # ONOS node number
1599 # Compare Hosts
1600 # Load hosts data for controller node
Jeremyd9e4eb12016-04-13 12:09:06 -07001601 try:
1602 if hosts[ controller ]:
1603 main.log.info( "Hosts discovered" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001604 else:
Jeremyd9e4eb12016-04-13 12:09:06 -07001605 main.log.error( "Problem discovering hosts" )
1606 if hosts[ controller ] and "Error" not in hosts[ controller ]:
1607 try:
1608 hostData = json.loads( hosts[ controller ] )
1609 except ( TypeError, ValueError ):
1610 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001611 hostFails.append( controllerStr )
Jeremyd9e4eb12016-04-13 12:09:06 -07001612 else:
1613 onosHostIPs = [ x.get( "ipAddresses" )[ 0 ]
1614 for x in hostData
1615 if len( x.get( "ipAddresses" ) ) > 0 ]
1616 if not set( collections.Counter( scapyHostIPs ) ).issubset( set ( collections.Counter( onosHostIPs ) ) ):
1617 main.log.warn( "Controller {0} only sees nodes with {1} IPs. It should see all of the following: {2}".format( controllerStr, onosHostIPs, scapyHostIPs ) )
1618 hostFails.append( controllerStr )
1619 else:
1620 main.log.error( "Hosts returned nothing or an error." )
1621 hostFails.append( controllerStr )
1622 except IndexError:
1623 main.log.error( "Hosts returned nothing, Failed to discover hosts." )
1624 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001625
1626 if hostFails:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001627 main.log.error( "List of failed ONOS Nodes:" + ', '.join( map( str, hostFails ) ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001628 return main.FALSE
1629 else:
1630 return main.TRUE
1631
1632def sendDiscoveryArp( main, hosts=None ):
1633 """
1634 Sends Discovery ARP packets from each host provided
1635 Defaults to each host in main.scapyHosts
1636 """
1637 # Send an arp ping from each host
1638 if not hosts:
1639 hosts = main.scapyHosts
1640 for host in hosts:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001641 pkt = 'Ether( src="{0}")/ARP( psrc="{1}")'.format( host.hostMac, host.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001642 # Send from the VLAN interface if there is one so ONOS discovers the VLAN correctly
1643 iface = None
1644 for interface in host.getIfList():
1645 if '.' in interface:
1646 main.log.debug( "Detected VLAN interface {0}. Sending ARP packet from {0}".format( interface ) )
1647 iface = interface
1648 break
1649 host.sendPacket( packet=pkt, iface=iface )
1650 main.log.info( "Sending ARP packet from {0}".format( host.name ) )
1651
1652def populateHostData( main ):
1653 """
1654 Populates hostsData
1655 """
1656 import json
1657 try:
1658 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
1659 hosts = main.Mininet1.getHosts().keys()
1660 # TODO: Make better use of new getHosts function
1661 for host in hosts:
1662 main.hostsData[ host ] = {}
1663 main.hostsData[ host ][ 'mac' ] = \
1664 main.Mininet1.getMacAddress( host ).upper()
1665 for hostj in hostsJson:
1666 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
1667 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
1668 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
1669 main.hostsData[ host ][ 'location' ] = \
1670 hostj[ 'location' ][ 'elementId' ] + '/' + \
1671 hostj[ 'location' ][ 'port' ]
1672 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
1673 return main.TRUE
Jeremyd9e4eb12016-04-13 12:09:06 -07001674 except ValueError:
1675 main.log.error( "ValueError while populating hostsData" )
1676 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001677 except KeyError:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001678 main.log.error( "KeyError while populating hostsData" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001679 return main.FALSE
Jeremyd9e4eb12016-04-13 12:09:06 -07001680 except IndexError:
1681 main.log.error( "IndexError while populating hostsData" )
1682 return main.FALSE
1683 except TypeError:
1684 main.log.error( "TypeError while populating hostsData" )
1685 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001686
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001687def checkTopology( main, expectedLink ):
1688 statusResult = main.TRUE
1689 # Check onos topology
1690 main.log.info( itemName + ": Checking ONOS topology " )
1691
1692 for i in range( main.numCtrls ):
Flavio Castro82ee2f62016-06-07 15:04:12 -07001693 statusResult = main.CLIs[ i ].checkStatus( main.numSwitch,
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001694 expectedLink )\
1695 and statusResult
1696 if not statusResult:
1697 main.log.error( itemName + ": Topology mismatch" )
1698 else:
1699 main.log.info( itemName + ": Topology match" )
1700 return statusResult
1701
1702def checkIntentState( main, intentsId ):
1703 """
1704 This function will check intent state to make sure all the intents
1705 are in INSTALLED state
1706 """
1707
1708 intentResult = main.TRUE
1709 results = []
1710
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001711 for i in range( main.numCtrls ):
1712 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
1713 results.append( tempResult )
1714
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001715 if all( result == main.TRUE for result in results ):
1716 main.log.info( itemName + ": Intents are installed correctly" )
1717 else:
Shreyaca8990f2017-03-16 11:43:11 -07001718 main.log.warn( "Intents are not installed correctly" )
1719 intentResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001720
1721 return intentResult
1722
1723def checkFlowsState( main ):
1724
1725 main.log.info( itemName + ": Check flows state" )
Jeremy Songsterff553672016-05-12 17:06:23 -07001726 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState( isPENDING=False )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001727 return checkFlowsResult
1728
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001729def link( main, sw1, sw2, option ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001730
1731 # link down
alison52b25892016-09-19 10:53:48 -07001732 main.log.info( itemName + ": Bring link " + option + " between " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001733 sw1 + " and " + sw2 )
1734 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
1735 return linkResult
1736
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001737def scapyCheckConnection( main, senders, recipients, vlanId=None, useTCP=False, packet=None, packetFilter=None, expectFailure=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001738 """
1739 Checks the connectivity between all given sender hosts and all given recipient hosts
1740 Packet may be specified. Defaults to Ether/IP packet
1741 Packet Filter may be specified. Defaults to Ether/IP from current sender MAC
1742 Todo: Optional packet and packet filter attributes for sender and recipients
1743 Expect Failure when the sender and recipient are not supposed to have connectivity
1744 Timeout of 1 second, returns main.TRUE if the filter is not triggered and kills the filter
1745
1746 """
1747 connectionsFunctional = main.TRUE
1748
1749 if not packetFilter:
1750 packetFilter = 'ether host {}'
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001751 if useTCP:
1752 packetFilter += ' ip proto \\tcp tcp port {}'.format(main.params[ 'SDNIP' ][ 'dstPort' ])
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001753 if expectFailure:
1754 timeout = 1
1755 else:
1756 timeout = 10
1757
1758 for sender in senders:
1759 try:
1760 senderComp = getattr( main, sender )
1761 except AttributeError:
1762 main.log.error( "main has no attribute {}".format( sender ) )
1763 connectionsFunctional = main.FALSE
1764 continue
1765
1766 for recipient in recipients:
1767 # Do not send packets to self since recipient CLI will already be busy
1768 if recipient == sender:
1769 continue
1770 try:
1771 recipientComp = getattr( main, recipient )
1772 except AttributeError:
1773 main.log.error( "main has no attribute {}".format( recipient ) )
1774 connectionsFunctional = main.FALSE
1775 continue
1776
Jeremy Songster832f9e92016-05-05 14:30:49 -07001777 if vlanId:
1778 recipientComp.startFilter( pktFilter = ( "vlan {}".format( vlanId ) + " && " + packetFilter.format( senderComp.hostMac ) ) )
1779 else:
1780 recipientComp.startFilter( pktFilter = packetFilter.format( senderComp.hostMac ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001781
1782 if not packet:
Jeremy Songster832f9e92016-05-05 14:30:49 -07001783 if vlanId:
1784 pkt = 'Ether( src="{0}", dst="{2}" )/Dot1Q(vlan={4})/IP( src="{1}", dst="{3}" )'.format(
1785 senderComp.hostMac,
1786 senderComp.hostIp,
1787 recipientComp.hostMac,
1788 recipientComp.hostIp,
1789 vlanId )
1790 else:
1791 pkt = 'Ether( src="{0}", dst="{2}" )/IP( src="{1}", dst="{3}" )'.format(
1792 senderComp.hostMac,
1793 senderComp.hostIp,
1794 recipientComp.hostMac,
1795 recipientComp.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001796 else:
1797 pkt = packet
Jeremy Songster832f9e92016-05-05 14:30:49 -07001798 if vlanId:
1799 senderComp.sendPacket( iface=( "{0}-eth0.{1}".format( sender, vlanId ) ), packet = pkt )
1800 else:
1801 senderComp.sendPacket( packet = pkt )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001802
1803 if recipientComp.checkFilter( timeout ):
1804 if expectFailure:
1805 main.log.error( "Packet from {0} successfully received by {1} when it should not have been".format( sender , recipient ) )
1806 connectionsFunctional = main.FALSE
1807 else:
1808 main.log.info( "Packet from {0} successfully received by {1}".format( sender , recipient ) )
alison52b25892016-09-19 10:53:48 -07001809 connectionsFunctional = main.TRUE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001810 else:
1811 recipientComp.killFilter()
1812 if expectFailure:
1813 main.log.info( "As expected, packet from {0} was not received by {1}".format( sender , recipient ) )
1814 else:
1815 main.log.error( "Packet from {0} was not received by {1}".format( sender , recipient ) )
1816 connectionsFunctional = main.FALSE
1817
1818 return connectionsFunctional
1819
alison52b25892016-09-19 10:53:48 -07001820
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001821def removeAllIntents( main, intentsId ):
1822 """
1823 Remove all intents in the intentsId
1824 """
1825
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001826 onosSummary = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001827 removeIntentResult = main.TRUE
1828 # Remove intents
1829 for intent in intentsId:
1830 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
1831
acsmarscfa52272015-08-06 15:21:45 -07001832 time.sleep( main.removeIntentSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001833
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001834 # If there is remianing intents then remove intents should fail
1835 for i in range( main.numCtrls ):
1836 onosSummary.append( json.loads( main.CLIs[ i ].summary() ) )
1837
1838 for summary in onosSummary:
1839 if summary.get( 'intents' ) != 0:
1840 main.log.warn( itemName + ": There are " +
1841 str( summary.get( 'intents' ) ) +
1842 " intents remaining in node " +
1843 str( summary.get( 'node' ) ) +
1844 ", failed to remove all the intents " )
1845 removeIntentResult = main.FALSE
1846
1847 if removeIntentResult:
1848 main.log.info( itemName + ": There are no more intents remaining, " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001849 "successfully removed all the intents." )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001850
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001851 return removeIntentResult
1852
1853def checkFlowsCount( main ):
1854 """
1855 Check flows count in each node
1856 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001857 flowsCount = []
1858 main.log.info( itemName + ": Checking flows count in each ONOS node" )
1859 for i in range( main.numCtrls ):
1860 summaryResult = main.CLIs[ i ].summary()
1861 if not summaryResult:
1862 main.log.error( itemName + ": There is something wrong with " +
1863 "summary command" )
1864 return main.FALSE
1865 else:
1866 summaryJson = json.loads( summaryResult )
1867 flowsCount.append( summaryJson.get( 'flows' ) )
1868
1869 if flowsCount:
1870 if all( flows==flowsCount[ 0 ] for flows in flowsCount ):
1871 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
1872 " flows in all ONOS node" )
1873 else:
1874 for i in range( main.numCtrls ):
1875 main.log.debug( itemName + ": ONOS node " + str( i ) + " has " +
kelvin-onlab6dea6e62015-07-23 13:07:26 -07001876 str( flowsCount[ i ] ) + " flows" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001877 else:
1878 main.log.error( "Checking flows count failed, check summary command" )
1879 return main.FALSE
1880
1881 return main.TRUE
1882
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001883def checkLeaderChange( leaders1, leaders2 ):
acsmarse6b410f2015-07-17 14:39:34 -07001884 """
1885 Checks for a change in intent partition leadership.
1886
1887 Takes the output of leaders -c in json string format before and after
1888 a potential change as input
1889
1890 Returns main.TRUE if no mismatches are detected
1891 Returns main.FALSE if there is a mismatch or on error loading the input
1892 """
1893 try:
1894 leaders1 = json.loads( leaders1 )
1895 leaders2 = json.loads( leaders2 )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001896 except( AttributeError, TypeError ):
acsmarse6b410f2015-07-17 14:39:34 -07001897 main.log.exception( self.name + ": Object not as expected" )
1898 return main.FALSE
1899 except Exception:
1900 main.log.exception( self.name + ": Uncaught exception!" )
1901 main.cleanup()
1902 main.exit()
1903 main.log.info( "Checking Intent Paritions for Change in Leadership" )
1904 mismatch = False
1905 for dict1 in leaders1:
1906 if "intent" in dict1.get( "topic", [] ):
1907 for dict2 in leaders2:
1908 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \
1909 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
1910 mismatch = True
1911 main.log.error( "{0} changed leader from {1} to {2}".\
1912 format( dict1.get( "topic", "no-topic" ),\
1913 dict1.get( "leader", "no-leader" ),\
1914 dict2.get( "leader", "no-leader" ) ) )
1915 if mismatch:
1916 return main.FALSE
1917 else:
1918 return main.TRUE
kelvin-onlab016dce22015-08-10 09:54:11 -07001919
1920def report( main ):
1921 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001922 Report errors/warnings/exceptions
kelvin-onlab016dce22015-08-10 09:54:11 -07001923 """
kelvin-onlab016dce22015-08-10 09:54:11 -07001924 main.ONOSbench.logReport( main.ONOSip[ 0 ],
1925 [ "INFO",
1926 "FOLLOWER",
1927 "WARN",
1928 "flow",
1929 "ERROR",
1930 "Except" ],
1931 "s" )
1932
1933 main.log.info( "ERROR report: \n" )
1934 for i in range( main.numCtrls ):
1935 main.ONOSbench.logReport( main.ONOSip[ i ],
1936 [ "ERROR" ],
1937 "d" )
1938
1939 main.log.info( "EXCEPTIONS report: \n" )
1940 for i in range( main.numCtrls ):
1941 main.ONOSbench.logReport( main.ONOSip[ i ],
1942 [ "Except" ],
1943 "d" )
1944
1945 main.log.info( "WARNING report: \n" )
1946 for i in range( main.numCtrls ):
1947 main.ONOSbench.logReport( main.ONOSip[ i ],
1948 [ "WARN" ],
1949 "d" )
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001950
1951def flowDuration( main ):
1952 """
1953 Check age of flows to see if flows are being overwritten
1954 """
1955 import time
1956 main.log.info( "Getting current flow durations" )
1957 flowsJson1 = main.CLIs[ 0 ].flows( noCore=True )
1958 try:
1959 flowsJson1 = json.loads( flowsJson1 )
1960 except ValueError:
1961 main.log.error( "Unable to read flows" )
1962 return main.FALSE
1963 flowLife = []
1964 waitFlowLife = []
1965 for device in flowsJson1:
1966 if device.get( 'flowcount', 0 ) > 0:
1967 for i in range( device[ 'flowCount' ] ):
1968 flowLife.append( device[ 'flows' ][ i ][ 'life' ] )
1969 main.log.info( "Sleeping for {} seconds".format( main.flowDurationSleep ) )
1970 time.sleep( main.flowDurationSleep )
1971 main.log.info( "Getting new flow durations" )
1972 flowsJson2 = main.CLIs[ 0 ].flows( noCore=True )
1973 try:
1974 flowsJson2 = json.loads( flowsJson2 )
1975 except ValueError:
1976 main.log.error( "Unable to read flows" )
1977 return main.FALSE
1978 for device in flowsJson2:
1979 if device.get( 'flowcount', 0 ) > 0:
1980 for i in range( device[ 'flowCount' ] ):
1981 waitFlowLife.append( device[ 'flows' ][ i ][ 'life' ] )
1982 main.log.info( "Determining whether flows where overwritten" )
1983 if len( flowLife ) == len( waitFlowLife ):
alison52b25892016-09-19 10:53:48 -07001984 for i in range( len( flowLife ) ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001985 if waitFlowLife[ i ] - flowLife[ i ] < main.flowDurationSleep:
1986 return main.FALSE
1987 else:
1988 return main.FALSE
1989 return main.TRUE
alison52b25892016-09-19 10:53:48 -07001990
1991
1992def EncapsulatedIntentCheck( main, tag="" ):
1993 """
1994 Check encapsulated intents
1995 tag: encapsulation tag (e.g. VLAN, MPLS)
1996
1997 Getting added flows
1998 Check tags on each flows
1999 If each direction has push or pop, passed
2000 else failed
2001
2002 """
2003 import json
2004 HostJson = []
2005 Jflows = main.CLIs[ 0 ].flows( noCore=True )
2006 try:
2007 Jflows = json.loads( Jflows )
2008 except ValueError:
2009 main.log.error( "Unable to read flows" )
2010 return main.FALSE
2011
2012 for flow in Jflows:
2013 if len(flow[ "flows" ]) != 0:
2014 HostJson.append( flow[ "flows" ] )
2015
2016 totalflows = len( HostJson[ 0 ])
2017
2018 pop = 0
2019 push = 0
2020
2021 PopTag = tag + "_POP"
2022 PushTag = tag + "_PUSH"
2023
2024 for EachHostJson in HostJson:
2025 for i in range( totalflows ):
2026 if EachHostJson[ i ][ "treatment" ][ "instructions" ][ 0 ][ "subtype" ] == PopTag:
2027 pop += 1
2028 elif EachHostJson[ i ][ "treatment" ][ "instructions" ][ 0 ][ "subtype" ] == PushTag:
2029 push += 1
2030
2031 if pop == totalflows and push == totalflows:
2032 return main.TRUE
2033 else:
alisonda157272016-12-22 01:13:21 -08002034 return main.FALSE
2035
2036def ProtectedIntentCheck( main ):
2037 import json
2038 intent = main.CLIs[ 0 ].intents( jsonFormat=False )
2039 if "Protection" in intent:
2040 return main.TRUE
Shreyaca8990f2017-03-16 11:43:11 -07002041 return main.FALSE