Initial push of Neutron interface
authorRyan Moats <rmoats@us.ibm.com>
Fri, 20 Sep 2013 17:51:39 +0000 (12:51 -0500)
committerAndrew Grimberg <agrimberg@linuxfoundation.org>
Fri, 13 Feb 2015 16:05:03 +0000 (08:05 -0800)
Two bundles included in this:
-networkconfig.neutron (contains JAXB annotated classes, *CRUD
interfaces with an implementation [for storing objects], and
Aware interfaces [for other bundles to register services])
-networkconfig.neutron.northbound (contains the JAXRS annotated
classes along with JAXB annotated request specific classes)

Commit amended to refactor .internal package to separate
implementation bundle and package

Commit re-amended to clean up issues in commons/opendaylight
and distribution/opendaylight poms

Commit re-re-amended to fix conflicts on rebase (I hope)

Getting close to just abandoning the change and starting over

Commit re-re-re-amended to fix parent issues in pom

amend to remove leaked CRs in distribution pom

- Cleanup of some duplicates artifact and of commons-net in modules
dependencies, anyway they get in via the commons.opendaylight

Change-Id: I15724c55e843237c010dfaec1e1e523560174f51
Signed-off-by: Ryan Moats <rmoats@us.ibm.com>
29 files changed:
implementation/pom.xml [new file with mode: 0644]
implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/Activator.java [new file with mode: 0644]
implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronFloatingIPInterface.java [new file with mode: 0644]
implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronNetworkInterface.java [new file with mode: 0644]
implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronPortInterface.java [new file with mode: 0644]
implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronRouterInterface.java [new file with mode: 0644]
implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronSubnetInterface.java [new file with mode: 0644]
pom.xml [new file with mode: 0644]
src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronFloatingIPAware.java [new file with mode: 0644]
src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronFloatingIPCRUD.java [new file with mode: 0644]
src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronNetworkAware.java [new file with mode: 0644]
src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronNetworkCRUD.java [new file with mode: 0644]
src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronPortAware.java [new file with mode: 0644]
src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronPortCRUD.java [new file with mode: 0644]
src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronRouterAware.java [new file with mode: 0644]
src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronRouterCRUD.java [new file with mode: 0644]
src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronSubnetAware.java [new file with mode: 0644]
src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronSubnetCRUD.java [new file with mode: 0644]
src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronCRUDInterfaces.java [new file with mode: 0644]
src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronFloatingIP.java [new file with mode: 0644]
src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronNetwork.java [new file with mode: 0644]
src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronPort.java [new file with mode: 0644]
src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronRouter.java [new file with mode: 0644]
src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronRouter_Interface.java [new file with mode: 0644]
src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronRouter_NetworkReference.java [new file with mode: 0644]
src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet.java [new file with mode: 0644]
src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet_HostRoute.java [new file with mode: 0644]
src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet_IPAllocationPool.java [new file with mode: 0644]
src/main/java/org/opendaylight/controller/networkconfig/neutron/Neutron_IPs.java [new file with mode: 0644]

