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 | * |
| 32 | * Functions related to mapping wire values to object types |
| 33 | * and lengths |
| 34 | * |
| 35 | ****************************************************************/ |
| 36 | |
| 37 | #include <loci/loci.h> |
| 38 | #include <loci/of_message.h> |
| 39 | |
Rich Lane | c0e20ff | 2013-12-15 23:40:31 -0800 | [diff] [blame] | 40 | ${legacy_code} |
| 41 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 42 | /**************************************************************** |
| 43 | * Top level OpenFlow message length functions |
| 44 | ****************************************************************/ |
| 45 | |
| 46 | /** |
| 47 | * Get the length of a message object as reported on the wire |
| 48 | * @param obj The object to check |
| 49 | * @param bytes (out) Where the length is stored |
| 50 | * @returns OF_ERROR_ code |
| 51 | */ |
| 52 | void |
| 53 | of_object_message_wire_length_get(of_object_t *obj, int *bytes) |
| 54 | { |
Rich Lane | e57f043 | 2014-02-19 10:31:53 -0800 | [diff] [blame] | 55 | LOCI_ASSERT(OF_OBJECT_TO_WBUF(obj) != NULL); |
| 56 | // LOCI_ASSERT(obj is message) |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 57 | *bytes = of_message_length_get(OF_OBJECT_TO_MESSAGE(obj)); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Set the length of a message object as reported on the wire |
| 62 | * @param obj The object to check |
| 63 | * @param bytes The new length of the object |
| 64 | * @returns OF_ERROR_ code |
| 65 | */ |
| 66 | void |
| 67 | of_object_message_wire_length_set(of_object_t *obj, int bytes) |
| 68 | { |
Rich Lane | e57f043 | 2014-02-19 10:31:53 -0800 | [diff] [blame] | 69 | LOCI_ASSERT(OF_OBJECT_TO_WBUF(obj) != NULL); |
| 70 | // LOCI_ASSERT(obj is message) |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 71 | of_message_length_set(OF_OBJECT_TO_MESSAGE(obj), bytes); |
| 72 | } |
| 73 | |
| 74 | /**************************************************************** |
| 75 | * TLV16 type/length functions |
| 76 | ****************************************************************/ |
| 77 | |
| 78 | /** |
| 79 | * Many objects are TLVs and use uint16 for the type and length values |
| 80 | * stored on the wire at the beginning of the buffer. |
| 81 | */ |
| 82 | #define TLV16_WIRE_TYPE_OFFSET 0 |
| 83 | #define TLV16_WIRE_LENGTH_OFFSET 2 |
| 84 | |
| 85 | /** |
| 86 | * Get the length field from the wire for a standard TLV |
| 87 | * object that uses uint16 for both type and length. |
| 88 | * @param obj The object being referenced |
| 89 | * @param bytes (out) Where to store the length |
| 90 | */ |
| 91 | |
| 92 | void |
| 93 | of_tlv16_wire_length_get(of_object_t *obj, int *bytes) |
| 94 | { |
| 95 | uint16_t val16; |
| 96 | of_wire_buffer_t *wbuf = OF_OBJECT_TO_WBUF(obj); |
Rich Lane | e57f043 | 2014-02-19 10:31:53 -0800 | [diff] [blame] | 97 | LOCI_ASSERT(wbuf != NULL); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 98 | |
| 99 | of_wire_buffer_u16_get(wbuf, |
| 100 | OF_OBJECT_ABSOLUTE_OFFSET(obj, TLV16_WIRE_LENGTH_OFFSET), &val16); |
| 101 | *bytes = val16; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Set the length field in the wire buffer for a standard TLV |
| 106 | * object that uses uint16 for both type and length. |
| 107 | * @param obj The object being referenced |
| 108 | * @param bytes The length value to use |
| 109 | */ |
| 110 | |
| 111 | void |
| 112 | of_tlv16_wire_length_set(of_object_t *obj, int bytes) |
| 113 | { |
| 114 | of_wire_buffer_t *wbuf = OF_OBJECT_TO_WBUF(obj); |
Rich Lane | e57f043 | 2014-02-19 10:31:53 -0800 | [diff] [blame] | 115 | LOCI_ASSERT(wbuf != NULL); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 116 | |
| 117 | of_wire_buffer_u16_set(wbuf, |
| 118 | OF_OBJECT_ABSOLUTE_OFFSET(obj, TLV16_WIRE_LENGTH_OFFSET), bytes); |
| 119 | } |
| 120 | |
Rich Lane | 713d928 | 2013-12-30 15:21:35 -0800 | [diff] [blame] | 121 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 122 | /**************************************************************** |
| 123 | * OXM type/length functions. |
| 124 | ****************************************************************/ |
| 125 | |
| 126 | /* Where does the OXM type-length header lie in the buffer */ |
| 127 | #define OXM_HDR_OFFSET 0 |
| 128 | |
| 129 | /** |
| 130 | * Get the OXM header (type-length fields) from the wire buffer |
| 131 | * associated with an OXM object |
| 132 | * |
| 133 | * Will return if error; set hdr to the OXM header |
| 134 | */ |
| 135 | |
| 136 | #define _GET_OXM_TYPE_LEN(obj, tl_p, wbuf) do { \ |
| 137 | wbuf = OF_OBJECT_TO_WBUF(obj); \ |
Rich Lane | e57f043 | 2014-02-19 10:31:53 -0800 | [diff] [blame] | 138 | LOCI_ASSERT(wbuf != NULL); \ |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 139 | of_wire_buffer_u32_get(wbuf, \ |
| 140 | OF_OBJECT_ABSOLUTE_OFFSET(obj, OXM_HDR_OFFSET), (tl_p)); \ |
| 141 | } while (0) |
| 142 | |
| 143 | #define _SET_OXM_TYPE_LEN(obj, tl_p, wbuf) do { \ |
| 144 | wbuf = OF_OBJECT_TO_WBUF(obj); \ |
Rich Lane | e57f043 | 2014-02-19 10:31:53 -0800 | [diff] [blame] | 145 | LOCI_ASSERT(wbuf != NULL); \ |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 146 | of_wire_buffer_u32_set(wbuf, \ |
| 147 | OF_OBJECT_ABSOLUTE_OFFSET(obj, OXM_HDR_OFFSET), (tl_p)); \ |
| 148 | } while (0) |
| 149 | |
| 150 | /** |
| 151 | * Get the length of an OXM object from the wire buffer |
| 152 | * @param obj The object whose wire buffer is an OXM type |
| 153 | * @param bytes (out) Where length is stored |
| 154 | */ |
| 155 | |
| 156 | void |
| 157 | of_oxm_wire_length_get(of_object_t *obj, int *bytes) |
| 158 | { |
| 159 | uint32_t type_len; |
| 160 | of_wire_buffer_t *wbuf; |
| 161 | |
| 162 | _GET_OXM_TYPE_LEN(obj, &type_len, wbuf); |
| 163 | *bytes = OF_OXM_LENGTH_GET(type_len); |
| 164 | } |
| 165 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 166 | #define OF_U16_LEN_LENGTH_OFFSET 0 |
| 167 | |
| 168 | /** |
| 169 | * Get the wire length for an object with a uint16 length as first member |
| 170 | * @param obj The object being referenced |
| 171 | * @param bytes Pointer to location to store length |
| 172 | */ |
| 173 | void |
| 174 | of_u16_len_wire_length_get(of_object_t *obj, int *bytes) |
| 175 | { |
| 176 | of_wire_buffer_t *wbuf = OF_OBJECT_TO_WBUF(obj); |
| 177 | uint16_t u16; |
| 178 | |
Rich Lane | e57f043 | 2014-02-19 10:31:53 -0800 | [diff] [blame] | 179 | LOCI_ASSERT(wbuf != NULL); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 180 | |
| 181 | of_wire_buffer_u16_get(wbuf, |
| 182 | OF_OBJECT_ABSOLUTE_OFFSET(obj, OF_U16_LEN_LENGTH_OFFSET), |
| 183 | &u16); |
| 184 | |
| 185 | *bytes = u16; |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Set the wire length for an object with a uint16 length as first member |
| 190 | * @param obj The object being referenced |
| 191 | * @param bytes The length of the object |
| 192 | */ |
| 193 | |
| 194 | void |
| 195 | of_u16_len_wire_length_set(of_object_t *obj, int bytes) |
| 196 | { |
| 197 | of_wire_buffer_t *wbuf = OF_OBJECT_TO_WBUF(obj); |
Rich Lane | e57f043 | 2014-02-19 10:31:53 -0800 | [diff] [blame] | 198 | LOCI_ASSERT(wbuf != NULL); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 199 | |
Rich Lane | e57f043 | 2014-02-19 10:31:53 -0800 | [diff] [blame] | 200 | /* LOCI_ASSERT(obj is u16-len entry) */ |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 201 | |
| 202 | of_wire_buffer_u16_set(wbuf, |
| 203 | OF_OBJECT_ABSOLUTE_OFFSET(obj, OF_U16_LEN_LENGTH_OFFSET), |
| 204 | bytes); |
| 205 | } |
| 206 | |
| 207 | |
| 208 | #define OF_PACKET_QUEUE_LENGTH_OFFSET(ver) \ |
| 209 | (((ver) >= OF_VERSION_1_2) ? 8 : 4) |
| 210 | |
| 211 | /** |
| 212 | * Get the wire length for a packet queue object |
| 213 | * @param obj The object being referenced |
| 214 | * @param bytes Pointer to location to store length |
| 215 | * |
| 216 | * The length is a uint16 at the offset indicated above |
| 217 | */ |
| 218 | void |
| 219 | of_packet_queue_wire_length_get(of_object_t *obj, int *bytes) |
| 220 | { |
| 221 | of_wire_buffer_t *wbuf = OF_OBJECT_TO_WBUF(obj); |
| 222 | uint16_t u16; |
| 223 | int offset; |
| 224 | |
Rich Lane | e57f043 | 2014-02-19 10:31:53 -0800 | [diff] [blame] | 225 | LOCI_ASSERT(wbuf != NULL); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 226 | |
Rich Lane | e57f043 | 2014-02-19 10:31:53 -0800 | [diff] [blame] | 227 | /* LOCI_ASSERT(obj is packet queue obj) */ |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 228 | offset = OF_PACKET_QUEUE_LENGTH_OFFSET(obj->version); |
| 229 | of_wire_buffer_u16_get(wbuf, OF_OBJECT_ABSOLUTE_OFFSET(obj, offset), |
| 230 | &u16); |
| 231 | |
| 232 | *bytes = u16; |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Set the wire length for a 1.2 packet queue object |
| 237 | * @param obj The object being referenced |
| 238 | * @param bytes The length of the object |
| 239 | * |
| 240 | * The length is a uint16 at the offset indicated above |
| 241 | */ |
| 242 | |
| 243 | void |
| 244 | of_packet_queue_wire_length_set(of_object_t *obj, int bytes) |
| 245 | { |
| 246 | of_wire_buffer_t *wbuf = OF_OBJECT_TO_WBUF(obj); |
| 247 | int offset; |
| 248 | |
Rich Lane | e57f043 | 2014-02-19 10:31:53 -0800 | [diff] [blame] | 249 | LOCI_ASSERT(wbuf != NULL); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 250 | |
Rich Lane | e57f043 | 2014-02-19 10:31:53 -0800 | [diff] [blame] | 251 | /* LOCI_ASSERT(obj is packet queue obj) */ |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 252 | offset = OF_PACKET_QUEUE_LENGTH_OFFSET(obj->version); |
| 253 | of_wire_buffer_u16_set(wbuf, OF_OBJECT_ABSOLUTE_OFFSET(obj, offset), |
| 254 | bytes); |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Get the wire length for a meter band stats list |
| 259 | * @param obj The object being referenced |
| 260 | * @param bytes Pointer to location to store length |
| 261 | * |
| 262 | * Must a meter_stats object as a parent |
| 263 | */ |
| 264 | |
| 265 | void |
| 266 | of_list_meter_band_stats_wire_length_get(of_object_t *obj, int *bytes) |
| 267 | { |
Rich Lane | e57f043 | 2014-02-19 10:31:53 -0800 | [diff] [blame] | 268 | LOCI_ASSERT(obj->parent != NULL); |
| 269 | LOCI_ASSERT(obj->parent->object_id == OF_METER_STATS); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 270 | |
| 271 | /* We're counting on the parent being properly initialized already. |
| 272 | * The length is stored in a uint16 at offset 4 of the parent. |
| 273 | */ |
| 274 | *bytes = obj->parent->length - OF_OBJECT_FIXED_LENGTH(obj->parent); |
| 275 | } |
| 276 | |
| 277 | #define OF_METER_STATS_LENGTH_OFFSET 4 |
| 278 | |
| 279 | /** |
| 280 | * Get/set the wire length for a meter stats object |
| 281 | * @param obj The object being referenced |
| 282 | * @param bytes Pointer to location to store length |
| 283 | * |
| 284 | * It's almost a TLV.... |
| 285 | */ |
| 286 | |
| 287 | void |
| 288 | of_meter_stats_wire_length_get(of_object_t *obj, int *bytes) |
| 289 | { |
| 290 | uint16_t val16; |
| 291 | of_wire_buffer_t *wbuf = OF_OBJECT_TO_WBUF(obj); |
Rich Lane | e57f043 | 2014-02-19 10:31:53 -0800 | [diff] [blame] | 292 | LOCI_ASSERT(wbuf != NULL); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 293 | of_wire_buffer_u16_get(wbuf, |
| 294 | OF_OBJECT_ABSOLUTE_OFFSET(obj, OF_METER_STATS_LENGTH_OFFSET), |
| 295 | &val16); |
| 296 | *bytes = val16; |
| 297 | } |
| 298 | |
| 299 | void |
| 300 | of_meter_stats_wire_length_set(of_object_t *obj, int bytes) |
| 301 | { |
| 302 | of_wire_buffer_t *wbuf = OF_OBJECT_TO_WBUF(obj); |
Rich Lane | e57f043 | 2014-02-19 10:31:53 -0800 | [diff] [blame] | 303 | LOCI_ASSERT(wbuf != NULL); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 304 | |
| 305 | of_wire_buffer_u16_set(wbuf, |
| 306 | OF_OBJECT_ABSOLUTE_OFFSET(obj, OF_METER_STATS_LENGTH_OFFSET), bytes); |
| 307 | } |