Hyunsun Moon
Committed by Gerrit Code Review

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

Change-Id: Ibf0474b5369d11d377fd33cf5ab48083cbca3308
Showing 36 changed files with 548 additions and 231 deletions
......@@ -35,6 +35,7 @@ import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.RADIUS;
import org.onlab.packet.RADIUSAttribute;
import org.onlab.packet.TpPort;
import org.onlab.packet.UDP;
import org.onlab.packet.VlanId;
import org.onlab.util.Tools;
......@@ -236,8 +237,8 @@ public class AAA {
TrafficSelector radSelector = DefaultTrafficSelector.builder()
.matchEthType(EthType.EtherType.IPV4.ethType().toShort())
.matchIPProtocol(IPv4.PROTOCOL_UDP)
.matchUdpDst((short) 1812)
.matchUdpSrc((short) 1812)
.matchUdpDst(TpPort.tpPort(1812))
.matchUdpSrc(TpPort.tpPort(1812))
.build();
packetService.requestPackets(radSelector, CONTROL, appId);
}
......@@ -253,8 +254,8 @@ public class AAA {
TrafficSelector radSelector = DefaultTrafficSelector.builder()
.matchEthType(EthType.EtherType.IPV4.ethType().toShort())
.matchIPProtocol(IPv4.PROTOCOL_UDP)
.matchUdpDst((short) 1812)
.matchUdpSrc((short) 1812)
.matchUdpDst(TpPort.tpPort(1812))
.matchUdpSrc(TpPort.tpPort(1812))
.build();
packetService.cancelPackets(radSelector, CONTROL, appId);
}
......
......@@ -19,6 +19,12 @@
*/
package org.onos.acl.impl;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IPv4;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip4Prefix;
import org.onlab.packet.IpAddress;
import org.onlab.packet.TpPort;
import org.onos.acl.AclRule;
import org.onos.acl.AclService;
import org.onos.acl.AclStore;
......@@ -28,11 +34,6 @@ import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IPv4;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip4Prefix;
import org.onlab.packet.IpAddress;
import org.onos.acl.RuleId;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
......@@ -278,10 +279,10 @@ public class AclManager implements AclService {
if (rule.dstTpPort() != 0) {
switch (rule.ipProto()) {
case IPv4.PROTOCOL_TCP:
selectorBuilder.matchTcpDst(rule.dstTpPort());
selectorBuilder.matchTcpDst(TpPort.tpPort(rule.dstTpPort()));
break;
case IPv4.PROTOCOL_UDP:
selectorBuilder.matchUdpDst(rule.dstTpPort());
selectorBuilder.matchUdpDst(TpPort.tpPort(rule.dstTpPort()));
break;
default:
break;
......
......@@ -21,6 +21,7 @@ import org.onlab.packet.Ethernet;
import org.onlab.packet.IPv4;
import org.onlab.packet.IpAddress;
import org.onlab.packet.TCP;
import org.onlab.packet.TpPort;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.flow.DefaultTrafficSelector;
......@@ -101,13 +102,13 @@ public class TunnellingConnectivityManager {
TrafficSelector selectorDst = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPProtocol(IPv4.PROTOCOL_TCP)
.matchTcpDst(BGP_PORT)
.matchTcpDst(TpPort.tpPort(BGP_PORT))
.build();
TrafficSelector selectorSrc = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPProtocol(IPv4.PROTOCOL_TCP)
.matchTcpSrc(BGP_PORT)
.matchTcpSrc(TpPort.tpPort(BGP_PORT))
.build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
......
......@@ -27,6 +27,7 @@ import org.apache.felix.scr.annotations.Service;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IPv4;
import org.onlab.packet.MacAddress;
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
......@@ -119,14 +120,14 @@ public class CordFabricManager implements FabricService {
TrafficSelector ofInBandMatchUp = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPProtocol(IPv4.PROTOCOL_TCP)
.matchTcpDst(ofPort)
.matchTcpDst(TpPort.tpPort(ofPort))
.matchInPort(PortNumber.portNumber(6))
.build();
TrafficSelector ofInBandMatchDown = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPProtocol(IPv4.PROTOCOL_TCP)
.matchTcpSrc(ofPort)
.matchTcpSrc(TpPort.tpPort(ofPort))
.matchInPort(PortNumber.portNumber(1))
.build();
......@@ -152,14 +153,14 @@ public class CordFabricManager implements FabricService {
.matchInPort(PortNumber.portNumber(2))
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPProtocol(IPv4.PROTOCOL_UDP)
.matchUdpDst(radiusPort)
.matchUdpDst(TpPort.tpPort(radiusPort))
.build();
TrafficSelector fromRadius = DefaultTrafficSelector.builder()
.matchInPort(PortNumber.portNumber(5))
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPProtocol(IPv4.PROTOCOL_UDP)
.matchUdpDst(radiusPort)
.matchUdpDst(TpPort.tpPort(radiusPort))
.build();
TrafficTreatment toOlt = DefaultTrafficTreatment.builder()
......
......@@ -32,6 +32,7 @@ import org.onlab.packet.Ip4Prefix;
import org.onlab.packet.Ip6Prefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.TCP;
import org.onlab.packet.TpPort;
import org.onlab.packet.UDP;
import org.onlab.packet.VlanId;
import org.onosproject.cfg.ComponentConfigService;
......@@ -587,14 +588,14 @@ public class ReactiveForwarding {
if (matchTcpUdpPorts && ipv4Protocol == IPv4.PROTOCOL_TCP) {
TCP tcpPacket = (TCP) ipv4Packet.getPayload();
selectorBuilder.matchIPProtocol(ipv4Protocol)
.matchTcpSrc(tcpPacket.getSourcePort())
.matchTcpDst(tcpPacket.getDestinationPort());
.matchTcpSrc(TpPort.tpPort(tcpPacket.getSourcePort()))
.matchTcpDst(TpPort.tpPort(tcpPacket.getDestinationPort()));
}
if (matchTcpUdpPorts && ipv4Protocol == IPv4.PROTOCOL_UDP) {
UDP udpPacket = (UDP) ipv4Packet.getPayload();
selectorBuilder.matchIPProtocol(ipv4Protocol)
.matchUdpSrc(udpPacket.getSourcePort())
.matchUdpDst(udpPacket.getDestinationPort());
.matchUdpSrc(TpPort.tpPort(udpPacket.getSourcePort()))
.matchUdpDst(TpPort.tpPort(udpPacket.getDestinationPort()));
}
if (matchIcmpFields && ipv4Protocol == IPv4.PROTOCOL_ICMP) {
ICMP icmpPacket = (ICMP) ipv4Packet.getPayload();
......@@ -628,14 +629,14 @@ public class ReactiveForwarding {
if (matchTcpUdpPorts && ipv6NextHeader == IPv6.PROTOCOL_TCP) {
TCP tcpPacket = (TCP) ipv6Packet.getPayload();
selectorBuilder.matchIPProtocol(ipv6NextHeader)
.matchTcpSrc(tcpPacket.getSourcePort())
.matchTcpDst(tcpPacket.getDestinationPort());
.matchTcpSrc(TpPort.tpPort(tcpPacket.getSourcePort()))
.matchTcpDst(TpPort.tpPort(tcpPacket.getDestinationPort()));
}
if (matchTcpUdpPorts && ipv6NextHeader == IPv6.PROTOCOL_UDP) {
UDP udpPacket = (UDP) ipv6Packet.getPayload();
selectorBuilder.matchIPProtocol(ipv6NextHeader)
.matchUdpSrc(udpPacket.getSourcePort())
.matchUdpDst(udpPacket.getDestinationPort());
.matchUdpSrc(TpPort.tpPort(udpPacket.getSourcePort()))
.matchUdpDst(TpPort.tpPort(udpPacket.getDestinationPort()));
}
if (matchIcmpFields && ipv6NextHeader == IPv6.PROTOCOL_ICMP6) {
ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
......
......@@ -20,6 +20,7 @@ import org.onlab.packet.IPv4;
import org.onlab.packet.IPv6;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.TpPort;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.flow.DefaultTrafficSelector;
......@@ -321,11 +322,11 @@ public class PeerConnectivityManager {
}
if (srcTcpPort != null) {
builder.matchTcpSrc(srcTcpPort);
builder.matchTcpSrc(TpPort.tpPort(srcTcpPort));
}
if (dstTcpPort != null) {
builder.matchTcpDst(dstTcpPort);
builder.matchTcpDst(TpPort.tpPort(dstTcpPort));
}
return builder.build();
......
......@@ -26,6 +26,7 @@ import org.onlab.packet.IPv4;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint;
......@@ -290,10 +291,10 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
.matchIPDst(IpPrefix.valueOf(dstPrefix));
if (srcTcpPort != null) {
builder.matchTcpSrc(srcTcpPort);
builder.matchTcpSrc(TpPort.tpPort(srcTcpPort));
}
if (dstTcpPort != null) {
builder.matchTcpDst(dstTcpPort);
builder.matchTcpDst(TpPort.tpPort(dstTcpPort));
}
PointToPointIntent intent = PointToPointIntent.builder()
......
......@@ -18,6 +18,7 @@ package org.onosproject.segmentrouting;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.TpPort;
import org.onosproject.cli.net.IpProtocol;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.DeviceId;
......@@ -193,17 +194,17 @@ public class PolicyHandler {
tsb.matchIPProtocol(ipProto.byteValue());
if (IpProtocol.valueOf(policy.ipProto()).equals(IpProtocol.TCP)) {
if (policy.srcPort() != 0) {
tsb.matchTcpSrc(policy.srcPort());
tsb.matchTcpSrc(TpPort.tpPort(policy.srcPort()));
}
if (policy.dstPort() != 0) {
tsb.matchTcpDst(policy.dstPort());
tsb.matchTcpDst(TpPort.tpPort(policy.dstPort()));
}
} else if (IpProtocol.valueOf(policy.ipProto()).equals(IpProtocol.UDP)) {
if (policy.srcPort() != 0) {
tsb.matchUdpSrc(policy.srcPort());
tsb.matchUdpSrc(TpPort.tpPort(policy.srcPort()));
}
if (policy.dstPort() != 0) {
tsb.matchUdpDst(policy.dstPort());
tsb.matchUdpDst(TpPort.tpPort(policy.dstPort()));
}
}
}
......
......@@ -24,6 +24,9 @@ import java.util.List;
import org.apache.karaf.shell.commands.Option;
import org.onlab.packet.Ip6Address;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onlab.util.Bandwidth;
import org.onosproject.cli.AbstractShellCommand;
......@@ -42,8 +45,6 @@ import org.onosproject.net.intent.constraint.LambdaConstraint;
import org.onosproject.net.intent.constraint.LinkTypeConstraint;
import org.onosproject.net.intent.constraint.PartialFailureConstraint;
import org.onosproject.net.resource.link.BandwidthResource;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
/**
* Base class for command line operations for connectivity based intents.
......@@ -266,11 +267,11 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
}
if (!isNullOrEmpty(srcTcpString)) {
selectorBuilder.matchTcpSrc((short) Integer.parseInt(srcTcpString));
selectorBuilder.matchTcpSrc(TpPort.tpPort(Integer.parseInt(srcTcpString)));
}
if (!isNullOrEmpty(dstTcpString)) {
selectorBuilder.matchTcpDst((short) Integer.parseInt(dstTcpString));
selectorBuilder.matchTcpDst(TpPort.tpPort(Integer.parseInt(dstTcpString)));
}
if (extHdrStringList != null) {
......
......@@ -21,6 +21,7 @@ import org.onlab.packet.Ip6Address;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onosproject.net.IndexedLambda;
import org.onosproject.net.PortNumber;
......@@ -208,37 +209,73 @@ public final class DefaultTrafficSelector implements TrafficSelector {
return add(Criteria.matchIPDst(ip));
}
@Deprecated
@Override
public Builder matchTcpSrc(short tcpPort) {
return add(Criteria.matchTcpSrc(tcpPort));
}
@Override
public Builder matchTcpSrc(TpPort tcpPort) {
return add(Criteria.matchTcpSrc(tcpPort));
}
@Deprecated
@Override
public Builder matchTcpDst(short tcpPort) {
return add(Criteria.matchTcpDst(tcpPort));
}
@Override
public Builder matchTcpDst(TpPort tcpPort) {
return add(Criteria.matchTcpDst(tcpPort));
}
@Deprecated
@Override
public Builder matchUdpSrc(short udpPort) {
return add(Criteria.matchUdpSrc(udpPort));
}
@Override
public Builder matchUdpSrc(TpPort udpPort) {
return add(Criteria.matchUdpSrc(udpPort));
}
@Deprecated
@Override
public Builder matchUdpDst(short udpPort) {
return add(Criteria.matchUdpDst(udpPort));
}
@Override
public Builder matchUdpDst(TpPort udpPort) {
return add(Criteria.matchUdpDst(udpPort));
}
@Deprecated
@Override
public Builder matchSctpSrc(short sctpPort) {
return add(Criteria.matchSctpSrc(sctpPort));
}
@Override
public Builder matchSctpSrc(TpPort sctpPort) {
return add(Criteria.matchSctpSrc(sctpPort));
}
@Deprecated
@Override
public Builder matchSctpDst(short sctpPort) {
return add(Criteria.matchSctpDst(sctpPort));
}
@Override
public Builder matchSctpDst(TpPort sctpPort) {
return add(Criteria.matchSctpDst(sctpPort));
}
@Override
public Builder matchIcmpType(byte icmpType) {
return add(Criteria.matchIcmpType(icmpType));
}
......
......@@ -22,6 +22,7 @@ import org.onlab.packet.EthType;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onosproject.core.GroupId;
import org.onosproject.net.IndexedLambda;
......@@ -416,27 +417,51 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
return add(Instructions.modTunnelId(tunnelId));
}
@Deprecated
@Override
public TrafficTreatment.Builder setTcpSrc(short port) {
return add(Instructions.modTcpSrc(port));
}
@Override
public TrafficTreatment.Builder setTcpSrc(TpPort port) {
return add(Instructions.modTcpSrc(port));
}
@Deprecated
@Override
public TrafficTreatment.Builder setTcpDst(short port) {
return add(Instructions.modTcpDst(port));
}
@Override
public TrafficTreatment.Builder setTcpDst(TpPort port) {
return add(Instructions.modTcpDst(port));
}
@Deprecated
@Override
public TrafficTreatment.Builder setUdpSrc(short port) {
return add(Instructions.modUdpSrc(port));
}
@Override
public TrafficTreatment.Builder setUdpSrc(TpPort port) {
return add(Instructions.modUdpSrc(port));
}
@Deprecated
@Override
public TrafficTreatment.Builder setUdpDst(short port) {
return add(Instructions.modUdpDst(port));
}
@Override
public TrafficTreatment.Builder setUdpDst(TpPort port) {
return add(Instructions.modUdpDst(port));
}
@Override
public TrafficTreatment build() {
//Don't add DROP instruction by default when instruction
//set is empty. This will be handled in DefaultSingleTablePipeline
......
......@@ -17,14 +17,15 @@ package org.onosproject.net.flow;
import java.util.Set;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.DefaultTrafficSelector.Builder;
import org.onosproject.net.flow.criteria.Criterion;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.Ip6Address;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.DefaultTrafficSelector.Builder;
import org.onosproject.net.flow.criteria.Criterion;
/**
* Abstraction of a slice of network traffic.
......@@ -170,50 +171,110 @@ public interface TrafficSelector {
*
* @param tcpPort a TCP source port number
* @return a selection builder
* @deprecated in Drake release
*/
@Deprecated
Builder matchTcpSrc(short tcpPort);
/**
* Matches a TCP source port number.
*
* @param tcpPort a TCP source port number
* @return a selection builder
*/
Builder matchTcpSrc(TpPort tcpPort);
/**
* Matches a TCP destination port number.
*
* @param tcpPort a TCP destination port number
* @return a selection builder
* @deprecated in Drake release
*/
@Deprecated
Builder matchTcpDst(short tcpPort);
/**
* Matches a TCP destination port number.
*
* @param tcpPort a TCP destination port number
* @return a selection builder
*/
Builder matchTcpDst(TpPort tcpPort);
/**
* Matches an UDP source port number.
*
* @param udpPort an UDP source port number
* @return a selection builder
* @deprecated in Drake release
*/
@Deprecated
Builder matchUdpSrc(short udpPort);
/**
* Matches an UDP source port number.
*
* @param udpPort an UDP source port number
* @return a selection builder
*/
Builder matchUdpSrc(TpPort udpPort);
/**
* Matches an UDP destination port number.
*
* @param udpPort an UDP destination port number
* @return a selection builder
* @deprecated in Drake release
*/
@Deprecated
Builder matchUdpDst(short udpPort);
/**
* Matches an UDP destination port number.
*
* @param udpPort an UDP destination port number
* @return a selection builder
*/
Builder matchUdpDst(TpPort udpPort);
/**
* Matches a SCTP source port number.
*
* @param sctpPort a SCTP source port number
* @return a selection builder
* @deprecated in Drake release
*/
@Deprecated
Builder matchSctpSrc(short sctpPort);
/**
* Matches a SCTP source port number.
*
* @param sctpPort a SCTP source port number
* @return a selection builder
*/
Builder matchSctpSrc(TpPort sctpPort);
/**
* Matches a SCTP destination port number.
*
* @param sctpPort a SCTP destination port number
* @return a selection builder
* @deprecated in Drake release
*/
@Deprecated
Builder matchSctpDst(short sctpPort);
/**
* Matches a SCTP destination port number.
*
* @param sctpPort a SCTP destination port number
* @return a selection builder
*/
Builder matchSctpDst(TpPort sctpPort);
/**
* Matches an ICMP type.
*
* @param icmpType an ICMP type
......
......@@ -19,6 +19,7 @@ import org.onlab.packet.EthType;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onosproject.core.GroupId;
import org.onosproject.net.PortNumber;
......@@ -346,34 +347,74 @@ public interface TrafficTreatment {
*
* @param port a port number
* @return a treatment builder
* @deprecated in Drake release
*/
@Deprecated
Builder setTcpSrc(short port);
/**
* Sets the src TCP port.
*
* @param port a port number
* @return a treatment builder
*/
Builder setTcpSrc(TpPort port);
/**
* Sets the dst TCP port.
*
* @param port a port number
* @return a treatment builder
* @deprecated in Drake release
*/
@Deprecated
Builder setTcpDst(short port);
/**
* Sets the dst TCP port.
*
* @param port a port number
* @return a treatment builder
*/
Builder setTcpDst(TpPort port);
/**
* Sets the src UDP port.
*
* @param port a port number
* @return a treatment builder
* @deprecated in Drake release
*/
@Deprecated
Builder setUdpSrc(short port);
/**
* Sets the src UDP port.
*
* @param port a port number
* @return a treatment builder
*/
Builder setUdpSrc(TpPort port);
/**
* Sets the dst UDP port.
*
* @param port a port number
* @return a treatment builder
* @deprecated in Drake release
*/
@Deprecated
Builder setUdpDst(short port);
/**
* Sets the dst UDP port.
*
* @param port a port number
* @return a treatment builder
*/
Builder setUdpDst(TpPort port);
/**
* Builds an immutable traffic treatment descriptor.
* <p>
* If the treatment is empty when build() is called, it will add a default
......
......@@ -16,16 +16,17 @@
package org.onosproject.net.flow.criteria;
import org.onlab.packet.EthType;
import org.onlab.packet.Ip6Address;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onosproject.net.IndexedLambda;
import org.onosproject.net.Lambda;
import org.onosproject.net.OchSignal;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.criteria.Criterion.Type;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.Ip6Address;
import org.onlab.packet.MacAddress;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.VlanId;
import org.onosproject.net.OchSignalType;
/**
......@@ -184,50 +185,110 @@ public final class Criteria {
/**
* Creates a match on TCP source port field using the specified value.
*
* @param tcpPort TCP source port (16 bits unsigned integer)
* @param tcpPort TCP source port
* @return match criterion
* @deprecated in Drake release
*/
@Deprecated
public static Criterion matchTcpSrc(short tcpPort) {
return new TcpPortCriterion(TpPort.tpPort(tcpPort), Type.TCP_SRC);
}
/**
* Creates a match on TCP source port field using the specified value.
*
* @param tcpPort TCP source port
* @return match criterion
*/
public static Criterion matchTcpSrc(int tcpPort) {
public static Criterion matchTcpSrc(TpPort tcpPort) {
return new TcpPortCriterion(tcpPort, Type.TCP_SRC);
}
/**
* Creates a match on TCP destination port field using the specified value.
*
* @param tcpPort TCP destination port (16 bits unsigned integer)
* @param tcpPort TCP destination port
* @return match criterion
* @deprecated in Drake release
*/
public static Criterion matchTcpDst(int tcpPort) {
@Deprecated
public static Criterion matchTcpDst(short tcpPort) {
return new TcpPortCriterion(TpPort.tpPort(tcpPort), Type.TCP_DST);
}
/**
* Creates a match on TCP destination port field using the specified value.
*
* @param tcpPort TCP destination port
* @return match criterion
*/
public static Criterion matchTcpDst(TpPort tcpPort) {
return new TcpPortCriterion(tcpPort, Type.TCP_DST);
}
/**
* Creates a match on UDP source port field using the specified value.
*
* @param udpPort UDP source port (16 bits unsigned integer)
* @param udpPort UDP source port
* @return match criterion
* @deprecated in Drake release
*/
public static Criterion matchUdpSrc(int udpPort) {
@Deprecated
public static Criterion matchUdpSrc(short udpPort) {
return new UdpPortCriterion(TpPort.tpPort(udpPort), Type.UDP_SRC);
}
/**
* Creates a match on UDP source port field using the specified value.
*
* @param udpPort UDP source port
* @return match criterion
*/
public static Criterion matchUdpSrc(TpPort udpPort) {
return new UdpPortCriterion(udpPort, Type.UDP_SRC);
}
/**
* Creates a match on UDP destination port field using the specified value.
*
* @param udpPort UDP destination port (16 bits unsigned integer)
* @param udpPort UDP destination port
* @return match criterion
* @deprecated in Drake release
*/
public static Criterion matchUdpDst(int udpPort) {
@Deprecated
public static Criterion matchUdpDst(short udpPort) {
return new UdpPortCriterion(TpPort.tpPort(udpPort), Type.UDP_DST);
}
/**
* Creates a match on UDP destination port field using the specified value.
*
* @param udpPort UDP destination port
* @return match criterion
*/
public static Criterion matchUdpDst(TpPort udpPort) {
return new UdpPortCriterion(udpPort, Type.UDP_DST);
}
/**
* Creates a match on SCTP source port field using the specified value.
*
* @param sctpPort SCTP source port (16 bits unsigned integer)
* @param sctpPort SCTP source port
* @return match criterion
* @deprecated in Drake release
*/
public static Criterion matchSctpSrc(int sctpPort) {
@Deprecated
public static Criterion matchSctpSrc(short sctpPort) {
return new SctpPortCriterion(TpPort.tpPort(sctpPort), Type.SCTP_SRC);
}
/**
* Creates a match on SCTP source port field using the specified value.
*
* @param sctpPort SCTP source port
* @return match criterion
*/
public static Criterion matchSctpSrc(TpPort sctpPort) {
return new SctpPortCriterion(sctpPort, Type.SCTP_SRC);
}
......@@ -235,10 +296,23 @@ public final class Criteria {
* Creates a match on SCTP destination port field using the specified
* value.
*
* @param sctpPort SCTP destination port (16 bits unsigned integer)
* @param sctpPort SCTP destination port
* @return match criterion
* @deprecated in Drake release
*/
@Deprecated
public static Criterion matchSctpDst(short sctpPort) {
return new SctpPortCriterion(TpPort.tpPort(sctpPort), Type.SCTP_DST);
}
/**
* Creates a match on SCTP destination port field using the specified
* value.
*
* @param sctpPort SCTP destination port
* @return match criterion
*/
public static Criterion matchSctpDst(int sctpPort) {
public static Criterion matchSctpDst(TpPort sctpPort) {
return new SctpPortCriterion(sctpPort, Type.SCTP_DST);
}
......
......@@ -15,6 +15,8 @@
*/
package org.onosproject.net.flow.criteria;
import org.onlab.packet.TpPort;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
......@@ -23,19 +25,18 @@ import static com.google.common.base.MoreObjects.toStringHelper;
* Implementation of SCTP port criterion (16 bits unsigned integer).
*/
public final class SctpPortCriterion implements Criterion {
private static final int MASK = 0xffff;
private final int sctpPort; // Port value: 16 bits
private final TpPort sctpPort;
private final Type type;
/**
* Constructor.
*
* @param sctpPort the SCTP port to match (16 bits unsigned integer)
* @param sctpPort the SCTP port to match
* @param type the match type. Should be either Type.SCTP_SRC or
* Type.SCTP_DST
*/
SctpPortCriterion(int sctpPort, Type type) {
this.sctpPort = sctpPort & MASK;
SctpPortCriterion(TpPort sctpPort, Type type) {
this.sctpPort = sctpPort;
this.type = type;
}
......@@ -47,9 +48,9 @@ public final class SctpPortCriterion implements Criterion {
/**
* Gets the SCTP port to match.
*
* @return the SCTP port to match (16 bits unsigned integer)
* @return the SCTP port to match
*/
public int sctpPort() {
public TpPort sctpPort() {
return this.sctpPort;
}
......
......@@ -15,6 +15,8 @@
*/
package org.onosproject.net.flow.criteria;
import org.onlab.packet.TpPort;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
......@@ -23,19 +25,18 @@ import static com.google.common.base.MoreObjects.toStringHelper;
* Implementation of TCP port criterion (16 bits unsigned integer).
*/
public final class TcpPortCriterion implements Criterion {
private static final int MASK = 0xffff;
private final int tcpPort; // Port value: 16 bits
private final TpPort tcpPort;
private final Type type;
/**
* Constructor.
*
* @param tcpPort the TCP port to match (16 bits unsigned integer)
* @param tcpPort the TCP port to match
* @param type the match type. Should be either Type.TCP_SRC or
* Type.TCP_DST
*/
TcpPortCriterion(int tcpPort, Type type) {
this.tcpPort = tcpPort & MASK;
TcpPortCriterion(TpPort tcpPort, Type type) {
this.tcpPort = tcpPort;
this.type = type;
}
......@@ -47,9 +48,9 @@ public final class TcpPortCriterion implements Criterion {
/**
* Gets the TCP port to match.
*
* @return the TCP port to match (16 bits unsigned integer)
* @return the TCP port to match
*/
public int tcpPort() {
public TpPort tcpPort() {
return this.tcpPort;
}
......
......@@ -15,6 +15,8 @@
*/
package org.onosproject.net.flow.criteria;
import org.onlab.packet.TpPort;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
......@@ -23,19 +25,18 @@ import static com.google.common.base.MoreObjects.toStringHelper;
* Implementation of UDP port criterion (16 bits unsigned integer).
*/
public final class UdpPortCriterion implements Criterion {
private static final int MASK = 0xffff;
private final int udpPort; // Port value: 16 bits
private final TpPort udpPort;
private final Type type;
/**
* Constructor.
*
* @param udpPort the UDP port to match (16 bits unsigned integer)
* @param udpPort the UDP port to match
* @param type the match type. Should be either Type.UDP_SRC or
* Type.UDP_DST
*/
UdpPortCriterion(int udpPort, Type type) {
this.udpPort = udpPort & MASK;
UdpPortCriterion(TpPort udpPort, Type type) {
this.udpPort = udpPort;
this.type = type;
}
......@@ -47,9 +48,9 @@ public final class UdpPortCriterion implements Criterion {
/**
* Gets the UDP port to match.
*
* @return the UDP port to match (16 bits unsigned integer)
* @return the UDP port to match
*/
public int udpPort() {
public TpPort udpPort() {
return this.udpPort;
}
......
......@@ -19,6 +19,7 @@ import org.onlab.packet.EthType;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onosproject.core.GroupId;
import org.onosproject.net.IndexedLambda;
......@@ -383,9 +384,22 @@ public final class Instructions {
*
* @param port the TCP port number to modify to
* @return a L4 modification
* @deprecated in Drake release
*/
@Deprecated
public static L4ModificationInstruction modTcpSrc(short port) {
checkNotNull(port, "Src TCP port cannot be null");
return new ModTransportPortInstruction(L4SubType.TCP_SRC, TpPort.tpPort(port));
}
/**
* Creates a TCP src modification.
*
* @param port the TCP port number to modify to
* @return a L4 modification
*/
public static L4ModificationInstruction modTcpSrc(TpPort port) {
checkNotNull(port, "Src TCP port cannot be null");
return new ModTransportPortInstruction(L4SubType.TCP_SRC, port);
}
......@@ -394,9 +408,22 @@ public final class Instructions {
*
* @param port the TCP port number to modify to
* @return a L4 modification
* @deprecated in Drake release
*/
@Deprecated
public static L4ModificationInstruction modTcpDst(short port) {
checkNotNull(port, "Dst TCP port cannot be null");
return new ModTransportPortInstruction(L4SubType.TCP_DST, TpPort.tpPort(port));
}
/**
* Creates a TCP dst modification.
*
* @param port the TCP port number to modify to
* @return a L4 modification
*/
public static L4ModificationInstruction modTcpDst(TpPort port) {
checkNotNull(port, "Dst TCP port cannot be null");
return new ModTransportPortInstruction(L4SubType.TCP_DST, port);
}
......@@ -405,9 +432,22 @@ public final class Instructions {
*
* @param port the UDP port number to modify to
* @return a L4 modification
* @deprecated in Drake release
*/
@Deprecated
public static L4ModificationInstruction modUdpSrc(short port) {
checkNotNull(port, "Src UDP port cannot be null");
return new ModTransportPortInstruction(L4SubType.UDP_SRC, TpPort.tpPort(port));
}
/**
* Creates a UDP src modification.
*
* @param port the UDP port number to modify to
* @return a L4 modification
*/
public static L4ModificationInstruction modUdpSrc(TpPort port) {
checkNotNull(port, "Src UDP port cannot be null");
return new ModTransportPortInstruction(L4SubType.UDP_SRC, port);
}
......@@ -416,9 +456,22 @@ public final class Instructions {
*
* @param port the UDP port number to modify to
* @return a L4 modification
* @deprecated in Drake release
*/
@Deprecated
public static L4ModificationInstruction modUdpDst(short port) {
checkNotNull(port, "Dst UDP port cannot be null");
return new ModTransportPortInstruction(L4SubType.UDP_DST, TpPort.tpPort(port));
}
/**
* Creates a UDP dst modification.
*
* @param port the UDP port number to modify to
* @return a L4 modification
*/
public static L4ModificationInstruction modUdpDst(TpPort port) {
checkNotNull(port, "Dst UDP port cannot be null");
return new ModTransportPortInstruction(L4SubType.UDP_DST, port);
}
......
......@@ -15,6 +15,8 @@
*/
package org.onosproject.net.flow.instructions;
import org.onlab.packet.TpPort;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
......@@ -69,9 +71,9 @@ public abstract class L4ModificationInstruction implements Instruction {
public static final class ModTransportPortInstruction extends L4ModificationInstruction {
private final L4SubType subtype;
private final short port;
private final TpPort port;
public ModTransportPortInstruction(L4SubType subtype, short port) {
public ModTransportPortInstruction(L4SubType subtype, TpPort port) {
this.subtype = subtype;
this.port = port;
}
......@@ -81,7 +83,7 @@ public abstract class L4ModificationInstruction implements Instruction {
return this.subtype;
}
public short port() {
public TpPort port() {
return this.port;
}
......
......@@ -22,15 +22,16 @@ import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.Test;
import org.onosproject.net.IndexedLambda;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.criteria.Criteria;
import org.onosproject.net.flow.criteria.Criterion;
import org.onlab.packet.Ip6Address;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onosproject.net.IndexedLambda;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.criteria.Criteria;
import org.onosproject.net.flow.criteria.Criterion;
import com.google.common.testing.EqualsTester;
......@@ -196,27 +197,27 @@ public class DefaultTrafficSelectorTest {
assertThat(selector, hasCriterionWithType(Type.IPV4_DST));
selector = DefaultTrafficSelector.builder()
.matchTcpSrc(shortValue).build();
.matchTcpSrc(TpPort.tpPort(intValue)).build();
assertThat(selector, hasCriterionWithType(Type.TCP_SRC));
selector = DefaultTrafficSelector.builder()
.matchTcpDst(shortValue).build();
.matchTcpDst(TpPort.tpPort(intValue)).build();
assertThat(selector, hasCriterionWithType(Type.TCP_DST));
selector = DefaultTrafficSelector.builder()
.matchUdpSrc(shortValue).build();
.matchUdpSrc(TpPort.tpPort(intValue)).build();
assertThat(selector, hasCriterionWithType(Type.UDP_SRC));
selector = DefaultTrafficSelector.builder()
.matchUdpDst(shortValue).build();
.matchUdpDst(TpPort.tpPort(intValue)).build();
assertThat(selector, hasCriterionWithType(Type.UDP_DST));
selector = DefaultTrafficSelector.builder()
.matchSctpSrc(shortValue).build();
.matchSctpSrc(TpPort.tpPort(intValue)).build();
assertThat(selector, hasCriterionWithType(Type.SCTP_SRC));
selector = DefaultTrafficSelector.builder()
.matchSctpDst(shortValue).build();
.matchSctpDst(TpPort.tpPort(intValue)).build();
assertThat(selector, hasCriterionWithType(Type.SCTP_DST));
selector = DefaultTrafficSelector.builder()
......
......@@ -17,15 +17,16 @@ package org.onosproject.net.flow.criteria;
import org.junit.Test;
import org.onlab.packet.EthType;
import org.onosproject.net.ChannelSpacing;
import org.onosproject.net.GridType;
import org.onosproject.net.Lambda;
import org.onosproject.net.PortNumber;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.Ip6Address;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onosproject.net.ChannelSpacing;
import org.onosproject.net.GridType;
import org.onosproject.net.Lambda;
import org.onosproject.net.PortNumber;
import com.google.common.testing.EqualsTester;
import org.onosproject.net.OchSignalType;
......@@ -122,17 +123,19 @@ public class CriteriaTest {
Criterion sameAsMatchIpv61 = Criteria.matchIPSrc(ipv61);
Criterion matchIpv62 = Criteria.matchIPSrc(ipv62);
Criterion matchTcpPort1 = Criteria.matchTcpSrc(1);
Criterion sameAsMatchTcpPort1 = Criteria.matchTcpSrc(1);
Criterion matchTcpPort2 = Criteria.matchTcpDst(2);
private TpPort tpPort1 = TpPort.tpPort(1);
private TpPort tpPort2 = TpPort.tpPort(2);
Criterion matchTcpPort1 = Criteria.matchTcpSrc(tpPort1);
Criterion sameAsMatchTcpPort1 = Criteria.matchTcpSrc(tpPort1);
Criterion matchTcpPort2 = Criteria.matchTcpDst(tpPort2);
Criterion matchUdpPort1 = Criteria.matchUdpSrc(1);
Criterion sameAsMatchUdpPort1 = Criteria.matchUdpSrc(1);
Criterion matchUdpPort2 = Criteria.matchUdpDst(2);
Criterion matchUdpPort1 = Criteria.matchUdpSrc(tpPort1);
Criterion sameAsMatchUdpPort1 = Criteria.matchUdpSrc(tpPort1);
Criterion matchUdpPort2 = Criteria.matchUdpDst(tpPort2);
Criterion matchSctpPort1 = Criteria.matchSctpSrc(1);
Criterion sameAsMatchSctpPort1 = Criteria.matchSctpSrc(1);
Criterion matchSctpPort2 = Criteria.matchSctpDst(2);
Criterion matchSctpPort1 = Criteria.matchSctpSrc(tpPort1);
Criterion sameAsMatchSctpPort1 = Criteria.matchSctpSrc(tpPort1);
Criterion matchSctpPort2 = Criteria.matchSctpDst(tpPort2);
short icmpType1 = 1;
short icmpType2 = 2;
......@@ -652,12 +655,12 @@ public class CriteriaTest {
*/
@Test
public void testMatchTcpSrcMethod() {
Criterion matchTcpSrc = Criteria.matchTcpSrc(1);
Criterion matchTcpSrc = Criteria.matchTcpSrc(tpPort1);
TcpPortCriterion tcpPortCriterion =
checkAndConvert(matchTcpSrc,
Criterion.Type.TCP_SRC,
TcpPortCriterion.class);
assertThat(tcpPortCriterion.tcpPort(), is(equalTo(1)));
assertThat(tcpPortCriterion.tcpPort(), is(equalTo(tpPort1)));
}
/**
......@@ -665,12 +668,12 @@ public class CriteriaTest {
*/
@Test
public void testMatchTcpDstMethod() {
Criterion matchTcpDst = Criteria.matchTcpDst(1);
Criterion matchTcpDst = Criteria.matchTcpDst(tpPort1);
TcpPortCriterion tcpPortCriterion =
checkAndConvert(matchTcpDst,
Criterion.Type.TCP_DST,
TcpPortCriterion.class);
assertThat(tcpPortCriterion.tcpPort(), is(equalTo(1)));
assertThat(tcpPortCriterion.tcpPort(), is(equalTo(tpPort1)));
}
/**
......@@ -691,12 +694,12 @@ public class CriteriaTest {
*/
@Test
public void testMatchUdpSrcMethod() {
Criterion matchUdpSrc = Criteria.matchUdpSrc(1);
Criterion matchUdpSrc = Criteria.matchUdpSrc(tpPort1);
UdpPortCriterion udpPortCriterion =
checkAndConvert(matchUdpSrc,
Criterion.Type.UDP_SRC,
UdpPortCriterion.class);
assertThat(udpPortCriterion.udpPort(), is(equalTo(1)));
assertThat(udpPortCriterion.udpPort(), is(equalTo(tpPort1)));
}
/**
......@@ -704,12 +707,12 @@ public class CriteriaTest {
*/
@Test
public void testMatchUdpDstMethod() {
Criterion matchUdpDst = Criteria.matchUdpDst(1);
Criterion matchUdpDst = Criteria.matchUdpDst(tpPort1);
UdpPortCriterion udpPortCriterion =
checkAndConvert(matchUdpDst,
Criterion.Type.UDP_DST,
UdpPortCriterion.class);
assertThat(udpPortCriterion.udpPort(), is(equalTo(1)));
assertThat(udpPortCriterion.udpPort(), is(equalTo(tpPort1)));
}
/**
......@@ -730,12 +733,12 @@ public class CriteriaTest {
*/
@Test
public void testMatchSctpSrcMethod() {
Criterion matchSctpSrc = Criteria.matchSctpSrc(1);
Criterion matchSctpSrc = Criteria.matchSctpSrc(tpPort1);
SctpPortCriterion sctpPortCriterion =
checkAndConvert(matchSctpSrc,
Criterion.Type.SCTP_SRC,
SctpPortCriterion.class);
assertThat(sctpPortCriterion.sctpPort(), is(equalTo(1)));
assertThat(sctpPortCriterion.sctpPort(), is(equalTo(tpPort1)));
}
/**
......@@ -743,12 +746,12 @@ public class CriteriaTest {
*/
@Test
public void testMatchSctpDstMethod() {
Criterion matchSctpDst = Criteria.matchSctpDst(1);
Criterion matchSctpDst = Criteria.matchSctpDst(tpPort1);
SctpPortCriterion sctpPortCriterion =
checkAndConvert(matchSctpDst,
Criterion.Type.SCTP_DST,
SctpPortCriterion.class);
assertThat(sctpPortCriterion.sctpPort(), is(equalTo(1)));
assertThat(sctpPortCriterion.sctpPort(), is(equalTo(tpPort1)));
}
/**
......
......@@ -16,15 +16,16 @@
package org.onosproject.net.flow.instructions;
import org.junit.Test;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onosproject.net.ChannelSpacing;
import org.onosproject.net.GridType;
import org.onosproject.net.IndexedLambda;
import org.onosproject.net.Lambda;
import org.onosproject.net.PortNumber;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.VlanId;
import com.google.common.testing.EqualsTester;
......@@ -638,22 +639,22 @@ public class InstructionsTest {
// ModTransportPortInstruction
private final short l4port1 = 1;
private final short l4port2 = 2;
private final Instruction modTransportPortInstruction1 = Instructions.modTcpSrc(l4port1);
private final Instruction sameAsModTransportPortInstruction1 = Instructions.modTcpSrc(l4port1);
private final Instruction modTransportPortInstruction2 = Instructions.modTcpSrc(l4port2);
private final TpPort tpPort1 = TpPort.tpPort(1);
private final TpPort tpPort2 = TpPort.tpPort(2);
private final Instruction modTransportPortInstruction1 = Instructions.modTcpSrc(tpPort1);
private final Instruction sameAsModTransportPortInstruction1 = Instructions.modTcpSrc(tpPort1);
private final Instruction modTransportPortInstruction2 = Instructions.modTcpSrc(tpPort2);
/**
* Test the modTcpSrc() method.
*/
@Test
public void testModTcpSrcMethod() {
final Instruction instruction = Instructions.modTcpSrc(l4port1);
final Instruction instruction = Instructions.modTcpSrc(tpPort1);
final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
L4ModificationInstruction.ModTransportPortInstruction.class);
assertThat(modTransportPortInstruction.port(), is(equalTo(l4port1)));
assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
assertThat(modTransportPortInstruction.subtype(),
is(equalTo(L4ModificationInstruction.L4SubType.TCP_SRC)));
}
......@@ -663,11 +664,11 @@ public class InstructionsTest {
*/
@Test
public void testModTcpDstMethod() {
final Instruction instruction = Instructions.modTcpDst(l4port1);
final Instruction instruction = Instructions.modTcpDst(tpPort1);
final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
L4ModificationInstruction.ModTransportPortInstruction.class);
assertThat(modTransportPortInstruction.port(), is(equalTo(l4port1)));
assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
assertThat(modTransportPortInstruction.subtype(),
is(equalTo(L4ModificationInstruction.L4SubType.TCP_DST)));
}
......@@ -677,11 +678,11 @@ public class InstructionsTest {
*/
@Test
public void testModUdpSrcMethod() {
final Instruction instruction = Instructions.modUdpSrc(l4port1);
final Instruction instruction = Instructions.modUdpSrc(tpPort1);
final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
L4ModificationInstruction.ModTransportPortInstruction.class);
assertThat(modTransportPortInstruction.port(), is(equalTo(l4port1)));
assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
assertThat(modTransportPortInstruction.subtype(),
is(equalTo(L4ModificationInstruction.L4SubType.UDP_SRC)));
}
......@@ -691,11 +692,11 @@ public class InstructionsTest {
*/
@Test
public void testModUdpDstMethod() {
final Instruction instruction = Instructions.modUdpDst(l4port1);
final Instruction instruction = Instructions.modUdpDst(tpPort1);
final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
L4ModificationInstruction.ModTransportPortInstruction.class);
assertThat(modTransportPortInstruction.port(), is(equalTo(l4port1)));
assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
assertThat(modTransportPortInstruction.subtype(),
is(equalTo(L4ModificationInstruction.L4SubType.UDP_DST)));
}
......
......@@ -22,6 +22,7 @@ import org.onlab.packet.Ip6Address;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onosproject.net.ChannelSpacing;
import org.onosproject.net.GridType;
......@@ -241,8 +242,8 @@ public final class DecodeCriterionCodecHelper {
private class TcpSrcDecoder implements CriterionDecoder {
@Override
public Criterion decodeCriterion(ObjectNode json) {
int tcpPort = nullIsIllegal(json.get(CriterionCodec.TCP_PORT),
CriterionCodec.TCP_PORT + MISSING_MEMBER_MESSAGE).asInt();
TpPort tcpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.TCP_PORT),
CriterionCodec.TCP_PORT + MISSING_MEMBER_MESSAGE).asInt());
return Criteria.matchTcpSrc(tcpPort);
}
}
......@@ -250,8 +251,8 @@ public final class DecodeCriterionCodecHelper {
private class TcpDstDecoder implements CriterionDecoder {
@Override
public Criterion decodeCriterion(ObjectNode json) {
int tcpPort = nullIsIllegal(json.get(CriterionCodec.TCP_PORT),
CriterionCodec.TCP_PORT + MISSING_MEMBER_MESSAGE).asInt();
TpPort tcpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.TCP_PORT),
CriterionCodec.TCP_PORT + MISSING_MEMBER_MESSAGE).asInt());
return Criteria.matchTcpDst(tcpPort);
}
}
......@@ -259,8 +260,8 @@ public final class DecodeCriterionCodecHelper {
private class UdpSrcDecoder implements CriterionDecoder {
@Override
public Criterion decodeCriterion(ObjectNode json) {
int udpPort = nullIsIllegal(json.get(CriterionCodec.UDP_PORT),
CriterionCodec.UDP_PORT + MISSING_MEMBER_MESSAGE).asInt();
TpPort udpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.UDP_PORT),
CriterionCodec.UDP_PORT + MISSING_MEMBER_MESSAGE).asInt());
return Criteria.matchUdpSrc(udpPort);
}
}
......@@ -268,8 +269,8 @@ public final class DecodeCriterionCodecHelper {
private class UdpDstDecoder implements CriterionDecoder {
@Override
public Criterion decodeCriterion(ObjectNode json) {
int udpPort = nullIsIllegal(json.get(CriterionCodec.UDP_PORT),
CriterionCodec.UDP_PORT + MISSING_MEMBER_MESSAGE).asInt();
TpPort udpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.UDP_PORT),
CriterionCodec.UDP_PORT + MISSING_MEMBER_MESSAGE).asInt());
return Criteria.matchUdpDst(udpPort);
}
}
......@@ -277,8 +278,8 @@ public final class DecodeCriterionCodecHelper {
private class SctpSrcDecoder implements CriterionDecoder {
@Override
public Criterion decodeCriterion(ObjectNode json) {
int sctpPort = nullIsIllegal(json.get(CriterionCodec.SCTP_PORT),
CriterionCodec.SCTP_PORT + MISSING_MEMBER_MESSAGE).asInt();
TpPort sctpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.SCTP_PORT),
CriterionCodec.SCTP_PORT + MISSING_MEMBER_MESSAGE).asInt());
return Criteria.matchSctpSrc(sctpPort);
}
}
......@@ -286,8 +287,8 @@ public final class DecodeCriterionCodecHelper {
private class SctpDstDecoder implements CriterionDecoder {
@Override
public Criterion decodeCriterion(ObjectNode json) {
int sctpPort = nullIsIllegal(json.get(CriterionCodec.SCTP_PORT),
CriterionCodec.SCTP_PORT + MISSING_MEMBER_MESSAGE).asInt();
TpPort sctpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.SCTP_PORT),
CriterionCodec.SCTP_PORT + MISSING_MEMBER_MESSAGE).asInt());
return Criteria.matchSctpDst(sctpPort);
}
}
......
......@@ -228,7 +228,7 @@ public final class EncodeCriterionCodecHelper {
public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) {
final TcpPortCriterion tcpPortCriterion =
(TcpPortCriterion) criterion;
return root.put(CriterionCodec.TCP_PORT, tcpPortCriterion.tcpPort());
return root.put(CriterionCodec.TCP_PORT, tcpPortCriterion.tcpPort().toInt());
}
}
......@@ -237,7 +237,7 @@ public final class EncodeCriterionCodecHelper {
public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) {
final UdpPortCriterion udpPortCriterion =
(UdpPortCriterion) criterion;
return root.put(CriterionCodec.UDP_PORT, udpPortCriterion.udpPort());
return root.put(CriterionCodec.UDP_PORT, udpPortCriterion.udpPort().toInt());
}
}
......@@ -246,7 +246,7 @@ public final class EncodeCriterionCodecHelper {
public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) {
final SctpPortCriterion sctpPortCriterion =
(SctpPortCriterion) criterion;
return root.put(CriterionCodec.SCTP_PORT, sctpPortCriterion.sctpPort());
return root.put(CriterionCodec.SCTP_PORT, sctpPortCriterion.sctpPort().toInt());
}
}
......
......@@ -23,6 +23,7 @@ import org.onlab.packet.Ip6Address;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
......@@ -54,6 +55,7 @@ public class CriterionCodecTest {
final IpPrefix ipPrefix4 = IpPrefix.valueOf("10.1.1.0/24");
final IpPrefix ipPrefix6 = IpPrefix.valueOf("fe80::/64");
final MacAddress mac1 = MacAddress.valueOf("00:00:11:00:00:01");
final TpPort tpPort = TpPort.tpPort(40000);
/**
* Sets up for each test. Creates a context and fetches the criterion
......@@ -219,7 +221,7 @@ public class CriterionCodecTest {
*/
@Test
public void matchTcpSrcTest() {
Criterion criterion = Criteria.matchTcpSrc((short) 40000);
Criterion criterion = Criteria.matchTcpSrc(tpPort);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result, matchesCriterion(criterion));
}
......@@ -229,7 +231,7 @@ public class CriterionCodecTest {
*/
@Test
public void matchTcpDstTest() {
Criterion criterion = Criteria.matchTcpDst((short) 40000);
Criterion criterion = Criteria.matchTcpDst(tpPort);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result, matchesCriterion(criterion));
}
......@@ -239,7 +241,7 @@ public class CriterionCodecTest {
*/
@Test
public void matchUdpSrcTest() {
Criterion criterion = Criteria.matchUdpSrc(40000);
Criterion criterion = Criteria.matchUdpSrc(tpPort);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result, matchesCriterion(criterion));
}
......@@ -249,7 +251,7 @@ public class CriterionCodecTest {
*/
@Test
public void matchUdpDstTest() {
Criterion criterion = Criteria.matchUdpDst(40000);
Criterion criterion = Criteria.matchUdpDst(tpPort);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result, matchesCriterion(criterion));
}
......@@ -259,7 +261,7 @@ public class CriterionCodecTest {
*/
@Test
public void matchSctpSrcTest() {
Criterion criterion = Criteria.matchSctpSrc(40000);
Criterion criterion = Criteria.matchSctpSrc(tpPort);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result, matchesCriterion(criterion));
}
......@@ -269,7 +271,7 @@ public class CriterionCodecTest {
*/
@Test
public void matchSctpDstTest() {
Criterion criterion = Criteria.matchSctpDst(40000);
Criterion criterion = Criteria.matchSctpDst(tpPort);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result, matchesCriterion(criterion));
}
......
......@@ -249,7 +249,7 @@ public final class CriterionJsonMatcher extends
* @return true if the JSON matches the criterion, false otherwise.
*/
private boolean matchCriterion(TcpPortCriterion criterion) {
final int tcpPort = criterion.tcpPort();
final int tcpPort = criterion.tcpPort().toInt();
final int jsonTcpPort = jsonCriterion.get("tcpPort").intValue();
if (tcpPort != jsonTcpPort) {
description.appendText("tcp port was "
......@@ -266,7 +266,7 @@ public final class CriterionJsonMatcher extends
* @return true if the JSON matches the criterion, false otherwise.
*/
private boolean matchCriterion(UdpPortCriterion criterion) {
final int udpPort = criterion.udpPort();
final int udpPort = criterion.udpPort().toInt();
final int jsonUdpPort = jsonCriterion.get("udpPort").intValue();
if (udpPort != jsonUdpPort) {
description.appendText("udp port was "
......@@ -283,7 +283,7 @@ public final class CriterionJsonMatcher extends
* @return true if the JSON matches the criterion, false otherwise.
*/
private boolean matchCriterion(SctpPortCriterion criterion) {
final int sctpPort = criterion.sctpPort();
final int sctpPort = criterion.sctpPort().toInt();
final int jsonSctpPort = jsonCriterion.get("sctpPort").intValue();
if (sctpPort != jsonSctpPort) {
description.appendText("sctp port was "
......
......@@ -419,27 +419,27 @@ public class FlowRuleCodecTest {
is((IpPrefix.valueOf("4.2.0.0/32"))));
criterion = getCriterion(Criterion.Type.TCP_SRC);
assertThat(((TcpPortCriterion) criterion).tcpPort(),
assertThat(((TcpPortCriterion) criterion).tcpPort().toInt(),
is(80));
criterion = getCriterion(Criterion.Type.TCP_DST);
assertThat(((TcpPortCriterion) criterion).tcpPort(),
assertThat(((TcpPortCriterion) criterion).tcpPort().toInt(),
is(443));
criterion = getCriterion(Criterion.Type.UDP_SRC);
assertThat(((UdpPortCriterion) criterion).udpPort(),
assertThat(((UdpPortCriterion) criterion).udpPort().toInt(),
is(180));
criterion = getCriterion(Criterion.Type.UDP_DST);
assertThat(((UdpPortCriterion) criterion).udpPort(),
assertThat(((UdpPortCriterion) criterion).udpPort().toInt(),
is(1443));
criterion = getCriterion(Criterion.Type.SCTP_SRC);
assertThat(((SctpPortCriterion) criterion).sctpPort(),
assertThat(((SctpPortCriterion) criterion).sctpPort().toInt(),
is(280));
criterion = getCriterion(Criterion.Type.SCTP_DST);
assertThat(((SctpPortCriterion) criterion).sctpPort(),
assertThat(((SctpPortCriterion) criterion).sctpPort().toInt(),
is(2443));
criterion = getCriterion(Criterion.Type.ICMPV4_TYPE);
......
......@@ -29,6 +29,7 @@ import org.onlab.packet.Ip6Prefix;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onlab.util.Bandwidth;
import org.onlab.util.Frequency;
......@@ -320,6 +321,7 @@ public final class KryoNamespaces {
IPEcnCriterion.class,
IPProtocolCriterion.class,
IPCriterion.class,
TpPort.class,
TcpPortCriterion.class,
UdpPortCriterion.class,
SctpPortCriterion.class,
......
......@@ -9,6 +9,7 @@ import com.google.common.cache.RemovalNotification;
import org.onlab.osgi.ServiceDirectory;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IPv4;
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onlab.util.KryoNamespace;
import org.onosproject.core.ApplicationId;
......@@ -515,7 +516,7 @@ public class CentecV350Pipeline extends AbstractHandlerBehaviour implements Pipe
treatment = DefaultTrafficTreatment.builder();
selector.matchEthType(Ethernet.TYPE_IPV4)
.matchIPProtocol(IPv4.PROTOCOL_TCP)
.matchTcpSrc(BGP_PORT);
.matchTcpSrc(TpPort.tpPort(BGP_PORT));
treatment.punt();
rule = DefaultFlowRule.builder()
.forDevice(deviceId)
......@@ -531,7 +532,7 @@ public class CentecV350Pipeline extends AbstractHandlerBehaviour implements Pipe
treatment = DefaultTrafficTreatment.builder();
selector.matchEthType(Ethernet.TYPE_IPV4)
.matchIPProtocol(IPv4.PROTOCOL_TCP)
.matchTcpDst(BGP_PORT);
.matchTcpDst(TpPort.tpPort(BGP_PORT));
treatment.punt();
rule = DefaultFlowRule.builder()
.forDevice(deviceId)
......
......@@ -30,6 +30,7 @@ import org.onlab.packet.Ip6Address;
import org.onlab.packet.Ip6Prefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onosproject.core.DefaultGroupId;
import org.onosproject.net.DeviceId;
......@@ -417,22 +418,22 @@ public class FlowEntryBuilder {
case TCP_DST:
@SuppressWarnings("unchecked")
OFOxm<TransportPort> tcpdst = (OFOxm<TransportPort>) oxm;
builder.setTcpDst((short) tcpdst.getValue().getPort());
builder.setTcpDst(TpPort.tpPort(tcpdst.getValue().getPort()));
break;
case TCP_SRC:
@SuppressWarnings("unchecked")
OFOxm<TransportPort> tcpsrc = (OFOxm<TransportPort>) oxm;
builder.setTcpSrc((short) tcpsrc.getValue().getPort());
builder.setTcpSrc(TpPort.tpPort(tcpsrc.getValue().getPort()));
break;
case UDP_DST:
@SuppressWarnings("unchecked")
OFOxm<TransportPort> udpdst = (OFOxm<TransportPort>) oxm;
builder.setUdpDst((short) udpdst.getValue().getPort());
builder.setUdpDst(TpPort.tpPort(udpdst.getValue().getPort()));
break;
case UDP_SRC:
@SuppressWarnings("unchecked")
OFOxm<TransportPort> udpsrc = (OFOxm<TransportPort>) oxm;
builder.setUdpSrc((short) udpsrc.getValue().getPort());
builder.setUdpSrc(TpPort.tpPort(udpsrc.getValue().getPort()));
break;
case ARP_OP:
case ARP_SHA:
......@@ -588,16 +589,16 @@ public class FlowEntryBuilder {
builder.matchIPDst(ip4Prefix);
break;
case TCP_SRC:
builder.matchTcpSrc((short) match.get(MatchField.TCP_SRC).getPort());
builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort()));
break;
case TCP_DST:
builder.matchTcpDst((short) match.get(MatchField.TCP_DST).getPort());
builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort()));
break;
case UDP_SRC:
builder.matchUdpSrc((short) match.get(MatchField.UDP_SRC).getPort());
builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort()));
break;
case UDP_DST:
builder.matchUdpDst((short) match.get(MatchField.UDP_DST).getPort());
builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort()));
break;
case MPLS_LABEL:
builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
......@@ -607,10 +608,10 @@ public class FlowEntryBuilder {
builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
break;
case SCTP_SRC:
builder.matchSctpSrc((short) match.get(MatchField.SCTP_SRC).getPort());
builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort()));
break;
case SCTP_DST:
builder.matchSctpDst((short) match.get(MatchField.SCTP_DST).getPort());
builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort()));
break;
case ICMPV4_TYPE:
byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
......
......@@ -268,32 +268,32 @@ public abstract class FlowModBuilder {
case TCP_SRC:
tcpPortCriterion = (TcpPortCriterion) c;
mBuilder.setExact(MatchField.TCP_SRC,
TransportPort.of(tcpPortCriterion.tcpPort()));
TransportPort.of(tcpPortCriterion.tcpPort().toInt()));
break;
case TCP_DST:
tcpPortCriterion = (TcpPortCriterion) c;
mBuilder.setExact(MatchField.TCP_DST,
TransportPort.of(tcpPortCriterion.tcpPort()));
TransportPort.of(tcpPortCriterion.tcpPort().toInt()));
break;
case UDP_SRC:
udpPortCriterion = (UdpPortCriterion) c;
mBuilder.setExact(MatchField.UDP_SRC,
TransportPort.of(udpPortCriterion.udpPort()));
TransportPort.of(udpPortCriterion.udpPort().toInt()));
break;
case UDP_DST:
udpPortCriterion = (UdpPortCriterion) c;
mBuilder.setExact(MatchField.UDP_DST,
TransportPort.of(udpPortCriterion.udpPort()));
TransportPort.of(udpPortCriterion.udpPort().toInt()));
break;
case SCTP_SRC:
sctpPortCriterion = (SctpPortCriterion) c;
mBuilder.setExact(MatchField.SCTP_SRC,
TransportPort.of(sctpPortCriterion.sctpPort()));
TransportPort.of(sctpPortCriterion.sctpPort().toInt()));
break;
case SCTP_DST:
sctpPortCriterion = (SctpPortCriterion) c;
mBuilder.setExact(MatchField.SCTP_DST,
TransportPort.of(sctpPortCriterion.sctpPort()));
TransportPort.of(sctpPortCriterion.sctpPort().toInt()));
break;
case ICMPV4_TYPE:
IcmpTypeCriterion icmpType = (IcmpTypeCriterion) c;
......
......@@ -431,19 +431,19 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
switch (l4m.subtype()) {
case TCP_SRC:
tp = (ModTransportPortInstruction) l4m;
oxm = factory().oxms().tcpSrc(TransportPort.of(tp.port()));
oxm = factory().oxms().tcpSrc(TransportPort.of(tp.port().toInt()));
break;
case TCP_DST:
tp = (ModTransportPortInstruction) l4m;
oxm = factory().oxms().tcpDst(TransportPort.of(tp.port()));
oxm = factory().oxms().tcpDst(TransportPort.of(tp.port().toInt()));
break;
case UDP_SRC:
tp = (ModTransportPortInstruction) l4m;
oxm = factory().oxms().udpSrc(TransportPort.of(tp.port()));
oxm = factory().oxms().udpSrc(TransportPort.of(tp.port().toInt()));
break;
case UDP_DST:
tp = (ModTransportPortInstruction) l4m;
oxm = factory().oxms().udpDst(TransportPort.of(tp.port()));
oxm = factory().oxms().udpDst(TransportPort.of(tp.port().toInt()));
break;
default:
log.warn("Unimplemented action type {}.", l4m.subtype());
......
......@@ -30,8 +30,8 @@ public class TCP extends BasePacket {
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 @@ public class TCP extends BasePacket {
*
* @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 @@ public class TCP extends BasePacket {
*
* @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 @@ public class TCP extends BasePacket {
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 class TCP extends BasePacket {
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 @@ public class TCP extends BasePacket {
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();
......
......@@ -46,24 +46,24 @@ public class UDP extends BasePacket {
}
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 @@ public class UDP extends BasePacket {
/**
* @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 @@ public class UDP extends BasePacket {
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 class UDP extends BasePacket {
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 @@ public class UDP extends BasePacket {
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();
......
......@@ -88,8 +88,8 @@ public class TCPTest {
@Test
public void testSerialize() {
TCP tcp = new TCP();
tcp.setSourcePort((short) 0x50);
tcp.setDestinationPort((short) 0x60);
tcp.setSourcePort(0x50);
tcp.setDestinationPort(0x60);
tcp.setSequence(0x10);
tcp.setAcknowledge(0x20);
tcp.setDataOffset((byte) 0x5);
......@@ -121,8 +121,8 @@ public class TCPTest {
public void testDeserialize() throws Exception {
TCP tcp = deserializer.deserialize(bytePacketTCP4, 0, bytePacketTCP4.length);
assertThat(tcp.getSourcePort(), is((short) 0x50));
assertThat(tcp.getDestinationPort(), is((short) 0x60));
assertThat(tcp.getSourcePort(), is(0x50));
assertThat(tcp.getDestinationPort(), is(0x60));
assertThat(tcp.getSequence(), is(0x10));
assertThat(tcp.getAcknowledge(), is(0x20));
assertThat(tcp.getDataOffset(), is((byte) 0x5));
......@@ -138,8 +138,8 @@ public class TCPTest {
@Test
public void testEqual() {
TCP tcp1 = new TCP();
tcp1.setSourcePort((short) 0x50);
tcp1.setDestinationPort((short) 0x60);
tcp1.setSourcePort(0x50);
tcp1.setDestinationPort(0x60);
tcp1.setSequence(0x10);
tcp1.setAcknowledge(0x20);
tcp1.setDataOffset((byte) 0x5);
......@@ -148,8 +148,8 @@ public class TCPTest {
tcp1.setUrgentPointer((short) 0x1);
TCP tcp2 = new TCP();
tcp2.setSourcePort((short) 0x70);
tcp2.setDestinationPort((short) 0x60);
tcp2.setSourcePort(0x70);
tcp2.setDestinationPort(0x60);
tcp2.setSequence(0x10);
tcp2.setAcknowledge(0x20);
tcp2.setDataOffset((byte) 0x5);
......
......@@ -82,8 +82,8 @@ public class UDPTest {
@Test
public void testSerialize() {
UDP udp = new UDP();
udp.setSourcePort((short) 0x50);
udp.setDestinationPort((short) 0x60);
udp.setSourcePort(0x50);
udp.setDestinationPort(0x60);
udp.setParent(ipv4);
assertArrayEquals(bytePacketUDP4, udp.serialize());
......@@ -109,8 +109,8 @@ public class UDPTest {
public void testDeserialize() throws Exception {
UDP udp = deserializer.deserialize(bytePacketUDP4, 0, bytePacketUDP4.length);
assertThat(udp.getSourcePort(), is((short) 0x50));
assertThat(udp.getDestinationPort(), is((short) 0x60));
assertThat(udp.getSourcePort(), is(0x50));
assertThat(udp.getDestinationPort(), is(0x60));
assertThat(udp.getLength(), is((short) 8));
assertThat(udp.getChecksum(), is((short) 0x7bda));
}
......@@ -121,12 +121,12 @@ public class UDPTest {
@Test
public void testEqual() {
UDP udp1 = new UDP();
udp1.setSourcePort((short) 0x50);
udp1.setDestinationPort((short) 0x60);
udp1.setSourcePort(0x50);
udp1.setDestinationPort(0x60);
UDP udp2 = new UDP();
udp2.setSourcePort((short) 0x70);
udp2.setDestinationPort((short) 0x60);
udp2.setSourcePort(0x70);
udp2.setDestinationPort(0x60);
assertTrue(udp1.equals(udp1));
assertFalse(udp1.equals(udp2));
......