diff --git a/implementation/pom.xml b/implementation/pom.xml
new file mode 100644 (file)
index 0000000..5aa3c32
--- /dev/null
@@ -0,0 +1,81 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
+  <modelVersion>4.0.0</modelVersion>\r
+  <parent>\r
+    <groupId>org.opendaylight.controller</groupId>\r
+    <artifactId>commons.opendaylight</artifactId>\r
+    <version>1.4.0-SNAPSHOT</version>\r
+    <relativePath>../../../commons/opendaylight</relativePath>\r
+  </parent>\r
+      <properties>\r
+        <nexusproxy>http://nexus.opendaylight.org/content</nexusproxy>\r
+        <enunciate.version>1.26.2</enunciate.version>\r
+    </properties>\r
+\r
+    <distributionManagement>\r
+        <!-- OpenDayLight Released artifact -->\r
+        <repository>\r
+            <id>opendaylight-release</id>\r
+            <url>${nexusproxy}/repositories/opendaylight.release/</url>\r
+        </repository>\r
+        <!-- OpenDayLight Snapshot artifact -->\r
+        <snapshotRepository>\r
+            <id>opendaylight-snapshot</id>\r
+            <url>${nexusproxy}/repositories/opendaylight.snapshot/</url>\r
+        </snapshotRepository>\r
+        <!-- Site deployment -->\r
+        <site>\r
+            <id>website</id>\r
+            <url>${sitedeploy}</url>\r
+        </site>\r
+    </distributionManagement>\r
+  <groupId>org.opendaylight.controller</groupId>\r
+  <artifactId>networkconfig.neutron.implementation</artifactId>\r
+  <version>0.4.0-SNAPSHOT</version>\r
+  <packaging>bundle</packaging>\r
+  <build>\r
+        <plugins>\r
+            <plugin>\r
+                <groupId>org.apache.felix</groupId>\r
+                <artifactId>maven-bundle-plugin</artifactId>\r
+                <version>2.3.6</version>\r
+                <extensions>true</extensions>\r
+                <configuration>\r
+                    <instructions>\r
+                        <Import-Package>\r
+                            org.opendaylight.controller.clustering.services,\r
+                            org.opendaylight.controller.sal.core,\r
+                            org.opendaylight.controller.sal.utils,\r
+                            org.apache.felix.dm,\r
+                            org.apache.commons.net.util,\r
+                            org.osgi.service.component,\r
+                            org.opendaylight.controller.networkconfig.neutron,\r
+                            org.slf4j,\r
+                            javax.xml.bind.annotation\r
+                        </Import-Package>\r
+                        <Bundle-Activator>\r
+                            org.opendaylight.controller.networkconfig.neutron.implementation.Activator\r
+                        </Bundle-Activator>\r
+                    </instructions>\r
+                    <manifestLocation>${project.basedir}/src/main/resources/META-INF</manifestLocation>\r
+                </configuration>\r
+            </plugin>\r
+        </plugins>\r
+    </build>\r
+     <dependencies>\r
+        <dependency>\r
+            <groupId>org.opendaylight.controller</groupId>\r
+            <artifactId>clustering.services</artifactId>\r
+            <version>0.4.0-SNAPSHOT</version>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>org.opendaylight.controller</groupId>\r
+            <artifactId>networkconfig.neutron</artifactId>\r
+            <version>0.4.0-SNAPSHOT</version>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>org.opendaylight.controller</groupId>\r
+            <artifactId>sal</artifactId>\r
+            <version>0.5.0-SNAPSHOT</version>\r
+        </dependency>\r
+    </dependencies>\r
+</project>\r
diff --git a/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/Activator.java b/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/Activator.java
new file mode 100644 (file)
index 0000000..d8d5cc4
--- /dev/null
@@ -0,0 +1,141 @@
+/*\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.util.Hashtable;\r
+import java.util.Dictionary;\r
+import org.apache.felix.dm.Component;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+import org.opendaylight.controller.clustering.services.IClusterContainerServices;\r
+import org.opendaylight.controller.networkconfig.neutron.INeutronFloatingIPCRUD;\r
+import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;\r
+import org.opendaylight.controller.networkconfig.neutron.INeutronPortCRUD;\r
+import org.opendaylight.controller.networkconfig.neutron.INeutronRouterCRUD;\r
+import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetCRUD;\r
+import org.opendaylight.controller.networkconfig.neutron.implementation.NeutronFloatingIPInterface;\r
+import org.opendaylight.controller.networkconfig.neutron.implementation.NeutronNetworkInterface;\r
+import org.opendaylight.controller.networkconfig.neutron.implementation.NeutronPortInterface;\r
+import org.opendaylight.controller.networkconfig.neutron.implementation.NeutronRouterInterface;\r
+import org.opendaylight.controller.networkconfig.neutron.implementation.NeutronSubnetInterface;\r
+import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;\r
+\r
+public class Activator extends ComponentActivatorAbstractBase {\r
+    protected static final Logger logger = LoggerFactory\r
+    .getLogger(Activator.class);\r
+\r
+    /**\r
+     * Function called when the activator starts just after some\r
+     * initializations are done by the\r
+     * ComponentActivatorAbstractBase.\r
+     *\r
+     */\r
+    public void init() {\r
+\r
+    }\r
+\r
+    /**\r
+     * Function called when the activator stops just before the\r
+     * cleanup done by ComponentActivatorAbstractBase\r
+     *\r
+     */\r
+    public void destroy() {\r
+\r
+    }\r
+\r
+    /**\r
+     * Function that is used to communicate to dependency manager the\r
+     * list of known implementations for services inside a container\r
+     *\r
+     *\r
+     * @return An array containing all the CLASS objects that will be\r
+     * instantiated in order to get an fully working implementation\r
+     * Object\r
+     */\r
+    public Object[] getImplementations() {\r
+        Object[] res = { NeutronFloatingIPInterface.class,\r
+                NeutronRouterInterface.class,\r
+                NeutronPortInterface.class,\r
+                NeutronSubnetInterface.class,\r
+                NeutronNetworkInterface.class };\r
+        return res;\r
+    }\r
+\r
+    /**\r
+     * Function that is called when configuration of the dependencies\r
+     * is required.\r
+     *\r
+     * @param c dependency manager Component object, used for\r
+     * configuring the dependencies exported and imported\r
+     * @param imp Implementation class that is being configured,\r
+     * needed as long as the same routine can configure multiple\r
+     * implementations\r
+     * @param containerName The containerName being configured, this allow\r
+     * also optional per-container different behavior if needed, usually\r
+     * should not be the case though.\r
+     */\r
+    public void configureInstance(Component c, Object imp, String containerName) {\r
+        if (imp.equals(NeutronFloatingIPInterface.class)) {\r
+            // export the service\r
+            c.setInterface(\r
+                    new String[] { INeutronFloatingIPCRUD.class.getName() }, null);\r
+            Dictionary<String, String> props = new Hashtable<String, String>();\r
+            props.put("salListenerName", "neutron");\r
+            c.add(createContainerServiceDependency(containerName)\r
+                    .setService(IClusterContainerServices.class)\r
+                    .setCallbacks("setClusterContainerService",\r
+                    "unsetClusterContainerService").setRequired(true));\r
+        }\r
+        if (imp.equals(NeutronRouterInterface.class)) {\r
+            // export the service\r
+            c.setInterface(\r
+                    new String[] { INeutronRouterCRUD.class.getName() }, null);\r
+            Dictionary<String, String> props = new Hashtable<String, String>();\r
+            props.put("salListenerName", "neutron");\r
+            c.add(createContainerServiceDependency(containerName)\r
+                    .setService(IClusterContainerServices.class)\r
+                    .setCallbacks("setClusterContainerService",\r
+                    "unsetClusterContainerService").setRequired(true));\r
+        }\r
+        if (imp.equals(NeutronPortInterface.class)) {\r
+            // export the service\r
+            c.setInterface(\r
+                    new String[] { INeutronPortCRUD.class.getName() }, null);\r
+            Dictionary<String, String> props = new Hashtable<String, String>();\r
+            props.put("salListenerName", "neutron");\r
+            c.add(createContainerServiceDependency(containerName)\r
+                    .setService(IClusterContainerServices.class)\r
+                    .setCallbacks("setClusterContainerService",\r
+                    "unsetClusterContainerService").setRequired(true));\r
+        }\r
+        if (imp.equals(NeutronSubnetInterface.class)) {\r
+            // export the service\r
+            c.setInterface(\r
+                    new String[] { INeutronSubnetCRUD.class.getName() }, null);\r
+            Dictionary<String, String> props = new Hashtable<String, String>();\r
+            props.put("salListenerName", "neutron");\r
+            c.add(createContainerServiceDependency(containerName)\r
+                    .setService(IClusterContainerServices.class)\r
+                    .setCallbacks("setClusterContainerService",\r
+                    "unsetClusterContainerService").setRequired(true));\r
+        }\r
+        if (imp.equals(NeutronNetworkInterface.class)) {\r
+            // export the service\r
+            c.setInterface(\r
+                    new String[] { INeutronNetworkCRUD.class.getName() }, null);\r
+            Dictionary<String, String> props = new Hashtable<String, String>();\r
+            props.put("salListenerName", "neutron");\r
+            c.add(createContainerServiceDependency(containerName)\r
+                    .setService(IClusterContainerServices.class)\r
+                    .setCallbacks("setClusterContainerService",\r
+                    "unsetClusterContainerService").setRequired(true));\r
+        }\r
+    }\r
+}\r
diff --git a/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronFloatingIPInterface.java b/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronFloatingIPInterface.java
new file mode 100644 (file)
index 0000000..7b10756
--- /dev/null
@@ -0,0 +1,266 @@
+/*\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.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.INeutronFloatingIPCRUD;\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.NeutronFloatingIP;\r
+import org.opendaylight.controller.networkconfig.neutron.NeutronPort;\r
+import org.opendaylight.controller.networkconfig.neutron.NeutronSubnet;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+public class NeutronFloatingIPInterface implements INeutronFloatingIPCRUD {\r
+    private static final Logger logger = LoggerFactory.getLogger(NeutronFloatingIPInterface.class);\r
+    private String containerName = null;\r
+\r
+    private IClusterContainerServices clusterContainerService = null;\r
+    private ConcurrentMap<String, NeutronFloatingIP> floatingIPDB;\r
+\r
+    // methods needed for creating caches\r
+\r
+    void setClusterContainerService(IClusterContainerServices s) {\r
+        logger.debug("Cluster Service set");\r
+        this.clusterContainerService = s;\r
+    }\r
+\r
+    void unsetClusterContainerService(IClusterContainerServices s) {\r
+        if (this.clusterContainerService == s) {\r
+            logger.debug("Cluster Service removed!");\r
+            this.clusterContainerService = null;\r
+        }\r
+    }\r
+\r
+    @SuppressWarnings("deprecation")\r
+    private void allocateCache() {\r
+        if (this.clusterContainerService == null) {\r
+            logger.error("un-initialized clusterContainerService, can't create cache");\r
+            return;\r
+        }\r
+        logger.debug("Creating Cache for Neutron FloatingIPs");\r
+        try {\r
+            // neutron caches\r
+            this.clusterContainerService.createCache("neutronFloatingIPs",\r
+                    EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));\r
+        } catch (CacheConfigException cce) {\r
+            logger.error("Cache couldn't be created for Neutron -  check cache mode");\r
+        } catch (CacheExistException cce) {\r
+            logger.error("Cache for Neutron already exists, destroy and recreate");\r
+        }\r
+        logger.debug("Cache successfully created for NeutronFloatingIps");\r
+    }\r
+\r
+    @SuppressWarnings({ "unchecked", "deprecation" })\r
+    private void retrieveCache() {\r
+        if (this.clusterContainerService == null) {\r
+            logger.error("un-initialized clusterContainerService, can't retrieve cache");\r
+            return;\r
+        }\r
+\r
+        logger.debug("Retrieving cache for Neutron FloatingIPs");\r
+        floatingIPDB = (ConcurrentMap<String, NeutronFloatingIP>) this.clusterContainerService\r
+        .getCache("neutronFloatingIPs");\r
+        if (floatingIPDB == null) {\r
+            logger.error("Cache couldn't be retrieved for Neutron FloatingIPs");\r
+        }\r
+        logger.debug("Cache was successfully retrieved for Neutron FloatingIPs");\r
+    }\r
+\r
+    @SuppressWarnings("deprecation")\r
+    private void destroyCache() {\r
+        if (this.clusterContainerService == null) {\r
+            logger.error("un-initialized clusterMger, can't destroy cache");\r
+            return;\r
+        }\r
+        logger.debug("Destroying Cache for HostTracker");\r
+        this.clusterContainerService.destroyCache("neutronFloatingIPs");\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
+            this.containerName = (String) props.get("containerName");\r
+            logger.debug("Running containerName: {}", this.containerName);\r
+        } else {\r
+            // In the Global instance case the containerName is empty\r
+            this.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
+    // IfNBFloatingIPCRUD interface methods\r
+\r
+    public boolean floatingIPExists(String uuid) {\r
+        return floatingIPDB.containsKey(uuid);\r
+    }\r
+\r
+    public NeutronFloatingIP getFloatingIP(String uuid) {\r
+        if (!floatingIPExists(uuid))\r
+            return null;\r
+        return floatingIPDB.get(uuid);\r
+    }\r
+\r
+    public List<NeutronFloatingIP> getAllFloatingIPs() {\r
+        Set<NeutronFloatingIP> allIPs = new HashSet<NeutronFloatingIP>();\r
+        for (Entry<String, NeutronFloatingIP> entry : floatingIPDB.entrySet()) {\r
+            NeutronFloatingIP floatingip = entry.getValue();\r
+            allIPs.add(floatingip);\r
+        }\r
+        logger.debug("Exiting getAllFloatingIPs, Found {} FloatingIPs", allIPs.size());\r
+        List<NeutronFloatingIP> ans = new ArrayList<NeutronFloatingIP>();\r
+        ans.addAll(allIPs);\r
+        return ans;\r
+    }\r
+\r
+    public boolean addFloatingIP(NeutronFloatingIP input) {\r
+        INeutronNetworkCRUD networkCRUD = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);\r
+        INeutronSubnetCRUD subnetCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);\r
+        INeutronPortCRUD portCRUD = NeutronCRUDInterfaces.getINeutronPortCRUD(this);\r
+\r
+        if (floatingIPExists(input.getID()))\r
+            return false;\r
+        //if floating_ip_address isn't there, allocate from the subnet pool\r
+        NeutronSubnet subnet = subnetCRUD.getSubnet(networkCRUD.getNetwork(input.getFloatingNetworkUUID()).getSubnets().get(0));\r
+        if (input.getFloatingIPAddress() == null)\r
+            input.setFloatingIPAddress(subnet.getLowAddr());\r
+        subnet.allocateIP(input.getFloatingIPAddress());\r
+\r
+        //if port_id is there, bind port to this floating ip\r
+        if (input.getPortUUID() != null) {\r
+            NeutronPort port = portCRUD.getPort(input.getPortUUID());\r
+            port.addFloatingIP(input.getFixedIPAddress(), input);\r
+        }\r
+\r
+        floatingIPDB.putIfAbsent(input.getID(), input);\r
+        return true;\r
+    }\r
+\r
+    public boolean removeFloatingIP(String uuid) {\r
+        INeutronNetworkCRUD networkCRUD = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);\r
+        INeutronSubnetCRUD subnetCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);\r
+        INeutronPortCRUD portCRUD = NeutronCRUDInterfaces.getINeutronPortCRUD(this);\r
+\r
+        if (!floatingIPExists(uuid))\r
+            return false;\r
+        NeutronFloatingIP floatIP = getFloatingIP(uuid);\r
+        //if floating_ip_address isn't there, allocate from the subnet pool\r
+        NeutronSubnet subnet = subnetCRUD.getSubnet(networkCRUD.getNetwork(floatIP.getFloatingNetworkUUID()).getSubnets().get(0));\r
+        subnet.releaseIP(floatIP.getFloatingIPAddress());\r
+        if (floatIP.getPortUUID() != null) {\r
+            NeutronPort port = portCRUD.getPort(floatIP.getPortUUID());\r
+            port.removeFloatingIP(floatIP.getFixedIPAddress());\r
+        }\r
+        floatingIPDB.remove(uuid);\r
+        return true;\r
+    }\r
+\r
+    public boolean updateFloatingIP(String uuid, NeutronFloatingIP delta) {\r
+        INeutronPortCRUD portCRUD = NeutronCRUDInterfaces.getINeutronPortCRUD(this);\r
+\r
+        if (!floatingIPExists(uuid))\r
+            return false;\r
+        NeutronFloatingIP target = floatingIPDB.get(uuid);\r
+        if (target.getPortUUID() != null) {\r
+            NeutronPort port = portCRUD.getPort(target.getPortUUID());\r
+            port.removeFloatingIP(target.getFixedIPAddress());\r
+        }\r
+\r
+        //if port_id is there, bind port to this floating ip\r
+        if (delta.getPortUUID() != null) {\r
+            NeutronPort port = portCRUD.getPort(delta.getPortUUID());\r
+            port.addFloatingIP(delta.getFixedIPAddress(), delta);\r
+        }\r
+\r
+        target.setPortUUID(delta.getPortUUID());\r
+        target.setFixedIPAddress(delta.getFixedIPAddress());\r
+        return true;\r
+    }\r
+}\r
diff --git a/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronNetworkInterface.java b/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronNetworkInterface.java
new file mode 100644 (file)
index 0000000..035e6dc
--- /dev/null
@@ -0,0 +1,227 @@
+/*\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.NeutronNetwork;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+public class NeutronNetworkInterface implements INeutronNetworkCRUD {\r
+    private static final Logger logger = LoggerFactory.getLogger(NeutronNetworkInterface.class);\r
+    private String containerName = null;\r
+\r
+    private ConcurrentMap<String, NeutronNetwork> networkDB;\r
+    private IClusterContainerServices clusterContainerService = null;\r
+\r
+    // methods needed for creating caches\r
+\r
+    void setClusterContainerService(IClusterContainerServices s) {\r
+        logger.debug("Cluster Service set");\r
+        this.clusterContainerService = s;\r
+    }\r
+\r
+    void unsetClusterContainerService(IClusterContainerServices s) {\r
+        if (this.clusterContainerService == s) {\r
+            logger.debug("Cluster Service removed!");\r
+            this.clusterContainerService = null;\r
+        }\r
+    }\r
+\r
+    @SuppressWarnings("deprecation")\r
+    private void allocateCache() {\r
+        if (this.clusterContainerService == null) {\r
+            logger.error("un-initialized clusterContainerService, can't create cache");\r
+            return;\r
+        }\r
+        logger.debug("Creating Cache for Neutron Networks");\r
+        try {\r
+            // neutron caches\r
+            this.clusterContainerService.createCache("neutronNetworks",\r
+                    EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));\r
+        } catch (CacheConfigException cce) {\r
+            logger.error("Cache couldn't be created for Neutron Networks -  check cache mode");\r
+        } catch (CacheExistException cce) {\r
+            logger.error("Cache for Neutron Networks already exists, destroy and recreate");\r
+        }\r
+        logger.debug("Cache successfully created for Neutron Networks");\r
+    }\r
+\r
+    @SuppressWarnings({ "unchecked", "deprecation" })\r
+    private void retrieveCache() {\r
+        if (this.clusterContainerService == null) {\r
+            logger.error("un-initialized clusterContainerService, can't retrieve cache");\r
+            return;\r
+        }\r
+        logger.debug("Retrieving cache for Neutron Networks");\r
+        networkDB = (ConcurrentMap<String, NeutronNetwork>) this.clusterContainerService.getCache("neutronNetworks");\r
+        if (networkDB == null) {\r
+            logger.error("Cache couldn't be retrieved for Neutron Networks");\r
+        }\r
+        logger.debug("Cache was successfully retrieved for Neutron Networks");\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
+            this.containerName = (String) props.get("containerName");\r
+            logger.debug("Running containerName: {}", this.containerName);\r
+        } else {\r
+            // In the Global instance case the containerName is empty\r
+            this.containerName = "";\r
+        }\r
+        startUp();\r
+    }\r
+\r
+    @SuppressWarnings("deprecation")\r
+    private void destroyCache() {\r
+        if (this.clusterContainerService == null) {\r
+            logger.error("un-initialized clusterMger, can't destroy cache");\r
+            return;\r
+        }\r
+        logger.debug("Destroying Cache for Neutron Networks");\r
+        this.clusterContainerService.destroyCache("Neutron Networks");\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
+    // IfNBNetworkCRUD methods\r
+\r
+    public boolean networkExists(String uuid) {\r
+        return networkDB.containsKey(uuid);\r
+    }\r
+\r
+    public NeutronNetwork getNetwork(String uuid) {\r
+        if (!networkExists(uuid))\r
+            return null;\r
+        return networkDB.get(uuid);\r
+    }\r
+\r
+    public List<NeutronNetwork> getAllNetworks() {\r
+        Set<NeutronNetwork> allNetworks = new HashSet<NeutronNetwork>();\r
+        for (Entry<String, NeutronNetwork> entry : networkDB.entrySet()) {\r
+            NeutronNetwork network = entry.getValue();\r
+            allNetworks.add(network);\r
+        }\r
+        logger.debug("Exiting getAllNetworks, Found {} OpenStackNetworks", allNetworks.size());\r
+        List<NeutronNetwork> ans = new ArrayList<NeutronNetwork>();\r
+        ans.addAll(allNetworks);\r
+        return ans;\r
+    }\r
+\r
+    public boolean addNetwork(NeutronNetwork input) {\r
+        if (networkExists(input.getID()))\r
+            return false;\r
+        networkDB.putIfAbsent(input.getID(), input);\r
+      //TODO: add code to find INeutronNetworkAware services and call newtorkCreated on them\r
+        return true;\r
+    }\r
+\r
+    public boolean removeNetwork(String uuid) {\r
+        if (!networkExists(uuid))\r
+            return false;\r
+        networkDB.remove(uuid);\r
+      //TODO: add code to find INeutronNetworkAware services and call newtorkDeleted on them\r
+        return true;\r
+    }\r
+\r
+    public boolean updateNetwork(String uuid, NeutronNetwork delta) {\r
+        if (!networkExists(uuid))\r
+            return false;\r
+        NeutronNetwork target = networkDB.get(uuid);\r
+        return overwrite(target, delta);\r
+    }\r
+\r
+    public boolean networkInUse(String netUUID) {\r
+        if (!networkExists(netUUID))\r
+            return true;\r
+        NeutronNetwork target = networkDB.get(netUUID);\r
+        if (target.getPortsOnNetwork().size() > 0)\r
+            return true;\r
+        return false;\r
+    }\r
+}\r
diff --git a/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronPortInterface.java b/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronPortInterface.java
new file mode 100644 (file)
index 0000000..eea1977
--- /dev/null
@@ -0,0 +1,313 @@
+/*\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
+        this.clusterContainerService = s;\r
+    }\r
+\r
+    void unsetClusterContainerService(IClusterContainerServices s) {\r
+        if (this.clusterContainerService == s) {\r
+            logger.debug("Cluster Service removed!");\r
+            this.clusterContainerService = null;\r
+        }\r
+    }\r
+\r
+    @SuppressWarnings("deprecation")\r
+    private void allocateCache() {\r
+        if (this.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
+            this.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 (this.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>) this.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 (this.clusterContainerService == null) {\r
+            logger.error("un-initialized clusterMger, can't destroy cache");\r
+            return;\r
+        }\r
+        logger.debug("Destroying Cache for HostTracker");\r
+        this.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
+            this.containerName = (String) props.get("containerName");\r
+            logger.debug("Running containerName: {}", this.containerName);\r
+        } else {\r
+            // In the Global instance case the containerName is empty\r
+            this.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
+    public boolean portExists(String uuid) {\r
+        return portDB.containsKey(uuid);\r
+    }\r
+\r
+    public NeutronPort getPort(String uuid) {\r
+        if (!portExists(uuid))\r
+            return null;\r
+        return portDB.get(uuid);\r
+    }\r
+\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
+    public boolean addPort(NeutronPort input) {\r
+        if (portExists(input.getID()))\r
+            return false;\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
+        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
+            if (!ip.getIpAddress().equals(subnet.getGatewayIP()))\r
+                subnet.allocateIP(ip.getIpAddress());\r
+            else\r
+                subnet.setGatewayIPAllocated();\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
+    public boolean removePort(String uuid) {\r
+        if (!portExists(uuid))\r
+            return false;\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
+            else\r
+                subnet.resetGatewayIPAllocated();\r
+            subnet.removePort(port);\r
+        }\r
+        return true;\r
+    }\r
+\r
+    public boolean updatePort(String uuid, NeutronPort delta) {\r
+        if (!portExists(uuid))\r
+            return false;\r
+        NeutronPort target = portDB.get(uuid);\r
+        // remove old Fixed_IPs\r
+        NeutronPort port = getPort(uuid);\r
+        INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);\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
+            subnet.releaseIP(ip.getIpAddress());\r
+        }\r
+\r
+        // allocate new Fixed_IPs\r
+        fixedIPIterator = delta.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
+            subnet.allocateIP(ip.getIpAddress());\r
+        }\r
+        return overwrite(target, delta);\r
+    }\r
+\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
+        return false;\r
+    }\r
+\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
+        return null;\r
+    }\r
+\r
+}\r
diff --git a/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronRouterInterface.java b/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronRouterInterface.java
new file mode 100644 (file)
index 0000000..0a7afa5
--- /dev/null
@@ -0,0 +1,224 @@
+/*\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.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.INeutronRouterCRUD;\r
+import org.opendaylight.controller.networkconfig.neutron.NeutronRouter;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+public class NeutronRouterInterface implements INeutronRouterCRUD {\r
+    private static final Logger logger = LoggerFactory.getLogger(NeutronRouterInterface.class);\r
+    private String containerName = null;\r
+\r
+    private IClusterContainerServices clusterContainerService = null;\r
+    private ConcurrentMap<String, NeutronRouter> routerDB;\r
+    // methods needed for creating caches\r
+\r
+    void setClusterContainerService(IClusterContainerServices s) {\r
+        logger.debug("Cluster Service set");\r
+        this.clusterContainerService = s;\r
+    }\r
+\r
+    void unsetClusterContainerService(IClusterContainerServices s) {\r
+        if (this.clusterContainerService == s) {\r
+            logger.debug("Cluster Service removed!");\r
+            this.clusterContainerService = null;\r
+        }\r
+    }\r
+\r
+    @SuppressWarnings("deprecation")\r
+    private void allocateCache() {\r
+        if (this.clusterContainerService == null) {\r
+            logger.error("un-initialized clusterContainerService, can't create cache");\r
+            return;\r
+        }\r
+        logger.debug("Creating Cache for Neutron Routers");\r
+        try {\r
+            // neutron caches\r
+            this.clusterContainerService.createCache("neutronRouters",\r
+                    EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));\r
+        } catch (CacheConfigException cce) {\r
+            logger.error("Cache couldn't be created for Neutron Routers -  check cache mode");\r
+        } catch (CacheExistException cce) {\r
+            logger.error("Cache for Neutron Routers already exists, destroy and recreate");\r
+        }\r
+        logger.debug("Cache successfully created for Neutron Routers");\r
+    }\r
+\r
+    @SuppressWarnings({ "unchecked", "deprecation" })\r
+    private void retrieveCache() {\r
+        if (this.clusterContainerService == null) {\r
+            logger.error("un-initialized clusterContainerService, can't retrieve cache");\r
+            return;\r
+        }\r
+\r
+        logger.debug("Retrieving cache for Neutron Routers");\r
+        routerDB = (ConcurrentMap<String, NeutronRouter>) this.clusterContainerService\r
+        .getCache("neutronRouters");\r
+        if (routerDB == null) {\r
+            logger.error("Cache couldn't be retrieved for Neutron Routers");\r
+        }\r
+        logger.debug("Cache was successfully retrieved for Neutron Routers");\r
+    }\r
+\r
+    @SuppressWarnings("deprecation")\r
+    private void destroyCache() {\r
+        if (this.clusterContainerService == null) {\r
+            logger.error("un-initialized clusterMger, can't destroy cache");\r
+            return;\r
+        }\r
+        logger.debug("Destroying Cache for HostTracker");\r
+        this.clusterContainerService.destroyCache("neutronRouters");\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
+            this.containerName = (String) props.get("containerName");\r
+            logger.debug("Running containerName: {}", this.containerName);\r
+        } else {\r
+            // In the Global instance case the containerName is empty\r
+            this.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
+\r
+    // IfNBRouterCRUD Interface methods\r
+\r
+    public boolean routerExists(String uuid) {\r
+        return routerDB.containsKey(uuid);\r
+    }\r
+\r
+    public NeutronRouter getRouter(String uuid) {\r
+        if (!routerExists(uuid))\r
+            return null;\r
+        return routerDB.get(uuid);\r
+    }\r
+\r
+    public List<NeutronRouter> getAllRouters() {\r
+        Set<NeutronRouter> allRouters = new HashSet<NeutronRouter>();\r
+        for (Entry<String, NeutronRouter> entry : routerDB.entrySet()) {\r
+            NeutronRouter router = entry.getValue();\r
+            allRouters.add(router);\r
+        }\r
+        logger.debug("Exiting getAllRouters, Found {} Routers", allRouters.size());\r
+        List<NeutronRouter> ans = new ArrayList<NeutronRouter>();\r
+        ans.addAll(allRouters);\r
+        return ans;\r
+    }\r
+\r
+    public boolean addRouter(NeutronRouter input) {\r
+        if (routerExists(input.getID()))\r
+            return false;\r
+        routerDB.putIfAbsent(input.getID(), input);\r
+        return true;\r
+    }\r
+\r
+    public boolean removeRouter(String uuid) {\r
+        if (!routerExists(uuid))\r
+            return false;\r
+        routerDB.remove(uuid);\r
+        return true;\r
+    }\r
+\r
+    public boolean updateRouter(String uuid, NeutronRouter delta) {\r
+        if (!routerExists(uuid))\r
+            return false;\r
+        NeutronRouter target = routerDB.get(uuid);\r
+        return overwrite(target, delta);\r
+    }\r
+\r
+    public boolean routerInUse(String routerUUID) {\r
+        if (!routerExists(routerUUID))\r
+            return true;\r
+        NeutronRouter target = routerDB.get(routerUUID);\r
+        return (target.getInterfaces().size() > 0);\r
+    }\r
+}\r
diff --git a/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronSubnetInterface.java b/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronSubnetInterface.java
new file mode 100644 (file)
index 0000000..0fc3337
--- /dev/null
@@ -0,0 +1,238 @@
+/*\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.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.INeutronSubnetCRUD;\r
+import org.opendaylight.controller.networkconfig.neutron.NeutronCRUDInterfaces;\r
+import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;\r
+import org.opendaylight.controller.networkconfig.neutron.NeutronSubnet;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+public class NeutronSubnetInterface implements INeutronSubnetCRUD {\r
+    private static final Logger logger = LoggerFactory.getLogger(NeutronSubnetInterface.class);\r
+    private String containerName = null;\r
+\r
+    private IClusterContainerServices clusterContainerService = null;\r
+    private ConcurrentMap<String, NeutronSubnet> subnetDB;\r
+\r
+    // methods needed for creating caches\r
+\r
+    void setClusterContainerService(IClusterContainerServices s) {\r
+        logger.debug("Cluster Service set");\r
+        this.clusterContainerService = s;\r
+    }\r
+\r
+    void unsetClusterContainerService(IClusterContainerServices s) {\r
+        if (this.clusterContainerService == s) {\r
+            logger.debug("Cluster Service removed!");\r
+            this.clusterContainerService = null;\r
+        }\r
+    }\r
+\r
+    @SuppressWarnings("deprecation")\r
+    private void allocateCache() {\r
+        if (this.clusterContainerService == null) {\r
+            logger.error("un-initialized clusterContainerService, can't create cache");\r
+            return;\r
+        }\r
+        logger.debug("Creating Cache for Neutron Subnets");\r
+        try {\r
+            // neutron caches\r
+            this.clusterContainerService.createCache("neutronSubnets",\r
+                    EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));\r
+        } catch (CacheConfigException cce) {\r
+            logger.error("Cache couldn't be created for Neutron Subnets -  check cache mode");\r
+        } catch (CacheExistException cce) {\r
+            logger.error("Cache for Neutron Subnets already exists, destroy and recreate");\r
+        }\r
+        logger.debug("Cache successfully created for Neutron Subnets");\r
+    }\r
+\r
+    @SuppressWarnings({ "unchecked", "deprecation" })\r
+    private void retrieveCache() {\r
+        if (this.clusterContainerService == null) {\r
+            logger.error("un-initialized clusterContainerService, can't retrieve cache");\r
+            return;\r
+        }\r
+\r
+        logger.debug("Retrieving cache for Neutron Subnets");\r
+        subnetDB = (ConcurrentMap<String, NeutronSubnet>) this.clusterContainerService\r
+        .getCache("neutronSubnets");\r
+        if (subnetDB == null) {\r
+            logger.error("Cache couldn't be retrieved for Neutron Subnets");\r
+        }\r
+        logger.debug("Cache was successfully retrieved for Neutron Subnets");\r
+    }\r
+\r
+    @SuppressWarnings("deprecation")\r
+    private void destroyCache() {\r
+        if (this.clusterContainerService == null) {\r
+            logger.error("un-initialized clusterMger, can't destroy cache");\r
+            return;\r
+        }\r
+        logger.debug("Destroying Cache for HostTracker");\r
+        this.clusterContainerService.destroyCache("neutronSubnets");\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
+            this.containerName = (String) props.get("containerName");\r
+            logger.debug("Running containerName: {}", this.containerName);\r
+        } else {\r
+            // In the Global instance case the containerName is empty\r
+            this.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
+\r
+    // IfNBSubnetCRUD methods\r
+\r
+    public boolean subnetExists(String uuid) {\r
+        return subnetDB.containsKey(uuid);\r
+    }\r
+\r
+    public NeutronSubnet getSubnet(String uuid) {\r
+        if (!subnetExists(uuid))\r
+            return null;\r
+        return subnetDB.get(uuid);\r
+    }\r
+\r
+    public List<NeutronSubnet> getAllSubnets() {\r
+        Set<NeutronSubnet> allSubnets = new HashSet<NeutronSubnet>();\r
+        for (Entry<String, NeutronSubnet> entry : subnetDB.entrySet()) {\r
+            NeutronSubnet subnet = entry.getValue();\r
+            allSubnets.add(subnet);\r
+        }\r
+        logger.debug("Exiting getAllSubnets, Found {} OpenStackSubnets", allSubnets.size());\r
+        List<NeutronSubnet> ans = new ArrayList<NeutronSubnet>();\r
+        ans.addAll(allSubnets);\r
+        return ans;\r
+    }\r
+\r
+    public boolean addSubnet(NeutronSubnet input) {\r
+        String id = input.getID();\r
+        if (subnetExists(id))\r
+            return false;\r
+        subnetDB.putIfAbsent(id, input);\r
+        INeutronNetworkCRUD networkIf = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);\r
+\r
+        NeutronNetwork targetNet = networkIf.getNetwork(input.getNetworkUUID());\r
+        targetNet.addSubnet(id);\r
+        return true;\r
+    }\r
+\r
+    public boolean removeSubnet(String uuid) {\r
+        if (!subnetExists(uuid))\r
+            return false;\r
+        NeutronSubnet target = subnetDB.get(uuid);\r
+        INeutronNetworkCRUD networkIf = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);\r
+\r
+        NeutronNetwork targetNet = networkIf.getNetwork(target.getNetworkUUID());\r
+        targetNet.removeSubnet(uuid);\r
+        subnetDB.remove(uuid);\r
+        return true;\r
+    }\r
+\r
+    public boolean updateSubnet(String uuid, NeutronSubnet delta) {\r
+        if (!subnetExists(uuid))\r
+            return false;\r
+        NeutronSubnet target = subnetDB.get(uuid);\r
+        return overwrite(target, delta);\r
+    }\r
+\r
+    public boolean subnetInUse(String subnetUUID) {\r
+        if (!subnetExists(subnetUUID))\r
+            return true;\r
+        NeutronSubnet target = subnetDB.get(subnetUUID);\r
+        return (target.getPortsInSubnet().size() > 0);\r
+    }\r
+}\r
diff --git a/pom.xml b/pom.xml
new file mode 100644 (file)
index 0000000..a905ebf
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,71 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
+  <modelVersion>4.0.0</modelVersion>\r
+  <parent>\r
+    <groupId>org.opendaylight.controller</groupId>\r
+    <artifactId>commons.opendaylight</artifactId>\r
+    <version>1.4.0-SNAPSHOT</version>\r
+    <relativePath>../../commons/opendaylight</relativePath>\r
+  </parent>\r
+      <properties>\r
+        <nexusproxy>http://nexus.opendaylight.org/content</nexusproxy>\r
+        <enunciate.version>1.26.2</enunciate.version>\r
+    </properties>\r
+    <distributionManagement>\r
+        <!-- OpenDayLight Released artifact -->\r
+        <repository>\r
+            <id>opendaylight-release</id>\r
+            <url>${nexusproxy}/repositories/opendaylight.release/</url>\r
+        </repository>\r
+        <!-- OpenDayLight Snapshot artifact -->\r
+        <snapshotRepository>\r
+            <id>opendaylight-snapshot</id>\r
+            <url>${nexusproxy}/repositories/opendaylight.snapshot/</url>\r
+        </snapshotRepository>\r
+        <!-- Site deployment -->\r
+        <site>\r
+            <id>website</id>\r
+            <url>${sitedeploy}</url>\r
+        </site>\r
+    </distributionManagement>\r
+  <groupId>org.opendaylight.controller</groupId>\r
+  <artifactId>networkconfig.neutron</artifactId>\r
+  <version>0.4.0-SNAPSHOT</version>\r
+  <packaging>bundle</packaging>\r
+  <build>\r
+        <plugins>\r
+            <plugin>\r
+                <groupId>org.apache.felix</groupId>\r
+                <artifactId>maven-bundle-plugin</artifactId>\r
+                <version>2.3.6</version>\r
+                <extensions>true</extensions>\r
+                <configuration>\r
+                    <instructions>\r
+                        <Import-Package>\r
+                            org.opendaylight.controller.clustering.services,\r
+                            org.opendaylight.controller.sal.core,\r
+                            org.opendaylight.controller.sal.utils,\r
+                            org.apache.felix.dm,\r
+                            org.apache.commons.net.util,\r
+                            org.osgi.service.component,\r
+                            org.slf4j,\r
+                            javax.xml.bind.annotation\r
+                        </Import-Package>\r
+                    </instructions>\r
+                    <manifestLocation>${project.basedir}/src/main/resources/META-INF</manifestLocation>\r
+                </configuration>\r
+            </plugin>\r
+        </plugins>\r
+    </build>\r
+     <dependencies>\r
+        <dependency>\r
+            <groupId>org.opendaylight.controller</groupId>\r
+            <artifactId>clustering.services</artifactId>\r
+            <version>0.4.0-SNAPSHOT</version>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>org.opendaylight.controller</groupId>\r
+            <artifactId>sal</artifactId>\r
+            <version>0.5.0-SNAPSHOT</version>\r
+        </dependency>\r
+    </dependencies>\r
+</project>\r
diff --git a/src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronFloatingIPAware.java b/src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronFloatingIPAware.java
new file mode 100644 (file)
index 0000000..05d50be
--- /dev/null
@@ -0,0 +1,83 @@
+/*\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;\r
+\r
+/**\r
+ * This interface defines the methods a service that wishes to be aware of Neutron FloatingIPs needs to implement\r
+ *\r
+ */\r
+\r
+public interface INeutronFloatingIPAware {\r
+\r
+    /**\r
+     * Services provide this interface method to indicate if the specified floatingIP can be created\r
+     *\r
+     * @param floatingIP\r
+     *            instance of proposed new Neutron FloatingIP object\r
+     * @return integer\r
+     *            the return value is understood to be a HTTP status code.  A return value outside of 200 through 299\r
+     *            results in the create operation being interrupted and the returned status value reflected in the\r
+     *            HTTP response.\r
+     */\r
+    public int canCreateFloatingIP(NeutronFloatingIP floatingIP);\r
+\r
+    /**\r
+     * Services provide this interface method for taking action after a floatingIP has been created\r
+     *\r
+     * @param floatingIP\r
+     *            instance of new Neutron FloatingIP object\r
+     * @return void\r
+     */\r
+    public void neutronFloatingIPCreated(NeutronFloatingIP floatingIP);\r
+\r
+    /**\r
+     * Services provide this interface method to indicate if the specified floatingIP can be changed using the specified\r
+     * delta\r
+     *\r
+     * @param delta\r
+     *            updates to the floatingIP object using patch semantics\r
+     * @param floatingIP\r
+     *            instance of the Neutron FloatingIP object to be updated\r
+     * @return integer\r
+     *            the return value is understood to be a HTTP status code.  A return value outside of 200 through 299\r
+     *            results in the update operation being interrupted and the returned status value reflected in the\r
+     *            HTTP response.\r
+     */\r
+    public int canUpdateFloatingIP(NeutronFloatingIP delta, NeutronFloatingIP original);\r
+\r
+    /**\r
+     * Services provide this interface method for taking action after a floatingIP has been updated\r
+     *\r
+     * @param floatingIP\r
+     *            instance of modified Neutron FloatingIP object\r
+     * @return void\r
+     */\r
+    public void neutronFloatingIPUpdated(NeutronFloatingIP floatingIP);\r
+\r
+    /**\r
+     * Services provide this interface method to indicate if the specified floatingIP can be deleted\r
+     *\r
+     * @param floatingIP\r
+     *            instance of the Neutron FloatingIP object to be deleted\r
+     * @return integer\r
+     *            the return value is understood to be a HTTP status code.  A return value outside of 200 through 299\r
+     *            results in the delete operation being interrupted and the returned status value reflected in the\r
+     *            HTTP response.\r
+     */\r
+    public int canDeleteFloatingIP(NeutronFloatingIP floatingIP);\r
+\r
+    /**\r
+     * Services provide this interface method for taking action after a floatingIP has been deleted\r
+     *\r
+     * @param floatingIP\r
+     *            instance of deleted Neutron FloatingIP object\r
+     * @return void\r
+     */\r
+    public void neutronFloatingIPDeleted(NeutronFloatingIP floatingIP);\r
+}\r
diff --git a/src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronFloatingIPCRUD.java b/src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronFloatingIPCRUD.java
new file mode 100644 (file)
index 0000000..7443dee
--- /dev/null
@@ -0,0 +1,83 @@
+/*\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;\r
+\r
+import java.util.List;\r
+\r
+/**\r
+ * This interface defines the methods for CRUD of NB FloatingIP objects\r
+ *\r
+ */\r
+\r
+public interface INeutronFloatingIPCRUD {\r
+    /**\r
+     * Applications call this interface method to determine if a particular\r
+     * FloatingIP object exists\r
+     *\r
+     * @param uuid\r
+     *            UUID of the FloatingIP object\r
+     * @return boolean\r
+     */\r
+\r
+    public boolean floatingIPExists(String uuid);\r
+\r
+    /**\r
+     * Applications call this interface method to return if a particular\r
+     * FloatingIP object exists\r
+     *\r
+     * @param uuid\r
+     *            UUID of the FloatingIP object\r
+     * @return {@link org.opendaylight.controller.networkconfig.neutron.NeutronFloatingIP.OpenStackFloatingIPs}\r
+     *          OpenStack FloatingIP class\r
+     */\r
+\r
+    public NeutronFloatingIP getFloatingIP(String uuid);\r
+\r
+    /**\r
+     * Applications call this interface method to return all FloatingIP objects\r
+     *\r
+     * @return a Set of OpenStackFloatingIPs objects\r
+     */\r
+\r
+    public List<NeutronFloatingIP> getAllFloatingIPs();\r
+\r
+    /**\r
+     * Applications call this interface method to add a FloatingIP object to the\r
+     * concurrent map\r
+     *\r
+     * @param input\r
+     *            OpenStackFloatingIP object\r
+     * @return boolean on whether the object was added or not\r
+     */\r
+\r
+    public boolean addFloatingIP(NeutronFloatingIP input);\r
+\r
+    /**\r
+     * Applications call this interface method to remove a FloatingIP object to the\r
+     * concurrent map\r
+     *\r
+     * @param uuid\r
+     *            identifier for the FloatingIP object\r
+     * @return boolean on whether the object was removed or not\r
+     */\r
+\r
+    public boolean removeFloatingIP(String uuid);\r
+\r
+    /**\r
+     * Applications call this interface method to edit a FloatingIP object\r
+     *\r
+     * @param uuid\r
+     *            identifier of the FloatingIP object\r
+     * @param delta\r
+     *            OpenStackFloatingIP object containing changes to apply\r
+     * @return boolean on whether the object was updated or not\r
+     */\r
+\r
+    public boolean updateFloatingIP(String uuid, NeutronFloatingIP delta);\r
+}\r
diff --git a/src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronNetworkAware.java b/src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronNetworkAware.java
new file mode 100644 (file)
index 0000000..dc6df25
--- /dev/null
@@ -0,0 +1,83 @@
+/*\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;\r
+\r
+/**\r
+ * This interface defines the methods a service that wishes to be aware of Neutron Networks needs to implement\r
+ *\r
+ */\r
+\r
+public interface INeutronNetworkAware {\r
+\r
+    /**\r
+     * Services provide this interface method to indicate if the specified network can be created\r
+     *\r
+     * @param network\r
+     *            instance of proposed new Neutron Network object\r
+     * @return integer\r
+     *            the return value is understood to be a HTTP status code.  A return value outside of 200 through 299\r
+     *            results in the create operation being interrupted and the returned status value reflected in the\r
+     *            HTTP response.\r
+     */\r
+    public int canCreateNetwork(NeutronNetwork network);\r
+\r
+    /**\r
+     * Services provide this interface method for taking action after a network has been created\r
+     *\r
+     * @param network\r
+     *            instance of new Neutron Network object\r
+     * @return void\r
+     */\r
+    public void neutronNetworkCreated(NeutronNetwork network);\r
+\r
+    /**\r
+     * Services provide this interface method to indicate if the specified network can be changed using the specified\r
+     * delta\r
+     *\r
+     * @param delta\r
+     *            updates to the network object using patch semantics\r
+     * @param network\r
+     *            instance of the Neutron Network object to be updated\r
+     * @return integer\r
+     *            the return value is understood to be a HTTP status code.  A return value outside of 200 through 299\r
+     *            results in the update operation being interrupted and the returned status value reflected in the\r
+     *            HTTP response.\r
+     */\r
+    public int canUpdateNetwork(NeutronNetwork delta, NeutronNetwork original);\r
+\r
+    /**\r
+     * Services provide this interface method for taking action after a network has been updated\r
+     *\r
+     * @param network\r
+     *            instance of modified Neutron Network object\r
+     * @return void\r
+     */\r
+    public void neutronNetworkUpdated(NeutronNetwork network);\r
+\r
+    /**\r
+     * Services provide this interface method to indicate if the specified network can be deleted\r
+     *\r
+     * @param network\r
+     *            instance of the Neutron Network object to be deleted\r
+     * @return integer\r
+     *            the return value is understood to be a HTTP status code.  A return value outside of 200 through 299\r
+     *            results in the delete operation being interrupted and the returned status value reflected in the\r
+     *            HTTP response.\r
+     */\r
+    public int canDeleteNetwork(NeutronNetwork network);\r
+\r
+    /**\r
+     * Services provide this interface method for taking action after a network has been deleted\r
+     *\r
+     * @param network\r
+     *            instance of deleted Neutron Network object\r
+     * @return void\r
+     */\r
+    public void neutronNetworkDeleted(NeutronNetwork network);\r
+}\r
diff --git a/src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronNetworkCRUD.java b/src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronNetworkCRUD.java
new file mode 100644 (file)
index 0000000..2481531
--- /dev/null
@@ -0,0 +1,95 @@
+/*\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;\r
+\r
+import java.util.List;\r
+\r
+/**\r
+ * This interface defines the methods for CRUD of NB network objects\r
+ *\r
+ */\r
+\r
+public interface INeutronNetworkCRUD {\r
+    /**\r
+     * Applications call this interface method to determine if a particular\r
+     * Network object exists\r
+     *\r
+     * @param uuid\r
+     *            UUID of the Network object\r
+     * @return boolean\r
+     */\r
+\r
+    public boolean networkExists(String uuid);\r
+\r
+    /**\r
+     * Applications call this interface method to return if a particular\r
+     * Network object exists\r
+     *\r
+     * @param uuid\r
+     *            UUID of the Network object\r
+     * @return {@link org.opendaylight.controller.networkconfig.neutron.NeutronNetwork.OpenStackNetworks}\r
+     *          OpenStack Network class\r
+     */\r
+\r
+    public NeutronNetwork getNetwork(String uuid);\r
+\r
+    /**\r
+     * Applications call this interface method to return all Network objects\r
+     *\r
+     * @return List of OpenStackNetworks objects\r
+     */\r
+\r
+    public List<NeutronNetwork> getAllNetworks();\r
+\r
+    /**\r
+     * Applications call this interface method to add a Network object to the\r
+     * concurrent map\r
+     *\r
+     * @param input\r
+     *            OpenStackNetwork object\r
+     * @return boolean on whether the object was added or not\r
+     */\r
+\r
+    public boolean addNetwork(NeutronNetwork input);\r
+\r
+    /**\r
+     * Applications call this interface method to remove a Network object to the\r
+     * concurrent map\r
+     *\r
+     * @param uuid\r
+     *            identifier for the network object\r
+     * @return boolean on whether the object was removed or not\r
+     */\r
+\r
+    public boolean removeNetwork(String uuid);\r
+\r
+    /**\r
+     * Applications call this interface method to edit a Network object\r
+     *\r
+     * @param uuid\r
+     *            identifier of the network object\r
+     * @param delta\r
+     *            OpenStackNetwork object containing changes to apply\r
+     * @return boolean on whether the object was updated or not\r
+     */\r
+\r
+    public boolean updateNetwork(String uuid, NeutronNetwork delta);\r
+\r
+    /**\r
+     * Applications call this interface method to determine if a Network object\r
+     * is use\r
+     *\r
+     * @param netUUID\r
+     *            identifier of the network object\r
+     *\r
+     * @return boolean on whether the network is in use or not\r
+     */\r
+\r
+    public boolean networkInUse(String netUUID);\r
+}\r
diff --git a/src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronPortAware.java b/src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronPortAware.java
new file mode 100644 (file)
index 0000000..36ed4ff
--- /dev/null
@@ -0,0 +1,83 @@
+/*\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;\r
+\r
+/**\r
+ * This interface defines the methods a service that wishes to be aware of Neutron Ports needs to implement\r
+ *\r
+ */\r
+\r
+public interface INeutronPortAware {\r
+\r
+    /**\r
+     * Services provide this interface method to indicate if the specified port can be created\r
+     *\r
+     * @param port\r
+     *            instance of proposed new Neutron Port object\r
+     * @return integer\r
+     *            the return value is understood to be a HTTP status code.  A return value outside of 200 through 299\r
+     *            results in the create operation being interrupted and the returned status value reflected in the\r
+     *            HTTP response.\r
+     */\r
+    public int canCreatePort(NeutronPort port);\r
+\r
+    /**\r
+     * Services provide this interface method for taking action after a port has been created\r
+     *\r
+     * @param port\r
+     *            instance of new Neutron Port object\r
+     * @return void\r
+     */\r
+    public void neutronPortCreated(NeutronPort port);\r
+\r
+    /**\r
+     * Services provide this interface method to indicate if the specified port can be changed using the specified\r
+     * delta\r
+     *\r
+     * @param delta\r
+     *            updates to the port object using patch semantics\r
+     * @param port\r
+     *            instance of the Neutron Port object to be updated\r
+     * @return integer\r
+     *            the return value is understood to be a HTTP status code.  A return value outside of 200 through 299\r
+     *            results in the update operation being interrupted and the returned status value reflected in the\r
+     *            HTTP response.\r
+     */\r
+    public int canUpdatePort(NeutronPort delta, NeutronPort original);\r
+\r
+    /**\r
+     * Services provide this interface method for taking action after a port has been updated\r
+     *\r
+     * @param port\r
+     *            instance of modified Neutron Port object\r
+     * @return void\r
+     */\r
+    public void neutronPortUpdated(NeutronPort port);\r
+\r
+    /**\r
+     * Services provide this interface method to indicate if the specified port can be deleted\r
+     *\r
+     * @param port\r
+     *            instance of the Neutron Port object to be deleted\r
+     * @return integer\r
+     *            the return value is understood to be a HTTP status code.  A return value outside of 200 through 299\r
+     *            results in the delete operation being interrupted and the returned status value reflected in the\r
+     *            HTTP response.\r
+     */\r
+    public int canDeletePort(NeutronPort port);\r
+\r
+    /**\r
+     * Services provide this interface method for taking action after a port has been deleted\r
+     *\r
+     * @param port\r
+     *            instance of deleted Port Network object\r
+     * @return void\r
+     */\r
+    public void neutronPortDeleted(NeutronPort port);\r
+}\r
diff --git a/src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronPortCRUD.java b/src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronPortCRUD.java
new file mode 100644 (file)
index 0000000..681e925
--- /dev/null
@@ -0,0 +1,105 @@
+/*\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;\r
+\r
+import java.util.List;\r
+\r
+/**\r
+ * This interface defines the methods for CRUD of NB Port objects\r
+ *\r
+ */\r
+\r
+public interface INeutronPortCRUD {\r
+    /**\r
+     * Applications call this interface method to determine if a particular\r
+     * Port object exists\r
+     *\r
+     * @param uuid\r
+     *            UUID of the Port object\r
+     * @return boolean\r
+     */\r
+\r
+    public boolean portExists(String uuid);\r
+\r
+    /**\r
+     * Applications call this interface method to return if a particular\r
+     * Port object exists\r
+     *\r
+     * @param uuid\r
+     *            UUID of the Port object\r
+     * @return {@link org.opendaylight.controller.networkconfig.neutron.NeutronPort.OpenStackPorts}\r
+     *          OpenStack Port class\r
+     */\r
+\r
+    public NeutronPort getPort(String uuid);\r
+\r
+    /**\r
+     * Applications call this interface method to return all Port objects\r
+     *\r
+     * @return List of OpenStackPorts objects\r
+     */\r
+\r
+    public List<NeutronPort> getAllPorts();\r
+\r
+    /**\r
+     * Applications call this interface method to add a Port object to the\r
+     * concurrent map\r
+     *\r
+     * @param input\r
+     *            OpenStackPort object\r
+     * @return boolean on whether the object was added or not\r
+     */\r
+\r
+    public boolean addPort(NeutronPort input);\r
+\r
+    /**\r
+     * Applications call this interface method to remove a Port object to the\r
+     * concurrent map\r
+     *\r
+     * @param uuid\r
+     *            identifier for the Port object\r
+     * @return boolean on whether the object was removed or not\r
+     */\r
+\r
+    public boolean removePort(String uuid);\r
+\r
+    /**\r
+     * Applications call this interface method to edit a Port object\r
+     *\r
+     * @param uuid\r
+     *            identifier of the Port object\r
+     * @param delta\r
+     *            OpenStackPort object containing changes to apply\r
+     * @return boolean on whether the object was updated or not\r
+     */\r
+\r
+    public boolean updatePort(String uuid, NeutronPort delta);\r
+\r
+    /**\r
+     * Applications call this interface method to see if a MAC address is in use\r
+     *\r
+     * @param macAddress\r
+     *            mac Address to be tested\r
+     * @return boolean on whether the macAddress is already associated with a\r
+     * port or not\r
+     */\r
+\r
+    public boolean macInUse(String macAddress);\r
+\r
+    /**\r
+     * Applications call this interface method to retrieve the port associated with\r
+     * the gateway address of a subnet\r
+     *\r
+     * @param subnetUUID\r
+     *            identifier of the subnet\r
+     * @return OpenStackPorts object if the port exists and null if it does not\r
+     */\r
+\r
+    public NeutronPort getGatewayPort(String subnetUUID);\r
+}\r
diff --git a/src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronRouterAware.java b/src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronRouterAware.java
new file mode 100644 (file)
index 0000000..16a9aec
--- /dev/null
@@ -0,0 +1,105 @@
+/*\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;\r
+\r
+/**\r
+ * This interface defines the methods a service that wishes to be aware of Neutron Routers needs to implement\r
+ *\r
+ */\r
+\r
+public interface INeutronRouterAware {\r
+\r
+    /**\r
+     * Services provide this interface method to indicate if the specified router can be created\r
+     *\r
+     * @param router\r
+     *            instance of proposed new Neutron Router object\r
+     * @return integer\r
+     *            the return value is understood to be a HTTP status code.  A return value outside of 200 through 299\r
+     *            results in the create operation being interrupted and the returned status value reflected in the\r
+     *            HTTP response.\r
+     */\r
+    public int canCreateRouter(NeutronRouter router);\r
+\r
+    /**\r
+     * Services provide this interface method for taking action after a router has been created\r
+     *\r
+     * @param router\r
+     *            instance of new Neutron Router object\r
+     * @return void\r
+     */\r
+    public void neutronRouterCreated(NeutronRouter router);\r
+\r
+    /**\r
+     * Services provide this interface method to indicate if the specified router can be changed using the specified\r
+     * delta\r
+     *\r
+     * @param delta\r
+     *            updates to the router object using patch semantics\r
+     * @param router\r
+     *            instance of the Neutron Router object to be updated\r
+     * @return integer\r
+     *            the return value is understood to be a HTTP status code.  A return value outside of 200 through 299\r
+     *            results in the update operation being interrupted and the returned status value reflected in the\r
+     *            HTTP response.\r
+     */\r
+    public int canUpdateRouter(NeutronRouter delta, NeutronRouter original);\r
+\r
+    /**\r
+     * Services provide this interface method for taking action after a router has been updated\r
+     *\r
+     * @param router\r
+     *            instance of modified Neutron Router object\r
+     * @return void\r
+     */\r
+    public void neutronRouterUpdated(NeutronRouter router);\r
+\r
+    /**\r
+     * Services provide this interface method to indicate if the specified router can be deleted\r
+     *\r
+     * @param router\r
+     *            instance of the Neutron Router object to be deleted\r
+     * @return integer\r
+     *            the return value is understood to be a HTTP status code.  A return value outside of 200 through 299\r
+     *            results in the delete operation being interrupted and the returned status value reflected in the\r
+     *            HTTP response.\r
+     */\r
+    public int canDeleteRouter(NeutronRouter router);\r
+\r
+    /**\r
+     * Services provide this interface method for taking action after a router has been deleted\r
+     *\r
+     * @param router\r
+     *            instance of deleted Router Network object\r
+     * @return void\r
+     */\r
+    public void neutronRouterDeleted(NeutronRouter router);\r
+\r
+    /**\r
+     * Services provide this interface method for taking action after an interface has been added to a router\r
+     *\r
+     * @param router\r
+     *            instance of the base Neutron Router object\r
+     * @param routerInterface\r
+     *            instance of the NeutronRouter_Interface being attached to the router\r
+     * @return void\r
+     */\r
+    public void neutronRouterInterfaceAttached(NeutronRouter router, NeutronRouter_Interface routerInterface);\r
+\r
+    /**\r
+     * Services provide this interface method for taking action after an interface has been removed from a router\r
+     *\r
+     * @param router\r
+     *            instance of the base Neutron Router object\r
+     * @param routerInterface\r
+     *            instance of the NeutronRouter_Interface being detached from the router\r
+     * @return void\r
+     */\r
+    public void neutronRouterInterfaceDetached(NeutronRouter router, NeutronRouter_Interface routerInterface);\r
+}\r
diff --git a/src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronRouterCRUD.java b/src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronRouterCRUD.java
new file mode 100644 (file)
index 0000000..19be16d
--- /dev/null
@@ -0,0 +1,93 @@
+/*\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;\r
+\r
+import java.util.List;\r
+\r
+/**\r
+ * This interface defines the methods for CRUD of NB Router objects\r
+ *\r
+ */\r
+\r
+public interface INeutronRouterCRUD {\r
+    /**\r
+     * Applications call this interface method to determine if a particular\r
+     * Router object exists\r
+     *\r
+     * @param uuid\r
+     *            UUID of the Router object\r
+     * @return boolean\r
+     */\r
+\r
+    public boolean routerExists(String uuid);\r
+\r
+    /**\r
+     * Applications call this interface method to return if a particular\r
+     * Router object exists\r
+     *\r
+     * @param uuid\r
+     *            UUID of the Router object\r
+     * @return {@link org.opendaylight.controller.networkconfig.neutron.NeutronRouter.OpenStackRouters}\r
+     *          OpenStack Router class\r
+     */\r
+\r
+    public NeutronRouter getRouter(String uuid);\r
+\r
+    /**\r
+     * Applications call this interface method to return all Router objects\r
+     *\r
+     * @return List of OpenStackRouters objects\r
+     */\r
+\r
+    public List<NeutronRouter> getAllRouters();\r
+\r
+    /**\r
+     * Applications call this interface method to add a Router object to the\r
+     * concurrent map\r
+     *\r
+     * @param input\r
+     *            OpenStackRouter object\r
+     * @return boolean on whether the object was added or not\r
+     */\r
+\r
+    public boolean addRouter(NeutronRouter input);\r
+\r
+    /**\r
+     * Applications call this interface method to remove a Router object to the\r
+     * concurrent map\r
+     *\r
+     * @param uuid\r
+     *            identifier for the Router object\r
+     * @return boolean on whether the object was removed or not\r
+     */\r
+\r
+    public boolean removeRouter(String uuid);\r
+\r
+    /**\r
+     * Applications call this interface method to edit a Router object\r
+     *\r
+     * @param uuid\r
+     *            identifier of the Router object\r
+     * @param delta\r
+     *            OpenStackRouter object containing changes to apply\r
+     * @return boolean on whether the object was updated or not\r
+     */\r
+\r
+    public boolean updateRouter(String uuid, NeutronRouter delta);\r
+\r
+    /**\r
+     * Applications call this interface method to check if a router is in use\r
+     *\r
+     * @param uuid\r
+     *            identifier of the Router object\r
+     * @return boolean on whether the router is in use or not\r
+     */\r
+\r
+    public boolean routerInUse(String routerUUID);\r
+}\r
diff --git a/src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronSubnetAware.java b/src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronSubnetAware.java
new file mode 100644 (file)
index 0000000..b7bafab
--- /dev/null
@@ -0,0 +1,84 @@
+/*\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;\r
+\r
+/**\r
+ * This interface defines the methods a service that wishes to be aware of Neutron Subnets needs to implement\r
+ *\r
+ */\r
+\r
+public interface INeutronSubnetAware {\r
+\r
+    /**\r
+     * Services provide this interface method to indicate if the specified subnet can be created\r
+     *\r
+     * @param subnet\r
+     *            instance of proposed new Neutron Subnet object\r
+     * @return integer\r
+     *            the return value is understood to be a HTTP status code.  A return value outside of 200 through 299\r
+     *            results in the create operation being interrupted and the returned status value reflected in the\r
+     *            HTTP response.\r
+     */\r
+    public int canCreateSubnet(NeutronSubnet subnet);\r
+\r
+    /**\r
+     * Services provide this interface method for taking action after a subnet has been created\r
+     *\r
+     * @param subnet\r
+     *            instance of new Neutron Subnet object\r
+     * @return void\r
+     */\r
+    public void neutronSubnetCreated(NeutronSubnet subnet);\r
+\r
+    /**\r
+     * Services provide this interface method to indicate if the specified subnet can be changed using the specified\r
+     * delta\r
+     *\r
+     * @param delta\r
+     *            updates to the subnet object using patch semantics\r
+     * @param subnet\r
+     *            instance of the Neutron Subnet object to be updated\r
+     * @return integer\r
+     *            the return value is understood to be a HTTP status code.  A return value outside of 200 through 299\r
+     *            results in the update operation being interrupted and the returned status value reflected in the\r
+     *            HTTP response.\r
+     */\r
+    public int canUpdateSubnet(NeutronSubnet delta, NeutronSubnet original);\r
+\r
+    /**\r
+     * Services provide this interface method for taking action after a subnet has been updated\r
+     *\r
+     * @param subnet\r
+     *            instance of modified Neutron Subnet object\r
+     * @return void\r
+     */\r
+    public void neutronSubnetUpdated(NeutronSubnet subnet);\r
+\r
+    /**\r
+     * Services provide this interface method to indicate if the specified subnet can be deleted\r
+     *\r
+     * @param subnet\r
+     *            instance of the Subnet Router object to be deleted\r
+     * @return integer\r
+     *            the return value is understood to be a HTTP status code.  A return value outside of 200 through 299\r
+     *            results in the delete operation being interrupted and the returned status value reflected in the\r
+     *            HTTP response.\r
+     */\r
+    public int canDeleteSubnet(NeutronSubnet subnet);\r
+\r
+    /**\r
+     * Services provide this interface method for taking action after a subnet has been deleted\r
+     *\r
+     * @param subnet\r
+     *            instance of deleted Router Subnet object\r
+     * @return void\r
+     */\r
+    public void neutronSubnetDeleted(NeutronSubnet subnet);\r
+\r
+}\r
diff --git a/src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronSubnetCRUD.java b/src/main/java/org/opendaylight/controller/networkconfig/neutron/INeutronSubnetCRUD.java
new file mode 100644 (file)
index 0000000..9c39046
--- /dev/null
@@ -0,0 +1,95 @@
+/*\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;\r
+\r
+import java.util.List;\r
+\r
+/**\r
+ * This interface defines the methods for CRUD of NB Subnet objects\r
+ *\r
+ */\r
+\r
+public interface INeutronSubnetCRUD {\r
+    /**\r
+     * Applications call this interface method to determine if a particular\r
+     * Subnet object exists\r
+     *\r
+     * @param uuid\r
+     *            UUID of the Subnet object\r
+     * @return boolean\r
+     */\r
+\r
+    public boolean subnetExists(String uuid);\r
+\r
+    /**\r
+     * Applications call this interface method to return if a particular\r
+     * Subnet object exists\r
+     *\r
+     * @param uuid\r
+     *            UUID of the Subnet object\r
+     * @return {@link org.opendaylight.controller.networkconfig.neutron.NeutronSubnet.OpenStackSubnets}\r
+     *          OpenStack Subnet class\r
+     */\r
+\r
+    public NeutronSubnet getSubnet(String uuid);\r
+\r
+    /**\r
+     * Applications call this interface method to return all Subnet objects\r
+     *\r
+     * @return List of OpenStackSubnets objects\r
+     */\r
+\r
+    public List<NeutronSubnet> getAllSubnets();\r
+\r
+    /**\r
+     * Applications call this interface method to add a Subnet object to the\r
+     * concurrent map\r
+     *\r
+     * @param input\r
+     *            OpenStackSubnet object\r
+     * @return boolean on whether the object was added or not\r
+     */\r
+\r
+    public boolean addSubnet(NeutronSubnet input);\r
+\r
+    /**\r
+     * Applications call this interface method to remove a Subnet object to the\r
+     * concurrent map\r
+     *\r
+     * @param uuid\r
+     *            identifier for the Subnet object\r
+     * @return boolean on whether the object was removed or not\r
+     */\r
+\r
+    public boolean removeSubnet(String uuid);\r
+\r
+    /**\r
+     * Applications call this interface method to edit a Subnet object\r
+     *\r
+     * @param uuid\r
+     *            identifier of the Subnet object\r
+     * @param delta\r
+     *            OpenStackSubnet object containing changes to apply\r
+     * @return boolean on whether the object was updated or not\r
+     */\r
+\r
+    public boolean updateSubnet(String uuid, NeutronSubnet delta);\r
+\r
+    /**\r
+     * Applications call this interface method to determine if a Subnet object\r
+     * is use\r
+     *\r
+     * @param subnetUUID\r
+     *            identifier of the subnet object\r
+     *\r
+     * @return boolean on whether the subnet is in use or not\r
+     */\r
+\r
+    public boolean subnetInUse(String subnetUUID);\r
+}\r
diff --git a/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronCRUDInterfaces.java b/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronCRUDInterfaces.java
new file mode 100644 (file)
index 0000000..0becb47
--- /dev/null
@@ -0,0 +1,39 @@
+/*\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;\r
+\r
+import org.opendaylight.controller.sal.utils.ServiceHelper;\r
+\r
+public class NeutronCRUDInterfaces {\r
+\r
+    public static INeutronNetworkCRUD getINeutronNetworkCRUD(Object o) {\r
+        INeutronNetworkCRUD answer = (INeutronNetworkCRUD) ServiceHelper.getGlobalInstance(INeutronNetworkCRUD.class, o);\r
+        return answer;\r
+    }\r
+\r
+    public static INeutronSubnetCRUD getINeutronSubnetCRUD(Object o) {\r
+        INeutronSubnetCRUD answer = (INeutronSubnetCRUD) ServiceHelper.getGlobalInstance(INeutronSubnetCRUD.class, o);\r
+        return answer;\r
+    }\r
+\r
+    public static INeutronPortCRUD getINeutronPortCRUD(Object o) {\r
+        INeutronPortCRUD answer = (INeutronPortCRUD) ServiceHelper.getGlobalInstance(INeutronPortCRUD.class, o);\r
+        return answer;\r
+    }\r
+\r
+    public static INeutronRouterCRUD getINeutronRouterCRUD(Object o) {\r
+        INeutronRouterCRUD answer = (INeutronRouterCRUD) ServiceHelper.getGlobalInstance(INeutronRouterCRUD.class, o);\r
+        return answer;\r
+    }\r
+\r
+    public static INeutronFloatingIPCRUD getINeutronFloatingIPCRUD(Object o) {\r
+        INeutronFloatingIPCRUD answer = (INeutronFloatingIPCRUD) ServiceHelper.getGlobalInstance(INeutronFloatingIPCRUD.class, o);\r
+        return answer;\r
+    }\r
+}\r
diff --git a/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronFloatingIP.java b/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronFloatingIP.java
new file mode 100644 (file)
index 0000000..906b4d4
--- /dev/null
@@ -0,0 +1,130 @@
+/*\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;\r
+\r
+import java.util.Iterator;\r
+import java.util.List;\r
+\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+import javax.xml.bind.annotation.XmlElement;\r
+import javax.xml.bind.annotation.XmlRootElement;\r
+\r
+@XmlRootElement\r
+@XmlAccessorType(XmlAccessType.NONE)\r
+\r
+public class NeutronFloatingIP {\r
+    // See OpenStack Network API v2.0 Reference for description of\r
+    // annotated attributes\r
+\r
+    @XmlElement (name="id")\r
+    String floatingIPUUID;\r
+\r
+    @XmlElement (name="floating_network_id")\r
+    String floatingNetworkUUID;\r
+\r
+    @XmlElement (name="port_id")\r
+    String portUUID;\r
+\r
+    @XmlElement (name="fixed_ip_address")\r
+    String fixedIPAddress;\r
+\r
+    @XmlElement (name="floating_ip_address")\r
+    String floatingIPAddress;\r
+\r
+    @XmlElement (name="tenant_id")\r
+    String tenantUUID;\r
+\r
+    public NeutronFloatingIP() {\r
+    }\r
+\r
+    public String getID() { return floatingIPUUID; }\r
+\r
+    public String getFloatingIPUUID() {\r
+        return floatingIPUUID;\r
+    }\r
+\r
+    public void setFloatingIPUUID(String floatingIPUUID) {\r
+        this.floatingIPUUID = floatingIPUUID;\r
+    }\r
+\r
+    public String getFloatingNetworkUUID() {\r
+        return floatingNetworkUUID;\r
+    }\r
+\r
+    public void setFloatingNetworkUUID(String floatingNetworkUUID) {\r
+        this.floatingNetworkUUID = floatingNetworkUUID;\r
+    }\r
+\r
+    public String getPortUUID() {\r
+        return portUUID;\r
+    }\r
+\r
+    public void setPortUUID(String portUUID) {\r
+        this.portUUID = portUUID;\r
+    }\r
+\r
+    public String getFixedIPAddress() {\r
+        return fixedIPAddress;\r
+    }\r
+\r
+    public void setFixedIPAddress(String fixedIPAddress) {\r
+        this.fixedIPAddress = fixedIPAddress;\r
+    }\r
+\r
+    public String getFloatingIPAddress() {\r
+        return floatingIPAddress;\r
+    }\r
+\r
+    public void setFloatingIPAddress(String floatingIPAddress) {\r
+        this.floatingIPAddress = floatingIPAddress;\r
+    }\r
+\r
+    public String getTenantUUID() {\r
+        return tenantUUID;\r
+    }\r
+\r
+    public void setTenantUUID(String tenantUUID) {\r
+        this.tenantUUID = tenantUUID;\r
+    }\r
+\r
+    /**\r
+     * This method copies selected fields from the object and returns them\r
+     * as a new object, suitable for marshaling.\r
+     *\r
+     * @param fields\r
+     *            List of attributes to be extracted\r
+     * @return an OpenStackFloatingIPs object with only the selected fields\r
+     * populated\r
+     */\r
+\r
+    public NeutronFloatingIP extractFields(List<String> fields) {\r
+        NeutronFloatingIP ans = new NeutronFloatingIP();\r
+        Iterator<String> i = fields.iterator();\r
+        while (i.hasNext()) {\r
+            String s = i.next();\r
+            if (s.equals("id"))\r
+                ans.setFloatingIPUUID(this.getFloatingIPUUID());\r
+            if (s.equals("floating_network_id"))\r
+                ans.setFloatingNetworkUUID(this.getFloatingNetworkUUID());\r
+            if (s.equals("port_id"))\r
+                ans.setPortUUID(this.getPortUUID());\r
+            if (s.equals("fixed_ip_address"))\r
+                ans.setFixedIPAddress(this.getFixedIPAddress());\r
+            if (s.equals("floating_ip_address"))\r
+                ans.setFloatingIPAddress(this.getFloatingIPAddress());\r
+            if (s.equals("tenant_id"))\r
+                ans.setTenantUUID(this.getTenantUUID());\r
+        }\r
+        return ans;\r
+    }\r
+\r
+    public void initDefaults() {\r
+    }\r
+}\r
diff --git a/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronNetwork.java b/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronNetwork.java
new file mode 100644 (file)
index 0000000..eccbbcc
--- /dev/null
@@ -0,0 +1,233 @@
+/*\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;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+import javax.xml.bind.annotation.XmlElement;\r
+import javax.xml.bind.annotation.XmlRootElement;\r
+\r
+@XmlRootElement(name = "network")\r
+@XmlAccessorType(XmlAccessType.NONE)\r
+\r
+public class NeutronNetwork {\r
+    // See OpenStack Network API v2.0 Reference for description of\r
+    // annotated attributes\r
+\r
+    @XmlElement (name="id")\r
+    String networkUUID;              // network UUID\r
+\r
+    @XmlElement (name="name")\r
+    String networkName;              // name\r
+\r
+    @XmlElement (defaultValue="true", name="admin_state_up")\r
+    Boolean adminStateUp;             // admin state up (true/false)\r
+\r
+    @XmlElement (defaultValue="false", name="shared")\r
+    Boolean shared;                   // shared network or not\r
+\r
+    @XmlElement (name="tenant_id")\r
+    String tenantID;                 // tenant for this network\r
+\r
+    @XmlElement (defaultValue="false", namespace="router", name="external")\r
+    Boolean routerExternal;           // network external or not\r
+\r
+    @XmlElement (defaultValue="flat", namespace="provider", name="network_type")\r
+    String providerNetworkType;      // provider network type (flat or vlan)\r
+\r
+    @XmlElement (namespace="provider", name="physical_network")\r
+    String providerPhysicalNetwork;  // provider physical network (name)\r
+\r
+    @XmlElement (namespace="provider", name="segmentation_id")\r
+    String providerSegmentationID;   // provide segmentation ID (vlan ID)\r
+\r
+    @XmlElement (name="status")\r
+    String status;                   // status (read-only)\r
+\r
+    @XmlElement (name="subnets")\r
+    List<String> subnets;            // subnets (read-only)\r
+\r
+    /* This attribute lists the ports associated with an instance\r
+     * which is needed for determining if that instance can be deleted\r
+     */\r
+\r
+    List<NeutronPort> myPorts;\r
+\r
+    public NeutronNetwork() {\r
+        myPorts = new ArrayList<NeutronPort>();\r
+    }\r
+\r
+    public void initDefaults() {\r
+        subnets = new ArrayList<String>();\r
+        if (this.status == null)\r
+            this.status = "ACTIVE";\r
+        if (this.adminStateUp == null)\r
+            this.adminStateUp = true;\r
+        if (this.shared == null)\r
+            this.shared = false;\r
+        if (this.routerExternal == null)\r
+            this.routerExternal = false;\r
+        if (this.providerNetworkType == null)\r
+            this.providerNetworkType = "flat";\r
+    }\r
+\r
+    public String getID() { return networkUUID; }\r
+\r
+    public String getNetworkUUID() {\r
+        return networkUUID;\r
+    }\r
+\r
+    public void setNetworkUUID(String networkUUID) {\r
+        this.networkUUID = networkUUID;\r
+    }\r
+\r
+    public String getNetworkName() {\r
+        return networkName;\r
+    }\r
+\r
+    public void setNetworkName(String networkName) {\r
+        this.networkName = networkName;\r
+    }\r
+\r
+    public boolean isAdminStateUp() {\r
+        return adminStateUp;\r
+    }\r
+\r
+    public Boolean getAdminStateUp() { return adminStateUp; }\r
+\r
+    public void setAdminStateUp(boolean newValue) {\r
+        this.adminStateUp = newValue;\r
+    }\r
+\r
+    public boolean isShared() { return shared; }\r
+\r
+    public Boolean getShared() { return shared; }\r
+\r
+    public void setShared(boolean newValue) {\r
+        this.shared = newValue;\r
+    }\r
+\r
+    public String getTenantID() {\r
+        return tenantID;\r
+    }\r
+\r
+    public void setTenantID(String tenantID) {\r
+        this.tenantID = tenantID;\r
+    }\r
+\r
+    public boolean isRouterExternal() { return routerExternal; }\r
+\r
+    public Boolean getRouterExternal() { return routerExternal; }\r
+\r
+    public void setRouterExternal(boolean newValue) {\r
+        this.routerExternal = newValue;\r
+    }\r
+\r
+    public String getProviderNetworkType() {\r
+        return providerNetworkType;\r
+    }\r
+\r
+    public void setProviderNetworkType(String providerNetworkType) {\r
+        this.providerNetworkType = providerNetworkType;\r
+    }\r
+\r
+    public String getProviderPhysicalNetwork() {\r
+        return providerPhysicalNetwork;\r
+    }\r
+\r
+    public void setProviderPhysicalNetwork(String providerPhysicalNetwork) {\r
+        this.providerPhysicalNetwork = providerPhysicalNetwork;\r
+    }\r
+\r
+    public String getProviderSegmentationID() {\r
+        return providerSegmentationID;\r
+    }\r
+\r
+    public void setProviderSegmentationID(String providerSegmentationID) {\r
+        this.providerSegmentationID = providerSegmentationID;\r
+    }\r
+\r
+    public String getStatus() {\r
+        return status;\r
+    }\r
+\r
+    public void setStatus(String status) {\r
+        this.status = status;\r
+    }\r
+\r
+    public List<String> getSubnets() {\r
+        return subnets;\r
+    }\r
+\r
+    public void setSubnets(List<String> subnets) {\r
+        this.subnets = subnets;\r
+    }\r
+\r
+    public void addSubnet(String uuid) {\r
+        this.subnets.add(uuid);\r
+    }\r
+\r
+    public void removeSubnet(String uuid) {\r
+        this.subnets.remove(uuid);\r
+    }\r
+\r
+    public List<NeutronPort> getPortsOnNetwork() {\r
+        return myPorts;\r
+    }\r
+\r
+    public void addPort(NeutronPort port) {\r
+        myPorts.add(port);\r
+    }\r
+\r
+    public void removePort(NeutronPort port) {\r
+        myPorts.remove(port);\r
+    }\r
+\r
+    /**\r
+     * This method copies selected fields from the object and returns them\r
+     * as a new object, suitable for marshaling.\r
+     *\r
+     * @param fields\r
+     *            List of attributes to be extracted\r
+     * @return an OpenStackNetworks object with only the selected fields\r
+     * populated\r
+     */\r
+\r
+    public NeutronNetwork extractFields(List<String> fields) {\r
+        NeutronNetwork ans = new NeutronNetwork();\r
+        Iterator<String> i = fields.iterator();\r
+        while (i.hasNext()) {\r
+            String s = i.next();\r
+            if (s.equals("id"))\r
+                ans.setNetworkUUID(this.getNetworkUUID());\r
+            if (s.equals("name"))\r
+                ans.setNetworkName(this.getNetworkName());\r
+            if (s.equals("admin_state_up"))\r
+                ans.setAdminStateUp(this.adminStateUp);\r
+            if (s.equals("status"))\r
+                ans.setStatus(this.getStatus());\r
+            if (s.equals("subnets")) {\r
+                List<String> subnetList = new ArrayList<String>();\r
+                subnetList.addAll(this.getSubnets());\r
+                ans.setSubnets(subnetList);\r
+            }\r
+            if (s.equals("shared"))\r
+                ans.setShared(this.shared);\r
+            if (s.equals("tenant_id"))\r
+                ans.setTenantID(this.getTenantID());\r
+        }\r
+        return ans;\r
+    }\r
+\r
+}\r
+\r
diff --git a/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronPort.java b/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronPort.java
new file mode 100644 (file)
index 0000000..7f7f712
--- /dev/null
@@ -0,0 +1,239 @@
+/*\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;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+import javax.xml.bind.annotation.XmlElement;\r
+import javax.xml.bind.annotation.XmlRootElement;\r
+\r
+\r
+@XmlRootElement\r
+@XmlAccessorType(XmlAccessType.NONE)\r
+\r
+public class NeutronPort {\r
+    // See OpenStack Network API v2.0 Reference for description of\r
+    // annotated attributes\r
+\r
+    @XmlElement (name="id")\r
+    String portUUID;\r
+\r
+    @XmlElement (name="network_id")\r
+    String networkUUID;\r
+\r
+    @XmlElement (name="name")\r
+    String name;\r
+\r
+    @XmlElement (defaultValue="true", name="admin_state_up")\r
+    Boolean adminStateUp;\r
+\r
+    @XmlElement (name="status")\r
+    String status;\r
+\r
+    @XmlElement (name="mac_address")\r
+    String macAddress;\r
+\r
+    @XmlElement (name="fixed_ips")\r
+    List<Neutron_IPs> fixedIPs;\r
+\r
+    @XmlElement (name="device_id")\r
+    String deviceID;\r
+\r
+    @XmlElement (name="device_owner")\r
+    String deviceOwner;\r
+\r
+    @XmlElement (name="tenant_id")\r
+    String tenantID;\r
+\r
+    // TODO: add security groups\r
+    //        @XmlElement (name="security_groups")\r
+    //        List<String> securityGroups;\r
+\r
+    /* this attribute stores the floating IP address assigned to\r
+     * each fixed IP address\r
+     */\r
+\r
+    HashMap<String, NeutronFloatingIP> floatingIPMap;\r
+\r
+    public NeutronPort() {\r
+        floatingIPMap = new HashMap<String, NeutronFloatingIP>();\r
+    }\r
+\r
+    public String getID() { return portUUID; }\r
+\r
+    public String getPortUUID() {\r
+        return portUUID;\r
+    }\r
+\r
+    public void setPortUUID(String portUUID) {\r
+        this.portUUID = portUUID;\r
+    }\r
+\r
+    public String getNetworkUUID() {\r
+        return networkUUID;\r
+    }\r
+\r
+    public void setNetworkUUID(String networkUUID) {\r
+        this.networkUUID = networkUUID;\r
+    }\r
+\r
+    public String getName() {\r
+        return name;\r
+    }\r
+\r
+    public void setName(String name) {\r
+        this.name = name;\r
+    }\r
+\r
+    public boolean isAdminStateUp() {\r
+        if (adminStateUp == null)\r
+            return true;\r
+        return adminStateUp;\r
+    }\r
+\r
+    public Boolean getAdminStateUp() { return adminStateUp; }\r
+\r
+    public void setAdminStateUp(Boolean newValue) {\r
+            this.adminStateUp = newValue;\r
+    }\r
+\r
+    public String getStatus() {\r
+        return status;\r
+    }\r
+\r
+    public void setStatus(String status) {\r
+        this.status = status;\r
+    }\r
+\r
+    public String getMacAddress() {\r
+        return macAddress;\r
+    }\r
+\r
+    public void setMacAddress(String macAddress) {\r
+        this.macAddress = macAddress;\r
+    }\r
+\r
+    public List<Neutron_IPs> getFixedIPs() {\r
+        return fixedIPs;\r
+    }\r
+\r
+    public void setFixedIPs(List<Neutron_IPs> fixedIPs) {\r
+        this.fixedIPs = fixedIPs;\r
+    }\r
+\r
+    public String getDeviceID() {\r
+        return deviceID;\r
+    }\r
+\r
+    public void setDeviceID(String deviceID) {\r
+        this.deviceID = deviceID;\r
+    }\r
+\r
+    public String getDeviceOwner() {\r
+        return deviceOwner;\r
+    }\r
+\r
+    public void setDeviceOwner(String deviceOwner) {\r
+        this.deviceOwner = deviceOwner;\r
+    }\r
+\r
+    public String getTenantID() {\r
+        return tenantID;\r
+    }\r
+\r
+    public void setTenantID(String tenantID) {\r
+        this.tenantID = tenantID;\r
+    }\r
+\r
+    public NeutronFloatingIP getFloatingIP(String key) {\r
+        if (!floatingIPMap.containsKey(key))\r
+            return null;\r
+        return floatingIPMap.get(key);\r
+    }\r
+\r
+    public void removeFloatingIP(String key) {\r
+        floatingIPMap.remove(key);\r
+    }\r
+\r
+    public void addFloatingIP(String key, NeutronFloatingIP floatingIP) {\r
+        if (!floatingIPMap.containsKey(key))\r
+            floatingIPMap.put(key, floatingIP);\r
+    }\r
+\r
+    /**\r
+     * This method copies selected fields from the object and returns them\r
+     * as a new object, suitable for marshaling.\r
+     *\r
+     * @param fields\r
+     *            List of attributes to be extracted\r
+     * @return an OpenStackPorts object with only the selected fields\r
+     * populated\r
+     */\r
+\r
+    public NeutronPort extractFields(List<String> fields) {\r
+        NeutronPort ans = new NeutronPort();\r
+        Iterator<String> i = fields.iterator();\r
+        while (i.hasNext()) {\r
+            String s = i.next();\r
+            if (s.equals("id"))\r
+                ans.setPortUUID(this.getPortUUID());\r
+            if (s.equals("network_id"))\r
+                ans.setNetworkUUID(this.getNetworkUUID());\r
+            if (s.equals("name"))\r
+                ans.setName(this.getName());\r
+            if (s.equals("admin_state_up"))\r
+                ans.setAdminStateUp(this.getAdminStateUp());\r
+            if (s.equals("status"))\r
+                ans.setStatus(this.getStatus());\r
+            if (s.equals("mac_address"))\r
+                ans.setMacAddress(this.getMacAddress());\r
+            if (s.equals("fixed_ips")) {\r
+                List<Neutron_IPs> fixedIPs = new ArrayList<Neutron_IPs>();\r
+                fixedIPs.addAll(this.getFixedIPs());\r
+                ans.setFixedIPs(fixedIPs);\r
+            }\r
+            if (s.equals("device_id")) {\r
+                ans.setDeviceID(this.getDeviceID());\r
+            }\r
+            if (s.equals("device_owner")) {\r
+                ans.setDeviceOwner(this.getDeviceOwner());\r
+            }\r
+            if (s.equals("tenant_id"))\r
+                ans.setTenantID(this.getTenantID());\r
+        }\r
+        return ans;\r
+    }\r
+\r
+    public void initDefaults() {\r
+        adminStateUp = true;\r
+        if (status == null)\r
+            status = "ACTIVE";\r
+        if (fixedIPs == null)\r
+            fixedIPs = new ArrayList<Neutron_IPs>();\r
+    }\r
+\r
+    /**\r
+     * This method checks to see if the port has a floating IPv4 address\r
+     * associated with the supplied fixed IPv4 address\r
+     *\r
+     * @param fixedIP\r
+     *            fixed IPv4 address in dotted decimal format\r
+     * @return a boolean indicating if there is a floating IPv4 address bound\r
+     * to the fixed IPv4 address\r
+     */\r
+\r
+    public boolean isBoundToFloatingIP(String fixedIP) {\r
+        return floatingIPMap.containsKey(fixedIP);\r
+    }\r
+}\r
diff --git a/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronRouter.java b/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronRouter.java
new file mode 100644 (file)
index 0000000..8329ffc
--- /dev/null
@@ -0,0 +1,153 @@
+/*\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;\r
+\r
+import java.util.HashMap;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+import javax.xml.bind.annotation.XmlElement;\r
+import javax.xml.bind.annotation.XmlRootElement;\r
+\r
+@XmlRootElement\r
+@XmlAccessorType(XmlAccessType.NONE)\r
+\r
+public class NeutronRouter {\r
+    // See OpenStack Network API v2.0 Reference for description of\r
+    // annotated attributes\r
+    @XmlElement (name="id")\r
+    String routerUUID;\r
+\r
+    @XmlElement (name="name")\r
+    String name;\r
+\r
+    @XmlElement (defaultValue="true", name="admin_state_up")\r
+    Boolean adminStateUp;\r
+\r
+    @XmlElement (name="status")\r
+    String status;\r
+\r
+    @XmlElement (name="tenant_id")\r
+    String tenantID;\r
+\r
+    @XmlElement (name="external_gateway_info")\r
+    NeutronRouter_NetworkReference externalGatewayInfo;\r
+\r
+    /* Holds a map of OpenStackRouterInterfaces by subnet UUID\r
+     * used for internal mapping to DOVE\r
+     */\r
+    HashMap<String, NeutronRouter_Interface> interfaces;\r
+\r
+    public NeutronRouter() {\r
+        interfaces = new HashMap<String, NeutronRouter_Interface>();\r
+    }\r
+\r
+    public String getID() { return routerUUID; }\r
+\r
+    public String getRouterUUID() {\r
+        return routerUUID;\r
+    }\r
+\r
+    public void setRouterUUID(String routerUUID) {\r
+        this.routerUUID = routerUUID;\r
+    }\r
+\r
+    public String getName() {\r
+        return name;\r
+    }\r
+\r
+    public void setName(String name) {\r
+        this.name = name;\r
+    }\r
+\r
+    public boolean isAdminStateUp() {\r
+        if (adminStateUp == null)\r
+            return true;\r
+        return adminStateUp;\r
+    }\r
+\r
+    public Boolean getAdminStateUp() { return adminStateUp; }\r
+\r
+    public void setAdminStateUp(Boolean newValue) {\r
+        this.adminStateUp = newValue;\r
+    }\r
+\r
+    public String getStatus() {\r
+        return status;\r
+    }\r
+\r
+    public void setStatus(String status) {\r
+        this.status = status;\r
+    }\r
+\r
+    public String getTenantID() {\r
+        return tenantID;\r
+    }\r
+\r
+    public void setTenantID(String tenantID) {\r
+        this.tenantID = tenantID;\r
+    }\r
+\r
+    public NeutronRouter_NetworkReference getExternalGatewayInfo() {\r
+        return externalGatewayInfo;\r
+    }\r
+\r
+    public void setExternalGatewayInfo(NeutronRouter_NetworkReference externalGatewayInfo) {\r
+        this.externalGatewayInfo = externalGatewayInfo;\r
+    }\r
+\r
+    /**\r
+     * This method copies selected fields from the object and returns them\r
+     * as a new object, suitable for marshaling.\r
+     *\r
+     * @param fields\r
+     *            List of attributes to be extracted\r
+     * @return an OpenStackRouters object with only the selected fields\r
+     * populated\r
+     */\r
+\r
+    public NeutronRouter extractFields(List<String> fields) {\r
+        NeutronRouter ans = new NeutronRouter();\r
+        Iterator<String> i = fields.iterator();\r
+        while (i.hasNext()) {\r
+            String s = i.next();\r
+            if (s.equals("id"))\r
+                ans.setRouterUUID(this.getRouterUUID());\r
+            if (s.equals("name"))\r
+                ans.setName(this.getName());\r
+            if (s.equals("admin_state_up"))\r
+                ans.setAdminStateUp(this.getAdminStateUp());\r
+            if (s.equals("status"))\r
+                ans.setStatus(this.getStatus());\r
+            if (s.equals("tenant_id"))\r
+                ans.setTenantID(this.getTenantID());\r
+            if (s.equals("external_gateway_info")) {\r
+                ans.setExternalGatewayInfo(this.getExternalGatewayInfo());\r
+            }\r
+        }\r
+        return ans;\r
+    }\r
+\r
+    public HashMap<String, NeutronRouter_Interface> getInterfaces() {\r
+        return interfaces;\r
+    }\r
+\r
+    public void addInterface(String s, NeutronRouter_Interface i) {\r
+        interfaces.put(s, i);\r
+    }\r
+\r
+    public void removeInterface(String s) {\r
+        interfaces.remove(s);\r
+    }\r
+\r
+    public void initDefaults() {\r
+        adminStateUp = true;\r
+    }\r
+}\r
diff --git a/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronRouter_Interface.java b/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronRouter_Interface.java
new file mode 100644 (file)
index 0000000..307789c
--- /dev/null
@@ -0,0 +1,65 @@
+/*\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;\r
+\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+import javax.xml.bind.annotation.XmlElement;\r
+import javax.xml.bind.annotation.XmlRootElement;\r
+\r
+@XmlRootElement\r
+@XmlAccessorType(XmlAccessType.NONE)\r
+public class NeutronRouter_Interface {\r
+    // See OpenStack Network API v2.0 Reference for description of\r
+    // annotated attributes\r
+\r
+    @XmlElement (name="subnet_id")\r
+    String subnetUUID;\r
+\r
+    @XmlElement (name="port_id")\r
+    String portUUID;\r
+\r
+    @XmlElement (name="id")\r
+    String id;\r
+\r
+    @XmlElement (name="tenant_id")\r
+    String tenantID;\r
+\r
+    public NeutronRouter_Interface() {\r
+    }\r
+\r
+    public NeutronRouter_Interface(String subnetUUID, String portUUID) {\r
+        this.subnetUUID = subnetUUID;\r
+        this.portUUID = portUUID;\r
+    }\r
+\r
+    public String getSubnetUUID() {\r
+        return subnetUUID;\r
+    }\r
+\r
+    public void setSubnetUUID(String subnetUUID) {\r
+        this.subnetUUID = subnetUUID;\r
+    }\r
+\r
+    public String getPortUUID() {\r
+        return portUUID;\r
+    }\r
+\r
+    public void setPortUUID(String portUUID) {\r
+        this.portUUID = portUUID;\r
+    }\r
+\r
+    public void setID(String id) {\r
+        this.id = id;\r
+    }\r
+\r
+    public void setTenantID(String tenantID) {\r
+        this.tenantID = tenantID;\r
+    }\r
+}\r
diff --git a/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronRouter_NetworkReference.java b/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronRouter_NetworkReference.java
new file mode 100644 (file)
index 0000000..012215c
--- /dev/null
@@ -0,0 +1,36 @@
+/*\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;\r
+\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+import javax.xml.bind.annotation.XmlElement;\r
+import javax.xml.bind.annotation.XmlRootElement;\r
+\r
+@XmlRootElement\r
+@XmlAccessorType(XmlAccessType.NONE)\r
+\r
+public class NeutronRouter_NetworkReference {\r
+    // See OpenStack Network API v2.0 Reference for description of\r
+    // annotated attributes\r
+\r
+    @XmlElement(name="network_id")\r
+    String networkID;\r
+\r
+    public NeutronRouter_NetworkReference() {\r
+    }\r
+\r
+    public String getNetworkID() {\r
+        return networkID;\r
+    }\r
+\r
+    public void setNetworkID(String networkID) {\r
+        this.networkID = networkID;\r
+    }\r
+}\r
diff --git a/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet.java b/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet.java
new file mode 100644 (file)
index 0000000..b1414c3
--- /dev/null
@@ -0,0 +1,403 @@
+/*\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;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+import javax.xml.bind.annotation.XmlElement;\r
+import javax.xml.bind.annotation.XmlRootElement;\r
+\r
+import org.apache.commons.net.util.SubnetUtils;\r
+import org.apache.commons.net.util.SubnetUtils.SubnetInfo;\r
+\r
+@XmlRootElement\r
+@XmlAccessorType(XmlAccessType.NONE)\r
+\r
+public class NeutronSubnet {\r
+    // See OpenStack Network API v2.0 Reference for description of\r
+    // annotated attributes\r
+\r
+    @XmlElement (name="id")\r
+    String subnetUUID;\r
+\r
+    @XmlElement (name="network_id")\r
+    String networkUUID;\r
+\r
+    @XmlElement (name="name")\r
+    String name;\r
+\r
+    @XmlElement (defaultValue="4", name="ip_version")\r
+    Integer ipVersion;\r
+\r
+    @XmlElement (name="cidr")\r
+    String cidr;\r
+\r
+    @XmlElement (name="gateway_ip")\r
+    String gatewayIP;\r
+\r
+    @XmlElement (name="dns_nameservers")\r
+    List<String> dnsNameservers;\r
+\r
+    @XmlElement (name="allocation_pools")\r
+    List<NeutronSubnet_IPAllocationPool> allocationPools;\r
+\r
+    @XmlElement (name="host_routes")\r
+    List<NeutronSubnet_HostRoute> hostRoutes;\r
+\r
+    @XmlElement (defaultValue="true", name="enable_dhcp")\r
+    Boolean enableDHCP;\r
+\r
+    @XmlElement (name="tenant_id")\r
+    String tenantID;\r
+\r
+    /* stores the OpenStackPorts associated with an instance\r
+     * used to determine if that instance can be deleted.\r
+     */\r
+    List<NeutronPort> myPorts;\r
+\r
+    boolean gatewayIPAssigned;\r
+\r
+    public NeutronSubnet() {\r
+        myPorts = new ArrayList<NeutronPort>();\r
+    }\r
+\r
+    public String getID() { return subnetUUID; }\r
+\r
+    public String getSubnetUUID() {\r
+        return subnetUUID;\r
+    }\r
+\r
+    public void setSubnetUUID(String subnetUUID) {\r
+        this.subnetUUID = subnetUUID;\r
+    }\r
+\r
+    public String getNetworkUUID() {\r
+        return networkUUID;\r
+    }\r
+\r
+    public void setNetworkUUID(String networkUUID) {\r
+        this.networkUUID = networkUUID;\r
+    }\r
+\r
+    public String getName() {\r
+        return name;\r
+    }\r
+\r
+    public void setName(String name) {\r
+        this.name = name;\r
+    }\r
+\r
+    public Integer getIpVersion() {\r
+        return ipVersion;\r
+    }\r
+\r
+    public void setIpVersion(Integer ipVersion) {\r
+        this.ipVersion = ipVersion;\r
+    }\r
+\r
+    public String getCidr() {\r
+        return cidr;\r
+    }\r
+\r
+    public void setCidr(String cidr) {\r
+        this.cidr = cidr;\r
+    }\r
+\r
+    public String getGatewayIP() {\r
+        return gatewayIP;\r
+    }\r
+\r
+    public void setGatewayIP(String gatewayIP) {\r
+        this.gatewayIP = gatewayIP;\r
+    }\r
+\r
+    public List<String> getDnsNameservers() {\r
+        return dnsNameservers;\r
+    }\r
+\r
+    public void setDnsNameservers(List<String> dnsNameservers) {\r
+        this.dnsNameservers = dnsNameservers;\r
+    }\r
+\r
+    public List<NeutronSubnet_IPAllocationPool> getAllocationPools() {\r
+        return allocationPools;\r
+    }\r
+\r
+    public void setAllocationPools(List<NeutronSubnet_IPAllocationPool> allocationPools) {\r
+        this.allocationPools = allocationPools;\r
+    }\r
+\r
+    public List<NeutronSubnet_HostRoute> getHostRoutes() {\r
+        return hostRoutes;\r
+    }\r
+\r
+    public void setHostRoutes(List<NeutronSubnet_HostRoute> hostRoutes) {\r
+        this.hostRoutes = hostRoutes;\r
+    }\r
+\r
+    public boolean isEnableDHCP() {\r
+        if (enableDHCP == null)\r
+            return true;\r
+        return enableDHCP;\r
+    }\r
+\r
+    public Boolean getEnableDHCP() { return enableDHCP; }\r
+\r
+    public void setEnableDHCP(Boolean newValue) {\r
+            this.enableDHCP = newValue;\r
+    }\r
+\r
+    public String getTenantID() {\r
+        return tenantID;\r
+    }\r
+\r
+    public void setTenantID(String tenantID) {\r
+        this.tenantID = tenantID;\r
+    }\r
+\r
+    /**\r
+     * This method copies selected fields from the object and returns them\r
+     * as a new object, suitable for marshaling.\r
+     *\r
+     * @param fields\r
+     *            List of attributes to be extracted\r
+     * @return an OpenStackSubnets object with only the selected fields\r
+     * populated\r
+     */\r
+\r
+    public NeutronSubnet extractFields(List<String> fields) {\r
+        NeutronSubnet ans = new NeutronSubnet();\r
+        Iterator<String> i = fields.iterator();\r
+        while (i.hasNext()) {\r
+            String s = i.next();\r
+            if (s.equals("id"))\r
+                ans.setSubnetUUID(this.getSubnetUUID());\r
+            if (s.equals("network_id"))\r
+                ans.setNetworkUUID(this.getNetworkUUID());\r
+            if (s.equals("name"))\r
+                ans.setName(this.getName());\r
+            if (s.equals("ip_version"))\r
+                ans.setIpVersion(this.getIpVersion());\r
+            if (s.equals("cidr"))\r
+                ans.setCidr(this.getCidr());\r
+            if (s.equals("gateway_ip"))\r
+                ans.setGatewayIP(this.getGatewayIP());\r
+            if (s.equals("dns_nameservers")) {\r
+                List<String> nsList = new ArrayList<String>();\r
+                nsList.addAll(this.getDnsNameservers());\r
+                ans.setDnsNameservers(nsList);\r
+            }\r
+            if (s.equals("allocation_pools")) {\r
+                List<NeutronSubnet_IPAllocationPool> aPools = new ArrayList<NeutronSubnet_IPAllocationPool>();\r
+                aPools.addAll(this.getAllocationPools());\r
+                ans.setAllocationPools(aPools);\r
+            }\r
+            if (s.equals("host_routes")) {\r
+                List<NeutronSubnet_HostRoute> hRoutes = new ArrayList<NeutronSubnet_HostRoute>();\r
+                hRoutes.addAll(this.getHostRoutes());\r
+                ans.setHostRoutes(hRoutes);\r
+            }\r
+            if (s.equals("enable_dhcp"))\r
+                ans.setEnableDHCP(this.getEnableDHCP());\r
+            if (s.equals("tenant_id"))\r
+                ans.setTenantID(this.getTenantID());\r
+        }\r
+        return ans;\r
+    }\r
+\r
+    /* test to see if the cidr address used to define this subnet\r
+     * is a valid network address (an necessary condition when creating\r
+     * a new subnet)\r
+     */\r
+    public boolean isValidCIDR() {\r
+        try {\r
+            SubnetUtils util = new SubnetUtils(cidr);\r
+            SubnetInfo info = util.getInfo();\r
+            if (!info.getNetworkAddress().equals(info.getAddress()))\r
+                return false;\r
+        } catch (Exception e) {\r
+            return false;\r
+        }\r
+        return true;\r
+    }\r
+\r
+    /* test to see if the gateway IP specified overlaps with specified\r
+     * allocation pools (an error condition when creating a new subnet\r
+     * or assigning a gateway IP)\r
+     */\r
+    public boolean gatewayIP_Pool_overlap() {\r
+        Iterator<NeutronSubnet_IPAllocationPool> i = allocationPools.iterator();\r
+        while (i.hasNext()) {\r
+            NeutronSubnet_IPAllocationPool pool = i.next();\r
+            if (pool.contains(gatewayIP))\r
+                return true;\r
+        }\r
+        return false;\r
+    }\r
+\r
+    public void initDefaults() {\r
+        if (enableDHCP == null)\r
+            enableDHCP = true;\r
+        if (ipVersion == null)\r
+            ipVersion = 4;\r
+        gatewayIPAssigned = false;\r
+        dnsNameservers = new ArrayList<String>();\r
+        allocationPools = new ArrayList<NeutronSubnet_IPAllocationPool>();\r
+        hostRoutes = new ArrayList<NeutronSubnet_HostRoute>();\r
+        try {\r
+            SubnetUtils util = new SubnetUtils(cidr);\r
+            SubnetInfo info = util.getInfo();\r
+            if (gatewayIP == null)\r
+                gatewayIP = info.getLowAddress();\r
+            if (allocationPools.size() < 1) {\r
+                NeutronSubnet_IPAllocationPool source =\r
+                    new NeutronSubnet_IPAllocationPool(info.getLowAddress(),\r
+                            info.getHighAddress());\r
+                allocationPools = source.splitPool(gatewayIP);\r
+            }\r
+        } catch (Exception e) {\r
+            ;\r
+        }\r
+    }\r
+\r
+    public List<NeutronPort> getPortsInSubnet() {\r
+        return myPorts;\r
+    }\r
+\r
+    public void addPort(NeutronPort port) {\r
+        myPorts.add(port);\r
+    }\r
+\r
+    public void removePort(NeutronPort port) {\r
+        myPorts.remove(port);\r
+    }\r
+\r
+    /* this method tests to see if the supplied IPv4 address\r
+     * is valid for this subnet or not\r
+     */\r
+    public boolean isValidIP(String ipAddress) {\r
+        try {\r
+            SubnetUtils util = new SubnetUtils(cidr);\r
+            SubnetInfo info = util.getInfo();\r
+            return info.isInRange(ipAddress);\r
+        } catch (Exception e) {\r
+            return false;\r
+        }\r
+    }\r
+\r
+    /* test to see if the supplied IPv4 address is part of one of the\r
+     * available allocation pools or not\r
+     */\r
+    public boolean isIPInUse(String ipAddress) {\r
+        if (ipAddress.equals(gatewayIP) && !gatewayIPAssigned )\r
+            return false;\r
+        Iterator<NeutronSubnet_IPAllocationPool> i = allocationPools.iterator();\r
+        while (i.hasNext()) {\r
+            NeutronSubnet_IPAllocationPool pool = i.next();\r
+            if (pool.contains(ipAddress))\r
+                return false;\r
+        }\r
+        return true;\r
+    }\r
+\r
+    /* method to get the lowest available address of the subnet.\r
+     * go through all the allocation pools and keep the lowest of their\r
+     * low addresses.\r
+     */\r
+    public String getLowAddr() {\r
+        String ans = null;\r
+        Iterator<NeutronSubnet_IPAllocationPool> i = allocationPools.iterator();\r
+        while (i.hasNext()) {\r
+            NeutronSubnet_IPAllocationPool pool = i.next();\r
+            if (ans == null)\r
+                ans = pool.getPoolStart();\r
+            else\r
+                if (NeutronSubnet_IPAllocationPool.convert(pool.getPoolStart()) <\r
+                        NeutronSubnet_IPAllocationPool.convert(ans))\r
+                    ans = pool.getPoolStart();\r
+        }\r
+        return ans;\r
+    }\r
+\r
+    /*\r
+     * allocate the parameter address.  Because this uses an iterator to\r
+     * check the instance's list of allocation pools and we want to modify\r
+     * pools while the iterator is being used, it is necessary to\r
+     * build a new list of allocation pools and replace the list when\r
+     * finished (otherwise a split will cause undefined iterator behavior.\r
+     */\r
+    public void allocateIP(String ipAddress) {\r
+        Iterator<NeutronSubnet_IPAllocationPool> i = allocationPools.iterator();\r
+        List<NeutronSubnet_IPAllocationPool> newList = new ArrayList<NeutronSubnet_IPAllocationPool>();    // we have to modify a separate list\r
+        while (i.hasNext()) {\r
+            NeutronSubnet_IPAllocationPool pool = i.next();\r
+            if (pool.getPoolEnd().equalsIgnoreCase(ipAddress) &&\r
+                    pool.getPoolStart().equalsIgnoreCase(ipAddress))\r
+                ; // do nothing, i.e. don't add the current pool to the new list\r
+            else\r
+                if (pool.contains(ipAddress)) {\r
+                    List<NeutronSubnet_IPAllocationPool> pools = pool.splitPool(ipAddress);\r
+                    newList.addAll(pools);\r
+                } else\r
+                    newList.add(pool);\r
+        }\r
+        allocationPools = newList;\r
+    }\r
+\r
+    /*\r
+     * release an IP address back to the subnet.  Although an iterator\r
+     * is used, the list is not modified until the iterator is complete, so\r
+     * an extra list is not necessary.\r
+     */\r
+    public void releaseIP(String ipAddress) {\r
+        NeutronSubnet_IPAllocationPool lPool = null;\r
+        NeutronSubnet_IPAllocationPool hPool = null;\r
+        Iterator<NeutronSubnet_IPAllocationPool> i = allocationPools.iterator();\r
+        long sIP = NeutronSubnet_IPAllocationPool.convert(ipAddress);\r
+        //look for lPool where ipAddr - 1 is high address\r
+        //look for hPool where ipAddr + 1 is low address\r
+        while (i.hasNext()) {\r
+            NeutronSubnet_IPAllocationPool pool = i.next();\r
+            long lIP = NeutronSubnet_IPAllocationPool.convert(pool.getPoolStart());\r
+            long hIP = NeutronSubnet_IPAllocationPool.convert(pool.getPoolEnd());\r
+            if (sIP+1 == lIP)\r
+                hPool = pool;\r
+            if (sIP-1 == hIP)\r
+                lPool = pool;\r
+        }\r
+        //if (lPool == NULL and hPool == NULL) create new pool where low = ip = high\r
+        if (lPool == null && hPool == null)\r
+            allocationPools.add(new NeutronSubnet_IPAllocationPool(ipAddress,ipAddress));\r
+        //if (lPool == NULL and hPool != NULL) change low address of hPool to ipAddr\r
+        if (lPool == null && hPool != null)\r
+            hPool.setPoolStart(ipAddress);\r
+        //if (lPool != NULL and hPool == NULL) change high address of lPool to ipAddr\r
+        if (lPool != null && hPool == null)\r
+            lPool.setPoolEnd(ipAddress);\r
+        //if (lPool != NULL and hPool != NULL) remove lPool and hPool and create new pool\r
+        //        where low address = lPool.low address and high address = hPool.high Address\r
+        if (lPool != null && hPool != null) {\r
+            allocationPools.remove(lPool);\r
+            allocationPools.remove(hPool);\r
+            allocationPools.add(new NeutronSubnet_IPAllocationPool(\r
+                    lPool.getPoolStart(), hPool.getPoolEnd()));\r
+        }\r
+    }\r
+\r
+    public void setGatewayIPAllocated() {\r
+        gatewayIPAssigned = true;\r
+    }\r
+\r
+    public void resetGatewayIPAllocated() {\r
+        gatewayIPAssigned = false;\r
+    }\r
+}\r
diff --git a/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet_HostRoute.java b/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet_HostRoute.java
new file mode 100644 (file)
index 0000000..c108429
--- /dev/null
@@ -0,0 +1,29 @@
+/*\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;\r
+\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+import javax.xml.bind.annotation.XmlElement;\r
+import javax.xml.bind.annotation.XmlRootElement;\r
+\r
+@XmlRootElement\r
+@XmlAccessorType(XmlAccessType.NONE)\r
+public class NeutronSubnet_HostRoute {\r
+    // See OpenStack Network API v2.0 Reference for description of\r
+    // annotated attributes\r
+\r
+    @XmlElement(name="destination")\r
+    String destination;\r
+\r
+    @XmlElement(name="nexthop")\r
+    String nextHop;\r
+\r
+    public NeutronSubnet_HostRoute() { }\r
+}\r
diff --git a/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet_IPAllocationPool.java b/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet_IPAllocationPool.java
new file mode 100644 (file)
index 0000000..15401b7
--- /dev/null
@@ -0,0 +1,171 @@
+/*\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;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+import javax.xml.bind.annotation.XmlElement;\r
+import javax.xml.bind.annotation.XmlRootElement;\r
+\r
+@XmlRootElement\r
+@XmlAccessorType(XmlAccessType.NONE)\r
+public class NeutronSubnet_IPAllocationPool {\r
+    // See OpenStack Network API v2.0 Reference for description of\r
+    // annotated attributes\r
+\r
+    @XmlElement(name="start")\r
+    String poolStart;\r
+\r
+    @XmlElement(name="end")\r
+    String poolEnd;\r
+\r
+    public NeutronSubnet_IPAllocationPool() { }\r
+\r
+    public NeutronSubnet_IPAllocationPool(String lowAddress, String highAddress) {\r
+        poolStart = lowAddress;\r
+        poolEnd = highAddress;\r
+    }\r
+\r
+    public String getPoolStart() {\r
+        return poolStart;\r
+    }\r
+\r
+    public void setPoolStart(String poolStart) {\r
+        this.poolStart = poolStart;\r
+    }\r
+\r
+    public String getPoolEnd() {\r
+        return poolEnd;\r
+    }\r
+\r
+    public void setPoolEnd(String poolEnd) {\r
+        this.poolEnd = poolEnd;\r
+    }\r
+\r
+    /**\r
+     * This method determines if this allocation pool contains the\r
+     * input IPv4 address\r
+     *\r
+     * @param inputString\r
+     *            IPv4 address in dotted decimal format\r
+     * @returns a boolean on whether the pool contains the address or not\r
+     */\r
+\r
+    public boolean contains(String inputString) {\r
+        long inputIP = convert(inputString);\r
+        long startIP = convert(poolStart);\r
+        long endIP = convert(poolEnd);\r
+        return (inputIP >= startIP && inputIP <= endIP);\r
+    }\r
+\r
+    /**\r
+     * This static method converts the supplied IPv4 address to a long\r
+     * integer for comparison\r
+     *\r
+     * @param inputString\r
+     *            IPv4 address in dotted decimal format\r
+     * @returns high-endian representation of the IPv4 address as a long\r
+     */\r
+\r
+    static long convert(String inputString) {\r
+        long ans = 0;\r
+        String[] parts = inputString.split("\\.");\r
+        for (String part: parts) {\r
+            ans <<= 8;\r
+            ans |= Integer.parseInt(part);\r
+        }\r
+        return ans;\r
+    }\r
+\r
+    /**\r
+     * This static method converts the supplied high-ending long back\r
+     * into a dotted decimal representation of an IPv4 address\r
+     *\r
+     * @param l\r
+     *            high-endian representation of the IPv4 address as a long\r
+     * @returns IPv4 address in dotted decimal format\r
+     */\r
+    static String longtoIP(long l) {\r
+        int i;\r
+        String[] parts = new String[4];\r
+        for (i=0; i<4; i++) {\r
+            parts[3-i] = String.valueOf(l & 255);\r
+            l >>= 8;\r
+        }\r
+        return join(parts,".");\r
+    }\r
+\r
+    /*\r
+     * helper routine used by longtoIP\r
+     */\r
+    public static String join(String r[],String d)\r
+    {\r
+        if (r.length == 0) return "";\r
+        StringBuilder sb = new StringBuilder();\r
+        int i;\r
+        for(i=0;i<r.length-1;i++)\r
+            sb.append(r[i]+d);\r
+        return sb.toString()+r[i];\r
+    }\r
+\r
+    /*\r
+     * This method splits the current instance by removing the supplied\r
+     * parameter.\r
+     *\r
+     * If the parameter is either the low or high address,\r
+     * then that member is adjusted and a list containing just this instance\r
+     * is returned.\r
+     *\r
+     * If the parameter is in the middle of the pool, then\r
+     * create two new instances, one ranging from low to parameter-1\r
+     * the other ranging from parameter+1 to high\r
+     */\r
+    public List<NeutronSubnet_IPAllocationPool> splitPool(String ipAddress) {\r
+        List<NeutronSubnet_IPAllocationPool> ans = new ArrayList<NeutronSubnet_IPAllocationPool>();\r
+        long gIP = NeutronSubnet_IPAllocationPool.convert(ipAddress);\r
+        long sIP = NeutronSubnet_IPAllocationPool.convert(poolStart);\r
+        long eIP = NeutronSubnet_IPAllocationPool.convert(poolEnd);\r
+        long i;\r
+        NeutronSubnet_IPAllocationPool p = new NeutronSubnet_IPAllocationPool();\r
+        boolean poolStarted = false;\r
+        for (i=sIP; i<=eIP; i++) {\r
+            if (i == sIP) {\r
+                if (i != gIP) {\r
+                    p.setPoolStart(poolStart);\r
+                    poolStarted = true;\r
+                }\r
+            }\r
+            if (i == eIP) {\r
+                if (i != gIP) {\r
+                    p.setPoolEnd(poolEnd);\r
+                } else {\r
+                    p.setPoolEnd(NeutronSubnet_IPAllocationPool.longtoIP(i-1));\r
+                }\r
+                ans.add(p);\r
+            }\r
+            if (i != sIP && i != eIP) {\r
+                if (i != gIP) {\r
+                    if (!poolStarted) {\r
+                        p.setPoolStart(NeutronSubnet_IPAllocationPool.longtoIP(i));\r
+                        poolStarted = true;\r
+                    }\r
+                } else {\r
+                    p.setPoolEnd(NeutronSubnet_IPAllocationPool.longtoIP(i-1));\r
+                    poolStarted = false;\r
+                    ans.add(p);\r
+                    p = new NeutronSubnet_IPAllocationPool();\r
+                }\r
+            }\r
+        }\r
+        return ans;\r
+    }\r
+}\r
diff --git a/src/main/java/org/opendaylight/controller/networkconfig/neutron/Neutron_IPs.java b/src/main/java/org/opendaylight/controller/networkconfig/neutron/Neutron_IPs.java
new file mode 100644 (file)
index 0000000..7309479
--- /dev/null
@@ -0,0 +1,49 @@
+/*\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;\r
+\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+import javax.xml.bind.annotation.XmlElement;\r
+import javax.xml.bind.annotation.XmlRootElement;\r
+\r
+@XmlRootElement\r
+@XmlAccessorType(XmlAccessType.NONE)\r
+public class Neutron_IPs {\r
+    // See OpenStack Network API v2.0 Reference for description of\r
+    // annotated attributes\r
+\r
+    @XmlElement(name="ip_address")\r
+    String ipAddress;\r
+\r
+    @XmlElement(name="subnet_id")\r
+    String subnetUUID;\r
+\r
+    public Neutron_IPs() { }\r
+\r
+    public Neutron_IPs(String uuid) {\r
+        this.subnetUUID = uuid;\r
+    }\r
+\r
+    public String getIpAddress() {\r
+        return ipAddress;\r
+    }\r
+\r
+    public void setIpAddress(String ipAddress) {\r
+        this.ipAddress = ipAddress;\r
+    }\r
+\r
+    public String getSubnetUUID() {\r
+        return subnetUUID;\r
+    }\r
+\r
+    public void setSubnetUUID(String subnetUUID) {\r
+        this.subnetUUID = subnetUUID;\r
+    }\r
+}\r