From: Jason Ye Date: Tue, 16 Apr 2013 21:29:52 +0000 (-0700) Subject: - Added OSGI cmd to display TLS configuration X-Git-Tag: releasepom-0.1.0~564 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=9a56865bf08f5a2365fb1102e1518df8a1d2f392 - Added OSGI cmd to display TLS configuration - Added null pointer checks and more debug msgs Signed-off-by: Jason Ye --- diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/Controller.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/Controller.java index f3004acaba..32cdeaa614 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/Controller.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/Controller.java @@ -9,6 +9,7 @@ package org.opendaylight.controller.protocol_plugin.openflow.core.internal; +import java.io.FileNotFoundException; import java.io.IOException; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; @@ -338,6 +339,28 @@ public class Controller implements IController, CommandProvider { } } + public void _controllerShowConnConfig(CommandInterpreter ci) { + String str = System.getProperty("secureChannelEnabled"); + if ((str != null) && (str.trim().equalsIgnoreCase("true"))) { + ci.print("The Controller and Switch should communicate through TLS connetion.\n"); + + String keyStoreFile = System.getProperty("controllerKeyStore"); + String trustStoreFile = System.getProperty("controllerTrustStore"); + if ((keyStoreFile == null) || keyStoreFile.trim().isEmpty()) { + ci.print("controllerKeyStore not specified in ./configuration/config.ini\n"); + } else { + ci.print("controllerKeyStore=" + keyStoreFile + "\n"); + } + if ((trustStoreFile == null) || trustStoreFile.trim().isEmpty()) { + ci.print("controllerTrustStore not specified in ./configuration/config.ini\n"); + } else { + ci.print("controllerTrustStore=" + trustStoreFile + "\n"); + } + } else { + ci.print("The Controller and Switch should communicate through TCP connetion.\n"); + } + } + private void registerWithOSGIConsole() { BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()) .getBundleContext(); @@ -351,6 +374,7 @@ public class Controller implements IController, CommandProvider { help.append("--Open Flow Controller --\n"); help.append("\tcontrollerShowSwitches\n"); help.append("\tcontrollerReset\n"); + help.append("\tcontrollerShowConnConfig\n"); return help.toString(); } } diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/MessageReadWriteService.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/MessageReadWriteService.java index fb34b0f063..8e611924e4 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/MessageReadWriteService.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/MessageReadWriteService.java @@ -69,6 +69,8 @@ public class MessageReadWriteService implements IMessageReadWrite { newBuffer.put(outBuffer); outBuffer = newBuffer; } + } + synchronized (outBuffer) { msg.writeTo(outBuffer); if (!socket.isOpen()) { diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SecureMessageReadWriteService.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SecureMessageReadWriteService.java index ddc87bc530..bb8ba04fb8 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SecureMessageReadWriteService.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SecureMessageReadWriteService.java @@ -10,6 +10,7 @@ package org.opendaylight.controller.protocol_plugin.openflow.core.internal; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.AsynchronousCloseException; @@ -74,11 +75,36 @@ public class SecureMessageReadWriteService implements IMessageReadWrite { * @throws Exception */ private void createSecureChannel(SocketChannel socket) throws Exception { - String keyStoreFile = System.getProperty("controllerKeyStore").trim(); - String keyStorePassword = System.getProperty("controllerKeyStorePassword").trim(); - String trustStoreFile = System.getProperty("controllerTrustStore").trim(); - String trustStorePassword = System.getProperty("controllerTrustStorePassword").trim(); - + String keyStoreFile = System.getProperty("controllerKeyStore"); + String keyStorePassword = System.getProperty("controllerKeyStorePassword"); + String trustStoreFile = System.getProperty("controllerTrustStore"); + String trustStorePassword = System.getProperty("controllerTrustStorePassword"); + + if (keyStoreFile != null) { + keyStoreFile = keyStoreFile.trim(); + } + if ((keyStoreFile == null) || keyStoreFile.isEmpty()) { + throw new FileNotFoundException("controllerKeyStore not specified in ./configuration/config.ini"); + } + if (keyStorePassword != null) { + keyStorePassword = keyStorePassword.trim(); + } + if ((keyStorePassword == null) || keyStorePassword.isEmpty()) { + throw new FileNotFoundException("controllerKeyStorePassword not specified in ./configuration/config.ini"); + } + if (trustStoreFile != null) { + trustStoreFile = trustStoreFile.trim(); + } + if ((trustStoreFile == null) || trustStoreFile.isEmpty()) { + throw new FileNotFoundException("controllerTrustStore not specified in ./configuration/config.ini"); + } + if (trustStorePassword != null) { + trustStorePassword = trustStorePassword.trim(); + } + if ((trustStorePassword == null) || trustStorePassword.isEmpty()) { + throw new FileNotFoundException("controllerTrustStorePassword not specified in ./configuration/config.ini"); + } + KeyStore ks = KeyStore.getInstance("JKS"); KeyStore ts = KeyStore.getInstance("JKS"); KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); @@ -126,6 +152,8 @@ public class SecureMessageReadWriteService implements IMessageReadWrite { newBuffer.put(myAppData); myAppData = newBuffer; } + } + synchronized (myAppData) { msg.writeTo(myAppData); myAppData.flip(); sslEngineResult = sslEngine.wrap(myAppData, myNetData); diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SwitchHandler.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SwitchHandler.java index cba8b1d4f1..5913ad0dd9 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SwitchHandler.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SwitchHandler.java @@ -9,7 +9,7 @@ package org.opendaylight.controller.protocol_plugin.openflow.core.internal; -import java.io.IOException; +import java.net.SocketException; import java.nio.channels.AsynchronousCloseException; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; @@ -249,7 +249,9 @@ public class SwitchHandler implements ISwitch { @Override public Integer asyncSend(OFMessage msg, int xid) { msg.setXid(xid); - transmitQ.add(new PriorityMessage(msg, 0)); + if (transmitQ != null) { + transmitQ.add(new PriorityMessage(msg, 0)); + } return xid; } @@ -280,13 +282,17 @@ public class SwitchHandler implements ISwitch { @Override public Integer asyncFastSend(OFMessage msg, int xid) { msg.setXid(xid); - transmitQ.add(new PriorityMessage(msg, 1)); + if (transmitQ != null) { + transmitQ.add(new PriorityMessage(msg, 1)); + } return xid; } public void resumeSend() { try { - msgReadWriteService.resumeSend(); + if (msgReadWriteService != null) { + msgReadWriteService.resumeSend(); + } } catch (Exception e) { reportError(e); } @@ -445,7 +451,9 @@ public class SwitchHandler implements ISwitch { } private void reportError(Exception e) { - if (e instanceof AsynchronousCloseException) { + if (e instanceof AsynchronousCloseException || + e instanceof InterruptedException || + e instanceof SocketException) { logger.debug("Caught exception {}", e.getMessage()); } else { logger.warn("Caught exception {}", e.getMessage()); @@ -739,6 +747,8 @@ public class SwitchHandler implements ISwitch { logger.trace("Message sent: {}", pmsg.toString()); } Thread.sleep(10); + } catch (InterruptedException ie) { + reportError(new InterruptedException("PriorityMessageTransmit thread interrupted")); } catch (Exception e) { reportError(e); }