Merge "Upgrade ietf-{inet,yang}-types to 2013-07-15"
[vpnservice.git] / bgpmanager / bgpmanager-impl / src / main / java / org / opendaylight / bgpmanager / BgpManager.java
index cbcaa2e5d9e3a2048f9d6b0cba28f7dca0fd1896..6e9a1a5b2eee44a0f4c491dbcb73989533c6f520 100644 (file)
@@ -1,32 +1,29 @@
 /*
- * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-package org.opendaylight.bgpmanager;
 
+package org.opendaylight.bgpmanager;
 
-import java.net.SocketTimeoutException;
+import java.lang.management.ManagementFactory;
 import java.util.*;
-import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.CountDownLatch;
-
+import javax.management.*;
 import org.apache.thrift.TException;
-import org.opendaylight.bgpmanager.thrift.client.globals.Route;
-import org.opendaylight.bgpmanager.thrift.client.implementation.BgpRouter;
-import org.opendaylight.bgpmanager.thrift.server.implementation.BgpThriftService;
-import org.opendaylight.bgpmanager.thrift.exceptions.BgpRouterException;
 import org.opendaylight.bgpmanager.api.IBgpManager;
-import org.opendaylight.bgpmanager.globals.BgpConfiguration;
-import org.opendaylight.bgpmanager.globals.BgpConstants;
-
+import org.opendaylight.bgpmanager.commands.Commands;
+import org.opendaylight.bgpmanager.oam.*;
+import org.opendaylight.bgpmanager.thrift.gen.af_afi;
+import org.opendaylight.bgpmanager.thrift.gen.af_safi;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
-
+//import org.opendaylight.vpnservice.itm.api.IITMProvider;
+import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp;
+import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Neighbors;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.FrameworkUtil;
@@ -35,490 +32,244 @@ import org.slf4j.LoggerFactory;
 
 public class BgpManager implements BindingAwareProvider, AutoCloseable, IBgpManager {
 
-    private static final Logger s_logger = LoggerFactory.getLogger(BgpManager.class);
-    private BgpConfigurationManager bgpConfigurationMgr;
+    private static final Logger LOGGER = LoggerFactory.getLogger(BgpManager.class);
+    private BgpConfigurationManager bcm;
     private FibDSWriter fibDSWriter;
-    private BgpConfiguration   bgpConfiguration = new BgpConfiguration();
-    private BgpRouter           bgpThriftClient;
-    private BgpThriftService    bgpThriftService;
-    private boolean             isBgpInitialized = false;
-    private boolean             hasBgpServiceStarted = false;
-    private String                             bgpHost;
-    private int                                        bgpPort;
-
-
-    private String getCustomConfig(String var, String def) {
-        Bundle b = FrameworkUtil.getBundle(this.getClass());
-        BundleContext context = null;
-        if (b != null) {
-            context = b.getBundleContext();
-        }
-        if (context != null)
-            return context.getProperty(var);
-        else
-            return def;
-
-    }
-
-    private void initializeBGPCommunication() {
-        //start our side of thrift server
-        bgpThriftService = new BgpThriftService(this, fibDSWriter);
-        bgpThriftService.start();
-
-        //start bgp thrift client connection
-        bgpThriftClient = new BgpRouter();
-
-        bgpHost = getCustomConfig(BgpConstants.BGP_SPEAKER_HOST_NAME, BgpConstants.DEFAULT_BGP_HOST_NAME);
-        bgpPort = BgpConstants.DEFAULT_BGP_THRIFT_PORT;
-
-        configureBgpServer(bgpHost, bgpPort);
-        try {
-            connectToServer(bgpHost, bgpPort);
-        } catch (Exception e) {
-            return;
-        }
-
-        isBgpInitialized = true;
-        //notify();       //notify all threads waiting for bgp init
-
-    }
-
-    public synchronized void waitForBgpInit() {
-        if(!isBgpInitialized) {
-            try {
-                wait();
-            } catch (InterruptedException e) {
-                s_logger.error("InterruptedException while waiting for Bgp connection to initialize");
-                return;
-            }
-        }
-    }
-
-    public void startBgpService() throws TException {
-        if(bgpThriftClient == null) {
-            s_logger.info("Start Bgp Service - bgpThriftClient is null. Unable to start BGP service.");
-            return;
-        }
-
-        // Now try start bgp - if bgp is already Active, it will tell us, nothing to do then
-        try {
-            bgpThriftClient.startBgp((int)bgpConfiguration.getAsNum(), bgpConfiguration.getRouterId());
-            s_logger.info("Started BGP with AS number " + (int)bgpConfiguration.getAsNum() + " and router id " + bgpConfiguration.getRouterId());
-        } catch (BgpRouterException be) {
-            if(be.getErrorCode() == BgpRouterException.BGP_ERR_ACTIVE) {
-                s_logger.info("bgp server already active");
-                return;
-            }
-            else if(be.getErrorCode() == BgpRouterException.BGP_ERR_NOT_INITED) {
-                s_logger.error("bgp server connection not initialized.");
-                reInitConn();
-                return;
-            }
-            else {
-                s_logger.error("application error while starting bgp server " + be.getErrorCode());
-                return;
-            }
-
-        }  catch (TException t) {
-            s_logger.error("Could not set up thrift connection with bgp server");
-            //s_logger.trace("Transport error while starting bgp server ", t);
-            reInitConn();
-            throw t;
-        } catch (Exception e) {
-            s_logger.error("Error while starting bgp server");
-            //s_logger.trace("Bgp Service not started due to exception", e);
-            return;
-        }
-
-        hasBgpServiceStarted = true;
+    //private IITMProvider        itmProvider;
+    private DataBroker dataBroker;
+    private BgpAlarmBroadcaster     qbgpAlarmProducer = null;
+    private MBeanServer qbgpAlarmServer = null;
+    private NotificationFilter  qbgpAlarmFilter = null;
+    final static int DEFAULT_STALEPATH_TIME = 210;
+    final static boolean DEFAULT_FBIT = true;
 
-    }
+    public BgpCounters bgpCounters;
+    public Timer bgpCountersTimer;
 
     @Override
     public void onSessionInitiated(ProviderContext session) {
-        s_logger.info("BgpManager Session Initiated");
         try {
-            final DataBroker dataBroker = session.getSALService(DataBroker.class);
-            bgpConfigurationMgr = new BgpConfigurationManager(dataBroker, bgpConfiguration, this);
+            dataBroker = session.getSALService(DataBroker.class);
             fibDSWriter = new FibDSWriter(dataBroker);
+            BgpUtil.setBroker(dataBroker);
+            bcm = new BgpConfigurationManager(this);
+            Commands commands = new Commands(this);
+            ConfigureBgpCli.setBgpManager(this);
+            LOGGER.info("BgpManager started");
         } catch (Exception e) {
-            s_logger.error("Error initializing services", e);
+            LOGGER.error("Failed to start BgpManager: "+e);
         }
 
-        initializeBGPCommunication();
+        // Set up the Infra for Posting BGP Alarms as JMX notifications.
+        try {
+            qbgpAlarmProducer = new BgpAlarmBroadcaster();
+            MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+            ObjectName alarmObj = new ObjectName("SDNC.FM:name=BgpAlarmObj");
+            mbs.registerMBean(qbgpAlarmProducer, alarmObj);
+        } catch (JMException e) {
+            LOGGER.error("Adding a NotificationBroadcaster failed." + e.toString());
+            e.printStackTrace();
+        }
     }
 
-
    @Override
     public void close() throws Exception {
-        s_logger.info("BgpManager Closed");
-
-       //close the client and server ends of the thrift communication
-       if(bgpThriftClient != null)
-           bgpThriftClient.disconnect();
-       bgpThriftService.stop();
-
-
+        bcm.close(); 
+        LOGGER.info("BgpManager Closed");
    }
 
-    private void setBgpServerDetails() {
-        if(bgpThriftClient != null)
-            bgpThriftClient.setBgpServer(bgpHost, bgpPort);
+    /*public void setITMProvider(IITMProvider itmProvider) {
+        this.itmProvider = itmProvider;
     }
 
-    private void configureBgpServer(String bgpServer, int bgpPort) {
-        bgpConfiguration.setBgpServer(bgpServer);
-        bgpConfiguration.setBgpPort(bgpPort);
-        setBgpServerDetails();
+    public IITMProvider getItmProvider() { return this.itmProvider; } */
+
+    public Bgp getConfig() {
+      return bcm.get();
     }
 
