Make OpenFlow port configurable via cfg command
Example:
cfg set org.onosproject.openflow.controller.impl.OpenFlowControllerImpl openflowPort 6633
Change-Id: I2fa4b0db671003d0b357e63df619f1b0dec38e03
diff --git a/openflow/ctl/pom.xml b/openflow/ctl/pom.xml
index 9f52cf7..683a09a 100644
--- a/openflow/ctl/pom.xml
+++ b/openflow/ctl/pom.xml
@@ -55,6 +55,10 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
</plugin>
+ <plugin>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-maven-plugin</artifactId>
+ </plugin>
</plugins>
</build>
diff --git a/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OpenFlowControllerImpl.java b/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OpenFlowControllerImpl.java
index 26cfb6d..cdd9854 100644
--- a/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OpenFlowControllerImpl.java
+++ b/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OpenFlowControllerImpl.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.openflow.controller.impl;
+import com.google.common.base.Strings;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
@@ -22,9 +23,11 @@
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Modified;
+import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
+import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.net.driver.DefaultDriverProviderService;
import org.onosproject.net.driver.DriverService;
import org.onosproject.openflow.controller.DefaultOpenFlowPacketContext;
@@ -77,11 +80,14 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
+import static org.onlab.util.Tools.get;
import static org.onlab.util.Tools.groupedThreads;
@Component(immediate = true)
@Service
public class OpenFlowControllerImpl implements OpenFlowController {
+ private static final int DEFAULT_OFPORT = 6633;
+ private static final int DEFAULT_WORKER_THREADS = 16;
private static final Logger log =
LoggerFactory.getLogger(OpenFlowControllerImpl.class);
@@ -93,6 +99,17 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DefaultDriverProviderService defaultDriverProviderService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected ComponentConfigService cfgService;
+
+ @Property(name = "openflowPort", intValue = DEFAULT_OFPORT,
+ label = "Port number used by OpenFlow protocol; default is 6633")
+ private int openflowPort = DEFAULT_OFPORT;
+
+ @Property(name = "workerThreads", intValue = DEFAULT_WORKER_THREADS,
+ label = "Number of controller worker threads; default is 16")
+ private int workerThreads = DEFAULT_WORKER_THREADS;
+
private final ExecutorService executorMsgs =
Executors.newFixedThreadPool(32, groupedThreads("onos/of", "event-stats-%d"));
@@ -130,6 +147,7 @@
@Activate
public void activate(ComponentContext context) {
+ cfgService.registerProperties(getClass());
Map<String, String> properties = readComponentConfiguration(context);
ctrl.setConfigParams(properties);
ctrl.start(agent, driverService);
@@ -137,6 +155,7 @@
@Deactivate
public void deactivate() {
+ cfgService.unregisterProperties(getClass(), false);
ctrl.stop();
}
@@ -148,22 +167,26 @@
private Map<String, String> readComponentConfiguration(ComponentContext context) {
Dictionary<?, ?> properties = context.getProperties();
Map<String, String> outProperties = new HashMap<>();
- try {
- String strDpid = (String) properties.get("corsaDpid");
- if (strDpid != null) {
- outProperties.put("corsaDpid", strDpid);
- }
- } catch (ClassCastException e) {
- return outProperties;
+
+ String port = get(properties, "openflowPort");
+ if (!Strings.isNullOrEmpty(port)) {
+ outProperties.put("openflowport", port);
}
+
+ String thread = get(properties, "workerThreads");
+ if (!Strings.isNullOrEmpty(thread)) {
+ outProperties.put("workerthreads", thread);
+ }
+
return outProperties;
}
@Modified
public void modified(ComponentContext context) {
- // Blank @Modified method to catch modifications to the context.
- // If no @Modified method exists, @Activate is called again
- // when the context is modified.
+ Map<String, String> properties = readComponentConfiguration(context);
+ ctrl.stop();
+ ctrl.setConfigParams(properties);
+ ctrl.start(agent, driverService);
}
@Override