Expand implementation of Neutron Service APIs in Lisp 20/10420/2
authorVina Ermagan <vermagan@cisco.com>
Thu, 28 Aug 2014 04:49:45 +0000 (21:49 -0700)
committerVina Ermagan <vermagan@cisco.com>
Thu, 28 Aug 2014 05:43:28 +0000 (22:43 -0700)
.

Change-Id: I28e3a20439796fa436ea2cac62c7ff664d4a6ef3
Signed-off-by: Vina Ermagan <vermagan@cisco.com>
commons/parent/pom.xml
distribution/pom.xml
mappingservice/neutron/pom.xml
mappingservice/neutron/src/main/java/org/opendaylight/lispflowmapping/neutron/Activator.java
mappingservice/neutron/src/main/java/org/opendaylight/lispflowmapping/neutron/ILispNeutronService.java
mappingservice/neutron/src/main/java/org/opendaylight/lispflowmapping/neutron/LispNeutronNetworkHandler.java [new file with mode: 0644]
mappingservice/neutron/src/main/java/org/opendaylight/lispflowmapping/neutron/LispNeutronPortHandler.java [new file with mode: 0644]
mappingservice/neutron/src/main/java/org/opendaylight/lispflowmapping/neutron/LispNeutronService.java
mappingservice/neutron/src/main/java/org/opendaylight/lispflowmapping/neutron/LispNeutronSubnetHandler.java [new file with mode: 0644]

index daec4437e73cb2adee767e3065d1222c095d4668..a5292735b3052efbb20cba4480814177348ccd7b 100644 (file)
               <artifactId>mappingservice.northbound</artifactId>
               <version>${lispflowmapping.version}</version>
             </dependency>
+            <dependency>
+              <groupId>org.opendaylight.lispflowmapping</groupId>
+              <artifactId>mappingservice.neutron</artifactId>
+              <version>${lispflowmapping.version}</version>
+            </dependency>            
                <dependency>
                        <groupId>org.opendaylight.lispflowmapping</groupId>
                        <artifactId>common.unittest.tools</artifactId>
index 0146c3e1bfc17e112b2a9ee99b8ab5703aee53e8..389e194fb6d784702a0e444187bed781cfd85cc9 100644 (file)
                        <artifactId>mappingservice.northbound</artifactId>
                </dependency>
                
+               <dependency>
+                       <groupId>org.opendaylight.lispflowmapping</groupId>
+                       <artifactId>mappingservice.neutron</artifactId>
+               </dependency>           
+               
   </dependencies>
 
   <build>
index 048f08d5a66e46dffb878450a7272739751fef12..2d9e414d52c0092fd2f94280f89ae43aafe22a37 100644 (file)
@@ -7,11 +7,10 @@
                <version>1.1.11-SNAPSHOT</version>
                <relativePath>..</relativePath>
        </parent>
-
        <artifactId>mappingservice.neutron</artifactId>
         <name>LISP Flow Mapping Neutron APIs</name>
-       <version>1.1.11-SNAPSHOT</version>
-       <packaging>bundle</packaging>
+<!--        <version>0.4.2-SNAPSHOT</version> -->         
+               <packaging>bundle</packaging>           
        <scm>
                <connection>scm:git:https://git.opendaylight.org/gerrit/p/lispflowmapping.git</connection>
                <developerConnection>scm:git:ssh://git.opendaylight.org:29418/lispflowmapping.git</developerConnection>
@@ -23,7 +22,6 @@
                        <plugin>
                                <groupId>org.apache.felix</groupId>
                                <artifactId>maven-bundle-plugin</artifactId>
-                               <version>2.3.6</version>
                                <extensions>true</extensions>
                                <configuration>
                                        <instructions>
                                                        org.opendaylight.lispflowmapping.type.lisp,
                                                        org.opendaylight.lispflowmapping.type.lisp.address,
                                                        org.opendaylight.lispflowmapping.interfaces.lisp,
+                                                       org.opendaylight.yang.gen.v1.lispflowmapping.rev131031,
+                                                       org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress,
+                                                       org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.lispaddresscontainer, 
+                                                       org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.lispaddresscontainer.address, 
+                                                       org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924,
                                                        org.slf4j,
                                                        org.apache.catalina.filters,
                                                        org.apache.felix.dm,
+                                           org.apache.commons.net.util,
                                                        org.apache.commons.lang3.builder,
                                                        org.osgi.service.component,
                                                        org.eclipse.osgi.framework.console,
