4 * Generated from: yang module name: openflow-switch-connection-provider-impl yang module local name: openflow-switch-connection-provider-impl
5 * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
6 * Generated at: Fri Mar 28 17:50:58 PDT 2014
8 * Do not modify this file unless it is present under src/main directory
10 package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328;
12 import com.google.common.base.MoreObjects;
13 import java.net.InetAddress;
14 import java.net.UnknownHostException;
15 import java.util.List;
17 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration;
18 import org.opendaylight.openflowjava.protocol.api.connection.ThreadConfiguration;
19 import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration;
20 import org.opendaylight.openflowjava.protocol.impl.core.SwitchConnectionProviderImpl;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.KeystoreType;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.TransportProtocol;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
30 public final class SwitchConnectionProviderModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328.AbstractSwitchConnectionProviderModule
33 private static Logger LOG = LoggerFactory
34 .getLogger(SwitchConnectionProviderModule.class);
38 * @param dependencyResolver
40 public SwitchConnectionProviderModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
41 super(identifier, dependencyResolver);
46 * @param dependencyResolver
50 public SwitchConnectionProviderModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
51 final SwitchConnectionProviderModule oldModule, final java.lang.AutoCloseable oldInstance) {
52 super(identifier, dependencyResolver, oldModule, oldInstance);
56 protected void customValidation(){
57 // Add custom validation for module attributes here.
61 public java.lang.AutoCloseable createInstance() {
62 LOG.info("SwitchConnectionProvider started.");
63 final SwitchConnectionProviderImpl switchConnectionProviderImpl = new SwitchConnectionProviderImpl();
65 final ConnectionConfiguration connConfiguration = createConnectionConfiguration();
66 switchConnectionProviderImpl.setConfiguration(connConfiguration);
67 } catch (final UnknownHostException e) {
68 throw new IllegalArgumentException(e.getMessage(), e);
70 return switchConnectionProviderImpl;
74 * @return instance configuration object
75 * @throws UnknownHostException
77 private ConnectionConfiguration createConnectionConfiguration() throws UnknownHostException {
78 final InetAddress address = extractIpAddressBin(getAddress());
79 final Integer port = getPort();
80 final long switchIdleTimeout = getSwitchIdleTimeout();
81 final Tls tlsConfig = getTls();
82 final Threads threads = getThreads();
83 final Boolean useBarrier = getUseBarrier();
84 final TransportProtocol transportProtocol = getTransportProtocol();
86 return new ConnectionConfiguration() {
88 public InetAddress getAddress() {
92 public int getPort() {
96 public Object getTransferProtocol() {
97 return transportProtocol;
100 public TlsConfiguration getTlsConfiguration() {
101 if (tlsConfig == null || !(TransportProtocol.TLS.equals(transportProtocol))) {
104 return new TlsConfiguration() {
106 public KeystoreType getTlsTruststoreType() {
107 return MoreObjects.firstNonNull(tlsConfig.getTruststoreType(), null);
110 public String getTlsTruststore() {
111 return MoreObjects.firstNonNull(tlsConfig.getTruststore(), null);
114 public KeystoreType getTlsKeystoreType() {
115 return MoreObjects.firstNonNull(tlsConfig.getKeystoreType(), null);
118 public String getTlsKeystore() {
119 return MoreObjects.firstNonNull(tlsConfig.getKeystore(), null);
122 public org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType getTlsKeystorePathType() {
123 return MoreObjects.firstNonNull(tlsConfig.getKeystorePathType(), null);
126 public org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType getTlsTruststorePathType() {
127 return MoreObjects.firstNonNull(tlsConfig.getTruststorePathType(), null);
130 public String getKeystorePassword() {
131 return MoreObjects.firstNonNull(tlsConfig.getKeystorePassword(), null);
134 public String getCertificatePassword() {
135 return MoreObjects.firstNonNull(tlsConfig.getCertificatePassword(), null);
138 public String getTruststorePassword() {
139 return MoreObjects.firstNonNull(tlsConfig.getTruststorePassword(), null);
142 public List<String> getCipherSuites() {
143 return tlsConfig.getCipherSuites();
148 public long getSwitchIdleTimeout() {
149 return switchIdleTimeout;
152 public Object getSslContext() {
153 // TODO Auto-generated method stub
157 public ThreadConfiguration getThreadConfiguration() {
158 if (threads == null) {
161 return new ThreadConfiguration() {
164 public int getWorkerThreadCount() {
165 return threads.getWorkerThreads();
169 public int getBossThreadCount() {
170 return threads.getBossThreads();
176 public boolean useBarrier() {
185 * @throws UnknownHostException
187 private static InetAddress extractIpAddressBin(final IpAddress address) throws UnknownHostException {
188 byte[] addressBin = null;
189 if (address != null) {
190 if (address.getIpv4Address() != null) {
191 addressBin = address2bin(address.getIpv4Address().getValue());
192 } else if (address.getIpv6Address() != null) {
193 addressBin = address2bin(address.getIpv6Address().getValue());
197 if (addressBin == null) {
200 return InetAddress.getByAddress(addressBin);
208 private static byte[] address2bin(final String value) {
209 //TODO: translate ipv4 or ipv6 into byte[]