Get rid of JSR305 annotations
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / state / BGPPeerStateImpl.java
index 682e09fcc73f5bf825e62ed2405c34c43b839695..66743f7ccb4437b4e69fd1eea58eccec652fe2ae 100644 (file)
@@ -5,12 +5,10 @@
  * 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.impl.state;
 
 import static java.util.Objects.requireNonNull;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableSet;
 import java.util.Collections;
 import java.util.HashMap;
@@ -19,9 +17,9 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.atomic.LongAdder;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import javax.annotation.concurrent.GuardedBy;
+import org.checkerframework.checker.lock.qual.GuardedBy;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.protocol.bgp.rib.DefaultRibReference;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPMessagesListener;
 import org.opendaylight.protocol.bgp.rib.impl.state.peer.PrefixesInstalledCounters;
@@ -30,31 +28,38 @@ 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;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.operational.rev151009.BgpAfiSafiGracefulRestartState.Mode;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Notify;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.Rib;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.RibKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Notify;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Update;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.Rib;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.RibKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
 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();
     private final LongAdder notificationReceivedCounter = new LongAdder();
     private final LongAdder erroneousUpdate = new LongAdder();
     private final String groupId;
+    @GuardedBy("this")
+    private boolean active;
 
     @GuardedBy("this")
     private final Map<TablesKey, PrefixesSentCounters> prefixesSent = new HashMap<>();
@@ -69,15 +74,17 @@ public abstract class BGPPeerStateImpl extends DefaultRibReference implements BG
     @GuardedBy("this")
     private boolean peerRestarting;
 
-    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) {
+    public BGPPeerStateImpl(final @NonNull KeyedInstanceIdentifier<Rib, RibKey> instanceIdentifier,
+            final @Nullable String groupId, final @NonNull IpAddress neighborAddress,
+            final @NonNull Set<TablesKey> afiSafisAdvertized,
+            final @NonNull Set<TablesKey> afiSafisGracefulAdvertized,
+            final @NonNull 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
@@ -110,8 +117,8 @@ public abstract class BGPPeerStateImpl extends DefaultRibReference implements BG
 
     @Override
     public final synchronized boolean isAfiSafiSupported(final TablesKey tablesKey) {
-        return this.prefixesReceived != null && this.prefixesReceived.isSupported(tablesKey) &&
-            this.afiSafisAdvertized.contains(tablesKey);
+        return this.prefixesReceived != null && this.prefixesReceived.isSupported(tablesKey)
+                && this.afiSafisAdvertized.contains(tablesKey);
     }
 
     @Override
@@ -123,7 +130,7 @@ public abstract class BGPPeerStateImpl extends DefaultRibReference implements BG
     }
 
     @Override
-    public final synchronized long getPrefixesSentCount(@Nonnull final TablesKey tablesKey) {
+    public final synchronized long getPrefixesSentCount(final TablesKey tablesKey) {
         if (this.prefixesSent == null) {
             return 0;
         }
@@ -180,15 +187,15 @@ public abstract class BGPPeerStateImpl extends DefaultRibReference implements BG
         return this.peerRestarting;
     }
 
-    //FIXME BUG-196
-    public final void setAfiSafiGracefulRestartState(final int peerRestartTime, final boolean peerRestarting,
-        final boolean localRestarting) {
-        this.peerRestartTime = peerRestartTime;
-        this.peerRestarting = peerRestarting;
-        this.localRestarting = localRestarting;
+    public final synchronized void setAfiSafiGracefulRestartState(final int newPeerRestartTime,
+            final boolean newPeerRestarting, final boolean newLocalRestarting) {
+        this.peerRestartTime = newPeerRestartTime;
+        this.peerRestarting = newPeerRestarting;
+        this.localRestarting = newLocalRestarting;
     }
 
     protected final synchronized void setAdvertizedGracefulRestartTableTypes(final List<TablesKey> receivedGraceful) {
+        this.afiSafisGracefulReceived.clear();
         this.afiSafisGracefulReceived.addAll(receivedGraceful);
     }
 
@@ -197,10 +204,11 @@ public abstract class BGPPeerStateImpl extends DefaultRibReference implements BG
         this.prefixesSent.put(tablesKey, prefixesSentCounter);
     }
 
-    protected final synchronized void registerPrefixesCounters(@Nonnull final PrefixesReceivedCounters prefixesReceived,
-        @Nonnull final PrefixesInstalledCounters prefixesInstalled) {
-        this.prefixesReceived = prefixesReceived;
-        this.prefixesInstalled = prefixesInstalled;
+    protected final synchronized void registerPrefixesCounters(
+            final @NonNull PrefixesReceivedCounters newPrefixesReceived,
+            final @NonNull PrefixesInstalledCounters newPrefixesInstalled) {
+        this.prefixesReceived = newPrefixesReceived;
+        this.prefixesInstalled = newPrefixesInstalled;
     }
 
     protected final synchronized void resetState() {
@@ -209,6 +217,14 @@ public abstract class BGPPeerStateImpl extends DefaultRibReference implements BG
         this.peerRestarting = false;
     }
 
+    protected final synchronized void setRestartingState() {
+        this.peerRestarting = true;
+    }
+
+    protected final synchronized void setLocalRestartingState(final boolean restarting) {
+        this.localRestarting = restarting;
+    }
+
     @Override
     public final BGPPeerState getPeerState() {
         return this;
@@ -257,4 +273,49 @@ public abstract class BGPPeerStateImpl extends DefaultRibReference implements BG
             this.updateReceivedCounter.increment();
         }
     }
+
+    @Override
+    public final synchronized boolean isActive() {
+        return this.active;
+    }
+
+    protected final synchronized void setActive(final boolean active) {
+        this.active = active;
+    }
+
+    @Override
+    public final synchronized Mode getMode() {
+        if (this.afiSafisGracefulAdvertized.isEmpty()) {
+            return Mode.HELPERONLY;
+        }
+        if (this.afiSafisGracefulReceived.isEmpty()) {
+            return Mode.REMOTEHELPER;
+        }
+        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(final 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);
+    }
 }