Search in sources :

Example 1 with NetconfClientConfiguration

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

the class CallHomeMountDispatcherTest method someConfiguration.

NetconfClientConfiguration someConfiguration(final InetSocketAddress address) {
    // NetconfClientConfiguration has mostly final methods, making it un-mock-able
    final NetconfClientConfiguration.NetconfClientProtocol protocol = NetconfClientConfiguration.NetconfClientProtocol.SSH;
    final NetconfHelloMessageAdditionalHeader additionalHeader = mock(NetconfHelloMessageAdditionalHeader.class);
    final NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class);
    final ReconnectStrategy reconnectStrategy = mock(ReconnectStrategy.class);
    final AuthenticationHandler authHandler = mock(AuthenticationHandler.class);
    return NetconfClientConfigurationBuilder.create().withProtocol(protocol).withAddress(address).withConnectionTimeoutMillis(0).withAdditionalHeader(additionalHeader).withSessionListener(sessionListener).withReconnectStrategy(reconnectStrategy).withAuthHandler(authHandler).build();
}
Also used : NetconfClientSessionListener(org.opendaylight.netconf.client.NetconfClientSessionListener) NetconfHelloMessageAdditionalHeader(org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader) ReconnectStrategy(org.opendaylight.netconf.nettyutil.ReconnectStrategy) NetconfClientConfiguration(org.opendaylight.netconf.client.conf.NetconfClientConfiguration) AuthenticationHandler(org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler)

Example 2 with NetconfClientConfiguration

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

the class TestToolTest method invokeRpc.

private Document invokeRpc(final Configuration simulatorConfig, final String xmlRequest) throws Exception {
    // GIVEN
    int localPort = launchSimulator(simulatorConfig);
    SimpleNetconfClientSessionListener sessionListener = new SimpleNetconfClientSessionListener();
    NetconfClientConfiguration clientConfig = getClientConfig("localhost", localPort, simulatorConfig, sessionListener);
    Document docRequest = XmlUtil.readXmlToDocument(xmlRequest);
    NetconfMessage request = new NetconfMessage(docRequest);
    // WHEN
    NetconfMessage response;
    try (NetconfClientSession ignored = dispatcher.createClient(clientConfig).get()) {
        response = sessionListener.sendRequest(request).get(RECEIVE_TIMEOUT_MS, TimeUnit.MILLISECONDS);
    }
    // THEN
    assertNotNull(response);
    return response.getDocument();
}
Also used : NetconfClientConfiguration(org.opendaylight.netconf.client.conf.NetconfClientConfiguration) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) SimpleNetconfClientSessionListener(org.opendaylight.netconf.client.SimpleNetconfClientSessionListener) Document(org.w3c.dom.Document) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession)

Example 3 with NetconfClientConfiguration

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

the class NetconfClientConfigurationTest method testNetconfClientConfiguration.

