Skip to content
Snippets Groups Projects
Commit d54a1a56 authored by Alex Reimers's avatar Alex Reimers
Browse files

Fix links REST API.

parent b0a574fc
No related branches found
No related tags found
No related merge requests found
......@@ -103,6 +103,29 @@ public interface ILinkDiscovery {
};
public enum LinkType {
INVALID_LINK, DIRECT_LINK, MULTIHOP_LINK, TUNNEL
INVALID_LINK {
@Override
public String toString() {
return "invalid";
}
},
DIRECT_LINK{
@Override
public String toString() {
return "internal";
}
},
MULTIHOP_LINK {
@Override
public String toString() {
return "external";
}
},
TUNNEL {
@Override
public String toString() {
return "tunnel";
}
}
};
}
package net.floodlightcontroller.linkdiscovery.web;
import java.io.IOException;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.openflow.util.HexString;
import net.floodlightcontroller.linkdiscovery.ILinkDiscovery.LinkType;
import net.floodlightcontroller.routing.Link;
/**
* This class is both the datastructure and the serializer
* for a link with the corresponding type of link.
* @author alexreimers
*/
@JsonSerialize(using=LinkWithType.class)
public class LinkWithType extends JsonSerializer<LinkWithType> {
public long srcSwDpid;
public short srcPort;
public long dstSwDpid;
public short dstPort;
public LinkType type;
// Do NOT delete this, it's required for the serializer
public LinkWithType() {}
public LinkWithType(Link link, LinkType type) {
this.srcSwDpid = link.getSrc();
this.srcPort = link.getSrcPort();
this.dstSwDpid = link.getDst();
this.dstPort = link.getDstPort();
this.type = type;
}
@Override
public void serialize(LinkWithType lwt, JsonGenerator jgen, SerializerProvider arg2)
throws IOException, JsonProcessingException {
// You ****MUST*** use lwt for the fields as it's actually a different object.
jgen.writeStartObject();
jgen.writeStringField("src-switch", HexString.toHexString(lwt.srcSwDpid));
jgen.writeNumberField("src-port", lwt.srcPort);
jgen.writeStringField("dst-switch", HexString.toHexString(lwt.dstSwDpid));
jgen.writeNumberField("dst-port", lwt.dstPort);
jgen.writeStringField("type", lwt.type.toString());
jgen.writeEndObject();
}
@Override
public Class<LinkWithType> handledType() {
return LinkWithType.class;
}
}
\ No newline at end of file
......@@ -5,7 +5,6 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import net.floodlightcontroller.linkdiscovery.ILinkDiscovery.LinkType;
import net.floodlightcontroller.linkdiscovery.ILinkDiscoveryService;
import net.floodlightcontroller.linkdiscovery.LinkInfo;
import net.floodlightcontroller.routing.Link;
......@@ -15,26 +14,8 @@ import org.restlet.resource.ServerResource;
public class LinksResource extends ServerResource {
public class LinkWithType {
long src;
short srcPort;
long dst;
short dstPort;
String type;
public LinkWithType(Link link, String type) {
this.src = link.getSrc();
this.srcPort = link.getSrcPort();
this.dst = link.getDst();
this.dstPort = link.getDstPort();
this.type = type;
}
};
@Get("json")
public Set<LinkWithType> retrieve() {
String str;
ILinkDiscoveryService ld = (ILinkDiscoveryService)getContext().getAttributes().
get(ILinkDiscoveryService.class.getCanonicalName());
Map<Link, LinkInfo> links = new HashMap<Link, LinkInfo>();
......@@ -44,17 +25,7 @@ public class LinksResource extends ServerResource {
links.putAll(ld.getLinks());
for (Link link: links.keySet()) {
LinkInfo info = links.get(link);
LinkType type = ld.getLinkType(info);
if (type == LinkType.DIRECT_LINK)
str = "internal";
else if (type == LinkType.MULTIHOP_LINK)
str = "external";
else if (type == LinkType.TUNNEL)
str = "tunnel";
else str = "invalid";
LinkWithType lwt = new LinkWithType(link, str);
LinkWithType lwt = new LinkWithType(link, ld.getLinkType(info));
returnLinkSet.add(lwt);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment