Committed by
Gerrit Code Review
Refactor getIntegerProperty and isPropertyEnabled methods into Tools
- Add getIntegerProperty and isPropertyEnabled methods which take default value as third parameter - Remove all duplicated code from RefactiveForwarding, GroupManager, FlowRuleManager, CoreManager, HostLocationProvider and ProxyArp Change-Id: Ifc93aa813acfdd4cbac0166497d7b526b08b2090
Showing
7 changed files
with
185 additions
and
237 deletions
... | @@ -81,7 +81,6 @@ import java.util.Map; | ... | @@ -81,7 +81,6 @@ import java.util.Map; |
81 | import java.util.Objects; | 81 | import java.util.Objects; |
82 | import java.util.Set; | 82 | import java.util.Set; |
83 | 83 | ||
84 | -import static com.google.common.base.Strings.isNullOrEmpty; | ||
85 | import static org.slf4j.LoggerFactory.getLogger; | 84 | import static org.slf4j.LoggerFactory.getLogger; |
86 | 85 | ||
87 | /** | 86 | /** |
... | @@ -252,153 +251,143 @@ public class ReactiveForwarding { | ... | @@ -252,153 +251,143 @@ public class ReactiveForwarding { |
252 | */ | 251 | */ |
253 | private void readComponentConfiguration(ComponentContext context) { | 252 | private void readComponentConfiguration(ComponentContext context) { |
254 | Dictionary<?, ?> properties = context.getProperties(); | 253 | Dictionary<?, ?> properties = context.getProperties(); |
255 | - boolean packetOutOnlyEnabled = | 254 | + |
256 | - isPropertyEnabled(properties, "packetOutOnly"); | 255 | + Boolean packetOutOnlyEnabled = |
257 | - if (packetOutOnly != packetOutOnlyEnabled) { | 256 | + Tools.isPropertyEnabled(properties, "packetOutOnly"); |
257 | + if (packetOutOnlyEnabled == null) { | ||
258 | + log.info("Packet-out is not configured, " + | ||
259 | + "using current value of {}", packetOutOnly); | ||
260 | + } else { | ||
258 | packetOutOnly = packetOutOnlyEnabled; | 261 | packetOutOnly = packetOutOnlyEnabled; |
259 | log.info("Configured. Packet-out only forwarding is {}", | 262 | log.info("Configured. Packet-out only forwarding is {}", |
260 | packetOutOnly ? "enabled" : "disabled"); | 263 | packetOutOnly ? "enabled" : "disabled"); |
261 | } | 264 | } |
262 | - boolean packetOutOfppTableEnabled = | 265 | + |
263 | - isPropertyEnabled(properties, "packetOutOfppTable"); | 266 | + Boolean packetOutOfppTableEnabled = |
264 | - if (packetOutOfppTable != packetOutOfppTableEnabled) { | 267 | + Tools.isPropertyEnabled(properties, "packetOutOfppTable"); |
268 | + if (packetOutOfppTableEnabled == null) { | ||
269 | + log.info("OFPP_TABLE port is not configured, " + | ||
270 | + "using current value of {}", packetOutOfppTable); | ||
271 | + } else { | ||
265 | packetOutOfppTable = packetOutOfppTableEnabled; | 272 | packetOutOfppTable = packetOutOfppTableEnabled; |
266 | log.info("Configured. Forwarding using OFPP_TABLE port is {}", | 273 | log.info("Configured. Forwarding using OFPP_TABLE port is {}", |
267 | packetOutOfppTable ? "enabled" : "disabled"); | 274 | packetOutOfppTable ? "enabled" : "disabled"); |
268 | } | 275 | } |
269 | - boolean ipv6ForwardingEnabled = | 276 | + |
270 | - isPropertyEnabled(properties, "ipv6Forwarding"); | 277 | + Boolean ipv6ForwardingEnabled = |
271 | - if (ipv6Forwarding != ipv6ForwardingEnabled) { | 278 | + Tools.isPropertyEnabled(properties, "ipv6Forwarding"); |
279 | + if (ipv6ForwardingEnabled == null) { | ||
280 | + log.info("IPv6 forwarding is not configured, " + | ||
281 | + "using current value of {}", ipv6Forwarding); | ||
282 | + } else { | ||
272 | ipv6Forwarding = ipv6ForwardingEnabled; | 283 | ipv6Forwarding = ipv6ForwardingEnabled; |
273 | log.info("Configured. IPv6 forwarding is {}", | 284 | log.info("Configured. IPv6 forwarding is {}", |
274 | ipv6Forwarding ? "enabled" : "disabled"); | 285 | ipv6Forwarding ? "enabled" : "disabled"); |
275 | } | 286 | } |
276 | - boolean matchDstMacOnlyEnabled = | 287 | + |
277 | - isPropertyEnabled(properties, "matchDstMacOnly"); | 288 | + Boolean matchDstMacOnlyEnabled = |
278 | - if (matchDstMacOnly != matchDstMacOnlyEnabled) { | 289 | + Tools.isPropertyEnabled(properties, "matchDstMacOnly"); |
290 | + if (matchDstMacOnlyEnabled == null) { | ||
291 | + log.info("Match Dst MAC is not configured, " + | ||
292 | + "using current value of {}", matchDstMacOnly); | ||
293 | + } else { | ||
279 | matchDstMacOnly = matchDstMacOnlyEnabled; | 294 | matchDstMacOnly = matchDstMacOnlyEnabled; |
280 | log.info("Configured. Match Dst MAC Only is {}", | 295 | log.info("Configured. Match Dst MAC Only is {}", |
281 | matchDstMacOnly ? "enabled" : "disabled"); | 296 | matchDstMacOnly ? "enabled" : "disabled"); |
282 | } | 297 | } |
283 | - boolean matchVlanIdEnabled = | 298 | + |
284 | - isPropertyEnabled(properties, "matchVlanId"); | 299 | + Boolean matchVlanIdEnabled = |
285 | - if (matchVlanId != matchVlanIdEnabled) { | 300 | + Tools.isPropertyEnabled(properties, "matchVlanId"); |
301 | + if (matchVlanIdEnabled == null) { | ||
302 | + log.info("Matching Vlan ID is not configured, " + | ||
303 | + "using current value of {}", matchVlanId); | ||
304 | + } else { | ||
286 | matchVlanId = matchVlanIdEnabled; | 305 | matchVlanId = matchVlanIdEnabled; |
287 | log.info("Configured. Matching Vlan ID is {}", | 306 | log.info("Configured. Matching Vlan ID is {}", |
288 | matchVlanId ? "enabled" : "disabled"); | 307 | matchVlanId ? "enabled" : "disabled"); |
289 | } | 308 | } |
290 | - boolean matchIpv4AddressEnabled = | 309 | + |
291 | - isPropertyEnabled(properties, "matchIpv4Address"); | 310 | + Boolean matchIpv4AddressEnabled = |
292 | - if (matchIpv4Address != matchIpv4AddressEnabled) { | 311 | + Tools.isPropertyEnabled(properties, "matchIpv4Address"); |
312 | + if (matchIpv4AddressEnabled == null) { | ||
313 | + log.info("Matching IPv4 Address is not configured, " + | ||
314 | + "using current value of {}", matchIpv4Address); | ||
315 | + } else { | ||
293 | matchIpv4Address = matchIpv4AddressEnabled; | 316 | matchIpv4Address = matchIpv4AddressEnabled; |
294 | log.info("Configured. Matching IPv4 Addresses is {}", | 317 | log.info("Configured. Matching IPv4 Addresses is {}", |
295 | matchIpv4Address ? "enabled" : "disabled"); | 318 | matchIpv4Address ? "enabled" : "disabled"); |
296 | } | 319 | } |
297 | - boolean matchIpv4DscpEnabled = | 320 | + |
298 | - isPropertyEnabled(properties, "matchIpv4Dscp"); | 321 | + Boolean matchIpv4DscpEnabled = |
299 | - if (matchIpv4Dscp != matchIpv4DscpEnabled) { | 322 | + Tools.isPropertyEnabled(properties, "matchIpv4Dscp"); |
323 | + if (matchIpv4DscpEnabled == null) { | ||
324 | + log.info("Matching IPv4 DSCP and ECN is not configured, " + | ||
325 | + "using current value of {}", matchIpv4Dscp); | ||
326 | + } else { | ||
300 | matchIpv4Dscp = matchIpv4DscpEnabled; | 327 | matchIpv4Dscp = matchIpv4DscpEnabled; |
301 | log.info("Configured. Matching IPv4 DSCP and ECN is {}", | 328 | log.info("Configured. Matching IPv4 DSCP and ECN is {}", |
302 | matchIpv4Dscp ? "enabled" : "disabled"); | 329 | matchIpv4Dscp ? "enabled" : "disabled"); |
303 | } | 330 | } |
304 | - boolean matchIpv6AddressEnabled = | 331 | + |
305 | - isPropertyEnabled(properties, "matchIpv6Address"); | 332 | + Boolean matchIpv6AddressEnabled = |
306 | - if (matchIpv6Address != matchIpv6AddressEnabled) { | 333 | + Tools.isPropertyEnabled(properties, "matchIpv6Address"); |
334 | + if (matchIpv6AddressEnabled == null) { | ||
335 | + log.info("Matching IPv6 Address is not configured, " + | ||
336 | + "using current value of {}", matchIpv6Address); | ||
337 | + } else { | ||
307 | matchIpv6Address = matchIpv6AddressEnabled; | 338 | matchIpv6Address = matchIpv6AddressEnabled; |
308 | log.info("Configured. Matching IPv6 Addresses is {}", | 339 | log.info("Configured. Matching IPv6 Addresses is {}", |
309 | matchIpv6Address ? "enabled" : "disabled"); | 340 | matchIpv6Address ? "enabled" : "disabled"); |
310 | } | 341 | } |
311 | - boolean matchIpv6FlowLabelEnabled = | 342 | + |
312 | - isPropertyEnabled(properties, "matchIpv6FlowLabel"); | 343 | + Boolean matchIpv6FlowLabelEnabled = |
313 | - if (matchIpv6FlowLabel != matchIpv6FlowLabelEnabled) { | 344 | + Tools.isPropertyEnabled(properties, "matchIpv6FlowLabel"); |
345 | + if (matchIpv6FlowLabelEnabled == null) { | ||
346 | + log.info("Matching IPv6 FlowLabel is not configured, " + | ||
347 | + "using current value of {}", matchIpv6FlowLabel); | ||
348 | + } else { | ||
314 | matchIpv6FlowLabel = matchIpv6FlowLabelEnabled; | 349 | matchIpv6FlowLabel = matchIpv6FlowLabelEnabled; |
315 | log.info("Configured. Matching IPv6 FlowLabel is {}", | 350 | log.info("Configured. Matching IPv6 FlowLabel is {}", |
316 | matchIpv6FlowLabel ? "enabled" : "disabled"); | 351 | matchIpv6FlowLabel ? "enabled" : "disabled"); |
317 | } | 352 | } |
318 | - boolean matchTcpUdpPortsEnabled = | 353 | + |
319 | - isPropertyEnabled(properties, "matchTcpUdpPorts"); | 354 | + Boolean matchTcpUdpPortsEnabled = |
320 | - if (matchTcpUdpPorts != matchTcpUdpPortsEnabled) { | 355 | + Tools.isPropertyEnabled(properties, "matchTcpUdpPorts"); |
356 | + if (matchTcpUdpPortsEnabled == null) { | ||
357 | + log.info("Matching TCP/UDP fields is not configured, " + | ||
358 | + "using current value of {}", matchTcpUdpPorts); | ||
359 | + } else { | ||
321 | matchTcpUdpPorts = matchTcpUdpPortsEnabled; | 360 | matchTcpUdpPorts = matchTcpUdpPortsEnabled; |
322 | log.info("Configured. Matching TCP/UDP fields is {}", | 361 | log.info("Configured. Matching TCP/UDP fields is {}", |
323 | matchTcpUdpPorts ? "enabled" : "disabled"); | 362 | matchTcpUdpPorts ? "enabled" : "disabled"); |
324 | } | 363 | } |
325 | - boolean matchIcmpFieldsEnabled = | 364 | + |
326 | - isPropertyEnabled(properties, "matchIcmpFields"); | 365 | + Boolean matchIcmpFieldsEnabled = |
327 | - if (matchIcmpFields != matchIcmpFieldsEnabled) { | 366 | + Tools.isPropertyEnabled(properties, "matchIcmpFields"); |
367 | + if (matchIcmpFieldsEnabled == null) { | ||
368 | + log.info("Matching ICMP (v4 and v6) fields is not configured, " + | ||
369 | + "using current value of {}", matchIcmpFields); | ||
370 | + } else { | ||
328 | matchIcmpFields = matchIcmpFieldsEnabled; | 371 | matchIcmpFields = matchIcmpFieldsEnabled; |
329 | log.info("Configured. Matching ICMP (v4 and v6) fields is {}", | 372 | log.info("Configured. Matching ICMP (v4 and v6) fields is {}", |
330 | matchIcmpFields ? "enabled" : "disabled"); | 373 | matchIcmpFields ? "enabled" : "disabled"); |
331 | } | 374 | } |
332 | - Integer flowTimeoutConfigured = | ||
333 | - getIntegerProperty(properties, "flowTimeout"); | ||
334 | - if (flowTimeoutConfigured == null) { | ||
335 | - flowTimeout = DEFAULT_TIMEOUT; | ||
336 | - log.info("Flow Timeout is not configured, default value is {}", | ||
337 | - flowTimeout); | ||
338 | - } else { | ||
339 | - flowTimeout = flowTimeoutConfigured; | ||
340 | - log.info("Configured. Flow Timeout is configured to {}", | ||
341 | - flowTimeout, " seconds"); | ||
342 | - } | ||
343 | - Integer flowPriorityConfigured = | ||
344 | - getIntegerProperty(properties, "flowPriority"); | ||
345 | - if (flowPriorityConfigured == null) { | ||
346 | - flowPriority = DEFAULT_PRIORITY; | ||
347 | - log.info("Flow Priority is not configured, default value is {}", | ||
348 | - flowPriority); | ||
349 | - } else { | ||
350 | - flowPriority = flowPriorityConfigured; | ||
351 | - log.info("Configured. Flow Priority is configured to {}", | ||
352 | - flowPriority); | ||
353 | - } | ||
354 | 375 | ||
355 | - boolean ignoreIpv4McastPacketsEnabled = | 376 | + Boolean ignoreIpv4McastPacketsEnabled = |
356 | - isPropertyEnabled(properties, "ignoreIpv4McastPackets"); | 377 | + Tools.isPropertyEnabled(properties, "ignoreIpv4McastPackets"); |
357 | - if (ignoreIpv4McastPackets != ignoreIpv4McastPacketsEnabled) { | 378 | + if (ignoreIpv4McastPacketsEnabled == null) { |
379 | + log.info("Ignore IPv4 multi-cast packet is not configured, " + | ||
380 | + "using current value of {}", ignoreIpv4McastPackets); | ||
381 | + } else { | ||
358 | ignoreIpv4McastPackets = ignoreIpv4McastPacketsEnabled; | 382 | ignoreIpv4McastPackets = ignoreIpv4McastPacketsEnabled; |
359 | log.info("Configured. Ignore IPv4 multicast packets is {}", | 383 | log.info("Configured. Ignore IPv4 multicast packets is {}", |
360 | ignoreIpv4McastPackets ? "enabled" : "disabled"); | 384 | ignoreIpv4McastPackets ? "enabled" : "disabled"); |
361 | } | 385 | } |
362 | - } | 386 | + flowTimeout = Tools.getIntegerProperty(properties, "flowTimeout", DEFAULT_TIMEOUT); |
387 | + log.info("Configured. Flow Timeout is configured to {}", flowTimeout, " seconds"); | ||
363 | 388 | ||
364 | - /** | 389 | + flowPriority = Tools.getIntegerProperty(properties, "flowPriority", DEFAULT_PRIORITY); |
365 | - * Get Integer property from the propertyName | 390 | + log.info("Configured. Flow Priority is configured to {}", flowPriority); |
366 | - * Return null if propertyName is not found. | ||
367 | - * | ||
368 | - * @param properties properties to be looked up | ||
369 | - * @param propertyName the name of the property to look up | ||
370 | - * @return value when the propertyName is defined or return null | ||
371 | - */ | ||
372 | - private static Integer getIntegerProperty(Dictionary<?, ?> properties, | ||
373 | - String propertyName) { | ||
374 | - Integer value = null; | ||
375 | - try { | ||
376 | - String s = Tools.get(properties, propertyName); | ||
377 | - value = isNullOrEmpty(s) ? value : Integer.parseInt(s); | ||
378 | - } catch (NumberFormatException | ClassCastException e) { | ||
379 | - value = null; | ||
380 | - } | ||
381 | - return value; | ||
382 | - } | ||
383 | - | ||
384 | - /** | ||
385 | - * Check property name is defined and set to true. | ||
386 | - * | ||
387 | - * @param properties properties to be looked up | ||
388 | - * @param propertyName the name of the property to look up | ||
389 | - * @return true when the propertyName is defined and set to true | ||
390 | - */ | ||
391 | - private static boolean isPropertyEnabled(Dictionary<?, ?> properties, | ||
392 | - String propertyName) { | ||
393 | - boolean enabled = false; | ||
394 | - try { | ||
395 | - String flag = Tools.get(properties, propertyName); | ||
396 | - enabled = isNullOrEmpty(flag) ? enabled : flag.equals("true"); | ||
397 | - } catch (ClassCastException e) { | ||
398 | - // No propertyName defined. | ||
399 | - enabled = false; | ||
400 | - } | ||
401 | - return enabled; | ||
402 | } | 391 | } |
403 | 392 | ||
404 | /** | 393 | /** | ... | ... |
... | @@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; | ... | @@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; |
25 | import org.onlab.packet.Ethernet; | 25 | import org.onlab.packet.Ethernet; |
26 | import org.onlab.packet.ICMP6; | 26 | import org.onlab.packet.ICMP6; |
27 | import org.onlab.packet.IPv6; | 27 | import org.onlab.packet.IPv6; |
28 | +import org.onlab.util.Tools; | ||
28 | import org.onosproject.cfg.ComponentConfigService; | 29 | import org.onosproject.cfg.ComponentConfigService; |
29 | import org.onosproject.core.ApplicationId; | 30 | import org.onosproject.core.ApplicationId; |
30 | import org.onosproject.core.CoreService; | 31 | import org.onosproject.core.CoreService; |
... | @@ -40,7 +41,6 @@ import org.slf4j.Logger; | ... | @@ -40,7 +41,6 @@ import org.slf4j.Logger; |
40 | 41 | ||
41 | import java.util.Dictionary; | 42 | import java.util.Dictionary; |
42 | 43 | ||
43 | -import static com.google.common.base.Strings.isNullOrEmpty; | ||
44 | import static org.onlab.packet.Ethernet.TYPE_ARP; | 44 | import static org.onlab.packet.Ethernet.TYPE_ARP; |
45 | import static org.onlab.packet.Ethernet.TYPE_IPV6; | 45 | import static org.onlab.packet.Ethernet.TYPE_IPV6; |
46 | import static org.onlab.packet.ICMP6.NEIGHBOR_ADVERTISEMENT; | 46 | import static org.onlab.packet.ICMP6.NEIGHBOR_ADVERTISEMENT; |
... | @@ -173,7 +173,7 @@ public class ProxyArp { | ... | @@ -173,7 +173,7 @@ public class ProxyArp { |
173 | Dictionary<?, ?> properties = context.getProperties(); | 173 | Dictionary<?, ?> properties = context.getProperties(); |
174 | Boolean flag; | 174 | Boolean flag; |
175 | 175 | ||
176 | - flag = isPropertyEnabled(properties, "ipv6NeighborDiscovery"); | 176 | + flag = Tools.isPropertyEnabled(properties, "ipv6NeighborDiscovery"); |
177 | if (flag == null) { | 177 | if (flag == null) { |
178 | log.info("IPv6 Neighbor Discovery is not configured, " + | 178 | log.info("IPv6 Neighbor Discovery is not configured, " + |
179 | "using current value of {}", ipv6NeighborDiscovery); | 179 | "using current value of {}", ipv6NeighborDiscovery); |
... | @@ -185,26 +185,6 @@ public class ProxyArp { | ... | @@ -185,26 +185,6 @@ public class ProxyArp { |
185 | } | 185 | } |
186 | 186 | ||
187 | /** | 187 | /** |
188 | - * Check property name is defined and set to true. | ||
189 | - * | ||
190 | - * @param properties properties to be looked up | ||
191 | - * @param propertyName the name of the property to look up | ||
192 | - * @return value when the propertyName is defined or return null | ||
193 | - */ | ||
194 | - private static Boolean isPropertyEnabled(Dictionary<?, ?> properties, | ||
195 | - String propertyName) { | ||
196 | - Boolean value = null; | ||
197 | - try { | ||
198 | - String s = (String) properties.get(propertyName); | ||
199 | - value = isNullOrEmpty(s) ? null : s.trim().equals("true"); | ||
200 | - } catch (ClassCastException e) { | ||
201 | - // No propertyName defined. | ||
202 | - value = null; | ||
203 | - } | ||
204 | - return value; | ||
205 | - } | ||
206 | - | ||
207 | - /** | ||
208 | * Packet processor responsible for forwarding packets along their paths. | 188 | * Packet processor responsible for forwarding packets along their paths. |
209 | */ | 189 | */ |
210 | private class ProxyArpProcessor implements PacketProcessor { | 190 | private class ProxyArpProcessor implements PacketProcessor { | ... | ... |
... | @@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; | ... | @@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; |
25 | import org.apache.felix.scr.annotations.Service; | 25 | import org.apache.felix.scr.annotations.Service; |
26 | import org.onlab.metrics.MetricsService; | 26 | import org.onlab.metrics.MetricsService; |
27 | import org.onlab.util.SharedExecutors; | 27 | import org.onlab.util.SharedExecutors; |
28 | +import org.onlab.util.Tools; | ||
28 | import org.onosproject.app.ApplicationService; | 29 | import org.onosproject.app.ApplicationService; |
29 | import org.onosproject.cfg.ComponentConfigService; | 30 | import org.onosproject.cfg.ComponentConfigService; |
30 | import org.onosproject.core.ApplicationId; | 31 | import org.onosproject.core.ApplicationId; |
... | @@ -48,9 +49,9 @@ import java.util.List; | ... | @@ -48,9 +49,9 @@ import java.util.List; |
48 | import java.util.Set; | 49 | import java.util.Set; |
49 | 50 | ||
50 | import static com.google.common.base.Preconditions.checkNotNull; | 51 | import static com.google.common.base.Preconditions.checkNotNull; |
51 | -import static com.google.common.base.Strings.isNullOrEmpty; | ||
52 | import static org.onosproject.security.AppGuard.checkPermission; | 52 | import static org.onosproject.security.AppGuard.checkPermission; |
53 | -import static org.onosproject.security.AppPermission.Type.*; | 53 | +import static org.onosproject.security.AppPermission.Type.APP_READ; |
54 | +import static org.onosproject.security.AppPermission.Type.APP_WRITE; | ||
54 | 55 | ||
55 | 56 | ||
56 | /** | 57 | /** |
... | @@ -172,7 +173,7 @@ public class CoreManager implements CoreService { | ... | @@ -172,7 +173,7 @@ public class CoreManager implements CoreService { |
172 | @Modified | 173 | @Modified |
173 | public void modified(ComponentContext context) { | 174 | public void modified(ComponentContext context) { |
174 | Dictionary<?, ?> properties = context.getProperties(); | 175 | Dictionary<?, ?> properties = context.getProperties(); |
175 | - Integer poolSize = getIntegerProperty(properties, "sharedThreadPoolSize"); | 176 | + Integer poolSize = Tools.getIntegerProperty(properties, "sharedThreadPoolSize"); |
176 | 177 | ||
177 | if (poolSize != null && poolSize > 1) { | 178 | if (poolSize != null && poolSize > 1) { |
178 | sharedThreadPoolSize = poolSize; | 179 | sharedThreadPoolSize = poolSize; |
... | @@ -181,7 +182,7 @@ public class CoreManager implements CoreService { | ... | @@ -181,7 +182,7 @@ public class CoreManager implements CoreService { |
181 | log.warn("sharedThreadPoolSize must be greater than 1"); | 182 | log.warn("sharedThreadPoolSize must be greater than 1"); |
182 | } | 183 | } |
183 | 184 | ||
184 | - Integer timeLimit = getIntegerProperty(properties, "maxEventTimeLimit"); | 185 | + Integer timeLimit = Tools.getIntegerProperty(properties, "maxEventTimeLimit"); |
185 | if (timeLimit != null && timeLimit > 1) { | 186 | if (timeLimit != null && timeLimit > 1) { |
186 | maxEventTimeLimit = timeLimit; | 187 | maxEventTimeLimit = timeLimit; |
187 | eventDeliveryService.setDispatchTimeLimit(maxEventTimeLimit); | 188 | eventDeliveryService.setDispatchTimeLimit(maxEventTimeLimit); |
... | @@ -189,7 +190,7 @@ public class CoreManager implements CoreService { | ... | @@ -189,7 +190,7 @@ public class CoreManager implements CoreService { |
189 | log.warn("maxEventTimeLimit must be greater than 1"); | 190 | log.warn("maxEventTimeLimit must be greater than 1"); |
190 | } | 191 | } |
191 | 192 | ||
192 | - Boolean performanceCheck = isPropertyEnabled(properties, "sharedThreadPerformanceCheck"); | 193 | + Boolean performanceCheck = Tools.isPropertyEnabled(properties, "sharedThreadPerformanceCheck"); |
193 | if (performanceCheck != null) { | 194 | if (performanceCheck != null) { |
194 | calculatePoolPerformance = performanceCheck; | 195 | calculatePoolPerformance = performanceCheck; |
195 | SharedExecutors.setCalculatePoolPerformance(calculatePoolPerformance, metricsService); | 196 | SharedExecutors.setCalculatePoolPerformance(calculatePoolPerformance, metricsService); |
... | @@ -198,48 +199,4 @@ public class CoreManager implements CoreService { | ... | @@ -198,48 +199,4 @@ public class CoreManager implements CoreService { |
198 | log.info("Settings: sharedThreadPoolSize={}, maxEventTimeLimit={}, calculatePoolPerformance={}", | 199 | log.info("Settings: sharedThreadPoolSize={}, maxEventTimeLimit={}, calculatePoolPerformance={}", |
199 | sharedThreadPoolSize, maxEventTimeLimit, calculatePoolPerformance); | 200 | sharedThreadPoolSize, maxEventTimeLimit, calculatePoolPerformance); |
200 | } | 201 | } |
201 | - | ||
202 | - | ||
203 | - /** | ||
204 | - * Get Integer property from the propertyName | ||
205 | - * Return null if propertyName is not found. | ||
206 | - * | ||
207 | - * @param properties properties to be looked up | ||
208 | - * @param propertyName the name of the property to look up | ||
209 | - * @return value when the propertyName is defined or return null | ||
210 | - */ | ||
211 | - private static Integer getIntegerProperty(Dictionary<?, ?> properties, | ||
212 | - String propertyName) { | ||
213 | - Integer value; | ||
214 | - try { | ||
215 | - String s = (String) properties.get(propertyName); | ||
216 | - value = isNullOrEmpty(s) ? null : Integer.parseInt(s.trim()); | ||
217 | - } catch (NumberFormatException | ClassCastException e) { | ||
218 | - value = null; | ||
219 | - } | ||
220 | - return value; | ||
221 | - } | ||
222 | - | ||
223 | - /** | ||
224 | - * Check property name is defined and set to true. | ||
225 | - * | ||
226 | - * @param properties properties to be looked up | ||
227 | - * @param propertyName the name of the property to look up | ||
228 | - * @return value when the propertyName is defined or return null | ||
229 | - */ | ||
230 | - private static Boolean isPropertyEnabled(Dictionary<?, ?> properties, | ||
231 | - String propertyName) { | ||
232 | - Boolean value = null; | ||
233 | - try { | ||
234 | - String s = (String) properties.get(propertyName); | ||
235 | - value = isNullOrEmpty(s) ? null : s.trim().equals("true"); | ||
236 | - } catch (ClassCastException e) { | ||
237 | - // No propertyName defined. | ||
238 | - value = null; | ||
239 | - } | ||
240 | - return value; | ||
241 | - } | ||
242 | - | ||
243 | - | ||
244 | - | ||
245 | } | 202 | } | ... | ... |
... | @@ -29,6 +29,7 @@ import org.apache.felix.scr.annotations.Property; | ... | @@ -29,6 +29,7 @@ import org.apache.felix.scr.annotations.Property; |
29 | import org.apache.felix.scr.annotations.Reference; | 29 | import org.apache.felix.scr.annotations.Reference; |
30 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 30 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
31 | import org.apache.felix.scr.annotations.Service; | 31 | import org.apache.felix.scr.annotations.Service; |
32 | +import org.onlab.util.Tools; | ||
32 | import org.onosproject.cfg.ComponentConfigService; | 33 | import org.onosproject.cfg.ComponentConfigService; |
33 | import org.onosproject.core.ApplicationId; | 34 | import org.onosproject.core.ApplicationId; |
34 | import org.onosproject.core.CoreService; | 35 | import org.onosproject.core.CoreService; |
... | @@ -190,7 +191,7 @@ public class FlowRuleManager | ... | @@ -190,7 +191,7 @@ public class FlowRuleManager |
190 | Dictionary<?, ?> properties = context.getProperties(); | 191 | Dictionary<?, ?> properties = context.getProperties(); |
191 | Boolean flag; | 192 | Boolean flag; |
192 | 193 | ||
193 | - flag = isPropertyEnabled(properties, "allowExtraneousRules"); | 194 | + flag = Tools.isPropertyEnabled(properties, "allowExtraneousRules"); |
194 | if (flag == null) { | 195 | if (flag == null) { |
195 | log.info("AllowExtraneousRules is not configured, " + | 196 | log.info("AllowExtraneousRules is not configured, " + |
196 | "using current value of {}", allowExtraneousRules); | 197 | "using current value of {}", allowExtraneousRules); |
... | @@ -200,7 +201,7 @@ public class FlowRuleManager | ... | @@ -200,7 +201,7 @@ public class FlowRuleManager |
200 | allowExtraneousRules ? "enabled" : "disabled"); | 201 | allowExtraneousRules ? "enabled" : "disabled"); |
201 | } | 202 | } |
202 | 203 | ||
203 | - flag = isPropertyEnabled(properties, "purgeOnDisconnection"); | 204 | + flag = Tools.isPropertyEnabled(properties, "purgeOnDisconnection"); |
204 | if (flag == null) { | 205 | if (flag == null) { |
205 | log.info("PurgeOnDisconnection is not configured, " + | 206 | log.info("PurgeOnDisconnection is not configured, " + |
206 | "using current value of {}", purgeOnDisconnection); | 207 | "using current value of {}", purgeOnDisconnection); |
... | @@ -218,24 +219,6 @@ public class FlowRuleManager | ... | @@ -218,24 +219,6 @@ public class FlowRuleManager |
218 | } | 219 | } |
219 | } | 220 | } |
220 | 221 | ||
221 | - /** | ||
222 | - * Check property name is defined and set to true. | ||
223 | - * | ||
224 | - * @param properties properties to be looked up | ||
225 | - * @param propertyName the name of the property to look up | ||
226 | - * @return value when the propertyName is defined or return null | ||
227 | - */ | ||
228 | - private static Boolean isPropertyEnabled(Dictionary<?, ?> properties, | ||
229 | - String propertyName) { | ||
230 | - try { | ||
231 | - String s = (String) properties.get(propertyName); | ||
232 | - return isNullOrEmpty(s) ? null : s.trim().equals("true"); | ||
233 | - } catch (ClassCastException e) { | ||
234 | - // No propertyName defined. | ||
235 | - return null; | ||
236 | - } | ||
237 | - } | ||
238 | - | ||
239 | @Override | 222 | @Override |
240 | public int getFlowRuleCount() { | 223 | public int getFlowRuleCount() { |
241 | checkPermission(FLOWRULE_READ); | 224 | checkPermission(FLOWRULE_READ); | ... | ... |
... | @@ -23,8 +23,8 @@ import org.apache.felix.scr.annotations.Property; | ... | @@ -23,8 +23,8 @@ import org.apache.felix.scr.annotations.Property; |
23 | import org.apache.felix.scr.annotations.Reference; | 23 | import org.apache.felix.scr.annotations.Reference; |
24 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
25 | import org.apache.felix.scr.annotations.Service; | 25 | import org.apache.felix.scr.annotations.Service; |
26 | +import org.onlab.util.Tools; | ||
26 | import org.onosproject.cfg.ComponentConfigService; | 27 | import org.onosproject.cfg.ComponentConfigService; |
27 | -import org.onosproject.net.provider.AbstractListenerProviderRegistry; | ||
28 | import org.onosproject.core.ApplicationId; | 28 | import org.onosproject.core.ApplicationId; |
29 | import org.onosproject.net.DeviceId; | 29 | import org.onosproject.net.DeviceId; |
30 | import org.onosproject.net.device.DeviceEvent; | 30 | import org.onosproject.net.device.DeviceEvent; |
... | @@ -45,6 +45,7 @@ import org.onosproject.net.group.GroupService; | ... | @@ -45,6 +45,7 @@ import org.onosproject.net.group.GroupService; |
45 | import org.onosproject.net.group.GroupStore; | 45 | import org.onosproject.net.group.GroupStore; |
46 | import org.onosproject.net.group.GroupStore.UpdateType; | 46 | import org.onosproject.net.group.GroupStore.UpdateType; |
47 | import org.onosproject.net.group.GroupStoreDelegate; | 47 | import org.onosproject.net.group.GroupStoreDelegate; |
48 | +import org.onosproject.net.provider.AbstractListenerProviderRegistry; | ||
48 | import org.onosproject.net.provider.AbstractProviderService; | 49 | import org.onosproject.net.provider.AbstractProviderService; |
49 | import org.osgi.service.component.ComponentContext; | 50 | import org.osgi.service.component.ComponentContext; |
50 | import org.slf4j.Logger; | 51 | import org.slf4j.Logger; |
... | @@ -53,10 +54,10 @@ import java.util.Collection; | ... | @@ -53,10 +54,10 @@ import java.util.Collection; |
53 | import java.util.Collections; | 54 | import java.util.Collections; |
54 | import java.util.Dictionary; | 55 | import java.util.Dictionary; |
55 | 56 | ||
56 | -import static com.google.common.base.Strings.isNullOrEmpty; | ||
57 | import static org.onosproject.security.AppGuard.checkPermission; | 57 | import static org.onosproject.security.AppGuard.checkPermission; |
58 | +import static org.onosproject.security.AppPermission.Type.GROUP_READ; | ||
59 | +import static org.onosproject.security.AppPermission.Type.GROUP_WRITE; | ||
58 | import static org.slf4j.LoggerFactory.getLogger; | 60 | import static org.slf4j.LoggerFactory.getLogger; |
59 | -import static org.onosproject.security.AppPermission.Type.*; | ||
60 | 61 | ||
61 | 62 | ||
62 | 63 | ||
... | @@ -129,7 +130,7 @@ public class GroupManager | ... | @@ -129,7 +130,7 @@ public class GroupManager |
129 | Dictionary<?, ?> properties = context.getProperties(); | 130 | Dictionary<?, ?> properties = context.getProperties(); |
130 | Boolean flag; | 131 | Boolean flag; |
131 | 132 | ||
132 | - flag = isPropertyEnabled(properties, "purgeOnDisconnection"); | 133 | + flag = Tools.isPropertyEnabled(properties, "purgeOnDisconnection"); |
133 | if (flag == null) { | 134 | if (flag == null) { |
134 | log.info("PurgeOnDisconnection is not configured, " + | 135 | log.info("PurgeOnDisconnection is not configured, " + |
135 | "using current value of {}", purgeOnDisconnection); | 136 | "using current value of {}", purgeOnDisconnection); |
... | @@ -141,26 +142,6 @@ public class GroupManager | ... | @@ -141,26 +142,6 @@ public class GroupManager |
141 | } | 142 | } |
142 | 143 | ||
143 | /** | 144 | /** |
144 | - * Check property name is defined and set to true. | ||
145 | - * | ||
146 | - * @param properties properties to be looked up | ||
147 | - * @param propertyName the name of the property to look up | ||
148 | - * @return value when the propertyName is defined or return null | ||
149 | - */ | ||
150 | - private static Boolean isPropertyEnabled(Dictionary<?, ?> properties, | ||
151 | - String propertyName) { | ||
152 | - Boolean value = null; | ||
153 | - try { | ||
154 | - String s = (String) properties.get(propertyName); | ||
155 | - value = isNullOrEmpty(s) ? null : s.trim().equals("true"); | ||
156 | - } catch (ClassCastException e) { | ||
157 | - // No propertyName defined. | ||
158 | - value = null; | ||
159 | - } | ||
160 | - return value; | ||
161 | - } | ||
162 | - | ||
163 | - /** | ||
164 | * Create a group in the specified device with the provided parameters. | 145 | * Create a group in the specified device with the provided parameters. |
165 | * | 146 | * |
166 | * @param groupDesc group creation parameters | 147 | * @param groupDesc group creation parameters | ... | ... |
... | @@ -35,6 +35,7 @@ import org.onlab.packet.ndp.NeighborAdvertisement; | ... | @@ -35,6 +35,7 @@ import org.onlab.packet.ndp.NeighborAdvertisement; |
35 | import org.onlab.packet.ndp.NeighborSolicitation; | 35 | import org.onlab.packet.ndp.NeighborSolicitation; |
36 | import org.onlab.packet.ndp.RouterAdvertisement; | 36 | import org.onlab.packet.ndp.RouterAdvertisement; |
37 | import org.onlab.packet.ndp.RouterSolicitation; | 37 | import org.onlab.packet.ndp.RouterSolicitation; |
38 | +import org.onlab.util.Tools; | ||
38 | import org.onosproject.cfg.ComponentConfigService; | 39 | import org.onosproject.cfg.ComponentConfigService; |
39 | import org.onosproject.core.ApplicationId; | 40 | import org.onosproject.core.ApplicationId; |
40 | import org.onosproject.core.CoreService; | 41 | import org.onosproject.core.CoreService; |
... | @@ -69,7 +70,6 @@ import java.util.Dictionary; | ... | @@ -69,7 +70,6 @@ import java.util.Dictionary; |
69 | import java.util.Set; | 70 | import java.util.Set; |
70 | import java.util.concurrent.ExecutorService; | 71 | import java.util.concurrent.ExecutorService; |
71 | 72 | ||
72 | -import static com.google.common.base.Strings.isNullOrEmpty; | ||
73 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; | 73 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; |
74 | import static org.onlab.util.Tools.groupedThreads; | 74 | import static org.onlab.util.Tools.groupedThreads; |
75 | import static org.slf4j.LoggerFactory.getLogger; | 75 | import static org.slf4j.LoggerFactory.getLogger; |
... | @@ -228,7 +228,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -228,7 +228,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
228 | Dictionary<?, ?> properties = context.getProperties(); | 228 | Dictionary<?, ?> properties = context.getProperties(); |
229 | Boolean flag; | 229 | Boolean flag; |
230 | 230 | ||
231 | - flag = isPropertyEnabled(properties, "hostRemovalEnabled"); | 231 | + flag = Tools.isPropertyEnabled(properties, "hostRemovalEnabled"); |
232 | if (flag == null) { | 232 | if (flag == null) { |
233 | log.info("Host removal on port/device down events is not configured, " + | 233 | log.info("Host removal on port/device down events is not configured, " + |
234 | "using current value of {}", hostRemovalEnabled); | 234 | "using current value of {}", hostRemovalEnabled); |
... | @@ -238,7 +238,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -238,7 +238,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
238 | hostRemovalEnabled ? "enabled" : "disabled"); | 238 | hostRemovalEnabled ? "enabled" : "disabled"); |
239 | } | 239 | } |
240 | 240 | ||
241 | - flag = isPropertyEnabled(properties, "ipv6NeighborDiscovery"); | 241 | + flag = Tools.isPropertyEnabled(properties, "ipv6NeighborDiscovery"); |
242 | if (flag == null) { | 242 | if (flag == null) { |
243 | log.info("Using IPv6 Neighbor Discovery is not configured, " + | 243 | log.info("Using IPv6 Neighbor Discovery is not configured, " + |
244 | "using current value of {}", ipv6NeighborDiscovery); | 244 | "using current value of {}", ipv6NeighborDiscovery); |
... | @@ -248,7 +248,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -248,7 +248,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
248 | ipv6NeighborDiscovery ? "enabled" : "disabled"); | 248 | ipv6NeighborDiscovery ? "enabled" : "disabled"); |
249 | } | 249 | } |
250 | 250 | ||
251 | - flag = isPropertyEnabled(properties, "requestInterceptsEnabled"); | 251 | + flag = Tools.isPropertyEnabled(properties, "requestInterceptsEnabled"); |
252 | if (flag == null) { | 252 | if (flag == null) { |
253 | log.info("Request intercepts is not configured, " + | 253 | log.info("Request intercepts is not configured, " + |
254 | "using current value of {}", requestInterceptsEnabled); | 254 | "using current value of {}", requestInterceptsEnabled); |
... | @@ -259,26 +259,6 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -259,26 +259,6 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
259 | } | 259 | } |
260 | } | 260 | } |
261 | 261 | ||
262 | - /** | ||
263 | - * Check property name is defined and set to true. | ||
264 | - * | ||
265 | - * @param properties properties to be looked up | ||
266 | - * @param propertyName the name of the property to look up | ||
267 | - * @return value when the propertyName is defined or return null | ||
268 | - */ | ||
269 | - private static Boolean isPropertyEnabled(Dictionary<?, ?> properties, | ||
270 | - String propertyName) { | ||
271 | - Boolean value = null; | ||
272 | - try { | ||
273 | - String s = (String) properties.get(propertyName); | ||
274 | - value = isNullOrEmpty(s) ? null : s.trim().equals("true"); | ||
275 | - } catch (ClassCastException e) { | ||
276 | - // No propertyName defined. | ||
277 | - value = null; | ||
278 | - } | ||
279 | - return value; | ||
280 | - } | ||
281 | - | ||
282 | @Override | 262 | @Override |
283 | public void triggerProbe(Host host) { | 263 | public void triggerProbe(Host host) { |
284 | log.info("Triggering probe on device {}", host); | 264 | log.info("Triggering probe on device {}", host); | ... | ... |
... | @@ -275,6 +275,84 @@ public abstract class Tools { | ... | @@ -275,6 +275,84 @@ public abstract class Tools { |
275 | } | 275 | } |
276 | 276 | ||
277 | /** | 277 | /** |
278 | + * Get Integer property from the propertyName | ||
279 | + * Return null if propertyName is not found. | ||
280 | + * | ||
281 | + * @param properties properties to be looked up | ||
282 | + * @param propertyName the name of the property to look up | ||
283 | + * @return value when the propertyName is defined or return null | ||
284 | + */ | ||
285 | + public static Integer getIntegerProperty(Dictionary<?, ?> properties, | ||
286 | + String propertyName) { | ||
287 | + Integer value; | ||
288 | + try { | ||
289 | + String s = get(properties, propertyName); | ||
290 | + value = Strings.isNullOrEmpty(s) ? null : Integer.valueOf(s); | ||
291 | + } catch (NumberFormatException | ClassCastException e) { | ||
292 | + value = null; | ||
293 | + } | ||
294 | + return value; | ||
295 | + } | ||
296 | + | ||
297 | + /** | ||
298 | + * Get Integer property from the propertyName | ||
299 | + * Return default value if propertyName is not found. | ||
300 | + * | ||
301 | + * @param properties properties to be looked up | ||
302 | + * @param propertyName the name of the property to look up | ||
303 | + * @param defaultValue the default value that to be assigned | ||
304 | + * @return value when the propertyName is defined or return default value | ||
305 | + */ | ||
306 | + public static int getIntegerProperty(Dictionary<?, ?> properties, | ||
307 | + String propertyName, | ||
308 | + int defaultValue) { | ||
309 | + try { | ||
310 | + String s = get(properties, propertyName); | ||
311 | + return Strings.isNullOrEmpty(s) ? defaultValue : Integer.valueOf(s); | ||
312 | + } catch (NumberFormatException | ClassCastException e) { | ||
313 | + return defaultValue; | ||
314 | + } | ||
315 | + } | ||
316 | + | ||
317 | + /** | ||
318 | + * Check property name is defined and set to true. | ||
319 | + * | ||
320 | + * @param properties properties to be looked up | ||
321 | + * @param propertyName the name of the property to look up | ||
322 | + * @return value when the propertyName is defined or return null | ||
323 | + */ | ||
324 | + public static Boolean isPropertyEnabled(Dictionary<?, ?> properties, | ||
325 | + String propertyName) { | ||
326 | + Boolean value; | ||
327 | + try { | ||
328 | + String s = get(properties, propertyName); | ||
329 | + value = Strings.isNullOrEmpty(s) ? null : Boolean.valueOf(s); | ||
330 | + } catch (ClassCastException e) { | ||
331 | + value = null; | ||
332 | + } | ||
333 | + return value; | ||
334 | + } | ||
335 | + | ||
336 | + /** | ||
337 | + * Check property name is defined as set to true. | ||
338 | + * | ||
339 | + * @param properties properties to be looked up | ||
340 | + * @param propertyName the name of the property to look up | ||
341 | + * @param defaultValue the default value that to be assigned | ||
342 | + * @return value when the propertyName is defined or return the default value | ||
343 | + */ | ||
344 | + public static boolean isPropertyEnabled(Dictionary<?, ?> properties, | ||
345 | + String propertyName, | ||
346 | + boolean defaultValue) { | ||
347 | + try { | ||
348 | + String s = get(properties, propertyName); | ||
349 | + return Strings.isNullOrEmpty(s) ? defaultValue : Boolean.valueOf(s); | ||
350 | + } catch (ClassCastException e) { | ||
351 | + return defaultValue; | ||
352 | + } | ||
353 | + } | ||
354 | + | ||
355 | + /** | ||
278 | * Suspends the current thread for a specified number of millis. | 356 | * Suspends the current thread for a specified number of millis. |
279 | * | 357 | * |
280 | * @param ms number of millis | 358 | * @param ms number of millis | ... | ... |
-
Please register or login to post a comment