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.AddKeyOutput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.OdlMappingserviceService;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveKeyInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveKeyOutput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet;
21 import org.opendaylight.yangtools.yang.common.RpcResult;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * Lisp Service implementation of creation and deletion of a Subnet results
27 * in defining the subnet as an EID prefix in the LISP Mapping System with
28 * subnet's network UUID as the key to use for registering mappings for the subnet.
30 * @author Vina Ermagan
34 public class SubnetDataProcessor implements DataProcessor<Subnet> {
35 private static final Logger LOG = LoggerFactory.getLogger(SubnetDataProcessor.class);
36 // private static final Integer SIX = Integer.valueOf(6);
38 // The implementation for each of these services is resolved by the OSGi
40 private volatile ILispNeutronService lispNeutronService;
42 public SubnetDataProcessor(ILispNeutronService lispNeutronService) {
43 this.lispNeutronService = lispNeutronService;
47 * Method adds the newly created subnet as an EID prefix to the
48 * MappingService. The subnet's network UUID is used as the key for this EID
52 public void create(Subnet subnet) {
53 // TODO update for multi-tenancy
54 LOG.info("Neutron Subnet Created request : Subnet name: "
55 + subnet.getName() + " Subnet Cidr: " + subnet.getCidr());
56 LOG.debug("Lisp Neutron Subnet: " + subnet.toString());
58 // Determine the IANA code for the subnet IP version
59 // Default is set to IPv4 for neutron subnets
60 final Eid eid = LispAddressUtil.asIpv4PrefixEid(subnet.getCidr().stringValue());
63 final OdlMappingserviceService lfmdb = lispNeutronService.getMappingDbService();
65 LOG.debug("lfmdb is null!!!");
68 final AddKeyInput addKeyInput = LispUtil.buildAddKeyInput(eid, subnet.getUuid().getValue());
69 final Future<RpcResult<AddKeyOutput>> result = lfmdb.addKey(addKeyInput);
70 final Boolean isSuccessful = result.get().isSuccessful();
73 LOG.debug("Neutron Subnet Added to MapServer : Subnet name: "
74 + subnet.getName() + " EID Prefix: "
75 + subnet.getCidr() + " Key: "
78 LOG.info("Neutron Subnet Created request : Subnet name: "
79 + subnet.getName() + " Subnet Cidr: " + subnet.getCidr());
80 } catch (InterruptedException | ExecutionException e) {
81 LOG.error("Adding new subnet to lisp service mapping service failed. Subnet : "
82 + subnet.toString() + "Error: " + ExceptionUtils.getStackTrace(e));
87 public void update(Subnet subnet) {
88 // Nothing to do here.
92 * Method removes the EID prefix and key associated with the deleted subnet
93 * from Lisp mapping service.
96 public void delete(Subnet subnet) {
97 LOG.info("Neutron Subnet Deleted Request : Subnet name: "
98 + subnet.getName() + " Subnet Cidr: " + subnet.getCidr()
99 + "Key: " + subnet.getUuid());
100 LOG.debug("Lisp Neutron Subnet: " + subnet.toString());
102 // Determine the IANA code for the subnet IP version
103 // Default is set to IPv4 for neutron subnets
104 final Eid eid = LispAddressUtil.asIpv4PrefixEid(subnet.getCidr().stringValue());
107 final OdlMappingserviceService lfmdb = lispNeutronService.getMappingDbService();
109 LOG.debug("lfmdb is null!!!");
112 final RemoveKeyInput removeKeyInput = LispUtil.buildRemoveKeyInput(eid);
113 final Future<RpcResult<RemoveKeyOutput>> result = lfmdb.removeKey(removeKeyInput);
114 final Boolean isSuccessful = result.get().isSuccessful();
117 LOG.debug("Neutron Subnet Deleted from MapServer : Subnet name: "
118 + subnet.getName() + " Eid Prefix: "
119 + subnet.getCidr() + " Key: "
122 } catch (InterruptedException | ExecutionException e) {
123 LOG.error("Deleting subnet's EID prefix from mapping service failed + Subnet: "
124 + subnet.toString() + "Error: " + ExceptionUtils.getStackTrace(e));