4 * Generated from: yang module name: opendaylight-sal-netconf-connector yang module local name: sal-netconf-connector
5 * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
6 * Generated at: Mon Nov 18 09:44:16 CET 2013
8 * Do not modify this file unless it is present under src/main directory
10 package org.opendaylight.controller.config.yang.md.sal.connector.netconf;
12 import io.netty.channel.EventLoopGroup;
13 import io.netty.util.concurrent.GlobalEventExecutor;
15 import java.net.InetAddress;
16 import java.net.InetSocketAddress;
18 import javax.net.ssl.SSLContext;
20 import org.opendaylight.controller.netconf.client.NetconfClientDispatcher;
21 import org.opendaylight.controller.netconf.client.NetconfSshClientDispatcher;
22 import org.opendaylight.controller.netconf.util.handler.ssh.authentication.AuthenticationHandler;
23 import org.opendaylight.controller.netconf.util.handler.ssh.authentication.LoginPassword;
24 import org.opendaylight.controller.sal.connect.netconf.NetconfDevice;
25 import org.opendaylight.protocol.framework.ReconnectStrategy;
26 import org.opendaylight.protocol.framework.TimedReconnectStrategy;
27 import org.osgi.framework.BundleContext;
29 import static com.google.common.base.Preconditions.*;
31 import com.google.common.base.Optional;
32 import com.google.common.net.InetAddresses;
37 public final class NetconfConnectorModule extends org.opendaylight.controller.config.yang.md.sal.connector.netconf.AbstractNetconfConnectorModule
40 private BundleContext bundleContext;
42 public NetconfConnectorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
43 super(identifier, dependencyResolver);
46 public NetconfConnectorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, NetconfConnectorModule oldModule, java.lang.AutoCloseable oldInstance) {
47 super(identifier, dependencyResolver, oldModule, oldInstance);
51 public void validate(){
53 checkState(getAddress() != null,"Address must be set.");
54 //checkState(getAddress().getIpv4Address() != null || getAddress().getIpv6Address() != null,"Address must be set.");
55 checkState(getPort() != null,"Port must be set.");
56 checkState(getDomRegistry() != null,"Dom Registry must be provided.");
61 public java.lang.AutoCloseable createInstance() {
63 getDomRegistryDependency();
64 NetconfDevice device = new NetconfDevice(getIdentifier().getInstanceName());
65 String addressValue = getAddress();
68 int attemptMsTimeout = 60*1000;
69 int connectionAttempts = 5;
71 * Uncomment after Switch to IP Address
72 if(getAddress().getIpv4Address() != null) {
73 addressValue = getAddress().getIpv4Address().getValue();
75 addressValue = getAddress().getIpv6Address().getValue();
79 ReconnectStrategy strategy = new TimedReconnectStrategy(GlobalEventExecutor.INSTANCE, attemptMsTimeout, 1000, 1.0, null,
80 Long.valueOf(connectionAttempts), null);
83 device.setStrategy(strategy);
85 InetAddress addr = InetAddresses.forString(addressValue);
86 InetSocketAddress socketAddress = new InetSocketAddress(addr , getPort().intValue());
87 device.setSocketAddress(socketAddress);
89 EventLoopGroup bossGroup = getBossThreadGroupDependency();
90 EventLoopGroup workerGroup = getWorkerThreadGroupDependency();
91 NetconfClientDispatcher dispatcher = null;
93 dispatcher = new NetconfClientDispatcher( bossGroup, workerGroup);
95 AuthenticationHandler authHandler = new LoginPassword(getUsername(),getPassword());
96 dispatcher = new NetconfSshClientDispatcher(authHandler , bossGroup, workerGroup);
98 getDomRegistryDependency().registerProvider(device, bundleContext);
100 device.start(dispatcher);
104 public void setBundleContext(BundleContext bundleContext) {
105 this.bundleContext = bundleContext;