@@ -65,7 +69,7 @@
                        </plugin>
                </plugins>
        </build>
-       <dependencies>
+       <dependencies>  
                <dependency>
                        <groupId>equinoxSDK381</groupId>
                        <artifactId>org.eclipse.osgi</artifactId>
                        <artifactId>networkconfig.neutron</artifactId>
                        <version>0.4.2-SNAPSHOT</version>
                </dependency>
-       </dependencies>
+               <dependency>
+                       <groupId>org.opendaylight.lispflowmapping</groupId>
+                       <artifactId>mappingservice.yangmodel</artifactId>
+               </dependency>           
+               <dependency>
+                       <groupId>org.opendaylight.yangtools.model</groupId>
+                       <artifactId>ietf-inet-types</artifactId>
+               </dependency>
+       </dependencies>         
 </project>
index d2422d96a5b9afc91c8fcc36d6c472e8c29f5315..53c1c5b25db0d5789ce4cb5dee4f302a5a96a51f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 Contextream, Inc. and others.  All rights reserved.
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -8,6 +8,7 @@
 
 package org.opendaylight.lispflowmapping.neutron;
 
+
 import java.util.Dictionary;
 import java.util.Hashtable;
 
@@ -15,13 +16,15 @@ import org.apache.felix.dm.Component;
 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
 import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping;
 import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkAware;
