return this.state;
}
- private final void negotiationSuccessful(BGPSessionImpl session) {
+ private void negotiationSuccessful(BGPSessionImpl session) {
LOG.debug("Negotiation on channel {} successful with session {}", this.channel, session);
channel.pipeline().replace(this, "session", session);
promise.setSuccess(session);
promise.setFailure(cause);
}
- private final void sendMessage(final Notification msg) {
+ private void sendMessage(final Notification msg) {
channel.writeAndFlush(msg).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture f) {
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.BGPSessionValidator;
+import org.opendaylight.protocol.bgp.rib.impl.spi.ChannelPipelineInitializer;
import org.opendaylight.protocol.bgp.rib.spi.BGPSessionNegotiatorFactory;
import org.opendaylight.protocol.framework.ReconnectStrategy;
import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
*/
public class BGPDispatcherImpl implements BGPDispatcher, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(BGPDispatcherImpl.class);
+ private static final int SOCKET_BACKLOG_SIZE = 128;
private final MD5ServerChannelFactory<?> scf;
private final MD5ChannelFactory<?> cf;
private final BGPHandlerFactory hf;
(BGPDispatcherImpl.this.hf.getDecoders(), snf, BGPDispatcherImpl.this.hf.getEncoders());
final ServerBootstrap b = new ServerBootstrap();
b.childHandler(BGPChannel.createChannelInitializer(initializer, new DefaultPromise(BGPDispatcherImpl.this.executor)));
- b.option(ChannelOption.SO_BACKLOG, Integer.valueOf(128));
+ b.option(ChannelOption.SO_BACKLOG, Integer.valueOf(SOCKET_BACKLOG_SIZE));
b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
this.customizeBootstrap(b);
}
}
- public interface ChannelPipelineInitializer {
- void initializeChannel(SocketChannel socketChannel, Promise<BGPSessionImpl> promise);
- }
-
- public static class BGPChannel {
+ public final static class BGPChannel {
private static final String NEGOTIATOR = "negotiator";
private BGPChannel() {
}
}
- private class ReconnectingStrategyListener implements FutureListener<Void> {
+ private final class ReconnectingStrategyListener implements FutureListener<Void> {
private ReconnectingStrategyListener() {
}
import java.net.InetSocketAddress;
import org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImpl;
import org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl;
+import org.opendaylight.protocol.bgp.rib.impl.spi.ChannelPipelineInitializer;
import org.opendaylight.protocol.framework.ReconnectStrategy;
import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
import org.slf4j.Logger;
private final InetSocketAddress address;
private final ReconnectStrategyFactory strategyFactory;
private final Bootstrap b;
- private final BGPDispatcherImpl.ChannelPipelineInitializer initializer;
+ private final ChannelPipelineInitializer initializer;
private final EventExecutor executor;
private Future<BGPSessionImpl> pending;
public BGPReconnectPromise(final EventExecutor executor, final InetSocketAddress address,
final ReconnectStrategyFactory connectStrategyFactory, final Bootstrap b,
- final BGPDispatcherImpl.ChannelPipelineInitializer initializer) {
+ final ChannelPipelineInitializer initializer) {
super(executor);
this.executor = executor;
this.b = b;
final ReconnectStrategy cs = this.strategyFactory.createReconnectStrategy();
// Set up a client with pre-configured bootstrap, but add a closed channel handler into the pipeline to support reconnect attempts
- pending = createClient(this.address, cs, b, new BGPDispatcherImpl.ChannelPipelineInitializer() {
+ pending = createClient(this.address, cs, b, new ChannelPipelineInitializer() {
@Override
public void initializeChannel(final SocketChannel channel, final Promise<BGPSessionImpl> promise) {
initializer.initializeChannel(channel, promise);
}
public Future<BGPSessionImpl> createClient(final InetSocketAddress address, final ReconnectStrategy strategy, final Bootstrap bootstrap,
- final BGPDispatcherImpl.ChannelPipelineInitializer initializer) {
+ final ChannelPipelineInitializer initializer) {
final BGPProtocolSessionPromise p = new BGPProtocolSessionPromise(this.executor, address, strategy, bootstrap);
final ChannelHandler chInit = BGPDispatcherImpl.BGPChannel.createChannelInitializer(initializer, p);
bootstrap.handler(chInit);
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. 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.rib.impl.spi;
+
+import io.netty.channel.socket.SocketChannel;
+import io.netty.util.concurrent.Promise;
+import org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl;
+
+public interface ChannelPipelineInitializer {
+ void initializeChannel(SocketChannel socketChannel, Promise<BGPSessionImpl> promise);
+}
*/
public class PCEPDispatcherImpl implements PCEPDispatcher, Closeable {
private static final Logger LOG = LoggerFactory.getLogger(PCEPDispatcherImpl.class);
+ private static final Integer SOCKET_BACKLOG_SIZE = 128;
private final PCEPSessionNegotiatorFactory snf;
private final PCEPHandlerFactory hf;
initializer.initializeChannel(ch, new DefaultPromise(PCEPDispatcherImpl.this.executor));
}
});
- b.option(ChannelOption.SO_BACKLOG, 128);
+ b.option(ChannelOption.SO_BACKLOG, SOCKET_BACKLOG_SIZE);
b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
this.customizeBootstrap(b);
}
}
- private class ReconnectingStrategyListener implements FutureListener<Void> {
+ private final class ReconnectingStrategyListener implements FutureListener<Void> {
private ReconnectingStrategyListener() {
}
public abstract class AbstractPCCDispatcher implements Closeable {
private static final Logger LOG = LoggerFactory.getLogger(AbstractPCCDispatcher.class);
+ private static final Integer SOCKET_BACKLOG_SIZE = 128;
private final EventLoopGroup bossGroup;
private final EventLoopGroup workerGroup;
private final EventExecutor executor;
initializer.initializeChannel(ch, new DefaultPromise(AbstractPCCDispatcher.this.executor));
}
});
- b.option(ChannelOption.SO_BACKLOG, 128);
+ b.option(ChannelOption.SO_BACKLOG, SOCKET_BACKLOG_SIZE);
b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
this.customizeBootstrap(b);
}
}
- private class ReconnectingStrategyListener implements FutureListener<Void> {
+ private final class ReconnectingStrategyListener implements FutureListener<Void> {
private ReconnectingStrategyListener() {
}
return;
}
if (message instanceof Pcupd) {
- final Updates update = ((Pcupd) message).getPcupdMessage().getUpdates().get(0);
- if (update.getLsp().isDelegate() != null && update.getLsp().isDelegate()) {
- //regular LSP update
- this.tunnelManager.reportToAll(update, this);
- } else {
- //returning LSP delegation
- this.tunnelManager.returnDelegation(update, this);
- }
+ handlePcupd((Pcupd) message);
} else if (message instanceof Pcinitiate) {
- final Requests request = ((Pcinitiate) message).getPcinitiateMessage().getRequests().get(0);
- if (request.getSrp().getAugmentation(Srp1.class) != null && request.getSrp().getAugmentation(Srp1.class).isRemove()) {
- //remove LSP
- this.tunnelManager.removeTunnel(request, this);
- } else if (request.getLsp().isDelegate() != null && request.getLsp().isDelegate() && request.getEndpointsObj() == null) {
- //take LSP delegation
- this.tunnelManager.takeDelegation(request, this);
- } else {
- //create LSP
- this.tunnelManager.addTunnel(request, this);
- }
+ handlePcinitiate((Pcinitiate) message);
+ }
+ }
+
+ private void handlePcupd(final Pcupd message) {
+ final Updates update = message.getPcupdMessage().getUpdates().get(0);
+ if (update.getLsp().isDelegate() != null && update.getLsp().isDelegate()) {
+ //regular LSP update
+ this.tunnelManager.reportToAll(update, this);
+ } else {
+ //returning LSP delegation
+ this.tunnelManager.returnDelegation(update, this);
+ }
+ }
+
+ private void handlePcinitiate(final Pcinitiate message) {
+ final Requests request = message.getPcinitiateMessage().getRequests().get(0);
+ if (request.getSrp().getAugmentation(Srp1.class) != null && request.getSrp().getAugmentation(Srp1.class).isRemove()) {
+ //remove LSP
+ this.tunnelManager.removeTunnel(request, this);
+ } else if (request.getLsp().isDelegate() != null && request.getLsp().isDelegate() && request.getEndpointsObj() == null) {
+ //take LSP delegation
+ this.tunnelManager.takeDelegation(request, this);
+ } else {
+ //create LSP
+ this.tunnelManager.addTunnel(request, this);
}
}