Fix for BgpManager Sonar issues. 70/19570/1
authorManisha Malla <manisha.malla@ericsson.com>
Tue, 5 May 2015 05:49:36 +0000 (11:19 +0530)
committerManisha Malla <manisha.malla@ericsson.com>
Tue, 5 May 2015 05:53:09 +0000 (11:23 +0530)
Signed-off-by: Manisha Malla <manisha.malla@ericsson.com>
Change-Id: I934811b6f5d7ec69258de6d114acd64e722cbe85

bgpmanager/bgpmanager-impl/src/main/java/org/opendaylight/bgpmanager/BgpManager.java
bgpmanager/bgpmanager-impl/src/main/java/org/opendaylight/bgpmanager/thrift/client/implementation/BgpRouter.java
bgpmanager/bgpmanager-impl/src/main/java/org/opendaylight/bgpmanager/thrift/client/implementation/BgpSyncHandle.java
bgpmanager/bgpmanager-impl/src/main/java/org/opendaylight/bgpmanager/thrift/server/implementation/BgpThriftService.java
bgpmanager/bgpmanager-impl/src/main/java/org/opendaylight/bgpmanager/thrift/server/implementation/BgpUpdateHandler.java

index cbcaa2e5d9e3a2048f9d6b0cba28f7dca0fd1896..35d492471d2e48227a0cafc39bcff876c19c077a 100644 (file)
@@ -35,7 +35,7 @@ import org.slf4j.LoggerFactory;
 
 public class BgpManager implements BindingAwareProvider, AutoCloseable, IBgpManager {
 
-    private static final Logger s_logger = LoggerFactory.getLogger(BgpManager.class);
+    private static final Logger LOGGER = LoggerFactory.getLogger(BgpManager.class);
     private BgpConfigurationManager bgpConfigurationMgr;
     private FibDSWriter fibDSWriter;
     private BgpConfiguration   bgpConfiguration = new BgpConfiguration();
@@ -88,7 +88,7 @@ public class BgpManager implements BindingAwareProvider, AutoCloseable, IBgpMana
             try {
                 wait();
             } catch (InterruptedException e) {
-                s_logger.error("InterruptedException while waiting for Bgp connection to initialize");
+                LOGGER.error("InterruptedException while waiting for Bgp connection to initialize");
                 return;
             }
         }
@@ -96,37 +96,37 @@ public class BgpManager implements BindingAwareProvider, AutoCloseable, IBgpMana
 
     public void startBgpService() throws TException {
         if(bgpThriftClient == null) {
-            s_logger.info("Start Bgp Service - bgpThriftClient is null. Unable to start BGP service.");
+            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());
+            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");
+                LOGGER.info("bgp server already active");
                 return;
             }
             else if(be.getErrorCode() == BgpRouterException.BGP_ERR_NOT_INITED) {
-                s_logger.error("bgp server connection not initialized.");
+                LOGGER.error("bgp server connection not initialized.");
                 reInitConn();
                 return;
             }
             else {
-                s_logger.error("application error while starting bgp server " + be.getErrorCode());
+                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);
+            LOGGER.error("Could not set up thrift connection with bgp server");
+            //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);
+            LOGGER.error("Error while starting bgp server");
+            //LOGGER.trace("Bgp Service not started due to exception", e);
             return;
         }
 
@@ -136,13 +136,13 @@ public class BgpManager implements BindingAwareProvider, AutoCloseable, IBgpMana
 
     @Override
     public void onSessionInitiated(ProviderContext session) {
-        s_logger.info("BgpManager Session Initiated");
+        LOGGER.info("BgpManager Session Initiated");
         try {
             final DataBroker dataBroker = session.getSALService(DataBroker.class);
             bgpConfigurationMgr = new BgpConfigurationManager(dataBroker, bgpConfiguration, this);
             fibDSWriter = new FibDSWriter(dataBroker);
         } catch (Exception e) {
-            s_logger.error("Error initializing services", e);
+            LOGGER.error("Error initializing services", e);
         }
 
         initializeBGPCommunication();
@@ -151,7 +151,7 @@ public class BgpManager implements BindingAwareProvider, AutoCloseable, IBgpMana
 
    @Override
     public void close() throws Exception {
-        s_logger.info("BgpManager Closed");
+        LOGGER.info("BgpManager Closed");
 
        //close the client and server ends of the thrift communication
        if(bgpThriftClient != null)
@@ -174,42 +174,42 @@ public class BgpManager implements BindingAwareProvider, AutoCloseable, IBgpMana
 
     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.");
+            LOGGER.info("Add BGP Neighbor - bgpThriftClient is null. Unable to add BGP Neighbor.");
             return;
         }
 
         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);
