blob: 63e2741b47033844df8f0da357962ac12c5f3117 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
Ray Milkey269ffb92014-04-03 14:43:30 -07002 * Copyright 2011, Big Switch Networks, Inc.
3 * Originally created by David Erickson, Stanford 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 **/
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080017
Jonathan Hartdeda0ba2014-04-03 11:14:12 -070018package net.onrc.onos.core.packet;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080019
20import java.util.Arrays;
21
Pavlin Radoslavov1d595c02014-04-16 14:11:54 -070022import org.apache.commons.lang.ArrayUtils;
23
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080024/**
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080025 * @author David Erickson (daviderickson@cs.stanford.edu)
26 */
27public class DHCPOption {
28 protected byte code;
29 protected byte length;
30 protected byte[] data;
31
32 /**
33 * @return the code
34 */
35 public byte getCode() {
36 return code;
37 }
38
39 /**
40 * @param code the code to set
41 */
42 public DHCPOption setCode(byte code) {
43 this.code = code;
44 return this;
45 }
46
47 /**
48 * @return the length
49 */
50 public byte getLength() {
51 return length;
52 }
53
54 /**
55 * @param length the length to set
56 */
57 public DHCPOption setLength(byte length) {
58 this.length = length;
59 return this;
60 }
61
62 /**
63 * @return the data
64 */
65 public byte[] getData() {
Pavlin Radoslavov1d595c02014-04-16 14:11:54 -070066 return ArrayUtils.clone(this.data);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080067 }
68
69 /**
70 * @param data the data to set
71 */
72 public DHCPOption setData(byte[] data) {
Pavlin Radoslavov1d595c02014-04-16 14:11:54 -070073 this.data = ArrayUtils.clone(data);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080074 return this;
75 }
76
77 /* (non-Javadoc)
78 * @see java.lang.Object#hashCode()
79 */
80 @Override
81 public int hashCode() {
82 final int prime = 31;
83 int result = 1;
84 result = prime * result + code;
85 result = prime * result + Arrays.hashCode(data);
86 result = prime * result + length;
87 return result;
88 }
89
90 /* (non-Javadoc)
91 * @see java.lang.Object#equals(java.lang.Object)
92 */
93 @Override
94 public boolean equals(Object obj) {
Ray Milkeyb29e6262014-04-09 16:02:14 -070095 if (this == obj) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080096 return true;
Ray Milkeyb29e6262014-04-09 16:02:14 -070097 }
98 if (obj == null) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080099 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700100 }
101 if (!(obj instanceof DHCPOption)) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800102 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700103 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800104 DHCPOption other = (DHCPOption) obj;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700105 if (code != other.code) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800106 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700107 }
108 if (!Arrays.equals(data, other.data)) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800109 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700110 }
111 if (length != other.length) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800112 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700113 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800114 return true;
115 }
116
117 /* (non-Javadoc)
118 * @see java.lang.Object#toString()
119 */
120 @Override
121 public String toString() {
122 return "DHCPOption [code=" + code + ", length=" + length + ", data="
123 + Arrays.toString(data) + "]";
124 }
125}