From: Madhavan Kasthurirangan Date: Wed, 17 Apr 2013 19:15:39 +0000 (-0700) Subject: Improve Vendor Extension Error Handling. X-Git-Tag: releasepom-0.1.0~560^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=95abc843094ef5fa8bc87c1d5933bfad9702b0a0;p=controller.git Improve Vendor Extension Error Handling. Signed-off-by: Madhavan Kasthurirangan --- diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowProgrammerService.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowProgrammerService.java index b30b5c76c1..983c7c2190 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowProgrammerService.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowProgrammerService.java @@ -9,8 +9,10 @@ package org.opendaylight.controller.protocol_plugin.openflow.internal; +import java.nio.ByteBuffer; import org.opendaylight.controller.protocol_plugin.openflow.core.IController; import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; +import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Error; import org.openflow.protocol.OFError; import org.openflow.protocol.OFFlowMod; import org.openflow.protocol.OFMessage; @@ -22,6 +24,8 @@ import org.opendaylight.controller.sal.flowprogrammer.Flow; import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService; import org.opendaylight.controller.sal.utils.StatusCode; import org.opendaylight.controller.sal.utils.Status; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Represents the openflow plugin component in charge of programming the flows @@ -31,6 +35,8 @@ import org.opendaylight.controller.sal.utils.Status; * */ public class FlowProgrammerService implements IPluginInFlowProgrammerService { + private static final Logger log = LoggerFactory + .getLogger(FlowProgrammerService.class); private IController controller; public FlowProgrammerService() { @@ -107,9 +113,21 @@ public class FlowProgrammerService implements IPluginInFlowProgrammerService { errorString(null, action, "Request Timed Out")); } else if (result instanceof OFError) { + OFError res = (OFError) result; + if (res.getErrorType() == V6Error.NICIRA_VENDOR_ERRORTYPE) { + V6Error er = new V6Error(res); + byte[] b = res.getError(); + ByteBuffer bb = ByteBuffer.allocate(b.length); + bb.put(b); + bb.rewind(); + er.readFrom(bb); + log.trace("V6Error {}",er); + return new Status(StatusCode.INTERNALERROR, + errorString("program", action, "Vendor Extension Internal Error")); + } return new Status(StatusCode.INTERNALERROR, errorString("program", action, Utils - .getOFErrorString((OFError) result))); + .getOFErrorString(res))); } else { return new Status(StatusCode.INTERNALERROR, errorString("send", action, "Internal Error")); diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6Error.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6Error.java new file mode 100644 index 0000000000..4f0dbd5ca5 --- /dev/null +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6Error.java @@ -0,0 +1,80 @@ +package org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension; + +import java.nio.ByteBuffer; + +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.openflow.protocol.OFError; + +public class V6Error extends OFError { + private static final long serialVersionUID = 1L; + public static int MINIMUM_LENGTH = 20;//OfHdr(8) + NXET_VENDOR(2) + NXEC_VENDOR_ERROR(2) + struct nx_vendor_error(8) + public static final short NICIRA_VENDOR_ERRORTYPE = (short)0xb0c2; + protected int V6VendorId; + protected short V6VendorErrorType; + protected short V6VendorErrorCode; + protected byte[] V6ErrorData; + + public V6Error(OFError e) { + this.length = (short)e.getLengthU(); + this.errorType = e.getErrorType(); + this.errorCode = e.getErrorCode(); + this.xid = e.getXid(); + } + + @Override + public void readFrom(ByteBuffer data) { + this.V6VendorId = data.getInt(); + this.V6VendorErrorType = data.getShort(); + this.V6VendorErrorCode = data.getShort(); + int dataLength = this.getLengthU() - MINIMUM_LENGTH; + if (dataLength > 0) { + this.V6ErrorData = new byte[dataLength]; + data.get(this.V6ErrorData); + } + } + + /** + * @return the V6VendorId + */ + public int getVendorId() { + return V6VendorId; + } + + /** + * @return the V6VendorErrorType + */ + public short getVendorErrorType() { + return V6VendorErrorType; + } + + /** + * @return the VendorErrorType + */ + public short getVendorErrorCode() { + return V6VendorErrorCode; + } + + /** + * @return the Error Bytes + */ + public byte[] getError() { + return V6ErrorData; + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } + + @Override + public String toString() { + return "V6Error[" + ReflectionToStringBuilder.toString(this) + "]"; + } + + @Override + public boolean equals(Object obj) { + return EqualsBuilder.reflectionEquals(this, obj); + } +}