Package org.batfish.datamodel
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 Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionintbooleancontainsIp(Ip ip) booleancontainsPrefix(Prefix prefix) static Prefixstatic PrefixbooleangetEndIp()Returns the last ip in the prefix that is not a broadcast address.intinthashCode()static PrefixlongestCommonPrefix(Prefix p1, Prefix p2) Return the longest prefix that contains both input prefixes.static PrefixParse aPrefixfrom a string.static PrefixParse aPrefixfrom a string.toString()Return anOptionalPrefixfrom a string, orOptional.empty()if the string does not represent aPrefix.
-
Field Details
-
MAX_PREFIX_LENGTH
public static final int MAX_PREFIX_LENGTHMaximum prefix length (number of bits) for a IPv4 address, which is 32- See Also:
-
ZERO
A "0.0.0.0/0" 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
Parse aPrefixfrom a string. -
tryParse
Return anOptionalPrefixfrom a string, orOptional.empty()if the string does not represent aPrefix. -
strict
Parse aPrefixfrom a string.- Throws:
IllegalArgumentException- if the string does not represent a prefix in canonical form.
-
create
-
create
-
longestCommonPrefix
Return the longest prefix that contains both input prefixes. -
compareTo
- Specified by:
compareToin interfaceComparable<Prefix>
-
containsIp
-
containsPrefix
-
equals
-
getEndIp
-
getPrefixLength
public int getPrefixLength() -
getPrefixWildcard
-
getStartIp
-
hashCode
public int hashCode() -
getFirstHostIp
-
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
-