We have quite a few places which hard-code the "netconf" string.
Centralize them in TransportConstants along with pointer to where it is
defined.
JIRA: NETCONF-1106
JIRA: NETCONF-1108
Change-Id: Ifc273c084a59f52c37c7d123de7256f682d5a0d9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutionException;
+import org.opendaylight.netconf.api.TransportConstants;
import org.opendaylight.netconf.auth.AuthProvider;
import org.opendaylight.netconf.server.ServerChannelInitializer;
import org.opendaylight.netconf.server.ServerTransportInitializer;
public @interface Configuration {
@AttributeDefinition
String bindingAddress() default "0.0.0.0";
+ // NOTE: default is not TransportConstants.SSH_TCP_PORT to allow unprivileged execution
@AttributeDefinition(min = "1", max = "65535")
int portNumber() default 2830;
}
final var localPort = listenParams.requireLocalPort().getValue();
try {
- sshServer = factoryHolder.factory().listenServer("netconf", new ServerTransportInitializer(initializer),
- listenParams, null, factoryMgr -> {
+ sshServer = factoryHolder.factory().listenServer(TransportConstants.SSH_SUBSYSTEM,
+ new ServerTransportInitializer(initializer), listenParams, null, factoryMgr -> {
factoryMgr.setUserAuthFactories(List.of(UserAuthPasswordFactory.INSTANCE));
factoryMgr.setPasswordAuthenticator(
(username, password, session) -> authProvider.authenticated(username, password));
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.netconf.api.TransportConstants;
import org.opendaylight.netconf.client.NetconfClientSession;
import org.opendaylight.netconf.client.NetconfClientSessionListener;
import org.opendaylight.netconf.client.NetconfClientSessionNegotiatorFactory;
// Non-final for testing
class CallHomeSessionContext implements CallHomeProtocolSessionContext {
-
private static final Logger LOG = LoggerFactory.getLogger(CallHomeSessionContext.class);
- private static final String NETCONF = "netconf";
@VisibleForTesting
static final Session.AttributeKey<CallHomeSessionContext> SESSION_KEY = new Session.AttributeKey<>();
LOG.debug("Opening NETCONF Subsystem on {}", sshSession);
try {
final MinaSshNettyChannel nettyChannel = newMinaSshNettyChannel();
- final ClientChannel netconfChannel =
- ((NetconfClientSessionImpl) sshSession).createSubsystemChannel(NETCONF, nettyChannel.pipeline());
+ final ClientChannel netconfChannel = ((NetconfClientSessionImpl) sshSession).createSubsystemChannel(
+ TransportConstants.SSH_SUBSYSTEM, nettyChannel.pipeline());
netconfChannel.setStreaming(ClientChannel.Streaming.Async);
netconfChannel.open().addListener(newSshFutureListener(netconfChannel, nettyChannel));
} catch (IOException e) {
import org.checkerframework.checker.lock.qual.GuardedBy;
import org.checkerframework.checker.lock.qual.Holding;
import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.netconf.api.TransportConstants;
import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
import org.opendaylight.netconf.shaded.sshd.client.channel.ChannelSubsystem;
import org.opendaylight.netconf.shaded.sshd.client.channel.ClientChannel;
}
}
- public static final String SUBSYSTEM = "netconf";
-
public static final int SSH_DEFAULT_NIO_WORKERS = 8;
public static final NetconfSshClient DEFAULT_CLIENT;
final OpenFuture openFuture;
try {
- channel = clientSession.createSubsystemChannel(SUBSYSTEM, ctx);
+ channel = clientSession.createSubsystemChannel(TransportConstants.SSH_SUBSYSTEM, ctx);
channel.setStreaming(ClientChannel.Streaming.Async);
openFuture = channel.open();
} catch (final IOException e) {
--- /dev/null
+/*
+ * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.api;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * Various constants related to NETCONF transport layer.
+ */
+@NonNullByDefault
+public final class TransportConstants {
+ /**
+ * The name of the SSH subsystem used to carry NETCONF sessions, as defined in
+ * <a href="https://www.rfc-editor.org/rfc/rfc6242#section-7">RFC6242</a>.
+ */
+ public static final String SSH_SUBSYSTEM = "netconf";
+
+ /**
+ * The default TCP port to use for NETCONF over SSH, as defined in
+ * <a href="https://www.rfc-editor.org/rfc/rfc6242#section-7">RFC6242</a>.
+ */
+ public static final int SSH_TCP_PORT = 830;
+
+ private TransportConstants() {
+ // Hidden on purpose
+ }
+}
import io.netty.util.HashedWheelTimer;
import io.netty.util.Timer;
import javax.inject.Singleton;
+import org.opendaylight.netconf.api.TransportConstants;
import org.opendaylight.netconf.client.conf.NetconfClientConfiguration;
import org.opendaylight.netconf.transport.api.TransportChannel;
import org.opendaylight.netconf.transport.api.TransportChannelListener;
configuration.getTcpParameters(), configuration.getTransportSslHandlerFactory());
}
} else if (SSH.equals(protocol)) {
- factory.connectClient("netconf", new ClientTransportChannelListener(future, channelInitializer),
- configuration.getTcpParameters(), configuration.getSshParameters());
+ factory.connectClient(TransportConstants.SSH_SUBSYSTEM,
+ new ClientTransportChannelListener(future, channelInitializer), configuration.getTcpParameters(),
+ configuration.getSshParameters());
}
return future;
}
import static java.util.Objects.requireNonNull;
import com.google.common.util.concurrent.ListenableFuture;
+import org.opendaylight.netconf.api.TransportConstants;
import org.opendaylight.netconf.server.api.NetconfServerFactory;
import org.opendaylight.netconf.transport.api.UnsupportedConfigurationException;
import org.opendaylight.netconf.transport.ssh.SSHServer;
public ListenableFuture<SSHServer> createSshServer(final TcpServerGrouping tcpParams,
final SshServerGrouping sshParams, final ServerFactoryManagerConfigurator configurator)
throws UnsupportedConfigurationException {
- return factory.listenServer("netconf", new ServerTransportInitializer(channelInitializer), tcpParams, sshParams,
- configurator);
+ return factory.listenServer(TransportConstants.SSH_SUBSYSTEM,
+ new ServerTransportInitializer(channelInitializer), tcpParams, sshParams, configurator);
}
}