package org.opendaylight.protocol.bgp.rib.impl.config;
-import static org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil.getHoldTimer;
-import static org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil.getPeerAs;
-import static org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil.getSimpleRoutingPolicy;
+import static java.util.Objects.requireNonNull;
-import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.Futures;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
+import java.util.Optional;
import java.util.Set;
import javax.annotation.concurrent.GuardedBy;
-import org.opendaylight.controller.config.yang.bgp.rib.impl.BGPPeerRuntimeMXBean;
-import org.opendaylight.controller.config.yang.bgp.rib.impl.BgpPeerState;
-import org.opendaylight.controller.config.yang.bgp.rib.impl.BgpSessionState;
+import org.apache.commons.lang3.StringUtils;
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
-import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
import org.opendaylight.protocol.bgp.parser.BgpExtendedMessageUtil;
import org.opendaylight.protocol.bgp.parser.spi.MultiprotocolCapabilitiesUtil;
import org.opendaylight.protocol.bgp.rib.impl.BGPPeer;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
+import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
-import org.opendaylight.protocol.bgp.rib.impl.spi.BgpDeployer.WriteConfiguration;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerState;
import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerStateConsumer;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.AfiSafis;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.Config;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.peer.group.PeerGroup;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.Bgp;
+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.message.rev130919.open.message.BgpParameters;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.BgpParametersBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.OptionalCapabilities;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.OptionalCapabilitiesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.CParametersBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapabilityBuilder;
-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.CParameters1;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.CParameters1Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.AddPathCapabilityBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.MultiprotocolCapabilityBuilder;
-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.rib.rev130925.rib.TablesKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParametersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.OptionalCapabilities;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.OptionalCapabilitiesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParametersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapabilityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.AddPathCapabilityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.MultiprotocolCapabilityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.add.path.capability.AddressFamilies;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.NeighborPeerGroupConfig;
+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.rib.TablesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.osgi.framework.ServiceRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
-public final class BgpPeer implements PeerBean, BGPPeerStateConsumer, BGPPeerRuntimeMXBean {
+public final class BgpPeer implements PeerBean, BGPPeerStateConsumer {
private static final Logger LOG = LoggerFactory.getLogger(BgpPeer.class);
private final RpcProviderRegistry rpcRegistry;
+ @GuardedBy("this")
private ServiceRegistration<?> serviceRegistration;
+ @GuardedBy("this")
private Neighbor currentConfiguration;
+ @GuardedBy("this")
private BgpPeerSingletonService bgpPeerSingletonService;
public BgpPeer(final RpcProviderRegistry rpcRegistry) {
this.rpcRegistry = rpcRegistry;
}
- @Override
- public void start(final RIB rib, final Neighbor neighbor, final BGPTableTypeRegistryConsumer tableTypeRegistry,
- final WriteConfiguration configurationWriter) {
- Preconditions.checkState(this.bgpPeerSingletonService == null, "Previous peer instance was not closed.");
- this.bgpPeerSingletonService = new BgpPeerSingletonService(rib, neighbor, tableTypeRegistry, configurationWriter);
- this.currentConfiguration = neighbor;
- }
-
- @Override
- public void restart(final RIB rib, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
- Preconditions.checkState(this.currentConfiguration != null);
- start(rib, this.currentConfiguration, tableTypeRegistry, null);
- }
-
- @Override
- public void close() {
- closeSingletonService();
- if (this.serviceRegistration != null) {
- this.serviceRegistration.unregister();
- this.serviceRegistration = null;
- }
- }
-
- @Override
- public ListenableFuture<Void> closeServiceInstance() {
- if (this.bgpPeerSingletonService != null) {
- return this.bgpPeerSingletonService.closeServiceInstance();
- }
- return Futures.immediateFuture(null);
- }
-
- private void closeSingletonService() {
- try {
- this.bgpPeerSingletonService.close();
- this.bgpPeerSingletonService = null;
- } catch (final Exception e) {
- LOG.warn("Failed to close peer instance", e);
- }
- }
-
- @Override
- public Boolean containsEqualConfiguration(final Neighbor neighbor) {
- final AfiSafis actAfiSafi = this.currentConfiguration.getAfiSafis();
- final AfiSafis extAfiSafi = neighbor.getAfiSafis();
- final List<AfiSafi> actualSafi = actAfiSafi != null ? actAfiSafi.getAfiSafi() : Collections.emptyList();
- final List<AfiSafi> extSafi = extAfiSafi != null ? extAfiSafi.getAfiSafi() : Collections.emptyList();
- return actualSafi.containsAll(extSafi) && extSafi.containsAll(actualSafi)
- && Objects.equals(this.currentConfiguration.getConfig(), neighbor.getConfig())
- && Objects.equals(this.currentConfiguration.getNeighborAddress(), neighbor.getNeighborAddress())
- && Objects.equals(this.currentConfiguration.getAddPaths(),neighbor.getAddPaths())
- && Objects.equals(this.currentConfiguration.getApplyPolicy(), neighbor.getApplyPolicy())
- && Objects.equals(this.currentConfiguration.getAsPathOptions(), neighbor.getAsPathOptions())
- && Objects.equals(this.currentConfiguration.getEbgpMultihop(), neighbor.getEbgpMultihop())
- && Objects.equals(this.currentConfiguration.getGracefulRestart(), neighbor.getGracefulRestart())
- && Objects.equals(this.currentConfiguration.getErrorHandling(), neighbor.getErrorHandling())
- && Objects.equals(this.currentConfiguration.getLoggingOptions(), neighbor.getLoggingOptions())
- && Objects.equals(this.currentConfiguration.getRouteReflector(), neighbor.getRouteReflector())
- && Objects.equals(this.currentConfiguration.getState(), neighbor.getState())
- && Objects.equals(this.currentConfiguration.getTimers(), neighbor.getTimers())
- && Objects.equals(this.currentConfiguration.getTransport(), neighbor.getTransport());
- }
-
- private static List<BgpParameters> getBgpParameters(final Neighbor neighbor, final RIB rib,
+ private static List<BgpParameters> getBgpParameters(final AfiSafis afiSafis, final RIB rib,
final BGPTableTypeRegistryConsumer tableTypeRegistry) {
final List<BgpParameters> tlvs = new ArrayList<>();
final List<OptionalCapabilities> caps = new ArrayList<>();
caps.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().setAs4BytesCapability(
new As4BytesCapabilityBuilder().setAsNumber(rib.getLocalAs()).build()).build()).build());
- caps.add(new OptionalCapabilitiesBuilder().setCParameters(BgpExtendedMessageUtil.EXTENDED_MESSAGE_CAPABILITY).build());
- caps.add(new OptionalCapabilitiesBuilder().setCParameters(MultiprotocolCapabilitiesUtil.RR_CAPABILITY).build());
+ caps.add(new OptionalCapabilitiesBuilder()
+ .setCParameters(BgpExtendedMessageUtil.EXTENDED_MESSAGE_CAPABILITY).build());
+ caps.add(new OptionalCapabilitiesBuilder()
+ .setCParameters(MultiprotocolCapabilitiesUtil.RR_CAPABILITY).build());
- final List<AfiSafi> afiSafi = OpenConfigMappingUtil.getAfiSafiWithDefault(neighbor.getAfiSafis(), false);
- final List<AddressFamilies> addPathCapability = OpenConfigMappingUtil.toAddPathCapability(afiSafi, tableTypeRegistry);
+ final List<AfiSafi> afiSafi = OpenConfigMappingUtil.getAfiSafiWithDefault(afiSafis, false);
+ final List<AddressFamilies> addPathCapability = OpenConfigMappingUtil
+ .toAddPathCapability(afiSafi, tableTypeRegistry);
if (!addPathCapability.isEmpty()) {
- caps.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(CParameters1.class,
- new CParameters1Builder().setAddPathCapability(
- new AddPathCapabilityBuilder().setAddressFamilies(addPathCapability).build()).build()).build()).build());
+ caps.add(new OptionalCapabilitiesBuilder()
+ .setCParameters(new CParametersBuilder().addAugmentation(CParameters1.class,
+ new CParameters1Builder().setAddPathCapability(
+ new AddPathCapabilityBuilder()
+ .setAddressFamilies(addPathCapability).build()).build()).build()).build());
}
final List<BgpTableType> tableTypes = OpenConfigMappingUtil.toTableTypes(afiSafi, tableTypeRegistry);
for (final BgpTableType tableType : tableTypes) {
if (!rib.getLocalTables().contains(tableType)) {
- LOG.info("RIB instance does not list {} in its local tables. Incoming data will be dropped.", tableType);
+ LOG.info("RIB instance does not list {} " +
+ "in its local tables. Incoming data will be dropped.", tableType);
}
caps.add(new OptionalCapabilitiesBuilder().setCParameters(
if (key != null) {
return Optional.of(Iterables.getOnlyElement(key.values()));
}
- return Optional.absent();
+ return Optional.empty();
}
@Override
- public BgpPeerState getBgpPeerState() {
- return this.bgpPeerSingletonService.getPeer().getBgpPeerState();
+ public synchronized void start(final RIB rib, final Neighbor neighbor, final InstanceIdentifier<Bgp> bgpIid,
+ final PeerGroupConfigLoader peerGroupLoader, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
+ Preconditions.checkState(this.bgpPeerSingletonService == null,
+ "Previous peer instance was not closed.");
+
+ this.bgpPeerSingletonService = new BgpPeerSingletonService(rib, neighbor, bgpIid, peerGroupLoader,
+ tableTypeRegistry);
+ this.currentConfiguration = neighbor;
}
@Override
- public BgpSessionState getBgpSessionState() {
- return this.bgpPeerSingletonService.getPeer().getBgpSessionState();
+ public synchronized void restart(final RIB rib, final InstanceIdentifier<Bgp> bgpIid,
+ final PeerGroupConfigLoader peerGroupLoader, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
+ Preconditions.checkState(this.currentConfiguration != null);
+ start(rib, this.currentConfiguration, bgpIid, peerGroupLoader, tableTypeRegistry);
}
@Override
- public void resetSession() {
- this.bgpPeerSingletonService.getPeer().resetSession();
+ public synchronized void close() {
+ if (this.serviceRegistration != null) {
+ this.serviceRegistration.unregister();
+ this.serviceRegistration = null;
+ }
+ }
+
+ @Override
+ public synchronized void instantiateServiceInstance() {
+ if (this.bgpPeerSingletonService != null) {
+ this.bgpPeerSingletonService.instantiateServiceInstance();
+ }
+ }
+
+ @Override
+ public synchronized ListenableFuture<Void> closeServiceInstance() {
+ if (this.bgpPeerSingletonService != null) {
+ final ListenableFuture<Void> fut = this.bgpPeerSingletonService.closeServiceInstance();
+ this.bgpPeerSingletonService = null;
+ return fut;
+ }
+ return Futures.immediateFuture(null);
}
@Override
- public void resetStats() {
- this.bgpPeerSingletonService.getPeer().resetStats();
+ public synchronized Boolean containsEqualConfiguration(final Neighbor neighbor) {
+ if (this.currentConfiguration == null) {
+ return false;
+ }
+ final AfiSafis actAfiSafi = this.currentConfiguration.getAfiSafis();
+ final AfiSafis extAfiSafi = neighbor.getAfiSafis();
+ final List<AfiSafi> actualSafi = actAfiSafi != null ? actAfiSafi.getAfiSafi() : Collections.emptyList();
+ final List<AfiSafi> extSafi = extAfiSafi != null ? extAfiSafi.getAfiSafi() : Collections.emptyList();
+ return actualSafi.containsAll(extSafi) && extSafi.containsAll(actualSafi)
+ && Objects.equals(this.currentConfiguration.getConfig(), neighbor.getConfig())
+ && Objects.equals(this.currentConfiguration.getNeighborAddress(), neighbor.getNeighborAddress())
+ && Objects.equals(this.currentConfiguration.getAddPaths(), neighbor.getAddPaths())
+ && Objects.equals(this.currentConfiguration.getApplyPolicy(), neighbor.getApplyPolicy())
+ && Objects.equals(this.currentConfiguration.getAsPathOptions(), neighbor.getAsPathOptions())
+ && Objects.equals(this.currentConfiguration.getEbgpMultihop(), neighbor.getEbgpMultihop())
+ && Objects.equals(this.currentConfiguration.getGracefulRestart(), neighbor.getGracefulRestart())
+ && Objects.equals(this.currentConfiguration.getErrorHandling(), neighbor.getErrorHandling())
+ && Objects.equals(this.currentConfiguration.getLoggingOptions(), neighbor.getLoggingOptions())
+ && Objects.equals(this.currentConfiguration.getRouteReflector(), neighbor.getRouteReflector())
+ && Objects.equals(this.currentConfiguration.getState(), neighbor.getState())
+ && Objects.equals(this.currentConfiguration.getTimers(), neighbor.getTimers())
+ && Objects.equals(this.currentConfiguration.getTransport(), neighbor.getTransport());
}
@Override
- public BGPPeerState getPeerState() {
+ public synchronized BGPPeerState getPeerState() {
if (this.bgpPeerSingletonService == null) {
return null;
}
return this.bgpPeerSingletonService.getPeerState();
}
- void setServiceRegistration(final ServiceRegistration<?> serviceRegistration) {
+ synchronized void setServiceRegistration(final ServiceRegistration<?> serviceRegistration) {
this.serviceRegistration = serviceRegistration;
}
- private final class BgpPeerSingletonService implements BGPPeerStateConsumer, ClusterSingletonService,
- AutoCloseable {
- private final ServiceGroupIdentifier serviceGroupIdentifier;
- private final boolean activeConnection;
+ synchronized void removePeer(final BGPPeerRegistry bgpPeerRegistry) {
+ if (BgpPeer.this.currentConfiguration != null) {
+ bgpPeerRegistry.removePeer(BgpPeer.this.currentConfiguration.getNeighborAddress());
+ }
+ }
+
+ private final class BgpPeerSingletonService implements BGPPeerStateConsumer {
+ private boolean activeConnection;
private final BGPDispatcher dispatcher;
private final InetSocketAddress inetAddress;
private final int retryTimer;
private final KeyMapping keys;
- private final WriteConfiguration configurationWriter;
- private ClusterSingletonServiceRegistration registration;
+ private final InetSocketAddress localAddress;
private final BGPPeer bgpPeer;
private final IpAddress neighborAddress;
private final BGPSessionPreferences prefs;
private Future<Void> connection;
- @GuardedBy("this")
private boolean isServiceInstantiated;
- private BgpPeerSingletonService(final RIB rib, final Neighbor neighbor,
- final BGPTableTypeRegistryConsumer tableTypeRegistry, final WriteConfiguration configurationWriter) {
+ private BgpPeerSingletonService(final RIB rib, final Neighbor neighbor, final InstanceIdentifier<Bgp> bgpIid,
+ final PeerGroupConfigLoader peerGroupLoader, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
this.neighborAddress = neighbor.getNeighborAddress();
- final AfiSafis afisSAfis = Preconditions.checkNotNull(neighbor.getAfiSafis());
+
+ PeerGroup peerGroup = null;
+ String peerGroupName = null;
+ final Config neighborConfig = neighbor.getConfig();
+ if (neighborConfig != null) {
+ final NeighborPeerGroupConfig pgConfig = neighborConfig.getAugmentation(NeighborPeerGroupConfig.class);
+ if (pgConfig != null) {
+ peerGroupName = StringUtils.substringBetween(pgConfig.getPeerGroup(), "=\"", "\"");
+ peerGroup = peerGroupLoader.getPeerGroup(bgpIid, peerGroupName);
+ }
+ }
+ final AfiSafis afisSAfis;
+ if (peerGroup != null && peerGroup.getAfiSafis() != null) {
+ afisSAfis = peerGroup.getAfiSafis();
+ } else {
+ afisSAfis = requireNonNull(neighbor.getAfiSafis(), "Missing mandatory AFIs/SAFIs");
+ }
+
final Set<TablesKey> afiSafisAdvertized = OpenConfigMappingUtil
- .toTableKey(afisSAfis.getAfiSafi(), tableTypeRegistry);
- this.bgpPeer = new BGPPeer(Ipv4Util.toStringIP(this.neighborAddress), rib,
- OpenConfigMappingUtil.toPeerRole(neighbor), getSimpleRoutingPolicy(neighbor), BgpPeer.this.rpcRegistry,
- afiSafisAdvertized, Collections.emptySet());
- final List<BgpParameters> bgpParameters = getBgpParameters(neighbor, rib, tableTypeRegistry);
+ .toTableKey(afisSAfis.getAfiSafi(), tableTypeRegistry);
+ final PeerRole role = OpenConfigMappingUtil.toPeerRole(neighbor, peerGroup);
+ final ClusterIdentifier clusterId = OpenConfigMappingUtil
+ .getNeighborClusterIdentifier(neighbor.getConfig());
+ final List<BgpParameters> bgpParameters = getBgpParameters(afisSAfis, rib, tableTypeRegistry);
final KeyMapping keyMapping = OpenConfigMappingUtil.getNeighborKey(neighbor);
- this.prefs = new BGPSessionPreferences(rib.getLocalAs(), getHoldTimer(neighbor), rib.getBgpIdentifier(),
- getPeerAs(neighbor, rib), bgpParameters, getPassword(keyMapping));
- this.activeConnection = OpenConfigMappingUtil.isActive(neighbor);
+ final IpAddress neighborLocalAddress = OpenConfigMappingUtil.getLocalAddress(neighbor.getTransport());
+ int hold = OpenConfigMappingUtil.getHoldTimer(neighbor, peerGroup);
+ final AsNumber globalAs = rib.getLocalAs();
+ final AsNumber neighborRemoteAs = OpenConfigMappingUtil
+ .getRemotePeerAs(neighbor.getConfig(), peerGroup, globalAs);
+ final AsNumber neighborLocalAs = OpenConfigMappingUtil.getLocalPeerAs(neighbor.getConfig(), globalAs);
+
+ 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();
- this.inetAddress = Ipv4Util.toInetSocketAddress(this.neighborAddress, OpenConfigMappingUtil.getPort(neighbor));
- this.retryTimer = OpenConfigMappingUtil.getRetryTimer(neighbor);
- this.keys = keyMapping;
- this.configurationWriter = configurationWriter;
- this.serviceGroupIdentifier = rib.getRibIServiceGroupIdentifier();
- LOG.info("Peer Singleton Service {} registered", this.serviceGroupIdentifier.getValue());
- //this need to be always the last step
- this.registration = rib.registerClusterSingletonService(this);
- }
- @Override
- public void close() throws Exception {
- if (this.registration != null) {
- this.registration.close();
- this.registration = null;
+ final PortNumber port = OpenConfigMappingUtil.getPort(neighbor, peerGroup);
+ this.inetAddress = Ipv4Util.toInetSocketAddress(this.neighborAddress, port);
+ if (neighborLocalAddress != null) {
+ this.localAddress = Ipv4Util.toInetSocketAddress(neighborLocalAddress, port);
+ } else {
+ this.localAddress = null;
}
+ this.keys = keyMapping;
}
- @Override
- public synchronized void instantiateServiceInstance() {
+ private synchronized void instantiateServiceInstance() {
this.isServiceInstantiated = true;
- if(this.configurationWriter != null) {
- this.configurationWriter.apply();
- }
- LOG.info("Peer Singleton Service {} instantiated, Peer {}", getIdentifier().getValue(), this.neighborAddress);
+ LOG.info("Peer instantiated {}", this.neighborAddress);
this.bgpPeer.instantiateServiceInstance();
this.dispatcher.getBGPPeerRegistry().addPeer(this.neighborAddress, this.bgpPeer, this.prefs);
if (this.activeConnection) {
- this.connection = this.dispatcher.createReconnectingClient(this.inetAddress, this.retryTimer, this.keys);
+ this.connection = this.dispatcher.createReconnectingClient(this.inetAddress, this.localAddress,
+ this.retryTimer, this.keys);
}
}
- @Override
- public synchronized ListenableFuture<Void> closeServiceInstance() {
- if(!this.isServiceInstantiated) {
- LOG.info("Peer Singleton Service {} already closed, Peer {}", getIdentifier().getValue(),
- this.neighborAddress);
+ private synchronized ListenableFuture<Void> closeServiceInstance() {
+ if (!this.isServiceInstantiated) {
+ LOG.info("Peer {} already closed", this.neighborAddress);
return Futures.immediateFuture(null);
}
- LOG.info("Close Peer Singleton Service {}, Peer {}", getIdentifier().getValue(), this.neighborAddress);
+ LOG.info("Close Peer {}", this.neighborAddress);
this.isServiceInstantiated = false;
if (this.connection != null) {
this.connection.cancel(true);
this.connection = null;
}
final ListenableFuture<Void> future = this.bgpPeer.close();
- if(BgpPeer.this.currentConfiguration != null) {
- this.dispatcher.getBGPPeerRegistry().removePeer(BgpPeer.this.currentConfiguration.getNeighborAddress());
- }
+ removePeer(this.dispatcher.getBGPPeerRegistry());
return future;
}
- @Override
- public ServiceGroupIdentifier getIdentifier() {
- return this.serviceGroupIdentifier;
- }
-
- BGPPeerRuntimeMXBean getPeer() {
- return this.bgpPeer;
- }
-
@Override
public BGPPeerState getPeerState() {
return this.bgpPeer.getPeerState();