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;
}
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;
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;
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;
this.baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
}
- /**
- * To eBGP.
- */
@Test
public void testToEbgp() {
final Statement statement = getStatementAndSetToRole("to-external", PeerRole.Ebgp);
assertApplyExportStatement(statement, PeerRole.RrClient, attributeContainer, expectedOutput);
}
-
- /**
- * From iBGP To iBGP.
- */
@Test
public void testFromInternalToInternal() {
final Statement statement = getStatementAndSetToRole("from-internal-to-internal", PeerRole.Ibgp);
assertApplyExportStatement(statement, PeerRole.Ibgp, attributeContainer, null);
}
- /**
- * From iBGP To iBGP.
- */
@Test
public void testFromExternalToInternal() {
final Statement statement = getStatementAndSetToRole("from-external-to-internal", PeerRole.Ibgp);
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",
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);
assertApplyExportStatement(statement, PeerRole.RrClient, attributeContainer, createInputWithOriginator());
}
- /**
- * Any role To Internal.
- */
@Test
public void testOdlInternal() {
final Statement statement = getStatementAndSetToRole("to-odl-internal", PeerRole.Internal);
assertApplyExportStatement(statement, PeerRole.RrClient, attributeContainer, null);
}
- /**
- * To RrClient.
- */
@Test
public void testFromExternalToRRClient() {
final Statement statement = getStatementAndSetToRole("from-external-to-route-reflector", PeerRole.RrClient);
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",
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());
private List<Statement> defaultImportStatements;
private PolicyRIBBaseParametersImpl baseAttributes;
-
@Before
@Override
public void setUp() throws Exception {
this.baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
}
- /**
- * From eBGP.
- */
@Test
public void testFromEbgp() {
final Statement statement = getStatement("from-external");
ImportAttributeTestUtil.createOutput());
}
- /**
- * From NonExternal.
- */
@Test
public void testFromNonExternal() {
final Statement statement = getStatement("from-non-external");
+++ /dev/null
-/*
- * 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());
-}*/
-}
--- /dev/null
+/*
+ * 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();
+ }
+}
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;
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);
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)
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;
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);
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;
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));
}
*/
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
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.
@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();
}
* @return peer Id of announced Peer
*/
@Nonnull
- PeerId getToPeer();
+ PeerId getToPeerId();
/**
* Peer role of Peer destiny for route entry.