blob: 0e563be176ae111f1516ce6646e047a4744ffcc2 [file] [log] [blame]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001"""
2 Wrapper functions for FuncIntent
3 This functions include Onosclidriver and Mininetclidriver driver functions
4 Author: kelvin@onlab.us
5"""
6import time
7import copy
8import json
9
10def __init__( self ):
11 self.default = ''
12
Jeremy Songster1f39bf02016-01-20 17:17:25 -080013def installHostIntent( main,
Jeremy2f190ca2016-01-29 15:23:57 -080014 name,
15 host1,
16 host2,
17 onosNode=0,
18 ethType="",
19 bandwidth="",
20 lambdaAlloc=False,
21 ipProto="",
22 ipAddresses="",
23 tcp="",
24 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -070025 sw2="",
Jeremy Songsterc032f162016-08-04 17:14:49 -070026 setVlan="",
27 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -070028 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -080029 Installs a Host Intent
30
kelvin-onlab58dc39e2015-08-06 08:11:09 -070031 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -080032 Install a host intent using
33 add-host-intent
34
kelvin-onlab58dc39e2015-08-06 08:11:09 -070035 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -080036 - Fetch host data if not given
37 - Add host intent
38 - Ingress device is the first sender host
39 - Egress devices are the recipient devices
40 - Ports if defined in senders or recipients
41 - MAC address ethSrc loaded from Ingress device
42 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -070043 Required:
44 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -080045 host1 - Dictionary for host1
46 { "name":"h8", "id":"of:0000000000000005/8" }
47 host2 - Dictionary for host2
48 { "name":"h16", "id":"of:0000000000000006/8" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -070049 Optional:
50 onosNode - ONOS node to install the intents in main.CLIs[ ]
51 0 by default so that it will always use the first
52 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -070053 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -070054 bandwidth - Bandwidth capacity
55 lambdaAlloc - Allocate lambda, defaults to False
56 ipProto - IP protocol
Jeremy Songster1f39bf02016-01-20 17:17:25 -080057 tcp - TCP ports in the same order as the hosts in hostNames
58 """
59
60 assert main, "There is no main variable"
61 assert host1, "You must specify host1"
62 assert host2, "You must specify host2"
63
64 global itemName # The name of this run. Used for logs.
65 itemName = name
66 onosNode = int( onosNode )
67
68 main.log.info( itemName + ": Adding single point to multi point intents" )
Jeremyd9e4eb12016-04-13 12:09:06 -070069 try:
70 if not host1.get( "id" ):
71 main.log.warn( "ID not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
72 main.log.debug( main.hostsData.get( host1.get( "name" ) ) )
73 host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "id" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -080074
Jeremyd9e4eb12016-04-13 12:09:06 -070075 if not host2.get( "id" ):
76 main.log.warn( "ID not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
77 host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "id" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -080078
Jeremyd9e4eb12016-04-13 12:09:06 -070079 # Adding point intent
Jeremy Songster832f9e92016-05-05 14:30:49 -070080 vlanId = host1.get( "vlan" )
Jeremyd9e4eb12016-04-13 12:09:06 -070081 intentId = main.CLIs[ onosNode ].addHostIntent( hostIdOne=host1.get( "id" ),
Jeremy Songster832f9e92016-05-05 14:30:49 -070082 hostIdTwo=host2.get( "id" ),
Jeremy Songsterff553672016-05-12 17:06:23 -070083 vlanId=vlanId,
Jeremy Songsterc032f162016-08-04 17:14:49 -070084 setVlan=setVlan,
85 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -070086 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -070087 errorMsg = "There was a problem loading the hosts data."
88 if intentId:
89 errorMsg += " There was a problem installing host to host intent."
90 main.log.error( errorMsg )
91 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -080092
93 # Check intents state
94 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
95 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -070096 main.assertReturnString += 'Install Intent State Passed\n'
97 if flowDuration( main ):
98 main.assertReturnString += 'Flow duration check Passed\n'
99 return intentId
100 else:
101 main.assertReturnString += 'Flow duration check failed\n'
102 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800103 else:
Jeremy2f190ca2016-01-29 15:23:57 -0800104 main.log.error( "Host Intent did not install correctly" )
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700105 main.assertReturnString += 'Install Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800106 return main.FALSE
107
108def testHostIntent( main,
109 name,
110 intentId,
111 host1,
112 host2,
113 onosNode=0,
114 sw1="s5",
115 sw2="s2",
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700116 expectedLink=0 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800117 """
118 Test a Host Intent
119
120 Description:
121 Test a host intent of given ID between given hosts
122
123 Steps:
124 - Fetch host data if not given
125 - Check Intent State
126 - Check Flow State
127 - Check Connectivity
128 - Check Lack of Connectivity Between Hosts not in the Intent
129 - Reroute
130 - Take Expected Link Down
131 - Check Intent State
132 - Check Flow State
133 - Check Topology
134 - Check Connectivity
135 - Bring Expected Link Up
136 - Check Intent State
137 - Check Flow State
138 - Check Topology
139 - Check Connectivity
140 - Remove Topology
141
142 Required:
143 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
144 intentId - intent ID to be tested ( and removed )
145 host1 - Dictionary for host1
146 { "name":"h8", "id":"of:0000000000000005/8" }
147 host2 - Dictionary for host2
148 { "name":"h16", "id":"of:0000000000000006/8" }
149 Optional:
150 onosNode - ONOS node to install the intents in main.CLIs[ ]
151 0 by default so that it will always use the first
152 ONOS node
153 sw1 - First switch to bring down & up for rerouting purpose
154 sw2 - Second switch to bring down & up for rerouting purpose
155 expectedLink - Expected link when the switches are down, it should
156 be two links lower than the links before the two
157 switches are down
158
159 """
160
161 # Parameter Validity Check
162 assert main, "There is no main variable"
163 assert host1, "You must specify host1"
164 assert host2, "You must specify host2"
165
166 global itemName
167 itemName = name
168 tempHostsData = {}
169 onosNode = int( onosNode )
170
Jeremy2f190ca2016-01-29 15:23:57 -0800171 main.log.info( itemName + ": Testing Host Intent" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800172
Jeremyd9e4eb12016-04-13 12:09:06 -0700173 try:
174 if not host1.get( "id" ):
175 main.log.warn( "Id not given for host1 {0}. Loading from main.hostData".format( host1.get( "name" ) ) )
176 host1[ "id" ] = main.hostsData.get( host1.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800177
Jeremyd9e4eb12016-04-13 12:09:06 -0700178 if not host2.get( "id" ):
179 main.log.warn( "Id not given for host2 {0}. Loading from main.hostData".format( host2.get( "name" ) ) )
180 host2[ "id" ] = main.hostsData.get( host2.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800181
Jeremyd9e4eb12016-04-13 12:09:06 -0700182 senderNames = [ host1.get( "name" ), host2.get( "name" ) ]
183 recipientNames = [ host1.get( "name" ), host2.get( "name" ) ]
Jeremy Songster832f9e92016-05-05 14:30:49 -0700184 vlanId = host1.get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800185
Jeremyd9e4eb12016-04-13 12:09:06 -0700186 testResult = main.TRUE
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700187 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700188 main.log.error( "There was a problem loading the hosts data." )
189 return main.FALSE
190
191 main.log.info( itemName + ": Testing Host to Host intents" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800192
193 # Check intent state
194 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
195 main.assertReturnString += 'Initial Intent State Passed\n'
196 else:
197 main.assertReturnString += 'Initial Intent State Failed\n'
198 testResult = main.FALSE
199
200 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -0700201 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800202 main.assertReturnString += 'Initial Flow State Passed\n'
203 else:
204 main.assertReturnString += 'Intial Flow State Failed\n'
205 testResult = main.FALSE
206
207 # Check Connectivity
Jeremy Songster832f9e92016-05-05 14:30:49 -0700208 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800209 main.assertReturnString += 'Initial Ping Passed\n'
210 else:
211 main.assertReturnString += 'Initial Ping Failed\n'
212 testResult = main.FALSE
213
214 # Test rerouting if these variables exist
215 if sw1 and sw2 and expectedLink:
216 # Take link down
217 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
218 main.assertReturnString += 'Link Down Passed\n'
219 else:
220 main.assertReturnString += 'Link Down Failed\n'
221 testResult = main.FALSE
222
223 # Check intent state
224 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
225 main.assertReturnString += 'Link Down Intent State Passed\n'
226 else:
227 main.assertReturnString += 'Link Down Intent State Failed\n'
228 testResult = main.FALSE
229
230 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -0700231 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800232 main.assertReturnString += 'Link Down Flow State Passed\n'
233 else:
234 main.assertReturnString += 'Link Down Flow State Failed\n'
235 testResult = main.FALSE
236
237 # Check OnosTopology
238 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink ) ):
239 main.assertReturnString += 'Link Down Topology State Passed\n'
240 else:
241 main.assertReturnString += 'Link Down Topology State Failed\n'
242 testResult = main.FALSE
243
244 # Check Connection
Jeremy Songster832f9e92016-05-05 14:30:49 -0700245 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800246 main.assertReturnString += 'Link Down Pingall Passed\n'
247 else:
248 main.assertReturnString += 'Link Down Pingall Failed\n'
249 testResult = main.FALSE
250
251 # Bring link up
252 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
253 main.assertReturnString += 'Link Up Passed\n'
254 else:
255 main.assertReturnString += 'Link Up Failed\n'
256 testResult = main.FALSE
257
258 # Wait for reroute
259 time.sleep( main.rerouteSleep )
260
261 # Check Intents
262 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
263 main.assertReturnString += 'Link Up Intent State Passed\n'
264 else:
265 main.assertReturnString += 'Link Up Intent State Failed\n'
266 testResult = main.FALSE
267
268 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -0700269 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800270 main.assertReturnString += 'Link Up Flow State Passed\n'
271 else:
272 main.assertReturnString += 'Link Up Flow State Failed\n'
273 testResult = main.FALSE
274
275 # Check OnosTopology
276 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
277 main.assertReturnString += 'Link Up Topology State Passed\n'
278 else:
279 main.assertReturnString += 'Link Up Topology State Failed\n'
280 testResult = main.FALSE
281
282 # Check Connection
Jeremy Songster832f9e92016-05-05 14:30:49 -0700283 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800284 main.assertReturnString += 'Link Up Pingall Passed\n'
285 else:
286 main.assertReturnString += 'Link Up Pingall Failed\n'
287 testResult = main.FALSE
288
289 # Remove all intents
290 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ):
291 main.assertReturnString += 'Remove Intents Passed'
292 else:
293 main.assertReturnString += 'Remove Intents Failed'
294 testResult = main.FALSE
295
296 return testResult
297
298def installPointIntent( main,
299 name,
300 senders,
301 recipients,
302 onosNode=0,
303 ethType="",
304 bandwidth="",
305 lambdaAlloc=False,
306 ipProto="",
307 ipSrc="",
308 ipDst="",
309 tcpSrc="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700310 tcpDst="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700311 setVlan="",
312 encap="" ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800313 """
314 Installs a Single to Single Point Intent
315
316 Description:
317 Install a single to single point intent
318
319 Steps:
320 - Fetch host data if not given
321 - Add point intent
322 - Ingress device is the first sender device
323 - Egress device is the first recipient device
324 - Ports if defined in senders or recipients
325 - MAC address ethSrc loaded from Ingress device
326 - Check intent state with retry
327 Required:
328 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
329 senders - List of host dictionaries i.e.
330 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
331 recipients - List of host dictionaries i.e.
332 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
333 Optional:
334 onosNode - ONOS node to install the intents in main.CLIs[ ]
335 0 by default so that it will always use the first
336 ONOS node
337 ethType - Ethernet type eg. IPV4, IPV6
338 bandwidth - Bandwidth capacity
339 lambdaAlloc - Allocate lambda, defaults to False
340 ipProto - IP protocol
341 tcp - TCP ports in the same order as the hosts in hostNames
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700342 sw1 - First switch to bring down & up for rerouting purpose
343 sw2 - Second switch to bring down & up for rerouting purpose
344 expectedLink - Expected link when the switches are down, it should
345 be two links lower than the links before the two
346 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700347 """
348
349 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800350 assert senders, "You must specify a sender"
351 assert recipients, "You must specify a recipient"
352 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700353
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800354 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700355 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700356 onosNode = int( onosNode )
357
Jeremy6f000c62016-02-25 17:02:28 -0800358 main.log.info( itemName + ": Adding point to point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700359
Jeremyd9e4eb12016-04-13 12:09:06 -0700360 try:
361 for sender in senders:
362 if not sender.get( "device" ):
363 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
364 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800365
Jeremyd9e4eb12016-04-13 12:09:06 -0700366 for recipient in recipients:
367 if not recipient.get( "device" ):
368 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
369 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800370
371
Jeremyd9e4eb12016-04-13 12:09:06 -0700372 ingressDevice = senders[ 0 ].get( "device" )
373 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800374
Jeremyd9e4eb12016-04-13 12:09:06 -0700375 portIngress = senders[ 0 ].get( "port", "" )
376 portEgress = recipients[ 0 ].get( "port", "" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800377
Jeremyd9e4eb12016-04-13 12:09:06 -0700378 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800379
Jeremyd9e4eb12016-04-13 12:09:06 -0700380 ipSrc = senders[ 0 ].get( "ip" )
381 ipDst = recipients[ 0 ].get( "ip" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800382
Jeremy Songster832f9e92016-05-05 14:30:49 -0700383 vlanId = senders[ 0 ].get( "vlan" )
384
Jeremyd9e4eb12016-04-13 12:09:06 -0700385 # Adding point intent
386 intentId = main.CLIs[ onosNode ].addPointIntent(
387 ingressDevice=ingressDevice,
388 egressDevice=egressDevice,
389 portIngress=portIngress,
390 portEgress=portEgress,
391 ethType=ethType,
392 ethDst=dstMac,
393 bandwidth=bandwidth,
394 lambdaAlloc=lambdaAlloc,
395 ipProto=ipProto,
396 ipSrc=ipSrc,
397 ipDst=ipDst,
398 tcpSrc=tcpSrc,
Jeremy Songster832f9e92016-05-05 14:30:49 -0700399 tcpDst=tcpDst,
Jeremy Songsterff553672016-05-12 17:06:23 -0700400 vlanId=vlanId,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700401 setVlan=setVlan,
402 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700403 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700404 errorMsg = "There was a problem loading the hosts data."
405 if intentId:
406 errorMsg += " There was a problem installing Point to Point intent."
407 main.log.error( errorMsg )
408 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700409
410 # Check intents state
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700411 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
412 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
413 main.assertReturnString += 'Install Intent State Passed\n'
414 if flowDuration( main ):
415 main.assertReturnString += 'Flow duration check Passed\n'
416 return intentId
417 else:
418 main.assertReturnString += 'Flow duration check failed\n'
419 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -0700420 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800421 main.log.error( "Point Intent did not install correctly" )
422 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700423
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700424def pointIntentTcp( main,
425 name,
426 host1,
427 host2,
428 onosNode=0,
429 deviceId1="",
430 deviceId2="",
431 port1="",
432 port2="",
433 ethType="",
434 mac1="",
435 mac2="",
436 bandwidth="",
437 lambdaAlloc=False,
438 ipProto="",
439 ip1="",
440 ip2="",
441 tcp1="",
442 tcp2="",
443 sw1="",
444 sw2="",
445 expectedLink=0 ):
446
447 """
448 Description:
449 Verify add-point-intent only for TCP
450 Steps:
451 - Get device ids | ports
452 - Add point intents
453 - Check intents
454 - Verify flows
455 - Ping hosts
456 - Reroute
457 - Link down
458 - Verify flows
459 - Check topology
460 - Ping hosts
461 - Link up
462 - Verify flows
463 - Check topology
464 - Ping hosts
465 - Remove intents
466 Required:
467 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
468 host1 - Name of first host
469 host2 - Name of second host
470 Optional:
471 onosNode - ONOS node to install the intents in main.CLIs[ ]
472 0 by default so that it will always use the first
473 ONOS node
474 deviceId1 - ONOS device id of the first switch, the same as the
475 location of the first host eg. of:0000000000000001/1,
476 located at device 1 port 1
477 deviceId2 - ONOS device id of the second switch
478 port1 - The port number where the first host is attached
479 port2 - The port number where the second host is attached
480 ethType - Ethernet type eg. IPV4, IPV6
481 mac1 - Mac address of first host
482 mac2 - Mac address of the second host
483 bandwidth - Bandwidth capacity
484 lambdaAlloc - Allocate lambda, defaults to False
485 ipProto - IP protocol
486 ip1 - IP address of first host
487 ip2 - IP address of second host
488 tcp1 - TCP port of first host
489 tcp2 - TCP port of second host
490 sw1 - First switch to bring down & up for rerouting purpose
491 sw2 - Second switch to bring down & up for rerouting purpose
492 expectedLink - Expected link when the switches are down, it should
493 be two links lower than the links before the two
494 switches are down
495 """
496
497 assert main, "There is no main variable"
498 assert name, "variable name is empty"
499 assert host1 and host2, "You must specify hosts"
500
501 global itemName
502 itemName = name
503 host1 = host1
504 host2 = host2
505 hostNames = [ host1, host2 ]
506 intentsId = []
507
508 iperfResult = main.TRUE
509 intentResult = main.TRUE
510 removeIntentResult = main.TRUE
511 flowResult = main.TRUE
512 topoResult = main.TRUE
513 linkDownResult = main.TRUE
514 linkUpResult = main.TRUE
515 onosNode = int( onosNode )
516
517 # Adding bidirectional point intents
518 main.log.info( itemName + ": Adding point intents" )
519 intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
520 egressDevice=deviceId2,
521 portIngress=port1,
522 portEgress=port2,
523 ethType=ethType,
524 ethSrc=mac1,
525 ethDst=mac2,
526 bandwidth=bandwidth,
527 lambdaAlloc=lambdaAlloc,
528 ipProto=ipProto,
529 ipSrc=ip1,
530 ipDst=ip2,
531 tcpSrc=tcp1,
532 tcpDst="" )
533
534 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
535 egressDevice=deviceId1,
536 portIngress=port2,
537 portEgress=port1,
538 ethType=ethType,
539 ethSrc=mac2,
540 ethDst=mac1,
541 bandwidth=bandwidth,
542 lambdaAlloc=lambdaAlloc,
543 ipProto=ipProto,
544 ipSrc=ip2,
545 ipDst=ip1,
546 tcpSrc=tcp2,
547 tcpDst="" )
548
549 intent3 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
550 egressDevice=deviceId2,
551 portIngress=port1,
552 portEgress=port2,
553 ethType=ethType,
554 ethSrc=mac1,
555 ethDst=mac2,
556 bandwidth=bandwidth,
557 lambdaAlloc=lambdaAlloc,
558 ipProto=ipProto,
559 ipSrc=ip1,
560 ipDst=ip2,
561 tcpSrc="",
562 tcpDst=tcp2 )
563
564 intent4 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
565 egressDevice=deviceId1,
566 portIngress=port2,
567 portEgress=port1,
568 ethType=ethType,
569 ethSrc=mac2,
570 ethDst=mac1,
571 bandwidth=bandwidth,
572 lambdaAlloc=lambdaAlloc,
573 ipProto=ipProto,
574 ipSrc=ip2,
575 ipDst=ip1,
576 tcpSrc="",
577 tcpDst=tcp1 )
578 intentsId.append( intent1 )
579 intentsId.append( intent2 )
580 intentsId.append( intent3 )
581 intentsId.append( intent4 )
582
583 # Check intents state
584 time.sleep( main.checkIntentSleep )
585 intentResult = checkIntentState( main, intentsId )
586 # Check flows count in each node
587 checkFlowsCount( main )
588
589 # Check intents state again if first check fails...
590 if not intentResult:
591 intentResult = checkIntentState( main, intentsId )
592
593 # Check flows count in each node
594 checkFlowsCount( main )
595
596 # Verify flows
597 checkFlowsState( main )
598
599 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700600 iperfTemp = main.Mininet1.iperftcp( host1, host2 ,10 )
acsmarsd4862d12015-10-06 17:57:34 -0700601 iperfResult = iperfResult and iperfTemp
602 if iperfTemp:
603 main.assertReturnString += 'Initial Iperf Passed\n'
604 else:
605 main.assertReturnString += 'Initial Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700606
607 # Test rerouting if these variables exist
608 if sw1 and sw2 and expectedLink:
609 # link down
610 linkDownResult = link( main, sw1, sw2, "down" )
acsmarsd4862d12015-10-06 17:57:34 -0700611
612 if linkDownResult:
613 main.assertReturnString += 'Link Down Passed\n'
614 else:
615 main.assertReturnString += 'Link Down Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700616
617 # Check flows count in each node
618 checkFlowsCount( main )
619 # Verify flows
620 checkFlowsState( main )
621
622 # Check OnosTopology
623 topoResult = checkTopology( main, expectedLink )
acsmarsd4862d12015-10-06 17:57:34 -0700624 if topoResult:
625 main.assertReturnString += 'Link Down Topology State Passed\n'
626 else:
627 main.assertReturnString += 'Link Down Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700628
629 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700630 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700631 iperfResult = iperfResult and iperfTemp
632 if iperfTemp:
633 main.assertReturnString += 'Link Down Iperf Passed\n'
634 else:
635 main.assertReturnString += 'Link Down Iperf Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700636
acsmarsd4862d12015-10-06 17:57:34 -0700637 # Check intent state
638 intentTemp = checkIntentState( main, intentsId )
639 intentResult = intentResult and intentTemp
640 if intentTemp:
641 main.assertReturnString += 'Link Down Intent State Passed\n'
642 else:
643 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700644
645 # Checks ONOS state in link down
646 if linkDownResult and topoResult and iperfResult and intentResult:
647 main.log.info( itemName + ": Successfully brought link down" )
648 else:
649 main.log.error( itemName + ": Failed to bring link down" )
650
651 # link up
652 linkUpResult = link( main, sw1, sw2, "up" )
acsmarsd4862d12015-10-06 17:57:34 -0700653 if linkUpTemp:
654 main.assertReturnString += 'Link Up Passed\n'
655 else:
656 main.assertReturnString += 'Link Up Failed\n'
657
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700658 time.sleep( main.rerouteSleep )
659
660 # Check flows count in each node
661 checkFlowsCount( main )
662 # Verify flows
663 checkFlowsState( main )
664
665 # Check OnosTopology
666 topoResult = checkTopology( main, main.numLinks )
667
acsmarsd4862d12015-10-06 17:57:34 -0700668 if topoResult:
669 main.assertReturnString += 'Link Up Topology State Passed\n'
670 else:
671 main.assertReturnString += 'Link Up Topology State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700672
acsmarsd4862d12015-10-06 17:57:34 -0700673 # Run iperf to both host
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700674 iperfTemp = main.Mininet1.iperftcp( host1, host2, 10 )
acsmarsd4862d12015-10-06 17:57:34 -0700675 iperfResult = iperfResult and iperfTemp
676 if iperfTemp:
677 main.assertReturnString += 'Link Up Iperf Passed\n'
678 else:
679 main.assertReturnString += 'Link Up Iperf Failed\n'
680
681 # Check intent state
682 intentTemp = checkIntentState( main, intentsId )
683 intentResult = intentResult and intentTemp
684 if intentTemp:
685 main.assertReturnString += 'Link Down Intent State Passed\n'
686 else:
687 main.assertReturnString += 'Link Down Intent State Failed\n'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700688
689 # Checks ONOS state in link up
690 if linkUpResult and topoResult and iperfResult and intentResult:
691 main.log.info( itemName + ": Successfully brought link back up" )
692 else:
693 main.log.error( itemName + ": Failed to bring link back up" )
694
695 # Remove all intents
696 removeIntentResult = removeAllIntents( main, intentsId )
acsmarsd4862d12015-10-06 17:57:34 -0700697 if removeIntentResult:
698 main.assertReturnString += 'Remove Intents Passed'
699 else:
700 main.assertReturnString += 'Remove Intents Failed'
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700701
702 stepResult = iperfResult and linkDownResult and linkUpResult \
703 and intentResult and removeIntentResult
704
705 return stepResult
706
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800707def installSingleToMultiIntent( main,
708 name,
709 senders,
710 recipients,
711 onosNode=0,
712 ethType="",
713 bandwidth="",
714 lambdaAlloc=False,
715 ipProto="",
716 ipAddresses="",
717 tcp="",
718 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700719 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -0700720 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700721 partial=False,
722 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700723 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800724 Installs a Single to Multi Point Intent
725
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700726 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800727 Install a single to multi point intent using
728 add-single-to-multi-intent
729
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700730 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800731 - Fetch host data if not given
732 - Add single to multi intent
733 - Ingress device is the first sender host
734 - Egress devices are the recipient devices
735 - Ports if defined in senders or recipients
736 - MAC address ethSrc loaded from Ingress device
737 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700738 Required:
739 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800740 senders - List of host dictionaries i.e.
741 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
742 recipients - List of host dictionaries i.e.
743 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700744 Optional:
745 onosNode - ONOS node to install the intents in main.CLIs[ ]
746 0 by default so that it will always use the first
747 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700748 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700749 bandwidth - Bandwidth capacity
750 lambdaAlloc - Allocate lambda, defaults to False
751 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700752 tcp - TCP ports in the same order as the hosts in hostNames
753 sw1 - First switch to bring down & up for rerouting purpose
754 sw2 - Second switch to bring down & up for rerouting purpose
755 expectedLink - Expected link when the switches are down, it should
756 be two links lower than the links before the two
757 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700758 """
759
760 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800761 assert senders, "You must specify a sender"
762 assert recipients, "You must specify a recipient"
763 # Assert devices or main.hostsData, "You must specify devices"
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700764
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800765 global itemName # The name of this run. Used for logs.
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700766 itemName = name
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700767 onosNode = int( onosNode )
768
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700769 main.log.info( itemName + ": Adding single point to multi point intents" )
770
Jeremyd9e4eb12016-04-13 12:09:06 -0700771 try:
772 for sender in senders:
773 if not sender.get( "device" ):
774 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
775 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700776
Jeremyd9e4eb12016-04-13 12:09:06 -0700777 for recipient in recipients:
778 if not recipient.get( "device" ):
779 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
780 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700781
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700782
Jeremyd9e4eb12016-04-13 12:09:06 -0700783 ingressDevice = senders[ 0 ].get( "device" )
784 egressDeviceList = [ x.get( "device" ) for x in recipients if x.get( "device" ) ]
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800785
Jeremyd9e4eb12016-04-13 12:09:06 -0700786 portIngress = senders[ 0 ].get( "port", "" )
787 portEgressList = [ x.get( "port" ) for x in recipients if x.get( "port" ) ]
788 if not portEgressList:
789 portEgressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800790
Jeremyd9e4eb12016-04-13 12:09:06 -0700791 srcMac = senders[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700792 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800793
Jeremyd9e4eb12016-04-13 12:09:06 -0700794 # Adding point intent
795 intentId = main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
796 ingressDevice=ingressDevice,
797 egressDeviceList=egressDeviceList,
798 portIngress=portIngress,
799 portEgressList=portEgressList,
800 ethType=ethType,
801 ethSrc=srcMac,
802 bandwidth=bandwidth,
803 lambdaAlloc=lambdaAlloc,
804 ipProto=ipProto,
805 ipSrc="",
806 ipDst="",
807 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -0700808 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700809 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -0700810 setVlan=setVlan,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700811 partial=partial,
812 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700813 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700814 errorMsg = "There was a problem loading the hosts data."
815 if intentId:
816 errorMsg += " There was a problem installing Singlepoint to Multipoint intent."
817 main.log.error( errorMsg )
818 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700819
820 # Check intents state
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700821 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
822 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
823 main.assertReturnString += 'Install Intent State Passed\n'
824 if flowDuration( main ):
825 main.assertReturnString += 'Flow duration check Passed\n'
826 return intentId
827 else:
828 main.assertReturnString += 'Flow duration check failed\n'
829 return main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -0700830 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800831 main.log.error( "Single to Multi Intent did not install correctly" )
832 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700833
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800834def installMultiToSingleIntent( main,
835 name,
836 senders,
837 recipients,
838 onosNode=0,
839 ethType="",
840 bandwidth="",
841 lambdaAlloc=False,
842 ipProto="",
843 ipAddresses="",
844 tcp="",
845 sw1="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700846 sw2="",
Jeremy Songster9385d412016-06-02 17:57:36 -0700847 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -0700848 partial=False,
849 encap="" ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700850 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800851 Installs a Multi to Single Point Intent
852
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700853 Description:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800854 Install a multi to single point intent using
855 add-multi-to-single-intent
856
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700857 Steps:
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800858 - Fetch host data if not given
859 - Add multi to single intent
860 - Ingress devices are the senders devices
861 - Egress device is the first recipient host
862 - Ports if defined in senders or recipients
863 - MAC address ethSrc loaded from Ingress device
864 - Check intent state with retry
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700865 Required:
866 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800867 senders - List of host dictionaries i.e.
868 [ { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" } ]
869 recipients - List of host dictionaries i.e.
870 [ { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" } ]
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700871 Optional:
872 onosNode - ONOS node to install the intents in main.CLIs[ ]
873 0 by default so that it will always use the first
874 ONOS node
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700875 ethType - Ethernet type eg. IPV4, IPV6
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700876 bandwidth - Bandwidth capacity
877 lambdaAlloc - Allocate lambda, defaults to False
878 ipProto - IP protocol
kelvin-onlab58dc39e2015-08-06 08:11:09 -0700879 tcp - TCP ports in the same order as the hosts in hostNames
880 sw1 - First switch to bring down & up for rerouting purpose
881 sw2 - Second switch to bring down & up for rerouting purpose
882 expectedLink - Expected link when the switches are down, it should
883 be two links lower than the links before the two
884 switches are down
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700885 """
886
887 assert main, "There is no main variable"
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800888 assert senders, "You must specify a sender"
889 assert recipients, "You must specify a recipient"
890 # Assert devices or main.hostsData, "You must specify devices"
891
892 global itemName # The name of this run. Used for logs.
893 itemName = name
894 onosNode = int( onosNode )
895
896 main.log.info( itemName + ": Adding mutli to single point intents" )
897
Jeremyd9e4eb12016-04-13 12:09:06 -0700898 try:
899 for sender in senders:
900 if not sender.get( "device" ):
901 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
902 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800903
Jeremyd9e4eb12016-04-13 12:09:06 -0700904 for recipient in recipients:
905 if not recipient.get( "device" ):
906 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
907 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800908
Jeremyd9e4eb12016-04-13 12:09:06 -0700909 ingressDeviceList = [ x.get( "device" ) for x in senders if x.get( "device" ) ]
910 egressDevice = recipients[ 0 ].get( "device" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800911
Jeremyd9e4eb12016-04-13 12:09:06 -0700912 portIngressList = [ x.get( "port" ) for x in senders if x.get( "port" ) ]
913 portEgress = recipients[ 0 ].get( "port", "" )
914 if not portIngressList:
915 portIngressList = None
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800916
Jeremyd9e4eb12016-04-13 12:09:06 -0700917 dstMac = recipients[ 0 ].get( "mac" )
Jeremy Songster832f9e92016-05-05 14:30:49 -0700918 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800919
Jeremyd9e4eb12016-04-13 12:09:06 -0700920 # Adding point intent
921 intentId = main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
922 ingressDeviceList=ingressDeviceList,
923 egressDevice=egressDevice,
924 portIngressList=portIngressList,
925 portEgress=portEgress,
926 ethType=ethType,
927 ethDst=dstMac,
928 bandwidth=bandwidth,
929 lambdaAlloc=lambdaAlloc,
930 ipProto=ipProto,
931 ipSrc="",
932 ipDst="",
933 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -0700934 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -0700935 vlanId=vlanId,
Jeremy Songster9385d412016-06-02 17:57:36 -0700936 setVlan=setVlan,
Jeremy Songsterc032f162016-08-04 17:14:49 -0700937 partial=partial,
938 encap=encap )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700939 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -0700940 errorMsg = "There was a problem loading the hosts data."
941 if intentId:
942 errorMsg += " There was a problem installing Multipoint to Singlepoint intent."
943 main.log.error( errorMsg )
944 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800945
946 # Check intents state
Jeremy Songster306ed7a2016-07-19 10:59:07 -0700947 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
948 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
949 main.assertReturnString += 'Install Intent State Passed\n'
950 if flowDuration( main ):
951 main.assertReturnString += 'Flow duration check Passed\n'
952 return intentId
953 else:
954 main.assertReturnString += 'Flow duration check failed\n'
955 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800956 else:
957 main.log.error( "Multi to Single Intent did not install correctly" )
958 return main.FALSE
959
960def testPointIntent( main,
Jeremye0cb5eb2016-01-27 17:39:09 -0800961 name,
962 intentId,
963 senders,
964 recipients,
965 badSenders={},
966 badRecipients={},
967 onosNode=0,
968 ethType="",
969 bandwidth="",
970 lambdaAlloc=False,
971 ipProto="",
972 ipAddresses="",
973 tcp="",
974 sw1="s5",
975 sw2="s2",
Jeremy Songstere405d3d2016-05-17 11:18:57 -0700976 expectedLink=0,
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700977 useTCP=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -0800978 """
979 Test a Point Intent
980
981 Description:
982 Test a point intent
983
984 Steps:
985 - Fetch host data if not given
986 - Check Intent State
987 - Check Flow State
988 - Check Connectivity
989 - Check Lack of Connectivity Between Hosts not in the Intent
990 - Reroute
991 - Take Expected Link Down
992 - Check Intent State
993 - Check Flow State
994 - Check Topology
995 - Check Connectivity
996 - Bring Expected Link Up
997 - Check Intent State
998 - Check Flow State
999 - Check Topology
1000 - Check Connectivity
1001 - Remove Topology
1002
1003 Required:
1004 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
1005
1006 senders - List of host dictionaries i.e.
1007 { "name":"h8", "device":"of:0000000000000005/8","mac":"00:00:00:00:00:08" }
1008 recipients - List of host dictionaries i.e.
1009 { "name":"h16", "device":"of:0000000000000006/8", "mac":"00:00:00:00:00:10" }
1010 Optional:
1011 onosNode - ONOS node to install the intents in main.CLIs[ ]
1012 0 by default so that it will always use the first
1013 ONOS node
1014 ethType - Ethernet type eg. IPV4, IPV6
1015 bandwidth - Bandwidth capacity
1016 lambdaAlloc - Allocate lambda, defaults to False
1017 ipProto - IP protocol
1018 tcp - TCP ports in the same order as the hosts in hostNames
1019 sw1 - First switch to bring down & up for rerouting purpose
1020 sw2 - Second switch to bring down & up for rerouting purpose
1021 expectedLink - Expected link when the switches are down, it should
1022 be two links lower than the links before the two
1023 switches are down
1024
1025 """
1026
1027 # Parameter Validity Check
1028 assert main, "There is no main variable"
1029 assert senders, "You must specify a sender"
1030 assert recipients, "You must specify a recipient"
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001031
1032 global itemName
1033 itemName = name
1034 tempHostsData = {}
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001035 onosNode = int( onosNode )
1036
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001037 main.log.info( itemName + ": Testing Point Intent" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001038
Jeremyd9e4eb12016-04-13 12:09:06 -07001039 try:
1040 # Names for scapy
1041 senderNames = [ x.get( "name" ) for x in senders ]
1042 recipientNames = [ x.get( "name" ) for x in recipients ]
1043 badSenderNames = [ x.get( "name" ) for x in badSenders ]
1044 badRecipientNames = [ x.get( "name" ) for x in badRecipients ]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001045
Jeremyd9e4eb12016-04-13 12:09:06 -07001046 for sender in senders:
1047 if not sender.get( "device" ):
1048 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1049 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001050
Jeremyd9e4eb12016-04-13 12:09:06 -07001051 for recipient in recipients:
1052 if not recipient.get( "device" ):
1053 main.log.warn( "Device not given for recipient {0}. Loading from main.hostData".format( recipient.get( "name" ) ) )
1054 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songster832f9e92016-05-05 14:30:49 -07001055 vlanId = senders[ 0 ].get( "vlan" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001056 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001057 main.log.error( "There was a problem loading the hosts data." )
1058 return main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001059
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001060 testResult = main.TRUE
1061 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001062
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001063 # Check intent state
1064 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1065 main.assertReturnString += 'Initial Intent State Passed\n'
acsmarsd4862d12015-10-06 17:57:34 -07001066 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001067 main.assertReturnString += 'Initial Intent State Failed\n'
1068 testResult = main.FALSE
1069
1070 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -07001071 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001072 main.assertReturnString += 'Initial Flow State Passed\n'
1073 else:
1074 main.assertReturnString += 'Intial Flow State Failed\n'
1075 testResult = main.FALSE
1076
1077 # Check Connectivity
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001078 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId, useTCP ), attempts=3, sleep=5 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001079 main.assertReturnString += 'Initial Ping Passed\n'
1080 else:
1081 main.assertReturnString += 'Initial Ping Failed\n'
1082 testResult = main.FALSE
1083
1084 # Check connections that shouldn't work
1085 if badSenderNames:
1086 main.log.info( "Checking that packets from incorrect sender do not go through" )
1087 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, badSenderNames, recipientNames ), kwargs={ "expectFailure":True } ):
1088 main.assertReturnString += 'Bad Sender Ping Passed\n'
1089 else:
1090 main.assertReturnString += 'Bad Sender Ping Failed\n'
1091 testResult = main.FALSE
1092
1093 if badRecipientNames:
1094 main.log.info( "Checking that packets to incorrect recipients do not go through" )
1095 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, badRecipientNames ), kwargs={ "expectFailure":True } ):
1096 main.assertReturnString += 'Bad Recipient Ping Passed\n'
1097 else:
1098 main.assertReturnString += 'Bad Recipient Ping Failed\n'
1099 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001100
1101 # Test rerouting if these variables exist
1102 if sw1 and sw2 and expectedLink:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001103 # Take link down
1104 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001105 main.assertReturnString += 'Link Down Passed\n'
1106 else:
1107 main.assertReturnString += 'Link Down Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001108 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001109
acsmarsd4862d12015-10-06 17:57:34 -07001110 # Check intent state
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001111 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001112 main.assertReturnString += 'Link Down Intent State Passed\n'
1113 else:
1114 main.assertReturnString += 'Link Down Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001115 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001116
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001117 # Check flows count in each node
Jeremy Songsterc032f162016-08-04 17:14:49 -07001118 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=5 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=5 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001119 main.assertReturnString += 'Link Down Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001120 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001121 main.assertReturnString += 'Link Down Flow State Failed\n'
1122 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001123
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001124 # Check OnosTopology
1125 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink ) ):
1126 main.assertReturnString += 'Link Down Topology State Passed\n'
1127 else:
1128 main.assertReturnString += 'Link Down Topology State Failed\n'
1129 testResult = main.FALSE
1130
1131 # Check Connection
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001132 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001133 main.assertReturnString += 'Link Down Pingall Passed\n'
1134 else:
1135 main.assertReturnString += 'Link Down Pingall Failed\n'
1136 testResult = main.FALSE
1137
1138 # Bring link up
1139 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001140 main.assertReturnString += 'Link Up Passed\n'
1141 else:
1142 main.assertReturnString += 'Link Up Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001143 testResult = main.FALSE
acsmarsd4862d12015-10-06 17:57:34 -07001144
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001145 # Wait for reroute
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001146 time.sleep( main.rerouteSleep )
1147
acsmarsd4862d12015-10-06 17:57:34 -07001148 # Check Intents
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001149 if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
acsmarsd4862d12015-10-06 17:57:34 -07001150 main.assertReturnString += 'Link Up Intent State Passed\n'
1151 else:
1152 main.assertReturnString += 'Link Up Intent State Failed\n'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001153 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001154
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001155 # Check flows count in each node
Jeremy03dab012016-04-11 08:59:17 -07001156 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ) and utilities.retry( f=checkFlowsState, retValue=main.FALSE, args=[ main ], sleep=20, attempts=3 ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001157 main.assertReturnString += 'Link Up Flow State Passed\n'
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001158 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001159 main.assertReturnString += 'Link Up Flow State Failed\n'
1160 testResult = main.FALSE
1161
1162 # Check OnosTopology
1163 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
1164 main.assertReturnString += 'Link Up Topology State Passed\n'
1165 else:
1166 main.assertReturnString += 'Link Up Topology State Failed\n'
1167 testResult = main.FALSE
1168
1169 # Check Connection
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001170 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE, args=( main, senderNames, recipientNames, vlanId, useTCP ) ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001171 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1172 else:
1173 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1174 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001175
1176 # Remove all intents
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001177 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ):
acsmarsd4862d12015-10-06 17:57:34 -07001178 main.assertReturnString += 'Remove Intents Passed'
1179 else:
1180 main.assertReturnString += 'Remove Intents Failed'
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001181 testResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001182
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001183 return testResult
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001184
Jeremye0cb5eb2016-01-27 17:39:09 -08001185def testEndPointFail( main,
1186 name,
1187 intentId,
1188 senders,
1189 recipients,
1190 isolatedSenders,
1191 isolatedRecipients,
1192 onosNode=0,
1193 ethType="",
1194 bandwidth="",
1195 lambdaAlloc=False,
1196 ipProto="",
1197 ipAddresses="",
1198 tcp="",
1199 sw1="",
1200 sw2="",
1201 sw3="",
1202 sw4="",
1203 sw5="",
1204 expectedLink1=0,
Jeremy Songster9385d412016-06-02 17:57:36 -07001205 expectedLink2=0,
1206 partial=False ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001207 """
1208 Test Single to Multipoint Topology for Endpoint failures
1209 """
1210
1211 # Parameter Validity Check
1212 assert main, "There is no main variable"
1213 assert senders, "You must specify a sender"
1214 assert recipients, "You must specify a recipient"
1215
1216 global itemName
1217 itemName = name
1218 tempHostsData = {}
1219 onosNode = int( onosNode )
1220
1221 main.log.info( itemName + ": Testing Point Intent" )
1222
Jeremyd9e4eb12016-04-13 12:09:06 -07001223 try:
1224 # Names for scapy
1225 senderNames = [ x.get( "name" ) for x in senders ]
1226 recipientNames = [ x.get( "name" ) for x in recipients ]
1227 isolatedSenderNames = [ x.get( "name" ) for x in isolatedSenders ]
1228 isolatedRecipientNames = [ x.get( "name" ) for x in isolatedRecipients ]
1229 connectedSenderNames = [x.get("name") for x in senders if x.get("name") not in isolatedSenderNames]
1230 connectedRecipientNames = [x.get("name") for x in recipients if x.get("name") not in isolatedRecipientNames]
Jeremye0cb5eb2016-01-27 17:39:09 -08001231
Jeremyd9e4eb12016-04-13 12:09:06 -07001232 for sender in senders:
1233 if not sender.get( "device" ):
1234 main.log.warn( "Device not given for sender {0}. Loading from main.hostData".format( sender.get( "name" ) ) )
1235 sender[ "device" ] = main.hostsData.get( sender.get( "name" ) ).get( "location" )
Jeremye0cb5eb2016-01-27 17:39:09 -08001236
Jeremyd9e4eb12016-04-13 12:09:06 -07001237 for recipient in recipients:
1238 if not recipient.get( "device" ):
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001239 main.log.warn( "Device not given for recipient {0}. Loading from " +\
1240 main.hostData.format( recipient.get( "name" ) ) )
Jeremyd9e4eb12016-04-13 12:09:06 -07001241 recipient[ "device" ] = main.hostsData.get( recipient.get( "name" ) ).get( "location" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001242 except( KeyError, TypeError ):
Jeremyd9e4eb12016-04-13 12:09:06 -07001243 main.log.error( "There was a problem loading the hosts data." )
1244 return main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001245
1246 testResult = main.TRUE
1247 main.log.info( itemName + ": Adding multi point to single point intents" )
1248
1249 # Check intent state
1250 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1251 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1252 main.assertReturnString += 'Initial Intent State Passed\n'
1253 else:
1254 main.assertReturnString += 'Initial Intent State Failed\n'
1255 testResult = main.FALSE
1256
1257 # Check flows count in each node
1258 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
Jeremy Songster9385d412016-06-02 17:57:36 -07001259 args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState,
1260 retValue=main.FALSE,
1261 args=[ main ], attempts=5 ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001262 main.assertReturnString += 'Initial Flow State Passed\n'
1263 else:
1264 main.assertReturnString += 'Intial Flow State Failed\n'
1265 testResult = main.FALSE
1266
1267 # Check Connectivity
1268 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1269 args=( main, senderNames, recipientNames ) ):
1270 main.assertReturnString += 'Initial Connectivity Check Passed\n'
1271 else:
1272 main.assertReturnString += 'Initial Connectivity Check Failed\n'
1273 testResult = main.FALSE
1274
1275 # Take two links down
1276 # Take first link down
1277 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "down" ) ):
1278 main.assertReturnString += 'Link Down Passed\n'
1279 else:
1280 main.assertReturnString += 'Link Down Failed\n'
1281 testResult = main.FALSE
1282
1283 # Take second link down
1284 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw4, "down" ) ):
1285 main.assertReturnString += 'Link Down Passed\n'
1286 else:
1287 main.assertReturnString += 'Link Down Failed\n'
1288 testResult = main.FALSE
1289
1290 # Check intent state
1291 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1292 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1293 main.assertReturnString += 'Link Down Intent State Passed\n'
1294 else:
1295 main.assertReturnString += 'Link Down Intent State Failed\n'
1296 testResult = main.FALSE
1297
1298 # Check flows count in each node
1299 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1300 args=[ main ] ) and utilities.retry( f=checkFlowsState,
1301 retValue=main.FALSE, args=[ main ] ):
1302 main.assertReturnString += 'Link Down Flow State Passed\n'
1303 else:
1304 main.assertReturnString += 'Link Down Flow State Failed\n'
1305 testResult = main.FALSE
1306
1307 # Check OnosTopology
1308 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink1 ) ):
1309 main.assertReturnString += 'Link Down Topology State Passed\n'
1310 else:
1311 main.assertReturnString += 'Link Down Topology State Failed\n'
1312 testResult = main.FALSE
1313
1314 # Check Connection
1315 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1316 args=( main, senderNames, recipientNames ) ):
1317 main.assertReturnString += 'Link Down Connectivity Check Passed\n'
1318 else:
1319 main.assertReturnString += 'Link Down Connectivity Check Failed\n'
1320 testResult = main.FALSE
1321
1322 # Take a third link down to isolate one node
1323 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw5, "down" ) ):
1324 main.assertReturnString += 'Isolation link Down Passed\n'
1325 else:
1326 main.assertReturnString += 'Isolation link Down Failed\n'
1327 testResult = main.FALSE
1328
Jeremy Songster9385d412016-06-02 17:57:36 -07001329 if partial:
1330 # Check intent state
1331 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1332 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1333 main.assertReturnString += 'Partial failure isolation link Down Intent State Passed\n'
1334 else:
1335 main.assertReturnString += 'Partial failure isolation link Down Intent State Failed\n'
1336 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001337
Jeremy Songster9385d412016-06-02 17:57:36 -07001338 # Check flows count in each node
1339 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1340 args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState,
1341 retValue=main.FALSE,
1342 args=[ main ], attempts=5 ):
1343 main.assertReturnString += 'Partial failure isolation link Down Flow State Passed\n'
1344 else:
1345 main.assertReturnString += 'Partial failure isolation link Down Flow State Failed\n'
1346 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001347
Jeremy Songster9385d412016-06-02 17:57:36 -07001348 # Check OnosTopology
1349 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink2 ) ):
1350 main.assertReturnString += 'Partial failure isolation link Down Topology State Passed\n'
1351 else:
1352 main.assertReturnString += 'Partial failure isolation link Down Topology State Failed\n'
1353 testResult = main.FALSE
Jeremye0cb5eb2016-01-27 17:39:09 -08001354
Jeremy Songster9385d412016-06-02 17:57:36 -07001355 # Check Connectivity
1356 # First check connectivity of any isolated senders to recipients
1357 if isolatedSenderNames:
1358 if scapyCheckConnection( main, isolatedSenderNames, recipientNames, None, None, None, None, main.TRUE ):
1359 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1360 else:
1361 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1362 testResult = main.FALSE
1363
1364 # Next check connectivity of senders to any isolated recipients
1365 if isolatedRecipientNames:
1366 if scapyCheckConnection( main, senderNames, isolatedRecipientNames, None, None, None, None, main.TRUE ):
1367 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1368 else:
1369 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1370 testResult = main.FALSE
1371
1372 # Next check connectivity of connected senders and recipients
1373 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1374 args=( main, connectedSenderNames , connectedRecipientNames ) ):
1375 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Passed\n'
1376 else:
1377 main.assertReturnString += 'Partial failure isolation link Down Connectivity Check Failed\n'
1378 testResult = main.FALSE
1379 else:
1380 # Check intent state
1381 if not utilities.retry( f=checkIntentState, retValue=main.TRUE,
1382 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1383 main.assertReturnString += 'Isolation link Down Intent State Passed\n'
1384 else:
1385 main.assertReturnString += 'Isolation link Down Intent State Failed\n'
1386 testResult = main.FALSE
1387
1388 # Check flows count in each node
1389 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
1390 args=[ main ], attempts=5 ) and utilities.retry( f=checkFlowsState,
1391 retValue=main.FALSE,
1392 args=[ main ], attempts=5 ):
1393 main.assertReturnString += 'Isolation link Down Flow State Passed\n'
1394 else:
1395 main.assertReturnString += 'Isolation link Down Flow State Failed\n'
1396 testResult = main.FALSE
1397
1398 # Check OnosTopology
1399 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, expectedLink2 ) ):
1400 main.assertReturnString += 'Isolation link Down Topology State Passed\n'
1401 else:
1402 main.assertReturnString += 'Isolation link Down Topology State Failed\n'
1403 testResult = main.FALSE
1404
1405 # Check Connectivity
1406 # First check connectivity of any isolated senders to recipients
1407 if isolatedSenderNames:
1408 if scapyCheckConnection( main, isolatedSenderNames, recipientNames, None, None, None, None, main.TRUE ):
1409 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1410 else:
1411 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1412 testResult = main.FALSE
1413
1414 # Next check connectivity of senders to any isolated recipients
1415 if isolatedRecipientNames:
1416 if scapyCheckConnection( main, senderNames, isolatedRecipientNames, None, None, None, None, main.TRUE ):
1417 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1418 else:
1419 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1420 testResult = main.FALSE
1421
1422 # Next check connectivity of connected senders and recipients
1423 if utilities.retry( f=scapyCheckConnection, retValue=main.TRUE,
1424 args=( main, connectedSenderNames , connectedRecipientNames, None, None, None, None, main.TRUE ) ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001425 main.assertReturnString += 'Isolation link Down Connectivity Check Passed\n'
1426 else:
1427 main.assertReturnString += 'Isolation link Down Connectivity Check Failed\n'
1428 testResult = main.FALSE
1429
Jeremye0cb5eb2016-01-27 17:39:09 -08001430 # Bring the links back up
1431 # Bring first link up
1432 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw1, sw2, "up" ) ):
1433 main.assertReturnString += 'Link Up Passed\n'
1434 else:
1435 main.assertReturnString += 'Link Up Failed\n'
1436 testResult = main.FALSE
1437
1438 # Bring second link up
1439 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw5, "up" ) ):
1440 main.assertReturnString += 'Link Up Passed\n'
1441 else:
1442 main.assertReturnString += 'Link Up Failed\n'
1443 testResult = main.FALSE
1444
1445 # Bring third link up
1446 if utilities.retry( f=link, retValue=main.FALSE, args=( main, sw3, sw4, "up" ) ):
1447 main.assertReturnString += 'Link Up Passed\n'
1448 else:
1449 main.assertReturnString += 'Link Up Failed\n'
1450 testResult = main.FALSE
1451
1452 # Wait for reroute
1453 time.sleep( main.rerouteSleep )
1454
1455 # Check Intents
1456 if utilities.retry( f=checkIntentState, retValue=main.FALSE,
1457 args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
1458 main.assertReturnString += 'Link Up Intent State Passed\n'
1459 else:
1460 main.assertReturnString += 'Link Up Intent State Failed\n'
1461 testResult = main.FALSE
1462
1463 # Check flows count in each node
1464 if utilities.retry( f=checkFlowsCount, retValue=main.FALSE,
Jeremy Songster9385d412016-06-02 17:57:36 -07001465 args=[ main ], sleep=5, attempts=5 ) and utilities.retry( f=checkFlowsState,
1466 retValue=main.FALSE,
1467 args=[ main ], sleep=5, attempts=5 ):
Jeremye0cb5eb2016-01-27 17:39:09 -08001468 main.assertReturnString += 'Link Up Flow State Passed\n'
1469 else:
1470 main.assertReturnString += 'Link Up Flow State Failed\n'
1471 testResult = main.FALSE
1472
1473 # Check OnosTopology
1474 if utilities.retry( f=checkTopology, retValue=main.FALSE, args=( main, main.numLinks ) ):
1475 main.assertReturnString += 'Link Up Topology State Passed\n'
1476 else:
1477 main.assertReturnString += 'Link Up Topology State Failed\n'
1478 testResult = main.FALSE
1479
1480 # Check Connection
1481 if utilities.retry( f=scapyCheckConnection, retValue=main.FALSE,
1482 args=( main, senderNames, recipientNames ) ):
1483 main.assertReturnString += 'Link Up Scapy Packet Received Passed\n'
1484 else:
1485 main.assertReturnString += 'Link Up Scapy Packet Recieved Failed\n'
1486 testResult = main.FALSE
1487
1488 # Remove all intents
1489 if utilities.retry( f=removeAllIntents, retValue=main.FALSE, args=( main, [ intentId ] ) ):
1490 main.assertReturnString += 'Remove Intents Passed'
1491 else:
1492 main.assertReturnString += 'Remove Intents Failed'
1493 testResult = main.FALSE
1494
1495 return testResult
1496
1497
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001498def pingallHosts( main, hostList ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001499 """
1500 Ping all host in the hosts list variable
1501 """
Jon Halla5cb3412015-08-18 14:08:22 -07001502 main.log.info( "Pinging: " + str( hostList ) )
1503 return main.Mininet1.pingallHosts( hostList )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001504
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001505def fwdPingall( main ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001506 """
1507 Use fwd app and pingall to discover all the hosts
1508 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001509 activateResult = main.TRUE
1510 appCheck = main.TRUE
1511 getDataResult = main.TRUE
1512 main.log.info( "Activating reactive forwarding app " )
1513 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001514
1515 # Wait for forward app activation to propagate
kelvin-onlab0ad05d12015-07-23 14:21:15 -07001516 time.sleep( main.fwdSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001517
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001518 # Check that forwarding is enabled on all nodes
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001519 for i in range( main.numCtrls ):
1520 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
1521 if appCheck != main.TRUE:
1522 main.log.warn( main.CLIs[ i ].apps() )
1523 main.log.warn( main.CLIs[ i ].appIDs() )
1524
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001525 # Send pingall in mininet
1526 main.log.info( "Run Pingall" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001527 pingResult = main.Mininet1.pingall( timeout = 600 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001528
1529 main.log.info( "Deactivating reactive forwarding app " )
1530 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001531 if activateResult and deactivateResult:
1532 main.log.info( "Successfully used fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001533 getDataResult = main.TRUE
1534 else:
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001535 main.log.info( "Failed to use fwd app to discover hosts" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001536 getDataResult = main.FALSE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001537 return getDataResult
1538
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001539def confirmHostDiscovery( main ):
1540 """
1541 Confirms that all ONOS nodes have discovered all scapy hosts
1542 """
1543 import collections
1544 scapyHostCount = len( main.scapyHosts )
1545 hosts = main.topo.getAllHosts( main ) # Get host data from each ONOS node
1546 hostFails = [] # Reset for each failed attempt
1547
1548 # Check for matching hosts on each node
1549 scapyHostIPs = [ x.hostIp for x in main.scapyHosts if x.hostIp != "0.0.0.0" ]
1550 for controller in range( main.numCtrls ):
1551 controllerStr = str( controller + 1 ) # ONOS node number
1552 # Compare Hosts
1553 # Load hosts data for controller node
Jeremyd9e4eb12016-04-13 12:09:06 -07001554 try:
1555 if hosts[ controller ]:
1556 main.log.info( "Hosts discovered" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001557 else:
Jeremyd9e4eb12016-04-13 12:09:06 -07001558 main.log.error( "Problem discovering hosts" )
1559 if hosts[ controller ] and "Error" not in hosts[ controller ]:
1560 try:
1561 hostData = json.loads( hosts[ controller ] )
1562 except ( TypeError, ValueError ):
1563 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001564 hostFails.append( controllerStr )
Jeremyd9e4eb12016-04-13 12:09:06 -07001565 else:
1566 onosHostIPs = [ x.get( "ipAddresses" )[ 0 ]
1567 for x in hostData
1568 if len( x.get( "ipAddresses" ) ) > 0 ]
1569 if not set( collections.Counter( scapyHostIPs ) ).issubset( set ( collections.Counter( onosHostIPs ) ) ):
1570 main.log.warn( "Controller {0} only sees nodes with {1} IPs. It should see all of the following: {2}".format( controllerStr, onosHostIPs, scapyHostIPs ) )
1571 hostFails.append( controllerStr )
1572 else:
1573 main.log.error( "Hosts returned nothing or an error." )
1574 hostFails.append( controllerStr )
1575 except IndexError:
1576 main.log.error( "Hosts returned nothing, Failed to discover hosts." )
1577 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001578
1579 if hostFails:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001580 main.log.error( "List of failed ONOS Nodes:" + ', '.join( map( str, hostFails ) ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001581 return main.FALSE
1582 else:
1583 return main.TRUE
1584
1585def sendDiscoveryArp( main, hosts=None ):
1586 """
1587 Sends Discovery ARP packets from each host provided
1588 Defaults to each host in main.scapyHosts
1589 """
1590 # Send an arp ping from each host
1591 if not hosts:
1592 hosts = main.scapyHosts
1593 for host in hosts:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001594 pkt = 'Ether( src="{0}")/ARP( psrc="{1}")'.format( host.hostMac, host.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001595 # Send from the VLAN interface if there is one so ONOS discovers the VLAN correctly
1596 iface = None
1597 for interface in host.getIfList():
1598 if '.' in interface:
1599 main.log.debug( "Detected VLAN interface {0}. Sending ARP packet from {0}".format( interface ) )
1600 iface = interface
1601 break
1602 host.sendPacket( packet=pkt, iface=iface )
1603 main.log.info( "Sending ARP packet from {0}".format( host.name ) )
1604
1605def populateHostData( main ):
1606 """
1607 Populates hostsData
1608 """
1609 import json
1610 try:
1611 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
1612 hosts = main.Mininet1.getHosts().keys()
1613 # TODO: Make better use of new getHosts function
1614 for host in hosts:
1615 main.hostsData[ host ] = {}
1616 main.hostsData[ host ][ 'mac' ] = \
1617 main.Mininet1.getMacAddress( host ).upper()
1618 for hostj in hostsJson:
1619 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
1620 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
1621 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
1622 main.hostsData[ host ][ 'location' ] = \
1623 hostj[ 'location' ][ 'elementId' ] + '/' + \
1624 hostj[ 'location' ][ 'port' ]
1625 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
1626 return main.TRUE
Jeremyd9e4eb12016-04-13 12:09:06 -07001627 except ValueError:
1628 main.log.error( "ValueError while populating hostsData" )
1629 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001630 except KeyError:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001631 main.log.error( "KeyError while populating hostsData" )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001632 return main.FALSE
Jeremyd9e4eb12016-04-13 12:09:06 -07001633 except IndexError:
1634 main.log.error( "IndexError while populating hostsData" )
1635 return main.FALSE
1636 except TypeError:
1637 main.log.error( "TypeError while populating hostsData" )
1638 return main.FALSE
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001639
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001640def checkTopology( main, expectedLink ):
1641 statusResult = main.TRUE
1642 # Check onos topology
1643 main.log.info( itemName + ": Checking ONOS topology " )
1644
1645 for i in range( main.numCtrls ):
Flavio Castro82ee2f62016-06-07 15:04:12 -07001646 statusResult = main.CLIs[ i ].checkStatus( main.numSwitch,
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001647 expectedLink )\
1648 and statusResult
1649 if not statusResult:
1650 main.log.error( itemName + ": Topology mismatch" )
1651 else:
1652 main.log.info( itemName + ": Topology match" )
1653 return statusResult
1654
1655def checkIntentState( main, intentsId ):
1656 """
1657 This function will check intent state to make sure all the intents
1658 are in INSTALLED state
1659 """
1660
1661 intentResult = main.TRUE
1662 results = []
1663
1664 main.log.info( itemName + ": Checking intents state" )
1665 # First check of intents
1666 for i in range( main.numCtrls ):
1667 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
1668 results.append( tempResult )
1669
1670 expectedState = [ 'INSTALLED', 'INSTALLING' ]
1671
1672 if all( result == main.TRUE for result in results ):
1673 main.log.info( itemName + ": Intents are installed correctly" )
1674 else:
1675 # Wait for at least 5 second before checking the intents again
acsmarsb9a92692015-10-08 16:43:01 -07001676 main.log.error( "Intents are not installed correctly. Waiting 5 sec" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001677 time.sleep( 5 )
1678 results = []
1679 # Second check of intents since some of the intents may be in
1680 # INSTALLING state, they should be in INSTALLED at this time
1681 for i in range( main.numCtrls ):
Jeremy2f190ca2016-01-29 15:23:57 -08001682 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001683 results.append( tempResult )
1684 if all( result == main.TRUE for result in results ):
1685 main.log.info( itemName + ": Intents are installed correctly" )
acsmarsb9a92692015-10-08 16:43:01 -07001686 intentResult = main.TRUE
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001687 else:
1688 main.log.error( itemName + ": Intents are NOT installed correctly" )
1689 intentResult = main.FALSE
1690
1691 return intentResult
1692
1693def checkFlowsState( main ):
1694
1695 main.log.info( itemName + ": Check flows state" )
Jeremy Songsterff553672016-05-12 17:06:23 -07001696 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState( isPENDING=False )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001697 return checkFlowsResult
1698
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001699def link( main, sw1, sw2, option ):
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001700
1701 # link down
1702 main.log.info( itemName + ": Bring link " + option + "between " +
1703 sw1 + " and " + sw2 )
1704 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
1705 return linkResult
1706
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001707def scapyCheckConnection( main, senders, recipients, vlanId=None, useTCP=False, packet=None, packetFilter=None, expectFailure=False ):
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001708 """
1709 Checks the connectivity between all given sender hosts and all given recipient hosts
1710 Packet may be specified. Defaults to Ether/IP packet
1711 Packet Filter may be specified. Defaults to Ether/IP from current sender MAC
1712 Todo: Optional packet and packet filter attributes for sender and recipients
1713 Expect Failure when the sender and recipient are not supposed to have connectivity
1714 Timeout of 1 second, returns main.TRUE if the filter is not triggered and kills the filter
1715
1716 """
1717 connectionsFunctional = main.TRUE
1718
1719 if not packetFilter:
1720 packetFilter = 'ether host {}'
Jeremy Songstere405d3d2016-05-17 11:18:57 -07001721 if useTCP:
1722 packetFilter += ' ip proto \\tcp tcp port {}'.format(main.params[ 'SDNIP' ][ 'dstPort' ])
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001723 if expectFailure:
1724 timeout = 1
1725 else:
1726 timeout = 10
1727
1728 for sender in senders:
1729 try:
1730 senderComp = getattr( main, sender )
1731 except AttributeError:
1732 main.log.error( "main has no attribute {}".format( sender ) )
1733 connectionsFunctional = main.FALSE
1734 continue
1735
1736 for recipient in recipients:
1737 # Do not send packets to self since recipient CLI will already be busy
1738 if recipient == sender:
1739 continue
1740 try:
1741 recipientComp = getattr( main, recipient )
1742 except AttributeError:
1743 main.log.error( "main has no attribute {}".format( recipient ) )
1744 connectionsFunctional = main.FALSE
1745 continue
1746
Jeremy Songster832f9e92016-05-05 14:30:49 -07001747 if vlanId:
1748 recipientComp.startFilter( pktFilter = ( "vlan {}".format( vlanId ) + " && " + packetFilter.format( senderComp.hostMac ) ) )
1749 else:
1750 recipientComp.startFilter( pktFilter = packetFilter.format( senderComp.hostMac ) )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001751
1752 if not packet:
Jeremy Songster832f9e92016-05-05 14:30:49 -07001753 if vlanId:
1754 pkt = 'Ether( src="{0}", dst="{2}" )/Dot1Q(vlan={4})/IP( src="{1}", dst="{3}" )'.format(
1755 senderComp.hostMac,
1756 senderComp.hostIp,
1757 recipientComp.hostMac,
1758 recipientComp.hostIp,
1759 vlanId )
1760 else:
1761 pkt = 'Ether( src="{0}", dst="{2}" )/IP( src="{1}", dst="{3}" )'.format(
1762 senderComp.hostMac,
1763 senderComp.hostIp,
1764 recipientComp.hostMac,
1765 recipientComp.hostIp )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001766 else:
1767 pkt = packet
Jeremy Songster832f9e92016-05-05 14:30:49 -07001768 if vlanId:
1769 senderComp.sendPacket( iface=( "{0}-eth0.{1}".format( sender, vlanId ) ), packet = pkt )
1770 else:
1771 senderComp.sendPacket( packet = pkt )
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001772
1773 if recipientComp.checkFilter( timeout ):
1774 if expectFailure:
1775 main.log.error( "Packet from {0} successfully received by {1} when it should not have been".format( sender , recipient ) )
1776 connectionsFunctional = main.FALSE
1777 else:
1778 main.log.info( "Packet from {0} successfully received by {1}".format( sender , recipient ) )
1779 else:
1780 recipientComp.killFilter()
1781 if expectFailure:
1782 main.log.info( "As expected, packet from {0} was not received by {1}".format( sender , recipient ) )
1783 else:
1784 main.log.error( "Packet from {0} was not received by {1}".format( sender , recipient ) )
1785 connectionsFunctional = main.FALSE
1786
1787 return connectionsFunctional
1788
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001789def removeAllIntents( main, intentsId ):
1790 """
1791 Remove all intents in the intentsId
1792 """
1793
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001794 onosSummary = []
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001795 removeIntentResult = main.TRUE
1796 # Remove intents
1797 for intent in intentsId:
1798 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
1799
acsmarscfa52272015-08-06 15:21:45 -07001800 time.sleep( main.removeIntentSleep )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001801
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001802 # If there is remianing intents then remove intents should fail
1803 for i in range( main.numCtrls ):
1804 onosSummary.append( json.loads( main.CLIs[ i ].summary() ) )
1805
1806 for summary in onosSummary:
1807 if summary.get( 'intents' ) != 0:
1808 main.log.warn( itemName + ": There are " +
1809 str( summary.get( 'intents' ) ) +
1810 " intents remaining in node " +
1811 str( summary.get( 'node' ) ) +
1812 ", failed to remove all the intents " )
1813 removeIntentResult = main.FALSE
1814
1815 if removeIntentResult:
1816 main.log.info( itemName + ": There are no more intents remaining, " +
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001817 "successfully removed all the intents." )
kelvin-onlab5c706ff2015-07-20 10:56:52 -07001818
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001819 return removeIntentResult
1820
1821def checkFlowsCount( main ):
1822 """
1823 Check flows count in each node
1824 """
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001825 flowsCount = []
1826 main.log.info( itemName + ": Checking flows count in each ONOS node" )
1827 for i in range( main.numCtrls ):
1828 summaryResult = main.CLIs[ i ].summary()
1829 if not summaryResult:
1830 main.log.error( itemName + ": There is something wrong with " +
1831 "summary command" )
1832 return main.FALSE
1833 else:
1834 summaryJson = json.loads( summaryResult )
1835 flowsCount.append( summaryJson.get( 'flows' ) )
1836
1837 if flowsCount:
1838 if all( flows==flowsCount[ 0 ] for flows in flowsCount ):
1839 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
1840 " flows in all ONOS node" )
1841 else:
1842 for i in range( main.numCtrls ):
1843 main.log.debug( itemName + ": ONOS node " + str( i ) + " has " +
kelvin-onlab6dea6e62015-07-23 13:07:26 -07001844 str( flowsCount[ i ] ) + " flows" )
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001845 else:
1846 main.log.error( "Checking flows count failed, check summary command" )
1847 return main.FALSE
1848
1849 return main.TRUE
1850
kelvin-onlab58dc39e2015-08-06 08:11:09 -07001851def checkLeaderChange( leaders1, leaders2 ):
acsmarse6b410f2015-07-17 14:39:34 -07001852 """
1853 Checks for a change in intent partition leadership.
1854
1855 Takes the output of leaders -c in json string format before and after
1856 a potential change as input
1857
1858 Returns main.TRUE if no mismatches are detected
1859 Returns main.FALSE if there is a mismatch or on error loading the input
1860 """
1861 try:
1862 leaders1 = json.loads( leaders1 )
1863 leaders2 = json.loads( leaders2 )
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001864 except( AttributeError, TypeError ):
acsmarse6b410f2015-07-17 14:39:34 -07001865 main.log.exception( self.name + ": Object not as expected" )
1866 return main.FALSE
1867 except Exception:
1868 main.log.exception( self.name + ": Uncaught exception!" )
1869 main.cleanup()
1870 main.exit()
1871 main.log.info( "Checking Intent Paritions for Change in Leadership" )
1872 mismatch = False
1873 for dict1 in leaders1:
1874 if "intent" in dict1.get( "topic", [] ):
1875 for dict2 in leaders2:
1876 if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \
1877 dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
1878 mismatch = True
1879 main.log.error( "{0} changed leader from {1} to {2}".\
1880 format( dict1.get( "topic", "no-topic" ),\
1881 dict1.get( "leader", "no-leader" ),\
1882 dict2.get( "leader", "no-leader" ) ) )
1883 if mismatch:
1884 return main.FALSE
1885 else:
1886 return main.TRUE
kelvin-onlab016dce22015-08-10 09:54:11 -07001887
1888def report( main ):
1889 """
Jeremy Songster1f39bf02016-01-20 17:17:25 -08001890 Report errors/warnings/exceptions
kelvin-onlab016dce22015-08-10 09:54:11 -07001891 """
kelvin-onlab016dce22015-08-10 09:54:11 -07001892 main.ONOSbench.logReport( main.ONOSip[ 0 ],
1893 [ "INFO",
1894 "FOLLOWER",
1895 "WARN",
1896 "flow",
1897 "ERROR",
1898 "Except" ],
1899 "s" )
1900
1901 main.log.info( "ERROR report: \n" )
1902 for i in range( main.numCtrls ):
1903 main.ONOSbench.logReport( main.ONOSip[ i ],
1904 [ "ERROR" ],
1905 "d" )
1906
1907 main.log.info( "EXCEPTIONS report: \n" )
1908 for i in range( main.numCtrls ):
1909 main.ONOSbench.logReport( main.ONOSip[ i ],
1910 [ "Except" ],
1911 "d" )
1912
1913 main.log.info( "WARNING report: \n" )
1914 for i in range( main.numCtrls ):
1915 main.ONOSbench.logReport( main.ONOSip[ i ],
1916 [ "WARN" ],
1917 "d" )
Jeremy Songster306ed7a2016-07-19 10:59:07 -07001918
1919def flowDuration( main ):
1920 """
1921 Check age of flows to see if flows are being overwritten
1922 """
1923 import time
1924 main.log.info( "Getting current flow durations" )
1925 flowsJson1 = main.CLIs[ 0 ].flows( noCore=True )
1926 try:
1927 flowsJson1 = json.loads( flowsJson1 )
1928 except ValueError:
1929 main.log.error( "Unable to read flows" )
1930 return main.FALSE
1931 flowLife = []
1932 waitFlowLife = []
1933 for device in flowsJson1:
1934 if device.get( 'flowcount', 0 ) > 0:
1935 for i in range( device[ 'flowCount' ] ):
1936 flowLife.append( device[ 'flows' ][ i ][ 'life' ] )
1937 main.log.info( "Sleeping for {} seconds".format( main.flowDurationSleep ) )
1938 time.sleep( main.flowDurationSleep )
1939 main.log.info( "Getting new flow durations" )
1940 flowsJson2 = main.CLIs[ 0 ].flows( noCore=True )
1941 try:
1942 flowsJson2 = json.loads( flowsJson2 )
1943 except ValueError:
1944 main.log.error( "Unable to read flows" )
1945 return main.FALSE
1946 for device in flowsJson2:
1947 if device.get( 'flowcount', 0 ) > 0:
1948 for i in range( device[ 'flowCount' ] ):
1949 waitFlowLife.append( device[ 'flows' ][ i ][ 'life' ] )
1950 main.log.info( "Determining whether flows where overwritten" )
1951 if len( flowLife ) == len( waitFlowLife ):
1952 for i in range( len( flowLife) ):
1953 if waitFlowLife[ i ] - flowLife[ i ] < main.flowDurationSleep:
1954 return main.FALSE
1955 else:
1956 return main.FALSE
1957 return main.TRUE