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.mount;
10 import java.net.InetAddress;
11 import java.net.UnknownHostException;
12 import java.util.Optional;
13 import javax.inject.Inject;
14 import javax.inject.Singleton;
15 import org.opendaylight.netconf.callhome.server.CallHomeStatusRecorder;
16 import org.opendaylight.netconf.callhome.server.ssh.CallHomeSshAuthProvider;
17 import org.opendaylight.netconf.callhome.server.ssh.CallHomeSshServer;
18 import org.opendaylight.netconf.client.NetconfClientSessionNegotiatorFactory;
19 import org.opendaylight.netconf.common.NetconfTimer;
20 import org.osgi.service.component.annotations.Activate;
21 import org.osgi.service.component.annotations.Component;
22 import org.osgi.service.component.annotations.Deactivate;
23 import org.osgi.service.component.annotations.Reference;
24 import org.osgi.service.metatype.annotations.AttributeDefinition;
25 import org.osgi.service.metatype.annotations.Designate;
26 import org.osgi.service.metatype.annotations.ObjectClassDefinition;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 @Component(service = { }, configurationPid = "org.opendaylight.netconf.callhome.mount.ssh.server")
31 @Designate(ocd = IetfZeroTouchCallHomeServerProvider.Configuration.class)
33 public final class IetfZeroTouchCallHomeServerProvider implements AutoCloseable {
35 @ObjectClassDefinition
36 public @interface Configuration {
38 String host() default "0.0.0.0";
40 @AttributeDefinition(min = "1", max = "65535")
41 int port() default 4334;
44 private static final Logger LOG = LoggerFactory.getLogger(IetfZeroTouchCallHomeServerProvider.class);
45 private final CallHomeSshServer server;
49 public IetfZeroTouchCallHomeServerProvider(
50 final @Reference NetconfTimer timer,
51 final @Reference CallHomeMountService mountService,
52 final @Reference CallHomeSshAuthProvider authProvider,
53 final @Reference CallHomeStatusRecorder statusRecorder,
54 final Configuration configuration) {
56 LOG.info("Starting Call-Home SSH server at {}:{}", configuration.host(), configuration.port());
59 server = CallHomeSshServer.builder()
60 .withAddress(InetAddress.getByName(configuration.host()))
61 .withPort(configuration.port())
62 .withAuthProvider(authProvider)
63 .withStatusRecorder(statusRecorder)
64 .withSessionContextManager(mountService.createSshSessionContextManager())
65 .withNegotiationFactory(new NetconfClientSessionNegotiatorFactory(timer, Optional.empty(), 10000L,
66 NetconfClientSessionNegotiatorFactory.DEFAULT_CLIENT_CAPABILITIES))
68 } catch (UnknownHostException e) {
69 throw new IllegalArgumentException("Invalid address", e);
72 LOG.info("Call-Home SSH server started successfully");
77 public void close() throws Exception {
81 LOG.info("Call-Home SSH server stopped.");