BGPCEP-754: Fix NPE and rework 10/69310/1
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Fri, 9 Mar 2018 13:02:16 +0000 (14:02 +0100)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Fri, 9 Mar 2018 13:38:46 +0000 (14:38 +0100)
- Fix npe
- Simplify PeerTracker
- Fix test name

Change-Id: I239d634a98799c73220e55cbb9b295b84576f7ec
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
12 files changed:
bgp/openconfig-rp-spi/src/main/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/spi/registry/StatementRegistry.java
bgp/openconfig-rp-spi/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/spi/AsPathLengthTest.java [moved from bgp/openconfig-rp-spi/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/spi/AsPathLength.java with 99% similarity]
bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/ExportDefaultStatementTest.java
bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/ImportDefaultStatementTest.java
bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/PrefixMatchTest.java [deleted file]
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/BGPRouteEntryExportParametersImpl.java [new file with mode: 0644]
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathAbstractRouteEntry.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseAbstractRouteEntry.java
bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/BGPPeerTrackerMock.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeerTrackerImpl.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/BGPPeerTracker.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/policy/BGPRouteEntryExportParameters.java

index 34eb75b23c267e879b923f864119c822f9588c23..fc08ddefa6b10a781f44a2a679c84104cf58a878 100644 (file)
@@ -46,10 +46,11 @@ public final class StatementRegistry implements StatementRegistryConsumer, State
             final BGPRouteEntryExportParameters routeEntryExportParameters,
             final RouteAttributeContainer attributes,
             final Statement statement) {
-        if (!this.conditionsRegistry.matchExportConditions(
+        final Attributes att = attributes.getAttributes();
+        if (att == null || !this.conditionsRegistry.matchExportConditions(
                 routeEntryInfo,
                 routeEntryExportParameters,
-                attributes.getAttributes(),
+                att,
                 statement.getConditions())) {
             return attributes;
         }
@@ -26,7 +26,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mess
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPathBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.SegmentsBuilder;
 
-public class AsPathLength extends AbstractStatementRegistryTest {
+public class AsPathLengthTest extends AbstractStatementRegistryTest {
     @Mock
     private BGPRouteEntryExportParameters exportParameters;
     private List<Statement> basicStatements;
index 9761cad4fdf6fa57f4a2e4d4c15c119ba508e69a..97286e02791650b9092097bf7ca5d7c24b53fa5a 100644 (file)
@@ -15,7 +15,6 @@ import static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.
 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.ExportAttributeTestUtil.createPathInput;
 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.ExportAttributeTestUtil.createPathInputWithAs;
 
-import com.google.common.collect.ImmutableMap;
 import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
@@ -24,16 +23,10 @@ import org.opendaylight.protocol.bgp.openconfig.routing.policy.impl.PolicyRIBBas
 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer;
 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv4.routes.ipv4.routes.Ipv4Route;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
 public class ExportDefaultStatementTest extends AbstractStatementRegistryConsumerTest {
-    private static final YangInstanceIdentifier.NodeIdentifierWithPredicates ROUTE_ID_PA
-            = new YangInstanceIdentifier.NodeIdentifierWithPredicates(Ipv4Route.QNAME,
-            ImmutableMap.of(QName.create(Ipv4Route.QNAME, "prefix").intern(), "1.2.3.4/32"));
     @Mock
     private BGPRouteEntryExportParameters exportParameters;
     private List<Statement> defaultExportStatements;
@@ -47,9 +40,6 @@ public class ExportDefaultStatementTest extends AbstractStatementRegistryConsume
         this.baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
     }
 
-    /**
-     * To eBGP.
-     */
     @Test
     public void testToEbgp() {
         final Statement statement = getStatementAndSetToRole("to-external", PeerRole.Ebgp);
@@ -63,10 +53,6 @@ public class ExportDefaultStatementTest extends AbstractStatementRegistryConsume
         assertApplyExportStatement(statement, PeerRole.RrClient, attributeContainer, expectedOutput);
     }
 
-
-    /**
-     * From iBGP To iBGP.
-     */
     @Test
     public void testFromInternalToInternal() {
         final Statement statement = getStatementAndSetToRole("from-internal-to-internal", PeerRole.Ibgp);
@@ -74,9 +60,6 @@ public class ExportDefaultStatementTest extends AbstractStatementRegistryConsume
         assertApplyExportStatement(statement, PeerRole.Ibgp, attributeContainer, null);
     }
 
-    /**
-     * From iBGP To iBGP.
-     */
     @Test
     public void testFromExternalToInternal() {
         final Statement statement = getStatementAndSetToRole("from-external-to-internal", PeerRole.Ibgp);
@@ -84,9 +67,6 @@ public class ExportDefaultStatementTest extends AbstractStatementRegistryConsume
         assertApplyExportStatement(statement, PeerRole.Ebgp, attributeContainer, attributeContainer.getAttributes());
     }
 
-    /**
-     * From Internal To iBGP.
-     */
     @Test
     public void testFromOdlInternalToInternal() {
         final Statement statement = getStatementAndSetToRole("from-odl-internal-to-internal-or-rr-client",
@@ -95,9 +75,6 @@ public class ExportDefaultStatementTest extends AbstractStatementRegistryConsume
         assertApplyExportStatement(statement, PeerRole.Internal, attributeContainer, createClusterInput());
     }
 
-    /**
-     * From RR-Client To iBGP.
-     */
     @Test
     public void testFromRRclientToInternal() {
         final Statement statement = getStatementAndSetToRole("from-rr-client-to-internal", PeerRole.Ibgp);
@@ -105,9 +82,6 @@ public class ExportDefaultStatementTest extends AbstractStatementRegistryConsume
         assertApplyExportStatement(statement, PeerRole.RrClient, attributeContainer, createInputWithOriginator());
     }
 
-    /**
-     * Any role To Internal.
-     */
     @Test
     public void testOdlInternal() {
         final Statement statement = getStatementAndSetToRole("to-odl-internal", PeerRole.Internal);
@@ -119,9 +93,6 @@ public class ExportDefaultStatementTest extends AbstractStatementRegistryConsume
         assertApplyExportStatement(statement, PeerRole.RrClient, attributeContainer, null);
     }
 
-    /**
-     * To RrClient.
-     */
     @Test
     public void testFromExternalToRRClient() {
         final Statement statement = getStatementAndSetToRole("from-external-to-route-reflector", PeerRole.RrClient);
@@ -129,9 +100,6 @@ public class ExportDefaultStatementTest extends AbstractStatementRegistryConsume
         assertApplyExportStatement(statement, PeerRole.Ebgp, attributeContainer, attributeContainer.getAttributes());
     }
 
-    /**
-     * To RrClient.
-     */
     @Test
     public void testFromInternalOrRRClientToRRClient() {
         final Statement statement = getStatementAndSetToRole("from-internal-or-rr-client-to-route-reflector",
@@ -143,11 +111,8 @@ public class ExportDefaultStatementTest extends AbstractStatementRegistryConsume
         assertApplyExportStatement(statement, PeerRole.RrClient, attributeContainer, expectedOutput);
     }
 
-    /**
-     * To RrClient.
-     */
     @Test
-    public void testFromOdlInternalRRClient() {
+    public void testFromOdlInternalToRRClient() {
         final Statement statement = getStatementAndSetToRole("from-odl-internal-to-internal-or-rr-client",
                 PeerRole.RrClient);
         final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(createClusterInput());
index d7836c26c352892470c846e9073110a246d665e6..71326b8cbdc3ebd4c3d7d9d93775de0dc89bc70f 100644 (file)
@@ -28,7 +28,6 @@ public class ImportDefaultStatementTest extends AbstractStatementRegistryConsume
     private List<Statement> defaultImportStatements;
     private PolicyRIBBaseParametersImpl baseAttributes;
 
-
     @Before
     @Override
     public void setUp() throws Exception {
@@ -37,9 +36,6 @@ public class ImportDefaultStatementTest extends AbstractStatementRegistryConsume
         this.baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
     }
 
-    /**
-     * From eBGP.
-     */
     @Test
     public void testFromEbgp() {
         final Statement statement = getStatement("from-external");
@@ -51,9 +47,6 @@ public class ImportDefaultStatementTest extends AbstractStatementRegistryConsume
                 ImportAttributeTestUtil.createOutput());
     }
 
-    /**
-     * From NonExternal.
-     */
     @Test
     public void testFromNonExternal() {
         final Statement statement = getStatement("from-non-external");
diff --git a/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/PrefixMatchTest.java b/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/PrefixMatchTest.java
deleted file mode 100644 (file)
index 41e271a..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * 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.openconfig.routing.policy.statement;
-
-import org.junit.Ignore;
-
-@Ignore
-public class PrefixMatchTest extends AbstractStatementRegistryConsumerTest {/*
-    @Mock
-    private BGPRouteEntryExportParameters exportParameters;
-    private List<Statement> basicStatements;
-    private PolicyRIBBaseParametersImpl baseAttributes;
-
-    @Before
-    @Override
-    public void setUp() throws Exception {
-        super.setUp();
-        this.basicStatements = loadStatement("basic-statements-test");
-        this.baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
-    }
-
-    @Test
-    public void testPrefixRange() {
-        //RANGE
-       doReturn(new NodeIdentifierWithPredicates(Ipv4Route.QNAME,
-                ImmutableMap.of(QName.create(Ipv4Route.QNAME, "prefix").intern(), "10.3.191.0/22")))
-                .when(this.exportParameters).getRouteId();
-        Statement statement = this.basicStatements.stream()
-                .filter(st -> st.getName().equals("reject-prefix-test")).findFirst().get();
-        final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(createClusterInput());
-        RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
-                this.baseAttributes,
-                this.exportParameters,
-                attributeContainer,
-                statement);
-        assertNull(result.getAttributes());
-
-        doReturn(new NodeIdentifierWithPredicates(Ipv4Route.QNAME,
-                ImmutableMap.of(QName.create(Ipv4Route.QNAME, "prefix").intern(), "14.3.191.0/22")))
-                .when(this.exportParameters).getRouteId();
-        result = this.statementRegistry.applyExportStatement(
-                this.baseAttributes,
-                this.exportParameters,
-                attributeContainer,
-                statement);
-        assertNotNull(result.getAttributes());
-    }
-
-    @Test
-    public void testPrefixExact() {
-      /*  final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(createClusterInput());
-        Statement statement = this.basicStatements.stream()
-                .filter(st -> st.getName().equals("reject-prefix-test")).findFirst().get();
-
-        doReturn(new NodeIdentifierWithPredicates(Ipv4Route.QNAME,
-                ImmutableMap.of(QName.create(Ipv4Route.QNAME, "prefix").intern(), "10.3.192.0/21")))
-                .when(this.exportParameters).getRouteId();
-        RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
-                this.baseAttributes,
-                this.exportParameters,
-                attributeContainer,
-                statement);
-        assertNull(result.getAttributes());
-
-        doReturn(new NodeIdentifierWithPredicates(Ipv4Route.QNAME,
-                ImmutableMap.of(QName.create(Ipv4Route.QNAME, "prefix").intern(), "11.3.192.0/21")))
-                .when(this.exportParameters).getRouteId();
-        result = this.statementRegistry.applyExportStatement(
-                this.baseAttributes,
-                this.exportParameters,
-                attributeContainer,
-                statement);
-        assertNotNull(result.getAttributes());
-    }
-
-    @Test
-    public void testPrefixInverse() {
-       /* final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(createClusterInput());
-
-        doReturn(new NodeIdentifierWithPredicates(Ipv4Route.QNAME,
-                ImmutableMap.of(QName.create(Ipv4Route.QNAME, "prefix").intern(), "10.3.192.0/21")))
-                .when(this.exportParameters).getRouteId();
-        final Statement statement = this.basicStatements.stream()
-                .filter(st -> st.getName().equals("reject-prefix-inverse-test")).findFirst().get();
-        RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
-                this.baseAttributes,
-                this.exportParameters,
-                attributeContainer,
-                statement);
-        assertNotNull(result.getAttributes());
-
-        doReturn(new NodeIdentifierWithPredicates(Ipv4Route.QNAME,
-                ImmutableMap.of(QName.create(Ipv4Route.QNAME, "prefix").intern(), "11.3.192.0/21")))
-                .when(this.exportParameters).getRouteId();
-        result = this.statementRegistry.applyExportStatement(
-                this.baseAttributes,
-                this.exportParameters,
-                attributeContainer,
-                statement);
-        assertNull(result.getAttributes());
-}*/
-}
diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/BGPRouteEntryExportParametersImpl.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/BGPRouteEntryExportParametersImpl.java
new file mode 100644 (file)
index 0000000..84e3602
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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.mode.impl;
+
+import org.opendaylight.protocol.bgp.rib.spi.Peer;
+import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
+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;
+
+public final class BGPRouteEntryExportParametersImpl implements BGPRouteEntryExportParameters {
+    private final Peer fromPeer;
+    private final Peer toPeer;
+
+    public BGPRouteEntryExportParametersImpl(final Peer fromPeer, final Peer toPeer) {
+        this.fromPeer = fromPeer;
+        this.toPeer = toPeer;
+    }
+
+    @Override
+    public PeerRole getFromPeerRole() {
+        return this.fromPeer.getRole();
+    }
+
+    @Override
+    public PeerId getFromPeerId() {
+        return this.fromPeer.getPeerId();
+    }
+
+    @Override
+    public PeerRole getToPeerRole() {
+        return this.toPeer.getRole();
+    }
+
+    @Override
+    public PeerId getToPeerId() {
+        return this.toPeer.getPeerId();
+    }
+}
index 57b7226f59dca0e57833381ff44aed409c942dae..c6f7830d517eff4f5b340a539ee9ff1bb9598a78 100644 (file)
@@ -19,6 +19,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.protocol.bgp.mode.spi.AbstractRouteEntry;
 import org.opendaylight.protocol.bgp.rib.spi.BGPPeerTracker;
 import org.opendaylight.protocol.bgp.rib.spi.ExportPolicyPeerTracker;
+import org.opendaylight.protocol.bgp.rib.spi.Peer;
 import org.opendaylight.protocol.bgp.rib.spi.PeerExportGroup;
 import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
 import org.opendaylight.protocol.bgp.rib.spi.RouterIds;
@@ -180,8 +181,9 @@ public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry<AddPa
             final boolean destPeerSupAddPath, final AddPathBestPath path,
             final TablesKey localTK, final RIBSupport ribSup, final DOMDataWriteTransaction tx) {
         final NodeIdentifierWithPredicates routeId = entryInfo.getRouteId();
+        final Peer fromPeer = this.peerTracker.getPeer(path.getPeerId());
         final ContainerNode effectiveAttributes
-                = peerGroup.effectiveAttributes(this.peerTracker.getRole(path.getPeerId()), path.getAttributes());
+                = peerGroup.effectiveAttributes(fromPeer.getRole(), path.getAttributes());
         final NodeIdentifierWithPredicates routeIdAddPath = ribSup
                 .getRouteIdAddPath(destPeerSupAddPath ? path.getPathId() : NON_PATH_ID, routeId);
 
@@ -222,8 +224,9 @@ public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry<AddPa
         for (final PeerRole role : PeerRole.values()) {
             final PeerExportGroup peerGroup = peerPT.getPeerGroup(role);
             if (peerGroup != null) {
+                final Peer fromPeer = this.peerTracker.getPeer(routePeerId);
                 final ContainerNode effectiveAttributes = peerGroup.effectiveAttributes(
-                        this.peerTracker.getRole(routePeerId), attributes);
+                        fromPeer.getRole(), attributes);
                 peerGroup.forEach((destPeer, rootPath) -> {
                     final boolean destPeerSupAddPath = peerPT.isAddPathSupportedByPeer(destPeer);
                     if (filterRoutes(routePeerId, destPeer, localTK)
index b240b3bf73be210a5f9fd0b91db0c644c184df96..9cc49dc59309df5f0dac599e8c0fd6b9ab90472f 100644 (file)
@@ -14,6 +14,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.protocol.bgp.mode.spi.AbstractRouteEntry;
 import org.opendaylight.protocol.bgp.rib.spi.BGPPeerTracker;
 import org.opendaylight.protocol.bgp.rib.spi.ExportPolicyPeerTracker;
+import org.opendaylight.protocol.bgp.rib.spi.Peer;
 import org.opendaylight.protocol.bgp.rib.spi.PeerExportGroup;
 import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
 import org.opendaylight.protocol.bgp.rib.spi.entry.RouteEntryDependenciesContainer;
@@ -133,8 +134,9 @@ abstract class BaseAbstractRouteEntry extends AbstractRouteEntry<BaseBestPath> {
                 if (routeIdDest == null) {
                     routeIdDest = routeId;
                 }
+                final Peer fromPeer = this.peerTracker.getPeer(path.getPeerId());
                 final ContainerNode effAttrib = peerGroup.effectiveAttributes(
-                        this.peerTracker.getRole(path.getPeerId()), path.getAttributes());
+                        fromPeer.getRole(), path.getAttributes());
                 final YangInstanceIdentifier rootPath = entryInfo.getRootPath();
                 writeRoute(toPeerId, getAdjRibOutYII(ribSupport, rootPath, routeIdDest, localTK), effAttrib,
                         createValue(routeIdDest, path), ribSupport, tx);
@@ -198,8 +200,8 @@ abstract class BaseAbstractRouteEntry extends AbstractRouteEntry<BaseBestPath> {
         for (final PeerRole role : PeerRole.values()) {
             final PeerExportGroup peerGroup = peerPT.getPeerGroup(role);
             if (peerGroup != null) {
-                final ContainerNode effAttrib = peerGroup
-                        .effectiveAttributes(this.peerTracker.getRole(fromPeerId), attributes);
+                final Peer fromPeer = this.peerTracker.getPeer(fromPeerId);
+                final ContainerNode effAttrib = peerGroup.effectiveAttributes(fromPeer.getRole(), attributes);
                 peerGroup.forEach((destPeer, rootPath) -> {
                     if (!filterRoutes(fromPeerId, destPeer, localTK)) {
                         return;
index d28649a32d14a861eab026fdc470f1f4ab00acc9..a5690412d3847599328eec3d10d1ac468079b114 100644 (file)
@@ -44,12 +44,8 @@ public class BGPPeerTrackerMock {
         final PeerId pId = new PeerId("bgp://0.0.0.1");
         doReturn(this.peerMock).when(this.peerTracker).getPeer(eq(pId));
         doReturn(this.peerMock).when(this.peerTracker).getPeer(eq(PEER_ID));
-        doReturn(PeerRole.Ibgp).when(this.peerTracker).getRole(eq(pId));
-        doReturn(PeerRole.Ibgp).when(this.peerTracker).getRole(eq(PEER_ID));
         doReturn(true).when(this.peerMock).supportsTable(Mockito.eq(TABLES_KEY));
         doReturn(PeerRole.Ibgp).when(this.peerMock).getRole();
-
-
         doReturn(this.peerMock2).when(this.peerTracker).getPeer(eq(PEER_ID2));
         doReturn(false).when(this.peerMock2).supportsTable(Mockito.eq(TABLES_KEY));
     }
index 642d27fbdee0ee2a80a94d30bac579dee59afd9c..aea5facf73141ca76e9a086a0c0956681a3abb32 100644 (file)
@@ -7,82 +7,42 @@
  */
 package org.opendaylight.protocol.bgp.rib.impl;
 
-import java.util.ArrayList;
+import com.google.common.collect.ImmutableList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Optional;
-import java.util.stream.Collectors;
 import javax.annotation.concurrent.GuardedBy;
 import org.opendaylight.protocol.bgp.rib.spi.BGPPeerTracker;
 import org.opendaylight.protocol.bgp.rib.spi.Peer;
 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;
 
 public final class BGPPeerTrackerImpl implements BGPPeerTracker {
     @GuardedBy("this")
-    private final List<Peer> peers = new ArrayList<>();
-    private Map<PeerRole, List<PeerId>> rolePerPeerId;
+    private Map<PeerId, Peer> peers = new HashMap<>();
+    private ImmutableList<Peer> peersList;
 
     @Override
     public synchronized AbstractRegistration registerPeer(final Peer peer) {
-        this.peers.add(peer);
-        this.rolePerPeerId = this.peers.stream().collect(Collectors.groupingBy(Peer::getRole,
-                Collectors.mapping(Peer::getPeerId, Collectors.toList())));
+        this.peers.put(peer.getPeerId(), peer);
+        this.peersList = ImmutableList.copyOf(this.peers.values());
         return new AbstractRegistration() {
             @Override
             protected void removeRegistration() {
                 synchronized (BGPPeerTrackerImpl.this) {
-                    BGPPeerTrackerImpl.this.peers.remove(peer);
-                    BGPPeerTrackerImpl.this.rolePerPeerId = BGPPeerTrackerImpl.this.peers
-                            .stream().collect(Collectors.groupingBy(Peer::getRole,
-                                    Collectors.mapping(Peer::getPeerId, Collectors.toList())));
+                    BGPPeerTrackerImpl.this.peers.remove(peer.getPeerId());
                 }
             }
         };
     }
 
     @Override
-    public Peer getPeer(final PeerId peerId) {
-        synchronized (this.peers) {
-            return this.peers.stream().filter(peer -> peer.getPeerId().equals(peerId)).findFirst().orElse(null);
-        }
+    public synchronized Peer getPeer(final PeerId peerId) {
+        return this.peers.get(peerId);
     }
 
     @Override
-    public boolean supportsTable(final PeerId peerIdOfNewPeer, final TablesKey tableKey) {
-        final Peer peer = getPeer(peerIdOfNewPeer);
-        return peer != null && peer.supportsTable(tableKey);
-    }
-
-    @Override
-    public synchronized Map<PeerRole, List<PeerId>> getRoles() {
-        return this.rolePerPeerId;
-    }
-
-    @Override
-    public boolean supportsAddPathSupported(final PeerId toPeer, final TablesKey localTK) {
-        final Peer peer = getPeer(toPeer);
-        return peer != null && peer.supportsAddPathSupported(localTK);
-    }
-
-    @Override
-    public PeerRole getRole(final PeerId peerId) {
-        synchronized (this.peers) {
-            final Optional<Peer> peerOptional = this.peers.stream()
-                    .filter(peer -> peer.getPeerId().equals(peerId)).findFirst();
-            if (peerOptional.isPresent()) {
-                return peerOptional.get().getRole();
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public YangInstanceIdentifier getPeerRibInstanceIdentifier(final PeerId peerId) {
-        final Peer peer = getPeer(peerId);
-        return peer == null ? null : peer.getPeerRibInstanceIdentifier();
+    public synchronized List<Peer> getPeers() {
+        return this.peersList;
     }
 }
\ No newline at end of file
index cb3ba6ec73599f55e0720a74bb52dd887386c394..06391b3614f12a845b137f59bb5e328f7a1cf960 100644 (file)
@@ -16,7 +16,6 @@ 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.
@@ -39,47 +38,12 @@ public interface BGPPeerTracker {
     @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
+     * @return Returns map of Peer 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);
+    List<Peer> getPeers();
 }
index 9ac74a9850e0a0e8fc5fa1f9491bef0f850b4a0c..dc61c9b6163f47084c0449a98b3705102b19957c 100644 (file)
@@ -21,7 +21,7 @@ public interface BGPRouteEntryExportParameters extends BGPRouteEntryImportParame
      * @return peer Id of announced Peer
      */
     @Nonnull
-    PeerId getToPeer();
+    PeerId getToPeerId();
 
     /**
      * Peer role of Peer destiny for route entry.