Search in sources :

Example 6 with NetconfClientSessionListener

use of org.opendaylight.netconf.client.NetconfClientSessionListener in project netconf by opendaylight.

the class AbstractNetconfTopology method setupConnection.

protected ListenableFuture<NetconfDeviceCapabilities> setupConnection(final NodeId nodeId, final Node configNode) {
    final NetconfNode netconfNode = configNode.augmentation(NetconfNode.class);
    final NetconfNodeAugmentedOptional nodeOptional = configNode.augmentation(NetconfNodeAugmentedOptional.class);
    requireNonNull(netconfNode.getHost());
    requireNonNull(netconfNode.getPort());
    final NetconfConnectorDTO deviceCommunicatorDTO = createDeviceCommunicator(nodeId, netconfNode, nodeOptional);
    final NetconfDeviceCommunicator deviceCommunicator = deviceCommunicatorDTO.getCommunicator();
    final NetconfClientSessionListener netconfClientSessionListener = deviceCommunicatorDTO.getSessionListener();
    final NetconfReconnectingClientConfiguration clientConfig = getClientConfig(netconfClientSessionListener, netconfNode);
    final ListenableFuture<NetconfDeviceCapabilities> future = deviceCommunicator.initializeRemoteConnection(clientDispatcher, clientConfig);
    activeConnectors.put(nodeId, deviceCommunicatorDTO);
    Futures.addCallback(future, new FutureCallback<NetconfDeviceCapabilities>() {

        @Override
        public void onSuccess(final NetconfDeviceCapabilities result) {
            LOG.debug("Connector for {} started succesfully", nodeId.getValue());
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Connector for {} failed", nodeId.getValue(), throwable);
        // remove this node from active connectors?
        }
    }, MoreExecutors.directExecutor());
    return future;
}
Also used : NetconfClientSessionListener(org.opendaylight.netconf.client.NetconfClientSessionListener) NetconfNodeAugmentedOptional(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.optional.rev190614.NetconfNodeAugmentedOptional) NetconfDeviceCommunicator(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator) NetconfDeviceCapabilities(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities) NetconfNode(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode) NetconfReconnectingClientConfiguration(org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration)

Example 7 with NetconfClientSessionListener

use of org.opendaylight.netconf.client.NetconfClientSessionListener 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 8 with NetconfClientSessionListener

use of org.opendaylight.netconf.client.NetconfClientSessionListener 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)

Example 9 with NetconfClientSessionListener

use of org.opendaylight.netconf.client.NetconfClientSessionListener in project netconf by opendaylight.

the class CallHomeMountSessionContextTest method activationOfListenerSupportsSessionDown.

@Test
public void activationOfListenerSupportsSessionDown() {
    // given
    when(mockActivator.activate(any(NetconfClientSessionListener.class))).thenAnswer(invocationOnMock -> {
        NetconfClientSession mockSession = mock(NetconfClientSession.class);
        Exception mockException = mock(Exception.class);
        Object arg = invocationOnMock.getArguments()[0];
        ((NetconfClientSessionListener) arg).onSessionDown(mockSession, mockException);
        return null;
    });
    // given
    NetconfClientSessionListener mockListener = mock(NetconfClientSessionListener.class);
    // when
    mockActivator.activate(mockListener);
    // then
    verify(mockListener, times(1)).onSessionDown(any(NetconfClientSession.class), any(Exception.class));
}
Also used : NetconfClientSessionListener(org.opendaylight.netconf.client.NetconfClientSessionListener) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession) Test(org.junit.Test)

Aggregations

NetconfClientSessionListener (org.opendaylight.netconf.client.NetconfClientSessionListener)9 Test (org.junit.Test)6 NetconfClientSession (org.opendaylight.netconf.client.NetconfClientSession)4 NetconfReconnectingClientConfiguration (org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration)4 NetconfNode (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode)3 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 LoginPasswordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPasswordBuilder)2 BigDecimal (java.math.BigDecimal)1 InetSocketAddress (java.net.InetSocketAddress)1 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)1 NetconfTerminationReason (org.opendaylight.netconf.api.NetconfTerminationReason)1 NetconfHelloMessageAdditionalHeader (org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader)1 NetconfClientConfiguration (org.opendaylight.netconf.client.conf.NetconfClientConfiguration)1 ReconnectStrategy (org.opendaylight.netconf.nettyutil.ReconnectStrategy)1