@Test public void testAreProtocolsAndPortsIncompatibleNoTCP() { thrown.expect(IllegalArgumentException.class); areProtocolsAndPortsCompatible( ImmutableSet.of(UDP), IntegerSpace.of(new SubRange(22)), ImmutableSet.of(SSH.toApplication())); }
@VisibleForTesting static boolean areProtocolsAndPortsCompatible( @Nullable Set<IpProtocol> ipProtocols, @Nullable IntegerSpace ports, @Nullable Set<Application> applications) throws IllegalArgumentException { if (ports != null && ipProtocols != null) { checkArgument( Sets.difference(ipProtocols, IpProtocol.IP_PROTOCOLS_WITH_PORTS).isEmpty(), "Cannot combine given ports (%s) and IP protocols (%s)", ports, ipProtocols); } if (ipProtocols != null && applications != null) { Set<IpProtocol> resolvedIpProtocols = applications.stream() .map(Application::getIpProtocol) .collect(ImmutableSet.toImmutableSet()); checkArgument( !Sets.intersection(ipProtocols, resolvedIpProtocols).isEmpty(), "Combination of given IP protocols (%s) and application protocols (%s) cannot be satisfied", ipProtocols, applications); } if (ports != null && applications != null) { IntegerSpace resolvedPorts = applications.stream() .filter(application -> application instanceof PortsApplication) .flatMap(application -> ((PortsApplication) application).getPorts().stream()) .map(IntegerSpace::of) .reduce(IntegerSpace::union) .orElse(IntegerSpace.EMPTY); checkArgument( !ports.intersection(resolvedPorts).isEmpty(), "Given ports (%s) and applications (%s) do not overlap", ports, applications); } return true; }
PacketHeaderConstraints { @VisibleForTesting static boolean areProtocolsAndPortsCompatible( @Nullable Set<IpProtocol> ipProtocols, @Nullable IntegerSpace ports, @Nullable Set<Application> applications) throws IllegalArgumentException { if (ports != null && ipProtocols != null) { checkArgument( Sets.difference(ipProtocols, IpProtocol.IP_PROTOCOLS_WITH_PORTS).isEmpty(), "Cannot combine given ports (%s) and IP protocols (%s)", ports, ipProtocols); } if (ipProtocols != null && applications != null) { Set<IpProtocol> resolvedIpProtocols = applications.stream() .map(Application::getIpProtocol) .collect(ImmutableSet.toImmutableSet()); checkArgument( !Sets.intersection(ipProtocols, resolvedIpProtocols).isEmpty(), "Combination of given IP protocols (%s) and application protocols (%s) cannot be satisfied", ipProtocols, applications); } if (ports != null && applications != null) { IntegerSpace resolvedPorts = applications.stream() .filter(application -> application instanceof PortsApplication) .flatMap(application -> ((PortsApplication) application).getPorts().stream()) .map(IntegerSpace::of) .reduce(IntegerSpace::union) .orElse(IntegerSpace.EMPTY); checkArgument( !ports.intersection(resolvedPorts).isEmpty(), "Given ports (%s) and applications (%s) do not overlap", ports, applications); } return true; } }
PacketHeaderConstraints { @VisibleForTesting static boolean areProtocolsAndPortsCompatible( @Nullable Set<IpProtocol> ipProtocols, @Nullable IntegerSpace ports, @Nullable Set<Application> applications) throws IllegalArgumentException { if (ports != null && ipProtocols != null) { checkArgument( Sets.difference(ipProtocols, IpProtocol.IP_PROTOCOLS_WITH_PORTS).isEmpty(), "Cannot combine given ports (%s) and IP protocols (%s)", ports, ipProtocols); } if (ipProtocols != null && applications != null) { Set<IpProtocol> resolvedIpProtocols = applications.stream() .map(Application::getIpProtocol) .collect(ImmutableSet.toImmutableSet()); checkArgument( !Sets.intersection(ipProtocols, resolvedIpProtocols).isEmpty(), "Combination of given IP protocols (%s) and application protocols (%s) cannot be satisfied", ipProtocols, applications); } if (ports != null && applications != null) { IntegerSpace resolvedPorts = applications.stream() .filter(application -> application instanceof PortsApplication) .flatMap(application -> ((PortsApplication) application).getPorts().stream()) .map(IntegerSpace::of) .reduce(IntegerSpace::union) .orElse(IntegerSpace.EMPTY); checkArgument( !ports.intersection(resolvedPorts).isEmpty(), "Given ports (%s) and applications (%s) do not overlap", ports, applications); } return true; } private  PacketHeaderConstraints(
      @Nullable IntegerSpace dscps,
      @Nullable IntegerSpace ecns,
      @Nullable IntegerSpace packetLengths,
      @Nullable IntegerSpace fragmentOffsets,
      @Nullable Set<IpProtocol> ipProtocols,
      @Nullable String srcIp,
      @Nullable String dstIp,
      @Nullable IntegerSpace icmpCode,
      @Nullable IntegerSpace icmpType,
      @Nullable IntegerSpace srcPorts,
      @Nullable IntegerSpace dstPorts,
      @Nullable String applications,
      @Nullable Set<TcpFlagsMatchConditions> tcpFlags); }
