Search in sources :

Example 11 with NetconfHelloMessageAdditionalHeader

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

the class AdditionalHeaderParserTest method testParsing2.

@Test
public void testParsing2() throws Exception {
    String message = "[tomas;10.0.0.0/10000;tcp;1000;1000;;/home/tomas;;]";
    NetconfHelloMessageAdditionalHeader header = NetconfHelloMessageAdditionalHeader.fromString(message);
    assertEquals("tomas", header.getUserName());
    assertEquals("10.0.0.0", header.getAddress());
    assertEquals("tcp", header.getTransport());
}
Also used : NetconfHelloMessageAdditionalHeader(org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader) Test(org.junit.Test)

Example 12 with NetconfHelloMessageAdditionalHeader

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

the class StressClientCallable method getNetconfClientConfiguration.

private static NetconfClientConfiguration getNetconfClientConfiguration(final Parameters params, final NetconfDeviceCommunicator sessionListener) {
    final NetconfClientConfigurationBuilder netconfClientConfigurationBuilder = NetconfClientConfigurationBuilder.create();
    netconfClientConfigurationBuilder.withSessionListener(sessionListener);
    netconfClientConfigurationBuilder.withAddress(params.getInetAddress());
    if (params.tcpHeader != null) {
        final String header = params.tcpHeader.replaceAll("\"", "").trim() + "\n";
        netconfClientConfigurationBuilder.withAdditionalHeader(new NetconfHelloMessageAdditionalHeader(null, null, null, null, null) {

            @Override
            public String toFormattedString() {
                LOG.debug("Sending TCP header {}", header);
                return header;
            }
        });
    }
    netconfClientConfigurationBuilder.withProtocol(params.ssh ? NetconfClientConfiguration.NetconfClientProtocol.SSH : NetconfClientConfiguration.NetconfClientProtocol.TCP);
    netconfClientConfigurationBuilder.withAuthHandler(new LoginPasswordHandler(params.username, params.password));
    netconfClientConfigurationBuilder.withConnectionTimeoutMillis(20000L);
    netconfClientConfigurationBuilder.withReconnectStrategy(new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000));
    return netconfClientConfigurationBuilder.build();
}
Also used : NetconfHelloMessageAdditionalHeader(org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader) LoginPasswordHandler(org.opendaylight.netconf.nettyutil.handler.ssh.authentication.LoginPasswordHandler) NeverReconnectStrategy(org.opendaylight.netconf.nettyutil.NeverReconnectStrategy) NetconfClientConfigurationBuilder(org.opendaylight.netconf.client.conf.NetconfClientConfigurationBuilder)

Example 13 with NetconfHelloMessageAdditionalHeader

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

the class RemoteNetconfCommand method start.

@Override
public void start(final ChannelSession channel, final Environment env) {
    final ServerSession session = channel.getServerSession();
    final SocketAddress remoteAddress = session.getIoSession().getRemoteAddress();
    final String hostName;
    final String port;
    if (remoteAddress instanceof InetSocketAddress) {
        hostName = ((InetSocketAddress) remoteAddress).getAddress().getHostAddress();
        port = Integer.toString(((InetSocketAddress) remoteAddress).getPort());
    } else {
        hostName = "";
        port = "";
    }
    netconfHelloMessageAdditionalHeader = new NetconfHelloMessageAdditionalHeader(session.getUsername(), hostName, port, "ssh", "client");
    LOG.trace("Establishing internal connection to netconf server for client: {}", getClientAddress());
    final Bootstrap clientBootstrap = new Bootstrap();
    clientBootstrap.group(clientEventGroup).channel(LocalChannel.class);
    clientBootstrap.handler(new ChannelInitializer<LocalChannel>() {

        @Override
        public void initChannel(final LocalChannel ch) {
            ch.pipeline().addLast(new SshProxyClientHandler(in, out, netconfHelloMessageAdditionalHeader, callback));
        }
    });
    clientChannelFuture = clientBootstrap.connect(localAddress);
    clientChannelFuture.addListener(future -> {
        if (future.isSuccess()) {
            clientChannel = clientChannelFuture.channel();
        } else {
            LOG.warn("Unable to establish internal connection to netconf server for client: {}", getClientAddress());
            requireNonNull(callback, "Exit callback must be set").onExit(1, "Unable to establish internal connection to netconf server for client: " + getClientAddress());
        }
    });
}
Also used : ServerSession(org.opendaylight.netconf.shaded.sshd.server.session.ServerSession) NetconfHelloMessageAdditionalHeader(org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader) InetSocketAddress(java.net.InetSocketAddress) LocalChannel(io.netty.channel.local.LocalChannel) Bootstrap(io.netty.bootstrap.Bootstrap) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

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