BGP fib cache and alarm task fixes 47/87047/9
authormanjunath.hethur <manjunath.hethur@gmail.com>
Mon, 20 Jan 2020 10:08:47 +0000 (15:38 +0530)
committerChetan Arakere Gowdru <chetan.arakere@altencalsoftlabs.com>
Fri, 3 Apr 2020 04:15:51 +0000 (04:15 +0000)
Fib cache issue : when 6644 move from one node to another, the fib cache was not handled
properly.
Alarm issue: BGP alarm task was not getting stopped even if the entity ownership has
changed. Adding code to stop it

JIRA: NETVIRT-1663

Signed-off-by: manjunath.hethur <manjunath.hethur@gmail.com>
Change-Id: I21c70fc4cfcd1f0ca8f9f185dd4cdebd396cc8a2
Signed-off-by: manjunath.hethur <manjunath.hethur@gmail.com>
bgpmanager/impl/src/main/java/org/opendaylight/netvirt/bgpmanager/BgpConfigurationManager.java
bgpmanager/impl/src/main/java/org/opendaylight/netvirt/bgpmanager/FibDSWriter.java
bgpmanager/impl/src/main/java/org/opendaylight/netvirt/bgpmanager/oam/BgpAlarms.java

index 32bfdd2fc1fc699e367dac71e688290e1bac26ff..926fe55528b3a26e56885cebdb19246c5d049a0d 100755 (executable)
@@ -496,6 +496,8 @@ public class BgpConfigurationManager implements EbgpService {
                     //disconnect the CONFIG SERVER port (which was )opened during I was Owner
                     bgpRouter.disconnect();
                 }
+                stopBgpCountersTask();
+                stopBgpAlarmsTask();
             }
         });
     }
