public String getLowAddr() { String ans = null; Iterator<NeutronSubnet_IPAllocationPool> i = allocationPools.iterator(); while (i.hasNext()) { NeutronSubnet_IPAllocationPool pool = i.next(); if (ans == null) { ans = pool.getPoolStart(); } else { if (ipVersion == 4) { if (NeutronSubnet_IPAllocationPool.convert(pool.getPoolStart()) < NeutronSubnet_IPAllocationPool.convert(ans)) { ans = pool.getPoolStart(); } } if (ipVersion == 6) { if (NeutronSubnet_IPAllocationPool.convert_V6(pool.getPoolStart()).compareTo(NeutronSubnet_IPAllocationPool.convert_V6(ans)) < 0) { ans = pool.getPoolStart(); } } } } return ans; }
public List<NeutronSubnet_IPAllocationPool> splitPool(String ipAddress) { List<NeutronSubnet_IPAllocationPool> ans = new ArrayList<NeutronSubnet_IPAllocationPool>(); long gIP = NeutronSubnet_IPAllocationPool.convert(ipAddress); long sIP = NeutronSubnet_IPAllocationPool.convert(poolStart); long eIP = NeutronSubnet_IPAllocationPool.convert(poolEnd); long i; NeutronSubnet_IPAllocationPool p = new NeutronSubnet_IPAllocationPool(); boolean poolStarted = false; for (i=sIP; i<=eIP; i++) { if (i == sIP) { if (i != gIP) { p.setPoolStart(poolStart); poolStarted = true; } else { p.setPoolStart(NeutronSubnet_IPAllocationPool.longToIP(i+1)); p.setPoolEnd(poolEnd); } else { p.setPoolEnd(NeutronSubnet_IPAllocationPool.longToIP(i-1)); if (i != gIP) { if (!poolStarted) { p.setPoolStart(NeutronSubnet_IPAllocationPool.longToIP(i)); poolStarted = true; p.setPoolEnd(NeutronSubnet_IPAllocationPool.longToIP(i-1)); poolStarted = false; ans.add(p); p = new NeutronSubnet_IPAllocationPool();
public boolean gatewayIP_Pool_overlap() { Iterator<NeutronSubnet_IPAllocationPool> i = allocationPools.iterator(); while (i.hasNext()) { NeutronSubnet_IPAllocationPool pool = i.next(); if (ipVersion == 4) { if (pool.contains(gatewayIP)) { return true; } } if (ipVersion == 6) { if (pool.contains_V6(gatewayIP)) { return true; } } } return false; }
Iterator<NeutronSubnet_IPAllocationPool> i = allocationPools.iterator(); if (ipVersion == 4) { long sIP = NeutronSubnet_IPAllocationPool.convert(ipAddress); long lIP = NeutronSubnet_IPAllocationPool.convert(pool.getPoolStart()); long hIP = NeutronSubnet_IPAllocationPool.convert(pool.getPoolEnd()); if (sIP+1 == lIP) { hPool = pool; BigInteger sIP = NeutronSubnet_IPAllocationPool.convert_V6(ipAddress); BigInteger lIP = NeutronSubnet_IPAllocationPool.convert_V6(pool.getPoolStart()); BigInteger hIP = NeutronSubnet_IPAllocationPool.convert_V6(pool.getPoolEnd()); if (lIP.compareTo(sIP.add(BigInteger.ONE)) == 0) { hPool = pool; allocationPools.add(new NeutronSubnet_IPAllocationPool(ipAddress,ipAddress)); hPool.setPoolStart(ipAddress); lPool.setPoolEnd(ipAddress); allocationPools.remove(lPool); allocationPools.remove(hPool); allocationPools.add(new NeutronSubnet_IPAllocationPool( lPool.getPoolStart(), hPool.getPoolEnd()));
if (!(pool.getPoolEnd().equalsIgnoreCase(ipAddress) && pool.getPoolStart().equalsIgnoreCase(ipAddress))) { if (ipVersion == 4) { if (pool.contains(ipAddress)) { List<NeutronSubnet_IPAllocationPool> pools = pool.splitPool(ipAddress); newList.addAll(pools); } else { if (pool.contains_V6(ipAddress)) { List<NeutronSubnet_IPAllocationPool> pools = pool.splitPool_V6(ipAddress); newList.addAll(pools); } else {
public List<NeutronSubnet_IPAllocationPool> splitPool_V6(String ipAddress) { List<NeutronSubnet_IPAllocationPool> ans = new ArrayList<NeutronSubnet_IPAllocationPool>(); BigInteger gIP = NeutronSubnet_IPAllocationPool.convert_V6(ipAddress); BigInteger sIP = NeutronSubnet_IPAllocationPool.convert_V6(poolStart); BigInteger eIP = NeutronSubnet_IPAllocationPool.convert_V6(poolEnd); if (gIP.compareTo(sIP) == 0 && gIP.compareTo(eIP) < 0) { NeutronSubnet_IPAllocationPool p = new NeutronSubnet_IPAllocationPool(); p.setPoolStart(NeutronSubnet_IPAllocationPool.bigIntegerToIP(sIP.add(BigInteger.ONE))); p.setPoolEnd(poolEnd); ans.add(p); return(ans); NeutronSubnet_IPAllocationPool p = new NeutronSubnet_IPAllocationPool(); p.setPoolStart(poolStart); p.setPoolEnd(NeutronSubnet_IPAllocationPool.bigIntegerToIP(eIP.subtract(BigInteger.ONE))); ans.add(p); return(ans); NeutronSubnet_IPAllocationPool p = new NeutronSubnet_IPAllocationPool(); p.setPoolStart(poolStart); p.setPoolEnd(NeutronSubnet_IPAllocationPool.bigIntegerToIP(gIP.subtract(BigInteger.ONE))); ans.add(p); NeutronSubnet_IPAllocationPool p2 = new NeutronSubnet_IPAllocationPool(); p2.setPoolStart(NeutronSubnet_IPAllocationPool.bigIntegerToIP(gIP.add(BigInteger.ONE))); p2.setPoolEnd(poolEnd); ans.add(p2); return ans;
new NeutronSubnet_IPAllocationPool(info.getLowAddress(), info.getHighAddress()); allocationPools = source.splitPool(gatewayIP); BigInteger lowAddress_bi = NeutronSubnet_IPAllocationPool.convert_V6(parts[0]); String lowAddress = NeutronSubnet_IPAllocationPool.bigIntegerToIP(lowAddress_bi.add(BigInteger.ONE)); BigInteger mask = BigInteger.ONE.shiftLeft(length).subtract(BigInteger.ONE); String highAddress = NeutronSubnet_IPAllocationPool.bigIntegerToIP(lowAddress_bi.add(mask).subtract(BigInteger.ONE)); if (gatewayIP == null || ("").equals(gatewayIP)) { gatewayIP = lowAddress; new NeutronSubnet_IPAllocationPool(lowAddress, highAddress); allocationPools = source.splitPool_V6(gatewayIP);
static private Integer poolSize(NeutronSubnet_IPAllocationPool pool) { long bottom = convertIPv4StringToLong(pool.getPoolStart()); long top = convertIPv4StringToLong(pool.getPoolEnd()); int ans = (int) (top-bottom)+1; return new Integer(ans); }
int i1; for (i1=1; i1<=snatPoolSize; i1++) { String ipAddr = pool.getPoolStart(); if (i1 == 1) { ip_low = ipAddr;
/** * This method determines if this allocation pool contains the * input IPv4 address * * @param inputString * IPv4 address in dotted decimal format * @returns a boolean on whether the pool contains the address or not */ public boolean contains(String inputString) { long inputIP = convert(inputString); long startIP = convert(poolStart); long endIP = convert(poolEnd); return (inputIP >= startIP && inputIP <= endIP); }
/** * This method determines if this allocation pool contains the * input IPv4 address * * @param inputString * IPv4 address in dotted decimal format * @returns a boolean on whether the pool contains the address or not */ public boolean contains_V6(String inputString) { BigInteger inputIP = convert_V6(inputString); BigInteger startIP = convert_V6(poolStart); BigInteger endIP = convert_V6(poolEnd); return (inputIP.compareTo(startIP) >= 0 && inputIP.compareTo(endIP) <= 0); }
/** * This static method converts the supplied high-ending long back * into a dotted decimal representation of an IPv4 address * * @param l * high-endian representation of the IPv4 address as a long * @returns IPv4 address in dotted decimal format */ static String longToIP(long l) { int i; String[] parts = new String[4]; for (i=0; i<4; i++) { parts[3-i] = String.valueOf(l & 255); l >>= 8; } return join(parts,"."); }
public boolean isIPInUse(String ipAddress) { if (ipAddress.equals(gatewayIP) && !gatewayIPAssigned ) { return false; } Iterator<NeutronSubnet_IPAllocationPool> i = allocationPools.iterator(); while (i.hasNext()) { NeutronSubnet_IPAllocationPool pool = i.next(); if (ipVersion == 4 && pool.contains(ipAddress)) { return false; } if (ipVersion == 6 && pool.contains_V6(ipAddress)) { return false; } } return true; }