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> |
| 49 | |
| 50 | #if defined(OF_OBJECT_TRACKING) |
| 51 | #include <BigList/biglist.h> |
| 52 | #endif |
| 53 | |
| 54 | /** |
| 55 | * This is the number of bytes reserved for metadata in each |
| 56 | * of_object_t instance. |
| 57 | */ |
| 58 | #define OF_OBJECT_METADATA_BYTES 32 |
| 59 | |
| 60 | /**************************************************************** |
| 61 | * General list operations: first, next, append_setup, append_advance |
| 62 | ****************************************************************/ |
| 63 | |
| 64 | /* General list first operation */ |
| 65 | extern int of_list_first(of_object_t *parent, of_object_t *child); |
| 66 | |
| 67 | /* General list next operation */ |
| 68 | extern int of_list_next(of_object_t *parent, of_object_t *child); |
| 69 | |
| 70 | /* General list append bind operation */ |
| 71 | extern int of_list_append_bind(of_object_t *parent, of_object_t *child); |
| 72 | |
| 73 | /* Append a copy of item to list */ |
| 74 | extern int of_list_append(of_object_t *list, of_object_t *item); |
| 75 | |
| 76 | extern of_object_t *of_object_new(int bytes); |
| 77 | extern of_object_t * of_object_dup_(of_object_t *src); |
| 78 | |
| 79 | /** |
| 80 | * Callback function prototype for deleting an object |
| 81 | */ |
| 82 | typedef void (*of_object_delete_callback_f)(of_object_t *obj); |
| 83 | |
| 84 | #if defined(OF_OBJECT_TRACKING) |
| 85 | /** |
| 86 | * When tracking is enabled, the location of each new or dup |
| 87 | * call of an OF object is recorded and a list is kept of all |
| 88 | * outstanding objects. |
| 89 | * |
| 90 | * This dovetails with using objects to track outstanding operations |
| 91 | * for barrier processing. |
| 92 | */ |
| 93 | |
| 94 | /** |
| 95 | * Global tracking stats |
| 96 | */ |
| 97 | typedef struct loci_object_track_s { |
| 98 | biglist_t *objects; |
| 99 | int count_current; |
| 100 | uint32_t count_max; |
| 101 | uint32_t allocs; |
| 102 | uint32_t deletes; |
| 103 | } loci_object_track_t; |
| 104 | |
| 105 | extern loci_object_track_t loci_global_tracking; |
| 106 | |
| 107 | /* Remap dup call to tracking */ |
| 108 | extern of_object_t * of_object_dup_tracking(of_object_t *src, |
| 109 | const char *file, int line); |
| 110 | #define of_object_dup(src) of_object_dup_tracking(src, __FILE__, __LINE__) |
| 111 | extern void of_object_track(of_object_t *obj, const char *file, int line); |
| 112 | |
| 113 | extern void of_object_track_output(of_object_t *obj, loci_writer_f writer, void* cookie); |
| 114 | extern void of_object_track_report(loci_writer_f writer, void* cookie); |
| 115 | |
| 116 | /** |
| 117 | * The data stored in each object related to tracking and |
| 118 | * The LOCI client may install a delete callback function to allow |
| 119 | * the notification of an object's destruction. |
| 120 | */ |
| 121 | |
| 122 | typedef struct of_object_track_info_s { |
| 123 | of_object_delete_callback_f delete_cb; /* To be implemented */ |
| 124 | void *delete_cookie; |
| 125 | |
| 126 | /* Track file and line where allocated */ |
| 127 | const char *file; |
| 128 | int line; |
| 129 | biglist_t *bl_entry; /* Pointer to self */ |
| 130 | uint32_t magic; /* validation value */ |
| 131 | } of_object_track_info_t; |
| 132 | |
| 133 | #define OF_OBJECT_TRACKING_MAGIC 0x11235813 |
| 134 | #else |
| 135 | |
| 136 | /* Use native dup call */ |
| 137 | #define of_object_dup of_object_dup_ |
| 138 | |
| 139 | /** |
| 140 | * When tracking is not enabled, we still support a delete callback |
| 141 | */ |
| 142 | |
| 143 | typedef struct of_object_track_info_s { |
| 144 | of_object_delete_callback_f delete_cb; /* To be implemented */ |
| 145 | void *delete_cookie; |
| 146 | } of_object_track_info_t; |
| 147 | |
| 148 | #endif |
| 149 | |
| 150 | extern int of_object_xid_set(of_object_t *obj, uint32_t xid); |
| 151 | extern int of_object_xid_get(of_object_t *obj, uint32_t *xid); |
| 152 | |
| 153 | /* Bind a buffer to an object, usually for parsing the buffer */ |
| 154 | extern int of_object_buffer_bind(of_object_t *obj, uint8_t *buf, |
| 155 | int bytes, of_buffer_free_f buf_free); |
| 156 | |
| 157 | |
| 158 | /** |
| 159 | * Steal a wire buffer from an object. |
| 160 | * @param obj The object whose buffer is being removed |
| 161 | * @param buffer[out] A handle for the pointer to the uint8_t * returned |
| 162 | * |
| 163 | * The wire buffer is taken from the object and its wirebuffer is set to |
| 164 | * NULL. The ref_count of the wire buffer is not changed. |
| 165 | */ |
| 166 | extern void of_object_wire_buffer_steal(of_object_t *obj, uint8_t **buffer); |
| 167 | extern int of_object_append_buffer(of_object_t *dst, of_object_t *src); |
| 168 | |
| 169 | extern of_object_t *of_object_new_from_message(of_message_t msg, int len); |
| 170 | |
| 171 | /* Delete an OpenFlow object without reference to its type */ |
| 172 | extern void of_object_delete(of_object_t *obj); |
| 173 | |
| 174 | int of_object_can_grow(of_object_t *obj, int new_len); |
| 175 | |
| 176 | #endif /* _OF_OBJECT_H_ */ |