Bug 3819: Fixing the inconsistency by using RPC to register 69/22969/3
authorVina Ermagan <vermagan@cisco.com>
Thu, 18 Jun 2015 20:18:04 +0000 (13:18 -0700)
committerVina Ermagan <vermagan@cisco.com>
Thu, 18 Jun 2015 22:44:50 +0000 (15:44 -0700)
Change-Id: Ib390645f507ff011d7596e72d8b85ac17eb3038c
Signed-off-by: Vina Ermagan <vermagan@cisco.com>
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/util/LispAFIConvertor.java
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/LispNeutronPortHandler.java
mappingservice/neutron/src/main/java/org/opendaylight/lispflowmapping/neutron/LispNeutronService.java
mappingservice/neutron/src/main/java/org/opendaylight/lispflowmapping/neutron/LispNeutronSubnetHandler.java
mappingservice/neutron/src/main/java/org/opendaylight/lispflowmapping/neutron/LispUtil.java [new file with mode: 0644]

index 07feb3dc36f53ad03b3aef22871cb35cff96ac65..a630dcf25fd61cb8599fa54c15e1ea4f94c62f42 100644 (file)
@@ -250,7 +250,8 @@ public class LispAFIConvertor {
     public static org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispaddress.lispaddresscontainer.address.distinguishedname.DistinguishedName asDistinguishedNameAddress(
             String distName) {
         return new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispaddress.lispaddresscontainer.address.distinguishedname.DistinguishedNameBuilder()
-                .setDistinguishedName(distName).build();
+            .setAfi(AddressFamilyNumberEnum.DISTINGUISHED_NAME.getIanaCode())
+            .setDistinguishedName(distName).build();
     }
 
     public static org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispaddress.lispaddresscontainer.address.ipv4.Ipv4Address asIPAfiAddress(
index b6f592a0adbd5555e972693b21294e4b2f09c03f..498468ab475f9d303032d13adc5331d5013483aa 100644 (file)
         <configuration>
           <instructions>
             <Export-Package></Export-Package>
-            <Import-Package>org.apache.commons.net.util,
+            <Import-Package>
+<!--               org.apache.commons.net.util,
               org.apache.felix.dm,
               org.opendaylight.neutron.spi,
+              org.opendaylight.controller.sal.binding.api,             
               org.opendaylight.lispflowmapping.type,
               org.opendaylight.lispflowmapping.type.lisp,
               org.opendaylight.lispflowmapping.type.lisp.address,
               org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispaddress,
               org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispaddress.lispaddresscontainer,
               org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispaddress.lispaddresscontainer.address,
+              org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.eidtolocatorrecords,
+              org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.locatorrecords, 
+              org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.mapregisternotification,  
+              org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mapping.database.rev150314,          
               org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924,
-              org.slf4j</Import-Package>
+              org.opendaylight.yangtools.yang.common,
+              org.slf4j            
+ -->           * </Import-Package>
             <Bundle-Activator>org.opendaylight.lispflowmapping.neutron.Activator</Bundle-Activator>
 
             <Export-Package></Export-Package>
index 60db7b597c5f956b759ef137f4750707decf19a6..8cf667b894c722fcdb57cba558699c635d313739 100644 (file)
@@ -14,6 +14,7 @@ import java.util.Hashtable;
 
 import org.apache.felix.dm.DependencyActivatorBase;
 import org.apache.felix.dm.DependencyManager;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
 import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping;
 import org.opendaylight.neutron.spi.INeutronNetworkAware;
 import org.opendaylight.neutron.spi.INeutronSubnetAware;
@@ -35,25 +36,28 @@ public class Activator extends DependencyActivatorBase {
     @Override
     public void init(BundleContext context, DependencyManager manager) throws Exception {
         Dictionary<String, String> props = new Hashtable<String, String>();
-        props.put("name", "mappingservice");
+        props.put("name", "LISPNeutronService");
 
         manager.add(createComponent()
-                .setInterface(ILispNeutronService.class.getName(), null)
+                .setInterface(new String[] { ILispNeutronService.class.getName()}, props)
                 .setImplementation(LispNeutronService.class)
-                .add(createServiceDependency().setService(IFlowMapping.class)));
+                .add(createServiceDependency().setService(IFlowMapping.class))
+                .add(createServiceDependency().setService(BindingAwareBroker.class)
+                .setCallbacks("setBindingAwareBroker", "unsetBindingAwareBroker")));
 
         manager.add(createComponent()
-                .setInterface(new String[] { ILispNeutronService.class.getName(), INeutronNetworkAware.class.getName()}, props)
+                .setInterface(new String[] {  INeutronNetworkAware.class.getName()}, props)
                 .setImplementation(LispNeutronNetworkHandler.class));
 
         manager.add(createComponent()
-                .setInterface(new String[] { ILispNeutronService.class.getName(), INeutronSubnetAware.class.getName()}, props)
+                .setInterface(new String[] {  INeutronSubnetAware.class.getName()}, props)
                 .setImplementation(LispNeutronSubnetHandler.class)
                 .add(createServiceDependency().setService(ILispNeutronService.class)));
 
         manager.add(createComponent()
-                .setInterface(new String[] { ILispNeutronService.class.getName(), INeutronPortAware.class.getName()}, props)
-                .setImplementation(LispNeutronPortHandler.class));
+                .setInterface(new String[] { INeutronPortAware.class.getName()}, props)
+                .setImplementation(LispNeutronPortHandler.class)
+                .add(createServiceDependency().setService(ILispNeutronService.class)));
 
         LOG.debug("LISP Neutron Service is initialized!");
 
index 912546efe45a39be0c54baf4ffe5ee13a19578bc..c099c3fb71787fe56821c89b0211a55a3ac611c7 100644 (file)
@@ -9,9 +9,12 @@
 package org.opendaylight.lispflowmapping.neutron;
 
 import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mapping.database.rev150314.LfmMappingDatabaseService;
 
 public interface ILispNeutronService {
 
        public IFlowMapping getMappingService();
 
+       public LfmMappingDatabaseService getMappingDbService();
+
 }
index db41646c34068019f23a8e99f075e02ba6154ea8..8973bfee549cd1bdbbc18d3521517207c6c0df84 100644 (file)
@@ -10,19 +10,20 @@ package org.opendaylight.lispflowmapping.neutron;
 
 import java.net.HttpURLConnection;
 import java.util.List;
+import java.util.concurrent.Future;
 
 import org.opendaylight.lispflowmapping.implementation.util.LispAFIConvertor;
-import org.opendaylight.lispflowmapping.implementation.util.MapServerMapResolverUtil;
 import org.opendaylight.neutron.spi.INeutronPortAware;
 import org.opendaylight.neutron.spi.NeutronPort;
 import org.opendaylight.neutron.spi.Neutron_IPs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.LispIpv4Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.MapRegister;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.MapReply;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.MapRequest;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.eidtolocatorrecords.EidToLocatorRecordBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.eidtolocatorrecords.EidToLocatorRecord;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispaddress.LispAddressContainer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.locatorrecords.LocatorRecord;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mapping.database.rev150314.GetMappingInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mapping.database.rev150314.GetMappingOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mapping.database.rev150314.LfmMappingDatabaseService;
+import org.opendaylight.yangtools.yang.common.RpcResult;
 
 /**
  * Lisp Service implementation of NeutronPortAware API Creation of a new port
@@ -31,236 +32,170 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314
  * required information to achieve the port's host_ip. Once such extension is
  * available this class shall be updated.
  *
+ * @author Vina Ermagan
+ *
  */
+
 public class LispNeutronPortHandler extends LispNeutronService implements
-               INeutronPortAware {
-
-       // The implementation for each of these services is resolved by the OSGi
-       // Service Manager
-       private volatile ILispNeutronService lispNeutronService;
-
-       // private static final Integer SIX = Integer.valueOf(6);
-
-       @Override
-       public int canCreatePort(NeutronPort port) {
-               LOG.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 , if Port.host_id mapping to
-               // host_ip exists in MS
-
-               LOG.info("Neutron Port Created: Port name: "
-                               + port.getName()
-                               + " Port Fixed IP: "
-                               + (port.getFixedIPs() != null ? port.getFixedIPs().get(0)
-                                               : "No Fixed IP assigned"));
-               LOG.debug("Neutron Port Created : " + port.toString());
-
-               // Check if port.hostID is in map-server, if it is, get host eidtoloc
-               // record?
-               if (port.getBindinghostID() == null) {
-                       LOG.error("Adding new Neutron port to lisp service mapping service failed. Port does not have Host_ID. Port : "
-                                       + port.toString());
-                       return;
-               }
-               // LispAFIAddress hostAddress =
-               // LispAFIConvertor.asDistinguishedNameAddress(port.getBindinghostID());
-               LispAFIAddress hostAddress = new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispaddress.lispaddresscontainer.address.distinguishedname.DistinguishedNameBuilder()
-                               .setDistinguishedName(port.getBindinghostID()).build();
-               MapRequest request = MapServerMapResolverUtil.getMapRequest(
-                               LispAFIConvertor.toContainer(hostAddress), (short) 0);
-
-               MapReply reply = lispNeutronService.getMappingService()
-                               .handleMapRequest(request, false);
-
-               if (reply == null) {
-                       LOG.error("Adding new Neutron port to lisp service mapping service failed. Host_ID mapping does not exist. Port : "
-                                       + port.toString());
-                       return;
-               }
-               // TODO for now only selecting the first EidToLocatorRecord from the
-               // Host_ID mapping
-               List<LocatorRecord> hostLocRecords = reply.getEidToLocatorRecord()
-                               .get(0).getLocatorRecord();
-
-               List<Neutron_IPs> fixedIPs = port.getFixedIPs();
-               if (fixedIPs != null && fixedIPs.size() > 0) {
-                       EidToLocatorRecordBuilder etlrBuilder;
-                       MapRegister mapRegister;
-                       LispIpv4Address eidAddress;
-                       for (Neutron_IPs ip : fixedIPs) {
-
-                               // TODO Add check/support for IPv6.
-                               // Get subnet for this port, based on v4 or v6 decide address
-                               // iana code.
-
-                               eidAddress = LispAFIConvertor.asIPAfiAddress(ip.getIpAddress());
-
-                               // Prepare Map Register
-                               etlrBuilder = new EidToLocatorRecordBuilder();
-                               etlrBuilder.setLispAddressContainer(LispAFIConvertor
-                                               .toContainer(eidAddress));
-                               etlrBuilder.setMaskLength((short) 32);
-                               etlrBuilder.setLocatorRecord(hostLocRecords);
-                               mapRegister = MapServerMapResolverUtil
-                                               .getMapRegister(etlrBuilder.build());
-                               LOG.info("Neutron Port mapping added to lisp: "
-                                               + " Port Fixed IP: " + ip + "Port host IP: "
-                                               + hostLocRecords.toString());
-
-                               // SMR is false, since we don't want to subscribe for SMRs
-                               // (that's for SB Map-Registers)
-                               lispNeutronService.getMappingService().handleMapRegister(
-                                               mapRegister, false);
-                       }
-               }
-       }
-
-       @Override
-       public int canUpdatePort(NeutronPort delta, NeutronPort original) {
-               // TODO Change of Fixed IPs are not allowed as we are storing ports by
-               // fixed IPs for now
-
-               if (original.getFixedIPs().equals(original.getFixedIPs())) {
-                       LOG.info("Neutron canUpdatePort : Port name: "
-                                       + original.getName()
-                                       + " Port Fixed IP: "
-                                       + (original.getFixedIPs() != null ? original.getFixedIPs()
-                                                       .get(0) : "No Fixed IP assigned")
-                                       + "New Port Fixed IP: "
-                                       + (delta.getFixedIPs() != null ? delta.getFixedIPs().get(0)
-                                                       : "No Fixed IP assigned"));
-                       LOG.debug("Neutron canUpdatePort : original" + original.toString()
-                                       + " delta : " + delta.toString());
-
-                       return HttpURLConnection.HTTP_OK;
-               }
-               return HttpURLConnection.HTTP_NOT_IMPLEMENTED;
-       }
-
-       @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.
-
-               LOG.info("Neutron Port updated: Port name: "
-                               + port.getName()
-                               + " Port Fixed IP: "
-                               + (port.getFixedIPs() != null ? port.getFixedIPs().get(0)
-                                               : "No Fixed IP assigned"));
-               LOG.debug("Neutron Port Updated : " + port.toString());
-
-               // Check if port.hostID is in map-server, if it is, get host eidtoloc
-               // record?
-               if (port.getBindinghostID() == null) {
-                       LOG.error("Updating Neutron port to lisp service mapping service failed. Port does not have Host_ID. Port : "
-                                       + port.toString());
-                       return;
-               }
-               // LispAFIAddress hostAddress =
-               // LispAFIConvertor.asDistinguishedNameAddress(port.getBindinghostID());
-               LispAFIAddress hostAddress = new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispaddress.lispaddresscontainer.address.distinguishedname.DistinguishedNameBuilder()
-                               .setDistinguishedName(port.getBindinghostID()).build();
-               MapRequest request = MapServerMapResolverUtil.getMapRequest(
-                               LispAFIConvertor.toContainer(hostAddress), (short) 0);
-
-               MapReply reply = lispNeutronService.getMappingService()
-                               .handleMapRequest(request, false);
-
-               if (reply == null) {
-                       LOG.error("Adding new Neutron port to lisp service mapping service failed. Host_ID mapping does not exist. Port : "
-                                       + port.toString());
-                       return;
-               }
-               // TODO for now only selecting the first EidToLocatorRecord from the
-               // Host_ID mapping
-               List<LocatorRecord> hostLocRecords = reply.getEidToLocatorRecord()
-                               .get(0).getLocatorRecord();
-
-               List<Neutron_IPs> fixedIPs = port.getFixedIPs();
-               if (fixedIPs != null && fixedIPs.size() > 0) {
-                       EidToLocatorRecordBuilder etlrBuilder;
-                       MapRegister mapRegister;
-                       LispIpv4Address eidAddress;
-                       for (Neutron_IPs ip : fixedIPs) {
-
-                               // TODO Add check/support for IPv6.
-                               // Get subnet for this port, based on v4 or v6 decide address
-                               // iana code.
-
-                               eidAddress = LispAFIConvertor.asIPAfiAddress(ip.getIpAddress());
-
-                               // Prepare Map Register
-                               etlrBuilder = new EidToLocatorRecordBuilder();
-                               etlrBuilder.setLispAddressContainer(LispAFIConvertor
-                                               .toContainer(eidAddress));
-                               etlrBuilder.setMaskLength((short) 32);
-                               etlrBuilder.setLocatorRecord(hostLocRecords);
-                               mapRegister = MapServerMapResolverUtil
-                                               .getMapRegister(etlrBuilder.build());
-                               LOG.info("Neutron Port mapping added to lisp: "
-                                               + " Port Fixed IP: " + ip + "Port host IP: "
-                                               + hostLocRecords.toString());
-
-                               // SMR is false, since we don't want to subscribe for SMRs
-                               // (that's for SB Map-Registers)
-                               lispNeutronService.getMappingService().handleMapRegister(
-                                               mapRegister, false);
-                       }
-               }
-
-       }
-
-       @Override
-       public int canDeletePort(NeutronPort port) {
-               // TODO Check if Port IPs are stored by Lisp Neutron Service. if not
-               // return error code.
-
-               LOG.info("Neutron canDeletePort : Port name: "
-                               + port.getName()
-                               + " Port Fixed IP: "
-                               + (port.getFixedIPs() != null ? port.getFixedIPs().get(0)
-                                               : "No Fixed IP assigned"));
-               LOG.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.
-
-               LOG.info("Neutron Port Deleted: Port name: "
-                               + port.getName()
-                               + " Port Fixed IP: "
-                               + (port.getFixedIPs() != null ? port.getFixedIPs().get(0)
-                                               : "No Fixed IP assigned"));
-               LOG.debug("Neutron Port Deleted : " + port.toString());
-
-               List<Neutron_IPs> fixedIPs = port.getFixedIPs();
-               if (fixedIPs != null && fixedIPs.size() > 0) {
-                       LispIpv4Address eidAddress;
-                       for (Neutron_IPs ip : fixedIPs) {
-
-                               // TODO Add check/support for IPv6.
-                               // Get subnet for this port, based on v4 or v6 decide address
-                               // iana code.
-
-                               eidAddress = LispAFIConvertor.asIPAfiAddress(ip.getIpAddress());
-                               lispNeutronService.getMappingService().removeMapping(
-                                               LispAFIConvertor.toContainer(eidAddress), (short) 32);
-
-                               LOG.info("Neutron Port mapping deleted from lisp: "
-                                               + " Port Fixed IP: " + ip + "Port host IP: ");
-
-                       }
-               }
-
-       }
+        INeutronPortAware {
+
+    // The implementation for each of these services is resolved by the OSGi
+    // Service Manager
+    private volatile ILispNeutronService lispNeutronService;
+
+    @Override
+    public int canCreatePort(NeutronPort port) {
+        LOG.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 , if Port.host_id mapping to
+        // host_ip exists in MS
+
+        LOG.debug("Neutron Port Created : " + port.toString());
+
+        // Check if port.hostID is in map-server, if it is, get host eidtoloc
+        // record?
+        if (port.getBindinghostID() == null) {
+            LOG.error("Adding new Neutron port to lisp service mapping service failed. Port does not have Host_ID. Port : "
+                    + port.toString());
+            return;
+        }
+        LispAFIAddress hostAddress = LispAFIConvertor.asDistinguishedNameAddress(port.getBindinghostID());
+
+        EidToLocatorRecord eidRecord;
+        List<LocatorRecord> hostLocRecords;
+        GetMappingInput input = LispUtil.buildGetMappingInput(LispAFIConvertor.toContainer(hostAddress), (short) 0);
+        try {
+            LfmMappingDatabaseService lfmdb = lispNeutronService.getMappingDbService();
+            if (lfmdb == null) {
+                LOG.debug("lfmdb is null!!!");
+                return;
+            }
+            Future<RpcResult<GetMappingOutput>> result = lfmdb.getMapping(input);
+            GetMappingOutput output = result.get().getResult();
+
+            // TODO for now only selecting the first EidToLocatorRecord from the
+            // Host_ID mapping
+
+            eidRecord = output.getEidToLocatorRecord().get(0);
+            hostLocRecords = eidRecord.getLocatorRecord();
+            LOG.debug("hostLocRecords is : {}",hostLocRecords);
+
+
+        } catch (Exception e) {
+            LOG.warn("Failed to GET mapping for EID {}: , mappingInput: {} , Exception: {}", hostAddress, input, e);
+            return;
+        }
+
+        List<Neutron_IPs> fixedIPs = port.getFixedIPs();
+        if (fixedIPs != null && fixedIPs.size() > 0) {
+          LispAddressContainer eidAddress;
+            for (Neutron_IPs ip : fixedIPs) {
+
+                // TODO Add check/support for IPv6.
+                // Get subnet for this port, based on v4 or v6 decide address
+                // iana code.
+
+                eidAddress = LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress(ip.getIpAddress()));
+                lispNeutronService.getMappingDbService().addMapping(LispUtil.buildAddMappingInput(eidAddress, hostLocRecords, 32));
+            }
+        }
+
+        LOG.info("Neutron Port Created: Port name: "
+                    + port.getName()
+                    + " Port Fixed IP: "
+                    + (port.getFixedIPs() != null ? port.getFixedIPs().get(0)
+                            : "No Fixed IP assigned"));
+
+    }
+
+    @Override
+    public int canUpdatePort(NeutronPort delta, NeutronPort original) {
+        // TODO Change of Fixed IPs are not allowed as we are storing ports by
+        // fixed IPs for now
+
+        if (original.getFixedIPs().equals(original.getFixedIPs())) {
+            LOG.info("Neutron canUpdatePort : Port name: "
+                    + original.getName()
+                    + " Port Fixed IP: "
+                    + (original.getFixedIPs() != null ? original.getFixedIPs()
+                            .get(0) : "No Fixed IP assigned")
+                    + "New Port Fixed IP: "
+                    + (delta.getFixedIPs() != null ? delta.getFixedIPs().get(0)
+                            : "No Fixed IP assigned"));
+            LOG.debug("Neutron canUpdatePort : original" + original.toString()
+                    + " delta : " + delta.toString());
+
+            return HttpURLConnection.HTTP_OK;
+        }
+        return HttpURLConnection.HTTP_NOT_IMPLEMENTED;
+    }
+
+    @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.
+
+        LOG.info("Neutron Port updated: Port name: "
+                + port.getName()
+                + " Port Fixed IP: "
+                + (port.getFixedIPs() != null ? port.getFixedIPs().get(0)
+                        : "No Fixed IP assigned"));
+        LOG.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.
+
+        LOG.info("Neutron canDeletePort : Port name: "
+                + port.getName()
+                + " Port Fixed IP: "
+                + (port.getFixedIPs() != null ? port.getFixedIPs().get(0)
+                        : "No Fixed IP assigned"));
+        LOG.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.
+
+        LOG.info("Neutron Port Deleted: Port name: "
+                + port.getName()
+                + " Port Fixed IP: "
+                + (port.getFixedIPs() != null ? port.getFixedIPs().get(0)
+                        : "No Fixed IP assigned"));
+        LOG.debug("Neutron Port Deleted : " + port.toString());
+
+        List<Neutron_IPs> fixedIPs = port.getFixedIPs();
+        if (fixedIPs != null && fixedIPs.size() > 0) {
+            LispAddressContainer eidAddress;
+
+            for (Neutron_IPs ip : fixedIPs) {
+
+                // TODO Add check/support for IPv6.
+                // Get subnet for this port, based on v4 or v6 decide address
+                // iana code.
+
+                eidAddress = LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress(ip.getIpAddress()));
+                lispNeutronService.getMappingDbService().removeMapping(LispUtil.buildRemoveMappingInput(eidAddress,32));
+
+                LOG.info("Neutron Port mapping deleted from lisp: "
+                        + " Port Fixed IP: " + ip + "Port host IP: ");
+
+            }
+        }
+
+    }
+
 }
