2 * Copyright (c) 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 java.util.Collection;
11 import java.util.List;
13 import java.util.Map.Entry;
14 import java.util.Objects;
15 import org.opendaylight.mdsal.binding.api.DataTreeModification;
16 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitchesKey;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 public class LogicalSwitchRemoveCommand
26 extends AbstractTransactCommand<LogicalSwitches, LogicalSwitchesKey, HwvtepGlobalAugmentation> {
27 private static final Logger LOG = LoggerFactory.getLogger(LogicalSwitchRemoveCommand.class);
28 List<LogicalSwitches> deletedLs;
30 public LogicalSwitchRemoveCommand(final HwvtepOperationalState state,
31 final Collection<DataTreeModification<Node>> changes) {
32 super(state, changes);
36 public void execute(final TransactionBuilder transaction) {
37 Map<InstanceIdentifier<Node>, List<LogicalSwitches>> removeds =
38 extractRemoved(getChanges(), LogicalSwitches.class);
39 if (removeds != null) {
40 for (Entry<InstanceIdentifier<Node>, List<LogicalSwitches>> deleted: removeds.entrySet()) {
41 deletedLs = deleted.getValue();
42 for (LogicalSwitches lswitch : deleted.getValue()) {
43 InstanceIdentifier<LogicalSwitches> lsKey =
44 deleted.getKey().augmentation(HwvtepGlobalAugmentation.class)
45 .child(LogicalSwitches.class, lswitch.key());
46 getDeviceInfo().clearConfigData(LogicalSwitches.class, lsKey);
47 onConfigUpdate(transaction, deleted.getKey(), lswitch, lsKey);
54 public void onConfigUpdate(final TransactionBuilder transaction, final InstanceIdentifier<Node> nodeIid,
55 final LogicalSwitches logicalSwitches, final InstanceIdentifier lsKey,
56 final Object... extraData) {
57 processDependencies(EmptyDependencyGetter.INSTANCE, transaction, nodeIid, lsKey, logicalSwitches);
61 public void doDeviceTransaction(final TransactionBuilder transaction,
62 final InstanceIdentifier<Node> instanceIdentifier,
63 final LogicalSwitches lswitch,
64 final InstanceIdentifier lsKey,
65 final Object... extraData) {
66 LogicalSwitchUcastsRemoveCommand cmd = new LogicalSwitchUcastsRemoveCommand(
67 newOperState(), getChanges(), deletedLs, lswitch);
68 markKeyAsInTransit(LogicalSwitches.class, lsKey);
69 clearConfigData(LogicalSwitches.class, lsKey);
70 hwvtepOperationalState.getConnectionInstance().transact(cmd);
74 protected Map<LogicalSwitchesKey, LogicalSwitches> getData(final HwvtepGlobalAugmentation augmentation) {
75 return augmentation.getLogicalSwitches();
79 protected boolean areEqual(final LogicalSwitches sw1, final LogicalSwitches sw2) {
80 return sw1.key().equals(sw2.key()) && Objects.equals(sw1.getTunnelKey(), sw2.getTunnelKey());
84 protected boolean isDeleteCmd() {
89 public void onCommandSucceeded() {
90 for (MdsalUpdate mdsalUpdate : updates) {
91 getDeviceInfo().clearLogicalSwitchRefs(mdsalUpdate.getKey());