Class Prefix

java.lang.Object
org.batfish.datamodel.Prefix
All Implemented Interfaces:
Serializable, Comparable<Prefix>

@ParametersAreNonnullByDefault public final class Prefix extends Object implements Comparable<Prefix>, Serializable
An IPv4 Prefix
See Also:
  • Field Details

    • MAX_PREFIX_LENGTH

      public static final int MAX_PREFIX_LENGTH
      Maximum prefix length (number of bits) for a IPv4 address, which is 32
      See Also:
    • ZERO

      public static final Prefix ZERO
      A "0.0.0.0/0" prefix
    • MULTICAST

      public static final Prefix MULTICAST
      Multicast IPs are in "244.0.0.0/4".
    • HOST_SUBNET_MAX_PREFIX_LENGTH

      public static final int HOST_SUBNET_MAX_PREFIX_LENGTH
      /32s are loopback interfaces -- no hosts are connected.

      /31s are point-to-point connections between nodes -- again, no hosts.

      /30s could have hosts, but usually do not. Historically, each subnet was required to reserve two addresses: one identifying the network itself, and a broadcast address. This made /31s invalid, since there were no usable IPs left over. A /30 had 2 usable IPs, so was used for point-to-point connections. Eventually /31s were allowed, but we assume here that any /30s are hold-over point-to-point connections in the legacy model.

      See Also:
  • Method Details

    • parse

      @Nonnull public static Prefix parse(@Nullable String text)
      Parse a Prefix from a string.
    • tryParse

      @Nonnull public static Optional<Prefix> tryParse(@Nonnull String text)
      Return an Optional Prefix from a string, or Optional.empty() if the string does not represent a Prefix.
    • strict

      @Nonnull public static Prefix strict(String prefixStr)
      Parse a Prefix from a string.
      Throws:
      IllegalArgumentException - if the string does not represent a prefix in canonical form.
    • create

      public static Prefix create(Ip ip, int prefixLength)
    • create

      public static Prefix create(Ip address, Ip mask)
    • longestCommonPrefix

      public static Prefix longestCommonPrefix(Prefix p1, Prefix p2)
      Return the longest prefix that contains both input prefixes.
    • compareTo

      public int compareTo(Prefix rhs)
      Specified by:
      compareTo in interface Comparable<Prefix>
    • containsIp

      public boolean containsIp(Ip ip)
    • containsPrefix

      public boolean containsPrefix(Prefix prefix)
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • getEndIp

      @Nonnull public Ip getEndIp()
    • getPrefixLength

      public int getPrefixLength()
    • getPrefixWildcard

      @Nonnull public Ip getPrefixWildcard()
    • getStartIp

      @Nonnull public Ip getStartIp()
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getFirstHostIp

      @Nonnull public Ip getFirstHostIp()
    • getLastHostIp

      public Ip getLastHostIp()
      Returns the last ip in the prefix that is not a broadcast address. When the prefix is /32 or /31, returns the getEndIp(), otherwise, returns the ip before getEndIp().
    • toString

      public String toString()
      Overrides:
      toString in class Object