blob: 1d7f2270d58d45e2fbd5877138567f349bd6f5ea [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
kelvin-onlab381b34c2015-05-21 09:21:06 -07004 Author: kelvin@onlab.us
kelvin-onlabe5239e52015-05-13 14:46:45 -07005"""
6def __init__( self ):
7 self.default = ''
8
kelvin-onlab2ccad6e2015-05-18 10:36:54 -07009def hostIntent( main,
kelvin-onlabf0594d72015-05-19 17:25:12 -070010 name,
11 host1,
12 host2,
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070013 host1Id="",
14 host2Id="",
15 mac1="",
16 mac2="",
17 vlan1="-1",
18 vlan2="-1",
19 sw1="",
20 sw2="",
21 expectedLink=0 ):
kelvin-onlabe5239e52015-05-13 14:46:45 -070022 """
kelvin-onlab381b34c2015-05-21 09:21:06 -070023 Description:
24 Verify add-host-intent
25 Steps:
26 - Discover hosts
27 - Add host intents
28 - Check intents
29 - Verify flows
30 - Ping hosts
31 - Reroute
32 - Link down
33 - Verify flows
34 - Check topology
35 - Ping hosts
36 - Link up
37 - Verify flows
38 - Check topology
39 - Ping hosts
40 - Remove intents
41 Required:
42 name - Type of host intent to add eg. IPV4 | VLAN | Dualstack
43 host1 - Name of first host
44 host2 - Name of second host
45 Optional:
46 host1Id - ONOS id of the first host eg. 00:00:00:00:00:01/-1
47 host2Id - ONOS id of the second host
48 mac1 - Mac address of first host
49 mac2 - Mac address of the second host
50 vlan1 - Vlan tag of first host, defaults to -1
51 vlan2 - Vlan tag of second host, defaults to -1
52 sw1 - First switch to bring down & up for rerouting purpose
53 sw2 - Second switch to bring down & up for rerouting purpose
54 expectedLink - Expected link when the switches are down, it should
55 be two links lower than the links before the two
56 switches are down
kelvin-onlabe5239e52015-05-13 14:46:45 -070057 """
58 import time
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070059
60 # Assert variables
61 assert main, "There is no main variable"
62 assert name, "variable name is empty"
63 assert host1 and host2, "You must specify hosts"
64
kelvin-onlabe5239e52015-05-13 14:46:45 -070065 global itemName
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070066 itemName = name
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070067 h1Id = host1Id
68 h2Id = host2Id
69 h1Mac = mac1
70 h2Mac = mac2
71 vlan1 = vlan1
72 vlan2 = vlan2
kelvin-onlab08900012015-05-20 14:30:44 -070073 hostNames = [ host1 , host2 ]
kelvin-onlabe5239e52015-05-13 14:46:45 -070074 intentsId = []
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070075 stepResult = main.TRUE
kelvin-onlabe5239e52015-05-13 14:46:45 -070076 pingResult = main.TRUE
77 intentResult = main.TRUE
kelvin-onlabf0594d72015-05-19 17:25:12 -070078 removeIntentResult = main.TRUE
kelvin-onlabe5239e52015-05-13 14:46:45 -070079 flowResult = main.TRUE
80 topoResult = main.TRUE
81 linkDownResult = main.TRUE
82 linkUpResult = main.TRUE
83
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070084 if main.hostsData:
85 if not h1Mac:
kelvin-onlab08900012015-05-20 14:30:44 -070086 h1Mac = main.hostsData[ host1 ][ 'mac' ]
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070087 if not h2Mac:
kelvin-onlab08900012015-05-20 14:30:44 -070088 h2Mac = main.hostsData[ host2 ][ 'mac' ]
89 if main.hostsData[ host1 ][ 'vlan' ] != '-1':
90 vlan1 = main.hostsData[ host1 ][ 'vlan' ]
91 if main.hostsData[ host2 ][ 'vlan' ] != '-1':
92 vlan2 = main.hostsData[ host2 ][ 'vlan' ]
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070093 if not h1Id:
kelvin-onlab08900012015-05-20 14:30:44 -070094 h1Id = main.hostsData[ host1 ][ 'id' ]
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070095 if not h2Id:
kelvin-onlab08900012015-05-20 14:30:44 -070096 h2Id = main.hostsData[ host2 ][ 'id' ]
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070097
98 assert h1Id and h2Id, "You must specify host IDs"
99 if not ( h1Id and h2Id ):
100 main.log.info( "There are no host IDs" )
101 return main.FALSE
102
kelvin-onlabe5239e52015-05-13 14:46:45 -0700103 # Discover hosts using arping
104 main.log.info( itemName + ": Discover host using arping" )
kelvin-onlab08900012015-05-20 14:30:44 -0700105 main.Mininet1.arping( host=host1 )
106 main.Mininet1.arping( host=host2 )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700107 host1 = main.CLIs[ 0 ].getHost( mac=h1Mac )
108 host2 = main.CLIs[ 0 ].getHost( mac=h2Mac )
109
110 # Adding host intents
111 main.log.info( itemName + ": Adding host intents" )
112 intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne=h1Id,
113 hostIdTwo=h2Id )
114 intentsId.append( intent1 )
115 time.sleep( 5 )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700116
117 # Check intents state
kelvin-onlabf0594d72015-05-19 17:25:12 -0700118 time.sleep( 30 )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700119 intentResult = checkIntentState( main, intentsId )
120
kelvin-onlab381b34c2015-05-21 09:21:06 -0700121 # Check intents state again if first check fails...
122 if not intentResult:
123 intentResult = checkIntentState( main, intentsId )
124
kelvin-onlabe5239e52015-05-13 14:46:45 -0700125 # Verify flows
126 checkFlowsState( main )
127
128 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700129 firstPingResult = pingallHosts( main, hostNames )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700130 if not firstPingResult:
kelvin-onlab08900012015-05-20 14:30:44 -0700131 main.log.debug( "First ping failed, there must be" +
kelvin-onlabf0594d72015-05-19 17:25:12 -0700132 " something wrong with ONOS performance" )
133
kelvin-onlabe5239e52015-05-13 14:46:45 -0700134 # Ping hosts again...
kelvin-onlab08900012015-05-20 14:30:44 -0700135 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700136 time.sleep( 5 )
137
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700138 # Test rerouting if these variables exist
139 if sw1 and sw2 and expectedLink:
140 # link down
kelvin-onlabf0594d72015-05-19 17:25:12 -0700141 linkDownResult = link( main, sw1, sw2, "down" )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700142 intentResult = intentResult and checkIntentState( main, intentsId )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700143
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700144 # Verify flows
145 checkFlowsState( main )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700146
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700147 # Check OnosTopology
148 topoResult = checkTopology( main, expectedLink )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700149
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700150 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700151 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700152
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700153 intentResult = checkIntentState( main, intentsId )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700154
kelvin-onlabf0594d72015-05-19 17:25:12 -0700155 # Checks ONOS state in link down
156 if linkDownResult and topoResult and pingResult and intentResult:
157 main.log.info( itemName + ": Successfully brought link down" )
158 else:
kelvin-onlab08900012015-05-20 14:30:44 -0700159 main.log.error( itemName + ": Failed to bring link down" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700160
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700161 # link up
kelvin-onlabf0594d72015-05-19 17:25:12 -0700162 linkUpResult = link( main, sw1, sw2, "up" )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700163 time.sleep( 5 )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700164
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700165 # Verify flows
166 checkFlowsState( main )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700167
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700168 # Check OnosTopology
kelvin-onlabf0594d72015-05-19 17:25:12 -0700169 topoResult = checkTopology( main, main.numLinks )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700170
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700171 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700172 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700173
kelvin-onlabf0594d72015-05-19 17:25:12 -0700174 intentResult = checkIntentState( main, intentsId )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700175
kelvin-onlabf0594d72015-05-19 17:25:12 -0700176 # Checks ONOS state in link up
177 if linkUpResult and topoResult and pingResult and intentResult:
178 main.log.info( itemName + ": Successfully brought link back up" )
179 else:
kelvin-onlab08900012015-05-20 14:30:44 -0700180 main.log.error( itemName + ": Failed to bring link back up" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700181
182 # Remove all intents
183 removeIntentResult = removeAllIntents( main, intentsId )
184
kelvin-onlabe5239e52015-05-13 14:46:45 -0700185 stepResult = pingResult and linkDownResult and linkUpResult \
kelvin-onlabf0594d72015-05-19 17:25:12 -0700186 and intentResult and removeIntentResult
kelvin-onlabe5239e52015-05-13 14:46:45 -0700187
188 return stepResult
189
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700190def pointIntent( main,
kelvin-onlabf0594d72015-05-19 17:25:12 -0700191 name,
192 host1,
193 host2,
kelvin-onlab381b34c2015-05-21 09:21:06 -0700194 deviceId1="",
195 deviceId2="",
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700196 port1="",
197 port2="",
198 ethType="",
199 mac1="",
200 mac2="",
201 bandwidth="",
202 lambdaAlloc=False,
203 ipProto="",
204 ip1="",
205 ip2="",
206 tcp1="",
207 tcp2="",
208 sw1="",
209 sw2="",
210 expectedLink=0 ):
kelvin-onlab381b34c2015-05-21 09:21:06 -0700211
kelvin-onlabe5239e52015-05-13 14:46:45 -0700212 """
kelvin-onlab381b34c2015-05-21 09:21:06 -0700213 Description:
214 Verify add-point-intent
215 Steps:
216 - Get device ids | ports
217 - Add point intents
218 - Check intents
219 - Verify flows
220 - Ping hosts
221 - Reroute
222 - Link down
223 - Verify flows
224 - Check topology
225 - Ping hosts
226 - Link up
227 - Verify flows
228 - Check topology
229 - Ping hosts
230 - Remove intents
231 Required:
232 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
233 host1 - Name of first host
234 host2 - Name of second host
235 Optional:
236 deviceId1 - ONOS device id of the first switch, the same as the
237 location of the first host eg. of:0000000000000001/1,
238 located at device 1 port 1
239 deviceId2 - ONOS device id of the second switch
240 port1 - The port number where the first host is attached
241 port2 - The port number where the second host is attached
242 ethType - Ethernet type eg. IPV4, IPV6
243 mac1 - Mac address of first host
244 mac2 - Mac address of the second host
245 bandwidth - Bandwidth capacity
246 lambdaAlloc - Allocate lambda, defaults to False
247 ipProto - IP protocol
248 ip1 - IP address of first host
249 ip2 - IP address of second host
250 tcp1 - TCP port of first host
251 tcp2 - TCP port of second host
252 sw1 - First switch to bring down & up for rerouting purpose
253 sw2 - Second switch to bring down & up for rerouting purpose
254 expectedLink - Expected link when the switches are down, it should
255 be two links lower than the links before the two
256 switches are down
kelvin-onlabe5239e52015-05-13 14:46:45 -0700257 """
kelvin-onlab381b34c2015-05-21 09:21:06 -0700258
kelvin-onlabe5239e52015-05-13 14:46:45 -0700259 import time
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700260 assert main, "There is no main variable"
261 assert name, "variable name is empty"
262 assert host1 and host2, "You must specify hosts"
263
kelvin-onlabe5239e52015-05-13 14:46:45 -0700264 global itemName
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700265 itemName = name
kelvin-onlab08900012015-05-20 14:30:44 -0700266 host1 = host1
267 host2 = host2
268 hostNames = [ host1, host2 ]
kelvin-onlabe5239e52015-05-13 14:46:45 -0700269 intentsId = []
kelvin-onlabb2235602015-05-13 17:51:06 -0700270
kelvin-onlabe5239e52015-05-13 14:46:45 -0700271 pingResult = main.TRUE
272 intentResult = main.TRUE
kelvin-onlabf0594d72015-05-19 17:25:12 -0700273 removeIntentResult = main.TRUE
kelvin-onlabe5239e52015-05-13 14:46:45 -0700274 flowResult = main.TRUE
275 topoResult = main.TRUE
276 linkDownResult = main.TRUE
277 linkUpResult = main.TRUE
278
kelvin-onlabb2235602015-05-13 17:51:06 -0700279 # Adding bidirectional point intents
kelvin-onlabf0594d72015-05-19 17:25:12 -0700280 main.log.info( itemName + ": Adding point intents" )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700281 intent1 = main.CLIs[ 0 ].addPointIntent( ingressDevice=deviceId1,
282 egressDevice=deviceId2,
283 portIngress=port1,
284 portEgress=port2,
kelvin-onlabb2235602015-05-13 17:51:06 -0700285 ethType=ethType,
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700286 ethSrc=mac1,
287 ethDst=mac2,
kelvin-onlabb2235602015-05-13 17:51:06 -0700288 bandwidth=bandwidth,
289 lambdaAlloc=lambdaAlloc,
290 ipProto=ipProto,
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700291 ipSrc=ip1,
292 ipDst=ip2,
293 tcpSrc=tcp1,
294 tcpDst=tcp2 )
kelvin-onlabb2235602015-05-13 17:51:06 -0700295
kelvin-onlabe5239e52015-05-13 14:46:45 -0700296 intentsId.append( intent1 )
297 time.sleep( 5 )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700298 intent2 = main.CLIs[ 0 ].addPointIntent( ingressDevice=deviceId2,
299 egressDevice=deviceId1,
300 portIngress=port2,
301 portEgress=port1,
kelvin-onlabb2235602015-05-13 17:51:06 -0700302 ethType=ethType,
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700303 ethSrc=mac2,
304 ethDst=mac1,
kelvin-onlabb2235602015-05-13 17:51:06 -0700305 bandwidth=bandwidth,
306 lambdaAlloc=lambdaAlloc,
307 ipProto=ipProto,
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700308 ipSrc=ip2,
309 ipDst=ip1,
310 tcpSrc=tcp2,
311 tcpDst=tcp1 )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700312 intentsId.append( intent2 )
313
314 # Check intents state
kelvin-onlabf0594d72015-05-19 17:25:12 -0700315 time.sleep( 30 )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700316 intentResult = checkIntentState( main, intentsId )
317
kelvin-onlab381b34c2015-05-21 09:21:06 -0700318 # Check intents state again if first check fails...
319 if not intentResult:
320 intentResult = checkIntentState( main, intentsId )
321
kelvin-onlabe5239e52015-05-13 14:46:45 -0700322 # Verify flows
323 checkFlowsState( main )
324
325 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700326 firstPingResult = pingallHosts( main, hostNames )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700327 if not firstPingResult:
kelvin-onlab08900012015-05-20 14:30:44 -0700328 main.log.debug( "First ping failed, there must be" +
kelvin-onlabf0594d72015-05-19 17:25:12 -0700329 " something wrong with ONOS performance" )
330
kelvin-onlabe5239e52015-05-13 14:46:45 -0700331 # Ping hosts again...
kelvin-onlab08900012015-05-20 14:30:44 -0700332 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700333 time.sleep( 5 )
334
kelvin-onlabf0594d72015-05-19 17:25:12 -0700335 # Test rerouting if these variables exist
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700336 if sw1 and sw2 and expectedLink:
337 # link down
kelvin-onlabf0594d72015-05-19 17:25:12 -0700338 linkDownResult = link( main, sw1, sw2, "down" )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700339 intentResult = intentResult and checkIntentState( main, intentsId )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700340
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700341 # Verify flows
342 checkFlowsState( main )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700343
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700344 # Check OnosTopology
345 topoResult = checkTopology( main, expectedLink )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700346
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700347 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700348 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700349
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700350 intentResult = checkIntentState( main, intentsId )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700351
kelvin-onlabf0594d72015-05-19 17:25:12 -0700352 # Checks ONOS state in link down
353 if linkDownResult and topoResult and pingResult and intentResult:
354 main.log.info( itemName + ": Successfully brought link down" )
355 else:
kelvin-onlab08900012015-05-20 14:30:44 -0700356 main.log.error( itemName + ": Failed to bring link down" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700357
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700358 # link up
kelvin-onlabf0594d72015-05-19 17:25:12 -0700359 linkUpResult = link( main, sw1, sw2, "up" )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700360 time.sleep( 5 )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700361
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700362 # Verify flows
363 checkFlowsState( main )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700364
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700365 # Check OnosTopology
kelvin-onlabf0594d72015-05-19 17:25:12 -0700366 topoResult = checkTopology( main, main.numLinks )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700367
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700368 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700369 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700370
kelvin-onlabf0594d72015-05-19 17:25:12 -0700371 intentResult = checkIntentState( main, intentsId )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700372
kelvin-onlabf0594d72015-05-19 17:25:12 -0700373 # Checks ONOS state in link up
374 if linkUpResult and topoResult and pingResult and intentResult:
375 main.log.info( itemName + ": Successfully brought link back up" )
376 else:
kelvin-onlab08900012015-05-20 14:30:44 -0700377 main.log.error( itemName + ": Failed to bring link back up" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700378
379 # Remove all intents
380 removeIntentResult = removeAllIntents( main, intentsId )
381
kelvin-onlabe5239e52015-05-13 14:46:45 -0700382 stepResult = pingResult and linkDownResult and linkUpResult \
kelvin-onlabf0594d72015-05-19 17:25:12 -0700383 and intentResult and removeIntentResult
kelvin-onlabe5239e52015-05-13 14:46:45 -0700384
385 return stepResult
386
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700387def singleToMultiIntent( main,
kelvin-onlabf0594d72015-05-19 17:25:12 -0700388 name,
389 hostNames,
kelvin-onlab90b6b042015-05-18 20:57:13 -0700390 devices="",
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700391 ports=None,
392 ethType="",
393 macs=None,
394 bandwidth="",
395 lambdaAlloc=False,
396 ipProto="",
397 ipAddresses="",
398 tcp="",
399 sw1="",
400 sw2="",
401 expectedLink=0 ):
402 """
kelvin-onlab381b34c2015-05-21 09:21:06 -0700403 Verify Single to Multi Point intents
404 NOTE:If main.hostsData is not defined, variables data should be passed in the
kelvin-onlabf0594d72015-05-19 17:25:12 -0700405 same order index wise. All devices in the list should have the same
406 format, either all the devices have its port or it doesn't.
kelvin-onlab90b6b042015-05-18 20:57:13 -0700407 eg. hostName = [ 'h1', 'h2' ,.. ]
408 devices = [ 'of:0000000000000001', 'of:0000000000000002', ...]
409 ports = [ '1', '1', ..]
410 ...
kelvin-onlab381b34c2015-05-21 09:21:06 -0700411 Description:
kelvin-onlab583fcb52015-05-21 13:10:46 -0700412 Verify add-single-to-multi-intent iterates through the list of given
413 host | devices and add intents
kelvin-onlab381b34c2015-05-21 09:21:06 -0700414 Steps:
415 - Get device ids | ports
416 - Add single to multi point intents
417 - Check intents
418 - Verify flows
419 - Ping hosts
420 - Reroute
421 - Link down
422 - Verify flows
423 - Check topology
424 - Ping hosts
425 - Link up
426 - Verify flows
427 - Check topology
428 - Ping hosts
429 - Remove intents
430 Required:
431 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
432 hostNames - List of host names
433 Optional:
434 devices - List of device ids in the same order as the hosts
435 in hostNames
436 ports - List of port numbers in the same order as the device in
437 devices
438 ethType - Ethernet type eg. IPV4, IPV6
439 macs - List of hosts mac address in the same order as the hosts in
440 hostNames
441 bandwidth - Bandwidth capacity
442 lambdaAlloc - Allocate lambda, defaults to False
443 ipProto - IP protocol
444 ipAddresses - IP addresses of host in the same order as the hosts in
445 hostNames
446 tcp - TCP ports in the same order as the hosts in hostNames
447 sw1 - First switch to bring down & up for rerouting purpose
448 sw2 - Second switch to bring down & up for rerouting purpose
449 expectedLink - Expected link when the switches are down, it should
450 be two links lower than the links before the two
451 switches are down
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700452 """
kelvin-onlab381b34c2015-05-21 09:21:06 -0700453
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700454 import time
kelvin-onlabf0594d72015-05-19 17:25:12 -0700455 import copy
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700456 assert main, "There is no main variable"
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700457 assert hostNames, "You must specify hosts"
458 assert devices or main.hostsData, "You must specify devices"
459
460 global itemName
461 itemName = name
kelvin-onlab90b6b042015-05-18 20:57:13 -0700462 tempHostsData = {}
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700463 intentsId = []
464
kelvin-onlab08900012015-05-20 14:30:44 -0700465 macsDict = {}
466 ipDict = {}
kelvin-onlab90b6b042015-05-18 20:57:13 -0700467 if hostNames and devices:
468 if len( hostNames ) != len( devices ):
kelvin-onlab08900012015-05-20 14:30:44 -0700469 main.log.debug( "hosts and devices does not have the same length" )
470 #print "len hostNames = ", len( hostNames )
471 #print "len devices = ", len( devices )
kelvin-onlab90b6b042015-05-18 20:57:13 -0700472 return main.FALSE
473 if ports:
474 if len( ports ) != len( devices ):
475 main.log.error( "Ports and devices does " +
476 "not have the same length" )
kelvin-onlab08900012015-05-20 14:30:44 -0700477 #print "len devices = ", len( devices )
478 #print "len ports = ", len( ports )
kelvin-onlab90b6b042015-05-18 20:57:13 -0700479 return main.FALSE
480 else:
481 main.log.info( "Device Ports are not specified" )
kelvin-onlabf2ec6e02015-05-27 14:15:28 -0700482 if macs:
483 for i in range( len( devices ) ):
484 macsDict[ devices[ i ] ] = macs[ i ]
485
kelvin-onlab90b6b042015-05-18 20:57:13 -0700486 elif hostNames and not devices and main.hostsData:
kelvin-onlab08900012015-05-20 14:30:44 -0700487 devices = []
kelvin-onlab90b6b042015-05-18 20:57:13 -0700488 main.log.info( "singleToMultiIntent function is using main.hostsData" )
kelvin-onlab08900012015-05-20 14:30:44 -0700489 for host in hostNames:
kelvin-onlab08900012015-05-20 14:30:44 -0700490 devices.append( main.hostsData.get( host ).get( 'location' ) )
491 macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \
492 main.hostsData.get( host ).get( 'mac' )
493 ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \
494 main.hostsData.get( host ).get( 'ipAddresses' )
kelvin-onlab381b34c2015-05-21 09:21:06 -0700495 #print main.hostsData
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700496
kelvin-onlab381b34c2015-05-21 09:21:06 -0700497 #print 'host names = ', hostNames
498 #print 'devices = ', devices
499 #print "macsDict = ", macsDict
kelvin-onlabf0594d72015-05-19 17:25:12 -0700500
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700501 pingResult = main.TRUE
502 intentResult = main.TRUE
kelvin-onlabf0594d72015-05-19 17:25:12 -0700503 removeIntentResult = main.TRUE
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700504 flowResult = main.TRUE
505 topoResult = main.TRUE
506 linkDownResult = main.TRUE
507 linkUpResult = main.TRUE
508
kelvin-onlabf0594d72015-05-19 17:25:12 -0700509 devicesCopy = copy.copy( devices )
510 if ports:
511 portsCopy = copy.copy( ports )
512 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700513 # Adding bidirectional point intents
kelvin-onlabf0594d72015-05-19 17:25:12 -0700514 for i in range( len( devices ) ):
515 ingressDevice = devicesCopy[ i ]
516 egressDeviceList = copy.copy( devicesCopy )
517 egressDeviceList.remove( ingressDevice )
518 if ports:
519 portIngress = portsCopy[ i ]
520 portEgressList = copy.copy( portsCopy )
521 del portEgressList[ i ]
522 else:
523 portIngress = ""
524 portEgressList = None
kelvin-onlab08900012015-05-20 14:30:44 -0700525 if not macsDict:
526 srcMac = ""
527 else:
528 srcMac = macsDict[ ingressDevice ]
529 if srcMac == None:
kelvin-onlabc751ab42015-05-21 14:09:39 -0700530 main.log.debug( "There is no MAC in device - " + ingressDevice )
kelvin-onlab08900012015-05-20 14:30:44 -0700531 srcMac = ""
532
kelvin-onlabf0594d72015-05-19 17:25:12 -0700533 intentsId.append( main.CLIs[ 0 ].addSinglepointToMultipointIntent(
534 ingressDevice=ingressDevice,
535 egressDeviceList=egressDeviceList,
536 portIngress=portIngress,
537 portEgressList=portEgressList,
kelvin-onlab90b6b042015-05-18 20:57:13 -0700538 ethType=ethType,
kelvin-onlab08900012015-05-20 14:30:44 -0700539 ethSrc=srcMac,
kelvin-onlab90b6b042015-05-18 20:57:13 -0700540 bandwidth=bandwidth,
541 lambdaAlloc=lambdaAlloc,
542 ipProto=ipProto,
kelvin-onlabf0594d72015-05-19 17:25:12 -0700543 ipSrc="",
544 ipDst="",
545 tcpSrc="",
546 tcpDst="" ) )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700547
kelvin-onlab08900012015-05-20 14:30:44 -0700548 pingResult = pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700549
550 # Check intents state
kelvin-onlabf0594d72015-05-19 17:25:12 -0700551 time.sleep( 30 )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700552 intentResult = checkIntentState( main, intentsId )
553
kelvin-onlab381b34c2015-05-21 09:21:06 -0700554 # Check intents state again if first check fails...
555 if not intentResult:
556 intentResult = checkIntentState( main, intentsId )
557
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700558 # Verify flows
559 checkFlowsState( main )
560
561 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700562 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700563 # Ping hosts again...
kelvin-onlab08900012015-05-20 14:30:44 -0700564 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700565 time.sleep( 5 )
566
kelvin-onlabf0594d72015-05-19 17:25:12 -0700567 # Test rerouting if these variables exist
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700568 if sw1 and sw2 and expectedLink:
569 # link down
kelvin-onlabf0594d72015-05-19 17:25:12 -0700570 linkDownResult = link( main, sw1, sw2, "down" )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700571 intentResult = intentResult and checkIntentState( main, intentsId )
572
573 # Verify flows
574 checkFlowsState( main )
575
576 # Check OnosTopology
577 topoResult = checkTopology( main, expectedLink )
578
579 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700580 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700581
582 intentResult = checkIntentState( main, intentsId )
583
kelvin-onlabf0594d72015-05-19 17:25:12 -0700584 # Checks ONOS state in link down
585 if linkDownResult and topoResult and pingResult and intentResult:
586 main.log.info( itemName + ": Successfully brought link down" )
587 else:
kelvin-onlab08900012015-05-20 14:30:44 -0700588 main.log.error( itemName + ": Failed to bring link down" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700589
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700590 # link up
kelvin-onlabf0594d72015-05-19 17:25:12 -0700591 linkUpResult = link( main, sw1, sw2, "up" )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700592 time.sleep( 5 )
593
594 # Verify flows
595 checkFlowsState( main )
596
597 # Check OnosTopology
kelvin-onlabf0594d72015-05-19 17:25:12 -0700598 topoResult = checkTopology( main, main.numLinks )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700599
600 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700601 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700602
kelvin-onlabf0594d72015-05-19 17:25:12 -0700603 intentResult = checkIntentState( main, intentsId )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700604
kelvin-onlabf0594d72015-05-19 17:25:12 -0700605 # Checks ONOS state in link up
606 if linkUpResult and topoResult and pingResult and intentResult:
607 main.log.info( itemName + ": Successfully brought link back up" )
608 else:
kelvin-onlab08900012015-05-20 14:30:44 -0700609 main.log.error( itemName + ": Failed to bring link back up" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700610
611 # Remove all intents
612 removeIntentResult = removeAllIntents( main, intentsId )
613
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700614 stepResult = pingResult and linkDownResult and linkUpResult \
kelvin-onlabf0594d72015-05-19 17:25:12 -0700615 and intentResult and removeIntentResult
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700616
617 return stepResult
618
kelvin-onlabc751ab42015-05-21 14:09:39 -0700619def multiToSingleIntent( main,
620 name,
621 hostNames,
622 devices="",
623 ports=None,
624 ethType="",
625 macs=None,
626 bandwidth="",
627 lambdaAlloc=False,
628 ipProto="",
629 ipAddresses="",
630 tcp="",
631 sw1="",
632 sw2="",
633 expectedLink=0 ):
634 """
635 Verify Single to Multi Point intents
636 NOTE:If main.hostsData is not defined, variables data should be passed in the
637 same order index wise. All devices in the list should have the same
638 format, either all the devices have its port or it doesn't.
639 eg. hostName = [ 'h1', 'h2' ,.. ]
640 devices = [ 'of:0000000000000001', 'of:0000000000000002', ...]
641 ports = [ '1', '1', ..]
642 ...
643 Description:
644 Verify add-multi-to-single-intent
645 Steps:
646 - Get device ids | ports
kelvin-onlabb2310a42015-05-21 14:17:29 -0700647 - Add multi to single point intents
kelvin-onlabc751ab42015-05-21 14:09:39 -0700648 - Check intents
649 - Verify flows
650 - Ping hosts
651 - Reroute
652 - Link down
653 - Verify flows
654 - Check topology
655 - Ping hosts
656 - Link up
657 - Verify flows
658 - Check topology
659 - Ping hosts
660 - Remove intents
661 Required:
662 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
663 hostNames - List of host names
664 Optional:
665 devices - List of device ids in the same order as the hosts
666 in hostNames
667 ports - List of port numbers in the same order as the device in
668 devices
669 ethType - Ethernet type eg. IPV4, IPV6
670 macs - List of hosts mac address in the same order as the hosts in
671 hostNames
672 bandwidth - Bandwidth capacity
673 lambdaAlloc - Allocate lambda, defaults to False
674 ipProto - IP protocol
675 ipAddresses - IP addresses of host in the same order as the hosts in
676 hostNames
677 tcp - TCP ports in the same order as the hosts in hostNames
678 sw1 - First switch to bring down & up for rerouting purpose
679 sw2 - Second switch to bring down & up for rerouting purpose
680 expectedLink - Expected link when the switches are down, it should
681 be two links lower than the links before the two
682 switches are down
683 """
684
685 import time
686 import copy
687 assert main, "There is no main variable"
688 assert hostNames, "You must specify hosts"
689 assert devices or main.hostsData, "You must specify devices"
690
691 global itemName
692 itemName = name
693 tempHostsData = {}
694 intentsId = []
695
696 macsDict = {}
697 ipDict = {}
698 if hostNames and devices:
699 if len( hostNames ) != len( devices ):
700 main.log.debug( "hosts and devices does not have the same length" )
701 #print "len hostNames = ", len( hostNames )
702 #print "len devices = ", len( devices )
703 return main.FALSE
704 if ports:
705 if len( ports ) != len( devices ):
706 main.log.error( "Ports and devices does " +
707 "not have the same length" )
708 #print "len devices = ", len( devices )
709 #print "len ports = ", len( ports )
710 return main.FALSE
kelvin-onlabc751ab42015-05-21 14:09:39 -0700711 else:
712 main.log.info( "Device Ports are not specified" )
kelvin-onlabf2ec6e02015-05-27 14:15:28 -0700713 if macs:
714 for i in range( len( devices ) ):
715 macsDict[ devices[ i ] ] = macs[ i ]
kelvin-onlabc751ab42015-05-21 14:09:39 -0700716 elif hostNames and not devices and main.hostsData:
717 devices = []
kelvin-onlabb2310a42015-05-21 14:17:29 -0700718 main.log.info( "multiToSingleIntent function is using main.hostsData" )
kelvin-onlabc751ab42015-05-21 14:09:39 -0700719 for host in hostNames:
720 devices.append( main.hostsData.get( host ).get( 'location' ) )
721 macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \
722 main.hostsData.get( host ).get( 'mac' )
723 ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \
724 main.hostsData.get( host ).get( 'ipAddresses' )
725 #print main.hostsData
726
727 #print 'host names = ', hostNames
728 #print 'devices = ', devices
729 #print "macsDict = ", macsDict
730
731 pingResult = main.TRUE
732 intentResult = main.TRUE
733 removeIntentResult = main.TRUE
734 flowResult = main.TRUE
735 topoResult = main.TRUE
736 linkDownResult = main.TRUE
737 linkUpResult = main.TRUE
738
739 devicesCopy = copy.copy( devices )
740 if ports:
741 portsCopy = copy.copy( ports )
kelvin-onlabb2310a42015-05-21 14:17:29 -0700742 main.log.info( itemName + ": Adding multi point to single point intents" )
kelvin-onlabc751ab42015-05-21 14:09:39 -0700743 # Adding bidirectional point intents
744 for i in range( len( devices ) ):
745 egressDevice = devicesCopy[ i ]
746 ingressDeviceList = copy.copy( devicesCopy )
747 ingressDeviceList.remove( egressDevice )
748 if ports:
749 portEgress = portsCopy[ i ]
750 portIngressList = copy.copy( portsCopy )
751 del portIngressList[ i ]
752 else:
753 portEgress = ""
754 portIngressList = None
755 if not macsDict:
756 dstMac = ""
757 else:
758 dstMac = macsDict[ egressDevice ]
759 if dstMac == None:
760 main.log.debug( "There is no MAC in device - " + egressDevice )
761 dstMac = ""
762
763 intentsId.append( main.CLIs[ 0 ].addMultipointToSinglepointIntent(
764 ingressDeviceList=ingressDeviceList,
765 egressDevice=egressDevice,
766 portIngressList=portIngressList,
767 portEgress=portEgress,
768 ethType=ethType,
769 ethDst=dstMac,
770 bandwidth=bandwidth,
771 lambdaAlloc=lambdaAlloc,
772 ipProto=ipProto,
773 ipSrc="",
774 ipDst="",
775 tcpSrc="",
776 tcpDst="" ) )
777
778 pingResult = pingallHosts( main, hostNames )
779
780 # Check intents state
781 time.sleep( 30 )
782 intentResult = checkIntentState( main, intentsId )
783
784 # Check intents state again if first check fails...
785 if not intentResult:
786 intentResult = checkIntentState( main, intentsId )
787
788 # Verify flows
789 checkFlowsState( main )
790
791 # Ping hosts
792 pingResult = pingResult and pingallHosts( main, hostNames )
793 # Ping hosts again...
794 pingResult = pingResult and pingallHosts( main, hostNames )
795 time.sleep( 5 )
796
797 # Test rerouting if these variables exist
798 if sw1 and sw2 and expectedLink:
799 # link down
800 linkDownResult = link( main, sw1, sw2, "down" )
801 intentResult = intentResult and checkIntentState( main, intentsId )
802
803 # Verify flows
804 checkFlowsState( main )
805
806 # Check OnosTopology
807 topoResult = checkTopology( main, expectedLink )
808
809 # Ping hosts
810 pingResult = pingResult and pingallHosts( main, hostNames )
811
812 intentResult = checkIntentState( main, intentsId )
813
814 # Checks ONOS state in link down
815 if linkDownResult and topoResult and pingResult and intentResult:
816 main.log.info( itemName + ": Successfully brought link down" )
817 else:
818 main.log.error( itemName + ": Failed to bring link down" )
819
820 # link up
821 linkUpResult = link( main, sw1, sw2, "up" )
822 time.sleep( 5 )
823
824 # Verify flows
825 checkFlowsState( main )
826
827 # Check OnosTopology
828 topoResult = checkTopology( main, main.numLinks )
829
830 # Ping hosts
831 pingResult = pingResult and pingallHosts( main, hostNames )
832
833 intentResult = checkIntentState( main, intentsId )
834
835 # Checks ONOS state in link up
836 if linkUpResult and topoResult and pingResult and intentResult:
837 main.log.info( itemName + ": Successfully brought link back up" )
838 else:
839 main.log.error( itemName + ": Failed to bring link back up" )
840
841 # Remove all intents
842 removeIntentResult = removeAllIntents( main, intentsId )
843
844 stepResult = pingResult and linkDownResult and linkUpResult \
845 and intentResult and removeIntentResult
846
847 return stepResult
848
kelvin-onlab08900012015-05-20 14:30:44 -0700849def pingallHosts( main, hostList, pingType="ipv4" ):
kelvin-onlabf0594d72015-05-19 17:25:12 -0700850 # Ping all host in the hosts list variable
kelvin-onlab08900012015-05-20 14:30:44 -0700851 print "Pinging : ", hostList
kelvin-onlabf0594d72015-05-19 17:25:12 -0700852 pingResult = main.TRUE
kelvin-onlab08900012015-05-20 14:30:44 -0700853 pingResult = main.Mininet1.pingallHosts( hostList, pingType )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700854 return pingResult
855
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700856def getHostsData( main ):
kelvin-onlabe5239e52015-05-13 14:46:45 -0700857 """
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700858 Use fwd app and pingall to discover all the hosts
kelvin-onlabe5239e52015-05-13 14:46:45 -0700859 """
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700860 import json
861 activateResult = main.TRUE
862 appCheck = main.TRUE
kelvin-onlab08900012015-05-20 14:30:44 -0700863 getDataResult = main.TRUE
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700864 main.log.info( "Activating reactive forwarding app " )
865 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
866
867 for i in range( main.numCtrls ):
868 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
kelvin-onlabf0594d72015-05-19 17:25:12 -0700869 if appCheck != main.TRUE:
kelvin-onlab08900012015-05-20 14:30:44 -0700870 main.log.warn( main.CLIs[ i ].apps() )
871 main.log.warn( main.CLIs[ i ].appIDs() )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700872
873 pingResult = main.Mininet1.pingall()
874 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
875 hosts = main.Mininet1.getHosts()
876 for host in hosts:
877 main.hostsData[ host ] = {}
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700878 main.hostsData[ host ][ 'mac' ] = \
879 main.Mininet1.getMacAddress( host ).upper()
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700880 for hostj in hostsJson:
881 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
882 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
883 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
884 main.hostsData[ host ][ 'location' ] = \
885 hostj[ 'location' ][ 'elementId' ] + '/' + \
886 hostj[ 'location' ][ 'port' ]
887 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
888
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700889 main.log.info( "Deactivating reactive forwarding app " )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700890 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
kelvin-onlab08900012015-05-20 14:30:44 -0700891 if activateResult and deactivateResult and main.hostsData:
kelvin-onlabf0594d72015-05-19 17:25:12 -0700892 main.log.info( "Successfully used fwd app to discover hosts " )
kelvin-onlab08900012015-05-20 14:30:44 -0700893 getDataResult = main.TRUE
kelvin-onlabf0594d72015-05-19 17:25:12 -0700894 else:
895 main.log.info( "Failed to use fwd app to discover hosts " )
kelvin-onlab08900012015-05-20 14:30:44 -0700896 getDataResult = main.FALSE
kelvin-onlabf0594d72015-05-19 17:25:12 -0700897
kelvin-onlab08900012015-05-20 14:30:44 -0700898 print main.hostsData
kelvin-onlabf0594d72015-05-19 17:25:12 -0700899
kelvin-onlab08900012015-05-20 14:30:44 -0700900 return getDataResult
kelvin-onlabe5239e52015-05-13 14:46:45 -0700901
902def checkTopology( main, expectedLink ):
903 statusResult = main.TRUE
904 # Check onos topology
905 main.log.info( itemName + ": Checking ONOS topology " )
906
907 for i in range( main.numCtrls ):
908 topologyResult = main.CLIs[ i ].topology()
909 statusResult = main.ONOSbench.checkStatus( topologyResult,
910 main.numSwitch,
911 expectedLink )\
912 and statusResult
913 if not statusResult:
kelvin-onlab381b34c2015-05-21 09:21:06 -0700914 main.log.error( itemName + ": Topology mismatch" )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700915 else:
916 main.log.info( itemName + ": Topology match" )
917 return statusResult
918
919def checkIntentState( main, intentsId ):
920
kelvin-onlab381b34c2015-05-21 09:21:06 -0700921 intentResult = main.TRUE
922
923 main.log.info( itemName + ": Checking intents state" )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700924 for i in range( main.numCtrls ):
kelvin-onlab381b34c2015-05-21 09:21:06 -0700925 intentResult = intentResult and \
926 main.CLIs[ i ].checkIntentState( intentsId=intentsId )
927
kelvin-onlabe5239e52015-05-13 14:46:45 -0700928 return intentResult
929
930def checkFlowsState( main ):
931
932 main.log.info( itemName + ": Check flows state" )
933 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState()
934 return checkFlowsResult
935
kelvin-onlabf0594d72015-05-19 17:25:12 -0700936def link( main, sw1, sw2, option):
kelvin-onlabe5239e52015-05-13 14:46:45 -0700937
kelvin-onlabf0594d72015-05-19 17:25:12 -0700938 # link down
939 main.log.info( itemName + ": Bring link " + option + "between " +
940 sw1 + " and " + sw2 )
941 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
942 return linkResult
943
944def removeAllIntents( main, intentsId ):
945 """
946 Remove all intents in the intentsId
947 """
948 import time
949 intentsRemaining = []
950 removeIntentResult = main.TRUE
951 # Remove intents
952 for intent in intentsId:
953 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
954
955 time.sleep( 5 )
956 # Checks if there is remaining intents using intents()
kelvin-onlab583fcb52015-05-21 13:10:46 -0700957 intentsRemaining = main.CLIs[ 0 ].intents( jsonFormat=False )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700958 # If there is remianing intents then remove intents should fail
kelvin-onlab583fcb52015-05-21 13:10:46 -0700959
960 if intentsRemaining:
kelvin-onlabf0594d72015-05-19 17:25:12 -0700961 main.log.info( itemName + ": There are " +
962 str( len( intentsRemaining ) ) + " intents remaining, "
963 + "failed to remove all the intents " )
964 removeIntentResult = main.FALSE
kelvin-onlab08900012015-05-20 14:30:44 -0700965 main.log.info( intentsRemaining )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700966 else:
967 main.log.info( itemName + ": There are no intents remaining, " +
968 "successfully removed all the intents." )
969 removeIntentResult = main.TRUE
970 return removeIntentResult