PacketHeaderConstraints { @VisibleForTesting static boolean areProtocolsAndPortsCompatible( @Nullable Set<IpProtocol> ipProtocols, @Nullable IntegerSpace ports, @Nullable Set<Application> applications) throws IllegalArgumentException { if (ports != null && ipProtocols != null) { checkArgument( Sets.difference(ipProtocols, IpProtocol.IP_PROTOCOLS_WITH_PORTS).isEmpty(), "Cannot combine given ports (%s) and IP protocols (%s)", ports, ipProtocols); } if (ipProtocols != null && applications != null) { Set<IpProtocol> resolvedIpProtocols = applications.stream() .map(Application::getIpProtocol) .collect(ImmutableSet.toImmutableSet()); checkArgument( !Sets.intersection(ipProtocols, resolvedIpProtocols).isEmpty(), "Combination of given IP protocols (%s) and application protocols (%s) cannot be satisfied", ipProtocols, applications); } if (ports != null && applications != null) { IntegerSpace resolvedPorts = applications.stream() .filter(application -> application instanceof PortsApplication) .flatMap(application -> ((PortsApplication) application).getPorts().stream()) .map(IntegerSpace::of) .reduce(IntegerSpace::union) .orElse(IntegerSpace.EMPTY); checkArgument( !ports.intersection(resolvedPorts).isEmpty(), "Given ports (%s) and applications (%s) do not overlap", ports, applications); } return true; } private  PacketHeaderConstraints(
      @Nullable IntegerSpace dscps,
      @Nullable IntegerSpace ecns,
      @Nullable IntegerSpace packetLengths,
      @Nullable IntegerSpace fragmentOffsets,
      @Nullable Set<IpProtocol> ipProtocols,
      @Nullable String srcIp,
      @Nullable String dstIp,
      @Nullable IntegerSpace icmpCode,
      @Nullable IntegerSpace icmpType,
      @Nullable IntegerSpace srcPorts,
      @Nullable IntegerSpace dstPorts,
      @Nullable String applications,
      @Nullable Set<TcpFlagsMatchConditions> tcpFlags); static PacketHeaderConstraints unconstrained(); @Nullable @JsonProperty(PROP_DSCPS) IntegerSpace getDscps(); @Nullable @JsonProperty(PROP_ECNS) IntegerSpace getEcns(); @Nullable @JsonProperty(PROP_PACKET_LENGTHS) IntegerSpace getPacketLengths(); @Nullable @JsonProperty(PROP_FRAGMENT_OFFSETS) IntegerSpace getFragmentOffsets(); @Nullable Set<IpProtocol> getIpProtocols(); @Nullable @JsonProperty(PROP_SRC_IPS) String getSrcIps(); @Nullable @JsonProperty(PROP_DST_IPS) String getDstIps(); @Nullable @JsonProperty(PROP_ICMP_CODES) IntegerSpace getIcmpCodes(); @Nullable @JsonProperty(PROP_ICMP_TYPES) IntegerSpace getIcmpTypes(); @Nullable @JsonProperty(PROP_SRC_PORTS) IntegerSpace getSrcPorts(); @Nullable @JsonProperty(PROP_DST_PORTS) IntegerSpace getDstPorts(); @JsonProperty(PROP_APPLICATIONS) @Nullable String getApplicationsString(); Set<Application> getApplications(); @Nullable @JsonProperty(PROP_TCP_FLAGS) Set<TcpFlagsMatchConditions> getTcpFlags(); @Nullable Set<IpProtocol> resolveIpProtocols(); @Nullable IntegerSpace resolveDstPorts(); @Override boolean equals(Object o); @Override int hashCode(); static Builder builder(); }
