Search in sources :

Example 6 with NetconfHelloMessageAdditionalHeader

use of org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader 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 7 with NetconfHelloMessageAdditionalHeader

use of org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader in project netconf by opendaylight.

the class NetconfServerSessionNegotiator method getSession.

@Override
@SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
protected NetconfServerSession getSession(NetconfServerSessionListener sessionListener, Channel channel, NetconfHelloMessage message) {
    Optional<NetconfHelloMessageAdditionalHeader> additionalHeader = message.getAdditionalHeader();
    NetconfHelloMessageAdditionalHeader parsedHeader;
    if (additionalHeader.isPresent()) {
        parsedHeader = additionalHeader.get();
    } else {
        parsedHeader = new NetconfHelloMessageAdditionalHeader(UNKNOWN, getHostName(channel.localAddress()).getValue(), getHostName(channel.localAddress()).getKey(), "tcp", "client");
    }
    LOG.debug("Additional header from hello parsed as {} from {}", parsedHeader, additionalHeader);
    return new NetconfServerSession(sessionListener, channel, getSessionPreferences().getSessionId(), parsedHeader);
}
Also used : NetconfHelloMessageAdditionalHeader(org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 8 with NetconfHelloMessageAdditionalHeader

use of org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader in project netconf by opendaylight.

the class NetconfServerSessionTest method testToManagementSession.

@Test
public void testToManagementSession() throws Exception {
    final NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader(USER, HOST, PORT, TCP_TRANSPORT, SESSION_ID);
    final EmbeddedChannel ch = new EmbeddedChannel();
    final NetconfServerSession tcpSession = new NetconfServerSession(listener, ch, 1L, header);
    tcpSession.sessionUp();
    final Session managementSession = tcpSession.toManagementSession();
    assertEquals(HOST, managementSession.getSourceHost().getIpAddress().getIpv4Address().getValue());
    assertEquals(managementSession.getUsername(), USER);
    assertEquals(managementSession.getSessionId().toString(), SESSION_ID);
    assertEquals(managementSession.getTransport(), NetconfTcp.class);
}
Also used : NetconfHelloMessageAdditionalHeader(org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Session(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.sessions.Session) Test(org.junit.Test)

Example 9 with NetconfHelloMessageAdditionalHeader

use of org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader in project netconf by opendaylight.

the class NetconfServerSessionTest method testToManagementSessionUnknownTransport.

@Test(expected = IllegalArgumentException.class)
public void testToManagementSessionUnknownTransport() throws Exception {
    final NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader(USER, HOST, PORT, "http", SESSION_ID);
    final EmbeddedChannel ch = new EmbeddedChannel();
    final NetconfServerSession tcpSession = new NetconfServerSession(listener, ch, 1L, header);
    tcpSession.sessionUp();
    tcpSession.toManagementSession();
    tcpSession.close();
}
Also used : NetconfHelloMessageAdditionalHeader(org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Example 10 with NetconfHelloMessageAdditionalHeader

use of org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader in project netconf by opendaylight.

the class NetconfServerSessionTest method setUp.

@Before
public void setUp() throws Exception {
    final NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader(USER, HOST, PORT, SSH_TRANSPORT, SESSION_ID);
    channel = new EmbeddedChannel();
    session = new NetconfServerSession(listener, channel, 1L, header);
    doNothing().when(listener).onSessionUp(any());
    msg = new NetconfMessage(XmlUtil.readXmlToDocument("<rpc-reply></rpc-reply>"));
}
Also used : NetconfHelloMessageAdditionalHeader(org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Before(org.junit.Before)

Aggregations

NetconfHelloMessageAdditionalHeader (org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader)13 Test (org.junit.Test)8 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)4 InetSocketAddress (java.net.InetSocketAddress)4 ReconnectStrategy (org.opendaylight.netconf.nettyutil.ReconnectStrategy)4 AuthenticationHandler (org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler)4 NetconfClientConfiguration (org.opendaylight.netconf.client.conf.NetconfClientConfiguration)2 NetconfReconnectingClientConfiguration (org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration)2 ReconnectStrategyFactory (org.opendaylight.netconf.nettyutil.ReconnectStrategyFactory)2 Session (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.sessions.Session)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Bootstrap (io.netty.bootstrap.Bootstrap)1 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelPromise (io.netty.channel.ChannelPromise)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 LocalChannel (io.netty.channel.local.LocalChannel)1 HashedWheelTimer (io.netty.util.HashedWheelTimer)1 Timer (io.netty.util.Timer)1 GenericFutureListener (io.netty.util.concurrent.GenericFutureListener)1