d5e971659cf7362c5423d0653e5135de9b3a0ebb
[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.server.api.NetconfServerFactory;
14 import org.opendaylight.netconf.transport.api.UnsupportedConfigurationException;
15 import org.opendaylight.netconf.transport.ssh.SSHServer;
16 import org.opendaylight.netconf.transport.ssh.SSHTransportStackFactory;
17 import org.opendaylight.netconf.transport.ssh.ServerFactoryManagerConfigurator;
18 import org.opendaylight.netconf.transport.tcp.TCPServer;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ssh.server.rev230417.SshServerGrouping;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.tcp.server.rev230417.TcpServerGrouping;
21
22 public final class NetconfServerFactoryImpl implements NetconfServerFactory {
23     private final SSHTransportStackFactory factory;
24     private final ServerChannelInitializer channelInitializer;
25
26     public NetconfServerFactoryImpl(final ServerChannelInitializer channelInitializer,
27             final SSHTransportStackFactory factory) {
28         this.factory = requireNonNull(factory);
29         this.channelInitializer = requireNonNull(channelInitializer);
30     }
31
32     @Override
33     public ListenableFuture<TCPServer> createTcpServer(final TcpServerGrouping params)
34             throws UnsupportedConfigurationException {
35         return TCPServer.listen(new ServerTransportInitializer(channelInitializer), factory.newServerBootstrap(),
36             params);
37     }
38
39     @Override
40     public ListenableFuture<SSHServer> createSshServer(final TcpServerGrouping tcpParams,
41             final SshServerGrouping sshParams, final ServerFactoryManagerConfigurator configurator)
42                 throws UnsupportedConfigurationException {
43         return factory.listenServer("netconf", new ServerTransportInitializer(channelInitializer), tcpParams, sshParams,
44             configurator);
45     }
46 }