Initial opendaylight infrastructure commit!!
[controller.git] / third-party / openflowj / src / main / java / org / openflow / protocol / OFEchoRequest.java
1 package org.openflow.protocol;
2
3 import java.nio.ByteBuffer;
4
5 import org.openflow.util.U16;
6
7 /**
8  * Represents an ofp_echo_request message
9  * 
10  * @author Rob Sherwood (rob.sherwood@stanford.edu)
11  */
12
13 public class OFEchoRequest extends OFMessage {
14     public static int MINIMUM_LENGTH = 8;
15     byte[] payload;
16
17     public OFEchoRequest() {
18         super();
19         this.type = OFType.ECHO_REQUEST;
20         this.length = U16.t(MINIMUM_LENGTH);
21     }
22
23     @Override
24     public void readFrom(ByteBuffer bb) {
25         super.readFrom(bb);
26         int datalen = this.getLengthU() - MINIMUM_LENGTH;
27         if (datalen > 0) {
28             this.payload = new byte[datalen];
29             bb.get(payload);
30         }
31     }
32
33     /**
34      * @return the payload
35      */
36     public byte[] getPayload() {
37         return payload;
38     }
39
40     /**
41      * @param payload
42      *            the payload to set
43      */
44     public void setPayload(byte[] payload) {
45         this.payload = payload;
46     }
47
48     @Override
49     public void writeTo(ByteBuffer bb) {
50         super.writeTo(bb);
51         if (payload != null)
52             bb.put(payload);
53     }
54 }