alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame^] | 1 | /******************************************************************************* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | ******************************************************************************/ |
| 16 | /** |
| 17 | * Copyright 2011, Big Switch Networks, Inc. |
| 18 | * Originally created by David Erickson, Stanford University |
| 19 | * |
| 20 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 21 | * not use this file except in compliance with the License. You may obtain |
| 22 | * a copy of the License at |
| 23 | * |
| 24 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 25 | * |
| 26 | * Unless required by applicable law or agreed to in writing, software |
| 27 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 28 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 29 | * License for the specific language governing permissions and limitations |
| 30 | * under the License. |
| 31 | **/ |
| 32 | |
| 33 | package org.onlab.packet; |
| 34 | |
| 35 | import java.util.Arrays; |
| 36 | |
| 37 | /** |
| 38 | * |
| 39 | * @author David Erickson (daviderickson@cs.stanford.edu) |
| 40 | */ |
| 41 | public class DHCPOption { |
| 42 | protected byte code; |
| 43 | protected byte length; |
| 44 | protected byte[] data; |
| 45 | |
| 46 | /** |
| 47 | * @return the code |
| 48 | */ |
| 49 | public byte getCode() { |
| 50 | return this.code; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * @param code |
| 55 | * the code to set |
| 56 | */ |
| 57 | public DHCPOption setCode(final byte code) { |
| 58 | this.code = code; |
| 59 | return this; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @return the length |
| 64 | */ |
| 65 | public byte getLength() { |
| 66 | return this.length; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * @param length |
| 71 | * the length to set |
| 72 | */ |
| 73 | public DHCPOption setLength(final byte length) { |
| 74 | this.length = length; |
| 75 | return this; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * @return the data |
| 80 | */ |
| 81 | public byte[] getData() { |
| 82 | return this.data; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @param data |
| 87 | * the data to set |
| 88 | */ |
| 89 | public DHCPOption setData(final byte[] data) { |
| 90 | this.data = data; |
| 91 | return this; |
| 92 | } |
| 93 | |
| 94 | /* |
| 95 | * (non-Javadoc) |
| 96 | * |
| 97 | * @see java.lang.Object#hashCode() |
| 98 | */ |
| 99 | @Override |
| 100 | public int hashCode() { |
| 101 | final int prime = 31; |
| 102 | int result = 1; |
| 103 | result = prime * result + this.code; |
| 104 | result = prime * result + Arrays.hashCode(this.data); |
| 105 | result = prime * result + this.length; |
| 106 | return result; |
| 107 | } |
| 108 | |
| 109 | /* |
| 110 | * (non-Javadoc) |
| 111 | * |
| 112 | * @see java.lang.Object#equals(java.lang.Object) |
| 113 | */ |
| 114 | @Override |
| 115 | public boolean equals(final Object obj) { |
| 116 | if (this == obj) { |
| 117 | return true; |
| 118 | } |
| 119 | if (obj == null) { |
| 120 | return false; |
| 121 | } |
| 122 | if (!(obj instanceof DHCPOption)) { |
| 123 | return false; |
| 124 | } |
| 125 | final DHCPOption other = (DHCPOption) obj; |
| 126 | if (this.code != other.code) { |
| 127 | return false; |
| 128 | } |
| 129 | if (!Arrays.equals(this.data, other.data)) { |
| 130 | return false; |
| 131 | } |
| 132 | if (this.length != other.length) { |
| 133 | return false; |
| 134 | } |
| 135 | return true; |
| 136 | } |
| 137 | |
| 138 | /* |
| 139 | * (non-Javadoc) |
| 140 | * |
| 141 | * @see java.lang.Object#toString() |
| 142 | */ |
| 143 | @Override |
| 144 | public String toString() { |
| 145 | return "DHCPOption [code=" + this.code + ", length=" + this.length |
| 146 | + ", data=" + Arrays.toString(this.data) + "]"; |
| 147 | } |
| 148 | } |