blob: 3f411800bdb29a0eee783a482596ec2288204361 [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
kelvin-onlab08900012015-05-20 14:30:44 -0700480 for i in range( len( devices ) ):
481 macsDict[ devices[ i ] ] = macs[ i ]
kelvin-onlab90b6b042015-05-18 20:57:13 -0700482 else:
483 main.log.info( "Device Ports are not specified" )
484 elif hostNames and not devices and main.hostsData:
kelvin-onlab08900012015-05-20 14:30:44 -0700485 devices = []
kelvin-onlab90b6b042015-05-18 20:57:13 -0700486 main.log.info( "singleToMultiIntent function is using main.hostsData" )
kelvin-onlab08900012015-05-20 14:30:44 -0700487 for host in hostNames:
kelvin-onlab08900012015-05-20 14:30:44 -0700488 devices.append( main.hostsData.get( host ).get( 'location' ) )
489 macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \
490 main.hostsData.get( host ).get( 'mac' )
491 ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \
492 main.hostsData.get( host ).get( 'ipAddresses' )
kelvin-onlab381b34c2015-05-21 09:21:06 -0700493 #print main.hostsData
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700494
kelvin-onlab381b34c2015-05-21 09:21:06 -0700495 #print 'host names = ', hostNames
496 #print 'devices = ', devices
497 #print "macsDict = ", macsDict
kelvin-onlabf0594d72015-05-19 17:25:12 -0700498
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700499 pingResult = main.TRUE
500 intentResult = main.TRUE
kelvin-onlabf0594d72015-05-19 17:25:12 -0700501 removeIntentResult = main.TRUE
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700502 flowResult = main.TRUE
503 topoResult = main.TRUE
504 linkDownResult = main.TRUE
505 linkUpResult = main.TRUE
506
kelvin-onlabf0594d72015-05-19 17:25:12 -0700507 devicesCopy = copy.copy( devices )
508 if ports:
509 portsCopy = copy.copy( ports )
510 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700511 # Adding bidirectional point intents
kelvin-onlabf0594d72015-05-19 17:25:12 -0700512 for i in range( len( devices ) ):
513 ingressDevice = devicesCopy[ i ]
514 egressDeviceList = copy.copy( devicesCopy )
515 egressDeviceList.remove( ingressDevice )
516 if ports:
517 portIngress = portsCopy[ i ]
518 portEgressList = copy.copy( portsCopy )
519 del portEgressList[ i ]
520 else:
521 portIngress = ""
522 portEgressList = None
kelvin-onlab08900012015-05-20 14:30:44 -0700523 if not macsDict:
524 srcMac = ""
525 else:
526 srcMac = macsDict[ ingressDevice ]
527 if srcMac == None:
kelvin-onlabc751ab42015-05-21 14:09:39 -0700528 main.log.debug( "There is no MAC in device - " + ingressDevice )
kelvin-onlab08900012015-05-20 14:30:44 -0700529 srcMac = ""
530
kelvin-onlabf0594d72015-05-19 17:25:12 -0700531 intentsId.append( main.CLIs[ 0 ].addSinglepointToMultipointIntent(
532 ingressDevice=ingressDevice,
533 egressDeviceList=egressDeviceList,
534 portIngress=portIngress,
535 portEgressList=portEgressList,
kelvin-onlab90b6b042015-05-18 20:57:13 -0700536 ethType=ethType,
kelvin-onlab08900012015-05-20 14:30:44 -0700537 ethSrc=srcMac,
kelvin-onlab90b6b042015-05-18 20:57:13 -0700538 bandwidth=bandwidth,
539 lambdaAlloc=lambdaAlloc,
540 ipProto=ipProto,
kelvin-onlabf0594d72015-05-19 17:25:12 -0700541 ipSrc="",
542 ipDst="",
543 tcpSrc="",
544 tcpDst="" ) )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700545
kelvin-onlab08900012015-05-20 14:30:44 -0700546 pingResult = pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700547
548 # Check intents state
kelvin-onlabf0594d72015-05-19 17:25:12 -0700549 time.sleep( 30 )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700550 intentResult = checkIntentState( main, intentsId )
551
kelvin-onlab381b34c2015-05-21 09:21:06 -0700552 # Check intents state again if first check fails...
553 if not intentResult:
554 intentResult = checkIntentState( main, intentsId )
555
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700556 # Verify flows
557 checkFlowsState( main )
558
559 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700560 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700561 # Ping hosts again...
kelvin-onlab08900012015-05-20 14:30:44 -0700562 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700563 time.sleep( 5 )
564
kelvin-onlabf0594d72015-05-19 17:25:12 -0700565 # Test rerouting if these variables exist
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700566 if sw1 and sw2 and expectedLink:
567 # link down
kelvin-onlabf0594d72015-05-19 17:25:12 -0700568 linkDownResult = link( main, sw1, sw2, "down" )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700569 intentResult = intentResult and checkIntentState( main, intentsId )
570
571 # Verify flows
572 checkFlowsState( main )
573
574 # Check OnosTopology
575 topoResult = checkTopology( main, expectedLink )
576
577 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700578 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700579
580 intentResult = checkIntentState( main, intentsId )
581
kelvin-onlabf0594d72015-05-19 17:25:12 -0700582 # Checks ONOS state in link down
583 if linkDownResult and topoResult and pingResult and intentResult:
584 main.log.info( itemName + ": Successfully brought link down" )
585 else:
kelvin-onlab08900012015-05-20 14:30:44 -0700586 main.log.error( itemName + ": Failed to bring link down" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700587
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700588 # link up
kelvin-onlabf0594d72015-05-19 17:25:12 -0700589 linkUpResult = link( main, sw1, sw2, "up" )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700590 time.sleep( 5 )
591
592 # Verify flows
593 checkFlowsState( main )
594
595 # Check OnosTopology
kelvin-onlabf0594d72015-05-19 17:25:12 -0700596 topoResult = checkTopology( main, main.numLinks )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700597
598 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700599 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700600
kelvin-onlabf0594d72015-05-19 17:25:12 -0700601 intentResult = checkIntentState( main, intentsId )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700602
kelvin-onlabf0594d72015-05-19 17:25:12 -0700603 # Checks ONOS state in link up
604 if linkUpResult and topoResult and pingResult and intentResult:
605 main.log.info( itemName + ": Successfully brought link back up" )
606 else:
kelvin-onlab08900012015-05-20 14:30:44 -0700607 main.log.error( itemName + ": Failed to bring link back up" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700608
609 # Remove all intents
610 removeIntentResult = removeAllIntents( main, intentsId )
611
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700612 stepResult = pingResult and linkDownResult and linkUpResult \
kelvin-onlabf0594d72015-05-19 17:25:12 -0700613 and intentResult and removeIntentResult
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700614
615 return stepResult
616
kelvin-onlabc751ab42015-05-21 14:09:39 -0700617def multiToSingleIntent( main,
618 name,
619 hostNames,
620 devices="",
621 ports=None,
622 ethType="",
623 macs=None,
624 bandwidth="",
625 lambdaAlloc=False,
626 ipProto="",
627 ipAddresses="",
628 tcp="",
629 sw1="",
630 sw2="",
631 expectedLink=0 ):
632 """
633 Verify Single to Multi Point intents
634 NOTE:If main.hostsData is not defined, variables data should be passed in the
635 same order index wise. All devices in the list should have the same
636 format, either all the devices have its port or it doesn't.
637 eg. hostName = [ 'h1', 'h2' ,.. ]
638 devices = [ 'of:0000000000000001', 'of:0000000000000002', ...]
639 ports = [ '1', '1', ..]
640 ...
641 Description:
642 Verify add-multi-to-single-intent
643 Steps:
644 - Get device ids | ports
645 - Add single to multi point intents
646 - Check intents
647 - Verify flows
648 - Ping hosts
649 - Reroute
650 - Link down
651 - Verify flows
652 - Check topology
653 - Ping hosts
654 - Link up
655 - Verify flows
656 - Check topology
657 - Ping hosts
658 - Remove intents
659 Required:
660 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
661 hostNames - List of host names
662 Optional:
663 devices - List of device ids in the same order as the hosts
664 in hostNames
665 ports - List of port numbers in the same order as the device in
666 devices
667 ethType - Ethernet type eg. IPV4, IPV6
668 macs - List of hosts mac address in the same order as the hosts in
669 hostNames
670 bandwidth - Bandwidth capacity
671 lambdaAlloc - Allocate lambda, defaults to False
672 ipProto - IP protocol
673 ipAddresses - IP addresses of host in the same order as the hosts in
674 hostNames
675 tcp - TCP ports in the same order as the hosts in hostNames
676 sw1 - First switch to bring down & up for rerouting purpose
677 sw2 - Second switch to bring down & up for rerouting purpose
678 expectedLink - Expected link when the switches are down, it should
679 be two links lower than the links before the two
680 switches are down
681 """
682
683 import time
684 import copy
685 assert main, "There is no main variable"
686 assert hostNames, "You must specify hosts"
687 assert devices or main.hostsData, "You must specify devices"
688
689 global itemName
690 itemName = name
691 tempHostsData = {}
692 intentsId = []
693
694 macsDict = {}
695 ipDict = {}
696 if hostNames and devices:
697 if len( hostNames ) != len( devices ):
698 main.log.debug( "hosts and devices does not have the same length" )
699 #print "len hostNames = ", len( hostNames )
700 #print "len devices = ", len( devices )
701 return main.FALSE
702 if ports:
703 if len( ports ) != len( devices ):
704 main.log.error( "Ports and devices does " +
705 "not have the same length" )
706 #print "len devices = ", len( devices )
707 #print "len ports = ", len( ports )
708 return main.FALSE
709 for i in range( len( devices ) ):
710 macsDict[ devices[ i ] ] = macs[ i ]
711 else:
712 main.log.info( "Device Ports are not specified" )
713 elif hostNames and not devices and main.hostsData:
714 devices = []
715 main.log.info( "singleToMultiIntent function is using main.hostsData" )
716 for host in hostNames:
717 devices.append( main.hostsData.get( host ).get( 'location' ) )
718 macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \
719 main.hostsData.get( host ).get( 'mac' )
720 ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \
721 main.hostsData.get( host ).get( 'ipAddresses' )
722 #print main.hostsData
723
724 #print 'host names = ', hostNames
725 #print 'devices = ', devices
726 #print "macsDict = ", macsDict
727
728 pingResult = main.TRUE
729 intentResult = main.TRUE
730 removeIntentResult = main.TRUE
731 flowResult = main.TRUE
732 topoResult = main.TRUE
733 linkDownResult = main.TRUE
734 linkUpResult = main.TRUE
735
736 devicesCopy = copy.copy( devices )
737 if ports:
738 portsCopy = copy.copy( ports )
739 main.log.info( itemName + ": Adding single point to multi point intents" )
740 # Adding bidirectional point intents
741 for i in range( len( devices ) ):
742 egressDevice = devicesCopy[ i ]
743 ingressDeviceList = copy.copy( devicesCopy )
744 ingressDeviceList.remove( egressDevice )
745 if ports:
746 portEgress = portsCopy[ i ]
747 portIngressList = copy.copy( portsCopy )
748 del portIngressList[ i ]
749 else:
750 portEgress = ""
751 portIngressList = None
752 if not macsDict:
753 dstMac = ""
754 else:
755 dstMac = macsDict[ egressDevice ]
756 if dstMac == None:
757 main.log.debug( "There is no MAC in device - " + egressDevice )
758 dstMac = ""
759
760 intentsId.append( main.CLIs[ 0 ].addMultipointToSinglepointIntent(
761 ingressDeviceList=ingressDeviceList,
762 egressDevice=egressDevice,
763 portIngressList=portIngressList,
764 portEgress=portEgress,
765 ethType=ethType,
766 ethDst=dstMac,
767 bandwidth=bandwidth,
768 lambdaAlloc=lambdaAlloc,
769 ipProto=ipProto,
770 ipSrc="",
771 ipDst="",
772 tcpSrc="",
773 tcpDst="" ) )
774
775 pingResult = pingallHosts( main, hostNames )
776
777 # Check intents state
778 time.sleep( 30 )
779 intentResult = checkIntentState( main, intentsId )
780
781 # Check intents state again if first check fails...
782 if not intentResult:
783 intentResult = checkIntentState( main, intentsId )
784
785 # Verify flows
786 checkFlowsState( main )
787
788 # Ping hosts
789 pingResult = pingResult and pingallHosts( main, hostNames )
790 # Ping hosts again...
791 pingResult = pingResult and pingallHosts( main, hostNames )
792 time.sleep( 5 )
793
794 # Test rerouting if these variables exist
795 if sw1 and sw2 and expectedLink:
796 # link down
797 linkDownResult = link( main, sw1, sw2, "down" )
798 intentResult = intentResult and checkIntentState( main, intentsId )
799
800 # Verify flows
801 checkFlowsState( main )
802
803 # Check OnosTopology
804 topoResult = checkTopology( main, expectedLink )
805
806 # Ping hosts
807 pingResult = pingResult and pingallHosts( main, hostNames )
808
809 intentResult = checkIntentState( main, intentsId )
810
811 # Checks ONOS state in link down
812 if linkDownResult and topoResult and pingResult and intentResult:
813 main.log.info( itemName + ": Successfully brought link down" )
814 else:
815 main.log.error( itemName + ": Failed to bring link down" )
816
817 # link up
818 linkUpResult = link( main, sw1, sw2, "up" )
819 time.sleep( 5 )
820
821 # Verify flows
822 checkFlowsState( main )
823
824 # Check OnosTopology
825 topoResult = checkTopology( main, main.numLinks )
826
827 # Ping hosts
828 pingResult = pingResult and pingallHosts( main, hostNames )
829
830 intentResult = checkIntentState( main, intentsId )
831
832 # Checks ONOS state in link up
833 if linkUpResult and topoResult and pingResult and intentResult:
834 main.log.info( itemName + ": Successfully brought link back up" )
835 else:
836 main.log.error( itemName + ": Failed to bring link back up" )
837
838 # Remove all intents
839 removeIntentResult = removeAllIntents( main, intentsId )
840
841 stepResult = pingResult and linkDownResult and linkUpResult \
842 and intentResult and removeIntentResult
843
844 return stepResult
845
kelvin-onlab08900012015-05-20 14:30:44 -0700846def pingallHosts( main, hostList, pingType="ipv4" ):
kelvin-onlabf0594d72015-05-19 17:25:12 -0700847 # Ping all host in the hosts list variable
kelvin-onlab08900012015-05-20 14:30:44 -0700848 print "Pinging : ", hostList
kelvin-onlabf0594d72015-05-19 17:25:12 -0700849 pingResult = main.TRUE
kelvin-onlab08900012015-05-20 14:30:44 -0700850 pingResult = main.Mininet1.pingallHosts( hostList, pingType )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700851 return pingResult
852
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700853def getHostsData( main ):
kelvin-onlabe5239e52015-05-13 14:46:45 -0700854 """
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700855 Use fwd app and pingall to discover all the hosts
kelvin-onlabe5239e52015-05-13 14:46:45 -0700856 """
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700857 import json
858 activateResult = main.TRUE
859 appCheck = main.TRUE
kelvin-onlab08900012015-05-20 14:30:44 -0700860 getDataResult = main.TRUE
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700861 main.log.info( "Activating reactive forwarding app " )
862 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
863
864 for i in range( main.numCtrls ):
865 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
kelvin-onlabf0594d72015-05-19 17:25:12 -0700866 if appCheck != main.TRUE:
kelvin-onlab08900012015-05-20 14:30:44 -0700867 main.log.warn( main.CLIs[ i ].apps() )
868 main.log.warn( main.CLIs[ i ].appIDs() )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700869
870 pingResult = main.Mininet1.pingall()
871 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
872 hosts = main.Mininet1.getHosts()
873 for host in hosts:
874 main.hostsData[ host ] = {}
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700875 main.hostsData[ host ][ 'mac' ] = \
876 main.Mininet1.getMacAddress( host ).upper()
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700877 for hostj in hostsJson:
878 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
879 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
880 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
881 main.hostsData[ host ][ 'location' ] = \
882 hostj[ 'location' ][ 'elementId' ] + '/' + \
883 hostj[ 'location' ][ 'port' ]
884 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
885
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700886 main.log.info( "Deactivating reactive forwarding app " )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700887 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
kelvin-onlab08900012015-05-20 14:30:44 -0700888 if activateResult and deactivateResult and main.hostsData:
kelvin-onlabf0594d72015-05-19 17:25:12 -0700889 main.log.info( "Successfully used fwd app to discover hosts " )
kelvin-onlab08900012015-05-20 14:30:44 -0700890 getDataResult = main.TRUE
kelvin-onlabf0594d72015-05-19 17:25:12 -0700891 else:
892 main.log.info( "Failed to use fwd app to discover hosts " )
kelvin-onlab08900012015-05-20 14:30:44 -0700893 getDataResult = main.FALSE
kelvin-onlabf0594d72015-05-19 17:25:12 -0700894
kelvin-onlab08900012015-05-20 14:30:44 -0700895 print main.hostsData
kelvin-onlabf0594d72015-05-19 17:25:12 -0700896
kelvin-onlab08900012015-05-20 14:30:44 -0700897 return getDataResult
kelvin-onlabe5239e52015-05-13 14:46:45 -0700898
899def checkTopology( main, expectedLink ):
900 statusResult = main.TRUE
901 # Check onos topology
902 main.log.info( itemName + ": Checking ONOS topology " )
903
904 for i in range( main.numCtrls ):
905 topologyResult = main.CLIs[ i ].topology()
906 statusResult = main.ONOSbench.checkStatus( topologyResult,
907 main.numSwitch,
908 expectedLink )\
909 and statusResult
910 if not statusResult:
kelvin-onlab381b34c2015-05-21 09:21:06 -0700911 main.log.error( itemName + ": Topology mismatch" )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700912 else:
913 main.log.info( itemName + ": Topology match" )
914 return statusResult
915
916def checkIntentState( main, intentsId ):
917
kelvin-onlab381b34c2015-05-21 09:21:06 -0700918 intentResult = main.TRUE
919
920 main.log.info( itemName + ": Checking intents state" )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700921 for i in range( main.numCtrls ):
kelvin-onlab381b34c2015-05-21 09:21:06 -0700922 intentResult = intentResult and \
923 main.CLIs[ i ].checkIntentState( intentsId=intentsId )
924
kelvin-onlabe5239e52015-05-13 14:46:45 -0700925 return intentResult
926
927def checkFlowsState( main ):
928
929 main.log.info( itemName + ": Check flows state" )
930 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState()
931 return checkFlowsResult
932
kelvin-onlabf0594d72015-05-19 17:25:12 -0700933def link( main, sw1, sw2, option):
kelvin-onlabe5239e52015-05-13 14:46:45 -0700934
kelvin-onlabf0594d72015-05-19 17:25:12 -0700935 # link down
936 main.log.info( itemName + ": Bring link " + option + "between " +
937 sw1 + " and " + sw2 )
938 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
939 return linkResult
940
941def removeAllIntents( main, intentsId ):
942 """
943 Remove all intents in the intentsId
944 """
945 import time
946 intentsRemaining = []
947 removeIntentResult = main.TRUE
948 # Remove intents
949 for intent in intentsId:
950 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
951
952 time.sleep( 5 )
953 # Checks if there is remaining intents using intents()
kelvin-onlab583fcb52015-05-21 13:10:46 -0700954 intentsRemaining = main.CLIs[ 0 ].intents( jsonFormat=False )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700955 # If there is remianing intents then remove intents should fail
kelvin-onlab583fcb52015-05-21 13:10:46 -0700956
957 if intentsRemaining:
kelvin-onlabf0594d72015-05-19 17:25:12 -0700958 main.log.info( itemName + ": There are " +
959 str( len( intentsRemaining ) ) + " intents remaining, "
960 + "failed to remove all the intents " )
961 removeIntentResult = main.FALSE
kelvin-onlab08900012015-05-20 14:30:44 -0700962 main.log.info( intentsRemaining )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700963 else:
964 main.log.info( itemName + ": There are no intents remaining, " +
965 "successfully removed all the intents." )
966 removeIntentResult = main.TRUE
967 return removeIntentResult