In-memory object should hold reference to other objects when possible.
Change-Id: I8974eed07b546bd3521c727cb3c79297687a34a7
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/FloodlightToOnosMappers.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/FloodlightToOnosMappers.java
index 0619087..9bd8051 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/FloodlightToOnosMappers.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/FloodlightToOnosMappers.java
@@ -9,29 +9,32 @@
public static Switch map(NetworkGraph graph, IOFSwitch sw) {
SwitchImpl onosSwitch = new SwitchImpl(graph);
onosSwitch.setDpid(sw.getId());
-
+
for (OFPhysicalPort port : sw.getPorts()) {
onosSwitch.addPort(map(graph, port));
}
-
+
return onosSwitch;
}
-
+
public static Port map(NetworkGraph graph, OFPhysicalPort port) {
PortImpl onosPort = new PortImpl(graph);
onosPort.setPortNumber(port.getPortNumber());
return onosPort;
}
-
+
public static Link map(NetworkGraph graph, net.floodlightcontroller.routing.Link link) {
LinkImpl onosLink = new LinkImpl(graph);
-
- onosLink.setSrcSwitch(link.getSrc());
- onosLink.setSrcPort(link.getSrcPort());
- onosLink.setDstSwitch(link.getDst());
- onosLink.setDstPort(link.getDstPort());
-
+
+ Switch srcSw = graph.getSwitch(link.getSrc());
+ onosLink.setSrcSwitch(srcSw);
+ onosLink.setSrcPort(srcSw.getPort(link.getSrcPort()));
+
+ Switch dstSw = graph.getSwitch(link.getDst());
+ onosLink.setDstSwitch(dstSw);
+ onosLink.setDstPort(dstSw.getPort(link.getDstPort()));
+
return onosLink;
-
+
}
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkImpl.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkImpl.java
index 59af6d0..c566eea 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkImpl.java
@@ -8,10 +8,10 @@
*/
public class LinkImpl extends NetworkGraphObject implements Link {
- private long srcSwitch;
- private short srcPort;
- private long dstSwitch;
- private short dstPort;
+ private Switch srcSwitch;
+ private Port srcPort;
+ private Switch dstSwitch;
+ private Port dstPort;
private static final int DEFAULT_COST = 1;
private int cost = DEFAULT_COST;
@@ -61,37 +61,41 @@
@Override
public long getSourceSwitchDpid() {
- return srcSwitch;
+ return srcSwitch.getDpid();
}
- public void setSrcSwitch(long srcSwitch) {
+ public void setSrcSwitch(Switch srcSwitch) {
+ // TODO null check
this.srcSwitch = srcSwitch;
}
@Override
public short getSourcePortNumber() {
- return srcPort;
+ return srcPort.getNumber();
}
- public void setSrcPort(short srcPort) {
+ public void setSrcPort(Port srcPort) {
+ // TODO null check
this.srcPort = srcPort;
}
@Override
public long getDestinationSwitchDpid() {
- return dstSwitch;
+ return dstSwitch.getDpid();
}
- public void setDstSwitch(long dstSwitch) {
+ public void setDstSwitch(Switch dstSwitch) {
+ // TODO null check
this.dstSwitch = dstSwitch;
}
@Override
public short getDestinationPortNumber() {
- return dstPort;
+ return dstPort.getNumber();
}
- public void setDstPort(short dstPort) {
+ public void setDstPort(Port dstPort) {
+ // TODO null check
this.dstPort = dstPort;
}