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.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 public class LogicalSwitchRemoveCommand extends AbstractTransactCommand<LogicalSwitches, HwvtepGlobalAugmentation> {
25 private static final Logger LOG = LoggerFactory.getLogger(LogicalSwitchRemoveCommand.class);
26 List<LogicalSwitches> deletedLs;
28 public LogicalSwitchRemoveCommand(final HwvtepOperationalState state,
29 final Collection<DataTreeModification<Node>> changes) {
30 super(state, changes);
34 public void execute(final TransactionBuilder transaction) {
35 Map<InstanceIdentifier<Node>, List<LogicalSwitches>> removeds =
36 extractRemoved(getChanges(), LogicalSwitches.class);
37 if (removeds != null) {
38 for (Entry<InstanceIdentifier<Node>, List<LogicalSwitches>> deleted: removeds.entrySet()) {
39 deletedLs = deleted.getValue();
40 for (LogicalSwitches lswitch : deleted.getValue()) {
41 InstanceIdentifier<LogicalSwitches> lsKey =
42 deleted.getKey().augmentation(HwvtepGlobalAugmentation.class)
43 .child(LogicalSwitches.class, lswitch.key());
44 getDeviceInfo().clearConfigData(LogicalSwitches.class, lsKey);
45 onConfigUpdate(transaction, deleted.getKey(), lswitch, lsKey);
52 public void onConfigUpdate(TransactionBuilder transaction, InstanceIdentifier<Node> nodeIid,
53 LogicalSwitches logicalSwitches, InstanceIdentifier lsKey, Object... extraData) {
54 processDependencies(EmptyDependencyGetter.INSTANCE, transaction, nodeIid, lsKey, logicalSwitches);
58 public void doDeviceTransaction(final TransactionBuilder transaction,
59 final InstanceIdentifier<Node> instanceIdentifier,
60 final LogicalSwitches lswitch,
61 final InstanceIdentifier lsKey,
62 final Object... extraData) {
63 LogicalSwitchUcastsRemoveCommand cmd = new LogicalSwitchUcastsRemoveCommand(
64 newOperState(), getChanges(), deletedLs, lswitch);
65 markKeyAsInTransit(LogicalSwitches.class, lsKey);
66 clearConfigData(LogicalSwitches.class, lsKey);
67 hwvtepOperationalState.getConnectionInstance().transact(cmd);
71 protected List<LogicalSwitches> getData(final HwvtepGlobalAugmentation augmentation) {
72 return augmentation.getLogicalSwitches();
76 protected boolean areEqual(final LogicalSwitches sw1, final LogicalSwitches sw2) {
77 return sw1.key().equals(sw2.key()) && Objects.equals(sw1.getTunnelKey(), sw2.getTunnelKey());
81 protected boolean isDeleteCmd() {
86 public void onCommandSucceeded() {
87 for (MdsalUpdate mdsalUpdate : updates) {
88 getDeviceInfo().clearLogicalSwitchRefs(mdsalUpdate.getKey());