*/
package org.opendaylight.netconf.ssh;
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
-import org.apache.sshd.common.NamedFactory;
-import org.apache.sshd.common.io.IoInputStream;
-import org.apache.sshd.common.io.IoOutputStream;
-import org.apache.sshd.server.Environment;
-import org.apache.sshd.server.ExitCallback;
-import org.apache.sshd.server.SessionAware;
-import org.apache.sshd.server.command.AsyncCommand;
-import org.apache.sshd.server.command.Command;
-import org.apache.sshd.server.session.ServerSession;
import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader;
+import org.opendaylight.netconf.shaded.sshd.common.io.IoInputStream;
+import org.opendaylight.netconf.shaded.sshd.common.io.IoOutputStream;
+import org.opendaylight.netconf.shaded.sshd.server.Environment;
+import org.opendaylight.netconf.shaded.sshd.server.ExitCallback;
+import org.opendaylight.netconf.shaded.sshd.server.channel.ChannelSession;
+import org.opendaylight.netconf.shaded.sshd.server.command.AsyncCommand;
+import org.opendaylight.netconf.shaded.sshd.server.command.Command;
+import org.opendaylight.netconf.shaded.sshd.server.session.ServerSession;
+import org.opendaylight.netconf.shaded.sshd.server.subsystem.SubsystemFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* <p>
* Command is Apache Mina SSH terminology for objects handling ssh data.
*/
-public class RemoteNetconfCommand implements AsyncCommand, SessionAware {
+public class RemoteNetconfCommand implements AsyncCommand {
private static final Logger LOG = LoggerFactory.getLogger(RemoteNetconfCommand.class);
}
@Override
- public void start(final Environment env) {
+ 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();
} else {
LOG.warn("Unable to establish internal connection to netconf server for client: {}",
getClientAddress());
- Preconditions.checkNotNull(callback, "Exit callback must be set");
- callback.onExit(1, "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());
}
});
}
@Override
- public void destroy() {
+ public void destroy(final ChannelSession channel) {
LOG.trace("Releasing internal connection to netconf server for client: {} on channel: {}",
getClientAddress(), clientChannel);
return netconfHelloMessageAdditionalHeader.getAddress();
}
- @Override
- public void setSession(final ServerSession session) {
- final SocketAddress remoteAddress = session.getIoSession().getRemoteAddress();
- String hostName = "";
- String port = "";
- if (remoteAddress instanceof InetSocketAddress) {
- hostName = ((InetSocketAddress) remoteAddress).getAddress().getHostAddress();
- port = Integer.toString(((InetSocketAddress) remoteAddress).getPort());
- }
- netconfHelloMessageAdditionalHeader = new NetconfHelloMessageAdditionalHeader(
- session.getUsername(), hostName, port, "ssh", "client");
- }
-
- public static class NetconfCommandFactory implements NamedFactory<Command> {
+ public static class NetconfCommandFactory implements SubsystemFactory {
public static final String NETCONF = "netconf";
}
@Override
- public RemoteNetconfCommand create() {
+ public Command createSubsystem(final ChannelSession channel) {
return new RemoteNetconfCommand(clientBootstrap, localAddress);
}
}
-
}