Added Link REST and service for active links
diff --git a/src/main/java/net/floodlightcontroller/core/ISwitchStorage.java b/src/main/java/net/floodlightcontroller/core/ISwitchStorage.java
index 28e6a5d..5e81000 100644
--- a/src/main/java/net/floodlightcontroller/core/ISwitchStorage.java
+++ b/src/main/java/net/floodlightcontroller/core/ISwitchStorage.java
@@ -1,20 +1,15 @@
package net.floodlightcontroller.core;
import java.util.Collection;
-import java.util.List;
-
-import org.codehaus.jackson.annotate.JsonAutoDetect;
-import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonProperty;
-import org.codehaus.jackson.map.annotate.JsonSerialize;
-import org.codehaus.jackson.map.ser.StdSerializers;
import org.openflow.protocol.OFPhysicalPort;
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.frames.Adjacency;
import com.tinkerpop.frames.Incidence;
import com.tinkerpop.frames.Property;
+import com.tinkerpop.frames.VertexFrame;
public interface ISwitchStorage extends INetMapStorage {
@@ -23,7 +18,7 @@
ACTIVE
}
- public interface ISwitchObject {
+ public interface ISwitchObject extends VertexFrame{
@JsonProperty("dpid")
@Property("dpid")
@@ -42,7 +37,7 @@
public Iterable<IPortObject> getPorts();
}
- public interface IPortObject {
+ public interface IPortObject extends VertexFrame{
@JsonProperty("state")
@Property("state")
@@ -63,6 +58,10 @@
@JsonIgnore
@Incidence(label="on",direction = Direction.IN)
public ISwitchObject getSwitch();
+
+// @JsonIgnore
+// @Adjacency(label="link")
+// public Iterable<ILinkObject> getLinks();
}
/*
* Update the switch details
diff --git a/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java b/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java
index bf5aaf7..5ffd9bc 100644
--- a/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java
+++ b/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java
@@ -48,7 +48,7 @@
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonSerialize;
-import org.codehaus.jackson.map.ser.ToStringSerializer;
+import org.codehaus.jackson.map.ser.std.ToStringSerializer;
import org.jboss.netty.channel.Channel;
import org.openflow.protocol.OFFeaturesReply;
import org.openflow.protocol.OFFeaturesRequest;
diff --git a/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImpl.java b/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImpl.java
index dbb985e..1e14b05 100644
--- a/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImpl.java
+++ b/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImpl.java
@@ -20,6 +20,8 @@
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.frames.FramedGraph;
+import com.tinkerpop.gremlin.java.GremlinPipeline;
+
import net.floodlightcontroller.core.ISwitchStorage;
public class SwitchStorageImpl implements ISwitchStorage {
@@ -53,11 +55,11 @@
if ((sw = graph.getVertices("dpid",dpid).iterator().next()) != null) {
sw.setProperty("state",state.toString());
graph.stopTransaction(Conclusion.SUCCESS);
- log.info("SwitchStorage:setSTatus dpid:{} state: {} done", dpid, state);
+ log.info("SwitchStorage:setStatus dpid:{} state: {} done", dpid, state);
}
} catch (TitanException e) {
// TODO: handle exceptions
- log.info("SwitchStorage:setSTatus dpid:{} state: {} failed", dpid, state);
+ log.info("SwitchStorage:setStatus dpid:{} state: {} failed", dpid, state);
}
@@ -204,14 +206,14 @@
FramedGraph<TitanGraph> fg = new FramedGraph<TitanGraph>(graph);
Iterable<ISwitchObject> switches = fg.getVertices("type","switch",ISwitchObject.class);
List<ISwitchObject> activeSwitches = new ArrayList<ISwitchObject>();
-
+
for (ISwitchObject sw: switches) {
if(sw.getState().equals(SwitchState.ACTIVE.toString())) {
activeSwitches.add(sw);
}
}
-
- return activeSwitches;
+
+ return activeSwitches;
}
@Override
@@ -250,14 +252,14 @@
FramedGraph<TitanGraph> fg = new FramedGraph<TitanGraph>(graph);
Iterable<ISwitchObject> switches = fg.getVertices("type","switch",ISwitchObject.class);
- List<ISwitchObject> inActiveSwitches = new ArrayList<ISwitchObject>();
+ List<ISwitchObject> inactiveSwitches = new ArrayList<ISwitchObject>();
for (ISwitchObject sw: switches) {
if(sw.getState().equals(SwitchState.INACTIVE.toString())) {
- inActiveSwitches.add(sw);
+ inactiveSwitches.add(sw);
}
}
- return inActiveSwitches;
+ return inactiveSwitches;
}
diff --git a/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java b/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java
index 0c41259..a3c5c01 100644
--- a/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java
+++ b/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java
@@ -18,6 +18,7 @@
package net.floodlightcontroller.core.web;
import net.floodlightcontroller.core.module.ModuleLoaderResource;
+import net.floodlightcontroller.linkdiscovery.web.TopoLinksResource;
import net.floodlightcontroller.restserver.RestletRoutable;
import org.restlet.Context;
@@ -61,6 +62,7 @@
router.attach("/health/json", HealthCheckResource.class);
router.attach("/system/uptime/json", SystemUptimeResource.class);
router.attach("/topology/switches/{filter}/json", TopoSwitchesResource.class);
+ router.attach("/topology/links/json", TopoLinksResource.class);
return router;
}
}
diff --git a/src/main/java/net/floodlightcontroller/devicemanager/SwitchPort.java b/src/main/java/net/floodlightcontroller/devicemanager/SwitchPort.java
index 7426163..725d699 100644
--- a/src/main/java/net/floodlightcontroller/devicemanager/SwitchPort.java
+++ b/src/main/java/net/floodlightcontroller/devicemanager/SwitchPort.java
@@ -20,7 +20,7 @@
import net.floodlightcontroller.core.web.serializers.DPIDSerializer;
import org.codehaus.jackson.map.annotate.JsonSerialize;
-import org.codehaus.jackson.map.ser.ToStringSerializer;
+import org.codehaus.jackson.map.ser.std.ToStringSerializer;
/**
* A simple switch DPID/port pair
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();
+
+ }
+
+}
diff --git a/src/main/java/net/floodlightcontroller/routing/TopoRouteServiceImpl.java b/src/main/java/net/floodlightcontroller/routing/TopoRouteServiceImpl.java
new file mode 100644
index 0000000..42ce6a8
--- /dev/null
+++ b/src/main/java/net/floodlightcontroller/routing/TopoRouteServiceImpl.java
@@ -0,0 +1,23 @@
+package net.floodlightcontroller.routing;
+
+import java.util.List;
+
+import net.floodlightcontroller.core.INetMapTopologyService.ITopoRouteService;
+import net.floodlightcontroller.topology.NodePortTuple;
+
+public class TopoRouteServiceImpl implements ITopoRouteService {
+
+ @Override
+ public List<NodePortTuple> GetShortestPath(NodePortTuple src,
+ NodePortTuple dest) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Boolean RouteExists(NodePortTuple src, NodePortTuple dest) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}