Reduced graph handles and thread locals
diff --git a/src/main/java/net/onrc/onos/util/GraphDBConnection.java b/src/main/java/net/onrc/onos/util/GraphDBConnection.java
index 724095b..ee50cd0 100644
--- a/src/main/java/net/onrc/onos/util/GraphDBConnection.java
+++ b/src/main/java/net/onrc/onos/util/GraphDBConnection.java
@@ -85,7 +85,7 @@
}
public void close() {
-
+ graph.stopTransaction(Conclusion.SUCCESS);
}
}
diff --git a/src/main/java/net/onrc/onos/util/GraphDBUtils.java b/src/main/java/net/onrc/onos/util/GraphDBUtils.java
index 097cfa0..ba48103 100644
--- a/src/main/java/net/onrc/onos/util/GraphDBUtils.java
+++ b/src/main/java/net/onrc/onos/util/GraphDBUtils.java
@@ -1,5 +1,8 @@
package net.onrc.onos.util;
+import java.util.ArrayList;
+import java.util.List;
+
import com.thinkaurelius.titan.core.TitanGraph;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.frames.FramedGraph;
@@ -11,12 +14,26 @@
import net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath;
import net.floodlightcontroller.core.INetMapTopologyObjects.IPortObject;
import net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject;
+import net.floodlightcontroller.core.ISwitchStorage.SwitchState;
import net.floodlightcontroller.util.FlowEntryId;
import net.floodlightcontroller.util.FlowId;
public class GraphDBUtils implements IDBUtils {
+
+ @Override
+ public ISwitchObject newSwitch(GraphDBConnection conn) {
+ FramedGraph<TitanGraph> fg = conn.getFramedGraph();
+ ISwitchObject obj = fg.addVertex(null,ISwitchObject.class);
+ return obj;
+ }
@Override
+ public void removeSwitch(GraphDBConnection conn, ISwitchObject sw) {
+ FramedGraph<TitanGraph> fg = conn.getFramedGraph();
+ fg.removeVertex(sw.asVertex());
+ }
+
+ @Override
public ISwitchObject searchSwitch(GraphDBConnection conn, String dpid) {
// TODO Auto-generated method stub
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
@@ -46,11 +63,24 @@
}
@Override
+ public IPortObject newPort(GraphDBConnection conn) {
+ FramedGraph<TitanGraph> fg = conn.getFramedGraph();
+ IPortObject obj = fg.addVertex(null,IPortObject.class);
+ return obj;
+ }
+
+ @Override
public IDeviceObject newDevice(GraphDBConnection conn) {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
IDeviceObject obj = fg.addVertex(null,IDeviceObject.class);
return obj;
}
+
+ @Override
+ public void removePort(GraphDBConnection conn, IPortObject port) {
+ FramedGraph<TitanGraph> fg = conn.getFramedGraph();
+ fg.removeVertex(port.asVertex());
+ }
@Override
public void removeDevice(GraphDBConnection conn, IDeviceObject dev) {
@@ -136,4 +166,39 @@
return fg.getVertices("type", "flow_entry", IFlowEntry.class);
}
+
+ @Override
+ public Iterable<ISwitchObject> getActiveSwitches(GraphDBConnection conn) {
+ FramedGraph<TitanGraph> fg = conn.getFramedGraph();
+ Iterable<ISwitchObject> switches = fg.getVertices("type","switch",ISwitchObject.class);
+ List<ISwitchObject> activeSwitches = new ArrayList<ISwitchObject>();
+
+ for (ISwitchObject sw: switches) {
+ if(sw.getState().equals(SwitchState.ACTIVE.toString())) {
+ activeSwitches.add(sw);
+ }
+ }
+ return activeSwitches;
+ }
+
+ @Override
+ public Iterable<ISwitchObject> getAllSwitches(GraphDBConnection conn) {
+ FramedGraph<TitanGraph> fg = conn.getFramedGraph();
+ Iterable<ISwitchObject> switches = fg.getVertices("type","switch",ISwitchObject.class);
+ return switches;
+ }
+
+ @Override
+ public Iterable<ISwitchObject> getInactiveSwitches(GraphDBConnection conn) {
+ FramedGraph<TitanGraph> fg = conn.getFramedGraph();
+ Iterable<ISwitchObject> switches = fg.getVertices("type","switch",ISwitchObject.class);
+ List<ISwitchObject> inactiveSwitches = new ArrayList<ISwitchObject>();
+
+ for (ISwitchObject sw: switches) {
+ if(sw.getState().equals(SwitchState.INACTIVE.toString())) {
+ inactiveSwitches.add(sw);
+ }
+ }
+ return inactiveSwitches;
+ }
}
diff --git a/src/main/java/net/onrc/onos/util/IDBUtils.java b/src/main/java/net/onrc/onos/util/IDBUtils.java
index 48d5946..864e227 100644
--- a/src/main/java/net/onrc/onos/util/IDBUtils.java
+++ b/src/main/java/net/onrc/onos/util/IDBUtils.java
@@ -10,6 +10,11 @@
public interface IDBUtils {
public ISwitchObject searchSwitch(GraphDBConnection conn, String dpid);
+ public Iterable<ISwitchObject> getActiveSwitches(GraphDBConnection conn);
+ public Iterable<ISwitchObject> getAllSwitches(GraphDBConnection conn);
+ public Iterable<ISwitchObject> getInactiveSwitches(GraphDBConnection conn);
+
+
public IDeviceObject searchDevice(GraphDBConnection conn, String macAddr);
public IDeviceObject newDevice(GraphDBConnection conn);
public void removeDevice(GraphDBConnection conn, IDeviceObject dev);
@@ -27,4 +32,8 @@
public void removeFlowEntry(GraphDBConnection conn,
IFlowEntry flowEntry);
public Iterable<IFlowEntry> getAllFlowEntries(GraphDBConnection conn);
+ public IPortObject newPort(GraphDBConnection conn);
+ ISwitchObject newSwitch(GraphDBConnection conn);
+ void removePort(GraphDBConnection conn, IPortObject port);
+ void removeSwitch(GraphDBConnection conn, ISwitchObject sw);
}