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.AlivenessMonitorUtils;
16 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils;
17 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils;
18 import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
19 import org.opendaylight.vpnservice.mdsalutil.NwConstants;
20 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.AlivenessMonitorService;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntry;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntryKey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info._interface.parent.entry.InterfaceChildEntry;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfTunnel;
34 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
38 import java.math.BigInteger;
39 import java.util.ArrayList;
40 import java.util.List;
42 public class OvsInterfaceStateRemoveHelper {
43 private static final Logger LOG = LoggerFactory.getLogger(OvsInterfaceStateRemoveHelper.class);
45 public static List<ListenableFuture<Void>> removeState(IdManagerService idManager, IMdsalApiManager mdsalApiManager,
46 AlivenessMonitorService alivenessMonitorService,
47 InstanceIdentifier<FlowCapableNodeConnector> key,
48 DataBroker dataBroker, String portName, FlowCapableNodeConnector fcNodeConnectorOld) {
49 LOG.debug("Removing interface-state for port: {}", portName);
50 List<ListenableFuture<Void>> futures = new ArrayList<>();
51 WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
53 InstanceIdentifier<Interface> ifStateId = IfmUtil.buildStateInterfaceId(portName);
54 /* Remove entry from if-index-interface-name map and deallocate Id from Idmanager. */
55 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState =
56 InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(portName, dataBroker);
57 if(interfaceState != null) {
58 InterfaceMetaUtils.removeLportTagInterfaceMap(transaction, idManager, dataBroker, interfaceState.getName(), interfaceState.getIfIndex());
61 transaction.delete(LogicalDatastoreType.OPERATIONAL, ifStateId);
63 // For Vlan-Trunk Interface, remove the trunk-member operstates as well...
64 InterfaceKey interfaceKey = new InterfaceKey(portName);
65 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface =
66 InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
68 futures.add(transaction.submit());
72 // If this interface is a tunnel interface, remove the tunnel ingress flow and stop lldp monitoring
73 IfTunnel tunnel = iface.getAugmentation(IfTunnel.class);
75 NodeConnectorId nodeConnectorId = InstanceIdentifier.keyOf(key.firstIdentifierOf(NodeConnector.class)).getId();
76 BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
77 long portNo = Long.valueOf(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId));
78 InterfaceManagerCommonUtils.makeTunnelIngressFlow(futures, mdsalApiManager, tunnel, dpId, portNo, iface, -1,
79 NwConstants.DEL_FLOW);
80 futures.add(transaction.submit());
81 AlivenessMonitorUtils.stopLLDPMonitoring(alivenessMonitorService, dataBroker, iface);
85 InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(iface.getName());
86 InterfaceParentEntry interfaceParentEntry =
87 InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(interfaceParentEntryKey, dataBroker);
88 if (interfaceParentEntry == null) {
89 futures.add(transaction.submit());
93 List<InterfaceChildEntry> interfaceChildEntries = interfaceParentEntry.getInterfaceChildEntry();
94 if (interfaceChildEntries == null) {
95 futures.add(transaction.submit());
99 //FIXME: If the no. of child entries exceeds 100, perform txn updates in batches of 100.
100 for (InterfaceChildEntry interfaceChildEntry : interfaceChildEntries) {
101 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifChildStateId =
102 IfmUtil.buildStateInterfaceId(interfaceChildEntry.getChildInterface());
103 /* Remove entry from if-index-interface-name map and deallocate Id from Idmanager. */
104 Interface childInterfaceState = InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(interfaceChildEntry.getChildInterface(), dataBroker);
105 if(interfaceState != null) {
106 InterfaceMetaUtils.removeLportTagInterfaceMap(transaction, idManager, dataBroker, childInterfaceState.getName(), childInterfaceState.getIfIndex());
107 transaction.delete(LogicalDatastoreType.OPERATIONAL, ifChildStateId);
111 /* Below code will be needed if we want to update the vlan-trunk in the of-port.
112 NodeConnectorId nodeConnectorId = InstanceIdentifier.keyOf(key.firstIdentifierOf(NodeConnector.class)).getId();
113 BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
115 BridgeRefEntryKey BridgeRefEntryKey = new BridgeRefEntryKey(dpId);
116 InstanceIdentifier<BridgeRefEntry> dpnBridgeEntryIid =
117 InterfaceMetaUtils.getBridgeRefEntryIdentifier(BridgeRefEntryKey);
118 BridgeRefEntry bridgeRefEntry =
119 InterfaceMetaUtils.getBridgeRefEntryFromOperDS(dpnBridgeEntryIid, dataBroker);
120 if (bridgeRefEntry == null) {
121 futures.add(t.submit());
125 InstanceIdentifier<?> bridgeIid = bridgeRefEntry.getBridgeReference().getValue();
126 InstanceIdentifier<TerminationPoint> tpIid = SouthboundUtils.createTerminationPointInstanceIdentifier(
127 InstanceIdentifier.keyOf(bridgeIid.firstIdentifierOf(Node.class)), interfaceOld.getName());
128 t.delete(LogicalDatastoreType.CONFIGURATION, tpIid); */
130 futures.add(transaction.submit());