Convert neutron implementation classes to unix line delimiters
[controller.git] / opendaylight / networkconfiguration / neutron / implementation / src / main / java / org / opendaylight / controller / networkconfig / neutron / implementation / NeutronPortInterface.java
index 8f1e70f052832ebb68ef38045d1b80638b2fca66..fd030e178bd021cb8ec4ccfcb14c1877d89b172a 100644 (file)
-/*\r
- * Copyright IBM Corporation, 2013.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-\r
-package org.opendaylight.controller.networkconfig.neutron.implementation;\r
-\r
-import java.lang.reflect.Method;\r
-import java.util.ArrayList;\r
-import java.util.Dictionary;\r
-import java.util.EnumSet;\r
-import java.util.HashSet;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Set;\r
-import java.util.Map.Entry;\r
-import java.util.concurrent.ConcurrentMap;\r
-\r
-import org.apache.felix.dm.Component;\r
-import org.opendaylight.controller.clustering.services.CacheConfigException;\r
-import org.opendaylight.controller.clustering.services.CacheExistException;\r
-import org.opendaylight.controller.clustering.services.IClusterContainerServices;\r
-import org.opendaylight.controller.clustering.services.IClusterServices;\r
-import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;\r
-import org.opendaylight.controller.networkconfig.neutron.INeutronPortCRUD;\r
-import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetCRUD;\r
-import org.opendaylight.controller.networkconfig.neutron.NeutronCRUDInterfaces;\r
-import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;\r
-import org.opendaylight.controller.networkconfig.neutron.NeutronPort;\r
-import org.opendaylight.controller.networkconfig.neutron.NeutronSubnet;\r
-import org.opendaylight.controller.networkconfig.neutron.Neutron_IPs;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-public class NeutronPortInterface implements INeutronPortCRUD {\r
-    private static final Logger logger = LoggerFactory.getLogger(NeutronPortInterface.class);\r
-    private String containerName = null;\r
-\r
-    private IClusterContainerServices clusterContainerService = null;\r
-    private ConcurrentMap<String, NeutronPort> portDB;\r
-\r
-    // methods needed for creating caches\r
-\r
-    void setClusterContainerService(IClusterContainerServices s) {\r
-        logger.debug("Cluster Service set");\r
-        clusterContainerService = s;\r
-    }\r
-\r
-    void unsetClusterContainerService(IClusterContainerServices s) {\r
-        if (clusterContainerService == s) {\r
-            logger.debug("Cluster Service removed!");\r
-            clusterContainerService = null;\r
-        }\r
-    }\r
-\r
-    @SuppressWarnings("deprecation")\r
-    private void allocateCache() {\r
-        if (clusterContainerService == null) {\r
-            logger.error("un-initialized clusterContainerService, can't create cache");\r
-            return;\r
-        }\r
-        logger.debug("Creating Cache for OpenDOVE");\r
-        try {\r
-            // neutron caches\r
-            clusterContainerService.createCache("neutronPorts",\r
-                    EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));\r
-        } catch (CacheConfigException cce) {\r
-            logger.error("Cache couldn't be created for OpenDOVE -  check cache mode");\r
-        } catch (CacheExistException cce) {\r
-            logger.error("Cache for OpenDOVE already exists, destroy and recreate");\r
-        }\r
-        logger.debug("Cache successfully created for OpenDOVE");\r
-    }\r
-\r
-    @SuppressWarnings({ "unchecked", "deprecation" })\r
-    private void retrieveCache() {\r
-        if (clusterContainerService == null) {\r
-            logger.error("un-initialized clusterContainerService, can't retrieve cache");\r
-            return;\r
-        }\r
-\r
-        logger.debug("Retrieving cache for Neutron Ports");\r
-        portDB = (ConcurrentMap<String, NeutronPort>) clusterContainerService\r
-        .getCache("neutronPorts");\r
-        if (portDB == null) {\r
-            logger.error("Cache couldn't be retrieved for Neutron Ports");\r
-        }\r
-        logger.debug("Cache was successfully retrieved for Neutron Ports");\r
-    }\r
-\r
-    @SuppressWarnings("deprecation")\r
-    private void destroyCache() {\r
-        if (clusterContainerService == null) {\r
-            logger.error("un-initialized clusterMger, can't destroy cache");\r
-            return;\r
-        }\r
-        logger.debug("Destroying Cache for HostTracker");\r
-        clusterContainerService.destroyCache("neutronPorts");\r
-    }\r
-\r
-    private void startUp() {\r
-        allocateCache();\r
-        retrieveCache();\r
-    }\r
-\r
-    /**\r
-     * Function called by the dependency manager when all the required\r
-     * dependencies are satisfied\r
-     *\r
-     */\r
-    void init(Component c) {\r
-        Dictionary<?, ?> props = c.getServiceProperties();\r
-        if (props != null) {\r
-            containerName = (String) props.get("containerName");\r
-            logger.debug("Running containerName: {}", containerName);\r
-        } else {\r
-            // In the Global instance case the containerName is empty\r
-            containerName = "";\r
-        }\r
-        startUp();\r
-    }\r
-\r
-    /**\r
-     * Function called by the dependency manager when at least one dependency\r
-     * become unsatisfied or when the component is shutting down because for\r
-     * example bundle is being stopped.\r
-     *\r
-     */\r
-    void destroy() {\r
-        destroyCache();\r
-    }\r
-\r
-    /**\r
-     * Function called by dependency manager after "init ()" is called and after\r
-     * the services provided by the class are registered in the service registry\r
-     *\r
-     */\r
-    void start() {\r
-    }\r
-\r
-    /**\r
-     * Function called by the dependency manager before the services exported by\r
-     * the component are unregistered, this will be followed by a "destroy ()"\r
-     * calls\r
-     *\r
-     */\r
-    void stop() {\r
-    }\r
-\r
-    // this method uses reflection to update an object from it's delta.\r
-\r
-    private boolean overwrite(Object target, Object delta) {\r
-        Method[] methods = target.getClass().getMethods();\r
-\r
-        for(Method toMethod: methods){\r
-            if(toMethod.getDeclaringClass().equals(target.getClass())\r
-                    && toMethod.getName().startsWith("set")){\r
-\r
-                String toName = toMethod.getName();\r
-                String fromName = toName.replace("set", "get");\r
-\r
-                try {\r
-                    Method fromMethod = delta.getClass().getMethod(fromName);\r
-                    Object value = fromMethod.invoke(delta, (Object[])null);\r
-                    if(value != null){\r
-                        toMethod.invoke(target, value);\r
-                    }\r
-                } catch (Exception e) {\r
-                    e.printStackTrace();\r
-                    return false;\r
-                }\r
-            }\r
-        }\r
-        return true;\r
-    }\r
-\r
-    // IfNBPortCRUD methods\r
-\r
-    @Override\r
-    public boolean portExists(String uuid) {\r
-        return portDB.containsKey(uuid);\r
-    }\r
-\r
-    @Override\r
-    public NeutronPort getPort(String uuid) {\r
-        if (!portExists(uuid)) {\r
-            return null;\r
-        }\r
-        return portDB.get(uuid);\r
-    }\r
-\r
-    @Override\r
-    public List<NeutronPort> getAllPorts() {\r
-        Set<NeutronPort> allPorts = new HashSet<NeutronPort>();\r
-        for (Entry<String, NeutronPort> entry : portDB.entrySet()) {\r
-            NeutronPort port = entry.getValue();\r
-            allPorts.add(port);\r
-        }\r
-        logger.debug("Exiting getAllPorts, Found {} OpenStackPorts", allPorts.size());\r
-        List<NeutronPort> ans = new ArrayList<NeutronPort>();\r
-        ans.addAll(allPorts);\r
-        return ans;\r
-    }\r
-\r
-    @Override\r
-    public boolean addPort(NeutronPort input) {\r
-        if (portExists(input.getID())) {\r
-            return false;\r
-        }\r
-        portDB.putIfAbsent(input.getID(), input);\r
-        // if there are no fixed IPs, allocate one for each subnet in the network\r
-        INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);\r
-        if (input.getFixedIPs().size() == 0) {\r
-            List<Neutron_IPs> list = input.getFixedIPs();\r
-            Iterator<NeutronSubnet> subnetIterator = systemCRUD.getAllSubnets().iterator();\r
-            while (subnetIterator.hasNext()) {\r
-                NeutronSubnet subnet = subnetIterator.next();\r
-                if (subnet.getNetworkUUID().equals(input.getNetworkUUID())) {\r
-                    list.add(new Neutron_IPs(subnet.getID()));\r
-                }\r
-            }\r
-        }\r
-        Iterator<Neutron_IPs> fixedIPIterator = input.getFixedIPs().iterator();\r
-        while (fixedIPIterator.hasNext()) {\r
-            Neutron_IPs ip = fixedIPIterator.next();\r
-            NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());\r
-            if (ip.getIpAddress() == null) {\r
-                ip.setIpAddress(subnet.getLowAddr());\r
-            }\r
-            if (!ip.getIpAddress().equals(subnet.getGatewayIP())) {\r
-                subnet.allocateIP(ip.getIpAddress());\r
-            }\r
-            else {\r
-                subnet.setGatewayIPAllocated();\r
-            }\r
-            subnet.addPort(input);\r
-        }\r
-        INeutronNetworkCRUD networkIf = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);\r
-\r
-        NeutronNetwork network = networkIf.getNetwork(input.getNetworkUUID());\r
-        network.addPort(input);\r
-        return true;\r
-    }\r
-\r
-    @Override\r
-    public boolean removePort(String uuid) {\r
-        if (!portExists(uuid)) {\r
-            return false;\r
-        }\r
-        NeutronPort port = getPort(uuid);\r
-        portDB.remove(uuid);\r
-        INeutronNetworkCRUD networkCRUD = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);\r
-        INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);\r
-\r
-        NeutronNetwork network = networkCRUD.getNetwork(port.getNetworkUUID());\r
-        network.removePort(port);\r
-        Iterator<Neutron_IPs> fixedIPIterator = port.getFixedIPs().iterator();\r
-        while (fixedIPIterator.hasNext()) {\r
-            Neutron_IPs ip = fixedIPIterator.next();\r
-            NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());\r
-            if (!ip.getIpAddress().equals(subnet.getGatewayIP())) {\r
-                subnet.releaseIP(ip.getIpAddress());\r
-            }\r
-            else {\r
-                subnet.resetGatewayIPAllocated();\r
-            }\r
-            subnet.removePort(port);\r
-        }\r
-        return true;\r
-    }\r
-\r
-    @Override\r
-    public boolean updatePort(String uuid, NeutronPort delta) {\r
-        if (!portExists(uuid)) {\r
-            return false;\r
-        }\r
-        NeutronPort target = portDB.get(uuid);\r
-        // remove old Fixed_IPs\r
-        if (delta.getFixedIPs() != null) {\r
-            NeutronPort port = getPort(uuid);\r
-            INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);\r
-            for (Neutron_IPs ip: port.getFixedIPs()) {\r
-                NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());\r
-                subnet.releaseIP(ip.getIpAddress());\r
-            }\r
-\r
-            // allocate new Fixed_IPs\r
-            for (Neutron_IPs ip: delta.getFixedIPs()) {\r
-                NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());\r
-                if (ip.getIpAddress() == null) {\r
-                    ip.setIpAddress(subnet.getLowAddr());\r
-                }\r
-                subnet.allocateIP(ip.getIpAddress());\r
-            }\r
-        }\r
-        return overwrite(target, delta);\r
-    }\r
-\r
-    @Override\r
-    public boolean macInUse(String macAddress) {\r
-        List<NeutronPort> ports = getAllPorts();\r
-        Iterator<NeutronPort> portIterator = ports.iterator();\r
-        while (portIterator.hasNext()) {\r
-            NeutronPort port = portIterator.next();\r
-            if (macAddress.equalsIgnoreCase(port.getMacAddress())) {\r
-                return true;\r
-            }\r
-        }\r
-        return false;\r
-    }\r
-\r
-    @Override\r
-    public NeutronPort getGatewayPort(String subnetUUID) {\r
-        INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);\r
-        NeutronSubnet subnet = systemCRUD.getSubnet(subnetUUID);\r
-        Iterator<NeutronPort> portIterator = getAllPorts().iterator();\r
-        while (portIterator.hasNext()) {\r
-            NeutronPort port = portIterator.next();\r
-            List<Neutron_IPs> fixedIPs = port.getFixedIPs();\r
-            if (fixedIPs.size() == 1) {\r
-                if (subnet.getGatewayIP().equals(fixedIPs.get(0).getIpAddress())) {\r
-                    return port;\r
-                }\r
-            }\r
-        }\r
-        return null;\r
-    }\r
-\r
-}\r
+/*
+ * Copyright IBM Corporation, 2013.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.networkconfig.neutron.implementation;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.felix.dm.Component;
+import org.opendaylight.controller.clustering.services.CacheConfigException;
+import org.opendaylight.controller.clustering.services.CacheExistException;
+import org.opendaylight.controller.clustering.services.IClusterContainerServices;
+import org.opendaylight.controller.clustering.services.IClusterServices;
+import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;
+import org.opendaylight.controller.networkconfig.neutron.INeutronPortCRUD;
+import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetCRUD;
+import org.opendaylight.controller.networkconfig.neutron.NeutronCRUDInterfaces;
+import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
+import org.opendaylight.controller.networkconfig.neutron.NeutronPort;
+import org.opendaylight.controller.networkconfig.neutron.NeutronSubnet;
+import org.opendaylight.controller.networkconfig.neutron.Neutron_IPs;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NeutronPortInterface implements INeutronPortCRUD {
+    private static final Logger logger = LoggerFactory.getLogger(NeutronPortInterface.class);
+    private String containerName = null;
+
+    private IClusterContainerServices clusterContainerService = null;
+    private ConcurrentMap<String, NeutronPort> portDB;
+
+    // methods needed for creating caches
+
+    void setClusterContainerService(IClusterContainerServices s) {
+        logger.debug("Cluster Service set");
+        clusterContainerService = s;
+    }
+
+    void unsetClusterContainerService(IClusterContainerServices s) {
+        if (clusterContainerService == s) {
+            logger.debug("Cluster Service removed!");
+            clusterContainerService = null;
+        }
+    }
+
+    @SuppressWarnings("deprecation")
+    private void allocateCache() {
+        if (clusterContainerService == null) {
+            logger.error("un-initialized clusterContainerService, can't create cache");
+            return;
+        }
+        logger.debug("Creating Cache for OpenDOVE");
+        try {
+            // neutron caches
+            clusterContainerService.createCache("neutronPorts",
+                    EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+        } catch (CacheConfigException cce) {
+            logger.error("Cache couldn't be created for OpenDOVE -  check cache mode");
+        } catch (CacheExistException cce) {
+            logger.error("Cache for OpenDOVE already exists, destroy and recreate");
+        }
+        logger.debug("Cache successfully created for OpenDOVE");
+    }
+
+    @SuppressWarnings({ "unchecked", "deprecation" })
+    private void retrieveCache() {
+        if (clusterContainerService == null) {
+            logger.error("un-initialized clusterContainerService, can't retrieve cache");
+            return;
+        }
+
+        logger.debug("Retrieving cache for Neutron Ports");
+        portDB = (ConcurrentMap<String, NeutronPort>) clusterContainerService
+        .getCache("neutronPorts");
+        if (portDB == null) {
+            logger.error("Cache couldn't be retrieved for Neutron Ports");
+        }
+        logger.debug("Cache was successfully retrieved for Neutron Ports");
+    }
+
+    @SuppressWarnings("deprecation")
+    private void destroyCache() {
+        if (clusterContainerService == null) {
+            logger.error("un-initialized clusterMger, can't destroy cache");
+            return;
+        }
+        logger.debug("Destroying Cache for HostTracker");
+        clusterContainerService.destroyCache("neutronPorts");
+    }
+
+    private void startUp() {
+        allocateCache();
+        retrieveCache();
+    }
+
+    /**
+     * Function called by the dependency manager when all the required
+     * dependencies are satisfied
+     *
+     */
+    void init(Component c) {
+        Dictionary<?, ?> props = c.getServiceProperties();
+        if (props != null) {
+            containerName = (String) props.get("containerName");
+            logger.debug("Running containerName: {}", containerName);
+        } else {
+            // In the Global instance case the containerName is empty
+            containerName = "";
+        }
+        startUp();
+    }
+
+    /**
+     * Function called by the dependency manager when at least one dependency
+     * become unsatisfied or when the component is shutting down because for
+     * example bundle is being stopped.
+     *
+     */
+    void destroy() {
+        destroyCache();
+    }
+
+    /**
+     * Function called by dependency manager after "init ()" is called and after
+     * the services provided by the class are registered in the service registry
+     *
+     */
+    void start() {
+    }
+
+    /**
+     * Function called by the dependency manager before the services exported by
+     * the component are unregistered, this will be followed by a "destroy ()"
+     * calls
+     *
+     */
+    void stop() {
+    }
+
+    // this method uses reflection to update an object from it's delta.
+
+    private boolean overwrite(Object target, Object delta) {
+        Method[] methods = target.getClass().getMethods();
+
+        for(Method toMethod: methods){
+            if(toMethod.getDeclaringClass().equals(target.getClass())
+                    && toMethod.getName().startsWith("set")){
+
+                String toName = toMethod.getName();
+                String fromName = toName.replace("set", "get");
+
+                try {
+                    Method fromMethod = delta.getClass().getMethod(fromName);
+                    Object value = fromMethod.invoke(delta, (Object[])null);
+                    if(value != null){
+                        toMethod.invoke(target, value);
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+    // IfNBPortCRUD methods
+
+    @Override
+    public boolean portExists(String uuid) {
+        return portDB.containsKey(uuid);
+    }
+
+    @Override
+    public NeutronPort getPort(String uuid) {
+        if (!portExists(uuid)) {
+            return null;
+        }
+        return portDB.get(uuid);
+    }
+
+    @Override
+    public List<NeutronPort> getAllPorts() {
+        Set<NeutronPort> allPorts = new HashSet<NeutronPort>();
+        for (Entry<String, NeutronPort> entry : portDB.entrySet()) {
+            NeutronPort port = entry.getValue();
+            allPorts.add(port);
+        }
+        logger.debug("Exiting getAllPorts, Found {} OpenStackPorts", allPorts.size());
+        List<NeutronPort> ans = new ArrayList<NeutronPort>();
+        ans.addAll(allPorts);
+        return ans;
+    }
+
+    @Override
+    public boolean addPort(NeutronPort input) {
+        if (portExists(input.getID())) {
+            return false;
+        }
+        portDB.putIfAbsent(input.getID(), input);
+        // if there are no fixed IPs, allocate one for each subnet in the network
+        INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);
+        if (input.getFixedIPs().size() == 0) {
+            List<Neutron_IPs> list = input.getFixedIPs();
+            Iterator<NeutronSubnet> subnetIterator = systemCRUD.getAllSubnets().iterator();
+            while (subnetIterator.hasNext()) {
+                NeutronSubnet subnet = subnetIterator.next();
+                if (subnet.getNetworkUUID().equals(input.getNetworkUUID())) {
+                    list.add(new Neutron_IPs(subnet.getID()));
+                }
+            }
+        }
+        Iterator<Neutron_IPs> fixedIPIterator = input.getFixedIPs().iterator();
+        while (fixedIPIterator.hasNext()) {
+            Neutron_IPs ip = fixedIPIterator.next();
+            NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());
+            if (ip.getIpAddress() == null) {
+                ip.setIpAddress(subnet.getLowAddr());
+            }
+            if (!ip.getIpAddress().equals(subnet.getGatewayIP())) {
+                subnet.allocateIP(ip.getIpAddress());
+            }
+            else {
+                subnet.setGatewayIPAllocated();
+            }
+            subnet.addPort(input);
+        }
+        INeutronNetworkCRUD networkIf = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);
+
+        NeutronNetwork network = networkIf.getNetwork(input.getNetworkUUID());
+        network.addPort(input);
+        return true;
+    }
+
+    @Override
+    public boolean removePort(String uuid) {
+        if (!portExists(uuid)) {
+            return false;
+        }
+        NeutronPort port = getPort(uuid);
+        portDB.remove(uuid);
+        INeutronNetworkCRUD networkCRUD = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);
+        INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);
+
+        NeutronNetwork network = networkCRUD.getNetwork(port.getNetworkUUID());
+        network.removePort(port);
+        Iterator<Neutron_IPs> fixedIPIterator = port.getFixedIPs().iterator();
+        while (fixedIPIterator.hasNext()) {
+            Neutron_IPs ip = fixedIPIterator.next();
+            NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());
+            if (!ip.getIpAddress().equals(subnet.getGatewayIP())) {
+                subnet.releaseIP(ip.getIpAddress());
+            }
+            else {
+                subnet.resetGatewayIPAllocated();
+            }
+            subnet.removePort(port);
+        }
+        return true;
+    }
+
+    @Override
+    public boolean updatePort(String uuid, NeutronPort delta) {
+        if (!portExists(uuid)) {
+            return false;
+        }
+        NeutronPort target = portDB.get(uuid);
+        // remove old Fixed_IPs
+        if (delta.getFixedIPs() != null) {
+            NeutronPort port = getPort(uuid);
+            INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);
+            for (Neutron_IPs ip: port.getFixedIPs()) {
+                NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());
+                subnet.releaseIP(ip.getIpAddress());
+            }
+
+            // allocate new Fixed_IPs
+            for (Neutron_IPs ip: delta.getFixedIPs()) {
+                NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());
+                if (ip.getIpAddress() == null) {
+                    ip.setIpAddress(subnet.getLowAddr());
+                }
+                subnet.allocateIP(ip.getIpAddress());
+            }
+        }
+        return overwrite(target, delta);
+    }
+
+    @Override
+    public boolean macInUse(String macAddress) {
+        List<NeutronPort> ports = getAllPorts();
+        Iterator<NeutronPort> portIterator = ports.iterator();
+        while (portIterator.hasNext()) {
+            NeutronPort port = portIterator.next();
+            if (macAddress.equalsIgnoreCase(port.getMacAddress())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public NeutronPort getGatewayPort(String subnetUUID) {
+        INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);
+        NeutronSubnet subnet = systemCRUD.getSubnet(subnetUUID);
+        Iterator<NeutronPort> portIterator = getAllPorts().iterator();
+        while (portIterator.hasNext()) {
+            NeutronPort port = portIterator.next();
+            List<Neutron_IPs> fixedIPs = port.getFixedIPs();
+            if (fixedIPs.size() == 1) {
+                if (subnet.getGatewayIP().equals(fixedIPs.get(0).getIpAddress())) {
+                    return port;
+                }
+            }
+        }
+        return null;
+    }
+
+}