Package org.onlab.packet
Class IpAddress
- java.lang.Object
- 
- org.onlab.packet.IpAddress
 
- 
- All Implemented Interfaces:
- Comparable<IpAddress>
 - Direct Known Subclasses:
- Ip4Address,- Ip6Address
 
 public class IpAddress extends Object implements Comparable<IpAddress> A class representing an IP address. This class is immutable.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classIpAddress.Version
 - 
Field SummaryFields Modifier and Type Field Description static intINET_BIT_LENGTHstatic intINET_BYTE_LENGTHstatic intINET6_BIT_LENGTHstatic intINET6_BYTE_LENGTH
 - 
Constructor SummaryConstructors Modifier Constructor Description protectedIpAddress()Default constructor for Kryo serialization.protectedIpAddress(IpAddress.Version version, byte[] value)Constructor for given IP address version and address octets.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static intbyteLength(IpAddress.Version version)Computes the IP address byte length for a given IP version.intcompareTo(IpAddress o)booleanequals(Object obj)Ip4AddressgetIp4Address()Gets theIp4Addressview of the IP address.Ip6AddressgetIp6Address()Gets theIp6Addressview of the IP address.inthashCode()booleanisIp4()Tests whether the IP version of this address is IPv4.booleanisIp6()Tests whether the IP version of this address is IPv6.booleanisLinkLocal()Check if this IP address is a link-local address.booleanisMulticast()Check if this IP address is a multicast address.booleanisSelfAssigned()Check if this IP address is self-assigned.booleanisZero()Check if this IP address is zero.static IpAddressmakeMaskedAddress(IpAddress address, int prefixLength)Creates an IP address by masking it with a network mask of given mask length.static IpAddressmakeMaskPrefix(IpAddress.Version version, int prefixLength)Creates an IP network mask prefix.InetAddresstoInetAddress()Returns the IP address as InetAddress.IpPrefixtoIpPrefix()Generates an IP prefix.byte[]toOctets()Returns the IP address as a byte array.StringtoString()static IpAddressvalueOf(int value)Converts an integer into an IPv4 address.static IpAddressvalueOf(String value)Converts an IPv4 or IPv6 string literal (e.g., "10.2.3.4" or "1111:2222::8888") into an IP address.static IpAddressvalueOf(InetAddress inetAddress)Converts an InetAddress into an IP address.static IpAddressvalueOf(IpAddress.Version version, byte[] value)Converts a byte array into an IP address.static IpAddressvalueOf(IpAddress.Version version, byte[] value, int offset)Converts a byte array and a given offset from the beginning of the array into an IP address.IpAddress.Versionversion()Returns the IP version of this address.
 
- 
- 
- 
Field Detail- 
INET_BYTE_LENGTHpublic static final int INET_BYTE_LENGTH - See Also:
- Constant Field Values
 
 - 
INET_BIT_LENGTHpublic static final int INET_BIT_LENGTH - See Also:
- Constant Field Values
 
 - 
INET6_BYTE_LENGTHpublic static final int INET6_BYTE_LENGTH - See Also:
- Constant Field Values
 
 - 
INET6_BIT_LENGTHpublic static final int INET6_BIT_LENGTH - See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
IpAddressprotected IpAddress(IpAddress.Version version, byte[] value) Constructor for given IP address version and address octets.- Parameters:
- version- the IP address version
- value- the IP address value stored in network byte order (i.e., the most significant byte first)
- Throws:
- IllegalArgumentException- if the arguments are invalid
 
 - 
IpAddressprotected IpAddress() Default constructor for Kryo serialization.
 
- 
 - 
Method Detail- 
versionpublic IpAddress.Version version() Returns the IP version of this address.- Returns:
- the version
 
 - 
isIp4public boolean isIp4() Tests whether the IP version of this address is IPv4.- Returns:
- true if the IP version of this address is IPv4, otherwise false.
 
 - 
isIp6public boolean isIp6() Tests whether the IP version of this address is IPv6.- Returns:
- true if the IP version of this address is IPv6, otherwise false.
 
 - 
getIp4Addresspublic Ip4Address getIp4Address() Gets theIp4Addressview of the IP address.- Returns:
- the Ip4Addressview of the IP address if it is IPv4, otherwise null
 
 - 
