2 * Copyright (c) 2016 Brocade Communication Systems and others. All rights reserved.
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
8 package org.opendaylight.netconf.callhome.protocol;
10 import io.netty.channel.DefaultEventLoopGroup;
11 import io.netty.channel.EventLoopGroup;
12 import io.netty.util.HashedWheelTimer;
13 import java.net.InetSocketAddress;
14 import java.util.Optional;
15 import java.util.concurrent.TimeUnit;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.opendaylight.netconf.client.NetconfClientSessionNegotiatorFactory;
18 import org.opendaylight.netconf.nettyutil.handler.ssh.client.NetconfClientBuilder;
19 import org.opendaylight.netconf.shaded.sshd.client.SshClient;
21 public class NetconfCallHomeServerBuilder {
22 private static final long DEFAULT_SESSION_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(5);
23 private static final int DEFAULT_CALL_HOME_PORT = 4334;
25 private SshClient sshClient;
26 private EventLoopGroup nettyGroup;
27 private NetconfClientSessionNegotiatorFactory negotiationFactory;
28 private InetSocketAddress bindAddress;
30 private final CallHomeAuthorizationProvider authProvider;
31 private final CallHomeNetconfSubsystemListener subsystemListener;
32 private final StatusRecorder recorder;
34 public NetconfCallHomeServerBuilder(final CallHomeAuthorizationProvider authProvider,
35 final CallHomeNetconfSubsystemListener subsystemListener, final StatusRecorder recorder) {
36 this.authProvider = authProvider;
37 this.subsystemListener = subsystemListener;
38 this.recorder = recorder;
41 public @NonNull NetconfCallHomeServer build() {
42 return new NetconfCallHomeServer(sshClient(), authProvider(),
43 new CallHomeSessionContext.Factory(nettyGroup(), negotiatorFactory(), subsystemListener()),
44 bindAddress(), recorder);
47 public SshClient getSshClient() {
51 public void setSshClient(final SshClient sshClient) {
52 this.sshClient = sshClient;
55 public EventLoopGroup getNettyGroup() {
59 public void setNettyGroup(final EventLoopGroup nettyGroup) {
60 this.nettyGroup = nettyGroup;
63 public NetconfClientSessionNegotiatorFactory getNegotiationFactory() {
64 return negotiationFactory;
67 public void setNegotiationFactory(final NetconfClientSessionNegotiatorFactory negotiationFactory) {
68 this.negotiationFactory = negotiationFactory;
71 public InetSocketAddress getBindAddress() {
75 public void setBindAddress(final InetSocketAddress bindAddress) {
76 this.bindAddress = bindAddress;
79 public CallHomeAuthorizationProvider getAuthProvider() {
83 private InetSocketAddress bindAddress() {
84 return bindAddress != null ? bindAddress : defaultBindAddress();
87 private EventLoopGroup nettyGroup() {
88 return nettyGroup != null ? nettyGroup : defaultNettyGroup();
91 private NetconfClientSessionNegotiatorFactory negotiatorFactory() {
92 return negotiationFactory != null ? negotiationFactory : defaultNegotiationFactory();
95 private CallHomeNetconfSubsystemListener subsystemListener() {
96 return subsystemListener;
99 private CallHomeAuthorizationProvider authProvider() {
103 private SshClient sshClient() {
104 return sshClient != null ? sshClient : defaultSshClient();
107 private static SshClient defaultSshClient() {
108 return new NetconfClientBuilder().build();
111 private static NetconfClientSessionNegotiatorFactory defaultNegotiationFactory() {
112 return new NetconfClientSessionNegotiatorFactory(new HashedWheelTimer(),
113 Optional.empty(), DEFAULT_SESSION_TIMEOUT_MILLIS);
116 private static EventLoopGroup defaultNettyGroup() {
117 return new DefaultEventLoopGroup();
120 private static InetSocketAddress defaultBindAddress() {
121 return new InetSocketAddress(DEFAULT_CALL_HOME_PORT);