-    protected void addNeighbor(String ipAddress, long asNum) throws TException {
-        if(bgpThriftClient == null) {
-            s_logger.info("Add BGP Neighbor - bgpThriftClient is null. Unable to add BGP Neighbor.");
-            return;
-        }
+    public void configureGR(int stalepathTime) throws TException {
+      bcm.addGracefulRestart(stalepathTime);
+    }
 
-        try {
-            bgpThriftClient.addNeighbor(ipAddress, (int) asNum);
-        } catch (BgpRouterException b) {
-            s_logger.error("Failed to add BGP neighbor " + ipAddress + "due to BgpRouter Exception number " + b.getErrorCode());
-            s_logger.error("BgpRouterException trace ", b);
-        } catch (TException t) {
-            s_logger.error(String.format("Failed adding neighbor %s due to Transport error", ipAddress));
-            reInitConn();
-            throw t;
-        } catch (Exception e) {
-            s_logger.error(String.format("Failed adding neighbor %s", ipAddress));
-        }
+    public void delGracefulRestart() throws Exception {
+      bcm.delGracefulRestart();
     }
 
+    public void addNeighbor(String ipAddress, long asNum) throws TException {
+      bcm.addNeighbor(ipAddress, (int) asNum);
+    }
 
-    protected void deleteNeighbor(String ipAddress) throws TException {
-        if(bgpThriftClient == null) {
-            s_logger.info("Delete BGP Neighbor - bgpThriftClient is null. Unable to delete BGP Neighbor.");
-            return;
-        }
+    public void addEbgpMultihop(String ipAddress, int nhops) throws TException {
+      bcm.addEbgpMultihop(ipAddress, nhops);
+    }
+    
+    public void addUpdateSource(String ipAddress, String srcIp) throws TException {
+      bcm.addUpdateSource(ipAddress, srcIp);
+    }
 
-        try {
-            bgpThriftClient.delNeighbor(ipAddress);
-        } catch (BgpRouterException b) {
-            s_logger.error("Failed to delete BGP neighbor " + ipAddress + "due to BgpRouter Exception number " + b.getErrorCode());
-            s_logger.error("BgpRouterException trace ", b);
-        }catch (TException t) {
-            s_logger.error(String.format("Failed deleting neighbor %s due to Transport error", ipAddress));
-            reInitConn();
-            throw t;
-        } catch (Exception e) {
-            s_logger.error(String.format("Failed deleting neighbor %s", ipAddress));
-        }
+    public void addAddressFamily(String ipAddress, af_afi afi, af_safi safi) throws TException {
+      bcm.addAddressFamily(ipAddress, afi.getValue(), safi.getValue());
     }
 
+    public void deleteNeighbor(String ipAddress) throws TException {
+      bcm.delNeighbor(ipAddress);
+    }
 
     @Override
     public void addVrf(String rd, Collection<String> importRts, Collection<String> exportRts) throws Exception {
-        if(bgpThriftClient == null) {
-            s_logger.info("Add BGP vrf - bgpThriftClient is null. Unable to add BGP vrf.");
-            return;
-        }
-        try {
-            bgpThriftClient.addVrf(rd, new ArrayList<>(importRts), new ArrayList<>(exportRts));
-        } catch (BgpRouterException b) {
-            s_logger.error("Failed to add BGP vrf " + rd + "due to BgpRouter Exception number " + b.getErrorCode());
-            s_logger.error("BgpRouterException trace ", b);
-            throw b;
-        } catch (TException t) {
-            s_logger.error(String.format("Failed adding vrf %s due to Transport error", rd));
-            reInitConn();
-            throw t;
-        } catch (Exception e) {
-            s_logger.error(String.format("Failed adding vrf %s", rd));
-            throw e;
-        }
+        bcm.addVrf(rd, new ArrayList<String>(importRts), 
+                       new ArrayList<String>(exportRts)); 
     }
 
     @Override
     public void deleteVrf(String rd) throws Exception {
-        if(bgpThriftClient == null) {
-            s_logger.info("Delete BGP vrf - bgpThriftClient is null. Unable to delete BGP vrf.");
-            return;
-        }
-        try {
-            bgpThriftClient.delVrf(rd);
-        } catch (BgpRouterException b) {
-            s_logger.error("Failed to delete BGP vrf " + rd + "due to BgpRouter Exception number " + b.getErrorCode());
-            s_logger.error("BgpRouterException trace ", b);
-            throw b;
-        } catch (TException t) {
-            s_logger.error(String.format("Failed deleting vrf %s due to Transport error", rd));
-            reInitConn();
-            throw t;
-        } catch (Exception e) {
-            s_logger.error(String.format("Failed deleting vrf %s", rd));
-            throw e;
-        }
+      bcm.delVrf(rd);
     }
 
     @Override
     public void addPrefix(String rd, String prefix, String nextHop, int vpnLabel) throws Exception {
+      fibDSWriter.addFibEntryToDS(rd, prefix, nextHop, vpnLabel);
+      bcm.addPrefix(rd, prefix, nextHop, vpnLabel);
+    }
 
-        if(bgpThriftClient == null || !hasBgpServiceStarted) {
-            fibDSWriter.addFibEntryToDS(rd, prefix, nextHop, vpnLabel);
-            return;
-        }
-
-        try {
-            bgpThriftClient.addPrefix(rd, prefix, nextHop, vpnLabel);
-        } catch (BgpRouterException b) {
-            s_logger.error("Failed to add BGP prefix " + prefix + "due to BgpRouter Exception number " + b.getErrorCode());
-            s_logger.error("BgpRouterException trace ", b);
-            throw b;
-        } catch (TException t) {
-            s_logger.error(String.format("Failed adding prefix entry <vrf:prefix:nexthop:vpnlabel> %s:%s:%s:%d due to Transport error",
-                rd, prefix, nextHop, vpnLabel));
-            reInitConn();
-            throw t;
-        } catch (Exception e) {
-            s_logger.error(String.format("Failed adding prefix entry <vrf:prefix:nexthop:vpnlabel> %s:%s:%s:%d",
-                rd, prefix, nextHop, vpnLabel));
-            throw e;
-        }
+    @Override
+    public void deletePrefix(String rd, String prefix) throws Exception {
+      fibDSWriter.removeFibEntryFromDS(rd, prefix);
+      bcm.delPrefix(rd, prefix);
     }
 
+    @Override
+    public void advertisePrefix(String rd, String prefix, String nextHop, int vpnLabel) throws Exception {
+        bcm.addPrefix(rd, prefix, nextHop, vpnLabel);
+    }
 
     @Override
-    public void deletePrefix(String rd, String prefix) throws Exception {
-        if(bgpThriftClient == null || !hasBgpServiceStarted) {
-            fibDSWriter.removeFibEntryFromDS(rd, prefix);
-            return;
-        }
+    public void withdrawPrefix(String rd, String prefix) throws Exception {
+        bcm.delPrefix(rd, prefix);
+    }
 
-        try {
-            bgpThriftClient.delPrefix(rd, prefix);
-        } catch (BgpRouterException b) {
-            s_logger.error("Failed to delete BGP prefix " + prefix + "due to BgpRouter Exception number " + b.getErrorCode());
-            s_logger.error("BgpRouterException trace ", b);
-            throw b;
-        } catch (TException t) {
-            s_logger.error(String.format("Failed deleting prefix entry <vrf:prefix> %s:%s due to Transport error",
-                rd, prefix));
-            reInitConn();
-            throw t;
-        } catch (Exception e) {
-            s_logger.error(String.format("Failed deleting prefix entry <vrf:prefix> %s:%s",
-                rd, prefix));
-            throw e;
-        }
+    public void setQbgpLog(String fileName, String debugLevel) throws Exception {
+      bcm.addLogging(fileName, debugLevel);
     }
 
-    private void connectToServer(String host, int port) throws Exception {
+    public void delLogging() throws Exception {
+      bcm.delLogging();
+    }
 
-        bgpHost = host;
-        bgpPort = port;
+    public void startBgp(int asn, String routerId, int spt, boolean fbit) {
+      bcm.startBgp(asn, routerId, spt, fbit);
+    }
 
-        if(bgpThriftClient == null) {
-            s_logger.error("Failed to connect to BGP server since Bgp Thrift Client is not initialized yet.");
-            return;
-        }
-        try {
-            bgpThriftClient.connect(host, port);
-            s_logger.info("Connected to BGP server " + host + " on port " + port);
-        } catch (BgpRouterException b) {
-            s_logger.error("Failed to connect to BGP server " + host + " on port " + port + " due to BgpRouter Exception number " + b.getErrorCode());
-            //_logger.error("BgpRouterException trace ", b);
-            throw b;
-        } catch (TException t) {
-            s_logger.error("Failed to initialize BGP Connection due to Transport error ");
-            throw t;
-        }
-        catch (Exception e) {
-            s_logger.error("Failed to initialize BGP Connection ");
-            throw e;
-        }
+    public void stopBgp() {
+      bcm.stopBgp();
     }
 
-    public void configureBgp(long asNum, String routerId) {
-        try {
-            bgpConfiguration.setAsNum(asNum);
-            bgpConfiguration.setRouterId(routerId);
-        } catch(Throwable e) {
-            s_logger.error("failed configuring bgp ",e);
-        }
+    public void startConfig(String host, int port) {
+      bcm.startConfig(host, port);
     }
 
-    public synchronized void reInitConn() {
+    public void stopConfig() {
+      bcm.stopConfig();
+    }
 
-        try {
-            bgpThriftClient.reInit();
-            s_logger.info("Reinitialized connection to BGP Server " + bgpHost);
-        } catch (BgpRouterException b) {
-            s_logger.error("Failed to reinitialize connection to BGP server " + bgpHost + " on port " + bgpPort + " due to BgpRouter Exception number " + b.getErrorCode());
-            s_logger.error("BgpRouterException trace ", b);
-        } catch (TException t) {
-            s_logger.error("Failed to reinitialize BGP Connection due to Transport error.");
+    @Override
+    public String getDCGwIP() {
+        Bgp conf = getConfig();
+        if (conf == null) {
+          return null;
         }
-        catch (Exception e) {
-            s_logger.error("Failed to reinitialize BGP Connection.", e);
+        List<Neighbors> nbrs = conf.getNeighbors();
+        if (nbrs == null) {
+          return null;
         }
+        return nbrs.get(0).getAddress().getValue();
     }
 
-    /*public synchronized void startBgpSync() {
-        boolean getRoutes = true;
-        readBgpConfiguration();
-        try {
-            pushConfigurationToBgp();
+    public MBeanServer getBgpAlarmServer() {
+        return qbgpAlarmServer;
+    }
 
-        } catch (BgpRouterException b) {
-            s_logger.error("Failed to push configuration to BGP due to BgpRouter Exception number " + b.getErrorCode());
-            s_logger.error("BgpRouterException trace ", b);
-            if(b.getErrorCode() == BgpRouterException.BGP_ERR_INACTIVE)
-                getRoutes = false;
-        } catch (Exception e) {
-            s_logger.error("Failed to push configuration to bgp ", e);
+    public synchronized void sendNotificationEvent(String pfx, int code, int subcode) {
+        BgpAlarmErrorCodes errorSubCode;
+        if (code != BgpConstants.BGP_NOTIFY_CEASE_CODE) {
+            // CEASE Notifications alone have to be reported to the CBA.
+            // Silently return here. No need to log because tons
+            // of non-alarm notifications will be sent to the SDNc.
+            return;
         }
-        if(getRoutes == true)
-            pullConfigurationFromBgp();
-        //controllerResyncLatch.countDown();
-    }*/
-
-    /*public void waitForControllerBgpResync() {
-        try {
-            controllerResyncLatch.await();
-        } catch (InterruptedException e) {
+        errorSubCode = BgpAlarmErrorCodes.checkErrorSubcode(subcode);
+        if (errorSubCode == BgpAlarmErrorCodes.ERROR_IGNORE) {
+            // Need to report only those subcodes, defined in
+            // BgpAlarmErrorCodes enum class.
+            return;
         }
-    }*/
+        String alarmString = "";
+        alarmString = "Alarm (" + code + "," + subcode + ") from neighbor " + pfx;
+        qbgpAlarmProducer.sendBgpAlarmInfo(pfx, code, subcode);
+    }
 
-    /*private void pullConfigurationFromBgp() {
-        //get routes from bgp server
-        s_logger.info("Starting bgp route sync");
-        try {
-            bgpThriftClient.doRouteSync();
-        } catch (BgpRouterException b) {
-            s_logger.error("Failed BGP Route sync due to BgpRouter Exception number " + b.getErrorCode());
-            s_logger.error("BgpRouterException trace ", b);
-        } catch (Exception e) {
-            s_logger.error("Failed to pull configuration from bgp ", e);
-        }
-    }*/
-
-    /*private BgpConfiguration readBgpConfiguration() {
-        if (cache != null) {
-            bgpConfiguration = cache.get("bgpConfiguration");
-            if (bgpConfiguration == null) {
-                s_logger.info("Created bgp configuration cache");
-                bgpConfiguration = new BgpConfiguration();
-                cache.put("bgpConfiguration", bgpConfiguration);
-            } else {
-                s_logger.info("Using bgp configuration cache");
-            }
-        }
-        return bgpConfiguration;
-    }*/
-
-    /*public synchronized void pushConfigurationToBgp() throws Exception {
-        if (bgpConfiguration.getAsNum() == 0) {
-            s_logger.error("No as num configured, Skipping the push configuration to bgp ");
-            throw new BgpRouterException(BgpRouterException.BGP_ERR_INACTIVE);
-            //return;
-        }
-        if(bgpThriftClient == null) {
-            s_logger.error("bgpThriftClient is null. Skipping the push configuration to bgp.");
-            throw new BgpRouterException(BgpRouterException.BGP_ERR_INACTIVE);
-            //return;
-        }
+    public Timer getBgpCountersTimer() {
+        return bgpCountersTimer;
+    }
 
-        try {
-            bgpThriftClient.startBgp((int)bgpConfiguration.getAsNum(), bgpConfiguration.getRouterId());
-            s_logger.info("Started BGP with AS number " + (int)bgpConfiguration.getAsNum() + " and router id " + bgpConfiguration.getRouterId());
-        } catch (BgpRouterException be) {
-            if(be.getErrorCode() == BgpRouterException.BGP_ERR_ACTIVE) {
-                s_logger.info("bgp server already active");
-                return;                //the assumption here is that bgp server is configured already with neighbor, vrfs and routes as well
-            } if(be.getErrorCode() == BgpRouterException.BGP_ERR_INACTIVE) {
-                s_logger.info("bgp server inactive");
-                throw be;
-            }
+    public BgpCounters getBgpCounters() {
+        return bgpCounters;
+    }
 
-            else {
-                s_logger.error("application error while starting bgp server %d", be.getErrorCode());
-                return;
-            }
+    public  void setBgpCountersTimer (Timer t) {
+        bgpCountersTimer = t;
+    }
 
-        } catch (SocketTimeoutException to) {
-            s_logger.error("Socket Timeout error while starting bgp server", to);
-            return;
-        } catch (TException t) {
-            s_logger.error("Transport error while starting bgp server ", t);
-            return;
-        } catch (Exception e) {
-            s_logger.error("Error while starting bgp server", e);
-        }
+    public void startBgpCountersTask() {
+        if (getBgpCounters() == null) {
 
-        if (bgpConfiguration.getNeighbourIp().trim().length() > 0) {
             try {
-                bgpThriftClient.addNeighbor(bgpConfiguration.getNeighbourIp(), bgpConfiguration.getNeighbourAsNum());
-            } catch (TException t) {
-                s_logger.error("Failed to push vrf to bgp due to Transport error" );
-                //retry connection
-                reInitConn();
-                addNeighbor(bgpConfiguration.getNeighbourIp(), bgpConfiguration.getNeighbourAsNum());
+                bgpCounters = new BgpCounters();
+                setBgpCountersTimer(new Timer(true));
+                getBgpCountersTimer().scheduleAtFixedRate(bgpCounters, 0, 120 * 1000);
+
+
+                LOGGER.info("Bgp Counters task scheduled for every two minutes.");
             } catch (Exception e) {
-                s_logger.error("Error while starting bgp server", e);
+                System.out.println("Could not start the timertask for Bgp Counters.");
+                e.printStackTrace();
             }
-        }
 
-        Tenant tenant;
-        try {
-            tenant = tenantManager.getTenant("NEUTRON");
-        } catch (TenantNotFoundException e) {
-            s_logger.error("Tenant not found. Skipping push configuration to bgp.");
-            return;
-        }
-        if (tenant != null) {
-            int tenantId = tenant.getTenantId();
-
-            Set<VpnInstanceInfo> vpnInfos = l3Manager.getVpnInstanceManager().getVpnsForTenant(tenantId);
-            s_logger.info("Number of vpns to configure is "+vpnInfos.size());
-            for (VpnInstanceInfo vpnInfo: vpnInfos) {
-                try {
-                    bgpThriftClient.addVrf(vpnInfo.getRouteDistinguisher(),
-                        new ArrayList<>(vpnInfo.getRtImportList()),
-                        new ArrayList<>(vpnInfo.getRtExportList()));
-                } catch (TException t) {
-                    s_logger.error("Failed to push vrf to bgp due to Transport error" );
-                    //retry connection
-                    reInitConn();
-                    addVrf(vpnInfo.getRouteDistinguisher(), new ArrayList<>(vpnInfo.getRtImportList()),
-                        new ArrayList<>(vpnInfo.getRtExportList()));
-                } catch (Exception e) {
-                    s_logger.error("Failed to push vrf to bgp ", e);
-                }
-            }
-            for (VpnInstanceInfo vpnInfo: vpnInfos) {
-                ConcurrentMap<FibInfo, Object>  fibInfos = l3Manager.getVpnInstanceManager().
-                    getLocalFibInfosForRdCache(vpnInfo.getRouteDistinguisher());
-                s_logger.info("Number of fib infos to configure is "+fibInfos.size());
-                for (FibInfo fibInfo : fibInfos.keySet()) {
-                    try {
-                        bgpThriftClient.addPrefix(vpnInfo.getRouteDistinguisher(), fibInfo.getDestinationPrefix(),
-                            fibInfo.getNextHopPrefix(), (int) fibInfo.getLabel());
-                    } catch (TException t) {
-                        s_logger.error("Failed to push route to bgp due to Transport error" );
-                        reInitConn();
-                        addPrefix(vpnInfo.getRouteDistinguisher(), fibInfo.getDestinationPrefix(),
-                            fibInfo.getNextHopPrefix(), (int) fibInfo.getLabel());
-                    } catch (Exception e) {
-                        s_logger.error("Failed to push route to bgp ", e);
-                    }
-                }
+            try {
+                setQbgpLog(BgpConstants.BGP_DEF_LOG_FILE, BgpConstants.BGP_DEF_LOG_LEVEL);
+            } catch (Exception e) {
+                System.out.println("Could not set the default options for logging");
             }
         }
+    }
 
+    public void stopBgpCountersTask() {
+        Timer t = getBgpCountersTimer();
+        if (getBgpCounters() != null) {
+            t.cancel();
+            setBgpCountersTimer(null);
+            bgpCounters = null;
+        }
     }
-    */
 
-    public void disconnect() {
-        bgpThriftClient.disconnect();
+    public FibDSWriter getFibWriter() {
+        return fibDSWriter;
+    } 
+
+    public DataBroker getBroker() {
+        return dataBroker;
+    } 
+
+    public String getConfigHost() {
+        return bcm.getConfigHost();
     }
 
+    public int getConfigPort() {
+        return bcm.getConfigPort();
+    }
 
+    public void bgpRestarted() {
+        bcm.bgpRestarted();
+    }
 }