blob: 3172ad12f82f670f90f3e299e16b418bc59f8a94 [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
Rich Lanea06d0c32013-03-25 08:52:03 -070051/**
52 * This is the number of bytes reserved for metadata in each
53 * of_object_t instance.
54 */
55#define OF_OBJECT_METADATA_BYTES 32
56
Rich Lanedef2e512013-12-15 15:54:02 -080057/*
58 * Generic accessors:
59 *
60 * Many objects have a length represented in the wire buffer
61 * wire_length_get and wire_length_set access these values directly on the
62 * wire.
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 * FIXME: TBD if wire_length_set and wire_type_set are required.
69 */
70typedef void (*of_wire_length_get_f)(of_object_t *obj, int *bytes);
71typedef void (*of_wire_length_set_f)(of_object_t *obj, int bytes);
72typedef void (*of_wire_type_get_f)(of_object_t *obj, of_object_id_t *id);
73typedef void (*of_wire_type_set_f)(of_object_t *obj);
74
Rich Lanea06d0c32013-03-25 08:52:03 -070075/****************************************************************
76 * General list operations: first, next, append_setup, append_advance
77 ****************************************************************/
78
79/* General list first operation */
80extern int of_list_first(of_object_t *parent, of_object_t *child);
81
82/* General list next operation */
83extern int of_list_next(of_object_t *parent, of_object_t *child);
84
85/* General list append bind operation */
86extern int of_list_append_bind(of_object_t *parent, of_object_t *child);
87
88/* Append a copy of item to list */
89extern int of_list_append(of_object_t *list, of_object_t *item);
90
91extern of_object_t *of_object_new(int bytes);
Rich Lanecd6ef152013-12-15 16:42:18 -080092extern of_object_t *of_object_dup(of_object_t *src);
Rich Lanea06d0c32013-03-25 08:52:03 -070093
94/**
95 * Callback function prototype for deleting an object
96 */
97typedef void (*of_object_delete_callback_f)(of_object_t *obj);
98
Rich Lanea06d0c32013-03-25 08:52:03 -070099typedef struct of_object_track_info_s {
100 of_object_delete_callback_f delete_cb; /* To be implemented */
101 void *delete_cookie;
102} of_object_track_info_t;
103
Rich Lanea06d0c32013-03-25 08:52:03 -0700104extern int of_object_xid_set(of_object_t *obj, uint32_t xid);
105extern int of_object_xid_get(of_object_t *obj, uint32_t *xid);
106
107/* Bind a buffer to an object, usually for parsing the buffer */
108extern int of_object_buffer_bind(of_object_t *obj, uint8_t *buf,
109 int bytes, of_buffer_free_f buf_free);
110
111
112/**
113 * Steal a wire buffer from an object.
114 * @param obj The object whose buffer is being removed
115 * @param buffer[out] A handle for the pointer to the uint8_t * returned
116 *
117 * The wire buffer is taken from the object and its wirebuffer is set to
118 * NULL. The ref_count of the wire buffer is not changed.
119 */
120extern void of_object_wire_buffer_steal(of_object_t *obj, uint8_t **buffer);
121extern int of_object_append_buffer(of_object_t *dst, of_object_t *src);
122
123extern of_object_t *of_object_new_from_message(of_message_t msg, int len);
124
Rich Lanec73680c2014-02-22 10:44:28 -0800125typedef struct of_object_storage_s of_object_storage_t;
126
127of_object_t *of_object_new_from_message_preallocated(
128 of_object_storage_t *storage, uint8_t *buf, int len);
129
Rich Lanea06d0c32013-03-25 08:52:03 -0700130/* Delete an OpenFlow object without reference to its type */
131extern void of_object_delete(of_object_t *obj);
132
133int of_object_can_grow(of_object_t *obj, int new_len);
134
Rich Lane50aa5942013-12-15 16:20:38 -0800135void of_object_parent_length_update(of_object_t *obj, int delta);
136
Rich Lanedef2e512013-12-15 15:54:02 -0800137struct of_object_s {
138 /* The control block for the underlying data buffer */
139 of_wire_object_t wire_object;
140 /* The LOCI type enum value of the object */
141 of_object_id_t object_id;
142
143 /*
144 * Objects need to track their "parent" so that updates to the
145 * object that affect its length can be pushed to the parent.
146 * Treat as private.
147 */
148 of_object_t *parent;
149
150 /*
151 * Not all objects have length and version on the wire so we keep
152 * them here. NOTE: Infrastructure manages length and version.
153 * Treat length as private and version as read only.
154 */
155 int length;
156 of_version_t version;
157
158 /*
159 * Many objects have a length and/or type represented in the wire buffer
160 * These accessors get and set those value when present. Treat as private.
161 */
162 of_wire_length_get_f wire_length_get;
163 of_wire_length_set_f wire_length_set;
164 of_wire_type_get_f wire_type_get;
165 of_wire_type_set_f wire_type_set;
166
167 of_object_track_info_t track_info;
168
169 /*
170 * Metadata available for applications. Ensure 8-byte alignment, but
171 * that buffer is at least as large as requested. This data is not used
172 * or inspected by LOCI.
173 */
174 uint64_t metadata[(OF_OBJECT_METADATA_BYTES + 7) / 8];
175};
176
Rich Lanec73680c2014-02-22 10:44:28 -0800177struct of_object_storage_s {
178 of_object_t obj;
179 of_wire_buffer_t wbuf;
180};
181
Rich Lanea06d0c32013-03-25 08:52:03 -0700182#endif /* _OF_OBJECT_H_ */