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.SouthboundMapper;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeName;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
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.TerminationPoint;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class OvsdbPortRemoveCommand extends AbstractTransactionCommand {
33 private static final Logger LOG = LoggerFactory.getLogger(OvsdbPortRemoveCommand.class);
35 public OvsdbPortRemoveCommand(ConnectionInfo key, TableUpdates updates,
36 DatabaseSchema dbSchema) {
37 super(key, updates, dbSchema);
41 public void execute(ReadWriteTransaction transaction) {
42 String bridgeName = null;
43 String portName = null;
44 Collection<Port> portRemovedRows = TyperUtils.extractRowsRemoved(
45 Port.class, getUpdates(), getDbSchema()).values();
46 Map<UUID,Bridge> bridgeUpdatedRows = TyperUtils.extractRowsUpdated(
47 Bridge.class, getUpdates(), getDbSchema());
48 Map<UUID,Bridge> bridgeUpdatedOldRows = TyperUtils.extractRowsOld(
49 Bridge.class, getUpdates(), getDbSchema());
50 for (Port port : portRemovedRows) {
51 for (UUID bridgeUUID : bridgeUpdatedOldRows.keySet()) {
52 Bridge oldBridgeData = bridgeUpdatedOldRows.get(bridgeUUID);
53 if (oldBridgeData.getPortsColumn() != null
54 && oldBridgeData.getPortsColumn().getData().contains(port.getUuidColumn().getData())
55 && (! bridgeUpdatedRows.isEmpty())) {
56 Bridge updatedBridgeData = bridgeUpdatedRows.get(bridgeUUID);
57 bridgeName = updatedBridgeData.getName();
61 if (bridgeName == null) {
62 LOG.warn("Bridge not found for port {}",port);
65 portName = port.getName();
66 final InstanceIdentifier<TerminationPoint> nodePath = SouthboundMapper
67 .createInstanceIdentifier(getConnectionInfo(),
68 new OvsdbBridgeName(bridgeName)).child(
69 TerminationPoint.class,
70 new TerminationPointKey(new TpId(portName)));
71 transaction.delete(LogicalDatastoreType.OPERATIONAL, nodePath);