Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | |
alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame] | 18 | |
| 19 | package org.onlab.packet; |
| 20 | |
| 21 | import java.util.Arrays; |
| 22 | |
| 23 | /** |
| 24 | * |
alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame] | 25 | */ |
| 26 | public class DHCPOption { |
| 27 | protected byte code; |
| 28 | protected byte length; |
| 29 | protected byte[] data; |
| 30 | |
| 31 | /** |
| 32 | * @return the code |
| 33 | */ |
| 34 | public byte getCode() { |
| 35 | return this.code; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @param code |
| 40 | * the code to set |
Yuta HIGUCHI | 2281b3f | 2014-11-04 00:20:48 -0800 | [diff] [blame] | 41 | * @return this |
alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame] | 42 | */ |
| 43 | public DHCPOption setCode(final byte code) { |
| 44 | this.code = code; |
| 45 | return this; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @return the length |
| 50 | */ |
| 51 | public byte getLength() { |
| 52 | return this.length; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @param length |
| 57 | * the length to set |
Yuta HIGUCHI | 2281b3f | 2014-11-04 00:20:48 -0800 | [diff] [blame] | 58 | * @return this |
alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame] | 59 | */ |
| 60 | public DHCPOption setLength(final byte length) { |
| 61 | this.length = length; |
| 62 | return this; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @return the data |
| 67 | */ |
| 68 | public byte[] getData() { |
| 69 | return this.data; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * @param data |
| 74 | * the data to set |
Yuta HIGUCHI | 2281b3f | 2014-11-04 00:20:48 -0800 | [diff] [blame] | 75 | * @return this |
alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame] | 76 | */ |
| 77 | public DHCPOption setData(final byte[] data) { |
| 78 | this.data = data; |
| 79 | return this; |
| 80 | } |
| 81 | |
| 82 | /* |
| 83 | * (non-Javadoc) |
| 84 | * |
| 85 | * @see java.lang.Object#hashCode() |
| 86 | */ |
| 87 | @Override |
| 88 | public int hashCode() { |
| 89 | final int prime = 31; |
| 90 | int result = 1; |
| 91 | result = prime * result + this.code; |
| 92 | result = prime * result + Arrays.hashCode(this.data); |
| 93 | result = prime * result + this.length; |
| 94 | return result; |
| 95 | } |
| 96 | |
| 97 | /* |
| 98 | * (non-Javadoc) |
| 99 | * |
| 100 | * @see java.lang.Object#equals(java.lang.Object) |
| 101 | */ |
| 102 | @Override |
| 103 | public boolean equals(final Object obj) { |
| 104 | if (this == obj) { |
| 105 | return true; |
| 106 | } |
| 107 | if (obj == null) { |
| 108 | return false; |
| 109 | } |
| 110 | if (!(obj instanceof DHCPOption)) { |
| 111 | return false; |
| 112 | } |
| 113 | final DHCPOption other = (DHCPOption) obj; |
| 114 | if (this.code != other.code) { |
| 115 | return false; |
| 116 | } |
| 117 | if (!Arrays.equals(this.data, other.data)) { |
| 118 | return false; |
| 119 | } |
| 120 | if (this.length != other.length) { |
| 121 | return false; |
| 122 | } |
| 123 | return true; |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * (non-Javadoc) |
| 128 | * |
| 129 | * @see java.lang.Object#toString() |
| 130 | */ |
| 131 | @Override |
| 132 | public String toString() { |
| 133 | return "DHCPOption [code=" + this.code + ", length=" + this.length |
| 134 | + ", data=" + Arrays.toString(this.data) + "]"; |
| 135 | } |
| 136 | } |