Upgrade to the Neon base platform
[netvirt.git] / bgpmanager / impl / src / main / java / org / opendaylight / netvirt / bgpmanager / BgpConfigurationManager.java
index 9801f767f3edba7e2320478ef4a9cec509ac7f0e..bdfa0d108fdacc81f79e99eb9072baaa9b2eec38 100755 (executable)
@@ -8,12 +8,15 @@
 package org.opendaylight.netvirt.bgpmanager;
 
 import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.net.InetAddresses;
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
 import io.netty.util.concurrent.GlobalEventExecutor;
 import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.net.InetAddress;
+import java.net.InetSocketAddress;
 import java.net.NetworkInterface;
 import java.net.SocketException;
 import java.util.ArrayList;
@@ -29,13 +32,11 @@ import java.util.Timer;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
 import javax.annotation.Nullable;
@@ -45,7 +46,6 @@ import javax.inject.Singleton;
 import org.apache.thrift.TApplicationException;
 import org.apache.thrift.TException;
 import org.apache.thrift.transport.TTransport;
-import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
 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;
@@ -120,6 +120,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.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;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder;
 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;
@@ -130,6 +131,7 @@ import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
 import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -140,20 +142,21 @@ public class BgpConfigurationManager {
     // to have stale FIB map (RD, Prefix)
     //  number of seconds wait for route sync-up between ODL and BGP
     private static final int BGP_RESTART_ROUTE_SYNC_SEC = 600;
-    private static final String DEF_LOGFILE = "/var/log/bgp_debug.log";
-    private static final String DEF_LOGLEVEL = "errors";
     private static final String UPDATE_PORT = "bgp.thrift.service.port";
     private static final String CONFIG_HOST = "vpnservice.bgpspeaker.host.name";
     private static final String CONFIG_PORT = "vpnservice.bgpspeaker.thrift.port";
     private static final String DEF_UPORT = "6644";
     private static final String DEF_CHOST = "255.255.255.255"; // Invalid Host IP
-    private static final String DEF_CPORT = "0";               // Invalid Port
+    private static final String DEF_CPORT = "7644";
     private static final String DEF_BGP_SDNC_MIP = "127.0.0.1";
-    private static final String BGP_SDNC_MIP = "vpnservice.bgp.thrift.sdnc.mip";
+    //vpnservice.bgp.thrift.bgp.mip is the MIP present with ODL. Here we open 6644 port
+    private static final String BGP_SDNC_MIP = "vpnservice.bgp.thrift.bgp.mip";
     private static final int RESTART_DEFAULT_GR = 90;
     private static final int DS_RETRY_COUNT = 100; //100 retries, each after WAIT_TIME_BETWEEN_EACH_TRY_MILLIS seconds
     private static final long WAIT_TIME_BETWEEN_EACH_TRY_MILLIS = 1000L; //one second sleep after every retry
     private static final String BGP_ENTITY_TYPE_FOR_OWNERSHIP = "bgp";
+    private static final String BGP_EOR_DELAY = "vpnservice.bgp.eordelay";
+    private static final String DEF_BGP_EOR_DELAY = "1800";
     private static final String BGP_ENTITY_NAME = "bgp";
     private static final String ADD_WARN = "Config store updated; undo with Delete if needed.";
     private static final String DEL_WARN = "Config store updated; undo with Add if needed.";
@@ -178,7 +181,8 @@ public class BgpConfigurationManager {
     private volatile Bgp config;
     private final BgpRouter bgpRouter;
     private final BgpSyncHandle bgpSyncHandle = new BgpSyncHandle();
-    private BgpThriftService updateServer;
+    private volatile BgpThriftService bgpThriftService = null;
+    private final int delayEorSeconds;
 
     private final CountDownLatch initer = new CountDownLatch(1);
 
@@ -233,38 +237,64 @@ public class BgpConfigurationManager {
             final IVpnLinkService vpnLinkSrvce,
             final BundleContext bundleContext,
             final BgpUtil bgpUtil,
-            final MetricProvider metricProvider)
-            throws InterruptedException, ExecutionException, TimeoutException {
+            final MetricProvider metricProvider) {
         this.dataBroker = dataBroker;
         this.fibDSWriter = fibDSWriter;
         this.vpnLinkService = vpnLinkSrvce;
         this.bundleContext = bundleContext;
         this.bgpUtil = bgpUtil;
         this.metricProvider = metricProvider;
-        String updatePort = getProperty(UPDATE_PORT, DEF_UPORT);
         hostStartup = getProperty(CONFIG_HOST, DEF_CHOST);
         portStartup = getProperty(CONFIG_PORT, DEF_CPORT);
-        LOG.info("UpdateServer at localhost:" + updatePort + " ConfigServer at "
-                + hostStartup + ":" + portStartup);
+        LOG.info("ConfigServer at {}:{}", hostStartup, portStartup);
         VtyshCli.setHostAddr(hostStartup);
         ClearBgpCli.setHostAddr(hostStartup);
         bgpRouter = BgpRouter.newInstance(this::getConfig, this::isBGPEntityOwner);
-        registerCallbacks();
+        delayEorSeconds = Integer.parseInt(getProperty(BGP_EOR_DELAY, DEF_BGP_EOR_DELAY));
 
         entityOwnershipUtils = new EntityOwnershipUtils(entityOwnershipService);
 
         candidateRegistration = registerEntityCandidate(entityOwnershipService);
         entityListenerRegistration = registerEntityListener(entityOwnershipService);
 
+        /*register callbacks for reactors, shall be called after EoS registration.
+         * as listeners user EoS service to identify Owner node. Listener call-backs
+         * can get triggered immediately after registeration (before EoS register complete)
+        */
+        registerCallbacks();
+
         LOG.info("BGP Configuration manager initialized");
         initer.countDown();
 
         GlobalEventExecutor.INSTANCE.execute(() -> {
-            final WaitingServiceTracker<IBgpManager> tracker = WaitingServiceTracker.create(
-                    IBgpManager.class, bundleContext);
-            bgpManager = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
-            updateServer = new BgpThriftService(Integer.parseInt(updatePort), bgpManager, this);
-            updateServer.start();
+            ServiceTracker<IBgpManager, ?> tracker = null;
+            try {
+                tracker = new ServiceTracker<>(bundleContext, IBgpManager.class, null);
+                tracker.open();
+                bgpManager = (IBgpManager) tracker.waitForService(TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES));
+                Preconditions.checkState(bgpManager != null, "IBgpManager service not found");
+            } catch (InterruptedException e) {
+                throw new IllegalStateException("Error retrieving IBgpManager service", e);
+            } finally {
+                if (tracker != null) {
+                    tracker.close();
+                }
+            }
+
+            String updatePort = getProperty(UPDATE_PORT, DEF_UPORT);
+            if (InetAddresses.isInetAddress(getBgpSdncMipIp())) {
+                InetSocketAddress bgpThriftServerSocketAddr = new InetSocketAddress(getBgpSdncMipIp(),
+                        Integer.parseInt(updatePort));
+                bgpThriftService = new BgpThriftService(bgpThriftServerSocketAddr, bgpManager, this);
+                if (isBGPEntityOwner()) {
+                    //I am EoS owner of BGP, opening bgp thrift UPDATE-SERVER port.
+                    LOG.info("BGP Configuration manager initialized: UPDATE-SERVER started");
+                    bgpThriftService.start();
+                }
+                LOG.info("UPDATE server started :ip:port={}:{}", getBgpSdncMipIp(), updatePort);
+            } else {
+                LOG.error("Failed to init UPDATE server invalid ip:port={}:{}", getBgpSdncMipIp(), updatePort);
+            }
             LOG.info("BgpConfigurationManager initialized. IBgpManager={}", bgpManager);
         });
     }
@@ -340,8 +370,14 @@ public class BgpConfigurationManager {
     public void close() {
         executor.shutdown();
 
-        if (updateServer != null) {
-            updateServer.stop();
+        if (bgpThriftService != null) {
+            bgpThriftService.stop();
+            bgpThriftService = null;
+        }
+
+        if (isBgpConnected()) {
+            //disconnect the CONFIG SERVER port (which was )opened during I was Owner
+            bgpRouter.disconnect();
         }
 
         if (candidateRegistration != null) {
@@ -384,16 +420,34 @@ public class BgpConfigurationManager {
 
             if (ownershipChange.getState() == EntityOwnershipChangeState.LOCAL_OWNERSHIP_GRANTED) {
                 LOG.trace("This PL is the Owner");
-                activateMIP();
+                if (bgpThriftService != null) {
+                    //opening UPDATE-SERVER port.
+                    bgpThriftService.start();
+                } else {
+                    LOG.error("I am the owner of BGP entity, but bgpThriftService is not initialized yet");
+                }
                 bgpRestarted();
             } else {
                 LOG.debug("Not owner: hasOwner: {}, isOwner: {}", ownershipChange.getState().hasOwner(),
                         ownershipChange.getState().isOwner());
+                if (bgpThriftService != null && bgpThriftService.isBgpThriftServiceStarted()) {
+                    //close the bgp Thrift Update-SERVER port opened on non-Entity Owner
+                    bgpThriftService.stop();
+                    bgpThriftService = null;
+                }
+                if (isBgpConnected()) {
+                    //disconnect the CONFIG SERVER port (which was )opened during I was Owner
+                    bgpRouter.disconnect();
+                }
             }
         });
     }
 
     public boolean isBGPEntityOwner() {
+        if (entityOwnershipUtils == null) {
+            LOG.error("entityOwnershipUtils is NULL when listener callbacks fired");
+            return false;
+        }
         return entityOwnershipUtils.isEntityOwner(new Entity(BGP_ENTITY_TYPE_FOR_OWNERSHIP, BGP_ENTITY_NAME), 0, 1);
     }
 
@@ -456,6 +510,24 @@ public class BgpConfigurationManager {
             bgpRouter.configServerUpdated();
 
             synchronized (BgpConfigurationManager.this) {
+                Bgp conf = getConfig();
+                if (conf != null) {
+                    AsId asId = conf.getAsId();
+                    if (asId != null) {
+                        long asNum = asId.getLocalAs();
+                        try {
+                            bgpRouter.stopBgp(asNum);
+                            stopBgpCountersTask();
+                            stopBgpAlarmsTask();
+                        } catch (TException | BgpRouterException e) {
+                            LOG.error("{} Delete received exception; {}", YANG_OBJ, DEL_WARN, e);
+                        }
+                    } else {
+                        LOG.debug("bgp as-id is null while removing config-server");
+                    }
+                } else {
+                    LOG.error("Config Null while removing the config-server");
+                }
                 bgpRouter.disconnect();
             }
         }
@@ -499,7 +571,7 @@ public class BgpConfigurationManager {
             synchronized (BgpConfigurationManager.this) {
                 BgpRouter br = getClient(YANG_OBJ);
                 if (br == null) {
-                    LOG.debug("{} Unable to process add for asNum {}; {}", YANG_OBJ, val.getLocalAs(),
+                    LOG.debug("{} Unable to process add for asNum {}; {} {}", YANG_OBJ, val.getLocalAs(),
                             BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
                     return;
                 }
@@ -530,7 +602,7 @@ public class BgpConfigurationManager {
                 long asNum = val.getLocalAs();
                 BgpRouter br = getClient(YANG_OBJ);
                 if (br == null) {
-                    LOG.debug("{} Unable to process remove for asNum {}; {}", YANG_OBJ, asNum,
+                    LOG.debug("{} Unable to process remove for asNum {}; {} {}", YANG_OBJ, asNum,
                             BgpRouterException.BGP_ERR_NOT_INITED, DEL_WARN);
                     return;
                 }
@@ -590,7 +662,7 @@ public class BgpConfigurationManager {
                 int stalePathTime = val.getStalepathTime().intValue();
                 BgpRouter br = getClient(YANG_OBJ);
                 if (br == null) {
-                    LOG.error("{} Unable to add stale-path time {}; {}", YANG_OBJ, stalePathTime,
+                    LOG.error("{} Unable to add stale-path time {}; {} {}", YANG_OBJ, stalePathTime,
                             BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
                     return;
                 }
@@ -621,7 +693,7 @@ public class BgpConfigurationManager {
             synchronized (BgpConfigurationManager.this) {
                 BgpRouter br = getClient(YANG_OBJ);
                 if (br == null) {
-                    LOG.error("{} Unable to delete stale-path time; {}", YANG_OBJ,
+                    LOG.error("{} Unable to delete stale-path time; {} {}", YANG_OBJ,
                             BgpRouterException.BGP_ERR_NOT_INITED, DEL_WARN);
                     return;
                 }
@@ -644,7 +716,7 @@ public class BgpConfigurationManager {
                 int stalePathTime = newval.getStalepathTime().intValue();
                 BgpRouter br = getClient(YANG_OBJ);
                 if (br == null) {
-                    LOG.error("{} Unable to update stale-path time to {}; {}", YANG_OBJ, stalePathTime,
+                    LOG.error("{} Unable to update stale-path time to {}; {} {}", YANG_OBJ, stalePathTime,
                             BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
                     return;
                 }
@@ -675,7 +747,7 @@ public class BgpConfigurationManager {
             synchronized (BgpConfigurationManager.this) {
                 BgpRouter br = getClient(YANG_OBJ);
                 if (br == null) {
-                    LOG.error("{} Unable to add logging for qbgp; {}", YANG_OBJ,
+                    LOG.error("{} Unable to add logging for qbgp; {} {}", YANG_OBJ,
                             BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
                     return;
                 }
@@ -706,12 +778,12 @@ public class BgpConfigurationManager {
             synchronized (BgpConfigurationManager.this) {
                 BgpRouter br = getClient(YANG_OBJ);
                 if (br == null) {
-                    LOG.error("{} Unable to remove logging for qbgp; {}", YANG_OBJ,
+                    LOG.error("{} Unable to remove logging for qbgp; {} {}", YANG_OBJ,
                             BgpRouterException.BGP_ERR_NOT_INITED, DEL_WARN);
                     return;
                 }
                 try {
-                    br.setLogging(DEF_LOGFILE, DEF_LOGLEVEL);
+                    br.setLogging(BgpConstants.BGP_DEF_LOG_FILE, BgpConstants.BGP_DEF_LOG_LEVEL);
                 } catch (TException | BgpRouterException e) {
                     LOG.error("{} Delete received exception; {}", YANG_OBJ, DEL_WARN, e);
                 }
@@ -727,7 +799,7 @@ public class BgpConfigurationManager {
             synchronized (BgpConfigurationManager.this) {
                 BgpRouter br = getClient(YANG_OBJ);
                 if (br == null) {
-                    LOG.error("{} Unable to update logging for qbgp; {}", YANG_OBJ,
+                    LOG.error("{} Unable to update logging for qbgp; {} {}", YANG_OBJ,
                             BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
                     return;
                 }
@@ -762,7 +834,7 @@ public class BgpConfigurationManager {
                 final String md5Secret = extractMd5Secret(val);
                 BgpRouter br = getClient(YANG_OBJ);
                 if (br == null) {
-                    LOG.debug("{} Unable to process add for peer {} as {}; {}", YANG_OBJ, peerIp, as,
+                    LOG.debug("{} Unable to process add for peer {} as {}; {} {}", YANG_OBJ, peerIp, as,
                             BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
                     return;
                 }
@@ -796,7 +868,7 @@ public class BgpConfigurationManager {
                 String peerIp = val.getAddress().getValue();
                 BgpRouter br = getClient(YANG_OBJ);
                 if (br == null) {
-                    LOG.debug("{} Unable to process remove for peer {}; {}", YANG_OBJ, peerIp,
+                    LOG.debug("{} Unable to process remove for peer {}; {} {}", YANG_OBJ, peerIp,
                             BgpRouterException.BGP_ERR_NOT_INITED, DEL_WARN);
                     return;
                 }
@@ -844,7 +916,7 @@ public class BgpConfigurationManager {
                 String peerIp = val.getPeerIp().getValue();
                 BgpRouter br = getClient(YANG_OBJ);
                 if (br == null) {
-                    LOG.debug("{} Unable to process add for peer {}; {}", YANG_OBJ, peerIp,
+                    LOG.debug("{} Unable to process add for peer {}; {} {}", YANG_OBJ, peerIp,
                             BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
                     return;
                 }
@@ -876,7 +948,7 @@ public class BgpConfigurationManager {
                 String peerIp = val.getPeerIp().getValue();
                 BgpRouter br = getClient(YANG_OBJ);
                 if (br == null) {
-                    LOG.debug("{} Unable to process remove for peer {}; {}", YANG_OBJ, peerIp,
+                    LOG.debug("{} Unable to process remove for peer {}; {} {}", YANG_OBJ, peerIp,
                             BgpRouterException.BGP_ERR_NOT_INITED, DEL_WARN);
                     return;
                 }
@@ -918,7 +990,7 @@ public class BgpConfigurationManager {
                 String peerIp = val.getPeerIp().getValue();
                 BgpRouter br = getClient(YANG_OBJ);
                 if (br == null) {
-                    LOG.debug("{} Unable to process add for peer {}; {}", YANG_OBJ, peerIp,
+                    LOG.debug("{} Unable to process add for peer {}; {} {}", YANG_OBJ, peerIp,
                             BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
                     return;
                 }
@@ -950,7 +1022,7 @@ public class BgpConfigurationManager {
                 String peerIp = val.getPeerIp().getValue();
                 BgpRouter br = getClient(YANG_OBJ);
                 if (br == null) {
-                    LOG.debug("{} Unable to process remove for peer {}; {}", YANG_OBJ, peerIp,
+                    LOG.debug("{} Unable to process remove for peer {}; {} {}", YANG_OBJ, peerIp,
                             BgpRouterException.BGP_ERR_NOT_INITED, DEL_WARN);
                     return;
                 }
@@ -992,7 +1064,7 @@ public class BgpConfigurationManager {
                 String peerIp = val.getPeerIp().getValue();
                 BgpRouter br = getClient(YANG_OBJ);
                 if (br == null) {
-                    LOG.debug("{} Unable to process add for peer {}; {}", YANG_OBJ, peerIp,
+                    LOG.debug("{} Unable to process add for peer {}; {} {}", YANG_OBJ, peerIp,
                             BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
                     return;
                 }
@@ -1026,7 +1098,7 @@ public class BgpConfigurationManager {
                 String peerIp = val.getPeerIp().getValue();
                 BgpRouter br = getClient(YANG_OBJ);
                 if (br == null) {
-                    LOG.debug("{} Unable to process remove for peer {}; {}", YANG_OBJ, peerIp,
+                    LOG.debug("{} Unable to process remove for peer {}; {} {}", YANG_OBJ, peerIp,
                             BgpRouterException.BGP_ERR_NOT_INITED, DEL_WARN);
                     return;
                 }
@@ -1077,8 +1149,8 @@ public class BgpConfigurationManager {
                 String nh = val.getNexthop().getValue();
                 BgpRouter br = getClient(YANG_OBJ);
                 if (br == null) {
-                    LOG.debug("{} Unable to process add for rd {} prefix {} nexthop {}; {}", YANG_OBJ, rd, pfxlen, nh,
-                            BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
+                    LOG.debug("{} Unable to process add for rd {} prefix {} nexthop {}; {} {}", YANG_OBJ, rd, pfxlen,
+                            nh, BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
                     return;
                 }
                 Long label = val.getLabel();
@@ -1121,7 +1193,7 @@ public class BgpConfigurationManager {
                 String pfxlen = val.getPrefixLen();
                 BgpRouter br = getClient(YANG_OBJ);
                 if (br == null) {
-                    LOG.debug("{} Unable to process remove for rd {} prefix {}; {}", YANG_OBJ, rd, pfxlen,
+                    LOG.debug("{} Unable to process remove for rd {} prefix {}; {} {}", YANG_OBJ, rd, pfxlen,
                             BgpRouterException.BGP_ERR_NOT_INITED, DEL_WARN);
                     return;
                 }
@@ -1200,7 +1272,7 @@ public class BgpConfigurationManager {
                 String rd = vrfs.getRd();
                 BgpRouter br = getClient(YANG_OBJ);
                 if (br == null) {
-                    LOG.debug("{} Unable to process add for rd {}; {}", YANG_OBJ, rd,
+                    LOG.debug("{} Unable to process add for rd {}; {} {}", YANG_OBJ, rd,
                             BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
                     return;
                 }
@@ -1208,8 +1280,8 @@ public class BgpConfigurationManager {
                     List<AddressFamiliesVrf> vrfAddrFamilyList = vrfs.getAddressFamiliesVrf();
                     for (AddressFamiliesVrf vrfAddrFamily : vrfAddrFamilyList) {
                         /*add to br the new vrfs arguments*/
-                        br.addVrf(BgpUtil.getLayerType(vrfAddrFamily), rd, vrfs.getImportRts(), vrfs.getExportRts(),
-                                vrfAddrFamily.getAfi(), vrfAddrFamily.getSafi());
+                        br.addVrf(BgpUtil.getLayerType(vrfAddrFamily), rd, vrfs.getImportRts(), vrfs.getExportRts()
+                        );
                     }
                     /*add to br the vrfs contained in mapNewAdFamily*/
                     List<AddressFamiliesVrf> vrfAddrFamilyListFromMap = mapNewAdFamily.get(rd);
@@ -1222,8 +1294,8 @@ public class BgpConfigurationManager {
                             mapNewAdFamily.remove(rd);
                         } else  if (adf != null) {
 
-                            br.addVrf(BgpUtil.getLayerType(adf), rd, vrfs.getImportRts(), vrfs.getExportRts(),
-                                    adf.getAfi(), adf.getSafi());
+                            br.addVrf(BgpUtil.getLayerType(adf), rd, vrfs.getImportRts(), vrfs.getExportRts()
+                            );
                             // remove AddressFamiliesVrf which was already added to BGP
                             vrfAddrFamilyListFromMap.remove(adf);
                             if (vrfAddrFamilyListFromMap.isEmpty()) {
@@ -1234,7 +1306,7 @@ public class BgpConfigurationManager {
                         }
                     }
                 } catch (TException | BgpRouterException e) {
-                    LOG.error("{} get {}, Add received exception; {}", YANG_OBJ, ADD_WARN, e);
+                    LOG.error("{} get {}, Add received exception", YANG_OBJ, ADD_WARN, e);
                 }
             }
         }
@@ -1259,7 +1331,7 @@ public class BgpConfigurationManager {
                 String rd = val.getRd();
                 BgpRouter br = getClient(YANG_OBJ);
                 if (br == null) {
-                    LOG.debug("{} Unable to process remove for rd {}; {}", YANG_OBJ, rd,
+                    LOG.debug("{} Unable to process remove for rd {}; {} {}", YANG_OBJ, rd,
                             BgpRouterException.BGP_ERR_NOT_INITED, DEL_WARN);
                     return;
                 }
@@ -1321,7 +1393,7 @@ public class BgpConfigurationManager {
             if (rd != null) {
                 BgpRouter br = getClient(YANG_OBJ);
                 if (br == null) {
-                    LOG.debug("{} Unable to process add for rd {}; {}", YANG_OBJ, rd,
+                    LOG.debug("{} Unable to process add for rd {}; {} {}", YANG_OBJ, rd,
                             BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
                     return;
                 }
@@ -1330,7 +1402,7 @@ public class BgpConfigurationManager {
                     try {
                         LOG.debug("call addVRf rd {} afi {} safi {}", rd, adfvrf.getAfi(), adfvrf.getSafi());
                         br.addVrf(BgpUtil.getLayerType(adfvrf), rd, newval.getImportRts(),
-                                newval.getExportRts(), adfvrf.getAfi(), adfvrf.getSafi());
+                                newval.getExportRts());
                     } catch (TException | BgpRouterException e) {
                         LOG.error("{} Add received exception; {}", YANG_OBJ, ADD_WARN, e);
                     }
@@ -1483,7 +1555,7 @@ public class BgpConfigurationManager {
                                     br.disableMultipath(afi, safi);
                                 }
                             } catch (TException | BgpRouterException e) {
-                                LOG.error(YANG_OBJ + " received exception: \"" + e + "\"");
+                                LOG.error("{} received exception", YANG_OBJ, e);
                             }
                         }
                     }
@@ -1536,11 +1608,10 @@ public class BgpConfigurationManager {
                         if (br != null) {
                             try {
                                 br.multipaths(vrfMaxpathVal.getRd(), vrfMaxpathVal.getMaxpaths());
-                                LOG.debug("Maxpath for vrf: " + vrfMaxpathVal.getRd() + " : is "
-                                        vrfMaxpathVal.getMaxpaths());
+                                LOG.debug("Maxpath for vrf {} is {}", vrfMaxpathVal.getRd(),
+                                        vrfMaxpathVal.getMaxpaths());
                             } catch (TException | BgpRouterException e) {
-                                LOG.error(YANG_OBJ
-                                        + " received exception: \"" + e + "\"");
+                                LOG.error("{} received exception", YANG_OBJ, e);
                             }
                         }
                     }
@@ -1618,7 +1689,7 @@ public class BgpConfigurationManager {
     }
 
     public static boolean isValidConfigBgpHostPort(String bgpHost, int bgpPort) {
-        if (!bgpHost.equals(DEF_CHOST) && bgpPort != Integer.parseInt(DEF_CPORT)) {
+        if (!bgpHost.equals(DEF_CHOST)) {
             return true;
         } else {
             return false;
@@ -1634,36 +1705,32 @@ public class BgpConfigurationManager {
             cancelPreviousReplayJob();
         }
         Runnable task = () -> {
-            try {
-                LOG.info("running bgp replay task ");
-                if (get() == null) {
-                    String host = getConfigHost();
-                    int port = getConfigPort();
-                    LOG.info("connecting  to bgp host {} ", host);
-                    bgpRouter.connect(host, port);
-                    LOG.info("no config to push in bgp replay task ");
-                    return;
-                }
-                setStaleStartTime(System.currentTimeMillis());
-                LOG.info("started creating stale fibDSWriter  map ");
-                createStaleFibMap();
-                setStaleEndTime(System.currentTimeMillis());
-                LOG.info("took {} msecs for stale fibDSWriter map creation ", getStaleEndTime() - getStaleStartTime());
-                LOG.info("started bgp config replay ");
-                setCfgReplayStartTime(System.currentTimeMillis());
-                boolean replaySucceded = replay();
-                setCfgReplayEndTime(System.currentTimeMillis());
-                LOG.info("took {} msecs for bgp replay ", getCfgReplayEndTime() - getCfgReplayStartTime());
-                if (replaySucceded) {
-                    LOG.info("starting the stale cleanup timer");
-                    long routeSyncTime = getStalePathtime(BGP_RESTART_ROUTE_SYNC_SEC, config.getAsId());
-                    setStaleCleanupTime(routeSyncTime);
-                    routeCleanupFuture = executor.schedule(new RouteCleanup(), routeSyncTime, TimeUnit.SECONDS);
-                } else {
-                    staledFibEntriesMap.clear();
-                }
-            } catch (InterruptedException | TimeoutException | ExecutionException eCancel) {
-                LOG.error("Stale Cleanup Task Cancelled", eCancel);
+            LOG.info("running bgp replay task ");
+            if (get() == null) {
+                String host = getConfigHost();
+                int port = getConfigPort();
+                LOG.info("connecting  to bgp host {} ", host);
+                bgpRouter.connect(host, port);
+                LOG.info("no config to push in bgp replay task ");
+                return;
+            }
+            setStaleStartTime(System.currentTimeMillis());
+            LOG.info("started creating stale fibDSWriter  map ");
+            createStaleFibMap();
+            setStaleEndTime(System.currentTimeMillis());
+            LOG.info("took {} msecs for stale fibDSWriter map creation ", getStaleEndTime() - getStaleStartTime());
+            LOG.info("started bgp config replay ");
+            setCfgReplayStartTime(System.currentTimeMillis());
+            boolean replaySucceded = replay();
+            setCfgReplayEndTime(System.currentTimeMillis());
+            LOG.info("took {} msecs for bgp replay ", getCfgReplayEndTime() - getCfgReplayStartTime());
+            if (replaySucceded) {
+                LOG.info("starting the stale cleanup timer");
+                long routeSyncTime = getStalePathtime(BGP_RESTART_ROUTE_SYNC_SEC, config.getAsId());
+                setStaleCleanupTime(routeSyncTime);
+                routeCleanupFuture = executor.schedule(new RouteCleanup(), routeSyncTime, TimeUnit.SECONDS);
+            } else {
+                staledFibEntriesMap.clear();
             }
         };
         lastReplayJobFt = executor.submit(task);
@@ -1692,11 +1759,11 @@ public class BgpConfigurationManager {
         }
     }
 
-    private void doRouteSync() throws InterruptedException, TimeoutException, ExecutionException {
+    private void doRouteSync() {
         LOG.error("Starting BGP route sync");
         try {
             bgpRouter.initRibSync(bgpSyncHandle);
-        } catch (TException | BgpRouterException e) {
+        } catch (BgpRouterException e) {
             LOG.error("Route sync aborted, exception when initializing", e);
             return;
         }
@@ -1732,8 +1799,6 @@ public class BgpConfigurationManager {
                            prefix,
                            plen,
                            nexthop,
-                           update.getEthtag(),
-                           update.getEsi(),
                            update.getMacaddress(),
                            label,
                            l2label,
@@ -1745,7 +1810,7 @@ public class BgpConfigurationManager {
         try {
             LOG.error("Ending BGP route-sync");
             bgpRouter.endRibSync(bgpSyncHandle);
-        } catch (TException | BgpRouterException e) {
+        } catch (BgpRouterException e) {
             // Ignored?
         }
     }
@@ -1781,8 +1846,7 @@ public class BgpConfigurationManager {
      */
 
     public void onUpdatePushRoute(protocol_type protocolType, String rd, String prefix, int plen, String nextHop,
-            int ethtag, String esi, String macaddress, int label, int l2label, String routermac, af_afi afi)
-            throws InterruptedException, ExecutionException, TimeoutException {
+                                  String macaddress, int label, int l2label, String routermac, af_afi afi) {
         boolean addroute = false;
         boolean macupdate = false;
         long l3vni = 0L;
@@ -1840,7 +1904,7 @@ public class BgpConfigurationManager {
                     rd, prefix, nextHop, label, afi);
             // TODO: modify addFibEntryToDS signature
             List<String> nextHopList = Collections.singletonList(nextHop);
-            fibDSWriter.addFibEntryToDS(rd, macaddress, prefix + "/" + plen, nextHopList, encapType, label, l3vni,
+            fibDSWriter.addFibEntryToDS(rd, prefix + "/" + plen, nextHopList, encapType, label, l3vni,
                                         routermac, RouteOrigin.BGP);
             LOG.info("ADD: Added Fib entry rd {} prefix {} nexthop {} label {}", rd, prefix, nextHop, label);
             String vpnName = bgpUtil.getVpnNameFromRd(rd);
@@ -1852,7 +1916,7 @@ public class BgpConfigurationManager {
     }
 
     public void onUpdateWithdrawRoute(protocol_type protocolType, String rd, String prefix, int plen, String nextHop,
-            String macaddress) throws InterruptedException, ExecutionException, TimeoutException {
+            String macaddress) {
         long vni = 0L;
         boolean macupdate = false;
         if (protocolType.equals(protocol_type.PROTOCOL_EVPN)) {
@@ -1860,10 +1924,10 @@ public class BgpConfigurationManager {
             if (vpnInstanceOpDataEntry != null) {
                 vni = vpnInstanceOpDataEntry.getL3vni();
                 if (vpnInstanceOpDataEntry.getType() == VpnInstanceOpDataEntry.Type.L2) {
-                    LOG.debug("Got RT2 withdraw for RD %s from tep %s with mac %s remote RD %s",
+                    LOG.debug("Got RT2 withdraw for RD {} {} from tep {} with mac {} remote RD {}",
                             vpnInstanceOpDataEntry.getVpnInstanceName(), vni, nextHop, macaddress, rd);
                     deleteTepfromElanDS(rd, nextHop, macaddress);
-                    LOG.debug("For rd %s. skipping fib update", rd);
+                    LOG.debug("For rd {}. skipping fib update", rd);
                     macupdate = true;
                 }
             } else {
@@ -2061,18 +2125,15 @@ public class BgpConfigurationManager {
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
-    public synchronized boolean replay() throws InterruptedException, TimeoutException, ExecutionException {
+    public synchronized boolean replay() {
         boolean replaySucceded = true;
         String host = getConfigHost();
         int port = getConfigPort();
         LOG.error("connecting  to bgp host {} ", host);
         boolean res = bgpRouter.connect(host, port);
         if (!res) {
-            String msg = "Cannot connect to BGP config server at " + host + ":" + port;
-            if (config != null) {
-                msg += "; Configuration Replay aborted";
-            }
-            LOG.error(msg);
+            LOG.error("Cannot connect to BGP config server at {}:{}{}", host, port,
+                    config != null ? "; Configuration Replay aborted" : "");
             return replaySucceded;
         }
         config = getConfig();
@@ -2088,7 +2149,7 @@ public class BgpConfigurationManager {
         }
         long asNum = asId.getLocalAs();
         IpAddress routerId = asId.getRouterId();
-        String rid = routerId == null ? "" : new String(routerId.getValue());
+        String rid = routerId == null ? "" : routerId.stringValue();
         int stalepathTime = (int) getStalePathtime(RESTART_DEFAULT_GR, config.getAsId());
         boolean announceFbit = true;
         boolean replayDone = false;
@@ -2150,11 +2211,11 @@ public class BgpConfigurationManager {
          * commenting this due to a bug with QBGP. Will uncomment once QBGP fix is done.
          * This wont have any functional impacts
          */
-        //try {
-        //    br.delayEOR(delayEorSeconds);
-        //} catch (TException | BgpRouterException e) {
-        //    LOG.error("Replay: delayEOR() number of seconds to wait for EOR from ODL:", e);
-        //}
+        try {
+            br.delayEOR(delayEorSeconds);
+        } catch (TException | BgpRouterException e) {
+            LOG.error("Replay: delayEOR() number of seconds to wait for EOR from ODL:", e);
+        }
 
         List<Neighbors> neighbors = config.getNeighbors();
         if (neighbors != null) {
@@ -2193,7 +2254,7 @@ public class BgpConfigurationManager {
             for (AddressFamiliesVrf adf : vrf.getAddressFamiliesVrf()) {
                 try {
                     br.addVrf(BgpUtil.getLayerType(adf), vrf.getRd(), vrf.getImportRts(),
-                            vrf.getExportRts(), adf.getAfi(), adf.getSafi());
+                            vrf.getExportRts());
                 } catch (TException | BgpRouterException e) {
                     LOG.error("Replay:addVrf() received exception", e);
                 }
@@ -2248,7 +2309,7 @@ public class BgpConfigurationManager {
                             br.disableMultipath(afi, safi);
                         }
                     } catch (TException | BgpRouterException e) {
-                        LOG.info("Replay:multipaths() received exception: \"" + e + "\"");
+                        LOG.info("Replay:multipaths() received exception", e);
                     }
                 }
             }
@@ -2259,7 +2320,7 @@ public class BgpConfigurationManager {
                 try {
                     br.multipaths(vrfMaxpath.getRd(), vrfMaxpath.getMaxpaths());
                 } catch (TException | BgpRouterException e) {
-                    LOG.info("Replay:vrfMaxPath() received exception: \"" + e + "\"");
+                    LOG.info("Replay:vrfMaxPath() received exception", e);
                 }
             }
         }
@@ -2284,11 +2345,11 @@ public class BgpConfigurationManager {
     }
 
     private <T extends DataObject> void update(InstanceIdentifier<T> iid, T dto) {
-        bgpUtil.update(LogicalDatastoreType.CONFIGURATION, iid, dto);
+        bgpUtil.update(iid, dto);
     }
 
     private <T extends DataObject> void delete(InstanceIdentifier<T> iid) {
-        bgpUtil.delete(LogicalDatastoreType.CONFIGURATION, iid);
+        bgpUtil.delete(iid);
     }
 
     public void startConfig(String bgpHost, int thriftPort) {
@@ -2302,7 +2363,7 @@ public class BgpConfigurationManager {
     }
 
     public void startBgp(long as, String routerId, int spt, boolean fbit) {
-        IpAddress rid = routerId == null ? null : new IpAddress(routerId.toCharArray());
+        IpAddress rid = routerId == null ? null : IpAddressBuilder.getDefaultInstance(routerId);
         Long staleTime = (long) spt;
         InstanceIdentifier.InstanceIdentifierBuilder<AsId> iib =
                 InstanceIdentifier.builder(Bgp.class).child(AsId.class);
@@ -2555,9 +2616,10 @@ public class BgpConfigurationManager {
 
         InstanceIdentifier<Vrfs> iid = iib.build();
 
+        InstanceIdentifier.builder(Bgp.class).build()
+                .child(Multipath.class, new MultipathKey(adfBuilder.getAfi(), adfBuilder.getSafi()));
         @SuppressWarnings("static-access")
-        InstanceIdentifier<Bgp> iid6 =  iid.builder(Bgp.class).build()
-                .child(Multipath.class, new MultipathKey(adfBuilder.getAfi(), adfBuilder.getSafi())).create(Bgp.class);
+        InstanceIdentifier<Bgp> iid6 =  InstanceIdentifier.create(Bgp.class);
         InstanceIdentifierBuilder<Vrfs> iib3 = iid6.child(Vrfs.class, new VrfsKey(rd)).builder();
         InstanceIdentifier<Vrfs> iidFinal = iib3.build();
 
@@ -2755,7 +2817,7 @@ public class BgpConfigurationManager {
                 rt2TepMap.get(rd).get(tepIp).put(mac, l2vni);
             } else {
                 LOG.debug("RT2 with mac {} l2vni {} from existing rd {} and new tep-ip {}",
-                        mac, rd, tepIp);
+                        mac, l2vni, rd, tepIp);
                 isFirstMacUpdateFromTep = true;
                 Map<String, Long> macList = new HashMap<>();
                 macList.put(mac, l2vni);
@@ -2841,7 +2903,7 @@ public class BgpConfigurationManager {
                     TimeUnit.MILLISECONDS);
             LOG.info("Bgp Counters task scheduled for every two minutes.");
 
-            bgpManager.setQbgpLog(BgpConstants.BGP_DEF_LOG_FILE, BgpConstants.BGP_DEF_LOG_LEVEL);
+            addLogging(BgpConstants.BGP_DEF_LOG_FILE, BgpConstants.BGP_DEF_LOG_LEVEL);
         }
     }