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