<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>
<artifactId>mappingservice.northbound</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.lispflowmapping</groupId>
+ <artifactId>mappingservice.neutron</artifactId>
+ </dependency>
+
</dependencies>
<build>
<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>
<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,
</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>
/*
- * 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,
package org.opendaylight.lispflowmapping.neutron;
+
import java.util.Dictionary;
import java.util.Hashtable;
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 {
/**
* 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
*/
@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) {
}
+
}
/*
- * 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,
import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping;
public interface ILispNeutronService {
-
+
public IFlowMapping getMappingService();
}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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());
+
+ }
+}
/*
- * 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!");
}
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;
- }
-
}
--- /dev/null
+/*
+ * 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());
+ }
+ }
+
+}