blob: cedd670f0a28aa0cf2e7376a07cd745373e16a2a [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
alshabibc4901cd2014-09-05 16:50:40 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
alshabibc4901cd2014-09-05 16:50:40 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska24c849c2014-10-27 09:53:05 -070015 */
16
alshabibc4901cd2014-09-05 16:50:40 -070017package org.onlab.packet;
18
19import java.util.Arrays;
20
21/**
Jian Li5fc14292015-12-04 11:30:46 -080022 * Representation of DHCPOption field.
alshabibc4901cd2014-09-05 16:50:40 -070023 */
24public 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 Li5fc14292015-12-04 11:30:46 -080037 * @param code the code to set
Yuta HIGUCHI2281b3f2014-11-04 00:20:48 -080038 * @return this
alshabibc4901cd2014-09-05 16:50:40 -070039 */
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 Li5fc14292015-12-04 11:30:46 -080053 * @param length the length to set
Yuta HIGUCHI2281b3f2014-11-04 00:20:48 -080054 * @return this
alshabibc4901cd2014-09-05 16:50:40 -070055 */
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 Li5fc14292015-12-04 11:30:46 -080069 * @param data the data to set
Yuta HIGUCHI2281b3f2014-11-04 00:20:48 -080070 * @return this
alshabibc4901cd2014-09-05 16:50:40 -070071 */
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}