+import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetAware;
+import org.opendaylight.controller.networkconfig.neutron.INeutronPortAware;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * Main application activator class for registering the dependencies and
- * initialising the Mapping Service application.
- * 
+ * Initializing the Mapping Service application.
+ *
  */
 
 public class Activator extends ComponentActivatorAbstractBase {
@@ -34,40 +37,46 @@ public class Activator extends ComponentActivatorAbstractBase {
     /**
      * Function called when the activator starts just after some initializations
      * are done by the ComponentActivatorAbstractBase.
-     * 
+     *
      */
     @Override
     public void init() {
+        logger.debug("LISP Neutron Service is initialized!");
+
     }
 
     /**
      * Function called when the activator stops just before the cleanup done by
      * ComponentActivatorAbstractBase
-     * 
+     *
      */
     @Override
     public void destroy() {
+        logger.debug("LISP Neutron Service is destroyed!");
     }
 
     /**
      * Function that is used to communicate to dependency manager the list of
      * known implementations for services inside a container
-     * 
-     * 
+     *
+     *
      * @return An array containing all the CLASS objects that will be
      *         instantiated in order to get an fully working implementation
      *         Object
      */
     @Override
     public Object[] getImplementations() {
-        Object[] res = { LispNeutronService.class };
+        Object[] res = { LispNeutronService.class,
+                                        LispNeutronSubnetHandler.class,
+                                        LispNeutronPortHandler.class,
+                                        LispNeutronNetworkHandler.class};
         return res;
     }
 
     /**
      * Function that is called when configuration of the dependencies is
      * required.
-     * 
+     *
      * @param c
      *            dependency manager Component object, used for configuring the
      *            dependencies exported and imported
@@ -81,54 +90,31 @@ public class Activator extends ComponentActivatorAbstractBase {
      */
     @Override
     public void configureInstance(Component c, Object imp, String containerName) {
-        
-        //partially based on OpenDove code
+        Dictionary<String, String> props = new Hashtable<String, String>();
+        props.put("name", "mappingservice");
+
         if (imp.equals(LispNeutronService.class)) {
-            c.setInterface(
-                    new String[] { INeutronNetworkAware.class.getName(),
-                               ILispNeutronService.class.getName()}, //Is this necessary? 
-                               null); // null or props here?
-            Dictionary<String, String> props = new Hashtable<String, String>();
-            props.put("name", "mappingservice");
-            c.add(createContainerServiceDependency(containerName)
-                       .setService(IFlowMapping.class)
-                       .setCallbacks("setFlowMappingService", "unsetFlowMappingService")
-                    .setRequired(true));
+            c.setInterface(ILispNeutronService.class.getName(), props);
         }
-    }
-    
-    
 
-    /**
-     * Method which tells how many Global implementations are supported by the
-     * bundle. This way we can tune the number of components created. This
-     * components will be created ONLY at the time of bundle startup and will be
-     * destroyed only at time of bundle destruction, this is the major
-     * difference with the implementation retrieved via getImplementations where
-     * all of them are assumed to be in a container !
-     * 
-     * 
-     * @return The list of implementations the bundle will support, in Global
-     *         version
-     */
-    @Override
-    protected Object[] getGlobalImplementations() {
-        return null;
-    }
+        if (imp.equals(LispNeutronNetworkHandler.class)) {
+            c.setInterface(new String[] { ILispNeutronService.class.getName(), INeutronNetworkAware.class.getName()}, props);
+        }
+
+        if (imp.equals(LispNeutronSubnetHandler.class)) {
+               c.setInterface(new String[] { ILispNeutronService.class.getName(), INeutronSubnetAware.class.getName()}, props);
+        }
+
+        if (imp.equals(LispNeutronPortHandler.class)) {
+            c.setInterface(new String[] { ILispNeutronService.class.getName(), INeutronPortAware.class.getName()}, props);
+        }
+
+        c.add(createContainerServiceDependency(containerName)
+                       .setService(IFlowMapping.class)
+                       .setCallbacks("setMappingService", "unsetMappingService")
+                .setRequired(true));
 
-    /**
-     * Configure the dependency for a given instance Global
-     * 
-     * @param c
-     *            Component assigned for this instance, this will be what will
-     *            be used for configuration
-     * @param imp
-     *            implementation to be configured
-     * @param containerName
-     *            container on which the configuration happens
-     */
-    @Override
-    protected void configureGlobalInstance(Component c, Object imp) {
 
     }
+
 }
index 87c7f69699630a4eb6048d440606752113f1684b..912546efe45a39be0c54baf4ffe5ee13a19578bc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -11,7 +11,7 @@ package org.opendaylight.lispflowmapping.neutron;
 import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping;
 
 public interface ILispNeutronService {
-       
+
        public IFlowMapping getMappingService();
 
 }
diff --git a/mappingservice/neutron/src/main/java/org/opendaylight/lispflowmapping/neutron/LispNeutronNetworkHandler.java b/mappingservice/neutron/src/main/java/org/opendaylight/lispflowmapping/neutron/LispNeutronNetworkHandler.java
new file mode 100644 (file)
index 0000000..000e6ae
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.lispflowmapping.neutron;
+
+import java.net.HttpURLConnection;
+
+import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkAware;
+import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
+
+/**
+ * LISP Service Implementation of NeutronNetworkAware API
+ *
+ */
+public class LispNeutronNetworkHandler extends LispNeutronService implements INeutronNetworkAware {
+
+
+       @Override
+       public int canCreateNetwork(NeutronNetwork network) {
+        logger.info("Neutron canCreateNetwork : Network name: " + network.getNetworkName());
+        logger.debug("Lisp Neutron Network: " + network.toString());
+
+        return HttpURLConnection.HTTP_OK;
+       }
+
+       @Override
+       public void neutronNetworkCreated(NeutronNetwork network) {
+        logger.info("Neutron Network Created : Network name: " + network.getNetworkName());
+        logger.debug("Lisp Neutron Network: " + network.toString());
+
+       }
+
+       @Override
+       public int canUpdateNetwork(NeutronNetwork delta, NeutronNetwork original) {
+        logger.info("Neutron canUpdateNetwork : Network name: " + original.getNetworkName());
+        logger.debug("Lisp Neutron Network: " + original.toString());
+
+        return HttpURLConnection.HTTP_OK;
+       }
+
+       @Override
+       public void neutronNetworkUpdated(NeutronNetwork network) {
+        logger.info("Neutron Network Updated : Network name: " + network.getNetworkName());
+        logger.debug("Lisp Neutron Network: " + network.toString());
+
+       }
+
+       @Override
+       public int canDeleteNetwork(NeutronNetwork network) {
+        logger.info("Neutron canDeleteNetwork : Network name: " + network.getNetworkName());
+        logger.debug("Lisp Neutron Network: " + network.toString());
+
+        return HttpURLConnection.HTTP_OK;
+       }
+
+       @Override
+       public void neutronNetworkDeleted(NeutronNetwork network) {
+        logger.info("Neutron Network Deleted : Network name: " + network.getNetworkName());
+        logger.debug("Lisp Neutron Network: " + network.toString());
+
+        return;
+       }
+
+}
diff --git a/mappingservice/neutron/src/main/java/org/opendaylight/lispflowmapping/neutron/LispNeutronPortHandler.java b/mappingservice/neutron/src/main/java/org/opendaylight/lispflowmapping/neutron/LispNeutronPortHandler.java
new file mode 100644 (file)
index 0000000..50d8228
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.lispflowmapping.neutron;
+
+import java.net.HttpURLConnection;
+
+import org.opendaylight.controller.networkconfig.neutron.INeutronPortAware;
+import org.opendaylight.controller.networkconfig.neutron.NeutronPort;
+
+/**
+ * Lisp Service implementation of NeutronPortAware API
+ * Creation of a new port results adding the mapping for
+ * the port's IP addresses to the port's host_ip in the mapping service.
+ * Currently the NetronPort object does not carry the required information
+ * to achieve the port's host_ip. Once such extension is available
+ * this class shall be updated.
+ *
+ */
+public class LispNeutronPortHandler extends LispNeutronService implements INeutronPortAware {
+
+
+       @Override
+       public int canCreatePort(NeutronPort port) {
+        logger.info("Neutron canCreatePort : Port name: " + port.getName());
+
+        return HttpURLConnection.HTTP_OK;
+       }
+
+       @Override
+       public void neutronPortCreated(NeutronPort port) {
+               // TODO Consider adding Port MAC -> Port fixed IP in MS
+               // TODO Add Port fixed ip -> host ip mapping in MS - Requires extension of Port object
+
+        logger.info("Neutron Port Created: Port name: " + port.getName() + " Port Fixed IP: " +
+                       ( port.getFixedIPs() != null ? port.getFixedIPs().get(0) : "No Fixed IP assigned" ));
+        logger.debug("Neutron Port Created : " + port.toString());
+
+       }
+
+       @Override
+       public int canUpdatePort(NeutronPort delta, NeutronPort original) {
+               // TODO Port IP and port's host ip is stored by Lisp Neutron Service. If there is change to these fields, the update needs to be processed.
+
+               logger.info("Neutron canUpdatePort : Port name: " + original.getName() + " Port Fixed IP: " +
+                               ( original.getFixedIPs() != null ? original.getFixedIPs().get(0) : "No Fixed IP assigned" ));
+               logger.debug("Neutron canUpdatePort : original" + original.toString() + " delta : " + delta.toString());
+
+        return HttpURLConnection.HTTP_OK;
+       }
+
+       @Override
+       public void neutronPortUpdated(NeutronPort port) {
+               // TODO Port IP and port's host ip is stored by Lisp Neutron Service. If there is change to these fields, the update needs to be processed.
+
+               logger.info("Neutron Port updated: Port name: " + port.getName() + " Port Fixed IP: " +
+                       ( port.getFixedIPs() != null ? port.getFixedIPs().get(0) : "No Fixed IP assigned" ));
+               logger.debug("Neutron Port Updated : " + port.toString());
+
+       }
+
+       @Override
+       public int canDeletePort(NeutronPort port) {
+               // TODO Check if Port IPs are stored by Lisp Neutron Service. if not return error code.
+
+               logger.info("Neutron canDeletePort : Port name: " + port.getName() + " Port Fixed IP: " +
+                       ( port.getFixedIPs() != null ? port.getFixedIPs().get(0) : "No Fixed IP assigned" ));
+               logger.debug("Neutron canDeltePort: " + port.toString());
+
+               return HttpURLConnection.HTTP_OK;
+       }
+
+       @Override
+       public void neutronPortDeleted(NeutronPort port) {
+               // TODO if port ips existed in MapServer, delete them. Else, log error.
+
+               logger.info("Neutron Port Deleted: Port name: " + port.getName() + " Port Fixed IP: " +
+                       ( port.getFixedIPs() != null ? port.getFixedIPs().get(0) : "No Fixed IP assigned" ));
+               logger.debug("Neutron Port Deleted : " + port.toString());
+
+       }
+}
index 5f3f5319a477d9ab4bebe96e4cd0a7b027f64fe4..42ae05181c67a0a785901e50a1dfd53564384f5d 100644 (file)
@@ -1,55 +1,56 @@
 /*
- * Copyright (c) 2014 Cisco, Inc. and others.  All rights reserved.
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
+
 package org.opendaylight.lispflowmapping.neutron;
 
-import org.eclipse.osgi.framework.console.CommandProvider;
-import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping;
-import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkAware;
-import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping;
+import org.opendaylight.controller.containermanager.IContainerManager;
+
+
 
-public class LispNeutronService implements ILispNeutronService, INeutronNetworkAware {
-    protected static final Logger logger = LoggerFactory.getLogger(LispNeutronService.class);
-    private IFlowMapping mappingService;
+public class LispNeutronService implements ILispNeutronService {
+
+       protected static final Logger logger = LoggerFactory.getLogger(LispNeutronService.class);
+    protected IFlowMapping mappingService;
 
     public IFlowMapping getMappingService() {
         return this.mappingService;
     }
 
-    void setFlowMappingService(IFlowMapping mappingService) {
-        logger.debug("FlowMapping set in LispNeutron");
+    public void setMappingService(IFlowMapping mappingService) {
+        logger.debug("MappingService set in Lisp Neutron");
         this.mappingService = mappingService;
     }
 
-    void unsetFlowMappingService(IFlowMapping mappingService) {
-        logger.debug("LispDAO was unset in LISP Neutron");
+    public void unsetMappingService(IFlowMapping mappingService) {
+        logger.debug("MappingService was unset in LISP Neutron");
         this.mappingService = null;
     }
 
-    public void init() {
-        logger.debug("LISP Neutron Service is initialized!");
-    }
-
-    public void start() {
-        logger.info("LISP Neutron Service is up!");
+ /*   protected IContainerManager containerManager;
 
-        // OSGI console
-        registerWithOSGIConsole();
+    public IContainerManager getContainerManager() {
+        return containerManager;
     }
 
-    private void registerWithOSGIConsole() {
-        BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
-        bundleContext.registerService(CommandProvider.class.getName(), this, null);
+    public void unsetContainerManager(IContainerManager s) {
+        if (s == this.containerManager) {
+            this.containerManager = null;
+        }
     }
 
+    public void setContainerManager(IContainerManager s) {
+        this.containerManager = s;
+    }
+*/
     public void stop() {
         logger.info("LISP Neutron Service is down!");
     }
@@ -59,42 +60,4 @@ public class LispNeutronService implements ILispNeutronService, INeutronNetworkA
         mappingService = null;
     }
 
