blob: df742315297f9d962f32727f78d38f418243196b [file] [log] [blame]
Rich Lanea06d0c32013-03-25 08:52:03 -07001:: # Copyright 2013, Big Switch Networks, Inc.
2:: #
3:: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
4:: # the following special exception:
5:: #
6:: # LOXI Exception
7:: #
8:: # As a special exception to the terms of the EPL, you may distribute libraries
9:: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
10:: # that copyright and licensing notices generated by LoxiGen are not altered or removed
11:: # from the LoxiGen Libraries and the notice provided below is (i) included in
12:: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any
13:: # documentation for the LoxiGen Libraries, if distributed in binary form.
14:: #
15:: # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
16:: #
17:: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
18:: # a copy of the EPL at:
19:: #
20:: # http://www.eclipse.org/legal/epl-v10.html
21:: #
22:: # Unless required by applicable law or agreed to in writing, software
23:: # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24:: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
25:: # EPL for the specific language governing permissions and limitations
26:: # under the EPL.
27::
Rich Laned983aa52013-06-13 11:48:37 -070028:: include('_copyright.c')
Rich Lanea06d0c32013-03-25 08:52:03 -070029
30/*
31 * These routines manipulate a low level buffer assuming it holds
32 * an OpenFlow message.
33 */
34
35#if !defined(_OF_MESSAGE_H_)
36#define _OF_MESSAGE_H_
37
38#include <loci/of_buffer.h>
39
40typedef uint8_t *of_message_t;
41
42/* A few key common header offsets */
43#define OF_MESSAGE_VERSION_OFFSET 0
44#define OF_MESSAGE_TYPE_OFFSET 1
45#define OF_MESSAGE_LENGTH_OFFSET 2
46#define OF_MESSAGE_XID_OFFSET 4
47#define OF_MESSAGE_HEADER_LENGTH 8
Rob Vaterlausb3f49d92013-10-01 17:57:31 -070048#define OF_MESSAGE_ERROR_TYPE_OFFSET 8
Rich Lanea06d0c32013-03-25 08:52:03 -070049#define OF_MESSAGE_STATS_TYPE_OFFSET 8
50#define OF_MESSAGE_FLOW_MOD_COMMAND_OFFSET(version) ((version) == 1 ? 56 : 25)
Rich Lanee3113672013-12-06 17:09:57 -080051#define OF_MESSAGE_GROUP_MOD_COMMAND_OFFSET 8
Rich Lanea06d0c32013-03-25 08:52:03 -070052
53#define OF_MESSAGE_MIN_LENGTH 8
54#define OF_MESSAGE_MIN_STATS_LENGTH (OF_MESSAGE_STATS_TYPE_OFFSET + 2)
Rob Vaterlausb3f49d92013-10-01 17:57:31 -070055#define OF_MESSAGE_MIN_ERROR_LENGTH (OF_MESSAGE_ERROR_TYPE_OFFSET + 4)
Rich Lanea06d0c32013-03-25 08:52:03 -070056#define OF_MESSAGE_MIN_FLOW_MOD_LENGTH(version) ((version) == 1 ? 57 : 26)
Rich Lanee3113672013-12-06 17:09:57 -080057#define OF_MESSAGE_MIN_GROUP_MOD_LENGTH (OF_MESSAGE_GROUP_MOD_COMMAND_OFFSET + 2)
Rich Lanea06d0c32013-03-25 08:52:03 -070058
59#define OF_MESSAGE_EXPERIMENTER_ID_OFFSET 8
60#define OF_MESSAGE_EXPERIMENTER_SUBTYPE_OFFSET 12
61#define OF_MESSAGE_EXPERIMENTER_MIN_LENGTH 16
62
Rich Lane353a79f2013-11-13 10:39:56 -080063#define OF_MESSAGE_STATS_EXPERIMENTER_ID_OFFSET 16
64#define OF_MESSAGE_STATS_EXPERIMENTER_SUBTYPE_OFFSET 20
65#define OF_MESSAGE_STATS_EXPERIMENTER_MIN_LENGTH 24
66
Rich Lanea06d0c32013-03-25 08:52:03 -070067/**
68 * The "default" free message function; NULL means use nominal malloc/free
69 */
70#define OF_MESSAGE_FREE_FUNCTION NULL
71
72/**
73 * Map a message to the uint8_t * start of the message
74 */
75#define OF_MESSAGE_TO_BUFFER(msg) ((uint8_t *)(msg))
76
77/**
78 * Map a uint8_t * to a message object
79 */
80#define OF_BUFFER_TO_MESSAGE(buf) ((of_message_t)(buf))
81
82/****************************************************************
83 *
84 * Message field accessors.
85 *
86 * These do no range checking and assume a buffer with sufficient
87 * length to access the data. These are low level accessors used
88 * during the parsing and coersion stage of message processing.
89 *
90 * Fields include: version, message type, message length,
91 * transaction id, stats type (now multi-part type), experimenter id,
92 * experimenter type
93 *
94 ****************************************************************/
95
96/**
97 * @brief Get/set version of a message
98 * @param msg Pointer to the message buffer of sufficient length
99 * @param version Data for set operation
100 * @returns get returns version
101 */
102
103static inline of_version_t
104of_message_version_get(of_message_t msg) {
105 return (of_version_t)msg[OF_MESSAGE_VERSION_OFFSET];
106}
107
Rich Lanea06d0c32013-03-25 08:52:03 -0700108/**
109 * @brief Get/set OpenFlow type of a message
110 * @param msg Pointer to the message buffer of sufficient length
111 * @param value Data for set operation
112 * @returns get returns message type
113 */
114
115static inline uint8_t
116of_message_type_get(of_message_t msg) {
117 return msg[OF_MESSAGE_TYPE_OFFSET];
118}
119
Rich Lanea06d0c32013-03-25 08:52:03 -0700120/**
121 * @brief Get/set in-buffer length of a message
122 * @param msg Pointer to the message buffer of sufficient length
123 * @param len Data for set operation
124 * @returns get returns length in host order
125 */
126
127static inline uint16_t
128of_message_length_get(of_message_t msg) {
129 uint16_t val;
130 buf_u16_get(msg + OF_MESSAGE_LENGTH_OFFSET, &val);
131 return val;
132}
133
134static inline void
135of_message_length_set(of_message_t msg, uint16_t len) {
136 buf_u16_set(msg + OF_MESSAGE_LENGTH_OFFSET, len);
137}
138
139
140/**
141 * @brief Get/set transaction ID of a message
142 * @param msg Pointer to the message buffer of sufficient length
143 * @param xid Data for set operation
144 * @returns get returns xid in host order
145 */
146
147static inline uint32_t
148of_message_xid_get(of_message_t msg) {
149 uint32_t val;
150 buf_u32_get(msg + OF_MESSAGE_XID_OFFSET, &val);
151 return val;
152}
153
Rich Lanea06d0c32013-03-25 08:52:03 -0700154/**
155 * @brief Get/set stats type of a message
156 * @param msg Pointer to the message buffer of sufficient length
157 * @param type Data for set operation
158 * @returns get returns stats type in host order
159 */
160
161static inline uint16_t
162of_message_stats_type_get(of_message_t msg) {
163 uint16_t val;
164 buf_u16_get(msg + OF_MESSAGE_STATS_TYPE_OFFSET, &val);
165 return val;
166}
167
Rob Vaterlausb3f49d92013-10-01 17:57:31 -0700168/**
169 * @brief Get/set error type of a message
170 * @param msg Pointer to the message buffer of sufficient length
171 * @param type Data for set operation
172 * @returns get returns error type in host order
173 */
174
175static inline uint16_t
176of_message_error_type_get(of_message_t msg) {
177 uint16_t val;
178 buf_u16_get(msg + OF_MESSAGE_ERROR_TYPE_OFFSET, &val);
179 return val;
180}
181
Rich Lanea06d0c32013-03-25 08:52:03 -0700182
183/**
184 * @brief Get/set experimenter ID of a message
185 * @param msg Pointer to the message buffer of sufficient length
186 * @param experimenter_id Data for set operation
187 * @returns get returns experimenter id in host order
188 */
189
190static inline uint32_t
191of_message_experimenter_id_get(of_message_t msg) {
192 uint32_t val;
193 buf_u32_get(msg + OF_MESSAGE_EXPERIMENTER_ID_OFFSET, &val);
194 return val;
195}
196
Rich Lanea06d0c32013-03-25 08:52:03 -0700197
198/**
199 * @brief Get/set experimenter message type (subtype) of a message
200 * @param msg Pointer to the message buffer of sufficient length
201 * @param subtype Data for set operation
202 * @returns get returns experimenter message type in host order
203 */
204
205static inline uint32_t
206of_message_experimenter_subtype_get(of_message_t msg) {
207 uint32_t val;
208 buf_u32_get(msg + OF_MESSAGE_EXPERIMENTER_SUBTYPE_OFFSET, &val);
209 return val;
210}
211
Rich Lanea06d0c32013-03-25 08:52:03 -0700212/**
213 * Flow mod command changed from 16 to 8 bits on the wire from 1.0 to 1.1
214 */
215static inline uint8_t
216of_message_flow_mod_command_get(of_message_t msg, of_version_t version) {
217 uint16_t val16;
218 uint8_t val8;
219
220 if (version == OF_VERSION_1_0) {
221 buf_u16_get(msg + OF_MESSAGE_FLOW_MOD_COMMAND_OFFSET(version), &val16);
222 val8 = val16;
223 } else {
224 buf_u8_get(msg + OF_MESSAGE_FLOW_MOD_COMMAND_OFFSET(version), &val8);
225 }
226 return val8;
227}
228
Rich Lane353a79f2013-11-13 10:39:56 -0800229/**
230 * @brief Get/set stats request/reply experimenter ID of a message
231 * @param msg Pointer to the message buffer of sufficient length
232 * @param experimenter_id Data for set operation
233 * @returns get returns experimenter id in host order
234 */
235
236static inline uint32_t
237of_message_stats_experimenter_id_get(of_message_t msg) {
238 uint32_t val;
239 buf_u32_get(msg + OF_MESSAGE_STATS_EXPERIMENTER_ID_OFFSET, &val);
240 return val;
241}
242
Rich Lane353a79f2013-11-13 10:39:56 -0800243/**
244 * @brief Get/set stats request/reply experimenter subtype of a message
245 * @param msg Pointer to the message buffer of sufficient length
246 * @param subtype Data for set operation
247 * @returns get returns experimenter subtype in host order
248 */
249
250static inline uint32_t
251of_message_stats_experimenter_subtype_get(of_message_t msg) {
252 uint32_t val;
253 buf_u32_get(msg + OF_MESSAGE_STATS_EXPERIMENTER_SUBTYPE_OFFSET, &val);
254 return val;
255}
256
Rich Lanee3113672013-12-06 17:09:57 -0800257/**
258 * @brief Get/set group mod command of a message
259 * @param msg Pointer to the message buffer of sufficient length
260 * @param subtype Data for set operation
261 * @returns get returns command in host order
262 */
263
264static inline uint16_t
265of_message_group_mod_command_get(of_message_t msg) {
266 uint16_t val;
267 buf_u16_get(msg + OF_MESSAGE_GROUP_MOD_COMMAND_OFFSET, &val);
268 return val;
269}
270
Rich Lanea06d0c32013-03-25 08:52:03 -0700271#endif /* _OF_MESSAGE_H_ */