/** * Allocate the given subnet from the pool. * * @param toAllocate subnet to allocate from the pool * @return resulting pool */ public IPv6AddressPool allocate(IPv6Network toAllocate) { if (!contains(toAllocate)) throw new IllegalArgumentException( "can not allocate network which is not contained in the pool to allocate from [" + toAllocate + "]"); if (!this.allocationSubnetSize.equals(toAllocate.getNetmask())) throw new IllegalArgumentException( "can not allocate network with prefix length /" + toAllocate.getNetmask().asPrefixLength() + " from a pool configured to hand out subnets with prefix length /" + allocationSubnetSize); // go find the range that contains the requested subnet final IPv6AddressRange rangeToAllocateFrom = findFreeRangeContaining(toAllocate); if (rangeToAllocateFrom != null) { // found a range in which this subnet is free, allocate it return doAllocate(toAllocate, rangeToAllocateFrom); } else { // requested subnet not free return null; } }
/** * Allocate the given subnet from the pool. * * @param toAllocate subnet to allocate from the pool * @return resulting pool */ public IPv6AddressPool allocate(IPv6Network toAllocate) { if (!contains(toAllocate)) throw new IllegalArgumentException( "can not allocate network which is not contained in the pool to allocate from [" + toAllocate + "]"); if (!this.allocationSubnetSize.equals(toAllocate.getNetmask())) throw new IllegalArgumentException( "can not allocate network with prefix length /" + toAllocate.getNetmask().asPrefixLength() + " from a pool configured to hand out subnets with prefix length /" + allocationSubnetSize); // go find the range that contains the requested subnet final IPv6AddressRange rangeToAllocateFrom = findFreeRangeContaining(toAllocate); if (rangeToAllocateFrom != null) { // found a range in which this subnet is free, allocate it return doAllocate(toAllocate, rangeToAllocateFrom); } else { // requested subnet not free return null; } }
if (!contains(toDeAllocate))
if (!contains(toDeAllocate))