BUG-3347 : fix receiving updates only on first route 77/22277/3
authorDana Kutenicsova <dkutenic@cisco.com>
Wed, 10 Jun 2015 13:42:00 +0000 (15:42 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 11 Jun 2015 18:28:57 +0000 (18:28 +0000)
This was due to calling clear before each write into AdjRibsOut.
Create tables in AdjRibsOut beforehand, so we don't have to take
care about it when a route comes.

Change-Id: I8679399a50b54d83d5432c7b75aadd9e1c7ea928
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AdjRibInWriter.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java

index 6e619c64b3fdf260cae5834460966420ed0c4b0b..bf1bca6cbebb17daced7e77ed40021144026bf02 100644 (file)
@@ -73,18 +73,18 @@ final class AdjRibInWriter {
     private static final ContainerNode EMPTY_ADJRIBOUT = Builders.containerBuilder().withNodeIdentifier(ADJRIBOUT).addChild(ImmutableNodes.mapNodeBuilder(Tables.QNAME).build()).build();
 
     private final Map<TablesKey, TableContext> tables;
-    private final YangInstanceIdentifier tablesRoot;
+    private final YangInstanceIdentifier peerPath;
     private final YangInstanceIdentifier ribPath;
     private final DOMTransactionChain chain;
     private final PeerId peerId;
     private final String role;
 
-    private AdjRibInWriter(final YangInstanceIdentifier ribPath, final DOMTransactionChain chain, final PeerId peerId, final String role, final YangInstanceIdentifier tablesRoot, final Map<TablesKey, TableContext> tables) {
+    private AdjRibInWriter(final YangInstanceIdentifier ribPath, final DOMTransactionChain chain, final PeerId peerId, final String role, final YangInstanceIdentifier peerPath, final Map<TablesKey, TableContext> tables) {
         this.ribPath = Preconditions.checkNotNull(ribPath);
         this.chain = Preconditions.checkNotNull(chain);
         this.tables = Preconditions.checkNotNull(tables);
         this.role = Preconditions.checkNotNull(role);
-        this.tablesRoot = tablesRoot;
+        this.peerPath = peerPath;
         this.peerId = peerId;
     }
 
@@ -126,33 +126,11 @@ final class AdjRibInWriter {
     AdjRibInWriter transform(final PeerId newPeerId, final RIBSupportContextRegistry registry, final Set<TablesKey> tableTypes, final boolean isAppPeer) {
         final DOMDataWriteTransaction tx = this.chain.newWriteOnlyTransaction();
 
-        final YangInstanceIdentifier newTablesRoot;
+        final YangInstanceIdentifier newPeerPath;
         if (!newPeerId.equals(this.peerId)) {
-            if (this.peerId != null) {
-                // Wipe old peer data completely
-                tx.delete(LogicalDatastoreType.OPERATIONAL, this.ribPath.node(Peer.QNAME).node(new NodeIdentifierWithPredicates(Peer.QNAME, PEER_ID_QNAME, this.peerId.getValue())));
-            }
-
-            // Install new empty peer structure
-            final NodeIdentifierWithPredicates peerKey = IdentifierUtils.domPeerId(newPeerId);
-            final YangInstanceIdentifier newPeerPath = this.ribPath.node(Peer.QNAME).node(peerKey);
-
-            final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> pb = Builders.mapEntryBuilder();
-            pb.withNodeIdentifier(peerKey);
-            pb.withChild(ImmutableNodes.leafNode(PEER_ID, newPeerId.getValue()));
-            pb.withChild(ImmutableNodes.leafNode(PEER_ROLE, this.role));
-            pb.withChild(EMPTY_ADJRIBIN);
-            pb.withChild(EMPTY_EFFRIBIN);
-            if (!isAppPeer) {
-                pb.withChild(EMPTY_ADJRIBOUT);
-            }
-
-            tx.put(LogicalDatastoreType.OPERATIONAL, newPeerPath, pb.build());
-            LOG.debug("New peer {} structure installed.", newPeerPath);
-
-            newTablesRoot = newPeerPath.node(EMPTY_ADJRIBIN.getIdentifier()).node(TABLES);
+            newPeerPath = this.createEmptyPeerStructure(newPeerId, isAppPeer, tx);
         } else {
-            newTablesRoot = this.tablesRoot;
+            newPeerPath = this.peerPath;
 
             // Wipe tables which are not present in the new types
             for (final Entry<TablesKey, TableContext> e : this.tables.entrySet()) {
@@ -168,17 +146,22 @@ final class AdjRibInWriter {
             TableContext ctx = this.tables.get(k);
             if (ctx == null) {
                 final RIBSupportContext rs = registry.getRIBSupportContext(k);
+                // TODO: Use returned value once Instance Identifier builder allows for it.
+                final NodeIdentifierWithPredicates key = RibSupportUtils.toYangTablesKey(k);
                 if (rs == null) {
                     LOG.warn("No support for table type {}, skipping it", k);
                     continue;
                 }
+                // install tables for adj-ribs-out (we do not need TableContext for that
+                if (!isAppPeer) {
+                    rs.clearTable(tx, newPeerPath.node(EMPTY_ADJRIBOUT.getIdentifier()).node(TABLES).node(key));
+                }
 
                 // We will use table keys very often, make sure they are optimized
-                final InstanceIdentifierBuilder idb = YangInstanceIdentifier.builder(newTablesRoot);
-
-                // TODO: Use returned value once Instance Identifier builder allows for it.
-                final NodeIdentifierWithPredicates key = RibSupportUtils.toYangTablesKey(k);
+                final InstanceIdentifierBuilder idb = YangInstanceIdentifier.builder(newPeerPath.node(EMPTY_ADJRIBIN.getIdentifier()).node(TABLES));
                 idb.nodeWithKey(key.getNodeType(), key.getKeyValues());
+
+                // install tables for adj-ribs-in
                 ctx = new TableContext(rs, idb.build());
                 ctx.clearTable(tx);
             }
@@ -189,7 +172,30 @@ final class AdjRibInWriter {
 
         tx.submit();
 
-        return new AdjRibInWriter(this.ribPath, this.chain, newPeerId, this.role, newTablesRoot, tb.build());
+        return new AdjRibInWriter(this.ribPath, this.chain, newPeerId, this.role, newPeerPath, tb.build());
+    }
+
+    private YangInstanceIdentifier createEmptyPeerStructure(final PeerId newPeerId, final boolean isAppPeer, final DOMDataWriteTransaction tx) {
+        if (this.peerId != null) {
+            // Wipe old peer data completely
+            tx.delete(LogicalDatastoreType.OPERATIONAL, this.ribPath.node(Peer.QNAME).node(new NodeIdentifierWithPredicates(Peer.QNAME, PEER_ID_QNAME, this.peerId.getValue())));
+        }
+        // Install new empty peer structure
+        final NodeIdentifierWithPredicates peerKey = IdentifierUtils.domPeerId(newPeerId);
+        final YangInstanceIdentifier newPeerPath = this.ribPath.node(Peer.QNAME).node(peerKey);
+
+        final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> pb = Builders.mapEntryBuilder();
+        pb.withNodeIdentifier(peerKey);
+        pb.withChild(ImmutableNodes.leafNode(PEER_ID, newPeerId.getValue()));
+        pb.withChild(ImmutableNodes.leafNode(PEER_ROLE, this.role));
+        pb.withChild(EMPTY_ADJRIBIN);
+        pb.withChild(EMPTY_EFFRIBIN);
+        if (!isAppPeer) {
+            pb.withChild(EMPTY_ADJRIBOUT);
+        }
+        tx.put(LogicalDatastoreType.OPERATIONAL, newPeerPath, pb.build());
+        LOG.debug("New peer {} structure installed.", newPeerPath);
+        return newPeerPath;
     }
 
     /**
index 4c21053a1a52616f67ca558613a8c04c9d813694..ea503efaf09d422d129b779909ace6ffa8e7eec0 100644 (file)
@@ -23,7 +23,6 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
-import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContext;
 import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry;
 import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
 import org.opendaylight.protocol.bgp.rib.spi.RibSupportUtils;
@@ -240,10 +239,6 @@ final class LocRibWriter implements AutoCloseable, DOMDataTreeChangeListener {
                 final PeerId peerId = key.getPeerId();
                 final ContainerNode effectiveAttributes = peerGroup.effectiveAttributes(peerId, attributes);
                 for (final Entry<PeerId, YangInstanceIdentifier> pid : peerGroup.getPeers()) {
-                    // This points to adj-rib-out for a particular peer/table combination
-                    final RIBSupportContext ribCtx = this.registry.getRIBSupportContext(this.tableKey);
-                    // FIXME: the table should be created for a peer only once
-                    ribCtx.clearTable(tx, pid.getValue().node(AdjRibOut.QNAME).node(Tables.QNAME).node(this.tableKey));
                     final YangInstanceIdentifier routeTarget = this.ribSupport.routePath(pid.getValue().node(AdjRibOut.QNAME).node(Tables.QNAME).node(this.tableKey).node(Routes.QNAME), key.getRouteId());
                     if (effectiveAttributes != null && value != null && !peerId.equals(pid.getKey())) {
                         LOG.debug("Write route to AdjRibsOut {}", value);