index c8691e061e6c537e72f76312a33cf859cf376709..a1bb08cea591881083bb92d5e4fa326fa5dba748 100644 (file)
@@ -11,19 +11,45 @@ package org.opendaylight.lispflowmapping.neutron;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mapping.database.rev150314.LfmMappingDatabaseService;
 
 
-
-public class LispNeutronService implements ILispNeutronService {
+public class LispNeutronService implements ILispNeutronService, BindingAwareProvider  {
 
        protected static final Logger LOG = LoggerFactory.getLogger(LispNeutronService.class);
-    protected IFlowMapping mappingService;
+    private IFlowMapping mappingService;
+    private LfmMappingDatabaseService lfmDbService;
+    private static ILispNeutronService neutronService;
+
+
+    void setBindingAwareBroker(BindingAwareBroker bindingAwareBroker) {
+        LOG.debug("LISP NEUTRON BindingAwareBroker set!");
+        bindingAwareBroker.registerProvider(this);
+        neutronService = this;
+    }
+
+    void unsetBindingAwareBroker(BindingAwareBroker bindingAwareBroker) {
+
+    }
+
+    public static ILispNeutronService getLispNeutronService() {
+        return neutronService;
+    }
+
 
     public IFlowMapping getMappingService() {
         return this.mappingService;
     }
 
+    public LfmMappingDatabaseService getMappingDbService() {
+        return this.lfmDbService;
+    }
+
     public void setMappingService(IFlowMapping mappingService) {
         LOG.debug("MappingService set in Lisp Neutron");
         this.mappingService = mappingService;
@@ -34,22 +60,15 @@ public class LispNeutronService implements ILispNeutronService {
         this.mappingService = null;
     }
 
- /*   protected IContainerManager containerManager;
+    @Override
+    public void onSessionInitiated(ProviderContext session) {
+        LOG.debug("LFMDBSERVICE IS BEING FILLED! SESSION INITIATED");
+        RpcProviderRegistry rpcRegistry = session.getSALService(RpcProviderRegistry.class);
+        lfmDbService = rpcRegistry.getRpcService(LfmMappingDatabaseService.class);
+        LOG.debug("LFMDBSERVICE was FILLED! SESSION INITIATED");
 
-    public IContainerManager getContainerManager() {
-        return containerManager;
     }
 
-    public void unsetContainerManager(IContainerManager s) {
-        if (s == this.containerManager) {
-            this.containerManager = null;
-        }
-    }
-
-    public void setContainerManager(IContainerManager s) {
-        this.containerManager = s;
-    }
-*/
     public void stop() {
         LOG.info("LISP Neutron Service is down!");
     }
index 0ffd90a150cf9c47ff0cd9d76db8498613341ff6..ee45782bc196aa65fab1c0ea130cae94d5ddf5bc 100644 (file)
@@ -17,10 +17,6 @@ import org.opendaylight.neutron.spi.INeutronSubnetAware;
 import org.opendaylight.neutron.spi.NeutronSubnet;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.LispAFIAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispaddress.LispAddressContainer;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispaddress.LispAddressContainerBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispaddress.lispaddresscontainer.Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispaddress.lispaddresscontainer.address.ipv4.Ipv4AddressBuilder;
-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
@@ -28,6 +24,8 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
  * System with subnet's network UUID as the key to use for registering mappings
  * for the subnet.
  *
+ * @author Vina Ermagan
+ *
  */
 public class LispNeutronSubnetHandler extends LispNeutronService implements
                INeutronSubnetAware {
@@ -69,19 +67,12 @@ public class LispNeutronSubnetHandler extends LispNeutronService implements
                // Determine the IANA code for the subnet IP version
                // Default is set to IPv4 for neutron subnets
 
-               short ianaCode = 1;
-               if (SIX.equals(subnet.getIpVersion())) {
-                       ianaCode = 2;
-                       LOG.error("Adding new subnet to lisp mapping service failed. No support for IPv6 addresses. Subnet : "
-                                       + subnet.toString());
-                       return;
-               }
                LispAFIAddress lispAddress = LispAFIConvertor.asIPAfiAddress(info.getNetworkAddress());
                LispAddressContainer addressContainer = LispAFIConvertor.toContainer(lispAddress);
 
                try {
-                       lispNeutronService.getMappingService().addAuthenticationKey(
-                                       addressContainer, masklen, subnet.getNetworkUUID());
+
+            lispNeutronService.getMappingDbService().addKey((LispUtil.buildAddKeyInput(addressContainer,subnet.getNetworkUUID(), masklen)));
 
                        LOG.debug("Neutron Subnet Added to MapServer : Subnet name: "
                                        + subnet.getName() + " EID Prefix: "
@@ -89,8 +80,10 @@ public class LispNeutronSubnetHandler extends LispNeutronService implements
                                        + subnet.getNetworkUUID());
                } catch (Exception e) {
                        LOG.error("Adding new subnet to lisp service mapping service failed. Subnet : "
-                                       + subnet.toString());
+                                       + subnet.toString() + "Error: "+ e);
                }
+        LOG.info("Neutron Subnet Created request : Subnet name: "
+                + subnet.getName() + " Subnet Cidr: " + subnet.getCidr());
 
        }
 
@@ -138,43 +131,8 @@ public class LispNeutronSubnetHandler extends LispNeutronService implements
                                + subnet.getNetworkUUID());
                LOG.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 (SIX.equals(subnet.getIpVersion()))
-                       ianaCode = 2;
 
-               LispAFIAddress lispAddress = new Ipv4AddressBuilder()
-                               .setIpv4Address(new Ipv4Address(info.getNetworkAddress()))
-                               .setAfi(ianaCode).build();
-               LispAddressContainer addressContainer = new LispAddressContainerBuilder()
-                               .setAddress((Address) lispAddress).build();
-
-               // if subnet does not exist in MapServer, return error
-               try {
-                       if (lispNeutronService.getMappingService().getAuthenticationKey(
-                                       addressContainer, masklen) == null) {
-
-                               LOG.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) {
-                       LOG.error("canDeleteSubnet request rejected. Subnet : "
-                                       + subnet.toString());
-                       result = HttpURLConnection.HTTP_BAD_REQUEST;
-               }
-               return result;
+                       return HttpURLConnection.HTTP_OK;
        }
 
        /**
@@ -195,30 +153,12 @@ public class LispNeutronSubnetHandler extends LispNeutronService implements
                // Determine the IANA code for the subnet IP version
                // Default is set to IPv4 for neutron subnets
 
-               short ianaCode = 1;
-               if (SIX.equals(subnet.getIpVersion()))
-                       ianaCode = 2;
+        LispAFIAddress lispAddress = LispAFIConvertor.asIPAfiAddress(info.getNetworkAddress());
+        LispAddressContainer addressContainer = LispAFIConvertor.toContainer(lispAddress);
 
-               LispAFIAddress lispAddress = new Ipv4AddressBuilder()
-                               .setIpv4Address(new Ipv4Address(info.getNetworkAddress()))
-                               .setAfi(ianaCode).build();
-               LispAddressContainer addressContainer = new LispAddressContainerBuilder()
-                               .setAddress((Address) lispAddress).build();
+        try {
 
-               try {
-                       // if subnet does not exist in MapServer, return error
-                       if (lispNeutronService.getMappingService().getAuthenticationKey(
-                                       addressContainer, masklen) == null) {
-                               LOG.error("Neutron Delete Subnet Failed: Subnet does not exist: Subnet name: "
-                                               + subnet.getName()
-                                               + " Eid Prefix: "
-                                               + addressContainer.toString()
-                                               + "Key: "
-                                               + subnet.getNetworkUUID());
-                               return;
-                       }
-                       lispNeutronService.getMappingService().removeAuthenticationKey(
-                                       addressContainer, masklen);
+            lispNeutronService.getMappingDbService().removeKey(LispUtil.buildRemoveKeyInput(addressContainer, masklen));
 
                        LOG.debug("Neutron Subnet Deleted from MapServer : Subnet name: "
                                        + subnet.getName() + " Eid Prefix: "
diff --git a/mappingservice/neutron/src/main/java/org/opendaylight/lispflowmapping/neutron/LispUtil.java b/mappingservice/neutron/src/main/java/org/opendaylight/lispflowmapping/neutron/LispUtil.java
new file mode 100644 (file)
index 0000000..ddfef53
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2014, 2015 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 java.util.List;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.EidToLocatorRecord.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispaddress.LispAddressContainer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.locatorrecords.LocatorRecord;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mapping.database.rev150314.AddKeyInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mapping.database.rev150314.AddKeyInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mapping.database.rev150314.AddMappingInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mapping.database.rev150314.AddMappingInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mapping.database.rev150314.GetMappingInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mapping.database.rev150314.GetMappingInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mapping.database.rev150314.RemoveKeyInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mapping.database.rev150314.RemoveKeyInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mapping.database.rev150314.RemoveMappingInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mapping.database.rev150314.RemoveMappingInputBuilder;
+
+/**
+ * LispUtil class has util functions for building inputs for LISP service RPCs.
+ *
+ *
+ *
+ */
+
+
+public class LispUtil {
+
+  //  private static final Logger LOG = LoggerFactory.getLogger(LispUtil.class);
+
+    public static AddMappingInput buildAddMappingInput(LispAddressContainer eid, List<LocatorRecord> locators, int mask) {
+        AddMappingInputBuilder mib = new AddMappingInputBuilder();
+
+        mib.setAction(Action.NoAction).setAuthoritative(true).setLispAddressContainer(eid)
+                .setLocatorRecord(locators).setMapVersion((short) 0).setMaskLength((short) mask)
+                .setRecordTtl(1440);
+        return mib.build();
+    }
+
+    public static AddKeyInput buildAddKeyInput(LispAddressContainer eid, String net, int mask) {
+        AddKeyInputBuilder kib = new AddKeyInputBuilder();
+
+        kib.setLispAddressContainer(eid).setAuthkey(net).setMaskLength((short)mask).setKeyType(1);
+        return kib.build();
+    }
+
+    public static GetMappingInput buildGetMappingInput(LispAddressContainer eid, short mask) {
+        return new GetMappingInputBuilder().setLispAddressContainer(eid).setMaskLength(mask).build();
+    }
+
+    public static RemoveMappingInput buildRemoveMappingInput(LispAddressContainer eid, int mask) {
+        RemoveMappingInputBuilder rmib = new RemoveMappingInputBuilder();
+        rmib.setLispAddressContainer(eid).setMaskLength((short)mask);
+        return rmib.build();
+    }
+    public static RemoveKeyInput buildRemoveKeyInput(LispAddressContainer eid, int mask) {
+        RemoveKeyInputBuilder kib = new RemoveKeyInputBuilder();
+
+        kib.setLispAddressContainer(eid).setMaskLength((short)mask);
+        return kib.build();
+    }
+}
\ No newline at end of file