MRI version bumpup for Aluminium
[netvirt.git] / bgpmanager / impl / src / main / java / org / opendaylight / netvirt / bgpmanager / BgpConfigurationManager.java
index 09398dc7fef74b12ebe885f0f3d9aa6a139cd64f..280f662204c2184c55228c42917e507288699f4c 100755 (executable)
@@ -10,7 +10,6 @@ package org.opendaylight.netvirt.bgpmanager;
 import static org.opendaylight.netvirt.bgpmanager.oam.BgpConstants.HISTORY_LIMIT;
 import static org.opendaylight.netvirt.bgpmanager.oam.BgpConstants.HISTORY_THRESHOLD;
 
-import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.net.InetAddresses;
 import com.google.common.util.concurrent.Futures;
@@ -33,6 +32,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.Optional;
 import java.util.Timer;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentHashMap;
@@ -54,16 +54,14 @@ import org.apache.thrift.TApplicationException;
 import org.apache.thrift.TException;
 import org.apache.thrift.transport.TTransport;
 import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 import org.opendaylight.genius.mdsalutil.NwConstants;
 import org.opendaylight.genius.utils.clustering.EntityOwnershipUtils;
 import org.opendaylight.infrautils.metrics.MetricProvider;
+import org.opendaylight.mdsal.binding.api.ClusteredDataTreeChangeListener;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
 import org.opendaylight.mdsal.eos.binding.api.Entity;
 import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipCandidateRegistration;
 import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipListenerRegistration;
@@ -89,6 +87,7 @@ import org.opendaylight.netvirt.fibmanager.api.RouteOrigin;
 import org.opendaylight.netvirt.vpnmanager.api.intervpnlink.IVpnLinkService;
 import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionHistory;
 import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionType;
+import org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener;
 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebfd.rev190219.BfdConfig;
 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebfd.rev190219.BfdConfigBuilder;
 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.AddressFamily;
@@ -142,6 +141,7 @@ import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev1509
 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfscontainer.VrfsKey;
 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfscontainer.vrfs.AddressFamiliesVrf;
 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfscontainer.vrfs.AddressFamiliesVrfBuilder;
+import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfscontainer.vrfs.AddressFamiliesVrfKey;
 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.tcp.security.option.grouping.TcpSecurityOption;
 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.tcp.security.option.grouping.tcp.security.option.TcpMd5SignatureOption;
 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.tcp.security.option.grouping.tcp.security.option.TcpMd5SignatureOptionBuilder;
@@ -150,6 +150,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.macvrfentries.MacVrfEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry;
@@ -200,6 +201,7 @@ public class BgpConfigurationManager implements EbgpService {
     private static final String UPD_WARN = "Update operation not supported; Config store updated;"
             + " restore with another Update if needed.";
     private static long bgp_as_num = 0;
+    private static List<Neighbors> nbrList = new ArrayList<>();
     private int bgpKaTime = 0;
     private int bgpHoldTime = 0;
     private int bgpGrRestartTime = 0;
@@ -264,6 +266,9 @@ public class BgpConfigurationManager implements EbgpService {
     // map<rd, map<tep-ip, map<mac, l2vni>>>
     private final Map<String, Map<String, Map<String, Uint32>>> rt2TepMap = new ConcurrentHashMap<>();
 
+    //map<rd+prefix/plen, list (nexthop)>
+    private final Map<String,List> fibMap = new HashMap<>();
+
     private final List<AutoCloseable> listeners = new ArrayList<>();
 
     private final EntityOwnershipUtils entityOwnershipUtils;
@@ -411,8 +416,8 @@ public class BgpConfigurationManager implements EbgpService {
         for (Class<?> reactor : REACTORS) {
             Object obj = createListener(reactor);
             if (obj != null) {
-                AsyncDataTreeChangeListenerBase dcl = (AsyncDataTreeChangeListenerBase) obj;
-                dcl.registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
+                AbstractAsyncDataTreeChangeListener dcl = (AbstractAsyncDataTreeChangeListener) obj;
+                dcl.register();
                 listeners.add(dcl);
             }
         }
@@ -491,6 +496,8 @@ public class BgpConfigurationManager implements EbgpService {
                     //disconnect the CONFIG SERVER port (which was )opened during I was Owner
                     bgpRouter.disconnect();
                 }
+                stopBgpCountersTask();
+                stopBgpAlarmsTask();
             }
         });
     }
@@ -509,16 +516,19 @@ public class BgpConfigurationManager implements EbgpService {
     }
 
     public class ConfigServerReactor
