org.opendaylight.controller.netconf.client,
org.opendaylight.controller.netconf.util.osgi,
org.opendaylight.controller.netconf.util.xml,
+ io.netty.channel,
+ io.netty.channel.nio,
+ io.netty.util.concurrent,
org.osgi.framework,
org.slf4j,
org.w3c.dom,
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
import org.opendaylight.controller.config.persist.api.Persister;
import org.opendaylight.controller.netconf.api.NetconfMessage;
import org.opendaylight.controller.netconf.api.jmx.CommitJMXNotification;
private final InetSocketAddress address;
private final NetconfClientDispatcher dispatcher;
+ private final EventLoopGroup nettyThreadgroup;
private NetconfClient netconfClient;
this.address = address;
this.mbeanServer = mbeanServer;
this.timeout = timeout;
- this.dispatcher = new NetconfClientDispatcher(Optional.<SSLContext>absent());
+
+ this.nettyThreadgroup = new NioEventLoopGroup();
+ this.dispatcher = new NetconfClientDispatcher(Optional.<SSLContext>absent(), nettyThreadgroup, nettyThreadgroup);
}
public void init() throws InterruptedException {
}
try {
- dispatcher.close();
+ nettyThreadgroup.shutdownGracefully();
} catch (Exception e) {
- logger.warn("Unable to close netconf client dispatcher {}", dispatcher, e);
+ logger.warn("Unable to close netconf client thread group {}", dispatcher, e);
}
// unregister from JMX
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import io.netty.channel.EventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.util.HashedWheelTimer;
import io.netty.util.concurrent.Future;
private final Optional<SSLContext> maybeContext;
private final NetconfClientSessionNegotiatorFactory negotatorFactory;
- public NetconfClientDispatcher(final Optional<SSLContext> maybeContext) {
+ public NetconfClientDispatcher(final Optional<SSLContext> maybeContext, EventLoopGroup bossGroup, EventLoopGroup workerGroup) {
+ super(bossGroup, workerGroup);
this.maybeContext = Preconditions.checkNotNull(maybeContext);
this.negotatorFactory = new NetconfClientSessionNegotiatorFactory(new HashedWheelTimer());
}
package org.opendaylight.controller.netconf.client;
+import io.netty.channel.EventLoopGroup;
+
public class NetconfSshClientDispatcher extends NetconfClientDispatcher {
- public NetconfSshClientDispatcher() {
- super(null);
+
+ public NetconfSshClientDispatcher(EventLoopGroup bossGroup, EventLoopGroup workerGroup) {
+ super(null, bossGroup, workerGroup);
}
}
io.netty.util.concurrent,
io.netty.buffer,
io.netty.handler.codec,
+ io.netty.channel.nio,
javax.management,
javax.net.ssl,
javax.xml.namespace,
import com.google.common.base.Optional;
import io.netty.channel.ChannelFuture;
+import io.netty.channel.EventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.util.concurrent.Promise;
import org.opendaylight.controller.netconf.api.NetconfSession;
private final ServerSslChannelInitializer initializer;
- public NetconfServerDispatcher(final Optional<SSLContext> maybeContext,
- NetconfServerSessionNegotiatorFactory serverNegotiatorFactory,
- NetconfServerSessionListenerFactory listenerFactory) {
- this.initializer = new ServerSslChannelInitializer(maybeContext, serverNegotiatorFactory, listenerFactory);
+ public NetconfServerDispatcher(ServerSslChannelInitializer serverChannelInitializer, EventLoopGroup bossGroup,
+ EventLoopGroup workerGroup) {
+ super(bossGroup, workerGroup);
+ this.initializer = serverChannelInitializer;
}
- // FIXME change headers for all new source code files
-
// TODO test create server with same address twice
public ChannelFuture createServer(InetSocketAddress address) {
});
}
- private static class ServerSslChannelInitializer extends AbstractSslChannelInitializer {
+ public static class ServerSslChannelInitializer extends AbstractSslChannelInitializer {
private final NetconfServerSessionNegotiatorFactory negotiatorFactory;
private final NetconfServerSessionListenerFactory listenerFactory;
- private ServerSslChannelInitializer(Optional<SSLContext> maybeContext,
+ public ServerSslChannelInitializer(Optional<SSLContext> maybeContext,
NetconfServerSessionNegotiatorFactory negotiatorFactory,
NetconfServerSessionListenerFactory listenerFactory) {
super(maybeContext);
package org.opendaylight.controller.netconf.impl.osgi;
import com.google.common.base.Optional;
+import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.HashedWheelTimer;
import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer;
import org.opendaylight.controller.netconf.impl.NetconfServerDispatcher;
private NetconfOperationServiceFactoryTracker factoriesTracker;
private DefaultCommitNotificationProducer commitNot;
private NetconfServerDispatcher dispatch;
+ private NioEventLoopGroup eventLoopGroup;
@Override
public void start(final BundleContext context) throws Exception {
NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
factoriesListener, commitNot, idProvider);
+ eventLoopGroup = new NioEventLoopGroup();
+
if (maybeTCPAddress.isPresent()) {
Optional<SSLContext> maybeSSLContext = Optional.absent();
InetSocketAddress address = maybeTCPAddress.get();
- dispatch = new NetconfServerDispatcher(maybeSSLContext, serverNegotiatorFactory, listenerFactory);
+ NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(
+ maybeSSLContext, serverNegotiatorFactory, listenerFactory);
+ dispatch = new NetconfServerDispatcher(serverChannelInitializer, eventLoopGroup, eventLoopGroup);
logger.info("Starting TCP netconf server at {}", address);
dispatch.createServer(address);
if (maybeTLSConfiguration.isPresent()) {
Optional<SSLContext> maybeSSLContext = Optional.of(maybeTLSConfiguration.get().getSslContext());
InetSocketAddress address = maybeTLSConfiguration.get().getAddress();
- dispatch = new NetconfServerDispatcher(maybeSSLContext, serverNegotiatorFactory, listenerFactory);
+ NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(
+ maybeSSLContext, serverNegotiatorFactory, listenerFactory);
+ dispatch = new NetconfServerDispatcher(serverChannelInitializer, eventLoopGroup, eventLoopGroup);
logger.info("Starting TLS netconf server at {}", address);
dispatch.createServer(address);
logger.info("Shutting down netconf because YangStoreService service was removed");
commitNot.close();
- dispatch.close();
+ eventLoopGroup.shutdownGracefully();
}
}
import com.google.common.base.Optional;
import com.google.common.collect.Sets;
import io.netty.channel.ChannelFuture;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.HashedWheelTimer;
import org.apache.commons.io.IOUtils;
import org.junit.After;
public class ConcurrentClientsTest {
private static final int CONCURRENCY = 16;
- public static final NetconfClientDispatcher NETCONF_CLIENT_DISPATCHER = new NetconfClientDispatcher(Optional.<SSLContext>absent());
+ private static EventLoopGroup nettyGroup = new NioEventLoopGroup();
+ public static final NetconfClientDispatcher NETCONF_CLIENT_DISPATCHER = new NetconfClientDispatcher(
+ Optional.<SSLContext> absent(), nettyGroup, nettyGroup);
+
@Mock
private YangStoreService yangStoreService;
@Mock
private DefaultCommitNotificationProducer commitNot;
private NetconfServerDispatcher dispatch;
+
@Before
public void setUp() throws Exception {
{ // init mocks
NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
factoriesListener, commitNot, idProvider);
- dispatch = new NetconfServerDispatcher(Optional.<SSLContext> absent(), serverNegotiatorFactory, listenerFactory);
+ NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(
+ Optional.<SSLContext> absent(), serverNegotiatorFactory, listenerFactory);
+ dispatch = new NetconfServerDispatcher(serverChannelInitializer, nettyGroup, nettyGroup);
ChannelFuture s = dispatch.createServer(netconfAddress);
s.await();
@AfterClass
public static void tearDownStatic() {
- NETCONF_CLIENT_DISPATCHER.close();
+ nettyGroup.shutdownGracefully();
}
private NetconfOperationServiceFactory mockOpF() {
@After
public void cleanUp() throws Exception {
commitNot.close();
- dispatch.close();
}
@Test
package org.opendaylight.controller.netconf.impl;
-import java.lang.management.ManagementFactory;
-import java.net.InetSocketAddress;
-
-import javax.net.ssl.SSLContext;
-
+import com.google.common.base.Optional;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.util.HashedWheelTimer;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListener;
import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl;
-import com.google.common.base.Optional;
-
-import io.netty.channel.ChannelFuture;
-import io.netty.util.HashedWheelTimer;
+import javax.net.ssl.SSLContext;
+import java.lang.management.ManagementFactory;
+import java.net.InetSocketAddress;
public class NetconfDispatcherImplTest {
+ private EventLoopGroup nettyGroup;
+
+ @Before
+ public void setUp() throws Exception {
+ nettyGroup = new NioEventLoopGroup();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ nettyGroup.shutdownGracefully();
+ }
+
@Test
public void test() throws Exception {
NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
factoriesListener, commitNot, idProvider);
- NetconfServerDispatcher dispatch = new NetconfServerDispatcher(Optional.<SSLContext> absent(),
- serverNegotiatorFactory, listenerFactory);
+ NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(Optional.<SSLContext>absent(), serverNegotiatorFactory, listenerFactory);
+
+
+ NetconfServerDispatcher dispatch = new NetconfServerDispatcher(
+ serverChannelInitializer, nettyGroup, nettyGroup);
InetSocketAddress addr = new InetSocketAddress("127.0.0.1", 8333);
ChannelFuture s = dispatch.createServer(addr);
commitNot.close();
- dispatch.close();
}
}
import com.google.common.base.Optional;
import io.netty.channel.ChannelFuture;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.HashedWheelTimer;
import org.junit.After;
import org.junit.Before;
private DefaultCommitNotificationProducer commitNot;
private NetconfServerDispatcher dispatchS;
+ private EventLoopGroup nettyThreadgroup;
+
@Before
public void setUp() throws Exception {
commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer());
+ nettyThreadgroup = new NioEventLoopGroup();
+
dispatchS = createDispatcher(Optional.of(getSslContext()), factoriesListener);
ChannelFuture s = dispatchS.createServer(tlsAddress);
s.await();
NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
factoriesListener, commitNot, idProvider);
- return new NetconfServerDispatcher(sslC, serverNegotiatorFactory, listenerFactory);
+ NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(
+ sslC, serverNegotiatorFactory, listenerFactory);
+ return new NetconfServerDispatcher(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup);
}
@After
public void tearDown() throws Exception {
commitNot.close();
- dispatchS.close();
+ nettyThreadgroup.shutdownGracefully();
}
private SSLContext getSslContext() throws KeyStoreException, NoSuchAlgorithmException, CertificateException,
@Test
public void testSecure() throws Exception {
- try (NetconfClientDispatcher dispatch = new NetconfClientDispatcher(Optional.of(getSslContext()));
- NetconfClient netconfClient = new NetconfClient("tls-client", tlsAddress, 4000, dispatch)) {
+ NetconfClientDispatcher dispatch = new NetconfClientDispatcher(Optional.of(getSslContext()), nettyThreadgroup, nettyThreadgroup);
+ try (NetconfClient netconfClient = new NetconfClient("tls-client", tlsAddress, 4000, dispatch)) {
}
}
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import io.netty.channel.ChannelFuture;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.HashedWheelTimer;
import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
closeSession, startExi, stopExi;
private DefaultCommitNotificationProducer commitNot;
private NetconfServerDispatcher dispatch;
+ private EventLoopGroup nettyThreadgroup;
- private static NetconfClientDispatcher NETCONF_CLIENT_DISPATCHER = new NetconfClientDispatcher(Optional.<SSLContext>absent());
+ private NetconfClientDispatcher clientDispatcher;
@Before
public void setUp() throws Exception {
NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl();
factoriesListener.onAddNetconfOperationServiceFactory(new NetconfOperationServiceFactoryImpl(getYangStore()));
+ nettyThreadgroup = new NioEventLoopGroup();
+
commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer());
dispatch = createDispatcher(Optional.<SSLContext> absent(), factoriesListener);
ChannelFuture s = dispatch.createServer(tcpAddress);
s.await();
+
+ clientDispatcher = new NetconfClientDispatcher(Optional.<SSLContext>absent(), nettyThreadgroup, nettyThreadgroup);
}
private NetconfServerDispatcher createDispatcher(Optional<SSLContext> sslC,
NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
factoriesListener, commitNot, idProvider);
- return new NetconfServerDispatcher(sslC, serverNegotiatorFactory, listenerFactory);
+ NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(
+ sslC, serverNegotiatorFactory, listenerFactory);
+ return new NetconfServerDispatcher(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup);
}
@After
public void tearDown() throws Exception {
commitNot.close();
- dispatch.close();
- }
-
- @AfterClass
- public static void tearDownStatic() {
- NETCONF_CLIENT_DISPATCHER.close();
+ nettyThreadgroup.shutdownGracefully();
}
private void loadMessages() throws IOException, SAXException, ParserConfigurationException {
@Test
public void testNetconfClientDemonstration() throws Exception {
- try (NetconfClient netconfClient = new NetconfClient("client", tcpAddress, 4000, NETCONF_CLIENT_DISPATCHER)) {
+ try (NetconfClient netconfClient = new NetconfClient("client", tcpAddress, 4000, clientDispatcher)) {
Set<String> capabilitiesFromNetconfServer = netconfClient.getCapabilities();
long sessionId = netconfClient.getSessionId();
@Test
public void testTwoSessions() throws Exception {
- try (NetconfClient netconfClient = new NetconfClient("1", tcpAddress, 4000, NETCONF_CLIENT_DISPATCHER)) {
- try (NetconfClient netconfClient2 = new NetconfClient("2", tcpAddress, 4000, NETCONF_CLIENT_DISPATCHER)) {
+ try (NetconfClient netconfClient = new NetconfClient("1", tcpAddress, 4000, clientDispatcher)) {
+ try (NetconfClient netconfClient2 = new NetconfClient("2", tcpAddress, 4000, clientDispatcher)) {
}
}
}
// final InputStream resourceAsStream =
// AbstractListenerTest.class.getResourceAsStream(fileName);
// assertNotNull(resourceAsStream);
- try (NetconfClient netconfClient = new NetconfClient("test", tcpAddress, 5000, NETCONF_CLIENT_DISPATCHER)) {
+ try (NetconfClient netconfClient = new NetconfClient("test", tcpAddress, 5000, clientDispatcher)) {
// IOUtils.copy(resourceAsStream, netconfClient.getStream());
// netconfClient.getOutputStream().write(NetconfMessageFactory.endOfMessage);
// server should not write anything back
}
private NetconfClient createSession(final InetSocketAddress address, final String expected) throws Exception {
- final NetconfClient netconfClient = new NetconfClient("test " + address.toString(), address, 5000, NETCONF_CLIENT_DISPATCHER);
+ final NetconfClient netconfClient = new NetconfClient("test " + address.toString(), address, 5000, clientDispatcher);
assertEquals(expected, Long.toString(netconfClient.getSessionId()));
return netconfClient;
}