Skip to content
Snippets Groups Projects
Commit 680ae322 authored by Srinivasan Ramasubramanian's avatar Srinivasan Ramasubramanian
Browse files

Merge pull request #224 from sriniram/master

Updates to link discovery manager.
parents 4cb3dea1 82cd9518
No related branches found
No related tags found
No related merge requests found
Showing
with 953 additions and 1051 deletions
package net.floodlightcontroller.core.web.serializers;
import java.io.IOException;
import net.floodlightcontroller.linkdiscovery.LinkTuple;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;
import org.openflow.util.HexString;
public class LinkTupleSerializer extends JsonSerializer<LinkTuple> {
/**
* Serializes the @LinkTuple object.
* @param linkTuple The LinkTuple to serialize
* @param jGen The JSON Generator to use
* @param serializer The Jackson serializer provider
*/
@Override
public void serialize(LinkTuple linkTuple, JsonGenerator jGen, SerializerProvider serializer) throws IOException, JsonProcessingException {
jGen.writeStartObject();
jGen.writeNumberField("dst-port", linkTuple.getDst().getPort());
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();
}
/**
* Tells SimpleModule that we are the serializer for @LinkTuple
*/
@Override
public Class<LinkTuple> handledType() {
return LinkTuple.class;
}
}
...@@ -29,25 +29,18 @@ public interface ILinkDiscovery { ...@@ -29,25 +29,18 @@ public interface ILinkDiscovery {
this.operation = operation; this.operation = operation;
} }
public LDUpdate(LinkTuple lt, int srcPortState,
int dstPortState, ILinkDiscovery.LinkType type, UpdateOperation operation) {
this(lt.getSrc().getSw().getId(), lt.getSrc().getPort(),
srcPortState, lt.getDst().getSw().getId(), lt.getDst().getPort(),
dstPortState, type, operation);
}
public LDUpdate(LDUpdate old) { public LDUpdate(LDUpdate old) {
this.src = old.src; this.src = old.src;
this.srcPort = old.srcPort; this.srcPort = old.srcPort;
this.srcPortState = old.srcPortState; this.srcPortState = old.srcPortState;
this.dst = old.dst; this.dst = old.dst;
this.dstPort = old.dstPort; this.dstPort = old.dstPort;
this.dstPortState = old.dstPortState; this.dstPortState = old.dstPortState;
this.srcType = old.srcType; this.srcType = old.srcType;
this.type = old.type; this.type = old.type;
this.operation = old.operation; this.operation = old.operation;
} }
// For updtedSwitch(sw) // For updtedSwitch(sw)
public LDUpdate(long switchId, SwitchType stype) { public LDUpdate(long switchId, SwitchType stype) {
this.operation = UpdateOperation.SWITCH_UPDATED; this.operation = UpdateOperation.SWITCH_UPDATED;
......
...@@ -17,78 +17,52 @@ ...@@ -17,78 +17,52 @@
package net.floodlightcontroller.linkdiscovery; package net.floodlightcontroller.linkdiscovery;
/**
*
*
* @author David Erickson (daviderickson@cs.stanford.edu)
*/
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import net.floodlightcontroller.core.IOFSwitch;
import net.floodlightcontroller.core.module.IFloodlightService; import net.floodlightcontroller.core.module.IFloodlightService;
import net.floodlightcontroller.routing.Link;
import net.floodlightcontroller.topology.NodePortTuple;
/**
*
*
* @author David Erickson (daviderickson@cs.stanford.edu)
*/
public interface ILinkDiscoveryService extends IFloodlightService {
/**
* Get the link that either sources from the port or terminates
* at the port. isSrcPort determines which of the two links is
* returned.
* @param idPort
* @param isSrcPort true for link that sources from idPort.
* @return linkTuple
*/
public LinkInfo getLinkInfo(SwitchPortTuple idPort, boolean isSrcPort);
public interface ILinkDiscoveryService extends IFloodlightService {
/** /**
* Get the link type of the link tuple based on link info. * Retrieves a map of all known link connections between OpenFlow switches
* @param linkTuple * and the associated info (valid time, port states) for the link.
* @param linkInfo
* @return linkType
*/ */
public ILinkDiscovery.LinkType getLinkType(LinkTuple lt, LinkInfo info); public Map<Link, LinkInfo> getLinks();
/** /**
* Retrieves a map of all known link connections between OpenFlow switches * Returns link type of a given link
* and the associated info (valid time, port states) for the link. * @param info
* @return * @return
*/ */
public Map<LinkTuple, LinkInfo> getLinks(); public ILinkDiscovery.LinkType getLinkType(LinkInfo info);
/** /**
* Returns an unmodifiable map from switch id to a set of all links with it * Returns an unmodifiable map from switch id to a set of all links with it
* as an endpoint. * as an endpoint.
*/ */
public Map<IOFSwitch, Set<LinkTuple>> getSwitchLinks(); public Map<Long, Set<Link>> getSwitchLinks();
/** /**
* Adds a listener to listen for ILinkDiscoveryService messages * Adds a listener to listen for ILinkDiscoveryService messages
* @param listener The listener that wants the notifications * @param listener The listener that wants the notifications
*/ */
public void addListener(ILinkDiscoveryListener listener); public void addListener(ILinkDiscoveryListener listener);
/** /**
* Retrieves a set of all switch ports on which lldps are suppressed. * Retrieves a set of all switch ports on which lldps are suppressed.
* @return
*/ */
public Set<SwitchPortTuple> getSuppressLLDPsInfo(); public Set<NodePortTuple> getSuppressLLDPsInfo();
/** /**
* Adds a switch port to suppress lldp set * Adds a switch port to suppress lldp set
* @param sw
* @param port
*/ */
public void AddToSuppressLLDPs(IOFSwitch sw, short port); public void AddToSuppressLLDPs(long sw, short port);
/** /**
* Removes a switch port from suppress lldp set * Removes a switch port from suppress lldp set
* @param sw
* @param port
*/ */
public void RemoveFromSuppressLLDPs(IOFSwitch sw, short port); public void RemoveFromSuppressLLDPs(long sw, short port);
} }
...@@ -15,24 +15,30 @@ ...@@ -15,24 +15,30 @@
package net.floodlightcontroller.linkdiscovery; package net.floodlightcontroller.linkdiscovery;
import net.floodlightcontroller.linkdiscovery.ILinkDiscovery.LinkType;
import org.openflow.protocol.OFPhysicalPort.OFPortState; import org.openflow.protocol.OFPhysicalPort.OFPortState;
public class LinkInfo { public class LinkInfo {
public enum PortBroadcastState {
PBS_BLOCK, public LinkInfo(Long firstSeenTime,
PBS_FORWARD, Long lastLldpReceivedTime,
}; Long lastBddpReceivedTime,
int srcPortState,
/** int dstPortState) {
* The term unicastValidTime may be slightly misleading here. super();
* The standard LLDP destination MAC address that is currently this.srcPortState = srcPortState;
* used is also a multicast address, however since this address this.dstPortState = dstPortState;
* is specified in the standard, we expect all switches to this.firstSeenTime = firstSeenTime;
* absorb this packet, thus making the standard LLDP packet this.lastLldpReceivedTime = lastLldpReceivedTime;
* traverse only one link. this.lastBddpReceivedTime = lastBddpReceivedTime;
*/ }
protected Long unicastValidTime;
protected Long multicastValidTime; protected Integer srcPortState;
protected Integer dstPortState;
protected Long firstSeenTime;
protected Long lastLldpReceivedTime; /* Standard LLLDP received time */
protected Long lastBddpReceivedTime; /* Modified LLDP received time */
/** The port states stored here are topology's last knowledge of /** The port states stored here are topology's last knowledge of
* the state of the port. This mostly mirrors the state * the state of the port. This mostly mirrors the state
...@@ -43,38 +49,36 @@ public class LinkInfo { ...@@ -43,38 +49,36 @@ public class LinkInfo {
* it can determine if the port state has changed and therefore * it can determine if the port state has changed and therefore
* requires the new state to be written to storage. * requires the new state to be written to storage.
*/ */
protected Integer srcPortState;
protected Integer dstPortState;
public LinkInfo(Long unicastValidTime,
Long broadcastValidTime,
Integer srcPortState,
Integer dstPortState) {
this.unicastValidTime = unicastValidTime;
this.multicastValidTime = broadcastValidTime;
this.srcPortState = srcPortState;
this.dstPortState = dstPortState;
}
public boolean linkStpBlocked() { public boolean linkStpBlocked() {
return ((srcPortState & OFPortState.OFPPS_STP_MASK.getValue()) == OFPortState.OFPPS_STP_BLOCK.getValue()) || return ((srcPortState & OFPortState.OFPPS_STP_MASK.getValue()) == OFPortState.OFPPS_STP_BLOCK.getValue()) ||
((dstPortState & OFPortState.OFPPS_STP_MASK.getValue()) == OFPortState.OFPPS_STP_BLOCK.getValue()); ((dstPortState & OFPortState.OFPPS_STP_MASK.getValue()) == OFPortState.OFPPS_STP_BLOCK.getValue());
} }
public Long getFirstSeenTime() {
return firstSeenTime;
}
public void setFirstSeenTime(Long firstSeenTime) {
this.firstSeenTime = firstSeenTime;
}
public Long getUnicastValidTime() { public Long getUnicastValidTime() {
return unicastValidTime; return lastLldpReceivedTime;
} }
public void setUnicastValidTime(Long unicastValidTime) { public void setUnicastValidTime(Long unicastValidTime) {
this.unicastValidTime = unicastValidTime; this.lastLldpReceivedTime = unicastValidTime;
} }
public Long getMulticastValidTime() { public Long getMulticastValidTime() {
return multicastValidTime; return lastBddpReceivedTime;
} }
public void setMulticastValidTime(Long multicastValidTime) { public void setMulticastValidTime(Long multicastValidTime) {
this.multicastValidTime = multicastValidTime; this.lastBddpReceivedTime = multicastValidTime;
} }
public Integer getSrcPortState() { public Integer getSrcPortState() {
...@@ -93,6 +97,15 @@ public class LinkInfo { ...@@ -93,6 +97,15 @@ public class LinkInfo {
this.dstPortState = dstPortState; this.dstPortState = dstPortState;
} }
public LinkType getLinkType() {
if (lastLldpReceivedTime != null) {
return LinkType.DIRECT_LINK;
} else if (lastBddpReceivedTime != null) {
return LinkType.MULTIHOP_LINK;
}
return LinkType.INVALID_LINK;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see java.lang.Object#hashCode() * @see java.lang.Object#hashCode()
*/ */
...@@ -100,9 +113,10 @@ public class LinkInfo { ...@@ -100,9 +113,10 @@ public class LinkInfo {
public int hashCode() { public int hashCode() {
final int prime = 5557; final int prime = 5557;
int result = 1; int result = 1;
result = prime * result + ((unicastValidTime == null) ? 0 : unicastValidTime.hashCode()); result = prime * result + ((firstSeenTime == null) ? 0 : firstSeenTime.hashCode());
result = prime * result + ((multicastValidTime == null) ? 0 : multicastValidTime.hashCode()); result = prime * result + ((lastLldpReceivedTime == null) ? 0 : lastLldpReceivedTime.hashCode());
result = prime * result + ((srcPortState == null) ? 0 : unicastValidTime.hashCode()); result = prime * result + ((lastBddpReceivedTime == null) ? 0 : lastBddpReceivedTime.hashCode());
result = prime * result + ((srcPortState == null) ? 0 : lastLldpReceivedTime.hashCode());
result = prime * result + ((dstPortState == null) ? 0 : dstPortState.hashCode()); result = prime * result + ((dstPortState == null) ? 0 : dstPortState.hashCode());
return result; return result;
} }
...@@ -120,16 +134,22 @@ public class LinkInfo { ...@@ -120,16 +134,22 @@ public class LinkInfo {
return false; return false;
LinkInfo other = (LinkInfo) obj; LinkInfo other = (LinkInfo) obj;
if (unicastValidTime == null) { if (firstSeenTime == null) {
if (other.unicastValidTime != null) if (other.firstSeenTime != null)
return false;
} else if (!firstSeenTime.equals(other.firstSeenTime))
return false;
if (lastLldpReceivedTime == null) {
if (other.lastLldpReceivedTime != null)
return false; return false;
} else if (!unicastValidTime.equals(other.unicastValidTime)) } else if (!lastLldpReceivedTime.equals(other.lastLldpReceivedTime))
return false; return false;
if (multicastValidTime == null) { if (lastBddpReceivedTime == null) {
if (other.multicastValidTime != null) if (other.lastBddpReceivedTime != null)
return false; return false;
} else if (!multicastValidTime.equals(other.multicastValidTime)) } else if (!lastBddpReceivedTime.equals(other.lastBddpReceivedTime))
return false; return false;
if (srcPortState == null) { if (srcPortState == null) {
...@@ -147,13 +167,14 @@ public class LinkInfo { ...@@ -147,13 +167,14 @@ public class LinkInfo {
return true; return true;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see java.lang.Object#toString() * @see java.lang.Object#toString()
*/ */
@Override @Override
public String toString() { public String toString() {
return "LinkInfo [unicastValidTime=" + ((unicastValidTime == null) ? "null" : unicastValidTime) return "LinkInfo [unicastValidTime=" + ((lastLldpReceivedTime == null) ? "null" : lastLldpReceivedTime)
+ ", multicastValidTime=" + ((multicastValidTime == null) ? "null" : multicastValidTime) + ", multicastValidTime=" + ((lastBddpReceivedTime == null) ? "null" : lastBddpReceivedTime)
+ ", srcPortState=" + ((srcPortState == null) ? "null" : srcPortState) + ", srcPortState=" + ((srcPortState == null) ? "null" : srcPortState)
+ ", dstPortState=" + ((dstPortState == null) ? "null" : srcPortState) + ", dstPortState=" + ((dstPortState == null) ? "null" : srcPortState)
+ "]"; + "]";
......
/**
* Copyright 2011, Big Switch Networks, Inc.
* Originally created by David Erickson, Stanford University
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
**/
package net.floodlightcontroller.linkdiscovery;
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;
/**
*
*
* @author David Erickson (daviderickson@cs.stanford.edu)
*/
@JsonSerialize(using=LinkTupleSerializer.class)
public class LinkTuple {
protected SwitchPortTuple src;
protected SwitchPortTuple dst;
protected LinkType type = null;
/**
* @param src
* @param dst
*/
public LinkTuple(SwitchPortTuple src, SwitchPortTuple dst) {
this.src = src;
this.dst = dst;
}
public LinkTuple(IOFSwitch src, Short srcPort, IOFSwitch dst, Short dstPort) {
this.src = new SwitchPortTuple(src, srcPort);
this.dst = new SwitchPortTuple(dst, dstPort);
}
/**
* Convenience constructor, ports are cast to shorts
* @param srcId
* @param srcPort
* @param dstId
* @param dstPort
*/
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
*/
public SwitchPortTuple getSrc() {
return src;
}
/**
* @param src the src to set
*/
public void setSrc(SwitchPortTuple src) {
this.src = src;
}
/**
* @return the dst
*/
public SwitchPortTuple getDst() {
return dst;
}
/**
* @param dst the dst to set
*/
public void setDst(SwitchPortTuple dst) {
this.dst = dst;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 2221;
int result = 1;
result = prime * result + ((dst == null) ? 0 : dst.hashCode());
result = prime * result + ((src == null) ? 0 : src.hashCode());
return result;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj instanceof LinkTuple))
return false;
LinkTuple other = (LinkTuple) obj;
if (dst == null) {
if (other.dst != null)
return false;
} else if (!dst.equals(other.dst))
return false;
if (src == null) {
if (other.src != null)
return false;
} else if (!src.equals(other.src))
return false;
return true;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "LinkTuple [src=" + src + ",dst=" + dst + "]";
}
}
/**
* Copyright 2011, Big Switch Networks, Inc.
* Originally created by David Erickson, Stanford University
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
**/
/**
*
*/
package net.floodlightcontroller.linkdiscovery;
import net.floodlightcontroller.core.IOFSwitch;
/**
* @author David Erickson (daviderickson@cs.stanford.edu)
*
*/
public class SwitchPortTuple {
protected IOFSwitch sw;
protected short port;
public SwitchPortTuple(IOFSwitch sw, short port) {
super();
this.sw = sw;
this.port = port;
}
public SwitchPortTuple(IOFSwitch sw, int port) {
this(sw, (short)port);
}
/**
* @return the sw
*/
public IOFSwitch getSw() {
return sw;
}
/**
* Set the switch
*/
public void setSw(IOFSwitch sw) {
this.sw = sw;
}
/**
* @return the port number
*/
public Short getPort() {
return port;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 5557;
int result = 1;
result = prime * result + ((sw == null) ? 0 : sw.hashCode());
result = prime * result + (new Short(port)).hashCode();
return result;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj instanceof SwitchPortTuple))
return false;
SwitchPortTuple other = (SwitchPortTuple) obj;
if (sw == null) {
if (other.sw != null)
return false;
} else if (!sw.equals(other.sw))
return false;
if (port != other.port)
return false;
return true;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "SwitchPortTuple [id="
+ ((sw == null) ? "null" : sw.getStringId())
+ ", port=" + (0xffff & (int)port) + "]";
}
}
package net.floodlightcontroller.linkdiscovery.web; package net.floodlightcontroller.linkdiscovery.web;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Set; import java.util.Set;
import net.floodlightcontroller.linkdiscovery.ILinkDiscovery.LinkType;
import net.floodlightcontroller.linkdiscovery.ILinkDiscoveryService; import net.floodlightcontroller.linkdiscovery.ILinkDiscoveryService;
import net.floodlightcontroller.linkdiscovery.LinkInfo; import net.floodlightcontroller.linkdiscovery.LinkInfo;
import net.floodlightcontroller.linkdiscovery.LinkTuple; import net.floodlightcontroller.routing.Link;
import org.restlet.resource.Get; import org.restlet.resource.Get;
import org.restlet.resource.ServerResource; import org.restlet.resource.ServerResource;
public class LinksResource extends 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") @Get("json")
public Set<LinkTuple> retrieve() { public Set<LinkWithType> retrieve() {
ILinkDiscoveryService topo = (ILinkDiscoveryService)getContext().getAttributes(). String str;
ILinkDiscoveryService ld = (ILinkDiscoveryService)getContext().getAttributes().
get(ILinkDiscoveryService.class.getCanonicalName()); get(ILinkDiscoveryService.class.getCanonicalName());
Set <LinkTuple> links = new HashSet<LinkTuple>(); Map<Link, LinkInfo> links = new HashMap<Link, LinkInfo>();
if (topo != null) { Set<LinkWithType> returnLinkSet = new HashSet<LinkWithType>();
for (Set<LinkTuple> linkSet : topo.getSwitchLinks().values()) {
for (LinkTuple lt : linkSet) { if (ld != null) {
LinkInfo info = topo.getLinkInfo(lt.getSrc(), true); links.putAll(ld.getLinks());
LinkTuple withType = new LinkTuple(lt.getSrc(), lt.getDst()); for (Link link: links.keySet()) {
withType.setType(topo.getLinkType(lt, info)); LinkInfo info = links.get(link);
links.add(withType); 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);
returnLinkSet.add(lwt);
} }
} }
return links; return returnLinkSet;
} }
} }
...@@ -31,11 +31,13 @@ public class BSN extends BasePacket { ...@@ -31,11 +31,13 @@ public class BSN extends BasePacket {
public static final int BSN_MAGIC = 0x20000604; public static final int BSN_MAGIC = 0x20000604;
public static final short BSN_VERSION_CURRENT = 0x0; public static final short BSN_VERSION_CURRENT = 0x0;
public static final short BSN_TYPE_PROBE = 0x1; public static final short BSN_TYPE_PROBE = 0x1;
public static final short BSN_TYPE_BDDP = 0x2;
public static Map<Short, Class<? extends IPacket>> typeClassMap; public static Map<Short, Class<? extends IPacket>> typeClassMap;
static { static {
typeClassMap = new HashMap<Short, Class<? extends IPacket>>(); typeClassMap = new HashMap<Short, Class<? extends IPacket>>();
typeClassMap.put(BSN_TYPE_PROBE, BSNPROBE.class); typeClassMap.put(BSN_TYPE_PROBE, BSNPROBE.class);
typeClassMap.put(BSN_TYPE_BDDP, LLDP.class);
} }
protected short type; protected short type;
......
...@@ -29,6 +29,7 @@ public class Link { ...@@ -29,6 +29,7 @@ public class Link {
private long dst; private long dst;
private short dstPort; private short dstPort;
public Link(long srcId, short srcPort, long dstId, short dstPort) { public Link(long srcId, short srcPort, long dstId, short dstPort) {
this.src = srcId; this.src = srcId;
this.srcPort = srcPort; this.srcPort = srcPort;
...@@ -36,7 +37,14 @@ public class Link { ...@@ -36,7 +37,14 @@ public class Link {
this.dstPort = dstPort; this.dstPort = dstPort;
} }
// Convenience method
public Link(long srcId, int srcPort, long dstId, int dstPort) {
this.src = srcId;
this.srcPort = (short) srcPort;
this.dst = dstId;
this.dstPort = (short) dstPort;
}
@JsonProperty("src-switch") @JsonProperty("src-switch")
@JsonSerialize(using=DPIDSerializer.class) @JsonSerialize(using=DPIDSerializer.class)
public long getSrc() { public long getSrc() {
......
package net.floodlightcontroller.topology; package net.floodlightcontroller.topology;
import net.floodlightcontroller.core.web.serializers.DPIDSerializer; import net.floodlightcontroller.core.web.serializers.DPIDSerializer;
import net.floodlightcontroller.linkdiscovery.SwitchPortTuple;
import org.codehaus.jackson.annotate.JsonProperty; import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonSerialize; import org.codehaus.jackson.map.annotate.JsonSerialize;
...@@ -26,18 +25,10 @@ public class NodePortTuple { ...@@ -26,18 +25,10 @@ public class NodePortTuple {
this.nodeId = nodeId; this.nodeId = nodeId;
this.portId = portId; this.portId = portId;
} }
/** public NodePortTuple(long nodeId, int portId) {
* Creates a NodePortTuple from the same information this.nodeId = nodeId;
* in a SwitchPortTuple this.portId = (short) portId;
* @param swt
*/
public NodePortTuple(SwitchPortTuple swt) {
if (swt.getSw() != null)
this.nodeId = swt.getSw().getId();
else
this.nodeId = 0;
this.portId = swt.getPort();
} }
@JsonProperty("switch") @JsonProperty("switch")
......
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