Bug 5064 - Deletion of tunnel interfaces not removing the TEP from switch
[vpnservice.git] / interfacemgr / interfacemgr-impl / src / main / java / org / opendaylight / vpnservice / interfacemgr / renderer / ovs / statehelpers / OvsInterfaceTopologyStateRemoveHelper.java
1 /*
2  * Copyright (c) 2015 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.vpnservice.interfacemgr.renderer.ovs.statehelpers;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.vpnservice.interfacemgr.IfmUtil;
15 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils;
16 import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.utilities.SouthboundUtils;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge.ref.info.BridgeRefEntry;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge.ref.info.BridgeRefEntryKey;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 import java.math.BigInteger;
25 import java.util.ArrayList;
26 import java.util.List;
27
28 public class OvsInterfaceTopologyStateRemoveHelper {
29     private static final Logger LOG = LoggerFactory.getLogger(OvsInterfaceTopologyStateRemoveHelper.class);
30
31     public static List<ListenableFuture<Void>> removePortFromBridge(InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid,
32                                                                OvsdbBridgeAugmentation bridgeOld, DataBroker dataBroker) {
33         List<ListenableFuture<Void>> futures = new ArrayList<>();
34         WriteTransaction t = dataBroker.newWriteOnlyTransaction();;
35         BigInteger dpnId = IfmUtil.getDpnId(bridgeOld.getDatapathId());
36
37         if (dpnId == null) {
38             LOG.warn("Got Null DPID for Bridge: {}", bridgeOld);
39             return futures;
40         }
41         BridgeRefEntryKey bridgeRefEntryKey = new BridgeRefEntryKey(dpnId);
42         InstanceIdentifier<BridgeRefEntry> bridgeEntryId =
43                 InterfaceMetaUtils.getBridgeRefEntryIdentifier(bridgeRefEntryKey);
44         t.delete(LogicalDatastoreType.OPERATIONAL, bridgeEntryId);
45
46         // FIX for ovsdb bug for delete TEP
47         SouthboundUtils.deleteBridge(bridgeIid, dataBroker, futures);
48
49         futures.add(t.submit());
50         return futures;
51     }
52 }