blob: 687d5449f2dfdce8a4200f4c70c0f28ac72b67fe [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
2* Copyright 2011, Big Switch Networks, Inc.
3* Originally created by David Erickson & Rob Sherwood, 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**/
17
18package org.openflow.vendor.nicira;
19
20import org.jboss.netty.buffer.ChannelBuffer;
21import org.openflow.protocol.vendor.OFVendorData;
22
23/**
24 * Base class for vendor data corresponding to a Nicira vendor extension.
25 * Nicira vendor data always starts with a 4-byte integer data type value.
26 *
27 * @author Rob Vaterlaus (rob.vaterlaus@bigswitch.com)
28 */
29public class OFNiciraVendorData implements OFVendorData {
30
31 public static final int NX_VENDOR_ID = 0x00002320;
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) Nicira vendor data.
39 */
40 public OFNiciraVendorData() {
41 }
42
43 /**
44 * Contruct Nicira vendor data with the specified data type
45 * @param dataType the data type value at the beginning of the vendor data.
46 */
47 public OFNiciraVendorData(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}