package org.opendaylight.protocol.bgp.rib.impl.config;
+import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
private ApplicationPeer applicationPeer;
private ListenerRegistration<ApplicationPeer> registration;
+ private Neighbor currentConfiguration;
@Override
public void start(final RIB rib, final Neighbor neighbor, final BGPOpenConfigMappingService mappingService) {
+ this.currentConfiguration = Preconditions.checkNotNull(neighbor);
final ApplicationRibId appRibId = createAppRibId(neighbor);
this.applicationPeer = new ApplicationPeer(appRibId, neighbor.getNeighborAddress().getIpv4Address(), rib);
final YangInstanceIdentifier yangIId = YangInstanceIdentifier.builder().node(ApplicationRib.QNAME)
this.applicationPeer);
}
+ @Override
+ public void restart(final RIB rib, final BGPOpenConfigMappingService mappingService) {
+ Preconditions.checkState(this.currentConfiguration != null);
+ start(rib, this.currentConfiguration, mappingService);
+ }
+
@Override
public void close() {
if (this.applicationPeer != null) {
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
+import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
//if not exists, create a new instance
onGlobalCreated(rootIdentifier, global, null);
} else if (!ribImpl.isGlobalEqual(global)) {
+ final List<PeerBean> closedPeers = closeAllBindedPeers(rootIdentifier);
ribImpl.close();
initiateRibInstance(rootIdentifier, global, ribImpl, null);
+ closedPeers.forEach(peer -> peer.restart(ribImpl, this.mappingService));
}
LOG.debug("RIB instance modified {}", ribImpl);
}
+ private List<PeerBean> closeAllBindedPeers(final InstanceIdentifier<Bgp> rootIdentifier) {
+ final List<PeerBean> filtered = new ArrayList<>();
+ for (final Entry<InstanceIdentifier<Neighbor>, PeerBean> entry : this.peers.entrySet()) {
+ if (entry.getKey().contains(rootIdentifier)) {
+ final PeerBean peer = entry.getValue();
+ peer.close();
+ filtered.add(peer);
+ }
+ }
+ return filtered;
+ }
+
@Override
public synchronized void onGlobalCreated(final InstanceIdentifier<Bgp> rootIdentifier, final Global global, final WriteConfiguration
configurationWriter) {
private final BGPPeerRegistry peerRegistry;
private BGPPeer bgpPeer;
- private IpAddress neighborAddress;
-
private Future<Void> connection;
private ServiceRegistration<?> serviceRegistration;
+ private Neighbor currentConfiguration;
public BgpPeer(final RpcProviderRegistry rpcRegistry, final BGPPeerRegistry peerRegistry) {
this.rpcRegistry = rpcRegistry;
@Override
public void start(final RIB rib, final Neighbor neighbor, final BGPOpenConfigMappingService mappingService) {
Preconditions.checkState(this.bgpPeer == null, "Previous peer instance {} was not closed.");
- this.neighborAddress = neighbor.getNeighborAddress();
- this.bgpPeer = new BGPPeer(Ipv4Util.toStringIP(this.neighborAddress), rib,
+ this.currentConfiguration = Preconditions.checkNotNull(neighbor);
+ final IpAddress neighborAddress = neighbor.getNeighborAddress();
+ this.bgpPeer = new BGPPeer(Ipv4Util.toStringIP(neighborAddress), rib,
mappingService.toPeerRole(neighbor), this.rpcRegistry);
final List<BgpParameters> bgpParameters = getBgpParameters(neighbor, rib, mappingService);
final KeyMapping key = OpenConfigMappingUtil.getNeighborKey(neighbor);
final BGPSessionPreferences prefs = new BGPSessionPreferences(rib.getLocalAs(),
getHoldTimer(neighbor), rib.getBgpIdentifier(), getPeerAs(neighbor, rib), bgpParameters, getPassword(key));
- this.peerRegistry.addPeer(this.neighborAddress, this.bgpPeer, prefs);
+ this.peerRegistry.addPeer(neighborAddress, this.bgpPeer, prefs);
if (OpenConfigMappingUtil.isActive(neighbor)) {
this.connection = rib.getDispatcher().createReconnectingClient(
- Ipv4Util.toInetSocketAddress(this.neighborAddress, PORT), this.peerRegistry,
+ Ipv4Util.toInetSocketAddress(neighborAddress, PORT), this.peerRegistry,
OpenConfigMappingUtil.getRetryTimer(neighbor), Optional.fromNullable(key));
}
}
+ @Override
+ public void restart(final RIB rib, final BGPOpenConfigMappingService mappingService) {
+ Preconditions.checkState(this.currentConfiguration != null);
+ start(rib, this.currentConfiguration, mappingService);
+ }
+
@Override
public void close() {
if (this.bgpPeer != null) {
}
this.bgpPeer.close();
this.bgpPeer = null;
- this.peerRegistry.removePeer(this.neighborAddress);
- this.neighborAddress = null;
+ this.peerRegistry.removePeer(this.currentConfiguration.getNeighborAddress());
+ this.currentConfiguration = null;
if (this.serviceRegistration != null) {
this.serviceRegistration.unregister();
this.serviceRegistration = null;