2 * Copyright (c) 2015, 2016 China Telecom Beijing Research Institute 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.ovsdb.hwvtepsouthbound.transact;
10 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
12 import java.util.ArrayList;
13 import java.util.Collection;
14 import java.util.List;
16 import java.util.Map.Entry;
17 import java.util.Objects;
18 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
19 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepDeviceInfo;
20 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundUtil;
21 import org.opendaylight.ovsdb.lib.notation.UUID;
22 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
23 import org.opendaylight.ovsdb.schema.hardwarevtep.McastMacsRemote;
24 import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionType;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class McastMacsRemoteRemoveCommand extends AbstractTransactCommand<RemoteMcastMacs, HwvtepGlobalAugmentation> {
33 private static final Logger LOG = LoggerFactory.getLogger(McastMacsRemoteRemoveCommand.class);
35 public McastMacsRemoteRemoveCommand(final HwvtepOperationalState state,
36 final Collection<DataTreeModification<Node>> changes) {
37 super(state, changes);
41 public void execute(final TransactionBuilder transaction) {
42 Map<InstanceIdentifier<Node>, List<RemoteMcastMacs>> removeds =
43 extractRemoved(getChanges(),RemoteMcastMacs.class);
44 if (!removeds.isEmpty()) {
45 for (Entry<InstanceIdentifier<Node>, List<RemoteMcastMacs>> removed:
46 removeds.entrySet()) {
47 removeMcastMacRemote(transaction, removed.getKey(), removed.getValue());
50 //Remove the ones whose locator set got emptied
51 Map<InstanceIdentifier<Node>, List<RemoteMcastMacs>> updated =
52 extractUpdated(getChanges(),RemoteMcastMacs.class);
53 if (!HwvtepSouthboundUtil.isEmptyMap(updated)) {
54 for (Entry<InstanceIdentifier<Node>, List<RemoteMcastMacs>> entry:
56 List<RemoteMcastMacs> updatedList = entry.getValue();
57 List<RemoteMcastMacs> tobeRemovedList = new ArrayList<>();
58 if (!HwvtepSouthboundUtil.isEmpty(updatedList)) {
59 for (RemoteMcastMacs mac: updatedList) {
60 if (HwvtepSouthboundUtil.isEmpty(mac.getLocatorSet())) {
61 tobeRemovedList.add(mac);
64 removeMcastMacRemote(transaction, entry.getKey(), tobeRemovedList);
70 private void removeMcastMacRemote(final TransactionBuilder transaction,
71 final InstanceIdentifier<Node> nodeIid, final List<RemoteMcastMacs> macList) {
72 for (RemoteMcastMacs mac : macList) {
73 InstanceIdentifier<RemoteMcastMacs> macKey = nodeIid.augmentation(HwvtepGlobalAugmentation.class)
74 .child(RemoteMcastMacs.class, mac.key());
75 onConfigUpdate(transaction, nodeIid, mac, macKey);
80 public void onConfigUpdate(final TransactionBuilder transaction,
81 final InstanceIdentifier<Node> nodeIid,
82 final RemoteMcastMacs remoteMcastMac,
83 final InstanceIdentifier macKey,
84 final Object... extraData) {
85 processDependencies(EmptyDependencyGetter.INSTANCE, transaction, nodeIid, macKey, remoteMcastMac);
89 public void doDeviceTransaction(final TransactionBuilder transaction,
90 final InstanceIdentifier<Node> instanceIdentifier,
91 final RemoteMcastMacs mac,
92 final InstanceIdentifier macIid,
93 final Object... extraData) {
94 LOG.debug("Removing remoteMcastMacs, mac address: {}", mac.getMacEntryKey().getValue());
95 clearConfigData(RemoteMcastMacs.class, macIid);
96 HwvtepDeviceInfo.DeviceData operationalMacOptional =
97 getDeviceInfo().getDeviceOperData(RemoteMcastMacs.class, macIid);
98 McastMacsRemote mcastMacsRemote = transaction.getTypedRowSchema(McastMacsRemote.class);
99 if (operationalMacOptional != null && operationalMacOptional.getUuid() != null) {
100 //when mac entry is deleted, its referenced locator set and locators are deleted automatically.
101 //TODO: locator in config DS is not deleted
102 UUID macEntryUUID = operationalMacOptional.getUuid();
103 mcastMacsRemote.getUuidColumn().setData(macEntryUUID);
104 transaction.add(op.delete(mcastMacsRemote.getSchema())
105 .where(mcastMacsRemote.getUuidColumn().getSchema().opEqual(macEntryUUID)).build());
106 transaction.add(op.comment("McastMacRemote: Deleting " + mac.getMacEntryKey().getValue()));
107 updateCurrentTxDeleteData(RemoteMcastMacs.class, macIid, mac);
108 updateControllerTxHistory(TransactionType.DELETE, mcastMacsRemote);
110 LOG.warn("Unable to delete remoteMcastMacs {} because it was not found in the operational store",
111 mac.getMacEntryKey().getValue());
116 protected List<RemoteMcastMacs> getData(final HwvtepGlobalAugmentation augmentation) {
117 return augmentation.getRemoteMcastMacs();
121 protected boolean areEqual(final RemoteMcastMacs macs1, final RemoteMcastMacs macs2) {
122 return macs1.key().equals(macs2.key()) && Objects.equals(macs1.getLocatorSet(), macs2.getLocatorSet());
126 protected boolean isDeleteCmd() {