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.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;
27 import java.util.ArrayList;
28 import java.util.List;
30 public class OvsInterfaceStateRemoveHelper {
31 private static final Logger LOG = LoggerFactory.getLogger(OvsInterfaceStateRemoveHelper.class);
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();
39 InstanceIdentifier<Interface> ifStateId = IfmUtil.buildStateInterfaceId(portName);
40 t.delete(LogicalDatastoreType.OPERATIONAL, ifStateId);
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);
47 futures.add(t.submit());
51 InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(iface.getName());
52 InterfaceParentEntry interfaceParentEntry =
53 InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(interfaceParentEntryKey, dataBroker);
54 if (interfaceParentEntry == null) {
55 futures.add(t.submit());
59 List<InterfaceChildEntry> interfaceChildEntries = interfaceParentEntry.getInterfaceChildEntry();
60 if (interfaceChildEntries == null) {
61 futures.add(t.submit());
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);
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));
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());
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); */
91 futures.add(t.submit());