Single Graph handle across all controller
diff --git a/src/main/java/net/floodlightcontroller/core/INetMapTopologyObjects.java b/src/main/java/net/floodlightcontroller/core/INetMapTopologyObjects.java
index 73b21fe..4a03327 100644
--- a/src/main/java/net/floodlightcontroller/core/INetMapTopologyObjects.java
+++ b/src/main/java/net/floodlightcontroller/core/INetMapTopologyObjects.java
@@ -44,10 +44,11 @@
@JsonProperty("ports")
@Adjacency(label="on")
public Iterable<IPortObject> getPorts();
-
- @JsonIgnore
- @GremlinGroovy("_().out('on').has('number',port_num)")
- public IPortObject getPort(final short port_num);
+
+// Requires Frames 2.3.0
+// @JsonIgnore
+// @GremlinGroovy("_().out('on').has('number',port_num)")
+// public IPortObject getPort(@GremlinParam("port_num") final short port_num);
@Adjacency(label="on")
public void addPort(final IPortObject port);
diff --git a/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImpl.java b/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImpl.java
index f040881..b8197b7 100644
--- a/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImpl.java
+++ b/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImpl.java
@@ -48,7 +48,7 @@
log.info("SwitchStorage:setStatus dpid:{} state: {} done", dpid, state);
} else {
conn.endTx(Transaction.ROLLBACK);
- log.info("SwitchStorage:setStatus dpid:{} state: {} failed", dpid, state);
+ log.info("SwitchStorage:setStatus dpid:{} state: {} failed: switch not found", dpid, state);
}
}
@@ -83,9 +83,12 @@
conn.endTx(Transaction.COMMIT);
}
+ } else {
+ log.error("SwitchStorage:addPort dpid:{} port:{} : failed switch does not exist", dpid, port.getPortNumber());
}
} catch (Exception e) {
// TODO: handle exceptions
+ e.printStackTrace();
conn.endTx(Transaction.ROLLBACK);
log.error("SwitchStorage:addPort dpid:{} port:{} failed", dpid, port.getPortNumber());
}
@@ -115,32 +118,37 @@
log.info("SwitchStorage:addSwitch(): dpid {} ", dpid);
- try {
- ISwitchObject sw = conn.utils().searchSwitch(conn, dpid);
- if (sw != null) {
- /*
- * Do nothing or throw exception?
- */
-
- log.info("SwitchStorage:addSwitch dpid:{} already exists", dpid);
- sw.setState(SwitchState.ACTIVE.toString());
- conn.endTx(Transaction.COMMIT);
- } else {
- sw = conn.utils().newSwitch(conn);
+ try {
+ ISwitchObject sw = conn.utils().searchSwitch(conn, dpid);
+ if (sw != null) {
+ /*
+ * Do nothing or throw exception?
+ */
- sw.setType("switch");
- sw.setDPID(dpid);
- sw.setState(SwitchState.ACTIVE.toString());
- conn.endTx(Transaction.COMMIT);
- log.info("SwitchStorage:addSwitch dpid:{} added", dpid);
- }
- } catch (Exception e) {
- /*
- * retry?
- */
- conn.endTx(Transaction.ROLLBACK);
- log.info("SwitchStorage:addSwitch dpid:{} failed", dpid);
- }
+ log.info("SwitchStorage:addSwitch dpid:{} already exists", dpid);
+ sw.setState(SwitchState.ACTIVE.toString());
+ conn.endTx(Transaction.COMMIT);
+ } else {
+ sw = conn.utils().newSwitch(conn);
+
+ if (sw != null) {
+ sw.setType("switch");
+ sw.setDPID(dpid);
+ sw.setState(SwitchState.ACTIVE.toString());
+ conn.endTx(Transaction.COMMIT);
+ log.info("SwitchStorage:addSwitch dpid:{} added", dpid);
+ } else {
+ log.error("switchStorage:addSwitch dpid:{} failed -> newSwitch failed", dpid);
+ }
+ }
+ } catch (Exception e) {
+ /*
+ * retry?
+ */
+ e.printStackTrace();
+ conn.endTx(Transaction.ROLLBACK);
+ log.info("SwitchStorage:addSwitch dpid:{} failed", dpid);
+ }
}
@@ -160,6 +168,7 @@
}
} catch (Exception e) {
// TODO: handle exceptions
+ e.printStackTrace();
conn.endTx(Transaction.ROLLBACK);
log.error("SwitchStorage:deleteSwitch {} failed", dpid);
}
diff --git a/src/main/java/net/floodlightcontroller/core/internal/TopoSwitchServiceImpl.java b/src/main/java/net/floodlightcontroller/core/internal/TopoSwitchServiceImpl.java
index 9f63fd7..931802e 100644
--- a/src/main/java/net/floodlightcontroller/core/internal/TopoSwitchServiceImpl.java
+++ b/src/main/java/net/floodlightcontroller/core/internal/TopoSwitchServiceImpl.java
@@ -1,14 +1,14 @@
package net.floodlightcontroller.core.internal;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import net.floodlightcontroller.core.INetMapTopologyObjects.IPortObject;
import net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject;
import net.floodlightcontroller.core.INetMapTopologyService.ITopoSwitchService;
import net.onrc.onos.util.GraphDBConnection;
import net.onrc.onos.util.GraphDBConnection.Transaction;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class TopoSwitchServiceImpl implements ITopoSwitchService {
private GraphDBConnection conn;
@@ -21,7 +21,7 @@
@Override
public void close() {
- conn.endTx(Transaction.COMMIT);
+
conn.close();
}
diff --git a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImpl.java b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImpl.java
index 0ab52e2..d62d65b 100644
--- a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImpl.java
+++ b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImpl.java
@@ -1,9 +1,7 @@
package net.floodlightcontroller.linkdiscovery.internal;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
-import java.util.Set;
import net.floodlightcontroller.core.INetMapTopologyObjects.IPortObject;
import net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject;
@@ -13,7 +11,6 @@
import net.floodlightcontroller.linkdiscovery.LinkInfo;
import net.floodlightcontroller.routing.Link;
import net.onrc.onos.util.GraphDBConnection;
-import net.onrc.onos.util.GraphDBConnection.GenerateEvent;
import net.onrc.onos.util.GraphDBConnection.Transaction;
import org.openflow.util.HexString;
@@ -21,20 +18,15 @@
import org.slf4j.LoggerFactory;
import com.thinkaurelius.titan.core.TitanException;
-import com.thinkaurelius.titan.core.TitanFactory;
-import com.thinkaurelius.titan.core.TitanGraph;
import com.tinkerpop.blueprints.Direction;
-import com.tinkerpop.blueprints.TransactionalGraph.Conclusion;
-import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.Edge;
-import com.tinkerpop.blueprints.util.wrappers.event.EventGraph;
-import com.tinkerpop.blueprints.util.wrappers.event.EventTransactionalGraph;
+import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.gremlin.java.GremlinPipeline;
import com.tinkerpop.pipes.PipeFunction;
import com.tinkerpop.pipes.transform.PathPipe;
public class LinkStorageImpl implements ILinkStorage {
- public TitanGraph graph;
+
protected static Logger log = LoggerFactory.getLogger(LinkStorageImpl.class);
protected String conf;
@@ -63,18 +55,6 @@
break;
}
}
-
- private Vertex getPortVertex(String dpid, short port) {
- Vertex vsw, vport = null;
- if ((vsw = graph.getVertices("dpid", dpid).iterator().next()) != null) {
- GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>();
- pipe.start(vsw).out("on").has("number", port);
- if (pipe.hasNext()) {
- vport = pipe.next();
- }
- }
- return vport;
- }
public void addOrUpdateLink(Link lt, LinkInfo linkinfo, DM_OPERATION op) {
GraphDBConnection conn = GraphDBConnection.getInstance(this.conf);
@@ -96,9 +76,9 @@
if (vportSrc != null && vportDst != null) {
// check if the link exists
- List<IPortObject> currLinks = new ArrayList<IPortObject>();
- Iterable<IPortObject> currPorts = vportSrc.getLinkedPorts();
+ Iterable<IPortObject> currPorts = vportSrc.getLinkedPorts();
+ List<IPortObject> currLinks = new ArrayList<IPortObject>();
for (IPortObject V : currPorts) {
currLinks.add(V);
}
@@ -110,20 +90,21 @@
new Object[]{op, lt, vportSrc, vportDst});
}
} else {
- conn.getFramedGraph().addEdge(null, vportSrc.asVertex(), vportDst.asVertex(), "link");
+ vportSrc.setLinkPort(vportDst);
+
conn.endTx(Transaction.COMMIT);
log.debug("addOrUpdateLink(): link added {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst});
}
} else {
log.error("addOrUpdateLink(): failed invalid vertices {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst});
- conn.endTx(Transaction.ROLLBACK);
+ // conn.endTx(Transaction.ROLLBACK);
}
} catch (TitanException e) {
/*
* retry till we succeed?
*/
- log.error("addOrUpdateLink(): titan exception {} {} {}", new Object[]{op, lt, e.toString()});
e.printStackTrace();
+ log.error("addOrUpdateLink(): titan exception {} {} {}", new Object[]{op, lt, e.toString()});
}
}
@@ -155,7 +136,6 @@
port = lt.getDstPort();
vportDst = conn.utils().searchPort(conn, dpid, port);
// FIXME: This needs to remove all edges
- // FIXME: Events will only be generated on singleton graph object (GraphDBConnection)
if (vportSrc != null && vportDst != null) {
@@ -174,7 +154,7 @@
} else {
log.error("deleteLink(): failed invalid vertices {} src {} dst {}", new Object[]{lt, vportSrc, vportDst});
- conn.endTx(Transaction.ROLLBACK);
+// conn.endTx(Transaction.ROLLBACK);
}
} catch (TitanException e) {
@@ -189,13 +169,15 @@
// TODO: Fix me
@Override
public List<Link> getLinks(Long dpid, short port) {
- Vertex vportSrc, vportDst;
+ GraphDBConnection conn = GraphDBConnection.getInstance(this.conf);
+ IPortObject vportSrc, vportDst;
List<Link> links = null;
Link lt;
- vportSrc = getPortVertex(HexString.toHexString(dpid), port);
+ vportSrc = conn.utils().searchPort(conn, HexString.toHexString(dpid), port);
if (vportSrc != null) {
- for (Edge e : vportSrc.getEdges(Direction.OUT)) {
+
+ for (Edge e : vportSrc.asVertex().getEdges(Direction.OUT)) {
if (e.getLabel().equals("link")) {
break;
}
@@ -209,18 +191,7 @@
//TODO extract the DB location from properties
this.conf = conf;
- graph = TitanFactory.open(this.conf);
-
- // FIXME: These keys are not needed for Links but we better create it before using it as per titan
- Set<String> s = graph.getIndexedKeys(Vertex.class);
- if (!s.contains("dpid")) {
- graph.createKeyIndex("dpid", Vertex.class);
- graph.stopTransaction(Conclusion.SUCCESS);
- }
- if (!s.contains("type")) {
- graph.createKeyIndex("type", Vertex.class);
- graph.stopTransaction(Conclusion.SUCCESS);
- }
+
}
@Override
@@ -237,9 +208,9 @@
public List<Link> getActiveLinks() {
- ITopoSwitchService swService = new TopoSwitchServiceImpl();
+ GraphDBConnection conn = GraphDBConnection.getInstance(this.conf);
- Iterable<ISwitchObject> switches = swService.getActiveSwitches();
+ Iterable<ISwitchObject> switches = conn.utils().getActiveSwitches(conn);
List<Link> links = new ArrayList<Link>();
for (ISwitchObject sw : switches) {
@@ -292,7 +263,7 @@
@Override
public void close() {
// TODO Auto-generated method stub
- graph.shutdown();
+// graph.shutdown();
}
diff --git a/src/main/java/net/floodlightcontroller/onoslistener/OnosPublisher.java b/src/main/java/net/floodlightcontroller/onoslistener/OnosPublisher.java
index 6d8087b..e07196f 100644
--- a/src/main/java/net/floodlightcontroller/onoslistener/OnosPublisher.java
+++ b/src/main/java/net/floodlightcontroller/onoslistener/OnosPublisher.java
@@ -51,7 +51,7 @@
protected static final String CleanupEnabled = "EnableCleanup";
protected IThreadPoolService threadPool;
- protected final int CLEANUP_TASK_INTERVAL = 10; // 10 sec
+ protected final int CLEANUP_TASK_INTERVAL = 60; // 1 min
protected SingletonTask cleanupTask;
/**
diff --git a/src/main/java/net/onrc/onos/util/GraphDBConnection.java b/src/main/java/net/onrc/onos/util/GraphDBConnection.java
index 84a0501..4d23b0d 100644
--- a/src/main/java/net/onrc/onos/util/GraphDBConnection.java
+++ b/src/main/java/net/onrc/onos/util/GraphDBConnection.java
@@ -87,6 +87,7 @@
FramedGraph<TitanGraph> fg = new FramedGraph<TitanGraph>(graph);
return fg;
} else {
+ log.error("new FramedGraph failed");
return null;
}
}
@@ -118,16 +119,16 @@
public void endTx(Transaction tx) {
try {
- switch (tx) {
+ switch (tx) {
case COMMIT:
graph.stopTransaction(Conclusion.SUCCESS);
case ROLLBACK:
graph.stopTransaction(Conclusion.FAILURE);
}
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ log.error("{}",e.toString());
+ }
}
public void endTx(TransactionHandle tr, Transaction tx) {
@@ -167,6 +168,7 @@
}
public void close() {
+ endTx(Transaction.COMMIT);
// graph.shutdown();
}
diff --git a/src/main/java/net/onrc/onos/util/GraphDBUtils.java b/src/main/java/net/onrc/onos/util/GraphDBUtils.java
index eea57fd..3409f59 100644
--- a/src/main/java/net/onrc/onos/util/GraphDBUtils.java
+++ b/src/main/java/net/onrc/onos/util/GraphDBUtils.java
@@ -38,7 +38,7 @@
// TODO Auto-generated method stub
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
- return fg.getVertices("dpid",dpid).iterator().hasNext() ?
+ return (fg != null && fg.getVertices("dpid",dpid).iterator().hasNext()) ?
fg.getVertices("dpid",dpid,ISwitchObject.class).iterator().next() : null;
}
@@ -47,7 +47,7 @@
public IDeviceObject searchDevice(GraphDBConnection conn, String macAddr) {
// TODO Auto-generated method stub
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
- return fg.getVertices("dl_address",macAddr).iterator().hasNext() ? fg.getVertices("dl_address",macAddr,
+ return (fg != null && fg.getVertices("dl_address",macAddr).iterator().hasNext()) ? fg.getVertices("dl_address",macAddr,
IDeviceObject.class).iterator().next() : null;
}
@@ -58,6 +58,9 @@
// if (sw != null) {
//
// IPortObject port = null;
+//
+ // Requires Frames 2.3.0
+//
// try {
// port = sw.getPort(number);
// } catch (Exception e) {
@@ -67,12 +70,15 @@
//
// return port;
// }
-// return null;
- GremlinPipeline<Vertex, IPortObject> pipe = new GremlinPipeline<Vertex, IPortObject>();
- pipe.start(sw.asVertex());
- pipe.out("on").has("number", number);
- FramedVertexIterable<IPortObject> r = new FramedVertexIterable<IPortObject>(conn.getFramedGraph(), (Iterable) pipe, IPortObject.class);
- return r.iterator().hasNext() ? r.iterator().next() : null;
+
+ if (sw != null) {
+ GremlinPipeline<Vertex, IPortObject> pipe = new GremlinPipeline<Vertex, IPortObject>();
+ pipe.start(sw.asVertex());
+ pipe.out("on").has("number", number);
+ FramedVertexIterable<IPortObject> r = new FramedVertexIterable<IPortObject>(conn.getFramedGraph(), (Iterable) pipe, IPortObject.class);
+ return r != null && r.iterator().hasNext() ? r.iterator().next() : null;
+ }
+ return null;
}
@Override
@@ -93,19 +99,19 @@
public void removePort(GraphDBConnection conn, IPortObject port) {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
// EventGraph<TitanGraph> eg = conn.getEventGraph();
- fg.removeVertex(port.asVertex());
+ if (fg != null) fg.removeVertex(port.asVertex());
}
@Override
public void removeDevice(GraphDBConnection conn, IDeviceObject dev) {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
- fg.removeVertex(dev.asVertex());
+ if (fg != null) fg.removeVertex(dev.asVertex());
}
@Override
public Iterable<IDeviceObject> getDevices(GraphDBConnection conn) {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
- return fg.getVertices("type","device",IDeviceObject.class);
+ return fg != null ? fg.getVertices("type","device",IDeviceObject.class) : null;
}
@Override