Enhancements in BGP module 55/85955/3
authorLoshmitha <loshmitha@ericsson.com>
Mon, 25 Nov 2019 09:29:03 +0000 (14:59 +0530)
committerAbhinav Gupta <abhinav.gupta@ericsson.com>
Tue, 26 Nov 2019 11:27:25 +0000 (11:27 +0000)
Error messages and other enhancements have been added

JIRA: NETVIRT-1644

Change-Id: Icbdf7a8bf8785765dc50de9999a67dcbeba7e166
Signed-off-by: Loshmitha <loshmitha@ericsson.com>
bgpmanager/impl/src/main/java/org/opendaylight/netvirt/bgpmanager/EvpnRdNetworkListener.java
bgpmanager/impl/src/main/java/org/opendaylight/netvirt/bgpmanager/VtyshCli.java
bgpmanager/impl/src/main/java/org/opendaylight/netvirt/bgpmanager/commands/Bfd.java
bgpmanager/impl/src/main/java/org/opendaylight/netvirt/bgpmanager/commands/ClearBgpCli.java
bgpmanager/impl/src/main/java/org/opendaylight/netvirt/bgpmanager/oam/BgpConstants.java
bgpmanager/impl/src/main/java/org/opendaylight/netvirt/bgpmanager/oam/BgpCounters.java
bgpmanager/impl/src/main/java/org/opendaylight/netvirt/bgpmanager/thrift/client/BgpSyncHandle.java

index 179281933d6395ec046bf6f6fccf7aad0ded0bb5..e3ce4494e6761ce84423fa26ac62091cfa81d62d 100644 (file)
@@ -12,6 +12,7 @@ import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeLis
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.EvpnRdToNetworks;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.evpn.rd.to.networks.EvpnRdToNetwork;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -27,7 +28,8 @@ public class EvpnRdNetworkListener extends AsyncDataTreeChangeListenerBase<EvpnR
     private final BgpConfigurationManager bgpConfigManager;
     private final BgpUtil bgpUtil;
 
