Pavlin Radoslavov

Implement some of the missing Selector and Match Conditions

Work toward ONOS-509

The following match conditions are added/implemented:
 - UDP_SRC, UDP_DST
 - SCTP_SRC, SCTP_DST
 - ICMPV4_TYPE, ICMPV4_CODE
 - IPV6_FLABEL
 - IPV6_ND_TARGET
 - IPV6_ND_SLL
 - IPV6_ND_TLL

Also:
 * Renamed method
     TrafficSelector.Builder.matchInport(PortNumber port)
   to
     TrafficSelector.Builder.matchInPort(PortNumber port)
   (for consistency with the corresponding method(s) elsewhere)
 * Reordered the code for some of the existing matching conditions
   to follow the order in the OpenFlow spec, so it is easier to
   cross-reference such code.
 * Added missing Javadoc
 * Added few more Criterion.Type values as per OpenFlow spec 1.5.0

Change-Id: I7fc1656f32d8a7280c67d7827e4aa84528b0eafc
......@@ -288,7 +288,7 @@ public class ReactiveForwarding {
builder.matchEthType(inPkt.getEtherType())
.matchEthSrc(inPkt.getSourceMAC())
.matchEthDst(inPkt.getDestinationMAC())
.matchInport(context.inPacket().receivedFrom().port());
.matchInPort(context.inPacket().receivedFrom().port());
TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder();
treat.setOutput(portNumber);
......
......@@ -107,21 +107,21 @@ public class LambdaForwarding {
case 1:
inport = 10;
outport = 20;
sbuilder.matchInport(PortNumber.portNumber(inport));
sbuilder.matchInPort(PortNumber.portNumber(inport));
tbuilder.setOutput(PortNumber.portNumber(outport)).setLambda(lambda);
break;
case 2:
inport = 21;
outport = 11;
sbuilder.matchLambda(lambda).
matchInport(PortNumber.portNumber(inport)); // match sigtype
matchInPort(PortNumber.portNumber(inport)); // match sigtype
tbuilder.setOutput(PortNumber.portNumber(outport));
break;
case 3:
inport = 30;
outport = 31;
sbuilder.matchLambda(lambda).
matchInport(PortNumber.portNumber(inport));
matchInPort(PortNumber.portNumber(inport));
tbuilder.setOutput(PortNumber.portNumber(outport)).setLambda(lambda);
break;
default:
......
......@@ -106,7 +106,7 @@ public class MPLSForwarding {
switch (switchNumber) {
case 1:
sbuilder.matchInport(PortNumber.portNumber(inport));
sbuilder.matchInPort(PortNumber.portNumber(inport));
tbuilder.setOutput(PortNumber.portNumber(outport))
.pushMpls()
.setMpls(mplsLabel);
......@@ -114,13 +114,13 @@ public class MPLSForwarding {
case 2:
sbuilder.matchMplsLabel(mplsLabel)
.matchEthType(Ethernet.MPLS_UNICAST)
.matchInport(PortNumber.portNumber(inport));
.matchInPort(PortNumber.portNumber(inport));
tbuilder.setOutput(PortNumber.portNumber(outport));
break;
case 3:
sbuilder.matchMplsLabel(mplsLabel)
.matchEthType(Ethernet.MPLS_UNICAST)
.matchInport(PortNumber.portNumber(inport));
.matchInPort(PortNumber.portNumber(inport));
tbuilder.popMpls().setOutput(PortNumber.portNumber(outport));
break;
default:
......
......@@ -24,6 +24,7 @@ import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.criteria.Criteria;
import org.onosproject.net.flow.criteria.Criterion;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.Ip6Address;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
......@@ -129,22 +130,22 @@ public final class DefaultTrafficSelector implements TrafficSelector {
}
@Override
public Builder matchInport(PortNumber port) {
public Builder matchInPort(PortNumber port) {
return add(Criteria.matchInPort(port));
}
@Override
public Builder matchEthSrc(MacAddress addr) {
return add(Criteria.matchEthSrc(addr));
public Builder matchEthDst(MacAddress addr) {
return add(Criteria.matchEthDst(addr));
}
@Override
public Builder matchEthDst(MacAddress addr) {
return add(Criteria.matchEthDst(addr));
public Builder matchEthSrc(MacAddress addr) {
return add(Criteria.matchEthSrc(addr));
}
@Override
public Builder matchEthType(short ethType) {
public Builder matchEthType(Short ethType) {
return add(Criteria.matchEthType(ethType));
}
......@@ -184,6 +185,36 @@ public final class DefaultTrafficSelector implements TrafficSelector {
}
@Override
public Builder matchUdpSrc(Short udpPort) {
return add(Criteria.matchUdpSrc(udpPort));
}
@Override
public Builder matchUdpDst(Short udpPort) {
return add(Criteria.matchUdpDst(udpPort));
}
@Override
public Builder matchSctpSrc(Short sctpPort) {
return add(Criteria.matchSctpSrc(sctpPort));
}
@Override
public Builder matchSctpDst(Short sctpPort) {
return add(Criteria.matchSctpDst(sctpPort));
}
@Override
public Builder matchIcmpType(Byte icmpType) {
return add(Criteria.matchIcmpType(icmpType));
}
@Override
public Builder matchIcmpCode(Byte icmpCode) {
return add(Criteria.matchIcmpCode(icmpCode));
}
@Override
public Builder matchIPv6Src(IpPrefix ip) {
return add(Criteria.matchIPv6Src(ip));
}
......@@ -194,6 +225,11 @@ public final class DefaultTrafficSelector implements TrafficSelector {
}
@Override
public Builder matchIPv6FlowLabel(Integer flowLabel) {
return add(Criteria.matchIPv6FlowLabel(flowLabel));
}
@Override
public Builder matchIcmpv6Type(Byte icmpv6Type) {
return add(Criteria.matchIcmpv6Type(icmpv6Type));
}
......@@ -204,6 +240,21 @@ public final class DefaultTrafficSelector implements TrafficSelector {
}
@Override
public Builder matchIPv6NDTargetAddress(Ip6Address targetAddress) {
return add(Criteria.matchIPv6NDTargetAddress(targetAddress));
}
@Override
public Builder matchIPv6NDSourceLinkLayerAddress(MacAddress mac) {
return add(Criteria.matchIPv6NDSourceLinkLayerAddress(mac));
}
@Override
public Builder matchIPv6NDTargetLinkLayerAddress(MacAddress mac) {
return add(Criteria.matchIPv6NDTargetLinkLayerAddress(mac));
}
@Override
public Builder matchMplsLabel(Integer mplsLabel) {
return add(Criteria.matchMplsLabel(mplsLabel));
}
......
......@@ -20,6 +20,7 @@ import java.util.Set;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.criteria.Criterion;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.Ip6Address;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
......@@ -64,23 +65,23 @@ public interface TrafficSelector {
* @param port the inport
* @return a selection builder
*/
public Builder matchInport(PortNumber port);
public Builder matchInPort(PortNumber port);
/**
* Matches a l2 src address.
* Matches a l2 dst address.
*
* @param addr a l2 address
* @return a selection builder
*/
public Builder matchEthSrc(MacAddress addr);
public Builder matchEthDst(MacAddress addr);
/**
* Matches a l2 dst address.
* Matches a l2 src address.
*
* @param addr a l2 address
* @return a selection builder
*/
public Builder matchEthDst(MacAddress addr);
public Builder matchEthSrc(MacAddress addr);
/**
* Matches the ethernet type.
......@@ -88,7 +89,7 @@ public interface TrafficSelector {
* @param ethType an ethernet type
* @return a selection builder
*/
public Builder matchEthType(short ethType);
public Builder matchEthType(Short ethType);
/**
* Matches the vlan id.
......@@ -147,6 +148,54 @@ public interface TrafficSelector {
public Builder matchTcpDst(Short tcpPort);
/**
* Matches an UDP source port number.
*
* @param udpPort an UDP source port number
* @return a selection builder
*/
public Builder matchUdpSrc(Short udpPort);
/**
* Matches an UDP destination port number.
*
* @param udpPort an UDP destination port number
* @return a selection builder
*/
public Builder matchUdpDst(Short udpPort);
/**
* Matches a SCTP source port number.
*
* @param sctpPort a SCTP source port number
* @return a selection builder
*/
public Builder matchSctpSrc(Short sctpPort);
/**
* Matches a SCTP destination port number.
*
* @param sctpPort a SCTP destination port number
* @return a selection builder
*/
public Builder matchSctpDst(Short sctpPort);
/**
* Matches an ICMP type.
*
* @param icmpType an ICMP type
* @return a selection builder
*/
public Builder matchIcmpType(Byte icmpType);
/**
* Matches an ICMP code.
*
* @param icmpCode an ICMP code
* @return a selection builder
*/
public Builder matchIcmpCode(Byte icmpCode);
/**
* Matches a l3 IPv6 address.
*
* @param ip a l3 IPv6 address
......@@ -163,23 +212,56 @@ public interface TrafficSelector {
public Builder matchIPv6Dst(IpPrefix ip);
/**
* Matches a ICMPv6 type.
* Matches an IPv6 flow label.
*
* @param icmpv6Type a ICMPv6 type
* @param flowLabel an IPv6 flow label
* @return a selection builder
*/
public Builder matchIPv6FlowLabel(Integer flowLabel);
/**
* Matches an ICMPv6 type.
*
* @param icmpv6Type an ICMPv6 type
* @return a selection builder
*/
public Builder matchIcmpv6Type(Byte icmpv6Type);
/**
* Matches a ICMPv6 code.
* Matches an ICMPv6 code.
*
* @param icmpv6Code a ICMPv6 code
* @param icmpv6Code an ICMPv6 code
* @return a selection builder
*/
public Builder matchIcmpv6Code(Byte icmpv6Code);
/**
* Matches on a MPLS label .
* Matches an IPv6 Neighbor Discovery target address.
*
* @param targetAddress an IPv6 Neighbor Discovery target address
* @return a selection builder
*/
public Builder matchIPv6NDTargetAddress(Ip6Address targetAddress);
/**
* Matches an IPv6 Neighbor Discovery source link-layer address.
*
* @param mac an IPv6 Neighbor Discovery source link-layer address
* @return a selection builder
*/
public Builder matchIPv6NDSourceLinkLayerAddress(MacAddress mac);
/**
* Matches an IPv6 Neighbor Discovery target link-layer address.
*
* @param mac an IPv6 Neighbor Discovery target link-layer address
* @return a selection builder
*/
public Builder matchIPv6NDTargetLinkLayerAddress(MacAddress mac);
/**
* Matches on a MPLS label.
*
* @param mplsLabel a MPLS label.
* @return a selection builder
*/
......@@ -208,5 +290,4 @@ public interface TrafficSelector {
*/
TrafficSelector build();
}
}
......
......@@ -24,7 +24,7 @@ public interface Criterion {
/**
* Types of fields to which the selection criterion may apply.
*/
// From page 42 of OpenFlow 1.3.x spec
// From page 75 of OpenFlow 1.5.0 spec
public enum Type {
/** Switch input port. */
IN_PORT,
......@@ -106,6 +106,21 @@ public interface Criterion {
TUNNEL_ID,
/** IPv6 Extension Header pseudo-field. */
IPV6_EXTHDR,
/** Unassigned value: 40. */
UNASSIGNED_40,
/** PBB UCA header field. */
PBB_UCA,
/** TCP flags. */
TCP_FLAGS,
/** Output port from action set metadata. */
ACTSET_OUTPUT,
/** Packet type value. */
PACKET_TYPE,
//
// NOTE: Everything below is defined elsewhere: ONOS-specific,
// extensions, etc.
//
/** Optical channel signal ID (lambda). */
OCH_SIGID,
/** Optical channel signal type (fixed or flexible). */
......
......@@ -25,6 +25,7 @@ import org.junit.Test;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.criteria.Criteria;
import org.onosproject.net.flow.criteria.Criterion;
import org.onlab.packet.Ip6Address;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
......@@ -126,22 +127,25 @@ public class DefaultTrafficSelectorTest {
public void testCriteriaCreation() {
TrafficSelector selector;
final int intValue = 22;
final short shortValue = 33;
final byte byteValue = 44;
final MacAddress macValue = MacAddress.valueOf("11:22:33:44:55:66");
final IpPrefix ipPrefixValue = IpPrefix.valueOf("192.168.1.0/24");
final IpPrefix ipv6PrefixValue = IpPrefix.valueOf("fe80::1/64");
final Ip6Address ipv6AddressValue = Ip6Address.valueOf("fe80::1");
selector = DefaultTrafficSelector.builder()
.matchInport(PortNumber.portNumber(11)).build();
.matchInPort(PortNumber.portNumber(11)).build();
assertThat(selector, hasCriterionWithType(Type.IN_PORT));
selector = DefaultTrafficSelector.builder()
.matchEthSrc(MacAddress.BROADCAST).build();
assertThat(selector, hasCriterionWithType(Type.ETH_SRC));
.matchEthDst(macValue).build();
assertThat(selector, hasCriterionWithType(Type.ETH_DST));
selector = DefaultTrafficSelector.builder()
.matchEthDst(MacAddress.BROADCAST).build();
assertThat(selector, hasCriterionWithType(Type.ETH_DST));
.matchEthSrc(macValue).build();
assertThat(selector, hasCriterionWithType(Type.ETH_SRC));
selector = DefaultTrafficSelector.builder()
.matchEthType(shortValue).build();
......@@ -176,6 +180,30 @@ public class DefaultTrafficSelectorTest {
assertThat(selector, hasCriterionWithType(Type.TCP_DST));
selector = DefaultTrafficSelector.builder()
.matchUdpSrc(shortValue).build();
assertThat(selector, hasCriterionWithType(Type.UDP_SRC));
selector = DefaultTrafficSelector.builder()
.matchUdpDst(shortValue).build();
assertThat(selector, hasCriterionWithType(Type.UDP_DST));
selector = DefaultTrafficSelector.builder()
.matchSctpSrc(shortValue).build();
assertThat(selector, hasCriterionWithType(Type.SCTP_SRC));
selector = DefaultTrafficSelector.builder()
.matchSctpDst(shortValue).build();
assertThat(selector, hasCriterionWithType(Type.SCTP_DST));
selector = DefaultTrafficSelector.builder()
.matchIcmpType(byteValue).build();
assertThat(selector, hasCriterionWithType(Type.ICMPV4_TYPE));
selector = DefaultTrafficSelector.builder()
.matchIcmpCode(byteValue).build();
assertThat(selector, hasCriterionWithType(Type.ICMPV4_CODE));
selector = DefaultTrafficSelector.builder()
.matchIPv6Src(ipv6PrefixValue).build();
assertThat(selector, hasCriterionWithType(Type.IPV6_SRC));
......@@ -184,6 +212,26 @@ public class DefaultTrafficSelectorTest {
assertThat(selector, hasCriterionWithType(Type.IPV6_DST));
selector = DefaultTrafficSelector.builder()
.matchIPv6FlowLabel(intValue).build();
assertThat(selector, hasCriterionWithType(Type.IPV6_FLABEL));
selector = DefaultTrafficSelector.builder()
.matchIcmpv6Type(byteValue).build();
assertThat(selector, hasCriterionWithType(Type.ICMPV6_TYPE));
selector = DefaultTrafficSelector.builder()
.matchIPv6NDTargetAddress(ipv6AddressValue).build();
assertThat(selector, hasCriterionWithType(Type.IPV6_ND_TARGET));
selector = DefaultTrafficSelector.builder()
.matchIPv6NDSourceLinkLayerAddress(macValue).build();
assertThat(selector, hasCriterionWithType(Type.IPV6_ND_SLL));
selector = DefaultTrafficSelector.builder()
.matchIPv6NDTargetLinkLayerAddress(macValue).build();
assertThat(selector, hasCriterionWithType(Type.IPV6_ND_TLL));
selector = DefaultTrafficSelector.builder()
.matchMplsLabel(3).build();
assertThat(selector, hasCriterionWithType(Type.MPLS_LABEL));
......@@ -194,12 +242,21 @@ public class DefaultTrafficSelectorTest {
selector = DefaultTrafficSelector.builder()
.matchOpticalSignalType(shortValue).build();
assertThat(selector, hasCriterionWithType(Type.OCH_SIGTYPE));
}
/**
* Tests the traffic selector builder.
*/
@Test
public void testTrafficSelectorBuilder() {
TrafficSelector selector;
final short shortValue = 33;
final TrafficSelector baseSelector = DefaultTrafficSelector.builder()
.matchOpticalSignalType(shortValue).build();
.matchLambda(shortValue).build();
selector = DefaultTrafficSelector.builder(baseSelector)
.build();
assertThat(selector, hasCriterionWithType(Type.OCH_SIGTYPE));
assertThat(selector, hasCriterionWithType(Type.OCH_SIGID));
final Criterion criterion = Criteria.matchLambda(shortValue);
selector = DefaultTrafficSelector.builder()
......
......@@ -127,7 +127,7 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
LinkResourceAllocations allocations,
FlowRuleOperation operation) {
TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
selectorBuilder.matchInport(intent.src().port());
selectorBuilder.matchInPort(intent.src().port());
List<FlowRuleBatchEntry> rules = Lists.newLinkedList();
ConnectPoint prev = intent.src();
......@@ -163,7 +163,7 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
rules.add(new FlowRuleBatchEntry(operation, rule));
prev = link.dst();
selectorBuilder.matchInport(link.dst().port());
selectorBuilder.matchInPort(link.dst().port());
selectorBuilder.matchOpticalSignalType(SIGNAL_TYPE); //todo
selectorBuilder.matchLambda((short) la.toInt());
......
......@@ -92,7 +92,7 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
List<FlowRuleBatchEntry> rules = Lists.newLinkedList();
// TODO Generate multiple batches
while (links.hasNext()) {
builder.matchInport(prev.port());
builder.matchInPort(prev.port());
Link link = links.next();
// if this is the last flow rule, apply the intent's treatments
TrafficTreatment treatment =
......@@ -124,7 +124,7 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
List<FlowRuleBatchEntry> rules = Lists.newLinkedList();
// TODO Generate multiple batches
while (links.hasNext()) {
builder.matchInport(prev.port());
builder.matchInPort(prev.port());
Link link = links.next();
// if this is the last flow rule, apply the intent's treatments
TrafficTreatment treatment =
......
......@@ -44,11 +44,11 @@ public class CriterionCodec extends JsonCodec<Criterion> {
case IN_PORT:
final Criteria.PortCriterion portCriterion = (Criteria.PortCriterion) criterion;
result.put("tcpPort", portCriterion.port().toLong());
result.put("port", portCriterion.port().toLong());
break;
case ETH_SRC:
case ETH_DST:
case ETH_SRC:
final Criteria.EthCriterion ethCriterion = (Criteria.EthCriterion) criterion;
result.put("mac", ethCriterion.mac().toString());
break;
......@@ -59,18 +59,10 @@ public class CriterionCodec extends JsonCodec<Criterion> {
result.put("ethType", ethTypeCriterion.ethType());
break;
case IPV4_SRC:
case IPV6_SRC:
case IPV4_DST:
case IPV6_DST:
final Criteria.IPCriterion iPCriterion = (Criteria.IPCriterion) criterion;
result.put("ip", iPCriterion.ip().toString());
break;
case IP_PROTO:
final Criteria.IPProtocolCriterion iPProtocolCriterion =
(Criteria.IPProtocolCriterion) criterion;
result.put("protocol", iPProtocolCriterion.protocol());
case VLAN_VID:
final Criteria.VlanIdCriterion vlanIdCriterion =
(Criteria.VlanIdCriterion) criterion;
result.put("vlanId", vlanIdCriterion.vlanId().toShort());
break;
case VLAN_PCP:
......@@ -79,10 +71,18 @@ public class CriterionCodec extends JsonCodec<Criterion> {
result.put("priority", vlanPcpCriterion.priority());
break;
case VLAN_VID:
final Criteria.VlanIdCriterion vlanIdCriterion =
(Criteria.VlanIdCriterion) criterion;
result.put("vlanId", vlanIdCriterion.vlanId().toShort());
case IP_PROTO:
final Criteria.IPProtocolCriterion iPProtocolCriterion =
(Criteria.IPProtocolCriterion) criterion;
result.put("protocol", iPProtocolCriterion.protocol());
break;
case IPV4_SRC:
case IPV4_DST:
case IPV6_SRC:
case IPV6_DST:
final Criteria.IPCriterion iPCriterion = (Criteria.IPCriterion) criterion;
result.put("ip", iPCriterion.ip().toString());
break;
case TCP_SRC:
......@@ -92,6 +92,67 @@ public class CriterionCodec extends JsonCodec<Criterion> {
result.put("tcpPort", tcpPortCriterion.tcpPort().byteValue());
break;
case UDP_SRC:
case UDP_DST:
final Criteria.UdpPortCriterion udpPortCriterion =
(Criteria.UdpPortCriterion) criterion;
result.put("udpPort", udpPortCriterion.udpPort().byteValue());
break;
case SCTP_SRC:
case SCTP_DST:
final Criteria.SctpPortCriterion sctpPortCriterion =
(Criteria.SctpPortCriterion) criterion;
result.put("sctpPort",
sctpPortCriterion.sctpPort().byteValue());
break;
case ICMPV4_TYPE:
final Criteria.IcmpTypeCriterion icmpTypeCriterion =
(Criteria.IcmpTypeCriterion) criterion;
result.put("icmpType", icmpTypeCriterion.icmpType());
break;
case ICMPV4_CODE:
final Criteria.IcmpCodeCriterion icmpCodeCriterion =
(Criteria.IcmpCodeCriterion) criterion;
result.put("icmpCode", icmpCodeCriterion.icmpCode());
break;
case IPV6_FLABEL:
final Criteria.IPv6FlowLabelCriterion ipv6FlowLabelCriterion =
(Criteria.IPv6FlowLabelCriterion) criterion;
result.put("flowLabel",
ipv6FlowLabelCriterion.flowLabel());
break;
case ICMPV6_TYPE:
final Criteria.Icmpv6TypeCriterion icmpv6TypeCriterion =
(Criteria.Icmpv6TypeCriterion) criterion;
result.put("icmpv6Type", icmpv6TypeCriterion.icmpv6Type());
break;
case ICMPV6_CODE:
final Criteria.Icmpv6CodeCriterion icmpv6CodeCriterion =
(Criteria.Icmpv6CodeCriterion) criterion;
result.put("icmpv6Code", icmpv6CodeCriterion.icmpv6Code());
break;
case IPV6_ND_TARGET:
final Criteria.IPv6NDTargetAddressCriterion ipv6NDTargetAddressCriterion
= (Criteria.IPv6NDTargetAddressCriterion) criterion;
result.put("targetAddress",
ipv6NDTargetAddressCriterion.targetAddress().toString());
break;
case IPV6_ND_SLL:
case IPV6_ND_TLL:
final Criteria.IPv6NDLinkLayerAddressCriterion ipv6NDLinkLayerAddressCriterion
= (Criteria.IPv6NDLinkLayerAddressCriterion) criterion;
result.put("mac",
ipv6NDLinkLayerAddressCriterion.mac().toString());
break;
case MPLS_LABEL:
final Criteria.MplsCriterion mplsCriterion =
(Criteria.MplsCriterion) criterion;
......
......@@ -33,6 +33,7 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo
criterion = criterionValue;
}
// CHECKSTYLE IGNORE MethodLength FOR NEXT 300 LINES
@Override
public boolean matchesSafely(JsonNode jsonCriterion, Description description) {
final String type = criterion.type().name();
......@@ -54,8 +55,8 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo
}
break;
case ETH_SRC:
case ETH_DST:
case ETH_SRC:
final Criteria.EthCriterion ethCriterion = (Criteria.EthCriterion) criterion;
final String mac = ethCriterion.mac().toString();
final String jsonMac = jsonCriterion.get("mac").textValue();
......@@ -76,15 +77,24 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo
}
break;
case IPV4_SRC:
case IPV6_SRC:
case IPV4_DST:
case IPV6_DST:
final Criteria.IPCriterion ipCriterion = (Criteria.IPCriterion) criterion;
final String ip = ipCriterion.ip().toString();
final String jsonIp = jsonCriterion.get("ip").textValue();
if (!ip.equals(jsonIp)) {
description.appendText("ip was " + jsonIp);
case VLAN_VID:
final Criteria.VlanIdCriterion vlanIdCriterion =
(Criteria.VlanIdCriterion) criterion;
final short vlanId = vlanIdCriterion.vlanId().toShort();
final short jsonVlanId = jsonCriterion.get("vlanId").shortValue();
if (vlanId != jsonVlanId) {
description.appendText("vlanId was " + Short.toString(jsonVlanId));
return false;
}
break;
case VLAN_PCP:
final Criteria.VlanPcpCriterion vlanPcpCriterion =
(Criteria.VlanPcpCriterion) criterion;
final byte priority = vlanPcpCriterion.priority();
final byte jsonPriority = (byte) jsonCriterion.get("priority").shortValue();
if (priority != jsonPriority) {
description.appendText("priority was " + Byte.toString(jsonPriority));
return false;
}
break;
......@@ -100,24 +110,15 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo
}
break;
case VLAN_PCP:
final Criteria.VlanPcpCriterion vlanPcpCriterion =
(Criteria.VlanPcpCriterion) criterion;
final byte priority = vlanPcpCriterion.priority();
final byte jsonPriority = (byte) jsonCriterion.get("protocol").shortValue();
if (priority != jsonPriority) {
description.appendText("priority was " + Byte.toString(jsonPriority));
return false;
}
break;
case VLAN_VID:
final Criteria.VlanIdCriterion vlanIdCriterion =
(Criteria.VlanIdCriterion) criterion;
final short vlanId = vlanIdCriterion.vlanId().toShort();
final short jsonvlanId = jsonCriterion.get("vlanId").shortValue();
if (vlanId != jsonvlanId) {
description.appendText("vlanId was " + Short.toString(jsonvlanId));
case IPV4_SRC:
case IPV4_DST:
case IPV6_SRC:
case IPV6_DST:
final Criteria.IPCriterion ipCriterion = (Criteria.IPCriterion) criterion;
final String ip = ipCriterion.ip().toString();
final String jsonIp = jsonCriterion.get("ip").textValue();
if (!ip.equals(jsonIp)) {
description.appendText("ip was " + jsonIp);
return false;
}
break;
......@@ -126,10 +127,119 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo
case TCP_DST:
final Criteria.TcpPortCriterion tcpPortCriterion =
(Criteria.TcpPortCriterion) criterion;
final byte tcpPort = tcpPortCriterion.tcpPort().byteValue();
final byte jsonTcpPort = (byte) jsonCriterion.get("tcpPort").shortValue();
final short tcpPort = tcpPortCriterion.tcpPort();
final short jsonTcpPort = jsonCriterion.get("tcpPort").shortValue();
if (tcpPort != jsonTcpPort) {
description.appendText("tcp port was " + Byte.toString(jsonTcpPort));
description.appendText("tcp port was " + Short.toString(jsonTcpPort));
return false;
}
break;
case UDP_SRC:
case UDP_DST:
final Criteria.UdpPortCriterion udpPortCriterion =
(Criteria.UdpPortCriterion) criterion;
final short udpPort = udpPortCriterion.udpPort();
final short jsonUdpPort = jsonCriterion.get("udpPort").shortValue();
if (udpPort != jsonUdpPort) {
description.appendText("udp port was " + Short.toString(jsonUdpPort));
return false;
}
break;
case SCTP_SRC:
case SCTP_DST:
final Criteria.SctpPortCriterion sctpPortCriterion =
(Criteria.SctpPortCriterion) criterion;
final short sctpPort = sctpPortCriterion.sctpPort();
final short jsonSctpPort = jsonCriterion.get("sctpPort").shortValue();
if (sctpPort != jsonSctpPort) {
description.appendText("sctp port was " + Short.toString(jsonSctpPort));
return false;
}
break;
case ICMPV4_TYPE:
final Criteria.IcmpTypeCriterion icmpTypeCriterion =
(Criteria.IcmpTypeCriterion) criterion;
final byte icmpType = icmpTypeCriterion.icmpType();
final byte jsonIcmpType = (byte) jsonCriterion.get("icmpType").shortValue();
if (icmpType != jsonIcmpType) {
description.appendText("icmp type was " + Byte.toString(jsonIcmpType));
return false;
}
break;
case ICMPV4_CODE:
final Criteria.IcmpCodeCriterion icmpCodeCriterion =
(Criteria.IcmpCodeCriterion) criterion;
final byte icmpCode = icmpCodeCriterion.icmpCode();
final byte jsonIcmpCode = (byte) jsonCriterion.get("icmpCode").shortValue();
if (icmpCode != jsonIcmpCode) {
description.appendText("icmp code was " + Byte.toString(jsonIcmpCode));
return false;
}
break;
case IPV6_FLABEL:
final Criteria.IPv6FlowLabelCriterion ipv6FlowLabelCriterion =
(Criteria.IPv6FlowLabelCriterion) criterion;
final int flowLabel = ipv6FlowLabelCriterion.flowLabel();
final int jsonFlowLabel = jsonCriterion.get("flowLabel").intValue();
if (flowLabel != jsonFlowLabel) {
description.appendText("IPv6 flow label was " + Integer.toString(jsonFlowLabel));
return false;
}
break;
case ICMPV6_TYPE:
final Criteria.Icmpv6TypeCriterion icmpv6TypeCriterion =
(Criteria.Icmpv6TypeCriterion) criterion;
final byte icmpv6Type = icmpv6TypeCriterion.icmpv6Type();
final byte jsonIcmpv6Type = (byte) jsonCriterion.get("icmpv6Type").shortValue();
if (icmpv6Type != jsonIcmpv6Type) {
description.appendText("icmpv6 type was " + Byte.toString(jsonIcmpv6Type));
return false;
}
break;
case ICMPV6_CODE:
final Criteria.Icmpv6CodeCriterion icmpv6CodeCriterion =
(Criteria.Icmpv6CodeCriterion) criterion;
final byte icmpv6Code = icmpv6CodeCriterion.icmpv6Code();
final byte jsonIcmpv6Code = (byte) jsonCriterion.get("icmpv6Code").shortValue();
if (icmpv6Code != jsonIcmpv6Code) {
description.appendText("icmpv6 code was " + Byte.toString(jsonIcmpv6Code));
return false;
}
break;
case IPV6_ND_TARGET:
final Criteria.IPv6NDTargetAddressCriterion
ipv6NDTargetAddressCriterion =
(Criteria.IPv6NDTargetAddressCriterion) criterion;
final String targetAddress =
ipv6NDTargetAddressCriterion.targetAddress().toString();
final String jsonTargetAddress =
jsonCriterion.get("targetAddress").textValue();
if (!targetAddress.equals(jsonTargetAddress)) {
description.appendText("target address was " +
jsonTargetAddress);
return false;
}
break;
case IPV6_ND_SLL:
case IPV6_ND_TLL:
final Criteria.IPv6NDLinkLayerAddressCriterion
ipv6NDLinkLayerAddressCriterion =
(Criteria.IPv6NDLinkLayerAddressCriterion) criterion;
final String llAddress =
ipv6NDLinkLayerAddressCriterion.mac().toString();
final String jsonLlAddress =
jsonCriterion.get("mac").textValue();
if (!llAddress.equals(jsonLlAddress)) {
description.appendText("mac was " + jsonLlAddress);
return false;
}
break;
......