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