2 * Copyright (c) 2016, 2017 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.genius.interfacemanager.renderer.ovs.confighelpers;
10 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
11 import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import java.util.ArrayList;
15 import java.util.Collections;
16 import java.util.List;
18 import javax.inject.Inject;
19 import javax.inject.Singleton;
20 import org.apache.aries.blueprint.annotation.service.Reference;
21 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
22 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
23 import org.opendaylight.genius.interfacemanager.IfmUtil;
24 import org.opendaylight.genius.interfacemanager.commons.InterfaceManagerCommonUtils;
25 import org.opendaylight.genius.interfacemanager.commons.InterfaceMetaUtils;
26 import org.opendaylight.genius.interfacemanager.servicebindings.flowbased.utilities.FlowBasedServicesUtils;
27 import org.opendaylight.mdsal.binding.api.DataBroker;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._interface.child.info.InterfaceParentEntry;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._interface.child.info.InterfaceParentEntryKey;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._interface.child.info._interface.parent.entry.InterfaceChildEntry;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._interface.child.info._interface.parent.entry.InterfaceChildEntryKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs;
34 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
35 import org.opendaylight.yangtools.yang.common.Uint64;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
40 public class OvsVlanMemberConfigRemoveHelper {
41 private static final Logger LOG = LoggerFactory.getLogger(OvsVlanMemberConfigRemoveHelper.class);
43 private final ManagedNewTransactionRunner txRunner;
44 private final InterfaceManagerCommonUtils interfaceManagerCommonUtils;
45 private final InterfaceMetaUtils interfaceMetaUtils;
48 public OvsVlanMemberConfigRemoveHelper(@Reference DataBroker dataBroker,
49 InterfaceManagerCommonUtils interfaceManagerCommonUtils, InterfaceMetaUtils interfaceMetaUtils) {
50 this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
51 this.interfaceManagerCommonUtils = interfaceManagerCommonUtils;
52 this.interfaceMetaUtils = interfaceMetaUtils;
55 public List<ListenableFuture<Void>> removeConfiguration(ParentRefs parentRefs, Interface interfaceOld) {
56 LOG.debug("remove vlan member configuration {}", interfaceOld.getName());
58 InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentRefs.getParentInterface());
59 InstanceIdentifier<InterfaceParentEntry> interfaceParentEntryIid = InterfaceMetaUtils
60 .getInterfaceParentEntryIdentifier(interfaceParentEntryKey);
61 InterfaceParentEntry interfaceParentEntry = interfaceMetaUtils
62 .getInterfaceParentEntryFromConfigDS(interfaceParentEntryIid);
64 if (interfaceParentEntry == null) {
65 return Collections.emptyList();
68 return txRunner.applyWithNewTransactionChainAndClose(txChain -> {
69 List<ListenableFuture<Void>> futures = new ArrayList<>();
71 // Configuration changes
72 futures.add(txChain.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
73 // Delete the interface child information
74 Map<InterfaceChildEntryKey, InterfaceChildEntry> interfaceChildEntries =
75 interfaceParentEntry.nonnullInterfaceChildEntry();
76 InterfaceChildEntryKey interfaceChildEntryKey = new InterfaceChildEntryKey(interfaceOld.getName());
77 InstanceIdentifier<InterfaceChildEntry> interfaceChildEntryIid = InterfaceMetaUtils
78 .getInterfaceChildEntryIdentifier(interfaceParentEntryKey, interfaceChildEntryKey);
79 tx.delete(interfaceChildEntryIid);
80 // If this is the last child, remove the interface parent info as well.
81 if (interfaceChildEntries.size() <= 1) {
82 tx.delete(interfaceParentEntryIid);
86 // Operational changes
87 futures.add(txChain.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, tx -> {
88 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
89 .ietf.interfaces.rev140508.interfaces.state.Interface ifState = interfaceManagerCommonUtils
90 .getInterfaceState(tx, parentRefs.getParentInterface());
91 if (ifState != null) {
92 LOG.debug("delete vlan member interface state {}", interfaceOld.getName());
93 Uint64 dpId = IfmUtil.getDpnFromInterface(ifState);
94 interfaceManagerCommonUtils.deleteInterfaceStateInformation(interfaceOld.getName(), tx);
95 // TODO skitt The following is another configuration transaction, we'll deal with it later
96 FlowBasedServicesUtils.removeIngressFlow(interfaceOld.getName(), dpId, txRunner, futures);