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;
14 import java.net.InetAddress;
15 import java.net.InetSocketAddress;
17 import javax.net.ssl.SSLContext;
19 import org.opendaylight.controller.netconf.client.NetconfClientDispatcher;
20 import org.opendaylight.controller.netconf.client.NetconfSshClientDispatcher;
21 import org.opendaylight.controller.netconf.util.handler.ssh.authentication.AuthenticationHandler;
22 import org.opendaylight.controller.netconf.util.handler.ssh.authentication.LoginPassword;
23 import org.opendaylight.controller.sal.connect.netconf.NetconfDevice;
24 import org.osgi.framework.BundleContext;
26 import static com.google.common.base.Preconditions.*;
28 import com.google.common.base.Optional;
29 import com.google.common.net.InetAddresses;
34 public final class NetconfConnectorModule extends org.opendaylight.controller.config.yang.md.sal.connector.netconf.AbstractNetconfConnectorModule
37 private BundleContext bundleContext;
39 public NetconfConnectorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
40 super(identifier, dependencyResolver);
43 public NetconfConnectorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, NetconfConnectorModule oldModule, java.lang.AutoCloseable oldInstance) {
44 super(identifier, dependencyResolver, oldModule, oldInstance);
48 public void validate(){
50 checkState(getAddress() != null,"Address must be set.");
51 //checkState(getAddress().getIpv4Address() != null || getAddress().getIpv6Address() != null,"Address must be set.");
52 checkState(getPort() != null,"Port must be set.");
53 checkState(getDomRegistry() != null,"Dom Registry must be provided.");
58 public java.lang.AutoCloseable createInstance() {
60 getDomRegistryDependency();
61 NetconfDevice device = new NetconfDevice(getIdentifier().getInstanceName());
62 String addressValue = getAddress();
66 * Uncomment after Switch to IP Address
67 if(getAddress().getIpv4Address() != null) {
68 addressValue = getAddress().getIpv4Address().getValue();
70 addressValue = getAddress().getIpv6Address().getValue();
74 InetAddress addr = InetAddresses.forString(addressValue);
75 InetSocketAddress socketAddress = new InetSocketAddress(addr , getPort().intValue());
76 device.setSocketAddress(socketAddress);
78 EventLoopGroup bossGroup = getBossThreadGroupDependency();
79 EventLoopGroup workerGroup = getWorkerThreadGroupDependency();
80 Optional<SSLContext> maybeContext = Optional.absent();
81 NetconfClientDispatcher dispatcher = null;
83 dispatcher = new NetconfClientDispatcher(maybeContext , bossGroup, workerGroup);
85 AuthenticationHandler authHandler = new LoginPassword(getUsername(),getPassword());
86 dispatcher = new NetconfSshClientDispatcher(authHandler , bossGroup, workerGroup);
88 getDomRegistryDependency().registerProvider(device, bundleContext);
90 device.start(dispatcher);
94 public void setBundleContext(BundleContext bundleContext) {
95 this.bundleContext = bundleContext;