c9ee16614916949609e0e89021754c2fa6e0c5fb
[genius.git] / interfacemanager / interfacemanager-impl / src / main / java / org / opendaylight / genius / interfacemanager / renderer / hwvtep / confighelpers / HwVTEPConfigRemoveHelper.java
1 /*
2  * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others.  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.genius.interfacemanager.renderer.hwvtep.confighelpers;
9
10 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
11 import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
12
13 import com.google.common.util.concurrent.ListenableFuture;
14 import java.util.ArrayList;
15 import java.util.List;
16 import org.opendaylight.genius.infra.Datastore.Configuration;
17 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
18 import org.opendaylight.genius.infra.TypedWriteTransaction;
19 import org.opendaylight.genius.interfacemanager.commons.InterfaceManagerCommonUtils;
20 import org.opendaylight.genius.interfacemanager.commons.InterfaceMetaUtils;
21 import org.opendaylight.genius.interfacemanager.renderer.hwvtep.utilities.SouthboundUtils;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 public final class HwVTEPConfigRemoveHelper {
32     private static final Logger LOG = LoggerFactory.getLogger(HwVTEPConfigRemoveHelper.class);
33
34     private HwVTEPConfigRemoveHelper() {
35     }
36
37     public static List<ListenableFuture<Void>> removeConfiguration(ManagedNewTransactionRunner txRunner,
38                                                                    Interface interfaceOld,
39                                                                    InstanceIdentifier<Node> physicalSwitchNodeId,
40                                                                    InstanceIdentifier<Node> globalNodeId) {
41         List<ListenableFuture<Void>> futures = new ArrayList<>();
42         LOG.info("removing hwvtep configuration for {}", interfaceOld.getName());
43         if (globalNodeId != null) {
44             IfTunnel ifTunnel = interfaceOld.augmentation(IfTunnel.class);
45             //removeTunnelTableEntry(defaultOperShardTransaction, ifTunnel, physicalSwitchNodeId);
46             // Topology configuration shard
47             futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
48                 tx -> removeTerminationEndPoint(tx, ifTunnel, globalNodeId)));
49             // Default operational shard
50             futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> {
51                     InterfaceManagerCommonUtils.deleteStateEntry(tx, interfaceOld.getName());
52                     InterfaceMetaUtils.removeTunnelToInterfaceMap(physicalSwitchNodeId, tx, ifTunnel);
53                 }
54             ));
55         }
56         return futures;
57     }
58
59     private static void removeTerminationEndPoint(TypedWriteTransaction<Configuration> transaction, IfTunnel ifTunnel,
60             InstanceIdentifier<Node> globalNodeId) {
61         LOG.info("removing remote termination end point {}", ifTunnel.getTunnelDestination());
62         TerminationPointKey tpKey = SouthboundUtils
63                 .getTerminationPointKey(ifTunnel.getTunnelDestination().getIpv4Address().getValue());
64         InstanceIdentifier<TerminationPoint> tpPath = SouthboundUtils.createInstanceIdentifier(globalNodeId, tpKey);
65         transaction.delete(tpPath);
66     }
67 }