Rename Port to PortNumber

Current util.Port actually only represent a port number.
Renaming it to PortNumber, so that it matches what it actually reprsent.

- Updated javadoc
- Removed unnecessary hashCode calculation
- Hide default constructor from public

Change-Id: Ib26c746eaa27464356c4ca0abff6af5e321afc35
diff --git a/src/main/java/net/onrc/onos/core/util/FlowEntry.java b/src/main/java/net/onrc/onos/core/util/FlowEntry.java
index 768f942..4d1eb45 100644
--- a/src/main/java/net/onrc/onos/core/util/FlowEntry.java
+++ b/src/main/java/net/onrc/onos/core/util/FlowEntry.java
@@ -19,10 +19,10 @@
     private FlowEntryMatch flowEntryMatch;    // The Flow Entry Match
     private FlowEntryActions flowEntryActions;    // The Flow Entry Actions
     private Dpid dpid;                // The Switch DPID
-    private Port inPort;        // The Switch incoming port. Used only
+    private PortNumber inPort;        // The Switch incoming port. Used only
     // when the entry is used to return
     // Shortest Path computation.
-    private Port outPort;        // The Switch outgoing port. Used only
+    private PortNumber outPort;        // The Switch outgoing port. Used only
     // when the entry is used to return
     // Shortest Path computation.
     private FlowEntryUserState flowEntryUserState; // The Flow Entry User state
@@ -327,7 +327,7 @@
      * @return the Switch incoming port.
      */
     @JsonProperty("inPort")
