blob: a2e7a7949930c4fb372e90efee40a6cf5dd9e82b [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 Data extends BasePacket {
26 protected byte[] data;
27
28 /**
Ray Milkey269ffb92014-04-03 14:43:30 -070029 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080030 */
31 public Data() {
32 }
33
34 /**
35 * @param data
36 */
37 public Data(byte[] data) {
38 this.data = data;
39 }
40
41 /**
42 * @return the data
43 */
44 public byte[] getData() {
45 return data;
46 }
47
48 /**
49 * @param data the data to set
50 */
51 public Data setData(byte[] data) {
52 this.data = data;
53 return this;
54 }
55
56 public byte[] serialize() {
57 return this.data;
58 }
59
60 @Override
61 public IPacket deserialize(byte[] data, int offset, int length) {
62 this.data = Arrays.copyOfRange(data, offset, data.length);
63 return this;
64 }
65
66 /* (non-Javadoc)
67 * @see java.lang.Object#hashCode()
68 */
69 @Override
70 public int hashCode() {
71 final int prime = 1571;
72 int result = super.hashCode();
73 result = prime * result + Arrays.hashCode(data);
74 return result;
75 }
76
77 /* (non-Javadoc)
78 * @see java.lang.Object#equals(java.lang.Object)
79 */
80 @Override
81 public boolean equals(Object obj) {
Ray Milkeyb29e6262014-04-09 16:02:14 -070082 if (this == obj) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080083 return true;
Ray Milkeyb29e6262014-04-09 16:02:14 -070084 }
85 if (!super.equals(obj)) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080086 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -070087 }
88 if (!(obj instanceof Data)) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080089 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -070090 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080091 Data other = (Data) obj;
Ray Milkeyb29e6262014-04-09 16:02:14 -070092 if (!Arrays.equals(data, other.data)) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080093 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -070094 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080095 return true;
96 }
97}