BUG-2383 : fix creating AdjRibsOut tables in datastore
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / RIBImpl.java
index ac3dd2e85c05192286e23773204a7b1fd45e1270..cbe5f6dd676c38c8cb1c7bdd05271590e530f64e 100644 (file)
@@ -83,6 +83,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.rib.TablesKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
 import org.opendaylight.yangtools.binding.data.codec.api.BindingCodecTreeFactory;
 import org.opendaylight.yangtools.sal.binding.generator.impl.GeneratedClassLoadingStrategy;
@@ -136,6 +137,8 @@ public final class RIBImpl extends DefaultRibReference implements AutoCloseable,
     private final RIBExtensionConsumerContext extensions;
     private final YangInstanceIdentifier yangRibId;
     private final RIBSupportContextRegistryImpl ribContextRegistry;
+    private final EffectiveRibInWriter efWriter;
+
     private final Runnable scheduler = new Runnable() {
         @Override
         public void run() {
@@ -191,13 +194,6 @@ public final class RIBImpl extends DefaultRibReference implements AutoCloseable,
 
         final WriteTransaction trans = this.chain.newWriteOnlyTransaction();
 
-        final PolicyDatabase pd  = new PolicyDatabase(localAs.getValue(), localBgpId, this.clusterId);
-
-        final DOMDataBrokerExtension service = this.domDataBroker.getSupportedExtensions().get(DOMDataTreeChangeService.class);
-        final DOMTransactionChain domChain = this.createPeerChain(this);
-        EffectiveRibInWriter.create((DOMDataTreeChangeService) service, domChain, getYangRibId(), pd, this.ribContextRegistry);
-        LOG.debug("Effective RIB created.");
-
         // put empty BgpRib if not exists
         trans.put(LogicalDatastoreType.OPERATIONAL, getInstanceIdentifier(),
             new RibBuilder().setKey(new RibKey(ribId)).setPeer(Collections.<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.Peer> emptyList()).setId(ribId).setLocRib(
@@ -208,13 +204,6 @@ public final class RIBImpl extends DefaultRibReference implements AutoCloseable,
             if (this.tables.create(trans, this, key) == null) {
                 LOG.debug("Did not create local table for unhandled table type {}", t);
             }
-
-            // reusing the for cycle
-            // create locRibWriter for each table
-            // FIXME: temporary create writer only for Ipv4
-            if (key.getAfi().equals(Ipv4AddressFamily.class)) {
-                LocRibWriter.create(this.ribContextRegistry.getRIBSupportContext(key).getRibSupport(), domChain, getYangRibId(), localAs, (DOMDataTreeChangeService) service, pd);
-            }
         }
 
         Futures.addCallback(trans.submit(), new FutureCallback<Void>() {
@@ -229,12 +218,30 @@ public final class RIBImpl extends DefaultRibReference implements AutoCloseable,
             }
 
         });
+
+        final PolicyDatabase pd  = new PolicyDatabase(localAs.getValue(), localBgpId, this.clusterId);
+
+        final DOMDataBrokerExtension service = this.domDataBroker.getSupportedExtensions().get(DOMDataTreeChangeService.class);
+        final DOMTransactionChain domChain = this.createPeerChain(this);
+        this.efWriter = EffectiveRibInWriter.create((DOMDataTreeChangeService) service, this.createPeerChain(this), getYangRibId(), pd, this.ribContextRegistry);
+        LOG.debug("Effective RIB created.");
+
+        for (final BgpTableType t : localTables) {
+            final TablesKey key = new TablesKey(t.getAfi(), t.getSafi());
+            // create locRibWriter for each table
+            // FIXME: temporary create writer only for Ipv4
+            if (key.getAfi().equals(Ipv4AddressFamily.class) || key.getAfi().equals(Ipv6AddressFamily.class)) {
+                LocRibWriter.create(this.ribContextRegistry, key, this.createPeerChain(this), getYangRibId(), localAs, (DOMDataTreeChangeService) service, pd);
+            }
+        }
     }
 
+    @Deprecated
     synchronized void initTables(final byte[] remoteBgpId) {
     }
 
     @Override
+    @Deprecated
     public synchronized void updateTables(final Peer peer, final Update message) {
         final AdjRIBsTransactionImpl trans = new AdjRIBsTransactionImpl(this.ribOuts, this.comparator, this.chain.newWriteOnlyTransaction());
 
@@ -346,6 +353,7 @@ public final class RIBImpl extends DefaultRibReference implements AutoCloseable,
         });
     }
 
+    @Deprecated
     @Override
     public synchronized void clearTable(final Peer peer, final TablesKey key) {
         final AdjRIBsIn<?, ?> ari = this.tables.get(key);
@@ -377,6 +385,7 @@ public final class RIBImpl extends DefaultRibReference implements AutoCloseable,
     }
 
     @SuppressWarnings("unchecked")
+    @Deprecated
     protected <K, V extends Route> AdjRIBsIn<K, V> getTable(final TablesKey key) {
         return (AdjRIBsIn<K, V>) this.tables.get(key);
     }
@@ -419,6 +428,7 @@ public final class RIBImpl extends DefaultRibReference implements AutoCloseable,
         return this.dispatcher;
     }
 
+    @Deprecated
     @Override
     public void initTable(final Peer bgpPeer, final TablesKey key) {
         // FIXME: BUG-196: support graceful restart