BUG-2218: Keep existing link augmentations during discovery process
[controller.git] / opendaylight / protocol_plugins / openflow / src / main / java / org / opendaylight / controller / protocol_plugin / openflow / vendorextension / v6extension / V6Error.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension;
9
10 import java.nio.ByteBuffer;
11 import java.util.Arrays;
12
13 import org.openflow.protocol.OFError;
14
15 public class V6Error extends OFError {
16         private static final long serialVersionUID = 1L;
17         public static int MINIMUM_LENGTH = 20;//OfHdr(8) + NXET_VENDOR(2) + NXEC_VENDOR_ERROR(2) + struct nx_vendor_error(8)
18         public static final short NICIRA_VENDOR_ERRORTYPE = (short)0xb0c2;
19         protected int V6VendorId;
20     protected short V6VendorErrorType;
21     protected short V6VendorErrorCode;
22     protected byte[] V6ErrorData;
23
24     public V6Error(OFError e) {
25         this.length = (short)e.getLengthU();
26         this.errorType = e.getErrorType();
27         this.errorCode = e.getErrorCode();
28         this.xid = e.getXid();
29     }
30
31     @Override
32     public void readFrom(ByteBuffer data) {
33         this.V6VendorId = data.getInt();
34         this.V6VendorErrorType = data.getShort();
35         this.V6VendorErrorCode = data.getShort();
36         int dataLength = this.getLengthU() - MINIMUM_LENGTH;
37         if (dataLength > 0) {
38             this.V6ErrorData = new byte[dataLength];
39             data.get(this.V6ErrorData);
40         }
41     }
42
43     /**
44      * @return the V6VendorId
45      */
46     public int getVendorId() {
47         return V6VendorId;
48     }
49
50     /**
51      * @return the V6VendorErrorType
52      */
53     public short getVendorErrorType() {
54         return V6VendorErrorType;
55     }
56
57     /**
58      * @return the VendorErrorType
59      */
60     public short getVendorErrorCode() {
61         return V6VendorErrorCode;
62     }
63
64     /**
65      * @return the Error Bytes
66      */
67     public byte[] getError() {
68         return V6ErrorData;
69     }
70
71     @Override
72     public int hashCode() {
73         final int prime = 31;
74         int result = super.hashCode();
75         result = prime * result + Arrays.hashCode(V6ErrorData);
76         result = prime * result + V6VendorErrorCode;
77         result = prime * result + V6VendorErrorType;
78         result = prime * result + V6VendorId;
79         return result;
80     }
81
82     @Override
83     public String toString() {
84         return "V6Error [V6VendorId=" + V6VendorId + ", V6VendorErrorType="
85                 + V6VendorErrorType + ", V6VendorErrorCode="
86                 + V6VendorErrorCode + ", V6ErrorData="
87                 + Arrays.toString(V6ErrorData) + ", errorType=" + errorType
88                 + ", errorCode=" + errorCode + ", factory=" + factory
89                 + ", error=" + Arrays.toString(error) + ", errorIsAscii="
90                 + errorIsAscii + ", version=" + version + ", type=" + type
91                 + ", length=" + length + ", xid=" + xid + "]";
92     }
93
94     @Override
95     public boolean equals(Object obj) {
96         if (this == obj)
97             return true;
98         if (!super.equals(obj))
99             return false;
100         if (getClass() != obj.getClass())
101             return false;
102         V6Error other = (V6Error) obj;
103         if (!Arrays.equals(V6ErrorData, other.V6ErrorData))
104             return false;
105         if (V6VendorErrorCode != other.V6VendorErrorCode)
106             return false;
107         if (V6VendorErrorType != other.V6VendorErrorType)
108             return false;
109         if (V6VendorId != other.V6VendorId)
110             return false;
111         return true;
112     }
113 }