Charles Chan
Committed by Gerrit Code Review

Make OpenFlow port configurable via cfg command

Example:
cfg set org.onosproject.openflow.controller.impl.OpenFlowControllerImpl openflowPort 6633

Change-Id: I2fa4b0db671003d0b357e63df619f1b0dec38e03
......@@ -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>
......
......@@ -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.Activate;
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.Executors;
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 @@ public class OpenFlowControllerImpl implements OpenFlowController {
@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 @@ public class OpenFlowControllerImpl implements OpenFlowController {
@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 @@ public class OpenFlowControllerImpl implements OpenFlowController {
@Deactivate
public void deactivate() {
cfgService.unregisterProperties(getClass(), false);
ctrl.stop();
}
......@@ -148,22 +167,26 @@ public class OpenFlowControllerImpl implements OpenFlowController {
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);
String port = get(properties, "openflowPort");
if (!Strings.isNullOrEmpty(port)) {
outProperties.put("openflowport", port);
}
} catch (ClassCastException e) {
return outProperties;
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
......