Merge "Barrier turn on/off-add switcher value to Config-Subsystem" 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         final SwitchConnectionProviderImpl switchConnectionProviderImpl = new SwitchConnectionProviderImpl();
62         try {
63             final ConnectionConfiguration connConfiguration = createConnectionConfiguration();
64             switchConnectionProviderImpl.setConfiguration(connConfiguration);
65         } catch (final 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 Boolean useBarrier = getUseBarrier();
82         final TransportProtocol transportProtocol = getTransportProtocol();
83
84         return new ConnectionConfiguration() {
85             @Override
86             public InetAddress getAddress() {
87                 return address;
88             }
89             @Override
90             public int getPort() {
91                 return port;
92             }
93             @Override
94             public Object getTransferProtocol() {
95                 return transportProtocol;
96             }
97             @Override
98             public TlsConfiguration getTlsConfiguration() {
99                 if (tlsConfig == null || !(TransportProtocol.TLS.equals(transportProtocol))) {
100                     return null;
101                 }
102                 return new TlsConfiguration() {
103                     @Override
104                     public KeystoreType getTlsTruststoreType() {
105                         return MoreObjects.firstNonNull(tlsConfig.getTruststoreType(), null);
106                     }
107                     @Override
108                     public String getTlsTruststore() {
109                         return MoreObjects.firstNonNull(tlsConfig.getTruststore(), null);
110                     }
111                     @Override
112                     public KeystoreType getTlsKeystoreType() {
113                         return MoreObjects.firstNonNull(tlsConfig.getKeystoreType(), null);
114                     }
115                     @Override
116                     public String getTlsKeystore() {
117                         return MoreObjects.firstNonNull(tlsConfig.getKeystore(), null);
118                     }
119                     @Override
120                     public org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType getTlsKeystorePathType() {
121                         return MoreObjects.firstNonNull(tlsConfig.getKeystorePathType(), null);
122                     }
123                     @Override
124                     public org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType getTlsTruststorePathType() {
125                         return MoreObjects.firstNonNull(tlsConfig.getTruststorePathType(), null);
126                     }
127                     @Override
128                     public String getKeystorePassword() {
129                         return MoreObjects.firstNonNull(tlsConfig.getKeystorePassword(), null);
130                     }
131                     @Override
132                     public String getCertificatePassword() {
133                         return MoreObjects.firstNonNull(tlsConfig.getCertificatePassword(), null);
134                     }
135                     @Override
136                     public String getTruststorePassword() {
137                         return MoreObjects.firstNonNull(tlsConfig.getTruststorePassword(), null);
138                     }
139                 };
140             }
141             @Override
142             public long getSwitchIdleTimeout() {
143                 return switchIdleTimeout;
144             }
145             @Override
146             public Object getSslContext() {
147                 // TODO Auto-generated method stub
148                 return null;
149             }
150             @Override
151             public ThreadConfiguration getThreadConfiguration() {
152                 if (threads == null) {
153                     return null;
154                 }
155                 return new ThreadConfiguration() {
156
157                     @Override
158                     public int getWorkerThreadCount() {
159                         return threads.getWorkerThreads();
160                     }
161
162                     @Override
163                     public int getBossThreadCount() {
164                         return threads.getBossThreads();
165                     }
166                 };
167             }
168
169             @Override
170             public boolean useBarrier() {
171                 return useBarrier;
172             }
173         };
174     }
175
176     /**
177      * @param address
178      * @return
179      * @throws UnknownHostException
180      */
181     private static InetAddress extractIpAddressBin(final IpAddress address) throws UnknownHostException {
182         byte[] addressBin = null;
183         if (address != null) {
184             if (address.getIpv4Address() != null) {
185                 addressBin = address2bin(address.getIpv4Address().getValue());
186             } else if (address.getIpv6Address() != null) {
187                 addressBin = address2bin(address.getIpv6Address().getValue());
188             }
189         }
190
191         if (addressBin == null) {
192             return null;
193         } else {
194             return InetAddress.getByAddress(addressBin);
195         }
196     }
197
198     /**
199      * @param value
200      * @return
201      */
202     private static byte[] address2bin(final String value) {
203         //TODO: translate ipv4 or ipv6 into byte[]
204         return null;
205     }
206 }