blob: fee95e14d5b078cb517e6dfb2c3af2be74fa974a [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 * @fixme THIS FILE NEEDS CLEANUP. It may just go away.
32 *
33 * Low level internal header file. Defines inheritance mechanism for
34 * LOCI objects. In general, the routines in this file should not be
35 * called directly. Rather the class-specific operations should be
36 * used from loci.h.
37 *
38 * TREAT THESE FUNCTIONS AS PRIVATE. THEY ARE GENERALLY HELPER
39 * FUNCTIONS FOR LOCI TYPE SPECIFIC IMPLEMENTATIONS
40 */
41
42#if !defined(_OF_OBJECT_H_)
43#define _OF_OBJECT_H_
44
45#include <loci/of_buffer.h>
46#include <loci/of_match.h>
47#include <loci/loci_base.h>
48#include <loci/of_message.h>
Rich Lanedef2e512013-12-15 15:54:02 -080049#include <loci/of_wire_buf.h>
Rich Lanea06d0c32013-03-25 08:52:03 -070050
51#if defined(OF_OBJECT_TRACKING)
52#include <BigList/biglist.h>
53#endif
54
55/**
56 * This is the number of bytes reserved for metadata in each
57 * of_object_t instance.
58 */
59#define OF_OBJECT_METADATA_BYTES 32
60
Rich Lanedef2e512013-12-15 15:54:02 -080061/*
62 * Generic accessors:
63 *
64 * Many objects have a length represented in the wire buffer
65 * wire_length_get and wire_length_set access these values directly on the
66 * wire.
67 *
68 * Many objects have a length represented in the wire buffer
69 * wire_length_get and wire_length_set access these values directly on the
70 * wire.
71 *
72 * FIXME: TBD if wire_length_set and wire_type_set are required.
73 */
74typedef void (*of_wire_length_get_f)(of_object_t *obj, int *bytes);
75typedef void (*of_wire_length_set_f)(of_object_t *obj, int bytes);
76typedef void (*of_wire_type_get_f)(of_object_t *obj, of_object_id_t *id);
77typedef void (*of_wire_type_set_f)(of_object_t *obj);
78
Rich Lanea06d0c32013-03-25 08:52:03 -070079/****************************************************************
80 * General list operations: first, next, append_setup, append_advance
81 ****************************************************************/
82
83/* General list first operation */
84extern int of_list_first(of_object_t *parent, of_object_t *child);
85
86/* General list next operation */
87extern int of_list_next(of_object_t *parent, of_object_t *child);
88
89/* General list append bind operation */
90extern int of_list_append_bind(of_object_t *parent, of_object_t *child);
91
92/* Append a copy of item to list */
93extern int of_list_append(of_object_t *list, of_object_t *item);
94
95extern of_object_t *of_object_new(int bytes);
96extern of_object_t * of_object_dup_(of_object_t *src);
97
98/**
99 * Callback function prototype for deleting an object
100 */
101typedef void (*of_object_delete_callback_f)(of_object_t *obj);
102
103#if defined(OF_OBJECT_TRACKING)
104/**
105 * When tracking is enabled, the location of each new or dup
106 * call of an OF object is recorded and a list is kept of all
107 * outstanding objects.
108 *
109 * This dovetails with using objects to track outstanding operations
110 * for barrier processing.
111 */
112
113/**
114 * Global tracking stats
115 */
116typedef struct loci_object_track_s {
117 biglist_t *objects;
118 int count_current;
119 uint32_t count_max;
120 uint32_t allocs;
121 uint32_t deletes;
122} loci_object_track_t;
123
124extern loci_object_track_t loci_global_tracking;
125
126/* Remap dup call to tracking */
127extern of_object_t * of_object_dup_tracking(of_object_t *src,
128 const char *file, int line);
129#define of_object_dup(src) of_object_dup_tracking(src, __FILE__, __LINE__)
130extern void of_object_track(of_object_t *obj, const char *file, int line);
131
132extern void of_object_track_output(of_object_t *obj, loci_writer_f writer, void* cookie);
133extern void of_object_track_report(loci_writer_f writer, void* cookie);
134
135/**
136 * The data stored in each object related to tracking and
137 * The LOCI client may install a delete callback function to allow
138 * the notification of an object's destruction.
139 */
140
141typedef struct of_object_track_info_s {
142 of_object_delete_callback_f delete_cb; /* To be implemented */
143 void *delete_cookie;
144
145 /* Track file and line where allocated */
146 const char *file;
147 int line;
148 biglist_t *bl_entry; /* Pointer to self */
149 uint32_t magic; /* validation value */
150} of_object_track_info_t;
151
152#define OF_OBJECT_TRACKING_MAGIC 0x11235813
153#else
154
155/* Use native dup call */
156#define of_object_dup of_object_dup_
157
158/**
159 * When tracking is not enabled, we still support a delete callback
160 */
161
162typedef struct of_object_track_info_s {
163 of_object_delete_callback_f delete_cb; /* To be implemented */
164 void *delete_cookie;
165} of_object_track_info_t;
166
167#endif
168
169extern int of_object_xid_set(of_object_t *obj, uint32_t xid);
170extern int of_object_xid_get(of_object_t *obj, uint32_t *xid);
171
172/* Bind a buffer to an object, usually for parsing the buffer */
173extern int of_object_buffer_bind(of_object_t *obj, uint8_t *buf,
174 int bytes, of_buffer_free_f buf_free);
175
176
177/**
178 * Steal a wire buffer from an object.
179 * @param obj The object whose buffer is being removed
180 * @param buffer[out] A handle for the pointer to the uint8_t * returned
181 *
182 * The wire buffer is taken from the object and its wirebuffer is set to
183 * NULL. The ref_count of the wire buffer is not changed.
184 */
185extern void of_object_wire_buffer_steal(of_object_t *obj, uint8_t **buffer);
186extern int of_object_append_buffer(of_object_t *dst, of_object_t *src);
187
188extern of_object_t *of_object_new_from_message(of_message_t msg, int len);
189
190/* Delete an OpenFlow object without reference to its type */
191extern void of_object_delete(of_object_t *obj);
192
193int of_object_can_grow(of_object_t *obj, int new_len);
194
Rich Lanedef2e512013-12-15 15:54:02 -0800195struct of_object_s {
196 /* The control block for the underlying data buffer */
197 of_wire_object_t wire_object;
198 /* The LOCI type enum value of the object */
199 of_object_id_t object_id;
200
201 /*
202 * Objects need to track their "parent" so that updates to the
203 * object that affect its length can be pushed to the parent.
204 * Treat as private.
205 */
206 of_object_t *parent;
207
208 /*
209 * Not all objects have length and version on the wire so we keep
210 * them here. NOTE: Infrastructure manages length and version.
211 * Treat length as private and version as read only.
212 */
213 int length;
214 of_version_t version;
215
216 /*
217 * Many objects have a length and/or type represented in the wire buffer
218 * These accessors get and set those value when present. Treat as private.
219 */
220 of_wire_length_get_f wire_length_get;
221 of_wire_length_set_f wire_length_set;
222 of_wire_type_get_f wire_type_get;
223 of_wire_type_set_f wire_type_set;
224
225 of_object_track_info_t track_info;
226
227 /*
228 * Metadata available for applications. Ensure 8-byte alignment, but
229 * that buffer is at least as large as requested. This data is not used
230 * or inspected by LOCI.
231 */
232 uint64_t metadata[(OF_OBJECT_METADATA_BYTES + 7) / 8];
233};
234
Rich Lanea06d0c32013-03-25 08:52:03 -0700235#endif /* _OF_OBJECT_H_ */