2 * Copyright (c) 2015 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.List;
16 import java.util.Map.Entry;
17 import java.util.Objects;
19 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
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.lib.schema.typed.TyperUtils;
24 import org.opendaylight.ovsdb.schema.hardwarevtep.LogicalSwitch;
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.LogicalSwitches;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
29 import org.opendaylight.yangtools.yang.binding.Identifiable;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 import com.google.common.base.Optional;
36 public class LogicalSwitchRemoveCommand extends AbstractTransactCommand<LogicalSwitches, HwvtepGlobalAugmentation> {
37 private static final Logger LOG = LoggerFactory.getLogger(LogicalSwitchRemoveCommand.class);
39 public LogicalSwitchRemoveCommand(HwvtepOperationalState state,
40 Collection<DataTreeModification<Node>> changes) {
41 super(state, changes);
45 public void execute(TransactionBuilder transaction) {
46 Map<InstanceIdentifier<Node>, List<LogicalSwitches>> removeds =
47 extractRemoved(getChanges(),LogicalSwitches.class);
48 if (removeds != null) {
49 for (Entry<InstanceIdentifier<Node>, List<LogicalSwitches>> created: removeds.entrySet()) {
50 if (!HwvtepSouthboundUtil.isEmpty(created.getValue())) {
51 for (LogicalSwitches lswitch : created.getValue()) {
52 InstanceIdentifier<LogicalSwitches> lsKey = created.getKey().augmentation(
53 HwvtepGlobalAugmentation.class).child(LogicalSwitches.class, lswitch.getKey());
54 updateCurrentTxDeleteData(LogicalSwitches.class, lsKey, lswitch);
56 getOperationalState().getDeviceInfo().scheduleTransaction(new TransactCommand() {
58 public void execute(TransactionBuilder transactionBuilder) {
59 LOG.debug("Running delete logical switch in seperate tx {}", created.getKey());
60 removeLogicalSwitch(transactionBuilder, created.getKey(), created.getValue());
64 public void onConfigUpdate(TransactionBuilder transaction, InstanceIdentifier nodeIid,
65 Identifiable data, InstanceIdentifier key, Object... extraData) {
69 public void doDeviceTransaction(TransactionBuilder transaction, InstanceIdentifier nodeIid,
70 Identifiable data, InstanceIdentifier key, Object... extraData) {
78 private void removeLogicalSwitch(final TransactionBuilder transaction,
79 final InstanceIdentifier<Node> nodeIid, final List<LogicalSwitches> lswitchList) {
80 for (LogicalSwitches lswitch: lswitchList) {
81 InstanceIdentifier<LogicalSwitches> lsKey = nodeIid.augmentation(HwvtepGlobalAugmentation.class).
82 child(LogicalSwitches.class, lswitch.getKey());
83 onConfigUpdate(transaction, nodeIid, lswitch, lsKey);
88 public void onConfigUpdate(final TransactionBuilder transaction,
89 final InstanceIdentifier<Node> nodeIid,
90 final LogicalSwitches lswitch,
91 final InstanceIdentifier lsKey,
92 final Object... extraData) {
93 processDependencies(null, transaction, nodeIid, lsKey, lswitch);
97 public void doDeviceTransaction(final TransactionBuilder transaction,
98 final InstanceIdentifier<Node> instanceIdentifier,
99 final LogicalSwitches lswitch,
100 final InstanceIdentifier lsKey,
101 final Object... extraData) {
102 LOG.debug("Removing logcial switch named: {}", lswitch.getHwvtepNodeName().getValue());
103 Optional<LogicalSwitches> operationalSwitchOptional =
104 getOperationalState().getLogicalSwitches(instanceIdentifier, lswitch.getKey());
105 LogicalSwitch logicalSwitch = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), LogicalSwitch.class, null);
107 if (operationalSwitchOptional.isPresent() &&
108 operationalSwitchOptional.get().getLogicalSwitchUuid() != null) {
109 UUID logicalSwitchUuid = new UUID(operationalSwitchOptional.get().getLogicalSwitchUuid().getValue());
110 transaction.add(op.delete(logicalSwitch.getSchema())
111 .where(logicalSwitch.getUuidColumn().getSchema().opEqual(logicalSwitchUuid)).build());
112 transaction.add(op.comment("Logical Switch: Deleting " + lswitch.getHwvtepNodeName().getValue()));
113 getOperationalState().getDeviceInfo().markKeyAsInTransit(RemoteMcastMacs.class, lsKey);
115 LOG.warn("Unable to delete logical switch {} because it was not found in the operational store",
116 lswitch.getHwvtepNodeName().getValue());
121 protected List<LogicalSwitches> getData(HwvtepGlobalAugmentation augmentation) {
122 return augmentation.getLogicalSwitches();
126 protected boolean areEqual(LogicalSwitches a , LogicalSwitches b) {
127 return a.getKey().equals(b.getKey()) && Objects.equals(a.getTunnelKey(), b.getTunnelKey());
131 protected boolean isRemoveCommand() {