From dac48d528aa5ddf2ef3b68277918cb8d2774225d Mon Sep 17 00:00:00 2001 From: "Claudio D. Gasparini" Date: Thu, 21 Jan 2016 20:41:19 +0100 Subject: [PATCH] BUG-5055: Initialization of LocRib Table When LocRib table are created when insert already existan routes. They where created when inserting supported tables. Which will make the process to be repeated if more than one table is supported. Solved by move the process at the point where specific table is created. Also fixed onTable change, since it should add only table to corresponding LocribWriter listener Change-Id: I4f87d1bf6e2b24d9ad1911d15ce3923c7538c156 Signed-off-by: Claudio D. Gasparini --- .../bgp/rib/impl/ExportPolicyPeerTracker.java | 8 +-- .../protocol/bgp/rib/impl/LocRibWriter.java | 65 ++++++++++--------- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/ExportPolicyPeerTracker.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/ExportPolicyPeerTracker.java index 69b6765610..f664edb799 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/ExportPolicyPeerTracker.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/ExportPolicyPeerTracker.java @@ -105,18 +105,18 @@ final class ExportPolicyPeerTracker extends AbstractPeerRoleTracker { return this.groups.get(Preconditions.checkNotNull(role)); } - boolean onTablesChanged(final PeerId peerId, final DataTreeCandidateNode node) { + void onTablesChanged(final PeerId peerId, final DataTreeCandidateNode node) { if (node.getDataAfter().isPresent()) { final NodeIdentifierWithPredicates value = (NodeIdentifierWithPredicates) node.getDataAfter().get().getIdentifier(); final boolean added = this.peerTables.put(peerId, value); if (added) { LOG.debug("Supported table {} added to peer {}", value, peerId); } - return added; } else { - LOG.debug("Removed tables {} from peer {}", this.peerTables.removeAll(peerId), peerId); + final NodeIdentifierWithPredicates value = (NodeIdentifierWithPredicates) node.getIdentifier(); + this.peerTables.remove(peerId,value); + LOG.debug("Removed tables {} from peer {}", value, peerId); } - return false; } boolean isTableSupported(final PeerId peerId, final TablesKey tablesKey) { diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java index 1f853a5adc..5fbe0a9fee 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java @@ -33,6 +33,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib. import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.Peer; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.peer.AdjRibOut; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.peer.EffectiveRibIn; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.peer.SupportedTables; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Attributes; @@ -157,15 +158,15 @@ final class LocRibWriter implements AutoCloseable, DOMDataTreeChangeListener { final NodeIdentifierWithPredicates peerKey = IdentifierUtils.peerKey(rootPath); final PeerId peerId = IdentifierUtils.peerId(peerKey); filterOutPeerRole(peerId, rootNode, rootPath, deletedPeers); - filterOutChangesToSupportedTables(peerId, rootNode, rootPath, tx); - filterOutAnyChangeOutsideEffRibsIn(peerId, rootNode, ret, tx); + filterOutChangesToSupportedTables(peerId, rootNode); + filterOutAnyChangeOutsideEffRibsIn(peerId, rootNode, ret, rootPath, tx); } return ret; } private void filterOutAnyChangeOutsideEffRibsIn(final PeerId peerId, final DataTreeCandidateNode rootNode, - final Map ret, final DOMDataWriteTransaction tx) { + final Map ret, final YangInstanceIdentifier rootPath, final DOMDataWriteTransaction tx) { final DataTreeCandidateNode ribIn = rootNode.getModifiedChild(EFFRIBIN_NID); if (ribIn == null) { LOG.debug("Skipping change {}", rootNode.getIdentifier()); @@ -176,34 +177,38 @@ final class LocRibWriter implements AutoCloseable, DOMDataTreeChangeListener { LOG.debug("Skipping change {}", rootNode.getIdentifier()); return; } + initializeTableWithExistenRoutes(table, peerId, rootPath, tx); updateNodes(table, peerId, tx, ret); } - private void filterOutChangesToSupportedTables(final PeerId peerIdOfNewPeer, final DataTreeCandidateNode rootNode, final YangInstanceIdentifier rootPath, final DOMDataWriteTransaction tx) { + private void filterOutChangesToSupportedTables(final PeerId peerIdOfNewPeer, final DataTreeCandidateNode rootNode) { final DataTreeCandidateNode tablesChange = rootNode.getModifiedChild(AbstractPeerRoleTracker.PEER_TABLES); - if (tablesChange != null) { + final NodeIdentifierWithPredicates supTablesKey = RibSupportUtils.toYangKey(SupportedTables.QNAME, this.localTablesKey); + final DataTreeCandidateNode containsLocalKeyTable = tablesChange.getModifiedChild(supTablesKey); + if(containsLocalKeyTable != null) { + this.peerPolicyTracker.onTablesChanged(peerIdOfNewPeer, containsLocalKeyTable); + } + } + } + + private void initializeTableWithExistenRoutes(final DataTreeCandidateNode table, final PeerId peerIdOfNewPeer, final YangInstanceIdentifier rootPath, + final DOMDataWriteTransaction tx) { + if (!table.getDataBefore().isPresent() && isTableSupported(peerIdOfNewPeer)) { + LOG.debug("Peer {} table has been created, inserting existent routes", peerIdOfNewPeer); final PeerRole newPeerRole = this.peerPolicyTracker.getRole(IdentifierUtils.peerPath(rootPath)); final PeerExportGroup peerGroup = this.peerPolicyTracker.getPeerGroup(newPeerRole); - - for (final DataTreeCandidateNode node : tablesChange.getChildNodes()) { - final boolean supportedTableAdded = this.peerPolicyTracker.onTablesChanged(peerIdOfNewPeer, node); - if (supportedTableAdded) { - for (Map.Entry entry : this.routeEntries.entrySet()) { - if(isTableSupported(peerIdOfNewPeer)) { - final AbstractRouteEntry routeEntry = entry.getValue(); - final PathArgument routeId = entry.getKey(); - final YangInstanceIdentifier routeTarget = getRouteTarget(rootPath, routeId); - final NormalizedNode value = routeEntry.createValue(routeId); - final PeerId routePeerId = RouterIds.createPeerId(routeEntry.getBestRouterId()); - final ContainerNode effectiveAttributes = peerGroup.effectiveAttributes(routePeerId, routeEntry.attributes()); - if (effectiveAttributes != null && value != null) { - LOG.debug("Write route {} to peer AdjRibsOut {}", value, peerIdOfNewPeer); - tx.put(LogicalDatastoreType.OPERATIONAL, routeTarget, value); - tx.put(LogicalDatastoreType.OPERATIONAL, routeTarget.node(this.attributesIdentifier), effectiveAttributes); - } - } - } + for (Map.Entry entry : this.routeEntries.entrySet()) { + final AbstractRouteEntry routeEntry = entry.getValue(); + final PathArgument routeId = entry.getKey(); + final YangInstanceIdentifier routeTarget = getRouteTarget(rootPath, routeId); + final NormalizedNode value = routeEntry.createValue(routeId); + final PeerId routePeerId = RouterIds.createPeerId(routeEntry.getBestRouterId()); + final ContainerNode effectiveAttributes = peerGroup.effectiveAttributes(routePeerId, routeEntry.attributes()); + if (effectiveAttributes != null && value != null) { + LOG.debug("Write route {} to peer AdjRibsOut {}", value, peerIdOfNewPeer); + tx.put(LogicalDatastoreType.OPERATIONAL, routeTarget, value); + tx.put(LogicalDatastoreType.OPERATIONAL, routeTarget.node(this.attributesIdentifier), effectiveAttributes); } } } @@ -254,14 +259,10 @@ final class LocRibWriter implements AutoCloseable, DOMDataTreeChangeListener { entry = createEntry(routeId); } entry.addRoute(routerId, this.attributesIdentifier, maybeData.get()); - } else if (entry != null) { - if(entry.removeRoute(routerId)) { - this.routeEntries.remove(routeId); - LOG.trace("Removed route from {}", routerId); - entry = null; - }else { - routes.put(routeUpdateKey, null); - } + } else if (entry != null && entry.removeRoute(routerId)) { + this.routeEntries.remove(routeId); + LOG.trace("Removed route from {}", routerId); + entry = null; } LOG.debug("Updated route {} entry {}", routeId, entry); routes.put(routeUpdateKey, entry); -- 2.36.6