2 * Copyright (c) 2016 Brocade Communications Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowjava.protocol.impl.core;
10 import com.google.common.base.MoreObjects;
11 import java.net.InetAddress;
12 import java.net.UnknownHostException;
13 import java.util.List;
14 import javax.inject.Inject;
15 import javax.inject.Singleton;
16 import org.apache.aries.blueprint.annotation.service.Reference;
17 import org.apache.aries.blueprint.annotation.service.Service;
18 import org.opendaylight.infrautils.diagstatus.DiagStatusService;
19 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration;
20 import org.opendaylight.openflowjava.protocol.api.connection.ThreadConfiguration;
21 import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration;
22 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
23 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProviderFactory;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.KeystoreType;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.TransportProtocol;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.config.rev160506.SwitchConnectionConfig;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.config.rev160506._switch.connection.config.Threads;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.config.rev160506._switch.connection.config.Tls;
32 * Implementation of the SwitchConnectionProviderFactory interface.
35 @Service(classes = SwitchConnectionProviderFactory.class)
36 public class SwitchConnectionProviderFactoryImpl implements SwitchConnectionProviderFactory {
38 private final DiagStatusService diagStatusService;
41 public SwitchConnectionProviderFactoryImpl(@Reference DiagStatusService diagStatusService) {
42 this.diagStatusService = diagStatusService;
46 public SwitchConnectionProvider newInstance(SwitchConnectionConfig config) {
47 return new SwitchConnectionProviderImpl(new ConnectionConfigurationImpl(config), diagStatusService);
50 private static InetAddress getInetAddress(final IpAddress address) throws UnknownHostException {
51 if (address != null) {
52 if (address.getIpv4Address() != null) {
53 return InetAddress.getByName(address.getIpv4Address().getValue());
54 } else if (address.getIpv6Address() != null) {
55 return InetAddress.getByName(address.getIpv6Address().getValue());
61 private static class ConnectionConfigurationImpl implements ConnectionConfiguration {
62 private final SwitchConnectionConfig config;
63 private InetAddress address;
65 ConnectionConfigurationImpl(SwitchConnectionConfig config) {
69 address = getInetAddress(config.getAddress());
70 } catch (UnknownHostException e) {
71 throw new RuntimeException(e);
76 public InetAddress getAddress() {
81 public int getPort() {
82 return config.getPort();
86 public Object getTransferProtocol() {
87 return config.getTransportProtocol();
91 public int getChannelOutboundQueueSize() {
92 return config.getChannelOutboundQueueSize();
96 public TlsConfiguration getTlsConfiguration() {
97 final Tls tlsConfig = config.getTls();
98 if (tlsConfig == null || !TransportProtocol.TLS.equals(getTransferProtocol())) {
102 return new TlsConfiguration() {
104 public KeystoreType getTlsTruststoreType() {
105 return MoreObjects.firstNonNull(tlsConfig.getTruststoreType(), null);
109 public String getTlsTruststore() {
110 return MoreObjects.firstNonNull(tlsConfig.getTruststore(), null);
114 public KeystoreType getTlsKeystoreType() {
115 return MoreObjects.firstNonNull(tlsConfig.getKeystoreType(), null);
119 public String getTlsKeystore() {
120 return MoreObjects.firstNonNull(tlsConfig.getKeystore(), null);
124 public org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType
125 getTlsKeystorePathType() {
126 return MoreObjects.firstNonNull(tlsConfig.getKeystorePathType(), null);
130 public org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType
131 getTlsTruststorePathType() {
132 return MoreObjects.firstNonNull(tlsConfig.getTruststorePathType(), null);
136 public String getKeystorePassword() {
137 return MoreObjects.firstNonNull(tlsConfig.getKeystorePassword(), null);
141 public String getCertificatePassword() {
142 return MoreObjects.firstNonNull(tlsConfig.getCertificatePassword(), null);
146 public String getTruststorePassword() {
147 return MoreObjects.firstNonNull(tlsConfig.getTruststorePassword(), null);
151 public List<String> getCipherSuites() {
152 return tlsConfig.getCipherSuites();
158 public long getSwitchIdleTimeout() {
159 return config.getSwitchIdleTimeout();
163 public Object getSslContext() {
168 public ThreadConfiguration getThreadConfiguration() {
169 final Threads threads = config.getThreads();
170 if (threads == null) {
174 return new ThreadConfiguration() {
176 public int getWorkerThreadCount() {
177 return threads.getWorkerThreads();
181 public int getBossThreadCount() {
182 return threads.getBossThreads();
188 public boolean useBarrier() {
189 return config.isUseBarrier();
193 public boolean isGroupAddModEnabled() {
194 return config.isGroupAddModEnabled();