import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import org.opendaylight.controller.config.api.JmxAttributeValidationException;
-import org.opendaylight.protocol.bgp.rib.impl.server.BGPServerSessionValidator;
+import org.opendaylight.protocol.bgp.rib.impl.BGPServerSessionValidator;
/**
* BGP peer acceptor that handles incomming bgp connections.
// Validate future success
future.addListener(new GenericFutureListener<Future<Void>>() {
@Override
- public void operationComplete(Future<Void> future) throws Exception {
- if(future.isSuccess() == false) {
+ public void operationComplete(Future<Void> future) {
+ if(!future.isSuccess()) {
throw new IllegalStateException(String.format("Unable to start bgp server on %s", getAddress()), future.cause());
}
}
return new AutoCloseable() {
@Override
- public void close() throws Exception {
+ public void close() {
// This closes the acceptor and no new bgp connections will be accepted
// Connections already established will be preserved
future.cancel(true);
getPeerRegistryBackwards().addPeer(getHostWithoutValue(), bgpClientPeer, prefs);
- final AutoCloseable peerCloseable = new AutoCloseable() {
+ final CloseableNoEx peerCloseable = new CloseableNoEx() {
@Override
- public void close() throws Exception {
+ public void close() {
bgpClientPeer.close();
getPeerRegistryBackwards().removePeer(getHostWithoutValue());
}
// Initiate connection
if(getInitiateConnection()) {
final Future<Void> cf = initiateConnection(createAddress(), password, remoteAs, getPeerRegistryBackwards());
- return new AutoCloseable() {
+ return new CloseableNoEx() {
@Override
- public void close() throws Exception {
+ public void close() {
cf.cancel(true);
peerCloseable.close();
}
}
}
+ private static interface CloseableNoEx extends AutoCloseable {
+ @Override
+ void close();
+ }
+
private String getPasswordOrNull() {
final String password;
if (getPassword() != null) {
}
@Override
- public void close() throws Exception {
+ public void close() {
// DO nothing, do not close the global instance
}
Preconditions.checkState(this.state == State.Idle);
// Check if peer is configured in registry before retrieving preferences
- if (registry.isPeerConfigured(getRemoteIp()) == false) {
+ if (!registry.isPeerConfigured(getRemoteIp())) {
final BGPDocumentedException cause = new BGPDocumentedException(
"BGP peer with ip: " + getRemoteIp()
+ " not configured, check configured peers in : "
* 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.rib.impl.client;
+package org.opendaylight.protocol.bgp.rib.impl;
import io.netty.channel.Channel;
import io.netty.util.Timer;
* 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.rib.impl.client;
+package org.opendaylight.protocol.bgp.rib.impl;
import com.google.common.base.Preconditions;
import io.netty.channel.Channel;
import io.netty.util.Timer;
import io.netty.util.concurrent.Promise;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
-import org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
import org.opendaylight.protocol.framework.SessionListenerFactory;
import org.opendaylight.protocol.framework.SessionNegotiator;
public BGPClientSessionNegotiatorFactory(final Timer timer, final AsNumber remoteAs, final BGPPeerRegistry peerRegistry) {
this.peerRegistry = peerRegistry;
this.timer = Preconditions.checkNotNull(timer);
- this.validator = new BGPClientSessionValidator(remoteAs, peerRegistry);
+ this.validator = new BGPClientSessionValidator(remoteAs);
}
@Override
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.protocol.bgp.rib.impl.client;
+package org.opendaylight.protocol.bgp.rib.impl;
import java.util.List;
import org.opendaylight.protocol.bgp.parser.AsNumberUtil;
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPError;
-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.BGPSessionValidator;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
private static final Logger LOG = LoggerFactory.getLogger(BGPClientSessionValidator.class);
private final AsNumber remoteAs;
- private final BGPPeerRegistry peerRegistry;
- public BGPClientSessionValidator(final AsNumber remoteAs, final BGPPeerRegistry peerRegistry) {
+ public BGPClientSessionValidator(final AsNumber remoteAs) {
this.remoteAs = remoteAs;
- this.peerRegistry = peerRegistry;
}
/**
import org.opendaylight.bgpcep.tcpmd5.netty.MD5ServerChannelFactory;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
-import org.opendaylight.protocol.bgp.rib.impl.client.BGPClientSessionNegotiatorFactory;
-import org.opendaylight.protocol.bgp.rib.impl.server.BGPServerSessionNegotiatorFactory;
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.BGPServerDispatcher;
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.protocol.bgp.rib.impl.server;
+package org.opendaylight.protocol.bgp.rib.impl;
import io.netty.channel.Channel;
import io.netty.util.Timer;
* 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.rib.impl.server;
+package org.opendaylight.protocol.bgp.rib.impl;
import com.google.common.base.Preconditions;
+
import io.netty.channel.Channel;
import io.netty.util.Timer;
import io.netty.util.concurrent.Promise;
+
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
-import org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionValidator;
import org.opendaylight.protocol.framework.SessionListenerFactory;
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.protocol.bgp.rib.impl.server;
+package org.opendaylight.protocol.bgp.rib.impl;
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
private static final Logger LOG = LoggerFactory.getLogger(StrictBGPPeerRegistry.class);
// TODO remove backwards compatibility
- public static StrictBGPPeerRegistry GLOBAL = new StrictBGPPeerRegistry();
+ public static final StrictBGPPeerRegistry GLOBAL = new StrictBGPPeerRegistry();
@GuardedBy("this")
private final Map<IpAddress, ReusableBGPPeer> peers = Maps.newHashMap();
@Override
public synchronized void addPeer(final IpAddress ip, final ReusableBGPPeer peer, final BGPSessionPreferences preferences) {
Preconditions.checkNotNull(ip);
- Preconditions.checkArgument(peers.containsKey(ip) == false, "Peer for %s already present", ip);
+ Preconditions.checkArgument(!peers.containsKey(ip), "Peer for %s already present", ip);
peers.put(ip, Preconditions.checkNotNull(peer));
peerPreferences.put(ip, Preconditions.checkNotNull(preferences));
}
final BGPSessionId previousConnection = sessionIds.get(ip);
// Session reestablished with different ids
- if (previousConnection.equals(currentConnection) == false) {
+ if (!previousConnection.equals(currentConnection)) {
LOG.warn("BGP session with {} {} has to be dropped. Same session already present {}", ip, currentConnection, previousConnection);
throw new BGPDocumentedException(
String.format("BGP session with %s %s has to be dropped. Same session already present %s",
}
@Override
- public synchronized void close() throws Exception {
+ public synchronized void close() {
peers.clear();
sessionIds.clear();
}
*/
@Override
public boolean equals(final Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
- final BGPSessionId BGPSessionId = (BGPSessionId) o;
+ final BGPSessionId bGPSessionId = (BGPSessionId) o;
- if (!from.equals(BGPSessionId.from) && !from.equals(BGPSessionId.to)) return false;
- if (!to.equals(BGPSessionId.to) && !to.equals(BGPSessionId.from)) return false;
+ if (!from.equals(bGPSessionId.from) && !from.equals(bGPSessionId.to)) {
+ return false;
+ }
+ if (!to.equals(bGPSessionId.to) && !to.equals(bGPSessionId.from)) {
+ return false;
+ }
return true;
}
@Override
public int hashCode() {
+ final int prime = 31;
int result = from.hashCode() + to.hashCode();
- result = 31 * result;
+ result = prime * result;
return result;
}
* Check if this connection is equal to other and if it contains higher source bgp id
*/
boolean isHigherDirection(final BGPSessionId other) {
- Preconditions.checkState(this.isSameDirection(other) == false, "Equal sessions with same direction");
+ Preconditions.checkState(!this.isSameDirection(other), "Equal sessions with same direction");
return toLong(from) > toLong(other.from);
}
import org.mockito.stubbing.Answer;
import org.opendaylight.protocol.bgp.parser.BGPError;
import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
-import org.opendaylight.protocol.bgp.rib.impl.client.BGPClientSessionNegotiator;
-import org.opendaylight.protocol.bgp.rib.impl.client.BGPClientSessionValidator;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
final BGPPeerRegistry peerRegistry = new StrictBGPPeerRegistry();
peerRegistry.addPeer(new IpAddress(new Ipv4Address(peerAddress.getHostAddress())), new SimpleSessionListener(), prefs);
- this.clientSession = new BGPClientSessionNegotiator(new HashedWheelTimer(), new DefaultPromise<BGPSessionImpl>(GlobalEventExecutor.INSTANCE), this.speakerListener, peerRegistry, new BGPClientSessionValidator(new AsNumber(30L), peerRegistry));
+ this.clientSession = new BGPClientSessionNegotiator(new HashedWheelTimer(), new DefaultPromise<BGPSessionImpl>(GlobalEventExecutor.INSTANCE), this.speakerListener, peerRegistry, new BGPClientSessionValidator(new AsNumber(30L)));
doAnswer(new Answer<Object>() {
@Override
public Object answer(final InvocationOnMock invocation) {
package org.opendaylight.protocol.bgp.testtool;
import com.google.common.base.Preconditions;
+
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.util.HashedWheelTimer;
import io.netty.util.concurrent.DefaultPromise;
import io.netty.util.concurrent.GlobalEventExecutor;
import io.netty.util.concurrent.Promise;
+
import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.Map;
+
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
import org.opendaylight.protocol.bgp.rib.impl.BGPHandlerFactory;
+import org.opendaylight.protocol.bgp.rib.impl.BGPServerSessionNegotiatorFactory;
import org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl;
import org.opendaylight.protocol.bgp.rib.impl.BGPSessionProposalImpl;
-import org.opendaylight.protocol.bgp.rib.impl.server.BGPServerSessionNegotiatorFactory;
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.BGPSessionValidator;