Merge remote-tracking branch 'upstream/master'
Conflicts:
src/main/java/net/onrc/onos/util/IDBUtils.java
diff --git a/src/main/java/net/onrc/onos/util/GraphDBConnection.java b/src/main/java/net/onrc/onos/util/GraphDBConnection.java
index 7ea0ab8..e25a0c6 100644
--- a/src/main/java/net/onrc/onos/util/GraphDBConnection.java
+++ b/src/main/java/net/onrc/onos/util/GraphDBConnection.java
@@ -12,165 +12,159 @@
import com.tinkerpop.blueprints.util.wrappers.event.EventTransactionalGraph;
import com.tinkerpop.frames.FramedGraph;
-public class GraphDBConnection {
+public class GraphDBConnection implements IDBConnection {
public enum Transaction {
- COMMIT,
- ROLLBACK
+ COMMIT, ROLLBACK
}
+
public enum GenerateEvent {
- TRUE,
- FALSE
+ TRUE, FALSE
}
+
class TransactionHandle {
protected TransactionalGraph tr;
+
public void create() {
- tr = graph.newTransaction();
+ tr = graph.newTransaction();
}
}
- protected static Logger log = LoggerFactory.getLogger(GraphDBConnection.class);
- private static GraphDBConnection singleton = new GraphDBConnection( );
+
+ protected static Logger log = LoggerFactory
+ .getLogger(GraphDBConnection.class);
+ private static GraphDBConnection singleton = new GraphDBConnection();
private static TitanGraph graph;
private static EventTransactionalGraph<TitanGraph> eg;
- private static GraphDBUtils utils;
private static String configFile;
-
- /* A private Constructor prevents any other
- * class from instantiating.
- */
- private GraphDBConnection(){ }
-
- /* Static 'instance' method */
- public static synchronized GraphDBConnection getInstance(final String conf) {
- if (GraphDBConnection.configFile == null || GraphDBConnection.configFile.isEmpty()) {
- GraphDBConnection.configFile = conf;
- log.debug("GraphDBConnection::Setting Config File {}", GraphDBConnection.configFile);
- }
- if (!GraphDBConnection.configFile.isEmpty() &&
- (graph == null||graph.isOpen() == Boolean.FALSE)) {
- graph = TitanFactory.open(GraphDBConnection.configFile);
- // FIXME: Creation on Indexes should be done only once
- Set<String> s = graph.getIndexedKeys(Vertex.class);
- if (!s.contains("dpid")) {
- graph.createKeyIndex("dpid", Vertex.class);
- }
- if (!s.contains("type")) {
- graph.createKeyIndex("type", Vertex.class);
- }
- if (!s.contains("dl_address")) {
- graph.createKeyIndex("dl_address", Vertex.class);
- }
- if (!s.contains("flow_id")) {
- graph.createKeyIndex("flow_id", Vertex.class);
- }
- if (!s.contains("flow_entry_id")) {
- graph.createKeyIndex("flow_entry_id",
- Vertex.class);
- }
- if (!s.contains("switch_state")) {
- graph.createKeyIndex("switch_state",
- Vertex.class);
- }
- graph.commit();
- eg = new EventTransactionalGraph<TitanGraph>(graph);
- }
- if (utils == null) {
- utils = new GraphDBUtils();
- }
- return singleton;
- }
-
- public IDBUtils utils() {
- return utils;
- }
-
- public FramedGraph<TitanGraph> getFramedGraph() {
-
- if (isValid()) {
- FramedGraph<TitanGraph> fg = new FramedGraph<TitanGraph>(graph);
- return fg;
- } else {
- log.error("new FramedGraph failed");
- return null;
- }
- }
-
- protected EventTransactionalGraph<TitanGraph> getEventGraph() {
-
- if (isValid()) {
- return eg;
- } else {
- return null;
- }
- }
-
- public void addEventListener(final LocalGraphChangedListener listener) {
- EventTransactionalGraph<TitanGraph> eg = this.getEventGraph();
- eg.addListener(listener);
- log.debug("Registered listener {}",listener.getClass());
- }
-
- public Boolean isValid() {
-
- return (graph != null||graph.isOpen());
- }
-
- public void startTx() {
-
-
- }
-
- public void endTx(Transaction tx) {
- try {
- switch (tx) {
- case COMMIT:
- graph.commit();
- case ROLLBACK:
- graph.rollback();
- }
- } catch (Exception e) {
- // TODO Auto-generated catch block
- log.error("{}",e.toString());
- }
- }
-
- public void endTx(TransactionHandle tr, Transaction tx) {
- switch (tx) {
- case COMMIT:
- if (tr != null && tr.tr != null) {
- tr.tr.commit();
- } else {
- graph.commit();
- }
- case ROLLBACK:
- if (tr != null && tr.tr != null) {
- tr.tr.rollback();
- } else {
- graph.rollback();
- }
- }
- }
-
- public void endTx(Transaction tx, GenerateEvent fire) {
+ /*
+ * A private Constructor prevents any other class from instantiating.
+ */
+ private GraphDBConnection() {
+ }
- try {
+ /* Static 'instance' method */
+ public static synchronized GraphDBConnection getInstance(final String conf) {
+ if (GraphDBConnection.configFile == null
+ || GraphDBConnection.configFile.isEmpty()) {
+ GraphDBConnection.configFile = conf;
+ log.debug("GraphDBConnection::Setting Config File {}",
+ GraphDBConnection.configFile);
+ }
+ if (!GraphDBConnection.configFile.isEmpty()
+ && (graph == null || graph.isOpen() == Boolean.FALSE)) {
+ graph = TitanFactory.open(GraphDBConnection.configFile);
+ // FIXME: Creation on Indexes should be done only once
+ Set<String> s = graph.getIndexedKeys(Vertex.class);
+ if (!s.contains("dpid")) {
+ graph.createKeyIndex("dpid", Vertex.class);
+ }
+ if (!s.contains("type")) {
+ graph.createKeyIndex("type", Vertex.class);
+ }
+ if (!s.contains("dl_address")) {
+ graph.createKeyIndex("dl_address", Vertex.class);
+ }
+ if (!s.contains("flow_id")) {
+ graph.createKeyIndex("flow_id", Vertex.class);
+ }
+ if (!s.contains("flow_entry_id")) {
+ graph.createKeyIndex("flow_entry_id", Vertex.class);
+ }
+ if (!s.contains("switch_state")) {
+ graph.createKeyIndex("switch_state", Vertex.class);
+ }
+ graph.commit();
+ eg = new EventTransactionalGraph<TitanGraph>(graph);
+ }
+ return singleton;
+ }
+
+ public FramedGraph<TitanGraph> getFramedGraph() {
+
+ if (isValid()) {
+ FramedGraph<TitanGraph> fg = new FramedGraph<TitanGraph>(graph);
+ return fg;
+ } else {
+ log.error("new FramedGraph failed");
+ return null;
+ }
+ }
+
+ protected EventTransactionalGraph<TitanGraph> getEventGraph() {
+
+ if (isValid()) {
+ return eg;
+ } else {
+ return null;
+ }
+ }
+
+ public void addEventListener(final LocalGraphChangedListener listener) {
+ EventTransactionalGraph<TitanGraph> eg = this.getEventGraph();
+ eg.addListener(listener);
+ log.debug("Registered listener {}", listener.getClass());
+ }
+
+ public Boolean isValid() {
+
+ return (graph != null || graph.isOpen());
+ }
+
+ public void startTx() {
+
+ }
+
+ public void endTx(Transaction tx) {
+ try {
+ switch (tx) {
+ case COMMIT:
+ graph.commit();
+ case ROLLBACK:
+ graph.rollback();
+ }
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ log.error("{}", e.toString());
+ }
+ }
+
+ public void endTx(TransactionHandle tr, Transaction tx) {
+ switch (tx) {
+ case COMMIT:
+ if (tr != null && tr.tr != null) {
+ tr.tr.commit();
+ } else {
+ graph.commit();
+ }
+ case ROLLBACK:
+ if (tr != null && tr.tr != null) {
+ tr.tr.rollback();
+ } else {
+ graph.rollback();
+ }
+ }
+ }
+
+ public void endTx(Transaction tx, GenerateEvent fire) {
+
+ try {
if (fire.equals(GenerateEvent.TRUE)) {
- switch (tx) {
- case COMMIT:
- eg.commit();
- case ROLLBACK:
- eg.rollback();
- }
- } else {
- endTx(tx);
- }
+ switch (tx) {
+ case COMMIT:
+ eg.commit();
+ case ROLLBACK:
+ eg.rollback();
+ }
+ } else {
+ endTx(tx);
+ }
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
- }
-
- public void close() {
- endTx(Transaction.COMMIT);
- }
+ }
+
+ public void close() {
+ endTx(Transaction.COMMIT);
+ }
}
diff --git a/src/main/java/net/onrc/onos/util/GraphDBUtils.java b/src/main/java/net/onrc/onos/util/GraphDBOperation.java
similarity index 76%
rename from src/main/java/net/onrc/onos/util/GraphDBUtils.java
rename to src/main/java/net/onrc/onos/util/GraphDBOperation.java
index 92befe6..a87d5f5 100644
--- a/src/main/java/net/onrc/onos/util/GraphDBUtils.java
+++ b/src/main/java/net/onrc/onos/util/GraphDBOperation.java
@@ -18,23 +18,32 @@
import com.tinkerpop.frames.structures.FramedVertexIterable;
import com.tinkerpop.gremlin.java.GremlinPipeline;
-public class GraphDBUtils implements IDBUtils {
+public class GraphDBOperation implements IDBOperation {
+ private GraphDBConnection conn;
+
+ public GraphDBOperation(GraphDBConnection dbConnection) {
+ this.conn = dbConnection;
+ }
@Override
- public ISwitchObject newSwitch(GraphDBConnection conn) {
+ public ISwitchObject newSwitch(String dpid) {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
ISwitchObject obj = fg.addVertex(null,ISwitchObject.class);
+ if (obj != null) {
+ obj.setType("switch");
+ obj.setDPID(dpid);
+ }
return obj;
}
@Override
- public void removeSwitch(GraphDBConnection conn, ISwitchObject sw) {
+ public void removeSwitch(ISwitchObject sw) {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
fg.removeVertex(sw.asVertex());
}
@Override
- public ISwitchObject searchSwitch(GraphDBConnection conn, String dpid) {
+ public ISwitchObject searchSwitch(String dpid) {
// TODO Auto-generated method stub
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
@@ -44,7 +53,7 @@
}
@Override
- public IDeviceObject searchDevice(GraphDBConnection conn, String macAddr) {
+ public IDeviceObject searchDevice(String macAddr) {
// TODO Auto-generated method stub
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
return (fg != null && fg.getVertices("dl_address",macAddr).iterator().hasNext()) ? fg.getVertices("dl_address",macAddr,
@@ -53,8 +62,8 @@
}
@Override
- public IPortObject searchPort(GraphDBConnection conn, String dpid, short number) {
- ISwitchObject sw = searchSwitch(conn, dpid);
+ public IPortObject searchPort(String dpid, short number) {
+ ISwitchObject sw = searchSwitch(dpid);
if (sw != null) {
IPortObject port = null;
@@ -82,41 +91,45 @@
}
@Override
- public IPortObject newPort(GraphDBConnection conn) {
+ public IPortObject newPort(Short portNumber) {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
IPortObject obj = fg.addVertex(null,IPortObject.class);
+ if (obj != null) {
+ obj.setType("port");
+ obj.setNumber(portNumber);
+ }
return obj;
}
@Override
- public IDeviceObject newDevice(GraphDBConnection conn) {
+ public IDeviceObject newDevice() {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
IDeviceObject obj = fg.addVertex(null,IDeviceObject.class);
+ if (obj != null) obj.setType("device");
return obj;
}
@Override
- public void removePort(GraphDBConnection conn, IPortObject port) {
+ public void removePort(IPortObject port) {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
// EventGraph<TitanGraph> eg = conn.getEventGraph();
if (fg != null) fg.removeVertex(port.asVertex());
}
@Override
- public void removeDevice(GraphDBConnection conn, IDeviceObject dev) {
+ public void removeDevice(IDeviceObject dev) {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
if (fg != null) fg.removeVertex(dev.asVertex());
}
@Override
- public Iterable<IDeviceObject> getDevices(GraphDBConnection conn) {
+ public Iterable<IDeviceObject> getDevices() {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
return fg != null ? fg.getVertices("type","device",IDeviceObject.class) : null;
}
@Override
- public IFlowPath searchFlowPath(GraphDBConnection conn,
- FlowId flowId) {
+ public IFlowPath searchFlowPath(FlowId flowId) {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
return fg.getVertices("flow_id", flowId.toString()).iterator().hasNext() ?
@@ -125,22 +138,21 @@
}
@Override
- public IFlowPath newFlowPath(GraphDBConnection conn) {
+ public IFlowPath newFlowPath() {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
IFlowPath flowPath = fg.addVertex(null, IFlowPath.class);
+ if (flowPath != null) flowPath.setType("flow");
return flowPath;
}
@Override
- public void removeFlowPath(GraphDBConnection conn,
- IFlowPath flowPath) {
+ public void removeFlowPath(IFlowPath flowPath) {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
fg.removeVertex(flowPath.asVertex());
}
@Override
- public IFlowPath getFlowPathByFlowEntry(GraphDBConnection conn,
- IFlowEntry flowEntry) {
+ public IFlowPath getFlowPathByFlowEntry(IFlowEntry flowEntry) {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
GremlinPipeline<Vertex, IFlowPath> pipe = new GremlinPipeline<Vertex, IFlowPath>();
pipe.start(flowEntry.asVertex());
@@ -150,7 +162,7 @@
}
@Override
- public Iterable<IFlowPath> getAllFlowPaths(GraphDBConnection conn) {
+ public Iterable<IFlowPath> getAllFlowPaths() {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
Iterable<IFlowPath> flowPaths = fg.getVertices("type", "flow", IFlowPath.class);
@@ -165,8 +177,7 @@
}
@Override
- public IFlowEntry searchFlowEntry(GraphDBConnection conn,
- FlowEntryId flowEntryId) {
+ public IFlowEntry searchFlowEntry(FlowEntryId flowEntryId) {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
return fg.getVertices("flow_entry_id", flowEntryId.toString()).iterator().hasNext() ?
@@ -175,35 +186,35 @@
}
@Override
- public IFlowEntry newFlowEntry(GraphDBConnection conn) {
+ public IFlowEntry newFlowEntry() {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
IFlowEntry flowEntry = fg.addVertex(null, IFlowEntry.class);
+ if (flowEntry != null) flowEntry.setType("flow_entry");
return flowEntry;
}
@Override
- public void removeFlowEntry(GraphDBConnection conn,
- IFlowEntry flowEntry) {
+ public void removeFlowEntry(IFlowEntry flowEntry) {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
fg.removeVertex(flowEntry.asVertex());
}
@Override
- public Iterable<IFlowEntry> getAllFlowEntries(GraphDBConnection conn) {
+ public Iterable<IFlowEntry> getAllFlowEntries() {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
return fg.getVertices("type", "flow_entry", IFlowEntry.class);
}
@Override
- public Iterable<IFlowEntry> getAllSwitchNotUpdatedFlowEntries(GraphDBConnection conn) {
+ public Iterable<IFlowEntry> getAllSwitchNotUpdatedFlowEntries() {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
//TODO: Should use an enum for flow_switch_state
return fg.getVertices("switch_state", "FE_SWITCH_NOT_UPDATED", IFlowEntry.class);
}
@Override
- public Iterable<ISwitchObject> getActiveSwitches(GraphDBConnection conn) {
+ public Iterable<ISwitchObject> getActiveSwitches() {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
Iterable<ISwitchObject> switches = fg.getVertices("type","switch",ISwitchObject.class);
List<ISwitchObject> activeSwitches = new ArrayList<ISwitchObject>();
@@ -217,14 +228,14 @@
}
@Override
- public Iterable<ISwitchObject> getAllSwitches(GraphDBConnection conn) {
+ public Iterable<ISwitchObject> getAllSwitches() {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
Iterable<ISwitchObject> switches = fg.getVertices("type","switch",ISwitchObject.class);
return switches;
}
@Override
- public Iterable<ISwitchObject> getInactiveSwitches(GraphDBConnection conn) {
+ public Iterable<ISwitchObject> getInactiveSwitches() {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
Iterable<ISwitchObject> switches = fg.getVertices("type","switch",ISwitchObject.class);
List<ISwitchObject> inactiveSwitches = new ArrayList<ISwitchObject>();
@@ -238,9 +249,9 @@
}
@Override
- public ISwitchObject searchActiveSwitch(GraphDBConnection conn, String dpid) {
+ public ISwitchObject searchActiveSwitch(String dpid) {
- ISwitchObject sw = searchSwitch(conn, dpid);
+ ISwitchObject sw = searchSwitch(dpid);
if ((sw != null) &&
sw.getState().equals(SwitchState.ACTIVE.toString())) {
return sw;
diff --git a/src/main/java/net/onrc/onos/util/IDBConnection.java b/src/main/java/net/onrc/onos/util/IDBConnection.java
new file mode 100644
index 0000000..e599a5e
--- /dev/null
+++ b/src/main/java/net/onrc/onos/util/IDBConnection.java
@@ -0,0 +1,19 @@
+package net.onrc.onos.util;
+
+import net.onrc.onos.util.GraphDBConnection.GenerateEvent;
+import net.onrc.onos.util.GraphDBConnection.Transaction;
+import net.onrc.onos.util.GraphDBConnection.TransactionHandle;
+
+import com.thinkaurelius.titan.core.TitanGraph;
+import com.tinkerpop.frames.FramedGraph;
+
+public interface IDBConnection {
+ public FramedGraph<TitanGraph> getFramedGraph();
+ public void addEventListener(final LocalGraphChangedListener listener);
+ public Boolean isValid();
+ public void startTx();
+ public void endTx(Transaction tx);
+ public void endTx(TransactionHandle tr, Transaction tx);
+ public void endTx(Transaction tx, GenerateEvent fire);
+ public void close();
+}
diff --git a/src/main/java/net/onrc/onos/util/IDBOperation.java b/src/main/java/net/onrc/onos/util/IDBOperation.java
new file mode 100644
index 0000000..6a0d52d
--- /dev/null
+++ b/src/main/java/net/onrc/onos/util/IDBOperation.java
@@ -0,0 +1,40 @@
+package net.onrc.onos.util;
+
+import net.floodlightcontroller.core.INetMapTopologyObjects.IDeviceObject;
+import net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry;
+import net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath;
+import net.floodlightcontroller.core.INetMapTopologyObjects.IPortObject;
+import net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject;
+import net.floodlightcontroller.util.FlowEntryId;
+import net.floodlightcontroller.util.FlowId;
+
+public interface IDBOperation {
+ public ISwitchObject newSwitch(String dpid);
+ public ISwitchObject searchSwitch(String dpid);
+ public ISwitchObject searchActiveSwitch(String dpid);
+ public Iterable<ISwitchObject> getActiveSwitches();
+ public Iterable<ISwitchObject> getAllSwitches();
+ public Iterable<ISwitchObject> getInactiveSwitches();
+ public Iterable<IFlowEntry> getAllSwitchNotUpdatedFlowEntries();
+ public void removeSwitch(ISwitchObject sw);
+
+ public IPortObject newPort(Short portNumber);
+ public IPortObject searchPort(String dpid, short number);
+ public void removePort(IPortObject port);
+
+ public IDeviceObject newDevice();
+ public IDeviceObject searchDevice(String macAddr);
+ public Iterable<IDeviceObject> getDevices();
+ public void removeDevice(IDeviceObject dev);
+
+ public IFlowPath newFlowPath();
+ public IFlowPath searchFlowPath(FlowId flowId);
+ public IFlowPath getFlowPathByFlowEntry(IFlowEntry flowEntry);
+ public Iterable<IFlowPath> getAllFlowPaths();
+ public void removeFlowPath(IFlowPath flowPath);
+
+ public IFlowEntry newFlowEntry();
+ public IFlowEntry searchFlowEntry(FlowEntryId flowEntryId);
+ public Iterable<IFlowEntry> getAllFlowEntries();
+ public void removeFlowEntry(IFlowEntry flowEntry);
+}
diff --git a/src/main/java/net/onrc/onos/util/IDBUtils.java b/src/main/java/net/onrc/onos/util/IDBUtils.java
deleted file mode 100644
index a16e136..0000000
--- a/src/main/java/net/onrc/onos/util/IDBUtils.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package net.onrc.onos.util;
-
-import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IDeviceObject;
-import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
-import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
-import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
-import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
-import net.onrc.onos.ofcontroller.util.FlowEntryId;
-import net.onrc.onos.ofcontroller.util.FlowId;
-
-public interface IDBUtils {
- public ISwitchObject searchSwitch(GraphDBConnection conn, String dpid);
- public ISwitchObject searchActiveSwitch(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);
- public IPortObject searchPort(GraphDBConnection conn, String dpid, short number);
- public Iterable<IDeviceObject> getDevices(GraphDBConnection conn);
- public IFlowPath searchFlowPath(GraphDBConnection conn, FlowId flowId);
- public IFlowPath newFlowPath(GraphDBConnection conn);
- public void removeFlowPath(GraphDBConnection conn, IFlowPath flowPath);
- public IFlowPath getFlowPathByFlowEntry(GraphDBConnection conn,
- IFlowEntry flowEntry);
- public Iterable<IFlowPath> getAllFlowPaths(GraphDBConnection conn);
- public IFlowEntry searchFlowEntry(GraphDBConnection conn,
- FlowEntryId flowEntryId);
- public IFlowEntry newFlowEntry(GraphDBConnection conn);
- 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);
- Iterable<IFlowEntry> getAllSwitchNotUpdatedFlowEntries(GraphDBConnection conn);
-}
diff --git a/src/test/java/net/onrc/onos/util/GraphDBOperationTest.java b/src/test/java/net/onrc/onos/util/GraphDBOperationTest.java
new file mode 100644
index 0000000..01f244c
--- /dev/null
+++ b/src/test/java/net/onrc/onos/util/GraphDBOperationTest.java
@@ -0,0 +1,298 @@
+/**
+ *
+ */
+package net.onrc.onos.util;
+
+import static org.junit.Assert.*;
+
+import net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject;
+import net.floodlightcontroller.core.ISwitchStorage.SwitchState;
+import net.floodlightcontroller.core.internal.TestDatabaseManager;
+import net.onrc.onos.util.GraphDBConnection.Transaction;
+
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.thinkaurelius.titan.core.TitanFactory;
+import com.thinkaurelius.titan.core.TitanGraph;
+
+/**
+ * @author Toshio Koide
+ *
+ */
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({TitanFactory.class})
+public class GraphDBOperationTest {
+ private static TitanGraph titanGraph;
+ private static GraphDBConnection conn;
+ private static GraphDBOperation op;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ TestDatabaseManager.deleteTestDatabase();
+ titanGraph = TestDatabaseManager.getTestDatabase();
+// TestDatabaseManager.populateTestData(titanGraph);
+
+ // replace return value of TitanFactory.open() to dummy DB created above
+ PowerMock.mockStatic(TitanFactory.class);
+ EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph);
+ PowerMock.replay(TitanFactory.class);
+
+ conn = GraphDBConnection.getInstance("/dummy/to/conf");
+ op = new GraphDBOperation(conn);
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ conn.close();
+ titanGraph.shutdown();
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#newSwitch(net.onrc.onos.util.GraphDBConnection)}.
+ */
+ @Test
+ public final void testNewSwitch() {
+ Iterable<ISwitchObject> switches;
+
+ switches = op.getAllSwitches();
+ assertFalse(switches.iterator().hasNext());
+
+ ISwitchObject sw = op.newSwitch("123");
+ sw.setState(SwitchState.ACTIVE.toString());
+ conn.endTx(Transaction.COMMIT);
+
+ switches = op.getAllSwitches();
+ assertTrue(switches.iterator().hasNext());
+
+ ISwitchObject obtained_sw = switches.iterator().next();
+ String obtained_dpid = obtained_sw.getDPID();
+ assertEquals("123", obtained_dpid);
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeSwitch(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject)}.
+ */
+ @Test
+ public final void testRemoveSwitch() {
+ Iterable<ISwitchObject> switches;
+
+ // make sure there is no switch
+ switches = op.getAllSwitches();
+ assertFalse(switches.iterator().hasNext());
+
+ ISwitchObject sw = op.newSwitch("123");
+ sw.setState(SwitchState.ACTIVE.toString());
+ conn.endTx(Transaction.COMMIT);
+
+ sw = op.searchSwitch("123");
+ op.removeSwitch(sw);
+
+ assertNull(op.searchSwitch("123"));
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchSwitch(net.onrc.onos.util.GraphDBConnection, java.lang.String)}.
+ */
+ @Test
+ public final void testSearchSwitch() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchDevice(net.onrc.onos.util.GraphDBConnection, java.lang.String)}.
+ */
+ @Test
+ public final void testSearchDevice() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchPort(net.onrc.onos.util.GraphDBConnection, java.lang.String, short)}.
+ */
+ @Test
+ public final void testSearchPort() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#newPort(net.onrc.onos.util.GraphDBConnection)}.
+ */
+ @Test
+ public final void testNewPort() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#newDevice(net.onrc.onos.util.GraphDBConnection)}.
+ */
+ @Test
+ public final void testNewDevice() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#removePort(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IPortObject)}.
+ */
+ @Test
+ public final void testRemovePort() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeDevice(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IDeviceObject)}.
+ */
+ @Test
+ public final void testRemoveDevice() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#getDevices(net.onrc.onos.util.GraphDBConnection)}.
+ */
+ @Test
+ public final void testGetDevices() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchFlowPath(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.util.FlowId)}.
+ */
+ @Test
+ public final void testSearchFlowPath() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#newFlowPath(net.onrc.onos.util.GraphDBConnection)}.
+ */
+ @Test
+ public final void testNewFlowPath() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeFlowPath(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath)}.
+ */
+ @Test
+ public final void testRemoveFlowPath() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#getFlowPathByFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry)}.
+ */
+ @Test
+ public final void testGetFlowPathByFlowEntry() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllFlowPaths(net.onrc.onos.util.GraphDBConnection)}.
+ */
+ @Test
+ public final void testGetAllFlowPaths() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.util.FlowEntryId)}.
+ */
+ @Test
+ public final void testSearchFlowEntry() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#newFlowEntry(net.onrc.onos.util.GraphDBConnection)}.
+ */
+ @Test
+ public final void testNewFlowEntry() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry)}.
+ */
+ @Test
+ public final void testRemoveFlowEntry() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllFlowEntries(net.onrc.onos.util.GraphDBConnection)}.
+ */
+ @Test
+ public final void testGetAllFlowEntries() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllSwitchNotUpdatedFlowEntries(net.onrc.onos.util.GraphDBConnection)}.
+ */
+ @Test
+ public final void testGetAllSwitchNotUpdatedFlowEntries() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#getActiveSwitches(net.onrc.onos.util.GraphDBConnection)}.
+ */
+ @Test
+ public final void testGetActiveSwitches() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllSwitches(net.onrc.onos.util.GraphDBConnection)}.
+ */
+ @Test
+ public final void testGetAllSwitches() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#getInactiveSwitches(net.onrc.onos.util.GraphDBConnection)}.
+ */
+ @Test
+ public final void testGetInactiveSwitches() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchActiveSwitch(net.onrc.onos.util.GraphDBConnection, java.lang.String)}.
+ */
+ @Test
+ public final void testSearchActiveSwitch() {
+ fail("Not yet implemented");
+ }
+
+}