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;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.vpnservice.interfacemgr.IfmUtil;
16 import org.opendaylight.vpnservice.interfacemgr.commons.AlivenessMonitorUtils;
17 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils;
18 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils;
19 import org.opendaylight.vpnservice.interfacemgr.servicebindings.flowbased.utilities.FlowBasedServicesUtils;
20 import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
21 import org.opendaylight.vpnservice.mdsalutil.MatchInfo;
22 import org.opendaylight.vpnservice.mdsalutil.NwConstants;
23 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.AlivenessMonitorService;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntry;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntryKey;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info._interface.parent.entry.InterfaceChildEntry;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfL2vlan;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfTunnel;
39 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
43 import java.math.BigInteger;
44 import java.util.ArrayList;
45 import java.util.List;
47 public class OvsInterfaceStateRemoveHelper {
48 private static final Logger LOG = LoggerFactory.getLogger(OvsInterfaceStateRemoveHelper.class);
50 public static List<ListenableFuture<Void>> removeState(IdManagerService idManager, IMdsalApiManager mdsalApiManager,
51 AlivenessMonitorService alivenessMonitorService,
52 InstanceIdentifier<FlowCapableNodeConnector> key,
53 DataBroker dataBroker, String portName, FlowCapableNodeConnector fcNodeConnectorOld) {
54 LOG.debug("Removing interface-state for port: {}", portName);
55 List<ListenableFuture<Void>> futures = new ArrayList<>();
56 WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
58 InstanceIdentifier<Interface> ifStateId = IfmUtil.buildStateInterfaceId(portName);
59 /* Remove entry from if-index-interface-name map and deallocate Id from Idmanager. */
60 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState =
61 InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(portName, dataBroker);
62 if(interfaceState != null) {
63 InterfaceMetaUtils.removeLportTagInterfaceMap(transaction, idManager, dataBroker, interfaceState.getName(), interfaceState.getIfIndex());
66 transaction.delete(LogicalDatastoreType.OPERATIONAL, ifStateId);
68 InterfaceKey interfaceKey = new InterfaceKey(portName);
69 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface =
70 InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
72 NodeConnectorId nodeConnectorId = InstanceIdentifier.keyOf(key.firstIdentifierOf(NodeConnector.class)).getId();
73 BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
74 // If this interface is a tunnel interface, remove the tunnel ingress flow and stop lldp monitoring
76 IfTunnel tunnel = iface.getAugmentation(IfTunnel.class);
78 long portNo = Long.valueOf(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId));
79 InterfaceManagerCommonUtils.makeTunnelIngressFlow(futures, mdsalApiManager, tunnel, dpId, portNo, iface, -1,
80 NwConstants.DEL_FLOW);
81 futures.add(transaction.submit());
82 AlivenessMonitorUtils.stopLLDPMonitoring(alivenessMonitorService, dataBroker, iface);
87 InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(portName);
88 InterfaceParentEntry interfaceParentEntry =
89 InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(interfaceParentEntryKey, dataBroker);
90 if (interfaceParentEntry == null || interfaceParentEntry.getInterfaceChildEntry() == null) {
91 futures.add(transaction.submit());
95 //FIXME: If the no. of child entries exceeds 100, perform txn updates in batches of 100.
96 InterfaceChildEntry higherlayerChild = interfaceParentEntry.getInterfaceChildEntry().get(0);
97 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface>
98 higerLayerChildIfStateId = IfmUtil.buildStateInterfaceId(higherlayerChild.getChildInterface());
99 /* Remove entry from if-index-interface-name map and deallocate Id from Idmanager. */
100 Interface higherLayerIfChildState = InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(higherlayerChild.getChildInterface(), dataBroker);
101 if (interfaceState != null) {
102 InterfaceMetaUtils.removeLportTagInterfaceMap(transaction, idManager, dataBroker, higherLayerIfChildState.getName(),
103 higherLayerIfChildState.getIfIndex());
104 transaction.delete(LogicalDatastoreType.OPERATIONAL, higerLayerChildIfStateId);
105 FlowBasedServicesUtils.removeIngressFlow(higherLayerIfChildState.getName(), dpId, transaction);
107 // If this interface maps to a Vlan trunk entity, operational states of all the vlan-trunk-members
108 // should also be created here.
109 InterfaceParentEntryKey higherLayerParentEntryKey = new InterfaceParentEntryKey(higherlayerChild.getChildInterface());
110 InterfaceParentEntry higherLayerParent =
111 InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(higherLayerParentEntryKey, dataBroker);
113 if(higherLayerParent != null && higherLayerParent.getInterfaceChildEntry() != null) {
114 for (InterfaceChildEntry interfaceChildEntry : higherLayerParent.getInterfaceChildEntry()) {
115 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifChildStateId =
116 IfmUtil.buildStateInterfaceId(interfaceChildEntry.getChildInterface());
117 /* Remove entry from if-index-interface-name map and deallocate Id from Idmanager. */
118 Interface childInterfaceState = InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(interfaceChildEntry.getChildInterface(), dataBroker);
119 if (interfaceState != null) {
120 InterfaceMetaUtils.removeLportTagInterfaceMap(transaction, idManager, dataBroker, childInterfaceState.getName(), childInterfaceState.getIfIndex());
121 transaction.delete(LogicalDatastoreType.OPERATIONAL, ifChildStateId);
122 FlowBasedServicesUtils.removeIngressFlow(childInterfaceState.getName(), dpId, transaction);
128 /* Below code will be needed if we want to update the vlan-trunk in the of-port.
129 NodeConnectorId nodeConnectorId = InstanceIdentifier.keyOf(key.firstIdentifierOf(NodeConnector.class)).getId();
130 BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
132 BridgeRefEntryKey BridgeRefEntryKey = new BridgeRefEntryKey(dpId);
133 InstanceIdentifier<BridgeRefEntry> dpnBridgeEntryIid =
134 InterfaceMetaUtils.getBridgeRefEntryIdentifier(BridgeRefEntryKey);
135 BridgeRefEntry bridgeRefEntry =
136 InterfaceMetaUtils.getBridgeRefEntryFromOperDS(dpnBridgeEntryIid, dataBroker);
137 if (bridgeRefEntry == null) {
138 futures.add(t.submit());
142 InstanceIdentifier<?> bridgeIid = bridgeRefEntry.getBridgeReference().getValue();
143 InstanceIdentifier<TerminationPoint> tpIid = SouthboundUtils.createTerminationPointInstanceIdentifier(
144 InstanceIdentifier.keyOf(bridgeIid.firstIdentifierOf(Node.class)), interfaceOld.getName());
145 t.delete(LogicalDatastoreType.CONFIGURATION, tpIid); */
147 futures.add(transaction.submit());