-    public Port inPort() {
+    public PortNumber inPort() {
         return inPort;
     }
 
@@ -339,7 +339,7 @@
      * @param inPort the Switch incoming port to set.
      */
     @JsonProperty("inPort")
-    public void setInPort(Port inPort) {
+    public void setInPort(PortNumber inPort) {
         this.inPort = inPort;
     }
 
@@ -351,7 +351,7 @@
      * @return the Switch outgoing port.
      */
     @JsonProperty("outPort")
-    public Port outPort() {
+    public PortNumber outPort() {
         return outPort;
     }
 
@@ -363,7 +363,7 @@
      * @param outPort the Switch outgoing port to set.
      */
     @JsonProperty("outPort")
-    public void setOutPort(Port outPort) {
+    public void setOutPort(PortNumber outPort) {
         this.outPort = outPort;
     }
 
diff --git a/src/main/java/net/onrc/onos/core/util/FlowEntryAction.java b/src/main/java/net/onrc/onos/core/util/FlowEntryAction.java
index 16b9d27..dd7bdbd 100644
--- a/src/main/java/net/onrc/onos/core/util/FlowEntryAction.java
+++ b/src/main/java/net/onrc/onos/core/util/FlowEntryAction.java
@@ -58,7 +58,7 @@
      * Action structure for ACTION_OUTPUT: Output to switch port.
      */
     public static class ActionOutput {
-        private Port port;    // Output port
+        private PortNumber port;    // Output port
         private short maxLen;    // Max. length (in bytes) to send to controller
         // if the port is set to PORT_CONTROLLER
 
@@ -77,7 +77,7 @@
          */
         public ActionOutput(ActionOutput other) {
             if (other.port != null) {
-                this.port = new Port(other.port);
+                this.port = new PortNumber(other.port);
             }
             this.maxLen = other.maxLen;
         }
@@ -101,7 +101,7 @@
          * @param maxLen the maximum length (in bytes) to send to controller
          *               if the port is set to PORT_CONTROLLER.
          */
-        public ActionOutput(Port port, short maxLen) {
+        public ActionOutput(PortNumber port, short maxLen) {
             this.port = port;
             this.maxLen = maxLen;
         }
@@ -111,7 +111,7 @@
          *
          * @param port the output port to set.
          */
-        public ActionOutput(Port port) {
+        public ActionOutput(PortNumber port) {
             this.port = port;
             this.maxLen = 0;
         }
@@ -122,7 +122,7 @@
          * @return the output port.
          */
         @JsonProperty("port")
-        public Port port() {
+        public PortNumber port() {
             return this.port;
         }
 
@@ -177,7 +177,7 @@
                 if (tokens.length > 1 && tokens[1] != null) {
                     try {
                         Short valueShort = Short.valueOf(tokens[1]);
-                        port = new Port(valueShort);
+                        port = new PortNumber(valueShort);
                     } catch (NumberFormatException e) {
                         throw new IllegalArgumentException("Invalid action string");
                     }
@@ -908,7 +908,7 @@
      * Action structure for ACTION_ENQUEUE: Output to queue on port.
      */
     public static class ActionEnqueue {
-        private Port port;    // Port that queue belongs. Should
+        private PortNumber port;    // Port that queue belongs. Should
         // refer to a valid physical port
         // (i.e. < PORT_MAX) or PORT_IN_PORT
         private int queueId;    // Where to enqueue the packets
@@ -928,7 +928,7 @@
          */
         public ActionEnqueue(ActionEnqueue other) {
             if (other.port != null) {
-                this.port = new Port(other.port);
+                this.port = new PortNumber(other.port);
             }
             this.queueId = other.queueId;
         }
@@ -951,7 +951,7 @@
          * @param port    the port to set.
          * @param queueId the queue ID on the port.
          */
-        public ActionEnqueue(Port port, int queueId) {
+        public ActionEnqueue(PortNumber port, int queueId) {
             this.port = port;
             this.queueId = queueId;
         }
@@ -962,7 +962,7 @@
          * @return the port.
          */
         @JsonProperty("port")
-        public Port port() {
+        public PortNumber port() {
             return this.port;
         }
 
@@ -1015,7 +1015,7 @@
                 if (tokens.length > 1 && tokens[1] != null) {
                     try {
                         Short valueShort = Short.valueOf(tokens[1]);
-                        port = new Port(valueShort);
+                        port = new PortNumber(valueShort);
                     } catch (NumberFormatException e) {
                         throw new IllegalArgumentException("Invalid action string");
                     }
@@ -1201,7 +1201,7 @@
      *
      * @param port the output port to set.
      */
-    public void setActionOutput(Port port) {
+    public void setActionOutput(PortNumber port) {
         actionOutput = new ActionOutput(port);
         actionType = ActionValues.ACTION_OUTPUT;
     }
@@ -1212,7 +1212,7 @@
      * @param maxLen the maximum length (in bytes) to send to controller.
      */
     public void setActionOutputToController(short maxLen) {
-        Port port = new Port(Port.PortValues.PORT_CONTROLLER);
+        PortNumber port = new PortNumber(PortNumber.PortValues.PORT_CONTROLLER);
         actionOutput = new ActionOutput(port, maxLen);
         actionType = ActionValues.ACTION_OUTPUT;
     }
@@ -1554,7 +1554,7 @@
      * @param port    the port to set.
      * @param queueId the queue ID to set.
      */
-    public void setActionEnqueue(Port port, int queueId) {
+    public void setActionEnqueue(PortNumber port, int queueId) {
         actionEnqueue = new ActionEnqueue(port, queueId);
         actionType = ActionValues.ACTION_ENQUEUE;
     }
diff --git a/src/main/java/net/onrc/onos/core/util/FlowEntryMatch.java b/src/main/java/net/onrc/onos/core/util/FlowEntryMatch.java
index eabf401..d3f8d71 100644
--- a/src/main/java/net/onrc/onos/core/util/FlowEntryMatch.java
+++ b/src/main/java/net/onrc/onos/core/util/FlowEntryMatch.java
@@ -73,7 +73,7 @@
         private boolean enabled;    // Set to true, if matching is enabled
     }
 
-    private Field<Port> inPort;        // Matching input switch port
+    private Field<PortNumber> inPort;        // Matching input switch port
     private Field<MACAddress> srcMac;    // Matching source MAC address
     private Field<MACAddress> dstMac;    // Matching destination MAC address
     private Field<Short> ethernetFrameType; // Matching Ethernet frame type
@@ -142,7 +142,7 @@
      * @return the matching input switch port.
      */
     @JsonProperty("inPort")
-    public Port inPort() {
+    public PortNumber inPort() {
         if (inPort != null) {
             return inPort.value();
         }
@@ -155,8 +155,8 @@
      * @param newInPort the input switch port value to enable for matching.
      */
     @JsonProperty("inPort")
-    public void enableInPort(Port newInPort) {
-        this.inPort = new Field<Port>(newInPort);
+    public void enableInPort(PortNumber newInPort) {
+        this.inPort = new Field<PortNumber>(newInPort);
     }
 
     /**
diff --git a/src/main/java/net/onrc/onos/core/util/Port.java b/src/main/java/net/onrc/onos/core/util/PortNumber.java
similarity index 73%
rename from src/main/java/net/onrc/onos/core/util/Port.java
rename to src/main/java/net/onrc/onos/core/util/PortNumber.java
index 20a2a21..f9f27bd 100644
--- a/src/main/java/net/onrc/onos/core/util/Port.java
+++ b/src/main/java/net/onrc/onos/core/util/PortNumber.java
@@ -3,10 +3,11 @@
 import org.codehaus.jackson.annotate.JsonProperty;
 
 /**
- * The class representing a network port of a switch.
- * This class is immutable.
+ * Immutable class representing a port number.
+ * <p/>
+ * Current implementation supports only OpenFlow 1.0 (16 bit unsigned) port number.
  */
-public final class Port {
+public final class PortNumber {
     /**
      * Special port values.
      * <p/>
@@ -14,39 +15,39 @@
      * (pp 18-19).
      */
     public enum PortValues {
-        /* Maximum number of physical switch ports. */
+        /** Maximum number of physical switch ports. */
         PORT_MAX((short) 0xff00),
 
     /* Fake output "ports". */
 
-        /* Send the packet out the input port. This
+        /** Send the packet out the input port. This
            virtual port must be explicitly used
            in order to send back out of the input
            port. */
         PORT_IN_PORT((short) 0xfff8),
 
-        /* Perform actions in flow table.
+        /** Perform actions in flow table.
            NB: This can only be the destination
            port for packet-out messages. */
         PORT_TABLE((short) 0xfff9),
 
-        /* Process with normal L2/L3 switching. */
+        /** Process with normal L2/L3 switching. */
         PORT_NORMAL((short) 0xfffa),
 
-        /* All physical ports except input port and
+        /** All physical ports except input port and
            those disabled by STP. */
         PORT_FLOOD((short) 0xfffb),
 
-        /* All physical ports except input port. */
+        /** All physical ports except input port. */
         PORT_ALL((short) 0xfffc),
 
-        /* Send to controller. */
+        /** Send to controller. */
         PORT_CONTROLLER((short) 0xfffd),
 
-        /* Local openflow "port". */
+        /** Local openflow "port". */
         PORT_LOCAL((short) 0xfffe),
 
-        /* Not associated with a physical port. */
+        /** Not associated with a physical port. */
         PORT_NONE((short) 0xffff);
 
         private final short value;    // The value
@@ -75,7 +76,7 @@
     /**
      * Default constructor.
      */
-    public Port() {
+    protected PortNumber() {
         this.value = 0;
     }
 
@@ -84,7 +85,7 @@
      *
      * @param other the object to copy from.
      */
-    public Port(Port other) {
+    public PortNumber(PortNumber other) {
         this.value = other.value();
     }
 
@@ -93,7 +94,7 @@
      *
      * @param value the value to use.
      */
-    public Port(short value) {
+    public PortNumber(short value) {
         this.value = value;
     }
 
@@ -102,7 +103,7 @@
      *
      * @param value the value to use.
      */
-    public Port(PortValues value) {
+    public PortNumber(PortValues value) {
         this.value = value.value();
     }
 
@@ -128,19 +129,17 @@
 
     @Override
     public boolean equals(Object other) {
-        if (!(other instanceof Port)) {
+        if (!(other instanceof PortNumber)) {
             return false;
         }
 
-        Port otherPort = (Port) other;
+        PortNumber otherPort = (PortNumber) other;
 
         return value == otherPort.value;
     }
 
     @Override
     public int hashCode() {
-        int hash = 17;
-        hash += 31 * hash + (int) value;
-        return hash;
+        return value;
     }
 }
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 edb9f77..b3ed985 100644
--- a/src/main/java/net/onrc/onos/core/util/SwitchPort.java
+++ b/src/main/java/net/onrc/onos/core/util/SwitchPort.java
@@ -8,7 +8,7 @@
  */
 public final class SwitchPort {
     private final Dpid dpid;        // The DPID of the switch
-    private final Port port;        // The port of the switch
+    private final PortNumber port;        // The port of the switch
 
     /**
      * Default constructor.
@@ -24,7 +24,7 @@
      * @param dpid the DPID to use.
      * @param port the port to use.
      */
-    public SwitchPort(Dpid dpid, Port port) {
+    public SwitchPort(Dpid dpid, PortNumber port) {
         this.dpid = dpid;
         this.port = port;
     }
@@ -37,7 +37,7 @@
      */
     public SwitchPort(long dpid, short port) {
         this.dpid = new Dpid(dpid);
-        this.port = new Port(port);
+        this.port = new PortNumber(port);
     }
 
     /**
@@ -56,7 +56,7 @@
      * @return the port value of the Switch-Port.
      */
     @JsonProperty("port")
-    public Port port() {
+    public PortNumber port() {
         return port;
     }
 
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 3b06ec3..aeb0c33 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
@@ -49,7 +49,7 @@
 import net.onrc.onos.core.util.IPv4Net;
 import net.onrc.onos.core.util.IPv6;
 import net.onrc.onos.core.util.IPv6Net;
-import net.onrc.onos.core.util.Port;
+import net.onrc.onos.core.util.PortNumber;
 import net.onrc.onos.core.util.Switch;
 
 import com.esotericsoftware.kryo.Kryo;
@@ -182,7 +182,7 @@
         kryo.register(IPv6Net.class);
         kryo.register(byte[].class);
         kryo.register(MACAddress.class);
-        kryo.register(Port.class);
+        kryo.register(PortNumber.class);
         kryo.register(Switch.class);
         // kryo.register(SwitchPort.class);