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 | def2e51 | 2013-12-15 15:54:02 -0800 | [diff] [blame] | 51 | /* |
| 52 | * Generic accessors: |
| 53 | * |
| 54 | * Many objects have a length represented in the wire buffer |
| 55 | * wire_length_get and wire_length_set access these values directly on the |
| 56 | * wire. |
| 57 | * |
| 58 | * Many objects have a length represented in the wire buffer |
| 59 | * wire_length_get and wire_length_set access these values directly on the |
| 60 | * wire. |
| 61 | * |
| 62 | * FIXME: TBD if wire_length_set and wire_type_set are required. |
| 63 | */ |
| 64 | typedef void (*of_wire_length_get_f)(of_object_t *obj, int *bytes); |
| 65 | typedef void (*of_wire_length_set_f)(of_object_t *obj, int bytes); |
| 66 | typedef void (*of_wire_type_get_f)(of_object_t *obj, of_object_id_t *id); |
| 67 | typedef void (*of_wire_type_set_f)(of_object_t *obj); |
| 68 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 69 | /**************************************************************** |
| 70 | * General list operations: first, next, append_setup, append_advance |
| 71 | ****************************************************************/ |
| 72 | |
| 73 | /* General list first operation */ |
| 74 | extern int of_list_first(of_object_t *parent, of_object_t *child); |
| 75 | |
| 76 | /* General list next operation */ |
| 77 | extern int of_list_next(of_object_t *parent, of_object_t *child); |
| 78 | |
| 79 | /* General list append bind operation */ |
| 80 | extern int of_list_append_bind(of_object_t *parent, of_object_t *child); |
| 81 | |
| 82 | /* Append a copy of item to list */ |
| 83 | extern int of_list_append(of_object_t *list, of_object_t *item); |
| 84 | |
| 85 | extern of_object_t *of_object_new(int bytes); |
Rich Lane | cd6ef15 | 2013-12-15 16:42:18 -0800 | [diff] [blame] | 86 | extern of_object_t *of_object_dup(of_object_t *src); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 87 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 88 | extern int of_object_xid_set(of_object_t *obj, uint32_t xid); |
| 89 | extern int of_object_xid_get(of_object_t *obj, uint32_t *xid); |
| 90 | |
| 91 | /* Bind a buffer to an object, usually for parsing the buffer */ |
| 92 | extern int of_object_buffer_bind(of_object_t *obj, uint8_t *buf, |
| 93 | int bytes, of_buffer_free_f buf_free); |
| 94 | |
| 95 | |
| 96 | /** |
| 97 | * Steal a wire buffer from an object. |
| 98 | * @param obj The object whose buffer is being removed |
| 99 | * @param buffer[out] A handle for the pointer to the uint8_t * returned |
| 100 | * |
| 101 | * The wire buffer is taken from the object and its wirebuffer is set to |
| 102 | * NULL. The ref_count of the wire buffer is not changed. |
| 103 | */ |
| 104 | extern void of_object_wire_buffer_steal(of_object_t *obj, uint8_t **buffer); |
| 105 | extern int of_object_append_buffer(of_object_t *dst, of_object_t *src); |
| 106 | |
| 107 | extern of_object_t *of_object_new_from_message(of_message_t msg, int len); |
| 108 | |
Rich Lane | c73680c | 2014-02-22 10:44:28 -0800 | [diff] [blame] | 109 | typedef struct of_object_storage_s of_object_storage_t; |
| 110 | |
| 111 | of_object_t *of_object_new_from_message_preallocated( |
| 112 | of_object_storage_t *storage, uint8_t *buf, int len); |
| 113 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 114 | /* Delete an OpenFlow object without reference to its type */ |
| 115 | extern void of_object_delete(of_object_t *obj); |
| 116 | |
| 117 | int of_object_can_grow(of_object_t *obj, int new_len); |
| 118 | |
Rich Lane | 50aa594 | 2013-12-15 16:20:38 -0800 | [diff] [blame] | 119 | void of_object_parent_length_update(of_object_t *obj, int delta); |
| 120 | |
Rich Lane | def2e51 | 2013-12-15 15:54:02 -0800 | [diff] [blame] | 121 | struct of_object_s { |
| 122 | /* The control block for the underlying data buffer */ |
| 123 | of_wire_object_t wire_object; |
| 124 | /* The LOCI type enum value of the object */ |
| 125 | of_object_id_t object_id; |
| 126 | |
| 127 | /* |
| 128 | * Objects need to track their "parent" so that updates to the |
| 129 | * object that affect its length can be pushed to the parent. |
| 130 | * Treat as private. |
| 131 | */ |
| 132 | of_object_t *parent; |
| 133 | |
| 134 | /* |
| 135 | * Not all objects have length and version on the wire so we keep |
| 136 | * them here. NOTE: Infrastructure manages length and version. |
| 137 | * Treat length as private and version as read only. |
| 138 | */ |
| 139 | int length; |
| 140 | of_version_t version; |
| 141 | |
| 142 | /* |
| 143 | * Many objects have a length and/or type represented in the wire buffer |
| 144 | * These accessors get and set those value when present. Treat as private. |
| 145 | */ |
| 146 | of_wire_length_get_f wire_length_get; |
| 147 | of_wire_length_set_f wire_length_set; |
| 148 | of_wire_type_get_f wire_type_get; |
| 149 | of_wire_type_set_f wire_type_set; |
Rich Lane | def2e51 | 2013-12-15 15:54:02 -0800 | [diff] [blame] | 150 | }; |
| 151 | |
Rich Lane | c73680c | 2014-02-22 10:44:28 -0800 | [diff] [blame] | 152 | struct of_object_storage_s { |
| 153 | of_object_t obj; |
| 154 | of_wire_buffer_t wbuf; |
| 155 | }; |
| 156 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 157 | #endif /* _OF_OBJECT_H_ */ |