2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.netconf.it;
10 import java.net.InetSocketAddress;
12 import org.junit.After;
13 import org.junit.Before;
14 import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
15 import org.opendaylight.controller.netconf.client.SimpleNetconfClientSessionListener;
16 import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration;
17 import org.opendaylight.controller.netconf.client.conf.NetconfClientConfigurationBuilder;
18 import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer;
19 import org.opendaylight.controller.netconf.impl.NetconfServerDispatcher;
20 import org.opendaylight.controller.netconf.impl.NetconfServerSessionNegotiatorFactory;
21 import org.opendaylight.controller.netconf.impl.SessionIdProvider;
22 import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl;
23 import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService;
24 import org.opendaylight.protocol.framework.NeverReconnectStrategy;
26 import io.netty.channel.EventLoopGroup;
27 import io.netty.channel.nio.NioEventLoopGroup;
28 import io.netty.util.HashedWheelTimer;
29 import io.netty.util.concurrent.GlobalEventExecutor;
31 public class AbstractNetconfConfigTest extends AbstractConfigTest {
33 private EventLoopGroup nettyThreadgroup;
34 private HashedWheelTimer hashedWheelTimer;
37 public void setUpAbstractNetconfConfigTest() {
38 nettyThreadgroup = new NioEventLoopGroup();
39 hashedWheelTimer = new HashedWheelTimer();
42 protected NetconfServerDispatcher createDispatcher(
43 NetconfOperationServiceFactoryListenerImpl factoriesListener, SessionMonitoringService sessionMonitoringService,
44 DefaultCommitNotificationProducer commitNotifier) {
45 SessionIdProvider idProvider = new SessionIdProvider();
47 NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
48 hashedWheelTimer, factoriesListener, idProvider, 5000, commitNotifier, sessionMonitoringService);
50 NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(
51 serverNegotiatorFactory);
52 return new NetconfServerDispatcher(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup);
55 protected HashedWheelTimer getHashedWheelTimer() {
56 return hashedWheelTimer;
59 protected EventLoopGroup getNettyThreadgroup() {
60 return nettyThreadgroup;
64 public void cleanUpTimer() {
65 hashedWheelTimer.stop();
66 nettyThreadgroup.shutdownGracefully();
69 public NetconfClientConfiguration getClientConfiguration(final InetSocketAddress tcpAddress, final int timeout) {
70 final NetconfClientConfigurationBuilder b = NetconfClientConfigurationBuilder.create();
71 b.withAddress(tcpAddress);
72 b.withSessionListener(new SimpleNetconfClientSessionListener());
73 b.withReconnectStrategy(new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE,
75 b.withConnectionTimeoutMillis(timeout);