ONOS-2711 Replaced short to TpPort for tcp/udp ports
Change-Id: Ibf0474b5369d11d377fd33cf5ab48083cbca3308
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();