X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fprotocol_plugins%2Fopenflow%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fprotocol_plugin%2Fopenflow%2Fcore%2Finternal%2FSwitchHandler.java;h=7a177fa078c8607e41bb2fa62f9ea6c2c8b7d032;hb=6fd408a04fe4a3611843e2246ece6d7c34b76903;hp=91909d20f53a5bde5adea2b7020c38a78406f080;hpb=78ef04c45c5a7fbee9bbb9ae77ecb1882add8623;p=controller.git 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 91909d20f5..7a177fa078 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 @@ -38,6 +38,7 @@ import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; import org.openflow.protocol.OFBarrierReply; import org.openflow.protocol.OFBarrierRequest; import org.openflow.protocol.OFEchoReply; +import org.openflow.protocol.OFEchoRequest; import org.openflow.protocol.OFError; import org.openflow.protocol.OFFeaturesReply; import org.openflow.protocol.OFFlowMod; @@ -60,6 +61,7 @@ import org.openflow.util.HexString; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + public class SwitchHandler implements ISwitch { private static final Logger logger = LoggerFactory.getLogger(SwitchHandler.class); private static final int SWITCH_LIVENESS_TIMER = 5000; @@ -359,8 +361,6 @@ public class SwitchHandler implements ISwitch { } if (msgs == null) { - logger.info("{} is down", this); - reportSwitchStateChange(false); return; } for (OFMessage msg : msgs) { @@ -369,22 +369,23 @@ 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); - // delete all pre-existing flows - OFMatch match = new OFMatch().setWildcards(OFMatch.OFPFW_ALL); - OFFlowMod flowMod = (OFFlowMod) factory.getMessage(OFType.FLOW_MOD); - flowMod.setMatch(match).setCommand(OFFlowMod.OFPFC_DELETE).setOutPort(OFPort.OFPP_NONE) - .setLength((short) OFFlowMod.MINIMUM_LENGTH); - asyncFastSend(flowMod); - this.state = SwitchState.WAIT_FEATURES_REPLY; - startSwitchTimer(); + sendFeaturesRequest(); break; case ECHO_REQUEST: OFEchoReply echoReply = (OFEchoReply) factory.getMessage(OFType.ECHO_REPLY); + + byte []payload = ((OFEchoRequest)msg).getPayload(); + if (payload != null && payload.length != 0 ) { + // the response must have the same payload as the request + echoReply.setPayload(payload); + echoReply.setLength( (short)(echoReply.getLength() + payload.length) ); + } + // respond immediately asyncSendNow(echoReply, msg.getXid()); + + // send features request if not sent yet + sendFeaturesRequest(); break; case ECHO_REPLY: this.probeSent = false; @@ -513,6 +514,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(); @@ -925,4 +936,14 @@ public class SwitchHandler implements ISwitch { return result; } } + + @Override + public void deleteAllFlows() { + logger.trace("deleteAllFlows on switch {}", HexString.toHexString(this.sid)); + OFMatch match = new OFMatch().setWildcards(OFMatch.OFPFW_ALL); + OFFlowMod flowMod = (OFFlowMod) factory.getMessage(OFType.FLOW_MOD); + flowMod.setMatch(match).setCommand(OFFlowMod.OFPFC_DELETE).setOutPort(OFPort.OFPP_NONE) + .setLength((short) OFFlowMod.MINIMUM_LENGTH); + asyncFastSend(flowMod); + } }