Bump versions by 0.1.0 for next dev cycle
[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 java.math.BigInteger;
11 import java.util.ArrayList;
12 import java.util.List;
13
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.vpnservice.interfacemgr.IfmUtil;
18 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils;
19 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils;
20 import org.opendaylight.vpnservice.interfacemgr.servicebindings.flowbased.utilities.FlowBasedServicesUtils;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntry;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntryKey;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info._interface.parent.entry.InterfaceChildEntry;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info._interface.parent.entry.InterfaceChildEntryKey;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfL2vlan;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.ParentRefs;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 import com.google.common.util.concurrent.ListenableFuture;
35
36 public class OvsVlanMemberConfigRemoveHelper {
37     private static final Logger LOG = LoggerFactory.getLogger(OvsVlanMemberConfigRemoveHelper.class);
38     public static List<ListenableFuture<Void>> removeConfiguration(DataBroker dataBroker, ParentRefs parentRefs,
39                                                                 Interface interfaceOld, IfL2vlan ifL2vlan,
40                                                                 IdManagerService idManager) {
41         LOG.debug("remove vlan member configuration {}",interfaceOld.getName());
42         List<ListenableFuture<Void>> futures = new ArrayList<>();
43         WriteTransaction t = dataBroker.newWriteOnlyTransaction();
44
45         InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentRefs.getParentInterface());
46         InstanceIdentifier<InterfaceParentEntry> interfaceParentEntryIid =
47                 InterfaceMetaUtils.getInterfaceParentEntryIdentifier(interfaceParentEntryKey);
48         InterfaceParentEntry interfaceParentEntry =
49                 InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(interfaceParentEntryIid, dataBroker);
50
51         if(interfaceParentEntry == null){
52             return futures;
53         }
54
55         //Delete the interface child information
56         List<InterfaceChildEntry> interfaceChildEntries = interfaceParentEntry.getInterfaceChildEntry();
57         InterfaceChildEntryKey interfaceChildEntryKey = new InterfaceChildEntryKey(interfaceOld.getName());
58         InstanceIdentifier<InterfaceChildEntry> interfaceChildEntryIid =
59                     InterfaceMetaUtils.getInterfaceChildEntryIdentifier(interfaceParentEntryKey, interfaceChildEntryKey);
60         t.delete(LogicalDatastoreType.CONFIGURATION, interfaceChildEntryIid);
61         //If this is the last child, remove the interface parent info as well.
62         if (interfaceChildEntries.size() <= 1) {
63             t.delete(LogicalDatastoreType.CONFIGURATION, interfaceParentEntryIid);
64         }
65
66         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState =
67                 InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(parentRefs.getParentInterface(), dataBroker);
68         if (ifState != null) {
69             /* FIXME -- The below code is needed if vlan-trunks should be updated in the of-port
70
71             String lowerLayerIf = ifState.getLowerLayerIf().get(0);
72             NodeConnectorId nodeConnectorId = new NodeConnectorId(lowerLayerIf);
73             BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
74
75             BridgeRefEntryKey BridgeRefEntryKey = new BridgeRefEntryKey(dpId);
76             InstanceIdentifier<BridgeRefEntry> dpnBridgeEntryIid =
77                     InterfaceMetaUtils.getBridgeRefEntryIdentifier(BridgeRefEntryKey);
78             BridgeRefEntry bridgeRefEntry =
79                     InterfaceMetaUtils.getBridgeRefEntryFromOperDS(dpnBridgeEntryIid, dataBroker);
80             if (bridgeRefEntry != null) {
81                 InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid =
82                         (InstanceIdentifier<OvsdbBridgeAugmentation>)bridgeRefEntry.getBridgeReference().getValue();
83                 Optional<OvsdbBridgeAugmentation> bridgeNodeOptional =
84                         IfmUtil.read(LogicalDatastoreType.OPERATIONAL, bridgeIid, dataBroker);
85                 if (bridgeNodeOptional.isPresent()) {
86                     OvsdbBridgeAugmentation ovsdbBridgeAugmentation = bridgeNodeOptional.get();
87                     String bridgeName = ovsdbBridgeAugmentation.getBridgeName().getValue();
88                     VlanTrunkSouthboundUtils.updateVlanMemberInTrunk(bridgeIid, ifL2vlan,
89                             ovsdbBridgeAugmentation, bridgeName, parentRefs.getParentInterface(), dataBroker, t);
90                 }
91             } */
92
93             LOG.debug("delete vlan member interface state {}",interfaceOld.getName());
94             BigInteger dpId = IfmUtil.getDpnFromInterface(ifState);
95             InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
96                     IfmUtil.buildStateInterfaceId(interfaceOld.getName());
97             t.delete(LogicalDatastoreType.OPERATIONAL, ifStateId);
98             FlowBasedServicesUtils.removeIngressFlow(interfaceOld.getName(), dpId, t);
99         }
100
101         futures.add(t.submit());
102         return futures;
103     }
104 }