Fix toward ONOS-960 - Signed/unsigned value mismatch for OpenFlow-related
match/action conditions
Fixed the signed/unsigned issue for the match conditions
Also:
* Reordered some of the code in CriterionCodec.java so the order
of handling various Criterion types follows the order as defined in
Criterion.java
- In the process, removed a duplicated entry for Type.MPLS_LABE
- Fixed an issue with TCP/UDP/SCTP ports being accessed as 8-bit integers
instead of 16-bit integers
* Updated some of the unit tests in CriterionCodecTest.java to use
larger integer values that could expose better potential bugs in
the tested code.
Change-Id: I531d13bd258ebc559ce6be716863c01613427a98
diff --git a/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java b/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java
index f972d9e..3c32dea 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java
@@ -59,7 +59,7 @@
/**
* Creates a match on METADATA field using the specified value.
*
- * @param metadata metadata value
+ * @param metadata metadata value (64 bits data)
* @return match criterion
*/
public static Criterion matchMetadata(Long metadata) {
@@ -91,10 +91,10 @@
/**
* Creates a match on ETH_TYPE field using the specified value.
*
- * @param ethType eth type value
+ * @param ethType eth type value (16 bits unsigned integer)
* @return match criterion
*/
- public static Criterion matchEthType(Short ethType) {
+ public static Criterion matchEthType(int ethType) {
return new EthTypeCriterion(ethType);
}
@@ -111,40 +111,40 @@
/**
* Creates a match on VLAN PCP field using the specified value.
*
- * @param vlanPcp vlan pcp value
+ * @param vlanPcp vlan pcp value (3 bits)
* @return match criterion
*/
- public static Criterion matchVlanPcp(Byte vlanPcp) {
+ public static Criterion matchVlanPcp(byte vlanPcp) {
return new VlanPcpCriterion(vlanPcp);
}
/**
* Creates a match on IP DSCP field using the specified value.
*
- * @param ipDscp ip dscp value
+ * @param ipDscp ip dscp value (6 bits)
* @return match criterion
*/
- public static Criterion matchIPDscp(Byte ipDscp) {
+ public static Criterion matchIPDscp(byte ipDscp) {
return new IPDscpCriterion(ipDscp);
}
/**
* Creates a match on IP ECN field using the specified value.
*
- * @param ipEcn ip ecn value
+ * @param ipEcn ip ecn value (3 bits)
* @return match criterion
*/
- public static Criterion matchIPEcn(Byte ipEcn) {
+ public static Criterion matchIPEcn(byte ipEcn) {
return new IPEcnCriterion(ipEcn);
}
/**
* Creates a match on IP proto field using the specified value.
*
- * @param proto ip protocol value
+ * @param proto ip protocol value (8 bits unsigned integer)
* @return match criterion
*/
- public static Criterion matchIPProtocol(Byte proto) {
+ public static Criterion matchIPProtocol(short proto) {
return new IPProtocolCriterion(proto);
}
@@ -171,50 +171,50 @@
/**
* Creates a match on TCP source port field using the specified value.
*
- * @param tcpPort TCP source port
+ * @param tcpPort TCP source port (16 bits unsigned integer)
* @return match criterion
*/
- public static Criterion matchTcpSrc(Short tcpPort) {
+ public static Criterion matchTcpSrc(int 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
+ * @param tcpPort TCP destination port (16 bits unsigned integer)
* @return match criterion
*/
- public static Criterion matchTcpDst(Short tcpPort) {
+ public static Criterion matchTcpDst(int 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
+ * @param udpPort UDP source port (16 bits unsigned integer)
* @return match criterion
*/
- public static Criterion matchUdpSrc(Short udpPort) {
+ public static Criterion matchUdpSrc(int 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
+ * @param udpPort UDP destination port (16 bits unsigned integer)
* @return match criterion
*/
- public static Criterion matchUdpDst(Short udpPort) {
+ public static Criterion matchUdpDst(int 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
+ * @param sctpPort SCTP source port (16 bits unsigned integer)
* @return match criterion
*/
- public static Criterion matchSctpSrc(Short sctpPort) {
+ public static Criterion matchSctpSrc(int sctpPort) {
return new SctpPortCriterion(sctpPort, Type.SCTP_SRC);
}
@@ -222,30 +222,30 @@
* Creates a match on SCTP destination port field using the specified
* value.
*
- * @param sctpPort SCTP destination port
+ * @param sctpPort SCTP destination port (16 bits unsigned integer)
* @return match criterion
*/
- public static Criterion matchSctpDst(Short sctpPort) {
+ public static Criterion matchSctpDst(int sctpPort) {
return new SctpPortCriterion(sctpPort, Type.SCTP_DST);
}
/**
* Creates a match on ICMP type field using the specified value.
*
- * @param icmpType ICMP type
+ * @param icmpType ICMP type (8 bits unsigned integer)
* @return match criterion
*/
- public static Criterion matchIcmpType(Byte icmpType) {
+ public static Criterion matchIcmpType(short icmpType) {
return new IcmpTypeCriterion(icmpType);
}
/**
* Creates a match on ICMP code field using the specified value.
*
- * @param icmpCode ICMP code
+ * @param icmpCode ICMP code (8 bits unsigned integer)
* @return match criterion
*/
- public static Criterion matchIcmpCode(Byte icmpCode) {
+ public static Criterion matchIcmpCode(short icmpCode) {
return new IcmpCodeCriterion(icmpCode);
}
@@ -272,30 +272,30 @@
/**
* Creates a match on IPv6 flow label field using the specified value.
*
- * @param flowLabel IPv6 flow label
+ * @param flowLabel IPv6 flow label (20 bits)
* @return match criterion
*/
- public static Criterion matchIPv6FlowLabel(Integer flowLabel) {
+ public static Criterion matchIPv6FlowLabel(int flowLabel) {
return new IPv6FlowLabelCriterion(flowLabel);
}
/**
* Creates a match on ICMPv6 type field using the specified value.
*
- * @param icmpv6Type ICMPv6 type
+ * @param icmpv6Type ICMPv6 type (8 bits unsigned integer)
* @return match criterion
*/
- public static Criterion matchIcmpv6Type(Byte icmpv6Type) {
+ public static Criterion matchIcmpv6Type(short icmpv6Type) {
return new Icmpv6TypeCriterion(icmpv6Type);
}
/**
* Creates a match on ICMPv6 code field using the specified value.
*
- * @param icmpv6Code ICMPv6 code
+ * @param icmpv6Code ICMPv6 code (8 bits unsigned integer)
* @return match criterion
*/
- public static Criterion matchIcmpv6Code(Byte icmpv6Code) {
+ public static Criterion matchIcmpv6Code(short icmpv6Code) {
return new Icmpv6CodeCriterion(icmpv6Code);
}
@@ -335,7 +335,7 @@
/**
* Creates a match on MPLS label.
*
- * @param mplsLabel MPLS label
+ * @param mplsLabel MPLS label (20 bits)
* @return match criterion
*/
public static Criterion matchMplsLabel(Integer mplsLabel) {
@@ -345,20 +345,20 @@
/**
* Creates a match on lambda field using the specified value.
*
- * @param lambda lambda to match on
+ * @param lambda lambda to match on (16 bits unsigned integer)
* @return match criterion
*/
- public static Criterion matchLambda(Short lambda) {
+ public static Criterion matchLambda(int lambda) {
return new LambdaCriterion(lambda, Type.OCH_SIGID);
}
/**
* Creates a match on optical signal type using the specified value.
*
- * @param sigType optical signal type
+ * @param sigType optical signal type (16 bits unsigned integer)
* @return match criterion
*/
- public static Criterion matchOpticalSignalType(Short sigType) {
+ public static Criterion matchOpticalSignalType(int sigType) {
return new OpticalSignalTypeCriterion(sigType, Type.OCH_SIGTYPE);
}
@@ -424,14 +424,14 @@
* Implementation of Metadata criterion.
*/
public static final class MetadataCriterion implements Criterion {
- private final Long metadata;
+ private final long metadata;
/**
* Constructor.
*
- * @param metadata the metadata to match
+ * @param metadata the metadata to match (64 bits data)
*/
- public MetadataCriterion(Long metadata) {
+ public MetadataCriterion(long metadata) {
this.metadata = metadata;
}
@@ -443,9 +443,9 @@
/**
* Gets the metadata to match.
*
- * @return the metadata to match
+ * @return the metadata to match (64 bits data)
*/
- public Long metadata() {
+ public long metadata() {
return metadata;
}
@@ -534,18 +534,20 @@
}
/**
- * Implementation of Ethernet type criterion.
+ * Implementation of Ethernet type criterion (16 bits unsigned integer).
*/
public static final class EthTypeCriterion implements Criterion {
- private final Short ethType;
+ private static final int MASK = 0xffff;
+ private final int ethType; // Ethernet type value: 16 bits
/**
* Constructor.
*
- * @param ethType the Ethernet frame type to match
+ * @param ethType the Ethernet frame type to match (16 bits unsigned
+ * integer)
*/
- public EthTypeCriterion(Short ethType) {
- this.ethType = ethType;
+ public EthTypeCriterion(int ethType) {
+ this.ethType = ethType & MASK;
}
@Override
@@ -556,16 +558,16 @@
/**
* Gets the Ethernet frame type to match.
*
- * @return the Ethernet frame type to match
+ * @return the Ethernet frame type to match (16 bits unsigned integer)
*/
- public Short ethType() {
+ public int ethType() {
return ethType;
}
@Override
public String toString() {
return toStringHelper(type().toString())
- .add("ethType", Long.toHexString(ethType & 0xffff))
+ .add("ethType", Long.toHexString(ethType))
.toString();
}
@@ -583,8 +585,6 @@
EthTypeCriterion that = (EthTypeCriterion) obj;
return Objects.equals(ethType, that.ethType) &&
Objects.equals(this.type(), that.type());
-
-
}
return false;
}
@@ -645,18 +645,19 @@
}
/**
- * Implementation of VLAN priority criterion.
+ * Implementation of VLAN priority criterion (3 bits).
*/
public static final class VlanPcpCriterion implements Criterion {
- private final Byte vlanPcp;
+ private static final byte MASK = 0x7;
+ private final byte vlanPcp; // VLAN pcp value: 3 bits
/**
* Constructor.
*
- * @param vlanPcp the VLAN priority to match
+ * @param vlanPcp the VLAN priority to match (3 bits)
*/
- public VlanPcpCriterion(Byte vlanPcp) {
- this.vlanPcp = vlanPcp;
+ public VlanPcpCriterion(byte vlanPcp) {
+ this.vlanPcp = (byte) (vlanPcp & MASK);
}
@Override
@@ -667,16 +668,16 @@
/**
* Gets the VLAN priority to match.
*
- * @return the VLAN priority to match
+ * @return the VLAN priority to match (3 bits)
*/
- public Byte priority() {
+ public byte priority() {
return vlanPcp;
}
@Override
public String toString() {
return toStringHelper(type().toString())
- .add("priority", Long.toHexString(vlanPcp)).toString();
+ .add("priority", Long.toHexString(vlanPcp)).toString();
}
@Override
@@ -699,20 +700,20 @@
}
/**
- * Implementation of IP DSCP criterion (6-bit Differentiated Services
- * Code Point).
+ * Implementation of IP DSCP (Differentiated Services Code Point)
+ * criterion (6 bits).
*/
public static final class IPDscpCriterion implements Criterion {
- private static final byte DSCP_MASK = 0x3f;
- private final Byte ipDscp; // IP DSCP value: 6 bits
+ private static final byte MASK = 0x3f;
+ private final byte ipDscp; // IP DSCP value: 6 bits
/**
* Constructor.
*
* @param ipDscp the IP DSCP value to match
*/
- public IPDscpCriterion(Byte ipDscp) {
- this.ipDscp = (byte) (ipDscp & DSCP_MASK);
+ public IPDscpCriterion(byte ipDscp) {
+ this.ipDscp = (byte) (ipDscp & MASK);
}
@Override
@@ -725,14 +726,14 @@
*
* @return the IP DSCP value to match
*/
- public Byte ipDscp() {
+ public byte ipDscp() {
return ipDscp;
}
@Override
public String toString() {
return toStringHelper(type().toString())
- .add("ipDscp", ipDscp).toString();
+ .add("ipDscp", Long.toHexString(ipDscp)).toString();
}
@Override
@@ -755,20 +756,20 @@
}
/**
- * Implementation of IP ECN criterion (3-bit Explicit Congestion
- * Notification).
+ * Implementation of IP ECN (Explicit Congestion Notification) criterion
+ * (3 bits).
*/
public static final class IPEcnCriterion implements Criterion {
- private static final byte ECN_MASK = 0x3;
- private final Byte ipEcn; // IP ECN value: 3 bits
+ private static final byte MASK = 0x7;
+ private final byte ipEcn; // IP ECN value: 3 bits
/**
* Constructor.
*
- * @param ipEcn the IP ECN value to match
+ * @param ipEcn the IP ECN value to match (3 bits)
*/
- public IPEcnCriterion(Byte ipEcn) {
- this.ipEcn = (byte) (ipEcn & ECN_MASK);
+ public IPEcnCriterion(byte ipEcn) {
+ this.ipEcn = (byte) (ipEcn & MASK);
}
@Override
@@ -779,16 +780,16 @@
/**
* Gets the IP ECN value to match.
*
- * @return the IP ECN value to match
+ * @return the IP ECN value to match (3 bits)
*/
- public Byte ipEcn() {
+ public byte ipEcn() {
return ipEcn;
}
@Override
public String toString() {
return toStringHelper(type().toString())
- .add("ipEcn", ipEcn).toString();
+ .add("ipEcn", Long.toHexString(ipEcn)).toString();
}
@Override
@@ -811,18 +812,21 @@
}
/**
- * Implementation of Internet Protocol Number criterion.
+ * Implementation of Internet Protocol Number criterion (8 bits unsigned)
+ * integer.
*/
public static final class IPProtocolCriterion implements Criterion {
- private final Byte proto;
+ private static final short MASK = 0xff;
+ private final short proto; // IP protocol number: 8 bits
/**
* Constructor.
*
- * @param protocol the IP protocol to match (e.g., TCP=6, UDP=17).
+ * @param protocol the IP protocol (e.g., TCP=6, UDP=17) to match
+ * (8 bits unsigned integer)
*/
- public IPProtocolCriterion(Byte protocol) {
- this.proto = protocol;
+ public IPProtocolCriterion(short protocol) {
+ this.proto = (short) (protocol & MASK);
}
@Override
@@ -833,17 +837,16 @@
/**
* Gets the IP protocol to match.
*
- * @return the IP protocol to match
+ * @return the IP protocol to match (8 bits unsigned integer)
*/
- public Byte protocol() {
+ public short protocol() {
return proto;
}
@Override
public String toString() {
return toStringHelper(type().toString())
- .add("protocol", Long.toHexString(proto & 0xff))
- .toString();
+ .add("protocol", proto).toString();
}
@Override
@@ -923,21 +926,22 @@
}
/**
- * Implementation of TCP port criterion.
+ * Implementation of TCP port criterion (16 bits unsigned integer).
*/
public static final class TcpPortCriterion implements Criterion {
- private final Short tcpPort;
+ private static final int MASK = 0xffff;
+ private final int tcpPort; // Port value: 16 bits
private final Type type;
/**
* Constructor.
*
- * @param tcpPort the TCP port to match
+ * @param tcpPort the TCP port to match (16 bits unsigned integer)
* @param type the match type. Should be either Type.TCP_SRC or
* Type.TCP_DST
*/
- public TcpPortCriterion(Short tcpPort, Type type) {
- this.tcpPort = tcpPort;
+ public TcpPortCriterion(int tcpPort, Type type) {
+ this.tcpPort = tcpPort & MASK;
this.type = type;
}
@@ -949,16 +953,16 @@
/**
* Gets the TCP port to match.
*
- * @return the TCP port to match
+ * @return the TCP port to match (16 bits unsigned integer)
*/
- public Short tcpPort() {
+ public int tcpPort() {
return this.tcpPort;
}
@Override
public String toString() {
return toStringHelper(type().toString())
- .add("tcpPort", tcpPort & 0xffff).toString();
+ .add("tcpPort", tcpPort).toString();
}
@Override
@@ -981,21 +985,22 @@
}
/**
- * Implementation of UDP port criterion.
+ * Implementation of UDP port criterion (16 bits unsigned integer).
*/
public static final class UdpPortCriterion implements Criterion {
- private final Short udpPort;
+ private static final int MASK = 0xffff;
+ private final int udpPort; // Port value: 16 bits
private final Type type;
/**
* Constructor.
*
- * @param udpPort the UDP port to match
+ * @param udpPort the UDP port to match (16 bits unsigned integer)
* @param type the match type. Should be either Type.UDP_SRC or
* Type.UDP_DST
*/
- public UdpPortCriterion(Short udpPort, Type type) {
- this.udpPort = udpPort;
+ public UdpPortCriterion(int udpPort, Type type) {
+ this.udpPort = udpPort & MASK;
this.type = type;
}
@@ -1007,16 +1012,16 @@
/**
* Gets the UDP port to match.
*
- * @return the UDP port to match
+ * @return the UDP port to match (16 bits unsigned integer)
*/
- public Short udpPort() {
+ public int udpPort() {
return this.udpPort;
}
@Override
public String toString() {
return toStringHelper(type().toString())
- .add("udpPort", udpPort & 0xffff).toString();
+ .add("udpPort", udpPort).toString();
}
@Override
@@ -1039,21 +1044,22 @@
}
/**
- * Implementation of SCTP port criterion.
+ * Implementation of SCTP port criterion (16 bits unsigned integer).
*/
public static final class SctpPortCriterion implements Criterion {
- private final Short sctpPort;
+ private static final int MASK = 0xffff;
+ private final int sctpPort; // Port value: 16 bits
private final Type type;
/**
* Constructor.
*
- * @param sctpPort the SCTP port to match
+ * @param sctpPort the SCTP port to match (16 bits unsigned integer)
* @param type the match type. Should be either Type.SCTP_SRC or
* Type.SCTP_DST
*/
- public SctpPortCriterion(Short sctpPort, Type type) {
- this.sctpPort = sctpPort;
+ public SctpPortCriterion(int sctpPort, Type type) {
+ this.sctpPort = sctpPort & MASK;
this.type = type;
}
@@ -1065,16 +1071,16 @@
/**
* Gets the SCTP port to match.
*
- * @return the SCTP port to match
+ * @return the SCTP port to match (16 bits unsigned integer)
*/
- public Short sctpPort() {
+ public int sctpPort() {
return this.sctpPort;
}
@Override
public String toString() {
return toStringHelper(type().toString())
- .add("sctpPort", sctpPort & 0xffff).toString();
+ .add("sctpPort", sctpPort).toString();
}
@Override
@@ -1097,18 +1103,19 @@
}
/**
- * Implementation of ICMP type criterion.
+ * Implementation of ICMP type criterion (8 bits unsigned integer).
*/
public static final class IcmpTypeCriterion implements Criterion {
- private final Byte icmpType;
+ private static final short MASK = 0xff;
+ private final short icmpType; // The ICMP type: 8 bits
/**
* Constructor.
*
- * @param icmpType the ICMP type to match
+ * @param icmpType the ICMP type to match (8 bits unsigned integer)
*/
- public IcmpTypeCriterion(Byte icmpType) {
- this.icmpType = icmpType;
+ public IcmpTypeCriterion(short icmpType) {
+ this.icmpType = (short) (icmpType & MASK);
}
@Override
@@ -1119,16 +1126,16 @@
/**
* Gets the ICMP type to match.
*
- * @return the ICMP type to match
+ * @return the ICMP type to match (8 bits unsigned integer)
*/
- public Byte icmpType() {
+ public short icmpType() {
return icmpType;
}
@Override
public String toString() {
return toStringHelper(type().toString())
- .add("icmpType", icmpType & 0xff).toString();
+ .add("icmpType", icmpType).toString();
}
@Override
@@ -1151,18 +1158,19 @@
}
/**
- * Implementation of ICMP code criterion.
+ * Implementation of ICMP code criterion (8 bits unsigned integer).
*/
public static final class IcmpCodeCriterion implements Criterion {
- private final Byte icmpCode;
+ private static final short MASK = 0xff;
+ private final short icmpCode; // The ICMP code: 8 bits
/**
* Constructor.
*
- * @param icmpCode the ICMP code to match
+ * @param icmpCode the ICMP code to match (8 bits unsigned integer)
*/
- public IcmpCodeCriterion(Byte icmpCode) {
- this.icmpCode = icmpCode;
+ public IcmpCodeCriterion(short icmpCode) {
+ this.icmpCode = (short) (icmpCode & MASK);
}
@Override
@@ -1173,16 +1181,16 @@
/**
* Gets the ICMP code to match.
*
- * @return the ICMP code to match
+ * @return the ICMP code to match (8 bits unsigned integer)
*/
- public Byte icmpCode() {
+ public short icmpCode() {
return icmpCode;
}
@Override
public String toString() {
return toStringHelper(type().toString())
- .add("icmpCode", icmpCode & 0xff).toString();
+ .add("icmpCode", icmpCode).toString();
}
@Override
@@ -1205,19 +1213,20 @@
}
/**
- * Implementation of IPv6 Flow Label criterion (RFC 6437).
+ * Implementation of IPv6 Flow Label (RFC 6437) criterion (20 bits unsigned
+ * integer).
*/
public static final class IPv6FlowLabelCriterion implements Criterion {
- private static final int FLOW_LABEL_MASK = 0xfffff;
- private final Integer flowLabel; // IPv6 flow label: 20 bits
+ private static final int MASK = 0xfffff;
+ private final int flowLabel; // IPv6 flow label: 20 bits
/**
* Constructor.
*
- * @param flowLabel the IPv6 flow label to match
+ * @param flowLabel the IPv6 flow label to match (20 bits)
*/
- public IPv6FlowLabelCriterion(Integer flowLabel) {
- this.flowLabel = flowLabel & FLOW_LABEL_MASK;
+ public IPv6FlowLabelCriterion(int flowLabel) {
+ this.flowLabel = flowLabel & MASK;
}
@Override
@@ -1228,16 +1237,16 @@
/**
* Gets the IPv6 flow label to match.
*
- * @return the IPv6 flow label to match
+ * @return the IPv6 flow label to match (20 bits)
*/
- public Integer flowLabel() {
+ public int flowLabel() {
return flowLabel;
}
@Override
public String toString() {
return toStringHelper(type().toString())
- .add("flowLabel", flowLabel).toString();
+ .add("flowLabel", Long.toHexString(flowLabel)).toString();
}
@Override
@@ -1260,18 +1269,19 @@
}
/**
- * Implementation of ICMPv6 type criterion.
+ * Implementation of ICMPv6 type criterion (8 bits unsigned integer).
*/
public static final class Icmpv6TypeCriterion implements Criterion {
- private final Byte icmpv6Type;
+ private static final short MASK = 0xff;
+ private final short icmpv6Type; // ICMPv6 type: 8 bits
/**
* Constructor.
*
- * @param icmpv6Type the ICMPv6 type to match
+ * @param icmpv6Type the ICMPv6 type to match (8 bits unsigned integer)
*/
- public Icmpv6TypeCriterion(Byte icmpv6Type) {
- this.icmpv6Type = icmpv6Type;
+ public Icmpv6TypeCriterion(short icmpv6Type) {
+ this.icmpv6Type = (short) (icmpv6Type & MASK);
}
@Override
@@ -1282,16 +1292,16 @@
/**
* Gets the ICMPv6 type to match.
*
- * @return the ICMPv6 type to match
+ * @return the ICMPv6 type to match (8 bits unsigned integer)
*/
- public Byte icmpv6Type() {
+ public short icmpv6Type() {
return icmpv6Type;
}
@Override
public String toString() {
return toStringHelper(type().toString())
- .add("icmpv6Type", icmpv6Type & 0xff).toString();
+ .add("icmpv6Type", icmpv6Type).toString();
}
@Override
@@ -1314,18 +1324,19 @@
}
/**
- * Implementation of ICMPv6 code criterion.
+ * Implementation of ICMPv6 code criterion (8 bits unsigned integer).
*/
public static final class Icmpv6CodeCriterion implements Criterion {
- private final Byte icmpv6Code;
+ private static final short MASK = 0xff;
+ private final short icmpv6Code; // ICMPv6 code: 8 bits
/**
* Constructor.
*
- * @param icmpv6Code the ICMPv6 code to match
+ * @param icmpv6Code the ICMPv6 code to match (8 bits unsigned integer)
*/
- public Icmpv6CodeCriterion(Byte icmpv6Code) {
- this.icmpv6Code = icmpv6Code;
+ public Icmpv6CodeCriterion(short icmpv6Code) {
+ this.icmpv6Code = (short) (icmpv6Code & MASK);
}
@Override
@@ -1336,16 +1347,16 @@
/**
* Gets the ICMPv6 code to match.
*
- * @return the ICMPv6 code to match
+ * @return the ICMPv6 code to match (8 bits unsigned integer)
*/
- public Byte icmpv6Code() {
+ public short icmpv6Code() {
return icmpv6Code;
}
@Override
public String toString() {
return toStringHelper(type().toString())
- .add("icmpv6Code", icmpv6Code & 0xff).toString();
+ .add("icmpv6Code", icmpv6Code).toString();
}
@Override
@@ -1484,18 +1495,19 @@
}
/**
- * Implementation of MPLS tag criterion.
+ * Implementation of MPLS tag criterion (20 bits).
*/
public static final class MplsCriterion implements Criterion {
- private final Integer mplsLabel;
+ private static final int MASK = 0xfffff;
+ private final int mplsLabel; // MPLS label: 20 bits
/**
* Constructor.
*
- * @param mplsLabel the MPLS label to match
+ * @param mplsLabel the MPLS label to match (20 bits)
*/
- public MplsCriterion(Integer mplsLabel) {
- this.mplsLabel = mplsLabel;
+ public MplsCriterion(int mplsLabel) {
+ this.mplsLabel = mplsLabel & MASK;
}
@Override
@@ -1506,16 +1518,16 @@
/**
* Gets the MPLS label to match.
*
- * @return the MPLS label to match
+ * @return the MPLS label to match (20 bits)
*/
- public Integer label() {
+ public int label() {
return mplsLabel;
}
@Override
public String toString() {
return toStringHelper(type().toString())
- .add("label", mplsLabel & 0xffffffffL).toString();
+ .add("label", Long.toHexString(mplsLabel)).toString();
}
@Override
@@ -1535,24 +1547,26 @@
}
return false;
}
-
}
/**
- * Implementation of lambda (wavelength) criterion.
+ * Implementation of lambda (wavelength) criterion (16 bits unsigned
+ * integer).
*/
public static final class LambdaCriterion implements Criterion {
- private final short lambda;
+ private static final int MASK = 0xffff;
+ private final int lambda; // Lambda value: 16 bits
private final Type type;
/**
* Constructor.
*
- * @param lambda the lambda (wavelength) to match
+ * @param lambda the lambda (wavelength) to match (16 bits unsigned
+ * integer)
* @param type the match type. Should be Type.OCH_SIGID
*/
- public LambdaCriterion(short lambda, Type type) {
- this.lambda = lambda;
+ public LambdaCriterion(int lambda, Type type) {
+ this.lambda = lambda & MASK;
this.type = type;
}
@@ -1564,16 +1578,16 @@
/**
* Gets the lambda (wavelength) to match.
*
- * @return the lambda (wavelength) to match.
+ * @return the lambda (wavelength) to match (16 bits unsigned integer)
*/
- public Short lambda() {
- return this.lambda;
+ public int lambda() {
+ return lambda;
}
@Override
public String toString() {
return toStringHelper(type().toString())
- .add("lambda", lambda & 0xffff).toString();
+ .add("lambda", lambda).toString();
}
@Override
@@ -1596,20 +1610,23 @@
}
/**
- * Implementation of optical signal type criterion.
+ * Implementation of optical signal type criterion (16 bits unsigned
+ * integer).
*/
public static final class OpticalSignalTypeCriterion implements Criterion {
- private final Short signalType;
+ private static final int MASK = 0xffff;
+ private final int signalType; // Signal type value: 16 bits
private final Type type;
/**
* Constructor.
*
- * @param signalType the optical signal type to match
+ * @param signalType the optical signal type to match (16 bits unsigned
+ * integer)
* @param type the match type. Should be Type.OCH_SIGTYPE
*/
- public OpticalSignalTypeCriterion(Short signalType, Type type) {
- this.signalType = signalType;
+ public OpticalSignalTypeCriterion(int signalType, Type type) {
+ this.signalType = signalType & MASK;
this.type = type;
}
@@ -1623,14 +1640,14 @@
*
* @return the optical signal type to match
*/
- public Short signalType() {
- return this.signalType;
+ public int signalType() {
+ return signalType;
}
@Override
public String toString() {
return toStringHelper(type().toString())
- .add("signalType", signalType & 0xffff).toString();
+ .add("signalType", signalType).toString();
}
@Override
diff --git a/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java b/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java
index ba01133..b9e1233 100644
--- a/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java
+++ b/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java
@@ -63,8 +63,8 @@
Criterion sameAsMatchEth1 = Criteria.matchEthSrc(mac1);
Criterion matchEth2 = Criteria.matchEthDst(mac2);
- short ethType1 = 1;
- short ethType2 = 2;
+ int ethType1 = 1;
+ int ethType2 = 2;
Criterion matchEthType1 = Criteria.matchEthType(ethType1);
Criterion sameAsMatchEthType1 = Criteria.matchEthType(ethType1);
Criterion matchEthType2 = Criteria.matchEthType(ethType2);
@@ -95,8 +95,8 @@
Criterion sameAsMatchIpEcn1 = Criteria.matchIPEcn(ipEcn1);
Criterion matchIpEcn2 = Criteria.matchIPEcn(ipEcn2);
- byte protocol1 = 1;
- byte protocol2 = 2;
+ short protocol1 = 1;
+ short protocol2 = 2;
Criterion matchIpProtocol1 = Criteria.matchIPProtocol(protocol1);
Criterion sameAsMatchIpProtocol1 = Criteria.matchIPProtocol(protocol1);
Criterion matchIpProtocol2 = Criteria.matchIPProtocol(protocol2);
@@ -116,26 +116,26 @@
Criterion sameAsMatchIpv61 = Criteria.matchIPSrc(ipv61);
Criterion matchIpv62 = Criteria.matchIPSrc(ipv62);
- Criterion matchTcpPort1 = Criteria.matchTcpSrc((short) 1);
- Criterion sameAsMatchTcpPort1 = Criteria.matchTcpSrc((short) 1);
- Criterion matchTcpPort2 = Criteria.matchTcpDst((short) 2);
+ Criterion matchTcpPort1 = Criteria.matchTcpSrc(1);
+ Criterion sameAsMatchTcpPort1 = Criteria.matchTcpSrc(1);
+ Criterion matchTcpPort2 = Criteria.matchTcpDst(2);
- Criterion matchUdpPort1 = Criteria.matchUdpSrc((short) 1);
- Criterion sameAsMatchUdpPort1 = Criteria.matchUdpSrc((short) 1);
- Criterion matchUdpPort2 = Criteria.matchUdpDst((short) 2);
+ Criterion matchUdpPort1 = Criteria.matchUdpSrc(1);
+ Criterion sameAsMatchUdpPort1 = Criteria.matchUdpSrc(1);
+ Criterion matchUdpPort2 = Criteria.matchUdpDst(2);
- Criterion matchSctpPort1 = Criteria.matchSctpSrc((short) 1);
- Criterion sameAsMatchSctpPort1 = Criteria.matchSctpSrc((short) 1);
- Criterion matchSctpPort2 = Criteria.matchSctpDst((short) 2);
+ Criterion matchSctpPort1 = Criteria.matchSctpSrc(1);
+ Criterion sameAsMatchSctpPort1 = Criteria.matchSctpSrc(1);
+ Criterion matchSctpPort2 = Criteria.matchSctpDst(2);
- byte icmpType1 = 1;
- byte icmpType2 = 2;
+ short icmpType1 = 1;
+ short icmpType2 = 2;
Criterion matchIcmpType1 = Criteria.matchIcmpType(icmpType1);
Criterion sameAsMatchIcmpType1 = Criteria.matchIcmpType(icmpType1);
Criterion matchIcmpType2 = Criteria.matchIcmpType(icmpType2);
- byte icmpCode1 = 1;
- byte icmpCode2 = 2;
+ short icmpCode1 = 1;
+ short icmpCode2 = 2;
Criterion matchIcmpCode1 = Criteria.matchIcmpCode(icmpCode1);
Criterion sameAsMatchIcmpCode1 = Criteria.matchIcmpCode(icmpCode1);
Criterion matchIcmpCode2 = Criteria.matchIcmpCode(icmpCode2);
@@ -146,14 +146,14 @@
Criterion sameAsMatchFlowLabel1 = Criteria.matchIPv6FlowLabel(flowLabel1);
Criterion matchFlowLabel2 = Criteria.matchIPv6FlowLabel(flowLabel2);
- byte icmpv6Type1 = 1;
- byte icmpv6Type2 = 2;
+ short icmpv6Type1 = 1;
+ short icmpv6Type2 = 2;
Criterion matchIcmpv6Type1 = Criteria.matchIcmpv6Type(icmpv6Type1);
Criterion sameAsMatchIcmpv6Type1 = Criteria.matchIcmpv6Type(icmpv6Type1);
Criterion matchIcmpv6Type2 = Criteria.matchIcmpv6Type(icmpv6Type2);
- byte icmpv6Code1 = 1;
- byte icmpv6Code2 = 2;
+ short icmpv6Code1 = 1;
+ short icmpv6Code2 = 2;
Criterion matchIcmpv6Code1 = Criteria.matchIcmpv6Code(icmpv6Code1);
Criterion sameAsMatchIcmpv6Code1 = Criteria.matchIcmpv6Code(icmpv6Code1);
Criterion matchIcmpv6Code2 = Criteria.matchIcmpv6Code(icmpv6Code2);
@@ -192,14 +192,14 @@
Criterion sameAsMatchMpls1 = Criteria.matchMplsLabel(mpls1);
Criterion matchMpls2 = Criteria.matchMplsLabel(mpls2);
- short lambda1 = 1;
- short lambda2 = 2;
+ int lambda1 = 1;
+ int lambda2 = 2;
Criterion matchLambda1 = Criteria.matchLambda(lambda1);
Criterion sameAsMatchLambda1 = Criteria.matchLambda(lambda1);
Criterion matchLambda2 = Criteria.matchLambda(lambda2);
- short signalLambda1 = 1;
- short signalLambda2 = 2;
+ int signalLambda1 = 1;
+ int signalLambda2 = 2;
Criterion matchSignalLambda1 = Criteria.matchOpticalSignalType(signalLambda1);
Criterion sameAsMatchSignalLambda1 = Criteria.matchOpticalSignalType(signalLambda1);
Criterion matchSignalLambda2 = Criteria.matchOpticalSignalType(signalLambda2);
@@ -379,7 +379,7 @@
*/
@Test
public void testMatchEthTypeMethod() {
- Short ethType = 12;
+ int ethType = 12;
Criterion matchEthType = Criteria.matchEthType(ethType);
Criteria.EthTypeCriterion ethTypeCriterion =
checkAndConvert(matchEthType,
@@ -606,12 +606,12 @@
*/
@Test
public void testMatchTcpSrcMethod() {
- Criterion matchTcpSrc = Criteria.matchTcpSrc((short) 1);
+ Criterion matchTcpSrc = Criteria.matchTcpSrc(1);
Criteria.TcpPortCriterion tcpPortCriterion =
checkAndConvert(matchTcpSrc,
Criterion.Type.TCP_SRC,
Criteria.TcpPortCriterion.class);
- assertThat(tcpPortCriterion.tcpPort(), is(equalTo((short) 1)));
+ assertThat(tcpPortCriterion.tcpPort(), is(equalTo(1)));
}
/**
@@ -619,12 +619,12 @@
*/
@Test
public void testMatchTcpDstMethod() {
- Criterion matchTcpDst = Criteria.matchTcpDst((short) 1);
+ Criterion matchTcpDst = Criteria.matchTcpDst(1);
Criteria.TcpPortCriterion tcpPortCriterion =
checkAndConvert(matchTcpDst,
Criterion.Type.TCP_DST,
Criteria.TcpPortCriterion.class);
- assertThat(tcpPortCriterion.tcpPort(), is(equalTo((short) 1)));
+ assertThat(tcpPortCriterion.tcpPort(), is(equalTo(1)));
}
/**
@@ -645,12 +645,12 @@
*/
@Test
public void testMatchUdpSrcMethod() {
- Criterion matchUdpSrc = Criteria.matchUdpSrc((short) 1);
+ Criterion matchUdpSrc = Criteria.matchUdpSrc(1);
Criteria.UdpPortCriterion udpPortCriterion =
checkAndConvert(matchUdpSrc,
Criterion.Type.UDP_SRC,
Criteria.UdpPortCriterion.class);
- assertThat(udpPortCriterion.udpPort(), is(equalTo((short) 1)));
+ assertThat(udpPortCriterion.udpPort(), is(equalTo(1)));
}
/**
@@ -658,12 +658,12 @@
*/
@Test
public void testMatchUdpDstMethod() {
- Criterion matchUdpDst = Criteria.matchUdpDst((short) 1);
+ Criterion matchUdpDst = Criteria.matchUdpDst(1);
Criteria.UdpPortCriterion udpPortCriterion =
checkAndConvert(matchUdpDst,
Criterion.Type.UDP_DST,
Criteria.UdpPortCriterion.class);
- assertThat(udpPortCriterion.udpPort(), is(equalTo((short) 1)));
+ assertThat(udpPortCriterion.udpPort(), is(equalTo(1)));
}
/**
@@ -684,12 +684,12 @@
*/
@Test
public void testMatchSctpSrcMethod() {
- Criterion matchSctpSrc = Criteria.matchSctpSrc((short) 1);
+ Criterion matchSctpSrc = Criteria.matchSctpSrc(1);
Criteria.SctpPortCriterion sctpPortCriterion =
checkAndConvert(matchSctpSrc,
Criterion.Type.SCTP_SRC,
Criteria.SctpPortCriterion.class);
- assertThat(sctpPortCriterion.sctpPort(), is(equalTo((short) 1)));
+ assertThat(sctpPortCriterion.sctpPort(), is(equalTo(1)));
}
/**
@@ -697,12 +697,12 @@
*/
@Test
public void testMatchSctpDstMethod() {
- Criterion matchSctpDst = Criteria.matchSctpDst((short) 1);
+ Criterion matchSctpDst = Criteria.matchSctpDst(1);
Criteria.SctpPortCriterion sctpPortCriterion =
checkAndConvert(matchSctpDst,
Criterion.Type.SCTP_DST,
Criteria.SctpPortCriterion.class);
- assertThat(sctpPortCriterion.sctpPort(), is(equalTo((short) 1)));
+ assertThat(sctpPortCriterion.sctpPort(), is(equalTo(1)));
}
/**
@@ -723,7 +723,7 @@
*/
@Test
public void testMatchIcmpTypeMethod() {
- Byte icmpType = 12;
+ short icmpType = 12;
Criterion matchIcmpType = Criteria.matchIcmpType(icmpType);
Criteria.IcmpTypeCriterion icmpTypeCriterion =
checkAndConvert(matchIcmpType,
@@ -750,7 +750,7 @@
*/
@Test
public void testMatchIcmpCodeMethod() {
- Byte icmpCode = 12;
+ short icmpCode = 12;
Criterion matchIcmpCode = Criteria.matchIcmpCode(icmpCode);
Criteria.IcmpCodeCriterion icmpCodeCriterion =
checkAndConvert(matchIcmpCode,
@@ -777,7 +777,7 @@
*/
@Test
public void testMatchIPv6FlowLabelMethod() {
- Integer flowLabel = 12;
+ int flowLabel = 12;
Criterion matchFlowLabel = Criteria.matchIPv6FlowLabel(flowLabel);
Criteria.IPv6FlowLabelCriterion flowLabelCriterion =
checkAndConvert(matchFlowLabel,
@@ -804,7 +804,7 @@
*/
@Test
public void testMatchIcmpv6TypeMethod() {
- Byte icmpv6Type = 12;
+ short icmpv6Type = 12;
Criterion matchIcmpv6Type = Criteria.matchIcmpv6Type(icmpv6Type);
Criteria.Icmpv6TypeCriterion icmpv6TypeCriterion =
checkAndConvert(matchIcmpv6Type,
@@ -831,7 +831,7 @@
*/
@Test
public void testMatchIcmpv6CodeMethod() {
- Byte icmpv6Code = 12;
+ short icmpv6Code = 12;
Criterion matchIcmpv6Code = Criteria.matchIcmpv6Code(icmpv6Code);
Criteria.Icmpv6CodeCriterion icmpv6CodeCriterion =
checkAndConvert(matchIcmpv6Code,
diff --git a/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilder.java b/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilder.java
index 076bfd6..15aa511 100644
--- a/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilder.java
+++ b/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilder.java
@@ -333,12 +333,12 @@
case ICMPV6_TYPE:
Icmpv6TypeCriterion icmpv6Type = (Icmpv6TypeCriterion) c;
mBuilder.setExact(MatchField.ICMPV6_TYPE,
- U8.of(icmpv6Type.icmpv6Type().byteValue()));
+ U8.of(icmpv6Type.icmpv6Type()));
break;
case ICMPV6_CODE:
Icmpv6CodeCriterion icmpv6Code = (Icmpv6CodeCriterion) c;
mBuilder.setExact(MatchField.ICMPV6_CODE,
- U8.of(icmpv6Code.icmpv6Code().byteValue()));
+ U8.of(icmpv6Code.icmpv6Code()));
break;
case IPV6_ND_TARGET:
IPv6NDTargetAddressCriterion targetAddressCriterion =
@@ -361,19 +361,19 @@
break;
case MPLS_LABEL:
Criteria.MplsCriterion mp = (Criteria.MplsCriterion) c;
- mBuilder.setExact(MatchField.MPLS_LABEL,
- U32.of(mp.label().intValue()));
+ mBuilder.setExact(MatchField.MPLS_LABEL, U32.of(mp.label()));
break;
case OCH_SIGID:
LambdaCriterion lc = (LambdaCriterion) c;
mBuilder.setExact(MatchField.OCH_SIGID,
- new CircuitSignalID((byte) 1, (byte) 2, lc.lambda(), (short) 1));
+ new CircuitSignalID((byte) 1, (byte) 2,
+ (short) lc.lambda(), (short) 1));
break;
case OCH_SIGTYPE:
Criteria.OpticalSignalTypeCriterion sc =
(Criteria.OpticalSignalTypeCriterion) c;
mBuilder.setExact(MatchField.OCH_SIGTYPE,
- U8.of(sc.signalType()));
+ U8.of((short) sc.signalType()));
break;
case ARP_OP:
case ARP_SHA:
diff --git a/web/api/src/main/java/org/onosproject/codec/impl/CriterionCodec.java b/web/api/src/main/java/org/onosproject/codec/impl/CriterionCodec.java
index 1dddc88..135fd83 100644
--- a/web/api/src/main/java/org/onosproject/codec/impl/CriterionCodec.java
+++ b/web/api/src/main/java/org/onosproject/codec/impl/CriterionCodec.java
@@ -43,19 +43,17 @@
formatMap.put(Criterion.Type.IN_PORT, new FormatInPort());
formatMap.put(Criterion.Type.IN_PHY_PORT, new FormatInPort());
+ formatMap.put(Criterion.Type.METADATA, new FormatMetadata());
formatMap.put(Criterion.Type.ETH_DST, new FormatEth());
formatMap.put(Criterion.Type.ETH_SRC, new FormatEth());
- formatMap.put(Criterion.Type.IP_PROTO, new FormatIpProto());
formatMap.put(Criterion.Type.ETH_TYPE, new FormatEthType());
- formatMap.put(Criterion.Type.METADATA, new FormatMetadata());
formatMap.put(Criterion.Type.VLAN_VID, new FormatVlanVid());
formatMap.put(Criterion.Type.VLAN_PCP, new FormatVlanPcp());
formatMap.put(Criterion.Type.IP_DSCP, new FormatIpDscp());
formatMap.put(Criterion.Type.IP_ECN, new FormatIpEcn());
+ formatMap.put(Criterion.Type.IP_PROTO, new FormatIpProto());
formatMap.put(Criterion.Type.IPV4_SRC, new FormatIp());
formatMap.put(Criterion.Type.IPV4_DST, new FormatIp());
- formatMap.put(Criterion.Type.IPV6_SRC, new FormatIp());
- formatMap.put(Criterion.Type.IPV6_DST, new FormatIp());
formatMap.put(Criterion.Type.TCP_SRC, new FormatTcp());
formatMap.put(Criterion.Type.TCP_DST, new FormatTcp());
formatMap.put(Criterion.Type.UDP_SRC, new FormatUdp());
@@ -64,6 +62,8 @@
formatMap.put(Criterion.Type.SCTP_DST, new FormatSctp());
formatMap.put(Criterion.Type.ICMPV4_TYPE, new FormatIcmpV4Type());
formatMap.put(Criterion.Type.ICMPV4_CODE, new FormatIcmpV4Code());
+ formatMap.put(Criterion.Type.IPV6_SRC, new FormatIp());
+ formatMap.put(Criterion.Type.IPV6_DST, new FormatIp());
formatMap.put(Criterion.Type.IPV6_FLABEL, new FormatIpV6FLabel());
formatMap.put(Criterion.Type.ICMPV6_TYPE, new FormatIcmpV6Type());
formatMap.put(Criterion.Type.ICMPV6_CODE, new FormatIcmpV6Code());
@@ -73,21 +73,20 @@
formatMap.put(Criterion.Type.MPLS_LABEL, new FormatMplsLabel());
formatMap.put(Criterion.Type.OCH_SIGID, new FormatOchSigId());
formatMap.put(Criterion.Type.OCH_SIGTYPE, new FormatOchSigType());
- formatMap.put(Criterion.Type.MPLS_LABEL, new FormatMplsLabel());
// Currently unimplemented
formatMap.put(Criterion.Type.ARP_OP, new FormatUnknown());
- formatMap.put(Criterion.Type.ARP_SHA, new FormatUnknown());
formatMap.put(Criterion.Type.ARP_SPA, new FormatUnknown());
- formatMap.put(Criterion.Type.ARP_THA, new FormatUnknown());
formatMap.put(Criterion.Type.ARP_TPA, new FormatUnknown());
+ formatMap.put(Criterion.Type.ARP_SHA, new FormatUnknown());
+ formatMap.put(Criterion.Type.ARP_THA, new FormatUnknown());
formatMap.put(Criterion.Type.MPLS_TC, new FormatUnknown());
formatMap.put(Criterion.Type.MPLS_BOS, new FormatUnknown());
formatMap.put(Criterion.Type.PBB_ISID, new FormatUnknown());
- formatMap.put(Criterion.Type.PBB_UCA, new FormatUnknown());
formatMap.put(Criterion.Type.TUNNEL_ID, new FormatUnknown());
formatMap.put(Criterion.Type.IPV6_EXTHDR, new FormatUnknown());
formatMap.put(Criterion.Type.UNASSIGNED_40, new FormatUnknown());
+ formatMap.put(Criterion.Type.PBB_UCA, new FormatUnknown());
formatMap.put(Criterion.Type.TCP_FLAGS, new FormatUnknown());
formatMap.put(Criterion.Type.ACTSET_OUTPUT, new FormatUnknown());
formatMap.put(Criterion.Type.PACKET_TYPE, new FormatUnknown());
@@ -112,6 +111,15 @@
}
}
+ private static class FormatMetadata implements CriterionTypeFormatter {
+ @Override
+ public ObjectNode formatCriterion(ObjectNode root, Criterion criterion) {
+ final Criteria.MetadataCriterion metadataCriterion =
+ (Criteria.MetadataCriterion) criterion;
+ return root.put("metadata", metadataCriterion.metadata());
+ }
+ }
+
private static class FormatEth implements CriterionTypeFormatter {
@Override
public ObjectNode formatCriterion(ObjectNode root, Criterion criterion) {
@@ -120,15 +128,6 @@
}
}
- private static class FormatIpProto implements CriterionTypeFormatter {
- @Override
- public ObjectNode formatCriterion(ObjectNode root, Criterion criterion) {
- final Criteria.IPProtocolCriterion iPProtocolCriterion =
- (Criteria.IPProtocolCriterion) criterion;
- return root.put("protocol", iPProtocolCriterion.protocol());
- }
- }
-
private static class FormatEthType implements CriterionTypeFormatter {
@Override
public ObjectNode formatCriterion(ObjectNode root, Criterion criterion) {
@@ -138,15 +137,6 @@
}
}
- private static class FormatMetadata implements CriterionTypeFormatter {
- @Override
- public ObjectNode formatCriterion(ObjectNode root, Criterion criterion) {
- final Criteria.MetadataCriterion metadataCriterion =
- (Criteria.MetadataCriterion) criterion;
- return root.put("metadata", metadataCriterion.metadata());
- }
- }
-
private static class FormatVlanVid implements CriterionTypeFormatter {
@Override
public ObjectNode formatCriterion(ObjectNode root, Criterion criterion) {
@@ -183,6 +173,15 @@
}
}
+ private static class FormatIpProto implements CriterionTypeFormatter {
+ @Override
+ public ObjectNode formatCriterion(ObjectNode root, Criterion criterion) {
+ final Criteria.IPProtocolCriterion iPProtocolCriterion =
+ (Criteria.IPProtocolCriterion) criterion;
+ return root.put("protocol", iPProtocolCriterion.protocol());
+ }
+ }
+
private static class FormatIp implements CriterionTypeFormatter {
@Override
public ObjectNode formatCriterion(ObjectNode root, Criterion criterion) {
@@ -196,7 +195,7 @@
public ObjectNode formatCriterion(ObjectNode root, Criterion criterion) {
final Criteria.TcpPortCriterion tcpPortCriterion =
(Criteria.TcpPortCriterion) criterion;
- return root.put("tcpPort", tcpPortCriterion.tcpPort().byteValue());
+ return root.put("tcpPort", tcpPortCriterion.tcpPort());
}
}
@@ -205,7 +204,7 @@
public ObjectNode formatCriterion(ObjectNode root, Criterion criterion) {
final Criteria.UdpPortCriterion udpPortCriterion =
(Criteria.UdpPortCriterion) criterion;
- return root.put("udpPort", udpPortCriterion.udpPort().byteValue());
+ return root.put("udpPort", udpPortCriterion.udpPort());
}
}
@@ -214,8 +213,7 @@
public ObjectNode formatCriterion(ObjectNode root, Criterion criterion) {
final Criteria.SctpPortCriterion sctpPortCriterion =
(Criteria.SctpPortCriterion) criterion;
- return root.put("sctpPort",
- sctpPortCriterion.sctpPort().byteValue());
+ return root.put("sctpPort", sctpPortCriterion.sctpPort());
}
}
diff --git a/web/api/src/test/java/org/onosproject/codec/impl/CriterionCodecTest.java b/web/api/src/test/java/org/onosproject/codec/impl/CriterionCodecTest.java
index 64f8114..6276f24 100644
--- a/web/api/src/test/java/org/onosproject/codec/impl/CriterionCodecTest.java
+++ b/web/api/src/test/java/org/onosproject/codec/impl/CriterionCodecTest.java
@@ -134,10 +134,10 @@
*/
@Test
public void matchEthTypeTest() {
- Criterion criterion = Criteria.matchEthType((short) 3);
+ Criterion criterion = Criteria.matchEthType((short) 0x8844);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result.get("type").textValue(), is(criterion.type().toString()));
- assertThat(result.get("ethType").asInt(), is(3));
+ assertThat(result.get("ethType").asInt(), is(0x8844));
}
/**
@@ -156,10 +156,10 @@
*/
@Test
public void matchVlanPcpTest() {
- Criterion criterion = Criteria.matchVlanPcp((byte) 4);
+ Criterion criterion = Criteria.matchVlanPcp((byte) 7);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result.get("type").textValue(), is(criterion.type().toString()));
- assertThat(result.get("priority").asInt(), is(4));
+ assertThat(result.get("priority").asInt(), is(7));
}
/**
@@ -167,10 +167,10 @@
*/
@Test
public void matchIPDscpTest() {
- Criterion criterion = Criteria.matchIPDscp((byte) 5);
+ Criterion criterion = Criteria.matchIPDscp((byte) 63);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result.get("type").textValue(), is(criterion.type().toString()));
- assertThat(result.get("ipDscp").asInt(), is(5));
+ assertThat(result.get("ipDscp").asInt(), is(63));
}
/**
@@ -178,10 +178,10 @@
*/
@Test
public void matchIPEcnTest() {
- Criterion criterion = Criteria.matchIPEcn((byte) 2);
+ Criterion criterion = Criteria.matchIPEcn((byte) 7);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result.get("type").textValue(), is(criterion.type().toString()));
- assertThat(result.get("ipEcn").asInt(), is(2));
+ assertThat(result.get("ipEcn").asInt(), is(7));
}
/**
@@ -189,10 +189,10 @@
*/
@Test
public void matchIPProtocolTest() {
- Criterion criterion = Criteria.matchIPProtocol((byte) 7);
+ Criterion criterion = Criteria.matchIPProtocol((byte) 250);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result.get("type").textValue(), is(criterion.type().toString()));
- assertThat(result.get("protocol").asInt(), is(7));
+ assertThat(result.get("protocol").asInt(), is(250));
}
/**
@@ -222,10 +222,10 @@
*/
@Test
public void matchTcpSrcTest() {
- Criterion criterion = Criteria.matchTcpSrc((short) 22);
+ Criterion criterion = Criteria.matchTcpSrc((short) 40000);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result.get("type").textValue(), is(criterion.type().toString()));
- assertThat(result.get("tcpPort").asInt(), is(22));
+ assertThat(result.get("tcpPort").asInt(), is(40000));
}
/**
@@ -233,10 +233,10 @@
*/
@Test
public void matchTcpDstTest() {
- Criterion criterion = Criteria.matchTcpDst((short) 22);
+ Criterion criterion = Criteria.matchTcpDst((short) 40000);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result.get("type").textValue(), is(criterion.type().toString()));
- assertThat(result.get("tcpPort").asInt(), is(22));
+ assertThat(result.get("tcpPort").asInt(), is(40000));
}
/**
@@ -244,10 +244,10 @@
*/
@Test
public void matchUdpSrcTest() {
- Criterion criterion = Criteria.matchUdpSrc((short) 22);
+ Criterion criterion = Criteria.matchUdpSrc((short) 40000);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result.get("type").textValue(), is(criterion.type().toString()));
- assertThat(result.get("udpPort").asInt(), is(22));
+ assertThat(result.get("udpPort").asInt(), is(40000));
}
/**
@@ -255,10 +255,10 @@
*/
@Test
public void matchUdpDstTest() {
- Criterion criterion = Criteria.matchUdpDst((short) 22);
+ Criterion criterion = Criteria.matchUdpDst((short) 40000);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result.get("type").textValue(), is(criterion.type().toString()));
- assertThat(result.get("udpPort").asInt(), is(22));
+ assertThat(result.get("udpPort").asInt(), is(40000));
}
/**
@@ -266,10 +266,10 @@
*/
@Test
public void matchSctpSrcTest() {
- Criterion criterion = Criteria.matchSctpSrc((short) 22);
+ Criterion criterion = Criteria.matchSctpSrc((short) 40000);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result.get("type").textValue(), is(criterion.type().toString()));
- assertThat(result.get("sctpPort").asInt(), is(22));
+ assertThat(result.get("sctpPort").asInt(), is(40000));
}
/**
@@ -277,10 +277,10 @@
*/
@Test
public void matchSctpDstTest() {
- Criterion criterion = Criteria.matchSctpDst((short) 22);
+ Criterion criterion = Criteria.matchSctpDst((short) 40000);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result.get("type").textValue(), is(criterion.type().toString()));
- assertThat(result.get("sctpPort").asInt(), is(22));
+ assertThat(result.get("sctpPort").asInt(), is(40000));
}
/**
@@ -288,10 +288,10 @@
*/
@Test
public void matchIcmpTypeTest() {
- Criterion criterion = Criteria.matchIcmpType((byte) 6);
+ Criterion criterion = Criteria.matchIcmpType((byte) 250);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result.get("type").textValue(), is(criterion.type().toString()));
- assertThat(result.get("icmpType").asInt(), is(6));
+ assertThat(result.get("icmpType").asInt(), is(250));
}
/**
@@ -299,10 +299,10 @@
*/
@Test
public void matchIcmpCodeTest() {
- Criterion criterion = Criteria.matchIcmpCode((byte) 6);
+ Criterion criterion = Criteria.matchIcmpCode((byte) 250);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result.get("type").textValue(), is(criterion.type().toString()));
- assertThat(result.get("icmpCode").asInt(), is(6));
+ assertThat(result.get("icmpCode").asInt(), is(250));
}
/**
@@ -332,10 +332,10 @@
*/
@Test
public void matchIPv6FlowLabelTest() {
- Criterion criterion = Criteria.matchIPv6FlowLabel(7);
+ Criterion criterion = Criteria.matchIPv6FlowLabel(0xffffe);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result.get("type").textValue(), is(criterion.type().toString()));
- assertThat(result.get("flowLabel").asInt(), is(7));
+ assertThat(result.get("flowLabel").asInt(), is(0xffffe));
}
/**
@@ -343,10 +343,10 @@
*/
@Test
public void matchIcmpv6TypeTest() {
- Criterion criterion = Criteria.matchIcmpv6Type((byte) 15);
+ Criterion criterion = Criteria.matchIcmpv6Type((byte) 250);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result.get("type").textValue(), is(criterion.type().toString()));
- assertThat(result.get("icmpv6Type").asInt(), is(15));
+ assertThat(result.get("icmpv6Type").asInt(), is(250));
}
/**
@@ -354,10 +354,10 @@
*/
@Test
public void matchIcmpv6CodeTest() {
- Criterion criterion = Criteria.matchIcmpv6Code((byte) 17);
+ Criterion criterion = Criteria.matchIcmpv6Code((byte) 250);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result.get("type").textValue(), is(criterion.type().toString()));
- assertThat(result.get("icmpv6Code").asInt(), is(17));
+ assertThat(result.get("icmpv6Code").asInt(), is(250));
}
/**
@@ -400,10 +400,10 @@
*/
@Test
public void matchMplsLabelTest() {
- Criterion criterion = Criteria.matchMplsLabel(88);
+ Criterion criterion = Criteria.matchMplsLabel(0xffffe);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result.get("type").textValue(), is(criterion.type().toString()));
- assertThat(result.get("label").asInt(), is(88));
+ assertThat(result.get("label").asInt(), is(0xffffe));
}
/**
@@ -411,10 +411,10 @@
*/
@Test
public void matchLambdaTest() {
- Criterion criterion = Criteria.matchLambda((short) 9);
+ Criterion criterion = Criteria.matchLambda((short) 40000);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result.get("type").textValue(), is(criterion.type().toString()));
- assertThat(result.get("lambda").asInt(), is(9));
+ assertThat(result.get("lambda").asInt(), is(40000));
}
/**
@@ -422,10 +422,10 @@
*/
@Test
public void matchOpticalSignalTypeTest() {
- Criterion criterion = Criteria.matchOpticalSignalType((short) 11);
+ Criterion criterion = Criteria.matchOpticalSignalType((short) 40000);
ObjectNode result = criterionCodec.encode(criterion, context);
assertThat(result.get("type").textValue(), is(criterion.type().toString()));
- assertThat(result.get("signalType").asInt(), is(11));
+ assertThat(result.get("signalType").asInt(), is(40000));
}
}
diff --git a/web/api/src/test/java/org/onosproject/codec/impl/CriterionJsonMatcher.java b/web/api/src/test/java/org/onosproject/codec/impl/CriterionJsonMatcher.java
index 8032ee5..9901f1a 100644
--- a/web/api/src/test/java/org/onosproject/codec/impl/CriterionJsonMatcher.java
+++ b/web/api/src/test/java/org/onosproject/codec/impl/CriterionJsonMatcher.java
@@ -84,7 +84,8 @@
case ETH_TYPE:
final Criteria.EthTypeCriterion ethTypeCriterion =
(Criteria.EthTypeCriterion) criterion;
- final String ethType = ethTypeCriterion.ethType().toString();
+ final String ethType =
+ Long.toHexString(ethTypeCriterion.ethType());
final String jsonEthType = jsonCriterion.get("ethType").textValue();
if (!ethType.equals(jsonEthType)) {
description.appendText("ethType was " + jsonEthType);
@@ -139,10 +140,10 @@
case IP_PROTO:
final Criteria.IPProtocolCriterion iPProtocolCriterion =
(Criteria.IPProtocolCriterion) criterion;
- final byte protocol = iPProtocolCriterion.protocol();
- final byte jsonProtocol = (byte) jsonCriterion.get("protocol").shortValue();
+ final short protocol = iPProtocolCriterion.protocol();
+ final short jsonProtocol = jsonCriterion.get("protocol").shortValue();
if (protocol != jsonProtocol) {
- description.appendText("protocol was " + Byte.toString(jsonProtocol));
+ description.appendText("protocol was " + Short.toString(jsonProtocol));
return false;
}
break;
@@ -165,10 +166,10 @@
case TCP_DST:
final Criteria.TcpPortCriterion tcpPortCriterion =
(Criteria.TcpPortCriterion) criterion;
- final short tcpPort = tcpPortCriterion.tcpPort();
- final short jsonTcpPort = jsonCriterion.get("tcpPort").shortValue();
+ final int tcpPort = tcpPortCriterion.tcpPort();
+ final int jsonTcpPort = jsonCriterion.get("tcpPort").intValue();
if (tcpPort != jsonTcpPort) {
- description.appendText("tcp port was " + Short.toString(jsonTcpPort));
+ description.appendText("tcp port was " + Integer.toString(jsonTcpPort));
return false;
}
break;
@@ -177,10 +178,10 @@
case UDP_DST:
final Criteria.UdpPortCriterion udpPortCriterion =
(Criteria.UdpPortCriterion) criterion;
- final short udpPort = udpPortCriterion.udpPort();
- final short jsonUdpPort = jsonCriterion.get("udpPort").shortValue();
+ final int udpPort = udpPortCriterion.udpPort();
+ final int jsonUdpPort = jsonCriterion.get("udpPort").intValue();
if (udpPort != jsonUdpPort) {
- description.appendText("udp port was " + Short.toString(jsonUdpPort));
+ description.appendText("udp port was " + Integer.toString(jsonUdpPort));
return false;
}
break;
@@ -189,10 +190,10 @@
case SCTP_DST:
final Criteria.SctpPortCriterion sctpPortCriterion =
(Criteria.SctpPortCriterion) criterion;
- final short sctpPort = sctpPortCriterion.sctpPort();
- final short jsonSctpPort = jsonCriterion.get("sctpPort").shortValue();
+ final int sctpPort = sctpPortCriterion.sctpPort();
+ final int jsonSctpPort = jsonCriterion.get("sctpPort").intValue();
if (sctpPort != jsonSctpPort) {
- description.appendText("sctp port was " + Short.toString(jsonSctpPort));
+ description.appendText("sctp port was " + Integer.toString(jsonSctpPort));
return false;
}
break;
@@ -200,10 +201,10 @@
case ICMPV4_TYPE:
final Criteria.IcmpTypeCriterion icmpTypeCriterion =
(Criteria.IcmpTypeCriterion) criterion;
- final byte icmpType = icmpTypeCriterion.icmpType();
- final byte jsonIcmpType = (byte) jsonCriterion.get("icmpType").shortValue();
+ final short icmpType = icmpTypeCriterion.icmpType();
+ final short jsonIcmpType = jsonCriterion.get("icmpType").shortValue();
if (icmpType != jsonIcmpType) {
- description.appendText("icmp type was " + Byte.toString(jsonIcmpType));
+ description.appendText("icmp type was " + Short.toString(jsonIcmpType));
return false;
}
break;
@@ -211,10 +212,10 @@
case ICMPV4_CODE:
final Criteria.IcmpCodeCriterion icmpCodeCriterion =
(Criteria.IcmpCodeCriterion) criterion;
- final byte icmpCode = icmpCodeCriterion.icmpCode();
- final byte jsonIcmpCode = (byte) jsonCriterion.get("icmpCode").shortValue();
+ final short icmpCode = icmpCodeCriterion.icmpCode();
+ final short jsonIcmpCode = jsonCriterion.get("icmpCode").shortValue();
if (icmpCode != jsonIcmpCode) {
- description.appendText("icmp code was " + Byte.toString(jsonIcmpCode));
+ description.appendText("icmp code was " + Short.toString(jsonIcmpCode));
return false;
}
break;
@@ -233,10 +234,10 @@
case ICMPV6_TYPE:
final Criteria.Icmpv6TypeCriterion icmpv6TypeCriterion =
(Criteria.Icmpv6TypeCriterion) criterion;
- final byte icmpv6Type = icmpv6TypeCriterion.icmpv6Type();
- final byte jsonIcmpv6Type = (byte) jsonCriterion.get("icmpv6Type").shortValue();
+ final short icmpv6Type = icmpv6TypeCriterion.icmpv6Type();
+ final short jsonIcmpv6Type = jsonCriterion.get("icmpv6Type").shortValue();
if (icmpv6Type != jsonIcmpv6Type) {
- description.appendText("icmpv6 type was " + Byte.toString(jsonIcmpv6Type));
+ description.appendText("icmpv6 type was " + Short.toString(jsonIcmpv6Type));
return false;
}
break;
@@ -244,10 +245,10 @@
case ICMPV6_CODE:
final Criteria.Icmpv6CodeCriterion icmpv6CodeCriterion =
(Criteria.Icmpv6CodeCriterion) criterion;
- final byte icmpv6Code = icmpv6CodeCriterion.icmpv6Code();
- final byte jsonIcmpv6Code = (byte) jsonCriterion.get("icmpv6Code").shortValue();
+ final short icmpv6Code = icmpv6CodeCriterion.icmpv6Code();
+ final short jsonIcmpv6Code = jsonCriterion.get("icmpv6Code").shortValue();
if (icmpv6Code != jsonIcmpv6Code) {
- description.appendText("icmpv6 code was " + Byte.toString(jsonIcmpv6Code));
+ description.appendText("icmpv6 code was " + Short.toString(jsonIcmpv6Code));
return false;
}
break;
@@ -296,10 +297,10 @@
case OCH_SIGID:
final Criteria.LambdaCriterion lambdaCriterion =
(Criteria.LambdaCriterion) criterion;
- final short lambda = lambdaCriterion.lambda();
- final short jsonLambda = jsonCriterion.get("lambda").shortValue();
+ final int lambda = lambdaCriterion.lambda();
+ final int jsonLambda = jsonCriterion.get("lambda").intValue();
if (lambda != jsonLambda) {
- description.appendText("lambda was " + Short.toString(lambda));
+ description.appendText("lambda was " + Integer.toString(lambda));
return false;
}
break;
@@ -307,10 +308,10 @@
case OCH_SIGTYPE:
final Criteria.OpticalSignalTypeCriterion opticalSignalTypeCriterion =
(Criteria.OpticalSignalTypeCriterion) criterion;
- final short signalType = opticalSignalTypeCriterion.signalType();
- final short jsonSignalType = jsonCriterion.get("signalType").shortValue();
+ final int signalType = opticalSignalTypeCriterion.signalType();
+ final int jsonSignalType = jsonCriterion.get("signalType").intValue();
if (signalType != jsonSignalType) {
- description.appendText("signal type was " + Short.toString(signalType));
+ description.appendText("signal type was " + Integer.toString(signalType));
return false;
}
break;