Merge "Make ActionInfo immutable"
[genius.git] / interfacemanager / interfacemanager-impl / src / main / java / org / opendaylight / genius / interfacemanager / renderer / ovs / statehelpers / OvsInterfaceTopologyStateRemoveHelper.java
1 /*
2  * Copyright (c) 2016 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.ovs.statehelpers;
9
10 import com.google.common.base.Optional;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.genius.interfacemanager.IfmUtil;
16 import org.opendaylight.genius.interfacemanager.commons.InterfaceMetaUtils;
17 import org.opendaylight.genius.interfacemanager.renderer.ovs.utilities.SouthboundUtils;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.bridge._interface.info.BridgeEntry;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeRef;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 import java.math.BigInteger;
26 import java.util.ArrayList;
27 import java.util.List;
28
29 public class OvsInterfaceTopologyStateRemoveHelper {
30     private static final Logger LOG = LoggerFactory.getLogger(OvsInterfaceTopologyStateRemoveHelper.class);
31
32     public static List<ListenableFuture<Void>> removePortFromBridge(InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid,
33                                                                     OvsdbBridgeAugmentation bridgeOld, DataBroker dataBroker) {
34         List<ListenableFuture<Void>> futures = new ArrayList<>();
35         WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();;
36         BigInteger dpnId = IfmUtil.getDpnId(bridgeOld.getDatapathId());
37
38         if (dpnId == null) {
39             LOG.warn("Got Null DPID for Bridge: {}", bridgeOld);
40             return futures;
41         }
42
43         //delete bridge reference entry in interface meta operational DS
44         InterfaceMetaUtils.deleteBridgeRefEntry(dpnId, transaction);
45
46         // the bridge reference is copied to dpn-tunnel interfaces map, so that whenever a northbound delete
47         // happens when bridge is not connected, we need the bridge reference to clean up the topology config DS
48         InterfaceMetaUtils.addBridgeRefToBridgeInterfaceEntry(dpnId, new OvsdbBridgeRef(bridgeIid), transaction);
49
50         futures.add(transaction.submit());
51         return futures;
52     }
53 }