getIp6Addresspublic Ip6Address getIp6Address() Gets theIp6Addressview of the IP address.- Returns:
- the Ip6Addressview of the IP address if it is IPv6, otherwise null
 
 - 
toOctetspublic byte[] toOctets() Returns the IP address as a byte array.- Returns:
- a byte array
 
 - 
toInetAddresspublic InetAddress toInetAddress() Returns the IP address as InetAddress.- Returns:
- InetAddress
 
 - 
byteLengthpublic static int byteLength(IpAddress.Version version) Computes the IP address byte length for a given IP version.- Parameters:
- version- the IP version
- Returns:
- the IP address byte length for the IP version
- Throws:
- IllegalArgumentException- if the IP version is invalid
 
 - 
valueOfpublic static IpAddress valueOf(int value) Converts an integer into an IPv4 address.- Parameters:
- value- an integer representing an IPv4 address value
- Returns:
- an IP address
 
 - 
valueOfpublic static IpAddress valueOf(IpAddress.Version version, byte[] value) Converts a byte array into an IP address.- Parameters:
- version- the IP address version
- value- the IP address value stored in network byte order (i.e., the most significant byte first)
- Returns:
- an IP address
- Throws:
- IllegalArgumentException- if the arguments are invalid
 
 - 
valueOfpublic static IpAddress valueOf(IpAddress.Version version, byte[] value, int offset) Converts a byte array and a given offset from the beginning of the array into an IP address.The IP address is stored in network byte order (i.e., the most significant byte first). - Parameters:
- version- the IP address version
- value- the value to use
- offset- the offset in bytes from the beginning of the byte array
- Returns:
- an IP address
- Throws:
- IllegalArgumentException- if the arguments are invalid
 
 - 
valueOfpublic static IpAddress valueOf(InetAddress inetAddress) Converts an InetAddress into an IP address.- Parameters:
- inetAddress- the InetAddress value to use
- Returns:
- an IP address
- Throws:
- IllegalArgumentException- if the argument is invalid
 
 - 
valueOfpublic static IpAddress valueOf(String value) Converts an IPv4 or IPv6 string literal (e.g., "10.2.3.4" or "1111:2222::8888") into an IP address.- Parameters:
- value- an IP address value in string form
- Returns:
- an IP address
- Throws:
- IllegalArgumentException- if the argument is invalid
 
 - 
makeMaskPrefixpublic static IpAddress makeMaskPrefix(IpAddress.Version version, int prefixLength) Creates an IP network mask prefix.- Parameters:
- version- the IP address version
- prefixLength- the length of the mask prefix. Must be in the interval [0, 32] for IPv4, or [0, 128] for IPv6
- Returns:
- a new IP address that contains a mask prefix of the specified length
- Throws:
- IllegalArgumentException- if the arguments are invalid
 
 - 
makeMaskedAddresspublic static IpAddress makeMaskedAddress(IpAddress address, int prefixLength) Creates an IP address by masking it with a network mask of given mask length.- Parameters:
- address- the address to mask
- prefixLength- the length of the mask prefix. Must be in the interval [0, 32] for IPv4, or [0, 128] for IPv6
- Returns:
- a new IP address that is masked with a mask prefix of the specified length
- Throws:
- IllegalArgumentException- if the prefix length is invalid
 
 - 
isZeropublic boolean isZero() Check if this IP address is zero.- Returns:
- true if this address is zero
 
 - 
isSelfAssignedpublic boolean isSelfAssigned() Check if this IP address is self-assigned.- Returns:
- true if this address is self-assigned
 
 - 
isMulticastpublic boolean isMulticast() Check if this IP address is a multicast address.- Returns:
- true if this address is a multicast address
 
 - 
isLinkLocalpublic boolean isLinkLocal() Check if this IP address is a link-local address.- Returns:
- true if this address is a link-local address
 
 - 
compareTopublic int compareTo(IpAddress o) - Specified by:
- compareToin interface- Comparable<IpAddress>
 
 - 
toIpPrefixpublic IpPrefix toIpPrefix() Generates an IP prefix.- Returns:
- the IP prefix of the IP address
 
 
- 
 
-