blob: 295a3972e8a29d5ed928150d2076ac6d6e16fd52 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
2* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
3* 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**/
17
18package org.openflow.protocol;
19
20
21import java.util.Arrays;
22
23import org.jboss.netty.buffer.ChannelBuffer;
24import org.openflow.util.U16;
25
26/**
27 * Represents an ofp_echo_request message
28 *
29 * @author Rob Sherwood (rob.sherwood@stanford.edu)
30 */
31
32public class OFEchoRequest extends OFMessage {
33 public static int MINIMUM_LENGTH = 8;
34 byte[] payload;
35
36 public OFEchoRequest() {
37 super();
38 this.type = OFType.ECHO_REQUEST;
39 this.length = U16.t(MINIMUM_LENGTH);
40 }
41
42 @Override
43 public void readFrom(ChannelBuffer bb) {
44 super.readFrom(bb);
45 int datalen = this.getLengthU() - MINIMUM_LENGTH;
46 if (datalen > 0) {
47 this.payload = new byte[datalen];
48 bb.readBytes(payload);
49 }
50 }
51
52 /**
53 * @return the payload
54 */
55 public byte[] getPayload() {
56 return payload;
57 }
58
59 /**
60 * @param payload
61 * the payload to set
62 */
63 public void setPayload(byte[] payload) {
64 this.payload = payload;
65 }
66
67 @Override
68 public void writeTo(ChannelBuffer bb) {
69 super.writeTo(bb);
70 if (payload != null)
71 bb.writeBytes(payload);
72 }
73
74 /* (non-Javadoc)
75 * @see java.lang.Object#hashCode()
76 */
77 @Override
78 public int hashCode() {
79 final int prime = 31;
80 int result = super.hashCode();
81 result = prime * result + Arrays.hashCode(payload);
82 return result;
83 }
84
85 /* (non-Javadoc)
86 * @see java.lang.Object#equals(java.lang.Object)
87 */
88 @Override
89 public boolean equals(Object obj) {
90 if (this == obj)
91 return true;
92 if (!super.equals(obj))
93 return false;
94 if (getClass() != obj.getClass())
95 return false;
96 OFEchoRequest other = (OFEchoRequest) obj;
97 if (!Arrays.equals(payload, other.payload))
98 return false;
99 return true;
100 }
101}