From: Jason Ye Date: Sat, 9 Nov 2013 05:18:08 +0000 (-0800) Subject: Clear the receive buffer when message parser throws exceptions. Don't terminate the... X-Git-Tag: jenkins-controller-bulk-release-prepare-only-2-1~438^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=253ca500e9b816a4e5df6d5da8e57c32b8a9b35e;p=controller.git Clear the receive buffer when message parser throws exceptions. Don't terminate the connection when message parser throws exceptions. Send Features Request msg if not done so. Change-Id: I80264520ea545c529dab3b4e685e4442818cb52d Signed-off-by: Jason Ye --- 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 da7735d4c5..9041004605 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 @@ -132,12 +132,17 @@ public class MessageReadWriteService implements IMessageReadWrite { throw new AsynchronousCloseException(); } - inBuffer.flip(); - msgs = factory.parseMessages(inBuffer); - if (inBuffer.hasRemaining()) { - inBuffer.compact(); - } else { + try { + inBuffer.flip(); + msgs = factory.parseMessages(inBuffer); + if (inBuffer.hasRemaining()) { + inBuffer.compact(); + } else { + inBuffer.clear(); + } + } catch (Exception e) { inBuffer.clear(); + logger.debug("Caught exception: ", e); } return msgs; } 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 f0922d3658..90b47cf264 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 @@ -282,12 +282,17 @@ public class SecureMessageReadWriteService implements IMessageReadWrite { peerNetData.position(), peerNetData.limit()); } - peerAppData.flip(); - msgs = factory.parseMessages(peerAppData); - if (peerAppData.hasRemaining()) { - peerAppData.compact(); - } else { + try { + peerAppData.flip(); + msgs = factory.parseMessages(peerAppData); + if (peerAppData.hasRemaining()) { + peerAppData.compact(); + } else { + peerAppData.clear(); + } + } catch (Exception e) { peerAppData.clear(); + logger.debug("Caught exception: ", e); } this.socket.register(this.selector, SelectionKey.OP_READ, this); 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 6e000022df..6fddef06a8 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 @@ -359,8 +359,6 @@ public class SwitchHandler implements ISwitch { } if (msgs == null) { - logger.info("{} is down", this); - reportSwitchStateChange(false); return; } for (OFMessage msg : msgs) { @@ -369,16 +367,15 @@ public class SwitchHandler implements ISwitch { OFType type = msg.getType(); switch (type) { case HELLO: - // send feature request - OFMessage featureRequest = factory.getMessage(OFType.FEATURES_REQUEST); - asyncFastSend(featureRequest); - this.state = SwitchState.WAIT_FEATURES_REPLY; - startSwitchTimer(); + sendFeaturesRequest(); break; case ECHO_REQUEST: OFEchoReply echoReply = (OFEchoReply) factory.getMessage(OFType.ECHO_REPLY); // respond immediately asyncSendNow(echoReply, msg.getXid()); + + // send features request if not sent yet + sendFeaturesRequest(); break; case ECHO_REPLY: this.probeSent = false; @@ -507,6 +504,16 @@ public class SwitchHandler implements ISwitch { return this.sid; } + private void sendFeaturesRequest() { + if (!isOperational() && (this.state != SwitchState.WAIT_FEATURES_REPLY)) { + // send feature request + OFMessage featureRequest = factory.getMessage(OFType.FEATURES_REQUEST); + asyncFastSend(featureRequest); + this.state = SwitchState.WAIT_FEATURES_REPLY; + startSwitchTimer(); + } + } + private void processFeaturesReply(OFFeaturesReply reply) { if (this.state == SwitchState.WAIT_FEATURES_REPLY) { this.sid = reply.getDatapathId();