Add configuration setting to allow one switch to use the Corsa driver.
Change-Id: I6b17098e6d7c31a2d19ccbb0b5a56bd3b5b1e33a
diff --git a/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/Controller.java b/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/Controller.java
index 23fd149..22a9cfc 100644
--- a/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/Controller.java
+++ b/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/Controller.java
@@ -89,7 +89,7 @@
// We return a copy of the mapping so we can guarantee that
// the mapping return is the same as one that will be (or was)
// dispatched to IHAListeners
- HashMap<String, String> retval = new HashMap<String, String>();
+ HashMap<String, String> retval = new HashMap<>();
synchronized (controllerNodeIPsCache) {
retval.putAll(controllerNodeIPsCache);
}
@@ -152,6 +152,15 @@
if (ofPort != null) {
this.openFlowPort = Integer.parseInt(ofPort);
}
+ String corsaDpid = configParams.get("corsaDpid");
+ if (corsaDpid != null) {
+ try {
+ DriverManager.setCorsaDpid(new Dpid(corsaDpid));
+ log.info("Corsa DPID set to {}", corsaDpid);
+ } catch (NumberFormatException e) {
+ log.warn("Malformed Corsa DPID string", e);
+ }
+ }
log.debug("OpenFlow port set to {}", this.openFlowPort);
String threads = configParams.get("workerthreads");
this.workerThreads = threads != null ? Integer.parseInt(threads) : 16;
@@ -161,18 +170,13 @@
/**
* Initialize internal data structures.
- *
- * @param configParams configuration parameters
*/
- public void init(Map<String, String> configParams) {
+ public void init() {
// These data structures are initialized here because other
// module's startUp() might be called before ours
- this.controllerNodeIPsCache = new HashMap<String, String>();
+ this.controllerNodeIPsCache = new HashMap<>();
- setConfigParams(configParams);
this.systemStartTime = System.currentTimeMillis();
-
-
}
// **************
@@ -180,7 +184,7 @@
// **************
public Map<String, Long> getMemory() {
- Map<String, Long> m = new HashMap<String, Long>();
+ Map<String, Long> m = new HashMap<>();
Runtime runtime = Runtime.getRuntime();
m.put("total", runtime.totalMemory());
m.put("free", runtime.freeMemory());
@@ -213,7 +217,7 @@
public void start(OpenFlowAgent ag) {
log.info("Starting OpenFlow IO");
this.agent = ag;
- this.init(new HashMap<String, String>());
+ this.init();
this.run();
}
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 a98f000..762a8f5 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
@@ -22,6 +22,7 @@
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.Service;
import org.onosproject.openflow.controller.DefaultOpenFlowPacketContext;
import org.onosproject.openflow.controller.Dpid;
@@ -33,6 +34,7 @@
import org.onosproject.openflow.controller.PacketListener;
import org.onosproject.openflow.controller.RoleState;
import org.onosproject.openflow.controller.driver.OpenFlowAgent;
+import org.osgi.service.component.ComponentContext;
import org.projectfloodlight.openflow.protocol.OFCircuitPortStatus;
import org.projectfloodlight.openflow.protocol.OFExperimenter;
import org.projectfloodlight.openflow.protocol.OFFactories;
@@ -52,7 +54,10 @@
import org.slf4j.LoggerFactory;
import java.util.Collection;
+import java.util.Dictionary;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
@@ -102,7 +107,9 @@
private final Controller ctrl = new Controller();
@Activate
- public void activate() {
+ public void activate(ComponentContext context) {
+ Map<String, String> properties = readComponentConfiguration(context);
+ ctrl.setConfigParams(properties);
ctrl.start(agent);
}
@@ -111,6 +118,32 @@
ctrl.stop();
}
+ /**
+ * Extracts properties from the component configuration context.
+ *
+ * @param context the component context
+ */
+ 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;
+ }
+ 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.
+ }
+
@Override
public Iterable<OpenFlowSwitch> getSwitches() {
return connectedSwitches.values();