Search in sources :

Example 1 with ServerSession

use of org.opendaylight.netconf.shaded.sshd.server.session.ServerSession 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

Bootstrap (io.netty.bootstrap.Bootstrap)1 LocalChannel (io.netty.channel.local.LocalChannel)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 NetconfHelloMessageAdditionalHeader (org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader)1 ServerSession (org.opendaylight.netconf.shaded.sshd.server.session.ServerSession)1