</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>bgp-concepts</artifactId>
+ <artifactId>bgp-openconfig-rp-spi</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>concepts</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal.model</groupId>
+ <artifactId>yang-ext</artifactId>
+ </dependency>
<!-- test scope dependencies -->
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>testtool-util</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>bgp-openconfig-rp-spi</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>config-loader-impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>config-loader-impl</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>routing-policy-config-loader</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>routing-policy-config-loader</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-binding-broker-impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-binding-broker-impl</artifactId>
+ <scope>test</scope>
+ <type>test-jar</type>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ </dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>mockito-configuration</artifactId>
import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupport;
-import org.opendaylight.protocol.bgp.route.targetcontrain.impl.nlri.RouteTargetConstrainNlriHandler;
+import org.opendaylight.protocol.bgp.route.targetcontrain.impl.nlri.SimpleRouteTargetConstrainNlriRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
private NodeIdentifierWithPredicates createRouteKey(final UnkeyedListEntryNode routeTarget) {
final ByteBuf buffer = Unpooled.buffer();
final RouteTargetConstrainDestination dest = extractDestination(routeTarget);
- buffer.writeBytes(RouteTargetConstrainNlriHandler.serializeNlriDestinations(Collections.singletonList(dest)));
+ buffer.writeBytes(SimpleRouteTargetConstrainNlriRegistry.getInstance()
+ .serializeRouteTargetConstrain(dest.getRouteTargetConstrainChoice()));
final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf =
routeTarget.getChild(routePathIdNid());
return PathIdUtil.createNidKey(routeQName(), routeKeyQName(),
--- /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.route.targetcontrain.impl.activators;
+
+import java.util.Collections;
+import java.util.List;
+import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.AbstractBGPStatementProviderActivator;
+import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.StatementRegistryProvider;
+import org.opendaylight.protocol.bgp.route.targetcontrain.impl.route.policy.ClientAttributePrependHandler;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.ClientAttributePrepend;
+
+public final class StatementActivator extends AbstractBGPStatementProviderActivator {
+ @Override
+ protected synchronized List<AutoCloseable> startImpl(final StatementRegistryProvider provider) {
+ return Collections.singletonList(provider.registerBgpActionAugmentationPolicy(ClientAttributePrepend.class,
+ ClientAttributePrependHandler.getInstance()));
+ }
+}
--- /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.route.targetcontrain.impl.route.policy;
+
+import java.util.List;
+import java.util.Optional;
+import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.RouteEntryBaseAttributes;
+import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.action.BgpActionAugPolicy;
+import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
+import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryImportParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.ClientAttributePrepend;
+
+public final class ClientAttributePrependHandler implements BgpActionAugPolicy<ClientAttributePrepend> {
+ private static final ClientAttributePrependHandler INSTANCE = new ClientAttributePrependHandler();
+
+ private ClientAttributePrependHandler() {
+
+ }
+
+ public static ClientAttributePrependHandler getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public Attributes applyImportAction(final RouteEntryBaseAttributes routeEntryInfo,
+ final BGPRouteEntryImportParameters routeBaseParameters,
+ final Attributes attributes,
+ final ClientAttributePrepend actions) {
+ return attributes;
+ }
+
+
+ @Override
+ public Attributes applyExportAction(final RouteEntryBaseAttributes routeEntryInfo,
+ final BGPRouteEntryExportParameters exportParameters,
+ final Attributes attributes,
+ final ClientAttributePrepend actions) {
+ final List<Route> rtRoutes = exportParameters.getClientRouteTargetContrainCache();
+ final Optional<Route> found = rtRoutes.stream()
+ .filter(rt -> rt.getRouteKey().equals(exportParameters.getRouteKey()))
+ .findFirst();
+ if (found.isPresent()) {
+ return found.get().getAttributes();
+ }
+ return attributes;
+ }
+}
\ No newline at end of file
--- /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.route.targetcontrain.spi;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
+
+/**
+ * Provide a cache to store client routes advertized, to be used for policy
+ * https://tools.ietf.org/html/rfc4684.
+ * ii. When advertising an RT membership NLRI to a non-client peer, if
+ * the best path as selected by the path selection procedure
+ * described in Section 9.1 of the base BGP specification [4] is a
+ * route received from a non-client peer, and if there is an
+ * alternative path to the same destination from a client, the
+ * attributes of the client path are advertised to the peer"
+ */
+public interface ClientRouteTargetContrainCache {
+ /**
+ * Cache Route.
+ *
+ * @param route target constrain
+ */
+ void cacheRoute(Route route);
+
+ /**
+ * Uncache Route.
+ *
+ * @param route target constrain
+ */
+ void uncacheRoute(Route route);
+}
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.protocol.bgp.rib.impl;
+package org.opendaylight.protocol.bgp.route.targetcontrain.spi;
import java.util.Optional;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.route.target.constrain.routes.route.target.constrain.routes.RouteTargetConstrainRoute;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.RouteTarget;
-final class RouteTargetMembeshipUtil {
+public final class RouteTargetMembeshipUtil {
private RouteTargetMembeshipUtil() {
throw new UnsupportedOperationException();
}
- static <R extends Route> Optional<RouteTarget> getRT(final R route) {
+ public static <R extends Route> Optional<RouteTarget> getRT(final R route) {
if (!(route instanceof RouteTargetConstrainRoute)) {
return Optional.empty();
}
<bean id="RIBActivator" class="org.opendaylight.protocol.bgp.route.targetcontrain.impl.activators.RIBActivator"/>
<service ref="RIBActivator" interface="org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderActivator"
odl:type="org.opendaylight.protocol.bgp.route.targetcontrain.impl.activators.RIBActivator"/>
+
+ <bean id="StatementActivator"
+ class="org.opendaylight.protocol.bgp.route.targetcontrain.impl.activators.StatementActivator">
+ </bean>
+
+ <service ref="StatementActivator"
+ interface="org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.StatementProviderActivator"
+ odl:type="org.opendaylight.protocol.bgp.route.targetcontrain.impl.activators.StatementActivator"/>
</blueprint>
\ No newline at end of file
import bmp-monitor { prefix bmp-mon; revision-date 2018-03-29; }
import bgp-message { prefix bgp-msg; revision-date 2018-03-29; }
import ietf-inet-types { prefix inet; revision-date 2013-07-15; }
+ import openconfig-routing-policy { prefix rpol; }
+ import openconfig-bgp-policy { prefix bgp-pol; }
+ import yang-ext { prefix ext; revision-date "2013-07-09"; }
organization "AT&T Services, Inc.";
uses route-target-constrain-routes;
}
}
+
+ augment /rpol:routing-policy/rpol:policy-definitions/rpol:policy-definition/rpol:statements/rpol:statement/rpol:actions/bgp-pol:bgp-actions {
+ ext:augment-identifier client-attribute-prepend;
+ container client-attribute-prepend {
+
+ presence "node is present in the config data to use the client attributes prepend action";
+ description "action to use attribute from advertized from a client(rfc4684)";
+ }
+ }
}
\ No newline at end of file
.setAs4SpecificCommon(AS_COMMON).build())
.build();
private static final RouteTargetConstrainRouteKey ROUTE_KEY
- = new RouteTargetConstrainRouteKey(PATH_ID, "YAAAAEgCAgAAABQAZA==");
+ = new RouteTargetConstrainRouteKey(PATH_ID, "AgIAAAAUAGQ=");
private static final RouteTargetConstrainRoute ROUTE = new RouteTargetConstrainRouteBuilder()
.setRouteKey(ROUTE_KEY.getRouteKey())
.setPathId(ROUTE_KEY.getPathId())
--- /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.route.targetcontrain.impl.route.policy;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.doReturn;
+import static org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer.routeAttributeContainerFalse;
+
+import java.util.Collections;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.AbstractStatementRegistryTest;
+import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.RouteEntryBaseAttributes;
+import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer;
+import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
+import org.opendaylight.protocol.bgp.route.targetcontrain.impl.activators.StatementActivator;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
+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.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.route.target.constrain.routes.route.target.constrain.routes.RouteTargetConstrainRouteBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder;
+
+public class ClientAttributePrependHandlerTest extends AbstractStatementRegistryTest {
+ @Mock
+ private BGPRouteEntryExportParameters exportParameters;
+ private List<Statement> basicStatements;
+ @Mock
+ private RouteEntryBaseAttributes baseAttributes;
+
+ @Before
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ final StatementActivator act = new StatementActivator();
+ act.start(this.statementRegistry);
+ this.basicStatements = loadStatement("basic-statements-test");
+ doReturn(CLUSTER).when(this.baseAttributes).getClusterId();
+ doReturn(LOCAL_AS).when(this.baseAttributes).getLocalAs();
+ doReturn(IPV4).when(this.baseAttributes).getOriginatorId();
+ }
+
+
+ @Test
+ public void testPreprendClientAttribute() {
+ Statement statement = this.basicStatements.stream()
+ .filter(st -> st.getName().equals("client-attribute-append-test")).findFirst().get();
+ final Attributes att = new AttributesBuilder()
+ .setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder()
+ .setGlobal(IPV4).build()).build())
+ .build();
+ final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(att);
+ doReturn(Collections.emptyList()).when(this.exportParameters).getClientRouteTargetContrainCache();
+
+ RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
+ this.baseAttributes,
+ IPV4UNICAST.class,
+ this.exportParameters,
+ attributeContainer,
+ statement);
+ assertEquals(att, result.getAttributes());
+
+ final Attributes expected = new AttributesBuilder()
+ .setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder()
+ .setGlobal(new Ipv4Address("2.2.2.2")).build()).build())
+ .build();
+ final String rk = "testRoute";
+ final Route rtRoute = new RouteTargetConstrainRouteBuilder()
+ .setRouteKey(rk)
+ .setAttributes(expected)
+ .build();
+ doReturn(Collections.singletonList(rtRoute)).when(this.exportParameters).getClientRouteTargetContrainCache();
+ doReturn(rk).when(this.exportParameters).getRouteKey();
+
+ result = this.statementRegistry.applyExportStatement(
+ this.baseAttributes,
+ IPV4UNICAST.class,
+ this.exportParameters,
+ attributeContainer,
+ statement);
+ assertEquals(expected, result.getAttributes());
+ }
+
+}
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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
+ -->
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<routing-policy xmlns="http://openconfig.net/yang/routing-policy">
+ <policy-definitions>
+ <policy-definition>
+ <name>basic-statements-test</name>
+ <statements>
+ <statement>
+ <name>client-attribute-append-test</name>
+ <conditions>
+ <bgp-conditions xmlns="http://openconfig.net/yang/bgp-policy">
+ <match-role-set xmlns="urn:opendaylight:params:xml:ns:yang:odl:bgp:default:policy">
+ <from-role>
+ <role-set>/rpol:routing-policy/rpol:defined-sets/bgppol:bgp-defined-sets/role-sets/role-set[role-set-name="all"]</role-set>
+ </from-role>
+ </match-role-set>
+ </bgp-conditions>
+ </conditions>
+ <actions>
+ <bgp-actions xmlns="http://openconfig.net/yang/bgp-policy">
+ <client-attribute-prepend xmlns="urn:opendaylight:params:xml:ns:yang:bgp:route:target:constrain"/>
+ </bgp-actions>
+ </actions>
+ </statement>
+ </statements>
+ </policy-definition>
+ </policy-definitions>
+</routing-policy>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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
+-->
+<configuration scan="true">
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <logger name="org.opendaylight.protocol" additivity="false">
+ <level value="DEBUG"/>
+ <appender-ref ref="STDOUT"/>
+ </logger>
+ <logger name="org.opendaylight.bgpcep" additivity="false">
+ <level value="DEBUG"/>
+ <appender-ref ref="STDOUT"/>
+ </logger>
+
+ <root level="info">
+ <appender-ref ref="STDOUT"/>
+ </root>
+</configuration>
\ No newline at end of file
}
}
- augment /rpol:routing-policy/rpol:policy-definitions/rpol:policy-definition/rpol:statements/rpol:statement/rpol:actions/bgp-pol:bgp-actions {
+ augment /rpol:routing-policy/rpol:policy-definitions/rpol:policy-definition/rpol:statements/rpol:statement/rpol:actions/bgppol:bgp-actions {
ext:augment-identifier reflect-attributes-actions;
container reflect-attributes-actions {
presence "Modify attributes so they are updated as per RFC4456 route reflection";
}
}
- augment /rpol:routing-policy/rpol:policy-definitions/rpol:policy-definition/rpol:statements/rpol:statement/rpol:actions/bgp-pol:bgp-actions {
+ augment /rpol:routing-policy/rpol:policy-definitions/rpol:policy-definition/rpol:statements/rpol:statement/rpol:actions/bgppol:bgp-actions {
ext:augment-identifier non-transitive-attributes-filter;
container non-transitive-attributes-filter {
presence "Filters attributes, removing non transitive attributes";
}
}
- augment /rpol:routing-policy/rpol:policy-definitions/rpol:policy-definition/rpol:statements/rpol:statement/rpol:actions/bgp-pol:bgp-actions {
+ augment /rpol:routing-policy/rpol:policy-definitions/rpol:policy-definition/rpol:statements/rpol:statement/rpol:actions/bgppol:bgp-actions {
ext:augment-identifier local-as-path-prepend;
container local-as-path-prepend {
presence "Prepends local AS Path";
}
}
- augment /rpol:routing-policy/rpol:policy-definitions/rpol:policy-definition/rpol:statements/rpol:statement/rpol:actions/bgp-pol:bgp-actions {
+ augment /rpol:routing-policy/rpol:policy-definitions/rpol:policy-definition/rpol:statements/rpol:statement/rpol:actions/bgppol:bgp-actions {
ext:augment-identifier set-cluster-id-prepend;
container set-cluster-id-prepend {
}
}
- augment /rpol:routing-policy/rpol:policy-definitions/rpol:policy-definition/rpol:statements/rpol:statement/rpol:actions/bgp-pol:bgp-actions {
+ augment /rpol:routing-policy/rpol:policy-definitions/rpol:policy-definition/rpol:statements/rpol:statement/rpol:actions/bgppol:bgp-actions {
ext:augment-identifier set-originator-id-prepend;
container set-originator-id-prepend {
presence "node is present in the config data to use the Originator Id prepend action";
import java.util.List;
import org.opendaylight.protocol.bgp.rib.spi.Peer;
import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
+import org.opendaylight.protocol.bgp.rib.spi.policy.RTCCache;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerRole;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ClusterIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.RouteTarget;
public final class BGPRouteEntryExportParametersImpl implements BGPRouteEntryExportParameters {
private final Peer fromPeer;
private final Peer toPeer;
+ private final String routeKey;
+ private final RTCCache rtCache;
- public BGPRouteEntryExportParametersImpl(final Peer fromPeer, final Peer toPeer) {
+ public BGPRouteEntryExportParametersImpl(final Peer fromPeer, final Peer toPeer,
+ final String routeKey, final RTCCache rtCache) {
this.fromPeer = fromPeer;
this.toPeer = toPeer;
+ this.routeKey = routeKey;
+ this.rtCache = rtCache;
}
@Override
return this.toPeer.getLocalAs();
}
+ @Override
+ public String getRouteKey() {
+ return this.routeKey;
+ }
+
@Override
public PeerId getToPeerId() {
return this.toPeer.getPeerId();
public List<RouteTarget> getMemberships() {
return this.toPeer.getMemberships();
}
+
+ @Override
+ public List<Route> getClientRouteTargetContrainCache() {
+ return this.rtCache.getClientRouteTargetContrainCache();
+ }
}
@GuardedBy("this")
PeerId peerId;
private FluentFuture<? extends CommitInfo> submitted;
+ RTCClientRouteCache rtCache = new RTCClientRouteCache();
AbstractPeer(
final RIB rib,
}
final R route = initializingRoute.getRoute();
- final BGPRouteEntryExportParameters routeEntry = new BGPRouteEntryExportParametersImpl(fromPeer, this);
+ final BGPRouteEntryExportParameters routeEntry = new BGPRouteEntryExportParametersImpl(fromPeer,
+ this, route.getRouteKey(), this.rtCache);
final Optional<Attributes> effAttr = entryDep.getRoutingPolicies()
.applyExportPolicies(routeEntry, initializingRoute.getAttributes(), entryDep.getAfiSafType());
final KeyedInstanceIdentifier<Tables, TablesKey> tableRibout = getRibOutIId(tk);
}
final R route = actualBestRoute.getRoute();
- final BGPRouteEntryExportParameters routeEntry = new BGPRouteEntryExportParametersImpl(fromPeer, this);
+ final BGPRouteEntryExportParameters routeEntry = new BGPRouteEntryExportParametersImpl(fromPeer,
+ this, route.getRouteKey(), this.rtCache);
final Optional<Attributes> effAttr = entryDep.getRoutingPolicies()
.applyExportPolicies(routeEntry, actualBestRoute.getAttributes(), entryDep.getAfiSafType());
final KeyedInstanceIdentifier<Tables, TablesKey> tableRibout = getRibOutIId(tk);
Optional<Attributes> effAttr = Optional.empty();
final Peer fromPeer = peerTracker.getPeer(fromPeerId);
if (fromPeer != null && attributes != null) {
- final BGPRouteEntryExportParameters routeEntry
- = new BGPRouteEntryExportParametersImpl(fromPeer, this);
+ final BGPRouteEntryExportParameters routeEntry = new BGPRouteEntryExportParametersImpl(fromPeer,
+ this, route.getRouteKey(), this.rtCache);
effAttr = routingPolicies.applyExportPolicies(routeEntry, attributes, entryDep.getAfiSafType());
}
final KeyedInstanceIdentifier<Tables, TablesKey> tableRibout = getRibOutIId(tk);
Collections.emptyMap(), registerAppPeerListener);
this.effectiveRibInWriter = new EffectiveRibInWriter(this, this.rib,
this.rib.createPeerChain(this), this.peerIId, localTables, this.tableTypeRegistry,
- Collections.emptyList());
+ Collections.emptyList(), this.rtCache);
this.effectiveRibInWriter.init();
this.bgpSessionState.registerMessagesCounter(this);
this.trackerRegistration = this.rib.getPeerTracker().registerPeer(this);
import org.opendaylight.protocol.bgp.rib.spi.state.BGPSessionState;
import org.opendaylight.protocol.bgp.rib.spi.state.BGPTimersState;
import org.opendaylight.protocol.bgp.rib.spi.state.BGPTransportState;
+import org.opendaylight.protocol.bgp.route.targetcontrain.spi.ClientRouteTargetContrainCache;
import org.opendaylight.protocol.concepts.AbstractRegistration;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.peer.AdjRibOut;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.route.target.constrain.routes.route.target.constrain.routes.RouteTargetConstrainRoute;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.AddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ClusterIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily;
this.tables = ImmutableSet.copyOf(setTables);
this.effRibInWriter = new EffectiveRibInWriter(this, this.rib,
this.rib.createPeerChain(this),
- peerIId, this.tables, this.tableTypeRegistry, rtMemberships);
+ peerIId, this.tables, this.tableTypeRegistry,
+ this.rtMemberships,
+ this.rtCache);
registerPrefixesCounters(this.effRibInWriter, this.effRibInWriter);
this.peerRibOutIId = peerIId.child(AdjRibOut.class);
this.effRibInWriter.init();
import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRibRoutingPolicy;
import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryImportParameters;
+import org.opendaylight.protocol.bgp.route.targetcontrain.spi.ClientRouteTargetContrainCache;
+import org.opendaylight.protocol.bgp.route.targetcontrain.spi.RouteTargetMembeshipUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerRole;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.Peer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.PeerKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.route.target.constrain.routes.route.target.constrain.routes.RouteTargetConstrainRoute;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv6AddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.MplsLabeledVpnSubsequentAddressFamily;
private final DataBroker databroker;
private final List<RouteTarget> rtMemberships;
private final RibOutRefresh vpnTableRefresher;
+ private final ClientRouteTargetContrainCache rtCache;
private ListenerRegistration<?> reg;
private BindingTransactionChain chain;
private final Map<TablesKey, LongAdder> prefixesReceived;
final KeyedInstanceIdentifier<Peer, PeerKey> peerIId,
final Set<TablesKey> tables,
final BGPTableTypeRegistryConsumer tableTypeRegistry,
- final List<RouteTarget> rtMemberships) {
+ final List<RouteTarget> rtMemberships,
+ final ClientRouteTargetContrainCache rtCache) {
this.registry = requireNonNull(rib.getRibSupportContext());
this.chain = requireNonNull(chain);
this.peerIId = requireNonNull(peerIId);
this.tableTypeRegistry = requireNonNull(tableTypeRegistry);
this.peerImportParameters = peer;
this.rtMemberships = rtMemberships;
+ this.rtCache = rtCache;
this.vpnTableRefresher = rib;
}
final WriteTransaction tx,
final TablesKey tableKey, final RIBSupport<C, S, R, I> ribSupport,
final KeyedInstanceIdentifier<Tables, TablesKey> tablePath,
- final Collection<DataObjectModification<? extends DataObject>> routeChanges) {
- for (final DataObjectModification<? extends DataObject> routeChanged : routeChanges) {
+ final Collection<DataObjectModification<R>> routeChanges) {
+ for (final DataObjectModification<R> routeChanged : routeChanges) {
final I routeKey
= ((InstanceIdentifier.IdentifiableItem<R, I>) routeChanged.getIdentifier()).getKey();
switch (routeChanged.getModificationType()) {
case SUBTREE_MODIFIED:
case WRITE:
- writeRoutes(tx, tableKey, ribSupport, tablePath, routeKey, (R) routeChanged.getDataAfter());
+ writeRoutes(tx, tableKey, ribSupport, tablePath, routeKey, routeChanged.getDataAfter());
break;
case DELETE:
final InstanceIdentifier<R> routeIID = ribSupport.createRouteIdentifier(tablePath, routeKey);
if (effAtt.isPresent()) {
final Optional<RouteTarget> rtMembership = RouteTargetMembeshipUtil.getRT(route);
if (rtMembership.isPresent()) {
- this.rtMemberships.add(rtMembership.get());
+ final RouteTarget rt = rtMembership.get();
+ if(PeerRole.Ibgp != this.peerImportParameters.getFromPeerRole()) {
+ this.rtCache.cacheRoute(route);
+ }
+ this.rtMemberships.add(rt);
this.rtMembershipsUpdated = true;
}
CountersUtil.increment(this.prefixesInstalled.get(tk), tk);
} else {
final Optional<RouteTarget> rtMembership = RouteTargetMembeshipUtil.getRT(route);
if (rtMembership.isPresent()) {
+ if(PeerRole.Ibgp != this.peerImportParameters.getFromPeerRole()) {
+ this.rtCache.uncacheRoute(route);
+ }
this.rtMemberships.remove(rtMembership.get());
this.rtMembershipsUpdated = true;
}
--- /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.rib.impl;
+
+import com.google.common.collect.ImmutableList;
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.concurrent.GuardedBy;
+import org.opendaylight.protocol.bgp.rib.spi.policy.RTCCache;
+import org.opendaylight.protocol.bgp.route.targetcontrain.spi.ClientRouteTargetContrainCache;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.route.target.constrain.routes.route.target.constrain.routes.RouteTargetConstrainRoute;
+
+public final class RTCClientRouteCache implements ClientRouteTargetContrainCache, RTCCache {
+ @GuardedBy("this")
+ private final List<RouteTargetConstrainRoute> rtCache = new ArrayList<>();
+
+ @Override
+ public synchronized void cacheRoute(final Route route) {
+ if (!(route instanceof RouteTargetConstrainRoute)) {
+ return;
+ }
+ this.rtCache.add((RouteTargetConstrainRoute) route);
+ }
+
+ @Override
+ public synchronized void uncacheRoute(final Route route) {
+ if (!(route instanceof RouteTargetConstrainRoute)) {
+ return;
+ }
+ this.rtCache.remove(route);
+ }
+
+ @Override
+ public synchronized List<Route> getClientRouteTargetContrainCache() {
+ return ImmutableList.copyOf(this.rtCache);
+ }
+}
\ No newline at end of file
/**
* Contains Peer destiny information for export route entry.
*/
-public interface BGPRouteEntryExportParameters extends RouteTargetMembershipConsumer, BGPRouteEntryImportParameters {
+public interface BGPRouteEntryExportParameters extends RouteTargetMembershipConsumer,
+ BGPRouteEntryImportParameters, RTCCache {
/**
* Peer id of Peer route entry destiny.
*/
@Nullable
AsNumber getToPeerLocalAs();
+
+ /**
+ * Destination Route Key.
+ *
+ * @return routeKey
+ */
+ String getRouteKey();
}
--- /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.rib.spi.policy;
+
+import java.util.List;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
+
+public interface RTCCache {
+ /**
+ * Cache of RTC routes advertized per clients peers.
+ *
+ * @return rtc cache
+ */
+ @Nonnull
+ List<Route> getClientRouteTargetContrainCache();
+}