+            LOGGER.error("Failed to add BGP neighbor " + ipAddress + "due to BgpRouter Exception number " + b.getErrorCode());
+            LOGGER.error("BgpRouterException trace ", b);
         } catch (TException t) {
-            s_logger.error(String.format("Failed adding neighbor %s due to Transport error", ipAddress));
+            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));
+            LOGGER.error(String.format("Failed adding neighbor %s", ipAddress));
         }
     }
 
 
     protected void deleteNeighbor(String ipAddress) throws TException {
         if(bgpThriftClient == null) {
-            s_logger.info("Delete BGP Neighbor - bgpThriftClient is null. Unable to delete BGP Neighbor.");
+            LOGGER.info("Delete BGP Neighbor - bgpThriftClient is null. Unable to delete BGP Neighbor.");
             return;
         }
 
         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);
+            LOGGER.error("Failed to delete BGP neighbor " + ipAddress + "due to BgpRouter Exception number " + b.getErrorCode());
+            LOGGER.error("BgpRouterException trace ", b);
         }catch (TException t) {
-            s_logger.error(String.format("Failed deleting neighbor %s due to Transport error", ipAddress));
+            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));
+            LOGGER.error(String.format("Failed deleting neighbor %s", ipAddress));
         }
     }
 
@@ -217,21 +217,21 @@ public class BgpManager implements BindingAwareProvider, AutoCloseable, IBgpMana
     @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.");
+            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);
+            LOGGER.error("Failed to add BGP vrf " + rd + "due to BgpRouter Exception number " + b.getErrorCode());
+            LOGGER.error("BgpRouterException trace ", b);
             throw b;
         } catch (TException t) {
-            s_logger.error(String.format("Failed adding vrf %s due to Transport error", rd));
+            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));
+            LOGGER.error(String.format("Failed adding vrf %s", rd));
             throw e;
         }
     }
@@ -239,21 +239,21 @@ public class BgpManager implements BindingAwareProvider, AutoCloseable, IBgpMana
     @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.");
+            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);
+            LOGGER.error("Failed to delete BGP vrf " + rd + "due to BgpRouter Exception number " + b.getErrorCode());
+            LOGGER.error("BgpRouterException trace ", b);
             throw b;
         } catch (TException t) {
-            s_logger.error(String.format("Failed deleting vrf %s due to Transport error", rd));
+            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));
+            LOGGER.error(String.format("Failed deleting vrf %s", rd));
             throw e;
         }
     }
@@ -269,16 +269,16 @@ public class BgpManager implements BindingAwareProvider, AutoCloseable, IBgpMana
         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);
+            LOGGER.error("Failed to add BGP prefix " + prefix + "due to BgpRouter Exception number " + b.getErrorCode());
+            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",
+            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",
+            LOGGER.error(String.format("Failed adding prefix entry <vrf:prefix:nexthop:vpnlabel> %s:%s:%s:%d",
                 rd, prefix, nextHop, vpnLabel));
             throw e;
         }
@@ -295,16 +295,16 @@ public class BgpManager implements BindingAwareProvider, AutoCloseable, IBgpMana
         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);
+            LOGGER.error("Failed to delete BGP prefix " + prefix + "due to BgpRouter Exception number " + b.getErrorCode());
+            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",
+            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",
+            LOGGER.error(String.format("Failed deleting prefix entry <vrf:prefix> %s:%s",
                 rd, prefix));
             throw e;
         }
