2 * Copyright (c) 2014 Cisco Systems, Inc. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.lispflowmapping.neutron;
11 import java.net.HttpURLConnection;
13 import org.apache.commons.lang3.exception.ExceptionUtils;
14 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
15 import org.opendaylight.neutron.spi.INeutronSubnetAware;
16 import org.opendaylight.neutron.spi.NeutronSubnet;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
20 * Lisp Service implementation of NeutronSubnetAware API Creation of a new
21 * Subnet results in defining the subnet as an EID prefix in the LISP Mapping
22 * System with subnet's network UUID as the key to use for registering mappings
25 * @author Vina Ermagan
28 public class LispNeutronSubnetHandler extends LispNeutronService implements
30 private static final Integer SIX = Integer.valueOf(6);
32 // The implementation for each of these services is resolved by the OSGi
34 private volatile ILispNeutronService lispNeutronService;
37 public int canCreateSubnet(NeutronSubnet subnet) {
38 LOG.info("Neutron canCreateSubnet : Subnet name: " + subnet.getName()
39 + " Subnet Cidr: " + subnet.getCidr());
40 LOG.debug("Lisp Neutron Subnet: " + subnet.toString());
41 if (SIX.equals(subnet.getIpVersion())) {
42 return HttpURLConnection.HTTP_PARTIAL;
44 return HttpURLConnection.HTTP_OK;
48 * Method adds the newly created subnet as an EID prefix to the
49 * MappingService. The subnet's network UUID is used as the key for this EID
54 public void neutronSubnetCreated(NeutronSubnet subnet) {
55 // TODO update for multi-tenancy
57 LOG.info("Neutron Subnet Created request : Subnet name: "
58 + subnet.getName() + " Subnet Cidr: " + subnet.getCidr());
59 LOG.debug("Lisp Neutron Subnet: " + subnet.toString());
61 // Determine the IANA code for the subnet IP version
62 // Default is set to IPv4 for neutron subnets
64 Eid eid = LispAddressUtil.asIpv4PrefixEid(subnet.getCidr());
68 lispNeutronService.getMappingDbService().addKey(LispUtil.buildAddKeyInput(eid, subnet.getNetworkUUID()));
70 LOG.debug("Neutron Subnet Added to MapServer : Subnet name: "
71 + subnet.getName() + " EID Prefix: "
72 + subnet.getCidr() + " Key: "
73 + subnet.getNetworkUUID());
74 } catch (Exception e) {
75 LOG.error("Adding new subnet to lisp service mapping service failed. Subnet : "
76 + subnet.toString() + "Error: " + ExceptionUtils.getStackTrace(e));
78 LOG.info("Neutron Subnet Created request : Subnet name: "
79 + subnet.getName() + " Subnet Cidr: " + subnet.getCidr());
84 * Method to check whether new Subnet can be created by LISP implementation
85 * of Neutron service API. Since we store the Cidr part of the subnet as the
86 * main key to the Lisp mapping service, we do not support updates to
87 * subnets that change it's cidr.
90 public int canUpdateSubnet(NeutronSubnet delta, NeutronSubnet original) {
91 if (delta == null || original == null) {
92 LOG.error("Neutron canUpdateSubnet rejected: subnet objects were null");
93 return HttpURLConnection.HTTP_BAD_REQUEST;
95 LOG.info("Neutron canUpdateSubnet : Subnet name: " + original.getName()
96 + " Subnet Cidr: " + original.getCidr());
97 LOG.debug("Lisp Neutron Subnet update: original : "
98 + original.toString() + " delta : " + delta.toString());
100 // We do not accept a Subnet update that changes the cidr. If cider or
101 // network UUID is changed, return error.
102 if (!(original.getCidr().equals(delta.getCidr()))) {
103 LOG.error("Neutron canUpdateSubnet rejected: Subnet name: "
104 + original.getName() + " Subnet Cidr: "
105 + original.getCidr());
106 return HttpURLConnection.HTTP_CONFLICT;
108 return HttpURLConnection.HTTP_OK;
112 public void neutronSubnetUpdated(NeutronSubnet subnet) {
113 // Nothing to do here.
117 * Method to check if subnet can be deleted. Returns error only if subnet
118 * does not exist in the lisp mapping service.
121 public int canDeleteSubnet(NeutronSubnet subnet) {
122 LOG.info("Neutron canDeleteSubnet : Subnet name: " + subnet.getName()
123 + " Subnet Cidr: " + subnet.getCidr() + "Key: "
124 + subnet.getNetworkUUID());
125 LOG.debug("Lisp Neutron Subnet: " + subnet.toString());
128 return HttpURLConnection.HTTP_OK;
132 * Method removes the EID prefix and key associated with the deleted subnet
133 * from Lisp mapping service.
136 public void neutronSubnetDeleted(NeutronSubnet subnet) {
137 LOG.info("Neutron Subnet Deleted Request : Subnet name: "
138 + subnet.getName() + " Subnet Cidr: " + subnet.getCidr()
139 + "Key: " + subnet.getNetworkUUID());
140 LOG.debug("Lisp Neutron Subnet: " + subnet.toString());
142 // Determine the IANA code for the subnet IP version
143 // Default is set to IPv4 for neutron subnets
145 Eid eid = LispAddressUtil.asIpv4PrefixEid(subnet.getCidr());
149 lispNeutronService.getMappingDbService().removeKey(LispUtil.buildRemoveKeyInput(eid));
151 LOG.debug("Neutron Subnet Deleted from MapServer : Subnet name: "
152 + subnet.getName() + " Eid Prefix: "
153 + subnet.getCidr() + " Key: "
154 + subnet.getNetworkUUID());
155 } catch (Exception e) {
156 LOG.error("Deleting subnet's EID prefix from mapping service failed + Subnet: "
157 + subnet.toString() + "Error: " + ExceptionUtils.getStackTrace(e));