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 | |
| 22 | /** |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 23 | * @author David Erickson (daviderickson@cs.stanford.edu) |
| 24 | */ |
| 25 | public 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() { |
| 64 | return data; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * @param data the data to set |
| 69 | */ |
| 70 | public DHCPOption setData(byte[] data) { |
| 71 | this.data = data; |
| 72 | return this; |
| 73 | } |
| 74 | |
| 75 | /* (non-Javadoc) |
| 76 | * @see java.lang.Object#hashCode() |
| 77 | */ |
| 78 | @Override |
| 79 | public int hashCode() { |
| 80 | final int prime = 31; |
| 81 | int result = 1; |
| 82 | result = prime * result + code; |
| 83 | result = prime * result + Arrays.hashCode(data); |
| 84 | result = prime * result + length; |
| 85 | return result; |
| 86 | } |
| 87 | |
| 88 | /* (non-Javadoc) |
| 89 | * @see java.lang.Object#equals(java.lang.Object) |
| 90 | */ |
| 91 | @Override |
| 92 | public boolean equals(Object obj) { |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 93 | if (this == obj) { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 94 | return true; |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 95 | } |
| 96 | if (obj == null) { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 97 | return false; |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 98 | } |
| 99 | if (!(obj instanceof DHCPOption)) { |
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 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 102 | DHCPOption other = (DHCPOption) obj; |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 103 | if (code != other.code) { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 104 | return false; |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 105 | } |
| 106 | if (!Arrays.equals(data, other.data)) { |
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 (length != other.length) { |
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 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 112 | return true; |
| 113 | } |
| 114 | |
| 115 | /* (non-Javadoc) |
| 116 | * @see java.lang.Object#toString() |
| 117 | */ |
| 118 | @Override |
| 119 | public String toString() { |
| 120 | return "DHCPOption [code=" + code + ", length=" + length + ", data=" |
| 121 | + Arrays.toString(data) + "]"; |
| 122 | } |
| 123 | } |