Yang changes for l3vpn
[vpnservice.git] / interfacemgr / interfacemgr-impl / src / main / java / org / opendaylight / vpnservice / interfacemgr / renderer / ovs / statehelpers / OvsInterfaceStateRemoveHelper.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.InterfaceManagerCommonUtils;
16 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
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.yangtools.yang.binding.InstanceIdentifier;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 import java.util.ArrayList;
28 import java.util.List;
29
30 public class OvsInterfaceStateRemoveHelper {
31     private static final Logger LOG = LoggerFactory.getLogger(OvsInterfaceStateRemoveHelper.class);
32
33     public static List<ListenableFuture<Void>> removeState(InstanceIdentifier<FlowCapableNodeConnector> key,
34                                                            DataBroker dataBroker, String portName, FlowCapableNodeConnector fcNodeConnectorOld) {
35         LOG.debug("Removing interface-state for port: {}", portName);
36         List<ListenableFuture<Void>> futures = new ArrayList<>();
37         WriteTransaction t = dataBroker.newWriteOnlyTransaction();
38
39         InstanceIdentifier<Interface> ifStateId = IfmUtil.buildStateInterfaceId(portName);
40         t.delete(LogicalDatastoreType.OPERATIONAL, ifStateId);
41
42         // For Vlan-Trunk Interface, remove the trunk-member operstates as well...
43         InterfaceKey interfaceKey = new InterfaceKey(portName);
44         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface =
45                 InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
46         if (iface == null) {
47             futures.add(t.submit());
48             return futures;
49         }
50
51         InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(iface.getName());
52         InterfaceParentEntry interfaceParentEntry =
53                 InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(interfaceParentEntryKey, dataBroker);
54         if (interfaceParentEntry == null) {
55             futures.add(t.submit());
56             return futures;
57         }
58
59         List<InterfaceChildEntry> interfaceChildEntries = interfaceParentEntry.getInterfaceChildEntry();
60         if (interfaceChildEntries == null) {
61             futures.add(t.submit());
62             return futures;
63         }
64
65         //FIXME: If the no. of child entries exceeds 100, perform txn updates in batches of 100.
66         for (InterfaceChildEntry interfaceChildEntry : interfaceChildEntries) {
67             InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifChildStateId =
68                     IfmUtil.buildStateInterfaceId(interfaceChildEntry.getChildInterface());
69             t.delete(LogicalDatastoreType.OPERATIONAL, ifChildStateId);
70         }
71
72        /* Below code will be needed if we want to update the vlan-trunk in the of-port.
73        NodeConnectorId nodeConnectorId = InstanceIdentifier.keyOf(key.firstIdentifierOf(NodeConnector.class)).getId();
74         BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
75
76         BridgeRefEntryKey BridgeRefEntryKey = new BridgeRefEntryKey(dpId);
77         InstanceIdentifier<BridgeRefEntry> dpnBridgeEntryIid =
78                 InterfaceMetaUtils.getBridgeRefEntryIdentifier(BridgeRefEntryKey);
79         BridgeRefEntry bridgeRefEntry =
80                 InterfaceMetaUtils.getBridgeRefEntryFromOperDS(dpnBridgeEntryIid, dataBroker);
81         if (bridgeRefEntry == null) {
82             futures.add(t.submit());
83             return futures;
84         }
85
86         InstanceIdentifier<?> bridgeIid = bridgeRefEntry.getBridgeReference().getValue();
87         InstanceIdentifier<TerminationPoint> tpIid = SouthboundUtils.createTerminationPointInstanceIdentifier(
88                 InstanceIdentifier.keyOf(bridgeIid.firstIdentifierOf(Node.class)), interfaceOld.getName());
89         t.delete(LogicalDatastoreType.CONFIGURATION, tpIid); */
90
91         futures.add(t.submit());
92         return futures;
93     }
94 }