BUG-5243: Failed to send message Notify 32/34132/4
authorClaudio D. Gasparini <cgaspari@cisco.com>
Fri, 5 Feb 2016 09:20:36 +0000 (10:20 +0100)
committerMilos Fabian <milfabia@cisco.com>
Fri, 5 Feb 2016 15:36:35 +0000 (15:36 +0000)
Don't try to send Notify message if the session
has been closed externally

Change-Id: Idd57bd5bf60e4f758ed0187bd12149854740cd36
Signed-off-by: Claudio D. Gasparini <cgaspari@cisco.com>
(cherry picked from commit 14cad280a7d1ba51f72d683e689eb3b2eca96909)

bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeer.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImplTest.java

index b33657c234edca8f539f5a70da1a737fed5b3947..57d2d38ca953382ef2537c16e4986e9713c43413 100644 (file)
@@ -248,7 +248,11 @@ public class BGPPeer implements BGPSessionListener, Peer, AutoCloseable, BGPPeer
 
     @Override
     public void onSessionDown(final BGPSession session, final Exception e) {
-        LOG.info("Session with peer {} went down", this.name, e);
+        if(e.getMessage().equals(BGPSessionImpl.END_OF_INPUT)) {
+            LOG.info("Session with peer {} went down", this.name);
+        } else {
+            LOG.info("Session with peer {} went down", this.name, e);
+        }
         releaseConnection();
     }
 
index dc5aa448e2592544bc1537c66dd313b88875b72c..cfc01e536d527ee0932af30004bb2003fd24b6fe 100644 (file)
@@ -61,6 +61,8 @@ public class BGPSessionImpl extends SimpleChannelInboundHandler<Notification> im
 
     private static final int KA_TO_DEADTIMER_RATIO = 3;
 
+    static final String END_OF_INPUT = "End of input detected. Close the session.";
+
     /**
      * Internal session state.
      */
@@ -175,15 +177,11 @@ public class BGPSessionImpl extends SimpleChannelInboundHandler<Notification> im
 
     @Override
     public synchronized void close() {
-        LOG.info("Closing session: {}", this);
-
-        if (this.state != State.IDLE) {
+        if (this.state != State.IDLE && this.channel.isActive()) {
             this.writeAndFlush(new NotifyBuilder().setErrorCode(BGPError.CEASE.getCode()).setErrorSubcode(
-                    BGPError.CEASE.getSubcode()).build());
-            removePeerSession();
-            this.channel.close();
-            this.state = State.IDLE;
+                BGPError.CEASE.getSubcode()).build());
         }
+        this.closeWithoutMessage();
     }
 
     /**
@@ -225,7 +223,8 @@ public class BGPSessionImpl extends SimpleChannelInboundHandler<Notification> im
 
     public synchronized void endOfInput() {
         if (this.state == State.UP) {
-            this.listener.onSessionDown(this, new IOException("End of input detected. Close the session."));
+            LOG.info(END_OF_INPUT);
+            this.listener.onSessionDown(this, new IOException(END_OF_INPUT));
         }
     }
 
@@ -268,7 +267,7 @@ public class BGPSessionImpl extends SimpleChannelInboundHandler<Notification> im
     }
 
     private synchronized void closeWithoutMessage() {
-        LOG.debug("Closing session: {}", this);
+        LOG.info("Closing session: {}", this);
         removePeerSession();
         this.channel.close();
         this.state = State.IDLE;
index e9352b2d2c1e9ad0cc40f2826439583809ade72c..06fdec89142d8aeab18d4f5b48642295741de703 100644 (file)
@@ -120,6 +120,7 @@ public class BGPSessionImplTest {
             }
         }).when(this.speakerListener).writeAndFlush(any(Notification.class));
         doReturn(this.eventLoop).when(this.speakerListener).eventLoop();
+        doReturn(true).when(this.speakerListener).isActive();
         doAnswer(new Answer<Void>() {
             @Override
             public Void answer(final InvocationOnMock invocation) throws Throwable {