/** * 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). * * @param range range from within to allocate * @param allocationSubnetSize size of the subnets that will be allocated * @return ipv6 address pool */ public static IPv6AddressPool fromRangeAndSubnet(final IPv6AddressRange range, final IPv6NetworkMask allocationSubnetSize) { // in the beginning, all is free return new IPv6AddressPool(range, allocationSubnetSize, new TreeSet<IPv6AddressRange>(Arrays.asList(range)), null); }
/** * 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). * * @param range range from within to allocate * @param allocationSubnetSize size of the subnets that will be allocated * @return ipv6 address pool */ public static IPv6AddressPool fromRangeAndSubnet(final IPv6AddressRange range, final IPv6NetworkMask allocationSubnetSize) { // in the beginning, all is free return new IPv6AddressPool(range, allocationSubnetSize, new TreeSet<IPv6AddressRange>(Arrays.asList(range)), null); }
/** * Private helper method to perform the allocation of a subnet within one of the free ranges. * * @param toAllocate subnet to allocate * @param rangeToAllocateFrom free range to allocate from * @return resulting pool */ private IPv6AddressPool doAllocate(final IPv6Network toAllocate, final IPv6AddressRange rangeToAllocateFrom) { assert freeRanges.contains(rangeToAllocateFrom); assert rangeToAllocateFrom.contains(toAllocate); final TreeSet<IPv6AddressRange> newFreeRanges = new TreeSet<IPv6AddressRange>(this.freeRanges); // remove range from free ranges newFreeRanges.remove(rangeToAllocateFrom); // from the range, remove the allocated subnet final List<IPv6AddressRange> newRanges = rangeToAllocateFrom.remove(toAllocate); // and add the resulting ranges as new free ranges newFreeRanges.addAll(newRanges); return new IPv6AddressPool(underlyingRange, allocationSubnetSize, newFreeRanges, toAllocate); }
/** * Private helper method to perform the allocation of a subnet within one of the free ranges. * * @param toAllocate subnet to allocate * @param rangeToAllocateFrom free range to allocate from * @return resulting pool */ private IPv6AddressPool doAllocate(final IPv6Network toAllocate, final IPv6AddressRange rangeToAllocateFrom) { assert freeRanges.contains(rangeToAllocateFrom); assert rangeToAllocateFrom.contains(toAllocate); final TreeSet<IPv6AddressRange> newFreeRanges = new TreeSet<IPv6AddressRange>(this.freeRanges); // remove range from free ranges newFreeRanges.remove(rangeToAllocateFrom); // from the range, remove the allocated subnet final List<IPv6AddressRange> newRanges = rangeToAllocateFrom.remove(toAllocate); // and add the resulting ranges as new free ranges newFreeRanges.addAll(newRanges); return new IPv6AddressPool(underlyingRange, allocationSubnetSize, newFreeRanges, toAllocate); }
return new IPv6AddressPool(underlyingRange, allocationSubnetSize, newFreeRanges, getLastAllocated());
return new IPv6AddressPool(underlyingRange, allocationSubnetSize, newFreeRanges, getLastAllocated());