2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.transactions.md;
11 import java.util.Collection;
13 import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
14 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
15 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundMapper;
16 import org.opendaylight.ovsdb.hwvtepsouthbound.events.PortEvent;
17 import org.opendaylight.ovsdb.lib.message.TableUpdates;
18 import org.opendaylight.ovsdb.lib.notation.UUID;
19 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
20 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
21 import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalPort;
22 import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalSwitch;
23 import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionType;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.port.attributes.VlanBindings;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 public class HwvtepPhysicalPortRemoveCommand extends AbstractTransactionCommand {
35 private static final Logger LOG = LoggerFactory.getLogger(HwvtepPhysicalPortRemoveCommand.class);
37 public HwvtepPhysicalPortRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates,
38 DatabaseSchema dbSchema) {
39 super(key, updates, dbSchema);
43 public void execute(ReadWriteTransaction transaction) {
44 Collection<PhysicalPort> deletedPortRows =
45 TyperUtils.extractRowsRemoved(PhysicalPort.class, getUpdates(), getDbSchema()).values();
46 Map<UUID, PhysicalSwitch> updatedPSRows =
47 TyperUtils.extractRowsUpdated(PhysicalSwitch.class, getUpdates(), getDbSchema());
48 Map<UUID, PhysicalSwitch> oldPSRows =
49 TyperUtils.extractRowsOld(PhysicalSwitch.class, getUpdates(), getDbSchema());
50 for (PhysicalPort port : deletedPortRows) {
51 PhysicalSwitch updatedPSwitchData = null;
52 for (Map.Entry<UUID, PhysicalSwitch> updatedEntry : updatedPSRows.entrySet()) {
53 UUID switchUUID = updatedEntry.getKey();
54 PhysicalSwitch oldPSwitchData = oldPSRows.get(switchUUID);
55 if (oldPSwitchData.getPortsColumn() != null
56 && oldPSwitchData.getPortsColumn().getData().contains(port.getUuidColumn().getData())
57 && !updatedPSRows.isEmpty()) {
58 updatedPSwitchData = updatedEntry.getValue();
62 if (updatedPSwitchData == null) {
63 LOG.warn("PhysicalSwitch not found for port {}", port);
65 String portName = port.getName();
66 final InstanceIdentifier<TerminationPoint> nodePath =
67 HwvtepSouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance(),
68 updatedPSwitchData).child(TerminationPoint.class,
69 new TerminationPointKey(new TpId(portName)));
70 addToDeleteTx(transaction, VlanBindings.class, nodePath, port.getUuid());
71 addToDeviceUpdate(TransactionType.DELETE,
72 new PortEvent(port, nodePath.firstKeyOf(Node.class).getNodeId()));
73 getDeviceInfo().clearDeviceOperData(TerminationPoint.class, nodePath);