Centralize NETCONF over SSH subsystem name
[netconf.git] / protocol / netconf-server / src / main / java / org / opendaylight / netconf / server / NetconfServerFactoryImpl.java
1 /*
2  * Copyright (c) 2023 PANTHEON.tech s.r.o. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netconf.server;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.util.concurrent.ListenableFuture;
13 import org.opendaylight.netconf.api.TransportConstants;
14 import org.opendaylight.netconf.server.api.NetconfServerFactory;
15 import org.opendaylight.netconf.transport.api.UnsupportedConfigurationException;
16 import org.opendaylight.netconf.transport.ssh.SSHServer;
17 import org.opendaylight.netconf.transport.ssh.SSHTransportStackFactory;
18 import org.opendaylight.netconf.transport.ssh.ServerFactoryManagerConfigurator;
19 import org.opendaylight.netconf.transport.tcp.TCPServer;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ssh.server.rev230417.SshServerGrouping;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.tcp.server.rev230417.TcpServerGrouping;
22
23 public final class NetconfServerFactoryImpl implements NetconfServerFactory {
24     private final SSHTransportStackFactory factory;
25     private final ServerChannelInitializer channelInitializer;
26
27     public NetconfServerFactoryImpl(final ServerChannelInitializer channelInitializer,
28             final SSHTransportStackFactory factory) {
29         this.factory = requireNonNull(factory);
30         this.channelInitializer = requireNonNull(channelInitializer);
31     }
32
33     @Override
34     public ListenableFuture<TCPServer> createTcpServer(final TcpServerGrouping params)
35             throws UnsupportedConfigurationException {
36         return TCPServer.listen(new ServerTransportInitializer(channelInitializer), factory.newServerBootstrap(),
37             params);
38     }
39
40     @Override
41     public ListenableFuture<SSHServer> createSshServer(final TcpServerGrouping tcpParams,
42             final SshServerGrouping sshParams, final ServerFactoryManagerConfigurator configurator)
43                 throws UnsupportedConfigurationException {
44         return factory.listenServer(TransportConstants.SSH_SUBSYSTEM,
45             new ServerTransportInitializer(channelInitializer), tcpParams, sshParams, configurator);
46     }
47 }