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.shaded.sshd.client.SshClient;
20 public class NetconfCallHomeServerBuilder {
21 private static final long DEFAULT_SESSION_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(5);
22 private static final int DEFAULT_CALL_HOME_PORT = 4334;
24 private SshClient sshClient;
25 private EventLoopGroup nettyGroup;
26 private NetconfClientSessionNegotiatorFactory negotiationFactory;
27 private InetSocketAddress bindAddress;
29 private final CallHomeAuthorizationProvider authProvider;
30 private final CallHomeNetconfSubsystemListener subsystemListener;
31 private final StatusRecorder recorder;
33 public NetconfCallHomeServerBuilder(final CallHomeAuthorizationProvider authProvider,
34 final CallHomeNetconfSubsystemListener subsystemListener, final StatusRecorder recorder) {
35 this.authProvider = authProvider;
36 this.subsystemListener = subsystemListener;
37 this.recorder = recorder;
40 public @NonNull NetconfCallHomeServer build() {
41 return new NetconfCallHomeServer(sshClient(), authProvider(),
42 new CallHomeSessionContext.Factory(nettyGroup(), negotiatorFactory(), subsystemListener()),
43 bindAddress(), recorder);
46 public SshClient getSshClient() {
50 public void setSshClient(final SshClient sshClient) {
51 this.sshClient = sshClient;
54 public EventLoopGroup getNettyGroup() {
58 public void setNettyGroup(final EventLoopGroup nettyGroup) {
59 this.nettyGroup = nettyGroup;
62 public NetconfClientSessionNegotiatorFactory getNegotiationFactory() {
63 return negotiationFactory;
66 public void setNegotiationFactory(final NetconfClientSessionNegotiatorFactory negotiationFactory) {
67 this.negotiationFactory = negotiationFactory;
70 public InetSocketAddress getBindAddress() {
74 public void setBindAddress(final InetSocketAddress bindAddress) {
75 this.bindAddress = bindAddress;
78 public CallHomeAuthorizationProvider getAuthProvider() {
82 private InetSocketAddress bindAddress() {
83 return bindAddress != null ? bindAddress : defaultBindAddress();
86 private EventLoopGroup nettyGroup() {
87 return nettyGroup != null ? nettyGroup : defaultNettyGroup();
90 private NetconfClientSessionNegotiatorFactory negotiatorFactory() {
91 return negotiationFactory != null ? negotiationFactory : defaultNegotiationFactory();
94 private CallHomeNetconfSubsystemListener subsystemListener() {
95 return subsystemListener;
98 private CallHomeAuthorizationProvider authProvider() {
102 private SshClient sshClient() {
103 return sshClient != null ? sshClient : defaultSshClient();
106 private static SshClient defaultSshClient() {
107 return SshClient.setUpDefaultClient();
110 private static NetconfClientSessionNegotiatorFactory defaultNegotiationFactory() {
111 return new NetconfClientSessionNegotiatorFactory(new HashedWheelTimer(),
112 Optional.empty(), DEFAULT_SESSION_TIMEOUT_MILLIS);
115 private static EventLoopGroup defaultNettyGroup() {
116 return new DefaultEventLoopGroup();
119 private static InetSocketAddress defaultBindAddress() {
120 return new InetSocketAddress(DEFAULT_CALL_HOME_PORT);