@Test public void testParseIpProtocolsNegation() throws IOException { Set<IpProtocol> ipProtocols = parseIpProtocols(BatfishObjectMapper.mapper().readValue("\"!ICMP\"", JsonNode.class)); assertThat( ipProtocols, equalTo(Sets.difference(ImmutableSet.copyOf(IpProtocol.values()), ImmutableSet.of(ICMP)))); }
@VisibleForTesting static Set<IpProtocol> parseIpProtocols(JsonNode ipProtocols) { String input = ""; if (ipProtocols == null || ipProtocols.isNull()) { return null; } else if (ipProtocols.isTextual()) { input = ipProtocols.asText(); } else if (ipProtocols.isArray()) { input = Streams.stream(ipProtocols.elements()) .map(JsonNode::textValue) .collect(Collectors.joining(",")); } else { throw new IllegalArgumentException( String.format( "IP protocol specifier should be a string or a list of strings. Got: %s", ipProtocols)); } return SpecifierFactories.getIpProtocolSpecifierOrDefault( input, NoIpProtocolsIpProtocolSpecifier.INSTANCE) .resolve(); }
PacketHeaderConstraints { @VisibleForTesting static Set<IpProtocol> parseIpProtocols(JsonNode ipProtocols) { String input = ""; if (ipProtocols == null || ipProtocols.isNull()) { return null; } else if (ipProtocols.isTextual()) { input = ipProtocols.asText(); } else if (ipProtocols.isArray()) { input = Streams.stream(ipProtocols.elements()) .map(JsonNode::textValue) .collect(Collectors.joining(",")); } else { throw new IllegalArgumentException( String.format( "IP protocol specifier should be a string or a list of strings. Got: %s", ipProtocols)); } return SpecifierFactories.getIpProtocolSpecifierOrDefault( input, NoIpProtocolsIpProtocolSpecifier.INSTANCE) .resolve(); } }
PacketHeaderConstraints { @VisibleForTesting static Set<IpProtocol> parseIpProtocols(JsonNode ipProtocols) { String input = ""; if (ipProtocols == null || ipProtocols.isNull()) { return null; } else if (ipProtocols.isTextual()) { input = ipProtocols.asText(); } else if (ipProtocols.isArray()) { input = Streams.stream(ipProtocols.elements()) .map(JsonNode::textValue) .collect(Collectors.joining(",")); } else { throw new IllegalArgumentException( String.format( "IP protocol specifier should be a string or a list of strings. Got: %s", ipProtocols)); } return SpecifierFactories.getIpProtocolSpecifierOrDefault( input, NoIpProtocolsIpProtocolSpecifier.INSTANCE) .resolve(); } 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 Set<IpProtocol> parseIpProtocols(JsonNode ipProtocols) { String input = ""; if (ipProtocols == null || ipProtocols.isNull()) { return null; } else if (ipProtocols.isTextual()) { input = ipProtocols.asText(); } else if (ipProtocols.isArray()) { input = Streams.stream(ipProtocols.elements()) .map(JsonNode::textValue) .collect(Collectors.joining(",")); } else { throw new IllegalArgumentException( String.format( "IP protocol specifier should be a string or a list of strings. Got: %s", ipProtocols)); } return SpecifierFactories.getIpProtocolSpecifierOrDefault( input, NoIpProtocolsIpProtocolSpecifier.INSTANCE) .resolve(); } 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 Set<IpProtocol> parseIpProtocols(JsonNode ipProtocols) { String input = ""; if (ipProtocols == null || ipProtocols.isNull()) { return null; } else if (ipProtocols.isTextual()) { input = ipProtocols.asText(); } else if (ipProtocols.isArray()) { input = Streams.stream(ipProtocols.elements()) .map(JsonNode::textValue) .collect(Collectors.joining(",")); } else { throw new IllegalArgumentException( String.format( "IP protocol specifier should be a string or a list of strings. Got: %s", ipProtocols)); } return SpecifierFactories.getIpProtocolSpecifierOrDefault( input, NoIpProtocolsIpProtocolSpecifier.INSTANCE) .resolve(); } 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();  }