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