X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowjava%2Fopenflow-protocol-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fcore%2FSwitchConnectionProviderFactoryImpl.java;h=cb8a963d5ae34062899997d0094a3ca290419d29;hb=5b685a5be740d0bda47b4d08203e099c75105ccf;hp=2ea22ad9950da3cdbff0ba6c51f94ea677f793e7;hpb=2497ae3e02ccc274ec775556f407eaadaa80d16e;p=openflowplugin.git diff --git a/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderFactoryImpl.java b/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderFactoryImpl.java index 2ea22ad995..cb8a963d5a 100644 --- a/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderFactoryImpl.java +++ b/openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderFactoryImpl.java @@ -9,183 +9,32 @@ package org.opendaylight.openflowjava.protocol.impl.core; import static java.util.Objects.requireNonNull; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.List; +import javax.inject.Inject; import javax.inject.Singleton; -import org.apache.aries.blueprint.annotation.service.Service; -import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration; -import org.opendaylight.openflowjava.protocol.api.connection.OpenflowDiagStatusProvider; -import org.opendaylight.openflowjava.protocol.api.connection.ThreadConfiguration; -import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration; +import org.opendaylight.infrautils.diagstatus.DiagStatusService; import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider; import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProviderFactory; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.KeystoreType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.TransportProtocol; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.config.rev160506.SwitchConnectionConfig; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.config.rev160506._switch.connection.config.Threads; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.config.rev160506._switch.connection.config.Tls; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; /** * Implementation of the SwitchConnectionProviderFactory interface. */ @Singleton -@Service(classes = SwitchConnectionProviderFactory.class) +@Component public class SwitchConnectionProviderFactoryImpl implements SwitchConnectionProviderFactory { + private final DiagStatusService diagStatus; - @Override - public SwitchConnectionProvider newInstance(final SwitchConnectionConfig config, - final OpenflowDiagStatusProvider openflowPluginDiagStatusProvider) { - return new SwitchConnectionProviderImpl(new ConnectionConfigurationImpl(config), - openflowPluginDiagStatusProvider); + @Inject + @Activate + public SwitchConnectionProviderFactoryImpl(@Reference final DiagStatusService diagStatus) { + this.diagStatus = requireNonNull(diagStatus); } - private static class ConnectionConfigurationImpl implements ConnectionConfiguration { - private final SwitchConnectionConfig config; - private InetAddress address; - - ConnectionConfigurationImpl(final SwitchConnectionConfig config) { - this.config = config; - - try { - address = getInetAddress(config.getAddress()); - } catch (UnknownHostException e) { - throw new RuntimeException(e); - } - } - - @Override - public InetAddress getAddress() { - return address; - } - - @Override - public int getPort() { - return config.getPort().toJava(); - } - - @Override - public Object getTransferProtocol() { - return config.getTransportProtocol(); - } - - @Override - public int getChannelOutboundQueueSize() { - return config.getChannelOutboundQueueSize().toJava(); - } - - @Override - public TlsConfiguration getTlsConfiguration() { - final Tls tlsConfig = config.getTls(); - if (tlsConfig == null || !TransportProtocol.TLS.equals(getTransferProtocol())) { - return null; - } - - return new TlsConfiguration() { - @Override - public KeystoreType getTlsTruststoreType() { - return requireNonNull(tlsConfig.getTruststoreType()); - } - - @Override - public String getTlsTruststore() { - return requireNonNull(tlsConfig.getTruststore()); - } - - @Override - public KeystoreType getTlsKeystoreType() { - return requireNonNull(tlsConfig.getKeystoreType()); - } - - @Override - public String getTlsKeystore() { - return requireNonNull(tlsConfig.getKeystore()); - } - - @Override - public org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType - getTlsKeystorePathType() { - return requireNonNull(tlsConfig.getKeystorePathType()); - } - - @Override - public org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType - getTlsTruststorePathType() { - return requireNonNull(tlsConfig.getTruststorePathType()); - } - - @Override - public String getKeystorePassword() { - return requireNonNull(tlsConfig.getKeystorePassword()); - } - - @Override - public String getCertificatePassword() { - return requireNonNull(tlsConfig.getCertificatePassword()); - } - - @Override - public String getTruststorePassword() { - return requireNonNull(tlsConfig.getTruststorePassword()); - } - - @Override - public List getCipherSuites() { - return tlsConfig.getCipherSuites(); - } - }; - } - - @Override - public long getSwitchIdleTimeout() { - return config.getSwitchIdleTimeout().toJava(); - } - - @Override - public Object getSslContext() { - return null; - } - - @Override - public ThreadConfiguration getThreadConfiguration() { - final Threads threads = config.getThreads(); - if (threads == null) { - return null; - } - - return new ThreadConfiguration() { - @Override - public int getWorkerThreadCount() { - return threads.getWorkerThreads().toJava(); - } - - @Override - public int getBossThreadCount() { - return threads.getBossThreads().toJava(); - } - }; - } - - @Override - public boolean useBarrier() { - return config.getUseBarrier(); - } - - @Override - public boolean isGroupAddModEnabled() { - return config.getGroupAddModEnabled(); - } - - private static InetAddress getInetAddress(final IpAddress address) throws UnknownHostException { - if (address != null) { - if (address.getIpv4Address() != null) { - return InetAddress.getByName(address.getIpv4Address().getValue()); - } else if (address.getIpv6Address() != null) { - return InetAddress.getByName(address.getIpv6Address().getValue()); - } - } - return null; - } + @Override + public SwitchConnectionProvider newInstance(final SwitchConnectionConfig config) { + return new SwitchConnectionProviderImpl(diagStatus, new ConnectionConfigurationImpl(config)); } }