BGPCEP-754: Introduce BGPPeerTracker interfaces 82/68882/3
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Wed, 17 Jan 2018 16:05:58 +0000 (17:05 +0100)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Wed, 17 Jan 2018 16:05:58 +0000 (17:05 +0100)
as replacement for static Export group.
Each Peer will provide information required
per rib policies for update tables.
BGPPeerTracker will just keep track of
all registered peers.

Change-Id: I08c94afab183a49c7277e30792d8344b87064d8a
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/ApplicationPeer.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/RIBImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/RibImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/spi/RIB.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/SynchronizationAndExceptionTest.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/BGPPeerTracker.java [new file with mode: 0644]
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/Peer.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/PeerTrackerInformation.java [new file with mode: 0644]
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/RouterIds.java

index 9069a655af37bf9f964761d1007ae1080f876cb3..9c636d9f6647cdc52e9aa8f3ce0cdb4231abd13a 100644 (file)
@@ -43,6 +43,7 @@ import org.opendaylight.protocol.bgp.rib.spi.state.BGPTimersState;
 import org.opendaylight.protocol.bgp.rib.spi.state.BGPTransportState;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.SendReceive;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.ApplicationRibId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole;
@@ -92,6 +93,7 @@ public class ApplicationPeer extends BGPPeerStateImpl implements org.opendayligh
     private ListenerRegistration<ApplicationPeer> registration;
     private final Set<NodeIdentifierWithPredicates> supportedTables = new HashSet<>();
     private final BGPSessionStateImpl bgpSessionState = new BGPSessionStateImpl();
+    private PeerId peerId;
 
     @FunctionalInterface
     interface RegisterAppPeerListener {
@@ -107,8 +109,8 @@ public class ApplicationPeer extends BGPPeerStateImpl implements org.opendayligh
         this.name = applicationRibId.getValue();
         final RIB targetRib = requireNonNull(rib);
         this.rawIdentifier = InetAddresses.forString(ipAddress.getValue()).getAddress();
-        final NodeIdentifierWithPredicates peerId = IdentifierUtils.domPeerId(RouterIds.createPeerId(ipAddress));
-        this.peerIId = targetRib.getYangRibId().node(Peer.QNAME).node(peerId);
+        final NodeIdentifierWithPredicates peerIId = IdentifierUtils.domPeerId(RouterIds.createPeerId(ipAddress));
+        this.peerIId = targetRib.getYangRibId().node(Peer.QNAME).node(peerIId);
         this.adjRibsInId = this.peerIId.node(AdjRibIn.QNAME).node(Tables.QNAME);
         this.rib = targetRib;
         this.ipAddress = ipAddress;
@@ -121,12 +123,12 @@ public class ApplicationPeer extends BGPPeerStateImpl implements org.opendayligh
         this.writerChain = this.rib.createPeerChain(this);
 
         final Optional<SimpleRoutingPolicy> simpleRoutingPolicy = Optional.of(SimpleRoutingPolicy.AnnounceNone);
-        final PeerId peerId = RouterIds.createPeerId(this.ipAddress);
+        this.peerId = RouterIds.createPeerId(this.ipAddress);
         final Set<TablesKey> localTables = this.rib.getLocalTablesKeys();
         localTables.forEach(tablesKey -> {
             final ExportPolicyPeerTracker exportTracker = this.rib.getExportPolicyPeerTracker(tablesKey);
             if (exportTracker != null) {
-                exportTracker.registerPeer(peerId, null, this.peerIId, PeerRole.Internal, simpleRoutingPolicy);
+                exportTracker.registerPeer(this.peerId, null, this.peerIId, PeerRole.Internal, simpleRoutingPolicy);
             }
             this.supportedTables.add(RibSupportUtils.toYangTablesKey(tablesKey));
         });
@@ -142,7 +144,7 @@ public class ApplicationPeer extends BGPPeerStateImpl implements org.opendayligh
                 }
             }
         };
