Update keepalive tracking 64/82964/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 7 May 2019 16:40:51 +0000 (18:40 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 8 Jul 2019 14:40:48 +0000 (16:40 +0200)
We should not be scheduling keepalives too aggressively after we
have exceeded the deadline. Also add some debugs to show when
keepalives are triggered.

Change-Id: I916a9d7f937dc6b062742b2726f4d906d91774ed
JIRA: BGPCEP-872
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 05d747c1b38c5c5e7f5dd0a865e2e144fb5471ce)

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

index 68ab5da2aed60ce48eebf88b25a887776fb119bf..d44eafdedb04bd6ef52256684ab383685b13166c 100644 (file)
@@ -424,13 +424,23 @@ public class BGPSessionImpl extends SimpleChannelInboundHandler<Notification> im
         }
 
         final long ct = System.nanoTime();
-        long nextKeepalive = this.lastMessageSentAt + TimeUnit.SECONDS.toNanos(this.keepAlive);
+        final long keepNanos = TimeUnit.SECONDS.toNanos(this.keepAlive);
+        long nextKeepalive = this.lastMessageSentAt + keepNanos;
 
         if (ct >= nextKeepalive) {
-            this.writeAndFlush(KEEP_ALIVE);
-            nextKeepalive = this.lastMessageSentAt + TimeUnit.SECONDS.toNanos(this.keepAlive);
+            final ChannelFuture future = this.writeAndFlush(KEEP_ALIVE);
+            LOG.debug("Enqueued session {} keepalive as {}", this, future);
+            nextKeepalive = ct + keepNanos;
+            if (LOG.isDebugEnabled()) {
+                future.addListener(compl -> LOG.debug("Session {} keepalive completed as {}", this, compl));
+            }
+        } else {
+            LOG.debug("Skipping keepalive on session {}", this);
         }
-        this.channel.eventLoop().schedule(this::handleKeepaliveTimer, nextKeepalive - ct, TimeUnit.NANOSECONDS);
+
+        final long nextNanos = nextKeepalive - ct;
+        LOG.debug("Scheduling next keepalive on {} in {} nanos", this, nextNanos);
+        this.channel.eventLoop().schedule(this::handleKeepaliveTimer, nextNanos, TimeUnit.NANOSECONDS);
     }
 
     @Override