Devices REST API
diff --git a/src/main/java/net/floodlightcontroller/core/INetMapTopologyObjects.java b/src/main/java/net/floodlightcontroller/core/INetMapTopologyObjects.java
index 1cf6f7b..4af1deb 100644
--- a/src/main/java/net/floodlightcontroller/core/INetMapTopologyObjects.java
+++ b/src/main/java/net/floodlightcontroller/core/INetMapTopologyObjects.java
@@ -74,7 +74,8 @@
@Incidence(label="on",direction = Direction.IN)
public ISwitchObject getSwitch();
- @JsonIgnore
+
+ @JsonProperty("devices")
@Adjacency(label="host")
public Iterable<IDeviceObject> getDevices();
@@ -119,8 +120,16 @@
@GremlinGroovy("_().in('host').in('on')")
public Iterable<ISwitchObject> getSwitch();
+/* @JsonProperty("dpid")
+ @GremlinGroovy("_().in('host').in('on').next().getProperty('dpid')")
+ public Iterable<String> getSwitchDPID();
+
+ @JsonProperty("number")
+ @GremlinGroovy("_().in('host').transform{it.number}")
+ public Iterable<Short> getPortNumber();
+
@JsonProperty("AttachmentPoint")
@GremlinGroovy("_().in('host').in('on').path(){it.number}{it.dpid}")
- public List<SwitchPort> getAttachmentPoints();
+ public Iterable<SwitchPort> getAttachmentPoints();*/
}
}
diff --git a/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java b/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java
index a3c5c01..c110651 100644
--- a/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java
+++ b/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java
@@ -19,6 +19,7 @@
import net.floodlightcontroller.core.module.ModuleLoaderResource;
import net.floodlightcontroller.linkdiscovery.web.TopoLinksResource;
+import net.floodlightcontroller.devicemanager.web.TopoDevicesResource;
import net.floodlightcontroller.restserver.RestletRoutable;
import org.restlet.Context;
@@ -63,6 +64,7 @@
router.attach("/system/uptime/json", SystemUptimeResource.class);
router.attach("/topology/switches/{filter}/json", TopoSwitchesResource.class);
router.attach("/topology/links/json", TopoLinksResource.class);
+ router.attach("/topology/devices/json", TopoDevicesResource.class);
return router;
}
}
diff --git a/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceStorageImpl.java b/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceStorageImpl.java
index cfbbb41..64c12dc 100644
--- a/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceStorageImpl.java
+++ b/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceStorageImpl.java
@@ -9,7 +9,6 @@
import com.thinkaurelius.titan.core.TitanException;
import net.floodlightcontroller.core.INetMapTopologyObjects.IDeviceObject;
import net.floodlightcontroller.core.INetMapTopologyObjects.IPortObject;
-import net.floodlightcontroller.core.INetMapTopologyService.ITopoSwitchService;
import net.floodlightcontroller.core.internal.SwitchStorageImpl;
import net.floodlightcontroller.devicemanager.IDevice;
import net.floodlightcontroller.devicemanager.IDeviceStorage;
@@ -19,10 +18,8 @@
public class DeviceStorageImpl implements IDeviceStorage {
-// public TitanGraph graph;
public GraphDBConnection conn;
protected static Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
- public ITopoSwitchService svc;
@Override
public void init(String conf) {
@@ -91,8 +88,7 @@
@Override
public IDeviceObject getDeviceByMac(String mac) {
-
- return null;
+ return conn.utils().searchDevice(conn, mac);
}
@Override
diff --git a/src/main/java/net/floodlightcontroller/devicemanager/web/TopoDevicesResource.java b/src/main/java/net/floodlightcontroller/devicemanager/web/TopoDevicesResource.java
new file mode 100644
index 0000000..db7059f
--- /dev/null
+++ b/src/main/java/net/floodlightcontroller/devicemanager/web/TopoDevicesResource.java
@@ -0,0 +1,22 @@
+package net.floodlightcontroller.devicemanager.web;
+
+import java.util.Iterator;
+
+import net.floodlightcontroller.core.INetMapTopologyObjects.IDeviceObject;
+import net.onrc.onos.util.GraphDBConnection;
+
+import org.restlet.resource.Get;
+import org.restlet.resource.ServerResource;
+
+public class TopoDevicesResource extends ServerResource {
+
+ @Get("json")
+ public Iterator<IDeviceObject> retrieve() {
+
+ GraphDBConnection conn = GraphDBConnection.getInstance("");
+
+ return conn.utils().getDevices(conn).iterator();
+
+ }
+
+}
diff --git a/src/main/java/net/onrc/onos/util/GraphDBConnection.java b/src/main/java/net/onrc/onos/util/GraphDBConnection.java
index 7c1ea2a..a2a8689 100644
--- a/src/main/java/net/onrc/onos/util/GraphDBConnection.java
+++ b/src/main/java/net/onrc/onos/util/GraphDBConnection.java
@@ -24,7 +24,7 @@
/* Static 'instance' method */
public static GraphDBConnection getInstance(String conf) {
- if (graph == null||graph.isOpen()) {
+ if (graph == null||graph.isOpen() == Boolean.FALSE) {
graph = TitanFactory.open(conf);
// FIXME: Creation on Indexes should be done only once
Set<String> s = graph.getIndexedKeys(Vertex.class);
diff --git a/src/main/java/net/onrc/onos/util/GraphDBUtils.java b/src/main/java/net/onrc/onos/util/GraphDBUtils.java
index 8bb83ea..d01de21 100644
--- a/src/main/java/net/onrc/onos/util/GraphDBUtils.java
+++ b/src/main/java/net/onrc/onos/util/GraphDBUtils.java
@@ -1,7 +1,6 @@
package net.onrc.onos.util;
import com.thinkaurelius.titan.core.TitanGraph;
-import com.thinkaurelius.titan.graphdb.transaction.VertexIterable;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.frames.FramedGraph;
import com.tinkerpop.frames.FramedVertexIterable;
@@ -10,7 +9,6 @@
import net.floodlightcontroller.core.INetMapTopologyObjects.IDeviceObject;
import net.floodlightcontroller.core.INetMapTopologyObjects.IPortObject;
import net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject;
-import net.floodlightcontroller.routing.Link;
public class GraphDBUtils implements IDBUtils {
@@ -56,4 +54,10 @@
fg.removeVertex(dev.asVertex());
}
+ @Override
+ public Iterable<IDeviceObject> getDevices(GraphDBConnection conn) {
+ FramedGraph<TitanGraph> fg = conn.getFramedGraph();
+ return fg.getVertices("type","device",IDeviceObject.class);
+ }
+
}
diff --git a/src/main/java/net/onrc/onos/util/IDBUtils.java b/src/main/java/net/onrc/onos/util/IDBUtils.java
index 52dbc70..a27a261 100644
--- a/src/main/java/net/onrc/onos/util/IDBUtils.java
+++ b/src/main/java/net/onrc/onos/util/IDBUtils.java
@@ -10,4 +10,5 @@
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);
}