-        this.adjRibInWriter = this.adjRibInWriter.transform(peerId, context, localTables, Collections.emptyMap(),
+        this.adjRibInWriter = this.adjRibInWriter.transform(this.peerId, context, localTables, Collections.emptyMap(),
                 registerAppPeerListener);
         this.effectiveRibInWriter = EffectiveRibInWriter
                 .create(this.rib.getService(), this.rib.createPeerChain(this), this.peerIId,
@@ -208,14 +210,6 @@ public class ApplicationPeer extends BGPPeerStateImpl implements org.opendayligh
         tx.submit();
     }
 
-    /**
-     * Applies modification under table routes based on modification type instead of only put. BUG 4438
-     *
-     * @param node
-     * @param identifier
-     * @param tx
-     * @param routeTableIdentifier
-     */
     private synchronized void processRoutesTable(final DataTreeCandidateNode node,
             final YangInstanceIdentifier identifier, final DOMDataWriteTransaction tx,
             final YangInstanceIdentifier routeTableIdentifier) {
@@ -288,9 +282,39 @@ public class ApplicationPeer extends BGPPeerStateImpl implements org.opendayligh
         return Arrays.copyOf(this.rawIdentifier, this.rawIdentifier.length);
     }
 
+    @Override
+    public PeerId getPeerId() {
+        return this.peerId;
+    }
+
+    @Override
+    public boolean supportsAddPathSupported(final TablesKey tableKey) {
+        return false;
+    }
+
+    @Override
+    public SendReceive getSupportedAddPathTables(final TablesKey tableKey) {
+        return null;
+    }
+
+    @Override
+    public boolean supportsTable(final TablesKey tableKey) {
+        return this.rib.supportsTable(tableKey);
+    }
+
+    @Override
+    public YangInstanceIdentifier getPeerRibInstanceIdentifier() {
+        return this.peerIId;
+    }
+
+    @Override
+    public PeerRole getRole() {
+        return PeerRole.Internal;
+    }
+
     @Override
     public void onTransactionChainFailed(final TransactionChain<?, ?> chain,
-            final AsyncTransaction<?, ?> transaction, final Throwable cause) {
+        final AsyncTransaction<?, ?> transaction, final Throwable cause) {
         LOG.error("Transaction chain {} failed.", transaction != null ? transaction.getIdentifier() : null, cause);
     }
 
index f709cbd1a679c7f664ebee1fc4ad3b705e2c29b4..d4ebeadfeafc3a43a7b9163c5056ddb6013cf784 100644 (file)
@@ -21,6 +21,7 @@ import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -28,7 +29,6 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
 import java.util.stream.Collectors;
-import javax.annotation.Nonnull;
 import javax.annotation.concurrent.GuardedBy;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
@@ -112,6 +112,8 @@ public class BGPPeer extends BGPPeerStateImpl implements BGPSessionListener, Pee
     private final Optional<SimpleRoutingPolicy> simpleRoutingPolicy;
     @GuardedBy("this")
     private final Set<AbstractRegistration> tableRegistration = new HashSet<>();
+    private final PeerId peerId;
+    private final YangInstanceIdentifier peerIId;
     @GuardedBy("this")
     private BGPSession session;
     @GuardedBy("this")
@@ -123,11 +125,12 @@ public class BGPPeer extends BGPPeerStateImpl implements BGPSessionListener, Pee
     @GuardedBy("this")
     private EffectiveRibInWriter effRibInWriter;
     private RoutedRpcRegistration<BgpPeerRpcService> rpcRegistration;
+    private Map<TablesKey, SendReceive> addPathTableMaps = Collections.emptyMap();
 
     public BGPPeer(final IpAddress neighborAddress, final RIB rib, final PeerRole role,
             final SimpleRoutingPolicy peerStatus, final RpcProviderRegistry rpcRegistry,
-            @Nonnull final Set<TablesKey> afiSafisAdvertized,
-            @Nonnull final Set<TablesKey> afiSafisGracefulAdvertized) {
+            final Set<TablesKey> afiSafisAdvertized,
+            final Set<TablesKey> afiSafisGracefulAdvertized) {
         //FIXME BUG-6971 Once Peer Group is implemented, pass it
         super(rib.getInstanceIdentifier(), null, neighborAddress, afiSafisAdvertized,
                 afiSafisGracefulAdvertized);
@@ -136,13 +139,17 @@ public class BGPPeer extends BGPPeerStateImpl implements BGPSessionListener, Pee
         this.rib = requireNonNull(rib);
         this.name = Ipv4Util.toStringIP(neighborAddress);
         this.rpcRegistry = rpcRegistry;
+        this.peerId = RouterIds.createPeerId(neighborAddress);
+        this.peerIId = this.rib.getYangRibId().node(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
+                .bgp.rib.rev171207.bgp.rib.rib.Peer.QNAME).node(IdentifierUtils.domPeerId(this.peerId));
+
         this.chain = rib.createPeerChain(this);
     }
 
     @VisibleForTesting
     BGPPeer(final IpAddress neighborAddress, final RIB rib, final PeerRole role,
-            final RpcProviderRegistry rpcRegistry, @Nonnull final Set<TablesKey> afiSafisAdvertized,
-            @Nonnull final Set<TablesKey> afiSafisGracefulAdvertized) {
+            final RpcProviderRegistry rpcRegistry, final Set<TablesKey> afiSafisAdvertized,
+            final Set<TablesKey> afiSafisGracefulAdvertized) {
         this(neighborAddress, rib, role, null, rpcRegistry, afiSafisAdvertized, afiSafisGracefulAdvertized);
     }
 
@@ -234,11 +241,11 @@ public class BGPPeer extends BGPPeerStateImpl implements BGPSessionListener, Pee
         if (msg instanceof Update) {
             onUpdateMessage((Update) msg);
         } else {
-            onRouteRefreshMessage((RouteRefresh) msg, session);
+            onRouteRefreshMessage((RouteRefresh) msg);
         }
     }
 
