4f0dbd5ca55b0b621f6202a68e7488cdc4447486
[controller.git] / opendaylight / protocol_plugins / openflow / src / main / java / org / opendaylight / controller / protocol_plugin / openflow / vendorextension / v6extension / V6Error.java
1 package org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension;
2
3 import java.nio.ByteBuffer;
4
5 import org.apache.commons.lang3.builder.EqualsBuilder;
6 import org.apache.commons.lang3.builder.HashCodeBuilder;
7 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
8 import org.openflow.protocol.OFError;
9
10 public class V6Error extends OFError {
11         private static final long serialVersionUID = 1L;
12         public static int MINIMUM_LENGTH = 20;//OfHdr(8) + NXET_VENDOR(2) + NXEC_VENDOR_ERROR(2) + struct nx_vendor_error(8)
13         public static final short NICIRA_VENDOR_ERRORTYPE = (short)0xb0c2;
14         protected int V6VendorId;
15     protected short V6VendorErrorType;
16     protected short V6VendorErrorCode;
17     protected byte[] V6ErrorData;
18     
19     public V6Error(OFError e) {
20         this.length = (short)e.getLengthU();
21         this.errorType = e.getErrorType();
22         this.errorCode = e.getErrorCode();
23         this.xid = e.getXid();
24     }
25     
26     @Override
27     public void readFrom(ByteBuffer data) {
28         this.V6VendorId = data.getInt();
29         this.V6VendorErrorType = data.getShort();
30         this.V6VendorErrorCode = data.getShort();
31         int dataLength = this.getLengthU() - MINIMUM_LENGTH;
32         if (dataLength > 0) {
33             this.V6ErrorData = new byte[dataLength];
34             data.get(this.V6ErrorData);
35         }   
36     }
37     
38     /**
39      * @return the V6VendorId
40      */
41     public int getVendorId() {
42         return V6VendorId;
43     }
44     
45     /**
46      * @return the V6VendorErrorType
47      */
48     public short getVendorErrorType() {
49         return V6VendorErrorType;
50     }
51     
52     /**
53      * @return the VendorErrorType
54      */
55     public short getVendorErrorCode() {
56         return V6VendorErrorCode;
57     }
58     
59     /**
60      * @return the Error Bytes
61      */
62     public byte[] getError() {
63         return V6ErrorData;
64     }
65     
66     @Override
67     public int hashCode() {
68         return HashCodeBuilder.reflectionHashCode(this);
69     }
70
71     @Override
72     public String toString() {
73         return "V6Error[" + ReflectionToStringBuilder.toString(this) + "]";
74     }
75
76     @Override
77     public boolean equals(Object obj) {
78         return EqualsBuilder.reflectionEquals(this, obj);
79     }
80 }