X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fnetworkconfiguration%2Fneutron%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetworkconfig%2Fneutron%2FNeutronSubnet.java;h=b0d9bf46d4e20ee851fd644b014161a1df8eefe3;hb=6a4c3c11f68c52d00d2bc7f0b30b086113ebe859;hp=ae84a72bbac84ddda56c102972c894e21873a603;hpb=e27d63bdcfbfb0c1078a9c3e5aabf59ae7e2315f;p=controller.git diff --git a/opendaylight/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet.java b/opendaylight/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet.java index ae84a72bba..b0d9bf46d4 100644 --- a/opendaylight/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet.java +++ b/opendaylight/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet.java @@ -9,6 +9,8 @@ package org.opendaylight.controller.networkconfig.neutron; import java.io.Serializable; +import java.net.InetAddress; +import java.net.Inet6Address; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -25,7 +27,7 @@ import org.opendaylight.controller.configuration.ConfigurationObject; @XmlRootElement @XmlAccessorType(XmlAccessType.NONE) -public class NeutronSubnet extends ConfigurationObject implements Serializable { +public class NeutronSubnet extends ConfigurationObject implements Serializable, INeutronObject { private static final long serialVersionUID = 1L; // See OpenStack Network API v2.0 Reference for description of @@ -75,7 +77,7 @@ public class NeutronSubnet extends ConfigurationObject implements Serializable { */ List myPorts; - boolean gatewayIPAssigned; + Boolean gatewayIPAssigned; public NeutronSubnet() { myPorts = new ArrayList(); @@ -83,6 +85,8 @@ public class NeutronSubnet extends ConfigurationObject implements Serializable { public String getID() { return subnetUUID; } + public void setID(String id) { this.subnetUUID = id; } + public String getSubnetUUID() { return subnetUUID; } @@ -253,16 +257,45 @@ public class NeutronSubnet extends ConfigurationObject implements Serializable { * a new subnet) */ public boolean isValidCIDR() { - try { - SubnetUtils util = new SubnetUtils(cidr); - SubnetInfo info = util.getInfo(); - if (!info.getNetworkAddress().equals(info.getAddress())) { + // fix for Bug 2290 - need to wrap the existing test as + // IPv4 because SubnetUtils doesn't support IPv6 + if (ipVersion == 4) { + try { + SubnetUtils util = new SubnetUtils(cidr); + SubnetInfo info = util.getInfo(); + if (!info.getNetworkAddress().equals(info.getAddress())) { + return false; + } + } catch (Exception e) { return false; } - } catch (Exception e) { - return false; + return true; } - return true; + if (ipVersion == 6) { + // fix for Bug2290 - this is custom code because no classes + // with ODL-friendly licenses have been found + // extract address (in front of /) and length (after /) + String[] parts = cidr.split("/"); + if (parts.length != 2) { + return false; + } + try { + int length = Integer.parseInt(parts[1]); + //TODO?: limit check on length + // convert to byte array + byte[] addrBytes = ((Inet6Address) InetAddress.getByName(parts[0])).getAddress(); + int i; + for (i=length; i<128; i++) { // offset is to ensure proper comparison + if (((((int) addrBytes[i/8]) & 0x000000FF) & (1 << (7-(i%8)))) != 0) { + return(false); + } + } + return(true); + } catch (Exception e) { + return(false); + } + } + return false; } /* test to see if the gateway IP specified overlaps with specified @@ -297,7 +330,7 @@ public class NeutronSubnet extends ConfigurationObject implements Serializable { try { SubnetUtils util = new SubnetUtils(cidr); SubnetInfo info = util.getInfo(); - if (gatewayIP == null) { + if (gatewayIP == null || ("").equals(gatewayIP)) { gatewayIP = info.getLowAddress(); } if (allocationPools.size() < 1) { @@ -458,6 +491,10 @@ public class NeutronSubnet extends ConfigurationObject implements Serializable { gatewayIPAssigned = false; } + public Boolean getGatewayIPAllocated() { + return gatewayIPAssigned; + } + @Override public String toString() { return "NeutronSubnet [subnetUUID=" + subnetUUID + ", networkUUID=" + networkUUID + ", name=" + name