From afd99993f7e7f9cf23055da12656fbf0d601a132 Mon Sep 17 00:00:00 2001 From: Chetan Arakere Gowdru Date: Thu, 9 Jan 2020 12:33:00 +0530 Subject: [PATCH] Avoid unnecessary bridge Oper DS read Description: Avoid uncessary bridge Oper DS read just to get the bridge-name during termination-point create and delete. The bridge name is already available in the termination point parent node-id(/bridge/br-int) from which bridge name can get fetched out. Ex: "node-id": "ovsdb://uuid/d6f5d855-cdae-4275-bf4f-a71ee6e24ca3/bridge/br-int" Signed-off-by: Chetan Arakere Gowdru Change-Id: I420face0c628f118b14c5c213756075a199ea6fa Signed-off-by: Chetan Arakere Gowdru Signed-off-by: xcheara --- .../ovsdb/southbound/SouthboundUtil.java | 10 ++++++ .../TerminationPointCreateCommand.java | 32 +++++-------------- .../TerminationPointDeleteCommand.java | 22 ++++--------- 3 files changed, 25 insertions(+), 39 deletions(-) diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundUtil.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundUtil.java index 34fd897e0..fe610b27c 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundUtil.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundUtil.java @@ -187,4 +187,14 @@ public final class SouthboundUtil { } return nodeId; } + + public static String getBridgeNameFromOvsdbNodeId(InstanceIdentifier nodeIid) { + String nodeId = getOvsdbNodeId(nodeIid); + if (nodeId != null && !nodeId.isEmpty() && nodeId.contains("bridge") + && nodeId.lastIndexOf("bridge") + 7 < nodeId.length()) { + return nodeId.substring(nodeId.indexOf("bridge") + 7);// to fetch bridge name ex: "/bridge/br-int" + } else { + return null; + } + } } diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/TerminationPointCreateCommand.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/TerminationPointCreateCommand.java index 0310f969f..6afa59b47 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/TerminationPointCreateCommand.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/TerminationPointCreateCommand.java @@ -22,7 +22,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; import org.opendaylight.controller.md.sal.binding.api.DataTreeModification; -import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; import org.opendaylight.ovsdb.lib.error.SchemaVersionMismatchException; import org.opendaylight.ovsdb.lib.notation.Mutator; import org.opendaylight.ovsdb.lib.notation.UUID; @@ -34,11 +33,9 @@ import org.opendaylight.ovsdb.schema.openvswitch.Port; import org.opendaylight.ovsdb.southbound.InstanceIdentifierCodec; import org.opendaylight.ovsdb.southbound.SouthboundConstants; import org.opendaylight.ovsdb.southbound.SouthboundMapper; -import org.opendaylight.ovsdb.southbound.SouthboundProvider; import org.opendaylight.ovsdb.southbound.SouthboundUtil; import org.opendaylight.ovsdb.utils.yang.YangUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.InterfaceTypeBase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbPortInterfaceAttributes.VlanMode; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceBfd; @@ -108,8 +105,11 @@ public class TerminationPointCreateCommand implements TransactCommand { terminationPoint.getName(),portUuid); //Configure bridge with the above port details Bridge bridge = transaction.getTypedRowWrapper(Bridge.class); - if (getBridge(entry.getKey(), nodes) != null) { - bridge.setName(getBridge(entry.getKey(), nodes).getBridgeName().getValue()); + String bridgeName = SouthboundUtil + .getBridgeNameFromOvsdbNodeId(entry.getKey().firstIdentifierOf(Node.class)); + if (bridgeName != null) { + LOG.trace("Updating bridge {} for newly added port {}", bridgeName, terminationPoint.getName()); + bridge.setName(bridgeName); bridge.setPorts(Collections.singleton(new UUID(portUuid))); transaction.add(op.mutate(bridge) @@ -117,6 +117,9 @@ public class TerminationPointCreateCommand implements TransactCommand { Mutator.INSERT, bridge.getPortsColumn().getData()) .where(bridge.getNameColumn().getSchema() .opEqual(bridge.getNameColumn().getData())).build()); + } else { + LOG.error("Missing BridgeName for Node {} during creation of port {}", + entry.getKey().firstIdentifierOf(Node.class), terminationPoint.getName()); } } } @@ -354,25 +357,6 @@ public class TerminationPointCreateCommand implements TransactCommand { } } - private OvsdbBridgeAugmentation getBridge(final InstanceIdentifier key, - final Map, Node> nodes) { - OvsdbBridgeAugmentation bridge = null; - InstanceIdentifier nodeIid = key.firstIdentifierOf(Node.class); - if (nodes != null && nodes.get(nodeIid) != null) { - Node node = nodes.get(nodeIid); - bridge = node.augmentation(OvsdbBridgeAugmentation.class); - if (bridge == null) { - ReadOnlyTransaction transaction = SouthboundProvider.getDb().newReadOnlyTransaction(); - Optional nodeOptional = SouthboundUtil.readNode(transaction, nodeIid); - if (nodeOptional.isPresent()) { - bridge = nodeOptional.get().augmentation(OvsdbBridgeAugmentation.class); - } - transaction.close(); - } - } - return bridge; - } - public static void stampInstanceIdentifier(final TransactionBuilder transaction, final InstanceIdentifier iid, final String interfaceName, final InstanceIdentifierCodec instanceIdentifierCodec) { diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/TerminationPointDeleteCommand.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/TerminationPointDeleteCommand.java index ce8cf610b..6242c3e6e 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/TerminationPointDeleteCommand.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/TerminationPointDeleteCommand.java @@ -21,7 +21,7 @@ import org.opendaylight.ovsdb.lib.operations.TransactionBuilder; import org.opendaylight.ovsdb.schema.openvswitch.Bridge; import org.opendaylight.ovsdb.schema.openvswitch.Port; import org.opendaylight.ovsdb.southbound.InstanceIdentifierCodec; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation; +import org.opendaylight.ovsdb.southbound.SouthboundUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -62,21 +62,13 @@ public class TerminationPointDeleteCommand implements TransactCommand { for (InstanceIdentifier removedTpIid: removedTps) { LOG.debug("Received request to delete termination point {}", removedTpIid); OvsdbTerminationPointAugmentation original = originals.get(removedTpIid); - Node originalNode = originalNodes.get(removedTpIid.firstIdentifierOf(Node.class)); - LOG.trace("Termination point's associated original node {}", originalNode); - OvsdbBridgeAugmentation originalOvsdbBridgeAugmentation = - originalNode.augmentation(OvsdbBridgeAugmentation.class); - String bridgeName = null; - if (originalOvsdbBridgeAugmentation != null) { - bridgeName = originalOvsdbBridgeAugmentation.getBridgeName().getValue(); - } else { - Optional bridgeAug = state.getOvsdbBridgeAugmentation(removedTpIid); - if (bridgeAug.isPresent()) { - bridgeName = bridgeAug.get().getBridgeName().getValue(); - } else { - LOG.error("Bridge does not exist for termination point {}", removedTpIid); - } + String bridgeName = SouthboundUtil.getBridgeNameFromOvsdbNodeId(removedTpIid.firstIdentifierOf(Node.class)); + if (bridgeName == null) { + LOG.error("Missing Bridge Name for Node {} during deletion of Port {}", + removedTpIid.firstIdentifierOf(Node.class), original.getName()); + continue; } + LOG.trace("Deleting port {} from bridge {}", original.getName(), bridgeName); Port port = transaction.getTypedRowSchema(Port.class); Optional tpAugmentation = state.getOvsdbTerminationPointAugmentation(removedTpIid); -- 2.36.6