-            extends AsyncDataTreeChangeListenerBase<ConfigServer, ConfigServerReactor>
+            extends AbstractAsyncDataTreeChangeListener<ConfigServer>
             implements ClusteredDataTreeChangeListener<ConfigServer> {
         private static final String YANG_OBJ = "config-server ";
 
         public ConfigServerReactor() {
-            super(ConfigServer.class, ConfigServerReactor.class);
+            super(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                    InstanceIdentifier.create(Bgp.class).child(ConfigServer.class),
+                    org.opendaylight.infrautils.utils.concurrent.Executors
+                            .newListeningSingleThreadExecutor("ConfigServerReactor", LOG));
         }
 
         @Override
-        protected void add(InstanceIdentifier<ConfigServer> iid, ConfigServer val) {
+        public void add(InstanceIdentifier<ConfigServer> iid, ConfigServer val) {
             LOG.trace("received bgp connect config host {}", val.getHost().getValue());
             if (!isBGPEntityOwner()) {
                 return;
@@ -543,17 +553,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected ConfigServerReactor getDataTreeChangeListener() {
-            return ConfigServerReactor.this;
-        }
-
-        @Override
-        protected InstanceIdentifier<ConfigServer> getWildCardPath() {
-            return InstanceIdentifier.create(Bgp.class).child(ConfigServer.class);
-        }
-
-        @Override
-        protected void remove(InstanceIdentifier<ConfigServer> iid, ConfigServer val) {
+        public void remove(InstanceIdentifier<ConfigServer> iid, ConfigServer val) {
             LOG.trace("received bgp disconnect");
             if (!isBGPEntityOwner()) {
                 return;
@@ -578,7 +578,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected void update(InstanceIdentifier<ConfigServer> iid,
+        public void update(InstanceIdentifier<ConfigServer> iid,
                 ConfigServer oldval, ConfigServer newval) {
             LOG.trace("received bgp Connection update");
             if (!isBGPEntityOwner()) {
@@ -598,18 +598,21 @@ public class BgpConfigurationManager implements EbgpService {
         return bgpRouter;
     }
 
-    public class AsIdReactor
-            extends AsyncDataTreeChangeListenerBase<AsId, AsIdReactor>
+    public class AsIdReactor extends AbstractAsyncDataTreeChangeListener<AsId>
             implements ClusteredDataTreeChangeListener<AsId> {
 
         private static final String YANG_OBJ = "as-id ";
 
         public AsIdReactor() {
-            super(AsId.class, AsIdReactor.class);
+            super(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                    InstanceIdentifier.create(Bgp.class).child(AsId.class),
+                    org.opendaylight.infrautils.utils.concurrent.Executors
+                            .newListeningSingleThreadExecutor("AsIdReactor", LOG));
         }
 
+        @SuppressFBWarnings(value  = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
         @Override
-        protected void add(InstanceIdentifier<AsId> iid, AsId val) {
+        public void add(InstanceIdentifier<AsId> iid, AsId val) {
             LOG.error("received bgp add asid {}", val);
             if (!isBGPEntityOwner()) {
                 return;
@@ -631,17 +634,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected AsIdReactor getDataTreeChangeListener() {
-            return AsIdReactor.this;
-        }
-
-        @Override
-        protected InstanceIdentifier<AsId> getWildCardPath() {
-            return InstanceIdentifier.create(Bgp.class).child(AsId.class);
-        }
-
-        @Override
-        protected void remove(InstanceIdentifier<AsId> iid, AsId val) {
+        public void remove(InstanceIdentifier<AsId> iid, AsId val) {
             LOG.error("received delete router config asNum {}", val.getLocalAs());
             if (!isBGPEntityOwner()) {
                 return;
@@ -671,11 +664,11 @@ public class BgpConfigurationManager implements EbgpService {
                 }
                 LOG.debug("Removing external routes from FIB");
                 deleteExternalFibRoutes();
-                List<Neighbors> nbrs = conf.getNeighborsContainer() == null ? null
+                Map<NeighborsKey, Neighbors> keyNeighborsMap = conf.getNeighborsContainer() == null ? null
                         : conf.getNeighborsContainer().getNeighbors();
-                if (nbrs != null && nbrs.size() > 0) {
+                if (keyNeighborsMap != null && keyNeighborsMap.size() > 0) {
                     LOG.error("Tring to remove the as-id when neighbor config is already present");
-                    for (Neighbors nbr : nbrs) {
+                    for (Neighbors nbr : keyNeighborsMap.values()) {
                         LOG.debug("Removing Neighbor {} from Data store", nbr.getAddress().getValue());
                         delNeighbor(nbr.getAddress().getValue());
                     }
@@ -684,7 +677,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected void update(InstanceIdentifier<AsId> iid,
+        public void update(InstanceIdentifier<AsId> iid,
                 AsId oldval, AsId newval) {
             if (!isBGPEntityOwner()) {
                 return;
@@ -693,18 +686,20 @@ public class BgpConfigurationManager implements EbgpService {
         }
     }
 
-    public class GracefulRestartReactor
-            extends AsyncDataTreeChangeListenerBase<GracefulRestart, GracefulRestartReactor>
+    public class GracefulRestartReactor extends AbstractAsyncDataTreeChangeListener<GracefulRestart>
             implements ClusteredDataTreeChangeListener<GracefulRestart> {
 
         private static final String YANG_OBJ = "graceful-restart ";
 
         public GracefulRestartReactor() {
-            super(GracefulRestart.class, GracefulRestartReactor.class);
+            super(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                    InstanceIdentifier.create(Bgp.class).child(GracefulRestart.class),
+                    org.opendaylight.infrautils.utils.concurrent.Executors
+                            .newListeningSingleThreadExecutor("GracefulRestartReactor", LOG));
         }
 
         @Override
-        protected void add(InstanceIdentifier<GracefulRestart> iid, GracefulRestart val) {
+        public void add(InstanceIdentifier<GracefulRestart> iid, GracefulRestart val) {
             if (!isBGPEntityOwner()) {
                 return;
             }
@@ -725,17 +720,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected GracefulRestartReactor getDataTreeChangeListener() {
-            return GracefulRestartReactor.this;
-        }
-
-        @Override
-        protected InstanceIdentifier<GracefulRestart> getWildCardPath() {
-            return InstanceIdentifier.create(Bgp.class).child(GracefulRestart.class);
-        }
-
-        @Override
-        protected void remove(InstanceIdentifier<GracefulRestart> iid, GracefulRestart val) {
+        public void remove(InstanceIdentifier<GracefulRestart> iid, GracefulRestart val) {
             if (!isBGPEntityOwner()) {
                 return;
             }
@@ -756,7 +741,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected void update(InstanceIdentifier<GracefulRestart> iid,
+        public void update(InstanceIdentifier<GracefulRestart> iid,
                 GracefulRestart oldval, GracefulRestart newval) {
             if (!isBGPEntityOwner()) {
                 return;
@@ -779,18 +764,20 @@ public class BgpConfigurationManager implements EbgpService {
         }
     }
 
-    public class LoggingReactor
-            extends AsyncDataTreeChangeListenerBase<Logging, LoggingReactor>
+    public class LoggingReactor extends AbstractAsyncDataTreeChangeListener<Logging>
             implements ClusteredDataTreeChangeListener<Logging> {
 
         private static final String YANG_OBJ = "logging ";
 
         public LoggingReactor() {
-            super(Logging.class, LoggingReactor.class);
+            super(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                    InstanceIdentifier.create(Bgp.class).child(Logging.class),
+                    org.opendaylight.infrautils.utils.concurrent.Executors
+                            .newListeningSingleThreadExecutor("LoggingReactor", LOG));
         }
 
         @Override
-        protected void add(InstanceIdentifier<Logging> iid, Logging val) {
+        public void add(InstanceIdentifier<Logging> iid, Logging val) {
             if (!isBGPEntityOwner()) {
                 return;
             }
@@ -810,17 +797,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected LoggingReactor getDataTreeChangeListener() {
-            return LoggingReactor.this;
-        }
-
-        @Override
-        protected InstanceIdentifier<Logging> getWildCardPath() {
-            return InstanceIdentifier.create(Bgp.class).child(Logging.class);
-        }
-
-        @Override
-        protected void remove(InstanceIdentifier<Logging> iid, Logging val) {
+        public void remove(InstanceIdentifier<Logging> iid, Logging val) {
             if (!isBGPEntityOwner()) {
                 return;
             }
@@ -841,7 +818,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected void update(InstanceIdentifier<Logging> iid,
+        public void update(InstanceIdentifier<Logging> iid,
                 Logging oldval, Logging newval) {
             if (!isBGPEntityOwner()) {
                 return;
@@ -862,24 +839,35 @@ public class BgpConfigurationManager implements EbgpService {
         }
     }
 
-    public class NeighborsReactor
-            extends AsyncDataTreeChangeListenerBase<Neighbors, NeighborsReactor>
+    public class NeighborsReactor extends AbstractAsyncDataTreeChangeListener<Neighbors>
             implements ClusteredDataTreeChangeListener<Neighbors> {
 
         private static final String YANG_OBJ = "neighbors ";
 
         public NeighborsReactor() {
-            super(Neighbors.class, NeighborsReactor.class);
+            super(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                    InstanceIdentifier.create(Bgp.class).child(NeighborsContainer.class).child(Neighbors.class),
+                    org.opendaylight.infrautils.utils.concurrent.Executors
+                            .newListeningSingleThreadExecutor("NeighborsReactor", LOG));
         }
 
         @Override
-        protected void add(InstanceIdentifier<Neighbors> iid, Neighbors val) {
+        public void add(InstanceIdentifier<Neighbors> iid, Neighbors val) {
+            if (nbrList != null && !nbrList.contains(val)) {
+                LOG.trace("Adding nbr {} to nbrlist", val.getAddress().getValue());
+                nbrList.add(val);
+            }
             if (!isBGPEntityOwner()) {
                 return;
             }
             LOG.debug("received add Neighbors config val {}", val.getAddress().getValue());
             synchronized (BgpConfigurationManager.this) {
                 String peerIp = val.getAddress().getValue();
+                String sourceIp = (val.getUpdateSource() == null) ? null :
+                                    val.getUpdateSource().getSourceIp().getValue();
+                int nhops = (val.getEbgpMultihop() == null) ? 0 :
+                                    val.getEbgpMultihop().getNhops().intValue();
+                Map<AddressFamiliesKey, AddressFamilies> keyAddressFamiliesMap = val.getAddressFamilies();
                 long as = val.getRemoteAs().toJava();
                 final String md5Secret = extractMd5Secret(val);
                 BgpRouter br = getClient(YANG_OBJ);
@@ -891,6 +879,19 @@ public class BgpConfigurationManager implements EbgpService {
                 try {
                     //itmProvider.buildTunnelsToDCGW(new IpAddress(peerIp.toCharArray()));
                     br.addNeighbor(peerIp, as, md5Secret);
+                    if (nhops != 0) {
+                        br.addEbgpMultihop(peerIp, nhops);
+                    }
+                    if (sourceIp != null) {
+                        br.addUpdateSource(peerIp, sourceIp);
+                    }
+                    if (keyAddressFamiliesMap != null) {
+                        for (AddressFamilies af : keyAddressFamiliesMap.values()) {
+                            af_afi afi = af_afi.findByValue(af.getAfi().intValue());
+                            af_safi safi = af_safi.findByValue(af.getSafi().intValue());
+                            br.addAddressFamily(af.getPeerIp().getValue(), afi, safi);
+                        }
+                    }
 
                 } catch (TException | BgpRouterException e) {
                     LOG.error("{} Add received exception; {}", YANG_OBJ, ADD_WARN, e);
@@ -899,17 +900,11 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected NeighborsReactor getDataTreeChangeListener() {
-            return NeighborsReactor.this;
-        }
-
-        @Override
-        protected InstanceIdentifier<Neighbors> getWildCardPath() {
-            return InstanceIdentifier.create(Bgp.class).child(NeighborsContainer.class).child(Neighbors.class);
-        }
-
-        @Override
-        protected void remove(InstanceIdentifier<Neighbors> iid, Neighbors val) {
+        public void remove(InstanceIdentifier<Neighbors> iid, Neighbors val) {
+            if (nbrList != null && nbrList.contains(val)) {
+                LOG.trace("Removing nbr {} from nbr list", val.getAddress().getValue());
+                nbrList.remove(val);
+            }
             if (!isBGPEntityOwner()) {
                 return;
             }
@@ -944,7 +939,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected void update(InstanceIdentifier<Neighbors> iid,
+        public void update(InstanceIdentifier<Neighbors> iid,
                 Neighbors oldval, Neighbors newval) {
             if (!isBGPEntityOwner()) {
                 return;
@@ -953,18 +948,20 @@ public class BgpConfigurationManager implements EbgpService {
         }
     }
 
-    public class EbgpMultihopReactor
-            extends AsyncDataTreeChangeListenerBase<EbgpMultihop, EbgpMultihopReactor>
+    public class EbgpMultihopReactor extends AbstractAsyncDataTreeChangeListener<EbgpMultihop>
             implements ClusteredDataTreeChangeListener<EbgpMultihop> {
 
         private static final String YANG_OBJ = "ebgp-multihop ";
 
         public EbgpMultihopReactor() {
-            super(EbgpMultihop.class, EbgpMultihopReactor.class);
+            super(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                    InstanceIdentifier.create(Bgp.class).child(NeighborsContainer.class).child(Neighbors.class)
+                    .child(EbgpMultihop.class), org.opendaylight.infrautils.utils.concurrent.Executors
+                            .newListeningSingleThreadExecutor("EbgpMultihopReactor", LOG));
         }
 
         @Override
-        protected void add(InstanceIdentifier<EbgpMultihop> iid, EbgpMultihop val) {
+        public void add(InstanceIdentifier<EbgpMultihop> iid, EbgpMultihop val) {
             if (!isBGPEntityOwner()) {
                 return;
             }
@@ -986,18 +983,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected EbgpMultihopReactor getDataTreeChangeListener() {
-            return EbgpMultihopReactor.this;
-        }
-
-        @Override
-        protected InstanceIdentifier<EbgpMultihop> getWildCardPath() {
-            return InstanceIdentifier.create(Bgp.class).child(NeighborsContainer.class).child(Neighbors.class)
-                    .child(EbgpMultihop.class);
-        }
-
-        @Override
-        protected void remove(InstanceIdentifier<EbgpMultihop> iid, EbgpMultihop val) {
+        public void remove(InstanceIdentifier<EbgpMultihop> iid, EbgpMultihop val) {
             if (!isBGPEntityOwner()) {
                 return;
             }
@@ -1019,7 +1005,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected void update(InstanceIdentifier<EbgpMultihop> iid,
+        public void update(InstanceIdentifier<EbgpMultihop> iid,
                 EbgpMultihop oldval, EbgpMultihop newval) {
             if (!isBGPEntityOwner()) {
                 return;
@@ -1028,18 +1014,20 @@ public class BgpConfigurationManager implements EbgpService {
         }
     }
 
-    public class UpdateSourceReactor
-            extends AsyncDataTreeChangeListenerBase<UpdateSource, UpdateSourceReactor>
+    public class UpdateSourceReactor extends AbstractAsyncDataTreeChangeListener<UpdateSource>
             implements ClusteredDataTreeChangeListener<UpdateSource> {
 
         private static final String YANG_OBJ = "update-source ";
 
         public UpdateSourceReactor() {
-            super(UpdateSource.class, UpdateSourceReactor.class);
+            super(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                    InstanceIdentifier.create(Bgp.class).child(NeighborsContainer.class).child(Neighbors.class)
+                    .child(UpdateSource.class), org.opendaylight.infrautils.utils.concurrent.Executors
+                            .newListeningSingleThreadExecutor("UpdateSourceReactor", LOG));
         }
 
         @Override
-        protected void add(InstanceIdentifier<UpdateSource> iid, UpdateSource val) {
+        public void add(InstanceIdentifier<UpdateSource> iid, UpdateSource val) {
             if (!isBGPEntityOwner()) {
                 return;
             }
@@ -1061,18 +1049,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected UpdateSourceReactor getDataTreeChangeListener() {
-            return UpdateSourceReactor.this;
-        }
-
-        @Override
-        protected InstanceIdentifier<UpdateSource> getWildCardPath() {
-            return InstanceIdentifier.create(Bgp.class).child(NeighborsContainer.class).child(Neighbors.class)
-                    .child(UpdateSource.class);
-        }
-
-        @Override
-        protected void remove(InstanceIdentifier<UpdateSource> iid, UpdateSource val) {
+        public void remove(InstanceIdentifier<UpdateSource> iid, UpdateSource val) {
             if (!isBGPEntityOwner()) {
                 return;
             }
@@ -1094,7 +1071,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected void update(InstanceIdentifier<UpdateSource> iid,
+        public void update(InstanceIdentifier<UpdateSource> iid,
                 UpdateSource oldval, UpdateSource newval) {
             if (!isBGPEntityOwner()) {
                 return;
@@ -1103,18 +1080,20 @@ public class BgpConfigurationManager implements EbgpService {
         }
     }
 
-    public class AddressFamiliesReactor
-            extends AsyncDataTreeChangeListenerBase<AddressFamilies, AddressFamiliesReactor>
+    public class AddressFamiliesReactor extends AbstractAsyncDataTreeChangeListener<AddressFamilies>
             implements ClusteredDataTreeChangeListener<AddressFamilies> {
 
         private static final String YANG_OBJ = "address-families ";
 
         public AddressFamiliesReactor() {
-            super(AddressFamilies.class, AddressFamiliesReactor.class);
+            super(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                    InstanceIdentifier.create(Bgp.class).child(NeighborsContainer.class).child(Neighbors.class)
+                    .child(AddressFamilies.class), org.opendaylight.infrautils.utils.concurrent.Executors
+                            .newListeningSingleThreadExecutor("AddressFamiliesReactor", LOG));
         }
 
         @Override
-        protected void add(InstanceIdentifier<AddressFamilies> iid, AddressFamilies val) {
+        public void add(InstanceIdentifier<AddressFamilies> iid, AddressFamilies val) {
             if (!isBGPEntityOwner()) {
                 return;
             }
@@ -1138,18 +1117,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected AddressFamiliesReactor getDataTreeChangeListener() {
-            return AddressFamiliesReactor.this;
-        }
-
-        @Override
-        protected InstanceIdentifier<AddressFamilies> getWildCardPath() {
-            return InstanceIdentifier.create(Bgp.class).child(NeighborsContainer.class).child(Neighbors.class)
-                    .child(AddressFamilies.class);
-        }
-
-        @Override
-        protected void remove(InstanceIdentifier<AddressFamilies> iid, AddressFamilies val) {
+        public void remove(InstanceIdentifier<AddressFamilies> iid, AddressFamilies val) {
             if (!isBGPEntityOwner()) {
                 return;
             }
@@ -1173,7 +1141,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected void update(InstanceIdentifier<AddressFamilies> iid,
+        public void update(InstanceIdentifier<AddressFamilies> iid,
                 AddressFamilies oldval, AddressFamilies newval) {
             if (!isBGPEntityOwner()) {
                 return;
@@ -1182,23 +1150,19 @@ public class BgpConfigurationManager implements EbgpService {
         }
     }
 
-    public class NetworksReactor
-            extends AsyncDataTreeChangeListenerBase<Networks, NetworksReactor>
+    public class NetworksReactor extends AbstractAsyncDataTreeChangeListener<Networks>
             implements ClusteredDataTreeChangeListener<Networks> {
 
         private static final String YANG_OBJ = "networks ";
 
         public NetworksReactor() {
-            super(Networks.class, NetworksReactor.class);
+            super(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                    InstanceIdentifier.create(Bgp.class).child(NetworksContainer.class).child(Networks.class),
+                    org.opendaylight.infrautils.utils.concurrent.Executors
+                            .newListeningSingleThreadExecutor("NetworksReactor", LOG));
         }
 
-        @Override
-        public NetworksReactor getDataTreeChangeListener() {
-            return NetworksReactor.this;
-        }
-
-        @Override
-        protected void add(InstanceIdentifier<Networks> iid, Networks val) {
+        public void add(InstanceIdentifier<Networks> iid, Networks val) {
             if (!isBGPEntityOwner()) {
                 return;
             }
@@ -1238,12 +1202,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected InstanceIdentifier<Networks> getWildCardPath() {
-            return InstanceIdentifier.create(Bgp.class).child(NetworksContainer.class).child(Networks.class);
-        }
-
-        @Override
-        protected void remove(InstanceIdentifier<Networks> iid, Networks val) {
+        public void remove(InstanceIdentifier<Networks> iid, Networks val) {
             if (!isBGPEntityOwner()) {
                 return;
             }
@@ -1290,7 +1249,7 @@ public class BgpConfigurationManager implements EbgpService {
 
 
         @Override
-        protected void update(final InstanceIdentifier<Networks> iid,
+        public void update(final InstanceIdentifier<Networks> iid,
                 final Networks oldval, final Networks newval) {
             if (!isBGPEntityOwner()) {
                 return;
@@ -1312,18 +1271,20 @@ public class BgpConfigurationManager implements EbgpService {
 
     static Timer timer = new Timer();
 
-    public class VrfsReactor
-            extends AsyncDataTreeChangeListenerBase<Vrfs, VrfsReactor>
+    public class VrfsReactor extends AbstractAsyncDataTreeChangeListener<Vrfs>
             implements ClusteredDataTreeChangeListener<Vrfs> {
 
         private static final String YANG_OBJ = "vrfs ";
 
         public VrfsReactor() {
-            super(Vrfs.class, VrfsReactor.class);
+            super(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                    InstanceIdentifier.create(Bgp.class).child(VrfsContainer.class).child(Vrfs.class),
+                    org.opendaylight.infrautils.utils.concurrent.Executors
+                            .newListeningSingleThreadExecutor("VrfsReactor", LOG));
         }
 
         @Override
-        protected void add(InstanceIdentifier<Vrfs> iid, Vrfs vrfs) {
+        public void add(InstanceIdentifier<Vrfs> iid, Vrfs vrfs) {
             if (!isBGPEntityOwner()) {
                 return;
             }
@@ -1337,8 +1298,9 @@ public class BgpConfigurationManager implements EbgpService {
                     return;
                 }
                 try {
-                    List<AddressFamiliesVrf> vrfAddrFamilyList = vrfs.getAddressFamiliesVrf();
-                    for (AddressFamiliesVrf vrfAddrFamily : vrfAddrFamilyList) {
+                    Map<AddressFamiliesVrfKey, AddressFamiliesVrf> keyAddressFamiliesVrfMap
+                            = vrfs.getAddressFamiliesVrf();
+                    for (AddressFamiliesVrf vrfAddrFamily : keyAddressFamiliesVrfMap.values()) {
                         /*add to br the new vrfs arguments*/
                         br.addVrf(BgpUtil.getLayerType(vrfAddrFamily), rd, vrfs.getImportRts(),
                                 vrfs.getExportRts(), vrfAddrFamily.getAfi().toJava(), vrfAddrFamily.getSafi().toJava());
@@ -1350,7 +1312,7 @@ public class BgpConfigurationManager implements EbgpService {
                     }
 
                     for (AddressFamiliesVrf adf : vrfAddrFamilyListFromMap) {
-                        if (vrfAddrFamilyList.contains(adf)) {
+                        if (keyAddressFamiliesVrfMap.values().contains(adf)) {
                             mapNewAdFamily.remove(rd);
                         } else  if (adf != null) {
 
@@ -1372,17 +1334,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected VrfsReactor getDataTreeChangeListener() {
-            return VrfsReactor.this;
-        }
-
-        @Override
-        protected InstanceIdentifier<Vrfs> getWildCardPath() {
-            return InstanceIdentifier.create(Bgp.class).child(VrfsContainer.class).child(Vrfs.class);
-        }
-
-        @Override
-        protected void remove(InstanceIdentifier<Vrfs> iid, Vrfs val) {
+        public void remove(InstanceIdentifier<Vrfs> iid, Vrfs val) {
             if (!isBGPEntityOwner()) {
                 return;
             }
@@ -1398,7 +1350,7 @@ public class BgpConfigurationManager implements EbgpService {
                 try {
                     List<AddressFamiliesVrf> adf = mapNewAdFamily.get(rd);
                     adf = adf != null ? adf : new ArrayList<>();
-                    for (AddressFamiliesVrf s : val.getAddressFamiliesVrf()) {
+                    for (AddressFamiliesVrf s : val.getAddressFamiliesVrf().values()) {
                         br.delVrf(rd, s.getAfi().toJava(), s.getSafi().toJava());
                         adf.remove(s);// remove in the map the vrf in waiting for advertise quagga
                     }
@@ -1412,7 +1364,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected void update(InstanceIdentifier<Vrfs> iid,
+        public void update(InstanceIdentifier<Vrfs> iid,
                 Vrfs oldval, Vrfs newval) {
             if (oldval != null && newval != null) {
                 LOG.debug("received update Vrfs config val {}, VRFS: Update getting triggered for VRFS rd {}",
@@ -1431,11 +1383,13 @@ public class BgpConfigurationManager implements EbgpService {
             List<AddressFamiliesVrf> newlistAdFamilies = new ArrayList<>();
             if (oldval != null) {
                 oldlistAdFamilies = oldval.getAddressFamiliesVrf() == null
-                        ? new ArrayList<>() : oldval.getAddressFamiliesVrf();
+                        ? new ArrayList<>()
+                        : new ArrayList<AddressFamiliesVrf>(oldval.getAddressFamiliesVrf().values());
             }
             if (newval != null) {
                 newlistAdFamilies = newval.getAddressFamiliesVrf() == null
-                        ? new ArrayList<>() : newval.getAddressFamiliesVrf();
+                        ? new ArrayList<>()
+                        : new ArrayList<AddressFamiliesVrf>(newval.getAddressFamiliesVrf().values());
             }
             /*find old AddressFamily to remove from new configuration*/
             for (AddressFamiliesVrf adVrf : oldlistAdFamilies) {
@@ -1480,19 +1434,19 @@ public class BgpConfigurationManager implements EbgpService {
         }
     }
 
-    public class BgpReactor
-            extends AsyncDataTreeChangeListenerBase<Bgp, BgpReactor>
+    public class BgpReactor extends AbstractAsyncDataTreeChangeListener<Bgp>
             implements ClusteredDataTreeChangeListener<Bgp> {
 
         private static final String YANG_OBJ = "Bgp ";
 
         public BgpReactor() {
-            super(Bgp.class, BgpReactor.class);
+            super(dataBroker, LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(Bgp.class),
+                    org.opendaylight.infrautils.utils.concurrent.Executors
+                            .newListeningSingleThreadExecutor("BgpReactor", LOG));
         }
 
-
         @Override
-        protected void add(InstanceIdentifier<Bgp> iid, Bgp val) {
+        public void add(InstanceIdentifier<Bgp> iid, Bgp val) {
             LOG.debug("received add Bgp config");
 
             try {
@@ -1509,17 +1463,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected BgpReactor getDataTreeChangeListener() {
-            return BgpReactor.this;
-        }
-
-        @Override
-        protected InstanceIdentifier<Bgp> getWildCardPath() {
-            return InstanceIdentifier.create(Bgp.class);
-        }
-
-        @Override
-        protected void remove(InstanceIdentifier<Bgp> iid, Bgp val) {
+        public void remove(InstanceIdentifier<Bgp> iid, Bgp val) {
             if (!isBGPEntityOwner()) {
                 return;
             }
@@ -1529,7 +1473,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected void update(InstanceIdentifier<Bgp> iid,
+        public void update(InstanceIdentifier<Bgp> iid,
                 Bgp oldval, Bgp newval) {
             if (!isBGPEntityOwner()) {
                 return;
@@ -1540,39 +1484,30 @@ public class BgpConfigurationManager implements EbgpService {
     }
 
     @SuppressWarnings("deprecation")
-    public class MultipathReactor
-            extends AsyncDataTreeChangeListenerBase<Multipath, MultipathReactor>
+    public class MultipathReactor extends AbstractAsyncDataTreeChangeListener<Multipath>
             implements ClusteredDataTreeChangeListener<Multipath> {
 
         private static final String YANG_OBJ = "multipath ";
 
         public MultipathReactor() {
-            super(Multipath.class, MultipathReactor.class);
-        }
-
-
-        @Override
-        protected MultipathReactor getDataTreeChangeListener() {
-            return MultipathReactor.this;
-        }
-
-        @Override
-        protected InstanceIdentifier<Multipath> getWildCardPath() {
-            return InstanceIdentifier.create(Bgp.class).child(MultipathContainer.class).child(Multipath.class);
+            super(dataBroker, LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(Bgp.class)
+                    .child(MultipathContainer.class).child(Multipath.class),
+                    org.opendaylight.infrautils.utils.concurrent.Executors
+                            .newListeningSingleThreadExecutor("MultipathReactor", LOG));
         }
 
         @Override
-        protected void remove(InstanceIdentifier<Multipath> iid, Multipath val) {
+        public void remove(InstanceIdentifier<Multipath> iid, Multipath val) {
             executor.execute(new MultipathStatusChange(val));
         }
 
         @Override
-        protected void update(InstanceIdentifier<Multipath> iid, Multipath oldval, Multipath newval) {
+        public void update(InstanceIdentifier<Multipath> iid, Multipath oldval, Multipath newval) {
             executor.execute(new MultipathStatusChange(newval));
         }
 
         @Override
-        protected void add(InstanceIdentifier<Multipath> key, Multipath dataObjectModification) {
+        public void add(InstanceIdentifier<Multipath> key, Multipath dataObjectModification) {
             executor.execute(new MultipathStatusChange(dataObjectModification));
         }
 
@@ -1618,25 +1553,16 @@ public class BgpConfigurationManager implements EbgpService {
     }
 
     @SuppressWarnings("deprecation")
-    public class VrfMaxpathReactor
-            extends AsyncDataTreeChangeListenerBase<VrfMaxpath, VrfMaxpathReactor>
+    public class VrfMaxpathReactor extends AbstractAsyncDataTreeChangeListener<VrfMaxpath>
             implements ClusteredDataTreeChangeListener<VrfMaxpath> {
 
         private static final String YANG_OBJ = "vrfMaxpath ";
 
         public VrfMaxpathReactor() {
-            super(VrfMaxpath.class, VrfMaxpathReactor.class);
-        }
-
-
-        @Override
-        protected VrfMaxpathReactor getDataTreeChangeListener() {
-            return VrfMaxpathReactor.this;
-        }
-
-        @Override
-        protected InstanceIdentifier<VrfMaxpath> getWildCardPath() {
-            return InstanceIdentifier.create(Bgp.class).child(VrfMaxpathContainer.class).child(VrfMaxpath.class);
+            super(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                    InstanceIdentifier.create(Bgp.class).child(VrfMaxpathContainer.class).child(VrfMaxpath.class),
+                    org.opendaylight.infrautils.utils.concurrent.Executors
+                            .newListeningSingleThreadExecutor("VrfMaxpathReactor", LOG));
         }
 
         class VrfMaxPathConfigurator implements Runnable {
@@ -1667,7 +1593,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected void remove(InstanceIdentifier<VrfMaxpath> iid, VrfMaxpath vrfMaxPathVal) {
+        public void remove(InstanceIdentifier<VrfMaxpath> iid, VrfMaxpath vrfMaxPathVal) {
             if (isBGPEntityOwner()) {
                 synchronized (BgpConfigurationManager.this) {
                     BgpRouter br = getClient(YANG_OBJ);
@@ -1684,7 +1610,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected void update(InstanceIdentifier<VrfMaxpath> iid,
+        public void update(InstanceIdentifier<VrfMaxpath> iid,
                               VrfMaxpath oldval, VrfMaxpath newval) {
             if (!Objects.equals(oldval.getMaxpaths(), newval.getMaxpaths())) {
                 executor.execute(new VrfMaxPathConfigurator(newval));
@@ -1692,7 +1618,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected void add(InstanceIdentifier<VrfMaxpath> instanceIdentifier, VrfMaxpath vrfMaxpathVal) {
+        public void add(InstanceIdentifier<VrfMaxpath> instanceIdentifier, VrfMaxpath vrfMaxpathVal) {
             executor.execute(new VrfMaxPathConfigurator(vrfMaxpathVal));
         }
 
@@ -1702,18 +1628,19 @@ public class BgpConfigurationManager implements EbgpService {
         }
     }
 
-    public class BfdConfigReactor
-            extends AsyncDataTreeChangeListenerBase<BfdConfig, BfdConfigReactor>
+    public class BfdConfigReactor extends AbstractAsyncDataTreeChangeListener<BfdConfig>
             implements ClusteredDataTreeChangeListener<BfdConfig> {
 
         private static final String YANG_OBJ = "BfdConfig ";
 
         public BfdConfigReactor() {
-            super(BfdConfig.class, BfdConfigReactor.class);
+            super(dataBroker, LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(BfdConfig.class),
+                    org.opendaylight.infrautils.utils.concurrent.Executors
+                            .newListeningSingleThreadExecutor("BfdConfigReactor", LOG));
         }
 
         @Override
-        protected void add(InstanceIdentifier<BfdConfig> iid, BfdConfig val) {
+        public void add(InstanceIdentifier<BfdConfig> iid, BfdConfig val) {
             if (!isBGPEntityOwner()) {
                 return;
             }
@@ -1742,17 +1669,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected BfdConfigReactor getDataTreeChangeListener() {
-            return BfdConfigReactor.this;
-        }
-
-        @Override
-        protected InstanceIdentifier<BfdConfig> getWildCardPath() {
-            return InstanceIdentifier.create(BfdConfig.class);
-        }
-
-        @Override
-        protected void remove(InstanceIdentifier<BfdConfig> iid, BfdConfig val) {
+        public void remove(InstanceIdentifier<BfdConfig> iid, BfdConfig val) {
             if (!isBGPEntityOwner()) {
                 return;
             }
@@ -1772,7 +1689,7 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
         @Override
-        protected void update(InstanceIdentifier<BfdConfig> iid,
+        public void update(InstanceIdentifier<BfdConfig> iid,
                               BfdConfig oldval, BfdConfig newval) {
             LOG.debug("received bfd config: updated oldval bfd enabled {}"
                     + "min-rx {} min-tx {} detect-mul {} mhop {}",
@@ -1820,7 +1737,13 @@ public class BgpConfigurationManager implements EbgpService {
     public long getStalePathtime(int defValue, AsId asId) {
         long spt = 0;
         try {
-            spt = getConfig().getGracefulRestart().getStalepathTime().toJava();
+            InstanceIdentifier<GracefulRestart> id =
+                    InstanceIdentifier.create(Bgp.class).child(GracefulRestart.class);
+            Optional<GracefulRestart> gracefulRestartOptional = SingleTransactionDataBroker.syncReadOptional(dataBroker,
+                    LogicalDatastoreType.CONFIGURATION, id);
+            if (gracefulRestartOptional.isPresent()) {
+                spt = gracefulRestartOptional.get().getStalepathTime().toJava();
+            }
         } catch (NullPointerException e) {
             try {
                 spt = asId.getStalepathTime().toJava();
@@ -1829,6 +1752,9 @@ public class BgpConfigurationManager implements EbgpService {
                 LOG.trace("BGP AS id is not set using graceful");
                 spt = defValue;
             }
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.trace("Exception while reading GracefulRestart DS for the As {}", asId.getStalepathTime());
+            spt = defValue;
         }
         if (spt == 0) {
             LOG.trace("BGP config/Stale-path time is not set using graceful/start-bgp");
@@ -2240,10 +2166,11 @@ public class BgpConfigurationManager implements EbgpService {
                     }
                 }
 
-                //afs
-                List<AddressFamilies> afs = replayNbr.getNbr().getAddressFamilies();
-                if (afs != null) {
-                    for (AddressFamilies af : afs) {
+                //keyAddressFamiliesMap
+                Map<AddressFamiliesKey, AddressFamilies> keyAddressFamiliesMap
+                        = replayNbr.getNbr().getAddressFamilies();
+                if (keyAddressFamiliesMap != null) {
+                    for (AddressFamilies af : keyAddressFamiliesMap.values()) {
                         af_afi afi = af_afi.findByValue(af.getAfi().intValue());
                         af_safi safi = af_safi.findByValue(af.getSafi().intValue());
                         try {
@@ -2291,8 +2218,8 @@ public class BgpConfigurationManager implements EbgpService {
         while (0 != bgpDSretryCount.decrementAndGet()) {
             try {
                 return SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
-                        InstanceIdentifier.create(Bgp.class)).orNull();
-            } catch (ReadFailedException e) {
+                        InstanceIdentifier.create(Bgp.class)).orElse(null);
+            } catch (InterruptedException | ExecutionException e) {
                 //Config DS may not be up, so sleep for 1 second and retry
                 LOG.debug("failed to get bgp config, may be DS is yet in consistent state(?)", e);
                 try {
@@ -2421,11 +2348,13 @@ public class BgpConfigurationManager implements EbgpService {
             }
         }
 
-        List<Neighbors> neighbors = config.getNeighborsContainer() == null ? null
+        Map<NeighborsKey, Neighbors> keyNeighborsMap = config.getNeighborsContainer() == null ? null
                 : config.getNeighborsContainer().getNeighbors();
-        if (neighbors != null) {
-            LOG.error("configuring existing Neighbors present for replay total neighbors {}", neighbors.size());
-            boolean neighborConfigReplayResult = replayNbrConfig(neighbors, br);
+        if (keyNeighborsMap != null) {
+            LOG.error("configuring existing Neighbors present for replay total keyNeighborsMap {}",
+                    keyNeighborsMap.values().size());
+            boolean neighborConfigReplayResult
+                    = replayNbrConfig(new ArrayList<Neighbors>(keyNeighborsMap.values()), br);
             if (neighborConfigReplayResult == false) {
                 replaySucceded = false;
             }
@@ -2450,13 +2379,13 @@ public class BgpConfigurationManager implements EbgpService {
         } catch (Exception e) {
             LOG.error("Replay:addGr() received exception: ", e);
         }
-        List<Vrfs> vrfs = config.getVrfsContainer() == null ? null
+        Map<VrfsKey, Vrfs> keyVrfsMap = config.getVrfsContainer() == null ? null
                 : config.getVrfsContainer().getVrfs();
-        if (vrfs == null) {
-            vrfs = new ArrayList<>();
+        if (keyVrfsMap == null) {
+            keyVrfsMap = new HashMap<VrfsKey, Vrfs>();
         }
-        for (Vrfs vrf : vrfs) {
-            for (AddressFamiliesVrf adf : vrf.getAddressFamiliesVrf()) {
+        for (Vrfs vrf : keyVrfsMap.values()) {
+            for (AddressFamiliesVrf adf : vrf.getAddressFamiliesVrf().values()) {
                 try {
                     br.addVrf(BgpUtil.getLayerType(adf), vrf.getRd(), vrf.getImportRts(),
                             vrf.getExportRts(), adf.getAfi().toJava(), adf.getSafi().toJava());
@@ -2467,10 +2396,10 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
 
-        List<Networks> ln = config.getNetworksContainer() == null ? null
+        Map<NetworksKey, Networks> keyNetworksMap = config.getNetworksContainer() == null ? null
                 : config.getNetworksContainer().getNetworks();
-        if (ln != null) {
-            for (Networks net : ln) {
+        if (keyNetworksMap != null) {
+            for (Networks net : keyNetworksMap.values()) {
                 String rd = net.getRd();
                 String pfxlen = net.getPrefixLen();
                 String nh = net.getNexthop().getValue();
@@ -2501,11 +2430,11 @@ public class BgpConfigurationManager implements EbgpService {
         }
 
 
-        List<Multipath> multipaths = config.getMultipathContainer() == null ? null
+        Map<MultipathKey, Multipath> keyMultipathMap = config.getMultipathContainer() == null ? null
                 : config.getMultipathContainer().getMultipath();
 
-        if (multipaths != null) {
-            for (Multipath multipath : multipaths) {
+        if (keyMultipathMap != null) {
+            for (Multipath multipath : keyMultipathMap.values()) {
                 if (multipath != null) {
                     af_afi afi = af_afi.findByValue(multipath.getAfi().intValue());
                     af_safi safi = af_safi.findByValue(multipath.getSafi().intValue());
@@ -2517,15 +2446,15 @@ public class BgpConfigurationManager implements EbgpService {
                             br.disableMultipath(afi, safi);
                         }
                     } catch (TException | BgpRouterException e) {
-                        LOG.info("Replay:multipaths() received exception", e);
+                        LOG.info("Replay:keyMultipathMap() received exception", e);
                     }
                 }
             }
         }
-        List<VrfMaxpath> vrfMaxpaths = config.getVrfMaxpathContainer() == null ? null
+        Map<VrfMaxpathKey, VrfMaxpath> keyVrfMaxpathMap = config.getVrfMaxpathContainer() == null ? null
                 : config.getVrfMaxpathContainer().getVrfMaxpath();
-        if (vrfMaxpaths != null) {
-            for (VrfMaxpath vrfMaxpath : vrfMaxpaths) {
+        if (keyVrfMaxpathMap != null) {
+            for (VrfMaxpath vrfMaxpath : keyVrfMaxpathMap.values()) {
                 try {
                     br.multipaths(vrfMaxpath.getRd(), vrfMaxpath.getMaxpaths().toJava());
                 } catch (TException | BgpRouterException e) {
@@ -2718,7 +2647,7 @@ public class BgpConfigurationManager implements EbgpService {
         Vrfs vrf = bgpUtil.getVrfFromRd(rd);
         List<AddressFamiliesVrf> adfList = new ArrayList<>(1);
         if (vrf != null) {
-            adfList = vrf.getAddressFamiliesVrf();
+            adfList = new ArrayList<AddressFamiliesVrf>(vrf.getAddressFamiliesVrf().values());
         }
         AddressFamiliesVrfBuilder adfBuilder = new AddressFamiliesVrfBuilder();
         if (addressFamily.equals(AddressFamily.IPV4)) {
@@ -2920,7 +2849,7 @@ public class BgpConfigurationManager implements EbgpService {
 
         //** update or delete the vrfs with the rest of AddressFamilies already present in the last list
         AddressFamiliesVrf adfToDel = adfBuilder.build();
-        List<AddressFamiliesVrf> adfListOriginal = new ArrayList<>(vrfOriginal.nonnullAddressFamiliesVrf());
+        List<AddressFamiliesVrf> adfListOriginal = new ArrayList<>(vrfOriginal.nonnullAddressFamiliesVrf().values());
         List<AddressFamiliesVrf> adfListToRemoveFromOriginal = new ArrayList<>();
         adfListOriginal.forEach(adf -> {
             if (adf.equals(adfToDel)) {
@@ -3027,15 +2956,16 @@ public class BgpConfigurationManager implements EbgpService {
         totalStaledCount = 0;
         try {
             staledFibEntriesMap.clear();
+            fibDSWriter.clearFibMap();
             InstanceIdentifier<FibEntries> id = InstanceIdentifier.create(FibEntries.class);
 
             Optional<FibEntries> fibEntries = SingleTransactionDataBroker.syncReadOptional(dataBroker,
                     LogicalDatastoreType.CONFIGURATION, id);
             if (fibEntries.isPresent()) {
-                List<VrfTables> staleVrfTables = fibEntries.get().getVrfTables();
-                for (VrfTables vrfTable : staleVrfTables) {
+                Map<VrfTablesKey, VrfTables> staleVrfTablesMap = fibEntries.get().getVrfTables();
+                for (VrfTables vrfTable : staleVrfTablesMap.values()) {
                     Map<String, Uint32> staleFibEntMap = new HashMap<>();
-                    for (VrfEntry vrfEntry : vrfTable.getVrfEntry()) {
+                    for (VrfEntry vrfEntry : vrfTable.getVrfEntry().values()) {
                         if (RouteOrigin.value(vrfEntry.getOrigin()) != RouteOrigin.BGP) {
                             //Stale marking and cleanup is only meant for the routes learned through BGP.
                             continue;
@@ -3044,19 +2974,25 @@ public class BgpConfigurationManager implements EbgpService {
                             break;
                         }
                         totalStaledCount++;
-                        //Create MAP from staleVrfTables.
-                        vrfEntry.getRoutePaths()
+                        //Create MAP from staleVrfTablesMap.
+                        vrfEntry.getRoutePaths().values()
                                 .forEach(
-                                    routePath -> staleFibEntMap.put(
-                                            appendNextHopToPrefix(vrfEntry.getDestPrefix(),
-                                                    routePath.getNexthopAddress()), routePath.getLabel()));
+                                    routePath -> {
+                                        staleFibEntMap.put(
+                                                appendNextHopToPrefix(vrfEntry.getDestPrefix(),
+                                                        routePath.getNexthopAddress()), routePath.getLabel());
+                                        fibDSWriter.addEntryToFibMap(
+                                                vrfTable.getRouteDistinguisher(),  vrfEntry.getDestPrefix(),
+                                                routePath.getNexthopAddress());
+
+                                    });
                     }
                     staledFibEntriesMap.put(vrfTable.getRouteDistinguisher(), staleFibEntMap);
                 }
             } else {
                 LOG.error("createStaleFibMap:: FIBentries.class is not present");
             }
-        } catch (ReadFailedException e) {
+        } catch (InterruptedException | ExecutionException e) {
             LOG.error("createStaleFibMap:: error ", e);
         }
         LOG.error("created {} staled entries ", totalStaledCount);
@@ -3079,11 +3015,11 @@ public class BgpConfigurationManager implements EbgpService {
                     LOG.error("deleteExternalFibRoutes::getVrfTables is null");
                     return;
                 }
-                List<VrfTables> staleVrfTables = fibEntries.get().getVrfTables();
-                for (VrfTables vrfTable : staleVrfTables) {
+                Map<VrfTablesKey, VrfTables> staleVrfTablesMap = fibEntries.get().getVrfTables();
+                for (VrfTables vrfTable : staleVrfTablesMap.values()) {
                     String rd = vrfTable.getRouteDistinguisher();
                     if (vrfTable.getVrfEntry() != null) {
-                        for (VrfEntry vrfEntry : vrfTable.getVrfEntry()) {
+                        for (VrfEntry vrfEntry : vrfTable.getVrfEntry().values()) {
                             if (RouteOrigin.value(vrfEntry.getOrigin()) != RouteOrigin.BGP) {
                                 //route cleanup is only meant for the routes learned through BGP.
                                 continue;
@@ -3092,7 +3028,7 @@ public class BgpConfigurationManager implements EbgpService {
                             fibDSWriter.removeFibEntryFromDS(rd, vrfEntry.getDestPrefix());
                         }
                     } else if (vrfTable.getMacVrfEntry() != null) {
-                        for (MacVrfEntry macEntry : vrfTable.getMacVrfEntry()) {
+                        for (MacVrfEntry macEntry : vrfTable.getMacVrfEntry().values()) {
                             if (RouteOrigin.value(macEntry.getOrigin()) != RouteOrigin.BGP) {
                                 //route cleanup is only meant for the routes learned through BGP.
                                 continue;
@@ -3105,7 +3041,7 @@ public class BgpConfigurationManager implements EbgpService {
             } else {
                 LOG.error("deleteExternalFibRoutes:: FIBentries.class is not present");
             }
-        } catch (ReadFailedException e) {
+        } catch (InterruptedException | ExecutionException e) {
             LOG.error("deleteExternalFibRoutes:: error ", e);
         }
         LOG.debug("deleted {} fib entries {} mac entries", totalExternalRoutes, totalExternalMacRoutes);
@@ -3195,6 +3131,10 @@ public class BgpConfigurationManager implements EbgpService {
         return totalCleared;
     }
 
+    public static List<Neighbors> getNbrList() {
+        return nbrList;
+    }
+
     public BgpCounters getBgpCounters() {
         return bgpCountersReference.get();
     }