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
9 package org.opendaylight.netconf.callhome.protocol;
11 import com.google.common.base.Optional;
12 import io.netty.channel.EventLoopGroup;
13 import io.netty.channel.local.LocalEventLoopGroup;
14 import io.netty.util.HashedWheelTimer;
15 import java.net.InetSocketAddress;
16 import java.util.concurrent.TimeUnit;
17 import org.apache.sshd.client.SshClient;
18 import org.opendaylight.netconf.callhome.protocol.CallHomeSessionContext.Factory;
19 import org.opendaylight.netconf.client.NetconfClientSessionNegotiatorFactory;
20 import org.opendaylight.yangtools.concepts.Builder;
22 public class NetconfCallHomeServerBuilder implements Builder<NetconfCallHomeServer> {
24 private static final long DEFAULT_SESSION_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(5);
25 private static final int DEFAULT_CALL_HOME_PORT = 6666;
27 private SshClient sshClient;
28 private EventLoopGroup nettyGroup;
29 private NetconfClientSessionNegotiatorFactory negotiationFactory;
30 private InetSocketAddress bindAddress;
32 private final CallHomeAuthorizationProvider authProvider;
33 private final CallHomeNetconfSubsystemListener subsystemListener;
34 private final StatusRecorder recorder;
36 public NetconfCallHomeServerBuilder(final CallHomeAuthorizationProvider authProvider,
37 final CallHomeNetconfSubsystemListener subsystemListener, final StatusRecorder recorder) {
38 this.authProvider = authProvider;
39 this.subsystemListener = subsystemListener;
40 this.recorder = recorder;
44 public NetconfCallHomeServer build() {
46 new CallHomeSessionContext.Factory(nettyGroup(), negotiatorFactory(), subsystemListener());
47 return new NetconfCallHomeServer(sshClient(), authProvider(), factory, bindAddress(), this.recorder);
50 public SshClient getSshClient() {
54 public void setSshClient(final SshClient sshClient) {
55 this.sshClient = sshClient;
58 public EventLoopGroup getNettyGroup() {
62 public void setNettyGroup(final EventLoopGroup nettyGroup) {
63 this.nettyGroup = nettyGroup;
66 public NetconfClientSessionNegotiatorFactory getNegotiationFactory() {
67 return negotiationFactory;
70 public void setNegotiationFactory(final NetconfClientSessionNegotiatorFactory negotiationFactory) {
71 this.negotiationFactory = negotiationFactory;
74 public InetSocketAddress getBindAddress() {
78 public void setBindAddress(final InetSocketAddress bindAddress) {
79 this.bindAddress = bindAddress;
82 public CallHomeAuthorizationProvider getAuthProvider() {
86 private InetSocketAddress bindAddress() {
87 return bindAddress != null ? bindAddress : defaultBindAddress();
90 private EventLoopGroup nettyGroup() {
91 return nettyGroup != null ? nettyGroup : defaultNettyGroup();
94 private NetconfClientSessionNegotiatorFactory negotiatorFactory() {
95 return negotiationFactory != null ? negotiationFactory : defaultNegotiationFactory();
98 private CallHomeNetconfSubsystemListener subsystemListener() {
99 return subsystemListener;
102 private CallHomeAuthorizationProvider authProvider() {
106 private SshClient sshClient() {
107 return sshClient != null ? sshClient : defaultSshClient();
110 private static SshClient defaultSshClient() {
111 return SshClient.setUpDefaultClient();
114 private static NetconfClientSessionNegotiatorFactory defaultNegotiationFactory() {
115 return new NetconfClientSessionNegotiatorFactory(new HashedWheelTimer(),
116 Optional.absent(), DEFAULT_SESSION_TIMEOUT_MILLIS);
119 private static EventLoopGroup defaultNettyGroup() {
120 return new LocalEventLoopGroup();
123 private static InetSocketAddress defaultBindAddress() {
124 return new InetSocketAddress(DEFAULT_CALL_HOME_PORT);