@@ -316,22 +316,22 @@ public class BgpManager implements BindingAwareProvider, AutoCloseable, IBgpMana
         bgpPort = port;
 
         if(bgpThriftClient == null) {
-            s_logger.error("Failed to connect to BGP server since Bgp Thrift Client is not initialized yet.");
+            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);
+            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("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 ");
+            LOGGER.error("Failed to initialize BGP Connection due to Transport error ");
             throw t;
         }
         catch (Exception e) {
-            s_logger.error("Failed to initialize BGP Connection ");
+            LOGGER.error("Failed to initialize BGP Connection ");
             throw e;
         }
     }
@@ -340,8 +340,8 @@ public class BgpManager implements BindingAwareProvider, AutoCloseable, IBgpMana
         try {
             bgpConfiguration.setAsNum(asNum);
             bgpConfiguration.setRouterId(routerId);
-        } catch(Throwable e) {
-            s_logger.error("failed configuring bgp ",e);
+        } catch(Exception e) {
+            LOGGER.error("failed configuring bgp ",e);
         }
     }
 
@@ -349,173 +349,18 @@ public class BgpManager implements BindingAwareProvider, AutoCloseable, IBgpMana
 
         try {
             bgpThriftClient.reInit();
-            s_logger.info("Reinitialized connection to BGP Server " + bgpHost);
+            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);
+            LOGGER.error("Failed to reinitialize connection to BGP server " + bgpHost + " on port " + bgpPort + " due to BgpRouter Exception number " + b.getErrorCode());
+            LOGGER.error("BgpRouterException trace ", b);
         } catch (TException t) {
-            s_logger.error("Failed to reinitialize BGP Connection due to Transport error.");
+            LOGGER.error("Failed to reinitialize BGP Connection due to Transport error.");
         }
         catch (Exception e) {
-            s_logger.error("Failed to reinitialize BGP Connection.", e);
+            LOGGER.error("Failed to reinitialize BGP Connection.", e);
         }
     }
 
-    /*public synchronized void startBgpSync() {
-        boolean getRoutes = true;
-        readBgpConfiguration();
-        try {
-            pushConfigurationToBgp();
-
-        } 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);
-        }
-        if(getRoutes == true)
-            pullConfigurationFromBgp();
-        //controllerResyncLatch.countDown();
-    }*/
-
-    /*public void waitForControllerBgpResync() {
-        try {
-            controllerResyncLatch.await();
-        } catch (InterruptedException e) {
-        }
-    }*/
-
-    /*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;
-        }
-
-        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;
-            }
-
-            else {
-                s_logger.error("application error while starting bgp server %d", be.getErrorCode());
-                return;
-            }
-
-        } 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);
-        }
-
-        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());
-            } catch (Exception e) {
-                s_logger.error("Error while starting bgp server", e);
-            }
-        }
-
-        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);
-                    }
-                }
-            }
-        }
-
-    }
-    */
-
     public void disconnect() {
         bgpThriftClient.disconnect();
     }
