Remove PortEvent.SwitchPort
- JSON format of util.SwitchPort has changed to match PortEvent.SwitchPort.
(not sure if it was currently used in public API)
- Note: SwitchPort#toString() format is different. Log messages, etc. may have changed.
PortEvent.SwitchPort : "(dpid@number)" both decimal
util.SwitchPort : "00:00:...:01/number" dpid as HexString, number as decimal
- Part of ONOS-1564
Change-Id: I19ea06de7a701f0f7aaae0a7ed6f0726c0133a91
diff --git a/src/main/java/net/onrc/onos/apps/forwarding/Forwarding.java b/src/main/java/net/onrc/onos/apps/forwarding/Forwarding.java
index 0a2ed39..fc30f12 100644
--- a/src/main/java/net/onrc/onos/apps/forwarding/Forwarding.java
+++ b/src/main/java/net/onrc/onos/apps/forwarding/Forwarding.java
@@ -37,7 +37,6 @@
import net.onrc.onos.core.topology.Port;
import net.onrc.onos.core.topology.Switch;
import net.onrc.onos.core.topology.Topology;
-import net.onrc.onos.core.util.Dpid;
import net.onrc.onos.core.util.FlowPath;
import net.onrc.onos.core.util.PortNumber;
import net.onrc.onos.core.util.SwitchPort;
@@ -420,7 +419,7 @@
for (Iterator<LinkEvent> i = path.iterator(); i.hasNext();) {
LinkEvent le = i.next();
- if (new Dpid(le.getSrc().dpid).equals(sw.getDpid())) {
+ if (le.getSrc().getDpid().equals(sw.getDpid())) {
log.trace("The packet-in sw dpid {} is on the path.", sw.getDpid());
isflowEntryForThisSwitch = true;
outPort = le.getSrc().getNumber().value();
diff --git a/src/main/java/net/onrc/onos/core/intent/PathIntentMap.java b/src/main/java/net/onrc/onos/core/intent/PathIntentMap.java
index dae154e..7b93acc 100644
--- a/src/main/java/net/onrc/onos/core/intent/PathIntentMap.java
+++ b/src/main/java/net/onrc/onos/core/intent/PathIntentMap.java
@@ -7,7 +7,9 @@
import net.onrc.onos.core.topology.Link;
import net.onrc.onos.core.topology.LinkEvent;
-import net.onrc.onos.core.topology.PortEvent.SwitchPort;
+import net.onrc.onos.core.util.Dpid;
+import net.onrc.onos.core.util.PortNumber;
+import net.onrc.onos.core.util.SwitchPort;
/**
* In addition to maintaining the Intent ID to Intent mapping of its
@@ -16,7 +18,7 @@
* when a network event involves a particular switch port.
*/
public class PathIntentMap extends IntentMap {
- private final HashMap<Long, HashMap<Long, HashSet<PathIntent>>> intents;
+ private final HashMap<Dpid, HashMap<PortNumber, HashSet<PathIntent>>> intents;
/**
* Constructor.
@@ -32,9 +34,9 @@
* @return a set of all intents that contain swPort
*/
private HashSet<PathIntent> get(SwitchPort swPort) {
- Long dpid = swPort.getDpid().value();
- Long port = (long) swPort.getNumber().value();
- HashMap<Long, HashSet<PathIntent>> portToIntents = intents.get(dpid);
+ Dpid dpid = swPort.getDpid();
+ PortNumber port = swPort.getNumber();
+ HashMap<PortNumber, HashSet<PathIntent>> portToIntents = intents.get(dpid);
if (portToIntents == null) {
portToIntents = new HashMap<>();
intents.put(dpid, portToIntents);
@@ -100,21 +102,21 @@
*/
public Collection<PathIntent> getIntentsByLink(LinkEvent linkEvent) {
return getIntentsByPort(
- linkEvent.getSrc().getDpid().value(),
- (long) linkEvent.getSrc().getNumber().value());
+ linkEvent.getSrc().getDpid(),
+ linkEvent.getSrc().getNumber());
}
/**
* Retrieve all intents that use a particular port.
*
* @param dpid the switch's DPID
- * @param port the switch's port
+ * @param portNumber the switch's port
* @return a collection of PathIntents that use the port
*/
- public Collection<PathIntent> getIntentsByPort(Long dpid, Long port) {
- HashMap<Long, HashSet<PathIntent>> portToIntents = intents.get(dpid);
+ public Collection<PathIntent> getIntentsByPort(Dpid dpid, PortNumber portNumber) {
+ HashMap<PortNumber, HashSet<PathIntent>> portToIntents = intents.get(dpid);
if (portToIntents != null) {
- HashSet<PathIntent> targetIntents = portToIntents.get(port);
+ HashSet<PathIntent> targetIntents = portToIntents.get(portNumber);
if (targetIntents != null) {
return Collections.unmodifiableCollection(targetIntents);
}
@@ -128,9 +130,9 @@
* @param dpid the switch's DPID
* @return a collection of PathIntents that use the switch
*/
- public Collection<PathIntent> getIntentsByDpid(Long dpid) {
+ public Collection<PathIntent> getIntentsByDpid(Dpid dpid) {
HashSet<PathIntent> result = new HashSet<>();
- HashMap<Long, HashSet<PathIntent>> portToIntents = intents.get(dpid);
+ HashMap<PortNumber, HashSet<PathIntent>> portToIntents = intents.get(dpid);
if (portToIntents != null) {
for (HashSet<PathIntent> targetIntents : portToIntents.values()) {
result.addAll(targetIntents);
diff --git a/src/main/java/net/onrc/onos/core/intent/runtime/PathCalcRuntimeModule.java b/src/main/java/net/onrc/onos/core/intent/runtime/PathCalcRuntimeModule.java
index b41b68a..d41296b 100644
--- a/src/main/java/net/onrc/onos/core/intent/runtime/PathCalcRuntimeModule.java
+++ b/src/main/java/net/onrc/onos/core/intent/runtime/PathCalcRuntimeModule.java
@@ -703,14 +703,14 @@
p.log("begin_getIntentsByPort");
for (PortEvent portEvent : removedPortEvents) {
affectedPaths.addAll(pathIntents.getIntentsByPort(
- portEvent.getDpid().value(),
- (long) portEvent.getNumber().value()));
+ portEvent.getDpid(),
+ portEvent.getNumber()));
}
p.log("end_getIntentsByPort");
p.log("begin_getIntentsByDpid");
for (SwitchEvent switchEvent : removedSwitchEvents) {
- affectedPaths.addAll(pathIntents.getIntentsByDpid(switchEvent.getDpid().value()));
+ affectedPaths.addAll(pathIntents.getIntentsByDpid(switchEvent.getDpid()));
}
p.log("end_getIntentsByDpid");
}
diff --git a/src/main/java/net/onrc/onos/core/topology/DeviceEvent.java b/src/main/java/net/onrc/onos/core/topology/DeviceEvent.java
index cdef9aa..0030516 100644
--- a/src/main/java/net/onrc/onos/core/topology/DeviceEvent.java
+++ b/src/main/java/net/onrc/onos/core/topology/DeviceEvent.java
@@ -5,7 +5,7 @@
import java.util.List;
import net.floodlightcontroller.util.MACAddress;
-import net.onrc.onos.core.topology.PortEvent.SwitchPort;
+import net.onrc.onos.core.util.SwitchPort;
/**
* Self-contained Device event(s) Object
diff --git a/src/main/java/net/onrc/onos/core/topology/LinkEvent.java b/src/main/java/net/onrc/onos/core/topology/LinkEvent.java
index c54140d..f72a429 100644
--- a/src/main/java/net/onrc/onos/core/topology/LinkEvent.java
+++ b/src/main/java/net/onrc/onos/core/topology/LinkEvent.java
@@ -2,10 +2,10 @@
import java.nio.ByteBuffer;
-import net.onrc.onos.core.topology.PortEvent.SwitchPort;
import net.onrc.onos.core.topology.web.serializers.LinkEventSerializer;
import net.onrc.onos.core.util.Dpid;
import net.onrc.onos.core.util.PortNumber;
+import net.onrc.onos.core.util.SwitchPort;
import org.codehaus.jackson.map.annotate.JsonSerialize;
@@ -65,8 +65,8 @@
public static ByteBuffer getLinkID(Dpid srcDpid, PortNumber srcPortNo,
Dpid dstDpid, PortNumber dstPortNo) {
- return getLinkID(srcDpid.value(), (long) srcPortNo.value(),
- dstDpid.value(), (long) dstPortNo.value());
+ return getLinkID(srcDpid.value(), (long) srcPortNo.value(),
+ dstDpid.value(), (long) dstPortNo.value());
}
public static ByteBuffer getLinkID(Long srcDpid, Long srcPortNo,
@@ -77,8 +77,7 @@
}
public byte[] getID() {
- return getLinkID(src.getDpid(), src.getNumber(),
- dst.getDpid(), dst.getNumber()).array();
+ return getIDasByteBuffer().array();
}
public ByteBuffer getIDasByteBuffer() {
diff --git a/src/main/java/net/onrc/onos/core/topology/PortEvent.java b/src/main/java/net/onrc/onos/core/topology/PortEvent.java
index 5c63de7..8d3c945 100644
--- a/src/main/java/net/onrc/onos/core/topology/PortEvent.java
+++ b/src/main/java/net/onrc/onos/core/topology/PortEvent.java
@@ -1,12 +1,10 @@
package net.onrc.onos.core.topology;
-import net.onrc.onos.core.topology.web.serializers.SwitchPortSerializer;
import net.onrc.onos.core.util.Dpid;
import net.onrc.onos.core.util.PortNumber;
+import net.onrc.onos.core.util.SwitchPort;
import org.apache.commons.lang.Validate;
-import org.codehaus.jackson.map.annotate.JsonSerialize;
-
import java.nio.ByteBuffer;
import java.util.Objects;
@@ -17,83 +15,6 @@
*/
public class PortEvent {
- // TODO eliminate this class and use util.SwitchPort if possible
- @JsonSerialize(using = SwitchPortSerializer.class)
- public static class SwitchPort {
- public final Long dpid;
- public final Long number;
-
- /**
- * Default constructor for Serializer to use.
- */
- @Deprecated
- public SwitchPort() {
- dpid = null;
- number = null;
- }
-
- public SwitchPort(Long dpid, Long number) {
- this.dpid = dpid;
- this.number = number;
- }
-
- public SwitchPort(Dpid dpid, PortNumber number) {
- this(dpid.value(), (long) number.value());
- }
-
- public Dpid getDpid() {
- return new Dpid(dpid);
- }
-
- public PortNumber getNumber() {
- return new PortNumber(number.shortValue());
- }
-
- @Override
- public String toString() {
- return "(" + Long.toHexString(dpid) + "@" + number + ")";
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((dpid == null) ? 0 : dpid.hashCode());
- result = prime * result
- + ((number == null) ? 0 : number.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- SwitchPort other = (SwitchPort) obj;
- if (dpid == null) {
- if (other.dpid != null) {
- return false;
- }
- } else if (!dpid.equals(other.dpid)) {
- return false;
- }
- if (number == null) {
- if (other.number != null) {
- return false;
- }
- } else if (!number.equals(other.number)) {
- return false;
- }
- return true;
- }
- }
-
protected final SwitchPort id;
// TODO Add Hardware Address
// TODO Add Description
@@ -102,18 +23,22 @@
* Default constructor for Serializer to use.
*/
@Deprecated
- public PortEvent() {
+ protected PortEvent() {
id = null;
}
- public PortEvent(Long dpid, Long number) {
- this.id = new SwitchPort(dpid, number);
+ public PortEvent(SwitchPort switchPort) {
+ this.id = switchPort;
}
public PortEvent(Dpid dpid, PortNumber number) {
this.id = new SwitchPort(dpid, number);
}
+ public PortEvent(Long dpid, Long number) {
+ this.id = new SwitchPort(dpid, number);
+ }
+
public Dpid getDpid() {
return id.getDpid();
}
@@ -143,7 +68,7 @@
@Override
public String toString() {
- return "[PortEvent 0x" + Long.toHexString(id.dpid) + "@" + id.number + "]";
+ return "[PortEvent 0x" + getDpid() + "@" + getNumber() + "]";
}
public static final int PORTID_BYTES = SwitchEvent.SWITCHID_BYTES + 2 + 8;
@@ -166,10 +91,11 @@
}
public byte[] getID() {
- return getPortID(getDpid(), getNumber()).array();
+ return getIDasByteBuffer().array();
}
public ByteBuffer getIDasByteBuffer() {
return getPortID(getDpid(), getNumber());
}
+
}
diff --git a/src/main/java/net/onrc/onos/core/topology/TopologyDatastore.java b/src/main/java/net/onrc/onos/core/topology/TopologyDatastore.java
index 5067666..171e87f 100644
--- a/src/main/java/net/onrc/onos/core/topology/TopologyDatastore.java
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyDatastore.java
@@ -13,7 +13,7 @@
import net.onrc.onos.core.datastore.topology.KVSwitch;
import net.onrc.onos.core.datastore.utils.KVObject;
import net.onrc.onos.core.datastore.utils.KVObject.WriteOp;
-import net.onrc.onos.core.topology.PortEvent.SwitchPort;
+import net.onrc.onos.core.util.SwitchPort;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/src/main/java/net/onrc/onos/core/topology/TopologyManager.java b/src/main/java/net/onrc/onos/core/topology/TopologyManager.java
index b800d84..190500f 100644
--- a/src/main/java/net/onrc/onos/core/topology/TopologyManager.java
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyManager.java
@@ -24,9 +24,10 @@
import net.onrc.onos.core.datastore.topology.KVPort;
import net.onrc.onos.core.datastore.topology.KVSwitch;
import net.onrc.onos.core.registry.IControllerRegistryService;
-import net.onrc.onos.core.topology.PortEvent.SwitchPort;
import net.onrc.onos.core.util.Dpid;
import net.onrc.onos.core.util.EventEntry;
+import net.onrc.onos.core.util.SwitchPort;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/src/main/java/net/onrc/onos/core/topology/TopologyPublisher.java b/src/main/java/net/onrc/onos/core/topology/TopologyPublisher.java
index 1c251c5..fbd409f 100644
--- a/src/main/java/net/onrc/onos/core/topology/TopologyPublisher.java
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyPublisher.java
@@ -23,8 +23,8 @@
import net.onrc.onos.core.registry.IControllerRegistryService;
import net.onrc.onos.core.registry.IControllerRegistryService.ControlChangeCallback;
import net.onrc.onos.core.registry.RegistryException;
-import net.onrc.onos.core.topology.PortEvent.SwitchPort;
import net.onrc.onos.core.util.Dpid;
+import net.onrc.onos.core.util.SwitchPort;
import org.openflow.protocol.OFPhysicalPort;
import org.openflow.util.HexString;
diff --git a/src/main/java/net/onrc/onos/core/util/SwitchPort.java b/src/main/java/net/onrc/onos/core/util/SwitchPort.java
index b3ed985..c2079a0 100644
--- a/src/main/java/net/onrc/onos/core/util/SwitchPort.java
+++ b/src/main/java/net/onrc/onos/core/util/SwitchPort.java
@@ -1,19 +1,22 @@
package net.onrc.onos.core.util;
-import org.codehaus.jackson.annotate.JsonProperty;
+import net.onrc.onos.core.util.serializers.SwitchPortSerializer;
+
+import org.codehaus.jackson.map.annotate.JsonSerialize;
/**
* The class representing a Switch-Port.
* This class is immutable.
*/
+@JsonSerialize(using = SwitchPortSerializer.class)
public final class SwitchPort {
private final Dpid dpid; // The DPID of the switch
private final PortNumber port; // The port of the switch
/**
- * Default constructor.
+ * Default constructor for Serializer to use.
*/
- public SwitchPort() {
+ protected SwitchPort() {
this.dpid = null;
this.port = null;
}
@@ -41,26 +44,53 @@
}
/**
+ * Constructor for the specified primitive values of a DPID and port.
+ *
+ * @param dpid the DPID to use
+ * @param port the port number to use
+ */
+ public SwitchPort(Long dpid, Long port) {
+ this.dpid = new Dpid(dpid);
+ this.port = new PortNumber(port.shortValue());
+ }
+
+ /**
* Get the DPID value of the Switch-Port.
*
* @return the DPID value of the Switch-Port.
*/
- @JsonProperty("dpid")
public Dpid dpid() {
return dpid;
}
/**
+ * Get the DPID value of the Switch-Port.
+ *
+ * @return the DPID value of the Switch-Port.
+ */
+ public Dpid getDpid() {
+ return dpid;
+ }
+
+ /**
* Get the port value of the Switch-Port.
*
* @return the port value of the Switch-Port.
*/
- @JsonProperty("port")
public PortNumber port() {
return port;
}
/**
+ * Get the port value of the Switch-Port.
+ *
+ * @return the port value of the Switch-Port.
+ */
+ public PortNumber getNumber() {
+ return port;
+ }
+
+ /**
* Convert the Switch-Port value to a string.
* <p/>
* The string has the following form:
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java b/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java
index aeb0c33..dc15810 100644
--- a/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java
+++ b/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java
@@ -51,6 +51,7 @@
import net.onrc.onos.core.util.IPv6Net;
import net.onrc.onos.core.util.PortNumber;
import net.onrc.onos.core.util.Switch;
+import net.onrc.onos.core.util.SwitchPort;
import com.esotericsoftware.kryo.Kryo;
@@ -184,14 +185,13 @@
kryo.register(MACAddress.class);
kryo.register(PortNumber.class);
kryo.register(Switch.class);
- // kryo.register(SwitchPort.class);
+ kryo.register(SwitchPort.class);
// New data model-related classes
kryo.register(DeviceEvent.class);
kryo.register(LinkedList.class);
kryo.register(LinkEvent.class);
kryo.register(PortEvent.class);
- kryo.register(PortEvent.SwitchPort.class);
kryo.register(SwitchEvent.class);
kryo.register(TopologyEvent.class);
diff --git a/src/main/java/net/onrc/onos/core/topology/web/serializers/SwitchPortSerializer.java b/src/main/java/net/onrc/onos/core/util/serializers/SwitchPortSerializer.java
similarity index 91%
rename from src/main/java/net/onrc/onos/core/topology/web/serializers/SwitchPortSerializer.java
rename to src/main/java/net/onrc/onos/core/util/serializers/SwitchPortSerializer.java
index 13c5d56..4ec491b 100644
--- a/src/main/java/net/onrc/onos/core/topology/web/serializers/SwitchPortSerializer.java
+++ b/src/main/java/net/onrc/onos/core/util/serializers/SwitchPortSerializer.java
@@ -1,6 +1,7 @@
-package net.onrc.onos.core.topology.web.serializers;
+package net.onrc.onos.core.util.serializers;
-import net.onrc.onos.core.topology.PortEvent.SwitchPort;
+import net.onrc.onos.core.util.SwitchPort;
+
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.SerializerProvider;
import org.codehaus.jackson.map.ser.std.SerializerBase;
diff --git a/src/test/java/net/onrc/onos/core/intent/PathIntentMapTest.java b/src/test/java/net/onrc/onos/core/intent/PathIntentMapTest.java
index 69b0fc2..b8d9a48 100644
--- a/src/test/java/net/onrc/onos/core/intent/PathIntentMapTest.java
+++ b/src/test/java/net/onrc/onos/core/intent/PathIntentMapTest.java
@@ -21,6 +21,12 @@
import org.junit.Test;
public class PathIntentMapTest {
+ private static final PortNumber PORT_NUMBER_1 = new PortNumber((short) 1);
+ private static final PortNumber PORT_NUMBER_3 = new PortNumber((short) 3);
+ private static final Dpid DPID_1 = new Dpid(1L);
+ private static final Dpid DPID_2 = new Dpid(2L);
+ private static final Dpid DPID_3 = new Dpid(3L);
+ private static final Dpid DPID_4 = new Dpid(4L);
Link link12, link23, link24;
Switch sw1, sw2, sw3, sw4;
Port port11, port22, port21, port23, port31, port41;
@@ -116,21 +122,21 @@
intents.executeOperations(operations);
assertEquals(2, intents.getAllIntents().size());
- Collection<PathIntent> pathIntents = intents.getIntentsByDpid(1L);
+ Collection<PathIntent> pathIntents = intents.getIntentsByDpid(DPID_1);
assertEquals(2, pathIntents.size());
assertTrue(pathIntents.contains(intent1));
assertTrue(pathIntents.contains(intent2));
- pathIntents = intents.getIntentsByDpid(2L);
+ pathIntents = intents.getIntentsByDpid(DPID_2);
assertEquals(2, pathIntents.size());
assertTrue(pathIntents.contains(intent1));
assertTrue(pathIntents.contains(intent2));
- pathIntents = intents.getIntentsByDpid(3L);
+ pathIntents = intents.getIntentsByDpid(DPID_3);
assertEquals(1, pathIntents.size());
assertTrue(pathIntents.contains(intent1));
- pathIntents = intents.getIntentsByDpid(4L);
+ pathIntents = intents.getIntentsByDpid(DPID_4);
assertEquals(1, pathIntents.size());
assertTrue(pathIntents.contains(intent2));
}
@@ -146,16 +152,16 @@
intents.executeOperations(operations);
assertEquals(2, intents.getAllIntents().size());
- Collection<PathIntent> pathIntents = intents.getIntentsByPort(1L, 1L);
+ Collection<PathIntent> pathIntents = intents.getIntentsByPort(DPID_1, PORT_NUMBER_1);
assertEquals(2, pathIntents.size());
assertTrue(pathIntents.contains(intent1));
assertTrue(pathIntents.contains(intent2));
- pathIntents = intents.getIntentsByPort(2L, 1L);
+ pathIntents = intents.getIntentsByPort(DPID_2, PORT_NUMBER_1);
assertEquals(1, pathIntents.size());
assertTrue(pathIntents.contains(intent1));
- pathIntents = intents.getIntentsByPort(2L, 3L);
+ pathIntents = intents.getIntentsByPort(DPID_2, PORT_NUMBER_3);
assertEquals(1, pathIntents.size());
assertTrue(pathIntents.contains(intent2));
}