Package org.onlab.packet
Class IpPrefix
- java.lang.Object
-
- org.onlab.packet.IpPrefix
-
public class IpPrefix extends java.lang.Object
A class representing an IP prefix. A prefix consists of an IP address and a subnet mask. This class is immutable.NOTE: The stored IP address in the result IP prefix is masked to contain zeroes in all bits after the prefix length.
-
-
Field Summary
Fields Modifier and Type Field Description static IpPrefix
IPV4_LINK_LOCAL_PREFIX
An IpPrefix that contains all IPv4 link local addresses.static IpPrefix
IPV4_MULTICAST_PREFIX
An IpPrefix that contains all IPv4 multicast addresses.static IpPrefix
IPV6_LINK_LOCAL_PREFIX
An IpPrefix that contains all IPv6 link local addresses.static IpPrefix
IPV6_MULTICAST_PREFIX
An IpPrefix that contains all IPv6 multicast addresses.static int
MAX_INET_MASK_LENGTH
Longest IPv4 network prefix.static int
MAX_INET6_MASK_LENGTH
Longest IPv6 network prefix.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description IpAddress
address()
Returns the IP address value of the prefix.boolean
contains(IpAddress other)
Determines whether a given IP address is contained within this prefix.boolean
contains(IpPrefix other)
Determines whether a given IP prefix is contained within this prefix.boolean
equals(java.lang.Object obj)
Ip4Prefix
getIp4Prefix()
Gets theIp4Prefix
view of the IP prefix.Ip6Prefix
getIp6Prefix()
Gets theIp6Prefix
view of the IP prefix.int
hashCode()
boolean
isIp4()
Tests whether the IP version of this prefix is IPv4.boolean
isIp6()
Tests whether the IP version of this prefix is IPv6.boolean
isMulticast()
Check if this IP prefix is a multicast prefix.int
prefixLength()
Returns the IP address prefix length.java.lang.String
toString()
static IpPrefix
valueOf(int address, int prefixLength)
Converts an integer and a prefix length into an IPv4 prefix.static IpPrefix
valueOf(java.lang.String address)
Converts a CIDR (slash) notation string (e.g., "10.1.0.0/16" or "1111:2222::/64") into an IP prefix.static IpPrefix
valueOf(IpAddress.Version version, byte[] address, int prefixLength)
Converts a byte array and a prefix length into an IP prefix.static IpPrefix
valueOf(IpAddress address, int prefixLength)
Converts an IP address and a prefix length into an IP prefix.IpAddress.Version
version()
Returns the IP version of the prefix.
-
-
-
Field Detail
-
MAX_INET_MASK_LENGTH
public static final int MAX_INET_MASK_LENGTH
Longest IPv4 network prefix.- See Also:
- Constant Field Values
-
MAX_INET6_MASK_LENGTH
public static final int MAX_INET6_MASK_LENGTH
Longest IPv6 network prefix.- See Also:
- Constant Field Values
-
IPV4_MULTICAST_PREFIX
public static final IpPrefix IPV4_MULTICAST_PREFIX
An IpPrefix that contains all IPv4 multicast addresses.
-
IPV6_MULTICAST_PREFIX
public static final IpPrefix IPV6_MULTICAST_PREFIX
An IpPrefix that contains all IPv6 multicast addresses.
-
IPV4_LINK_LOCAL_PREFIX
public static final IpPrefix IPV4_LINK_LOCAL_PREFIX
An IpPrefix that contains all IPv4 link local addresses.
-
IPV6_LINK_LOCAL_PREFIX
public static final IpPrefix IPV6_LINK_LOCAL_PREFIX
An IpPrefix that contains all IPv6 link local addresses.
-
-
Constructor Detail
-
IpPrefix
protected IpPrefix(IpAddress address, int prefixLength)
Constructor for given IP address, and a prefix length.- Parameters:
address
- the IP addressprefixLength
- the prefix length- Throws:
java.lang.IllegalArgumentException
- if the prefix length value is invalid
-
IpPrefix
protected IpPrefix()
Default constructor for Kryo serialization.
-
-
Method Detail
-
version
public IpAddress.Version version()
Returns the IP version of the prefix.- Returns:
- the IP version of the prefix
-
isIp4
public boolean isIp4()
Tests whether the IP version of this prefix is IPv4.- Returns:
- true if the IP version of this prefix is IPv4, otherwise false.
-
isIp6
public boolean isIp6()
Tests whether the IP version of this prefix is IPv6.- Returns:
- true if the IP version of this prefix is IPv6, otherwise false.
-
isMulticast
public boolean isMulticast()
Check if this IP prefix is a multicast prefix.- Returns:
- true if this prefix a multicast prefix
-
address
public IpAddress address()
Returns the IP address value of the prefix.- Returns:
- the IP address value of the prefix
-
prefixLength
public int prefixLength()
Returns the IP address prefix length.- Returns:
- the IP address prefix length
-
getIp4Prefix
public Ip4Prefix getIp4Prefix()
Gets theIp4Prefix
view of the IP prefix.- Returns:
- the
Ip4Prefix
view of the IP prefix if it is IPv4, otherwise null
-
getIp6Prefix
public Ip6Prefix getIp6Prefix()
Gets theIp6Prefix
view of the IP prefix.- Returns:
- the
Ip6Prefix
view of the IP prefix if it is IPv6, otherwise null
-
valueOf
public static IpPrefix valueOf(int address, int prefixLength)
Converts an integer and a prefix length into an IPv4 prefix.- Parameters:
address
- an integer representing the IPv4 addressprefixLength
- the prefix length- Returns:
- an IP prefix
- Throws:
java.lang.IllegalArgumentException
- if the prefix length value is invalid
-
valueOf
public static IpPrefix valueOf(IpAddress.Version version, byte[] address, int prefixLength)
Converts a byte array and a prefix length into an IP prefix.- Parameters:
version
- the IP address versionaddress
- the IP address value stored in network byte orderprefixLength
- the prefix length- Returns:
- an IP prefix
- Throws:
java.lang.IllegalArgumentException
- if the prefix length value is invalid
-
valueOf
public static IpPrefix valueOf(IpAddress address, int prefixLength)
Converts an IP address and a prefix length into an IP prefix.- Parameters:
address
- the IP addressprefixLength
- the prefix length- Returns:
- an IP prefix
- Throws:
java.lang.IllegalArgumentException
- if the prefix length value is invalid
-
valueOf
public static IpPrefix valueOf(java.lang.String address)
Converts a CIDR (slash) notation string (e.g., "10.1.0.0/16" or "1111:2222::/64") into an IP prefix.- Parameters:
address
- an IP prefix in string form (e.g. "10.1.0.0/16" or "1111:2222::/64")- Returns:
- an IP prefix
- Throws:
java.lang.IllegalArgumentException
- if the arguments are invalid
-
contains
public boolean contains(IpPrefix other)
Determines whether a given IP prefix is contained within this prefix.- Parameters:
other
- the IP prefix to test- Returns:
- true if the other IP prefix is contained in this prefix, otherwise false
-
contains
public boolean contains(IpAddress other)
Determines whether a given IP address is contained within this prefix.- Parameters:
other
- the IP address to test- Returns:
- true if the IP address is contained in this prefix, otherwise false
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-