blob: b4df78c58367a24e665f9385293779ca3227bc3d [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)]
33:: flow_stats = of_g.base_length[("of_flow_stats_entry", of_g.VERSION_1_2)]
34:: match1 = of_g.base_length[("of_match_v1",of_g.VERSION_1_0)]
35:: match2 = of_g.base_length[("of_match_v2",of_g.VERSION_1_1)]
Rich Lanea06d0c32013-03-25 08:52:03 -070036
37/******************************************************************************
38 *
39 * /module/src/loci_int.h
40 *
41 * loci Internal Header
42 *
43 *****************************************************************************/
44#ifndef __LOCI_INT_H__
45#define __LOCI_INT_H__
46
Rich Lanec3662bb2013-12-15 15:14:13 -080047#include <loci/loci.h>
48
Rich Lanea407b912013-12-15 11:53:35 -080049/****************************************************************
50 * Special case macros for calculating variable lengths and offsets
51 ****************************************************************/
Rich Lanea06d0c32013-03-25 08:52:03 -070052
Rich Lanea407b912013-12-15 11:53:35 -080053/**
54 * Get a u16 directly from an offset in an object's wire buffer
55 * @param obj An of_object_t object
56 * @param offset Base offset of the uint16 relative to the object
57 *
58 */
59
60static inline int
61of_object_u16_get(of_object_t *obj, int offset) {
62 uint16_t val16;
63
64 of_wire_buffer_u16_get(obj->wire_object.wbuf,
65 obj->wire_object.obj_offset + offset, &val16);
66
67 return (int)val16;
68}
69
70/**
71 * Set a u16 directly at an offset in an object's wire buffer
72 * @param obj An of_object_t object
73 * @param offset Base offset of the uint16 relative to the object
74 * @param val The value to store
75 *
76 */
77
78static inline void
79of_object_u16_set(of_object_t *obj, int offset, int value) {
80 uint16_t val16;
81
82 val16 = (uint16_t)value;
83 of_wire_buffer_u16_set(obj->wire_object.wbuf,
84 obj->wire_object.obj_offset + offset, val16);
85}
86
87/**
88 * Get length of an object with a TLV header with uint16_t
89 * @param obj An object with a match member
90 * @param offset The wire offset of the start of the object
91 *
92 * The length field follows the type field.
93 */
94
95#define _TLV16_LEN(obj, offset) \
96 (of_object_u16_get((of_object_t *)(obj), (offset) + 2))
97
98/**
99 * Get length of an object that is the "rest" of the object
100 * @param obj An object with a match member
101 * @param offset The wire offset of the start of the object
102 *
103 */
104
105#define _END_LEN(obj, offset) ((obj)->length - (offset))
106
107/**
108 * Offset of the action_len member in a packet-out object
109 */
110
111#define _PACKET_OUT_ACTION_LEN_OFFSET(obj) \
112 (((obj)->version == OF_VERSION_1_0) ? 14 : 16)
113
114/**
115 * Get length of the action list object in a packet_out object
116 * @param obj An object of type of_packet_out
117 */
118
119#define _PACKET_OUT_ACTION_LEN(obj) \
120 (of_object_u16_get((of_object_t *)(obj), _PACKET_OUT_ACTION_LEN_OFFSET(obj)))
121
122/**
123 * Set 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_SET(obj, len) \
128 (of_object_u16_set((of_object_t *)(obj), _PACKET_OUT_ACTION_LEN_OFFSET(obj), len))
129
130/*
131 * Match structs in 1.2 come at the end of the fixed length part
132 * of structures. They add 8 bytes to the minimal length of the
133 * message, but are also variable length. This means that the
134 * type/length offsets are 8 bytes back from the end of the fixed
135 * length part of the object. The right way to handle this is to
136 * expose the offset of the match member more explicitly. For now,
137 * we make the calculation as described here.
138 */
139
140/* 1.2 min length of match is 8 bytes */
141#define _MATCH_MIN_LENGTH_V3 8
142
143/**
144 * The offset of a 1.2 match object relative to fixed length of obj
145 */
146#define _MATCH_OFFSET_V3(fixed_obj_len) \
147 ((fixed_obj_len) - _MATCH_MIN_LENGTH_V3)
148
149/**
150 * The "extra" length beyond the minimal 8 bytes of a match struct
151 * in an object
152 */
153#define _MATCH_EXTRA_LENGTH_V3(obj, fixed_obj_len) \
154 (OF_MATCH_BYTES(_TLV16_LEN(obj, _MATCH_OFFSET_V3(fixed_obj_len))) - \
155 _MATCH_MIN_LENGTH_V3)
156
157/**
158 * The offset of an object following a match object for 1.2
159 */
160#define _OFFSET_FOLLOWING_MATCH_V3(obj, fixed_obj_len) \
161 ((fixed_obj_len) + _MATCH_EXTRA_LENGTH_V3(obj, fixed_obj_len))
162
163/**
164 * Get length of a match object from its wire representation
165 * @param obj An object with a match member
166 * @param match_offset The wire offset of the match object.
167 *
168 * See above; for 1.2,
169 * The match length is raw bytes but the actual space it takes
170 * up is padded for alignment to 64-bits
171 */
172#define _WIRE_MATCH_LEN(obj, match_offset) \
173 (((obj)->version == OF_VERSION_1_0) ? ${match1} : \
174 (((obj)->version == OF_VERSION_1_1) ? ${match2} : \
175 _TLV16_LEN(obj, match_offset)))
176
177#define _WIRE_LEN_MIN 4
178
179/*
180 * Wrapper function for match len. There are cases where the wire buffer
181 * has not been set with the proper minimum length. In this case, the
182 * wire match len is interpretted as its minimum length, 4 bytes.
183 */
184
185static inline int
186wire_match_len(of_object_t *obj, int match_offset) {
187 int len;
188
189 len = _WIRE_MATCH_LEN(obj, match_offset);
190
191 return (len == 0) ? _WIRE_LEN_MIN : len;
192}
193
194#define _WIRE_MATCH_PADDED_LEN(obj, match_offset) \
195 OF_MATCH_BYTES(wire_match_len((of_object_t *)(obj), (match_offset)))
196
197/**
198 * Macro to calculate variable offset of instructions member in flow mod
199 * @param obj An object of some type of flow modify/add/delete
200 *
201 * Get length of preceding match object and add to fixed length
202 * Applies only to version 1.2
203 */
204
205#define _FLOW_MOD_INSTRUCTIONS_OFFSET(obj) \
206 _OFFSET_FOLLOWING_MATCH_V3(obj, ${flow_mod})
207
208/* The different flavors of flow mod all use the above */
209#define _FLOW_ADD_INSTRUCTIONS_OFFSET(obj) \
210 _FLOW_MOD_INSTRUCTIONS_OFFSET(obj)
211#define _FLOW_MODIFY_INSTRUCTIONS_OFFSET(obj) \
212 _FLOW_MOD_INSTRUCTIONS_OFFSET(obj)
213#define _FLOW_MODIFY_STRICT_INSTRUCTIONS_OFFSET(obj) \
214 _FLOW_MOD_INSTRUCTIONS_OFFSET(obj)
215#define _FLOW_DELETE_INSTRUCTIONS_OFFSET(obj) \
216 _FLOW_MOD_INSTRUCTIONS_OFFSET(obj)
217#define _FLOW_DELETE_STRICT_INSTRUCTIONS_OFFSET(obj) \
218 _FLOW_MOD_INSTRUCTIONS_OFFSET(obj)
219
220/**
221 * Macro to calculate variable offset of instructions member in flow stats
222 * @param obj An object of type of_flow_mod_t
223 *
224 * Get length of preceding match object and add to fixed length
225 * Applies only to version 1.2 and 1.3
226 */
227
228#define _FLOW_STATS_ENTRY_INSTRUCTIONS_OFFSET(obj) \
229 _OFFSET_FOLLOWING_MATCH_V3(obj, ${flow_stats})
230
231/**
232 * Macro to calculate variable offset of data (packet) member in packet_in
233 * @param obj An object of type of_packet_in_t
234 *
235 * Get length of preceding match object and add to fixed length
236 * Applies only to version 1.2 and 1.3
237 * The +2 comes from the 2 bytes of padding between the match and packet data.
238 */
239
240#define _PACKET_IN_DATA_OFFSET(obj) \
241 (_OFFSET_FOLLOWING_MATCH_V3((obj), (obj)->version == OF_VERSION_1_2 ? \
242${packet_in} : ${packet_in_1_3}) + 2)
243
244/**
245 * Macro to calculate variable offset of data (packet) member in packet_out
246 * @param obj An object of type of_packet_out_t
247 *
248 * Find the length in the actions_len variable and add to the fixed len
249 * Applies only to version 1.2 and 1.3
250 */
251
252#define _PACKET_OUT_DATA_OFFSET(obj) (_PACKET_OUT_ACTION_LEN(obj) + \
253 of_object_fixed_len[(obj)->version][OF_PACKET_OUT])
254
255/**
256 * Macro to map port numbers that changed across versions
257 * @param port The port_no_t variable holding the value
258 * @param ver The OpenFlow version from which the value was extracted
259 */
260#define OF_PORT_NO_VALUE_CHECK(port, ver) \
261 if (((ver) == OF_VERSION_1_0) && ((port) > 0xff00)) (port) += 0xffff0000
Rich Lanea06d0c32013-03-25 08:52:03 -0700262
Rich Lane940b8752013-12-15 11:56:50 -0800263/**
264 * Macro to detect if an object ID falls in the "flow mod" family of objects
265 * This includes add, modify, modify_strict, delete and delete_strict
266 */
267#define IS_FLOW_MOD_SUBTYPE(object_id) \
268 (((object_id) == OF_FLOW_MODIFY) || \
269 ((object_id) == OF_FLOW_MODIFY_STRICT) || \
270 ((object_id) == OF_FLOW_DELETE) || \
271 ((object_id) == OF_FLOW_DELETE_STRICT) || \
272 ((object_id) == OF_FLOW_ADD))
Rich Lanea06d0c32013-03-25 08:52:03 -0700273
Rich Lanea06d0c32013-03-25 08:52:03 -0700274#endif /* __LOCI_INT_H__ */