2 * Copyright (c) 2015 Intel Corp. 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.southbound.transactions.md;
11 import java.util.Collection;
14 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.ovsdb.lib.message.TableUpdates;
17 import org.opendaylight.ovsdb.lib.notation.UUID;
18 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
19 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
20 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
21 import org.opendaylight.ovsdb.schema.openvswitch.Port;
22 import org.opendaylight.ovsdb.southbound.OvsdbConnectionInstance;
23 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public class OvsdbPortRemoveCommand extends AbstractTransactionCommand {
32 private static final Logger LOG = LoggerFactory.getLogger(OvsdbPortRemoveCommand.class);
34 public OvsdbPortRemoveCommand(OvsdbConnectionInstance key, TableUpdates updates,
35 DatabaseSchema dbSchema) {
36 super(key, updates, dbSchema);
40 public void execute(ReadWriteTransaction transaction) {
41 String portName = null;
42 Collection<Port> portRemovedRows = TyperUtils.extractRowsRemoved(
43 Port.class, getUpdates(), getDbSchema()).values();
44 Map<UUID,Bridge> bridgeUpdatedRows = TyperUtils.extractRowsUpdated(
45 Bridge.class, getUpdates(), getDbSchema());
46 Map<UUID,Bridge> bridgeUpdatedOldRows = TyperUtils.extractRowsOld(
47 Bridge.class, getUpdates(), getDbSchema());
48 for (Port port : portRemovedRows) {
49 Bridge updatedBridgeData = null;
50 for (UUID bridgeUUID : bridgeUpdatedOldRows.keySet()) {
51 Bridge oldBridgeData = bridgeUpdatedOldRows.get(bridgeUUID);
52 if (oldBridgeData.getPortsColumn() != null
53 && oldBridgeData.getPortsColumn().getData().contains(port.getUuidColumn().getData())
54 && (! bridgeUpdatedRows.isEmpty())) {
55 updatedBridgeData = bridgeUpdatedRows.get(bridgeUUID);
59 if (updatedBridgeData == null) {
60 LOG.warn("Bridge not found for port {}",port);
63 portName = port.getName();
64 final InstanceIdentifier<TerminationPoint> nodePath = SouthboundMapper
65 .createInstanceIdentifier(getOvsdbConnectionInstance(),
66 updatedBridgeData).child(
67 TerminationPoint.class,
68 new TerminationPointKey(new TpId(portName)));
69 transaction.delete(LogicalDatastoreType.OPERATIONAL, nodePath);