2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
8 package org.opendaylight.vpnservice.interfacemgr.renderer.ovs.statehelpers;
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.vpnservice.mdsalutil.MDSALUtil;
18 import org.opendaylight.vpnservice.mdsalutil.NwConstants;
19 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntry;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntryKey;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info._interface.parent.entry.InterfaceChildEntry;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfTunnel;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 import java.math.BigInteger;
37 import java.util.ArrayList;
38 import java.util.List;
40 public class OvsInterfaceStateRemoveHelper {
41 private static final Logger LOG = LoggerFactory.getLogger(OvsInterfaceStateRemoveHelper.class);
43 public static List<ListenableFuture<Void>> removeState(IdManagerService idManager, IMdsalApiManager mdsalApiManager,
44 InstanceIdentifier<FlowCapableNodeConnector> key,
45 DataBroker dataBroker, String portName, FlowCapableNodeConnector fcNodeConnectorOld) {
46 LOG.debug("Removing interface-state for port: {}", portName);
47 List<ListenableFuture<Void>> futures = new ArrayList<>();
48 WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
50 InstanceIdentifier<Interface> ifStateId = IfmUtil.buildStateInterfaceId(portName);
51 /* Remove entry from if-index-interface-name map and deallocate Id from Idmanager. */
52 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState =
53 InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(portName, dataBroker);
54 if(interfaceState != null) {
55 InterfaceMetaUtils.removeLportTagInterfaceMap(transaction, idManager, dataBroker, interfaceState.getName(), interfaceState.getIfIndex());
58 transaction.delete(LogicalDatastoreType.OPERATIONAL, ifStateId);
60 // For Vlan-Trunk Interface, remove the trunk-member operstates as well...
61 InterfaceKey interfaceKey = new InterfaceKey(portName);
62 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface =
63 InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
65 futures.add(transaction.submit());
69 // If this interface is a tunnel interface, remove the tunnel ingress flow
70 IfTunnel tunnel = iface.getAugmentation(IfTunnel.class);
72 NodeConnectorId nodeConnectorId = InstanceIdentifier.keyOf(key.firstIdentifierOf(NodeConnector.class)).getId();
73 BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
74 long portNo = Long.valueOf(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId));
75 InterfaceManagerCommonUtils.makeTunnelIngressFlow(futures, mdsalApiManager, tunnel, dpId, portNo, iface,
76 NwConstants.DEL_FLOW);
80 InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(iface.getName());
81 InterfaceParentEntry interfaceParentEntry =
82 InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(interfaceParentEntryKey, dataBroker);
83 if (interfaceParentEntry == null) {
84 futures.add(transaction.submit());
88 List<InterfaceChildEntry> interfaceChildEntries = interfaceParentEntry.getInterfaceChildEntry();
89 if (interfaceChildEntries == null) {
90 futures.add(transaction.submit());
94 //FIXME: If the no. of child entries exceeds 100, perform txn updates in batches of 100.
95 for (InterfaceChildEntry interfaceChildEntry : interfaceChildEntries) {
96 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifChildStateId =
97 IfmUtil.buildStateInterfaceId(interfaceChildEntry.getChildInterface());
98 transaction.delete(LogicalDatastoreType.OPERATIONAL, ifChildStateId);
101 /* Below code will be needed if we want to update the vlan-trunk in the of-port.
102 NodeConnectorId nodeConnectorId = InstanceIdentifier.keyOf(key.firstIdentifierOf(NodeConnector.class)).getId();
103 BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
105 BridgeRefEntryKey BridgeRefEntryKey = new BridgeRefEntryKey(dpId);
106 InstanceIdentifier<BridgeRefEntry> dpnBridgeEntryIid =
107 InterfaceMetaUtils.getBridgeRefEntryIdentifier(BridgeRefEntryKey);
108 BridgeRefEntry bridgeRefEntry =
109 InterfaceMetaUtils.getBridgeRefEntryFromOperDS(dpnBridgeEntryIid, dataBroker);
110 if (bridgeRefEntry == null) {
111 futures.add(t.submit());
115 InstanceIdentifier<?> bridgeIid = bridgeRefEntry.getBridgeReference().getValue();
116 InstanceIdentifier<TerminationPoint> tpIid = SouthboundUtils.createTerminationPointInstanceIdentifier(
117 InstanceIdentifier.keyOf(bridgeIid.firstIdentifierOf(Node.class)), interfaceOld.getName());
118 t.delete(LogicalDatastoreType.CONFIGURATION, tpIid); */
120 futures.add(transaction.submit());