@@ -3064,6 +3066,7 @@ public class BgpConfigurationManager implements EbgpService {
         totalStaledCount = 0;
         try {
             staledFibEntriesMap.clear();
+            fibDSWriter.clearFibMap();
             InstanceIdentifier<FibEntries> id = InstanceIdentifier.create(FibEntries.class);
 
             Optional<FibEntries> fibEntries = SingleTransactionDataBroker.syncReadOptional(dataBroker,
@@ -3084,9 +3087,15 @@ public class BgpConfigurationManager implements EbgpService {
                         //Create MAP from staleVrfTables.
                         vrfEntry.getRoutePaths()
                                 .forEach(
-                                    routePath -> staleFibEntMap.put(
-                                            appendNextHopToPrefix(vrfEntry.getDestPrefix(),
-                                                    routePath.getNexthopAddress()), routePath.getLabel()));
+                                    routePath -> {
+                                        staleFibEntMap.put(
+                                                appendNextHopToPrefix(vrfEntry.getDestPrefix(),
+                                                        routePath.getNexthopAddress()), routePath.getLabel());
+                                        fibDSWriter.addEntryToFibMap(
+                                                vrfTable.getRouteDistinguisher(),  vrfEntry.getDestPrefix(),
+                                                routePath.getNexthopAddress());
+
+                                    });
                     }
                     staledFibEntriesMap.put(vrfTable.getRouteDistinguisher(), staleFibEntMap);
                 }
index e9d62323e33b69c402a4b1c3c7f51bbea4442ca9..1c0797af6dfefbc7cb0bb8621cd54f1855e53c96 100644 (file)
@@ -46,8 +46,7 @@ public class FibDSWriter {
     private static final Logger LOG = LoggerFactory.getLogger(FibDSWriter.class);
     private final SingleTransactionDataBroker singleTxDB;
     private final BgpUtil bgpUtil;
-
-    private final Map<String,ArrayList<String>> fibMap = new HashMap<>();
+    private final Map<String, ArrayList<String>> fibMap = new HashMap<>();
 
     @Inject
     public FibDSWriter(final DataBroker dataBroker, final BgpUtil bgpUtil) {
@@ -88,6 +87,18 @@ public class FibDSWriter {
             LOG.debug("Created vrfEntry for {} nexthop {} label {}", prefix, nextHop, label);
         }
 
+        LOG.debug("addFibEntryToDS rd {} prefix {} NH {}",
+                rd, prefix, nextHopList.get(0));
+
+        ArrayList<String> temp = new ArrayList<String>();
+        if ((fibMap.get(appendrdtoprefix(rd, prefix)) != null)) {
+            temp.addAll(fibMap.get(appendrdtoprefix(rd, prefix)));
+        }
+        if (!temp.contains(nextHopList.get(0))) {
+            temp.addAll(nextHopList);
+            fibMap.put(appendrdtoprefix(rd, prefix), temp);
+        }
+
         // Looking for existing prefix in MDSAL database
         InstanceIdentifier<VrfEntry> vrfEntryId =
                 InstanceIdentifier.builder(FibEntries.class)
index fa0a3719080156e468aa156ee1b1c0fa96856667..a8bb06c873ccefa26f5da26b464337eac62df9e9 100644 (file)
@@ -13,7 +13,9 @@ import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.concurrent.ConcurrentHashMap;
+import org.apache.thrift.TException;
 import org.opendaylight.netvirt.bgpmanager.BgpConfigurationManager;
+import org.opendaylight.netvirt.bgpmanager.thrift.client.BgpRouterException;
 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.neighborscontainer.Neighbors;
 import org.slf4j.Logger;
@@ -89,40 +91,49 @@ public class BgpAlarms implements Runnable, AutoCloseable {
             return;
         }
 
-        for (Neighbors nbr : nbrs) {
-            boolean alarmToRaise = true;
-            if (nbrStatusMap != null && nbrStatusMap.containsKey(nbr.getAddress().getValue())) {
-                String nbrshipStatus = nbrStatusMap.get(nbr.getAddress().getValue());
-                LOG.trace("nbr {} status {}",
-                        nbr.getAddress().getValue(),
-                        nbrshipStatus);
-                try {
-                    Integer.parseInt(nbrshipStatus);
-                    alarmToRaise = false;
-                } catch (NumberFormatException e) {
-                    LOG.trace("Exception thrown in parsing the integers.", e);
+        LOG.debug("Fetching neighbor status' from BGP, #of neighbors: {}", nbrList.size());
+        for (Neighbors nbr : nbrList) {
+            boolean alarmToRaise = false;
+            try {
+                LOG.trace("nbr {} checking status, AS num: {}", nbr.getAddress().getValue(), nbr.getRemoteAs());
+                bgpMgr.getPeerStatus(nbr.getAddress().getValue(), nbr.getRemoteAs().longValue());
+                LOG.trace("nbr {} status is: PEER UP", nbr.getAddress().getValue());
+            } catch (BgpRouterException bre) {
+                if (bre.getErrorCode() == BgpRouterException.BGP_PEER_DOWN) {
+                    LOG.error("nbr {} status is: DOWN", nbr.getAddress().getValue());
+                    alarmToRaise = true;
+                } else if (bre.getErrorCode() == BgpRouterException.BGP_PEER_NOTCONFIGURED) {
+                    LOG.info("nbr {} status is: NOT CONFIGURED", nbr.getAddress().getValue());
+                } else if (bre.getErrorCode() == BgpRouterException.BGP_PEER_UNKNOWN) {
+                    LOG.info("nbr {} status is: Unknown", nbr.getAddress().getValue());
+                } else {
+                    LOG.info("nbr {} status is: Unknown, invalid BgpRouterException: ",
+                        nbr.getAddress().getValue(), bre);
                 }
+            } catch (TException tae) {
+                LOG.error("nbr {} status is: Unknown, received TException: ", nbr.getAddress().getValue(), tae);
+            }
 
-                final BgpAlarmStatus alarmStatus = neighborsRaisedAlarmStatusMap.get(nbr.getAddress().getValue());
-                if (alarmToRaise) {
-                    if (alarmStatus == null || alarmStatus != BgpAlarmStatus.RAISED) {
-                        LOG.trace("alarm raised for {}.", nbr.getAddress().getValue());
-                        raiseBgpNbrDownAlarm(nbr.getAddress().getValue());
-                    } else {
-                        LOG.trace("alarm raised already for {}", nbr.getAddress().getValue());
-                    }
+            final BgpAlarmStatus alarmStatus = neighborsRaisedAlarmStatusMap.get(nbr.getAddress().getValue());
+            if (alarmToRaise) {
+                if (alarmStatus == null || alarmStatus != BgpAlarmStatus.RAISED) {
+                    LOG.trace("alarm raised for {}.", nbr.getAddress().getValue());
+                    raiseBgpNbrDownAlarm(nbr.getAddress().getValue());
+                } else {
+                    LOG.trace("alarm raised already for {}", nbr.getAddress().getValue());
+                }
+            } else {
+                if (alarmStatus == null || alarmStatus != BgpAlarmStatus.CLEARED) {
+                    clearBgpNbrDownAlarm(nbr.getAddress().getValue());
+                    LOG.trace("alarm cleared for {}", nbr.getAddress().getValue());
                 } else {
-                    if (alarmStatus == null || alarmStatus != BgpAlarmStatus.CLEARED) {
-                        clearBgpNbrDownAlarm(nbr.getAddress().getValue());
-                        LOG.trace("alarm cleared for {}", nbr.getAddress().getValue());
-                    } else {
-                        LOG.trace("alarm cleared already for {}", nbr.getAddress().getValue());
-                    }
+                    LOG.trace("alarm cleared already for {}", nbr.getAddress().getValue());
                 }
             }
         }
     }
 
+
     private void raiseBgpNbrDownAlarm(String nbrIp) {
 
         StringBuilder source = new StringBuilder();