-    // callbacks for INeutronNetworkAware. Based on OpenDove project
-
-    public int canCreateNetwork(NeutronNetwork network) {
-        logger.info("hello world!");
-        logger.info("canCreateNetwork called!");
-        logger.info("Network name: " + network.getNetworkName());
-        // if (network.getAdminStateUp() != null && !network.isAdminStateUp())
-        // return 400;
-        return 200;
-    }
-
-    public void neutronNetworkCreated(NeutronNetwork input) {
-        logger.info("neutronNetworkCreated called!");
-        return;
-    }
-
-    public int canUpdateNetwork(NeutronNetwork delta, NeutronNetwork original) {
-        logger.info("canUpdateNetwork called!");
-        if (delta.getNetworkName() != null || delta.getAdminStateUp() != null || delta.getShared() != null || delta.getRouterExternal() != null)
-            return 403;
-        return 200;
-    }
-
-    public void neutronNetworkUpdated(NeutronNetwork network) {
-        logger.info("neutronNetworkUpdated called!");
-        return;
-    }
-
-    public int canDeleteNetwork(NeutronNetwork network) {
-        logger.info("canDeleteNetwork called!");
-        return 200;
-    }
-
-    public void neutronNetworkDeleted(NeutronNetwork network) {
-        logger.info("neutronNetworkDeleted called!");
-        return;
-    }
-
 }
