Merge "Bug 3178 - Statistics collection turned on by default" into stable/lithium
[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 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 /**
26 *
27 */
28 public final class SwitchConnectionProviderModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328.AbstractSwitchConnectionProviderModule
29  {
30
31     private static Logger LOG = LoggerFactory
32             .getLogger(SwitchConnectionProviderModule.class);
33
34     /**
35      * @param identifier
36      * @param dependencyResolver
37      */
38     public SwitchConnectionProviderModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
39         super(identifier, dependencyResolver);
40     }
41
42     /**
43      * @param identifier
44      * @param dependencyResolver
45      * @param oldModule
46      * @param oldInstance
47      */
48     public SwitchConnectionProviderModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
49             final SwitchConnectionProviderModule oldModule, final java.lang.AutoCloseable oldInstance) {
50         super(identifier, dependencyResolver, oldModule, oldInstance);
51     }
52
53     @Override
54     protected void customValidation(){
55         // Add custom validation for module attributes here.
56     }
57
58     @Override
59     public java.lang.AutoCloseable createInstance() {
60         LOG.info("SwitchConnectionProvider started.");
61         SwitchConnectionProviderImpl switchConnectionProviderImpl = new SwitchConnectionProviderImpl();
62         try {
63             ConnectionConfiguration connConfiguration = createConnectionConfiguration();
64             switchConnectionProviderImpl.setConfiguration(connConfiguration);
65         } catch (UnknownHostException e) {
66             throw new IllegalArgumentException(e.getMessage(), e);
67         }
68         return switchConnectionProviderImpl;
69     }
70
71     /**
72      * @return instance configuration object
73      * @throws UnknownHostException
74      */
75     private ConnectionConfiguration createConnectionConfiguration() throws UnknownHostException {
76         final InetAddress address = extractIpAddressBin(getAddress());
77         final Integer port = getPort();
78         final long switchIdleTimeout = getSwitchIdleTimeout();
79         final Tls tlsConfig = getTls();
80         final Threads threads = getThreads();
81         final TransportProtocol transportProtocol = getTransportProtocol();
82
83         return new ConnectionConfiguration() {
84             @Override
85             public InetAddress getAddress() {
86                 return address;
87             }
88             @Override
89             public int getPort() {
90                 return port;
91             }
92             @Override
93             public Object getTransferProtocol() {
94                 return transportProtocol;
95             }
96             @Override
97             public TlsConfiguration getTlsConfiguration() {
98                 if (tlsConfig == null || !(TransportProtocol.TLS.equals(transportProtocol))) {
99                     return null;
100                 }
101                 return new TlsConfiguration() {
102                     @Override
103                     public KeystoreType getTlsTruststoreType() {
104                         return MoreObjects.firstNonNull(tlsConfig.getTruststoreType(), null);
105                     }
106                     @Override
107                     public String getTlsTruststore() {
108                         return MoreObjects.firstNonNull(tlsConfig.getTruststore(), null);
109                     }
110                     @Override
111                     public KeystoreType getTlsKeystoreType() {
112                         return MoreObjects.firstNonNull(tlsConfig.getKeystoreType(), null);
113                     }
114                     @Override
115                     public String getTlsKeystore() {
116                         return MoreObjects.firstNonNull(tlsConfig.getKeystore(), null);
117                     }
118                     @Override
119                     public org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType getTlsKeystorePathType() {
120                         return MoreObjects.firstNonNull(tlsConfig.getKeystorePathType(), null);
121                     }
122                     @Override
123                     public org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType getTlsTruststorePathType() {
124                         return MoreObjects.firstNonNull(tlsConfig.getTruststorePathType(), null);
125                     }
126                     @Override
127                     public String getKeystorePassword() {
128                         return MoreObjects.firstNonNull(tlsConfig.getKeystorePassword(), null);
129                     }
130                     @Override
131                     public String getCertificatePassword() {
132                         return MoreObjects.firstNonNull(tlsConfig.getCertificatePassword(), null);
133                     }
134                     @Override
135                     public String getTruststorePassword() {
136                         return MoreObjects.firstNonNull(tlsConfig.getTruststorePassword(), null);
137                     }
138                 };
139             }
140             @Override
141             public long getSwitchIdleTimeout() {
142                 return switchIdleTimeout;
143             }
144             @Override
145             public Object getSslContext() {
146                 // TODO Auto-generated method stub
147                 return null;
148             }
149             @Override
150             public ThreadConfiguration getThreadConfiguration() {
151                 if (threads == null) {
152                     return null;
153                 }
154                 return new ThreadConfiguration() {
155
156                     @Override
157                     public int getWorkerThreadCount() {
158                         return threads.getWorkerThreads();
159                     }
160
161                     @Override
162                     public int getBossThreadCount() {
163                         return threads.getBossThreads();
164                     }
165                 };
166             }
167         };
168     }
169
170     /**
171      * @param address
172      * @return
173      * @throws UnknownHostException
174      */
175     private static InetAddress extractIpAddressBin(final IpAddress address) throws UnknownHostException {
176         byte[] addressBin = null;
177         if (address != null) {
178             if (address.getIpv4Address() != null) {
179                 addressBin = address2bin(address.getIpv4Address().getValue());
180             } else if (address.getIpv6Address() != null) {
181                 addressBin = address2bin(address.getIpv6Address().getValue());
182             }
183         }
184
185         if (addressBin == null) {
186             return null;
187         } else {
188             return InetAddress.getByAddress(addressBin);
189         }
190     }
191
192     /**
193      * @param value
194      * @return
195      */
196     private static byte[] address2bin(final String value) {
197         //TODO: translate ipv4 or ipv6 into byte[]
198         return null;
199     }
200 }