Thomas Vachuska

Making number of components configurable using the central component configuration subsystem.

Change-Id: Ia32c51480913689339a766d9849e792d62f7d133
Showing 24 changed files with 138 additions and 51 deletions
...@@ -38,6 +38,7 @@ import org.onlab.packet.ICMP6; ...@@ -38,6 +38,7 @@ import org.onlab.packet.ICMP6;
38 import org.onlab.packet.Ip4Prefix; 38 import org.onlab.packet.Ip4Prefix;
39 import org.onlab.packet.Ip6Prefix; 39 import org.onlab.packet.Ip6Prefix;
40 import org.onlab.packet.VlanId; 40 import org.onlab.packet.VlanId;
41 +import org.onosproject.cfg.ComponentConfigService;
41 import org.onosproject.core.ApplicationId; 42 import org.onosproject.core.ApplicationId;
42 import org.onosproject.core.CoreService; 43 import org.onosproject.core.CoreService;
43 import org.onosproject.net.Host; 44 import org.onosproject.net.Host;
...@@ -87,6 +88,9 @@ public class ReactiveForwarding { ...@@ -87,6 +88,9 @@ public class ReactiveForwarding {
87 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 88 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
88 protected CoreService coreService; 89 protected CoreService coreService;
89 90
91 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
92 + protected ComponentConfigService cfgService;
93 +
90 private ReactivePacketProcessor processor = new ReactivePacketProcessor(); 94 private ReactivePacketProcessor processor = new ReactivePacketProcessor();
91 95
92 private ApplicationId appId; 96 private ApplicationId appId;
...@@ -150,6 +154,7 @@ public class ReactiveForwarding { ...@@ -150,6 +154,7 @@ public class ReactiveForwarding {
150 154
151 @Activate 155 @Activate
152 public void activate(ComponentContext context) { 156 public void activate(ComponentContext context) {
157 + cfgService.registerProperties(getClass());
153 appId = coreService.registerApplication("org.onosproject.fwd"); 158 appId = coreService.registerApplication("org.onosproject.fwd");
154 159
155 packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2); 160 packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2);
...@@ -174,6 +179,7 @@ public class ReactiveForwarding { ...@@ -174,6 +179,7 @@ public class ReactiveForwarding {
174 179
175 @Deactivate 180 @Deactivate
176 public void deactivate() { 181 public void deactivate() {
182 + cfgService.unregisterProperties(getClass(), false);
177 flowRuleService.removeFlowRulesById(appId); 183 flowRuleService.removeFlowRulesById(appId);
178 packetService.removeProcessor(processor); 184 packetService.removeProcessor(processor);
179 processor = null; 185 processor = null;
......
1 +# Temporary: to be auto-generated in near future
2 +packetOutOnly|BOOLEAN|false|Enable packet-out only forwarding; default is false
3 +packetOutOfppTable|BOOLEAN|false|Enable first packet forwarding using OFPP_TABLE port instead of PacketOut with actual port; default is false
4 +flowTimeout|INTEGER|10|Configure Flow Timeout for installed flow rules; default is 10 sec
5 +flowPriority|INTEGER|10|Configure Flow Priority for installed flow rules; default is 10
6 +ipv6Forwarding|BOOLEAN|false|Enable IPv6 forwarding; default is false
7 +matchDstMacOnly|BOOLEAN|false|Enable matching Dst Mac Only; default is false
8 +matchVlanId|BOOLEAN|false|Enable matching Vlan ID; default is false
9 +matchIpv4Address|BOOLEAN|false|Enable matching IPv4 Addresses; default is false
10 +matchIpv4Dscp|BOOLEAN|false|Enable matching IPv4 DSCP and ECN; default is false
11 +matchIpv6Address|BOOLEAN|false|Enable matching IPv6 Addresses; default is false
12 +matchIpv6FlowLabel|BOOLEAN|false|Enable matching IPv6 FlowLabel; default is false
13 +matchTcpUdpPorts|BOOLEAN|false|Enable matching TCP/UDP ports; default is false
14 +matchIcmpFields|BOOLEAN|false|Enable matching ICMPv4 and ICMPv6 fields; default is false
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
15 */ 15 */
16 package org.onosproject.proxyarp; 16 package org.onosproject.proxyarp;
17 17
18 -import java.util.Dictionary;
19 -
20 import org.apache.felix.scr.annotations.Activate; 18 import org.apache.felix.scr.annotations.Activate;
21 import org.apache.felix.scr.annotations.Component; 19 import org.apache.felix.scr.annotations.Component;
22 import org.apache.felix.scr.annotations.Deactivate; 20 import org.apache.felix.scr.annotations.Deactivate;
...@@ -27,6 +25,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; ...@@ -27,6 +25,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
27 import org.onlab.packet.Ethernet; 25 import org.onlab.packet.Ethernet;
28 import org.onlab.packet.ICMP6; 26 import org.onlab.packet.ICMP6;
29 import org.onlab.packet.IPv6; 27 import org.onlab.packet.IPv6;
28 +import org.onosproject.cfg.ComponentConfigService;
30 import org.onosproject.core.ApplicationId; 29 import org.onosproject.core.ApplicationId;
31 import org.onosproject.core.CoreService; 30 import org.onosproject.core.CoreService;
32 import org.onosproject.net.flow.DefaultTrafficSelector; 31 import org.onosproject.net.flow.DefaultTrafficSelector;
...@@ -39,6 +38,8 @@ import org.onosproject.net.proxyarp.ProxyArpService; ...@@ -39,6 +38,8 @@ import org.onosproject.net.proxyarp.ProxyArpService;
39 import org.osgi.service.component.ComponentContext; 38 import org.osgi.service.component.ComponentContext;
40 import org.slf4j.Logger; 39 import org.slf4j.Logger;
41 40
41 +import java.util.Dictionary;
42 +
42 import static com.google.common.base.Strings.isNullOrEmpty; 43 import static com.google.common.base.Strings.isNullOrEmpty;
43 import static org.slf4j.LoggerFactory.getLogger; 44 import static org.slf4j.LoggerFactory.getLogger;
44 45
...@@ -61,6 +62,9 @@ public class ProxyArp { ...@@ -61,6 +62,9 @@ public class ProxyArp {
61 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 62 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
62 protected CoreService coreService; 63 protected CoreService coreService;
63 64
65 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
66 + protected ComponentConfigService cfgService;
67 +
64 private ApplicationId appId; 68 private ApplicationId appId;
65 69
66 @Property(name = "ipv6NeighborDiscovery", boolValue = false, 70 @Property(name = "ipv6NeighborDiscovery", boolValue = false,
...@@ -69,6 +73,7 @@ public class ProxyArp { ...@@ -69,6 +73,7 @@ public class ProxyArp {
69 73
70 @Activate 74 @Activate
71 public void activate(ComponentContext context) { 75 public void activate(ComponentContext context) {
76 + cfgService.registerProperties(getClass());
72 appId = coreService.registerApplication("org.onosproject.proxyarp"); 77 appId = coreService.registerApplication("org.onosproject.proxyarp");
73 readComponentConfiguration(context); 78 readComponentConfiguration(context);
74 79
...@@ -103,6 +108,7 @@ public class ProxyArp { ...@@ -103,6 +108,7 @@ public class ProxyArp {
103 108
104 @Deactivate 109 @Deactivate
105 public void deactivate() { 110 public void deactivate() {
111 + cfgService.unregisterProperties(getClass(), false);
106 packetService.removeProcessor(processor); 112 packetService.removeProcessor(processor);
107 processor = null; 113 processor = null;
108 log.info("Stopped"); 114 log.info("Stopped");
......
1 +# Temporary: to be auto-generated in near future
2 +ipv6NeighborDiscovery|BOOLEAN|false|Enable IPv6 Neighbor Discovery; default is false
...@@ -76,6 +76,7 @@ public abstract class Intent { ...@@ -76,6 +76,7 @@ public abstract class Intent {
76 * @param appId application identifier 76 * @param appId application identifier
77 * @param key optional key 77 * @param key optional key
78 * @param resources required network resources (optional) 78 * @param resources required network resources (optional)
79 + * @param priority flow rule priority
79 */ 80 */
80 protected Intent(ApplicationId appId, 81 protected Intent(ApplicationId appId,
81 Key key, 82 Key key,
...@@ -156,6 +157,7 @@ public abstract class Intent { ...@@ -156,6 +157,7 @@ public abstract class Intent {
156 * Binds an id generator for unique intent id generation. 157 * Binds an id generator for unique intent id generation.
157 * 158 *
158 * Note: A generator cannot be bound if there is already a generator bound. 159 * Note: A generator cannot be bound if there is already a generator bound.
160 + *
159 * @param newIdGenerator id generator 161 * @param newIdGenerator id generator
160 */ 162 */
161 public static void bindIdGenerator(IdGenerator newIdGenerator) { 163 public static void bindIdGenerator(IdGenerator newIdGenerator) {
...@@ -167,6 +169,7 @@ public abstract class Intent { ...@@ -167,6 +169,7 @@ public abstract class Intent {
167 * Unbinds an id generator. 169 * Unbinds an id generator.
168 * 170 *
169 * Note: The caller must provide the old id generator to succeed. 171 * Note: The caller must provide the old id generator to succeed.
172 + *
170 * @param oldIdGenerator the current id generator 173 * @param oldIdGenerator the current id generator
171 */ 174 */
172 public static void unbindIdGenerator(IdGenerator oldIdGenerator) { 175 public static void unbindIdGenerator(IdGenerator oldIdGenerator) {
......
...@@ -203,9 +203,8 @@ public class ComponentConfigManager implements ComponentConfigService { ...@@ -203,9 +203,8 @@ public class ComponentConfigManager implements ComponentConfigService {
203 203
204 // Loads existing property values that may have been set. 204 // Loads existing property values that may have been set.
205 private void loadExistingValues(String componentName) { 205 private void loadExistingValues(String componentName) {
206 - // FIXME: implement this by talking to the config admin.
207 try { 206 try {
208 - Configuration cfg = cfgAdmin.getConfiguration(componentName); 207 + Configuration cfg = cfgAdmin.getConfiguration(componentName, null);
209 Map<String, ConfigProperty> map = properties.get(componentName); 208 Map<String, ConfigProperty> map = properties.get(componentName);
210 Dictionary<String, Object> props = cfg.getProperties(); 209 Dictionary<String, Object> props = cfg.getProperties();
211 if (props != null) { 210 if (props != null) {
...@@ -229,7 +228,7 @@ public class ComponentConfigManager implements ComponentConfigService { ...@@ -229,7 +228,7 @@ public class ComponentConfigManager implements ComponentConfigService {
229 // after each other. 228 // after each other.
230 private void triggerUpdate(String componentName) { 229 private void triggerUpdate(String componentName) {
231 try { 230 try {
232 - Configuration cfg = cfgAdmin.getConfiguration(componentName); 231 + Configuration cfg = cfgAdmin.getConfiguration(componentName, null);
233 Map<String, ConfigProperty> map = properties.get(componentName); 232 Map<String, ConfigProperty> map = properties.get(componentName);
234 Dictionary<String, Object> props = new Hashtable<>(); 233 Dictionary<String, Object> props = new Hashtable<>();
235 map.values().forEach(p -> props.put(p.name(), p.value())); 234 map.values().forEach(p -> props.put(p.name(), p.value()));
......
...@@ -17,6 +17,7 @@ package org.onosproject.net.topology.impl; ...@@ -17,6 +17,7 @@ package org.onosproject.net.topology.impl;
17 17
18 import static com.google.common.base.Strings.isNullOrEmpty; 18 import static com.google.common.base.Strings.isNullOrEmpty;
19 import static java.util.concurrent.Executors.newFixedThreadPool; 19 import static java.util.concurrent.Executors.newFixedThreadPool;
20 +import static org.onlab.util.Tools.get;
20 import static org.onlab.util.Tools.groupedThreads; 21 import static org.onlab.util.Tools.groupedThreads;
21 import static org.onosproject.core.CoreService.CORE_PROVIDER_ID; 22 import static org.onosproject.core.CoreService.CORE_PROVIDER_ID;
22 import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_ADDED; 23 import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_ADDED;
...@@ -162,16 +163,16 @@ public class DefaultTopologyProvider extends AbstractProvider ...@@ -162,16 +163,16 @@ public class DefaultTopologyProvider extends AbstractProvider
162 return; 163 return;
163 } 164 }
164 165
165 - Dictionary properties = context.getProperties(); 166 + Dictionary<?, ?> properties = context.getProperties();
166 int newMaxEvents, newMaxBatchMs, newMaxIdleMs; 167 int newMaxEvents, newMaxBatchMs, newMaxIdleMs;
167 try { 168 try {
168 - String s = (String) properties.get("maxEvents"); 169 + String s = get(properties, "maxEvents");
169 newMaxEvents = isNullOrEmpty(s) ? maxEvents : Integer.parseInt(s.trim()); 170 newMaxEvents = isNullOrEmpty(s) ? maxEvents : Integer.parseInt(s.trim());
170 171
171 - s = (String) properties.get("maxBatchMs"); 172 + s = get(properties, "maxBatchMs");
172 newMaxBatchMs = isNullOrEmpty(s) ? maxBatchMs : Integer.parseInt(s.trim()); 173 newMaxBatchMs = isNullOrEmpty(s) ? maxBatchMs : Integer.parseInt(s.trim());
173 174
174 - s = (String) properties.get("maxIdleMs"); 175 + s = get(properties, "maxIdleMs");
175 newMaxIdleMs = isNullOrEmpty(s) ? maxIdleMs : Integer.parseInt(s.trim()); 176 newMaxIdleMs = isNullOrEmpty(s) ? maxIdleMs : Integer.parseInt(s.trim());
176 177
177 } catch (NumberFormatException | ClassCastException e) { 178 } catch (NumberFormatException | ClassCastException e) {
......
1 -# 1 +# Temporary: to be auto-generated in near future
2 -# Copyright 2015 Open Networking Laboratory
3 -#
4 -# Licensed under the Apache License, Version 2.0 (the "License");
5 -# you may not use this file except in compliance with the License.
6 -# You may obtain a copy of the License at
7 -#
8 -# http://www.apache.org/licenses/LICENSE-2.0
9 -#
10 -# Unless required by applicable law or agreed to in writing, software
11 -# distributed under the License is distributed on an "AS IS" BASIS,
12 -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 -# See the License for the specific language governing permissions and
14 -# limitations under the License.
15 -#
16 -
17 -# This is for temporary provision for testing purposes and will be auto-generated.
18 maxEvents|INTEGER|1000|Maximum number of events to accumulate 2 maxEvents|INTEGER|1000|Maximum number of events to accumulate
19 maxIdleMs|INTEGER|10|Maximum number of millis between events 3 maxIdleMs|INTEGER|10|Maximum number of millis between events
20 maxBatchMs|INTEGER|50|Maximum number of millis for whole batch 4 maxBatchMs|INTEGER|50|Maximum number of millis for whole batch
......
...@@ -95,6 +95,7 @@ import java.util.stream.Collectors; ...@@ -95,6 +95,7 @@ import java.util.stream.Collectors;
95 95
96 import static com.google.common.base.Strings.isNullOrEmpty; 96 import static com.google.common.base.Strings.isNullOrEmpty;
97 import static org.apache.felix.scr.annotations.ReferenceCardinality.MANDATORY_UNARY; 97 import static org.apache.felix.scr.annotations.ReferenceCardinality.MANDATORY_UNARY;
98 +import static org.onlab.util.Tools.get;
98 import static org.onlab.util.Tools.groupedThreads; 99 import static org.onlab.util.Tools.groupedThreads;
99 import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_REMOVED; 100 import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_REMOVED;
100 import static org.onosproject.store.flow.impl.FlowStoreMessageSubjects.*; 101 import static org.onosproject.store.flow.impl.FlowStoreMessageSubjects.*;
...@@ -267,10 +268,10 @@ public class DistributedFlowRuleStore ...@@ -267,10 +268,10 @@ public class DistributedFlowRuleStore
267 int newPoolSize; 268 int newPoolSize;
268 boolean newBackupEnabled; 269 boolean newBackupEnabled;
269 try { 270 try {
270 - String s = (String) properties.get("msgHandlerPoolSize"); 271 + String s = get(properties, "msgHandlerPoolSize");
271 newPoolSize = isNullOrEmpty(s) ? msgHandlerPoolSize : Integer.parseInt(s.trim()); 272 newPoolSize = isNullOrEmpty(s) ? msgHandlerPoolSize : Integer.parseInt(s.trim());
272 273
273 - s = (String) properties.get("backupEnabled"); 274 + s = get(properties, "backupEnabled");
274 newBackupEnabled = isNullOrEmpty(s) ? backupEnabled : Boolean.parseBoolean(s.trim()); 275 newBackupEnabled = isNullOrEmpty(s) ? backupEnabled : Boolean.parseBoolean(s.trim());
275 276
276 } catch (NumberFormatException | ClassCastException e) { 277 } catch (NumberFormatException | ClassCastException e) {
......
1 +# Temporary: to be auto-generated in near future
2 +msgHandlerPoolSize|INTEGER|8|Number of threads in the message handler pool
3 +backupEnabled|BOOLEAN|false|Indicates whether backups are enabled or not
1 +# Temporary: to be auto-generated in near future
2 +msgHandlerPoolSize|INTEGER|8|Number of threads in the message handler pool
3 +backupEnabled|BOOLEAN|DEFAULT_BACKUP_ENABLED|Indicates whether backups are enabled or not
...@@ -37,6 +37,7 @@ import org.onlab.packet.IpAddress; ...@@ -37,6 +37,7 @@ import org.onlab.packet.IpAddress;
37 import org.onlab.packet.VlanId; 37 import org.onlab.packet.VlanId;
38 import org.onlab.packet.ndp.NeighborAdvertisement; 38 import org.onlab.packet.ndp.NeighborAdvertisement;
39 import org.onlab.packet.ndp.NeighborSolicitation; 39 import org.onlab.packet.ndp.NeighborSolicitation;
40 +import org.onosproject.cfg.ComponentConfigService;
40 import org.onosproject.core.ApplicationId; 41 import org.onosproject.core.ApplicationId;
41 import org.onosproject.core.CoreService; 42 import org.onosproject.core.CoreService;
42 import org.onosproject.net.ConnectPoint; 43 import org.onosproject.net.ConnectPoint;
...@@ -93,6 +94,9 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid ...@@ -93,6 +94,9 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid
93 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 94 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
94 protected DeviceService deviceService; 95 protected DeviceService deviceService;
95 96
97 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
98 + protected ComponentConfigService cfgService;
99 +
96 private HostProviderService providerService; 100 private HostProviderService providerService;
97 101
98 private final InternalHostProvider processor = new InternalHostProvider(); 102 private final InternalHostProvider processor = new InternalHostProvider();
...@@ -118,8 +122,8 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid ...@@ -118,8 +122,8 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid
118 122
119 @Activate 123 @Activate
120 public void activate(ComponentContext context) { 124 public void activate(ComponentContext context) {
121 - appId = 125 + cfgService.registerProperties(getClass());
122 - coreService.registerApplication("org.onosproject.provider.host"); 126 + appId = coreService.registerApplication("org.onosproject.provider.host");
123 readComponentConfiguration(context); 127 readComponentConfiguration(context);
124 128
125 providerService = providerRegistry.register(this); 129 providerService = providerRegistry.register(this);
...@@ -155,6 +159,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid ...@@ -155,6 +159,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid
155 159
156 @Deactivate 160 @Deactivate
157 public void deactivate() { 161 public void deactivate() {
162 + cfgService.unregisterProperties(getClass(), false);
158 providerRegistry.unregister(this); 163 providerRegistry.unregister(this);
159 packetService.removeProcessor(processor); 164 packetService.removeProcessor(processor);
160 deviceService.removeListener(deviceListener); 165 deviceService.removeListener(deviceListener);
......
1 +# Temporary: to be auto-generated in near future
2 +hostRemovalEnabled|BOOLEAN|true|Enable host removal on port/device down events
3 +ipv6NeighborDiscovery|BOOLEAN|false|Enable using IPv6 Neighbor Discovery by the Host Location Provider; default is false
...@@ -46,6 +46,7 @@ import org.onlab.packet.Ethernet; ...@@ -46,6 +46,7 @@ import org.onlab.packet.Ethernet;
46 import org.onlab.packet.IpAddress; 46 import org.onlab.packet.IpAddress;
47 import org.onlab.packet.MacAddress; 47 import org.onlab.packet.MacAddress;
48 import org.onlab.packet.VlanId; 48 import org.onlab.packet.VlanId;
49 +import org.onosproject.cfg.ComponentConfigAdapter;
49 import org.onosproject.core.ApplicationId; 50 import org.onosproject.core.ApplicationId;
50 import org.onosproject.core.CoreService; 51 import org.onosproject.core.CoreService;
51 import org.onosproject.core.DefaultApplicationId; 52 import org.onosproject.core.DefaultApplicationId;
...@@ -145,6 +146,7 @@ public class HostLocationProviderTest { ...@@ -145,6 +146,7 @@ public class HostLocationProviderTest {
145 .andReturn(appId).anyTimes(); 146 .andReturn(appId).anyTimes();
146 replay(coreService); 147 replay(coreService);
147 148
149 + provider.cfgService = new ComponentConfigAdapter();
148 provider.coreService = coreService; 150 provider.coreService = coreService;
149 151
150 provider.providerRegistry = hostRegistry; 152 provider.providerRegistry = hostRegistry;
......
...@@ -26,6 +26,7 @@ import org.apache.felix.scr.annotations.Property; ...@@ -26,6 +26,7 @@ import org.apache.felix.scr.annotations.Property;
26 import org.apache.felix.scr.annotations.Reference; 26 import org.apache.felix.scr.annotations.Reference;
27 import org.apache.felix.scr.annotations.ReferenceCardinality; 27 import org.apache.felix.scr.annotations.ReferenceCardinality;
28 import org.onlab.packet.Ethernet; 28 import org.onlab.packet.Ethernet;
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;
31 import org.onosproject.mastership.MastershipEvent; 32 import org.onosproject.mastership.MastershipEvent;
...@@ -61,10 +62,10 @@ import java.util.concurrent.ScheduledExecutorService; ...@@ -61,10 +62,10 @@ import java.util.concurrent.ScheduledExecutorService;
61 62
62 import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; 63 import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
63 import static java.util.concurrent.TimeUnit.SECONDS; 64 import static java.util.concurrent.TimeUnit.SECONDS;
65 +import static org.onlab.util.Tools.get;
64 import static org.onlab.util.Tools.groupedThreads; 66 import static org.onlab.util.Tools.groupedThreads;
65 import static org.slf4j.LoggerFactory.getLogger; 67 import static org.slf4j.LoggerFactory.getLogger;
66 68
67 -
68 /** 69 /**
69 * Provider which uses an OpenFlow controller to detect network 70 * Provider which uses an OpenFlow controller to detect network
70 * infrastructure links. 71 * infrastructure links.
...@@ -95,22 +96,27 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -95,22 +96,27 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
95 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 96 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
96 protected MastershipService masterService; 97 protected MastershipService masterService;
97 98
99 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
100 + protected ComponentConfigService cfgService;
101 +
98 private LinkProviderService providerService; 102 private LinkProviderService providerService;
99 103
100 private ScheduledExecutorService executor; 104 private ScheduledExecutorService executor;
101 105
102 - @Property(name = PROP_USE_BDDP, label = "use BDDP for link discovery") 106 + @Property(name = PROP_USE_BDDP, boolValue = true,
107 + label = "Use BDDP for link discovery")
103 private boolean useBDDP = true; 108 private boolean useBDDP = true;
104 109
105 - @Property(name = PROP_DISABLE_LD, label = "permanently disable link discovery") 110 + @Property(name = PROP_DISABLE_LD, boolValue = false,
106 - private boolean disableLD = false; 111 + label = "Permanently disable link discovery")
112 + private boolean disableLinkDiscovery = false;
107 113
108 private static final long INIT_DELAY = 5; 114 private static final long INIT_DELAY = 5;
109 private static final long DELAY = 5; 115 private static final long DELAY = 5;
110 116
111 - @Property(name = PROP_LLDP_SUPPRESSION, 117 + @Property(name = PROP_LLDP_SUPPRESSION, value = DEFAULT_LLDP_SUPPRESSION_CONFIG,
112 label = "Path to LLDP suppression configuration file") 118 label = "Path to LLDP suppression configuration file")
113 - private String filePath = DEFAULT_LLDP_SUPPRESSION_CONFIG; 119 + private String lldpSuppression = DEFAULT_LLDP_SUPPRESSION_CONFIG;
114 120
115 121
116 private final InternalLinkProvider listener = new InternalLinkProvider(); 122 private final InternalLinkProvider listener = new InternalLinkProvider();
...@@ -131,12 +137,12 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -131,12 +137,12 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
131 137
132 @Activate 138 @Activate
133 public void activate(ComponentContext context) { 139 public void activate(ComponentContext context) {
134 - appId = 140 + cfgService.registerProperties(getClass());
135 - coreService.registerApplication("org.onosproject.provider.lldp"); 141 + appId = coreService.registerApplication("org.onosproject.provider.lldp");
136 142
137 // to load configuration at startup 143 // to load configuration at startup
138 modified(context); 144 modified(context);
139 - if (disableLD) { 145 + if (disableLinkDiscovery) {
140 log.info("Link Discovery has been permanently disabled by configuration"); 146 log.info("Link Discovery has been permanently disabled by configuration");
141 return; 147 return;
142 } 148 }
...@@ -177,7 +183,8 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -177,7 +183,8 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
177 183
178 @Deactivate 184 @Deactivate
179 public void deactivate() { 185 public void deactivate() {
180 - if (disableLD) { 186 + cfgService.unregisterProperties(getClass(), false);
187 + if (disableLinkDiscovery) {
181 return; 188 return;
182 } 189 }
183 executor.shutdownNow(); 190 executor.shutdownNow();
...@@ -202,29 +209,29 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -202,29 +209,29 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
202 @SuppressWarnings("rawtypes") 209 @SuppressWarnings("rawtypes")
203 Dictionary properties = context.getProperties(); 210 Dictionary properties = context.getProperties();
204 211
205 - String s = (String) properties.get(PROP_DISABLE_LD); 212 + String s = get(properties, PROP_DISABLE_LD);
206 if (!Strings.isNullOrEmpty(s)) { 213 if (!Strings.isNullOrEmpty(s)) {
207 - disableLD = Boolean.valueOf(s); 214 + disableLinkDiscovery = Boolean.valueOf(s);
208 } 215 }
209 - s = (String) properties.get(PROP_USE_BDDP); 216 + s = get(properties, PROP_USE_BDDP);
210 if (!Strings.isNullOrEmpty(s)) { 217 if (!Strings.isNullOrEmpty(s)) {
211 useBDDP = Boolean.valueOf(s); 218 useBDDP = Boolean.valueOf(s);
212 } 219 }
213 - s = (String) properties.get(PROP_LLDP_SUPPRESSION); 220 + s = get(properties, PROP_LLDP_SUPPRESSION);
214 if (!Strings.isNullOrEmpty(s)) { 221 if (!Strings.isNullOrEmpty(s)) {
215 - filePath = s; 222 + lldpSuppression = s;
216 } 223 }
217 224
218 loadSuppressionRules(); 225 loadSuppressionRules();
219 } 226 }
220 227
221 private void loadSuppressionRules() { 228 private void loadSuppressionRules() {
222 - SuppressionRulesStore store = new SuppressionRulesStore(filePath); 229 + SuppressionRulesStore store = new SuppressionRulesStore(lldpSuppression);
223 try { 230 try {
224 - log.info("Reading suppression rules from {}", filePath); 231 + log.info("Reading suppression rules from {}", lldpSuppression);
225 rules = store.read(); 232 rules = store.read();
226 } catch (IOException e) { 233 } catch (IOException e) {
227 - log.info("Failed to load {}, using built-in rules", filePath); 234 + log.info("Failed to load {}, using built-in rules", lldpSuppression);
228 // default rule to suppress ROADM to maintain compatibility 235 // default rule to suppress ROADM to maintain compatibility
229 rules = new SuppressionRules(ImmutableSet.of(), 236 rules = new SuppressionRules(ImmutableSet.of(),
230 EnumSet.of(Device.Type.ROADM), 237 EnumSet.of(Device.Type.ROADM),
...@@ -307,7 +314,8 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -307,7 +314,8 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
307 log.debug("Device added ({}) {}", event.type(), 314 log.debug("Device added ({}) {}", event.type(),
308 deviceId); 315 deviceId);
309 discoverers.put(deviceId, new LinkDiscovery(device, 316 discoverers.put(deviceId, new LinkDiscovery(device,
310 - packetService, masterService, providerService, useBDDP)); 317 + packetService, masterService,
318 + providerService, useBDDP));
311 } else { 319 } else {
312 if (ld.isStopped()) { 320 if (ld.isStopped()) {
313 log.debug("Device restarted ({}) {}", event.type(), 321 log.debug("Device restarted ({}) {}", event.type(),
......
1 +# Temporary: to be auto-generated in near future
2 +useBDDP|BOOLEAN|true|Use BDDP for link discovery
3 +disableLinkDiscovery|BOOLEAN|false|Permanently disable link discovery
4 +lldpSuppression|STRING|../config/lldp_suppression.json|Path to LLDP suppression configuration file
1 +# Temporary: to be auto-generated in near future
2 +useBDDP|BOOLEAN|true|Use BDDP for link discovery
3 +disableLinkDiscovery|BOOLEAN|false|Permanently disable link discovery
4 +lldpSuppression|STRING|../config/lldp_suppression.json|Path to LLDP suppression configuration file
...@@ -37,6 +37,7 @@ import org.junit.Test; ...@@ -37,6 +37,7 @@ import org.junit.Test;
37 import org.onlab.packet.ChassisId; 37 import org.onlab.packet.ChassisId;
38 import org.onlab.packet.Ethernet; 38 import org.onlab.packet.Ethernet;
39 import org.onlab.packet.ONOSLLDP; 39 import org.onlab.packet.ONOSLLDP;
40 +import org.onosproject.cfg.ComponentConfigAdapter;
40 import org.onosproject.cluster.NodeId; 41 import org.onosproject.cluster.NodeId;
41 import org.onosproject.cluster.RoleInfo; 42 import org.onosproject.cluster.RoleInfo;
42 import org.onosproject.core.ApplicationId; 43 import org.onosproject.core.ApplicationId;
...@@ -103,12 +104,12 @@ public class LLDPLinkProviderTest { ...@@ -103,12 +104,12 @@ public class LLDPLinkProviderTest {
103 104
104 @Before 105 @Before
105 public void setUp() { 106 public void setUp() {
106 -
107 coreService = createMock(CoreService.class); 107 coreService = createMock(CoreService.class);
108 expect(coreService.registerApplication(appId.name())) 108 expect(coreService.registerApplication(appId.name()))
109 .andReturn(appId).anyTimes(); 109 .andReturn(appId).anyTimes();
110 replay(coreService); 110 replay(coreService);
111 111
112 + provider.cfgService = new ComponentConfigAdapter();
112 provider.coreService = coreService; 113 provider.coreService = coreService;
113 114
114 provider.deviceService = deviceService; 115 provider.deviceService = deviceService;
......
...@@ -22,6 +22,7 @@ import org.apache.felix.scr.annotations.Reference; ...@@ -22,6 +22,7 @@ import org.apache.felix.scr.annotations.Reference;
22 import org.apache.felix.scr.annotations.ReferenceCardinality; 22 import org.apache.felix.scr.annotations.ReferenceCardinality;
23 import org.onlab.packet.MacAddress; 23 import org.onlab.packet.MacAddress;
24 import org.onlab.packet.VlanId; 24 import org.onlab.packet.VlanId;
25 +import org.onosproject.cfg.ComponentConfigService;
25 import org.onosproject.cluster.ClusterService; 26 import org.onosproject.cluster.ClusterService;
26 import org.onosproject.mastership.MastershipService; 27 import org.onosproject.mastership.MastershipService;
27 import org.onosproject.net.Device; 28 import org.onosproject.net.Device;
...@@ -65,6 +66,9 @@ public class NullHostProvider extends AbstractProvider implements HostProvider { ...@@ -65,6 +66,9 @@ public class NullHostProvider extends AbstractProvider implements HostProvider {
65 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 66 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
66 protected HostProviderRegistry providerRegistry; 67 protected HostProviderRegistry providerRegistry;
67 68
69 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
70 + protected ComponentConfigService cfgService;
71 +
68 private HostProviderService providerService; 72 private HostProviderService providerService;
69 73
70 //make sure the device has enough ports to accomodate all of them. 74 //make sure the device has enough ports to accomodate all of them.
...@@ -90,6 +94,7 @@ public class NullHostProvider extends AbstractProvider implements HostProvider { ...@@ -90,6 +94,7 @@ public class NullHostProvider extends AbstractProvider implements HostProvider {
90 94
91 @Activate 95 @Activate
92 public void activate() { 96 public void activate() {
97 + cfgService.registerProperties(getClass());
93 providerService = providerRegistry.register(this); 98 providerService = providerRegistry.register(this);
94 for (Device dev : deviceService.getDevices()) { 99 for (Device dev : deviceService.getDevices()) {
95 addHosts(dev); 100 addHosts(dev);
...@@ -101,6 +106,7 @@ public class NullHostProvider extends AbstractProvider implements HostProvider { ...@@ -101,6 +106,7 @@ public class NullHostProvider extends AbstractProvider implements HostProvider {
101 106
102 @Deactivate 107 @Deactivate
103 public void deactivate() { 108 public void deactivate() {
109 + cfgService.unregisterProperties(getClass(), false);
104 providerRegistry.unregister(this); 110 providerRegistry.unregister(this);
105 deviceService.removeListener(hostProvider); 111 deviceService.removeListener(hostProvider);
106 providerService = null; 112 providerService = null;
......
...@@ -27,6 +27,7 @@ import org.apache.felix.scr.annotations.Modified; ...@@ -27,6 +27,7 @@ import org.apache.felix.scr.annotations.Modified;
27 import org.apache.felix.scr.annotations.Property; 27 import org.apache.felix.scr.annotations.Property;
28 import org.apache.felix.scr.annotations.Reference; 28 import org.apache.felix.scr.annotations.Reference;
29 import org.apache.felix.scr.annotations.ReferenceCardinality; 29 import org.apache.felix.scr.annotations.ReferenceCardinality;
30 +import org.onosproject.cfg.ComponentConfigService;
30 import org.onosproject.cluster.ClusterService; 31 import org.onosproject.cluster.ClusterService;
31 import org.onosproject.cluster.NodeId; 32 import org.onosproject.cluster.NodeId;
32 import org.onosproject.mastership.MastershipService; 33 import org.onosproject.mastership.MastershipService;
...@@ -101,6 +102,9 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -101,6 +102,9 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider {
101 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 102 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
102 protected LinkProviderRegistry providerRegistry; 103 protected LinkProviderRegistry providerRegistry;
103 104
105 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
106 + protected ComponentConfigService cfgService;
107 +
104 private LinkProviderService providerService; 108 private LinkProviderService providerService;
105 109
106 private final InternalLinkProvider linkProvider = new InternalLinkProvider(); 110 private final InternalLinkProvider linkProvider = new InternalLinkProvider();
...@@ -119,7 +123,7 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -119,7 +123,7 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider {
119 Executors.newScheduledThreadPool(THREADS, groupedThreads("onos/null", "link-driver-%d")); 123 Executors.newScheduledThreadPool(THREADS, groupedThreads("onos/null", "link-driver-%d"));
120 124
121 // For flicker = true, duration between events in msec. 125 // For flicker = true, duration between events in msec.
122 - @Property(name = "eventRate", value = "0", label = "Duration between Link Event") 126 + @Property(name = "eventRate", intValue = 0, label = "Duration between Link Event")
123 private int eventRate = DEFAULT_RATE; 127 private int eventRate = DEFAULT_RATE;
124 128
125 // topology configuration file 129 // topology configuration file
...@@ -137,6 +141,7 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -137,6 +141,7 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider {
137 141
138 @Activate 142 @Activate
139 public void activate(ComponentContext context) { 143 public void activate(ComponentContext context) {
144 + cfgService.registerProperties(getClass());
140 providerService = providerRegistry.register(this); 145 providerService = providerRegistry.register(this);
141 modified(context); 146 modified(context);
142 147
...@@ -166,6 +171,7 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -166,6 +171,7 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider {
166 171
167 @Deactivate 172 @Deactivate
168 public void deactivate(ComponentContext context) { 173 public void deactivate(ComponentContext context) {
174 + cfgService.unregisterProperties(getClass(), false);
169 linkDriver.shutdown(); 175 linkDriver.shutdown();
170 try { 176 try {
171 linkDriver.awaitTermination(1000, TimeUnit.MILLISECONDS); 177 linkDriver.awaitTermination(1000, TimeUnit.MILLISECONDS);
......
1 +# Temporary: to be auto-generated in near future
2 + "eventRate"|INTEGER|0|Duration between Link Event
3 + "cfgFile"|STRING|"/opt/onos/apache-karaf-3.0.2/etc/linkGraph.cfg"|Topology file location
...@@ -24,6 +24,7 @@ import org.apache.felix.scr.annotations.Reference; ...@@ -24,6 +24,7 @@ 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.onlab.packet.Ethernet; 25 import org.onlab.packet.Ethernet;
26 import org.onlab.packet.ICMP; 26 import org.onlab.packet.ICMP;
27 +import org.onosproject.cfg.ComponentConfigService;
27 import org.onosproject.net.ConnectPoint; 28 import org.onosproject.net.ConnectPoint;
28 import org.onosproject.net.Device; 29 import org.onosproject.net.Device;
29 import org.onosproject.net.PortNumber; 30 import org.onosproject.net.PortNumber;
...@@ -77,6 +78,9 @@ public class NullPacketProvider extends AbstractProvider implements ...@@ -77,6 +78,9 @@ public class NullPacketProvider extends AbstractProvider implements
77 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 78 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
78 protected DeviceService deviceService; 79 protected DeviceService deviceService;
79 80
81 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
82 + protected ComponentConfigService cfgService;
83 +
80 // Rate to generate PacketEvents, per second 84 // Rate to generate PacketEvents, per second
81 @Property(name = "pktRate", intValue = DEFAULT_RATE, 85 @Property(name = "pktRate", intValue = DEFAULT_RATE,
82 label = "Rate of PacketEvent generation") 86 label = "Rate of PacketEvent generation")
...@@ -91,6 +95,7 @@ public class NullPacketProvider extends AbstractProvider implements ...@@ -91,6 +95,7 @@ public class NullPacketProvider extends AbstractProvider implements
91 95
92 @Activate 96 @Activate
93 public void activate(ComponentContext context) { 97 public void activate(ComponentContext context) {
98 + cfgService.registerProperties(getClass());
94 providerService = providerRegistry.register(this); 99 providerService = providerRegistry.register(this);
95 if (!modified(context)) { 100 if (!modified(context)) {
96 packetDriver.submit(new PacketDriver()); 101 packetDriver.submit(new PacketDriver());
...@@ -100,6 +105,7 @@ public class NullPacketProvider extends AbstractProvider implements ...@@ -100,6 +105,7 @@ public class NullPacketProvider extends AbstractProvider implements
100 105
101 @Deactivate 106 @Deactivate
102 public void deactivate(ComponentContext context) { 107 public void deactivate(ComponentContext context) {
108 + cfgService.unregisterProperties(getClass(), false);
103 try { 109 try {
104 packetDriver.awaitTermination(1000, TimeUnit.MILLISECONDS); 110 packetDriver.awaitTermination(1000, TimeUnit.MILLISECONDS);
105 } catch (InterruptedException e) { 111 } catch (InterruptedException e) {
......
1 +# Temporary: to be auto-generated in near future
2 + "pktRate"|INTEGER|5|Rate of PacketEvent generation
...@@ -35,6 +35,7 @@ import java.nio.file.StandardCopyOption; ...@@ -35,6 +35,7 @@ import java.nio.file.StandardCopyOption;
35 import java.nio.file.attribute.BasicFileAttributes; 35 import java.nio.file.attribute.BasicFileAttributes;
36 import java.util.ArrayList; 36 import java.util.ArrayList;
37 import java.util.Collection; 37 import java.util.Collection;
38 +import java.util.Dictionary;
38 import java.util.List; 39 import java.util.List;
39 import java.util.concurrent.ThreadFactory; 40 import java.util.concurrent.ThreadFactory;
40 41
...@@ -142,6 +143,20 @@ public abstract class Tools { ...@@ -142,6 +143,20 @@ public abstract class Tools {
142 } 143 }
143 144
144 /** 145 /**
146 + * Get property as a string value.
147 + *
148 + * @param properties properties to be looked up
149 + * @param propertyName the name of the property to look up
150 + * @return value when the propertyName is defined or return null
151 + */
152 + public static String get(Dictionary<?, ?> properties, String propertyName) {
153 + Object v = properties.get(propertyName);
154 + String s = (v instanceof String) ? (String) v :
155 + v != null ? v.toString() : null;
156 + return Strings.isNullOrEmpty(s) ? null : s.trim();
157 + }
158 +
159 + /**
145 * Suspends the current thread for a specified number of millis. 160 * Suspends the current thread for a specified number of millis.
146 * 161 *
147 * @param ms number of millis 162 * @param ms number of millis
......