index 181e266427071f85f542d432040d882c8ccc6d45..e5af15acd93e733c946c5d4d08b633a9334102f6 100644 (file)
@@ -17,10 +17,9 @@ import org.slf4j.LoggerFactory;
 
 public class BgpRouter {
     private TTransport transport;
-    private TSocket sock;
     private TProtocol protocol;
     private static BgpConfigurator.Client bgpClient=null;
-    private static final Logger logger = LoggerFactory.getLogger(BgpRouter.class);
+    private static final Logger LOGGER = LoggerFactory.getLogger(BgpRouter.class);
 
 
     private final static int ADD_NBR = 1;
@@ -31,10 +30,6 @@ public class BgpRouter {
     private final static int DEL_PFX = 6;
     private final static int START_BGP = 7;
 
-    //public final static int BGP_ERR_INITED = 101;
-    //public final static int BGP_ERR_NOT_INITED = 102;
-
-
     private final static int GET_RTS_INIT = 0;
     private final static int GET_RTS_NEXT = 1;
 
@@ -75,38 +70,42 @@ public class BgpRouter {
         this.bgpPort = bgpPort;
         bop = new BgpOp();
         try {
-            logger.info("Connecting to BGP Server " + bgpHost + " on port " + bgpPort);
+            LOGGER.info("Connecting to BGP Server " + bgpHost + " on port " + bgpPort);
             reInit();
         } catch (Exception e) {
-            logger.error("Failed connecting to BGP server ");
+            LOGGER.error("Failed connecting to BGP server ");
             throw e;
         }
     }
 
     public void disconnect() {
-        if(transport != null)
+        if(transport != null) {
             transport.close();
+        }
     }
 
     public void reInit()
         throws TException, BgpRouterException {
-        if(transport != null)
+        if(transport != null) {
             transport.close();
+        }
         transport = new TSocket(bgpHost, bgpPort);
         ((TSocket)transport).setTimeout(Constants.CL_SKT_TIMEO_MS);
         transport.open();
         protocol = new TBinaryProtocol(transport);
         bgpClient = new BgpConfigurator.Client(protocol);
-        if(bop == null)
+        if(bop == null) {
             bop = new BgpOp();
+        }
     }
 
     private void dispatch(BgpOp op)
         throws TException, BgpRouterException {
         int result = 1;
 
-        if (bgpClient == null)
+        if (bgpClient == null) {
             throw new BgpRouterException(BgpRouterException.BGP_ERR_NOT_INITED);
+        }
 
         switch (op.type) {
             case START_BGP:
@@ -133,7 +132,9 @@ public class BgpRouter {
                 break;
             default: break;
         }
-        if (result != 0) throw new BgpRouterException(result);
+        if (result != 0) {
+            throw new BgpRouterException(result);
+        }
     }
 
     public void startBgp(int asNum, String rtrId)
@@ -141,7 +142,7 @@ public class BgpRouter {
         bop.type = START_BGP;
         bop.asNum = asNum;
         bop.rtrId = rtrId;
-        logger.info("Starting BGP Server with as number " + asNum + " and router ID " + rtrId);
+        LOGGER.info("Starting BGP Server with as number " + asNum + " and router ID " + rtrId);
         dispatch(bop);
     }
 
@@ -150,7 +151,7 @@ public class BgpRouter {
         bop.type = ADD_NBR;
         bop.nbrIp = nbrIp;
         bop.nbrAsNum = nbrAsNum;
-        logger.info("Adding BGP Neighbor " + nbrIp + " with as number " + nbrAsNum);
+        LOGGER.info("Adding BGP Neighbor " + nbrIp + " with as number " + nbrAsNum);
         dispatch(bop);
     }
 
@@ -158,7 +159,7 @@ public class BgpRouter {
         throws TException, BgpRouterException {
         bop.type = DEL_NBR;
         bop.nbrIp = nbrIp;
-        logger.info("Deleting BGP Neighbor " + nbrIp);
+        LOGGER.info("Deleting BGP Neighbor " + nbrIp);
         dispatch(bop);
     }
 
@@ -168,7 +169,7 @@ public class BgpRouter {
         bop.rd = rd;
         bop.irts = irts;
         bop.erts = erts;
-        logger.info("Adding BGP VRF rd: " + rd);
+        LOGGER.info("Adding BGP VRF rd: " + rd);
         dispatch(bop);
     }
 
@@ -176,7 +177,7 @@ public class BgpRouter {
         throws TException, BgpRouterException {
         bop.type = DEL_VRF;
         bop.rd = rd;
-        logger.info("Deleting BGP VRF rd: " + rd);
+        LOGGER.info("Deleting BGP VRF rd: " + rd);
         dispatch(bop);
     }
 
@@ -187,7 +188,7 @@ public class BgpRouter {
         bop.pfx = prefix;
         bop.nh = nexthop;
         bop.lbl = label;
-        logger.info("Adding BGP route - rd:" + rd + " prefix:" + prefix + " nexthop:" + nexthop + " label:" + label);
+        LOGGER.info("Adding BGP route - rd:" + rd + " prefix:" + prefix + " nexthop:" + nexthop + " label:" + label);
         dispatch(bop);
     }
 
@@ -196,16 +197,18 @@ public class BgpRouter {
         bop.type = DEL_PFX;
         bop.rd = rd;
         bop.pfx = prefix;
-        logger.info("Deleting BGP route - rd:" + rd + " prefix:" + prefix);
+        LOGGER.info("Deleting BGP route - rd:" + rd + " prefix:" + prefix);
         dispatch(bop);
     }
 
     public int initRibSync(BgpSyncHandle handle)
         throws TException, BgpRouterException {
-        if (bgpClient == null)
+        if (bgpClient == null) {
             throw new BgpRouterException(BgpRouterException.BGP_ERR_NOT_INITED);
-        if (handle.getState() == BgpSyncHandle.ITERATING)
+        }
+        if (handle.getState() == BgpSyncHandle.ITERATING) {
             return BgpRouterException.BGP_ERR_IN_ITER;
+        }
         handle.setState(BgpSyncHandle.INITED);
         handle.setMore(1);
         return 0;
@@ -213,8 +216,9 @@ public class BgpRouter {
 
     public int endRibSync(BgpSyncHandle handle)
         throws TException, BgpRouterException {
-        if (bgpClient == null)
+        if (bgpClient == null) {
             throw new BgpRouterException(BgpRouterException.BGP_ERR_NOT_INITED);
+        }
         int state = handle.getState();
         switch (state) {
             case BgpSyncHandle.INITED:
@@ -233,8 +237,9 @@ public class BgpRouter {
 
     public Routes doRibSync(BgpSyncHandle handle)
         throws TException, BgpRouterException {
-        if (bgpClient == null)
+        if (bgpClient == null) {
             throw new BgpRouterException(BgpRouterException.BGP_ERR_NOT_INITED);
+        }
         int state = handle.getState();
         if (state != BgpSyncHandle.INITED && state != BgpSyncHandle.ITERATING) {
             Routes r = new Routes();
@@ -246,11 +251,13 @@ public class BgpRouter {
         handle.setState(BgpSyncHandle.ITERATING);
         int winSize = handle.getMaxCount()*handle.getRouteSize();
         Routes outRoutes = bgpClient.getRoutes(op, winSize);
-       if (outRoutes.errcode != 0)
-            return outRoutes;
+       if (outRoutes.errcode != 0) {
+           return outRoutes;
+       }
         handle.setMore(outRoutes.more);
-        if (outRoutes.more == 0)
+        if (outRoutes.more == 0) {
             handle.setState(BgpSyncHandle.DONE);
+        }
         return outRoutes;
     }
 
@@ -260,13 +267,13 @@ public class BgpRouter {
         BgpSyncHandle bsh = BgpSyncHandle.getInstance();
 
         try {
-            logger.info("Starting BGP Route sync.. ");
+            LOGGER.info("Starting BGP Route sync.. ");
             initRibSync(bsh);
             while (bsh.getState() != bsh.DONE) {
                 Routes r = doRibSync(bsh);
                 if(r.getErrcode() == BgpRouterException.BGP_ERR_INACTIVE) {
                     //BGP server is inactive; log and return
-                    logger.error("BGP Server is inactive. Failed BGP Route sync");
+                    LOGGER.error("BGP Server is inactive. Failed BGP Route sync");
                     return;
                 }
                 Iterator<Update> iter = r.getUpdatesIterator();
@@ -281,37 +288,12 @@ public class BgpRouter {
                 }
             }
             endRibSync(bsh);
-            logger.info("Completed BGP Route sync.");
+            LOGGER.info("Completed BGP Route sync.");
         }  catch (Exception e) {
             throw e;
         }
     };
 
 
-    public List<Route> getRoutes()
-        throws TException, BgpRouterException {
-
-        BgpSyncHandle bsh = BgpSyncHandle.getInstance();
-        List<Route> allRoutes = new ArrayList<Route>();
-
-        try {
-            initRibSync(bsh);
-            while (bsh.getState() != bsh.DONE) {
-                Routes r = doRibSync(bsh);
-                Iterator<Update> iter = r.getUpdatesIterator();
-                while (iter.hasNext()) {
-                    Update u = iter.next();
-                    Route route = new Route(u.rd, u.prefix, u.prefixlen, u.nexthop, u.label);
-
-                    allRoutes.add(route);
-                }
-            }
-            endRibSync(bsh);
-        }  catch (Exception e) {
-            throw e;
-        }
-        return allRoutes;
-    };
-
 
 }
index e00515f3fe18631ff0380237f23758b07ff57e18..5c0eb4238c2dc7a6a3e75982706eb239f83bb32e 100644 (file)
@@ -4,9 +4,12 @@ package org.opendaylight.bgpmanager.thrift.client.implementation;
 import java.io.IOException;
 import java.net.Socket;
 import java.net.SocketException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class BgpSyncHandle {
     private static BgpSyncHandle handle = null;
+    private static final Logger LOGGER = LoggerFactory.getLogger(BgpSyncHandle.class);
     private int more;
     private int state;
 
@@ -16,7 +19,7 @@ public class BgpSyncHandle {
     public static final int ABORTED = 4;
     public static final int NEVER_DONE = 5;
 
-    public static final int default_tcp_sock_sz = 87380;    //default receive buffer size on linux > 2.4 (SLES 11)
+    public static final int DEFAULT_TCP_SOCK_SZ = 87380;    //default receive buffer size on linux > 2.4
 
     private BgpSyncHandle() {
         more = 1; 
@@ -24,8 +27,9 @@ public class BgpSyncHandle {
     }
 
     public static synchronized BgpSyncHandle getInstance() {
-       if (handle == null) 
+       if (handle == null) {
            handle = new BgpSyncHandle();
+       }
        return handle;
     }
 
@@ -36,14 +40,16 @@ public class BgpSyncHandle {
     public int getMaxCount() {
         //compute the max count of routes we would like to send
         Socket skt = new Socket();
-        int sockBufSz = default_tcp_sock_sz;
+        int sockBufSz = DEFAULT_TCP_SOCK_SZ;
         try {
             sockBufSz = skt.getReceiveBufferSize();
         } catch (SocketException s) {
+            LOGGER.warn("Socket Exception while retrieving default socket buffer size");
         }
         try {
             skt.close();
         } catch (IOException e) {
+            LOGGER.warn("IO Exception while closing socket for retrieving default socket buffer size");
         }
         return sockBufSz/getRouteSize();
     }
index c6d01195c109050a2331b335a074060502e5f499..dfe4af646d97f2907c2f8b39c1cd6bd5d81ea699 100644 (file)
@@ -14,14 +14,12 @@ import org.slf4j.LoggerFactory;
 
 public class BgpThriftService {
        
-       private static final Logger logger = LoggerFactory.getLogger(BgpThriftService.class);
+       private static final Logger LOGGER = LoggerFactory.getLogger(BgpThriftService.class);
        
        private int port;
-       //private int serverType;
        private int maxWorkerThreads;
        private int minWorkerThreads;
     private TServerTransport serverTransport;
-       //private TNonblockingServerTransport serverTransport;
     private TServer server;
        private BgpUpdateHandler notificationHandler;
        private BgpManager bgpManager;
@@ -29,17 +27,16 @@ public class BgpThriftService {
     public BgpThriftService(BgpManager bgpMgr, FibDSWriter dsWriter) {
        bgpManager = bgpMgr;
                notificationHandler = new BgpUpdateHandler(bgpManager, dsWriter);
-               //fibDSWriter = dsWriter;
     }
 
 
        public void start() {
-               logger.info("BGP Thrift Server starting.");
+               LOGGER.info("BGP Thrift Server starting.");
                startBgpThriftServer();
        }
        
        public void stop() {
-               logger.info("BGP Thrift Server stopping.");
+               LOGGER.info("BGP Thrift Server stopping.");
                stopBgpThriftServer();
        }
 
@@ -47,7 +44,7 @@ public class BgpThriftService {
         * Destroy method called up after the bundle has been stopped
         */
        public void destroy() {
-               logger.debug("BGP Thrift Server destroy ");
+               LOGGER.debug("BGP Thrift Server destroy ");
        }
 
     /**
@@ -71,7 +68,7 @@ public class BgpThriftService {
 
        public void stopBgpThriftServer() {
                try {
-            logger.debug("Server stopping");
+            LOGGER.debug("Server stopping");
 
             if (serverTransport != null) {
                 serverTransport.close();
@@ -79,21 +76,19 @@ public class BgpThriftService {
             
             server.stop();
         } catch (Exception e) {
-            logger.error("Error while stopping the server - {} {}", getClass().getName(), e.getMessage());
+            LOGGER.error("Error while stopping the server - {} {}", getClass().getName(), e.getMessage());
         }
        }
        
        private class ThriftRunnable implements Runnable {
                @Override
                public void run() {
-                       //notificationHandler = new BgpUpdateHandler(bgpManager);
 
                try {
                                serverTransport = new TServerSocket(port);
-                               //serverTransport = new TNonblockingServerSocket(port);
-                   logger.info("Server Socket on Port {} ", port);
-                       } catch (TTransportException e) {                       
-                               e.printStackTrace();
+                   LOGGER.info("Server Socket on Port {} ", port);
+                       } catch (TTransportException e) {
+                               LOGGER.error("Transport Exception while starting bgp thrift server", e);
                                return;
                        }
                        /* This may need to change. Right now, its as good as a blocking server for each client (client would be
@@ -103,11 +98,6 @@ public class BgpThriftService {
                server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport)
                        .maxWorkerThreads(maxWorkerThreads).minWorkerThreads(minWorkerThreads)
                        .processor(new BgpUpdater.Processor<BgpUpdateHandler>(notificationHandler)));
-                       /*
-                       THsHaServer.Args args = new THsHaServer.Args(serverTransport);
-                       args.workerThreads(10);
-                       server = new THsHaServer(args.processor(new BgpUpdater.Processor<BgpUpdateHandler>(notificationHandler)));*/
-
                        server.serve();
                }               
        }
index a9aecccc9fd5edd6ccb423cc858a7c0a2add7ecc..9f3c40a89a65a2d5ae33f791bf1cab1abd3767bf 100644 (file)
@@ -8,7 +8,7 @@ import org.slf4j.LoggerFactory;
 
 class BgpUpdateHandler implements BgpUpdater.Iface {
 
-    private static final Logger logger = LoggerFactory.getLogger(BgpUpdateHandler.class);
+    private static final Logger LOGGER = LoggerFactory.getLogger(BgpUpdateHandler.class);
     private BgpManager bgpManager;
     private FibDSWriter fibDSWriter;
 
@@ -20,7 +20,7 @@ class BgpUpdateHandler implements BgpUpdater.Iface {
     public void onUpdatePushRoute(String rd, String prefix, int plen,
                                 String nexthop, int label) {
 
-       logger.info("Route add ** " + rd + " ** " + prefix + "/" + plen
+       LOGGER.info("Route add ** " + rd + " ** " + prefix + "/" + plen
                + " ** " + nexthop + " ** " + label);
         //Write to FIB in Data Store
         fibDSWriter.addFibEntryToDS(rd, prefix + "/" + plen, nexthop, label);
@@ -28,13 +28,13 @@ class BgpUpdateHandler implements BgpUpdater.Iface {
    }
 
    public void onUpdateWithdrawRoute(String rd, String prefix, int plen) {
-       logger.info("Route del ** " + rd + " ** " + prefix + "/" + plen);
+       LOGGER.info("Route del ** " + rd + " ** " + prefix + "/" + plen);
        fibDSWriter.removeFibEntryFromDS(rd, prefix + "/" + plen);
 
    }
 
    public void onStartConfigResyncNotification() {
-       logger.info("BGP (re)started");
+       LOGGER.info("BGP (re)started");
        bgpManager.reInitConn();
    }