-    public EvpnRdNetworkListener(DataBroker dataBroker, BgpConfigurationManager bgpConfigManager, BgpUtil bgpUtil) {
+    public EvpnRdNetworkListener(DataBroker dataBroker, BgpConfigurationManager bgpConfigManager, BgpUtil bgpUtil,
+            final IdManagerService idManager) {
         super(EvpnRdToNetwork.class, EvpnRdNetworkListener.class);
         this.broker = dataBroker;
         this.bgpConfigManager = bgpConfigManager;
index 3777776e8f86b4c5efcbaf3b18c31f42e112c4e4..c32dda3469f80992c6687a51b491547b9ef78af4 100644 (file)
@@ -61,6 +61,10 @@ public class VtyshCli extends OsgiCommandSupport {
         "display routing bgp ipv4 vpn summary",
         "display routing bgp ipv4 unicast <ip>",
         "display routing bgp ipv4 unicast <ip/mask>",
+        "display routing bgp bfd neighbors details",
+        "display routing bgp bfd neighbors",
+        "display routing bgp bfd neighbors <ip> details",
+        "display routing bgp bfd global-config",
         "display routing running-config"
     };
 
@@ -102,7 +106,8 @@ public class VtyshCli extends OsgiCommandSupport {
                 try {
                     handleCommand(cmd);
                 } catch (IOException ioe) {
-                    session.getConsole().println("IOException thrown.");
+                    session.getConsole().println("I/O error to" + serverName + ":"
+                            + SERVER_PORT + "occured " + ioe.getMessage());
                 }
                 break;
             default:
@@ -138,10 +143,12 @@ public class VtyshCli extends OsgiCommandSupport {
             socket = new Socket(serverName, SERVER_PORT);
 
         } catch (UnknownHostException ioe) {
-            System.out.println("No host exists: " + ioe.getMessage());
+            System.out.println("No host to " + serverName + ":"
+                                         + SERVER_PORT + "exists: " + ioe.getMessage());
             return;
         } catch (IOException ioe) {
-            System.out.println("I/O error occured " + ioe.getMessage());
+            System.out.println("I/O error to" + serverName + ":"
+                                         + SERVER_PORT + "occured " + ioe.getMessage());
             return;
         }
         try {
@@ -150,7 +157,8 @@ public class VtyshCli extends OsgiCommandSupport {
             inFromSocket = new BufferedReader(new InputStreamReader(socket.getInputStream()));
 
         } catch (IOException ioe) {
-            System.out.println("IOException thrown.");
+            System.out.println("I/O error to" + serverName + ":"
+                    + SERVER_PORT + "occured " + ioe.getMessage());
             socket.close();
             return;
         }
@@ -184,7 +192,8 @@ public class VtyshCli extends OsgiCommandSupport {
                 ip = inFromSocket.read();
             } catch (SocketTimeoutException ste) {
                 System.out.println(sb.toString());
-                System.out.println("Read from Socket timed Out while verifying the password.");
+                System.out.println("Socket timeout while verifying the  password in" + serverName + ":"
+                        + SERVER_PORT + "occured " + ste.getMessage());
                 socket.close();
                 return;
             }
@@ -215,7 +224,8 @@ public class VtyshCli extends OsgiCommandSupport {
                 ip = inFromSocket.read();
             } catch (SocketTimeoutException ste) {
                 System.out.println(sb.toString());
-                System.out.println("Read from Socket timed Out while sending the term len command..");
+                System.out.println("Read from socket timeout while sending term len command in" + serverName + ":"
+                        + SERVER_PORT + "occured " + ste.getMessage());
                 socket.close();
                 return;
             }
@@ -235,7 +245,7 @@ public class VtyshCli extends OsgiCommandSupport {
 
         String inputCmd = "show " + command;
         outToSocket.println(inputCmd);
-        StringBuilder output = new StringBuilder();
+        StringBuffer output = new StringBuffer();
         String errorMsg = "";
         while (true) {
             char[] opBuf = new char[100];
@@ -246,6 +256,8 @@ public class VtyshCli extends OsgiCommandSupport {
 
             } catch (SocketTimeoutException ste) {
                 errorMsg = "Read from Socket timed Out while getting the data.";
+                System.out.println("Socket timeout while getting the data in" + serverName + ":"
+                        + SERVER_PORT + "occured " + ste.getMessage());
                 break;
             }
             if (ret == -1) {
@@ -266,7 +278,7 @@ public class VtyshCli extends OsgiCommandSupport {
 
             }
 
-            String outputStr = temp.toString().replaceAll("^\\s", "");
+            String outputStr = temp.toString();
             output.append(outputStr);
             if (output.toString().trim().endsWith(prompt)) {
                 int index = output.toString().lastIndexOf(prompt);
index 32d56f3bc48195138a57320ec7d181c68a66a36a..761909ceeb7e2bf5867245551a8bd770f1ceb1ec 100644 (file)
@@ -100,7 +100,7 @@ public class Bfd extends OsgiCommandSupport {
                     } else {
                         mintx = Integer.parseInt(minTX);
                         if (mintx < MIN_TX_MIN || mintx > MIN_TX_MAX) {
-                            ps.println("error: value of TX should be between 1000 and 60000");
+                            ps.println("error: value of TX should be between 1000 and 4294000");
                             return null;
                         }
                     }
index d1d33f96e29fa7b319b9d131f73d2e9990b0129f..1e212e1fe33743e9b28d858bf1ab759402972ae5 100644 (file)
@@ -64,7 +64,7 @@ public class ClearBgpCli extends OsgiCommandSupport {
             try {
                 InetAddress.getByName(nbr);
             } catch (UnknownHostException e) {
-                session.getConsole().println("Invalid neighbor ip");
+                session.getConsole().println("Invalid neighbor ip :" + nbr);
                 return null;
             }
         }
index 4095b06ae9022ce9635aed2c0887bff3a2272022..cea13939fe6c5f73933c96cae0c34350b7135a13 100644 (file)
@@ -21,23 +21,26 @@ public interface BgpConstants {
     String BGP_COUNTER_NBR_PKTS_TX = "BgpNeighborPacketsSent";
     String BGP_COUNTER_RD_ROUTE_COUNT = "BgpRdRouteCount";
     String BGP_COUNTER_TOTAL_PFX = "BgpTotalPrefixes:Bgp_Total_Prefixes";
+    String BGP_COUNTER_IPV4_PFX = "BgpIPV4Prefixes:Bgp_IPV4_Prefixes";
+    String BGP_COUNTER_IPV6_PFX = "BgpIPV6Prefixes:Bgp_IPV6_Prefixes";
     String BGP_DEF_LOG_LEVEL = "debugging";
     String BGP_DEF_LOG_FILE = "/opt/quagga/var/log/quagga/zrpcd.init.log";
     String BFD_COUNTER_NBR_PKTS_RX = "BfdNeighborPacketsReceived";
     String BFD_COUNTER_NBR_PKTS_TX = "BfdNeighborPacketsSent";
     long DEFAULT_ETH_TAG = 0L;
     int BGP_DEFAULT_MULTIPATH = 2;
-    int BFD_DEFAULT_DETECT_MULT = 3;
+    int BFD_DEFAULT_DETECT_MULT = 8;
+    String BGP_CONFIG_ENTITY = "bgp";
     int BFD_DEFAULT_MIN_RX = 500;
-    int BFD_DEFAULT_MIN_TX = 6000;
+    int BFD_DEFAULT_MIN_TX = 500000;
     int MIN_RX_MIN = 50;
     int MIN_RX_MAX = 50000;
     int MIN_TX_MIN = 1000;
-    int MIN_TX_MAX = 60000;
-    int HISTORY_LIMIT = 10000;
-    int HISTORY_THRESHOLD = 7500;
+    int MIN_TX_MAX = 4294001;
     int MIN_DETECT_MULT = 2;
     int MAX_DETECT_MULT = 255;
+    int HISTORY_LIMIT = 100000;
+    int HISTORY_THRESHOLD = 75000;
     int BFD_DEFAULT_FAILURE_THRESHOLD = 0;
     int BFD_DEFAULT_SUCCESS_THRESHOLD = 0;
 }
index 8f758f980afb28d0bf5fcd3b9ca64a85bc820583..edd0844ea0e70d57c277a337a793fdc3869bf00e 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.netvirt.bgpmanager.oam;
 
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.File;
@@ -48,6 +49,7 @@ public class BgpCounters implements Runnable, AutoCloseable {
     public static final String BGP_EVPN_SUMMARY_FILE = "cmd_bgp_evpn_all_summary.txt";
     public static final String BFD_NBR_DETAIL_FILE = "cmd_bfd_neighbors_details.txt";
 
+
     // BFD related constants
     public static final int LINE = 1; // line where the ip address of neigbor present after "NeighbroAddr"
     public static final int NBR_IP_WORD_INDEX = 1; // word where the ip address is present (count start from 0)
@@ -57,6 +59,8 @@ public class BgpCounters implements Runnable, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(BgpCounters.class);
 
     private final Map<String, String> totalPfxMap = new ConcurrentHashMap<>();
+    private final Map<String, String> ipv4PfxMap = new ConcurrentHashMap<>();
+    private final Map<String, String> ipv6PfxMap = new ConcurrentHashMap<>();
 
     private final String bgpSdncMip;
     private final MetricProvider metricProvider;
@@ -130,10 +134,10 @@ public class BgpCounters implements Runnable, AutoCloseable {
                         sb.append((char) read);
                         break;
                 }
+
             }
 
-            // Enable
-            toRouter.println("en");
+            toRouter.flush();
 
             // Wait for '#'
             while ((read = fromRouter.read()) != '#') {
@@ -143,8 +147,11 @@ public class BgpCounters implements Runnable, AutoCloseable {
                 }
             }
 
+
             // Send the command
             toRouter.println(cmdName);
+            toRouter.flush();
+
 
             // Read all the router's output
             sb = new StringBuilder();
@@ -164,12 +171,18 @@ public class BgpCounters implements Runnable, AutoCloseable {
 
             // Store in the file
             toFile.write(sb.toString().trim());
+            socket.close();
+            toFile.flush();
+            toFile.close();
+            toRouter.flush();
+            toRouter.close();
+            fromRouter.close();
         } catch (UnknownHostException e) {
             LOG.info("Unknown host exception occured while socket creation {} ", bgpSdncMip);
         } catch (SocketTimeoutException e) {
             LOG.info("Socket timeout Exception occured while socket creation");
         } catch (IOException e) {
-            LOG.info("I/O exception occured while socket creation");
+            LOG.error("I/O error ip {} {}",bgpSdncMip, e.getMessage());
         }
     }
 
@@ -279,6 +292,11 @@ public class BgpCounters implements Runnable, AutoCloseable {
                 i = processRouteCount(rd + "_VPNV4", i + 1, inputStrs);
             }
         }
+        long bgpIpv4Pfxs = calculateBgpIpv4Prefixes();
+        LOG.trace("BGP IPV4 Prefixes:{}",bgpIpv4Pfxs);
+        Counter counter = getCounter(BgpConstants.BGP_COUNTER_IPV4_PFX, null, null, null,
+                null, null, "bgp-peer");
+        updateCounter(counter, bgpIpv4Pfxs);
     }
 
     /*
@@ -319,6 +337,11 @@ public class BgpCounters implements Runnable, AutoCloseable {
                 i = processRouteCount(rd + "_VPNV6", i + 1, inputStrs);
             }
         }
+        long bgpIpv6Pfxs = calculateBgpIpv6Prefixes();
+        LOG.trace("BGP IPV6 Prefixes:{}",bgpIpv6Pfxs);
+        Counter counter = getCounter(BgpConstants.BGP_COUNTER_IPV6_PFX, null, null, null,
+                null, null, "bgp-peer");
+        updateCounter(counter, bgpIpv6Pfxs);
     }
 
     private void parseBgpL2vpnEvpnAll() {
@@ -339,6 +362,7 @@ public class BgpCounters implements Runnable, AutoCloseable {
                 String[] result = instr.split(":");
                 String rd = result[1].trim() + "_" + result[2].trim();
                 i = processRouteCount(rd + "_EVPN", i + 1, inputStrs);
+                LOG.trace("BGP Total Prefixes:{}", i);
             }
         }
         /*populate the "BgpTotalPrefixes" counter by combining
@@ -416,7 +440,6 @@ public class BgpCounters implements Runnable, AutoCloseable {
         String bgpRdRouteCountKey = BgpConstants.BGP_COUNTER_RD_ROUTE_COUNT + rd;
         Counter counter = getCounter(BgpConstants.BGP_COUNTER_RD_ROUTE_COUNT, null, null, null,
                 null, rd, "bgp-peer");
-
         for (String str = inputStrs.get(num); str != null && !str.trim().equals("")
                 && num < inputStrs.size();
                 str = inputStrs.get(num)) {
@@ -425,7 +448,13 @@ public class BgpCounters implements Runnable, AutoCloseable {
                 updateCounter(counter, routeCount);
                 return num - 1;
             }
-            routeCount++;
+            else if (rd.contains("VPNV4")) {
+                ipv4PfxMap.put(bgpRdRouteCountKey, Long.toString(++routeCount));
+                updateCounter(counter, routeCount);
+            } else if (rd.contains("VPNV6")) {
+                ipv6PfxMap.put(bgpRdRouteCountKey, Long.toString(++routeCount));
+                updateCounter(counter, routeCount);
+            }
             num++;
             if (num == inputStrs.size()) {
                 break;
@@ -442,6 +471,16 @@ public class BgpCounters implements Runnable, AutoCloseable {
         return num - 1;
     }
 
+    private Long calculateBgpIpv4Prefixes() {
+        return ipv4PfxMap.entrySet().stream()
+                .map(Map.Entry::getValue).mapToLong(Long::parseLong).sum();
+    }
+
+    private Long calculateBgpIpv6Prefixes() {
+        return ipv6PfxMap.entrySet().stream()
+                .map(Map.Entry::getValue).mapToLong(Long::parseLong).sum();
+    }
+
     private Long calculateBgpTotalPrefixes() {
         return totalPfxMap.entrySet().stream()
                 .map(Map.Entry::getValue).mapToLong(Long::parseLong).sum();
@@ -449,6 +488,8 @@ public class BgpCounters implements Runnable, AutoCloseable {
 
     private void resetCounters() {
         totalPfxMap.clear();
+        ipv6PfxMap.clear();
+        ipv4PfxMap.clear();
         resetFile("cmd_ip_bgp_summary.txt");
         resetFile("cmd_bgp_ipv4_unicast_statistics.txt");
         resetFile(BGP_VPNV4_FILE);
index 6549f577116416f109d30a58457437027b13a22f..29bea23a8cd81ef9e196e845bb5c76ea58bfa5d5 100644 (file)
@@ -57,7 +57,7 @@ public class BgpSyncHandle {
         //moment, we just use 8 bytes more than the size of
         //the C struct.
 
-        return 96;
+        return 168;
     }
 
     public int setState(int newState) {