*/
package org.opendaylight.protocol.bgp.rib.impl;
+import static org.opendaylight.protocol.bgp.rib.impl.AdjRibInWriter.isAnnounceNone;
+import static org.opendaylight.protocol.bgp.rib.impl.AdjRibInWriter.isLearnNone;
+
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.base.Preconditions;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
+import java.util.stream.Collectors;
import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.controller.config.yang.bgp.rib.impl.BGPPeerRuntimeMXBean;
import org.opendaylight.controller.config.yang.bgp.rib.impl.BGPPeerRuntimeRegistration;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.RouteRefresh;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.add.path.capability.AddressFamilies;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlri;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev160322.PeerContext;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.SimpleRoutingPolicy;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.PeerKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
private final RpcProviderRegistry rpcRegistry;
private RoutedRpcRegistration<BgpPeerRpcService> rpcRegistration;
private final PeerRole peerRole;
+ private final Optional<SimpleRoutingPolicy> simpleRoutingPolicy;
- public BGPPeer(final String name, final RIB rib, final PeerRole role, final RpcProviderRegistry rpcRegistry) {
+ public BGPPeer(final String name, final RIB rib, final PeerRole role, final SimpleRoutingPolicy peerStatus, final RpcProviderRegistry rpcRegistry) {
this.peerRole = role;
+ this.simpleRoutingPolicy = Optional.ofNullable(peerStatus);
this.rib = Preconditions.checkNotNull(rib);
this.name = name;
this.chain = rib.createPeerChain(this);
- this.ribWriter = AdjRibInWriter.create(rib.getYangRibId(), role, this.chain);
+ this.ribWriter = AdjRibInWriter.create(rib.getYangRibId(), this.peerRole, this.simpleRoutingPolicy, this.chain);
this.rpcRegistry = rpcRegistry;
}
+ public BGPPeer(final String name, final RIB rib, final PeerRole role, final RpcProviderRegistry rpcRegistry) {
+ this(name, rib, role, null, rpcRegistry);
+ }
+
@Override
public synchronized void close() {
releaseConnection();
this.rawIdentifier = InetAddresses.forString(session.getBgpId().getValue()).getAddress();
final PeerId peerId = RouterIds.createPeerId(session.getBgpId());
- final YangInstanceIdentifier peerIId = this.rib.getYangRibId().node(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.Peer.QNAME).node(IdentifierUtils.domPeerId(peerId));
- createAdjRibOutListener(peerId);
- this.effRibInWriter = EffectiveRibInWriter.create(this.rib.getService(), this.rib.createPeerChain(this), peerIId, ((RIBImpl)this.rib).getImportPolicyPeerTracker(),
- this.rib.getRibSupportContext(), this.peerRole);
- this.ribWriter = this.ribWriter.transform(peerId, this.rib.getRibSupportContext(), this.tables, addPathTablesType, false);
+
+ this.tables.addAll(this.session.getAdvertisedTableTypes().stream().map(t -> new TablesKey(t.getAfi(), t.getSafi())).collect(Collectors.toList()));
+ final boolean announceNone = isAnnounceNone(this.simpleRoutingPolicy);
+ if(!announceNone) {
+ createAdjRibOutListener(peerId);
+ }
+ addBgp4Support(peerId, announceNone);
+
+ if(!isLearnNone(this.simpleRoutingPolicy)) {
+ final YangInstanceIdentifier peerIId = this.rib.getYangRibId().node(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.Peer.QNAME).node(IdentifierUtils.domPeerId(peerId));
+ this.effRibInWriter = EffectiveRibInWriter.create(this.rib.getService(), this.rib.createPeerChain(this), peerIId, ((RIBImpl) this.rib).getImportPolicyPeerTracker(),
+ this.rib.getRibSupportContext(), this.peerRole);
+ }
+ this.ribWriter = this.ribWriter.transform(peerId, this.rib.getRibSupportContext(), this.tables, addPathTablesType);
this.sessionEstablishedCounter++;
if (this.registrator != null) {
this.runtimeReg = this.registrator.register(this);
}
private void createAdjRibOutListener(final PeerId peerId) {
- for (final BgpTableType t : this.session.getAdvertisedTableTypes()) {
- final TablesKey key = new TablesKey(t.getAfi(), t.getSafi());
- if (this.tables.add(key)) {
- createAdjRibOutListener(peerId, key, true);
- }
- }
-
- addBgp4Support(peerId);
+ this.tables.forEach(key->createAdjRibOutListener(peerId, key, true));
}
//try to add a support for old-school BGP-4, if peer did not advertise IPv4-Unicast MP capability
- private void addBgp4Support(final PeerId peerId) {
+ private void addBgp4Support(final PeerId peerId, final boolean announceNone) {
final TablesKey key = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
- if (this.tables.add(key)) {
+ this.tables.add(key);
+ if (!announceNone) {
createAdjRibOutListener(peerId, key, false);
}
}
LOG.error("Transaction chain failed.", cause);
this.chain.close();
this.chain = this.rib.createPeerChain(this);
- this.ribWriter = AdjRibInWriter.create(this.rib.getYangRibId(), this.peerRole, this.chain);
+ this.ribWriter = AdjRibInWriter.create(this.rib.getYangRibId(), this.peerRole, this.simpleRoutingPolicy, this.chain);
releaseConnection();
}