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 | ef7b994 | 2013-11-18 16:29:28 -0800 | [diff] [blame] | 40 | #define OF_INSTRUCTION_EXPERIMENTER_ID_OFFSET 4 |
| 41 | #define OF_INSTRUCTION_EXPERIMENTER_SUBTYPE_OFFSET 8 |
| 42 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 43 | /**************************************************************** |
| 44 | * Top level OpenFlow message length functions |
| 45 | ****************************************************************/ |
| 46 | |
| 47 | /** |
| 48 | * Get the length of a message object as reported on the wire |
| 49 | * @param obj The object to check |
| 50 | * @param bytes (out) Where the length is stored |
| 51 | * @returns OF_ERROR_ code |
| 52 | */ |
| 53 | void |
| 54 | of_object_message_wire_length_get(of_object_t *obj, int *bytes) |
| 55 | { |
Rich Lane | ed79e0d | 2013-03-26 14:30:31 -0700 | [diff] [blame] | 56 | ASSERT(OF_OBJECT_TO_WBUF(obj) != NULL); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 57 | // ASSERT(obj is message) |
| 58 | *bytes = of_message_length_get(OF_OBJECT_TO_MESSAGE(obj)); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Set the length of a message object as reported on the wire |
| 63 | * @param obj The object to check |
| 64 | * @param bytes The new length of the object |
| 65 | * @returns OF_ERROR_ code |
| 66 | */ |
| 67 | void |
| 68 | of_object_message_wire_length_set(of_object_t *obj, int bytes) |
| 69 | { |
Rich Lane | ed79e0d | 2013-03-26 14:30:31 -0700 | [diff] [blame] | 70 | ASSERT(OF_OBJECT_TO_WBUF(obj) != NULL); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 71 | // ASSERT(obj is message) |
| 72 | of_message_length_set(OF_OBJECT_TO_MESSAGE(obj), bytes); |
| 73 | } |
| 74 | |
| 75 | /**************************************************************** |
| 76 | * TLV16 type/length functions |
| 77 | ****************************************************************/ |
| 78 | |
| 79 | /** |
| 80 | * Many objects are TLVs and use uint16 for the type and length values |
| 81 | * stored on the wire at the beginning of the buffer. |
| 82 | */ |
| 83 | #define TLV16_WIRE_TYPE_OFFSET 0 |
| 84 | #define TLV16_WIRE_LENGTH_OFFSET 2 |
| 85 | |
| 86 | /** |
| 87 | * Get the length field from the wire for a standard TLV |
| 88 | * object that uses uint16 for both type and length. |
| 89 | * @param obj The object being referenced |
| 90 | * @param bytes (out) Where to store the length |
| 91 | */ |
| 92 | |
| 93 | void |
| 94 | of_tlv16_wire_length_get(of_object_t *obj, int *bytes) |
| 95 | { |
| 96 | uint16_t val16; |
| 97 | of_wire_buffer_t *wbuf = OF_OBJECT_TO_WBUF(obj); |
| 98 | ASSERT(wbuf != NULL); |
| 99 | |
| 100 | of_wire_buffer_u16_get(wbuf, |
| 101 | OF_OBJECT_ABSOLUTE_OFFSET(obj, TLV16_WIRE_LENGTH_OFFSET), &val16); |
| 102 | *bytes = val16; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Set the length field in the wire buffer for a standard TLV |
| 107 | * object that uses uint16 for both type and length. |
| 108 | * @param obj The object being referenced |
| 109 | * @param bytes The length value to use |
| 110 | */ |
| 111 | |
| 112 | void |
| 113 | of_tlv16_wire_length_set(of_object_t *obj, int bytes) |
| 114 | { |
| 115 | of_wire_buffer_t *wbuf = OF_OBJECT_TO_WBUF(obj); |
| 116 | ASSERT(wbuf != NULL); |
| 117 | |
| 118 | of_wire_buffer_u16_set(wbuf, |
| 119 | OF_OBJECT_ABSOLUTE_OFFSET(obj, TLV16_WIRE_LENGTH_OFFSET), bytes); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Get the type field from the wire for a standard TLV object that uses |
| 124 | * uint16 for both type and length. |
| 125 | * @param obj The object being referenced |
| 126 | * @param wire_type (out) Where to store the type |
| 127 | */ |
| 128 | |
| 129 | static void |
| 130 | of_tlv16_wire_type_get(of_object_t *obj, int *wire_type) |
| 131 | { |
| 132 | uint16_t val16; |
| 133 | of_wire_buffer_t *wbuf = OF_OBJECT_TO_WBUF(obj); |
| 134 | |
| 135 | of_wire_buffer_u16_get(wbuf, OF_OBJECT_ABSOLUTE_OFFSET(obj, |
| 136 | TLV16_WIRE_TYPE_OFFSET), &val16); |
| 137 | |
| 138 | *wire_type = val16; |
| 139 | } |
| 140 | |
| 141 | /** |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 142 | * Get the object ID of an extended action |
| 143 | * @param obj The object being referenced |
| 144 | * @param id Where to store the object ID |
| 145 | * @fixme: This should be auto generated |
| 146 | * |
| 147 | * If unable to map to known extension, set id to generic "experimenter" |
| 148 | */ |
| 149 | |
| 150 | #define OF_ACTION_EXPERIMENTER_ID_OFFSET 4 |
| 151 | #define OF_ACTION_EXPERIMENTER_SUBTYPE_OFFSET 8 |
| 152 | |
| 153 | |
| 154 | static void |
| 155 | extension_action_object_id_get(of_object_t *obj, of_object_id_t *id) |
| 156 | { |
| 157 | uint32_t exp_id; |
| 158 | uint8_t *buf; |
| 159 | |
| 160 | *id = OF_ACTION_EXPERIMENTER; |
| 161 | |
| 162 | buf = OF_OBJECT_BUFFER_INDEX(obj, 0); |
| 163 | |
| 164 | buf_u32_get(buf + OF_ACTION_EXPERIMENTER_ID_OFFSET, &exp_id); |
| 165 | |
| 166 | switch (exp_id) { |
| 167 | case OF_EXPERIMENTER_ID_BSN: { |
| 168 | uint32_t subtype; |
| 169 | buf_u32_get(buf + OF_ACTION_EXPERIMENTER_SUBTYPE_OFFSET, &subtype); |
| 170 | switch (subtype) { |
| 171 | case 1: *id = OF_ACTION_BSN_MIRROR; break; |
| 172 | case 2: *id = OF_ACTION_BSN_SET_TUNNEL_DST; break; |
| 173 | } |
| 174 | break; |
| 175 | } |
| 176 | case OF_EXPERIMENTER_ID_NICIRA: { |
| 177 | uint16_t subtype; |
| 178 | buf_u16_get(buf + OF_ACTION_EXPERIMENTER_SUBTYPE_OFFSET, &subtype); |
| 179 | switch (subtype) { |
| 180 | case 18: *id = OF_ACTION_NICIRA_DEC_TTL; break; |
| 181 | } |
| 182 | break; |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | /** |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 188 | * Get the object ID of an extended action |
| 189 | * @param obj The object being referenced |
| 190 | * @param id Where to store the object ID |
| 191 | * @fixme: This should be auto generated |
| 192 | * |
| 193 | * If unable to map to known extension, set id to generic "experimenter" |
| 194 | */ |
| 195 | |
| 196 | static void |
| 197 | extension_action_id_object_id_get(of_object_t *obj, of_object_id_t *id) |
| 198 | { |
| 199 | uint32_t exp_id; |
| 200 | uint8_t *buf; |
| 201 | |
| 202 | *id = OF_ACTION_ID_EXPERIMENTER; |
| 203 | |
| 204 | buf = OF_OBJECT_BUFFER_INDEX(obj, 0); |
| 205 | |
| 206 | buf_u32_get(buf + OF_ACTION_EXPERIMENTER_ID_OFFSET, &exp_id); |
| 207 | |
| 208 | switch (exp_id) { |
| 209 | case OF_EXPERIMENTER_ID_BSN: { |
| 210 | uint32_t subtype; |
| 211 | buf_u32_get(buf + OF_ACTION_EXPERIMENTER_SUBTYPE_OFFSET, &subtype); |
| 212 | switch (subtype) { |
| 213 | case 1: *id = OF_ACTION_ID_BSN_MIRROR; break; |
| 214 | case 2: *id = OF_ACTION_ID_BSN_SET_TUNNEL_DST; break; |
| 215 | } |
| 216 | break; |
| 217 | } |
| 218 | case OF_EXPERIMENTER_ID_NICIRA: { |
| 219 | uint16_t subtype; |
| 220 | buf_u16_get(buf + OF_ACTION_EXPERIMENTER_SUBTYPE_OFFSET, &subtype); |
| 221 | switch (subtype) { |
| 222 | case 18: *id = OF_ACTION_ID_NICIRA_DEC_TTL; break; |
| 223 | } |
| 224 | break; |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | |
| 230 | /** |
| 231 | * Get the object ID based on the wire buffer for an action object |
| 232 | * @param obj The object being referenced |
| 233 | * @param id Where to store the object ID |
| 234 | */ |
| 235 | |
| 236 | |
| 237 | void |
| 238 | of_action_wire_object_id_get(of_object_t *obj, of_object_id_t *id) |
| 239 | { |
| 240 | int wire_type; |
| 241 | |
| 242 | of_tlv16_wire_type_get(obj, &wire_type); |
| 243 | if (wire_type == OF_EXPERIMENTER_TYPE) { |
| 244 | extension_action_object_id_get(obj, id); |
| 245 | return; |
| 246 | } |
| 247 | |
| 248 | ASSERT(wire_type >= 0 && wire_type < OF_ACTION_ITEM_COUNT); |
| 249 | |
| 250 | *id = of_action_type_to_id[obj->version][wire_type]; |
| 251 | ASSERT(*id != OF_OBJECT_INVALID); |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * Get the object ID based on the wire buffer for an action ID object |
| 256 | * @param obj The object being referenced |
| 257 | * @param id Where to store the object ID |
| 258 | */ |
| 259 | |
| 260 | |
| 261 | void |
| 262 | of_action_id_wire_object_id_get(of_object_t *obj, of_object_id_t *id) |
| 263 | { |
| 264 | int wire_type; |
| 265 | |
| 266 | of_tlv16_wire_type_get(obj, &wire_type); |
| 267 | if (wire_type == OF_EXPERIMENTER_TYPE) { |
| 268 | extension_action_id_object_id_get(obj, id); |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | ASSERT(wire_type >= 0 && wire_type < OF_ACTION_ID_ITEM_COUNT); |
| 273 | |
| 274 | *id = of_action_id_type_to_id[obj->version][wire_type]; |
| 275 | ASSERT(*id != OF_OBJECT_INVALID); |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * @fixme to do when we have instruction extensions |
| 280 | * See extension_action above |
| 281 | */ |
| 282 | |
| 283 | static int |
| 284 | extension_instruction_object_id_get(of_object_t *obj, of_object_id_t *id) |
| 285 | { |
Rich Lane | ef7b994 | 2013-11-18 16:29:28 -0800 | [diff] [blame] | 286 | uint32_t exp_id; |
| 287 | uint8_t *buf; |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 288 | |
| 289 | *id = OF_INSTRUCTION_EXPERIMENTER; |
| 290 | |
Rich Lane | ef7b994 | 2013-11-18 16:29:28 -0800 | [diff] [blame] | 291 | buf = OF_OBJECT_BUFFER_INDEX(obj, 0); |
| 292 | |
| 293 | buf_u32_get(buf + OF_INSTRUCTION_EXPERIMENTER_ID_OFFSET, &exp_id); |
| 294 | |
| 295 | switch (exp_id) { |
| 296 | case OF_EXPERIMENTER_ID_BSN: { |
| 297 | uint32_t subtype; |
| 298 | buf_u32_get(buf + OF_INSTRUCTION_EXPERIMENTER_SUBTYPE_OFFSET, &subtype); |
| 299 | switch (subtype) { |
| 300 | case 0: *id = OF_INSTRUCTION_BSN_DISABLE_SRC_MAC_CHECK; break; |
| 301 | } |
| 302 | break; |
| 303 | } |
| 304 | } |
| 305 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 306 | return OF_ERROR_NONE; |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * Get the object ID based on the wire buffer for an instruction object |
| 311 | * @param obj The object being referenced |
| 312 | * @param id Where to store the object ID |
| 313 | */ |
| 314 | |
| 315 | void |
| 316 | of_instruction_wire_object_id_get(of_object_t *obj, of_object_id_t *id) |
| 317 | { |
| 318 | int wire_type; |
| 319 | |
| 320 | of_tlv16_wire_type_get(obj, &wire_type); |
| 321 | if (wire_type == OF_EXPERIMENTER_TYPE) { |
| 322 | extension_instruction_object_id_get(obj, id); |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | ASSERT(wire_type >= 0 && wire_type < OF_INSTRUCTION_ITEM_COUNT); |
| 327 | |
| 328 | *id = of_instruction_type_to_id[obj->version][wire_type]; |
| 329 | ASSERT(*id != OF_OBJECT_INVALID); |
| 330 | } |
| 331 | |
| 332 | |
| 333 | /** |
| 334 | * @fixme to do when we have queue_prop extensions |
| 335 | * See extension_action above |
| 336 | */ |
| 337 | |
| 338 | static void |
| 339 | extension_queue_prop_object_id_get(of_object_t *obj, of_object_id_t *id) |
| 340 | { |
| 341 | (void)obj; |
| 342 | |
| 343 | *id = OF_QUEUE_PROP_EXPERIMENTER; |
| 344 | } |
| 345 | |
| 346 | /** |
| 347 | * Get the object ID based on the wire buffer for an queue_prop object |
| 348 | * @param obj The object being referenced |
| 349 | * @param id Where to store the object ID |
| 350 | */ |
| 351 | |
| 352 | void |
| 353 | of_queue_prop_wire_object_id_get(of_object_t *obj, of_object_id_t *id) |
| 354 | { |
| 355 | int wire_type; |
| 356 | |
| 357 | of_tlv16_wire_type_get(obj, &wire_type); |
| 358 | if (wire_type == OF_EXPERIMENTER_TYPE) { |
| 359 | extension_queue_prop_object_id_get(obj, id); |
| 360 | return; |
| 361 | } |
| 362 | |
| 363 | ASSERT(wire_type >= 0 && wire_type < OF_QUEUE_PROP_ITEM_COUNT); |
| 364 | |
| 365 | *id = of_queue_prop_type_to_id[obj->version][wire_type]; |
| 366 | ASSERT(*id != OF_OBJECT_INVALID); |
| 367 | } |
| 368 | |
| 369 | |
| 370 | /** |
| 371 | * @fixme to do when we have table_feature_prop extensions |
| 372 | * See extension_action above |
| 373 | */ |
| 374 | |
| 375 | static void |
| 376 | extension_table_feature_prop_object_id_get(of_object_t *obj, of_object_id_t *id) |
| 377 | { |
| 378 | (void)obj; |
| 379 | |
| 380 | *id = OF_TABLE_FEATURE_PROP_EXPERIMENTER; |
| 381 | } |
| 382 | |
| 383 | /** |
| 384 | * Table feature property object ID determination |
| 385 | * |
| 386 | * @param obj The object being referenced |
| 387 | * @param id Where to store the object ID |
| 388 | */ |
| 389 | |
| 390 | void |
| 391 | of_table_feature_prop_wire_object_id_get(of_object_t *obj, of_object_id_t *id) |
| 392 | { |
| 393 | int wire_type; |
| 394 | |
| 395 | of_tlv16_wire_type_get(obj, &wire_type); |
| 396 | if (wire_type == OF_EXPERIMENTER_TYPE) { |
| 397 | extension_table_feature_prop_object_id_get(obj, id); |
| 398 | return; |
| 399 | } |
| 400 | |
| 401 | ASSERT(wire_type >= 0 && wire_type < OF_TABLE_FEATURE_PROP_ITEM_COUNT); |
| 402 | |
| 403 | *id = of_table_feature_prop_type_to_id[obj->version][wire_type]; |
| 404 | ASSERT(*id != OF_OBJECT_INVALID); |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Get the object ID based on the wire buffer for meter_band object |
| 409 | * @param obj The object being referenced |
| 410 | * @param id Where to store the object ID |
| 411 | */ |
| 412 | |
| 413 | void |
| 414 | of_meter_band_wire_object_id_get(of_object_t *obj, of_object_id_t *id) |
| 415 | { |
| 416 | int wire_type; |
| 417 | |
| 418 | of_tlv16_wire_type_get(obj, &wire_type); |
| 419 | if (wire_type == OF_EXPERIMENTER_TYPE) { |
| 420 | *id = OF_METER_BAND_EXPERIMENTER; |
| 421 | return; |
| 422 | } |
| 423 | |
| 424 | ASSERT(wire_type >= 0 && wire_type < OF_METER_BAND_ITEM_COUNT); |
| 425 | |
| 426 | *id = of_meter_band_type_to_id[obj->version][wire_type]; |
| 427 | ASSERT(*id != OF_OBJECT_INVALID); |
| 428 | } |
| 429 | |
| 430 | /** |
| 431 | * Get the object ID based on the wire buffer for a hello_elem object |
| 432 | * @param obj The object being referenced |
| 433 | * @param id Where to store the object ID |
| 434 | */ |
| 435 | |
| 436 | void |
| 437 | of_hello_elem_wire_object_id_get(of_object_t *obj, of_object_id_t *id) |
| 438 | { |
| 439 | int wire_type; |
| 440 | |
| 441 | of_tlv16_wire_type_get(obj, &wire_type); |
| 442 | ASSERT(wire_type >= 0 && wire_type < OF_HELLO_ELEM_ITEM_COUNT); |
| 443 | *id = of_hello_elem_type_to_id[obj->version][wire_type]; |
| 444 | ASSERT(*id != OF_OBJECT_INVALID); |
| 445 | } |
| 446 | |
| 447 | /**************************************************************** |
| 448 | * OXM type/length functions. |
| 449 | ****************************************************************/ |
| 450 | |
| 451 | /* Where does the OXM type-length header lie in the buffer */ |
| 452 | #define OXM_HDR_OFFSET 0 |
| 453 | |
| 454 | /** |
| 455 | * Get the OXM header (type-length fields) from the wire buffer |
| 456 | * associated with an OXM object |
| 457 | * |
| 458 | * Will return if error; set hdr to the OXM header |
| 459 | */ |
| 460 | |
| 461 | #define _GET_OXM_TYPE_LEN(obj, tl_p, wbuf) do { \ |
| 462 | wbuf = OF_OBJECT_TO_WBUF(obj); \ |
| 463 | ASSERT(wbuf != NULL); \ |
| 464 | of_wire_buffer_u32_get(wbuf, \ |
| 465 | OF_OBJECT_ABSOLUTE_OFFSET(obj, OXM_HDR_OFFSET), (tl_p)); \ |
| 466 | } while (0) |
| 467 | |
| 468 | #define _SET_OXM_TYPE_LEN(obj, tl_p, wbuf) do { \ |
| 469 | wbuf = OF_OBJECT_TO_WBUF(obj); \ |
| 470 | ASSERT(wbuf != NULL); \ |
| 471 | of_wire_buffer_u32_set(wbuf, \ |
| 472 | OF_OBJECT_ABSOLUTE_OFFSET(obj, OXM_HDR_OFFSET), (tl_p)); \ |
| 473 | } while (0) |
| 474 | |
| 475 | /** |
| 476 | * Get the length of an OXM object from the wire buffer |
| 477 | * @param obj The object whose wire buffer is an OXM type |
| 478 | * @param bytes (out) Where length is stored |
| 479 | */ |
| 480 | |
| 481 | void |
| 482 | of_oxm_wire_length_get(of_object_t *obj, int *bytes) |
| 483 | { |
| 484 | uint32_t type_len; |
| 485 | of_wire_buffer_t *wbuf; |
| 486 | |
| 487 | _GET_OXM_TYPE_LEN(obj, &type_len, wbuf); |
| 488 | *bytes = OF_OXM_LENGTH_GET(type_len); |
| 489 | } |
| 490 | |
| 491 | /** |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 492 | * Get the object ID of an OXM object based on the wire buffer type |
| 493 | * @param obj The object whose wire buffer is an OXM type |
| 494 | * @param id (out) Where the ID is stored |
| 495 | */ |
| 496 | |
| 497 | void |
| 498 | of_oxm_wire_object_id_get(of_object_t *obj, of_object_id_t *id) |
| 499 | { |
| 500 | uint32_t type_len; |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 501 | of_wire_buffer_t *wbuf; |
| 502 | |
| 503 | _GET_OXM_TYPE_LEN(obj, &type_len, wbuf); |
Rich Lane | d8d29c9 | 2013-09-24 13:46:42 -0700 | [diff] [blame] | 504 | *id = of_oxm_to_object_id(type_len, obj->version); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 507 | #define OF_U16_LEN_LENGTH_OFFSET 0 |
| 508 | |
| 509 | /** |
| 510 | * Get the wire length for an object with a uint16 length as first member |
| 511 | * @param obj The object being referenced |
| 512 | * @param bytes Pointer to location to store length |
| 513 | */ |
| 514 | void |
| 515 | of_u16_len_wire_length_get(of_object_t *obj, int *bytes) |
| 516 | { |
| 517 | of_wire_buffer_t *wbuf = OF_OBJECT_TO_WBUF(obj); |
| 518 | uint16_t u16; |
| 519 | |
| 520 | ASSERT(wbuf != NULL); |
| 521 | |
| 522 | of_wire_buffer_u16_get(wbuf, |
| 523 | OF_OBJECT_ABSOLUTE_OFFSET(obj, OF_U16_LEN_LENGTH_OFFSET), |
| 524 | &u16); |
| 525 | |
| 526 | *bytes = u16; |
| 527 | } |
| 528 | |
| 529 | /** |
| 530 | * Set the wire length for an object with a uint16 length as first member |
| 531 | * @param obj The object being referenced |
| 532 | * @param bytes The length of the object |
| 533 | */ |
| 534 | |
| 535 | void |
| 536 | of_u16_len_wire_length_set(of_object_t *obj, int bytes) |
| 537 | { |
| 538 | of_wire_buffer_t *wbuf = OF_OBJECT_TO_WBUF(obj); |
| 539 | ASSERT(wbuf != NULL); |
| 540 | |
| 541 | /* ASSERT(obj is u16-len entry) */ |
| 542 | |
| 543 | of_wire_buffer_u16_set(wbuf, |
| 544 | OF_OBJECT_ABSOLUTE_OFFSET(obj, OF_U16_LEN_LENGTH_OFFSET), |
| 545 | bytes); |
| 546 | } |
| 547 | |
| 548 | |
| 549 | #define OF_PACKET_QUEUE_LENGTH_OFFSET(ver) \ |
| 550 | (((ver) >= OF_VERSION_1_2) ? 8 : 4) |
| 551 | |
| 552 | /** |
| 553 | * Get the wire length for a packet queue object |
| 554 | * @param obj The object being referenced |
| 555 | * @param bytes Pointer to location to store length |
| 556 | * |
| 557 | * The length is a uint16 at the offset indicated above |
| 558 | */ |
| 559 | void |
| 560 | of_packet_queue_wire_length_get(of_object_t *obj, int *bytes) |
| 561 | { |
| 562 | of_wire_buffer_t *wbuf = OF_OBJECT_TO_WBUF(obj); |
| 563 | uint16_t u16; |
| 564 | int offset; |
| 565 | |
| 566 | ASSERT(wbuf != NULL); |
| 567 | |
| 568 | /* ASSERT(obj is packet queue obj) */ |
| 569 | offset = OF_PACKET_QUEUE_LENGTH_OFFSET(obj->version); |
| 570 | of_wire_buffer_u16_get(wbuf, OF_OBJECT_ABSOLUTE_OFFSET(obj, offset), |
| 571 | &u16); |
| 572 | |
| 573 | *bytes = u16; |
| 574 | } |
| 575 | |
| 576 | /** |
| 577 | * Set the wire length for a 1.2 packet queue object |
| 578 | * @param obj The object being referenced |
| 579 | * @param bytes The length of the object |
| 580 | * |
| 581 | * The length is a uint16 at the offset indicated above |
| 582 | */ |
| 583 | |
| 584 | void |
| 585 | of_packet_queue_wire_length_set(of_object_t *obj, int bytes) |
| 586 | { |
| 587 | of_wire_buffer_t *wbuf = OF_OBJECT_TO_WBUF(obj); |
| 588 | int offset; |
| 589 | |
| 590 | ASSERT(wbuf != NULL); |
| 591 | |
| 592 | /* ASSERT(obj is packet queue obj) */ |
| 593 | offset = OF_PACKET_QUEUE_LENGTH_OFFSET(obj->version); |
| 594 | of_wire_buffer_u16_set(wbuf, OF_OBJECT_ABSOLUTE_OFFSET(obj, offset), |
| 595 | bytes); |
| 596 | } |
| 597 | |
| 598 | /** |
| 599 | * Get the wire length for a meter band stats list |
| 600 | * @param obj The object being referenced |
| 601 | * @param bytes Pointer to location to store length |
| 602 | * |
| 603 | * Must a meter_stats object as a parent |
| 604 | */ |
| 605 | |
| 606 | void |
| 607 | of_list_meter_band_stats_wire_length_get(of_object_t *obj, int *bytes) |
| 608 | { |
| 609 | ASSERT(obj->parent != NULL); |
| 610 | ASSERT(obj->parent->object_id == OF_METER_STATS); |
| 611 | |
| 612 | /* We're counting on the parent being properly initialized already. |
| 613 | * The length is stored in a uint16 at offset 4 of the parent. |
| 614 | */ |
| 615 | *bytes = obj->parent->length - OF_OBJECT_FIXED_LENGTH(obj->parent); |
| 616 | } |
| 617 | |
| 618 | #define OF_METER_STATS_LENGTH_OFFSET 4 |
| 619 | |
| 620 | /** |
| 621 | * Get/set the wire length for a meter stats object |
| 622 | * @param obj The object being referenced |
| 623 | * @param bytes Pointer to location to store length |
| 624 | * |
| 625 | * It's almost a TLV.... |
| 626 | */ |
| 627 | |
| 628 | void |
| 629 | of_meter_stats_wire_length_get(of_object_t *obj, int *bytes) |
| 630 | { |
| 631 | uint16_t val16; |
| 632 | of_wire_buffer_t *wbuf = OF_OBJECT_TO_WBUF(obj); |
| 633 | ASSERT(wbuf != NULL); |
| 634 | of_wire_buffer_u16_get(wbuf, |
| 635 | OF_OBJECT_ABSOLUTE_OFFSET(obj, OF_METER_STATS_LENGTH_OFFSET), |
| 636 | &val16); |
| 637 | *bytes = val16; |
| 638 | } |
| 639 | |
| 640 | void |
| 641 | of_meter_stats_wire_length_set(of_object_t *obj, int bytes) |
| 642 | { |
| 643 | of_wire_buffer_t *wbuf = OF_OBJECT_TO_WBUF(obj); |
| 644 | ASSERT(wbuf != NULL); |
| 645 | |
| 646 | of_wire_buffer_u16_set(wbuf, |
| 647 | OF_OBJECT_ABSOLUTE_OFFSET(obj, OF_METER_STATS_LENGTH_OFFSET), bytes); |
| 648 | } |
| 649 | |
| 650 | /* |
| 651 | * Non-message extension push wire values |
| 652 | */ |
| 653 | |
| 654 | int |
| 655 | of_extension_object_wire_push(of_object_t *obj) |
| 656 | { |
| 657 | of_action_bsn_mirror_t *action_mirror; |
| 658 | of_action_id_bsn_mirror_t *action_id_mirror; |
| 659 | of_action_bsn_set_tunnel_dst_t *action_set_tunnel_dst; |
| 660 | of_action_id_bsn_set_tunnel_dst_t *action_id_set_tunnel_dst; |
| 661 | of_action_nicira_dec_ttl_t *action_nicira_dec_ttl; |
| 662 | of_action_id_nicira_dec_ttl_t *action_id_nicira_dec_ttl; |
| 663 | |
| 664 | /* Push exp type, subtype */ |
| 665 | switch (obj->object_id) { |
| 666 | case OF_ACTION_BSN_MIRROR: |
| 667 | action_mirror = (of_action_bsn_mirror_t *)obj; |
| 668 | of_action_bsn_mirror_experimenter_set(action_mirror, |
| 669 | OF_EXPERIMENTER_ID_BSN); |
| 670 | of_action_bsn_mirror_subtype_set(action_mirror, 1); |
| 671 | break; |
| 672 | case OF_ACTION_ID_BSN_MIRROR: |
| 673 | action_id_mirror = (of_action_id_bsn_mirror_t *)obj; |
| 674 | of_action_id_bsn_mirror_experimenter_set(action_id_mirror, |
| 675 | OF_EXPERIMENTER_ID_BSN); |
| 676 | of_action_id_bsn_mirror_subtype_set(action_id_mirror, 1); |
| 677 | break; |
| 678 | case OF_ACTION_BSN_SET_TUNNEL_DST: |
| 679 | action_set_tunnel_dst = (of_action_bsn_set_tunnel_dst_t *)obj; |
| 680 | of_action_bsn_set_tunnel_dst_experimenter_set(action_set_tunnel_dst, |
| 681 | OF_EXPERIMENTER_ID_BSN); |
| 682 | of_action_bsn_set_tunnel_dst_subtype_set(action_set_tunnel_dst, 2); |
| 683 | break; |
| 684 | case OF_ACTION_ID_BSN_SET_TUNNEL_DST: |
| 685 | action_id_set_tunnel_dst = (of_action_id_bsn_set_tunnel_dst_t *)obj; |
| 686 | of_action_id_bsn_set_tunnel_dst_experimenter_set(action_id_set_tunnel_dst, |
| 687 | OF_EXPERIMENTER_ID_BSN); |
| 688 | of_action_id_bsn_set_tunnel_dst_subtype_set(action_id_set_tunnel_dst, 2); |
| 689 | break; |
| 690 | case OF_ACTION_NICIRA_DEC_TTL: |
| 691 | action_nicira_dec_ttl = (of_action_nicira_dec_ttl_t *)obj; |
| 692 | of_action_nicira_dec_ttl_experimenter_set(action_nicira_dec_ttl, |
| 693 | OF_EXPERIMENTER_ID_NICIRA); |
| 694 | of_action_nicira_dec_ttl_subtype_set(action_nicira_dec_ttl, 18); |
| 695 | break; |
| 696 | case OF_ACTION_ID_NICIRA_DEC_TTL: |
| 697 | action_id_nicira_dec_ttl = (of_action_id_nicira_dec_ttl_t *)obj; |
| 698 | of_action_id_nicira_dec_ttl_experimenter_set(action_id_nicira_dec_ttl, |
| 699 | OF_EXPERIMENTER_ID_NICIRA); |
| 700 | of_action_id_nicira_dec_ttl_subtype_set(action_id_nicira_dec_ttl, 18); |
| 701 | break; |
| 702 | default: |
| 703 | break; |
| 704 | } |
| 705 | |
| 706 | return OF_ERROR_NONE; |
| 707 | } |
Rich Lane | 353a79f | 2013-11-13 10:39:56 -0800 | [diff] [blame] | 708 | |
| 709 | int |
| 710 | of_experimenter_stats_request_to_object_id(uint32_t experimenter, uint32_t subtype, int ver) |
| 711 | { |
| 712 | switch (experimenter) { |
| 713 | case OF_EXPERIMENTER_ID_BSN: |
| 714 | switch (subtype) { |
| 715 | case 1: return OF_BSN_LACP_STATS_REQUEST; |
Wilson Ng | 45386fb | 2013-12-03 13:46:42 -0800 | [diff] [blame] | 716 | case 6: return OF_BSN_SWITCH_PIPELINE_STATS_REQUEST; |
xinwu | 54ceaca | 2013-12-04 17:02:27 -0800 | [diff] [blame] | 717 | case 8: return OF_BSN_PORT_COUNTER_STATS_REQUEST; |
| 718 | case 9: return OF_BSN_VLAN_COUNTER_STATS_REQUEST; |
Rich Lane | 353a79f | 2013-11-13 10:39:56 -0800 | [diff] [blame] | 719 | } |
| 720 | } |
| 721 | return OF_OBJECT_INVALID; |
| 722 | } |
| 723 | |
| 724 | int |
| 725 | of_experimenter_stats_reply_to_object_id(uint32_t experimenter, uint32_t subtype, int ver) |
| 726 | { |
| 727 | switch (experimenter) { |
| 728 | case OF_EXPERIMENTER_ID_BSN: |
| 729 | switch (subtype) { |
| 730 | case 1: return OF_BSN_LACP_STATS_REPLY; |
Wilson Ng | 45386fb | 2013-12-03 13:46:42 -0800 | [diff] [blame] | 731 | case 6: return OF_BSN_SWITCH_PIPELINE_STATS_REPLY; |
xinwu | 54ceaca | 2013-12-04 17:02:27 -0800 | [diff] [blame] | 732 | case 8: return OF_BSN_PORT_COUNTER_STATS_REPLY; |
| 733 | case 9: return OF_BSN_VLAN_COUNTER_STATS_REPLY; |
Rich Lane | 353a79f | 2013-11-13 10:39:56 -0800 | [diff] [blame] | 734 | } |
| 735 | } |
| 736 | return OF_OBJECT_INVALID; |
| 737 | } |