Skip to content
Snippets Groups Projects
Commit e51dede7 authored by abat's avatar abat
Browse files

Merge into master from pull request #196:

making it possible to get LinkType information both from LinkInfo.getLin... (https://github.com/floodlight/floodlight/pull/196)
parents cf9ff7fb abc02208
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,9 @@ public class LinkTupleSerializer extends JsonSerializer<LinkTuple> {
jGen.writeStringField("dst-switch", HexString.toHexString(linkTuple.getDst().getSw().getId()));
jGen.writeNumberField("src-port", linkTuple.getSrc().getPort());
jGen.writeStringField("src-switch", HexString.toHexString(linkTuple.getSrc().getSw().getId()));
if (linkTuple.getType() != null) {
jGen.writeStringField("type", linkTuple.getType().toString());
}
jGen.writeEndObject();
}
......
......@@ -92,6 +92,15 @@ public class LinkInfo {
public void setDstPortState(int dstPortState) {
this.dstPortState = dstPortState;
}
public static ILinkDiscovery.LinkType getLinkType(LinkTuple lt, LinkInfo info) {
if (info.getUnicastValidTime() != null) {
return ILinkDiscovery.LinkType.DIRECT_LINK;
} else if (info.getMulticastValidTime() != null) {
return ILinkDiscovery.LinkType.MULTIHOP_LINK;
}
return ILinkDiscovery.LinkType.INVALID_LINK;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
......
......@@ -21,6 +21,7 @@ import org.codehaus.jackson.map.annotate.JsonSerialize;
import net.floodlightcontroller.core.IOFSwitch;
import net.floodlightcontroller.core.web.serializers.LinkTupleSerializer;
import net.floodlightcontroller.linkdiscovery.ILinkDiscovery.LinkType;
/**
*
......@@ -31,6 +32,7 @@ import net.floodlightcontroller.core.web.serializers.LinkTupleSerializer;
public class LinkTuple {
protected SwitchPortTuple src;
protected SwitchPortTuple dst;
protected LinkType type = null;
/**
* @param src
......@@ -56,6 +58,22 @@ public class LinkTuple {
public LinkTuple(IOFSwitch src, Integer srcPort, IOFSwitch dst, Integer dstPort) {
this(src, srcPort.shortValue(), dst, dstPort.shortValue());
}
/**
* Set the LinkType, not done by default used primarily for the REST API
* @param t
*/
public void setType(LinkType t) {
this.type = t;
}
/**
* Gets the LinkType, used by the JSON serializer for the REST API
* @return the LinkType
*/
public LinkType getType() {
return type;
}
/**
* @return the src
......
......@@ -563,15 +563,6 @@ public class LinkDiscoveryManager
return Command.CONTINUE;
}
protected ILinkDiscovery.LinkType getLinkType(LinkTuple lt, LinkInfo info) {
if (info.getUnicastValidTime() != null) {
return ILinkDiscovery.LinkType.DIRECT_LINK;
} else if (info.getMulticastValidTime() != null) {
return ILinkDiscovery.LinkType.MULTIHOP_LINK;
}
return ILinkDiscovery.LinkType.INVALID_LINK;
}
protected void addOrUpdateLink(LinkTuple lt, LinkInfo newLinkInfo) {
lock.writeLock().lock();
try {
......@@ -621,7 +612,7 @@ public class LinkDiscoveryManager
lt.getSrc().getPort(),
lt.getDst().getPort(),
newLinkInfo.getSrcPortState(), newLinkInfo.getDstPortState(),
getLinkType(lt, newLinkInfo),
LinkInfo.getLinkType(lt, newLinkInfo),
EvAction.LINK_ADDED, "LLDP Recvd");
} else {
// Since the link info is already there, we need to
......@@ -677,14 +668,14 @@ public class LinkDiscoveryManager
lt.getSrc().getPort(),
lt.getDst().getPort(),
newLinkInfo.getSrcPortState(), newLinkInfo.getDstPortState(),
getLinkType(lt, newLinkInfo),
LinkInfo.getLinkType(lt, newLinkInfo),
EvAction.LINK_PORT_STATE_UPDATED,
"LLDP Recvd");
}
}
if (linkChanged) {
updates.add(new LDUpdate(lt, newLinkInfo.getSrcPortState(), newLinkInfo.getDstPortState(), getLinkType(lt, newLinkInfo), updateOperation));
updates.add(new LDUpdate(lt, newLinkInfo.getSrcPortState(), newLinkInfo.getDstPortState(), LinkInfo.getLinkType(lt, newLinkInfo), updateOperation));
}
} finally {
lock.writeLock().unlock();
......@@ -818,7 +809,7 @@ public class LinkDiscoveryManager
// send an LDUpdate.
updates.add(new LDUpdate(lt, linkInfo.getSrcPortState(),
linkInfo.getDstPortState(),
getLinkType(lt, linkInfo),
LinkInfo.getLinkType(lt, linkInfo),
UpdateOperation.ADD_OR_UPDATE));
writeLink(lt, linkInfo);
linkInfoChanged = true;
......@@ -941,7 +932,7 @@ public class LinkDiscoveryManager
} else if (linkChanged) {
updates.add(new LDUpdate(lt, info.getSrcPortState(),
info.getDstPortState(),
getLinkType(lt, info),
LinkInfo.getLinkType(lt, info),
UpdateOperation.ADD_OR_UPDATE));
}
}
......@@ -1078,7 +1069,7 @@ public class LinkDiscoveryManager
rowValues.put(LINK_SRC_SWITCH, srcDpid);
rowValues.put(LINK_SRC_PORT, lt.getSrc().getPort());
LinkType type = (this.getLinkType(lt, linkInfo));
LinkType type = (LinkInfo.getLinkType(lt, linkInfo));
if (type == LinkType.DIRECT_LINK)
rowValues.put(LINK_TYPE, "internal");
else if (type == LinkType.MULTIHOP_LINK)
......
......@@ -4,6 +4,7 @@ import java.util.HashSet;
import java.util.Set;
import net.floodlightcontroller.linkdiscovery.ILinkDiscoveryService;
import net.floodlightcontroller.linkdiscovery.LinkInfo;
import net.floodlightcontroller.linkdiscovery.LinkTuple;
import org.restlet.resource.Get;
......@@ -17,7 +18,12 @@ public class LinksResource extends ServerResource {
Set <LinkTuple> links = new HashSet<LinkTuple>();
if (topo != null) {
for (Set<LinkTuple> linkSet : topo.getSwitchLinks().values()) {
links.addAll(linkSet);
for (LinkTuple lt : linkSet) {
LinkInfo info = topo.getLinkInfo(lt.getSrc(), true);
LinkTuple withType = new LinkTuple(lt.getSrc(), lt.getDst());
withType.setType(LinkInfo.getLinkType(lt, info));
links.add(withType);
}
}
}
return links;
......
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