Guard against torn down peer 68/80768/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 11 Mar 2019 10:04:32 +0000 (11:04 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 11 Mar 2019 13:24:48 +0000 (14:24 +0100)
When we fail to look up peer we should not be throwing a NPE, as we
will end up with inconsistent TransactionChain.

Change-Id: Ia662d4fcb777cce5323fbad820466c9350ec039b
JIRA: BGPCEP-863
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit e2130f0896f4b88129af90c14d29ae7b41903837)

bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/BGPRouteEntryExportParametersImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AbstractPeer.java

index 21ee2cd790fc3ed82706a7655c1f6575f4b941f0..a1c31992f0b2eb70da32061dea36d08fb501278f 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.bgp.mode.impl;
 
+import static java.util.Objects.requireNonNull;
+
 import java.util.List;
 import org.opendaylight.protocol.bgp.rib.spi.Peer;
 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
@@ -26,8 +28,8 @@ public final class BGPRouteEntryExportParametersImpl implements BGPRouteEntryExp
 
     public BGPRouteEntryExportParametersImpl(final Peer fromPeer, final Peer toPeer,
             final String routeKey, final RTCCache rtCache) {
-        this.fromPeer = fromPeer;
-        this.toPeer = toPeer;
+        this.fromPeer = requireNonNull(fromPeer);
+        this.toPeer = requireNonNull(toPeer);
         this.routeKey = routeKey;
         this.rtCache = rtCache;
     }
index 7df17d0d973146b150444758cb813d70d94a16fe..61586fc093ed013f4c98fca65093db62a67aaca6 100644 (file)
@@ -37,8 +37,8 @@ import org.opendaylight.protocol.bgp.rib.spi.Peer;
 import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
 import org.opendaylight.protocol.bgp.rib.spi.entry.ActualBestPathRoutes;
 import org.opendaylight.protocol.bgp.rib.spi.entry.AdvertizedRoute;
-import org.opendaylight.protocol.bgp.rib.spi.entry.RouteKeyIdentifier;
 import org.opendaylight.protocol.bgp.rib.spi.entry.RouteEntryDependenciesContainer;
+import org.opendaylight.protocol.bgp.rib.spi.entry.RouteKeyIdentifier;
 import org.opendaylight.protocol.bgp.rib.spi.entry.StaleBestPathRoute;
 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRibRoutingPolicy;
 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
@@ -224,7 +224,7 @@ abstract class AbstractPeer extends BGPPeerStateImpl implements BGPRouteEntryImp
             R extends Route & ChildOf<? super S> & Identifiable<I>,
             I extends Identifier<R>> void initializeRibOut(
             final RouteEntryDependenciesContainer entryDep,
-            List<ActualBestPathRoutes<C, S, R, I>> routesToStore) {
+            final List<ActualBestPathRoutes<C, S, R, I>> routesToStore) {
         if (this.bindingChain == null) {
             LOG.debug("Session closed, skip changes to peer AdjRibsOut {}", getPeerId());
             return;
@@ -238,7 +238,7 @@ abstract class AbstractPeer extends BGPPeerStateImpl implements BGPRouteEntryImp
         for(final ActualBestPathRoutes<C,S,R,I> initializingRoute :routesToStore) {
             final PeerId fromPeerId = initializingRoute.getFromPeerId();
             final Peer fromPeer = entryDep.getPeerTracker().getPeer(fromPeerId);
-            if (!filterRoutes(fromPeerId, ribSupport.getTablesKey())) {
+            if (fromPeer == null || !filterRoutes(fromPeerId, ribSupport.getTablesKey())) {
                 continue;
             }
             final R route = initializingRoute.getRoute();
@@ -272,7 +272,7 @@ abstract class AbstractPeer extends BGPPeerStateImpl implements BGPRouteEntryImp
     public final synchronized <C extends Routes & DataObject & ChoiceIn<Tables>, S extends ChildOf<? super C>,
             R extends Route & ChildOf<? super S> & Identifiable<I>,
             I extends Identifier<R>> void refreshRibOut(final RouteEntryDependenciesContainer entryDep,
-            final List<StaleBestPathRoute<C, S, R, I>> staleRoutes, List<AdvertizedRoute<C, S, R, I>> newRoutes) {
+            final List<StaleBestPathRoute<C, S, R, I>> staleRoutes, final List<AdvertizedRoute<C, S, R, I>> newRoutes) {
         if (this.bindingChain == null) {
             LOG.debug("Session closed, skip changes to peer AdjRibsOut {}", getPeerId());
             return;
@@ -297,11 +297,12 @@ abstract class AbstractPeer extends BGPPeerStateImpl implements BGPRouteEntryImp
         }, MoreExecutors.directExecutor());
     }
 
+    @Override
     public final synchronized <C extends Routes & DataObject & ChoiceIn<Tables>, S extends ChildOf<? super C>,
             R extends Route & ChildOf<? super S> & Identifiable<I>,
             I extends Identifier<R>> void reEvaluateAdvertizement(
             final RouteEntryDependenciesContainer entryDep,
-            List<ActualBestPathRoutes<C, S, R, I>> routesToStore) {
+            final List<ActualBestPathRoutes<C, S, R, I>> routesToStore) {
         if (this.bindingChain == null) {
             LOG.debug("Session closed, skip changes to peer AdjRibsOut {}", getPeerId());
             return;
@@ -368,7 +369,7 @@ abstract class AbstractPeer extends BGPPeerStateImpl implements BGPRouteEntryImp
 
         for (final AdvertizedRoute<C,S,R,I> advRoute:routes) {
             final PeerId fromPeerId = advRoute.getFromPeerId();
-            if (!filterRoutes(fromPeerId, tk) || (!advRoute.isFirstBestPath() && !addPathSupported)) {
+            if (!filterRoutes(fromPeerId, tk) || !advRoute.isFirstBestPath() && !addPathSupported) {
                 continue;
             }
             final R route = advRoute.getRoute();