Deprecate mappingservice.neutron
[lispflowmapping.git] / mappingservice / neutron / src / main / java / org / opendaylight / lispflowmapping / neutron / SubnetDataProcessor.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.lispflowmapping.neutron;
9
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;
24
25 /**
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.
29  *
30  * @author Vina Ermagan
31  *
32  */
33 @Deprecated
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);
37
38     // The implementation for each of these services is resolved by the OSGi
39     // Service Manager
40     private volatile ILispNeutronService lispNeutronService;
41
42     public SubnetDataProcessor(ILispNeutronService lispNeutronService) {
43         this.lispNeutronService = lispNeutronService;
44     }
45
46     /**
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
49      * prefix.
50      */
51     @Override
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());
57
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());
61
62         try {
63             final OdlMappingserviceService lfmdb = lispNeutronService.getMappingDbService();
64             if (lfmdb == null) {
65                 LOG.debug("lfmdb is null!!!");
66                 return;
67             }
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();
71
72             if (isSuccessful) {
73                 LOG.debug("Neutron Subnet Added to MapServer : Subnet name: "
74                         + subnet.getName() + " EID Prefix: "
75                         + subnet.getCidr() + " Key: "
76                         + subnet.getUuid());
77             }
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));
83         }
84     }
85
86     @Override
87     public void update(Subnet subnet) {
88         // Nothing to do here.
89     }
90
91     /**
92      * Method removes the EID prefix and key associated with the deleted subnet
93      * from Lisp mapping service.
94      */
95     @Override
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());
101
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());
105
106         try {
107             final OdlMappingserviceService lfmdb = lispNeutronService.getMappingDbService();
108             if (lfmdb == null) {
109                 LOG.debug("lfmdb is null!!!");
110                 return;
111             }
112             final RemoveKeyInput removeKeyInput = LispUtil.buildRemoveKeyInput(eid);
113             final Future<RpcResult<RemoveKeyOutput>> result = lfmdb.removeKey(removeKeyInput);
114             final Boolean isSuccessful = result.get().isSuccessful();
115
116             if (isSuccessful) {
117                 LOG.debug("Neutron Subnet Deleted from MapServer : Subnet name: "
118                         + subnet.getName() + " Eid Prefix: "
119                         + subnet.getCidr() + " Key: "
120                         + subnet.getUuid());
121             }
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));
125         }
126     }
127 }