Merge "Yang changes for l3vpn"
[vpnservice.git] / interfacemgr / interfacemgr-impl / src / main / java / org / opendaylight / vpnservice / interfacemgr / renderer / ovs / confighelpers / OvsVlanMemberConfigRemoveHelper.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.confighelpers;
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.idmanager.IdManager;
15 import org.opendaylight.vpnservice.interfacemgr.IfmUtil;
16 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils;
17 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntry;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntryKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info._interface.parent.entry.InterfaceChildEntry;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info._interface.parent.entry.InterfaceChildEntryKey;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfL2vlan;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.ParentRefs;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 import java.util.ArrayList;
31 import java.util.List;
32
33 public class OvsVlanMemberConfigRemoveHelper {
34     private static final Logger LOG = LoggerFactory.getLogger(OvsVlanMemberConfigRemoveHelper.class);
35     public static List<ListenableFuture<Void>> removeConfiguration(DataBroker dataBroker, ParentRefs parentRefs,
36                                                                 Interface interfaceOld, IfL2vlan ifL2vlan,
37                                                                 IdManagerService idManager) {
38         List<ListenableFuture<Void>> futures = new ArrayList<>();
39         WriteTransaction t = dataBroker.newWriteOnlyTransaction();
40
41         InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentRefs.getParentInterface());
42         InstanceIdentifier<InterfaceParentEntry> interfaceParentEntryIid =
43                 InterfaceMetaUtils.getInterfaceParentEntryIdentifier(interfaceParentEntryKey);
44         InterfaceParentEntry interfaceParentEntry =
45                 InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(interfaceParentEntryIid, dataBroker);
46
47         List<InterfaceChildEntry> interfaceChildEntries = interfaceParentEntry.getInterfaceChildEntry();
48         if (interfaceChildEntries.size() <= 1) {
49             t.delete(LogicalDatastoreType.CONFIGURATION, interfaceParentEntryIid);
50         } else {
51             InterfaceChildEntryKey interfaceChildEntryKey = new InterfaceChildEntryKey(interfaceOld.getName());
52             InstanceIdentifier<InterfaceChildEntry> interfaceChildEntryIid =
53                     InterfaceMetaUtils.getInterfaceChildEntryIdentifier(interfaceParentEntryKey, interfaceChildEntryKey);
54             t.delete(LogicalDatastoreType.CONFIGURATION, interfaceChildEntryIid);
55         }
56
57         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState =
58                 InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(parentRefs.getParentInterface(), dataBroker);
59         if (ifState != null) {
60             /* FIXME -- The below code is needed if vlan-trunks should be updated in the of-port
61
62             String lowerLayerIf = ifState.getLowerLayerIf().get(0);
63             NodeConnectorId nodeConnectorId = new NodeConnectorId(lowerLayerIf);
64             BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
65
66             BridgeRefEntryKey BridgeRefEntryKey = new BridgeRefEntryKey(dpId);
67             InstanceIdentifier<BridgeRefEntry> dpnBridgeEntryIid =
68                     InterfaceMetaUtils.getBridgeRefEntryIdentifier(BridgeRefEntryKey);
69             BridgeRefEntry bridgeRefEntry =
70                     InterfaceMetaUtils.getBridgeRefEntryFromOperDS(dpnBridgeEntryIid, dataBroker);
71             if (bridgeRefEntry != null) {
72                 InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid =
73                         (InstanceIdentifier<OvsdbBridgeAugmentation>)bridgeRefEntry.getBridgeReference().getValue();
74                 Optional<OvsdbBridgeAugmentation> bridgeNodeOptional =
75                         IfmUtil.read(LogicalDatastoreType.OPERATIONAL, bridgeIid, dataBroker);
76                 if (bridgeNodeOptional.isPresent()) {
77                     OvsdbBridgeAugmentation ovsdbBridgeAugmentation = bridgeNodeOptional.get();
78                     String bridgeName = ovsdbBridgeAugmentation.getBridgeName().getValue();
79                     VlanTrunkSouthboundUtils.updateVlanMemberInTrunk(bridgeIid, ifL2vlan,
80                             ovsdbBridgeAugmentation, bridgeName, parentRefs.getParentInterface(), dataBroker, t);
81                 }
82             } */
83
84             InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
85                     IfmUtil.buildStateInterfaceId(interfaceOld.getName());
86             t.delete(LogicalDatastoreType.OPERATIONAL, ifStateId);
87         }
88
89         futures.add(t.submit());
90         return futures;
91     }
92 }