Merge "Choice and case resolving in JSON output"
[controller.git] / opendaylight / md-sal / sal-netconf-connector / src / main / java / org / opendaylight / controller / config / yang / md / sal / connector / netconf / NetconfConnectorModule.java
1 /**
2 * Generated file
3
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
7 *
8 * Do not modify this file unless it is present under src/main directory
9 */
10 package org.opendaylight.controller.config.yang.md.sal.connector.netconf;
11
12 import io.netty.channel.EventLoopGroup;
13
14 import java.net.InetAddress;
15 import java.net.InetSocketAddress;
16
17 import javax.net.ssl.SSLContext;
18
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;
25
26 import static com.google.common.base.Preconditions.*;
27
28 import com.google.common.base.Optional;
29 import com.google.common.net.InetAddresses;
30
31 /**
32 *
33 */
34 public final class NetconfConnectorModule extends org.opendaylight.controller.config.yang.md.sal.connector.netconf.AbstractNetconfConnectorModule
35 {
36
37     private BundleContext bundleContext;
38
39     public NetconfConnectorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
40         super(identifier, dependencyResolver);
41     }
42
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);
45     }
46
47     @Override
48     public void validate(){
49         super.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.");
54     }
55
56
57     @Override
58     public java.lang.AutoCloseable createInstance() {
59         
60         getDomRegistryDependency();
61         NetconfDevice device = new NetconfDevice(getIdentifier().getInstanceName());
62         String addressValue = getAddress();
63         
64         
65         /*
66          * Uncomment after Switch to IP Address
67         if(getAddress().getIpv4Address() != null) {
68             addressValue = getAddress().getIpv4Address().getValue();
69         } else {
70             addressValue = getAddress().getIpv6Address().getValue();
71         }
72         
73         */
74         InetAddress addr = InetAddresses.forString(addressValue);
75         InetSocketAddress socketAddress = new InetSocketAddress(addr , getPort().intValue());
76         device.setSocketAddress(socketAddress);
77         
78         EventLoopGroup bossGroup = getBossThreadGroupDependency();
79         EventLoopGroup workerGroup = getWorkerThreadGroupDependency();
80         Optional<SSLContext> maybeContext = Optional.absent();
81         NetconfClientDispatcher dispatcher = null;
82         if(getTcpOnly()) {
83             dispatcher = new NetconfClientDispatcher(maybeContext , bossGroup, workerGroup);
84         } else {
85             AuthenticationHandler authHandler = new LoginPassword(getUsername(),getPassword());
86             dispatcher = new NetconfSshClientDispatcher(authHandler , bossGroup, workerGroup);
87         }
88         getDomRegistryDependency().registerProvider(device, bundleContext);
89         
90         device.start(dispatcher);
91         return device;
92     }
93
94     public void setBundleContext(BundleContext bundleContext) {
95         this.bundleContext = bundleContext;
96     }
97 }