}
}
- augment /rpol:routing-policy/rpol:policy-definitions/rpol:policy-definition/rpol:statements/rpol:statement/rpol:actions/bgp-pol:bgp-actions {
- ext:augment-identifier set-originator-id-to-advertizer-router-id;
- container set-originator-id-to-advertizer-router-id {
-
- presence "node is present in the config data to apply the set-originator-id-to-advertizer-router-id action";
- description "action to set router-id of the advertiser as Originator attribute";
- }
- }
-
- augment /rpol:routing-policy/rpol:policy-definitions/rpol:policy-definition/rpol:statements/rpol:statement/rpol:actions/bgp-pol:bgp-actions {
- ext:augment-identifier set-local-address-as-next-hop;
- container set-local-address-as-next-hop {
-
- presence "node is present in the config data to apply set-local-address-as-next-hop action";
- description "action to set local address as next hop";
- }
- }
-
augment /rpol:routing-policy/rpol:policy-definitions/rpol:policy-definition/rpol:statements/rpol:statement/rpol:actions/bgp-pol:bgp-actions {
ext:augment-identifier set-originator-id-prepend;
container set-originator-id-prepend {
if (nhAction != null) {
final IpAddress address = nhAction.getIpAddress();
+ CNextHop nhNew;
if (address != null) {
- CNextHop nhNew;
if (address.getIpv4Address() != null) {
nhNew = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder()
.setGlobal(address.getIpv4Address()).build()).build();
}
attributesUpdatedBuilder.setCNextHop(nhNew);
+ } else if (nhAction.getEnumeration() != null
+ && BgpNextHopType.Enumeration.SELF == nhAction.getEnumeration()) {
+ nhNew = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder()
+ .setGlobal(routeEntryInfo.getOriginatorId()).build()).build();
+ attributesUpdatedBuilder.setCNextHop(nhNew);
}
}
attributesUpdated = attributesUpdatedBuilder.build();
@Test
- public void testAppend() {
+ public void testMultipleAppend() {
Statement statement = this.basicStatements.stream()
.filter(st -> st.getName().equals("multiple-append-test")).findFirst().get();
final RouteAttributeContainer attributeContainer
.build();
assertEquals(expected, result.getAttributes());
}
+
+ @Test
+ public void testNextHopSelf() {
+ Statement statement = this.basicStatements.stream()
+ .filter(st -> st.getName().equals("next-hop-self-append-test")).findFirst().get();
+ final RouteAttributeContainer attributeContainer
+ = routeAttributeContainerFalse(new AttributesBuilder().build());
+ RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
+ this.baseAttributes,
+ IPV4UNICAST.class,
+ this.exportParameters,
+ attributeContainer,
+ statement);
+
+ final Attributes expected = new AttributesBuilder()
+ .setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder()
+ .setGlobal(IPV4).build()).build())
+ .build();
+ assertEquals(expected, result.getAttributes());
+ }
}
</bgp-actions>
</actions>
</statement>
+ <statement>
+ <name>next-hop-self-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">
+ <set-next-hop>SELF</set-next-hop>
+ </bgp-actions>
+ </actions>
+ </statement>
</statements>
</policy-definition>
</policy-definitions>
+++ /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.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.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.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;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180329.SetLocalAddressAsNextHop;
-
-/**
- * Local Address shall be set as next Hop.
- * https://tools.ietf.org/html/rfc4684
- *
- * @author Claudio D. Gasparini
- */
-public final class SetLocalAddressAsNextHopHandler implements BgpActionAugPolicy<SetLocalAddressAsNextHop> {
- private static final SetLocalAddressAsNextHopHandler INSTANCE = new SetLocalAddressAsNextHopHandler();
-
- private SetLocalAddressAsNextHopHandler() {
-
- }
-
- public static SetLocalAddressAsNextHopHandler getInstance() {
- return INSTANCE;
- }
-
- @Override
- public Attributes applyImportAction(
- final RouteEntryBaseAttributes routeEntryInfo,
- final BGPRouteEntryImportParameters routeBaseParameters,
- final Attributes attributes,
- final SetLocalAddressAsNextHop actions) {
- return setNextHop(attributes, routeEntryInfo.getOriginatorId());
- }
-
- private Attributes setNextHop(final Attributes attributes, final Ipv4Address localAddress) {
- return new AttributesBuilder(attributes)
- .setCNextHop(new Ipv4NextHopCaseBuilder()
- .setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(localAddress).build())
- .build()).build();
- }
-
- @Override
- public Attributes applyExportAction(
- final RouteEntryBaseAttributes routeEntryInfo,
- final BGPRouteEntryExportParameters exportParameters,
- final Attributes attributes,
- final SetLocalAddressAsNextHop actions) {
- return setNextHop(attributes, routeEntryInfo.getOriginatorId());
- }
-}
import org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.actions.SetCommunityHandler;
import org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.actions.SetExtCommunityHandler;
import org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.actions.SetOriginatorIdPrependHandler;
-import org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.actions.SetOriginatorIdToAdvertizerRouterIdHandler;
import org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.conditions.MatchAfiSafiNotInHandler;
import org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.conditions.MatchAsPathSetHandler;
import org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.conditions.MatchBgpNeighborSetHandler;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180329.MatchRoleSetCondition;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180329.NonTransitiveAttributesFilter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180329.SetClusterIdPrepend;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180329.SetLocalAddressAsNextHop;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180329.SetOriginatorIdPrepend;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180329.SetOriginatorIdToAdvertizerRouterId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180329.VpnNonMemberCondition;
public final class StatementActivator extends AbstractBGPStatementProviderActivator {
registration.add(provider.registerBgpActionAugmentationPolicy(SetClusterIdPrepend.class,
new SetClusterIdPrependHandler()));
-
- registration.add(provider.registerBgpActionAugmentationPolicy(SetOriginatorIdToAdvertizerRouterId.class,
- SetOriginatorIdToAdvertizerRouterIdHandler.getInstance()));
-
- registration.add(provider.registerBgpActionAugmentationPolicy(SetLocalAddressAsNextHop.class,
- SetLocalAddressAsNextHopHandler.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.openconfig.routing.policy.statement.actions;
-
-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.RouterIds;
-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.message.rev180329.path.attributes.AttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.OriginatorIdBuilder;
-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.odl.bgp._default.policy.rev180329.SetOriginatorIdToAdvertizerRouterId;
-
-/**
- * Originator attribute shall be set to the router-id of the advertiser.
- * https://tools.ietf.org/html/rfc4684
- *
- * @author Claudio D. Gasparini
- */
-public final class SetOriginatorIdToAdvertizerRouterIdHandler
- implements BgpActionAugPolicy<SetOriginatorIdToAdvertizerRouterId> {
- private static SetOriginatorIdToAdvertizerRouterIdHandler INSTANCE
- = new SetOriginatorIdToAdvertizerRouterIdHandler();
-
- private SetOriginatorIdToAdvertizerRouterIdHandler() {
-
- }
-
- public static SetOriginatorIdToAdvertizerRouterIdHandler getInstance() {
- return INSTANCE;
- }
-
- @Override
- public Attributes applyImportAction(
- final RouteEntryBaseAttributes routeEntryInfo,
- final BGPRouteEntryImportParameters routeBaseParameters,
- final Attributes attributes,
- final SetOriginatorIdToAdvertizerRouterId actions) {
- return setOriginatorId(attributes, routeBaseParameters.getFromPeerId());
- }
-
- private Attributes setOriginatorId(final Attributes attributes, final PeerId peerId) {
- if (attributes.getOriginatorId() != null) {
- return attributes;
- }
- return new AttributesBuilder(attributes)
- .setOriginatorId(new OriginatorIdBuilder()
- .setOriginator(RouterIds.inetFromPeerId(peerId)).build()).build();
- }
-
- @Override
- public Attributes applyExportAction(
- final RouteEntryBaseAttributes routeEntryInfo,
- final BGPRouteEntryExportParameters routeBaseParameters,
- final Attributes attributes,
- final SetOriginatorIdToAdvertizerRouterId actions) {
- return setOriginatorId(attributes, routeBaseParameters.getFromPeerId());
- }
-}
+++ /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 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.List;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.opendaylight.protocol.bgp.openconfig.routing.policy.impl.PolicyRIBBaseParametersImpl;
-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.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.PeerRole;
-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 SetLocalAddressAsNextHopHandlerTest extends AbstractStatementRegistryConsumerTest {
- private final Attributes multipleCom = new AttributesBuilder()
- .setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder()
- .setGlobal(new Ipv4Address("1.2.3.4")).build()).build())
- .build();
- @Mock
- private BGPRouteEntryExportParameters exportParameters;
- private List<Statement> basicStatements;
- private PolicyRIBBaseParametersImpl baseAttributes;
-
- @Before
- @Override
- public void setUp() throws Exception {
- super.setUp();
- this.basicStatements = loadStatement("set-local-address-as-next-hop");
- this.baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
- doReturn(PeerRole.Ibgp).when(this.exportParameters).getFromPeerRole();
- }
-
- @Test
- public void testInlineAdd() {
- Statement statement = this.basicStatements.stream()
- .filter(st -> st.getName().equals("set-local-address-as-next-hop")).findFirst().get();
- RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
- new AttributesBuilder().build());
- RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
- this.baseAttributes,
- IPV4UNICAST.class,
- this.exportParameters,
- attributeContainer,
- statement);
-
- assertEquals(this.multipleCom, result.getAttributes());
- }
-}
\ 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.openconfig.routing.policy.statement;
-
-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.List;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.opendaylight.protocol.bgp.openconfig.routing.policy.impl.PolicyRIBBaseParametersImpl;
-import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer;
-import org.opendaylight.protocol.bgp.rib.spi.RouterIds;
-import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
-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.message.rev180329.path.attributes.attributes.OriginatorIdBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerRole;
-
-public class SetOriginatorIdToAdvertizerRouterIdHandlerTest extends AbstractStatementRegistryConsumerTest {
- private Ipv4Address ipv4 = Ipv4Address.getDefaultInstance("42.42.42.42");
- private final Attributes multipleCom = new AttributesBuilder()
- .setOriginatorId(new OriginatorIdBuilder().setOriginator(ipv4).build())
- .build();
- @Mock
- private BGPRouteEntryExportParameters exportParameters;
- private List<Statement> basicStatements;
- private PolicyRIBBaseParametersImpl baseAttributes;
-
- @Before
- @Override
- public void setUp() throws Exception {
- super.setUp();
- this.basicStatements = loadStatement("set-originator-id-to-advertizer-router-id");
- this.baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
- doReturn(PeerRole.Ibgp).when(this.exportParameters).getFromPeerRole();
- doReturn(RouterIds.createPeerId(ipv4)).when(this.exportParameters).getFromPeerId();
- }
-
- @Test
- public void testInlineAdd() {
- Statement statement = this.basicStatements.stream()
- .filter(st -> st.getName().equals("set-originator-id-to-advertizer-router-id")).findFirst().get();
- RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
- new AttributesBuilder().build());
- RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
- this.baseAttributes,
- IPV4UNICAST.class,
- this.exportParameters,
- attributeContainer,
- statement);
-
- assertEquals(this.multipleCom, result.getAttributes());
- }
-}
\ No newline at end of file
</statement>
</statements>
</policy-definition>
- <policy-definition>
- <name>set-originator-id-to-advertizer-router-id</name>
- <statements>
- <statement>
- <name>set-originator-id-to-advertizer-router-id</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">
- <set-originator-id-to-advertizer-router-id xmlns="urn:opendaylight:params:xml:ns:yang:odl:bgp:default:policy"/>
- </bgp-actions>
- </actions>
- </statement>
- </statements>
- </policy-definition>
- <policy-definition>
- <name>set-local-address-as-next-hop</name>
- <statements>
- <statement>
- <name>set-local-address-as-next-hop</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">
- <set-local-address-as-next-hop xmlns="urn:opendaylight:params:xml:ns:yang:odl:bgp:default:policy"/>
- </bgp-actions>
- </actions>
- </statement>
- </statements>
- </policy-definition>
<policy-definition>
<name>vpn-non-member-test</name>
<statements>
@Override
public void refreshTable(final TablesKey tk, final PeerId peerId) {
- this.vpnTableRefresher.get(tk).refreshTable(tk, peerId);
+ final RibOutRefresh table = this.vpnTableRefresher.get(tk);
+ if (table != null) {
+ table.refreshTable(tk, peerId);
+ }
}
@Override