Bug 5377: Support configuring cipher suites to use for SSLEngine
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / yang / gen / v1 / urn / opendaylight / params / xml / ns / yang / openflow / _switch / connection / provider / impl / rev140328 / SwitchConnectionProviderModule.java
1 /**
2 * Generated file
3
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
7 *
8 * Do not modify this file unless it is present under src/main directory
9 */
10 package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328;
11
12 import com.google.common.base.MoreObjects;
13 import java.net.InetAddress;
14 import java.net.UnknownHostException;
15 import java.util.List;
16
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;
26
27 /**
28 *
29 */
30 public final class SwitchConnectionProviderModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328.AbstractSwitchConnectionProviderModule
31  {
32
33     private static Logger LOG = LoggerFactory
34             .getLogger(SwitchConnectionProviderModule.class);
35
36     /**
37      * @param identifier
38      * @param dependencyResolver
39      */
40     public SwitchConnectionProviderModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
41         super(identifier, dependencyResolver);
42     }
43
44     /**
45      * @param identifier
46      * @param dependencyResolver
47      * @param oldModule
48      * @param oldInstance
49      */
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);
53     }
54
55     @Override
56     protected void customValidation(){
57         // Add custom validation for module attributes here.
58     }
59
60     @Override
61     public java.lang.AutoCloseable createInstance() {
62         LOG.info("SwitchConnectionProvider started.");
63         final SwitchConnectionProviderImpl switchConnectionProviderImpl = new SwitchConnectionProviderImpl();
64         try {
65             final ConnectionConfiguration connConfiguration = createConnectionConfiguration();
66             switchConnectionProviderImpl.setConfiguration(connConfiguration);
67         } catch (final UnknownHostException e) {
68             throw new IllegalArgumentException(e.getMessage(), e);
69         }
70         return switchConnectionProviderImpl;
71     }
72
73     /**
74      * @return instance configuration object
75      * @throws UnknownHostException
76      */
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();
85
86         return new ConnectionConfiguration() {
87             @Override
88             public InetAddress getAddress() {
89                 return address;
90             }
91             @Override
92             public int getPort() {
93                 return port;
94             }
95             @Override
96             public Object getTransferProtocol() {
97                 return transportProtocol;
98             }
99             @Override
100             public TlsConfiguration getTlsConfiguration() {
101                 if (tlsConfig == null || !(TransportProtocol.TLS.equals(transportProtocol))) {
102                     return null;
103                 }
104                 return new TlsConfiguration() {
105                     @Override
106                     public KeystoreType getTlsTruststoreType() {
107                         return MoreObjects.firstNonNull(tlsConfig.getTruststoreType(), null);
108                     }
109                     @Override
110                     public String getTlsTruststore() {
111                         return MoreObjects.firstNonNull(tlsConfig.getTruststore(), null);
112                     }
113                     @Override
114                     public KeystoreType getTlsKeystoreType() {
115                         return MoreObjects.firstNonNull(tlsConfig.getKeystoreType(), null);
116                     }
117                     @Override
118                     public String getTlsKeystore() {
119                         return MoreObjects.firstNonNull(tlsConfig.getKeystore(), null);
120                     }
121                     @Override
122                     public org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType getTlsKeystorePathType() {
123                         return MoreObjects.firstNonNull(tlsConfig.getKeystorePathType(), null);
124                     }
125                     @Override
126                     public org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType getTlsTruststorePathType() {
127                         return MoreObjects.firstNonNull(tlsConfig.getTruststorePathType(), null);
128                     }
129                     @Override
130                     public String getKeystorePassword() {
131                         return MoreObjects.firstNonNull(tlsConfig.getKeystorePassword(), null);
132                     }
133                     @Override
134                     public String getCertificatePassword() {
135                         return MoreObjects.firstNonNull(tlsConfig.getCertificatePassword(), null);
136                     }
137                     @Override
138                     public String getTruststorePassword() {
139                         return MoreObjects.firstNonNull(tlsConfig.getTruststorePassword(), null);
140                     }
141                     @Override
142                     public List<String> getCipherSuites() {
143                         return tlsConfig.getCipherSuites();
144                     }
145                 };
146             }
147             @Override
148             public long getSwitchIdleTimeout() {
149                 return switchIdleTimeout;
150             }
151             @Override
152             public Object getSslContext() {
153                 // TODO Auto-generated method stub
154                 return null;
155             }
156             @Override
157             public ThreadConfiguration getThreadConfiguration() {
158                 if (threads == null) {
159                     return null;
160                 }
161                 return new ThreadConfiguration() {
162
163                     @Override
164                     public int getWorkerThreadCount() {
165                         return threads.getWorkerThreads();
166                     }
167
168                     @Override
169                     public int getBossThreadCount() {
170                         return threads.getBossThreads();
171                     }
172                 };
173             }
174
175             @Override
176             public boolean useBarrier() {
177                 return useBarrier;
178             }
179         };
180     }
181
182     /**
183      * @param address
184      * @return
185      * @throws UnknownHostException
186      */
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());
194             }
195         }
196
197         if (addressBin == null) {
198             return null;
199         } else {
200             return InetAddress.getByAddress(addressBin);
201         }
202     }
203
204     /**
205      * @param value
206      * @return
207      */
208     private static byte[] address2bin(final String value) {
209         //TODO: translate ipv4 or ipv6 into byte[]
210         return null;
211     }
212 }