2 * Copyright © 2015, 2017 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.Collection;
13 import java.util.Collections;
14 import java.util.List;
16 import java.util.Map.Entry;
17 import java.util.Optional;
18 import org.opendaylight.mdsal.binding.api.DataTreeModification;
19 import org.opendaylight.ovsdb.lib.notation.UUID;
20 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
21 import org.opendaylight.ovsdb.schema.hardwarevtep.McastMacsLocal;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalMcastMacs;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalMcastMacsKey;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public class McastMacsLocalRemoveCommand
31 extends AbstractTransactCommand<LocalMcastMacs, LocalMcastMacsKey, HwvtepGlobalAugmentation> {
32 private static final Logger LOG = LoggerFactory.getLogger(McastMacsLocalRemoveCommand.class);
34 public McastMacsLocalRemoveCommand(final HwvtepOperationalState state,
35 final Collection<DataTreeModification<Node>> changes) {
36 super(state, changes);
40 public void execute(final TransactionBuilder transaction) {
41 Map<InstanceIdentifier<Node>, List<LocalMcastMacs>> removeds =
42 extractRemoved(getChanges(),LocalMcastMacs.class);
43 if (!removeds.isEmpty()) {
44 for (Entry<InstanceIdentifier<Node>, List<LocalMcastMacs>> removed:
45 removeds.entrySet()) {
46 removeMcastMacLocal(transaction, removed.getKey(), removed.getValue());
51 private void removeMcastMacLocal(final TransactionBuilder transaction,
52 final InstanceIdentifier<Node> instanceIdentifier, final List<LocalMcastMacs> macList) {
53 for (LocalMcastMacs mac: macList) {
54 LOG.debug("Removing localMcastMacs, mac address: {}", mac.getMacEntryKey().getValue());
55 Optional<LocalMcastMacs> operationalMacOptional =
56 getOperationalState().getLocalMcastMacs(instanceIdentifier, mac.key());
57 McastMacsLocal mcastMacsLocal = transaction.getTypedRowSchema(McastMacsLocal.class);
58 if (operationalMacOptional.isPresent() && operationalMacOptional.get().getMacEntryUuid() != null) {
59 //when mac entry is deleted, its referenced locator set and locators are deleted automatically.
60 //TODO: locator in config DS is not deleted
61 UUID macEntryUUID = new UUID(operationalMacOptional.get().getMacEntryUuid().getValue());
62 mcastMacsLocal.getUuidColumn().setData(macEntryUUID);
63 transaction.add(op.delete(mcastMacsLocal.getSchema())
64 .where(mcastMacsLocal.getUuidColumn().getSchema().opEqual(macEntryUUID)).build());
65 transaction.add(op.comment("McastMacLocal: Deleting " + mac.getMacEntryKey().getValue()));
67 LOG.warn("Unable to delete localMcastMacs {} because it was not found in the operational store",
68 mac.getMacEntryKey().getValue());
74 protected Map<LocalMcastMacsKey, LocalMcastMacs> getData(final HwvtepGlobalAugmentation augmentation) {
75 return augmentation.getLocalMcastMacs();
79 protected boolean cascadeDelete() {
84 protected UnMetDependencyGetter getDependencyGetter() {
85 return MAC_DEPENDENCY_GETTER;
88 static UnMetDependencyGetter MAC_DEPENDENCY_GETTER = new MacDependencyGetter();
90 public static class MacDependencyGetter extends UnMetDependencyGetter<LocalMcastMacs> {
92 public List<InstanceIdentifier<?>> getLogicalSwitchDependencies(final LocalMcastMacs data) {
93 return Collections.singletonList(data.getLogicalSwitchRef().getValue());
97 public List<InstanceIdentifier<?>> getTerminationPointDependencies(final LocalMcastMacs data) {
98 return Collections.emptyList();
103 protected boolean isDeleteCmd() {