Initial implementation using titan for reference...not tested
diff --git a/build.xml b/build.xml
index b141553..d3a3747 100644
--- a/build.xml
+++ b/build.xml
@@ -47,6 +47,7 @@
<property name="ant.build.javac.source" value="1.6"/>
<property name="ant.build.javac.target" value="1.6"/>
<property name="lib" location="lib"/>
+ <property name="titanlib" location="lib/titan/"/>
<patternset id="lib">
<include name="logback-classic-1.0.0.jar"/>
@@ -66,10 +67,19 @@
<include name="libthrift-0.7.0.jar"/>
</patternset>
+ <patternset id="titanlib">
+ <include name="titan-0.1.0.jar"/>
+ <include name="blueprints-core-2.1.0.jar"/>
+ <include name="commons-configuration-1.6.jar"/>
+ </patternset>
+
<path id="classpath">
<fileset dir="${lib}">
<patternset refid="lib"/>
</fileset>
+ <fileset dir="${titanlib}">
+ <patternset refid="titanlib"/>
+ </fileset>
</path>
<patternset id="lib-cobertura">
@@ -268,6 +278,9 @@
<patternset refid="lib"/>
<patternset refid="lib-test"/>
</fileset>
+ <fileset dir="${titanlib}">
+ <patternset refid="titanlib"/>
+ </fileset>
</pathconvert>
<exec executable="${basedir}/setup-eclipse.sh">
<arg value="${main-class}"/>
diff --git a/src/main/java/net/floodlightcontroller/core/ISwitchStorage.java b/src/main/java/net/floodlightcontroller/core/ISwitchStorage.java
index 7aa0169..9aec3b3 100644
--- a/src/main/java/net/floodlightcontroller/core/ISwitchStorage.java
+++ b/src/main/java/net/floodlightcontroller/core/ISwitchStorage.java
@@ -1,15 +1,21 @@
package net.floodlightcontroller.core;
import java.util.Collection;
+import java.util.List;
import org.openflow.protocol.OFPhysicalPort;
public interface ISwitchStorage extends INetMapStorage {
+ enum SwitchState {
+ INACTIVE,
+ ACTIVE
+ }
+
/*
* Update the switch details
*/
- public void update(String dpid,DM_OPERATION op);
+ public void update(String dpid,SwitchState state, DM_OPERATION op);
/*
* Associate a port on switch
*/
@@ -43,6 +49,8 @@
*/
public void deletePort(String dpid, String portName);
+ public List<String> getActiveSwitches();
+
/*
* Initialize
*/
diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java
index 90eff6f..d6098af 100644
--- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java
+++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java
@@ -52,11 +52,13 @@
import net.floodlightcontroller.core.IFloodlightProviderService;
import net.floodlightcontroller.core.IHAListener;
import net.floodlightcontroller.core.IInfoProvider;
+import net.floodlightcontroller.core.INetMapStorage.DM_OPERATION;
import net.floodlightcontroller.core.IOFMessageListener;
import net.floodlightcontroller.core.IListener.Command;
import net.floodlightcontroller.core.IOFSwitch;
import net.floodlightcontroller.core.IOFSwitchFilter;
import net.floodlightcontroller.core.IOFSwitchListener;
+import net.floodlightcontroller.core.ISwitchStorage.SwitchState;
import net.floodlightcontroller.core.annotations.LogMessageDoc;
import net.floodlightcontroller.core.annotations.LogMessageDocs;
import net.floodlightcontroller.core.internal.OFChannelState.HandshakeState;
@@ -136,6 +138,8 @@
public class Controller implements IFloodlightProviderService,
IStorageSourceListener {
+ protected SwitchStorageImpl swStore;
+
protected static Logger log = LoggerFactory.getLogger(Controller.class);
private static final String ERROR_DATABASE =
@@ -1141,17 +1145,20 @@
OFPhysicalPort port = m.getDesc();
if (m.getReason() == (byte)OFPortReason.OFPPR_MODIFY.ordinal()) {
sw.setPort(port);
+ swStore.addPort(sw.getStringId(), port);
if (updateStorage)
updatePortInfo(sw, port);
log.debug("Port #{} modified for {}", portNumber, sw);
} else if (m.getReason() == (byte)OFPortReason.OFPPR_ADD.ordinal()) {
sw.setPort(port);
+ swStore.addPort(sw.getStringId(), port);
if (updateStorage)
updatePortInfo(sw, port);
log.debug("Port #{} added for {}", portNumber, sw);
} else if (m.getReason() ==
(byte)OFPortReason.OFPPR_DELETE.ordinal()) {
sw.deletePort(portNumber);
+ swStore.deletePort(sw.getStringId(), portNumber);
if (updateStorage)
removePortInfo(sw, portNumber);
log.debug("Port #{} deleted for {}", portNumber, sw);
@@ -1423,6 +1430,7 @@
}
updateActiveSwitchInfo(sw);
+ swStore.update(sw.getStringId(), SwitchState.ACTIVE, DM_OPERATION.UPDATE);
SwitchUpdate update = new SwitchUpdate(sw, SwitchUpdateType.ADDED);
try {
this.updates.put(update);
@@ -1462,6 +1470,7 @@
// of the switch state that's written to storage.
updateInactiveSwitchInfo(sw);
+ swStore.update(sw.getStringId(), SwitchState.ACTIVE, DM_OPERATION.UPDATE);
SwitchUpdate update = new SwitchUpdate(sw, SwitchUpdateType.REMOVED);
try {
this.updates.put(update);
@@ -2050,6 +2059,7 @@
this.roleChanger = new RoleChanger();
initVendorMessages();
this.systemStartTime = System.currentTimeMillis();
+ this.swStore.init("");
}
/**
diff --git a/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImpl.java b/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImpl.java
index 114803b..789f3ba 100644
--- a/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImpl.java
+++ b/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImpl.java
@@ -60,6 +60,7 @@
if ((sw = graph.getVertices("dpid",dpid).iterator().next()) != null) {
// TODO: Check if port exists
Vertex p = graph.addVertex(null);
+ p.setProperty("type","port");
p.setProperty("number",port.getPortNumber());
p.setProperty("state",port.getState());
p.setProperty("desc",port.getName());
@@ -133,14 +134,14 @@
if ((sw = graph.getVertices("dpid",dpid).iterator().next()) != null) {
// TODO: Check if port exists
Vertex p = sw.query().direction(Direction.OUT).labels("on").has("number",port).vertices().iterator().next();
- graph.removeVertex(p);
- graph.stopTransaction(Conclusion.SUCCESS);
+ if (p != null) {
+ graph.removeVertex(p);
+ graph.stopTransaction(Conclusion.SUCCESS);
+ }
}
} catch (TitanException e) {
// TODO: handle exceptions
}
-
-
}
@Override
@@ -157,9 +158,11 @@
@Override
public void init(String conf) {
- graph = TitanFactory.open(conf);
+ //TODO extract the DB location from conf
+ String db = "/tmp/netmap";
+ graph = TitanFactory.open(db);
graph.createKeyIndex("dpid", Vertex.class);
-
+ graph.createKeyIndex("type", Vertex.class);
}
}
diff --git a/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImplStubs.java b/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImplStubs.java
index 8c3c833..c281141 100644
--- a/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImplStubs.java
+++ b/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImplStubs.java
@@ -4,6 +4,7 @@
package net.floodlightcontroller.core.internal;
import java.util.Collection;
+import java.util.List;
import org.openflow.protocol.OFPhysicalPort;
@@ -15,14 +16,6 @@
*/
public class SwitchStorageImplStubs implements ISwitchStorage {
- /* (non-Javadoc)
- * @see net.floodlightcontroller.core.ISwitchStorage#update(long, net.floodlightcontroller.core.INetMapStorage.DM_OPERATION)
- */
- @Override
- public void update(String dpid, DM_OPERATION op) {
- // TODO Auto-generated method stub
-
- }
/* (non-Javadoc)
* @see net.floodlightcontroller.core.ISwitchStorage#addPort(long, org.openflow.protocol.OFPhysicalPort)
@@ -105,4 +98,17 @@
}
+ @Override
+ public void update(String dpid, SwitchState state, DM_OPERATION op) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public List<String> getActiveSwitches() {
+ return null;
+ // TODO Auto-generated method stub
+
+ }
+
}