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
8 * Do not modify this file unless it is present under src/main directory
10 package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328;
12 import java.net.InetAddress;
13 import java.net.UnknownHostException;
15 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration;
16 import org.opendaylight.openflowjava.protocol.api.connection.StatisticsConfiguration;
17 import org.opendaylight.openflowjava.protocol.api.connection.ThreadConfiguration;
18 import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration;
19 import org.opendaylight.openflowjava.protocol.impl.core.SwitchConnectionProviderImpl;
20 import org.opendaylight.openflowjava.statistics.StatisticsCounters;
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;
27 import com.google.common.base.Objects;
32 public final class SwitchConnectionProviderModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328.AbstractSwitchConnectionProviderModule
35 private static Logger LOG = LoggerFactory
36 .getLogger(SwitchConnectionProviderModule.class);
40 * @param dependencyResolver
42 public SwitchConnectionProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
43 super(identifier, dependencyResolver);
48 * @param dependencyResolver
52 public SwitchConnectionProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
53 SwitchConnectionProviderModule oldModule, java.lang.AutoCloseable oldInstance) {
54 super(identifier, dependencyResolver, oldModule, oldInstance);
58 protected void customValidation(){
59 // Add custom validation for module attributes here.
63 public java.lang.AutoCloseable createInstance() {
64 LOG.info("SwitchConnectionProvider started.");
65 SwitchConnectionProviderImpl switchConnectionProviderImpl = new SwitchConnectionProviderImpl();
66 StatisticsCounters sc = StatisticsCounters.getInstance();
68 ConnectionConfiguration connConfiguration = createConnectionConfiguration();
69 switchConnectionProviderImpl.setConfiguration(connConfiguration);
70 startStatistics(sc, connConfiguration.getStatisticsConfiguration());
71 } catch (UnknownHostException e) {
72 throw new IllegalArgumentException(e.getMessage(), e);
74 return switchConnectionProviderImpl;
79 * @return instance configuration object
80 * @throws UnknownHostException
82 private ConnectionConfiguration createConnectionConfiguration() throws UnknownHostException {
83 final InetAddress address = extractIpAddressBin(getAddress());
84 final Integer port = getPort();
85 final long switchIdleTimeout = getSwitchIdleTimeout();
86 final Tls tlsConfig = getTls();
87 final Threads threads = getThreads();
88 final TransportProtocol transportProtocol = getTransportProtocol();
89 final Statistics statistics = getStatistics();
91 return new ConnectionConfiguration() {
93 public InetAddress getAddress() {
97 public int getPort() {
101 public Object getTransferProtocol() {
102 return transportProtocol;
105 public TlsConfiguration getTlsConfiguration() {
106 if (tlsConfig == null || !(TransportProtocol.TLS.equals(transportProtocol))) {
109 return new TlsConfiguration() {
111 public KeystoreType getTlsTruststoreType() {
112 return Objects.firstNonNull(tlsConfig.getTruststoreType(), null);
115 public String getTlsTruststore() {
116 return Objects.firstNonNull(tlsConfig.getTruststore(), null);
119 public KeystoreType getTlsKeystoreType() {
120 return Objects.firstNonNull(tlsConfig.getKeystoreType(), null);
123 public String getTlsKeystore() {
124 return Objects.firstNonNull(tlsConfig.getKeystore(), null);
127 public org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType getTlsKeystorePathType() {
128 return Objects.firstNonNull(tlsConfig.getKeystorePathType(), null);
131 public org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType getTlsTruststorePathType() {
132 return Objects.firstNonNull(tlsConfig.getTruststorePathType(), null);
135 public String getKeystorePassword() {
136 return Objects.firstNonNull(tlsConfig.getKeystorePassword(), null);
139 public String getCertificatePassword() {
140 return Objects.firstNonNull(tlsConfig.getCertificatePassword(), null);
143 public String getTruststorePassword() {
144 return Objects.firstNonNull(tlsConfig.getTruststorePassword(), null);
149 public long getSwitchIdleTimeout() {
150 return switchIdleTimeout;
153 public Object getSslContext() {
154 // TODO Auto-generated method stub
158 public ThreadConfiguration getThreadConfiguration() {
159 if (threads == null) {
162 return new ThreadConfiguration() {
165 public int getWorkerThreadCount() {
166 return threads.getWorkerThreads();
170 public int getBossThreadCount() {
171 return threads.getBossThreads();
176 public StatisticsConfiguration getStatisticsConfiguration(){
177 return new StatisticsConfiguration() {
179 public Boolean getStatisticsCollect() {
180 if(statistics == null){
183 if (statistics.getStatisticsCollect() == null){
186 return statistics.getStatisticsCollect();
189 public Integer getLogReportDelay() {
190 if(statistics == null){
193 if(statistics.getLogReportDelay() == null){
196 return statistics.getLogReportDelay();
206 * @throws UnknownHostException
208 private static InetAddress extractIpAddressBin(IpAddress address) throws UnknownHostException {
209 byte[] addressBin = null;
210 if (address != null) {
211 if (address.getIpv4Address() != null) {
212 addressBin = address2bin(address.getIpv4Address().getValue());
213 } else if (address.getIpv6Address() != null) {
214 addressBin = address2bin(address.getIpv6Address().getValue());
218 if (addressBin == null) {
221 return InetAddress.getByAddress(addressBin);
226 * Configure and start Statistics Counters by configuration parameters.
227 * No operations is performed if:
228 * - statisticsConfig is null
230 * - sc is not null and if counting is running
231 * @param sc - statistic counter to configure and start
232 * @param statisticsConfig - configuration parameters
234 private static void startStatistics(StatisticsCounters sc, StatisticsConfiguration statisticsConfig){
235 if(statisticsConfig == null){
238 if(sc == null || sc.isRunCounting()){
241 Boolean toCollectStats = statisticsConfig.getStatisticsCollect();
242 Integer logDelay = statisticsConfig.getLogReportDelay();
243 if(toCollectStats != null && toCollectStats.booleanValue()){
245 if(logDelay != null){
246 logPeriod = logDelay.intValue();
249 sc.startCounting(true, logPeriod);
251 sc.startCounting(false, 0);
260 private static byte[] address2bin(String value) {
261 //TODO: translate ipv4 or ipv6 into byte[]