PacketHeaderConstraints { @VisibleForTesting static boolean areProtocolsAndPortsCompatible( @Nullable Set<IpProtocol> ipProtocols, @Nullable IntegerSpace ports, @Nullable Set<Application> applications) throws IllegalArgumentException { if (ports != null && ipProtocols != null) { checkArgument( Sets.difference(ipProtocols, IpProtocol.IP_PROTOCOLS_WITH_PORTS).isEmpty(), "Cannot combine given ports (%s) and IP protocols (%s)", ports, ipProtocols); } if (ipProtocols != null && applications != null) { Set<IpProtocol> resolvedIpProtocols = applications.stream() .map(Application::getIpProtocol) .collect(ImmutableSet.toImmutableSet()); checkArgument( !Sets.intersection(ipProtocols, resolvedIpProtocols).isEmpty(), "Combination of given IP protocols (%s) and application protocols (%s) cannot be satisfied", ipProtocols, applications); } if (ports != null && applications != null) { IntegerSpace resolvedPorts = applications.stream() .filter(application -> application instanceof PortsApplication) .flatMap(application -> ((PortsApplication) application).getPorts().stream()) .map(IntegerSpace::of) .reduce(IntegerSpace::union) .orElse(IntegerSpace.EMPTY); checkArgument( !ports.intersection(resolvedPorts).isEmpty(), "Given ports (%s) and applications (%s) do not overlap", ports, applications); } return true; } private  PacketHeaderConstraints(
      @Nullable IntegerSpace dscps,
      @Nullable IntegerSpace ecns,
      @Nullable IntegerSpace packetLengths,
      @Nullable IntegerSpace fragmentOffsets,
      @Nullable Set<IpProtocol> ipProtocols,
      @Nullable String srcIp,
      @Nullable String dstIp,
      @Nullable IntegerSpace icmpCode,
      @Nullable IntegerSpace icmpType,
      @Nullable IntegerSpace srcPorts,
      @Nullable IntegerSpace dstPorts,
      @Nullable String applications,
      @Nullable Set<TcpFlagsMatchConditions> tcpFlags); static PacketHeaderConstraints unconstrained(); @Nullable @JsonProperty(PROP_DSCPS) IntegerSpace getDscps(); @Nullable @JsonProperty(PROP_ECNS) IntegerSpace getEcns(); @Nullable @JsonProperty(PROP_PACKET_LENGTHS) IntegerSpace getPacketLengths(); @Nullable @JsonProperty(PROP_FRAGMENT_OFFSETS) IntegerSpace getFragmentOffsets(); @Nullable Set<IpProtocol> getIpProtocols(); @Nullable @JsonProperty(PROP_SRC_IPS) String getSrcIps(); @Nullable @JsonProperty(PROP_DST_IPS) String getDstIps(); @Nullable @JsonProperty(PROP_ICMP_CODES) IntegerSpace getIcmpCodes(); @Nullable @JsonProperty(PROP_ICMP_TYPES) IntegerSpace getIcmpTypes(); @Nullable @JsonProperty(PROP_SRC_PORTS) IntegerSpace getSrcPorts(); @Nullable @JsonProperty(PROP_DST_PORTS) IntegerSpace getDstPorts(); @JsonProperty(PROP_APPLICATIONS) @Nullable String getApplicationsString(); Set<Application> getApplications(); @Nullable @JsonProperty(PROP_TCP_FLAGS) Set<TcpFlagsMatchConditions> getTcpFlags(); @Nullable Set<IpProtocol> resolveIpProtocols(); @Nullable IntegerSpace resolveDstPorts(); @Override boolean equals(Object o); @Override int hashCode(); static Builder builder();  }