blob: 75e586f1e1a832334c2fafe9732c731dd6c96294 [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-onlab2ff57022015-05-29 10:48:51 -070013 onosNode=0,
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070014 host1Id="",
15 host2Id="",
16 mac1="",
17 mac2="",
18 vlan1="-1",
19 vlan2="-1",
20 sw1="",
21 sw2="",
22 expectedLink=0 ):
kelvin-onlabe5239e52015-05-13 14:46:45 -070023 """
kelvin-onlab381b34c2015-05-21 09:21:06 -070024 Description:
25 Verify add-host-intent
26 Steps:
27 - Discover hosts
28 - Add host intents
29 - Check intents
30 - Verify flows
31 - Ping hosts
32 - Reroute
33 - Link down
34 - Verify flows
35 - Check topology
36 - Ping hosts
37 - Link up
38 - Verify flows
39 - Check topology
40 - Ping hosts
41 - Remove intents
42 Required:
43 name - Type of host intent to add eg. IPV4 | VLAN | Dualstack
44 host1 - Name of first host
45 host2 - Name of second host
46 Optional:
47 host1Id - ONOS id of the first host eg. 00:00:00:00:00:01/-1
48 host2Id - ONOS id of the second host
49 mac1 - Mac address of first host
50 mac2 - Mac address of the second host
51 vlan1 - Vlan tag of first host, defaults to -1
52 vlan2 - Vlan tag of second host, defaults to -1
53 sw1 - First switch to bring down & up for rerouting purpose
54 sw2 - Second switch to bring down & up for rerouting purpose
55 expectedLink - Expected link when the switches are down, it should
56 be two links lower than the links before the two
57 switches are down
kelvin-onlabe5239e52015-05-13 14:46:45 -070058 """
59 import time
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070060
61 # Assert variables
62 assert main, "There is no main variable"
63 assert name, "variable name is empty"
64 assert host1 and host2, "You must specify hosts"
65
kelvin-onlabe5239e52015-05-13 14:46:45 -070066 global itemName
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070067 itemName = name
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070068 h1Id = host1Id
69 h2Id = host2Id
70 h1Mac = mac1
71 h2Mac = mac2
72 vlan1 = vlan1
73 vlan2 = vlan2
kelvin-onlab08900012015-05-20 14:30:44 -070074 hostNames = [ host1 , host2 ]
kelvin-onlabe5239e52015-05-13 14:46:45 -070075 intentsId = []
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070076 stepResult = main.TRUE
kelvin-onlabe5239e52015-05-13 14:46:45 -070077 pingResult = main.TRUE
78 intentResult = main.TRUE
kelvin-onlabf0594d72015-05-19 17:25:12 -070079 removeIntentResult = main.TRUE
kelvin-onlabe5239e52015-05-13 14:46:45 -070080 flowResult = main.TRUE
81 topoResult = main.TRUE
82 linkDownResult = main.TRUE
83 linkUpResult = main.TRUE
kelvin-onlaba297c4d2015-06-01 13:53:55 -070084 onosNode = int( onosNode )
kelvin-onlabe5239e52015-05-13 14:46:45 -070085
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070086 if main.hostsData:
87 if not h1Mac:
kelvin-onlab08900012015-05-20 14:30:44 -070088 h1Mac = main.hostsData[ host1 ][ 'mac' ]
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070089 if not h2Mac:
kelvin-onlab08900012015-05-20 14:30:44 -070090 h2Mac = main.hostsData[ host2 ][ 'mac' ]
91 if main.hostsData[ host1 ][ 'vlan' ] != '-1':
92 vlan1 = main.hostsData[ host1 ][ 'vlan' ]
93 if main.hostsData[ host2 ][ 'vlan' ] != '-1':
94 vlan2 = main.hostsData[ host2 ][ 'vlan' ]
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070095 if not h1Id:
kelvin-onlab08900012015-05-20 14:30:44 -070096 h1Id = main.hostsData[ host1 ][ 'id' ]
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070097 if not h2Id:
kelvin-onlab08900012015-05-20 14:30:44 -070098 h2Id = main.hostsData[ host2 ][ 'id' ]
kelvin-onlab2ccad6e2015-05-18 10:36:54 -070099
100 assert h1Id and h2Id, "You must specify host IDs"
101 if not ( h1Id and h2Id ):
102 main.log.info( "There are no host IDs" )
103 return main.FALSE
104
kelvin-onlabe5239e52015-05-13 14:46:45 -0700105 # Discover hosts using arping
kelvin-onlab2ff57022015-05-29 10:48:51 -0700106 if not main.hostsData:
107 main.log.info( itemName + ": Discover host using arping" )
108 main.Mininet1.arping( host=host1 )
109 main.Mininet1.arping( host=host2 )
110 host1 = main.CLIs[ 0 ].getHost( mac=h1Mac )
111 host2 = main.CLIs[ 0 ].getHost( mac=h2Mac )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700112
kelvin-onlaba297c4d2015-06-01 13:53:55 -0700113 # Check flows count in each node
114 checkFlowsCount( main )
115
116 # Checking connectivity before installing intents
117 main.log.info( itemName + ": Check hosts connection before adding intents" )
118 checkPing = pingallHosts( main, hostNames )
119 if not checkPing:
120 main.log.info( itemName + ": Ping did not go through " +
121 "before adding intents" )
122 else:
123 main.log.debug( itemName + ": Pinged successful before adding " +
124 "intents,please check fwd app if it is activated" )
125
kelvin-onlabe5239e52015-05-13 14:46:45 -0700126 # Adding host intents
127 main.log.info( itemName + ": Adding host intents" )
kelvin-onlab2ff57022015-05-29 10:48:51 -0700128 intent1 = main.CLIs[ onosNode ].addHostIntent( hostIdOne=h1Id,
kelvin-onlabe5239e52015-05-13 14:46:45 -0700129 hostIdTwo=h2Id )
130 intentsId.append( intent1 )
131 time.sleep( 5 )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700132
133 # Check intents state
kelvin-onlabf0594d72015-05-19 17:25:12 -0700134 time.sleep( 30 )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700135 intentResult = checkIntentState( main, intentsId )
kelvin-onlaba297c4d2015-06-01 13:53:55 -0700136 checkFlowsCount( main )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700137
kelvin-onlab381b34c2015-05-21 09:21:06 -0700138 # Check intents state again if first check fails...
139 if not intentResult:
140 intentResult = checkIntentState( main, intentsId )
141
kelvin-onlaba297c4d2015-06-01 13:53:55 -0700142 # Check flows count in each node
143 checkFlowsCount( main )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700144 # Verify flows
145 checkFlowsState( main )
146
147 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700148 firstPingResult = pingallHosts( main, hostNames )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700149 if not firstPingResult:
kelvin-onlab08900012015-05-20 14:30:44 -0700150 main.log.debug( "First ping failed, there must be" +
kelvin-onlabf0594d72015-05-19 17:25:12 -0700151 " something wrong with ONOS performance" )
152
kelvin-onlabe5239e52015-05-13 14:46:45 -0700153 # Ping hosts again...
kelvin-onlab08900012015-05-20 14:30:44 -0700154 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700155 time.sleep( 5 )
156
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700157 # Test rerouting if these variables exist
158 if sw1 and sw2 and expectedLink:
159 # link down
kelvin-onlabf0594d72015-05-19 17:25:12 -0700160 linkDownResult = link( main, sw1, sw2, "down" )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700161 intentResult = intentResult and checkIntentState( main, intentsId )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700162
kelvin-onlaba297c4d2015-06-01 13:53:55 -0700163 # Check flows count in each node
164 checkFlowsCount( main )
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
169 topoResult = checkTopology( main, expectedLink )
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-onlab2ccad6e2015-05-18 10:36:54 -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 down
177 if linkDownResult and topoResult and pingResult and intentResult:
178 main.log.info( itemName + ": Successfully brought link down" )
179 else:
kelvin-onlab08900012015-05-20 14:30:44 -0700180 main.log.error( itemName + ": Failed to bring link down" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700181
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700182 # link up
kelvin-onlabf0594d72015-05-19 17:25:12 -0700183 linkUpResult = link( main, sw1, sw2, "up" )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700184 time.sleep( 5 )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700185
kelvin-onlaba297c4d2015-06-01 13:53:55 -0700186 # Check flows count in each node
187 checkFlowsCount( main )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700188 # Verify flows
189 checkFlowsState( main )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700190
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700191 # Check OnosTopology
kelvin-onlabf0594d72015-05-19 17:25:12 -0700192 topoResult = checkTopology( main, main.numLinks )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700193
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700194 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700195 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700196
kelvin-onlabf0594d72015-05-19 17:25:12 -0700197 intentResult = checkIntentState( main, intentsId )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700198
kelvin-onlabf0594d72015-05-19 17:25:12 -0700199 # Checks ONOS state in link up
200 if linkUpResult and topoResult and pingResult and intentResult:
201 main.log.info( itemName + ": Successfully brought link back up" )
202 else:
kelvin-onlab08900012015-05-20 14:30:44 -0700203 main.log.error( itemName + ": Failed to bring link back up" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700204
205 # Remove all intents
206 removeIntentResult = removeAllIntents( main, intentsId )
207
kelvin-onlabe5239e52015-05-13 14:46:45 -0700208 stepResult = pingResult and linkDownResult and linkUpResult \
kelvin-onlabf0594d72015-05-19 17:25:12 -0700209 and intentResult and removeIntentResult
kelvin-onlabe5239e52015-05-13 14:46:45 -0700210
211 return stepResult
212
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700213def pointIntent( main,
kelvin-onlabf0594d72015-05-19 17:25:12 -0700214 name,
215 host1,
216 host2,
kelvin-onlab2ff57022015-05-29 10:48:51 -0700217 onosNode=0,
kelvin-onlab381b34c2015-05-21 09:21:06 -0700218 deviceId1="",
219 deviceId2="",
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700220 port1="",
221 port2="",
222 ethType="",
223 mac1="",
224 mac2="",
225 bandwidth="",
226 lambdaAlloc=False,
227 ipProto="",
228 ip1="",
229 ip2="",
230 tcp1="",
231 tcp2="",
232 sw1="",
233 sw2="",
234 expectedLink=0 ):
kelvin-onlab381b34c2015-05-21 09:21:06 -0700235
kelvin-onlabe5239e52015-05-13 14:46:45 -0700236 """
kelvin-onlab381b34c2015-05-21 09:21:06 -0700237 Description:
238 Verify add-point-intent
239 Steps:
240 - Get device ids | ports
241 - Add point intents
242 - Check intents
243 - Verify flows
244 - Ping hosts
245 - Reroute
246 - Link down
247 - Verify flows
248 - Check topology
249 - Ping hosts
250 - Link up
251 - Verify flows
252 - Check topology
253 - Ping hosts
254 - Remove intents
255 Required:
256 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
257 host1 - Name of first host
258 host2 - Name of second host
259 Optional:
260 deviceId1 - ONOS device id of the first switch, the same as the
261 location of the first host eg. of:0000000000000001/1,
262 located at device 1 port 1
263 deviceId2 - ONOS device id of the second switch
264 port1 - The port number where the first host is attached
265 port2 - The port number where the second host is attached
266 ethType - Ethernet type eg. IPV4, IPV6
267 mac1 - Mac address of first host
268 mac2 - Mac address of the second host
269 bandwidth - Bandwidth capacity
270 lambdaAlloc - Allocate lambda, defaults to False
271 ipProto - IP protocol
272 ip1 - IP address of first host
273 ip2 - IP address of second host
274 tcp1 - TCP port of first host
275 tcp2 - TCP port of second host
276 sw1 - First switch to bring down & up for rerouting purpose
277 sw2 - Second switch to bring down & up for rerouting purpose
278 expectedLink - Expected link when the switches are down, it should
279 be two links lower than the links before the two
280 switches are down
kelvin-onlabe5239e52015-05-13 14:46:45 -0700281 """
kelvin-onlab381b34c2015-05-21 09:21:06 -0700282
kelvin-onlabe5239e52015-05-13 14:46:45 -0700283 import time
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700284 assert main, "There is no main variable"
285 assert name, "variable name is empty"
286 assert host1 and host2, "You must specify hosts"
287
kelvin-onlabe5239e52015-05-13 14:46:45 -0700288 global itemName
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700289 itemName = name
kelvin-onlab08900012015-05-20 14:30:44 -0700290 host1 = host1
291 host2 = host2
292 hostNames = [ host1, host2 ]
kelvin-onlabe5239e52015-05-13 14:46:45 -0700293 intentsId = []
kelvin-onlabb2235602015-05-13 17:51:06 -0700294
kelvin-onlabe5239e52015-05-13 14:46:45 -0700295 pingResult = main.TRUE
296 intentResult = main.TRUE
kelvin-onlabf0594d72015-05-19 17:25:12 -0700297 removeIntentResult = main.TRUE
kelvin-onlabe5239e52015-05-13 14:46:45 -0700298 flowResult = main.TRUE
299 topoResult = main.TRUE
300 linkDownResult = main.TRUE
301 linkUpResult = main.TRUE
kelvin-onlaba297c4d2015-06-01 13:53:55 -0700302 onosNode = int( onosNode )
303
304 # Checking connectivity before installing intents
305 main.log.info( itemName + ": Check hosts connection before adding intents" )
306 checkPing = pingallHosts( main, hostNames )
307 if not checkPing:
308 main.log.info( itemName + ": Ping did not go through " +
309 "before adding intents" )
310 else:
311 main.log.debug( itemName + ": Pinged successful before adding " +
312 "intents,please check fwd app if it is activated" )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700313
kelvin-onlabb2235602015-05-13 17:51:06 -0700314 # Adding bidirectional point intents
kelvin-onlabf0594d72015-05-19 17:25:12 -0700315 main.log.info( itemName + ": Adding point intents" )
kelvin-onlab2ff57022015-05-29 10:48:51 -0700316 intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1,
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700317 egressDevice=deviceId2,
318 portIngress=port1,
319 portEgress=port2,
kelvin-onlabb2235602015-05-13 17:51:06 -0700320 ethType=ethType,
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700321 ethSrc=mac1,
322 ethDst=mac2,
kelvin-onlabb2235602015-05-13 17:51:06 -0700323 bandwidth=bandwidth,
324 lambdaAlloc=lambdaAlloc,
325 ipProto=ipProto,
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700326 ipSrc=ip1,
327 ipDst=ip2,
328 tcpSrc=tcp1,
329 tcpDst=tcp2 )
kelvin-onlabb2235602015-05-13 17:51:06 -0700330
kelvin-onlabe5239e52015-05-13 14:46:45 -0700331 intentsId.append( intent1 )
332 time.sleep( 5 )
kelvin-onlab2ff57022015-05-29 10:48:51 -0700333 intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2,
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700334 egressDevice=deviceId1,
335 portIngress=port2,
336 portEgress=port1,
kelvin-onlabb2235602015-05-13 17:51:06 -0700337 ethType=ethType,
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700338 ethSrc=mac2,
339 ethDst=mac1,
kelvin-onlabb2235602015-05-13 17:51:06 -0700340 bandwidth=bandwidth,
341 lambdaAlloc=lambdaAlloc,
342 ipProto=ipProto,
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700343 ipSrc=ip2,
344 ipDst=ip1,
345 tcpSrc=tcp2,
346 tcpDst=tcp1 )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700347 intentsId.append( intent2 )
348
349 # Check intents state
kelvin-onlabf0594d72015-05-19 17:25:12 -0700350 time.sleep( 30 )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700351 intentResult = checkIntentState( main, intentsId )
kelvin-onlaba297c4d2015-06-01 13:53:55 -0700352 # Check flows count in each node
353 checkFlowsCount( main )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700354
kelvin-onlab381b34c2015-05-21 09:21:06 -0700355 # Check intents state again if first check fails...
356 if not intentResult:
357 intentResult = checkIntentState( main, intentsId )
358
kelvin-onlaba297c4d2015-06-01 13:53:55 -0700359 # Check flows count in each node
360 checkFlowsCount( main )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700361 # Verify flows
362 checkFlowsState( main )
363
364 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700365 firstPingResult = pingallHosts( main, hostNames )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700366 if not firstPingResult:
kelvin-onlab08900012015-05-20 14:30:44 -0700367 main.log.debug( "First ping failed, there must be" +
kelvin-onlabf0594d72015-05-19 17:25:12 -0700368 " something wrong with ONOS performance" )
369
kelvin-onlabe5239e52015-05-13 14:46:45 -0700370 # Ping hosts again...
kelvin-onlab08900012015-05-20 14:30:44 -0700371 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700372 time.sleep( 5 )
373
kelvin-onlabf0594d72015-05-19 17:25:12 -0700374 # Test rerouting if these variables exist
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700375 if sw1 and sw2 and expectedLink:
376 # link down
kelvin-onlabf0594d72015-05-19 17:25:12 -0700377 linkDownResult = link( main, sw1, sw2, "down" )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700378 intentResult = intentResult and checkIntentState( main, intentsId )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700379
kelvin-onlaba297c4d2015-06-01 13:53:55 -0700380 # Check flows count in each node
381 checkFlowsCount( main )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700382 # Verify flows
383 checkFlowsState( main )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700384
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700385 # Check OnosTopology
386 topoResult = checkTopology( main, expectedLink )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700387
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700388 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700389 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700390
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700391 intentResult = checkIntentState( main, intentsId )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700392
kelvin-onlabf0594d72015-05-19 17:25:12 -0700393 # Checks ONOS state in link down
394 if linkDownResult and topoResult and pingResult and intentResult:
395 main.log.info( itemName + ": Successfully brought link down" )
396 else:
kelvin-onlab08900012015-05-20 14:30:44 -0700397 main.log.error( itemName + ": Failed to bring link down" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700398
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700399 # link up
kelvin-onlabf0594d72015-05-19 17:25:12 -0700400 linkUpResult = link( main, sw1, sw2, "up" )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700401 time.sleep( 5 )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700402
kelvin-onlaba297c4d2015-06-01 13:53:55 -0700403 # Check flows count in each node
404 checkFlowsCount( main )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700405 # Verify flows
406 checkFlowsState( main )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700407
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700408 # Check OnosTopology
kelvin-onlabf0594d72015-05-19 17:25:12 -0700409 topoResult = checkTopology( main, main.numLinks )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700410
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700411 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700412 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700413
kelvin-onlabf0594d72015-05-19 17:25:12 -0700414 intentResult = checkIntentState( main, intentsId )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700415
kelvin-onlabf0594d72015-05-19 17:25:12 -0700416 # Checks ONOS state in link up
417 if linkUpResult and topoResult and pingResult and intentResult:
418 main.log.info( itemName + ": Successfully brought link back up" )
419 else:
kelvin-onlab08900012015-05-20 14:30:44 -0700420 main.log.error( itemName + ": Failed to bring link back up" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700421
422 # Remove all intents
423 removeIntentResult = removeAllIntents( main, intentsId )
424
kelvin-onlabe5239e52015-05-13 14:46:45 -0700425 stepResult = pingResult and linkDownResult and linkUpResult \
kelvin-onlabf0594d72015-05-19 17:25:12 -0700426 and intentResult and removeIntentResult
kelvin-onlabe5239e52015-05-13 14:46:45 -0700427
428 return stepResult
429
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700430def singleToMultiIntent( main,
kelvin-onlabf0594d72015-05-19 17:25:12 -0700431 name,
432 hostNames,
kelvin-onlab2ff57022015-05-29 10:48:51 -0700433 onosNode=0,
kelvin-onlab90b6b042015-05-18 20:57:13 -0700434 devices="",
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700435 ports=None,
436 ethType="",
437 macs=None,
438 bandwidth="",
439 lambdaAlloc=False,
440 ipProto="",
441 ipAddresses="",
442 tcp="",
443 sw1="",
444 sw2="",
445 expectedLink=0 ):
446 """
kelvin-onlab381b34c2015-05-21 09:21:06 -0700447 Verify Single to Multi Point intents
448 NOTE:If main.hostsData is not defined, variables data should be passed in the
kelvin-onlabf0594d72015-05-19 17:25:12 -0700449 same order index wise. All devices in the list should have the same
450 format, either all the devices have its port or it doesn't.
kelvin-onlab90b6b042015-05-18 20:57:13 -0700451 eg. hostName = [ 'h1', 'h2' ,.. ]
452 devices = [ 'of:0000000000000001', 'of:0000000000000002', ...]
453 ports = [ '1', '1', ..]
454 ...
kelvin-onlab381b34c2015-05-21 09:21:06 -0700455 Description:
kelvin-onlab583fcb52015-05-21 13:10:46 -0700456 Verify add-single-to-multi-intent iterates through the list of given
457 host | devices and add intents
kelvin-onlab381b34c2015-05-21 09:21:06 -0700458 Steps:
459 - Get device ids | ports
460 - Add single to multi point intents
461 - Check intents
462 - Verify flows
463 - Ping hosts
464 - Reroute
465 - Link down
466 - Verify flows
467 - Check topology
468 - Ping hosts
469 - Link up
470 - Verify flows
471 - Check topology
472 - Ping hosts
473 - Remove intents
474 Required:
475 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
476 hostNames - List of host names
477 Optional:
478 devices - List of device ids in the same order as the hosts
479 in hostNames
480 ports - List of port numbers in the same order as the device in
481 devices
482 ethType - Ethernet type eg. IPV4, IPV6
483 macs - List of hosts mac address in the same order as the hosts in
484 hostNames
485 bandwidth - Bandwidth capacity
486 lambdaAlloc - Allocate lambda, defaults to False
487 ipProto - IP protocol
488 ipAddresses - IP addresses of host in the same order as the hosts in
489 hostNames
490 tcp - TCP ports in the same order as the hosts in hostNames
491 sw1 - First switch to bring down & up for rerouting purpose
492 sw2 - Second switch to bring down & up for rerouting purpose
493 expectedLink - Expected link when the switches are down, it should
494 be two links lower than the links before the two
495 switches are down
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700496 """
kelvin-onlab381b34c2015-05-21 09:21:06 -0700497
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700498 import time
kelvin-onlabf0594d72015-05-19 17:25:12 -0700499 import copy
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700500 assert main, "There is no main variable"
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700501 assert hostNames, "You must specify hosts"
502 assert devices or main.hostsData, "You must specify devices"
503
504 global itemName
505 itemName = name
kelvin-onlab90b6b042015-05-18 20:57:13 -0700506 tempHostsData = {}
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700507 intentsId = []
kelvin-onlaba297c4d2015-06-01 13:53:55 -0700508 onosNode = int( onosNode )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700509
kelvin-onlab08900012015-05-20 14:30:44 -0700510 macsDict = {}
511 ipDict = {}
kelvin-onlab90b6b042015-05-18 20:57:13 -0700512 if hostNames and devices:
513 if len( hostNames ) != len( devices ):
kelvin-onlab08900012015-05-20 14:30:44 -0700514 main.log.debug( "hosts and devices does not have the same length" )
515 #print "len hostNames = ", len( hostNames )
516 #print "len devices = ", len( devices )
kelvin-onlab90b6b042015-05-18 20:57:13 -0700517 return main.FALSE
518 if ports:
519 if len( ports ) != len( devices ):
520 main.log.error( "Ports and devices does " +
521 "not have the same length" )
kelvin-onlab08900012015-05-20 14:30:44 -0700522 #print "len devices = ", len( devices )
523 #print "len ports = ", len( ports )
kelvin-onlab90b6b042015-05-18 20:57:13 -0700524 return main.FALSE
525 else:
526 main.log.info( "Device Ports are not specified" )
kelvin-onlabf2ec6e02015-05-27 14:15:28 -0700527 if macs:
528 for i in range( len( devices ) ):
529 macsDict[ devices[ i ] ] = macs[ i ]
530
kelvin-onlab90b6b042015-05-18 20:57:13 -0700531 elif hostNames and not devices and main.hostsData:
kelvin-onlab08900012015-05-20 14:30:44 -0700532 devices = []
kelvin-onlab90b6b042015-05-18 20:57:13 -0700533 main.log.info( "singleToMultiIntent function is using main.hostsData" )
kelvin-onlab08900012015-05-20 14:30:44 -0700534 for host in hostNames:
kelvin-onlab08900012015-05-20 14:30:44 -0700535 devices.append( main.hostsData.get( host ).get( 'location' ) )
536 macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \
537 main.hostsData.get( host ).get( 'mac' )
538 ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \
539 main.hostsData.get( host ).get( 'ipAddresses' )
kelvin-onlab381b34c2015-05-21 09:21:06 -0700540 #print main.hostsData
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700541
kelvin-onlab381b34c2015-05-21 09:21:06 -0700542 #print 'host names = ', hostNames
543 #print 'devices = ', devices
544 #print "macsDict = ", macsDict
kelvin-onlabf0594d72015-05-19 17:25:12 -0700545
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700546 pingResult = main.TRUE
547 intentResult = main.TRUE
kelvin-onlabf0594d72015-05-19 17:25:12 -0700548 removeIntentResult = main.TRUE
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700549 flowResult = main.TRUE
550 topoResult = main.TRUE
551 linkDownResult = main.TRUE
552 linkUpResult = main.TRUE
553
kelvin-onlabf0594d72015-05-19 17:25:12 -0700554 devicesCopy = copy.copy( devices )
555 if ports:
556 portsCopy = copy.copy( ports )
557 main.log.info( itemName + ": Adding single point to multi point intents" )
kelvin-onlaba297c4d2015-06-01 13:53:55 -0700558
559 # Check flows count in each node
560 checkFlowsCount( main )
561
562 # Checking connectivity before installing intents
563 main.log.info( itemName + ": Check hosts connection before adding intents" )
564 checkPing = pingallHosts( main, hostNames )
565 if not checkPing:
566 main.log.info( itemName + ": Ping did not go through " +
567 "before adding intents" )
568 else:
569 main.log.debug( itemName + ": Pinged successful before adding " +
570 "intents,please check fwd app if it is activated" )
571
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700572 # Adding bidirectional point intents
kelvin-onlabf0594d72015-05-19 17:25:12 -0700573 for i in range( len( devices ) ):
574 ingressDevice = devicesCopy[ i ]
575 egressDeviceList = copy.copy( devicesCopy )
576 egressDeviceList.remove( ingressDevice )
577 if ports:
578 portIngress = portsCopy[ i ]
579 portEgressList = copy.copy( portsCopy )
580 del portEgressList[ i ]
581 else:
582 portIngress = ""
583 portEgressList = None
kelvin-onlab08900012015-05-20 14:30:44 -0700584 if not macsDict:
585 srcMac = ""
586 else:
587 srcMac = macsDict[ ingressDevice ]
588 if srcMac == None:
kelvin-onlabc751ab42015-05-21 14:09:39 -0700589 main.log.debug( "There is no MAC in device - " + ingressDevice )
kelvin-onlab08900012015-05-20 14:30:44 -0700590 srcMac = ""
591
kelvin-onlab2ff57022015-05-29 10:48:51 -0700592 intentsId.append(
593 main.CLIs[ onosNode ].addSinglepointToMultipointIntent(
kelvin-onlabf0594d72015-05-19 17:25:12 -0700594 ingressDevice=ingressDevice,
595 egressDeviceList=egressDeviceList,
596 portIngress=portIngress,
597 portEgressList=portEgressList,
kelvin-onlab90b6b042015-05-18 20:57:13 -0700598 ethType=ethType,
kelvin-onlab08900012015-05-20 14:30:44 -0700599 ethSrc=srcMac,
kelvin-onlab90b6b042015-05-18 20:57:13 -0700600 bandwidth=bandwidth,
601 lambdaAlloc=lambdaAlloc,
602 ipProto=ipProto,
kelvin-onlabf0594d72015-05-19 17:25:12 -0700603 ipSrc="",
604 ipDst="",
605 tcpSrc="",
606 tcpDst="" ) )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700607
kelvin-onlaba297c4d2015-06-01 13:53:55 -0700608 # Wait some time for the flow to go through when using multi instance
kelvin-onlab2ff57022015-05-29 10:48:51 -0700609 time.sleep( 10 )
kelvin-onlab08900012015-05-20 14:30:44 -0700610 pingResult = pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700611
612 # Check intents state
kelvin-onlabf0594d72015-05-19 17:25:12 -0700613 time.sleep( 30 )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700614 intentResult = checkIntentState( main, intentsId )
615
kelvin-onlab381b34c2015-05-21 09:21:06 -0700616 # Check intents state again if first check fails...
617 if not intentResult:
618 intentResult = checkIntentState( main, intentsId )
619
kelvin-onlaba297c4d2015-06-01 13:53:55 -0700620 # Check flows count in each node
621 checkFlowsCount( main )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700622 # Verify flows
623 checkFlowsState( main )
624
625 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700626 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700627 # Ping hosts again...
kelvin-onlab08900012015-05-20 14:30:44 -0700628 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700629 time.sleep( 5 )
630
kelvin-onlabf0594d72015-05-19 17:25:12 -0700631 # Test rerouting if these variables exist
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700632 if sw1 and sw2 and expectedLink:
633 # link down
kelvin-onlabf0594d72015-05-19 17:25:12 -0700634 linkDownResult = link( main, sw1, sw2, "down" )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700635 intentResult = intentResult and checkIntentState( main, intentsId )
636
kelvin-onlaba297c4d2015-06-01 13:53:55 -0700637 # Check flows count in each node
638 checkFlowsCount( main )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700639 # Verify flows
640 checkFlowsState( main )
641
642 # Check OnosTopology
643 topoResult = checkTopology( main, expectedLink )
644
645 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700646 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700647
648 intentResult = checkIntentState( main, intentsId )
649
kelvin-onlabf0594d72015-05-19 17:25:12 -0700650 # Checks ONOS state in link down
651 if linkDownResult and topoResult and pingResult and intentResult:
652 main.log.info( itemName + ": Successfully brought link down" )
653 else:
kelvin-onlab08900012015-05-20 14:30:44 -0700654 main.log.error( itemName + ": Failed to bring link down" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700655
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700656 # link up
kelvin-onlabf0594d72015-05-19 17:25:12 -0700657 linkUpResult = link( main, sw1, sw2, "up" )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700658 time.sleep( 5 )
659
kelvin-onlaba297c4d2015-06-01 13:53:55 -0700660 # Check flows count in each node
661 checkFlowsCount( main )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700662 # Verify flows
663 checkFlowsState( main )
664
665 # Check OnosTopology
kelvin-onlabf0594d72015-05-19 17:25:12 -0700666 topoResult = checkTopology( main, main.numLinks )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700667
668 # Ping hosts
kelvin-onlab08900012015-05-20 14:30:44 -0700669 pingResult = pingResult and pingallHosts( main, hostNames )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700670
kelvin-onlabf0594d72015-05-19 17:25:12 -0700671 intentResult = checkIntentState( main, intentsId )
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700672
kelvin-onlabf0594d72015-05-19 17:25:12 -0700673 # Checks ONOS state in link up
674 if linkUpResult and topoResult and pingResult and intentResult:
675 main.log.info( itemName + ": Successfully brought link back up" )
676 else:
kelvin-onlab08900012015-05-20 14:30:44 -0700677 main.log.error( itemName + ": Failed to bring link back up" )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700678
679 # Remove all intents
680 removeIntentResult = removeAllIntents( main, intentsId )
681
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700682 stepResult = pingResult and linkDownResult and linkUpResult \
kelvin-onlabf0594d72015-05-19 17:25:12 -0700683 and intentResult and removeIntentResult
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700684
685 return stepResult
686
kelvin-onlabc751ab42015-05-21 14:09:39 -0700687def multiToSingleIntent( main,
688 name,
689 hostNames,
kelvin-onlab2ff57022015-05-29 10:48:51 -0700690 onosNode=0,
kelvin-onlabc751ab42015-05-21 14:09:39 -0700691 devices="",
692 ports=None,
693 ethType="",
694 macs=None,
695 bandwidth="",
696 lambdaAlloc=False,
697 ipProto="",
698 ipAddresses="",
699 tcp="",
700 sw1="",
701 sw2="",
702 expectedLink=0 ):
703 """
704 Verify Single to Multi Point intents
705 NOTE:If main.hostsData is not defined, variables data should be passed in the
706 same order index wise. All devices in the list should have the same
707 format, either all the devices have its port or it doesn't.
708 eg. hostName = [ 'h1', 'h2' ,.. ]
709 devices = [ 'of:0000000000000001', 'of:0000000000000002', ...]
710 ports = [ '1', '1', ..]
711 ...
712 Description:
713 Verify add-multi-to-single-intent
714 Steps:
715 - Get device ids | ports
kelvin-onlabb2310a42015-05-21 14:17:29 -0700716 - Add multi to single point intents
kelvin-onlabc751ab42015-05-21 14:09:39 -0700717 - Check intents
718 - Verify flows
719 - Ping hosts
720 - Reroute
721 - Link down
722 - Verify flows
723 - Check topology
724 - Ping hosts
725 - Link up
726 - Verify flows
727 - Check topology
728 - Ping hosts
729 - Remove intents
730 Required:
731 name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
732 hostNames - List of host names
733 Optional:
734 devices - List of device ids in the same order as the hosts
735 in hostNames
736 ports - List of port numbers in the same order as the device in
737 devices
738 ethType - Ethernet type eg. IPV4, IPV6
739 macs - List of hosts mac address in the same order as the hosts in
740 hostNames
741 bandwidth - Bandwidth capacity
742 lambdaAlloc - Allocate lambda, defaults to False
743 ipProto - IP protocol
744 ipAddresses - IP addresses of host in the same order as the hosts in
745 hostNames
746 tcp - TCP ports in the same order as the hosts in hostNames
747 sw1 - First switch to bring down & up for rerouting purpose
748 sw2 - Second switch to bring down & up for rerouting purpose
749 expectedLink - Expected link when the switches are down, it should
750 be two links lower than the links before the two
751 switches are down
752 """
753
754 import time
755 import copy
756 assert main, "There is no main variable"
757 assert hostNames, "You must specify hosts"
758 assert devices or main.hostsData, "You must specify devices"
759
760 global itemName
761 itemName = name
762 tempHostsData = {}
763 intentsId = []
kelvin-onlaba297c4d2015-06-01 13:53:55 -0700764 onosNode = int( onosNode )
kelvin-onlabc751ab42015-05-21 14:09:39 -0700765
766 macsDict = {}
767 ipDict = {}
768 if hostNames and devices:
769 if len( hostNames ) != len( devices ):
770 main.log.debug( "hosts and devices does not have the same length" )
771 #print "len hostNames = ", len( hostNames )
772 #print "len devices = ", len( devices )
773 return main.FALSE
774 if ports:
775 if len( ports ) != len( devices ):
776 main.log.error( "Ports and devices does " +
777 "not have the same length" )
778 #print "len devices = ", len( devices )
779 #print "len ports = ", len( ports )
780 return main.FALSE
kelvin-onlabc751ab42015-05-21 14:09:39 -0700781 else:
782 main.log.info( "Device Ports are not specified" )
kelvin-onlabf2ec6e02015-05-27 14:15:28 -0700783 if macs:
784 for i in range( len( devices ) ):
785 macsDict[ devices[ i ] ] = macs[ i ]
kelvin-onlabc751ab42015-05-21 14:09:39 -0700786 elif hostNames and not devices and main.hostsData:
787 devices = []
kelvin-onlabb2310a42015-05-21 14:17:29 -0700788 main.log.info( "multiToSingleIntent function is using main.hostsData" )
kelvin-onlabc751ab42015-05-21 14:09:39 -0700789 for host in hostNames:
790 devices.append( main.hostsData.get( host ).get( 'location' ) )
791 macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \
792 main.hostsData.get( host ).get( 'mac' )
793 ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \
794 main.hostsData.get( host ).get( 'ipAddresses' )
795 #print main.hostsData
796
797 #print 'host names = ', hostNames
798 #print 'devices = ', devices
799 #print "macsDict = ", macsDict
800
801 pingResult = main.TRUE
802 intentResult = main.TRUE
803 removeIntentResult = main.TRUE
804 flowResult = main.TRUE
805 topoResult = main.TRUE
806 linkDownResult = main.TRUE
807 linkUpResult = main.TRUE
808
809 devicesCopy = copy.copy( devices )
810 if ports:
811 portsCopy = copy.copy( ports )
kelvin-onlabb2310a42015-05-21 14:17:29 -0700812 main.log.info( itemName + ": Adding multi point to single point intents" )
kelvin-onlaba297c4d2015-06-01 13:53:55 -0700813
814 # Check flows count in each node
815 checkFlowsCount( main )
816
817 # Checking connectivity before installing intents
818 main.log.info( itemName + ": Check hosts connection before adding intents" )
819 checkPing = pingallHosts( main, hostNames )
820 if not checkPing:
821 main.log.info( itemName + ": Ping did not go through " +
822 "before adding intents" )
823 else:
824 main.log.debug( itemName + ": Pinged successful before adding " +
825 "intents,please check fwd app if it is activated" )
826
kelvin-onlabc751ab42015-05-21 14:09:39 -0700827 # Adding bidirectional point intents
828 for i in range( len( devices ) ):
829 egressDevice = devicesCopy[ i ]
830 ingressDeviceList = copy.copy( devicesCopy )
831 ingressDeviceList.remove( egressDevice )
832 if ports:
833 portEgress = portsCopy[ i ]
834 portIngressList = copy.copy( portsCopy )
835 del portIngressList[ i ]
836 else:
837 portEgress = ""
838 portIngressList = None
839 if not macsDict:
840 dstMac = ""
841 else:
842 dstMac = macsDict[ egressDevice ]
843 if dstMac == None:
844 main.log.debug( "There is no MAC in device - " + egressDevice )
845 dstMac = ""
846
kelvin-onlab2ff57022015-05-29 10:48:51 -0700847 intentsId.append(
848 main.CLIs[ onosNode ].addMultipointToSinglepointIntent(
kelvin-onlabc751ab42015-05-21 14:09:39 -0700849 ingressDeviceList=ingressDeviceList,
850 egressDevice=egressDevice,
851 portIngressList=portIngressList,
852 portEgress=portEgress,
853 ethType=ethType,
854 ethDst=dstMac,
855 bandwidth=bandwidth,
856 lambdaAlloc=lambdaAlloc,
857 ipProto=ipProto,
858 ipSrc="",
859 ipDst="",
860 tcpSrc="",
861 tcpDst="" ) )
862
863 pingResult = pingallHosts( main, hostNames )
864
865 # Check intents state
866 time.sleep( 30 )
867 intentResult = checkIntentState( main, intentsId )
868
869 # Check intents state again if first check fails...
870 if not intentResult:
871 intentResult = checkIntentState( main, intentsId )
872
kelvin-onlaba297c4d2015-06-01 13:53:55 -0700873 # Check flows count in each node
874 checkFlowsCount( main )
kelvin-onlabc751ab42015-05-21 14:09:39 -0700875 # Verify flows
876 checkFlowsState( main )
877
878 # Ping hosts
879 pingResult = pingResult and pingallHosts( main, hostNames )
880 # Ping hosts again...
881 pingResult = pingResult and pingallHosts( main, hostNames )
882 time.sleep( 5 )
883
884 # Test rerouting if these variables exist
885 if sw1 and sw2 and expectedLink:
886 # link down
887 linkDownResult = link( main, sw1, sw2, "down" )
888 intentResult = intentResult and checkIntentState( main, intentsId )
889
kelvin-onlaba297c4d2015-06-01 13:53:55 -0700890 # Check flows count in each node
891 checkFlowsCount( main )
kelvin-onlabc751ab42015-05-21 14:09:39 -0700892 # Verify flows
893 checkFlowsState( main )
894
895 # Check OnosTopology
896 topoResult = checkTopology( main, expectedLink )
897
898 # Ping hosts
899 pingResult = pingResult and pingallHosts( main, hostNames )
900
901 intentResult = checkIntentState( main, intentsId )
902
903 # Checks ONOS state in link down
904 if linkDownResult and topoResult and pingResult and intentResult:
905 main.log.info( itemName + ": Successfully brought link down" )
906 else:
907 main.log.error( itemName + ": Failed to bring link down" )
908
909 # link up
910 linkUpResult = link( main, sw1, sw2, "up" )
911 time.sleep( 5 )
912
kelvin-onlaba297c4d2015-06-01 13:53:55 -0700913 # Check flows count in each node
914 checkFlowsCount( main )
kelvin-onlabc751ab42015-05-21 14:09:39 -0700915 # Verify flows
916 checkFlowsState( main )
917
918 # Check OnosTopology
919 topoResult = checkTopology( main, main.numLinks )
920
921 # Ping hosts
922 pingResult = pingResult and pingallHosts( main, hostNames )
923
924 intentResult = checkIntentState( main, intentsId )
925
926 # Checks ONOS state in link up
927 if linkUpResult and topoResult and pingResult and intentResult:
928 main.log.info( itemName + ": Successfully brought link back up" )
929 else:
930 main.log.error( itemName + ": Failed to bring link back up" )
931
932 # Remove all intents
933 removeIntentResult = removeAllIntents( main, intentsId )
934
935 stepResult = pingResult and linkDownResult and linkUpResult \
936 and intentResult and removeIntentResult
937
938 return stepResult
939
kelvin-onlab08900012015-05-20 14:30:44 -0700940def pingallHosts( main, hostList, pingType="ipv4" ):
kelvin-onlabf0594d72015-05-19 17:25:12 -0700941 # Ping all host in the hosts list variable
kelvin-onlab08900012015-05-20 14:30:44 -0700942 print "Pinging : ", hostList
kelvin-onlabf0594d72015-05-19 17:25:12 -0700943 pingResult = main.TRUE
kelvin-onlab08900012015-05-20 14:30:44 -0700944 pingResult = main.Mininet1.pingallHosts( hostList, pingType )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700945 return pingResult
946
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700947def getHostsData( main ):
kelvin-onlabe5239e52015-05-13 14:46:45 -0700948 """
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700949 Use fwd app and pingall to discover all the hosts
kelvin-onlabe5239e52015-05-13 14:46:45 -0700950 """
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700951 import json
952 activateResult = main.TRUE
953 appCheck = main.TRUE
kelvin-onlab08900012015-05-20 14:30:44 -0700954 getDataResult = main.TRUE
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700955 main.log.info( "Activating reactive forwarding app " )
956 activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
957
958 for i in range( main.numCtrls ):
959 appCheck = appCheck and main.CLIs[ i ].appToIDCheck()
kelvin-onlabf0594d72015-05-19 17:25:12 -0700960 if appCheck != main.TRUE:
kelvin-onlab08900012015-05-20 14:30:44 -0700961 main.log.warn( main.CLIs[ i ].apps() )
962 main.log.warn( main.CLIs[ i ].appIDs() )
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700963
964 pingResult = main.Mininet1.pingall()
965 hostsJson = json.loads( main.CLIs[ 0 ].hosts() )
Jon Hallb87f3db2015-07-06 03:10:27 -0700966 hosts = main.Mininet1.getHosts()
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700967 for host in hosts:
968 main.hostsData[ host ] = {}
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700969 main.hostsData[ host ][ 'mac' ] = \
970 main.Mininet1.getMacAddress( host ).upper()
kelvin-onlab2ccad6e2015-05-18 10:36:54 -0700971 for hostj in hostsJson:
972 if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]:
973 main.hostsData[ host ][ 'id' ] = hostj[ 'id' ]
974 main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ]
975 main.hostsData[ host ][ 'location' ] = \
976 hostj[ 'location' ][ 'elementId' ] + '/' + \
977 hostj[ 'location' ][ 'port' ]
978 main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ]
979
kelvin-onlabe7270fa2015-05-18 14:35:03 -0700980 main.log.info( "Deactivating reactive forwarding app " )
kelvin-onlabf0594d72015-05-19 17:25:12 -0700981 deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
kelvin-onlab08900012015-05-20 14:30:44 -0700982 if activateResult and deactivateResult and main.hostsData:
kelvin-onlabf0594d72015-05-19 17:25:12 -0700983 main.log.info( "Successfully used fwd app to discover hosts " )
kelvin-onlab08900012015-05-20 14:30:44 -0700984 getDataResult = main.TRUE
kelvin-onlabf0594d72015-05-19 17:25:12 -0700985 else:
986 main.log.info( "Failed to use fwd app to discover hosts " )
kelvin-onlab08900012015-05-20 14:30:44 -0700987 getDataResult = main.FALSE
kelvin-onlabf0594d72015-05-19 17:25:12 -0700988
kelvin-onlab08900012015-05-20 14:30:44 -0700989 print main.hostsData
kelvin-onlabf0594d72015-05-19 17:25:12 -0700990
kelvin-onlab08900012015-05-20 14:30:44 -0700991 return getDataResult
kelvin-onlabe5239e52015-05-13 14:46:45 -0700992
993def checkTopology( main, expectedLink ):
994 statusResult = main.TRUE
995 # Check onos topology
996 main.log.info( itemName + ": Checking ONOS topology " )
997
998 for i in range( main.numCtrls ):
999 topologyResult = main.CLIs[ i ].topology()
1000 statusResult = main.ONOSbench.checkStatus( topologyResult,
1001 main.numSwitch,
1002 expectedLink )\
1003 and statusResult
1004 if not statusResult:
kelvin-onlab381b34c2015-05-21 09:21:06 -07001005 main.log.error( itemName + ": Topology mismatch" )
kelvin-onlabe5239e52015-05-13 14:46:45 -07001006 else:
1007 main.log.info( itemName + ": Topology match" )
1008 return statusResult
1009
1010def checkIntentState( main, intentsId ):
kelvin-onlabf512e942015-06-08 19:42:59 -07001011 """
1012 This function will check intent state to make sure all the intents
1013 are in INSTALLED state
1014 """
kelvin-onlabe5239e52015-05-13 14:46:45 -07001015
kelvin-onlab381b34c2015-05-21 09:21:06 -07001016 intentResult = main.TRUE
kelvin-onlab2ff57022015-05-29 10:48:51 -07001017 results = []
kelvin-onlab381b34c2015-05-21 09:21:06 -07001018
1019 main.log.info( itemName + ": Checking intents state" )
kelvin-onlabf512e942015-06-08 19:42:59 -07001020 # First check of intents
kelvin-onlabe5239e52015-05-13 14:46:45 -07001021 for i in range( main.numCtrls ):
kelvin-onlabf512e942015-06-08 19:42:59 -07001022 tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId )
1023 results.append( tempResult )
1024
1025 expectedState = [ 'INSTALLED', 'INSTALLING' ]
kelvin-onlab2ff57022015-05-29 10:48:51 -07001026
1027 if all( result == main.TRUE for result in results ):
1028 main.log.info( itemName + ": Intents are installed correctly" )
1029 else:
kelvin-onlabf512e942015-06-08 19:42:59 -07001030 # Wait for at least 5 second before checking the intents again
1031 time.sleep( 5 )
1032 results = []
1033 # Second check of intents since some of the intents may be in
1034 # INSTALLING state, they should be in INSTALLED at this time
1035 for i in range( main.numCtrls ):
1036 tempResult = main.CLIs[ i ].checkIntentState(
1037 intentsId=intentsId )
1038 results.append( tempResult )
1039 if all( result == main.TRUE for result in results ):
1040 main.log.info( itemName + ": Intents are installed correctly" )
1041 else:
1042 main.log.error( itemName + ": Intents are NOT installed correctly" )
1043 intentResult = main.FALSE
kelvin-onlab381b34c2015-05-21 09:21:06 -07001044
kelvin-onlabe5239e52015-05-13 14:46:45 -07001045 return intentResult
1046
1047def checkFlowsState( main ):
1048
1049 main.log.info( itemName + ": Check flows state" )
1050 checkFlowsResult = main.CLIs[ 0 ].checkFlowsState()
1051 return checkFlowsResult
1052
kelvin-onlabf0594d72015-05-19 17:25:12 -07001053def link( main, sw1, sw2, option):
kelvin-onlabe5239e52015-05-13 14:46:45 -07001054
kelvin-onlabf0594d72015-05-19 17:25:12 -07001055 # link down
1056 main.log.info( itemName + ": Bring link " + option + "between " +
1057 sw1 + " and " + sw2 )
1058 linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option )
1059 return linkResult
1060
1061def removeAllIntents( main, intentsId ):
1062 """
1063 Remove all intents in the intentsId
1064 """
1065 import time
1066 intentsRemaining = []
1067 removeIntentResult = main.TRUE
1068 # Remove intents
1069 for intent in intentsId:
1070 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
1071
1072 time.sleep( 5 )
1073 # Checks if there is remaining intents using intents()
kelvin-onlab583fcb52015-05-21 13:10:46 -07001074 intentsRemaining = main.CLIs[ 0 ].intents( jsonFormat=False )
kelvin-onlabf0594d72015-05-19 17:25:12 -07001075 # If there is remianing intents then remove intents should fail
kelvin-onlab583fcb52015-05-21 13:10:46 -07001076
1077 if intentsRemaining:
kelvin-onlabf0594d72015-05-19 17:25:12 -07001078 main.log.info( itemName + ": There are " +
1079 str( len( intentsRemaining ) ) + " intents remaining, "
1080 + "failed to remove all the intents " )
1081 removeIntentResult = main.FALSE
kelvin-onlab08900012015-05-20 14:30:44 -07001082 main.log.info( intentsRemaining )
kelvin-onlabf0594d72015-05-19 17:25:12 -07001083 else:
1084 main.log.info( itemName + ": There are no intents remaining, " +
1085 "successfully removed all the intents." )
1086 removeIntentResult = main.TRUE
1087 return removeIntentResult
kelvin-onlaba297c4d2015-06-01 13:53:55 -07001088
1089def checkFlowsCount( main ):
1090 """
1091 Check flows count in each node
1092 """
1093 import json
1094
1095 flowsCount = []
1096 main.log.info( itemName + ": Checking flows count in each ONOS node" )
1097 for i in range( main.numCtrls ):
1098 summaryResult = main.CLIs[ i ].summary()
1099 if not summaryResult:
1100 main.log.error( itemName + ": There is something wrong with " +
1101 "summary command" )
1102 return main.FALSE
1103 else:
1104 summaryJson = json.loads( summaryResult )
1105 flowsCount.append( summaryJson.get( 'flows' ) )
1106
1107 if flowsCount:
1108 if all( flows==flowsCount[ 0 ] for flows in flowsCount ):
1109 main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) +
1110 " flows in all ONOS node" )
1111 else:
1112 for i in range( main.numCtrls ):
1113 main.log.debug( itemName + ": ONOS node " + str( i ) + " has " +
1114 flowsCount[ i ] + " flows" )
1115 else:
1116 main.log.error( "Checking flows count failed, check summary command" )
1117 return main.FALSE
1118
1119 return main.TRUE
1120