</config>
</transport>
</neighbor>
+ <neighbor>
+ <neighbor-address>192.0.2.5</neighbor-address>
+ <config>
+ <peer-group>/bgp/neighbors/neighbor/bgp/peer-groups/peer-group[peer-group-name="external-neighbor"]</peer-group>
+ <local-as>65001</local-as>
+ </config>
+ <transport>
+ <config>
+ <remote-port>179</remote-port>
+ <passive-mode>true</passive-mode>
+ </config>
+ </transport>
+ </neighbor>
<neighbor>
<neighbor-address>192.0.2.6</neighbor-address>
<config>
</afi-safi>
</afi-safis>
</peer-group>
+ <peer-group>
+ <peer-group-name>external-neighbor</peer-group-name>
+ <config>
+ <peer-type>EXTERNAL</peer-type>
+ <peer-as>65000</peer-as>
+ </config>
+ <afi-safis>
+ <afi-safi>
+ <afi-safi-name xmlns:x="http://openconfig.net/yang/bgp-types">x:IPV4-UNICAST</afi-safi-name>
+ </afi-safi>
+ <afi-safi>
+ <afi-safi-name xmlns:x="http://openconfig.net/yang/bgp-types">x:IPV6-UNICAST</afi-safi-name>
+ </afi-safi>
+ <afi-safi>
+ <afi-safi-name xmlns:x="http://openconfig.net/yang/bgp-types">x:IPV4-LABELLED-UNICAST</afi-safi-name>
+ </afi-safi>
+ <afi-safi>
+ <afi-safi-name xmlns:x="http://openconfig.net/yang/bgp-types">x:IPV6-LABELLED-UNICAST</afi-safi-name>
+ </afi-safi>
+ <afi-safi>
+ <afi-safi-name xmlns:x="http://openconfig.net/yang/bgp-types">x:L3VPN-IPV4-UNICAST</afi-safi-name>
+ </afi-safi>
+ <afi-safi>
+ <afi-safi-name xmlns:x="http://openconfig.net/yang/bgp-types">x:L3VPN-IPV6-UNICAST</afi-safi-name>
+ </afi-safi>
+ <afi-safi>
+ <afi-safi-name xmlns:x="http://openconfig.net/yang/bgp-types">x:L2VPN-EVPN</afi-safi-name>
+ </afi-safi>
+ <afi-safi>
+ <afi-safi-name>LINKSTATE</afi-safi-name>
+ </afi-safi>
+ <afi-safi>
+ <afi-safi-name>IPV4-FLOW</afi-safi-name>
+ </afi-safi>
+ <afi-safi>
+ <afi-safi-name>IPV6-FLOW</afi-safi-name>
+ </afi-safi>
+ <afi-safi>
+ <afi-safi-name>IPV4-L3VPN-FLOW</afi-safi-name>
+ </afi-safi>
+ <afi-safi>
+ <afi-safi-name>IPV6-L3VPN-FLOW</afi-safi-name>
+ </afi-safi>
+ </afi-safis>
+ </peer-group>
</peer-groups>
</bgp>
</protocol>
<actions>
<bgp-actions xmlns="http://openconfig.net/yang/bgp-policy">
<non-transitive-attributes-filter xmlns="urn:opendaylight:params:xml:ns:yang:odl:bgp:default:policy"/>
+ <local-as-path-prepend xmlns="urn:opendaylight:params:xml:ns:yang:odl:bgp:default:policy"/>
</bgp-actions>
</actions>
</statement>
<actions>
<bgp-actions xmlns="http://openconfig.net/yang/bgp-policy">
<non-transitive-attributes-filter xmlns="urn:opendaylight:params:xml:ns:yang:odl:bgp:default:policy"/>
+ <local-as-path-prepend xmlns="urn:opendaylight:params:xml:ns:yang:odl:bgp:default:policy"/>
<set-as-path-prepend/>
</bgp-actions>
</actions>
}
}
+ augment /rpol:routing-policy/rpol:policy-definitions/rpol:policy-definition/rpol:statements/rpol:statement/rpol:actions/bgp-pol: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 {
ext:augment-identifier set-cluster-id-prepend;
container set-cluster-id-prepend {
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.openconfig.routing.policy.statement.actions.AsPathPrepend;
+import org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.actions.LocalAsPathPrependHandler;
import org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.actions.NonTransitiveAttributesFilterHandler;
import org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.actions.SetClusterIdPrependHandler;
import org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.actions.SetCommunityHandler;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetAsPathPrepend;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetCommunity;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetExtCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.LocalAsPathPrepend;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.MatchBgpNeighborCondition;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.MatchClusterIdSetCondition;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.MatchOriginatorIdSetCondition;
@Override
protected synchronized List<AutoCloseable> startImpl(final StatementRegistryProvider provider) {
- final List<AutoCloseable> registration = new ArrayList<>(13);
+ final List<AutoCloseable> registration = new ArrayList<>(14);
registerActions(provider, registration);
registerConditions(provider, registration);
return registration;
private void registerActions(final StatementRegistryProvider provider, final List<AutoCloseable> registration) {
registration.add(provider.registerBgpActionPolicy(SetAsPathPrepend.class, new AsPathPrepend()));
+ registration.add(provider.registerBgpActionAugmentationPolicy(LocalAsPathPrepend.class,
+ new LocalAsPathPrependHandler()));
+
registration.add(provider.registerBgpActionPolicy(SetCommunity.class,
new SetCommunityHandler(this.dataBroker)));
--- /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 java.util.ArrayList;
+import java.util.List;
+import org.opendaylight.protocol.util.Values;
+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.rev171207.path.attributes.Attributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder;
+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.Segments;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.SegmentsBuilder;
+
+class AbstractPrependAsPath {
+
+ final Attributes prependAS(final Attributes attributes, final AsNumber as) {
+ final List<Segments> oldSegments = attributes.getAsPath().getSegments();
+ /*
+ * We need to check the first segment.
+ * If it has as-set then new as-sequence with local AS is prepended.
+ * If it has as-sequence, we may add local AS when it has less than 255 elements.
+ * Otherwise we need to create new as-sequence for local AS.
+ */
+ final ArrayList<AsNumber> newAsSequence = new ArrayList<>();
+ newAsSequence.add(new AsNumber(as));
+
+ List<Segments> newSegments = new ArrayList<>();
+ if (oldSegments == null || oldSegments.isEmpty()) {
+ newSegments = new ArrayList<>();
+ newSegments.add(new SegmentsBuilder().setAsSequence(newAsSequence).build());
+ } else {
+ final Segments firstSegment = oldSegments.remove(0);
+ final List<AsNumber> firstAsSequence = firstSegment.getAsSequence();
+ if (firstAsSequence != null && firstAsSequence.size() < Values.UNSIGNED_BYTE_MAX_VALUE) {
+ newAsSequence.addAll(firstAsSequence);
+ newSegments.add(new SegmentsBuilder().setAsSequence(newAsSequence).build());
+ } else {
+ newSegments.add(new SegmentsBuilder().setAsSequence(newAsSequence).build());
+ newSegments.add(firstSegment);
+ }
+ newSegments.addAll(oldSegments);
+ }
+ return new AttributesBuilder(attributes).setAsPath(new AsPathBuilder()
+ .setSegments(newSegments).build()).build();
+ }
+}
package org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.actions;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.RouteEntryBaseAttributes;
import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.action.BgpActionPolicy;
import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryImportParameters;
-import org.opendaylight.protocol.util.Values;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetAsPathPrepend;
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.rev171207.path.attributes.Attributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder;
-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.Segments;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.SegmentsBuilder;
/**
* Prepend local AS, one time(n times not supported yet).
*/
-public final class AsPathPrepend implements BgpActionPolicy<SetAsPathPrepend> {
+public final class AsPathPrepend extends AbstractPrependAsPath implements BgpActionPolicy<SetAsPathPrepend> {
@Override
public Attributes applyImportAction(
final RouteEntryBaseAttributes routeEntryInfo,
final BGPRouteEntryExportParameters exportParameters,
final Attributes attributes,
final SetAsPathPrepend actions) {
-
- final List<Segments> oldSegments = attributes.getAsPath().getSegments();
- /*
- * We need to check the first segment.
- * If it has as-set then new as-sequence with local AS is prepended.
- * If it has as-sequence, we may add local AS when it has less than 255 elements.
- * Otherwise we need to create new as-sequence for local AS.
- */
- final ArrayList<AsNumber> newAsSequence = new ArrayList<>();
- newAsSequence.add(new AsNumber(routeEntryInfo.getLocalAs()));
-
- List<Segments> newSegments = new ArrayList<>();
- if (oldSegments == null || oldSegments.isEmpty()) {
- newSegments = Collections.singletonList(new SegmentsBuilder().setAsSequence(newAsSequence).build());
- } else {
- final Segments firstSegment = oldSegments.remove(0);
- final List<AsNumber> firstAsSequence = firstSegment.getAsSequence();
- if (firstAsSequence != null && firstAsSequence.size() < Values.UNSIGNED_BYTE_MAX_VALUE) {
- newAsSequence.addAll(firstAsSequence);
- newSegments.add(new SegmentsBuilder().setAsSequence(newAsSequence).build());
- } else {
- newSegments.add(new SegmentsBuilder().setAsSequence(newAsSequence).build());
- newSegments.add(firstSegment);
- }
- newSegments.addAll(oldSegments);
- }
- return new AttributesBuilder(attributes).setAsPath(new AsPathBuilder()
- .setSegments(newSegments).build()).build();
+ return prependAS(attributes, new AsNumber(routeEntryInfo.getLocalAs()));
}
}
\ 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.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.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.rev171207.path.attributes.Attributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.LocalAsPathPrepend;
+
+public final class LocalAsPathPrependHandler extends AbstractPrependAsPath
+ implements BgpActionAugPolicy<LocalAsPathPrepend> {
+ @Override
+ public Attributes applyImportAction(
+ final RouteEntryBaseAttributes routeEntryInfo,
+ final BGPRouteEntryImportParameters parameters,
+ final Attributes attributes,
+ final LocalAsPathPrepend actions) {
+ if (parameters.getFromPeerLocalAs() != null) {
+ return prependAS(attributes, parameters.getFromPeerLocalAs());
+ }
+ return attributes;
+ }
+
+ @Override
+ public Attributes applyExportAction(
+ final RouteEntryBaseAttributes routeEntryInfo,
+ final BGPRouteEntryExportParameters parameters,
+ final Attributes attributes,
+ final LocalAsPathPrepend actions) {
+ if (parameters.getToPeerLocalAs() != null) {
+ return prependAS(attributes, parameters.getToPeerLocalAs());
+ }
+ return attributes;
+ }
+}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
public final class ExportAttributeTestUtil {
- public static final long LOCAL_AS = 8;
+ public static final long REMOTE_AS = 8;
+ public static final AsNumber LOCAL_AS = new AsNumber(65L);
public static final Ipv4Address IPV4 = new Ipv4Address("1.2.3.4");
public static final ClusterIdentifier CLUSTER = new ClusterIdentifier(IPV4);
private static List<Segments> createSequenceWithLocalAs() {
return Collections.singletonList(new SegmentsBuilder()
- .setAsSequence(Collections.singletonList(new AsNumber(LOCAL_AS))).build());
+ .setAsSequence(Arrays.asList(new AsNumber(LOCAL_AS), new AsNumber(REMOTE_AS))).build());
}
}
import static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.ExportAttributeTestUtil.createInputWithOriginator;
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 static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.ImportAttributeTestUtil.AS;
+import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
final Statement statement = getStatementAndSetToRole("to-external", PeerRole.Ebgp);
final Attributes expectedOutput = createPathInputWithAs();
- final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(createPathInput(null));
+ final RouteAttributeContainer attributeContainer
+ = routeAttributeContainerFalse(createPathInput(Collections.emptyList()));
assertApplyExportStatement(statement, PeerRole.Ebgp, attributeContainer, expectedOutput);
assertApplyExportStatement(statement, PeerRole.Ibgp, attributeContainer, expectedOutput);
private Statement getStatementAndSetToRole(final String statementName, final PeerRole toPeerRole) {
doReturn(toPeerRole).when(this.exportParameters).getToPeerRole();
+ doReturn(AS).when(this.exportParameters).getToPeerLocalAs();
return this.defaultExportStatements.stream()
.filter(st -> st.getName().equals(statementName)).findFirst().get();
}
package org.opendaylight.protocol.bgp.openconfig.routing.policy.statement;
import java.util.Collections;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
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.rev171207.path.attributes.Attributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder;
+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.ClusterIdBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.LocalPrefBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.MultiExitDiscBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Origin;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.OriginBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.OriginatorIdBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.SegmentsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder;
public final class ImportAttributeTestUtil {
+ static final AsNumber AS = new AsNumber(65L);
+
private ImportAttributeTestUtil() {
throw new UnsupportedOperationException();
}
// origin pref
attBuilder.setOrigin(createOrigin());
+ // as path
+ attBuilder.setAsPath(new AsPathBuilder().build());
+
// multi-exit-disc pref
attBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed(0L).build());
return attBuilder.build();
final AttributesBuilder attBuilder = new AttributesBuilder();
attBuilder.setCNextHop(createNexHop());
attBuilder.setOrigin(createOrigin());
+ attBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.singletonList(new SegmentsBuilder()
+ .setAsSequence(Collections.singletonList(AS)).build())).build());
return attBuilder.build();
}
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 static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.ImportAttributeTestUtil.AS;
import java.util.List;
import org.junit.Before;
final Attributes attExpected) {
doReturn(fromPeerRole).when(this.importParameters).getFromPeerRole();
+ doReturn(AS).when(this.importParameters).getFromPeerLocalAs();
RouteAttributeContainer result = this.statementRegistry.applyImportStatement(
this.baseAttributes,
</conditions>
<actions>
<bgp-actions xmlns="http://openconfig.net/yang/bgp-policy">
- <non-transitive-attributes-filter
- xmlns="urn:opendaylight:params:xml:ns:yang:odl:bgp:default:policy"/>
+ <non-transitive-attributes-filter xmlns="urn:opendaylight:params:xml:ns:yang:odl:bgp:default:policy"/>
+ <local-as-path-prepend xmlns="urn:opendaylight:params:xml:ns:yang:odl:bgp:default:policy"/>
</bgp-actions>
</actions>
</statement>
</conditions>
<actions>
<bgp-actions xmlns="http://openconfig.net/yang/bgp-policy">
- <non-transitive-attributes-filter
- xmlns="urn:opendaylight:params:xml:ns:yang:odl:bgp:default:policy"/>
+ <non-transitive-attributes-filter xmlns="urn:opendaylight:params:xml:ns:yang:odl:bgp:default:policy"/>
+ <local-as-path-prepend xmlns="urn:opendaylight:params:xml:ns:yang:odl:bgp:default:policy"/>
<set-as-path-prepend/>
</bgp-actions>
</actions>
import org.opendaylight.protocol.bgp.rib.spi.Peer;
import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
+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.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.types.rev130919.ClusterIdentifier;
return this.fromPeer.getClusterId();
}
+ @Override
+ public AsNumber getFromPeerLocalAs() {
+ return this.fromPeer.getLocalAs();
+ }
+
@Override
public PeerRole getToPeerRole() {
return this.toPeer.getRole();
}
+ @Override
+ public AsNumber getToPeerLocalAs() {
+ return this.toPeer.getLocalAs();
+ }
+
@Override
public PeerId getToPeerId() {
return this.toPeer.getPeerId();
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
import org.opendaylight.protocol.bgp.rib.spi.state.BGPTimersState;
import org.opendaylight.protocol.bgp.rib.spi.state.BGPTransportState;
import org.opendaylight.protocol.concepts.AbstractRegistration;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.SendReceive;
return null;
}
+ @Override
+ public AsNumber getLocalAs() {
+ return null;
+ }
+
@Override
public KeyedInstanceIdentifier<Tables, TablesKey> getRibOutIId(final TablesKey tablesKey) {
return this.tablesIId.getUnchecked(tablesKey);
public ClusterIdentifier getFromClusterId() {
return getClusterId();
}
+
+ @Override
+ public AsNumber getFromPeerLocalAs() {
+ return null;
+ }
}
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
-import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
import org.opendaylight.protocol.bgp.rib.spi.state.BGPTransportState;
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.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv4.prefixes.DestinationIpv4Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv4.prefixes.destination.ipv4.Ipv4Prefixes;
BGPSessionListener, Peer, TransactionChainListener {
private static final Logger LOG = LoggerFactory.getLogger(BGPPeer.class);
private final ClusterIdentifier clusterId;
+ private final AsNumber localAs;
private Set<TablesKey> tables = Collections.emptySet();
private final RIB rib;
final RIB rib,
final PeerRole role,
final ClusterIdentifier clusterId,
+ final AsNumber localAs,
final RpcProviderRegistry rpcRegistry,
final Set<TablesKey> afiSafisAdvertized,
final Set<TablesKey> afiSafisGracefulAdvertized) {
this.peerRole = role;
this.rib = requireNonNull(rib);
this.clusterId = clusterId;
+ this.localAs = localAs;
this.name = Ipv4Util.toStringIP(neighborAddress);
this.rpcRegistry = rpcRegistry;
this.peerIId = getInstanceIdentifier().child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns
final RpcProviderRegistry rpcRegistry,
final Set<TablesKey> afiSafisAdvertized,
final Set<TablesKey> afiSafisGracefulAdvertized) {
- this(neighborAddress, null, rib, role, null, rpcRegistry, afiSafisAdvertized,
+ this(neighborAddress, null, rib, role, null, null, rpcRegistry, afiSafisAdvertized,
afiSafisGracefulAdvertized);
}
return this.clusterId;
}
+ @Override
+ public AsNumber getLocalAs() {
+ return this.localAs;
+ }
+
+ @Override
+ public AsNumber getFromPeerLocalAs() {
+ return getLocalAs();
+ }
+
@Override
public KeyedInstanceIdentifier<Tables, TablesKey> getRibOutIId(final TablesKey tablesKey) {
return this.tablesIId.getUnchecked(tablesKey);
private static void validateAs(final AsNumber remoteAs, final Open openObj, final BGPSessionPreferences localPref)
throws BGPDocumentedException {
if (!remoteAs.equals(localPref.getExpectedRemoteAs())) {
- LOG.warn("Unexpected remote AS number. Expecting {}, got {}", remoteAs, localPref.getExpectedRemoteAs());
+ LOG.warn("Unexpected remote AS number. Expecting {}, got {}", localPref.getExpectedRemoteAs(), remoteAs);
throw new BGPDocumentedException("Peer AS number mismatch", BGPError.BAD_PEER_AS);
}
final Set<TablesKey> afiSafisAdvertized = OpenConfigMappingUtil
.toTableKey(afisSAfis.getAfiSafi(), tableTypeRegistry);
-
final PeerRole role = OpenConfigMappingUtil.toPeerRole(neighbor, peerGroup);
final ClusterIdentifier clusterId = OpenConfigMappingUtil
.getNeighborClusterIdentifier(neighbor.getConfig());
-
- this.bgpPeer = new BGPPeer(this.neighborAddress, peerGroupName, rib, role, clusterId,
- BgpPeer.this.rpcRegistry, afiSafisAdvertized, Collections.emptySet());
-
final List<BgpParameters> bgpParameters = getBgpParameters(afisSAfis, rib, tableTypeRegistry);
final KeyMapping keyMapping = OpenConfigMappingUtil.getNeighborKey(neighbor);
final IpAddress neighborLocalAddress = OpenConfigMappingUtil.getLocalAddress(neighbor.getTransport());
int hold = OpenConfigMappingUtil.getHoldTimer(neighbor, peerGroup);
- final AsNumber ribAs = rib.getLocalAs();
- final AsNumber neighborAs = OpenConfigMappingUtil.getPeerAs(neighbor, peerGroup, ribAs);
+ final AsNumber globalAs = rib.getLocalAs();
+ final AsNumber neighborRemoteAs = OpenConfigMappingUtil
+ .getRemotePeerAs(neighbor.getConfig(), peerGroup, globalAs);
+ final AsNumber neighborLocalAs = OpenConfigMappingUtil.getLocalPeerAs(neighbor.getConfig(), globalAs);
- this.prefs = new BGPSessionPreferences(ribAs, hold, rib.getBgpIdentifier(),
- neighborAs, bgpParameters, getPassword(keyMapping));
+ this.bgpPeer = new BGPPeer(this.neighborAddress, peerGroupName, rib, role, clusterId, neighborLocalAs,
+ BgpPeer.this.rpcRegistry, afiSafisAdvertized, Collections.emptySet());
+ this.prefs = new BGPSessionPreferences(neighborLocalAs, hold, rib.getBgpIdentifier(),
+ neighborRemoteAs, bgpParameters, getPassword(keyMapping));
this.activeConnection = OpenConfigMappingUtil.isActive(neighbor, peerGroup);
this.retryTimer = OpenConfigMappingUtil.getRetryTimer(neighbor, peerGroup);
this.dispatcher = rib.getDispatcher();
}
@Nullable
- private static AsNumber getPeerAs(final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp
+ private static AsNumber getRemotePeerAs(final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp
.rev151009.bgp.neighbor.group.Config config) {
if (config != null) {
final AsNumber peerAs = config.getPeerAs();
}
@Nonnull
- public static AsNumber getPeerAs(final Neighbor neighbor, final PeerGroup peerGroup, final AsNumber localAs) {
+ public static AsNumber getRemotePeerAs(final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009
+ .bgp.neighbor.group.Config config, final PeerGroup peerGroup, final AsNumber localAs) {
AsNumber neighborAs = null;
if (peerGroup != null) {
- neighborAs = getPeerAs(peerGroup.getConfig());
+ neighborAs = getRemotePeerAs(peerGroup.getConfig());
}
if (neighborAs == null) {
- neighborAs = getPeerAs(neighbor.getConfig());
+ neighborAs = getRemotePeerAs(config);
}
if (neighborAs == null) {
}
@Nonnull
+ public static AsNumber getLocalPeerAs(@Nullable final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp
+ .rev151009.bgp.neighbor.group.Config config, @Nonnull final AsNumber globalAs) {
+ if (config != null) {
+ final AsNumber peerAs = config.getLocalAs();
+ if (peerAs != null) {
+ return peerAs;
+ }
+ }
+ return globalAs;
+ }
+
public static int getRetryTimer(final Neighbor neighbor, final PeerGroup peerGroup) {
Integer retryTimer = null;
if (peerGroup != null) {
class AbstractConfig extends DefaultRibPoliciesMockTest {
protected static final AsNumber AS = new AsNumber(72L);
+ protected static final AsNumber lOCAL_AS = new AsNumber(73L);
protected static final RibId RIB_ID = new RibId("test");
static final TablesKey TABLES_KEY = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
@Mock
return new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.
ConfigBuilder()
.setPeerAs(AS)
+ .setLocalAs(lOCAL_AS)
.setPeerType(PeerType.INTERNAL)
.setAuthPassword(MD5_PASSWORD)
.setRouteFlapDamping(false)
= new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class);
private static final AsNumber AS = new AsNumber(72L);
+ private static final AsNumber GLOBAL_AS = new AsNumber(73L);
private static final List<AddressFamilies> FAMILIES;
private static final List<BgpTableType> TABLE_TYPES;
private static final List<AfiSafi> AFISAFIS = new ArrayList<>();
}
@Test
- public void testGetPeerAs() {
- assertEquals(AS, OpenConfigMappingUtil.getPeerAs(NEIGHBOR, null, null));
- assertEquals(AS, OpenConfigMappingUtil.getPeerAs(new NeighborBuilder().build(), null, this.rib.getLocalAs()));
+ public void testGetRemotePeerAs() {
+ final ConfigBuilder configBuilder = new ConfigBuilder();
+ assertEquals(AS, OpenConfigMappingUtil.getRemotePeerAs(NEIGHBOR.getConfig(), null, null));
+ assertEquals(AS, OpenConfigMappingUtil.getRemotePeerAs(configBuilder.build(), null,
+ this.rib.getLocalAs()));
- assertEquals(AS, OpenConfigMappingUtil.getPeerAs(NEIGHBOR, new PeerGroupBuilder().build(), null));
- assertEquals(AS, OpenConfigMappingUtil.getPeerAs(new NeighborBuilder().build(), new PeerGroupBuilder().build(),
+ assertEquals(AS, OpenConfigMappingUtil.getRemotePeerAs(NEIGHBOR.getConfig(),
+ new PeerGroupBuilder().build(), null));
+ assertEquals(AS, OpenConfigMappingUtil.getRemotePeerAs(configBuilder.build(), new PeerGroupBuilder().build(),
this.rib.getLocalAs()));
- assertEquals(AS, OpenConfigMappingUtil.getPeerAs(null, new PeerGroupBuilder()
+ assertEquals(AS, OpenConfigMappingUtil.getRemotePeerAs(null, new PeerGroupBuilder()
.setConfig(new ConfigBuilder().setPeerAs(AS).build()).build(), null));
}
+ @Test
+ public void testGetLocalPeerAs() {
+ final ConfigBuilder configBuilder = new ConfigBuilder();
+ assertEquals(GLOBAL_AS,OpenConfigMappingUtil.getLocalPeerAs(null, GLOBAL_AS));
+ assertEquals(AS, OpenConfigMappingUtil.getLocalPeerAs(configBuilder.setLocalAs(AS).build(), GLOBAL_AS));
+ }
+
@Test
public void testIsActive() {
final TransportBuilder builder = new TransportBuilder();
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+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.multiprotocol.rev171207.SendReceive;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole;
*/
@Nullable
ClusterIdentifier getClusterId();
+
+ /**
+ * Returns Local AS.
+ *
+ * @return AS
+ */
+ @Nullable
+ AsNumber getLocalAs();
}
package org.opendaylight.protocol.bgp.rib.spi.policy;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+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.rev171207.PeerId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole;
*/
@Nonnull
PeerRole getToPeerRole();
+
+ /**
+ * Peer local AS of Peer route entry destiny.
+ *
+ * @return peer Local AS of destiny Peer
+ */
+ @Nullable
+ AsNumber getToPeerLocalAs();
}
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+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.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.types.rev130919.ClusterIdentifier;
*/
@Nullable
ClusterIdentifier getFromClusterId();
+
+ /**
+ * Peer local AS of route entry announcer.
+ *
+ * @return peer Local AS
+ */
+ @Nullable
+ AsNumber getFromPeerLocalAs();
}