Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 1 | :: # 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 Lane | d983aa5 | 2013-06-13 11:48:37 -0700 | [diff] [blame] | 28 | :: include('_copyright.c') |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 29 | |
| 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 Lane | def2e51 | 2013-12-15 15:54:02 -0800 | [diff] [blame] | 49 | #include <loci/of_wire_buf.h> |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 50 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 51 | /**************************************************************** |
| 52 | * General list operations: first, next, append_setup, append_advance |
| 53 | ****************************************************************/ |
| 54 | |
| 55 | /* General list first operation */ |
| 56 | extern int of_list_first(of_object_t *parent, of_object_t *child); |
| 57 | |
| 58 | /* General list next operation */ |
| 59 | extern int of_list_next(of_object_t *parent, of_object_t *child); |
| 60 | |
| 61 | /* General list append bind operation */ |
| 62 | extern int of_list_append_bind(of_object_t *parent, of_object_t *child); |
| 63 | |
| 64 | /* Append a copy of item to list */ |
| 65 | extern int of_list_append(of_object_t *list, of_object_t *item); |
| 66 | |
| 67 | extern of_object_t *of_object_new(int bytes); |
Rich Lane | cd6ef15 | 2013-12-15 16:42:18 -0800 | [diff] [blame] | 68 | extern of_object_t *of_object_dup(of_object_t *src); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 69 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 70 | extern int of_object_xid_set(of_object_t *obj, uint32_t xid); |
| 71 | extern 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 */ |
| 74 | extern 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 | */ |
| 86 | extern void of_object_wire_buffer_steal(of_object_t *obj, uint8_t **buffer); |
| 87 | extern int of_object_append_buffer(of_object_t *dst, of_object_t *src); |
| 88 | |
| 89 | extern of_object_t *of_object_new_from_message(of_message_t msg, int len); |
| 90 | |
Rich Lane | c73680c | 2014-02-22 10:44:28 -0800 | [diff] [blame] | 91 | typedef struct of_object_storage_s of_object_storage_t; |
| 92 | |
| 93 | of_object_t *of_object_new_from_message_preallocated( |
| 94 | of_object_storage_t *storage, uint8_t *buf, int len); |
| 95 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 96 | /* Delete an OpenFlow object without reference to its type */ |
| 97 | extern void of_object_delete(of_object_t *obj); |
| 98 | |
| 99 | int of_object_can_grow(of_object_t *obj, int new_len); |
| 100 | |
Rich Lane | 50aa594 | 2013-12-15 16:20:38 -0800 | [diff] [blame] | 101 | void of_object_parent_length_update(of_object_t *obj, int delta); |
| 102 | |
Rich Lane | def2e51 | 2013-12-15 15:54:02 -0800 | [diff] [blame] | 103 | struct of_object_s { |
Rich Lane | cdd542d | 2014-04-03 16:13:12 -0700 | [diff] [blame] | 104 | /** A pointer to the underlying buffer's management structure. */ |
| 105 | of_wire_buffer_t *wbuf; |
| 106 | |
| 107 | /** The start offset for this object relative to the start of the |
| 108 | * underlying buffer */ |
| 109 | int obj_offset; |
| 110 | |
Rich Lane | def2e51 | 2013-12-15 15:54:02 -0800 | [diff] [blame] | 111 | /* The LOCI type enum value of the object */ |
| 112 | of_object_id_t object_id; |
| 113 | |
| 114 | /* |
| 115 | * Objects need to track their "parent" so that updates to the |
| 116 | * object that affect its length can be pushed to the parent. |
| 117 | * Treat as private. |
| 118 | */ |
| 119 | of_object_t *parent; |
| 120 | |
| 121 | /* |
| 122 | * Not all objects have length and version on the wire so we keep |
| 123 | * them here. NOTE: Infrastructure manages length and version. |
| 124 | * Treat length as private and version as read only. |
| 125 | */ |
| 126 | int length; |
| 127 | of_version_t version; |
Rich Lane | def2e51 | 2013-12-15 15:54:02 -0800 | [diff] [blame] | 128 | }; |
| 129 | |
Rich Lane | c73680c | 2014-02-22 10:44:28 -0800 | [diff] [blame] | 130 | struct of_object_storage_s { |
| 131 | of_object_t obj; |
| 132 | of_wire_buffer_t wbuf; |
| 133 | }; |
| 134 | |
Rich Lane | d1fe697 | 2014-06-12 14:53:24 -0700 | [diff] [blame] | 135 | /** |
| 136 | * Connect a child to a parent at the wire buffer level |
| 137 | * |
| 138 | * @param parent The top level object to bind to |
| 139 | * @param child The sub-object connecting to the parent |
| 140 | * @param offset The offset at which to attach the child RELATIVE |
| 141 | * TO THE PARENT in the buffer |
| 142 | * @param bytes The amount of the buffer dedicated to the child |
| 143 | */ |
| 144 | static inline void |
| 145 | of_object_attach(of_object_t *parent, of_object_t *child, int offset, int length) |
| 146 | { |
| 147 | child->parent = parent; |
| 148 | child->wbuf = parent->wbuf; |
| 149 | child->obj_offset = parent->obj_offset + offset; |
| 150 | child->length = length; |
| 151 | } |
| 152 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 153 | #endif /* _OF_OBJECT_H_ */ |