BUG-5055: Initialization of LocRib Table 73/33373/1
authorClaudio D. Gasparini <cgaspari@cisco.com>
Thu, 21 Jan 2016 19:41:19 +0000 (20:41 +0100)
committerClaudio D. Gasparini <cgaspari@cisco.com>
Fri, 22 Jan 2016 15:58:41 +0000 (16:58 +0100)
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 <cgaspari@cisco.com>
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/ExportPolicyPeerTracker.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java

index 69b67656105e96992c3415dc111a6f8aa11a4741..f664edb79918614d8ba5baaa9845625cd1da5629 100644 (file)
@@ -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) {
index 1f853a5adc143ae0deffb34f7bccb615d7f519aa..5fbe0a9feec0cf2194eb693ef623e321db8566fc 100644 (file)
@@ -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<RouteUpdateKey, AbstractRouteEntry> ret, final DOMDataWriteTransaction tx) {
+        final Map<RouteUpdateKey, AbstractRouteEntry> 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<PathArgument, AbstractRouteEntry> 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<PathArgument, AbstractRouteEntry> 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);