Jonathan Hart

Add configuration setting to allow one switch to use the Corsa driver.

Change-Id: I6b17098e6d7c31a2d19ccbb0b5a56bd3b5b1e33a
......@@ -48,6 +48,10 @@
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
</dependencies>
<build>
......
......@@ -89,7 +89,7 @@ public class Controller {
// 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 @@ public class Controller {
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 @@ public class Controller {
/**
* 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 class Controller {
// **************
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 class Controller {
public void start(OpenFlowAgent ag) {
log.info("Starting OpenFlow IO");
this.agent = ag;
this.init(new HashMap<String, String>());
this.init();
this.run();
}
......
......@@ -22,6 +22,7 @@ import com.google.common.collect.Sets;
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.OpenFlowSwitchListener;
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.Logger;
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 @@ public class OpenFlowControllerImpl implements OpenFlowController {
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 @@ public class OpenFlowControllerImpl implements OpenFlowController {
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();
......
......@@ -16,9 +16,6 @@
package org.onosproject.openflow.drivers;
import java.util.Collections;
import java.util.List;
import org.onosproject.openflow.controller.Dpid;
import org.onosproject.openflow.controller.RoleState;
import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch;
......@@ -33,6 +30,9 @@ import org.projectfloodlight.openflow.types.TableId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collections;
import java.util.List;
/**
* A simple implementation of a driver manager that differentiates between
* connected switches using the OF Description Statistics Reply message.
......@@ -43,6 +43,8 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory {
private static final int LOWEST_PRIORITY = 0;
private static Dpid corsaDpid = new Dpid();
/**
* Return an IOFSwitch object based on switch's manufacturer description
* from OFDescStatsReply.
......@@ -56,6 +58,11 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory {
OFDescStatsReply desc, OFVersion ofv) {
String vendor = desc.getMfrDesc();
String hw = desc.getHwDesc();
if (dpid.equals(corsaDpid)) {
return new OFCorsaSwitchDriver(dpid, desc);
}
if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research")
&&
hw.startsWith("OpenFlow 1.3 Reference Userspace Switch")) {
......@@ -157,4 +164,8 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory {
return new DriverManager().getOFSwitchImpl(dpid, desc, ofv);
}
public static void setCorsaDpid(Dpid dpid) {
corsaDpid = dpid;
}
}
......