Merge "Bug 5046 : ELAN integration into NeutronVPN for ELAN instance/interfaces"
[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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge.ref.info.BridgeRefEntry;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge.ref.info.BridgeRefEntryKey;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 import java.math.BigInteger;
24 import java.util.ArrayList;
25 import java.util.List;
26
27 public class OvsInterfaceTopologyStateRemoveHelper {
28     private static final Logger LOG = LoggerFactory.getLogger(OvsInterfaceTopologyStateRemoveHelper.class);
29
30     public static List<ListenableFuture<Void>> removePortFromBridge(InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid,
31                                                                OvsdbBridgeAugmentation bridgeOld, DataBroker dataBroker) {
32         List<ListenableFuture<Void>> futures = new ArrayList<>();
33         WriteTransaction t = dataBroker.newWriteOnlyTransaction();;
34         BigInteger dpnId = IfmUtil.getDpnId(bridgeOld.getDatapathId());
35
36         if (dpnId == null) {
37             LOG.warn("Got Null DPID for Bridge: {}", bridgeOld);
38             return futures;
39         }
40         BridgeRefEntryKey bridgeRefEntryKey = new BridgeRefEntryKey(dpnId);
41         InstanceIdentifier<BridgeRefEntry> bridgeEntryId =
42                 InterfaceMetaUtils.getBridgeRefEntryIdentifier(bridgeRefEntryKey);
43         t.delete(LogicalDatastoreType.OPERATIONAL, bridgeEntryId);
44
45         futures.add(t.submit());
46         return futures;
47     }
48 }