-    private void onRouteRefreshMessage(final RouteRefresh message, final BGPSession session) {
+    private void onRouteRefreshMessage(final RouteRefresh message) {
         final Class<? extends AddressFamily> rrAfi = message.getAfi();
         final Class<? extends SubsequentAddressFamily> rrSafi = message.getSafi();
 
@@ -247,7 +254,7 @@ public class BGPPeer extends BGPPeerStateImpl implements BGPSessionListener, Pee
         if (listener != null) {
             listener.close();
             this.adjRibOutListenerSet.remove(key);
-            createAdjRibOutListener(RouterIds.createPeerId(session.getBgpId()), key, listener.isMpSupported());
+            createAdjRibOutListener(key, listener.isMpSupported());
         } else {
             LOG.info("Ignoring RouteRefresh message. Afi/Safi is not supported: {}, {}.", rrAfi, rrSafi);
         }
@@ -280,7 +287,7 @@ public class BGPPeer extends BGPPeerStateImpl implements BGPSessionListener, Pee
 
         // update AdjRibs
         final Attributes attrs = message.getAttributes();
-        MpReachNlri mpReach = null;
+        MpReachNlri mpReach;
         final boolean isAnyNlriAnnounced = message.getNlri() != null;
         if (isAnyNlriAnnounced) {
             mpReach = prefixesToMpReach(message);
@@ -290,7 +297,7 @@ public class BGPPeer extends BGPPeerStateImpl implements BGPSessionListener, Pee
         if (mpReach != null) {
             this.ribWriter.updateRoutes(mpReach, nextHopToAttribute(attrs, mpReach));
         }
-        MpUnreachNlri mpUnreach = null;
+        MpUnreachNlri mpUnreach;
         if (message.getWithdrawnRoutes() != null) {
             mpUnreach = prefixesToMpUnreach(message, isAnyNlriAnnounced);
         } else {
@@ -307,53 +314,46 @@ public class BGPPeer extends BGPPeerStateImpl implements BGPSessionListener, Pee
         if (this.session instanceof BGPSessionStateProvider) {
             ((BGPSessionStateProvider) this.session).registerMessagesCounter(this);
         }
-
         final List<AddressFamilies> addPathTablesType = session.getAdvertisedAddPathTableTypes();
         final Set<BgpTableType> advertizedTableTypes = session.getAdvertisedTableTypes();
         final List<BgpTableType> advertizedGracefulRestartTableTypes = session.getAdvertisedGracefulRestartTableTypes();
         LOG.info("Session with peer {} went up with tables {} and Add Path tables {}", this.name,
                 advertizedTableTypes, addPathTablesType);
         this.rawIdentifier = InetAddresses.forString(session.getBgpId().getValue()).getAddress();
-        final PeerId peerId = RouterIds.createPeerId(session.getBgpId());
-
         this.tables.addAll(advertizedTableTypes.stream().map(t -> new TablesKey(t.getAfi(), t.getSafi()))
                 .collect(Collectors.toList()));
 
         setAdvertizedGracefulRestartTableTypes(advertizedGracefulRestartTableTypes.stream()
                 .map(t -> new TablesKey(t.getAfi(), t.getSafi())).collect(Collectors.toList()));
         final boolean announceNone = isAnnounceNone(this.simpleRoutingPolicy);
-        final Map<TablesKey, SendReceive> addPathTableMaps = mapTableTypesFamilies(addPathTablesType);
+        this.addPathTableMaps = mapTableTypesFamilies(addPathTablesType);
 
         if (!announceNone) {
             for (final TablesKey key : this.tables) {
-                createAdjRibOutListener(peerId, key, true);
+                createAdjRibOutListener(key, true);
             }
         }
 
-        final YangInstanceIdentifier peerIId = this.rib.getYangRibId()
-                .node(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
-                        .bgp.rib.rev171207.bgp.rib.rib.Peer.QNAME).node(IdentifierUtils.domPeerId(peerId));
-
         for(final TablesKey tablesKey :this.tables) {
             final ExportPolicyPeerTracker exportTracker = this.rib.getExportPolicyPeerTracker(tablesKey);
             if (exportTracker != null) {
-                this.tableRegistration.add(exportTracker.registerPeer(peerId, addPathTableMaps.get(tablesKey),
-                        peerIId, this.peerRole, this.simpleRoutingPolicy));
+                this.tableRegistration.add(exportTracker.registerPeer(this.peerId, this.addPathTableMaps.get(tablesKey),
+                        this.peerIId, this.peerRole, this.simpleRoutingPolicy));
             }
         }
-        addBgp4Support(peerId, peerIId, announceNone);
+        addBgp4Support(announceNone);
 
         if (!isLearnNone(this.simpleRoutingPolicy)) {
             this.effRibInWriter = EffectiveRibInWriter.create(this.rib.getService(),
                     this.rib.createPeerChain(this),
-                    peerIId, this.rib.getImportPolicyPeerTracker(),
+                    this.peerIId, this.rib.getImportPolicyPeerTracker(),
                     this.rib.getRibSupportContext(),
                     this.peerRole,
                     this.tables);
             registerPrefixesCounters(this.effRibInWriter, this.effRibInWriter);
         }
-        this.ribWriter = this.ribWriter.transform(peerId, this.rib.getRibSupportContext(), this.tables,
-                addPathTableMaps);
+        this.ribWriter = this.ribWriter.transform(this.peerId, this.rib.getRibSupportContext(), this.tables,
+                this.addPathTableMaps);
 
         if (this.rpcRegistry != null) {
             this.rpcRegistration = this.rpcRegistry.addRoutedRpcImplementation(BgpPeerRpcService.class,
@@ -361,32 +361,32 @@ public class BGPPeer extends BGPPeerStateImpl implements BGPSessionListener, Pee
             final KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib
                     .rev171207.bgp.rib.rib.Peer, PeerKey> path = this.rib.getInstanceIdentifier()
                     .child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib
-                             .rib.Peer.class, new PeerKey(peerId));
+                             .rib.Peer.class, new PeerKey(this.peerId));
             this.rpcRegistration.registerPath(PeerContext.class, path);
         }
     }
 
     //try to add a support for old-school BGP-4, if peer did not advertise IPv4-Unicast MP capability
-    private void addBgp4Support(final PeerId peerId, final YangInstanceIdentifier peerIId, final boolean announceNone) {
+    private void addBgp4Support(final boolean announceNone) {
         final TablesKey key = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
         if (this.tables.add(key) && !announceNone) {
-            createAdjRibOutListener(peerId, key, false);
+            createAdjRibOutListener(key, false);
             final ExportPolicyPeerTracker exportTracker = this.rib.getExportPolicyPeerTracker(key);
             if (exportTracker != null) {
-                this.tableRegistration.add(exportTracker.registerPeer(peerId,  null, peerIId,
+                this.tableRegistration.add(exportTracker.registerPeer(peerId,  null, this.peerIId,
                         this.peerRole, this.simpleRoutingPolicy));
             }
         }
     }
 
-    private synchronized void createAdjRibOutListener(final PeerId peerId, final TablesKey key,
+    private synchronized void createAdjRibOutListener(final TablesKey key,
             final boolean mpSupport) {
         final RIBSupportContext context = this.rib.getRibSupportContext().getRIBSupportContext(key);
 
         // not particularly nice
         if (context != null && this.session instanceof BGPSessionImpl) {
             final ChannelOutputLimiter limiter = ((BGPSessionImpl) this.session).getLimiter();
-            final AdjRibOutListener adjRibOut = AdjRibOutListener.create(peerId, key,
+            final AdjRibOutListener adjRibOut = AdjRibOutListener.create(this.peerId, key,
                     this.rib.getYangRibId(), this.rib.getCodecsRegistry(), context.getRibSupport(),
                     this.rib.getService(), limiter, mpSupport);
             this.adjRibOutListenerSet.put(key, adjRibOut);
@@ -471,6 +471,31 @@ public class BGPPeer extends BGPPeerStateImpl implements BGPSessionListener, Pee
         return Arrays.copyOf(this.rawIdentifier, this.rawIdentifier.length);
     }
 
+    @Override
+    public PeerId getPeerId() {
+        return this.peerId;
+    }
+
+    @Override
+    public SendReceive getSupportedAddPathTables(final TablesKey tableKey) {
+        return this.addPathTableMaps.get(tableKey);
+    }
+
+    @Override
+    public boolean supportsTable(final TablesKey tableKey) {
+        return this.tables.contains(tableKey);
+    }
+
+    @Override
+    public YangInstanceIdentifier getPeerRibInstanceIdentifier() {
+        return this.peerIId;
+    }
+
+    @Override
+    public PeerRole getRole() {
+        return this.peerRole;
+    }
+
     @Override
     public synchronized void onTransactionChainFailed(final TransactionChain<?, ?> chain,
             final AsyncTransaction<?, ?> transaction, final Throwable cause) {
@@ -484,7 +509,7 @@ public class BGPPeer extends BGPPeerStateImpl implements BGPSessionListener, Pee
 
     @Override
     public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
-        LOG.debug("Transaction chain {} successfull.", chain);
+        LOG.debug("Transaction chain {} successful.", chain);
     }
 
     @Override
index aa539bf87297af00c6b0cbdd4c462e139035b295..a8dbc76b631f150ccdd222d549faaea14191d862 100755 (executable)
@@ -251,6 +251,11 @@ public final class RIBImpl extends BGPRIBStateImpl implements RIB, TransactionCh
         return this.localTablesKeys;
     }
 
+    @Override
+    public boolean supportsTable(final TablesKey tableKey) {
+        return this.localTablesKeys.contains(tableKey);
+    }
+
     @Override
     public DOMDataTreeChangeService getService() {
         return (DOMDataTreeChangeService) this.service;
index 9ec418315ad2852e23bfe870792e4915169dbedf..346ac6a88ca56addb7558f74734b24cd018b5e93 100644 (file)
@@ -216,6 +216,11 @@ public final class RibImpl implements RIB, BGPRIBStateConsumer, AutoCloseable {
         return this.ribImpl.getLocalTablesKeys();
     }
 
+    @Override
+    public boolean supportsTable(final TablesKey tableKey) {
+        return this.ribImpl.supportsTable(tableKey);
+    }
+
     @Override
     public String toString() {
         return this.ribImpl != null ? this.ribImpl.toString() : "";
index 12ec357cd5cab84af9bb7bccb2bce26c11fa4cd9..19216b06e1e3bfdb5a1c8c7b171c6359d70f7a9a 100755 (executable)
@@ -99,5 +99,13 @@ public interface RIB extends AttributeBindingCodecSerializer, RibReference {
      */
     ExportPolicyPeerTracker getExportPolicyPeerTracker(TablesKey tablesKey);
 
+    /**
+     * Returns true if RIB supports table.
+     *
+     * @param tableKey table
+     * @return true if supported
+     */
+    boolean supportsTable(TablesKey tableKey);
+
     Set<TablesKey> getLocalTablesKeys();
 }
index 42aa27966cf6b27082a5726ca82ceaabdee99e6f..11fec015ae4054378fce6b171a6c97933abdd216 100644 (file)
@@ -111,7 +111,7 @@ public class SynchronizationAndExceptionTest extends AbstractAddPathTest {
     private static final YangInstanceIdentifier PEER_PATH = YangInstanceIdentifier.builder()
             .node(BgpRib.QNAME).node(Rib.QNAME)
             .nodeWithKey(Rib.QNAME, QName.create(Rib.QNAME, "id").intern(), RIB_ID)
-            .node(Peer.QNAME).nodeWithKey(Peer.QNAME, AdjRibInWriter.PEER_ID_QNAME, "bgp://1.1.1.2").build();
+            .node(Peer.QNAME).nodeWithKey(Peer.QNAME, AdjRibInWriter.PEER_ID_QNAME, "bgp://1.1.1.4").build();
     private static final YangInstanceIdentifier TABLE_PATH = PEER_PATH.node(AdjRibIn.QNAME).node(Tables.QNAME)
             .node(RibSupportUtils.toYangTablesKey(new TablesKey(Ipv4AddressFamily.class,
                     UnicastSubsequentAddressFamily.class))).node(Attributes.QNAME)
diff --git a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/BGPPeerTracker.java b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/BGPPeerTracker.java
new file mode 100644 (file)
index 0000000..cb3ba6e
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * 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;
+
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import org.opendaylight.protocol.concepts.AbstractRegistration;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+
+/**
+ * Tracks Peers under RIB.
+ */
+public interface BGPPeerTracker {
+    /**
+     * Register Peer.
+     *
+     * @param peer Peer
+     * @return registration tickets
+     */
+    AbstractRegistration registerPeer(@Nonnull Peer peer);
+
+    /**
+     * Returns Peer
+     *
+     * @param peerId peer ID
+     * @return Peer
+     */
+    @Nullable
+    Peer getPeer(@Nonnull PeerId peerId);
+
+    /**
+     * Returns if peer supports table.
+     *
+     * @param peerIdOfNewPeer PeerId
+     * @param tableKey        table
+     * @return true if Additional Path is supported for defined table
+     */
+    boolean supportsTable(@Nonnull PeerId peerIdOfNewPeer, @Nonnull TablesKey tableKey);
+
+    /**
+     * Returns map of PeerId per PeerRole.
+     * Role with none peerId will be filtered.
+     *
+     * @return Returns map of PeerId group by PeerRole
+     */
+    @Nonnull
+    Map<PeerRole, List<PeerId>> getRoles();
+
+    /**
+     * Returns if peer supports Additional Path for specific table.
+     *
+     * @param toPeer  peer ID
+     * @param localTK table
+     * @return true if Additional Path is supported for defined table
+     */
+    boolean supportsAddPathSupported(@Nonnull PeerId toPeer, @Nonnull TablesKey localTK);
+
+    /**
+     * Returns role of specific peer if present.
+     *
+     * @param peerId peer identifier
+     * @return role
+     */
+    @Nullable
+    PeerRole getRole(@Nonnull PeerId peerId);
+
+    /**
+     * Returns YangInstanceIdentifier pointing peer under specific rib.
+     *
+     * @return Peer YangInstanceIdentifier
+     */
+    @Nullable
+    YangInstanceIdentifier getPeerRibInstanceIdentifier(@Nonnull PeerId peerId);
+}
index 7ec0fbe5fabba6d2bec0b00ed3787c6cc115e096..42f2aadbd6228f1a7d4c30bf8f42d522572c1a89 100644 (file)
@@ -13,7 +13,7 @@ import javax.annotation.Nonnull;
 /**
  * Marker interface identifying a BGP peer.
  */
-public interface Peer {
+public interface Peer extends PeerTrackerInformation {
     /**
      * Return peer's symbolic name.
      *
diff --git a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/PeerTrackerInformation.java b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/PeerTrackerInformation.java
new file mode 100644 (file)
index 0000000..2825c94
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * 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;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.SendReceive;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+
+/**
+ * Exposes information required from peer to PeerTracker.
+ */
+public interface PeerTrackerInformation {
+
+    /**
+     * Returns PeerID
+     *
+     * @return PeerID
+     */
+    @Nonnull
+    PeerId getPeerId();
+
+    /**
+     * Returns if peer supports Additional Path for specific table.
+     *
+     * @param tableKey table
+     * @return true if Additional Path is supported for defined table
+     */
+    default boolean supportsAddPathSupported(@Nonnull TablesKey tableKey) {
+        final SendReceive sendReceive = getSupportedAddPathTables(tableKey);
+        return sendReceive != null && (sendReceive.equals(SendReceive.Both) || sendReceive.equals(SendReceive.Receive));
+    }
+
+    /**
+     * Returns AddPath support configuration if supported, otherwise null.
+     *
+     * @param tableKey table
+     * @return AddPath support configuration if supported, otherwise null
+     */
+    @Nullable
+    SendReceive getSupportedAddPathTables(@Nonnull TablesKey tableKey);
+
+    /**
+     * Returns if peer supports table.
+     *
+     * @param tableKey table
+     * @return true if Additional Path is supported for defined table
+     */
+    boolean supportsTable(@Nonnull TablesKey tableKey);
+
+    /**
+     * Returns YangInstanceIdentifier pointing peer under specific rib.
+     *
+     * @return Peer YangInstanceIdentifier
+     */
+    @Nullable
+    YangInstanceIdentifier getPeerRibInstanceIdentifier();
+
+    /**
+     * Returns Peer Role.
+     *
+     * @return PeerRole
+     */
+    @Nonnull
+    PeerRole getRole();
+}
index 66fb2729b757e31d302e4b5c0341dc01fe89581a..b9f01a7f16bce7a643b20ea96a19b72963b31d73 100644 (file)
@@ -14,6 +14,7 @@ import com.google.common.cache.LoadingCache;
 import com.google.common.net.InetAddresses;
 import com.google.common.primitives.UnsignedInteger;
 import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId;
 
@@ -50,10 +51,18 @@ public final class RouterIds {
     }
 
     public static UnsignedInteger routerIdForPeerId(@Nonnull final PeerId peerId) {
-        Preconditions.checkArgument(peerId.getValue().startsWith(BGP_PREFIX), "Unhandled peer ID %s", peerId);
+        Preconditions.checkArgument(peerId.getValue().startsWith(BGP_PREFIX),
+                "Unhandled peer ID %s", peerId);
         return BGP_ROUTER_IDS.getUnchecked(peerId);
     }
 
+    public static PeerId createPeerId(@Nonnull final IpAddress address) {
+        if (address.getIpv4Address() != null) {
+            return createPeerId(address.getIpv4Address());
+        }
+        return new PeerId(BGP_PREFIX + address.getIpv6Address().getValue());
+    }
+
     public static PeerId createPeerId(@Nonnull final Ipv4Address address) {
         return new PeerId(BGP_PREFIX + address.getValue());
     }