Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | /** |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 2 | * 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 Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 17 | |
Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 18 | package net.onrc.onos.core.packet; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 19 | |
| 20 | import java.util.Arrays; |
| 21 | |
Pavlin Radoslavov | 1d595c0 | 2014-04-16 14:11:54 -0700 | [diff] [blame] | 22 | import org.apache.commons.lang.ArrayUtils; |
| 23 | |
Yuta HIGUCHI | aa132f5 | 2014-06-26 10:18:39 -0700 | [diff] [blame] | 24 | // CHECKSTYLE IGNORE WriteTag FOR NEXT 2 LINES |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 25 | /** |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 26 | * @author David Erickson (daviderickson@cs.stanford.edu) |
| 27 | */ |
| 28 | public class DHCPOption { |
| 29 | protected byte code; |
| 30 | protected byte length; |
| 31 | protected byte[] data; |
| 32 | |
| 33 | /** |
| 34 | * @return the code |
| 35 | */ |
| 36 | public byte getCode() { |
| 37 | return code; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @param code the code to set |
| 42 | */ |
| 43 | public DHCPOption setCode(byte code) { |
| 44 | this.code = code; |
| 45 | return this; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @return the length |
| 50 | */ |
| 51 | public byte getLength() { |
| 52 | return length; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @param length the length to set |
| 57 | */ |
| 58 | public DHCPOption setLength(byte length) { |
| 59 | this.length = length; |
| 60 | return this; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @return the data |
| 65 | */ |
| 66 | public byte[] getData() { |
Pavlin Radoslavov | 1d595c0 | 2014-04-16 14:11:54 -0700 | [diff] [blame] | 67 | return ArrayUtils.clone(this.data); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @param data the data to set |
| 72 | */ |
| 73 | public DHCPOption setData(byte[] data) { |
Pavlin Radoslavov | 1d595c0 | 2014-04-16 14:11:54 -0700 | [diff] [blame] | 74 | this.data = ArrayUtils.clone(data); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 75 | return this; |
| 76 | } |
| 77 | |
| 78 | /* (non-Javadoc) |
| 79 | * @see java.lang.Object#hashCode() |
| 80 | */ |
| 81 | @Override |
| 82 | public int hashCode() { |
| 83 | final int prime = 31; |
| 84 | int result = 1; |
| 85 | result = prime * result + code; |
| 86 | result = prime * result + Arrays.hashCode(data); |
| 87 | result = prime * result + length; |
| 88 | return result; |
| 89 | } |
| 90 | |
| 91 | /* (non-Javadoc) |
| 92 | * @see java.lang.Object#equals(java.lang.Object) |
| 93 | */ |
| 94 | @Override |
| 95 | public boolean equals(Object obj) { |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 96 | if (this == obj) { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 97 | return true; |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 98 | } |
| 99 | if (obj == null) { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 100 | return false; |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 101 | } |
| 102 | if (!(obj instanceof DHCPOption)) { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 103 | return false; |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 104 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 105 | DHCPOption other = (DHCPOption) obj; |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 106 | if (code != other.code) { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 107 | return false; |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 108 | } |
| 109 | if (!Arrays.equals(data, other.data)) { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 110 | return false; |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 111 | } |
| 112 | if (length != other.length) { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 113 | return false; |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 114 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 115 | return true; |
| 116 | } |
| 117 | |
| 118 | /* (non-Javadoc) |
| 119 | * @see java.lang.Object#toString() |
| 120 | */ |
| 121 | @Override |
| 122 | public String toString() { |
| 123 | return "DHCPOption [code=" + code + ", length=" + length + ", data=" |
| 124 | + Arrays.toString(data) + "]"; |
| 125 | } |
| 126 | } |