diff --git a/mappingservice/neutron/src/main/java/org/opendaylight/lispflowmapping/neutron/LispNeutronSubnetHandler.java b/mappingservice/neutron/src/main/java/org/opendaylight/lispflowmapping/neutron/LispNeutronSubnetHandler.java
new file mode 100644 (file)
index 0000000..63279b1
--- /dev/null
@@ -0,0 +1,209 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.lispflowmapping.neutron;
+
+
+import java.net.HttpURLConnection;
+
+import org.apache.commons.net.util.SubnetUtils;
+import org.apache.commons.net.util.SubnetUtils.SubnetInfo;
+import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetAware;
+import org.opendaylight.controller.networkconfig.neutron.NeutronSubnet;
+
+import org.opendaylight.controller.sal.utils.ServiceHelper;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.LispAFIAddress;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.LispAddressContainer;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.LispAddressContainerBuilder;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.lispaddresscontainer.Address;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.lispaddresscontainer.address.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+
+/**
+ * Lisp Service implementation of NeutronSubnetAware API
+ * Creation of a new Subnet results in defining the subnet as an EID prefix
+ * in the LISP Mapping System with subnet's network UUID as the key to use
+ * for registering mappings for the subnet.
+ *
+ */
+public class LispNeutronSubnetHandler extends LispNeutronService implements INeutronSubnetAware {
+
+       @Override
+       public int canCreateSubnet(NeutronSubnet subnet) {
+               logger.info("Neutron canCreateSubnet : Subnet name: " + subnet.getName() + " Subnet Cidr: " +
+                       subnet.getCidr());
+        logger.debug("Lisp Neutron Subnet: " + subnet.toString());
+
+        return HttpURLConnection.HTTP_OK;
+       }
+
+       /**
+        * Method adds the newly created subnet as an EID prefix to the
+        * MappingService. The subnet's network UUID is used as the key
+        * for this EID prefix.
+        *
+        */
+       @Override
+       public void neutronSubnetCreated(NeutronSubnet subnet) {
+               //TODO update for multi-tenancy
+
+               logger.info("Neutron Subnet Created request : Subnet name: " + subnet.getName() + " Subnet Cidr: " +
+                       subnet.getCidr());
+        logger.debug("Lisp Neutron Subnet: " + subnet.toString());
+
+           int masklen = Integer.parseInt(subnet.getCidr().split("/")[1]);
+           SubnetUtils util = new SubnetUtils(subnet.getCidr());
+        SubnetInfo info = util.getInfo();
+
+        // Determine the IANA code for the subnet IP version
+        // Default is set to IPv4 for neutron subnets
+
+        short ianaCode = 1;
+        if ( (new Integer(6)).equals(subnet.getIpVersion()) )
+               ianaCode = 2;
+
+        LispAFIAddress lispAddress = new Ipv4Builder().setIpv4Address(new Ipv4Address(info.getNetworkAddress())).setAfi(ianaCode).build();
+        LispAddressContainer addressContainer =        new LispAddressContainerBuilder().setAddress((Address) lispAddress).build();
+
+        ILispNeutronService lispService = (ILispNeutronService) ServiceHelper.getGlobalInstance(ILispNeutronService.class, this);
+
+        try{
+               lispService.getMappingService().addAuthenticationKey(addressContainer, masklen, subnet.getNetworkUUID());
+
+               logger.debug("Neutron Subnet Added to MapServer : Subnet name: " + subnet.getName() + " EID Prefix: " +
+                       addressContainer.toString() + " Key: " + subnet.getNetworkUUID());
+        }
+        catch (Exception e){
+               logger.error("Adding new subnet to lisp service mapping service failed. Subnet : " + subnet.toString());
+        }
+
+       }
+
+       /**
+        * Method to check whether new Subnet can be created by LISP
+        * implementation of Neutron service API.
+        * Since we store the Cidr part of the subnet as the main key to the Lisp
+        * mapping service, we do not support updates to subnets that change it's cidr.
+        */
+       @Override
+       public int canUpdateSubnet(NeutronSubnet delta, NeutronSubnet original) {
+               if (delta == null || original == null){
+               logger.error("Neutron canUpdateSubnet rejected: subnet objects were null");
+               return HttpURLConnection.HTTP_BAD_REQUEST;
+               }
+               logger.info("Neutron canUpdateSubnet : Subnet name: " + original.getName() + " Subnet Cidr: " +
+                       original.getCidr());
+        logger.debug("Lisp Neutron Subnet update: original : " + original.toString() + " delta : " + delta.toString());
+
+
+               // We do not accept a Subnet update that changes the cidr. If cider or network UUID is changed, return error.
+               if ( !(original.getCidr().equals(delta.getCidr())) ){
+                       logger.error("Neutron canUpdateSubnet rejected: Subnet name: " + original.getName() + " Subnet Cidr: " +
+                               original.getCidr());
+                       return HttpURLConnection.HTTP_CONFLICT;
+               }
+        return HttpURLConnection.HTTP_OK;
+       }
+
+       @Override
+       public void neutronSubnetUpdated(NeutronSubnet subnet) {
+               // Nothing to do here.
+       }
+
+       /**
+        * Method to check if subnet can be deleted.
+        * Returns error only if subnet does not exist
+        * in the lisp mapping service.
+        */
+       @Override
+       public int canDeleteSubnet(NeutronSubnet subnet) {
+        logger.info("Neutron canDeleteSubnet : Subnet name: " + subnet.getName() + " Subnet Cidr: " +
+                       subnet.getCidr() + "Key: " + subnet.getNetworkUUID());
+        logger.debug("Lisp Neutron Subnet: " + subnet.toString());
+
+        int result;
+           int masklen = Integer.parseInt(subnet.getCidr().split("/")[1]);
+           SubnetUtils util = new SubnetUtils(subnet.getCidr());
+        SubnetInfo info = util.getInfo();
+
+        // Determine the IANA code for the subnet IP version
+        // Default is set to IPv4 for neutron subnets
+        short ianaCode = 1;
+        if ( (new Integer(6)).equals(subnet.getIpVersion()) )
+               ianaCode = 2;
+
+        LispAFIAddress lispAddress = new Ipv4Builder().setIpv4Address(new Ipv4Address(info.getNetworkAddress())).setAfi(ianaCode).build();
+        LispAddressContainer addressContainer = new LispAddressContainerBuilder().setAddress((Address) lispAddress).build();
+
+        ILispNeutronService lispService = (ILispNeutronService) ServiceHelper.getGlobalInstance(ILispNeutronService.class, this);
+
+        // if subnet does not exist in MapServer, return error
+        try{
+               if (lispService.getMappingService().getAuthenticationKey(addressContainer, masklen) == null){
+
+                       logger.error("Neutron canDeleteSubnet rejected : Subnet does not exist: Subnet name: " +
+                                       subnet.getName() +
+                                       " Eid Prefix: " + addressContainer.toString() +
+                                       " Key: " + subnet.getNetworkUUID());
+                       return HttpURLConnection.HTTP_BAD_REQUEST;
+               }
+               result =  HttpURLConnection.HTTP_OK;
+        }
+        catch (Exception e){
+               logger.error("canDeleteSubnet request rejected. Subnet : " + subnet.toString());
+               result =  HttpURLConnection.HTTP_BAD_REQUEST;
+        }
+        return result;
+       }
+
+       /**
+        * Method removes the EID prefix and key associated
+        * with the deleted subnet from Lisp mapping service.
+        */
+       @Override
+       public void neutronSubnetDeleted(NeutronSubnet subnet) {
+               logger.info("Neutron Subnet Deleted Request : Subnet name: " + subnet.getName() + " Subnet Cidr: " +
+                       subnet.getCidr() + "Key: " + subnet.getNetworkUUID());
+        logger.debug("Lisp Neutron Subnet: " + subnet.toString());
+
+        int masklen = Integer.parseInt(subnet.getCidr().split("/")[1]);
+           SubnetUtils util = new SubnetUtils(subnet.getCidr());
+        SubnetInfo info = util.getInfo();
+
+        // Determine the IANA code for the subnet IP version
+        // Default is set to IPv4 for neutron subnets
+
+        short ianaCode = 1;
+        if ( (new Integer(6)).equals(subnet.getIpVersion()) )
+               ianaCode = 2;
+
+        LispAFIAddress lispAddress = new Ipv4Builder().setIpv4Address(new Ipv4Address(info.getNetworkAddress())).setAfi(ianaCode).build();
+        LispAddressContainer addressContainer = new LispAddressContainerBuilder().setAddress((Address) lispAddress).build();
+
+        try{
+               ILispNeutronService lispService = (ILispNeutronService) ServiceHelper.getGlobalInstance(ILispNeutronService.class, this);
+
+               // if subnet does not exist in MapServer, return error
+               if (lispService.getMappingService().getAuthenticationKey(addressContainer,masklen) == null){
+                   logger.error("Neutron Delete Subnet Failed: Subnet does not exist: Subnet name: " + subnet.getName() +
+                               " Eid Prefix: " + addressContainer.toString() +
+                               "Key: " + subnet.getNetworkUUID());
+                   return;
+               }
+               lispService.getMappingService().removeAuthenticationKey(addressContainer, masklen);
+
+               logger.debug("Neutron Subnet Deleted from MapServer : Subnet name: " + subnet.getName() +
+                               " Eid Prefix: " + addressContainer.toString() +
+                               " Key: " + subnet.getNetworkUUID());
+        }
+        catch (Exception e){
+               logger.error("Deleting subnet's EID prefix from mapping service failed + Subnet: " + subnet.toString());
+        }
+       }
+
+}