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

Refactoring Link and Route data structures in the RoutingImpl.

parent 84b5a326
No related branches found
No related tags found
No related merge requests found
......@@ -163,7 +163,7 @@ public abstract class ForwardingBase implements IOFMessageListener, IDeviceManag
for (int routeIndx = route.getPath().size() - 1; routeIndx >= 0; --routeIndx) {
Link link = route.getPath().get(routeIndx);
fm.setMatch(wildcard(match, sw, wildcard_hints));
fm.getMatch().setInputPort(link.getInPort());
fm.getMatch().setInputPort(link.getDstPort());
try {
counterStore.updatePktOutFMCounterStore(sw, fm);
if (log.isDebugEnabled()) {
......@@ -191,7 +191,7 @@ public abstract class ForwardingBase implements IOFMessageListener, IDeviceManag
}
// setup for the next loop iteration
((OFActionOutput)fm.getActions().get(0)).setPort(link.getOutPort());
((OFActionOutput)fm.getActions().get(0)).setPort(link.getSrcPort());
if (routeIndx > 0) {
sw = floodlightProvider.getSwitches().get(route.getPath().get(routeIndx-1).getDst());
} else {
......
......@@ -19,85 +19,42 @@ package net.floodlightcontroller.routing;
import org.openflow.util.HexString;
/**
* Represents a link between two datapaths. It is assumed that
* Links will generally be held in a list, and that the first datapath's
* id will be held in a different structure.
*
* @author David Erickson (daviderickson@cs.stanford.edu)
*/
public class Link {
/**
* Outgoing port number of the current datapath the link connects to
*/
protected Short outPort;
/**
* Destination datapath id
*/
protected Long dst;
/**
* Incoming port number on the dst datapath the link connects to
*/
protected Short inPort;
private long src;
private short srcPort;
private long dst;
private short dstPort;
public Link(Short outPort, Short inPort, Long dst) {
super();
this.outPort = outPort;
this.inPort = inPort;
this.dst = dst;
public Link(long srcId, short srcPort, long dstId, short dstPort) {
this.src = srcId;
this.srcPort = srcPort;
this.dst = dstId;
this.dstPort = dstPort;
}
/**
* @return the port number of the switch this link begins on
*/
public Short getOutPort() {
return outPort;
public long getSrc() {
return src;
}
/**
* @param outPort the outPort to set
*/
public void setOutPort(Short outPort) {
this.outPort = outPort;
public short getSrcPort() {
return srcPort;
}
/**
* @return the switch id of the destination switch on this link
*/
public Long getDst() {
public long getDst() {
return dst;
}
/**
* @param dst the dst to set
*/
public void setDst(Long dst) {
this.dst = dst;
}
/**
* @return the port number of the destination switch on this link
*/
public Short getInPort() {
return inPort;
}
/**
* @param inPort the inPort to set
*/
public void setInPort(Short inPort) {
this.inPort = inPort;
public short getDstPort() {
return dstPort;
}
@Override
public int hashCode() {
final int prime = 3203;
final int prime = 31;
int result = 1;
result = prime * result + ((dst == null) ? 0 : dst.hashCode());
result = prime * result + ((inPort == null) ? 0 : inPort.hashCode());
result = prime * result + ((outPort == null) ? 0 : outPort.hashCode());
result = prime * result + (int) (dst ^ (dst >>> 32));
result = prime * result + dstPort;
result = prime * result + (int) (src ^ (src >>> 32));
result = prime * result + srcPort;
return result;
}
......@@ -110,30 +67,27 @@ public class Link {
if (getClass() != obj.getClass())
return false;
Link other = (Link) obj;
if (dst == null) {
if (other.dst != null)
return false;
} else if (!dst.equals(other.dst))
if (dst != other.dst)
return false;
if (dstPort != other.dstPort)
return false;
if (inPort == null) {
if (other.inPort != null)
return false;
} else if (!inPort.equals(other.inPort))
if (src != other.src)
return false;
if (outPort == null) {
if (other.outPort != null)
return false;
} else if (!outPort.equals(other.outPort))
if (srcPort != other.srcPort)
return false;
return true;
}
@Override
public String toString() {
return "Link [outPort="
+ ((outPort == null) ? "null" : (0xffff & outPort))
return "Link [src=" + HexString.toHexString(this.src)
+ " outPort="
+ srcPort
+ ", dst=" + HexString.toHexString(this.dst)
+ ", inPort="
+ ((inPort == null) ? "null" : (0xffff & inPort))
+ ", dst=" + HexString.toHexString(this.dst) + "]";
+ dstPort
+ "]";
}
}
......@@ -25,7 +25,7 @@ import java.util.List;
*
* @author David Erickson (daviderickson@cs.stanford.edu)
*/
public class Route implements Cloneable, Comparable<Route> {
public class Route implements Comparable<Route> {
protected RouteId id;
protected List<Link> path;
......@@ -47,28 +47,32 @@ public class Route implements Cloneable, Comparable<Route> {
* @param srcDpid
* @param objects
*/
public Route(Long srcDpid, Object... routeElements) {
public Route(Long srcId, Object... routeElements) {
super();
this.path = new ArrayList<Link>();
if (routeElements.length % 3 > 0)
throw new RuntimeException("routeElements must be a multiple of 3");
Short outPort, inPort;
long s;
Short srcPort, dstPort;
s = srcId;
for (int i = 0; i < routeElements.length; i += 3) {
if (routeElements[i] instanceof Short)
outPort = (Short) routeElements[i];
srcPort = (Short) routeElements[i];
else
outPort = ((Integer)routeElements[i]).shortValue();
srcPort = ((Integer)routeElements[i]).shortValue();
if (routeElements[i+1] instanceof Short)
inPort = (Short) routeElements[i+1];
dstPort = (Short) routeElements[i+1];
else
inPort = ((Integer)routeElements[i+1]).shortValue();
dstPort = ((Integer)routeElements[i+1]).shortValue();
this.path.add(new Link(outPort, inPort, (Long) routeElements[i + 2]));
this.path.add(new Link(s, srcPort, ((Long) routeElements[i + 2]), dstPort));
s = (Long) routeElements[i + 2];
}
this.id = new RouteId(srcDpid, (this.path.size() == 0) ? srcDpid
: this.path.get(this.path.size() - 1).dst);
this.id = new RouteId(srcId, (this.path.size() == 0) ? srcId
: this.path.get(this.path.size() - 1).getDst());
}
/**
......@@ -135,15 +139,6 @@ public class Route implements Cloneable, Comparable<Route> {
return "Route [id=" + id + ", path=" + path + "]";
}
@SuppressWarnings("unchecked")
@Override
public Object clone() throws CloneNotSupportedException {
Route clone = (Route) super.clone();
clone.setId((RouteId) this.id.clone());
clone.path = (List<Link>) ((ArrayList<Link>)this.path).clone();
return clone;
}
/**
* Compares the path lengths between Routes.
*/
......
......@@ -204,7 +204,7 @@ public class RoutingImpl
network_updated = true;
}
Link srcLink = new Link(srcPort, dstPort, dstId);
Link srcLink = new Link(srcId, srcPort, dstId, dstPort);
if (added) {
if (src.containsKey(srcPort)) {
log.debug("update: unexpected link add request - srcPort in use src, link: {}, {}", srcId, src.get(srcPort));
......
......@@ -204,7 +204,7 @@ public class ForwardingTest extends FloodlightTestCase {
dstDevice.addAttachmentPoint(new SwitchPortTuple(sw2, (short)3), currentDate);
Route route = new Route(1L, 2L);
route.setPath(new ArrayList<Link>());
route.getPath().add(new Link((short)3, (short)1, 2L));
route.getPath().add(new Link(1L, (short)3, 2L, (short)1));
expect(routingEngine.getRoute(1L, 2L)).andReturn(route).atLeastOnce();
// Expected Flow-mods
......
......@@ -31,15 +31,18 @@ public class RouteTest extends FloodlightTestCase {
@Test
public void testCloneable() throws Exception {
Route r1 = new Route(1L, 2L);
Route r2 = (Route) r1.clone();
r2.getId().setDst(3L);
Route r2 = new Route(1L, 3L);
assertNotSame(r1, r2);
assertNotSame(r1.getId(), r2.getId());
r1.getId().setDst(3L);
r1.getPath().add(new Link((short)1, (short)1, 2L));
r1.getPath().add(new Link((short)2, (short)1, 3L));
r2 = (Route) r1.clone();
r1 = new Route(1L, 3L);
r1.getPath().add(new Link(1L, (short)1, 2L, (short)1));
r1.getPath().add(new Link(2L, (short)2, 3L, (short)1));
r2.getPath().add(new Link(1L, (short)1, 2L, (short)1));
r2.getPath().add(new Link(2L, (short)2, 3L, (short)1));
assertEquals(r1, r2);
Link temp = r2.getPath().remove(0);
......@@ -48,7 +51,9 @@ public class RouteTest extends FloodlightTestCase {
r2.getPath().add(0, temp);
assertEquals(r1, r2);
r2.getPath().get(0).setInPort((short) 5);
r2.getPath().remove(0);
temp = new Link(1L, (short)1, 2L, (short)5);
r2.getPath().add(0, temp);
assertNotSame(r1, r2);
}
}
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