fd5cf8aa2a9fcbf14c49ce7c8689745e591ea6a5
[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 java.net.InetAddress;
13 import java.net.UnknownHostException;
14
15 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration;
16 import org.opendaylight.openflowjava.protocol.api.connection.ThreadConfiguration;
17 import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration;
18 import org.opendaylight.openflowjava.protocol.impl.core.SwitchConnectionProviderImpl;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.KeystoreType;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.TransportProtocol;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 import com.google.common.base.Objects;
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(org.opendaylight.controller.config.api.ModuleIdentifier identifier, 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(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
51             SwitchConnectionProviderModule oldModule, 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         SwitchConnectionProviderImpl switchConnectionProviderImpl = new SwitchConnectionProviderImpl();
64         try {
65             ConnectionConfiguration connConfiguration = createConnectionConfiguration();
66             switchConnectionProviderImpl.setConfiguration(connConfiguration);
67         } catch (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 TransportProtocol transportProtocol = getTransportProtocol();
84
85         return new ConnectionConfiguration() {
86             @Override
87             public InetAddress getAddress() {
88                 return address;
89             }
90             @Override
91             public int getPort() {
92                 return port;
93             }
94             @Override
95             public Object getTransferProtocol() {
96                 return transportProtocol;
97             }
98             @Override
99             public TlsConfiguration getTlsConfiguration() {
100                 if (tlsConfig == null || !(TransportProtocol.TLS.equals(transportProtocol))) {
101                     return null;
102                 }
103                 return new TlsConfiguration() {
104                     @Override
105                     public KeystoreType getTlsTruststoreType() {
106                         return Objects.firstNonNull(tlsConfig.getTruststoreType(), null);
107                     }
108                     @Override
109                     public String getTlsTruststore() {
110                         return Objects.firstNonNull(tlsConfig.getTruststore(), null);
111                     }
112                     @Override
113                     public KeystoreType getTlsKeystoreType() {
114                         return Objects.firstNonNull(tlsConfig.getKeystoreType(), null);
115                     }
116                     @Override
117                     public String getTlsKeystore() {
118                         return Objects.firstNonNull(tlsConfig.getKeystore(), null);
119                     }
120                     @Override
121                     public org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType getTlsKeystorePathType() {
122                         return Objects.firstNonNull(tlsConfig.getKeystorePathType(), null);
123                     }
124                     @Override
125                     public org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType getTlsTruststorePathType() {
126                         return Objects.firstNonNull(tlsConfig.getTruststorePathType(), null);
127                     }
128                     @Override
129                     public String getKeystorePassword() {
130                         return Objects.firstNonNull(tlsConfig.getKeystorePassword(), null);
131                     }
132                     @Override
133                     public String getCertificatePassword() {
134                         return Objects.firstNonNull(tlsConfig.getCertificatePassword(), null);
135                     }
136                     @Override
137                     public String getTruststorePassword() {
138                         return Objects.firstNonNull(tlsConfig.getTruststorePassword(), null);
139                     }
140                 };
141             }
142             @Override
143             public long getSwitchIdleTimeout() {
144                 return switchIdleTimeout;
145             }
146             @Override
147             public Object getSslContext() {
148                 // TODO Auto-generated method stub
149                 return null;
150             }
151             @Override
152             public ThreadConfiguration getThreadConfiguration() {
153                 if (threads == null) {
154                     return null;
155                 }
156                 return new ThreadConfiguration() {
157                     
158                     @Override
159                     public int getWorkerThreadCount() {
160                         return threads.getWorkerThreads();
161                     }
162                     
163                     @Override
164                     public int getBossThreadCount() {
165                         return threads.getBossThreads();
166                     }
167                 };
168             }
169         };
170     }
171
172     /**
173      * @param address
174      * @return
175      * @throws UnknownHostException 
176      */
177     private static InetAddress extractIpAddressBin(IpAddress address) throws UnknownHostException {
178         byte[] addressBin = null;
179         if (address != null) {
180             if (address.getIpv4Address() != null) {
181                 addressBin = address2bin(address.getIpv4Address().getValue());
182             } else if (address.getIpv6Address() != null) {
183                 addressBin = address2bin(address.getIpv6Address().getValue());
184             }
185         }
186         
187         if (addressBin == null) {
188             return null;
189         } else {
190             return InetAddress.getByAddress(addressBin);
191         }
192     }
193
194     /**
195      * @param value
196      * @return
197      */
198     private static byte[] address2bin(String value) {
199         //TODO: translate ipv4 or ipv6 into byte[]
200         return null;
201     }
202 }