ONOS-2711 Replaced short to TpPort for tcp/udp ports

Change-Id: Ibf0474b5369d11d377fd33cf5ab48083cbca3308
diff --git a/utils/misc/src/main/java/org/onlab/packet/TCP.java b/utils/misc/src/main/java/org/onlab/packet/TCP.java
index b13b53c..8d45079 100644
--- a/utils/misc/src/main/java/org/onlab/packet/TCP.java
+++ b/utils/misc/src/main/java/org/onlab/packet/TCP.java
@@ -30,8 +30,8 @@
 
     private static final short TCP_HEADER_LENGTH = 20;
 
-    protected short sourcePort;
-    protected short destinationPort;
+    protected int sourcePort;
+    protected int destinationPort;
     protected int sequence;
     protected int acknowledge;
     protected byte dataOffset;
@@ -46,17 +46,17 @@
      *
      * @return TCP source port
      */
-    public short getSourcePort() {
+    public int getSourcePort() {
         return this.sourcePort;
     }
 
     /**
      * Sets TCP source port.
      *
-     * @param sourcePort the sourcePort to set
+     * @param sourcePort the sourcePort to set (unsigned 16 bits integer)
      * @return this
      */
-    public TCP setSourcePort(final short sourcePort) {
+    public TCP setSourcePort(final int sourcePort) {
         this.sourcePort = sourcePort;
         return this;
     }
@@ -66,17 +66,17 @@
      *
      * @return the destinationPort
      */
-    public short getDestinationPort() {
+    public int getDestinationPort() {
         return this.destinationPort;
     }
 
     /**
      * Sets TCP destination port.
      *
-     * @param destinationPort the destinationPort to set
+     * @param destinationPort the destinationPort to set (unsigned 16 bits integer)
      * @return this
      */
-    public TCP setDestinationPort(final short destinationPort) {
+    public TCP setDestinationPort(final int destinationPort) {
         this.destinationPort = destinationPort;
         return this;
     }
@@ -270,8 +270,8 @@
         final byte[] data = new byte[length];
         final ByteBuffer bb = ByteBuffer.wrap(data);
 
-        bb.putShort(this.sourcePort);
-        bb.putShort(this.destinationPort);
+        bb.putShort((short) (this.sourcePort & 0xffff));
+        bb.putShort((short) (this.destinationPort & 0xffff));
         bb.putInt(this.sequence);
         bb.putInt(this.acknowledge);
         bb.putShort((short) (this.flags | this.dataOffset << 12));
@@ -348,8 +348,8 @@
     public IPacket deserialize(final byte[] data, final int offset,
                                final int length) {
         final ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
-        this.sourcePort = bb.getShort();
-        this.destinationPort = bb.getShort();
+        this.sourcePort = (bb.getShort() & 0xffff);
+        this.destinationPort = (bb.getShort() & 0xffff);
         this.sequence = bb.getInt();
         this.acknowledge = bb.getInt();
         this.flags = bb.getShort();
@@ -435,8 +435,8 @@
             TCP tcp = new TCP();
 
             final ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
-            tcp.sourcePort = bb.getShort();
-            tcp.destinationPort = bb.getShort();
+            tcp.sourcePort = (bb.getShort() & 0xffff);
+            tcp.destinationPort = (bb.getShort() & 0xffff);
             tcp.sequence = bb.getInt();
             tcp.acknowledge = bb.getInt();
             tcp.flags = bb.getShort();
diff --git a/utils/misc/src/main/java/org/onlab/packet/UDP.java b/utils/misc/src/main/java/org/onlab/packet/UDP.java
index 32432e6..66534eb 100644
--- a/utils/misc/src/main/java/org/onlab/packet/UDP.java
+++ b/utils/misc/src/main/java/org/onlab/packet/UDP.java
@@ -46,24 +46,24 @@
 
     }
 
-    protected short sourcePort;
-    protected short destinationPort;
+    protected int sourcePort;
+    protected int destinationPort;
     protected short length;
     protected short checksum;
 
     /**
      * @return the sourcePort
      */
-    public short getSourcePort() {
+    public int getSourcePort() {
         return this.sourcePort;
     }
 
     /**
      * @param sourcePort
-     *            the sourcePort to set
+     *            the sourcePort to set (16 bits unsigned integer)
      * @return this
      */
-    public UDP setSourcePort(final short sourcePort) {
+    public UDP setSourcePort(final int sourcePort) {
         this.sourcePort = sourcePort;
         return this;
     }
@@ -71,16 +71,16 @@
     /**
      * @return the destinationPort
      */
-    public short getDestinationPort() {
+    public int getDestinationPort() {
         return this.destinationPort;
     }
 
     /**
      * @param destinationPort
-     *            the destinationPort to set
+     *            the destinationPort to set (16 bits unsigned integer)
      * @return this
      */
-    public UDP setDestinationPort(final short destinationPort) {
+    public UDP setDestinationPort(final int destinationPort) {
         this.destinationPort = destinationPort;
         return this;
     }
@@ -134,8 +134,8 @@
         final byte[] data = new byte[this.length];
         final ByteBuffer bb = ByteBuffer.wrap(data);
 
-        bb.putShort(this.sourcePort);
-        bb.putShort(this.destinationPort);
+        bb.putShort((short) (this.sourcePort & 0xffff));
+        bb.putShort((short) (this.destinationPort & 0xffff));
         bb.putShort(this.length);
         bb.putShort(this.checksum);
         if (payloadData != null) {
@@ -200,8 +200,8 @@
     public IPacket deserialize(final byte[] data, final int offset,
                                final int length) {
         final ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
-        this.sourcePort = bb.getShort();
-        this.destinationPort = bb.getShort();
+        this.sourcePort = (bb.getShort() & 0xffff);
+        this.destinationPort = (bb.getShort() & 0xffff);
         this.length = bb.getShort();
         this.checksum = bb.getShort();
 
@@ -284,8 +284,8 @@
             UDP udp = new UDP();
 
             ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
-            udp.sourcePort = bb.getShort();
-            udp.destinationPort = bb.getShort();
+            udp.sourcePort = (bb.getShort() & 0xffff);
+            udp.destinationPort = (bb.getShort() & 0xffff);
             udp.length = bb.getShort();
             udp.checksum = bb.getShort();