blob: 40ea4a2955dcf79aa78af3451a7604449ef9c98f [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:
412 Verify add-single-to-multi-intent
413 Steps:
414 - Get device ids | ports
415 - Add single to multi point intents
416 - Check intents
417 - Verify flows
418 - Ping hosts
419 - Reroute
420 - Link down
421 - Verify flows
422 - Check topology
423 - Ping hosts
424 - Link up
425 - Verify flows
426 - Check topology
427 - Ping hosts
428 - Remove intents
429 Required:
430 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
431 hostNames - List of host names
432 Optional:
433 devices - List of device ids in the same order as the hosts
434 in hostNames
435 ports - List of port numbers in the same order as the device in
436 devices
437 ethType - Ethernet type eg. IPV4, IPV6
438 macs - List of hosts mac address in the same order as the hosts in
439 hostNames
440 bandwidth - Bandwidth capacity
441 lambdaAlloc - Allocate lambda, defaults to False
442 ipProto - IP protocol
443 ipAddresses - IP addresses of host in the same order as the hosts in
444 hostNames
445 tcp - TCP ports in the same order as the hosts in hostNames
446 sw1 - First switch to bring down & up for rerouting purpose
447 sw2 - Second switch to bring down & up for rerouting purpose
448 expectedLink - Expected link when the switches are down, it should
449 be two links lower than the links before the two
450 switches are down
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700451 """
kelvin-onlab381b34c2015-05-21 09:21:06 -0700452
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700453 import time
kelvin-onlabf0594d72015-05-19 17:25:12 -0700454 import copy
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700455 assert main, "There is no main variable"
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700456 assert hostNames, "You must specify hosts"
457 assert devices or main.hostsData, "You must specify devices"
458
459 global itemName
460 itemName = name
kelvin-onlab90b6b042015-05-18 20:57:13 -0700461 tempHostsData = {}
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700462 intentsId = []
463
kelvin-onlab08900012015-05-20 14:30:44 -0700464 macsDict = {}
465 ipDict = {}
kelvin-onlab90b6b042015-05-18 20:57:13 -0700466 if hostNames and devices:
467 if len( hostNames ) != len( devices ):
kelvin-onlab08900012015-05-20 14:30:44 -0700468 main.log.debug( "hosts and devices does not have the same length" )
469 #print "len hostNames = ", len( hostNames )
470 #print "len devices = ", len( devices )
kelvin-onlab90b6b042015-05-18 20:57:13 -0700471 return main.FALSE
472 if ports:
473 if len( ports ) != len( devices ):
474 main.log.error( "Ports and devices does " +
475 "not have the same length" )
kelvin-onlab08900012015-05-20 14:30:44 -0700476 #print "len devices = ", len( devices )
477 #print "len ports = ", len( ports )
kelvin-onlab90b6b042015-05-18 20:57:13 -0700478 return main.FALSE
kelvin-onlab08900012015-05-20 14:30:44 -0700479 for i in range( len( devices ) ):
480 macsDict[ devices[ i ] ] = macs[ i ]
kelvin-onlab90b6b042015-05-18 20:57:13 -0700481 else:
482 main.log.info( "Device Ports are not specified" )
483 elif hostNames and not devices and main.hostsData:
kelvin-onlab08900012015-05-20 14:30:44 -0700484 devices = []
kelvin-onlab90b6b042015-05-18 20:57:13 -0700485 main.log.info( "singleToMultiIntent function is using main.hostsData" )
kelvin-onlab08900012015-05-20 14:30:44 -0700486 for host in hostNames:
kelvin-onlab08900012015-05-20 14:30:44 -0700487 devices.append( main.hostsData.get( host ).get( 'location' ) )
488 macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \
489 main.hostsData.get( host ).get( 'mac' )
490 ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \
491 main.hostsData.get( host ).get( 'ipAddresses' )
kelvin-onlab381b34c2015-05-21 09:21:06 -0700492 #print main.hostsData
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700493
kelvin-onlab381b34c2015-05-21 09:21:06 -0700494 #print 'host names = ', hostNames
495 #print 'devices = ', devices
496 #print "macsDict = ", macsDict
kelvin-onlabf0594d72015-05-19 17:25:12 -0700497
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700498 pingResult = main.TRUE
499 intentResult = main.TRUE
kelvin-onlabf0594d72015-05-19 17:25:12 -0700500 removeIntentResult = main.TRUE
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700501 flowResult = main.TRUE
502 topoResult = main.TRUE
503 linkDownResult = main.TRUE
504 linkUpResult = main.TRUE
505
kelvin-onlabf0594d72015-05-19 17:25:12 -0700506 devicesCopy = copy.copy( devices )
507 if ports:
508 portsCopy = copy.copy( ports )
509 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700510 # Adding bidirectional point intents
kelvin-onlabf0594d72015-05-19 17:25:12 -0700511 for i in range( len( devices ) ):
512 ingressDevice = devicesCopy[ i ]
513 egressDeviceList = copy.copy( devicesCopy )
514 egressDeviceList.remove( ingressDevice )
515 if ports:
516 portIngress = portsCopy[ i ]
517 portEgressList = copy.copy( portsCopy )
518 del portEgressList[ i ]
519 else:
520 portIngress = ""
521 portEgressList = None
kelvin-onlab08900012015-05-20 14:30:44 -0700522 if not macsDict:
523 srcMac = ""
524 else:
525 srcMac = macsDict[ ingressDevice ]
526 if srcMac == None:
527 srcMac = ""
528
kelvin-onlabf0594d72015-05-19 17:25:12 -0700529 intentsId.append( main.CLIs[ 0 ].addSinglepointToMultipointIntent(
530 ingressDevice=ingressDevice,
531 egressDeviceList=egressDeviceList,
532 portIngress=portIngress,
533 portEgressList=portEgressList,
kelvin-onlab90b6b042015-05-18 20:57:13 -0700534 ethType=ethType,
kelvin-onlab08900012015-05-20 14:30:44 -0700535 ethSrc=srcMac,
kelvin-onlab90b6b042015-05-18 20:57:13 -0700536 bandwidth=bandwidth,
537 lambdaAlloc=lambdaAlloc,
538 ipProto=ipProto,
kelvin-onlabf0594d72015-05-19 17:25:12 -0700539 ipSrc="",
540 ipDst="",
541 tcpSrc="",
542 tcpDst="" ) )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700543
kelvin-onlab08900012015-05-20 14:30:44 -0700544 pingResult = pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700545
546 # Check intents state
kelvin-onlabf0594d72015-05-19 17:25:12 -0700547 time.sleep( 30 )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700548 intentResult = checkIntentState( main, intentsId )
549
kelvin-onlab381b34c2015-05-21 09:21:06 -0700550 # Check intents state again if first check fails...
551 if not intentResult:
552 intentResult = checkIntentState( main, intentsId )
553
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700554 # Verify flows
555 checkFlowsState( main )
556
557 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700558 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700559 # Ping hosts again...
kelvin-onlab08900012015-05-20 14:30:44 -0700560 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700561 time.sleep( 5 )
562
kelvin-onlabf0594d72015-05-19 17:25:12 -0700563 # Test rerouting if these variables exist
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700564 if sw1 and sw2 and expectedLink:
565 # link down
kelvin-onlabf0594d72015-05-19 17:25:12 -0700566 linkDownResult = link( main, sw1, sw2, "down" )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700567 intentResult = intentResult and checkIntentState( main, intentsId )
568
569 # Verify flows
570 checkFlowsState( main )
571
572 # Check OnosTopology
573 topoResult = checkTopology( main, expectedLink )
574
575 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700576 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700577
578 intentResult = checkIntentState( main, intentsId )
579
kelvin-onlabf0594d72015-05-19 17:25:12 -0700580 # Checks ONOS state in link down
581 if linkDownResult and topoResult and pingResult and intentResult:
582 main.log.info( itemName + ": Successfully brought link down" )
583 else:
kelvin-onlab08900012015-05-20 14:30:44 -0700584 main.log.error( itemName + ": Failed to bring link down" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700585
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700586 # link up
kelvin-onlabf0594d72015-05-19 17:25:12 -0700587 linkUpResult = link( main, sw1, sw2, "up" )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700588 time.sleep( 5 )
589
590 # Verify flows
591 checkFlowsState( main )
592
593 # Check OnosTopology
kelvin-onlabf0594d72015-05-19 17:25:12 -0700594 topoResult = checkTopology( main, main.numLinks )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700595
596 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700597 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700598
kelvin-onlabf0594d72015-05-19 17:25:12 -0700599 intentResult = checkIntentState( main, intentsId )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700600
kelvin-onlabf0594d72015-05-19 17:25:12 -0700601 # Checks ONOS state in link up
602 if linkUpResult and topoResult and pingResult and intentResult:
603 main.log.info( itemName + ": Successfully brought link back up" )
604 else:
kelvin-onlab08900012015-05-20 14:30:44 -0700605 main.log.error( itemName + ": Failed to bring link back up" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700606
607 # Remove all intents
608 removeIntentResult = removeAllIntents( main, intentsId )
609
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700610 stepResult = pingResult and linkDownResult and linkUpResult \
kelvin-onlabf0594d72015-05-19 17:25:12 -0700611 and intentResult and removeIntentResult
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700612
613 return stepResult
614
kelvin-onlab08900012015-05-20 14:30:44 -0700615def pingallHosts( main, hostList, pingType="ipv4" ):
kelvin-onlabf0594d72015-05-19 17:25:12 -0700616 # Ping all host in the hosts list variable
kelvin-onlab08900012015-05-20 14:30:44 -0700617 print "Pinging : ", hostList
kelvin-onlabf0594d72015-05-19 17:25:12 -0700618 pingResult = main.TRUE
kelvin-onlab08900012015-05-20 14:30:44 -0700619 pingResult = main.Mininet1.pingallHosts( hostList, pingType )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700620 return pingResult
621
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700622def getHostsData( main ):
kelvin-onlabe5239e52015-05-13 14:46:45 -0700623 """
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700624 Use fwd app and pingall to discover all the hosts
kelvin-onlabe5239e52015-05-13 14:46:45 -0700625 """
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700626 import json
627 activateResult = main.TRUE
628 appCheck = main.TRUE
kelvin-onlab08900012015-05-20 14:30:44 -0700629 getDataResult = main.TRUE
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700630 main.log.info( "Activating reactive forwarding app " )
631 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
632
633 for i in range( main.numCtrls ):
634 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
kelvin-onlabf0594d72015-05-19 17:25:12 -0700635 if appCheck != main.TRUE:
kelvin-onlab08900012015-05-20 14:30:44 -0700636 main.log.warn( main.CLIs[ i ].apps() )
637 main.log.warn( main.CLIs[ i ].appIDs() )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700638
639 pingResult = main.Mininet1.pingall()
640 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
641 hosts = main.Mininet1.getHosts()
642 for host in hosts:
643 main.hostsData[ host ] = {}
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700644 main.hostsData[ host ][ 'mac' ] = \
645 main.Mininet1.getMacAddress( host ).upper()
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700646 for hostj in hostsJson:
647 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
648 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
649 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
650 main.hostsData[ host ][ 'location' ] = \
651 hostj[ 'location' ][ 'elementId' ] + '/' + \
652 hostj[ 'location' ][ 'port' ]
653 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
654
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700655 main.log.info( "Deactivating reactive forwarding app " )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700656 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
kelvin-onlab08900012015-05-20 14:30:44 -0700657 if activateResult and deactivateResult and main.hostsData:
kelvin-onlabf0594d72015-05-19 17:25:12 -0700658 main.log.info( "Successfully used fwd app to discover hosts " )
kelvin-onlab08900012015-05-20 14:30:44 -0700659 getDataResult = main.TRUE
kelvin-onlabf0594d72015-05-19 17:25:12 -0700660 else:
661 main.log.info( "Failed to use fwd app to discover hosts " )
kelvin-onlab08900012015-05-20 14:30:44 -0700662 getDataResult = main.FALSE
kelvin-onlabf0594d72015-05-19 17:25:12 -0700663
kelvin-onlab08900012015-05-20 14:30:44 -0700664 print main.hostsData
kelvin-onlabf0594d72015-05-19 17:25:12 -0700665
kelvin-onlab08900012015-05-20 14:30:44 -0700666 return getDataResult
kelvin-onlabe5239e52015-05-13 14:46:45 -0700667
668def checkTopology( main, expectedLink ):
669 statusResult = main.TRUE
670 # Check onos topology
671 main.log.info( itemName + ": Checking ONOS topology " )
672
673 for i in range( main.numCtrls ):
674 topologyResult = main.CLIs[ i ].topology()
675 statusResult = main.ONOSbench.checkStatus( topologyResult,
676 main.numSwitch,
677 expectedLink )\
678 and statusResult
679 if not statusResult:
kelvin-onlab381b34c2015-05-21 09:21:06 -0700680 main.log.error( itemName + ": Topology mismatch" )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700681 else:
682 main.log.info( itemName + ": Topology match" )
683 return statusResult
684
685def checkIntentState( main, intentsId ):
686
kelvin-onlab381b34c2015-05-21 09:21:06 -0700687 intentResult = main.TRUE
688
689 main.log.info( itemName + ": Checking intents state" )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700690 for i in range( main.numCtrls ):
kelvin-onlab381b34c2015-05-21 09:21:06 -0700691 intentResult = intentResult and \
692 main.CLIs[ i ].checkIntentState( intentsId=intentsId )
693
kelvin-onlabe5239e52015-05-13 14:46:45 -0700694 return intentResult
695
696def checkFlowsState( main ):
697
698 main.log.info( itemName + ": Check flows state" )
699 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState()
700 return checkFlowsResult
701
kelvin-onlabf0594d72015-05-19 17:25:12 -0700702def link( main, sw1, sw2, option):
kelvin-onlabe5239e52015-05-13 14:46:45 -0700703
kelvin-onlabf0594d72015-05-19 17:25:12 -0700704 # link down
705 main.log.info( itemName + ": Bring link " + option + "between " +
706 sw1 + " and " + sw2 )
707 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
708 return linkResult
709
710def removeAllIntents( main, intentsId ):
711 """
712 Remove all intents in the intentsId
713 """
714 import time
715 intentsRemaining = []
716 removeIntentResult = main.TRUE
717 # Remove intents
718 for intent in intentsId:
719 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
720
721 time.sleep( 5 )
722 # Checks if there is remaining intents using intents()
723 intentsRemaining = main.CLIs[ 0 ].intents()
kelvin-onlabf0594d72015-05-19 17:25:12 -0700724 # If there is remianing intents then remove intents should fail
kelvin-onlab08900012015-05-20 14:30:44 -0700725 if intentsRemaining == []:
kelvin-onlabf0594d72015-05-19 17:25:12 -0700726 main.log.info( itemName + ": There are " +
727 str( len( intentsRemaining ) ) + " intents remaining, "
728 + "failed to remove all the intents " )
729 removeIntentResult = main.FALSE
kelvin-onlab08900012015-05-20 14:30:44 -0700730 main.log.info( intentsRemaining )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700731 else:
732 main.log.info( itemName + ": There are no intents remaining, " +
733 "successfully removed all the intents." )
734 removeIntentResult = main.TRUE
735 return removeIntentResult