@Test
public void testNetconfClientConfiguration() throws Exception {
    Long timeout = 200L;
    NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader("a", "host", "port", "trans", "id");
    NetconfClientSessionListener listener = new SimpleNetconfClientSessionListener();
    InetSocketAddress address = InetSocketAddress.createUnresolved("host", 830);
    ReconnectStrategy strategy = Mockito.mock(ReconnectStrategy.class);
    AuthenticationHandler handler = Mockito.mock(AuthenticationHandler.class);
    NetconfClientConfiguration cfg = NetconfClientConfigurationBuilder.create().withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH).withAddress(address).withConnectionTimeoutMillis(timeout).withReconnectStrategy(strategy).withAdditionalHeader(header).withSessionListener(listener).withAuthHandler(handler).build();
    Assert.assertEquals(timeout, cfg.getConnectionTimeoutMillis());
    Assert.assertEquals(Optional.of(header), cfg.getAdditionalHeader());
    Assert.assertEquals(listener, cfg.getSessionListener());
    Assert.assertEquals(handler, cfg.getAuthHandler());
    Assert.assertEquals(strategy, cfg.getReconnectStrategy());
    Assert.assertEquals(NetconfClientConfiguration.NetconfClientProtocol.SSH, cfg.getProtocol());
    Assert.assertEquals(address, cfg.getAddress());
    SslHandlerFactory sslHandlerFactory = Mockito.mock(SslHandlerFactory.class);
    NetconfClientConfiguration cfg2 = NetconfClientConfigurationBuilder.create().withProtocol(NetconfClientConfiguration.NetconfClientProtocol.TLS).withAddress(address).withConnectionTimeoutMillis(timeout).withReconnectStrategy(strategy).withAdditionalHeader(header).withSessionListener(listener).withSslHandlerFactory(sslHandlerFactory).build();
    Assert.assertEquals(timeout, cfg2.getConnectionTimeoutMillis());
    Assert.assertEquals(Optional.of(header), cfg2.getAdditionalHeader());
    Assert.assertEquals(listener, cfg2.getSessionListener());
    Assert.assertEquals(sslHandlerFactory, cfg2.getSslHandlerFactory());
    Assert.assertEquals(strategy, cfg2.getReconnectStrategy());
    Assert.assertEquals(NetconfClientConfiguration.NetconfClientProtocol.TLS, cfg2.getProtocol());
    Assert.assertEquals(address, cfg2.getAddress());
}
Also used : NetconfHelloMessageAdditionalHeader(org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader) ReconnectStrategy(org.opendaylight.netconf.nettyutil.ReconnectStrategy) NetconfClientConfiguration(org.opendaylight.netconf.client.conf.NetconfClientConfiguration) InetSocketAddress(java.net.InetSocketAddress) AuthenticationHandler(org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler) Test(org.junit.Test)

Example 4 with NetconfClientConfiguration

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

the class CallHomeMountDispatcherTest method canCreateASessionFromAConfiguration.

@Test
public void canCreateASessionFromAConfiguration() {
    // given
    final CallHomeMountSessionContext mockContext = mock(CallHomeMountSessionContext.class);
    final InetSocketAddress someAddress = InetSocketAddress.createUnresolved("1.2.3.4", 123);
    doReturn(mockContext).when(mockSessMgr).getByAddress(eq(someAddress));
    final NetconfClientConfiguration someCfg = someConfiguration(someAddress);
    // when
    instance.createClient(someCfg);
    // then
    verify(mockContext, times(1)).activateNetconfChannel(any(NetconfClientSessionListener.class));
}
Also used : NetconfClientSessionListener(org.opendaylight.netconf.client.NetconfClientSessionListener) NetconfClientConfiguration(org.opendaylight.netconf.client.conf.NetconfClientConfiguration) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test)

Example 5 with NetconfClientConfiguration

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

the class CallHomeMountDispatcherTest method noSessionIsCreatedWithoutAContextAvailableForAGivenAddress.

@Test
public void noSessionIsCreatedWithoutAContextAvailableForAGivenAddress() {
    // given
    final InetSocketAddress someAddress = InetSocketAddress.createUnresolved("1.2.3.4", 123);
    final NetconfClientConfiguration someCfg = someConfiguration(someAddress);
    // when
    final Future<NetconfClientSession> future = instance.createClient(someCfg);
    // then
    assertFalse(future.isSuccess());
}
Also used : NetconfClientConfiguration(org.opendaylight.netconf.client.conf.NetconfClientConfiguration) InetSocketAddress(java.net.InetSocketAddress) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession) Test(org.junit.Test)

Aggregations

NetconfClientConfiguration (org.opendaylight.netconf.client.conf.NetconfClientConfiguration)5 InetSocketAddress (java.net.InetSocketAddress)3 Test (org.junit.Test)3 NetconfHelloMessageAdditionalHeader (org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader)2 NetconfClientSession (org.opendaylight.netconf.client.NetconfClientSession)2 NetconfClientSessionListener (org.opendaylight.netconf.client.NetconfClientSessionListener)2 ReconnectStrategy (org.opendaylight.netconf.nettyutil.ReconnectStrategy)2 AuthenticationHandler (org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler)2 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)1 SimpleNetconfClientSessionListener (org.opendaylight.netconf.client.SimpleNetconfClientSessionListener)1 Document (org.w3c.dom.Document)1