blob: 1334c9f24a81e67d01a37c73e6a1760e2dc9810b [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
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -070013hostIntentFailFlag = False
14pointIntentFailFlag = False
15singleToMultiFailFlag = False
16multiToSingleFailFlag = False
17
Jeremy Songster1f39bf02016-01-20 17:17:25 -080018def installHostIntent( main,
Jeremy2f190ca2016-01-29 15:23:57 -080019 name,
20 host1,
21 host2,
22 onosNode=0,
23 ethType="",
24 bandwidth="",
25 lambdaAlloc=False,
26 ipProto="",
27 ipAddresses="",
28 tcp="",
29 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -070030 sw2="",
Jeremy Songsterc032f162016-08-04 17:14:49 -070031 setVlan="",
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -070032 encap="",
33 bandwidthFlag=False ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -070034 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -080035 Installs a Host Intent
36
kelvin-onlab58dc39e2015-08-06 08:11:09 -070037 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -080038 Install a host intent using
39 add-host-intent
40
kelvin-onlab58dc39e2015-08-06 08:11:09 -070041 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -080042 - Fetch host data if not given
43 - Add host intent
44 - Ingress device is the first sender host
45 - Egress devices are the recipient devices
46 - Ports if defined in senders or recipients
47 - MAC address ethSrc loaded from Ingress device
48 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -070049 Required:
50 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -080051 host1 - Dictionary for host1
52 { "name":"h8", "id":"of:0000000000000005/8" }
53 host2 - Dictionary for host2
54 { "name":"h16", "id":"of:0000000000000006/8" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -070055 Optional:
56 onosNode - ONOS node to install the intents in main.CLIs[ ]
57 0 by default so that it will always use the first
58 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -070059 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -070060 bandwidth - Bandwidth capacity
61 lambdaAlloc - Allocate lambda, defaults to False
62 ipProto - IP protocol
Jeremy Songster1f39bf02016-01-20 17:17:25 -080063 tcp - TCP ports in the same order as the hosts in hostNames
64 """
65
66 assert main, "There is no main variable"
67 assert host1, "You must specify host1"
68 assert host2, "You must specify host2"
69
70 global itemName # The name of this run. Used for logs.
71 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -080072
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -070073 global hostIntentFailFlag
74 hostIntentFailFlag = False
75
Jeremy Songster1f39bf02016-01-20 17:17:25 -080076 main.log.info( itemName + ": Adding single point to multi point intents" )
Jeremyd9e4eb12016-04-13 12:09:06 -070077 try:
78 if not host1.get( "id" ):
79 main.log.warn( "ID not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
80 main.log.debug( main.hostsData.get( host1.get( "name" ) ) )
81 host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "id" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -080082
Jeremyd9e4eb12016-04-13 12:09:06 -070083 if not host2.get( "id" ):
84 main.log.warn( "ID not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
85 host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "id" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -080086
Jeremyd9e4eb12016-04-13 12:09:06 -070087 # Adding point intent
Jeremy Songster832f9e92016-05-05 14:30:49 -070088 vlanId = host1.get( "vlan" )
Jeremyd9e4eb12016-04-13 12:09:06 -070089 intentId = main.CLIs[ onosNode ].addHostIntent( hostIdOne=host1.get( "id" ),
Jeremy Songster832f9e92016-05-05 14:30:49 -070090 hostIdTwo=host2.get( "id" ),
Jeremy Songsterff553672016-05-12 17:06:23 -070091 vlanId=vlanId,
Jeremy Songsterc032f162016-08-04 17:14:49 -070092 setVlan=setVlan,
93 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -070094 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -070095 errorMsg = "There was a problem loading the hosts data."
96 if intentId:
97 errorMsg += " There was a problem installing host to host intent."
98 main.log.error( errorMsg )
99 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800100
101 # Check intents state
102 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700103 args=( main, [ intentId ], bandwidthFlag ), sleep=main.checkIntentSleep, attempts=50 ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700104 main.assertReturnString += 'Install Intent State Passed\n'
alison52b25892016-09-19 10:53:48 -0700105
106 #Check VLAN if test encapsulation
107 if encap != "":
108 if EncapsulatedIntentCheck( main, tag=encap ):
109 main.assertReturnString += 'Encapsulation intents check Passed\n'
110 else:
111 main.assertReturnString += 'Encapsulation intents check failed\n'
112
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700113 if flowDuration( main ):
114 main.assertReturnString += 'Flow duration check Passed\n'
115 return intentId
116 else:
117 main.assertReturnString += 'Flow duration check failed\n'
118 return main.FALSE
alison52b25892016-09-19 10:53:48 -0700119
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800120 else:
Jeremy2f190ca2016-01-29 15:23:57 -0800121 main.log.error( "Host Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700122 hostIntentFailFlag = True
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700123 main.assertReturnString += 'Install Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800124 return main.FALSE
125
126def testHostIntent( main,
127 name,
128 intentId,
129 host1,
130 host2,
131 onosNode=0,
132 sw1="s5",
133 sw2="s2",
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700134 expectedLink=0 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800135 """
136 Test a Host Intent
137
138 Description:
139 Test a host intent of given ID between given hosts
140
141 Steps:
142 - Fetch host data if not given
143 - Check Intent State
144 - Check Flow State
145 - Check Connectivity
146 - Check Lack of Connectivity Between Hosts not in the Intent
147 - Reroute
148 - Take Expected Link Down
149 - Check Intent State
150 - Check Flow State
151 - Check Topology
152 - Check Connectivity
153 - Bring Expected Link Up
154 - Check Intent State
155 - Check Flow State
156 - Check Topology
157 - Check Connectivity
158 - Remove Topology
159
160 Required:
161 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
162 intentId - intent ID to be tested ( and removed )
163 host1 - Dictionary for host1
164 { "name":"h8", "id":"of:0000000000000005/8" }
165 host2 - Dictionary for host2
166 { "name":"h16", "id":"of:0000000000000006/8" }
167 Optional:
168 onosNode - ONOS node to install the intents in main.CLIs[ ]
169 0 by default so that it will always use the first
170 ONOS node
171 sw1 - First switch to bring down & up for rerouting purpose
172 sw2 - Second switch to bring down & up for rerouting purpose
173 expectedLink - Expected link when the switches are down, it should
174 be two links lower than the links before the two
175 switches are down
176
177 """
178
179 # Parameter Validity Check
180 assert main, "There is no main variable"
181 assert host1, "You must specify host1"
182 assert host2, "You must specify host2"
183
184 global itemName
185 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800186
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700187 global hostIntentFailFlag
188
Jeremy2f190ca2016-01-29 15:23:57 -0800189 main.log.info( itemName + ": Testing Host Intent" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800190
Jeremyd9e4eb12016-04-13 12:09:06 -0700191 try:
192 if not host1.get( "id" ):
193 main.log.warn( "Id not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
194 host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800195
Jeremyd9e4eb12016-04-13 12:09:06 -0700196 if not host2.get( "id" ):
197 main.log.warn( "Id not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
198 host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800199
Jeremyd9e4eb12016-04-13 12:09:06 -0700200 senderNames = [ host1.get( "name" ), host2.get( "name" ) ]
201 recipientNames = [ host1.get( "name" ), host2.get( "name" ) ]
Jeremy Songster832f9e92016-05-05 14:30:49 -0700202 vlanId = host1.get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800203
Jeremyd9e4eb12016-04-13 12:09:06 -0700204 testResult = main.TRUE
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700205 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700206 main.log.error( "There was a problem loading the hosts data." )
207 return main.FALSE
208
209 main.log.info( itemName + ": Testing Host to Host intents" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800210
211 # Check intent state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700212 if hostIntentFailFlag:
213 attempts = 1
214 else:
215 attempts = 50
Shreyaca8990f2017-03-16 11:43:11 -0700216 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700217 args=( main, [ intentId ] ), sleep=main.checkIntentSleep, attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800218 main.assertReturnString += 'Initial Intent State Passed\n'
219 else:
220 main.assertReturnString += 'Initial Intent State Failed\n'
221 testResult = main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700222 attempts = 1
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800223
224 # Check flows count in each node
Shreyaca8990f2017-03-16 11:43:11 -0700225 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
226 args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState,
227 retValue=main.FALSE,
228 args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800229 main.assertReturnString += 'Initial Flow State Passed\n'
230 else:
231 main.assertReturnString += 'Intial Flow State Failed\n'
232 testResult = main.FALSE
233
234 # Check Connectivity
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700235 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, attempts=attempts, sleep=main.checkConnectionSleep,
Shreyaca8990f2017-03-16 11:43:11 -0700236 args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800237 main.assertReturnString += 'Initial Ping Passed\n'
238 else:
239 main.assertReturnString += 'Initial Ping Failed\n'
240 testResult = main.FALSE
241
242 # Test rerouting if these variables exist
243 if sw1 and sw2 and expectedLink:
244 # Take link down
245 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
246 main.assertReturnString += 'Link Down Passed\n'
247 else:
248 main.assertReturnString += 'Link Down Failed\n'
249 testResult = main.FALSE
250
251 # Check intent state
Shreyaca8990f2017-03-16 11:43:11 -0700252 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700253 args=( main, [ intentId ] ), sleep=main.checkIntentHostSleep, attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800254 main.assertReturnString += 'Link Down Intent State Passed\n'
255 else:
256 main.assertReturnString += 'Link Down Intent State Failed\n'
257 testResult = main.FALSE
258
259 # Check flows count in each node
Shreyaca8990f2017-03-16 11:43:11 -0700260 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=main.checkFlowCountSleep,
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700261 attempts=attempts ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ],
262 sleep=main.checkFlowCountSleep, attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800263 main.assertReturnString += 'Link Down Flow State Passed\n'
264 else:
265 main.assertReturnString += 'Link Down Flow State Failed\n'
266 testResult = main.FALSE
267
268 # Check OnosTopology
269 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink ) ):
270 main.assertReturnString += 'Link Down Topology State Passed\n'
271 else:
272 main.assertReturnString += 'Link Down Topology State Failed\n'
273 testResult = main.FALSE
274
275 # Check Connection
Shreyaca8990f2017-03-16 11:43:11 -0700276 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
277 args=( main, senderNames, recipientNames, vlanId ),
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700278 sleep=main.checkConnectionSleep, attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800279 main.assertReturnString += 'Link Down Pingall Passed\n'
280 else:
281 main.assertReturnString += 'Link Down Pingall Failed\n'
282 testResult = main.FALSE
283
284 # Bring link up
285 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
286 main.assertReturnString += 'Link Up Passed\n'
287 else:
288 main.assertReturnString += 'Link Up Failed\n'
289 testResult = main.FALSE
290
291 # Wait for reroute
292 time.sleep( main.rerouteSleep )
293
294 # Check Intents
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700295 if utilities.retry( f=checkIntentState, retValue=main.FALSE, attempts=attempts * 2,
Shreyaca8990f2017-03-16 11:43:11 -0700296 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800297 main.assertReturnString += 'Link Up Intent State Passed\n'
298 else:
299 main.assertReturnString += 'Link Up Intent State Failed\n'
300 testResult = main.FALSE
301
302 # Check flows count in each node
Shreyaca8990f2017-03-16 11:43:11 -0700303 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ],
304 sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE,
305 args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800306 main.assertReturnString += 'Link Up Flow State Passed\n'
307 else:
308 main.assertReturnString += 'Link Up Flow State Failed\n'
309 testResult = main.FALSE
310
311 # Check OnosTopology
312 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
313 main.assertReturnString += 'Link Up Topology State Passed\n'
314 else:
315 main.assertReturnString += 'Link Up Topology State Failed\n'
316 testResult = main.FALSE
317
318 # Check Connection
Jeremy Songster832f9e92016-05-05 14:30:49 -0700319 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800320 main.assertReturnString += 'Link Up Pingall Passed\n'
321 else:
322 main.assertReturnString += 'Link Up Pingall Failed\n'
323 testResult = main.FALSE
324
325 # Remove all intents
Shreyaca8990f2017-03-16 11:43:11 -0700326 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, attempts=10, args=( main, [ intentId ] ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800327 main.assertReturnString += 'Remove Intents Passed'
328 else:
329 main.assertReturnString += 'Remove Intents Failed'
330 testResult = main.FALSE
331
332 return testResult
333
334def installPointIntent( main,
335 name,
336 senders,
337 recipients,
338 onosNode=0,
339 ethType="",
340 bandwidth="",
341 lambdaAlloc=False,
alisonda157272016-12-22 01:13:21 -0800342 protected=False,
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800343 ipProto="",
344 ipSrc="",
345 ipDst="",
346 tcpSrc="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700347 tcpDst="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700348 setVlan="",
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700349 encap="",
350 bandwidthFlag=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800351 """
352 Installs a Single to Single Point Intent
353
354 Description:
355 Install a single to single point intent
356
357 Steps:
358 - Fetch host data if not given
359 - Add point intent
360 - Ingress device is the first sender device
361 - Egress device is the first recipient device
362 - Ports if defined in senders or recipients
363 - MAC address ethSrc loaded from Ingress device
364 - Check intent state with retry
365 Required:
366 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
367 senders - List of host dictionaries i.e.
368 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
369 recipients - List of host dictionaries i.e.
370 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
371 Optional:
372 onosNode - ONOS node to install the intents in main.CLIs[ ]
373 0 by default so that it will always use the first
374 ONOS node
375 ethType - Ethernet type eg. IPV4, IPV6
376 bandwidth - Bandwidth capacity
377 lambdaAlloc - Allocate lambda, defaults to False
378 ipProto - IP protocol
379 tcp - TCP ports in the same order as the hosts in hostNames
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700380 sw1 - First switch to bring down & up for rerouting purpose
381 sw2 - Second switch to bring down & up for rerouting purpose
382 expectedLink - Expected link when the switches are down, it should
383 be two links lower than the links before the two
384 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700385 """
386
387 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800388 assert senders, "You must specify a sender"
389 assert recipients, "You must specify a recipient"
390 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700391
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800392 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700393 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700394
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700395 global pointIntentFailFlag
396 pointIntentFailFlag = False
397
Jeremy6f000c62016-02-25 17:02:28 -0800398 main.log.info( itemName + ": Adding point to point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700399
Jeremyd9e4eb12016-04-13 12:09:06 -0700400 try:
401 for sender in senders:
402 if not sender.get( "device" ):
403 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
404 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800405
Jeremyd9e4eb12016-04-13 12:09:06 -0700406 for recipient in recipients:
407 if not recipient.get( "device" ):
408 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
409 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800410
411
Jeremyd9e4eb12016-04-13 12:09:06 -0700412 ingressDevice = senders[ 0 ].get( "device" )
413 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800414
Jeremyd9e4eb12016-04-13 12:09:06 -0700415 portIngress = senders[ 0 ].get( "port", "" )
416 portEgress = recipients[ 0 ].get( "port", "" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800417
Jeremyd9e4eb12016-04-13 12:09:06 -0700418 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800419
Jeremyd9e4eb12016-04-13 12:09:06 -0700420 ipSrc = senders[ 0 ].get( "ip" )
421 ipDst = recipients[ 0 ].get( "ip" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800422
Jeremy Songster832f9e92016-05-05 14:30:49 -0700423 vlanId = senders[ 0 ].get( "vlan" )
424
Jeremyd9e4eb12016-04-13 12:09:06 -0700425 # Adding point intent
426 intentId = main.CLIs[ onosNode ].addPointIntent(
427 ingressDevice=ingressDevice,
428 egressDevice=egressDevice,
429 portIngress=portIngress,
430 portEgress=portEgress,
431 ethType=ethType,
432 ethDst=dstMac,
433 bandwidth=bandwidth,
434 lambdaAlloc=lambdaAlloc,
alisonda157272016-12-22 01:13:21 -0800435 protected=protected,
Jeremyd9e4eb12016-04-13 12:09:06 -0700436 ipProto=ipProto,
437 ipSrc=ipSrc,
438 ipDst=ipDst,
439 tcpSrc=tcpSrc,
Jeremy Songster832f9e92016-05-05 14:30:49 -0700440 tcpDst=tcpDst,
Jeremy Songsterff553672016-05-12 17:06:23 -0700441 vlanId=vlanId,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700442 setVlan=setVlan,
443 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700444 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700445 errorMsg = "There was a problem loading the hosts data."
446 if intentId:
447 errorMsg += " There was a problem installing Point to Point intent."
448 main.log.error( errorMsg )
449 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700450
451 # Check intents state
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700452 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700453 args=( main, [ intentId ], bandwidthFlag ), sleep=main.checkIntentSleep*2, attempts=50 ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700454 main.assertReturnString += 'Install Intent State Passed\n'
alison52b25892016-09-19 10:53:48 -0700455
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700456 if bandwidth != "":
457 main.assertReturnString += 'Bandwidth Allocation Passed\n'
458
alison52b25892016-09-19 10:53:48 -0700459 # Check VLAN if test encapsulation
460 if encap != "":
461 if EncapsulatedIntentCheck( main, tag=encap ):
462 main.assertReturnString += 'Encapsulation intents check Passed\n'
463 else:
464 main.assertReturnString += 'Encapsulation intents check failed\n'
alisonda157272016-12-22 01:13:21 -0800465
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700466 if flowDuration( main ):
467 main.assertReturnString += 'Flow duration check Passed\n'
468 return intentId
469 else:
470 main.assertReturnString += 'Flow duration check failed\n'
471 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -0700472 else:
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700473 if bandwidth != "":
474 main.assertReturnString += 'Bandwidth Allocation Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800475 main.log.error( "Point Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700476 pointIntentFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800477 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700478
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700479def pointIntentTcp( main,
480 name,
481 host1,
482 host2,
483 onosNode=0,
484 deviceId1="",
485 deviceId2="",
486 port1="",
487 port2="",
488 ethType="",
489 mac1="",
490 mac2="",
491 bandwidth="",
492 lambdaAlloc=False,
493 ipProto="",
494 ip1="",
495 ip2="",
496 tcp1="",
497 tcp2="",
498 sw1="",
499 sw2="",
500 expectedLink=0 ):
501
502 """
503 Description:
504 Verify add-point-intent only for TCP
505 Steps:
506 - Get device ids | ports
507 - Add point intents
508 - Check intents
509 - Verify flows
510 - Ping hosts
511 - Reroute
512 - Link down
513 - Verify flows
514 - Check topology
515 - Ping hosts
516 - Link up
517 - Verify flows
518 - Check topology
519 - Ping hosts
520 - Remove intents
521 Required:
522 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
523 host1 - Name of first host
524 host2 - Name of second host
525 Optional:
526 onosNode - ONOS node to install the intents in main.CLIs[ ]
527 0 by default so that it will always use the first
528 ONOS node
529 deviceId1 - ONOS device id of the first switch, the same as the
530 location of the first host eg. of:0000000000000001/1,
531 located at device 1 port 1
532 deviceId2 - ONOS device id of the second switch
533 port1 - The port number where the first host is attached
534 port2 - The port number where the second host is attached
535 ethType - Ethernet type eg. IPV4, IPV6
536 mac1 - Mac address of first host
537 mac2 - Mac address of the second host
538 bandwidth - Bandwidth capacity
539 lambdaAlloc - Allocate lambda, defaults to False
540 ipProto - IP protocol
541 ip1 - IP address of first host
542 ip2 - IP address of second host
543 tcp1 - TCP port of first host
544 tcp2 - TCP port of second host
545 sw1 - First switch to bring down & up for rerouting purpose
546 sw2 - Second switch to bring down & up for rerouting purpose
547 expectedLink - Expected link when the switches are down, it should
548 be two links lower than the links before the two
549 switches are down
550 """
551
552 assert main, "There is no main variable"
553 assert name, "variable name is empty"
554 assert host1 and host2, "You must specify hosts"
555
556 global itemName
557 itemName = name
558 host1 = host1
559 host2 = host2
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700560 intentsId = []
561
562 iperfResult = main.TRUE
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700563 linkDownResult = main.TRUE
564 linkUpResult = main.TRUE
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700565
566 # Adding bidirectional point intents
567 main.log.info( itemName + ": Adding point intents" )
568 intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
569 egressDevice=deviceId2,
570 portIngress=port1,
571 portEgress=port2,
572 ethType=ethType,
573 ethSrc=mac1,
574 ethDst=mac2,
575 bandwidth=bandwidth,
576 lambdaAlloc=lambdaAlloc,
577 ipProto=ipProto,
578 ipSrc=ip1,
579 ipDst=ip2,
580 tcpSrc=tcp1,
581 tcpDst="" )
582
583 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
584 egressDevice=deviceId1,
585 portIngress=port2,
586 portEgress=port1,
587 ethType=ethType,
588 ethSrc=mac2,
589 ethDst=mac1,
590 bandwidth=bandwidth,
591 lambdaAlloc=lambdaAlloc,
592 ipProto=ipProto,
593 ipSrc=ip2,
594 ipDst=ip1,
595 tcpSrc=tcp2,
596 tcpDst="" )
597
598 intent3 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
599 egressDevice=deviceId2,
600 portIngress=port1,
601 portEgress=port2,
602 ethType=ethType,
603 ethSrc=mac1,
604 ethDst=mac2,
605 bandwidth=bandwidth,
606 lambdaAlloc=lambdaAlloc,
607 ipProto=ipProto,
608 ipSrc=ip1,
609 ipDst=ip2,
610 tcpSrc="",
611 tcpDst=tcp2 )
612
613 intent4 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
614 egressDevice=deviceId1,
615 portIngress=port2,
616 portEgress=port1,
617 ethType=ethType,
618 ethSrc=mac2,
619 ethDst=mac1,
620 bandwidth=bandwidth,
621 lambdaAlloc=lambdaAlloc,
622 ipProto=ipProto,
623 ipSrc=ip2,
624 ipDst=ip1,
625 tcpSrc="",
626 tcpDst=tcp1 )
627 intentsId.append( intent1 )
628 intentsId.append( intent2 )
629 intentsId.append( intent3 )
630 intentsId.append( intent4 )
631
632 # Check intents state
633 time.sleep( main.checkIntentSleep )
Shreyaca8990f2017-03-16 11:43:11 -0700634 intentResult = utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [intentsId ] ),
635 sleep=1, attempts=50 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700636 # Check flows count in each node
637 checkFlowsCount( main )
638
639 # Check intents state again if first check fails...
640 if not intentResult:
Shreyaca8990f2017-03-16 11:43:11 -0700641 intentResult = utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [intentsId ] ),
642 sleep=1, attempts=50 )
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700643
644 # Check flows count in each node
645 checkFlowsCount( main )
646
647 # Verify flows
648 checkFlowsState( main )
649
650 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700651 iperfTemp = main.Mininet1.iperftcp( host1, host2 ,10 )
acsmarsd4862d12015-10-06 17:57:34 -0700652 iperfResult = iperfResult and iperfTemp
653 if iperfTemp:
654 main.assertReturnString += 'Initial Iperf Passed\n'
655 else:
656 main.assertReturnString += 'Initial Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700657
658 # Test rerouting if these variables exist
659 if sw1 and sw2 and expectedLink:
660 # link down
661 linkDownResult = link( main, sw1, sw2, "down" )
acsmarsd4862d12015-10-06 17:57:34 -0700662
663 if linkDownResult:
664 main.assertReturnString += 'Link Down Passed\n'
665 else:
666 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700667
668 # Check flows count in each node
669 checkFlowsCount( main )
670 # Verify flows
671 checkFlowsState( main )
672
673 # Check OnosTopology
674 topoResult = checkTopology( main, expectedLink )
acsmarsd4862d12015-10-06 17:57:34 -0700675 if topoResult:
676 main.assertReturnString += 'Link Down Topology State Passed\n'
677 else:
678 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700679
680 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700681 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700682 iperfResult = iperfResult and iperfTemp
683 if iperfTemp:
684 main.assertReturnString += 'Link Down Iperf Passed\n'
685 else:
686 main.assertReturnString += 'Link Down Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700687
acsmarsd4862d12015-10-06 17:57:34 -0700688 # Check intent state
Shreyaca8990f2017-03-16 11:43:11 -0700689 intentTemp = utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [intentsId ] ),
690 sleep=1, attempts=50 )
acsmarsd4862d12015-10-06 17:57:34 -0700691 intentResult = intentResult and intentTemp
692 if intentTemp:
693 main.assertReturnString += 'Link Down Intent State Passed\n'
694 else:
695 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700696
697 # Checks ONOS state in link down
698 if linkDownResult and topoResult and iperfResult and intentResult:
699 main.log.info( itemName + ": Successfully brought link down" )
700 else:
701 main.log.error( itemName + ": Failed to bring link down" )
702
703 # link up
704 linkUpResult = link( main, sw1, sw2, "up" )
alison52b25892016-09-19 10:53:48 -0700705 if linkUpResult:
acsmarsd4862d12015-10-06 17:57:34 -0700706 main.assertReturnString += 'Link Up Passed\n'
707 else:
708 main.assertReturnString += 'Link Up Failed\n'
709
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700710 time.sleep( main.rerouteSleep )
711
712 # Check flows count in each node
713 checkFlowsCount( main )
714 # Verify flows
715 checkFlowsState( main )
716
717 # Check OnosTopology
718 topoResult = checkTopology( main, main.numLinks )
719
acsmarsd4862d12015-10-06 17:57:34 -0700720 if topoResult:
721 main.assertReturnString += 'Link Up Topology State Passed\n'
722 else:
723 main.assertReturnString += 'Link Up Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700724
acsmarsd4862d12015-10-06 17:57:34 -0700725 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700726 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700727 iperfResult = iperfResult and iperfTemp
728 if iperfTemp:
729 main.assertReturnString += 'Link Up Iperf Passed\n'
730 else:
731 main.assertReturnString += 'Link Up Iperf Failed\n'
732
733 # Check intent state
Shreyaca8990f2017-03-16 11:43:11 -0700734 intentTemp = utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [intentsId ] ),
735 sleep=1, attempts=50 )
acsmarsd4862d12015-10-06 17:57:34 -0700736 intentResult = intentResult and intentTemp
737 if intentTemp:
738 main.assertReturnString += 'Link Down Intent State Passed\n'
739 else:
740 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700741
742 # Checks ONOS state in link up
743 if linkUpResult and topoResult and iperfResult and intentResult:
744 main.log.info( itemName + ": Successfully brought link back up" )
745 else:
746 main.log.error( itemName + ": Failed to bring link back up" )
747
748 # Remove all intents
749 removeIntentResult = removeAllIntents( main, intentsId )
acsmarsd4862d12015-10-06 17:57:34 -0700750 if removeIntentResult:
751 main.assertReturnString += 'Remove Intents Passed'
752 else:
753 main.assertReturnString += 'Remove Intents Failed'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700754
755 stepResult = iperfResult and linkDownResult and linkUpResult \
756 and intentResult and removeIntentResult
757
758 return stepResult
759
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800760def installSingleToMultiIntent( main,
761 name,
762 senders,
763 recipients,
764 onosNode=0,
765 ethType="",
766 bandwidth="",
767 lambdaAlloc=False,
768 ipProto="",
769 ipAddresses="",
770 tcp="",
771 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700772 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -0700773 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700774 partial=False,
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700775 encap="",
776 bandwidthFlag=False ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700777 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800778 Installs a Single to Multi Point Intent
779
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700780 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800781 Install a single to multi point intent using
782 add-single-to-multi-intent
783
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700784 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800785 - Fetch host data if not given
786 - Add single to multi intent
787 - Ingress device is the first sender host
788 - Egress devices are the recipient devices
789 - Ports if defined in senders or recipients
790 - MAC address ethSrc loaded from Ingress device
791 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700792 Required:
793 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800794 senders - List of host dictionaries i.e.
795 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
796 recipients - List of host dictionaries i.e.
797 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700798 Optional:
799 onosNode - ONOS node to install the intents in main.CLIs[ ]
800 0 by default so that it will always use the first
801 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700802 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700803 bandwidth - Bandwidth capacity
804 lambdaAlloc - Allocate lambda, defaults to False
805 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700806 tcp - TCP ports in the same order as the hosts in hostNames
807 sw1 - First switch to bring down & up for rerouting purpose
808 sw2 - Second switch to bring down & up for rerouting purpose
809 expectedLink - Expected link when the switches are down, it should
810 be two links lower than the links before the two
811 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700812 """
813
814 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800815 assert senders, "You must specify a sender"
816 assert recipients, "You must specify a recipient"
817 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700818
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800819 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700820 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700821
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700822 global singleToMultiFailFlag
823 singleToMultiFailFlag = False
824
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700825 main.log.info( itemName + ": Adding single point to multi point intents" )
826
Jeremyd9e4eb12016-04-13 12:09:06 -0700827 try:
828 for sender in senders:
829 if not sender.get( "device" ):
830 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
831 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700832
Jeremyd9e4eb12016-04-13 12:09:06 -0700833 for recipient in recipients:
834 if not recipient.get( "device" ):
835 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
836 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700837
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700838
Jeremyd9e4eb12016-04-13 12:09:06 -0700839 ingressDevice = senders[ 0 ].get( "device" )
840 egressDeviceList = [ x.get( "device" ) for x in recipients if x.get( "device" ) ]
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800841
Jeremyd9e4eb12016-04-13 12:09:06 -0700842 portIngress = senders[ 0 ].get( "port", "" )
843 portEgressList = [ x.get( "port" ) for x in recipients if x.get( "port" ) ]
844 if not portEgressList:
845 portEgressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800846
Jeremyd9e4eb12016-04-13 12:09:06 -0700847 srcMac = senders[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700848 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800849
Jeremyd9e4eb12016-04-13 12:09:06 -0700850 # Adding point intent
851 intentId = main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
852 ingressDevice=ingressDevice,
853 egressDeviceList=egressDeviceList,
854 portIngress=portIngress,
855 portEgressList=portEgressList,
856 ethType=ethType,
857 ethSrc=srcMac,
858 bandwidth=bandwidth,
859 lambdaAlloc=lambdaAlloc,
860 ipProto=ipProto,
861 ipSrc="",
862 ipDst="",
863 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -0700864 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700865 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -0700866 setVlan=setVlan,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700867 partial=partial,
868 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700869 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700870 errorMsg = "There was a problem loading the hosts data."
871 if intentId:
872 errorMsg += " There was a problem installing Singlepoint to Multipoint intent."
873 main.log.error( errorMsg )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700874 singleToMultiFailFlag = True
Jeremyd9e4eb12016-04-13 12:09:06 -0700875 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700876
877 # Check intents state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700878 if singleToMultiFailFlag:
879 attempts = 5
880 else:
881 attempts = 50
882
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700883 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700884 args=( main, [ intentId ], bandwidthFlag ), sleep=main.checkIntentSleep, attempts=attempts ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700885 main.assertReturnString += 'Install Intent State Passed\n'
886 if flowDuration( main ):
887 main.assertReturnString += 'Flow duration check Passed\n'
888 return intentId
889 else:
890 main.assertReturnString += 'Flow duration check failed\n'
891 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -0700892 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800893 main.log.error( "Single to Multi Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700894 singleToMultiFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800895 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700896
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800897def installMultiToSingleIntent( main,
898 name,
899 senders,
900 recipients,
901 onosNode=0,
902 ethType="",
903 bandwidth="",
904 lambdaAlloc=False,
905 ipProto="",
906 ipAddresses="",
907 tcp="",
908 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700909 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -0700910 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700911 partial=False,
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700912 encap="",
913 bandwidthFlag=False ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700914 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800915 Installs a Multi to Single Point Intent
916
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700917 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800918 Install a multi to single point intent using
919 add-multi-to-single-intent
920
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700921 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800922 - Fetch host data if not given
923 - Add multi to single intent
924 - Ingress devices are the senders devices
925 - Egress device is the first recipient host
926 - Ports if defined in senders or recipients
927 - MAC address ethSrc loaded from Ingress device
928 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700929 Required:
930 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800931 senders - List of host dictionaries i.e.
932 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
933 recipients - List of host dictionaries i.e.
934 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700935 Optional:
936 onosNode - ONOS node to install the intents in main.CLIs[ ]
937 0 by default so that it will always use the first
938 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700939 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700940 bandwidth - Bandwidth capacity
941 lambdaAlloc - Allocate lambda, defaults to False
942 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700943 tcp - TCP ports in the same order as the hosts in hostNames
944 sw1 - First switch to bring down & up for rerouting purpose
945 sw2 - Second switch to bring down & up for rerouting purpose
946 expectedLink - Expected link when the switches are down, it should
947 be two links lower than the links before the two
948 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700949 """
950
951 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800952 assert senders, "You must specify a sender"
953 assert recipients, "You must specify a recipient"
954 # Assert devices or main.hostsData, "You must specify devices"
955
956 global itemName # The name of this run. Used for logs.
957 itemName = name
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800958
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700959 global multiToSingleFailFlag
960 multiToSingleFailFlag = False
961
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800962 main.log.info( itemName + ": Adding mutli to single point intents" )
963
Jeremyd9e4eb12016-04-13 12:09:06 -0700964 try:
965 for sender in senders:
966 if not sender.get( "device" ):
967 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
968 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800969
Jeremyd9e4eb12016-04-13 12:09:06 -0700970 for recipient in recipients:
971 if not recipient.get( "device" ):
972 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
973 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800974
Jeremyd9e4eb12016-04-13 12:09:06 -0700975 ingressDeviceList = [ x.get( "device" ) for x in senders if x.get( "device" ) ]
976 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800977
Jeremyd9e4eb12016-04-13 12:09:06 -0700978 portIngressList = [ x.get( "port" ) for x in senders if x.get( "port" ) ]
979 portEgress = recipients[ 0 ].get( "port", "" )
980 if not portIngressList:
981 portIngressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800982
Jeremyd9e4eb12016-04-13 12:09:06 -0700983 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700984 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800985
Jeremyd9e4eb12016-04-13 12:09:06 -0700986 # Adding point intent
987 intentId = main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
988 ingressDeviceList=ingressDeviceList,
989 egressDevice=egressDevice,
990 portIngressList=portIngressList,
991 portEgress=portEgress,
992 ethType=ethType,
993 ethDst=dstMac,
994 bandwidth=bandwidth,
995 lambdaAlloc=lambdaAlloc,
996 ipProto=ipProto,
997 ipSrc="",
998 ipDst="",
999 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -07001000 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -07001001 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -07001002 setVlan=setVlan,
Jeremy Songsterc032f162016-08-04 17:14:49 -07001003 partial=partial,
1004 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001005 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001006 errorMsg = "There was a problem loading the hosts data."
1007 if intentId:
1008 errorMsg += " There was a problem installing Multipoint to Singlepoint intent."
1009 main.log.error( errorMsg )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001010 multiToSingleFailFlag = True
Jeremyd9e4eb12016-04-13 12:09:06 -07001011 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001012
1013 # Check intents state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001014 if multiToSingleFailFlag:
1015 attempts = 5
1016 else:
1017 attempts = 50
1018
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001019 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001020 args=( main, [ intentId ], bandwidthFlag ), sleep=main.checkIntentSleep, attempts=attempts ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001021 main.assertReturnString += 'Install Intent State Passed\n'
1022 if flowDuration( main ):
1023 main.assertReturnString += 'Flow duration check Passed\n'
1024 return intentId
1025 else:
1026 main.assertReturnString += 'Flow duration check failed\n'
1027 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001028 else:
1029 main.log.error( "Multi to Single Intent did not install correctly" )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001030 multiToSingleFailFlag = True
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001031 return main.FALSE
1032
1033def testPointIntent( main,
Jeremye0cb5eb2016-01-27 17:39:09 -08001034 name,
1035 intentId,
1036 senders,
1037 recipients,
1038 badSenders={},
1039 badRecipients={},
1040 onosNode=0,
1041 ethType="",
1042 bandwidth="",
1043 lambdaAlloc=False,
alisonda157272016-12-22 01:13:21 -08001044 protected=False,
Jeremye0cb5eb2016-01-27 17:39:09 -08001045 ipProto="",
1046 ipAddresses="",
1047 tcp="",
1048 sw1="s5",
1049 sw2="s2",
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001050 expectedLink=0,
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001051 useTCP=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001052 """
1053 Test a Point Intent
1054
1055 Description:
1056 Test a point intent
1057
1058 Steps:
1059 - Fetch host data if not given
1060 - Check Intent State
1061 - Check Flow State
1062 - Check Connectivity
1063 - Check Lack of Connectivity Between Hosts not in the Intent
1064 - Reroute
1065 - Take Expected Link Down
1066 - Check Intent State
1067 - Check Flow State
1068 - Check Topology
1069 - Check Connectivity
1070 - Bring Expected Link Up
1071 - Check Intent State
1072 - Check Flow State
1073 - Check Topology
1074 - Check Connectivity
1075 - Remove Topology
1076
1077 Required:
1078 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
1079
1080 senders - List of host dictionaries i.e.
1081 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
1082 recipients - List of host dictionaries i.e.
1083 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
1084 Optional:
1085 onosNode - ONOS node to install the intents in main.CLIs[ ]
1086 0 by default so that it will always use the first
1087 ONOS node
1088 ethType - Ethernet type eg. IPV4, IPV6
1089 bandwidth - Bandwidth capacity
1090 lambdaAlloc - Allocate lambda, defaults to False
1091 ipProto - IP protocol
1092 tcp - TCP ports in the same order as the hosts in hostNames
1093 sw1 - First switch to bring down & up for rerouting purpose
1094 sw2 - Second switch to bring down & up for rerouting purpose
1095 expectedLink - Expected link when the switches are down, it should
1096 be two links lower than the links before the two
1097 switches are down
1098
1099 """
1100
1101 # Parameter Validity Check
1102 assert main, "There is no main variable"
1103 assert senders, "You must specify a sender"
1104 assert recipients, "You must specify a recipient"
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001105
1106 global itemName
1107 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001108
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001109 global pointIntentFailFlag
1110 global singleToMultiFailFlag
1111 global multiToSingleFailFlag
1112
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001113 main.log.info( itemName + ": Testing Point Intent" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001114
Jeremyd9e4eb12016-04-13 12:09:06 -07001115 try:
1116 # Names for scapy
1117 senderNames = [ x.get( "name" ) for x in senders ]
1118 recipientNames = [ x.get( "name" ) for x in recipients ]
1119 badSenderNames = [ x.get( "name" ) for x in badSenders ]
1120 badRecipientNames = [ x.get( "name" ) for x in badRecipients ]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001121
Jeremyd9e4eb12016-04-13 12:09:06 -07001122 for sender in senders:
1123 if not sender.get( "device" ):
1124 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1125 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001126
Jeremyd9e4eb12016-04-13 12:09:06 -07001127 for recipient in recipients:
1128 if not recipient.get( "device" ):
1129 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1130 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001131 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001132 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001133 main.log.error( "There was a problem loading the hosts data." )
1134 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001135
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001136 testResult = main.TRUE
1137 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001138
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001139 if pointIntentFailFlag or singleToMultiFailFlag or multiToSingleFailFlag:
1140 attempts = 1
1141 else:
1142 attempts = 50
1143
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001144 # Check intent state
Shreyaca8990f2017-03-16 11:43:11 -07001145 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ),
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001146 sleep=main.checkIntentSleep, attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001147 main.assertReturnString += 'Initial Intent State Passed\n'
acsmarsd4862d12015-10-06 17:57:34 -07001148 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001149 main.assertReturnString += 'Initial Intent State Failed\n'
1150 testResult = main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001151 attempts = 1
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001152
1153 # Check flows count in each node
Shreyaca8990f2017-03-16 11:43:11 -07001154 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ],
1155 sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE,
1156 args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001157 main.assertReturnString += 'Initial Flow State Passed\n'
1158 else:
1159 main.assertReturnString += 'Intial Flow State Failed\n'
1160 testResult = main.FALSE
1161
1162 # Check Connectivity
Shreyaca8990f2017-03-16 11:43:11 -07001163 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1164 args=( main, senderNames, recipientNames, vlanId, useTCP ),
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001165 attempts=attempts, sleep=main.checkConnectionSleep ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001166 main.assertReturnString += 'Initial Ping Passed\n'
1167 else:
1168 main.assertReturnString += 'Initial Ping Failed\n'
1169 testResult = main.FALSE
1170
1171 # Check connections that shouldn't work
1172 if badSenderNames:
1173 main.log.info( "Checking that packets from incorrect sender do not go through" )
1174 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, badSenderNames, recipientNames ), kwargs={ "expectFailure":True } ):
1175 main.assertReturnString += 'Bad Sender Ping Passed\n'
1176 else:
1177 main.assertReturnString += 'Bad Sender Ping Failed\n'
1178 testResult = main.FALSE
1179
1180 if badRecipientNames:
1181 main.log.info( "Checking that packets to incorrect recipients do not go through" )
1182 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, badRecipientNames ), kwargs={ "expectFailure":True } ):
1183 main.assertReturnString += 'Bad Recipient Ping Passed\n'
1184 else:
1185 main.assertReturnString += 'Bad Recipient Ping Failed\n'
1186 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001187
1188 # Test rerouting if these variables exist
1189 if sw1 and sw2 and expectedLink:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001190 # Take link down
1191 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001192 main.assertReturnString += 'Link Down Passed\n'
1193 else:
1194 main.assertReturnString += 'Link Down Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001195 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001196
alisonda157272016-12-22 01:13:21 -08001197 if protected:
1198 # Check Connection
1199 if utilities.retry(f=scapyCheckConnection, retValue=main.FALSE,
1200 args=(main, senderNames, recipientNames, vlanId, useTCP) ):
1201 main.assertReturnString += 'Link down Scapy Packet Received Passed\n'
1202 else:
1203 main.assertReturnString += 'Link down Scapy Packet Recieved Failed\n'
1204 testResult = main.FALSE
1205
1206 if ProtectedIntentCheck( main ):
1207 main.assertReturnString += 'Protected Intent Check Passed\n'
1208 else:
1209 main.assertReturnString += 'Protected Intent Check Failed\n'
1210 testResult = main.FALSE
1211
acsmarsd4862d12015-10-06 17:57:34 -07001212 # Check intent state
Shreyaca8990f2017-03-16 11:43:11 -07001213 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ),
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001214 sleep=main.checkIntentPointSleep, attempts=attempts ):
acsmarsd4862d12015-10-06 17:57:34 -07001215 main.assertReturnString += 'Link Down Intent State Passed\n'
1216 else:
1217 main.assertReturnString += 'Link Down Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001218 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001219
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001220 # Check flows count in each node
Shreyaca8990f2017-03-16 11:43:11 -07001221 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=main.checkFlowCountSleep,
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001222 attempts=attempts * 2 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ],
1223 sleep=main.checkFlowCountSleep, attempts=attempts * 2 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001224 main.assertReturnString += 'Link Down Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001225 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001226 main.assertReturnString += 'Link Down Flow State Failed\n'
1227 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001228
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001229 # Check OnosTopology
1230 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink ) ):
1231 main.assertReturnString += 'Link Down Topology State Passed\n'
1232 else:
1233 main.assertReturnString += 'Link Down Topology State Failed\n'
1234 testResult = main.FALSE
1235
1236 # Check Connection
Shreyaca8990f2017-03-16 11:43:11 -07001237 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1238 args=( main, senderNames, recipientNames, vlanId, useTCP ),
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001239 sleep=main.checkConnectionSleep, attempts=attempts ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001240 main.assertReturnString += 'Link Down Pingall Passed\n'
1241 else:
1242 main.assertReturnString += 'Link Down Pingall Failed\n'
1243 testResult = main.FALSE
1244
1245 # Bring link up
1246 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001247 main.assertReturnString += 'Link Up Passed\n'
1248 else:
1249 main.assertReturnString += 'Link Up Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001250 testResult = main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -07001251
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001252 # Wait for reroute
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001253 time.sleep( main.rerouteSleep )
1254
acsmarsd4862d12015-10-06 17:57:34 -07001255 # Check Intents
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001256 if utilities.retry( f=checkIntentState, retValue=main.FALSE, attempts=attempts * 2, args=( main, [ intentId ] ),
Shreyaca8990f2017-03-16 11:43:11 -07001257 sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001258 main.assertReturnString += 'Link Up Intent State Passed\n'
1259 else:
1260 main.assertReturnString += 'Link Up Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001261 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001262
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001263 # Check flows count in each node
Shreyaca8990f2017-03-16 11:43:11 -07001264 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ],
1265 sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE,
1266 args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001267 main.assertReturnString += 'Link Up Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001268 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001269 main.assertReturnString += 'Link Up Flow State Failed\n'
1270 testResult = main.FALSE
1271
1272 # Check OnosTopology
1273 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
1274 main.assertReturnString += 'Link Up Topology State Passed\n'
1275 else:
1276 main.assertReturnString += 'Link Up Topology State Failed\n'
1277 testResult = main.FALSE
1278
1279 # Check Connection
Shreyaca8990f2017-03-16 11:43:11 -07001280 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, sleep=main.checkConnectionSleep, attempts=100,
1281 args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001282 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1283 else:
1284 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1285 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001286
1287 # Remove all intents
Shreyaca8990f2017-03-16 11:43:11 -07001288 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, attempts=10, args=( main, [ intentId ] ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001289 main.assertReturnString += 'Remove Intents Passed'
1290 else:
1291 main.assertReturnString += 'Remove Intents Failed'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001292 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001293
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001294 return testResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001295
Jeremye0cb5eb2016-01-27 17:39:09 -08001296def testEndPointFail( main,
1297 name,
1298 intentId,
1299 senders,
1300 recipients,
1301 isolatedSenders,
1302 isolatedRecipients,
1303 onosNode=0,
1304 ethType="",
1305 bandwidth="",
1306 lambdaAlloc=False,
1307 ipProto="",
1308 ipAddresses="",
1309 tcp="",
1310 sw1="",
1311 sw2="",
1312 sw3="",
1313 sw4="",
1314 sw5="",
1315 expectedLink1=0,
Jeremy Songster9385d412016-06-02 17:57:36 -07001316 expectedLink2=0,
1317 partial=False ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001318 """
Shreyaca8990f2017-03-16 11:43:11 -07001319 Test Multi point to single point intent Topology for Endpoint failures
Jeremye0cb5eb2016-01-27 17:39:09 -08001320 """
1321
1322 # Parameter Validity Check
1323 assert main, "There is no main variable"
1324 assert senders, "You must specify a sender"
1325 assert recipients, "You must specify a recipient"
1326
1327 global itemName
1328 itemName = name
Jeremye0cb5eb2016-01-27 17:39:09 -08001329
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001330 global singleToMultiFailFlag
1331 global multiToSingleFailFlag
1332
Jeremye0cb5eb2016-01-27 17:39:09 -08001333 main.log.info( itemName + ": Testing Point Intent" )
1334
Jeremyd9e4eb12016-04-13 12:09:06 -07001335 try:
1336 # Names for scapy
1337 senderNames = [ x.get( "name" ) for x in senders ]
1338 recipientNames = [ x.get( "name" ) for x in recipients ]
1339 isolatedSenderNames = [ x.get( "name" ) for x in isolatedSenders ]
1340 isolatedRecipientNames = [ x.get( "name" ) for x in isolatedRecipients ]
1341 connectedSenderNames = [x.get("name") for x in senders if x.get("name") not in isolatedSenderNames]
1342 connectedRecipientNames = [x.get("name") for x in recipients if x.get("name") not in isolatedRecipientNames]
Jeremye0cb5eb2016-01-27 17:39:09 -08001343
Jeremyd9e4eb12016-04-13 12:09:06 -07001344 for sender in senders:
1345 if not sender.get( "device" ):
1346 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1347 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremye0cb5eb2016-01-27 17:39:09 -08001348
Jeremyd9e4eb12016-04-13 12:09:06 -07001349 for recipient in recipients:
1350 if not recipient.get( "device" ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001351 main.log.warn( "Device not given for recipient {0}. Loading from " +\
1352 main.hostData.format( recipient.get( "name" ) ) )
Jeremyd9e4eb12016-04-13 12:09:06 -07001353 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001354 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001355 main.log.error( "There was a problem loading the hosts data." )
1356 return main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001357
1358 testResult = main.TRUE
1359 main.log.info( itemName + ": Adding multi point to single point intents" )
1360
1361 # Check intent state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001362 if singleToMultiFailFlag or multiToSingleFailFlag:
1363 attempts = 1
1364 else:
1365 attempts = 50
1366
Jeremye0cb5eb2016-01-27 17:39:09 -08001367 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001368 args=( main, [ intentId ] ), sleep=main.checkIntentSleep, attempts=attempts ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001369 main.assertReturnString += 'Initial Intent State Passed\n'
1370 else:
1371 main.assertReturnString += 'Initial Intent State Failed\n'
1372 testResult = main.FALSE
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001373 attempts = 1
Jeremye0cb5eb2016-01-27 17:39:09 -08001374
1375 # Check flows count in each node
1376 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
Jeremy Songster9385d412016-06-02 17:57:36 -07001377 args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState,
1378 retValue=main.FALSE,
1379 args=[ main ], attempts=5 ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001380 main.assertReturnString += 'Initial Flow State Passed\n'
1381 else:
1382 main.assertReturnString += 'Intial Flow State Failed\n'
1383 testResult = main.FALSE
1384
1385 # Check Connectivity
1386 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1387 args=( main, senderNames, recipientNames ) ):
1388 main.assertReturnString += 'Initial Connectivity Check Passed\n'
1389 else:
1390 main.assertReturnString += 'Initial Connectivity Check Failed\n'
1391 testResult = main.FALSE
1392
1393 # Take two links down
1394 # Take first link down
1395 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
1396 main.assertReturnString += 'Link Down Passed\n'
1397 else:
1398 main.assertReturnString += 'Link Down Failed\n'
1399 testResult = main.FALSE
1400
1401 # Take second link down
1402 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw4, "down" ) ):
1403 main.assertReturnString += 'Link Down Passed\n'
1404 else:
1405 main.assertReturnString += 'Link Down Failed\n'
1406 testResult = main.FALSE
1407
1408 # Check intent state
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001409 if utilities.retry( f=checkIntentState, retValue=main.FALSE, attempts=attempts,
Jeremye0cb5eb2016-01-27 17:39:09 -08001410 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1411 main.assertReturnString += 'Link Down Intent State Passed\n'
1412 else:
1413 main.assertReturnString += 'Link Down Intent State Failed\n'
1414 testResult = main.FALSE
1415
1416 # Check flows count in each node
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001417 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, sleep=1, attempts=attempts,
Jeremye0cb5eb2016-01-27 17:39:09 -08001418 args=[ main ] ) and utilities.retry( f=checkFlowsState,
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001419 retValue=main.FALSE, sleep=1, attempts=attempts, args=[ main ] ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001420 main.assertReturnString += 'Link Down Flow State Passed\n'
1421 else:
1422 main.assertReturnString += 'Link Down Flow State Failed\n'
1423 testResult = main.FALSE
1424
1425 # Check OnosTopology
1426 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink1 ) ):
1427 main.assertReturnString += 'Link Down Topology State Passed\n'
1428 else:
1429 main.assertReturnString += 'Link Down Topology State Failed\n'
1430 testResult = main.FALSE
1431
1432 # Check Connection
1433 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1434 args=( main, senderNames, recipientNames ) ):
1435 main.assertReturnString += 'Link Down Connectivity Check Passed\n'
1436 else:
1437 main.assertReturnString += 'Link Down Connectivity Check Failed\n'
1438 testResult = main.FALSE
1439
1440 # Take a third link down to isolate one node
1441 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw5, "down" ) ):
1442 main.assertReturnString += 'Isolation link Down Passed\n'
1443 else:
1444 main.assertReturnString += 'Isolation link Down Failed\n'
1445 testResult = main.FALSE
1446
Jeremy Songster9385d412016-06-02 17:57:36 -07001447 if partial:
1448 # Check intent state
1449 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001450 args=( main, [ intentId ] ), sleep=main.checkIntentSleep, attempts=attempts ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001451 main.assertReturnString += 'Partial failure isolation link Down Intent State Passed\n'
1452 else:
1453 main.assertReturnString += 'Partial failure isolation link Down Intent State Failed\n'
1454 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001455
Jeremy Songster9385d412016-06-02 17:57:36 -07001456 # Check flows count in each node
1457 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1458 args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState,
1459 retValue=main.FALSE,
1460 args=[ main ], attempts=5 ):
1461 main.assertReturnString += 'Partial failure isolation link Down Flow State Passed\n'
1462 else:
1463 main.assertReturnString += 'Partial failure isolation link Down Flow State Failed\n'
1464 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001465
Jeremy Songster9385d412016-06-02 17:57:36 -07001466 # Check OnosTopology
1467 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink2 ) ):
1468 main.assertReturnString += 'Partial failure isolation link Down Topology State Passed\n'
1469 else:
1470 main.assertReturnString += 'Partial failure isolation link Down Topology State Failed\n'
1471 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001472
Jeremy Songster9385d412016-06-02 17:57:36 -07001473 # Check Connectivity
1474 # First check connectivity of any isolated senders to recipients
1475 if isolatedSenderNames:
1476 if scapyCheckConnection( main, isolatedSenderNames, recipientNames, None, None, None, None, main.TRUE ):
1477 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1478 else:
1479 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1480 testResult = main.FALSE
1481
1482 # Next check connectivity of senders to any isolated recipients
1483 if isolatedRecipientNames:
1484 if scapyCheckConnection( main, senderNames, isolatedRecipientNames, None, None, None, None, main.TRUE ):
1485 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1486 else:
1487 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1488 testResult = main.FALSE
1489
1490 # Next check connectivity of connected senders and recipients
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001491 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, attempts=attempts,
Jeremy Songster9385d412016-06-02 17:57:36 -07001492 args=( main, connectedSenderNames , connectedRecipientNames ) ):
1493 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1494 else:
1495 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1496 testResult = main.FALSE
1497 else:
1498 # Check intent state
1499 if not utilities.retry( f=checkIntentState, retValue=main.TRUE,
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001500 args=( main, [ intentId ] ), sleep=main.checkIntentSleep, attempts=attempts ):
Jeremy Songster9385d412016-06-02 17:57:36 -07001501 main.assertReturnString += 'Isolation link Down Intent State Passed\n'
1502 else:
1503 main.assertReturnString += 'Isolation link Down Intent State Failed\n'
1504 testResult = main.FALSE
1505
1506 # Check flows count in each node
1507 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1508 args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState,
1509 retValue=main.FALSE,
1510 args=[ main ], attempts=5 ):
1511 main.assertReturnString += 'Isolation link Down Flow State Passed\n'
1512 else:
1513 main.assertReturnString += 'Isolation link Down Flow State Failed\n'
1514 testResult = main.FALSE
1515
1516 # Check OnosTopology
1517 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink2 ) ):
1518 main.assertReturnString += 'Isolation link Down Topology State Passed\n'
1519 else:
1520 main.assertReturnString += 'Isolation link Down Topology State Failed\n'
1521 testResult = main.FALSE
1522
1523 # Check Connectivity
1524 # First check connectivity of any isolated senders to recipients
1525 if isolatedSenderNames:
1526 if scapyCheckConnection( main, isolatedSenderNames, recipientNames, None, None, None, None, main.TRUE ):
1527 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1528 else:
1529 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1530 testResult = main.FALSE
1531
1532 # Next check connectivity of senders to any isolated recipients
1533 if isolatedRecipientNames:
1534 if scapyCheckConnection( main, senderNames, isolatedRecipientNames, None, None, None, None, main.TRUE ):
1535 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1536 else:
1537 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1538 testResult = main.FALSE
1539
1540 # Next check connectivity of connected senders and recipients
1541 if utilities.retry( f=scapyCheckConnection, retValue=main.TRUE,
1542 args=( main, connectedSenderNames , connectedRecipientNames, None, None, None, None, main.TRUE ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001543 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1544 else:
1545 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1546 testResult = main.FALSE
1547
Jeremye0cb5eb2016-01-27 17:39:09 -08001548 # Bring the links back up
1549 # Bring first link up
1550 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
1551 main.assertReturnString += 'Link Up Passed\n'
1552 else:
1553 main.assertReturnString += 'Link Up Failed\n'
1554 testResult = main.FALSE
1555
1556 # Bring second link up
1557 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw5, "up" ) ):
1558 main.assertReturnString += 'Link Up Passed\n'
1559 else:
1560 main.assertReturnString += 'Link Up Failed\n'
1561 testResult = main.FALSE
1562
1563 # Bring third link up
1564 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw4, "up" ) ):
1565 main.assertReturnString += 'Link Up Passed\n'
1566 else:
1567 main.assertReturnString += 'Link Up Failed\n'
1568 testResult = main.FALSE
1569
1570 # Wait for reroute
1571 time.sleep( main.rerouteSleep )
1572
1573 # Check Intents
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001574 if utilities.retry( f=checkIntentState, retValue=main.FALSE, attempts=attempts,
Shreyaca8990f2017-03-16 11:43:11 -07001575 args=( main, [ intentId ] ), sleep=main.checkIntentHostSleep ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001576 main.assertReturnString += 'Link Up Intent State Passed\n'
1577 else:
1578 main.assertReturnString += 'Link Up Intent State Failed\n'
1579 testResult = main.FALSE
1580
1581 # Check flows count in each node
1582 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
Shreyaca8990f2017-03-16 11:43:11 -07001583 args=[ main ], sleep=5, attempts=5*20 ) and utilities.retry( f=checkFlowsState,
Jeremy Songster9385d412016-06-02 17:57:36 -07001584 retValue=main.FALSE,
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001585 args=[ main ], sleep=5, attempts=attempts ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001586 main.assertReturnString += 'Link Up Flow State Passed\n'
1587 else:
1588 main.assertReturnString += 'Link Up Flow State Failed\n'
1589 testResult = main.FALSE
1590
1591 # Check OnosTopology
1592 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
1593 main.assertReturnString += 'Link Up Topology State Passed\n'
1594 else:
1595 main.assertReturnString += 'Link Up Topology State Failed\n'
1596 testResult = main.FALSE
1597
1598 # Check Connection
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001599 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, sleep=main.checkConnectionSleep, attempts= attempts,
Jeremye0cb5eb2016-01-27 17:39:09 -08001600 args=( main, senderNames, recipientNames ) ):
1601 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1602 else:
1603 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1604 testResult = main.FALSE
1605
1606 # Remove all intents
Shreyaca8990f2017-03-16 11:43:11 -07001607 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, attempts=10, args=( main, [ intentId ] ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001608 main.assertReturnString += 'Remove Intents Passed'
1609 else:
1610 main.assertReturnString += 'Remove Intents Failed'
1611 testResult = main.FALSE
1612
1613 return testResult
1614
1615
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001616def pingallHosts( main, hostList ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001617 """
1618 Ping all host in the hosts list variable
1619 """
Jon Halla5cb3412015-08-18 14:08:22 -07001620 main.log.info( "Pinging: " + str( hostList ) )
1621 return main.Mininet1.pingallHosts( hostList )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001622
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001623def fwdPingall( main ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001624 """
1625 Use fwd app and pingall to discover all the hosts
1626 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001627 appCheck = main.TRUE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001628 main.log.info( "Activating reactive forwarding app " )
1629 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001630
1631 # Wait for forward app activation to propagate
kelvin-onlab0ad05d12015-07-23 14:21:15 -07001632 time.sleep( main.fwdSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001633
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001634 # Check that forwarding is enabled on all nodes
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001635 for i in range( main.numCtrls ):
1636 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
1637 if appCheck != main.TRUE:
1638 main.log.warn( main.CLIs[ i ].apps() )
1639 main.log.warn( main.CLIs[ i ].appIDs() )
1640
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001641 # Send pingall in mininet
1642 main.log.info( "Run Pingall" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001643 pingResult = main.Mininet1.pingall( timeout = 600 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001644
1645 main.log.info( "Deactivating reactive forwarding app " )
1646 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001647 if activateResult and deactivateResult:
1648 main.log.info( "Successfully used fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001649 getDataResult = main.TRUE
1650 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001651 main.log.info( "Failed to use fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001652 getDataResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001653 return getDataResult
1654
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001655def confirmHostDiscovery( main ):
1656 """
1657 Confirms that all ONOS nodes have discovered all scapy hosts
1658 """
1659 import collections
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001660 hosts = main.topo.getAllHosts( main ) # Get host data from each ONOS node
1661 hostFails = [] # Reset for each failed attempt
1662
1663 # Check for matching hosts on each node
1664 scapyHostIPs = [ x.hostIp for x in main.scapyHosts if x.hostIp != "0.0.0.0" ]
1665 for controller in range( main.numCtrls ):
1666 controllerStr = str( controller + 1 ) # ONOS node number
1667 # Compare Hosts
1668 # Load hosts data for controller node
Jeremyd9e4eb12016-04-13 12:09:06 -07001669 try:
1670 if hosts[ controller ]:
1671 main.log.info( "Hosts discovered" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001672 else:
Jeremyd9e4eb12016-04-13 12:09:06 -07001673 main.log.error( "Problem discovering hosts" )
1674 if hosts[ controller ] and "Error" not in hosts[ controller ]:
1675 try:
1676 hostData = json.loads( hosts[ controller ] )
1677 except ( TypeError, ValueError ):
1678 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001679 hostFails.append( controllerStr )
Jeremyd9e4eb12016-04-13 12:09:06 -07001680 else:
1681 onosHostIPs = [ x.get( "ipAddresses" )[ 0 ]
1682 for x in hostData
1683 if len( x.get( "ipAddresses" ) ) > 0 ]
1684 if not set( collections.Counter( scapyHostIPs ) ).issubset( set ( collections.Counter( onosHostIPs ) ) ):
1685 main.log.warn( "Controller {0} only sees nodes with {1} IPs. It should see all of the following: {2}".format( controllerStr, onosHostIPs, scapyHostIPs ) )
1686 hostFails.append( controllerStr )
1687 else:
1688 main.log.error( "Hosts returned nothing or an error." )
1689 hostFails.append( controllerStr )
1690 except IndexError:
1691 main.log.error( "Hosts returned nothing, Failed to discover hosts." )
1692 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001693
1694 if hostFails:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001695 main.log.error( "List of failed ONOS Nodes:" + ', '.join( map( str, hostFails ) ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001696 return main.FALSE
1697 else:
1698 return main.TRUE
1699
1700def sendDiscoveryArp( main, hosts=None ):
1701 """
1702 Sends Discovery ARP packets from each host provided
1703 Defaults to each host in main.scapyHosts
1704 """
1705 # Send an arp ping from each host
1706 if not hosts:
1707 hosts = main.scapyHosts
1708 for host in hosts:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001709 pkt = 'Ether( src="{0}")/ARP( psrc="{1}")'.format( host.hostMac, host.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001710 # Send from the VLAN interface if there is one so ONOS discovers the VLAN correctly
1711 iface = None
1712 for interface in host.getIfList():
1713 if '.' in interface:
1714 main.log.debug( "Detected VLAN interface {0}. Sending ARP packet from {0}".format( interface ) )
1715 iface = interface
1716 break
1717 host.sendPacket( packet=pkt, iface=iface )
1718 main.log.info( "Sending ARP packet from {0}".format( host.name ) )
1719
1720def populateHostData( main ):
1721 """
1722 Populates hostsData
1723 """
1724 import json
1725 try:
1726 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
1727 hosts = main.Mininet1.getHosts().keys()
1728 # TODO: Make better use of new getHosts function
1729 for host in hosts:
1730 main.hostsData[ host ] = {}
1731 main.hostsData[ host ][ 'mac' ] = \
1732 main.Mininet1.getMacAddress( host ).upper()
1733 for hostj in hostsJson:
1734 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
1735 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
1736 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
1737 main.hostsData[ host ][ 'location' ] = \
1738 hostj[ 'location' ][ 'elementId' ] + '/' + \
1739 hostj[ 'location' ][ 'port' ]
1740 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
1741 return main.TRUE
Jeremyd9e4eb12016-04-13 12:09:06 -07001742 except ValueError:
1743 main.log.error( "ValueError while populating hostsData" )
1744 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001745 except KeyError:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001746 main.log.error( "KeyError while populating hostsData" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001747 return main.FALSE
Jeremyd9e4eb12016-04-13 12:09:06 -07001748 except IndexError:
1749 main.log.error( "IndexError while populating hostsData" )
1750 return main.FALSE
1751 except TypeError:
1752 main.log.error( "TypeError while populating hostsData" )
1753 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001754
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001755def checkTopology( main, expectedLink ):
1756 statusResult = main.TRUE
1757 # Check onos topology
1758 main.log.info( itemName + ": Checking ONOS topology " )
1759
1760 for i in range( main.numCtrls ):
Flavio Castro82ee2f62016-06-07 15:04:12 -07001761 statusResult = main.CLIs[ i ].checkStatus( main.numSwitch,
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001762 expectedLink )\
1763 and statusResult
1764 if not statusResult:
1765 main.log.error( itemName + ": Topology mismatch" )
1766 else:
1767 main.log.info( itemName + ": Topology match" )
1768 return statusResult
1769
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001770def checkIntentState( main, intentsId, bandwidthFlag=False ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001771 """
1772 This function will check intent state to make sure all the intents
1773 are in INSTALLED state
1774 """
1775
1776 intentResult = main.TRUE
1777 results = []
1778
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001779 for i in range( main.numCtrls ):
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001780 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId, bandwidthFlag=bandwidthFlag )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001781 results.append( tempResult )
1782
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001783 if all( result == main.TRUE for result in results ):
1784 main.log.info( itemName + ": Intents are installed correctly" )
1785 else:
Shreyaca8990f2017-03-16 11:43:11 -07001786 main.log.warn( "Intents are not installed correctly" )
1787 intentResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001788
1789 return intentResult
1790
1791def checkFlowsState( main ):
1792
1793 main.log.info( itemName + ": Check flows state" )
Jeremy Songsterff553672016-05-12 17:06:23 -07001794 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState( isPENDING=False )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001795 return checkFlowsResult
1796
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001797def link( main, sw1, sw2, option ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001798
1799 # link down
alison52b25892016-09-19 10:53:48 -07001800 main.log.info( itemName + ": Bring link " + option + " between " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001801 sw1 + " and " + sw2 )
1802 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
1803 return linkResult
1804
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001805def scapyCheckConnection( main, senders, recipients, vlanId=None, useTCP=False, packet=None, packetFilter=None, expectFailure=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001806 """
1807 Checks the connectivity between all given sender hosts and all given recipient hosts
1808 Packet may be specified. Defaults to Ether/IP packet
1809 Packet Filter may be specified. Defaults to Ether/IP from current sender MAC
1810 Todo: Optional packet and packet filter attributes for sender and recipients
1811 Expect Failure when the sender and recipient are not supposed to have connectivity
1812 Timeout of 1 second, returns main.TRUE if the filter is not triggered and kills the filter
1813
1814 """
1815 connectionsFunctional = main.TRUE
1816
1817 if not packetFilter:
1818 packetFilter = 'ether host {}'
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001819 if useTCP:
1820 packetFilter += ' ip proto \\tcp tcp port {}'.format(main.params[ 'SDNIP' ][ 'dstPort' ])
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001821 if expectFailure:
1822 timeout = 1
1823 else:
1824 timeout = 10
1825
1826 for sender in senders:
1827 try:
1828 senderComp = getattr( main, sender )
1829 except AttributeError:
1830 main.log.error( "main has no attribute {}".format( sender ) )
1831 connectionsFunctional = main.FALSE
1832 continue
1833
1834 for recipient in recipients:
1835 # Do not send packets to self since recipient CLI will already be busy
1836 if recipient == sender:
1837 continue
1838 try:
1839 recipientComp = getattr( main, recipient )
1840 except AttributeError:
1841 main.log.error( "main has no attribute {}".format( recipient ) )
1842 connectionsFunctional = main.FALSE
1843 continue
1844
Jeremy Songster832f9e92016-05-05 14:30:49 -07001845 if vlanId:
1846 recipientComp.startFilter( pktFilter = ( "vlan {}".format( vlanId ) + " && " + packetFilter.format( senderComp.hostMac ) ) )
1847 else:
1848 recipientComp.startFilter( pktFilter = packetFilter.format( senderComp.hostMac ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001849
1850 if not packet:
Jeremy Songster832f9e92016-05-05 14:30:49 -07001851 if vlanId:
1852 pkt = 'Ether( src="{0}", dst="{2}" )/Dot1Q(vlan={4})/IP( src="{1}", dst="{3}" )'.format(
1853 senderComp.hostMac,
1854 senderComp.hostIp,
1855 recipientComp.hostMac,
1856 recipientComp.hostIp,
1857 vlanId )
1858 else:
1859 pkt = 'Ether( src="{0}", dst="{2}" )/IP( src="{1}", dst="{3}" )'.format(
1860 senderComp.hostMac,
1861 senderComp.hostIp,
1862 recipientComp.hostMac,
1863 recipientComp.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001864 else:
1865 pkt = packet
Jeremy Songster832f9e92016-05-05 14:30:49 -07001866 if vlanId:
1867 senderComp.sendPacket( iface=( "{0}-eth0.{1}".format( sender, vlanId ) ), packet = pkt )
1868 else:
1869 senderComp.sendPacket( packet = pkt )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001870
1871 if recipientComp.checkFilter( timeout ):
1872 if expectFailure:
1873 main.log.error( "Packet from {0} successfully received by {1} when it should not have been".format( sender , recipient ) )
1874 connectionsFunctional = main.FALSE
1875 else:
1876 main.log.info( "Packet from {0} successfully received by {1}".format( sender , recipient ) )
alison52b25892016-09-19 10:53:48 -07001877 connectionsFunctional = main.TRUE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001878 else:
1879 recipientComp.killFilter()
1880 if expectFailure:
1881 main.log.info( "As expected, packet from {0} was not received by {1}".format( sender , recipient ) )
1882 else:
1883 main.log.error( "Packet from {0} was not received by {1}".format( sender , recipient ) )
1884 connectionsFunctional = main.FALSE
1885
1886 return connectionsFunctional
1887
alison52b25892016-09-19 10:53:48 -07001888
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001889def removeAllIntents( main, intentsId ):
1890 """
1891 Remove all intents in the intentsId
1892 """
1893
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001894 onosSummary = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001895 removeIntentResult = main.TRUE
1896 # Remove intents
1897 for intent in intentsId:
1898 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
1899
acsmarscfa52272015-08-06 15:21:45 -07001900 time.sleep( main.removeIntentSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001901
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001902 # If there is remianing intents then remove intents should fail
1903 for i in range( main.numCtrls ):
1904 onosSummary.append( json.loads( main.CLIs[ i ].summary() ) )
1905
1906 for summary in onosSummary:
1907 if summary.get( 'intents' ) != 0:
1908 main.log.warn( itemName + ": There are " +
1909 str( summary.get( 'intents' ) ) +
1910 " intents remaining in node " +
1911 str( summary.get( 'node' ) ) +
1912 ", failed to remove all the intents " )
1913 removeIntentResult = main.FALSE
1914
1915 if removeIntentResult:
1916 main.log.info( itemName + ": There are no more intents remaining, " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001917 "successfully removed all the intents." )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001918
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001919 return removeIntentResult
1920
1921def checkFlowsCount( main ):
1922 """
1923 Check flows count in each node
1924 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001925 flowsCount = []
1926 main.log.info( itemName + ": Checking flows count in each ONOS node" )
1927 for i in range( main.numCtrls ):
1928 summaryResult = main.CLIs[ i ].summary()
1929 if not summaryResult:
1930 main.log.error( itemName + ": There is something wrong with " +
1931 "summary command" )
1932 return main.FALSE
1933 else:
1934 summaryJson = json.loads( summaryResult )
1935 flowsCount.append( summaryJson.get( 'flows' ) )
1936
1937 if flowsCount:
1938 if all( flows==flowsCount[ 0 ] for flows in flowsCount ):
1939 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
1940 " flows in all ONOS node" )
1941 else:
1942 for i in range( main.numCtrls ):
1943 main.log.debug( itemName + ": ONOS node " + str( i ) + " has " +
kelvin-onlab6dea6e62015-07-23 13:07:26 -07001944 str( flowsCount[ i ] ) + " flows" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001945 else:
1946 main.log.error( "Checking flows count failed, check summary command" )
1947 return main.FALSE
1948
1949 return main.TRUE
1950
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001951def checkLeaderChange( leaders1, leaders2 ):
acsmarse6b410f2015-07-17 14:39:34 -07001952 """
1953 Checks for a change in intent partition leadership.
1954
1955 Takes the output of leaders -c in json string format before and after
1956 a potential change as input
1957
1958 Returns main.TRUE if no mismatches are detected
1959 Returns main.FALSE if there is a mismatch or on error loading the input
1960 """
1961 try:
1962 leaders1 = json.loads( leaders1 )
1963 leaders2 = json.loads( leaders2 )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001964 except( AttributeError, TypeError ):
acsmarse6b410f2015-07-17 14:39:34 -07001965 main.log.exception( self.name + ": Object not as expected" )
1966 return main.FALSE
1967 except Exception:
1968 main.log.exception( self.name + ": Uncaught exception!" )
1969 main.cleanup()
1970 main.exit()
1971 main.log.info( "Checking Intent Paritions for Change in Leadership" )
1972 mismatch = False
1973 for dict1 in leaders1:
1974 if "intent" in dict1.get( "topic", [] ):
1975 for dict2 in leaders2:
1976 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \
1977 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
1978 mismatch = True
1979 main.log.error( "{0} changed leader from {1} to {2}".\
1980 format( dict1.get( "topic", "no-topic" ),\
1981 dict1.get( "leader", "no-leader" ),\
1982 dict2.get( "leader", "no-leader" ) ) )
1983 if mismatch:
1984 return main.FALSE
1985 else:
1986 return main.TRUE
kelvin-onlab016dce22015-08-10 09:54:11 -07001987
1988def report( main ):
1989 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001990 Report errors/warnings/exceptions
kelvin-onlab016dce22015-08-10 09:54:11 -07001991 """
kelvin-onlab016dce22015-08-10 09:54:11 -07001992 main.ONOSbench.logReport( main.ONOSip[ 0 ],
1993 [ "INFO",
1994 "FOLLOWER",
1995 "WARN",
1996 "flow",
1997 "ERROR",
1998 "Except" ],
1999 "s" )
2000
2001 main.log.info( "ERROR report: \n" )
2002 for i in range( main.numCtrls ):
2003 main.ONOSbench.logReport( main.ONOSip[ i ],
2004 [ "ERROR" ],
2005 "d" )
2006
2007 main.log.info( "EXCEPTIONS report: \n" )
2008 for i in range( main.numCtrls ):
2009 main.ONOSbench.logReport( main.ONOSip[ i ],
2010 [ "Except" ],
2011 "d" )
2012
2013 main.log.info( "WARNING report: \n" )
2014 for i in range( main.numCtrls ):
2015 main.ONOSbench.logReport( main.ONOSip[ i ],
2016 [ "WARN" ],
2017 "d" )
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002018
2019def flowDuration( main ):
2020 """
2021 Check age of flows to see if flows are being overwritten
2022 """
2023 import time
2024 main.log.info( "Getting current flow durations" )
2025 flowsJson1 = main.CLIs[ 0 ].flows( noCore=True )
2026 try:
2027 flowsJson1 = json.loads( flowsJson1 )
2028 except ValueError:
2029 main.log.error( "Unable to read flows" )
2030 return main.FALSE
2031 flowLife = []
2032 waitFlowLife = []
2033 for device in flowsJson1:
2034 if device.get( 'flowcount', 0 ) > 0:
2035 for i in range( device[ 'flowCount' ] ):
2036 flowLife.append( device[ 'flows' ][ i ][ 'life' ] )
2037 main.log.info( "Sleeping for {} seconds".format( main.flowDurationSleep ) )
2038 time.sleep( main.flowDurationSleep )
2039 main.log.info( "Getting new flow durations" )
2040 flowsJson2 = main.CLIs[ 0 ].flows( noCore=True )
2041 try:
2042 flowsJson2 = json.loads( flowsJson2 )
2043 except ValueError:
2044 main.log.error( "Unable to read flows" )
2045 return main.FALSE
2046 for device in flowsJson2:
2047 if device.get( 'flowcount', 0 ) > 0:
2048 for i in range( device[ 'flowCount' ] ):
2049 waitFlowLife.append( device[ 'flows' ][ i ][ 'life' ] )
2050 main.log.info( "Determining whether flows where overwritten" )
2051 if len( flowLife ) == len( waitFlowLife ):
alison52b25892016-09-19 10:53:48 -07002052 for i in range( len( flowLife ) ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002053 if waitFlowLife[ i ] - flowLife[ i ] < main.flowDurationSleep:
2054 return main.FALSE
2055 else:
2056 return main.FALSE
2057 return main.TRUE
alison52b25892016-09-19 10:53:48 -07002058
2059
2060def EncapsulatedIntentCheck( main, tag="" ):
2061 """
2062 Check encapsulated intents
2063 tag: encapsulation tag (e.g. VLAN, MPLS)
2064
2065 Getting added flows
2066 Check tags on each flows
2067 If each direction has push or pop, passed
2068 else failed
2069
2070 """
2071 import json
2072 HostJson = []
2073 Jflows = main.CLIs[ 0 ].flows( noCore=True )
2074 try:
2075 Jflows = json.loads( Jflows )
2076 except ValueError:
2077 main.log.error( "Unable to read flows" )
2078 return main.FALSE
2079
2080 for flow in Jflows:
2081 if len(flow[ "flows" ]) != 0:
2082 HostJson.append( flow[ "flows" ] )
2083
2084 totalflows = len( HostJson[ 0 ])
2085
2086 pop = 0
2087 push = 0
2088
2089 PopTag = tag + "_POP"
2090 PushTag = tag + "_PUSH"
2091
2092 for EachHostJson in HostJson:
2093 for i in range( totalflows ):
2094 if EachHostJson[ i ][ "treatment" ][ "instructions" ][ 0 ][ "subtype" ] == PopTag:
2095 pop += 1
2096 elif EachHostJson[ i ][ "treatment" ][ "instructions" ][ 0 ][ "subtype" ] == PushTag:
2097 push += 1
2098
2099 if pop == totalflows and push == totalflows:
2100 return main.TRUE
2101 else:
alisonda157272016-12-22 01:13:21 -08002102 return main.FALSE
2103
2104def ProtectedIntentCheck( main ):
2105 import json
2106 intent = main.CLIs[ 0 ].intents( jsonFormat=False )
2107 if "Protection" in intent:
2108 return main.TRUE
Shreyaca8990f2017-03-16 11:43:11 -07002109 return main.FALSE