ec730e381340ed99ed17f95094496ada1644b5a1
[openflowplugin.git] / openflow-codec / src / main / java / org / openflow / codec / protocol / statistics / OFPDescriptionStatistics.java
1 package org.openflow.codec.protocol.statistics;
2
3 import java.io.Serializable;
4
5 import org.openflow.codec.io.IDataBuffer;
6 import org.openflow.codec.util.StringByteSerializer;
7
8 /**
9  * Represents an ofp_desc structure
10  *
11  * @author David Erickson (daviderickson@cs.stanford.edu)
12  */
13 public class OFPDescriptionStatistics implements OFPStatistics, Serializable {
14     public static int DESCRIPTION_STRING_LENGTH = 256;
15     public static int SERIAL_NUMBER_LENGTH = 32;
16
17     protected String manufacturerDescription;
18     protected String hardwareDescription;
19     protected String softwareDescription;
20     protected String serialNumber;
21     protected String datapathDescription;
22
23     /**
24      * @return the manufacturerDescription
25      */
26     public String getManufacturerDescription() {
27         return manufacturerDescription;
28     }
29
30     /**
31      * @param manufacturerDescription
32      *            the manufacturerDescription to set
33      */
34     public void setManufacturerDescription(String manufacturerDescription) {
35         this.manufacturerDescription = manufacturerDescription;
36     }
37
38     /**
39      * @return the hardwareDescription
40      */
41     public String getHardwareDescription() {
42         return hardwareDescription;
43     }
44
45     /**
46      * @param hardwareDescription
47      *            the hardwareDescription to set
48      */
49     public void setHardwareDescription(String hardwareDescription) {
50         this.hardwareDescription = hardwareDescription;
51     }
52
53     /**
54      * @return the softwareDescription
55      */
56     public String getSoftwareDescription() {
57         return softwareDescription;
58     }
59
60     /**
61      * @param softwareDescription
62      *            the softwareDescription to set
63      */
64     public void setSoftwareDescription(String softwareDescription) {
65         this.softwareDescription = softwareDescription;
66     }
67
68     /**
69      * @return the serialNumber
70      */
71     public String getSerialNumber() {
72         if (serialNumber.equals("None"))
73             return "";
74         return serialNumber;
75     }
76
77     /**
78      * @param serialNumber
79      *            the serialNumber to set
80      */
81     public void setSerialNumber(String serialNumber) {
82         this.serialNumber = serialNumber;
83     }
84
85     /**
86      * @return the datapathDescription
87      */
88     public String getDatapathDescription() {
89         return datapathDescription;
90     }
91
92     /**
93      * @param datapathDescription
94      *            the datapathDescription to set
95      */
96     public void setDatapathDescription(String datapathDescription) {
97         this.datapathDescription = datapathDescription;
98     }
99
100     @Override
101     public int getLength() {
102         return 1056;
103     }
104
105     @Override
106     public void readFrom(IDataBuffer data) {
107         this.manufacturerDescription = StringByteSerializer.readFrom(data, DESCRIPTION_STRING_LENGTH);
108         this.hardwareDescription = StringByteSerializer.readFrom(data, DESCRIPTION_STRING_LENGTH);
109         this.softwareDescription = StringByteSerializer.readFrom(data, DESCRIPTION_STRING_LENGTH);
110         this.serialNumber = StringByteSerializer.readFrom(data, SERIAL_NUMBER_LENGTH);
111         this.datapathDescription = StringByteSerializer.readFrom(data, DESCRIPTION_STRING_LENGTH);
112     }
113
114     @Override
115     public void writeTo(IDataBuffer data) {
116         StringByteSerializer.writeTo(data, DESCRIPTION_STRING_LENGTH, this.manufacturerDescription);
117         StringByteSerializer.writeTo(data, DESCRIPTION_STRING_LENGTH, this.hardwareDescription);
118         StringByteSerializer.writeTo(data, DESCRIPTION_STRING_LENGTH, this.softwareDescription);
119         StringByteSerializer.writeTo(data, SERIAL_NUMBER_LENGTH, this.serialNumber);
120         StringByteSerializer.writeTo(data, DESCRIPTION_STRING_LENGTH, this.datapathDescription);
121     }
122
123     @Override
124     public int hashCode() {
125         final int prime = 409;
126         int result = 1;
127         result = prime * result + ((datapathDescription == null) ? 0 : datapathDescription.hashCode());
128         result = prime * result + ((hardwareDescription == null) ? 0 : hardwareDescription.hashCode());
129         result = prime * result + ((manufacturerDescription == null) ? 0 : manufacturerDescription.hashCode());
130         result = prime * result + ((serialNumber == null) ? 0 : serialNumber.hashCode());
131         result = prime * result + ((softwareDescription == null) ? 0 : softwareDescription.hashCode());
132         return result;
133     }
134
135     @Override
136     public boolean equals(Object obj) {
137         if (this == obj) {
138             return true;
139         }
140         if (obj == null) {
141             return false;
142         }
143         if (!(obj instanceof OFPDescriptionStatistics)) {
144             return false;
145         }
146         OFPDescriptionStatistics other = (OFPDescriptionStatistics) obj;
147         if (datapathDescription == null) {
148             if (other.datapathDescription != null) {
149                 return false;
150             }
151         } else if (!datapathDescription.equals(other.datapathDescription)) {
152             return false;
153         }
154         if (hardwareDescription == null) {
155             if (other.hardwareDescription != null) {
156                 return false;
157             }
158         } else if (!hardwareDescription.equals(other.hardwareDescription)) {
159             return false;
160         }
161         if (manufacturerDescription == null) {
162             if (other.manufacturerDescription != null) {
163                 return false;
164             }
165         } else if (!manufacturerDescription.equals(other.manufacturerDescription)) {
166             return false;
167         }
168         if (serialNumber == null) {
169             if (other.serialNumber != null) {
170                 return false;
171             }
172         } else if (!serialNumber.equals(other.serialNumber)) {
173             return false;
174         }
175         if (softwareDescription == null) {
176             if (other.softwareDescription != null) {
177                 return false;
178             }
179         } else if (!softwareDescription.equals(other.softwareDescription)) {
180             return false;
181         }
182         return true;
183     }
184 }