Improve Vendor Extension Error Handling. 06/206/1
authorMadhavan Kasthurirangan <mkasthur@cisco.com>
Wed, 17 Apr 2013 19:15:39 +0000 (12:15 -0700)
committerMadhavan Kasthurirangan <mkasthur@cisco.com>
Wed, 17 Apr 2013 19:15:39 +0000 (12:15 -0700)
Signed-off-by: Madhavan Kasthurirangan <mkasthur@cisco.com>
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowProgrammerService.java
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6Error.java [new file with mode: 0644]

index b30b5c76c10470655f94a30827fe8bebca49638b..983c7c2190e09d19298f7454a093615956f91299 100644 (file)
@@ -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 (file)
index 0000000..4f0dbd5
--- /dev/null
@@ -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);
+    }
+}