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