- private static InetAddress extractIpAddressBin(final IpAddress address) throws UnknownHostException {
- byte[] addressBin = null;
- if (address != null) {
- if (address.getIpv4Address() != null) {
- addressBin = address2bin(address.getIpv4Address().getValue());
- } else if (address.getIpv6Address() != null) {
- addressBin = address2bin(address.getIpv6Address().getValue());
- }
- }
-
- if (addressBin == null) {
- return null;
- } else {
- return InetAddress.getByAddress(addressBin);
- }
- }
-
- @SuppressFBWarnings("PZLA_PREFER_ZERO_LENGTH_ARRAYS")
- private static byte[] address2bin(final String value) {
- //TODO: translate ipv4 or ipv6 into byte[]
- return null;
- }
-
- private static class ConnectionConfigurationImpl implements ConnectionConfiguration {
- private final SwitchConnectionConfig config;
- private InetAddress address;
-
- ConnectionConfigurationImpl(SwitchConnectionConfig config) {
- this.config = config;
-
- try {
- address = extractIpAddressBin(config.getAddress());
- } catch (UnknownHostException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public InetAddress getAddress() {
- return address;
- }
-
- @Override
- public int getPort() {
- return config.getPort();
- }
-
- @Override
- public Object getTransferProtocol() {
- return config.getTransportProtocol();
- }
-
- @Override
- public int getChannelOutboundQueueSize() {
- return config.getChannelOutboundQueueSize();
- }
-
- @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 MoreObjects.firstNonNull(tlsConfig.getTruststoreType(), null);
- }
-
- @Override
- public String getTlsTruststore() {
- return MoreObjects.firstNonNull(tlsConfig.getTruststore(), null);
- }
-
- @Override
- public KeystoreType getTlsKeystoreType() {
- return MoreObjects.firstNonNull(tlsConfig.getKeystoreType(), null);
- }
-
- @Override
- public String getTlsKeystore() {
- return MoreObjects.firstNonNull(tlsConfig.getKeystore(), null);
- }
-
- @Override
- public org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType
- getTlsKeystorePathType() {
- return MoreObjects.firstNonNull(tlsConfig.getKeystorePathType(), null);
- }
-
- @Override
- public org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType
- getTlsTruststorePathType() {
- return MoreObjects.firstNonNull(tlsConfig.getTruststorePathType(), null);
- }
-
- @Override
- public String getKeystorePassword() {
- return MoreObjects.firstNonNull(tlsConfig.getKeystorePassword(), null);
- }
-
- @Override
- public String getCertificatePassword() {
- return MoreObjects.firstNonNull(tlsConfig.getCertificatePassword(), null);
- }
-
- @Override
- public String getTruststorePassword() {
- return MoreObjects.firstNonNull(tlsConfig.getTruststorePassword(), null);
- }
-
- @Override
- public List<String> getCipherSuites() {
- return tlsConfig.getCipherSuites();
- }
- };
- }
-
- @Override
- public long getSwitchIdleTimeout() {
- return config.getSwitchIdleTimeout();
- }
-
- @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();
- }
-
- @Override
- public int getBossThreadCount() {
- return threads.getBossThreads();
- }
- };
- }
-
- @Override
- public boolean useBarrier() {
- return config.isUseBarrier();
- }
-
- @Override
- public boolean isGroupAddModEnabled() {
- return config.isGroupAddModEnabled();
- }