Package com.googlecode.ipv6
Class IPv6AddressPool
- java.lang.Object
-
- com.googlecode.ipv6.IPv6AddressPool
-
- All Implemented Interfaces:
java.io.Serializable
public final class IPv6AddressPool extends java.lang.Object implements java.io.SerializableImmutable 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
-
-
Field Summary
Fields Modifier and Type Field Description private IPv6NetworkMaskallocationSubnetSizeprivate java.util.SortedSet<IPv6AddressRange>freeRangesprivate IPv6NetworklastAllocatedprivate IPv6AddressRangeunderlyingRange
-
Constructor Summary
Constructors Modifier Constructor Description privateIPv6AddressPool(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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description IPv6AddressPoolallocate()Allocate the first available subnet from the pool.IPv6AddressPoolallocate(IPv6Network toAllocate)Allocate the given subnet from the pool.private booleancheckWithinBounds(IPv6AddressRange range, java.util.SortedSet<IPv6AddressRange> toValidate)booleancontains(IPv6Address address)booleancontains(IPv6AddressRange range)IPv6AddressPooldeAllocate(IPv6Network toDeAllocate)Give a network back to the pool (de-allocate).private IPv6AddressPooldoAllocate(IPv6Network toAllocate, IPv6AddressRange rangeToAllocateFrom)Private helper method to perform the allocation of a subnet within one of the free ranges.booleanequals(java.lang.Object o)private IPv6AddressRangefindFreeRangeAfter(IPv6Network network)Private helper method to find the free range just after the given address.private IPv6AddressRangefindFreeRangeBefore(IPv6Network network)Private helper method to find the free range just before the given network.private IPv6AddressRangefindFreeRangeContaining(IPv6Network toAllocate)java.lang.Iterable<IPv6Network>freeNetworks()static IPv6AddressPoolfromRangeAndSubnet(IPv6AddressRange range, IPv6NetworkMask allocationSubnetSize)Create a pool of the given range (boundaries inclusive) which is completely free.IPv6AddressgetFirst()IPv6AddressgetLast()IPv6NetworkgetLastAllocated()inthashCode()booleanisExhausted()booleanisFree(IPv6Network network)booleanoverlaps(IPv6AddressRange range)java.lang.StringtoLongString()java.lang.StringtoString()private voidvalidateFreeRanges(IPv6AddressRange range, java.util.SortedSet<IPv6AddressRange> toValidate)private voidvalidateRangeIsMultipleOfSubnetsOfGivenSize(IPv6AddressRange range, IPv6NetworkMask allocationSubnetSize)
-
-
-
Field Detail
-
underlyingRange
private final IPv6AddressRange underlyingRange
-
freeRanges
private final java.util.SortedSet<IPv6AddressRange> freeRanges
-
allocationSubnetSize
private final IPv6NetworkMask allocationSubnetSize
-
lastAllocated
private final IPv6Network lastAllocated
-
-
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 allocateallocationSubnetSize- size of the subnets that will be allocatedfreeRanges- 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 allocateallocationSubnetSize- size of the subnets that will be allocated- Returns:
- ipv6 address pool
-
validateFreeRanges
private void validateFreeRanges(IPv6AddressRange range, java.util.SortedSet<IPv6AddressRange> toValidate)
-
checkWithinBounds
private boolean checkWithinBounds(IPv6AddressRange range, java.util.SortedSet<IPv6AddressRange> toValidate)
-
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
-
findFreeRangeContaining
private IPv6AddressRange findFreeRangeContaining(IPv6Network toAllocate)
-
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 allocaterangeToAllocateFrom- 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:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
contains
public boolean contains(IPv6Address address)
-
contains
public boolean contains(IPv6AddressRange range)
-
overlaps
public boolean overlaps(IPv6AddressRange range)
-
getFirst
public IPv6Address getFirst()
-
getLast
public IPv6Address getLast()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toLongString
public java.lang.String toLongString()
- Returns:
- like
toStringbut without using shorthand notations for addresses
-
-