@Test public void testResolvePorts() { final IntegerSpace sshSet = IntegerSpace.of(SubRange.singleton(22)); assertThat(resolvePorts(null, null), nullValue()); assertThat(resolvePorts(sshSet, ImmutableSet.of(SSH.toApplication())), equalTo(sshSet)); assertThat(resolvePorts(null, ImmutableSet.of(SSH.toApplication())), equalTo(sshSet)); assertThat( resolvePorts(IntegerSpace.of(new SubRange(22, 25)), null), equalTo(IntegerSpace.of(new SubRange(22, 25)))); assertThat( resolvePorts( IntegerSpace.builder() .including(new SubRange(1, 10)) .including(new SubRange(20, 30)) .including(new SubRange(40, 50)) .build(), ImmutableSet.of(SSH.toApplication(), HTTP.toApplication())), equalTo(sshSet)); assertThat(resolvePorts(null, ImmutableSet.of(IcmpTypesApplication.ALL)), equalTo(null)); }
@Nullable @VisibleForTesting static IntegerSpace resolvePorts( @Nullable IntegerSpace ports, @Nullable Set<Application> applications) { @Nullable IntegerSpace portsFromApplications = firstNonNull(applications, ImmutableSet.of()).stream() .filter(application -> application instanceof PortsApplication) .flatMap(application -> ((PortsApplication) application).getPorts().stream()) .map(IntegerSpace::of) .reduce(IntegerSpace::union) .orElse(null); return intersectNullable(ports, portsFromApplications); }
PacketHeaderConstraints { @Nullable @VisibleForTesting static IntegerSpace resolvePorts( @Nullable IntegerSpace ports, @Nullable Set<Application> applications) { @Nullable IntegerSpace portsFromApplications = firstNonNull(applications, ImmutableSet.of()).stream() .filter(application -> application instanceof PortsApplication) .flatMap(application -> ((PortsApplication) application).getPorts().stream()) .map(IntegerSpace::of) .reduce(IntegerSpace::union) .orElse(null); return intersectNullable(ports, portsFromApplications); } }
PacketHeaderConstraints { @Nullable @VisibleForTesting static IntegerSpace resolvePorts( @Nullable IntegerSpace ports, @Nullable Set<Application> applications) { @Nullable IntegerSpace portsFromApplications = firstNonNull(applications, ImmutableSet.of()).stream() .filter(application -> application instanceof PortsApplication) .flatMap(application -> ((PortsApplication) application).getPorts().stream()) .map(IntegerSpace::of) .reduce(IntegerSpace::union) .orElse(null); return intersectNullable(ports, portsFromApplications); } 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 { @Nullable @VisibleForTesting static IntegerSpace resolvePorts( @Nullable IntegerSpace ports, @Nullable Set<Application> applications) { @Nullable IntegerSpace portsFromApplications = firstNonNull(applications, ImmutableSet.of()).stream() .filter(application -> application instanceof PortsApplication) .flatMap(application -> ((PortsApplication) application).getPorts().stream()) .map(IntegerSpace::of) .reduce(IntegerSpace::union) .orElse(null); return intersectNullable(ports, portsFromApplications); } 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 { @Nullable @VisibleForTesting static IntegerSpace resolvePorts( @Nullable IntegerSpace ports, @Nullable Set<Application> applications) { @Nullable IntegerSpace portsFromApplications = firstNonNull(applications, ImmutableSet.of()).stream() .filter(application -> application instanceof PortsApplication) .flatMap(application -> ((PortsApplication) application).getPorts().stream()) .map(IntegerSpace::of) .reduce(IntegerSpace::union) .orElse(null); return intersectNullable(ports, portsFromApplications); } 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();  }