Pavlin Radoslavov

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
......@@ -63,8 +63,8 @@ public class CriteriaTest {
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 @@ public class CriteriaTest {
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 @@ public class CriteriaTest {
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 @@ public class CriteriaTest {
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 @@ public class CriteriaTest {
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 @@ public class CriteriaTest {
*/
@Test
public void testMatchEthTypeMethod() {
Short ethType = 12;
int ethType = 12;
Criterion matchEthType = Criteria.matchEthType(ethType);
Criteria.EthTypeCriterion ethTypeCriterion =
checkAndConvert(matchEthType,
......@@ -606,12 +606,12 @@ public class CriteriaTest {
*/
@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 @@ public class CriteriaTest {
*/
@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 @@ public class CriteriaTest {
*/
@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 @@ public class CriteriaTest {
*/
@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 @@ public class CriteriaTest {
*/
@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 @@ public class CriteriaTest {
*/
@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 @@ public class CriteriaTest {
*/
@Test
public void testMatchIcmpTypeMethod() {
Byte icmpType = 12;
short icmpType = 12;
Criterion matchIcmpType = Criteria.matchIcmpType(icmpType);
Criteria.IcmpTypeCriterion icmpTypeCriterion =
checkAndConvert(matchIcmpType,
......@@ -750,7 +750,7 @@ public class CriteriaTest {
*/
@Test
public void testMatchIcmpCodeMethod() {
Byte icmpCode = 12;
short icmpCode = 12;
Criterion matchIcmpCode = Criteria.matchIcmpCode(icmpCode);
Criteria.IcmpCodeCriterion icmpCodeCriterion =
checkAndConvert(matchIcmpCode,
......@@ -777,7 +777,7 @@ public class CriteriaTest {
*/
@Test
public void testMatchIPv6FlowLabelMethod() {
Integer flowLabel = 12;
int flowLabel = 12;
Criterion matchFlowLabel = Criteria.matchIPv6FlowLabel(flowLabel);
Criteria.IPv6FlowLabelCriterion flowLabelCriterion =
checkAndConvert(matchFlowLabel,
......@@ -804,7 +804,7 @@ public class CriteriaTest {
*/
@Test
public void testMatchIcmpv6TypeMethod() {
Byte icmpv6Type = 12;
short icmpv6Type = 12;
Criterion matchIcmpv6Type = Criteria.matchIcmpv6Type(icmpv6Type);
Criteria.Icmpv6TypeCriterion icmpv6TypeCriterion =
checkAndConvert(matchIcmpv6Type,
......@@ -831,7 +831,7 @@ public class CriteriaTest {
*/
@Test
public void testMatchIcmpv6CodeMethod() {
Byte icmpv6Code = 12;
short icmpv6Code = 12;
Criterion matchIcmpv6Code = Criteria.matchIcmpv6Code(icmpv6Code);
Criteria.Icmpv6CodeCriterion icmpv6CodeCriterion =
checkAndConvert(matchIcmpv6Code,
......
......@@ -333,12 +333,12 @@ public abstract class FlowModBuilder {
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 @@ public abstract class FlowModBuilder {
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:
......
......@@ -43,19 +43,17 @@ public final class CriterionCodec extends JsonCodec<Criterion> {
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 @@ public final class CriterionCodec extends JsonCodec<Criterion> {
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 @@ public final class CriterionCodec extends JsonCodec<Criterion> {
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,20 +111,20 @@ public final class CriterionCodec extends JsonCodec<Criterion> {
}
}
private static class FormatEth implements CriterionTypeFormatter {
private static class FormatMetadata implements CriterionTypeFormatter {
@Override
public ObjectNode formatCriterion(ObjectNode root, Criterion criterion) {
final Criteria.EthCriterion ethCriterion = (Criteria.EthCriterion) criterion;
return root.put("mac", ethCriterion.mac().toString());
final Criteria.MetadataCriterion metadataCriterion =
(Criteria.MetadataCriterion) criterion;
return root.put("metadata", metadataCriterion.metadata());
}
}
private static class FormatIpProto implements CriterionTypeFormatter {
private static class FormatEth implements CriterionTypeFormatter {
@Override
public ObjectNode formatCriterion(ObjectNode root, Criterion criterion) {
final Criteria.IPProtocolCriterion iPProtocolCriterion =
(Criteria.IPProtocolCriterion) criterion;
return root.put("protocol", iPProtocolCriterion.protocol());
final Criteria.EthCriterion ethCriterion = (Criteria.EthCriterion) criterion;
return root.put("mac", ethCriterion.mac().toString());
}
}
......@@ -138,15 +137,6 @@ public final class CriterionCodec extends JsonCodec<Criterion> {
}
}
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 @@ public final class CriterionCodec extends JsonCodec<Criterion> {
}
}
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 final class CriterionCodec extends JsonCodec<Criterion> {
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 final class CriterionCodec extends JsonCodec<Criterion> {
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 final class CriterionCodec extends JsonCodec<Criterion> {
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());
}
}
......
......@@ -134,10 +134,10 @@ public class CriterionCodecTest {
*/
@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 @@ public class CriterionCodecTest {
*/
@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 @@ public class CriterionCodecTest {
*/
@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 @@ public class CriterionCodecTest {
*/
@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 @@ public class CriterionCodecTest {
*/
@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 @@ public class CriterionCodecTest {
*/
@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 @@ public class CriterionCodecTest {
*/
@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 @@ public class CriterionCodecTest {
*/
@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 @@ public class CriterionCodecTest {
*/
@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 @@ public class CriterionCodecTest {
*/
@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 @@ public class CriterionCodecTest {
*/
@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 @@ public class CriterionCodecTest {
*/
@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 @@ public class CriterionCodecTest {
*/
@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 @@ public class CriterionCodecTest {
*/
@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 @@ public class CriterionCodecTest {
*/
@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 @@ public class CriterionCodecTest {
*/
@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 @@ public class CriterionCodecTest {
*/
@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 @@ public class CriterionCodecTest {
*/
@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 @@ public class CriterionCodecTest {
*/
@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));
}
}
......
......@@ -84,7 +84,8 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo
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 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo
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 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo
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 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo
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 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo
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 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo
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 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo
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 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo
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 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo
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 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo
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 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo
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;
......