blob: 804e7eccf64c863ef8c357a4c08b861ff7cd0c74 [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 * General list operations: first, next, append_setup, append_advance
53 ****************************************************************/
54
55/* General list first operation */
56extern int of_list_first(of_object_t *parent, of_object_t *child);
57
58/* General list next operation */
59extern int of_list_next(of_object_t *parent, of_object_t *child);
60
61/* General list append bind operation */
62extern int of_list_append_bind(of_object_t *parent, of_object_t *child);
63
64/* Append a copy of item to list */
65extern int of_list_append(of_object_t *list, of_object_t *item);
66
67extern of_object_t *of_object_new(int bytes);
Rich Lanecd6ef152013-12-15 16:42:18 -080068extern of_object_t *of_object_dup(of_object_t *src);
Rich Lanea06d0c32013-03-25 08:52:03 -070069
Rich Lanea06d0c32013-03-25 08:52:03 -070070extern int of_object_xid_set(of_object_t *obj, uint32_t xid);
71extern int of_object_xid_get(of_object_t *obj, uint32_t *xid);
72
73/* Bind a buffer to an object, usually for parsing the buffer */
74extern int of_object_buffer_bind(of_object_t *obj, uint8_t *buf,
75 int bytes, of_buffer_free_f buf_free);
76
77
78/**
79 * Steal a wire buffer from an object.
80 * @param obj The object whose buffer is being removed
81 * @param buffer[out] A handle for the pointer to the uint8_t * returned
82 *
83 * The wire buffer is taken from the object and its wirebuffer is set to
84 * NULL. The ref_count of the wire buffer is not changed.
85 */
86extern void of_object_wire_buffer_steal(of_object_t *obj, uint8_t **buffer);
87extern int of_object_append_buffer(of_object_t *dst, of_object_t *src);
88
89extern of_object_t *of_object_new_from_message(of_message_t msg, int len);
90
Rich Lanec73680c2014-02-22 10:44:28 -080091typedef struct of_object_storage_s of_object_storage_t;
92
93of_object_t *of_object_new_from_message_preallocated(
94 of_object_storage_t *storage, uint8_t *buf, int len);
95
Rich Lanea06d0c32013-03-25 08:52:03 -070096/* Delete an OpenFlow object without reference to its type */
97extern void of_object_delete(of_object_t *obj);
98
99int of_object_can_grow(of_object_t *obj, int new_len);
100
Rich Lane50aa5942013-12-15 16:20:38 -0800101void of_object_parent_length_update(of_object_t *obj, int delta);
102
Rich Lane9f00eb32015-03-03 15:49:07 -0800103void of_object_truncate(of_object_t *obj);
104
Rich Lanedef2e512013-12-15 15:54:02 -0800105struct of_object_s {
Rich Lanecdd542d2014-04-03 16:13:12 -0700106 /** A pointer to the underlying buffer's management structure. */
107 of_wire_buffer_t *wbuf;
108
109 /** The start offset for this object relative to the start of the
110 * underlying buffer */
111 int obj_offset;
112
Rich Lanedef2e512013-12-15 15:54:02 -0800113 /* The LOCI type enum value of the object */
114 of_object_id_t object_id;
115
116 /*
117 * Objects need to track their "parent" so that updates to the
118 * object that affect its length can be pushed to the parent.
119 * Treat as private.
120 */
121 of_object_t *parent;
122
123 /*
124 * Not all objects have length and version on the wire so we keep
125 * them here. NOTE: Infrastructure manages length and version.
126 * Treat length as private and version as read only.
127 */
128 int length;
129 of_version_t version;
Rich Lanedef2e512013-12-15 15:54:02 -0800130};
131
Rich Lanec73680c2014-02-22 10:44:28 -0800132struct of_object_storage_s {
133 of_object_t obj;
134 of_wire_buffer_t wbuf;
135};
136
Rich Laned1fe6972014-06-12 14:53:24 -0700137/**
138 * Connect a child to a parent at the wire buffer level
139 *
140 * @param parent The top level object to bind to
141 * @param child The sub-object connecting to the parent
142 * @param offset The offset at which to attach the child RELATIVE
143 * TO THE PARENT in the buffer
144 * @param bytes The amount of the buffer dedicated to the child
145 */
146static inline void
147of_object_attach(of_object_t *parent, of_object_t *child, int offset, int length)
148{
149 child->parent = parent;
150 child->wbuf = parent->wbuf;
151 child->obj_offset = parent->obj_offset + offset;
152 child->length = length;
153}
154
Rich Lanea06d0c32013-03-25 08:52:03 -0700155#endif /* _OF_OBJECT_H_ */