blob: eb1c9232b9d04b20136bec9812b655c8a3a60fef [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 Lanea407b912013-12-15 11:53:35 -080029:: import c_gen.of_g_legacy as of_g
30:: flow_mod = of_g.base_length[("of_flow_modify",of_g.VERSION_1_2)]
31:: packet_in = of_g.base_length[("of_packet_in",of_g.VERSION_1_2)]
32:: packet_in_1_3 = of_g.base_length[("of_packet_in",of_g.VERSION_1_3)]
Rich Lane2dd17012014-10-16 09:55:10 -070033:: packet_in_1_4 = of_g.base_length[("of_packet_in",of_g.VERSION_1_4)]
34:: assert packet_in_1_3 == packet_in_1_4
Rich Lanea407b912013-12-15 11:53:35 -080035:: flow_stats = of_g.base_length[("of_flow_stats_entry", of_g.VERSION_1_2)]
36:: match1 = of_g.base_length[("of_match_v1",of_g.VERSION_1_0)]
37:: match2 = of_g.base_length[("of_match_v2",of_g.VERSION_1_1)]
Rich Lanea06d0c32013-03-25 08:52:03 -070038
39/******************************************************************************
40 *
41 * /module/src/loci_int.h
42 *
43 * loci Internal Header
44 *
45 *****************************************************************************/
46#ifndef __LOCI_INT_H__
47#define __LOCI_INT_H__
48
Rich Lanec3662bb2013-12-15 15:14:13 -080049#include <loci/loci.h>
50
Rich Laneddcbca72014-03-24 09:17:44 -070051#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
Rich Lane22811f52013-12-15 15:28:03 -080052#define UNREACHABLE() __builtin_unreachable()
53#else
54#define UNREACHABLE()
55#endif
56
Rich Lanea407b912013-12-15 11:53:35 -080057/****************************************************************
58 * Special case macros for calculating variable lengths and offsets
59 ****************************************************************/
Rich Lanea06d0c32013-03-25 08:52:03 -070060
Rich Lanea407b912013-12-15 11:53:35 -080061/**
62 * Get a u16 directly from an offset in an object's wire buffer
63 * @param obj An of_object_t object
64 * @param offset Base offset of the uint16 relative to the object
65 *
66 */
67
68static inline int
69of_object_u16_get(of_object_t *obj, int offset) {
70 uint16_t val16;
71
Rich Lanecdd542d2014-04-03 16:13:12 -070072 of_wire_buffer_u16_get(obj->wbuf,
73 obj->obj_offset + offset, &val16);
Rich Lanea407b912013-12-15 11:53:35 -080074
75 return (int)val16;
76}
77
78/**
79 * Set a u16 directly at an offset in an object's wire buffer
80 * @param obj An of_object_t object
81 * @param offset Base offset of the uint16 relative to the object
82 * @param val The value to store
83 *
84 */
85
86static inline void
87of_object_u16_set(of_object_t *obj, int offset, int value) {
88 uint16_t val16;
89
90 val16 = (uint16_t)value;
Rich Lanecdd542d2014-04-03 16:13:12 -070091 of_wire_buffer_u16_set(obj->wbuf,
92 obj->obj_offset + offset, val16);
Rich Lanea407b912013-12-15 11:53:35 -080093}
94
95/**
96 * Get length of an object with a TLV header with uint16_t
97 * @param obj An object with a match member
98 * @param offset The wire offset of the start of the object
99 *
100 * The length field follows the type field.
101 */
102
103#define _TLV16_LEN(obj, offset) \
104 (of_object_u16_get((of_object_t *)(obj), (offset) + 2))
105
106/**
107 * Get length of an object that is the "rest" of the object
108 * @param obj An object with a match member
109 * @param offset The wire offset of the start of the object
110 *
111 */
112
113#define _END_LEN(obj, offset) ((obj)->length - (offset))
114
115/**
116 * Offset of the action_len member in a packet-out object
117 */
118
119#define _PACKET_OUT_ACTION_LEN_OFFSET(obj) \
120 (((obj)->version == OF_VERSION_1_0) ? 14 : 16)
121
122/**
123 * Get length of the action list object in a packet_out object
124 * @param obj An object of type of_packet_out
125 */
126
127#define _PACKET_OUT_ACTION_LEN(obj) \
128 (of_object_u16_get((of_object_t *)(obj), _PACKET_OUT_ACTION_LEN_OFFSET(obj)))
129
130/**
131 * Set length of the action list object in a packet_out object
132 * @param obj An object of type of_packet_out
133 */
134
135#define _PACKET_OUT_ACTION_LEN_SET(obj, len) \
136 (of_object_u16_set((of_object_t *)(obj), _PACKET_OUT_ACTION_LEN_OFFSET(obj), len))
137
138/*
139 * Match structs in 1.2 come at the end of the fixed length part
140 * of structures. They add 8 bytes to the minimal length of the
141 * message, but are also variable length. This means that the
142 * type/length offsets are 8 bytes back from the end of the fixed
143 * length part of the object. The right way to handle this is to
144 * expose the offset of the match member more explicitly. For now,
145 * we make the calculation as described here.
146 */
147
148/* 1.2 min length of match is 8 bytes */
149#define _MATCH_MIN_LENGTH_V3 8
150
151/**
152 * The offset of a 1.2 match object relative to fixed length of obj
153 */
154#define _MATCH_OFFSET_V3(fixed_obj_len) \
155 ((fixed_obj_len) - _MATCH_MIN_LENGTH_V3)
156
157/**
158 * The "extra" length beyond the minimal 8 bytes of a match struct
159 * in an object
160 */
161#define _MATCH_EXTRA_LENGTH_V3(obj, fixed_obj_len) \
162 (OF_MATCH_BYTES(_TLV16_LEN(obj, _MATCH_OFFSET_V3(fixed_obj_len))) - \
163 _MATCH_MIN_LENGTH_V3)
164
165/**
166 * The offset of an object following a match object for 1.2
167 */
168#define _OFFSET_FOLLOWING_MATCH_V3(obj, fixed_obj_len) \
169 ((fixed_obj_len) + _MATCH_EXTRA_LENGTH_V3(obj, fixed_obj_len))
170
171/**
172 * Get length of a match object from its wire representation
173 * @param obj An object with a match member
174 * @param match_offset The wire offset of the match object.
175 *
176 * See above; for 1.2,
177 * The match length is raw bytes but the actual space it takes
178 * up is padded for alignment to 64-bits
179 */
180#define _WIRE_MATCH_LEN(obj, match_offset) \
181 (((obj)->version == OF_VERSION_1_0) ? ${match1} : \
182 (((obj)->version == OF_VERSION_1_1) ? ${match2} : \
183 _TLV16_LEN(obj, match_offset)))
184
185#define _WIRE_LEN_MIN 4
186
187/*
188 * Wrapper function for match len. There are cases where the wire buffer
189 * has not been set with the proper minimum length. In this case, the
190 * wire match len is interpretted as its minimum length, 4 bytes.
191 */
192
193static inline int
194wire_match_len(of_object_t *obj, int match_offset) {
195 int len;
196
197 len = _WIRE_MATCH_LEN(obj, match_offset);
198
199 return (len == 0) ? _WIRE_LEN_MIN : len;
200}
201
202#define _WIRE_MATCH_PADDED_LEN(obj, match_offset) \
203 OF_MATCH_BYTES(wire_match_len((of_object_t *)(obj), (match_offset)))
204
205/**
206 * Macro to calculate variable offset of instructions member in flow mod
207 * @param obj An object of some type of flow modify/add/delete
208 *
209 * Get length of preceding match object and add to fixed length
210 * Applies only to version 1.2
211 */
212
213#define _FLOW_MOD_INSTRUCTIONS_OFFSET(obj) \
214 _OFFSET_FOLLOWING_MATCH_V3(obj, ${flow_mod})
215
216/* The different flavors of flow mod all use the above */
217#define _FLOW_ADD_INSTRUCTIONS_OFFSET(obj) \
218 _FLOW_MOD_INSTRUCTIONS_OFFSET(obj)
219#define _FLOW_MODIFY_INSTRUCTIONS_OFFSET(obj) \
220 _FLOW_MOD_INSTRUCTIONS_OFFSET(obj)
221#define _FLOW_MODIFY_STRICT_INSTRUCTIONS_OFFSET(obj) \
222 _FLOW_MOD_INSTRUCTIONS_OFFSET(obj)
223#define _FLOW_DELETE_INSTRUCTIONS_OFFSET(obj) \
224 _FLOW_MOD_INSTRUCTIONS_OFFSET(obj)
225#define _FLOW_DELETE_STRICT_INSTRUCTIONS_OFFSET(obj) \
226 _FLOW_MOD_INSTRUCTIONS_OFFSET(obj)
227
228/**
229 * Macro to calculate variable offset of instructions member in flow stats
230 * @param obj An object of type of_flow_mod_t
231 *
232 * Get length of preceding match object and add to fixed length
233 * Applies only to version 1.2 and 1.3
234 */
235
236#define _FLOW_STATS_ENTRY_INSTRUCTIONS_OFFSET(obj) \
237 _OFFSET_FOLLOWING_MATCH_V3(obj, ${flow_stats})
238
239/**
240 * Macro to calculate variable offset of data (packet) member in packet_in
241 * @param obj An object of type of_packet_in_t
242 *
243 * Get length of preceding match object and add to fixed length
Rich Lanecd6c1d62014-10-16 14:29:46 -0700244 * Applies only to version 1.2+
245 * There are 2 bytes of padding between the match and data. The
246 * _OFFSET_FOLLOWING_MATCH_V3 macro assumes the match is at the end of the
247 * fixed length, so we need to subtract 2 from the fixed length we pass and
248 * then add 2 to the resulting offset.
Rich Lanea407b912013-12-15 11:53:35 -0800249 */
250
251#define _PACKET_IN_DATA_OFFSET(obj) \
252 (_OFFSET_FOLLOWING_MATCH_V3((obj), (obj)->version == OF_VERSION_1_2 ? \
Rich Lanecd6c1d62014-10-16 14:29:46 -0700253(${packet_in} - 2) : (${packet_in_1_3} - 2)) + 2)
Rich Lanea407b912013-12-15 11:53:35 -0800254
255/**
256 * Macro to calculate variable offset of data (packet) member in packet_out
257 * @param obj An object of type of_packet_out_t
258 *
259 * Find the length in the actions_len variable and add to the fixed len
260 * Applies only to version 1.2 and 1.3
261 */
262
263#define _PACKET_OUT_DATA_OFFSET(obj) (_PACKET_OUT_ACTION_LEN(obj) + \
264 of_object_fixed_len[(obj)->version][OF_PACKET_OUT])
265
266/**
267 * Macro to map port numbers that changed across versions
268 * @param port The port_no_t variable holding the value
269 * @param ver The OpenFlow version from which the value was extracted
270 */
271#define OF_PORT_NO_VALUE_CHECK(port, ver) \
272 if (((ver) == OF_VERSION_1_0) && ((port) > 0xff00)) (port) += 0xffff0000
Rich Lanea06d0c32013-03-25 08:52:03 -0700273
Rich Lane940b8752013-12-15 11:56:50 -0800274/**
275 * Macro to detect if an object ID falls in the "flow mod" family of objects
276 * This includes add, modify, modify_strict, delete and delete_strict
277 */
278#define IS_FLOW_MOD_SUBTYPE(object_id) \
279 (((object_id) == OF_FLOW_MODIFY) || \
280 ((object_id) == OF_FLOW_MODIFY_STRICT) || \
281 ((object_id) == OF_FLOW_DELETE) || \
282 ((object_id) == OF_FLOW_DELETE_STRICT) || \
283 ((object_id) == OF_FLOW_ADD))
Rich Lanea06d0c32013-03-25 08:52:03 -0700284
Rich Lane713d9282013-12-30 15:21:35 -0800285/**
286 * Macro to calculate variable offset of value member in of_bsn_gentable_entry_add
287 * @param obj An object of type of_bsn_gentable_entry_add_t
288 */
289
290#define _BSN_GENTABLE_ENTRY_ADD_VALUE_OFFSET(obj) \
291 (of_object_u16_get(obj, 18) + \
292 of_object_fixed_len[(obj)->version][OF_BSN_GENTABLE_ENTRY_ADD])
293
294#define _BSN_GENTABLE_ENTRY_DESC_STATS_ENTRY_VALUE_OFFSET(obj) \
295 (of_object_u16_get(obj, 2) + \
296 of_object_fixed_len[(obj)->version][OF_BSN_GENTABLE_ENTRY_DESC_STATS_ENTRY])
297
298#define _BSN_GENTABLE_ENTRY_STATS_ENTRY_STATS_OFFSET(obj) \
299 (of_object_u16_get(obj, 2) + \
300 of_object_fixed_len[(obj)->version][OF_BSN_GENTABLE_ENTRY_STATS_ENTRY])
301
Rich Lanea06d0c32013-03-25 08:52:03 -0700302#endif /* __LOCI_INT_H__ */