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 | c9bacee | 2014-04-11 19:02:17 -0700 | [diff] [blame^] | 22 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
| 23 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 24 | /** |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 25 | * @author David Erickson (daviderickson@cs.stanford.edu) |
| 26 | */ |
| 27 | public 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 | */ |
Pavlin Radoslavov | c9bacee | 2014-04-11 19:02:17 -0700 | [diff] [blame^] | 65 | @SuppressFBWarnings(value = "EI_EXPOSE_REP", |
| 66 | justification = "TODO: Return a copy of the object?") |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 67 | public byte[] getData() { |
| 68 | return data; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @param data the data to set |
| 73 | */ |
Pavlin Radoslavov | c9bacee | 2014-04-11 19:02:17 -0700 | [diff] [blame^] | 74 | @SuppressFBWarnings(value = "EI_EXPOSE_REP2", |
| 75 | justification = "TODO: Store a copy of the object?") |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 76 | public DHCPOption setData(byte[] data) { |
| 77 | this.data = data; |
| 78 | return this; |
| 79 | } |
| 80 | |
| 81 | /* (non-Javadoc) |
| 82 | * @see java.lang.Object#hashCode() |
| 83 | */ |
| 84 | @Override |
| 85 | public int hashCode() { |
| 86 | final int prime = 31; |
| 87 | int result = 1; |
| 88 | result = prime * result + code; |
| 89 | result = prime * result + Arrays.hashCode(data); |
| 90 | result = prime * result + length; |
| 91 | return result; |
| 92 | } |
| 93 | |
| 94 | /* (non-Javadoc) |
| 95 | * @see java.lang.Object#equals(java.lang.Object) |
| 96 | */ |
| 97 | @Override |
| 98 | public boolean equals(Object obj) { |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 99 | if (this == obj) { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 100 | return true; |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 101 | } |
| 102 | if (obj == null) { |
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 | } |
| 105 | if (!(obj instanceof DHCPOption)) { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 106 | return false; |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 107 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 108 | DHCPOption other = (DHCPOption) obj; |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 109 | if (code != other.code) { |
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 (!Arrays.equals(data, other.data)) { |
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 | } |
| 115 | if (length != other.length) { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 116 | return false; |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 117 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 118 | return true; |
| 119 | } |
| 120 | |
| 121 | /* (non-Javadoc) |
| 122 | * @see java.lang.Object#toString() |
| 123 | */ |
| 124 | @Override |
| 125 | public String toString() { |
| 126 | return "DHCPOption [code=" + code + ", length=" + length + ", data=" |
| 127 | + Arrays.toString(data) + "]"; |
| 128 | } |
| 129 | } |