add interface for LLGR state 43/78743/11
authorMatej Perina <matej.perina@pantheon.tech>
Thu, 13 Dec 2018 09:12:44 +0000 (10:12 +0100)
committerMatej Perina <matej.perina@pantheon.tech>
Fri, 14 Dec 2018 11:48:03 +0000 (12:48 +0100)
This implements dedicated interface for LLGR state.

JIRA: BGPCEP-495
Change-Id: I54597dd6461dfed4ea655213d406d8ed8cbb5bfb
Signed-off-by: Matej Perina <matej.perina@pantheon.tech>
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AbstractPeer.java
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/state/BGPPeerStateImpl.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/state/BGPAfiSafiState.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/state/BGPLlGracelfulRestartState.java [new file with mode: 0644]

index f79b95f21ccd479649043fc0f6b9daf741d02bcd..e46e4e94bc4cc8f17415f09657bd6f75ff703ae0 100644 (file)
@@ -11,7 +11,9 @@ import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.MoreExecutors;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
@@ -92,8 +94,10 @@ abstract class AbstractPeer extends BGPPeerStateImpl implements BGPRouteEntryImp
             @Nullable final AsNumber localAs,
             final IpAddress neighborAddress,
             final Set<TablesKey> afiSafisAdvertized,
-            final Set<TablesKey> afiSafisGracefulAdvertized) {
-        super(rib.getInstanceIdentifier(), groupId, neighborAddress, afiSafisAdvertized, afiSafisGracefulAdvertized);
+            final Set<TablesKey> afiSafisGracefulAdvertized,
+            final Map<TablesKey, Integer> afiSafisLlGracefulAdvertized) {
+        super(rib.getInstanceIdentifier(), groupId, neighborAddress, afiSafisAdvertized, afiSafisGracefulAdvertized,
+                afiSafisLlGracefulAdvertized);
         this.name = peerName;
         this.peerRole = role;
         this.clusterId = clusterId;
@@ -110,7 +114,7 @@ abstract class AbstractPeer extends BGPPeerStateImpl implements BGPRouteEntryImp
             final IpAddress neighborAddress,
             final Set<TablesKey> afiSafisGracefulAdvertized) {
         this(rib, peerName, groupId, role, null, null, neighborAddress,
-                rib.getLocalTablesKeys(), afiSafisGracefulAdvertized);
+                rib.getLocalTablesKeys(), afiSafisGracefulAdvertized, Collections.emptyMap());
     }
 
     final synchronized FluentFuture<? extends CommitInfo> removePeer(@Nullable final YangInstanceIdentifier peerPath) {
index 695ae4e0e477a8e1dddb58d9db97d784a0121d33..b46c4385ed013893d6f6122935143cf8a1267c8b 100644 (file)
@@ -160,7 +160,7 @@ public class BGPPeer extends AbstractPeer implements BGPSessionListener {
             final Set<TablesKey> afiSafisGracefulAdvertized,
             final BgpPeer bgpPeer) {
         super(rib, Ipv4Util.toStringIP(neighborAddress), peerGroupName, role, clusterId,
-                localAs, neighborAddress, afiSafisAdvertized, afiSafisGracefulAdvertized);
+                localAs, neighborAddress, afiSafisAdvertized, afiSafisGracefulAdvertized, Collections.emptyMap());
         this.tableTypeRegistry = requireNonNull(tableTypeRegistry);
         this.rib = requireNonNull(rib);
         this.rpcRegistry = rpcRegistry;
index 485e40af47017f3ea41d7223e2fde79c59239059..cbfcc173150b3b4e35bacd9221c1cf9e8670b7e6 100644 (file)
@@ -29,6 +29,7 @@ import org.opendaylight.protocol.bgp.rib.impl.state.peer.PrefixesSentCounters;
 import org.opendaylight.protocol.bgp.rib.spi.state.BGPAfiSafiState;
 import org.opendaylight.protocol.bgp.rib.spi.state.BGPErrorHandlingState;
 import org.opendaylight.protocol.bgp.rib.spi.state.BGPGracelfulRestartState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPLlGracelfulRestartState;
 import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerMessagesState;
 import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerState;
 import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerStateConsumer;
@@ -43,12 +44,15 @@ import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.Notification;
 
 public abstract class BGPPeerStateImpl extends DefaultRibReference implements BGPPeerState, BGPAfiSafiState,
-    BGPGracelfulRestartState, BGPErrorHandlingState, BGPPeerMessagesState, BGPPeerStateConsumer, BGPMessagesListener {
+        BGPGracelfulRestartState, BGPLlGracelfulRestartState,BGPErrorHandlingState, BGPPeerMessagesState,
+        BGPPeerStateConsumer, BGPMessagesListener {
     private static final long NONE = 0L;
     private final IpAddress neighborAddress;
     private final Set<TablesKey> afiSafisAdvertized;
     private final Set<TablesKey> afiSafisGracefulAdvertized;
     private final Set<TablesKey> afiSafisGracefulReceived = new HashSet<>();
+    private final Map<TablesKey, Integer> afiSafisLlGracefulAdvertised;
+    private final Map<TablesKey, Integer> afiSafisLlGracefulReceived = new HashMap<>();
     private final LongAdder updateSentCounter = new LongAdder();
     private final LongAdder notificationSentCounter = new LongAdder();
     private final LongAdder updateReceivedCounter = new LongAdder();
@@ -74,12 +78,14 @@ public abstract class BGPPeerStateImpl extends DefaultRibReference implements BG
     public BGPPeerStateImpl(@Nonnull final KeyedInstanceIdentifier<Rib, RibKey> instanceIdentifier,
         @Nullable final String groupId, @Nonnull final IpAddress neighborAddress,
         @Nonnull final Set<TablesKey> afiSafisAdvertized,
-        @Nonnull final Set<TablesKey> afiSafisGracefulAdvertized) {
+        @Nonnull final Set<TablesKey> afiSafisGracefulAdvertized,
+        @Nonnull final Map<TablesKey, Integer> afiSafisLlGracefulAdvertized) {
         super(instanceIdentifier);
         this.neighborAddress = requireNonNull(neighborAddress);
         this.groupId = groupId;
         this.afiSafisAdvertized = requireNonNull(afiSafisAdvertized);
         this.afiSafisGracefulAdvertized = requireNonNull(afiSafisGracefulAdvertized);
+        this.afiSafisLlGracefulAdvertised = requireNonNull(afiSafisLlGracefulAdvertized);
     }
 
     @Override
@@ -287,4 +293,29 @@ public abstract class BGPPeerStateImpl extends DefaultRibReference implements BG
         }
         return Mode.BILATERAL;
     }
+
+    public final synchronized void setAdvertizedLlGracefulRestartTableTypes(
+            final Map<TablesKey, Integer> afiSafiReceived) {
+        this.afiSafisLlGracefulReceived.clear();
+        this.afiSafisLlGracefulReceived.putAll(afiSafiReceived);
+    }
+
+    @Override
+    public final synchronized boolean isLlGracefulRestartAdvertised(final TablesKey tablesKey) {
+        return this.afiSafisLlGracefulAdvertised.containsKey(tablesKey);
+    }
+
+    @Override
+    public final synchronized boolean isLlGracefulRestartReceived(final TablesKey tablesKey) {
+        return this.afiSafisLlGracefulReceived.containsKey(tablesKey);
+    }
+
+    @Override
+    public final synchronized int getLlGracefulRestartTimer(@Nonnull TablesKey tablesKey) {
+        final int timerAdvertised = isLlGracefulRestartAdvertised(tablesKey) ?
+                this.afiSafisLlGracefulAdvertised.get(tablesKey) : 0;
+        final int timerReceived = isLlGracefulRestartReceived(tablesKey) ?
+                this.afiSafisLlGracefulReceived.get(tablesKey) : 0;
+        return Integer.min(timerAdvertised, timerReceived);
+    }
 }
