Merge "Bug-590: Packet loss on first time ping test"
[controller.git] / opendaylight / netconf / netconf-it / src / test / java / org / opendaylight / controller / netconf / it / AbstractNetconfConfigTest.java
index b261218bf1c17129b6761b48668519b5ca99ab29..d4073e5c178f1748ef71ee8466e70982646dab94 100644 (file)
@@ -7,23 +7,30 @@
  */
 package org.opendaylight.controller.netconf.it;
 
-import io.netty.channel.EventLoopGroup;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.util.HashedWheelTimer;
+import java.net.InetSocketAddress;
+
 import org.junit.After;
 import org.junit.Before;
 import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
+import org.opendaylight.controller.netconf.client.SimpleNetconfClientSessionListener;
+import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration;
+import org.opendaylight.controller.netconf.client.conf.NetconfClientConfigurationBuilder;
 import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer;
 import org.opendaylight.controller.netconf.impl.NetconfServerDispatcher;
-import org.opendaylight.controller.netconf.impl.NetconfServerSessionListenerFactory;
 import org.opendaylight.controller.netconf.impl.NetconfServerSessionNegotiatorFactory;
 import org.opendaylight.controller.netconf.impl.SessionIdProvider;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl;
 import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService;
+import org.opendaylight.protocol.framework.NeverReconnectStrategy;
+
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.util.HashedWheelTimer;
+import io.netty.util.concurrent.GlobalEventExecutor;
 
 public class AbstractNetconfConfigTest extends AbstractConfigTest {
 
-    protected EventLoopGroup nettyThreadgroup;
+    private EventLoopGroup nettyThreadgroup;
     private HashedWheelTimer hashedWheelTimer;
 
     @Before
@@ -32,24 +39,26 @@ public class AbstractNetconfConfigTest extends AbstractConfigTest {
         hashedWheelTimer = new HashedWheelTimer();
     }
 
-
     protected NetconfServerDispatcher createDispatcher(
             NetconfOperationServiceFactoryListenerImpl factoriesListener, SessionMonitoringService sessionMonitoringService,
             DefaultCommitNotificationProducer commitNotifier) {
         SessionIdProvider idProvider = new SessionIdProvider();
 
         NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
-                hashedWheelTimer, factoriesListener, idProvider, 5000);
-
-        NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
-                factoriesListener, commitNotifier, idProvider,
-                sessionMonitoringService);
+                hashedWheelTimer, factoriesListener, idProvider, 5000, commitNotifier, sessionMonitoringService);
 
         NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(
-                serverNegotiatorFactory, listenerFactory);
+                serverNegotiatorFactory);
         return new NetconfServerDispatcher(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup);
     }
 
+    protected HashedWheelTimer getHashedWheelTimer() {
+        return hashedWheelTimer;
+    }
+
+    protected EventLoopGroup getNettyThreadgroup() {
+        return nettyThreadgroup;
+    }
 
     @After
     public void cleanUpTimer() {
@@ -57,4 +66,13 @@ public class AbstractNetconfConfigTest extends AbstractConfigTest {
         nettyThreadgroup.shutdownGracefully();
     }
 
+    public NetconfClientConfiguration getClientConfiguration(final InetSocketAddress tcpAddress, final int timeout) {
+        final NetconfClientConfigurationBuilder b = NetconfClientConfigurationBuilder.create();
+        b.withAddress(tcpAddress);
+        b.withSessionListener(new SimpleNetconfClientSessionListener());
+        b.withReconnectStrategy(new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE,
+                timeout));
+        b.withConnectionTimeoutMillis(timeout);
+        return b.build();
+    }
 }