Merge "Fix of bug in Notificator class"
[controller.git] / opendaylight / networkconfiguration / neutron / src / main / java / org / opendaylight / controller / networkconfig / neutron / NeutronSubnet.java
index e53c3d4b1a9ddee674c231bdf400f0beed22a162..6582d8c021d5f61de10ae6b221f1217fdd1d668f 100644 (file)
@@ -8,9 +8,11 @@
 
 package org.opendaylight.controller.networkconfig.neutron;
 
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
@@ -18,11 +20,14 @@ import javax.xml.bind.annotation.XmlRootElement;
 
 import org.apache.commons.net.util.SubnetUtils;
 import org.apache.commons.net.util.SubnetUtils.SubnetInfo;
+import org.opendaylight.controller.configuration.ConfigurationObject;
 
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.NONE)
 
-public class NeutronSubnet {
+public class NeutronSubnet extends ConfigurationObject implements Serializable {
+    private static final long serialVersionUID = 1L;
+
     // See OpenStack Network API v2.0 Reference for description of
     // annotated attributes
 
@@ -264,22 +269,26 @@ public class NeutronSubnet {
         }
         gatewayIPAssigned = false;
         dnsNameservers = new ArrayList<String>();
-        allocationPools = new ArrayList<NeutronSubnet_IPAllocationPool>();
-        hostRoutes = new ArrayList<NeutronSubnet_HostRoute>();
-        try {
-            SubnetUtils util = new SubnetUtils(cidr);
-            SubnetInfo info = util.getInfo();
-            if (gatewayIP == null) {
-                gatewayIP = info.getLowAddress();
-            }
-            if (allocationPools.size() < 1) {
-                NeutronSubnet_IPAllocationPool source =
-                    new NeutronSubnet_IPAllocationPool(info.getLowAddress(),
-                            info.getHighAddress());
-                allocationPools = source.splitPool(gatewayIP);
+        if (hostRoutes == null) {
+            hostRoutes = new ArrayList<NeutronSubnet_HostRoute>();
+        }
+        if (allocationPools == null) {
+            allocationPools = new ArrayList<NeutronSubnet_IPAllocationPool>();
+            try {
+                SubnetUtils util = new SubnetUtils(cidr);
+                SubnetInfo info = util.getInfo();
+                if (gatewayIP == null) {
+                    gatewayIP = info.getLowAddress();
+                }
+                if (allocationPools.size() < 1) {
+                    NeutronSubnet_IPAllocationPool source =
+                        new NeutronSubnet_IPAllocationPool(info.getLowAddress(),
+                                info.getHighAddress());
+                    allocationPools = source.splitPool(gatewayIP);
+                }
+            } catch (Exception e) {
+                return false;
             }
-        } catch (Exception e) {
-            return false;
         }
         return true;
     }
@@ -428,4 +437,13 @@ public class NeutronSubnet {
     public void resetGatewayIPAllocated() {
         gatewayIPAssigned = false;
     }
+
+    @Override
+    public String toString() {
+        return "NeutronSubnet [subnetUUID=" + subnetUUID + ", networkUUID=" + networkUUID + ", name=" + name
+                + ", ipVersion=" + ipVersion + ", cidr=" + cidr + ", gatewayIP=" + gatewayIP + ", dnsNameservers="
+                + dnsNameservers + ", allocationPools=" + allocationPools + ", hostRoutes=" + hostRoutes
+                + ", enableDHCP=" + enableDHCP + ", tenantID=" + tenantID + ", myPorts=" + myPorts
+                + ", gatewayIPAssigned=" + gatewayIPAssigned + "]";
+    }
 }