TLS support - configurable passwords
[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.TlsConfiguration;
17 import org.opendaylight.openflowjava.protocol.impl.connection.SwitchConnectionProviderImpl;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.KeystoreType;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 import com.google.common.base.Objects;
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(org.opendaylight.controller.config.api.ModuleIdentifier identifier, 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(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
49             SwitchConnectionProviderModule oldModule, 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         
81         return new ConnectionConfiguration() {
82             @Override
83             public InetAddress getAddress() {
84                 return address;
85             }
86             @Override
87             public int getPort() {
88                 return port;
89             }
90             @Override
91             public Object getTransferProtocol() {
92                 // TODO Auto-generated method stub
93                 return null;
94             }
95             @Override
96             public TlsConfiguration getTlsConfiguration() {
97                 if (tlsConfig == null) {
98                     return null;
99                 }
100                 return new TlsConfiguration() {
101                     @Override
102                     public KeystoreType getTlsTruststoreType() {
103                         return Objects.firstNonNull(tlsConfig.getTruststoreType(), null);
104                     }
105                     @Override
106                     public String getTlsTruststore() {
107                         return Objects.firstNonNull(tlsConfig.getTruststore(), null);
108                     }
109                     @Override
110                     public KeystoreType getTlsKeystoreType() {
111                         return Objects.firstNonNull(tlsConfig.getKeystoreType(), null);
112                     }
113                     @Override
114                     public String getTlsKeystore() {
115                         return Objects.firstNonNull(tlsConfig.getKeystore(), null);
116                     }
117                     @Override
118                     public org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType getTlsKeystorePathType() {
119                         return Objects.firstNonNull(tlsConfig.getKeystorePathType(), null);
120                     }
121                     @Override
122                     public org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType getTlsTruststorePathType() {
123                         return Objects.firstNonNull(tlsConfig.getTruststorePathType(), null);
124                     }
125                     @Override
126                     public String getKeystorePassword() {
127                         return Objects.firstNonNull(tlsConfig.getKeystorePassword(), null);
128                     }
129                     @Override
130                     public String getCertificatePassword() {
131                         return Objects.firstNonNull(tlsConfig.getCertificatePassword(), null);
132                     }
133                     @Override
134                     public String getTruststorePassword() {
135                         return Objects.firstNonNull(tlsConfig.getTruststorePassword(), null);
136                     }
137                 };
138             }
139             @Override
140             public long getSwitchIdleTimeout() {
141                 return switchIdleTimeout;
142             }
143             @Override
144             public Object getSslContext() {
145                 // TODO Auto-generated method stub
146                 return null;
147             }
148         };
149     }
150
151     /**
152      * @param address
153      * @return
154      * @throws UnknownHostException 
155      */
156     private static InetAddress extractIpAddressBin(IpAddress address) throws UnknownHostException {
157         byte[] addressBin = null;
158         if (address != null) {
159             if (address.getIpv4Address() != null) {
160                 addressBin = address2bin(address.getIpv4Address().getValue());
161             } else if (address.getIpv6Address() != null) {
162                 addressBin = address2bin(address.getIpv6Address().getValue());
163             }
164         }
165         
166         if (addressBin == null) {
167             return null;
168         } else {
169             return InetAddress.getByAddress(addressBin);
170         }
171     }
172
173     /**
174      * @param value
175      * @return
176      */
177     private static byte[] address2bin(String value) {
178         //TODO: translate ipv4 or ipv6 into byte[]
179         return null;
180     }
181 }