Search in sources :

Example 6 with NetconfReconnectingClientConfiguration

use of org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration in project netconf by opendaylight.

the class RemoteDeviceConnectorImpl method startRemoteDeviceConnection.

@Override
public void startRemoteDeviceConnection(final RemoteDeviceHandler<NetconfSessionPreferences> deviceHandler) {
    final NetconfNode netconfNode = netconfTopologyDeviceSetup.getNode().augmentation(NetconfNode.class);
    final NodeId nodeId = netconfTopologyDeviceSetup.getNode().getNodeId();
    requireNonNull(netconfNode.getHost());
    requireNonNull(netconfNode.getPort());
    this.deviceCommunicatorDTO = createDeviceCommunicator(nodeId, netconfNode, deviceHandler);
    final NetconfDeviceCommunicator deviceCommunicator = deviceCommunicatorDTO.getCommunicator();
    final NetconfClientSessionListener netconfClientSessionListener = deviceCommunicatorDTO.getSessionListener();
    final NetconfReconnectingClientConfiguration clientConfig = getClientConfig(netconfClientSessionListener, netconfNode);
    final ListenableFuture<NetconfDeviceCapabilities> future = deviceCommunicator.initializeRemoteConnection(netconfTopologyDeviceSetup.getNetconfClientDispatcher(), clientConfig);
    Futures.addCallback(future, new FutureCallback<NetconfDeviceCapabilities>() {

        @Override
        public void onSuccess(final NetconfDeviceCapabilities result) {
            LOG.debug("{}: Connector started successfully", remoteDeviceId);
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("{}: Connector failed", remoteDeviceId, throwable);
        }
    }, MoreExecutors.directExecutor());
}
Also used : NetconfClientSessionListener(org.opendaylight.netconf.client.NetconfClientSessionListener) NetconfDeviceCommunicator(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator) NetconfDeviceCapabilities(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) NetconfNode(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode) NetconfReconnectingClientConfiguration(org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration)

Example 7 with NetconfReconnectingClientConfiguration

use of org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration in project netconf by opendaylight.

the class NetconfTopologyImplTest method testGetClientConfig.

@Test
public void testGetClientConfig() {
    final NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class);
    final NetconfNodeBuilder nodeBuilder = new NetconfNodeBuilder().setHost(new Host(new IpAddress(new Ipv4Address("127.0.0.1")))).setPort(new PortNumber(Uint16.valueOf(9999))).setReconnectOnChangedSchema(true).setDefaultRequestTimeoutMillis(Uint32.valueOf(1000)).setBetweenAttemptsTimeoutMillis(Uint16.valueOf(100)).setKeepaliveDelay(Uint32.valueOf(1000)).setCredentials(new LoginPasswordBuilder().setUsername("testuser").setPassword("testpassword").build()).setMaxConnectionAttempts(Uint32.ZERO).setSleepFactor(new BigDecimal("1.5")).setConnectionTimeoutMillis(Uint32.valueOf(20000));
    final NetconfReconnectingClientConfiguration configuration = spyTopology.getClientConfig(sessionListener, nodeBuilder.setTcpOnly(true).build());
    assertEquals(NetconfClientConfiguration.NetconfClientProtocol.TCP, configuration.getProtocol());
    assertNotNull(configuration.getAuthHandler());
    assertNull(configuration.getSslHandlerFactory());
    final NetconfReconnectingClientConfiguration configuration2 = spyTopology.getClientConfig(sessionListener, nodeBuilder.setTcpOnly(false).build());
    assertEquals(NetconfClientConfiguration.NetconfClientProtocol.SSH, configuration2.getProtocol());
    assertNotNull(configuration2.getAuthHandler());
    assertNull(configuration2.getSslHandlerFactory());
    final NetconfReconnectingClientConfiguration configuration3 = spyTopology.getClientConfig(sessionListener, nodeBuilder.setProtocol(new ProtocolBuilder().setName(Name.SSH).build()).build());
    assertEquals(NetconfClientConfiguration.NetconfClientProtocol.SSH, configuration3.getProtocol());
    assertNotNull(configuration3.getAuthHandler());
    assertNull(configuration3.getSslHandlerFactory());
    final NetconfReconnectingClientConfiguration configuration4 = spyTopology.getClientConfig(sessionListener, nodeBuilder.setProtocol(new ProtocolBuilder().setName(Name.TLS).build()).build());
    assertEquals(NetconfClientConfiguration.NetconfClientProtocol.TLS, configuration4.getProtocol());
    assertNull(configuration4.getAuthHandler());
    assertNotNull(configuration4.getSslHandlerFactory());
}
Also used : NetconfClientSessionListener(org.opendaylight.netconf.client.NetconfClientSessionListener) NetconfNodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder) ProtocolBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.ProtocolBuilder) Host(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) LoginPasswordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPasswordBuilder) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber) NetconfReconnectingClientConfiguration(org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration) BigDecimal(java.math.BigDecimal) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Test(org.junit.Test)

Aggregations

NetconfReconnectingClientConfiguration (org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration)7 Test (org.junit.Test)5 InetSocketAddress (java.net.InetSocketAddress)4 NetconfClientSessionListener (org.opendaylight.netconf.client.NetconfClientSessionListener)4 ReconnectStrategy (org.opendaylight.netconf.nettyutil.ReconnectStrategy)3 NetconfNode (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode)3 ChannelFuture (io.netty.channel.ChannelFuture)2 EventLoopGroup (io.netty.channel.EventLoopGroup)2 HashedWheelTimer (io.netty.util.HashedWheelTimer)2 Timer (io.netty.util.Timer)2 NetconfHelloMessageAdditionalHeader (org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader)2 ReconnectStrategyFactory (org.opendaylight.netconf.nettyutil.ReconnectStrategyFactory)2 AuthenticationHandler (org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler)2 NetconfDeviceCapabilities (org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities)2 NetconfDeviceCommunicator (org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator)2 Host (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host)2 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)2 PortNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber)2 NetconfNodeBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder)2