blob: d24541e30be0fdbce839710e9525ecd4ffa4bfed [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
22/**
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080023 * @author David Erickson (daviderickson@cs.stanford.edu)
24 */
25public class DHCPOption {
26 protected byte code;
27 protected byte length;
28 protected byte[] data;
29
30 /**
31 * @return the code
32 */
33 public byte getCode() {
34 return code;
35 }
36
37 /**
38 * @param code the code to set
39 */
40 public DHCPOption setCode(byte code) {
41 this.code = code;
42 return this;
43 }
44
45 /**
46 * @return the length
47 */
48 public byte getLength() {
49 return length;
50 }
51
52 /**
53 * @param length the length to set
54 */
55 public DHCPOption setLength(byte length) {
56 this.length = length;
57 return this;
58 }
59
60 /**
61 * @return the data
62 */
63 public byte[] getData() {
Pavlin Radoslavov0a9d5c32014-04-15 17:45:23 -070064 if (this.data == null) {
65 return null;
66 }
67 return this.data.clone();
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080068 }
69
70 /**
71 * @param data the data to set
72 */
73 public DHCPOption setData(byte[] data) {
Pavlin Radoslavov0a9d5c32014-04-15 17:45:23 -070074 if (data == null) {
75 this.data = null;
76 } else {
77 this.data = data.clone();
78 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080079 return this;
80 }
81
82 /* (non-Javadoc)
83 * @see java.lang.Object#hashCode()
84 */
85 @Override
86 public int hashCode() {
87 final int prime = 31;
88 int result = 1;
89 result = prime * result + code;
90 result = prime * result + Arrays.hashCode(data);
91 result = prime * result + length;
92 return result;
93 }
94
95 /* (non-Javadoc)
96 * @see java.lang.Object#equals(java.lang.Object)
97 */
98 @Override
99 public boolean equals(Object obj) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700100 if (this == obj) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800101 return true;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700102 }
103 if (obj == null) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800104 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700105 }
106 if (!(obj instanceof DHCPOption)) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800107 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700108 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800109 DHCPOption other = (DHCPOption) obj;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700110 if (code != other.code) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800111 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700112 }
113 if (!Arrays.equals(data, other.data)) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800114 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700115 }
116 if (length != other.length) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800117 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700118 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800119 return true;
120 }
121
122 /* (non-Javadoc)
123 * @see java.lang.Object#toString()
124 */
125 @Override
126 public String toString() {
127 return "DHCPOption [code=" + code + ", length=" + length + ", data="
128 + Arrays.toString(data) + "]";
129 }
130}