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