Added Link REST and service for active links
diff --git a/src/main/java/net/floodlightcontroller/linkdiscovery/ILinkDiscovery.java b/src/main/java/net/floodlightcontroller/linkdiscovery/ILinkDiscovery.java
index f172f63..1efe015 100644
--- a/src/main/java/net/floodlightcontroller/linkdiscovery/ILinkDiscovery.java
+++ b/src/main/java/net/floodlightcontroller/linkdiscovery/ILinkDiscovery.java
@@ -1,7 +1,7 @@
package net.floodlightcontroller.linkdiscovery;
import org.codehaus.jackson.map.annotate.JsonSerialize;
-import org.codehaus.jackson.map.ser.ToStringSerializer;
+import org.codehaus.jackson.map.ser.std.ToStringSerializer;
import org.openflow.util.HexString;
public interface ILinkDiscovery {
diff --git a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImpl.java b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImpl.java
index 70d93c9..43c6c94 100644
--- a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImpl.java
+++ b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImpl.java
@@ -1,9 +1,13 @@
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.INetMapTopologyService.ITopoSwitchService;
+import net.floodlightcontroller.core.ISwitchStorage.ISwitchObject;
+import net.floodlightcontroller.core.internal.TopoSwitchServiceImpl;
import net.floodlightcontroller.linkdiscovery.ILinkStorage;
import net.floodlightcontroller.linkdiscovery.LinkInfo;
import net.floodlightcontroller.routing.Link;
@@ -20,6 +24,8 @@
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.Edge;
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;
@@ -214,9 +220,56 @@
}
public List<Link> getActiveLinks() {
- // TODO Auto-generated method stub
+
+ ITopoSwitchService swService = new TopoSwitchServiceImpl();
- return null;
+ Iterable<ISwitchObject> switches = swService.GetActiveSwitches();
+
+ List<Link> links = new ArrayList<Link>();
+ for (ISwitchObject sw : switches) {
+ GremlinPipeline<Vertex, Link> pipe = new GremlinPipeline<Vertex, Link>();
+ ExtractLink extractor = new ExtractLink();
+
+ pipe.start(sw.asVertex());
+ pipe.enablePath(true);
+ pipe.out("on").out("link").in("on").path().getCurrentPath();
+ pipe.step(extractor);
+
+ if (pipe.hasNext() ) {
+ Link l = pipe.next();
+ links.add(l);
+ }
+
+ }
+ return links;
}
+
+ static class ExtractLink implements PipeFunction<PathPipe<Vertex>, Link> {
+
+
+ @Override
+ public Link compute(PathPipe<Vertex> pipe ) {
+ // TODO Auto-generated method stub
+ long s_dpid = 0;
+ long d_dpid = 0;
+ short s_port = 0;
+ short d_port = 0;
+ List<Vertex> V = new ArrayList<Vertex>();
+ V = pipe.next();
+ Vertex src_sw = V.get(0);
+ Vertex dest_sw = V.get(3);
+ Vertex src_port = V.get(1);
+ Vertex dest_port = V.get(2);
+ s_dpid = HexString.toLong((String) src_sw.getProperty("dpid"));
+ d_dpid = HexString.toLong((String) dest_sw.getProperty("dpid"));
+ s_port = (Short) src_port.getProperty("number");
+ d_port = (Short) dest_port.getProperty("number");
+
+ Link l = new Link(s_dpid,s_port,d_dpid,d_port);
+
+ return l;
+ }
+ }
+
}
diff --git a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/TopoLinkServiceImpl.java b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/TopoLinkServiceImpl.java
new file mode 100644
index 0000000..b73224e
--- /dev/null
+++ b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/TopoLinkServiceImpl.java
@@ -0,0 +1,33 @@
+package net.floodlightcontroller.linkdiscovery.internal;
+
+import java.util.List;
+
+import net.floodlightcontroller.core.INetMapTopologyService.ITopoLinkService;
+import net.floodlightcontroller.routing.Link;
+
+public class TopoLinkServiceImpl implements ITopoLinkService {
+
+ ThreadLocal<LinkStorageImpl> store = new ThreadLocal<LinkStorageImpl>() {
+ @Override
+ protected LinkStorageImpl initialValue() {
+ LinkStorageImpl inStore = new LinkStorageImpl();
+ //TODO: Get the file path from global properties
+ inStore.init("/tmp/cassandra.titan");
+ return inStore;
+ }
+ };
+
+ LinkStorageImpl linkStore = store.get();
+ @Override
+ public List<Link> GetActiveLinks() {
+ // TODO Auto-generated method stub
+ return linkStore.getActiveLinks();
+ }
+
+ @Override
+ public List<Link> GetLinksOnSwitch(String dpid) {
+ // TODO Auto-generated method stub
+ return linkStore.getLinks(dpid);
+ }
+
+}
diff --git a/src/main/java/net/floodlightcontroller/linkdiscovery/web/TopoLinksResource.java b/src/main/java/net/floodlightcontroller/linkdiscovery/web/TopoLinksResource.java
new file mode 100644
index 0000000..323708e
--- /dev/null
+++ b/src/main/java/net/floodlightcontroller/linkdiscovery/web/TopoLinksResource.java
@@ -0,0 +1,20 @@
+package net.floodlightcontroller.linkdiscovery.web;
+
+import java.util.List;
+import net.floodlightcontroller.linkdiscovery.internal.TopoLinkServiceImpl;
+import net.floodlightcontroller.routing.Link;
+
+import org.restlet.resource.Get;
+import org.restlet.resource.ServerResource;
+
+public class TopoLinksResource extends ServerResource {
+
+ @Get("json")
+ public List<Link> retrieve() {
+ TopoLinkServiceImpl impl = new TopoLinkServiceImpl();
+
+ return impl.GetActiveLinks();
+
+ }
+
+}