2 * Copyright (c) 2013 Cisco Systems, Inc. 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.controller.netconf.ssh;
10 import java.io.IOException;
11 import java.net.InetSocketAddress;
12 import java.net.ServerSocket;
13 import java.util.concurrent.atomic.AtomicLong;
14 import javax.annotation.concurrent.ThreadSafe;
15 import org.opendaylight.controller.netconf.ssh.threads.SocketThread;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 public class NetconfSSHServer implements Runnable {
22 private static boolean acceptMore = true;
23 private ServerSocket ss = null;
24 private static final Logger logger = LoggerFactory.getLogger(NetconfSSHServer.class);
25 private static final AtomicLong sesssionId = new AtomicLong();
26 private final InetSocketAddress clientAddress;
28 private NetconfSSHServer(int serverPort,InetSocketAddress clientAddress) throws Exception{
30 logger.trace("Creating SSH server socket on port {}",serverPort);
31 this.ss = new ServerSocket(serverPort);
33 throw new Exception("Socket can't be bound to requested port :"+serverPort);
35 logger.trace("Server socket created.");
36 this.clientAddress = clientAddress;
41 public static NetconfSSHServer start(int serverPort, InetSocketAddress clientAddress) throws Exception {
42 return new NetconfSSHServer(serverPort, clientAddress);
45 public void stop() throws Exception {
47 logger.trace("Closing SSH server socket.");
49 logger.trace("SSH server socket closed.");
55 logger.trace("Starting new socket thread.");
57 SocketThread.start(ss.accept(), clientAddress, sesssionId.incrementAndGet());
58 } catch (IOException e) {
59 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.