*/
package org.opendaylight.protocol.bgp.rib.impl;
+import io.netty.channel.EventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.util.HashedWheelTimer;
import io.netty.util.Timer;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.Promise;
-
-import java.net.InetSocketAddress;
-
import org.opendaylight.protocol.bgp.parser.BGPMessageFactory;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
import org.opendaylight.protocol.framework.ReconnectStrategy;
import org.opendaylight.protocol.framework.SessionListenerFactory;
+import java.net.InetSocketAddress;
+
/**
* Implementation of BGPDispatcher.
*/
private final BGPHandlerFactory hf;
- public BGPDispatcherImpl(final BGPMessageFactory parser) {
- super();
+ public BGPDispatcherImpl(final BGPMessageFactory parser, EventLoopGroup bossGroup, EventLoopGroup workerGroup) {
+ super(bossGroup, workerGroup);
this.hf = new BGPHandlerFactory(parser);
}
*/
package org.opendaylight.protocol.bgp.testtool;
+import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.concurrent.GlobalEventExecutor;
-
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactoryImpl;
import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+
/**
* Starter class for testing.
*/
private static final int RECONNECT_MILLIS = 5000;
Main() throws Exception {
- this.dispatcher = new BGPDispatcherImpl(new BGPMessageFactoryImpl(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry()));
+ this.dispatcher = new BGPDispatcherImpl(new BGPMessageFactoryImpl(ServiceLoaderBGPExtensionProviderContext
+ .createConsumerContext().getMessageRegistry()), new NioEventLoopGroup(), new NioEventLoopGroup());
}
public static void main(final String[] args) throws Exception {
*/
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 org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactoryImpl;
import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
import org.opendaylight.yangtools.yang.binding.Notification;
-import com.google.common.base.Preconditions;
+import java.net.InetSocketAddress;
public class BGPSpeakerMock<M, S extends ProtocolSession<M>, L extends SessionListener<M, ?, ?>> extends AbstractDispatcher<S, L> {
public BGPSpeakerMock(final SessionNegotiatorFactory<M, S, L> negotiatorFactory, final ProtocolHandlerFactory<?> factory,
final DefaultPromise<BGPSessionImpl> defaultPromise) {
+ super(new NioEventLoopGroup(), new NioEventLoopGroup());
this.negotiatorFactory = Preconditions.checkNotNull(negotiatorFactory);
this.factory = Preconditions.checkNotNull(factory);
}
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GlobalEventExecutor;
import io.netty.util.concurrent.Promise;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.Closeable;
import java.net.InetSocketAddress;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
* Dispatcher class for creating servers and clients. The idea is to first create servers and clients and the run the
* start method that will handle sockets in different thread.
/**
* Initializes channel by specifying the handlers in its pipeline. Handlers are protocol specific, therefore this
* method needs to be implemented in protocol specific Dispatchers.
- *
+ *
* @param channel whose pipeline should be defined, also to be passed to {@link SessionNegotiatorFactory}
* @param promise to be passed to {@link SessionNegotiatorFactory}
*/
private final EventLoopGroup workerGroup;
+
+ /**
+ * Internally creates new instances of NioEventLoopGroup, might deplete system resources and result in Too many open files exception.
+ *
+ * @deprecated use {@link AbstractDispatcher#AbstractDispatcher(io.netty.channel.EventLoopGroup, io.netty.channel.EventLoopGroup)} instead.
+ */
+ @Deprecated
protected AbstractDispatcher() {
- // FIXME: we should get these as arguments
- this.bossGroup = new NioEventLoopGroup();
- this.workerGroup = new NioEventLoopGroup();
+ this(new NioEventLoopGroup(),new NioEventLoopGroup());
+ }
+
+ protected AbstractDispatcher(EventLoopGroup bossGroup, EventLoopGroup workerGroup) {
+ this.bossGroup = bossGroup;
+ this.workerGroup = workerGroup;
}
/**
* Creates server. Each server needs factories to pass their instances to client sessions.
- *
+ *
* @param address address to which the server should be bound
* @param initializer instance of PipelineInitializer used to initialize the channel pipeline
- *
+ *
* @return ChannelFuture representing the binding process
*/
protected ChannelFuture createServer(final InetSocketAddress address, final PipelineInitializer<S> initializer) {
/**
* Creates a client.
- *
+ *
* @param address remote address
* @param connectStrategy Reconnection strategy to be used when initial connection fails
- *
+ *
* @return Future representing the connection process. Its result represents the combined success of TCP connection
- * as well as session negotiation.
+ * as well as session negotiation.
*/
protected Future<S> createClient(final InetSocketAddress address, final ReconnectStrategy strategy, final PipelineInitializer<S> initializer) {
final Bootstrap b = new Bootstrap();
/**
* Creates a client.
- *
+ *
* @param address remote address
* @param connectStrategyFactory Factory for creating reconnection strategy to be used when initial connection fails
* @param reestablishStrategy Reconnection strategy to be used when the already-established session fails
- *
+ *
* @return Future representing the reconnection task. It will report completion based on reestablishStrategy, e.g.
- * success if it indicates no further attempts should be made and failure if it reports an error
+ * success if it indicates no further attempts should be made and failure if it reports an error
*/
protected Future<Void> createReconnectingClient(final InetSocketAddress address, final ReconnectStrategyFactory connectStrategyFactory,
final ReconnectStrategy reestablishStrategy, final PipelineInitializer<S> initializer) {
package org.opendaylight.protocol.framework;
+import com.google.common.base.Preconditions;
import io.netty.channel.ChannelFuture;
+import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.Promise;
-
-import java.net.InetSocketAddress;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Preconditions;
+import java.net.InetSocketAddress;
public class SimpleDispatcher extends AbstractDispatcher<SimpleSession, SimpleSessionListener> {
public SimpleDispatcher(final SessionNegotiatorFactory<SimpleMessage, SimpleSession, SimpleSessionListener> negotiatorFactory, final ProtocolHandlerFactory<?> factory,
final Promise<SimpleSession> promise) {
+ super(new NioEventLoopGroup(), new NioEventLoopGroup());
this.negotiatorFactory = Preconditions.checkNotNull(negotiatorFactory);
this.factory = Preconditions.checkNotNull(factory);
}
*/
package org.opendaylight.protocol.pcep.impl;
+import com.google.common.base.Preconditions;
import io.netty.channel.ChannelFuture;
+import io.netty.channel.EventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.util.concurrent.Promise;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-
import org.opendaylight.protocol.framework.AbstractDispatcher;
import org.opendaylight.protocol.framework.SessionListenerFactory;
import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
-import com.google.common.base.Preconditions;
+import java.io.IOException;
+import java.net.InetSocketAddress;
/**
* Implementation of PCEPDispatcher.
/**
* Creates an instance of PCEPDispatcherImpl, gets the default selector and opens it.
- *
+ *
* @throws IOException if some error occurred during opening the selector
*/
- public PCEPDispatcherImpl(final MessageHandlerRegistry registry, final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> negotiatorFactory) {
- super();
+ public PCEPDispatcherImpl(final MessageHandlerRegistry registry,
+ final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> negotiatorFactory,
+ EventLoopGroup bossGroup, EventLoopGroup workerGroup) {
+ super(bossGroup, workerGroup);
this.snf = Preconditions.checkNotNull(negotiatorFactory);
this.hf = new PCEPHandlerFactory(registry);
}
*/
package org.opendaylight.protocol.pcep.testtool;
+import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.HashedWheelTimer;
-
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-
import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
import org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+
public class Main {
private static final Logger logger = LoggerFactory.getLogger(Main.class);
final Open prefs = spf.getSessionProposal(address, 0);
- final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(PCEPExtensionProviderContextImpl.getSingletonInstance().getMessageHandlerRegistry(), new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), prefs, 5));
+ final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(PCEPExtensionProviderContextImpl
+ .getSingletonInstance().getMessageHandlerRegistry(), new DefaultPCEPSessionNegotiatorFactory(
+ new HashedWheelTimer(), prefs, 5), new NioEventLoopGroup(), new NioEventLoopGroup());
dispatcher.createServer(address, new TestingSessionListenerFactory()).get();
}
*/
package org.opendaylight.protocol.pcep.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.Future;
import io.netty.util.concurrent.GlobalEventExecutor;
import io.netty.util.concurrent.Promise;
-
-import java.net.InetSocketAddress;
-
import org.opendaylight.protocol.framework.AbstractDispatcher;
import org.opendaylight.protocol.framework.NeverReconnectStrategy;
import org.opendaylight.protocol.framework.ProtocolHandlerFactory;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.predundancy.group.id.tlv.PredundancyGroupIdBuilder;
-import com.google.common.base.Preconditions;
+import java.net.InetSocketAddress;
public class PCCMock<M, S extends ProtocolSession<M>, L extends SessionListener<M, ?, ?>> extends AbstractDispatcher<S, L> {
public PCCMock(final SessionNegotiatorFactory<M, S, L> negotiatorFactory, final ProtocolHandlerFactory<?> factory,
final DefaultPromise<PCEPSessionImpl> defaultPromise) {
+ super(new NioEventLoopGroup(), new NioEventLoopGroup());
this.negotiatorFactory = Preconditions.checkNotNull(negotiatorFactory);
this.factory = Preconditions.checkNotNull(factory);
}
*/
package org.opendaylight.bgpcep.pcep.topology.provider;
+import com.google.common.base.Preconditions;
import io.netty.channel.ChannelFuture;
+import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.HashedWheelTimer;
import java.net.InetSocketAddress;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Preconditions;
+import java.net.InetSocketAddress;
+import java.util.concurrent.ExecutionException;
public final class BundleActivator extends AbstractBindingAwareProvider {
private static final Logger LOG = LoggerFactory.getLogger(BundleActivator.class);
final InetSocketAddress address = new InetSocketAddress("0.0.0.0", 4189);
final PCEPSessionProposalFactory spf = new PCEPSessionProposalFactoryImpl(30, 10, true, true, true, true, 0);
final Open prefs = spf.getSessionProposal(address, 0);
- final PCEPDispatcher dispatcher = new PCEPDispatcherImpl(PCEPExtensionProviderContextImpl.getSingletonInstance().getMessageHandlerRegistry(), new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), prefs, 5));
+ final PCEPDispatcher dispatcher = new PCEPDispatcherImpl(PCEPExtensionProviderContextImpl
+ .getSingletonInstance().getMessageHandlerRegistry(), new DefaultPCEPSessionNegotiatorFactory(
+ new HashedWheelTimer(), prefs, 5), new NioEventLoopGroup(), new NioEventLoopGroup());
+
final InstanceIdentifier<Topology> topology = InstanceIdentifier.builder().node(Topology.class).toInstance();
final PCEPTopologyProvider exp = new PCEPTopologyProvider(dispatcher, null, dps, topology);