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
9 package org.opendaylight.ovsdb.hwvtepsouthbound.transact;
11 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
13 import java.util.Collection;
14 import java.util.Collections;
15 import java.util.List;
17 import java.util.Map.Entry;
18 import java.util.Optional;
19 import org.opendaylight.mdsal.binding.api.DataTreeModification;
20 import org.opendaylight.ovsdb.lib.notation.UUID;
21 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
22 import org.opendaylight.ovsdb.schema.hardwarevtep.UcastMacsLocal;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacs;
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 UcastMacsLocalRemoveCommand extends AbstractTransactCommand<LocalUcastMacs, HwvtepGlobalAugmentation> {
31 private static final Logger LOG = LoggerFactory.getLogger(UcastMacsLocalRemoveCommand.class);
33 public UcastMacsLocalRemoveCommand(final HwvtepOperationalState state,
34 final Collection<DataTreeModification<Node>> changes) {
35 super(state, changes);
39 public void execute(final TransactionBuilder transaction) {
40 Map<InstanceIdentifier<Node>, List<LocalUcastMacs>> removeds =
41 extractRemoved(getChanges(),LocalUcastMacs.class);
42 if (!removeds.isEmpty()) {
43 for (Entry<InstanceIdentifier<Node>, List<LocalUcastMacs>> removed:
44 removeds.entrySet()) {
45 removeUcastMacLocal(transaction, removed.getKey(), removed.getValue());
50 private void removeUcastMacLocal(final TransactionBuilder transaction,
51 final InstanceIdentifier<Node> instanceIdentifier, final List<LocalUcastMacs> macList) {
52 for (LocalUcastMacs mac: macList) {
53 LOG.debug("Removing remoteUcastMacs, mac address: {}", mac.getMacEntryKey().getValue());
54 Optional<LocalUcastMacs> operationalMacOptional =
55 getOperationalState().getLocalUcastMacs(instanceIdentifier, mac.key());
56 UcastMacsLocal ucastMacsLocal = transaction.getTypedRowSchema(UcastMacsLocal.class);
57 if (operationalMacOptional.isPresent() && operationalMacOptional.get().getMacEntryUuid() != null) {
58 //when mac entry is deleted, its referenced locators are deleted automatically.
59 //locators in config DS is not deleted and user need to be removed explicitly by user.
60 UUID macEntryUUID = new UUID(operationalMacOptional.get().getMacEntryUuid().getValue());
61 ucastMacsLocal.getUuidColumn().setData(macEntryUUID);
62 transaction.add(op.delete(ucastMacsLocal.getSchema())
63 .where(ucastMacsLocal.getUuidColumn().getSchema().opEqual(macEntryUUID)).build());
64 transaction.add(op.comment("UcastMacLocal: Deleting " + mac.getMacEntryKey().getValue()));
66 LOG.warn("Unable to delete remoteUcastMacs {} because it was not found in the operational store",
67 mac.getMacEntryKey().getValue());
73 protected List<LocalUcastMacs> getData(final HwvtepGlobalAugmentation augmentation) {
74 return augmentation.getLocalUcastMacs();
78 protected boolean cascadeDelete() {
83 protected UnMetDependencyGetter getDependencyGetter() {
84 return MAC_DEPENDENCY_GETTER;
87 static UnMetDependencyGetter MAC_DEPENDENCY_GETTER = new MacDependencyGetter();
89 public static class MacDependencyGetter extends UnMetDependencyGetter<LocalUcastMacs> {
91 public List<InstanceIdentifier<?>> getLogicalSwitchDependencies(final LocalUcastMacs data) {
92 return Collections.singletonList(data.getLogicalSwitchRef().getValue());
96 public List<InstanceIdentifier<?>> getTerminationPointDependencies(final LocalUcastMacs data) {
97 return Collections.emptyList();
102 protected boolean isDeleteCmd() {