Prince Pereira
Committed by Gerrit Code Review

Fix for BAD-ACTION ONOS-4688 , BAD-MATCH ONOS-4755 and other flow-mod errors.

Change-Id: Icf1a4883da50354bcebdad4c1a9693285d4cf8b4
(cherry picked from commit aaff2927)
...@@ -61,7 +61,6 @@ import org.osgi.service.component.ComponentContext; ...@@ -61,7 +61,6 @@ import org.osgi.service.component.ComponentContext;
61 import org.projectfloodlight.openflow.protocol.OFBadRequestCode; 61 import org.projectfloodlight.openflow.protocol.OFBadRequestCode;
62 import org.projectfloodlight.openflow.protocol.OFBarrierRequest; 62 import org.projectfloodlight.openflow.protocol.OFBarrierRequest;
63 import org.projectfloodlight.openflow.protocol.OFErrorMsg; 63 import org.projectfloodlight.openflow.protocol.OFErrorMsg;
64 -import org.projectfloodlight.openflow.protocol.OFErrorType;
65 import org.projectfloodlight.openflow.protocol.OFFlowMod; 64 import org.projectfloodlight.openflow.protocol.OFFlowMod;
66 import org.projectfloodlight.openflow.protocol.OFFlowRemoved; 65 import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
67 import org.projectfloodlight.openflow.protocol.OFFlowStatsReply; 66 import org.projectfloodlight.openflow.protocol.OFFlowStatsReply;
...@@ -71,6 +70,9 @@ import org.projectfloodlight.openflow.protocol.OFStatsReply; ...@@ -71,6 +70,9 @@ import org.projectfloodlight.openflow.protocol.OFStatsReply;
71 import org.projectfloodlight.openflow.protocol.OFStatsType; 70 import org.projectfloodlight.openflow.protocol.OFStatsType;
72 import org.projectfloodlight.openflow.protocol.OFTableStatsEntry; 71 import org.projectfloodlight.openflow.protocol.OFTableStatsEntry;
73 import org.projectfloodlight.openflow.protocol.OFTableStatsReply; 72 import org.projectfloodlight.openflow.protocol.OFTableStatsReply;
73 +import org.projectfloodlight.openflow.protocol.errormsg.OFBadActionErrorMsg;
74 +import org.projectfloodlight.openflow.protocol.errormsg.OFBadInstructionErrorMsg;
75 +import org.projectfloodlight.openflow.protocol.errormsg.OFBadMatchErrorMsg;
74 import org.projectfloodlight.openflow.protocol.errormsg.OFBadRequestErrorMsg; 76 import org.projectfloodlight.openflow.protocol.errormsg.OFBadRequestErrorMsg;
75 import org.projectfloodlight.openflow.protocol.errormsg.OFFlowModFailedErrorMsg; 77 import org.projectfloodlight.openflow.protocol.errormsg.OFFlowModFailedErrorMsg;
76 import org.slf4j.Logger; 78 import org.slf4j.Logger;
...@@ -488,32 +490,60 @@ public class OpenFlowRuleProvider extends AbstractProvider ...@@ -488,32 +490,60 @@ public class OpenFlowRuleProvider extends AbstractProvider
488 } else { 490 } else {
489 log.warn("Received error message {} from {}", msg, dpid); 491 log.warn("Received error message {} from {}", msg, dpid);
490 } 492 }
491 - 493 + handleErrorMsg(deviceId, msg);
492 - OFErrorMsg error = (OFErrorMsg) msg;
493 - if (error.getErrType() == OFErrorType.FLOW_MOD_FAILED) {
494 - OFFlowModFailedErrorMsg fmFailed = (OFFlowModFailedErrorMsg) error;
495 - if (fmFailed.getData().getParsedMessage().isPresent()) {
496 - OFMessage m = fmFailed.getData().getParsedMessage().get();
497 - OFFlowMod fm = (OFFlowMod) m;
498 - InternalCacheEntry entry =
499 - pendingBatches.getIfPresent(msg.getXid());
500 - if (entry != null) {
501 - entry.appendFailure(new FlowEntryBuilder(deviceId, fm, driverService).build());
502 - } else {
503 - log.error("No matching batch for this error: {}", error);
504 - }
505 - } else {
506 - // FIXME: Potentially add flowtracking to avoid this message.
507 - log.error("Flow installation failed but switch didn't"
508 - + " tell us which one.");
509 - }
510 - }
511 break; 494 break;
512 default: 495 default:
513 log.debug("Unhandled message type: {}", msg.getType()); 496 log.debug("Unhandled message type: {}", msg.getType());
514 } 497 }
515 } 498 }
516 499
500 + private void handleErrorMsg(DeviceId deviceId, OFMessage msg) {
501 + OFErrorMsg error = (OFErrorMsg) msg;
502 + OFMessage ofMessage = null;
503 + switch (error.getErrType()) {
504 + case BAD_ACTION:
505 + OFBadActionErrorMsg baErrorMsg = (OFBadActionErrorMsg) error;
506 + if (baErrorMsg.getData().getParsedMessage().isPresent()) {
507 + ofMessage = baErrorMsg.getData().getParsedMessage().get();
508 + }
509 + break;
510 + case BAD_INSTRUCTION:
511 + OFBadInstructionErrorMsg biErrorMsg = (OFBadInstructionErrorMsg) error;
512 + if (biErrorMsg.getData().getParsedMessage().isPresent()) {
513 + ofMessage = biErrorMsg.getData().getParsedMessage().get();
514 + }
515 + break;
516 + case BAD_MATCH:
517 + OFBadMatchErrorMsg bmErrorMsg = (OFBadMatchErrorMsg) error;
518 + if (bmErrorMsg.getData().getParsedMessage().isPresent()) {
519 + ofMessage = bmErrorMsg.getData().getParsedMessage().get();
520 + }
521 + break;
522 + case FLOW_MOD_FAILED:
523 + OFFlowModFailedErrorMsg fmFailed = (OFFlowModFailedErrorMsg) error;
524 + if (fmFailed.getData().getParsedMessage().isPresent()) {
525 + ofMessage = fmFailed.getData().getParsedMessage().get();
526 + }
527 + break;
528 + default:
529 + // Do nothing.
530 + return;
531 + }
532 + if (ofMessage != null) {
533 + InternalCacheEntry entry =
534 + pendingBatches.getIfPresent(msg.getXid());
535 + if (entry != null) {
536 + OFFlowMod ofFlowMod = (OFFlowMod) ofMessage;
537 + entry.appendFailure(new FlowEntryBuilder(deviceId, ofFlowMod, driverService).build());
538 + } else {
539 + log.error("No matching batch for this error: {}", error);
540 + }
541 + } else {
542 + log.error("Flow installation failed but switch didn't"
543 + + " tell us which one.");
544 + }
545 + }
546 +
517 @Override 547 @Override
518 public void receivedRoleReply(Dpid dpid, RoleState requested, 548 public void receivedRoleReply(Dpid dpid, RoleState requested,
519 RoleState response) { 549 RoleState response) {
......