Rewire SwitchConnectionProvider configuration
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / core / SwitchConnectionProviderFactoryImpl.java
index 7ee78a13ff930e0dbed1b6c8a6bd18526e5994a7..cb8a963d5ae34062899997d0094a3ca290419d29 100644 (file)
@@ -9,23 +9,12 @@ 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.opendaylight.infrautils.diagstatus.DiagStatusService;
-import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration;
-import org.opendaylight.openflowjava.protocol.api.connection.ThreadConfiguration;
-import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration;
 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;
@@ -48,152 +37,4 @@ public class SwitchConnectionProviderFactoryImpl implements SwitchConnectionProv
     public SwitchConnectionProvider newInstance(final SwitchConnectionConfig config) {
         return new SwitchConnectionProviderImpl(diagStatus, new ConnectionConfigurationImpl(config));
     }
-
-    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 IllegalStateException(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<String> 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;
-        }
-    }
 }