BUG-2109 : remove also sessionId when bgp session is closed 61/12161/1
authorDana Kutenicsova <dkutenic@cisco.com>
Tue, 21 Oct 2014 14:38:13 +0000 (16:38 +0200)
committerDana Kutenicsova <dkutenic@cisco.com>
Tue, 21 Oct 2014 15:21:29 +0000 (17:21 +0200)
Change-Id: I8f086b35ac3f75d9da04de37c0d88e465822077b
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
bgp/rib-impl/src/main/java/org/opendaylight/controller/config/yang/bgp/rib/impl/StrictBgpPeerRegistryModule.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AbstractBGPSessionNegotiator.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/StrictBGPPeerRegistry.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/spi/BGPPeerRegistry.java
bgp/testtool/src/test/java/org/opendaylight/protocol/bgp/testtool/BGPSpeakerMock.java

index 593ceff220a289bda696b75bb5d277e0c81e236e..928243a388502cd6ba31c78906149c4862053df3 100644 (file)
@@ -1,7 +1,6 @@
 package org.opendaylight.controller.config.yang.bgp.rib.impl;
 
 import com.google.common.base.Objects;
-
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.rib.impl.StrictBGPPeerRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
@@ -46,27 +45,32 @@ public class StrictBgpPeerRegistryModule extends org.opendaylight.controller.con
 
         @Override
         public BGPSessionPreferences getPeerPreferences(final IpAddress ip) {
-            return global.getPeerPreferences(ip);
+            return this.global.getPeerPreferences(ip);
         }
 
         @Override
         public BGPSessionListener getPeer(final IpAddress ip, final Ipv4Address sourceId, final Ipv4Address remoteId) throws BGPDocumentedException {
-            return global.getPeer(ip, sourceId, remoteId);
+            return this.global.getPeer(ip, sourceId, remoteId);
         }
 
         @Override
         public boolean isPeerConfigured(final IpAddress ip) {
-            return global.isPeerConfigured(ip);
+            return this.global.isPeerConfigured(ip);
         }
 
         @Override
         public void removePeer(final IpAddress ip) {
-            global.removePeer(ip);
+            this.global.removePeer(ip);
+        }
+
+        @Override
+        public void removePeerSession(final IpAddress ip) {
+            this.global.removePeerSession(ip);
         }
 
         @Override
         public void addPeer(final IpAddress ip, final ReusableBGPPeer peer, final BGPSessionPreferences preferences) {
-            global.addPeer(ip, peer, preferences);
+            this.global.addPeer(ip, peer, preferences);
         }
 
         @Override
@@ -77,9 +81,8 @@ public class StrictBgpPeerRegistryModule extends org.opendaylight.controller.con
         @Override
         public String toString() {
             return Objects.toStringHelper(this)
-                    .add("peers", global)
+                    .add("peers", this.global)
                     .toString();
         }
     }
-
 }
index b6f459e641aa22dc0330797b364fcde50d07a8d7..86d1faaa7d2b12d5331d0e9a066498f820147a3a 100644 (file)
@@ -199,6 +199,7 @@ public abstract class AbstractBGPSessionNegotiator extends AbstractSessionNegoti
             // deliver the message, this method gets called with different exception (definitely not with BGPDocumentedException).
             this.sendMessage(buildErrorNotify(((BGPDocumentedException)e).getError()));
         }
+        this.registry.removePeerSession(getRemoteIp());
         super.negotiationFailed(e);
         this.state = State.Finished;
     }
index eded3494a9d97410f694d5120c0dad19e29a33ea..47d5066d8cf3cbc057ad9cb3150e2a21fca33fa7 100644 (file)
@@ -12,17 +12,14 @@ import com.google.common.base.CharMatcher;
 import com.google.common.base.Objects;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Maps;
-
 import java.net.Inet4Address;
 import java.net.Inet6Address;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
 import java.util.Map;
-
 import javax.annotation.concurrent.GuardedBy;
 import javax.annotation.concurrent.ThreadSafe;
-
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPError;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
@@ -71,6 +68,11 @@ public final class StrictBGPPeerRegistry implements BGPPeerRegistry {
         this.peers.remove(ip);
     }
 
+    public synchronized void removePeerSession(final IpAddress ip) {
+        Preconditions.checkNotNull(ip);
+        this.sessionIds.remove(ip);
+    }
+
     @Override
     public boolean isPeerConfigured(final IpAddress ip) {
         Preconditions.checkNotNull(ip);
index 41407b8adffee158f7720f1231c0610dbbceb19b..fad64a23e60273a36c9f69a222ed9bc85a1ed8d7 100644 (file)
@@ -35,6 +35,13 @@ public interface BGPPeerRegistry extends AutoCloseable {
      */
     void removePeer(IpAddress ip);
 
+    /**
+     * Remove peer session from registry.
+     *
+     * @param ip address of remote peer
+     */
+    void removePeerSession(IpAddress ip);
+
     /**
      * Check whether peer on provided IP address is present in this registry.
      *
index cca1ac755f184dfb1b903580ab134aab7347cd45..e5b9d9ae9c0d6fb3fef68d0dd9384e7e57d52e32 100644 (file)
@@ -8,17 +8,14 @@
 package org.opendaylight.protocol.bgp.testtool;
 
 import com.google.common.base.Preconditions;
-
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.util.concurrent.DefaultPromise;
 import io.netty.util.concurrent.GlobalEventExecutor;
 import io.netty.util.concurrent.Promise;
-
 import java.net.InetSocketAddress;
 import java.util.HashMap;
 import java.util.Map;
-
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.rib.impl.BGPHandlerFactory;
@@ -102,6 +99,9 @@ public class BGPSpeakerMock<M, S extends ProtocolSession<M>, L extends SessionLi
             public void close() throws Exception {
 
             }
+
+            @Override
+            public void removePeerSession(final IpAddress ip) {}
         };
 
         final SessionNegotiatorFactory<Notification, BGPSessionImpl, BGPSessionListener> snf = new BGPServerSessionNegotiatorFactory(new BGPSessionValidator() {