blob: e48575560d1c7e048fa2f8d4a8ac422c64ceb2b0 [file] [log] [blame]
kelvin-onlabe5239e52015-05-13 14:46:45 -07001"""
2 Wrapper functions for FuncIntent
3 This functions include Onosclidriver and Mininetclidriver driver functions
4"""
5def __init__( self ):
6 self.default = ''
7
kelvin-onlab2ccad6e2015-05-18 10:36:54 -07008def hostIntent( main,
kelvin-onlabf0594d72015-05-19 17:25:12 -07009 name,
10 host1,
11 host2,
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070012 host1Id="",
13 host2Id="",
14 mac1="",
15 mac2="",
16 vlan1="-1",
17 vlan2="-1",
18 sw1="",
19 sw2="",
20 expectedLink=0 ):
kelvin-onlabe5239e52015-05-13 14:46:45 -070021 """
22 Add host intents
23 """
24 import time
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070025
26 # Assert variables
27 assert main, "There is no main variable"
28 assert name, "variable name is empty"
29 assert host1 and host2, "You must specify hosts"
30
kelvin-onlabe5239e52015-05-13 14:46:45 -070031 global itemName
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070032 itemName = name
33 h1Name = host1
34 h2Name = host2
35 h1Id = host1Id
36 h2Id = host2Id
37 h1Mac = mac1
38 h2Mac = mac2
39 vlan1 = vlan1
40 vlan2 = vlan2
kelvin-onlabe5239e52015-05-13 14:46:45 -070041 intentsId = []
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070042 stepResult = main.TRUE
kelvin-onlabe5239e52015-05-13 14:46:45 -070043 pingResult = main.TRUE
44 intentResult = main.TRUE
kelvin-onlabf0594d72015-05-19 17:25:12 -070045 removeIntentResult = main.TRUE
kelvin-onlabe5239e52015-05-13 14:46:45 -070046 flowResult = main.TRUE
47 topoResult = main.TRUE
48 linkDownResult = main.TRUE
49 linkUpResult = main.TRUE
50
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070051 if main.hostsData:
52 if not h1Mac:
53 h1Mac = main.hostsData[ h1Name ][ 'mac' ]
54 if not h2Mac:
55 h2Mac = main.hostsData[ h2Name ][ 'mac' ]
56 if main.hostsData[ h1Name ][ 'vlan' ] != '-1':
57 vlan1 = main.hostsData[ h1Name ][ 'vlan' ]
58 if main.hostsData[ h2Name ][ 'vlan' ] != '-1':
59 vlan2 = main.hostsData[ h2Name ][ 'vlan' ]
60 if not h1Id:
61 h1Id = main.hostsData[ h1Name ][ 'id' ]
62 if not h2Id:
63 h2Id = main.hostsData[ h2Name ][ 'id' ]
64
65 assert h1Id and h2Id, "You must specify host IDs"
66 if not ( h1Id and h2Id ):
67 main.log.info( "There are no host IDs" )
68 return main.FALSE
69
kelvin-onlabe5239e52015-05-13 14:46:45 -070070 # Discover hosts using arping
71 main.log.info( itemName + ": Discover host using arping" )
72 main.Mininet1.arping( host=h1Name )
73 main.Mininet1.arping( host=h2Name )
74 host1 = main.CLIs[ 0 ].getHost( mac=h1Mac )
75 host2 = main.CLIs[ 0 ].getHost( mac=h2Mac )
76
77 # Adding host intents
78 main.log.info( itemName + ": Adding host intents" )
79 intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne=h1Id,
80 hostIdTwo=h2Id )
81 intentsId.append( intent1 )
82 time.sleep( 5 )
kelvin-onlabe5239e52015-05-13 14:46:45 -070083
84 # Check intents state
kelvin-onlabf0594d72015-05-19 17:25:12 -070085 time.sleep( 30 )
kelvin-onlabe5239e52015-05-13 14:46:45 -070086 intentResult = checkIntentState( main, intentsId )
87
88 # Verify flows
89 checkFlowsState( main )
90
91 # Ping hosts
kelvin-onlabf0594d72015-05-19 17:25:12 -070092 firstPingResult = pingHost( main, h1Name, h2Name )
93 if not firstPingResult:
94 main.log.info( "First ping failed, there must be" +
95 " something wrong with ONOS performance" )
96
kelvin-onlabe5239e52015-05-13 14:46:45 -070097 # Ping hosts again...
98 pingResult = pingHost( main, h1Name, h2Name )
99 time.sleep( 5 )
100
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700101 # Test rerouting if these variables exist
102 if sw1 and sw2 and expectedLink:
103 # link down
kelvin-onlabf0594d72015-05-19 17:25:12 -0700104 linkDownResult = link( main, sw1, sw2, "down" )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700105 intentResult = intentResult and checkIntentState( main, intentsId )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700106
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700107 # Verify flows
108 checkFlowsState( main )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700109
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700110 # Check OnosTopology
111 topoResult = checkTopology( main, expectedLink )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700112
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700113 # Ping hosts
kelvin-onlabf0594d72015-05-19 17:25:12 -0700114 pingResult = pingResult and pingHost( main, h1Name, h2Name )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700115
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700116 intentResult = checkIntentState( main, intentsId )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700117
kelvin-onlabf0594d72015-05-19 17:25:12 -0700118 # Checks ONOS state in link down
119 if linkDownResult and topoResult and pingResult and intentResult:
120 main.log.info( itemName + ": Successfully brought link down" )
121 else:
122 main.log.info( itemName + ": Failed to bring link down" )
123
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700124 # link up
kelvin-onlabf0594d72015-05-19 17:25:12 -0700125 linkUpResult = link( main, sw1, sw2, "up" )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700126 time.sleep( 5 )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700127
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700128 # Verify flows
129 checkFlowsState( main )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700130
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700131 # Check OnosTopology
kelvin-onlabf0594d72015-05-19 17:25:12 -0700132 topoResult = checkTopology( main, main.numLinks )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700133
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700134 # Ping hosts
135 pingResult = pingResult and pingHost( main, h1Name, h2Name )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700136
kelvin-onlabf0594d72015-05-19 17:25:12 -0700137 intentResult = checkIntentState( main, intentsId )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700138
kelvin-onlabf0594d72015-05-19 17:25:12 -0700139 # Checks ONOS state in link up
140 if linkUpResult and topoResult and pingResult and intentResult:
141 main.log.info( itemName + ": Successfully brought link back up" )
142 else:
143 main.log.info( itemName + ": Failed to bring link back up" )
144
145 # Remove all intents
146 removeIntentResult = removeAllIntents( main, intentsId )
147
kelvin-onlabe5239e52015-05-13 14:46:45 -0700148 stepResult = pingResult and linkDownResult and linkUpResult \
kelvin-onlabf0594d72015-05-19 17:25:12 -0700149 and intentResult and removeIntentResult
kelvin-onlabe5239e52015-05-13 14:46:45 -0700150
151 return stepResult
152
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700153def pointIntent( main,
kelvin-onlabf0594d72015-05-19 17:25:12 -0700154 name,
155 host1,
156 host2,
157 deviceId1,
158 deviceId2,
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700159 port1="",
160 port2="",
161 ethType="",
162 mac1="",
163 mac2="",
164 bandwidth="",
165 lambdaAlloc=False,
166 ipProto="",
167 ip1="",
168 ip2="",
169 tcp1="",
170 tcp2="",
171 sw1="",
172 sw2="",
173 expectedLink=0 ):
kelvin-onlabe5239e52015-05-13 14:46:45 -0700174 """
175 Add Point intents
176 """
177 import time
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700178 assert main, "There is no main variable"
179 assert name, "variable name is empty"
180 assert host1 and host2, "You must specify hosts"
181
kelvin-onlabe5239e52015-05-13 14:46:45 -0700182 global itemName
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700183 itemName = name
184 h1Name = host1
185 h2Name = host2
kelvin-onlabe5239e52015-05-13 14:46:45 -0700186 intentsId = []
kelvin-onlabb2235602015-05-13 17:51:06 -0700187
kelvin-onlabe5239e52015-05-13 14:46:45 -0700188 pingResult = main.TRUE
189 intentResult = main.TRUE
kelvin-onlabf0594d72015-05-19 17:25:12 -0700190 removeIntentResult = main.TRUE
kelvin-onlabe5239e52015-05-13 14:46:45 -0700191 flowResult = main.TRUE
192 topoResult = main.TRUE
193 linkDownResult = main.TRUE
194 linkUpResult = main.TRUE
195
kelvin-onlabb2235602015-05-13 17:51:06 -0700196 # Adding bidirectional point intents
kelvin-onlabf0594d72015-05-19 17:25:12 -0700197 main.log.info( itemName + ": Adding point intents" )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700198 intent1 = main.CLIs[ 0 ].addPointIntent( ingressDevice=deviceId1,
199 egressDevice=deviceId2,
200 portIngress=port1,
201 portEgress=port2,
kelvin-onlabb2235602015-05-13 17:51:06 -0700202 ethType=ethType,
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700203 ethSrc=mac1,
204 ethDst=mac2,
kelvin-onlabb2235602015-05-13 17:51:06 -0700205 bandwidth=bandwidth,
206 lambdaAlloc=lambdaAlloc,
207 ipProto=ipProto,
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700208 ipSrc=ip1,
209 ipDst=ip2,
210 tcpSrc=tcp1,
211 tcpDst=tcp2 )
kelvin-onlabb2235602015-05-13 17:51:06 -0700212
kelvin-onlabe5239e52015-05-13 14:46:45 -0700213 intentsId.append( intent1 )
214 time.sleep( 5 )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700215 intent2 = main.CLIs[ 0 ].addPointIntent( ingressDevice=deviceId2,
216 egressDevice=deviceId1,
217 portIngress=port2,
218 portEgress=port1,
kelvin-onlabb2235602015-05-13 17:51:06 -0700219 ethType=ethType,
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700220 ethSrc=mac2,
221 ethDst=mac1,
kelvin-onlabb2235602015-05-13 17:51:06 -0700222 bandwidth=bandwidth,
223 lambdaAlloc=lambdaAlloc,
224 ipProto=ipProto,
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700225 ipSrc=ip2,
226 ipDst=ip1,
227 tcpSrc=tcp2,
228 tcpDst=tcp1 )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700229 intentsId.append( intent2 )
230
231 # Check intents state
kelvin-onlabf0594d72015-05-19 17:25:12 -0700232 time.sleep( 30 )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700233 intentResult = checkIntentState( main, intentsId )
234
235 # Verify flows
236 checkFlowsState( main )
237
238 # Ping hosts
kelvin-onlabf0594d72015-05-19 17:25:12 -0700239 firstPingResult = pingHost( main, h1Name, h2Name )
240 if not firstPingResult:
241 main.log.info( "First ping failed, there must be" +
242 " something wrong with ONOS performance" )
243
kelvin-onlabe5239e52015-05-13 14:46:45 -0700244 # Ping hosts again...
245 pingResult = pingHost( main, h1Name, h2Name )
246 time.sleep( 5 )
247
kelvin-onlabf0594d72015-05-19 17:25:12 -0700248 # Test rerouting if these variables exist
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700249 if sw1 and sw2 and expectedLink:
250 # link down
kelvin-onlabf0594d72015-05-19 17:25:12 -0700251 linkDownResult = link( main, sw1, sw2, "down" )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700252 intentResult = intentResult and checkIntentState( main, intentsId )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700253
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700254 # Verify flows
255 checkFlowsState( main )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700256
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700257 # Check OnosTopology
258 topoResult = checkTopology( main, expectedLink )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700259
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700260 # Ping hosts
kelvin-onlabf0594d72015-05-19 17:25:12 -0700261 pingResult = pingResult and pingHost( main, h1Name, h2Name )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700262
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700263 intentResult = checkIntentState( main, intentsId )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700264
kelvin-onlabf0594d72015-05-19 17:25:12 -0700265 # Checks ONOS state in link down
266 if linkDownResult and topoResult and pingResult and intentResult:
267 main.log.info( itemName + ": Successfully brought link down" )
268 else:
269 main.log.info( itemName + ": Failed to bring link down" )
270
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700271 # link up
kelvin-onlabf0594d72015-05-19 17:25:12 -0700272 linkUpResult = link( main, sw1, sw2, "up" )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700273 time.sleep( 5 )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700274
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700275 # Verify flows
276 checkFlowsState( main )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700277
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700278 # Check OnosTopology
kelvin-onlabf0594d72015-05-19 17:25:12 -0700279 topoResult = checkTopology( main, main.numLinks )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700280
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700281 # Ping hosts
282 pingResult = pingResult and pingHost( main, h1Name, h2Name )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700283
kelvin-onlabf0594d72015-05-19 17:25:12 -0700284 intentResult = checkIntentState( main, intentsId )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700285
kelvin-onlabf0594d72015-05-19 17:25:12 -0700286 # Checks ONOS state in link up
287 if linkUpResult and topoResult and pingResult and intentResult:
288 main.log.info( itemName + ": Successfully brought link back up" )
289 else:
290 main.log.info( itemName + ": Failed to bring link back up" )
291
292 # Remove all intents
293 removeIntentResult = removeAllIntents( main, intentsId )
294
kelvin-onlabe5239e52015-05-13 14:46:45 -0700295 stepResult = pingResult and linkDownResult and linkUpResult \
kelvin-onlabf0594d72015-05-19 17:25:12 -0700296 and intentResult and removeIntentResult
kelvin-onlabe5239e52015-05-13 14:46:45 -0700297
298 return stepResult
299
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700300def singleToMultiIntent( main,
kelvin-onlabf0594d72015-05-19 17:25:12 -0700301 name,
302 hostNames,
kelvin-onlab90b6b042015-05-18 20:57:13 -0700303 devices="",
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700304 ports=None,
305 ethType="",
306 macs=None,
307 bandwidth="",
308 lambdaAlloc=False,
309 ipProto="",
310 ipAddresses="",
311 tcp="",
312 sw1="",
313 sw2="",
314 expectedLink=0 ):
315 """
316 Add Single to Multi Point intents
kelvin-onlab90b6b042015-05-18 20:57:13 -0700317 If main.hostsData is not defined, variables data should be passed in the
kelvin-onlabf0594d72015-05-19 17:25:12 -0700318 same order index wise. All devices in the list should have the same
319 format, either all the devices have its port or it doesn't.
kelvin-onlab90b6b042015-05-18 20:57:13 -0700320 eg. hostName = [ 'h1', 'h2' ,.. ]
321 devices = [ 'of:0000000000000001', 'of:0000000000000002', ...]
322 ports = [ '1', '1', ..]
323 ...
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700324 """
325 import time
kelvin-onlabf0594d72015-05-19 17:25:12 -0700326 import copy
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700327 assert main, "There is no main variable"
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700328 assert hostNames, "You must specify hosts"
329 assert devices or main.hostsData, "You must specify devices"
330
331 global itemName
332 itemName = name
kelvin-onlab90b6b042015-05-18 20:57:13 -0700333 tempHostsData = {}
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700334 intentsId = []
335
kelvin-onlab90b6b042015-05-18 20:57:13 -0700336 if hostNames and devices:
337 if len( hostNames ) != len( devices ):
338 main.log.error( "hosts and devices does not have the same length" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700339 print "len hostNames = ", len( hostNames )
340 print "len devices = ", len( devices )
kelvin-onlab90b6b042015-05-18 20:57:13 -0700341 return main.FALSE
342 if ports:
343 if len( ports ) != len( devices ):
344 main.log.error( "Ports and devices does " +
345 "not have the same length" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700346 print "len devices = ", len( devices )
347 print "len ports = ", len( ports )
kelvin-onlab90b6b042015-05-18 20:57:13 -0700348 return main.FALSE
349 else:
350 main.log.info( "Device Ports are not specified" )
351 elif hostNames and not devices and main.hostsData:
352 main.log.info( "singleToMultiIntent function is using main.hostsData" )
353 print main.hostsData
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700354
kelvin-onlabf0594d72015-05-19 17:25:12 -0700355 print 'host names = ', hostNames
356 print 'devices = ', devices
357
358 macsDict = {}
359 for i in range( len( devices ) ):
360 macsDict[ devices[ i ] ] = macs[ i ]
361
362 print "macsDict = ", macsDict
363
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700364 pingResult = main.TRUE
365 intentResult = main.TRUE
kelvin-onlabf0594d72015-05-19 17:25:12 -0700366 removeIntentResult = main.TRUE
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700367 flowResult = main.TRUE
368 topoResult = main.TRUE
369 linkDownResult = main.TRUE
370 linkUpResult = main.TRUE
371
kelvin-onlabf0594d72015-05-19 17:25:12 -0700372 devicesCopy = copy.copy( devices )
373 if ports:
374 portsCopy = copy.copy( ports )
375 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700376 # Adding bidirectional point intents
kelvin-onlabf0594d72015-05-19 17:25:12 -0700377 for i in range( len( devices ) ):
378 ingressDevice = devicesCopy[ i ]
379 egressDeviceList = copy.copy( devicesCopy )
380 egressDeviceList.remove( ingressDevice )
381 if ports:
382 portIngress = portsCopy[ i ]
383 portEgressList = copy.copy( portsCopy )
384 del portEgressList[ i ]
385 else:
386 portIngress = ""
387 portEgressList = None
388 intentsId.append( main.CLIs[ 0 ].addSinglepointToMultipointIntent(
389 ingressDevice=ingressDevice,
390 egressDeviceList=egressDeviceList,
391 portIngress=portIngress,
392 portEgressList=portEgressList,
kelvin-onlab90b6b042015-05-18 20:57:13 -0700393 ethType=ethType,
kelvin-onlabf0594d72015-05-19 17:25:12 -0700394 ethSrc="",
kelvin-onlab90b6b042015-05-18 20:57:13 -0700395 bandwidth=bandwidth,
396 lambdaAlloc=lambdaAlloc,
397 ipProto=ipProto,
kelvin-onlabf0594d72015-05-19 17:25:12 -0700398 ipSrc="",
399 ipDst="",
400 tcpSrc="",
401 tcpDst="" ) )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700402
kelvin-onlabf0594d72015-05-19 17:25:12 -0700403 pingHost( main, hostNames[ 0 ], hostNames[ 1 ] )
404 pingHost( main, hostNames[ 0 ], hostNames[ 2 ] )
405 pingHost( main, hostNames[ 1 ], hostNames[ 2 ] )
406 pingHost( main, hostNames[ 1 ], hostNames[ 0 ] )
407 pingHost( main, hostNames[ 2 ], hostNames[ 1 ] )
408 pingHost( main, hostNames[ 2 ], hostNames[ 0 ] )
409 return main.TRUE
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700410
411 # Check intents state
kelvin-onlabf0594d72015-05-19 17:25:12 -0700412 time.sleep( 30 )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700413 intentResult = checkIntentState( main, intentsId )
414
415 # Verify flows
416 checkFlowsState( main )
417
418 # Ping hosts
419 pingHost( main, h1Name, h2Name )
420 # Ping hosts again...
421 pingResult = pingHost( main, h1Name, h2Name )
422 time.sleep( 5 )
423
kelvin-onlabf0594d72015-05-19 17:25:12 -0700424 # Test rerouting if these variables exist
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700425 if sw1 and sw2 and expectedLink:
426 # link down
kelvin-onlabf0594d72015-05-19 17:25:12 -0700427 linkDownResult = link( main, sw1, sw2, "down" )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700428 intentResult = intentResult and checkIntentState( main, intentsId )
429
430 # Verify flows
431 checkFlowsState( main )
432
433 # Check OnosTopology
434 topoResult = checkTopology( main, expectedLink )
435
436 # Ping hosts
kelvin-onlabf0594d72015-05-19 17:25:12 -0700437 pingResult = pingResult and pingHost( main, h1Name, h2Name )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700438
439 intentResult = checkIntentState( main, intentsId )
440
kelvin-onlabf0594d72015-05-19 17:25:12 -0700441 # Checks ONOS state in link down
442 if linkDownResult and topoResult and pingResult and intentResult:
443 main.log.info( itemName + ": Successfully brought link down" )
444 else:
445 main.log.info( itemName + ": Failed to bring link down" )
446
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700447 # link up
kelvin-onlabf0594d72015-05-19 17:25:12 -0700448 linkUpResult = link( main, sw1, sw2, "up" )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700449 time.sleep( 5 )
450
451 # Verify flows
452 checkFlowsState( main )
453
454 # Check OnosTopology
kelvin-onlabf0594d72015-05-19 17:25:12 -0700455 topoResult = checkTopology( main, main.numLinks )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700456
457 # Ping hosts
458 pingResult = pingResult and pingHost( main, h1Name, h2Name )
459
kelvin-onlabf0594d72015-05-19 17:25:12 -0700460 intentResult = checkIntentState( main, intentsId )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700461
kelvin-onlabf0594d72015-05-19 17:25:12 -0700462 # Checks ONOS state in link up
463 if linkUpResult and topoResult and pingResult and intentResult:
464 main.log.info( itemName + ": Successfully brought link back up" )
465 else:
466 main.log.info( itemName + ": Failed to bring link back up" )
467
468 # Remove all intents
469 removeIntentResult = removeAllIntents( main, intentsId )
470
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700471 stepResult = pingResult and linkDownResult and linkUpResult \
kelvin-onlabf0594d72015-05-19 17:25:12 -0700472 and intentResult and removeIntentResult
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700473
474 return stepResult
475
kelvin-onlabe5239e52015-05-13 14:46:45 -0700476def pingHost( main, h1Name, h2Name ):
477
478 # Ping hosts
479 main.log.info( itemName + ": Ping " + h1Name + " and " +
480 h2Name )
481 pingResult1 = main.Mininet1.pingHost( src=h1Name , target=h2Name )
482 if not pingResult1:
483 main.log.info( itemName + ": " + h1Name + " cannot ping "
484 + h2Name )
485 pingResult2 = main.Mininet1.pingHost( src=h2Name , target=h1Name )
486 if not pingResult2:
487 main.log.info( itemName + ": " + h2Name + " cannot ping "
488 + h1Name )
489 pingResult = pingResult1 and pingResult2
490 if pingResult:
491 main.log.info( itemName + ": Successfully pinged " +
492 "both hosts" )
493 else:
494 main.log.info( itemName + ": Failed to ping " +
495 "both hosts" )
496 return pingResult
497
kelvin-onlabf0594d72015-05-19 17:25:12 -0700498def pingAllHost( main, hosts ):
499 # Ping all host in the hosts list variable
500 import itertools
501 print "Pinging : ", hosts
502 hostCombination = itertools.permutations( hosts, 2 )
503 pingResult = main.TRUE
504 for hostPair in hostCombination:
505 pingResult = pingResult and main.Mininet.pingHost(
506 src=hostPair[ 0 ],
507 target=hostPair[ 1 ] )
508 return pingResult
509
510
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700511def getHostsData( main ):
kelvin-onlabe5239e52015-05-13 14:46:45 -0700512 """
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700513 Use fwd app and pingall to discover all the hosts
kelvin-onlabe5239e52015-05-13 14:46:45 -0700514 """
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700515 """
516 hosts json format:
517 """
518 import json
519 activateResult = main.TRUE
520 appCheck = main.TRUE
521 main.log.info( "Activating reactive forwarding app " )
522 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
523
524 for i in range( main.numCtrls ):
525 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
kelvin-onlabf0594d72015-05-19 17:25:12 -0700526 if appCheck != main.TRUE:
527 main.log.warn( main.CLIs[ 0 ].apps() )
528 main.log.warn( main.CLIs[ 0 ].appIDs() )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700529
530 pingResult = main.Mininet1.pingall()
531 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
532 hosts = main.Mininet1.getHosts()
533 for host in hosts:
534 main.hostsData[ host ] = {}
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700535 main.hostsData[ host ][ 'mac' ] = \
536 main.Mininet1.getMacAddress( host ).upper()
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700537 for hostj in hostsJson:
538 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
539 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
540 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
541 main.hostsData[ host ][ 'location' ] = \
542 hostj[ 'location' ][ 'elementId' ] + '/' + \
543 hostj[ 'location' ][ 'port' ]
544 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
545
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700546 main.log.info( "Deactivating reactive forwarding app " )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700547 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
548 if activateResult and deactivateResult and pingResult:
549 main.log.info( "Successfully used fwd app to discover hosts " )
550 else:
551 main.log.info( "Failed to use fwd app to discover hosts " )
552
553 main.log.info( "Hosts data:\n "+ main.hostsData )
554
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700555 return pingResult
kelvin-onlabe5239e52015-05-13 14:46:45 -0700556
557def checkTopology( main, expectedLink ):
558 statusResult = main.TRUE
559 # Check onos topology
560 main.log.info( itemName + ": Checking ONOS topology " )
561
562 for i in range( main.numCtrls ):
563 topologyResult = main.CLIs[ i ].topology()
564 statusResult = main.ONOSbench.checkStatus( topologyResult,
565 main.numSwitch,
566 expectedLink )\
567 and statusResult
568 if not statusResult:
569 main.log.info( itemName + ": Topology mismatch" )
570 else:
571 main.log.info( itemName + ": Topology match" )
572 return statusResult
573
574def checkIntentState( main, intentsId ):
575
576 main.log.info( itemName + ": Check host intents state" )
577 for i in range( main.numCtrls ):
578 intentResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
579 if not intentResult:
580 main.log.info( itemName + ": Check host intents state again")
581 for i in range( main.numCtrls ):
582 intentResult = main.CLIs[ i ].checkIntentState(
583 intentsId=intentsId )
584 return intentResult
585
586def checkFlowsState( main ):
587
588 main.log.info( itemName + ": Check flows state" )
589 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState()
590 return checkFlowsResult
591
kelvin-onlabf0594d72015-05-19 17:25:12 -0700592def link( main, sw1, sw2, option):
kelvin-onlabe5239e52015-05-13 14:46:45 -0700593
kelvin-onlabf0594d72015-05-19 17:25:12 -0700594 # link down
595 main.log.info( itemName + ": Bring link " + option + "between " +
596 sw1 + " and " + sw2 )
597 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
598 return linkResult
599
600def removeAllIntents( main, intentsId ):
601 """
602 Remove all intents in the intentsId
603 """
604 import time
605 intentsRemaining = []
606 removeIntentResult = main.TRUE
607 # Remove intents
608 for intent in intentsId:
609 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
610
611 time.sleep( 5 )
612 # Checks if there is remaining intents using intents()
613 intentsRemaining = main.CLIs[ 0 ].intents()
614 print intentsRemaining
615 # If there is remianing intents then remove intents should fail
616 if not intentsRemaining:
617 main.log.info( itemName + ": There are " +
618 str( len( intentsRemaining ) ) + " intents remaining, "
619 + "failed to remove all the intents " )
620 removeIntentResult = main.FALSE
621 else:
622 main.log.info( itemName + ": There are no intents remaining, " +
623 "successfully removed all the intents." )
624 removeIntentResult = main.TRUE
625 return removeIntentResult