2 * Copyright (c) 2016 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
8 package org.opendaylight.lispflowmapping.neutron;
10 import java.util.concurrent.ExecutionException;
11 import java.util.concurrent.Future;
12 import org.apache.commons.lang3.exception.ExceptionUtils;
13 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddKeyInput;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.OdlMappingserviceService;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveKeyInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet;
19 import org.opendaylight.yangtools.yang.common.RpcResult;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * Lisp Service implementation of creation and deletion of a Subnet results
25 * in defining the subnet as an EID prefix in the LISP Mapping System with
26 * subnet's network UUID as the key to use for registering mappings for the subnet.
28 * @author Vina Ermagan
31 public class SubnetDataProcessor implements DataProcessor<Subnet> {
32 private static final Logger LOG = LoggerFactory.getLogger(SubnetDataProcessor.class);
33 // private static final Integer SIX = Integer.valueOf(6);
35 // The implementation for each of these services is resolved by the OSGi
37 private volatile ILispNeutronService lispNeutronService;
39 public SubnetDataProcessor(ILispNeutronService lispNeutronService) {
40 this.lispNeutronService = lispNeutronService;
44 * Method adds the newly created subnet as an EID prefix to the
45 * MappingService. The subnet's network UUID is used as the key for this EID
49 public void create(Subnet subnet) {
50 // TODO update for multi-tenancy
51 LOG.info("Neutron Subnet Created request : Subnet name: "
52 + subnet.getName() + " Subnet Cidr: " + subnet.getCidr());
53 LOG.debug("Lisp Neutron Subnet: " + subnet.toString());
55 // Determine the IANA code for the subnet IP version
56 // Default is set to IPv4 for neutron subnets
57 final Eid eid = LispAddressUtil.asIpv4PrefixEid(String.valueOf(subnet.getCidr().getValue()));
60 final OdlMappingserviceService lfmdb = lispNeutronService.getMappingDbService();
62 LOG.debug("lfmdb is null!!!");
65 final AddKeyInput addKeyInput = LispUtil.buildAddKeyInput(eid, subnet.getUuid().getValue());
66 final Future<RpcResult<Void>> result = lfmdb.addKey(addKeyInput);
67 final Boolean isSuccessful = result.get().isSuccessful();
70 LOG.debug("Neutron Subnet Added to MapServer : Subnet name: "
71 + subnet.getName() + " EID Prefix: "
72 + subnet.getCidr() + " Key: "
75 LOG.info("Neutron Subnet Created request : Subnet name: "
76 + subnet.getName() + " Subnet Cidr: " + subnet.getCidr());
77 } catch (InterruptedException | ExecutionException e) {
78 LOG.error("Adding new subnet to lisp service mapping service failed. Subnet : "
79 + subnet.toString() + "Error: " + ExceptionUtils.getStackTrace(e));
84 public void update(Subnet subnet) {
85 // Nothing to do here.
89 * Method removes the EID prefix and key associated with the deleted subnet
90 * from Lisp mapping service.
93 public void delete(Subnet subnet) {
94 LOG.info("Neutron Subnet Deleted Request : Subnet name: "
95 + subnet.getName() + " Subnet Cidr: " + subnet.getCidr()
96 + "Key: " + subnet.getUuid());
97 LOG.debug("Lisp Neutron Subnet: " + subnet.toString());
99 // Determine the IANA code for the subnet IP version
100 // Default is set to IPv4 for neutron subnets
101 final Eid eid = LispAddressUtil.asIpv4PrefixEid(String.valueOf(subnet.getCidr().getValue()));
104 final OdlMappingserviceService lfmdb = lispNeutronService.getMappingDbService();
106 LOG.debug("lfmdb is null!!!");
109 final RemoveKeyInput removeKeyInput = LispUtil.buildRemoveKeyInput(eid);
110 final Future<RpcResult<Void>> result = lfmdb.removeKey(removeKeyInput);
111 final Boolean isSuccessful = result.get().isSuccessful();
114 LOG.debug("Neutron Subnet Deleted from MapServer : Subnet name: "
115 + subnet.getName() + " Eid Prefix: "
116 + subnet.getCidr() + " Key: "
119 } catch (InterruptedException | ExecutionException e) {
120 LOG.error("Deleting subnet's EID prefix from mapping service failed + Subnet: "
121 + subnet.toString() + "Error: " + ExceptionUtils.getStackTrace(e));