9be821f2ace4fb624a0a2314e0b997ec9d086f14
[controller.git] / third-party / openflowj_netty / src / main / java / org / openflow / vendor / openflow / OFOpenFlowVendorData.java
1 /**
2 *    Copyright 2012, Andrew Ferguson, Brown University
3 *
4 *    Licensed under the Apache License, Version 2.0 (the "License"); you may
5 *    not use this file except in compliance with the License. You may obtain
6 *    a copy of the License at
7 *
8 *         http://www.apache.org/licenses/LICENSE-2.0
9 *
10 *    Unless required by applicable law or agreed to in writing, software
11 *    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 *    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 *    License for the specific language governing permissions and limitations
14 *    under the License.
15 **/
16
17 package org.openflow.vendor.openflow;
18
19 import org.jboss.netty.buffer.ChannelBuffer;
20 import org.openflow.protocol.vendor.OFVendorData;
21
22 /**
23  * Base class for vendor data corresponding to extensions to OpenFlow 1.0.
24  * Based on org.openflow.vendor.nicira
25  *
26  * @author Andrew Ferguson (adf@cs.brown.edu)
27  */
28 public class OFOpenFlowVendorData implements OFVendorData {
29
30     public static final int OF_VENDOR_ID = 0x000026e1;
31
32     /**
33      * The value of the integer data type at the beginning of the vendor data
34      */
35     protected int dataType;
36
37     /**
38      * Construct empty (i.e. unspecified data type) OpenFlow vendor data.
39      */
40     public OFOpenFlowVendorData() {
41     }
42
43     /**
44      * Construct OpenFlow vendor data with the specified data type
45      * @param dataType the data type value at the beginning of the vendor data.
46      */
47     public OFOpenFlowVendorData(int dataType) {
48         this.dataType = dataType;
49     }
50
51     /**
52      * Get the data type value at the beginning of the vendor data
53      * @return the integer data type value
54      */
55     public int getDataType() {
56         return dataType;
57     }
58
59     /**
60      * Set the data type value
61      * @param dataType the integer data type value at the beginning of the
62      *     vendor data.
63      */
64     public void setDataType(int dataType) {
65         this.dataType = dataType;
66     }
67
68     /**
69      * Get the length of the vendor data. This implementation will normally
70      * be the superclass for another class that will override this to return
71      * the overall vendor data length. This implementation just returns the
72      * length of the part that includes the 4-byte integer data type value
73      * at the beginning of the vendor data.
74      */
75     @Override
76     public int getLength() {
77         return 4;
78     }
79
80     /**
81      * Read the vendor data from the ChannelBuffer
82      * @param data the channel buffer from which we're deserializing
83      * @param length the length to the end of the enclosing message
84      */
85     @Override
86     public void readFrom(ChannelBuffer data, int length) {
87         dataType = data.readInt();
88     }
89
90     /**
91      * Write the vendor data to the ChannelBuffer
92      * @param data the channel buffer to which we're serializing
93      */
94     @Override
95     public void writeTo(ChannelBuffer data) {
96         data.writeInt(dataType);
97     }
98 }