index e5bbff973fc1978708dbb210c2fdfe33348e338c..4b6b3130672a09d358170a5be3677b0d1875666e 100644 (file)
@@ -15,7 +15,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.
 /**
  * BGP Operational Afi SafiS State.
  */
-public interface BGPAfiSafiState extends BGPGracelfulRestartState {
+public interface BGPAfiSafiState extends BGPLlGracelfulRestartState {
     /**
      * is AfiSafi Supported.
      *
diff --git a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/state/BGPLlGracelfulRestartState.java b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/state/BGPLlGracelfulRestartState.java
new file mode 100644 (file)
index 0000000..93c0f29
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.rib.spi.state;
+
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
+
+/**
+ * BGP Operational Graceful Restart State.
+ */
+public interface BGPLlGracelfulRestartState extends BGPGracelfulRestartState {
+    /**
+     * is Long-lived Graceful Restart Support advertised to neighbor.
+     *
+     * @param tablesKey tables Key
+     * @return true if Afi Safi was advertised to neighbor
+     */
+    boolean isLlGracefulRestartAdvertised(@Nonnull TablesKey tablesKey);
+
+    /**
+     * is Long-lived Graceful Restart Support advertised by neighbor.
+     *
+     * @param tablesKey tables Key
+     * @return true if Afi Safi was advertised by neighbor
+     */
+    boolean isLlGracefulRestartReceived(@Nonnull TablesKey tablesKey);
+
+    /**
+     * If table is both advertised and received return timer with lower value.
+     * If table is not advertised or received return zero.
+     *
+     * @param tablesKey tables key
+     * @return effective value of timer in seconds
+     */
+    int getLlGracefulRestartTimer(@Nonnull TablesKey tablesKey);
+}