Class IPv6AddressPool

  • All Implemented Interfaces:
    java.io.Serializable

    public final class IPv6AddressPool
    extends java.lang.Object
    implements java.io.Serializable
    Immutable representation of an IPv6 address pool.

    An IPv6 address pool is like an IPv6 address range in which some addresses are "free" and some are "allocated". Think "dhcp server". Addresses are allocated in whole subnet blocks at once. These subnet blocks have a predefined prefix length for the whole allocatable range.

    See Also:
    Serialized Form
    • Constructor Detail

      • IPv6AddressPool

        private IPv6AddressPool​(IPv6AddressRange range,
                                IPv6NetworkMask allocationSubnetSize,
                                java.util.SortedSet<IPv6AddressRange> freeRanges,
                                IPv6Network lastAllocated)
        Private constructor to construct a pool with a given set of free ranges and a network which was just allocated.
        Parameters:
        range - range from within to allocate
        allocationSubnetSize - size of the subnets that will be allocated
        freeRanges - free ranges in the allocatable IP address range
    • Method Detail

      • fromRangeAndSubnet

        public static IPv6AddressPool fromRangeAndSubnet​(IPv6AddressRange range,
                                                         IPv6NetworkMask allocationSubnetSize)
        Create a pool of the given range (boundaries inclusive) which is completely free. The given subnet size is the network mask (thus size) of the allocated subnets in this range. This constructor verifies that the whole range is "aligned" with subnets of this size (i.e. there should not be a waste of space in the beginning or end which is smaller than one subnet of the given subnet size).
        Parameters:
        range - range from within to allocate
        allocationSubnetSize - size of the subnets that will be allocated
        Returns:
        ipv6 address pool
      • validateRangeIsMultipleOfSubnetsOfGivenSize

        private void validateRangeIsMultipleOfSubnetsOfGivenSize​(IPv6AddressRange range,
                                                                 IPv6NetworkMask allocationSubnetSize)
      • getLastAllocated

        public IPv6Network getLastAllocated()
        Returns:
        the last IPv6Network which was allocated or null if none was allocated yet
      • allocate

        public IPv6AddressPool allocate()
        Allocate the first available subnet from the pool.
        Returns:
        resulting pool
      • allocate

        public IPv6AddressPool allocate​(IPv6Network toAllocate)
        Allocate the given subnet from the pool.
        Parameters:
        toAllocate - subnet to allocate from the pool
        Returns:
        resulting pool
      • doAllocate

        private IPv6AddressPool doAllocate​(IPv6Network toAllocate,
                                           IPv6AddressRange rangeToAllocateFrom)
        Private helper method to perform the allocation of a subnet within one of the free ranges.
        Parameters:
        toAllocate - subnet to allocate
        rangeToAllocateFrom - free range to allocate from
        Returns:
        resulting pool
      • deAllocate

        public IPv6AddressPool deAllocate​(IPv6Network toDeAllocate)
        Give a network back to the pool (de-allocate).
        Parameters:
        toDeAllocate - network to de-allocate
      • findFreeRangeBefore

        private IPv6AddressRange findFreeRangeBefore​(IPv6Network network)
        Private helper method to find the free range just before the given network.
      • findFreeRangeAfter

        private IPv6AddressRange findFreeRangeAfter​(IPv6Network network)
        Private helper method to find the free range just after the given address.
      • isExhausted

        public boolean isExhausted()
        Returns:
        true if no subnets are free in this pool, false otherwize
      • isFree

        public boolean isFree​(IPv6Network network)
      • freeNetworks

        public java.lang.Iterable<IPv6Network> freeNetworks()
        Returns:
        all networks (all with the same fixed prefix length) which are free in this pool
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • contains

        public boolean contains​(IPv6Address address)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toLongString

        public java.lang.String toLongString()
        Returns:
        like toString but without using shorthand notations for addresses