Optimize source code
diff --git a/src/main/java/net/onrc/onos/graph/DBOperation.java b/src/main/java/net/onrc/onos/graph/DBOperation.java
index 9b89bed..5dd5aaa 100644
--- a/src/main/java/net/onrc/onos/graph/DBOperation.java
+++ b/src/main/java/net/onrc/onos/graph/DBOperation.java
@@ -29,190 +29,206 @@
*/
public abstract class DBOperation implements IDBOperation {
- protected DBConnection conn;
+ protected DBConnection conn;
- @Override
- public ISwitchObject searchActiveSwitch(String dpid) {
- ISwitchObject sw = searchSwitch(dpid);
- if ((sw != null)
- && sw.getState().equals(ISwitchStorage.SwitchState.ACTIVE.toString())) {
- return sw;
- }
- return null;
- }
+ @Override
+ public ISwitchObject searchActiveSwitch(String dpid) {
+ ISwitchObject sw = searchSwitch(dpid);
+ if ((sw != null)
+ && sw.getState().equals(ISwitchStorage.SwitchState.ACTIVE.toString())) {
+ return sw;
+ }
+ return null;
+ }
- @Override
- public ISwitchObject newSwitch(final String dpid) {
- ISwitchObject obj = (ISwitchObject) conn.getFramedGraph().addVertex(null, ISwitchObject.class);
- if (obj != null) {
- obj.setType("switch");
- obj.setDPID(dpid);
- }
- return obj;
- }
+ @Override
+ public ISwitchObject newSwitch(final String dpid) {
+ ISwitchObject obj = (ISwitchObject) conn.getFramedGraph().addVertex(null, ISwitchObject.class);
+ if (obj != null) {
+ obj.setType("switch");
+ obj.setDPID(dpid);
+ }
+ return obj;
+ }
- @Override
- public Iterable<ISwitchObject> getAllSwitches() {
- Iterable<ISwitchObject> switches = conn.getFramedGraph().getVertices("type", "switch", ISwitchObject.class);
- return switches;
- }
+ @Override
+ public Iterable<ISwitchObject> getAllSwitches() {
+ Iterable<ISwitchObject> switches = conn.getFramedGraph().getVertices("type", "switch", ISwitchObject.class);
+ return switches;
+ }
- @Override
- public Iterable<ISwitchObject> getInactiveSwitches() {
- Iterable<ISwitchObject> switches = conn.getFramedGraph().getVertices("type", "switch", ISwitchObject.class);
- List<ISwitchObject> inactiveSwitches = new ArrayList<ISwitchObject>();
+ @Override
+ public Iterable<ISwitchObject> getInactiveSwitches() {
+ Iterable<ISwitchObject> switches = conn.getFramedGraph().getVertices("type", "switch", ISwitchObject.class);
+ List<ISwitchObject> inactiveSwitches = new ArrayList<ISwitchObject>();
- for (ISwitchObject sw : switches) {
- if (sw.getState().equals(ISwitchStorage.SwitchState.INACTIVE.toString())) {
- inactiveSwitches.add(sw);
- }
- }
- return inactiveSwitches;
- }
+ for (ISwitchObject sw : switches) {
+ if (sw.getState().equals(ISwitchStorage.SwitchState.INACTIVE.toString())) {
+ inactiveSwitches.add(sw);
+ }
+ }
+ return inactiveSwitches;
+ }
- @Override
- public Iterable<INetMapTopologyObjects.IFlowEntry> getAllSwitchNotUpdatedFlowEntries() {
- //TODO: Should use an enum for flow_switch_state
- return conn.getFramedGraph().getVertices("switch_state", "FE_SWITCH_NOT_UPDATED", INetMapTopologyObjects.IFlowEntry.class);
+ @Override
+ public Iterable<INetMapTopologyObjects.IFlowEntry> getAllSwitchNotUpdatedFlowEntries() {
+ //TODO: Should use an enum for flow_switch_state
+ return conn.getFramedGraph().getVertices("switch_state", "FE_SWITCH_NOT_UPDATED", INetMapTopologyObjects.IFlowEntry.class);
- }
+ }
- @Override
- public void removeSwitch(ISwitchObject sw) {
- conn.getFramedGraph().removeVertex(sw.asVertex());
- }
+ @Override
+ public void removeSwitch(ISwitchObject sw) {
+ conn.getFramedGraph().removeVertex(sw.asVertex());
+ }
- @Override
- public IPortObject newPort(String dpid, Short portNum) {
- IPortObject obj = (IPortObject) conn.getFramedGraph().addVertex(null, IPortObject.class);
- if (obj != null) {
- obj.setType("port");
- String id = dpid + portNum.toString();
- obj.setPortId(id);
- obj.setNumber(portNum);
- }
- return obj;
- }
-
- /**
- * Create a port having specified port number.
- *
- * @param portNumber port number
- */
- @Deprecated
- public IPortObject newPort(Short portNumber) {
- IPortObject obj = (IPortObject) conn.getFramedGraph().addVertex(null, IPortObject.class);
- if (obj != null) {
- obj.setType("port");
- obj.setNumber(portNumber);
- }
- return obj;
- }
+ @Override
+ public IPortObject newPort(String dpid, Short portNum) {
+ IPortObject obj = (IPortObject) conn.getFramedGraph().addVertex(null, IPortObject.class);
+ if (obj != null) {
+ obj.setType("port");
+ String id = dpid + portNum.toString();
+ obj.setPortId(id);
+ obj.setNumber(portNum);
+ }
+ return obj;
+ }
- @Override
- public IPortObject searchPort(String dpid, Short number) {
- String id = dpid + number.toString();
- return (conn.getFramedGraph() != null && conn.getFramedGraph().getVertices("port_id", id).iterator().hasNext())
- ? (IPortObject) conn.getFramedGraph().getVertices("port_id", id, IPortObject.class).iterator().next() : null;
+ /**
+ * Create a port having specified port number.
+ *
+ * @param portNumber port number
+ */
+ @Deprecated
+ public IPortObject newPort(Short portNumber) {
+ IPortObject obj = (IPortObject) conn.getFramedGraph().addVertex(null, IPortObject.class);
+ if (obj != null) {
+ obj.setType("port");
+ obj.setNumber(portNumber);
+ }
+ return obj;
+ }
- }
+ @Override
+ public IPortObject searchPort(String dpid, Short number) {
+ String id = dpid + number.toString();
+ return (conn.getFramedGraph() != null && conn.getFramedGraph().getVertices("port_id", id).iterator().hasNext())
+ ? (IPortObject) conn.getFramedGraph().getVertices("port_id", id, IPortObject.class).iterator().next() : null;
- @Override
- public IDeviceObject newDevice() {
- IDeviceObject obj = (IDeviceObject) conn.getFramedGraph().addVertex(null, IDeviceObject.class);
- if (obj != null) {
- obj.setType("device");
- }
- return obj;
- }
+ }
- /**
- * Create and return a flow path object.
- */
-
- @Override
- public IFlowPath newFlowPath() {
- IFlowPath flowPath = (IFlowPath)conn.getFramedGraph().addVertex(null, IFlowPath.class);
- if (flowPath != null) {
- flowPath.setType("flow");
- }
- return flowPath;
- }
-
- @Override
- public IFlowPath getFlowPathByFlowEntry(INetMapTopologyObjects.IFlowEntry flowEntry) {
- GremlinPipeline<Vertex, IFlowPath> pipe = new GremlinPipeline<Vertex, IFlowPath>();
- pipe.start(flowEntry.asVertex());
- pipe.out("flow");
- FramedVertexIterable<IFlowPath> r = new FramedVertexIterable(conn.getFramedGraph(), (Iterable) pipe, IFlowPath.class);
- return r.iterator().hasNext() ? r.iterator().next() : null;
- }
+ @Override
+ public void removePort(IPortObject port) {
+ if (conn.getFramedGraph() != null) {
+ conn.getFramedGraph().removeVertex(port.asVertex());
+ }
+ }
+
+ @Override
+ public IDeviceObject newDevice() {
+ IDeviceObject obj = (IDeviceObject) conn.getFramedGraph().addVertex(null, IDeviceObject.class);
+ if (obj != null) {
+ obj.setType("device");
+ }
+ return obj;
+ }
+
+ @Override
+ public Iterable<IDeviceObject> getDevices() {
+ return conn.getFramedGraph() != null ? conn.getFramedGraph().getVertices("type", "device", IDeviceObject.class) : null;
+ }
- /**
- * Search and get a switch object with DPID.
- *
- * @param dpid DPID of the switch
- */
- @Override
- public ISwitchObject searchSwitch(final String dpid) {
- return (conn.getFramedGraph() != null && conn.getFramedGraph().getVertices("dpid", dpid).iterator().hasNext())
- ? (ISwitchObject) (conn.getFramedGraph().getVertices("dpid", dpid, ISwitchObject.class).iterator().next()) : null;
- }
+ @Override
+ public void removeDevice(IDeviceObject dev) {
+ if (conn.getFramedGraph() != null) {
+ conn.getFramedGraph().removeVertex(dev.asVertex());
+ }
+ }
+
+ /**
+ * Create and return a flow path object.
+ */
- @Override
- public Iterable<ISwitchObject> getActiveSwitches() {
- Iterable<ISwitchObject> switches = conn.getFramedGraph().getVertices("type", "switch", ISwitchObject.class);
- List<ISwitchObject> activeSwitches = new ArrayList<ISwitchObject>();
+ @Override
+ public IFlowPath newFlowPath() {
+ IFlowPath flowPath = (IFlowPath)conn.getFramedGraph().addVertex(null, IFlowPath.class);
+ if (flowPath != null) {
+ flowPath.setType("flow");
+ }
+ return flowPath;
+ }
- for (ISwitchObject sw : switches) {
- if (sw.getState().equals(ISwitchStorage.SwitchState.ACTIVE.toString())) {
- activeSwitches.add(sw);
- }
- }
- return activeSwitches;
- }
+ @Override
+ public IFlowPath getFlowPathByFlowEntry(INetMapTopologyObjects.IFlowEntry flowEntry) {
+ GremlinPipeline<Vertex, IFlowPath> pipe = new GremlinPipeline<Vertex, IFlowPath>();
+ pipe.start(flowEntry.asVertex());
+ pipe.out("flow");
+ FramedVertexIterable<IFlowPath> r = new FramedVertexIterable(conn.getFramedGraph(), (Iterable) pipe, IFlowPath.class);
+ return r.iterator().hasNext() ? r.iterator().next() : null;
+ }
- protected Iterable<ISwitchObject> getAllSwitches(final FramedGraph fg) {
- Iterable<ISwitchObject> switches = fg.getVertices("type", "switch", ISwitchObject.class);
- return switches;
- }
- protected IDeviceObject searchDevice(String macAddr, final FramedGraph fg) {
- return (fg != null && fg.getVertices("dl_addr", macAddr).iterator().hasNext())
- ? (IDeviceObject) fg.getVertices("dl_addr", macAddr, IDeviceObject.class).iterator().next() : null;
+ /**
+ * Search and get a switch object with DPID.
+ *
+ * @param dpid DPID of the switch
+ */
+ @Override
+ public ISwitchObject searchSwitch(final String dpid) {
+ return (conn.getFramedGraph() != null && conn.getFramedGraph().getVertices("dpid", dpid).iterator().hasNext())
+ ? (ISwitchObject) (conn.getFramedGraph().getVertices("dpid", dpid, ISwitchObject.class).iterator().next()) : null;
+ }
- }
-
- protected IFlowPath searchFlowPath(final FlowId flowId, final FramedGraph fg) {
- return fg.getVertices("flow_id", flowId.toString()).iterator().hasNext()
- ? (IFlowPath) fg.getVertices("flow_id", flowId.toString(),
- IFlowPath.class).iterator().next() : null;
- }
-
- protected Iterable<IFlowPath> getAllFlowPaths(final FramedGraph fg) {
- Iterable<IFlowPath> flowPaths = fg.getVertices("type", "flow", IFlowPath.class);
+ @Override
+ public Iterable<ISwitchObject> getActiveSwitches() {
+ Iterable<ISwitchObject> switches = conn.getFramedGraph().getVertices("type", "switch", ISwitchObject.class);
+ List<ISwitchObject> activeSwitches = new ArrayList<ISwitchObject>();
- List<IFlowPath> nonNullFlows = new ArrayList<IFlowPath>();
+ for (ISwitchObject sw : switches) {
+ if (sw.getState().equals(ISwitchStorage.SwitchState.ACTIVE.toString())) {
+ activeSwitches.add(sw);
+ }
+ }
+ return activeSwitches;
+ }
- for (IFlowPath fp : flowPaths) {
- if (fp.getFlowId() != null) {
- nonNullFlows.add(fp);
- }
- }
- return nonNullFlows;
- }
-
- @Override
- public IFlowEntry newFlowEntry() {
- IFlowEntry flowEntry = (IFlowEntry) conn.getFramedGraph().addVertex(null, IFlowEntry.class);
- if (flowEntry != null) {
- flowEntry.setType("flow_entry");
- }
- return flowEntry;
- }
-
-
+ @Override
+ public IDeviceObject searchDevice(String macAddr) {
+ return (conn.getFramedGraph() != null && conn.getFramedGraph().getVertices("dl_addr", macAddr).iterator().hasNext())
+ ? (IDeviceObject) conn.getFramedGraph().getVertices("dl_addr", macAddr, IDeviceObject.class).iterator().next() : null;
+
+ }
+
+ protected IFlowPath searchFlowPath(final FlowId flowId, final FramedGraph fg) {
+ return fg.getVertices("flow_id", flowId.toString()).iterator().hasNext()
+ ? (IFlowPath) fg.getVertices("flow_id", flowId.toString(),
+ IFlowPath.class).iterator().next() : null;
+ }
+
+ protected Iterable<IFlowPath> getAllFlowPaths(final FramedGraph fg) {
+ Iterable<IFlowPath> flowPaths = fg.getVertices("type", "flow", IFlowPath.class);
+
+ List<IFlowPath> nonNullFlows = new ArrayList<IFlowPath>();
+
+ for (IFlowPath fp : flowPaths) {
+ if (fp.getFlowId() != null) {
+ nonNullFlows.add(fp);
+ }
+ }
+ return nonNullFlows;
+ }
+
+ @Override
+ public IFlowEntry newFlowEntry() {
+ IFlowEntry flowEntry = (IFlowEntry) conn.getFramedGraph().addVertex(null, IFlowEntry.class);
+ if (flowEntry != null) {
+ flowEntry.setType("flow_entry");
+ }
+ return flowEntry;
+ }
+
+
public IIpv4Address newIpv4Address() {
return newVertex("ipv4Address", IIpv4Address.class);
}
@@ -224,7 +240,7 @@
}
return newVertex;
}
-
+
public IIpv4Address searchIpv4Address(int intIpv4Address) {
return searchForVertex("ipv4_address", intIpv4Address, IIpv4Address.class);
}
diff --git a/src/main/java/net/onrc/onos/graph/RamCloudDBOperation.java b/src/main/java/net/onrc/onos/graph/RamCloudDBOperation.java
index 68226d1..657c521 100644
--- a/src/main/java/net/onrc/onos/graph/RamCloudDBOperation.java
+++ b/src/main/java/net/onrc/onos/graph/RamCloudDBOperation.java
@@ -26,40 +26,6 @@
}
@Override
- public Iterable<ISwitchObject> getAllSwitches() {
- return getAllSwitches(conn.getFramedGraph());
- }
-
- @Override
- public void removePort(INetMapTopologyObjects.IPortObject port) {
- FramedGraph<RamCloudGraph> fg = conn.getFramedGraph();
- if (fg != null) {
- fg.removeVertex(port.asVertex());
- }
- }
-
- @Override
- public IDeviceObject searchDevice(String macAddr) {
- FramedGraph<RamCloudGraph> fg = conn.getFramedGraph();
- return searchDevice(macAddr, fg);
- }
-
- @Override
- public Iterable<IDeviceObject> getDevices() {
- FramedGraph<RamCloudGraph> fg = conn.getFramedGraph();
- return fg != null ? fg.getVertices("type", "device", IDeviceObject.class) : null;
- }
-
- @Override
- public void removeDevice(IDeviceObject dev) {
- FramedGraph<RamCloudGraph> fg = conn.getFramedGraph();
- if (fg != null) {
- fg.removeVertex(dev.asVertex());
- }
- }
-
-
- @Override
public IFlowPath searchFlowPath(FlowId flowId) {
FramedGraph<RamCloudGraph> fg = conn.getFramedGraph();
return searchFlowPath(flowId, fg);
diff --git a/src/main/java/net/onrc/onos/graph/TitanDBOperation.java b/src/main/java/net/onrc/onos/graph/TitanDBOperation.java
index 9362753..3a6f13d 100644
--- a/src/main/java/net/onrc/onos/graph/TitanDBOperation.java
+++ b/src/main/java/net/onrc/onos/graph/TitanDBOperation.java
@@ -22,35 +22,6 @@
* @author nickkaranatsios
*/
public class TitanDBOperation extends DBOperation {
-
- @Override
- public void removePort(IPortObject port) {
- FramedGraph<TitanGraph> fg = conn.getFramedGraph();
- if (fg != null) {
- fg.removeVertex(port.asVertex());
- }
- }
-
- @Override
- public IDeviceObject searchDevice(String macAddr) {
- // TODO Auto-generated method stub
- FramedGraph<TitanGraph> fg = conn.getFramedGraph();
- return searchDevice(macAddr, fg);
- }
-
- @Override
- public Iterable<IDeviceObject> getDevices() {
- FramedGraph<TitanGraph> fg = conn.getFramedGraph();
- return fg != null ? fg.getVertices("type", "device", IDeviceObject.class) : null;
- }
-
- @Override
- public void removeDevice(IDeviceObject dev) {
- FramedGraph<TitanGraph> fg = conn.getFramedGraph();
- if (fg != null) {
- fg.removeVertex(dev.asVertex());
- }
- }
@Override
public IFlowPath searchFlowPath(FlowId flowId) {
@@ -58,7 +29,6 @@
return searchFlowPath(flowId, fg);
}
-
@Override
public Iterable<IFlowPath> getAllFlowPaths() {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();