Module inet.ipaddr
Package inet.ipaddr

Class PrefixBlockAllocator<E extends IPAddress>

java.lang.Object
inet.ipaddr.PrefixBlockAllocator<E>
Type Parameters:
E - the address type

public class PrefixBlockAllocator<E extends IPAddress> extends Object
Allocates blocks of the desired size from a set of seed blocks provided to it previously for allocation. Once a prefix block allocator of generic type IPAddress has been provided with either an IPv4 or IPv6 address or subnet for allocation, it can only be used with the same address version from that point onwards. In other words, it can allocate either IPv4 or IPv6 blocks, but not both.
Author:
scfoley
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Represents a block of addresses allocated for assignment to hosts.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addAvailable(E... newBlocks)
    Provides the given blocks to the allocator for allocating.
    allocateBitLength(int bitLength)
    Allocates a block with the given bit-length, the bit-length being the number of bits extending beyond the prefix length, or nil if no such block is available in the allocator.
    allocateBitLengths(int... bitLengths)
    Returns multiple blocks of the given bit-lengths, or null if there is insufficient space in the allocator.
    allocateSize(long sizeRequired)
    Returns a block of sufficient size, the size indicating the number of distinct addresses required in the block.
    allocateSizes(long... blockSizes)
    Returns multiple blocks of sufficient size for the given size required, or null if there is insufficient space in the allocator.
    E[]
    Returns a list of all the blocks available for allocating in the allocator.
    int
    Returns the count of available blocks in this allocator.
    int
    Returns the reserved count.
    Returns the total of the count of all individual addresses available in this allocator, which is the total number of individual addresses in all the blocks.
    Returns the IP version of the available blocks in the allocator, which is determined by the version of the first block made available to the allocator.
    void
    setReserved(int reservedCount)
    Sets the additional number of addresses to be included in any size allocation.
    Returns a string showing the counts of available blocks for each prefix size in the allocator.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • PrefixBlockAllocator

      public PrefixBlockAllocator()
  • Method Details

    • getBlockCount

      public int getBlockCount()
      Returns the count of available blocks in this allocator.
    • getVersion

      public IPAddress.IPVersion getVersion()
      Returns the IP version of the available blocks in the allocator, which is determined by the version of the first block made available to the allocator.
    • getTotalCount

      public BigInteger getTotalCount()
      Returns the total of the count of all individual addresses available in this allocator, which is the total number of individual addresses in all the blocks.
    • setReserved

      public void setReserved(int reservedCount)
      Sets the additional number of addresses to be included in any size allocation. Any request for a block of a given size will adjust that size by the given number. This can be useful when the size requests do not include the count of additional addresses that must be included in every block. For IPv4, it is common to reserve two addresses, the network and broadcast addresses. If the reservedCount is negative, then every request will be shrunk by that number, useful for cases where insufficient space requires that all subnets be reduced in size by an equal number.
    • getReserved

      public int getReserved()
      Returns the reserved count. Use setReserved to change the reserved count.
    • addAvailable

      public void addAvailable(E... newBlocks)
      Provides the given blocks to the allocator for allocating.
    • getAvailable

      public E[] getAvailable()
      Returns a list of all the blocks available for allocating in the allocator.
    • allocateBitLength

      public E allocateBitLength(int bitLength)
      Allocates a block with the given bit-length, the bit-length being the number of bits extending beyond the prefix length, or nil if no such block is available in the allocator. The reserved count is ignored when allocating by bit-length.
    • allocateSize

      public E allocateSize(long sizeRequired)
      Returns a block of sufficient size, the size indicating the number of distinct addresses required in the block. AllocateSize returns null if no such block is available in the allocator, or if the size required is zero or negative. The returned block will be able to accommodate sizeRequired hosts as well as the reserved count, if any.
      Parameters:
      sizeRequired -
      Returns:
    • allocateSizes

      public PrefixBlockAllocator.AllocatedBlock<E>[] allocateSizes(long... blockSizes)
      Returns multiple blocks of sufficient size for the given size required, or null if there is insufficient space in the allocator. The reserved count, if any, will be added to the required sizes.
    • allocateBitLengths

      public PrefixBlockAllocator.AllocatedBlock<E>[] allocateBitLengths(int... bitLengths)
      Returns multiple blocks of the given bit-lengths, or null if there is insufficient space in the allocator. The reserved count is ignored when allocating by bit-length.
    • toString

      public String toString()
      Returns a string showing the counts of available blocks for each prefix size in the allocator.
      Overrides:
      toString in class Object