Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior |
| 3 | * University |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | * not use this file except in compliance with the License. You may obtain |
| 7 | * a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | * License for the specific language governing permissions and limitations |
| 15 | * under the License. |
| 16 | **/ |
| 17 | |
| 18 | package org.openflow.protocol.statistics; |
| 19 | |
| 20 | |
| 21 | import org.jboss.netty.buffer.ChannelBuffer; |
| 22 | import org.openflow.util.StringByteSerializer; |
| 23 | |
| 24 | /** |
| 25 | * Represents an ofp_desc_stats structure |
| 26 | * @author David Erickson (daviderickson@cs.stanford.edu) |
| 27 | */ |
| 28 | public class OFDescriptionStatistics implements OFStatistics { |
| 29 | public static int DESCRIPTION_STRING_LENGTH = 256; |
| 30 | public static int SERIAL_NUMBER_LENGTH = 32; |
| 31 | |
| 32 | protected String manufacturerDescription; |
| 33 | protected String hardwareDescription; |
| 34 | protected String softwareDescription; |
| 35 | protected String serialNumber; |
| 36 | protected String datapathDescription; |
| 37 | |
| 38 | /** |
| 39 | * @return the manufacturerDescription |
| 40 | */ |
| 41 | public String getManufacturerDescription() { |
| 42 | return manufacturerDescription; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @param manufacturerDescription the manufacturerDescription to set |
| 47 | */ |
| 48 | public void setManufacturerDescription(String manufacturerDescription) { |
| 49 | this.manufacturerDescription = manufacturerDescription; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @return the hardwareDescription |
| 54 | */ |
| 55 | public String getHardwareDescription() { |
| 56 | return hardwareDescription; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @param hardwareDescription the hardwareDescription to set |
| 61 | */ |
| 62 | public void setHardwareDescription(String hardwareDescription) { |
| 63 | this.hardwareDescription = hardwareDescription; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @return the softwareDescription |
| 68 | */ |
| 69 | public String getSoftwareDescription() { |
| 70 | return softwareDescription; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * @param softwareDescription the softwareDescription to set |
| 75 | */ |
| 76 | public void setSoftwareDescription(String softwareDescription) { |
| 77 | this.softwareDescription = softwareDescription; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * @return the serialNumber |
| 82 | */ |
| 83 | public String getSerialNumber() { |
| 84 | return serialNumber; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * @param serialNumber the serialNumber to set |
| 89 | */ |
| 90 | public void setSerialNumber(String serialNumber) { |
| 91 | this.serialNumber = serialNumber; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * @return the datapathDescription |
| 96 | */ |
| 97 | public String getDatapathDescription() { |
| 98 | return datapathDescription; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * @param datapathDescription the datapathDescription to set |
| 103 | */ |
| 104 | public void setDatapathDescription(String datapathDescription) { |
| 105 | this.datapathDescription = datapathDescription; |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public int getLength() { |
| 110 | return 1056; |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public void readFrom(ChannelBuffer data) { |
| 115 | this.manufacturerDescription = StringByteSerializer.readFrom(data, |
| 116 | DESCRIPTION_STRING_LENGTH); |
| 117 | this.hardwareDescription = StringByteSerializer.readFrom(data, |
| 118 | DESCRIPTION_STRING_LENGTH); |
| 119 | this.softwareDescription = StringByteSerializer.readFrom(data, |
| 120 | DESCRIPTION_STRING_LENGTH); |
| 121 | this.serialNumber = StringByteSerializer.readFrom(data, |
| 122 | SERIAL_NUMBER_LENGTH); |
| 123 | this.datapathDescription = StringByteSerializer.readFrom(data, |
| 124 | DESCRIPTION_STRING_LENGTH); |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public void writeTo(ChannelBuffer data) { |
| 129 | StringByteSerializer.writeTo(data, DESCRIPTION_STRING_LENGTH, |
| 130 | this.manufacturerDescription); |
| 131 | StringByteSerializer.writeTo(data, DESCRIPTION_STRING_LENGTH, |
| 132 | this.hardwareDescription); |
| 133 | StringByteSerializer.writeTo(data, DESCRIPTION_STRING_LENGTH, |
| 134 | this.softwareDescription); |
| 135 | StringByteSerializer.writeTo(data, SERIAL_NUMBER_LENGTH, |
| 136 | this.serialNumber); |
| 137 | StringByteSerializer.writeTo(data, DESCRIPTION_STRING_LENGTH, |
| 138 | this.datapathDescription); |
| 139 | } |
| 140 | |
| 141 | @Override |
| 142 | public int hashCode() { |
| 143 | final int prime = 409; |
| 144 | int result = 1; |
| 145 | result = prime |
| 146 | * result |
| 147 | + ((datapathDescription == null) ? 0 : datapathDescription |
| 148 | .hashCode()); |
| 149 | result = prime |
| 150 | * result |
| 151 | + ((hardwareDescription == null) ? 0 : hardwareDescription |
| 152 | .hashCode()); |
| 153 | result = prime |
| 154 | * result |
| 155 | + ((manufacturerDescription == null) ? 0 |
| 156 | : manufacturerDescription.hashCode()); |
| 157 | result = prime * result |
| 158 | + ((serialNumber == null) ? 0 : serialNumber.hashCode()); |
| 159 | result = prime |
| 160 | * result |
| 161 | + ((softwareDescription == null) ? 0 : softwareDescription |
| 162 | .hashCode()); |
| 163 | return result; |
| 164 | } |
| 165 | |
| 166 | @Override |
| 167 | public boolean equals(Object obj) { |
| 168 | if (this == obj) { |
| 169 | return true; |
| 170 | } |
| 171 | if (obj == null) { |
| 172 | return false; |
| 173 | } |
| 174 | if (!(obj instanceof OFDescriptionStatistics)) { |
| 175 | return false; |
| 176 | } |
| 177 | OFDescriptionStatistics other = (OFDescriptionStatistics) obj; |
| 178 | if (datapathDescription == null) { |
| 179 | if (other.datapathDescription != null) { |
| 180 | return false; |
| 181 | } |
| 182 | } else if (!datapathDescription.equals(other.datapathDescription)) { |
| 183 | return false; |
| 184 | } |
| 185 | if (hardwareDescription == null) { |
| 186 | if (other.hardwareDescription != null) { |
| 187 | return false; |
| 188 | } |
| 189 | } else if (!hardwareDescription.equals(other.hardwareDescription)) { |
| 190 | return false; |
| 191 | } |
| 192 | if (manufacturerDescription == null) { |
| 193 | if (other.manufacturerDescription != null) { |
| 194 | return false; |
| 195 | } |
| 196 | } else if (!manufacturerDescription |
| 197 | .equals(other.manufacturerDescription)) { |
| 198 | return false; |
| 199 | } |
| 200 | if (serialNumber == null) { |
| 201 | if (other.serialNumber != null) { |
| 202 | return false; |
| 203 | } |
| 204 | } else if (!serialNumber.equals(other.serialNumber)) { |
| 205 | return false; |
| 206 | } |
| 207 | if (softwareDescription == null) { |
| 208 | if (other.softwareDescription != null) { |
| 209 | return false; |
| 210 | } |
| 211 | } else if (!softwareDescription.equals(other.softwareDescription)) { |
| 212 | return false; |
| 213 | } |
| 214 | return true; |
| 215 | } |
| 216 | } |