blob: a84d3b0d899fdfb09c6b188bfd75eccd2033a9ef [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
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070033 h1Id = host1Id
34 h2Id = host2Id
35 h1Mac = mac1
36 h2Mac = mac2
37 vlan1 = vlan1
38 vlan2 = vlan2
kelvin-onlab08900012015-05-20 14:30:44 -070039 hostNames = [ host1 , host2 ]
kelvin-onlabe5239e52015-05-13 14:46:45 -070040 intentsId = []
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070041 stepResult = main.TRUE
kelvin-onlabe5239e52015-05-13 14:46:45 -070042 pingResult = main.TRUE
43 intentResult = main.TRUE
kelvin-onlabf0594d72015-05-19 17:25:12 -070044 removeIntentResult = main.TRUE
kelvin-onlabe5239e52015-05-13 14:46:45 -070045 flowResult = main.TRUE
46 topoResult = main.TRUE
47 linkDownResult = main.TRUE
48 linkUpResult = main.TRUE
49
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070050 if main.hostsData:
51 if not h1Mac:
kelvin-onlab08900012015-05-20 14:30:44 -070052 h1Mac = main.hostsData[ host1 ][ 'mac' ]
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070053 if not h2Mac:
kelvin-onlab08900012015-05-20 14:30:44 -070054 h2Mac = main.hostsData[ host2 ][ 'mac' ]
55 if main.hostsData[ host1 ][ 'vlan' ] != '-1':
56 vlan1 = main.hostsData[ host1 ][ 'vlan' ]
57 if main.hostsData[ host2 ][ 'vlan' ] != '-1':
58 vlan2 = main.hostsData[ host2 ][ 'vlan' ]
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070059 if not h1Id:
kelvin-onlab08900012015-05-20 14:30:44 -070060 h1Id = main.hostsData[ host1 ][ 'id' ]
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070061 if not h2Id:
kelvin-onlab08900012015-05-20 14:30:44 -070062 h2Id = main.hostsData[ host2 ][ 'id' ]
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070063
64 assert h1Id and h2Id, "You must specify host IDs"
65 if not ( h1Id and h2Id ):
66 main.log.info( "There are no host IDs" )
67 return main.FALSE
68
kelvin-onlabe5239e52015-05-13 14:46:45 -070069 # Discover hosts using arping
70 main.log.info( itemName + ": Discover host using arping" )
kelvin-onlab08900012015-05-20 14:30:44 -070071 main.Mininet1.arping( host=host1 )
72 main.Mininet1.arping( host=host2 )
kelvin-onlabe5239e52015-05-13 14:46:45 -070073 host1 = main.CLIs[ 0 ].getHost( mac=h1Mac )
74 host2 = main.CLIs[ 0 ].getHost( mac=h2Mac )
75
76 # Adding host intents
77 main.log.info( itemName + ": Adding host intents" )
78 intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne=h1Id,
79 hostIdTwo=h2Id )
80 intentsId.append( intent1 )
81 time.sleep( 5 )
kelvin-onlabe5239e52015-05-13 14:46:45 -070082
83 # Check intents state
kelvin-onlabf0594d72015-05-19 17:25:12 -070084 time.sleep( 30 )
kelvin-onlabe5239e52015-05-13 14:46:45 -070085 intentResult = checkIntentState( main, intentsId )
86
87 # Verify flows
88 checkFlowsState( main )
89
90 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -070091 firstPingResult = pingallHosts( main, hostNames )
kelvin-onlabf0594d72015-05-19 17:25:12 -070092 if not firstPingResult:
kelvin-onlab08900012015-05-20 14:30:44 -070093 main.log.debug( "First ping failed, there must be" +
kelvin-onlabf0594d72015-05-19 17:25:12 -070094 " something wrong with ONOS performance" )
95
kelvin-onlabe5239e52015-05-13 14:46:45 -070096 # Ping hosts again...
kelvin-onlab08900012015-05-20 14:30:44 -070097 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe5239e52015-05-13 14:46:45 -070098 time.sleep( 5 )
99
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700100 # Test rerouting if these variables exist
101 if sw1 and sw2 and expectedLink:
102 # link down
kelvin-onlabf0594d72015-05-19 17:25:12 -0700103 linkDownResult = link( main, sw1, sw2, "down" )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700104 intentResult = intentResult and checkIntentState( main, intentsId )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700105
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700106 # Verify flows
107 checkFlowsState( main )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700108
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700109 # Check OnosTopology
110 topoResult = checkTopology( main, expectedLink )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700111
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700112 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700113 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700114
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700115 intentResult = checkIntentState( main, intentsId )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700116
kelvin-onlabf0594d72015-05-19 17:25:12 -0700117 # Checks ONOS state in link down
118 if linkDownResult and topoResult and pingResult and intentResult:
119 main.log.info( itemName + ": Successfully brought link down" )
120 else:
kelvin-onlab08900012015-05-20 14:30:44 -0700121 main.log.error( itemName + ": Failed to bring link down" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700122
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700123 # link up
kelvin-onlabf0594d72015-05-19 17:25:12 -0700124 linkUpResult = link( main, sw1, sw2, "up" )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700125 time.sleep( 5 )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700126
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700127 # Verify flows
128 checkFlowsState( main )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700129
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700130 # Check OnosTopology
kelvin-onlabf0594d72015-05-19 17:25:12 -0700131 topoResult = checkTopology( main, main.numLinks )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700132
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700133 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700134 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700135
kelvin-onlabf0594d72015-05-19 17:25:12 -0700136 intentResult = checkIntentState( main, intentsId )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700137
kelvin-onlabf0594d72015-05-19 17:25:12 -0700138 # Checks ONOS state in link up
139 if linkUpResult and topoResult and pingResult and intentResult:
140 main.log.info( itemName + ": Successfully brought link back up" )
141 else:
kelvin-onlab08900012015-05-20 14:30:44 -0700142 main.log.error( itemName + ": Failed to bring link back up" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700143
144 # Remove all intents
145 removeIntentResult = removeAllIntents( main, intentsId )
146
kelvin-onlabe5239e52015-05-13 14:46:45 -0700147 stepResult = pingResult and linkDownResult and linkUpResult \
kelvin-onlabf0594d72015-05-19 17:25:12 -0700148 and intentResult and removeIntentResult
kelvin-onlabe5239e52015-05-13 14:46:45 -0700149
150 return stepResult
151
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700152def pointIntent( main,
kelvin-onlabf0594d72015-05-19 17:25:12 -0700153 name,
154 host1,
155 host2,
156 deviceId1,
157 deviceId2,
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700158 port1="",
159 port2="",
160 ethType="",
161 mac1="",
162 mac2="",
163 bandwidth="",
164 lambdaAlloc=False,
165 ipProto="",
166 ip1="",
167 ip2="",
168 tcp1="",
169 tcp2="",
170 sw1="",
171 sw2="",
172 expectedLink=0 ):
kelvin-onlabe5239e52015-05-13 14:46:45 -0700173 """
174 Add Point intents
175 """
176 import time
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700177 assert main, "There is no main variable"
178 assert name, "variable name is empty"
179 assert host1 and host2, "You must specify hosts"
180
kelvin-onlabe5239e52015-05-13 14:46:45 -0700181 global itemName
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700182 itemName = name
kelvin-onlab08900012015-05-20 14:30:44 -0700183 host1 = host1
184 host2 = host2
185 hostNames = [ host1, 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-onlab08900012015-05-20 14:30:44 -0700239 firstPingResult = pingallHosts( main, hostNames )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700240 if not firstPingResult:
kelvin-onlab08900012015-05-20 14:30:44 -0700241 main.log.debug( "First ping failed, there must be" +
kelvin-onlabf0594d72015-05-19 17:25:12 -0700242 " something wrong with ONOS performance" )
243
kelvin-onlabe5239e52015-05-13 14:46:45 -0700244 # Ping hosts again...
kelvin-onlab08900012015-05-20 14:30:44 -0700245 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700246 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-onlab08900012015-05-20 14:30:44 -0700261 pingResult = pingResult and pingallHosts( main, hostNames )
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:
kelvin-onlab08900012015-05-20 14:30:44 -0700269 main.log.error( itemName + ": Failed to bring link down" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700270
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
kelvin-onlab08900012015-05-20 14:30:44 -0700282 pingResult = pingResult and pingallHosts( main, hostNames )
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:
kelvin-onlab08900012015-05-20 14:30:44 -0700290 main.log.error( itemName + ": Failed to bring link back up" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700291
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-onlab08900012015-05-20 14:30:44 -0700336 macsDict = {}
337 ipDict = {}
kelvin-onlab90b6b042015-05-18 20:57:13 -0700338 if hostNames and devices:
339 if len( hostNames ) != len( devices ):
kelvin-onlab08900012015-05-20 14:30:44 -0700340 main.log.debug( "hosts and devices does not have the same length" )
341 #print "len hostNames = ", len( hostNames )
342 #print "len devices = ", len( devices )
kelvin-onlab90b6b042015-05-18 20:57:13 -0700343 return main.FALSE
344 if ports:
345 if len( ports ) != len( devices ):
346 main.log.error( "Ports and devices does " +
347 "not have the same length" )
kelvin-onlab08900012015-05-20 14:30:44 -0700348 #print "len devices = ", len( devices )
349 #print "len ports = ", len( ports )
kelvin-onlab90b6b042015-05-18 20:57:13 -0700350 return main.FALSE
kelvin-onlab08900012015-05-20 14:30:44 -0700351 for i in range( len( devices ) ):
352 macsDict[ devices[ i ] ] = macs[ i ]
kelvin-onlab90b6b042015-05-18 20:57:13 -0700353 else:
354 main.log.info( "Device Ports are not specified" )
355 elif hostNames and not devices and main.hostsData:
kelvin-onlab08900012015-05-20 14:30:44 -0700356 devices = []
kelvin-onlab90b6b042015-05-18 20:57:13 -0700357 main.log.info( "singleToMultiIntent function is using main.hostsData" )
kelvin-onlab08900012015-05-20 14:30:44 -0700358 for host in hostNames:
359 print main.hostsData.get( host ).get( 'location' )
360 devices.append( main.hostsData.get( host ).get( 'location' ) )
361 macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \
362 main.hostsData.get( host ).get( 'mac' )
363 ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \
364 main.hostsData.get( host ).get( 'ipAddresses' )
kelvin-onlab90b6b042015-05-18 20:57:13 -0700365 print main.hostsData
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700366
kelvin-onlabf0594d72015-05-19 17:25:12 -0700367
kelvin-onlab08900012015-05-20 14:30:44 -0700368 print 'host names = ', hostNames
369
370 print 'devices = ', devices
kelvin-onlabf0594d72015-05-19 17:25:12 -0700371
372 print "macsDict = ", macsDict
373
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700374 pingResult = main.TRUE
375 intentResult = main.TRUE
kelvin-onlabf0594d72015-05-19 17:25:12 -0700376 removeIntentResult = main.TRUE
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700377 flowResult = main.TRUE
378 topoResult = main.TRUE
379 linkDownResult = main.TRUE
380 linkUpResult = main.TRUE
381
kelvin-onlabf0594d72015-05-19 17:25:12 -0700382 devicesCopy = copy.copy( devices )
383 if ports:
384 portsCopy = copy.copy( ports )
385 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700386 # Adding bidirectional point intents
kelvin-onlabf0594d72015-05-19 17:25:12 -0700387 for i in range( len( devices ) ):
388 ingressDevice = devicesCopy[ i ]
389 egressDeviceList = copy.copy( devicesCopy )
390 egressDeviceList.remove( ingressDevice )
391 if ports:
392 portIngress = portsCopy[ i ]
393 portEgressList = copy.copy( portsCopy )
394 del portEgressList[ i ]
395 else:
396 portIngress = ""
397 portEgressList = None
kelvin-onlab08900012015-05-20 14:30:44 -0700398 if not macsDict:
399 srcMac = ""
400 else:
401 srcMac = macsDict[ ingressDevice ]
402 if srcMac == None:
403 srcMac = ""
404
kelvin-onlabf0594d72015-05-19 17:25:12 -0700405 intentsId.append( main.CLIs[ 0 ].addSinglepointToMultipointIntent(
406 ingressDevice=ingressDevice,
407 egressDeviceList=egressDeviceList,
408 portIngress=portIngress,
409 portEgressList=portEgressList,
kelvin-onlab90b6b042015-05-18 20:57:13 -0700410 ethType=ethType,
kelvin-onlab08900012015-05-20 14:30:44 -0700411 ethSrc=srcMac,
kelvin-onlab90b6b042015-05-18 20:57:13 -0700412 bandwidth=bandwidth,
413 lambdaAlloc=lambdaAlloc,
414 ipProto=ipProto,
kelvin-onlabf0594d72015-05-19 17:25:12 -0700415 ipSrc="",
416 ipDst="",
417 tcpSrc="",
418 tcpDst="" ) )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700419
kelvin-onlab08900012015-05-20 14:30:44 -0700420 pingResult = pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700421
422 # Check intents state
kelvin-onlabf0594d72015-05-19 17:25:12 -0700423 time.sleep( 30 )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700424 intentResult = checkIntentState( main, intentsId )
425
426 # Verify flows
427 checkFlowsState( main )
428
429 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700430 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700431 # Ping hosts again...
kelvin-onlab08900012015-05-20 14:30:44 -0700432 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700433 time.sleep( 5 )
434
kelvin-onlabf0594d72015-05-19 17:25:12 -0700435 # Test rerouting if these variables exist
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700436 if sw1 and sw2 and expectedLink:
437 # link down
kelvin-onlabf0594d72015-05-19 17:25:12 -0700438 linkDownResult = link( main, sw1, sw2, "down" )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700439 intentResult = intentResult and checkIntentState( main, intentsId )
440
441 # Verify flows
442 checkFlowsState( main )
443
444 # Check OnosTopology
445 topoResult = checkTopology( main, expectedLink )
446
447 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700448 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700449
450 intentResult = checkIntentState( main, intentsId )
451
kelvin-onlabf0594d72015-05-19 17:25:12 -0700452 # Checks ONOS state in link down
453 if linkDownResult and topoResult and pingResult and intentResult:
454 main.log.info( itemName + ": Successfully brought link down" )
455 else:
kelvin-onlab08900012015-05-20 14:30:44 -0700456 main.log.error( itemName + ": Failed to bring link down" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700457
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700458 # link up
kelvin-onlabf0594d72015-05-19 17:25:12 -0700459 linkUpResult = link( main, sw1, sw2, "up" )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700460 time.sleep( 5 )
461
462 # Verify flows
463 checkFlowsState( main )
464
465 # Check OnosTopology
kelvin-onlabf0594d72015-05-19 17:25:12 -0700466 topoResult = checkTopology( main, main.numLinks )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700467
468 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700469 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700470
kelvin-onlabf0594d72015-05-19 17:25:12 -0700471 intentResult = checkIntentState( main, intentsId )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700472
kelvin-onlabf0594d72015-05-19 17:25:12 -0700473 # Checks ONOS state in link up
474 if linkUpResult and topoResult and pingResult and intentResult:
475 main.log.info( itemName + ": Successfully brought link back up" )
476 else:
kelvin-onlab08900012015-05-20 14:30:44 -0700477 main.log.error( itemName + ": Failed to bring link back up" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700478
479 # Remove all intents
480 removeIntentResult = removeAllIntents( main, intentsId )
481
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700482 stepResult = pingResult and linkDownResult and linkUpResult \
kelvin-onlabf0594d72015-05-19 17:25:12 -0700483 and intentResult and removeIntentResult
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700484
485 return stepResult
486
kelvin-onlab08900012015-05-20 14:30:44 -0700487def pingallHosts( main, hostList, pingType="ipv4" ):
kelvin-onlabf0594d72015-05-19 17:25:12 -0700488 # Ping all host in the hosts list variable
kelvin-onlab08900012015-05-20 14:30:44 -0700489 print "Pinging : ", hostList
kelvin-onlabf0594d72015-05-19 17:25:12 -0700490 pingResult = main.TRUE
kelvin-onlab08900012015-05-20 14:30:44 -0700491 pingResult = main.Mininet1.pingallHosts( hostList, pingType )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700492 return pingResult
493
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700494def getHostsData( main ):
kelvin-onlabe5239e52015-05-13 14:46:45 -0700495 """
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700496 Use fwd app and pingall to discover all the hosts
kelvin-onlabe5239e52015-05-13 14:46:45 -0700497 """
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700498 """
499 hosts json format:
500 """
501 import json
502 activateResult = main.TRUE
503 appCheck = main.TRUE
kelvin-onlab08900012015-05-20 14:30:44 -0700504 getDataResult = main.TRUE
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700505 main.log.info( "Activating reactive forwarding app " )
506 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
507
508 for i in range( main.numCtrls ):
509 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
kelvin-onlabf0594d72015-05-19 17:25:12 -0700510 if appCheck != main.TRUE:
kelvin-onlab08900012015-05-20 14:30:44 -0700511 main.log.warn( main.CLIs[ i ].apps() )
512 main.log.warn( main.CLIs[ i ].appIDs() )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700513
514 pingResult = main.Mininet1.pingall()
515 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
516 hosts = main.Mininet1.getHosts()
517 for host in hosts:
518 main.hostsData[ host ] = {}
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700519 main.hostsData[ host ][ 'mac' ] = \
520 main.Mininet1.getMacAddress( host ).upper()
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700521 for hostj in hostsJson:
522 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
523 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
524 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
525 main.hostsData[ host ][ 'location' ] = \
526 hostj[ 'location' ][ 'elementId' ] + '/' + \
527 hostj[ 'location' ][ 'port' ]
528 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
529
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700530 main.log.info( "Deactivating reactive forwarding app " )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700531 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
kelvin-onlab08900012015-05-20 14:30:44 -0700532 if activateResult and deactivateResult and main.hostsData:
kelvin-onlabf0594d72015-05-19 17:25:12 -0700533 main.log.info( "Successfully used fwd app to discover hosts " )
kelvin-onlab08900012015-05-20 14:30:44 -0700534 getDataResult = main.TRUE
kelvin-onlabf0594d72015-05-19 17:25:12 -0700535 else:
536 main.log.info( "Failed to use fwd app to discover hosts " )
kelvin-onlab08900012015-05-20 14:30:44 -0700537 getDataResult = main.FALSE
kelvin-onlabf0594d72015-05-19 17:25:12 -0700538
kelvin-onlab08900012015-05-20 14:30:44 -0700539 print main.hostsData
kelvin-onlabf0594d72015-05-19 17:25:12 -0700540
kelvin-onlab08900012015-05-20 14:30:44 -0700541 return getDataResult
kelvin-onlabe5239e52015-05-13 14:46:45 -0700542
543def checkTopology( main, expectedLink ):
544 statusResult = main.TRUE
545 # Check onos topology
546 main.log.info( itemName + ": Checking ONOS topology " )
547
548 for i in range( main.numCtrls ):
549 topologyResult = main.CLIs[ i ].topology()
550 statusResult = main.ONOSbench.checkStatus( topologyResult,
551 main.numSwitch,
552 expectedLink )\
553 and statusResult
554 if not statusResult:
555 main.log.info( itemName + ": Topology mismatch" )
556 else:
557 main.log.info( itemName + ": Topology match" )
558 return statusResult
559
560def checkIntentState( main, intentsId ):
561
562 main.log.info( itemName + ": Check host intents state" )
563 for i in range( main.numCtrls ):
564 intentResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
565 if not intentResult:
566 main.log.info( itemName + ": Check host intents state again")
567 for i in range( main.numCtrls ):
568 intentResult = main.CLIs[ i ].checkIntentState(
569 intentsId=intentsId )
570 return intentResult
571
572def checkFlowsState( main ):
573
574 main.log.info( itemName + ": Check flows state" )
575 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState()
576 return checkFlowsResult
577
kelvin-onlabf0594d72015-05-19 17:25:12 -0700578def link( main, sw1, sw2, option):
kelvin-onlabe5239e52015-05-13 14:46:45 -0700579
kelvin-onlabf0594d72015-05-19 17:25:12 -0700580 # link down
581 main.log.info( itemName + ": Bring link " + option + "between " +
582 sw1 + " and " + sw2 )
583 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
584 return linkResult
585
586def removeAllIntents( main, intentsId ):
587 """
588 Remove all intents in the intentsId
589 """
590 import time
591 intentsRemaining = []
592 removeIntentResult = main.TRUE
593 # Remove intents
594 for intent in intentsId:
595 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
596
597 time.sleep( 5 )
598 # Checks if there is remaining intents using intents()
599 intentsRemaining = main.CLIs[ 0 ].intents()
kelvin-onlabf0594d72015-05-19 17:25:12 -0700600 # If there is remianing intents then remove intents should fail
kelvin-onlab08900012015-05-20 14:30:44 -0700601 if intentsRemaining == []:
kelvin-onlabf0594d72015-05-19 17:25:12 -0700602 main.log.info( itemName + ": There are " +
603 str( len( intentsRemaining ) ) + " intents remaining, "
604 + "failed to remove all the intents " )
605 removeIntentResult = main.FALSE
kelvin-onlab08900012015-05-20 14:30:44 -0700606 main.log.info( intentsRemaining )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700607 else:
608 main.log.info( itemName + ": There are no intents remaining, " +
609 "successfully removed all the intents." )
610 removeIntentResult = main.TRUE
611 return removeIntentResult