blob: a227645a9f2330dfcdedf251d0519dd6600af6ba [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#if !defined(_LOCI_SHOW_H_)
31#define _LOCI_SHOW_H_
32
33#include <loci/loci_base.h>
34#include <loci/of_match.h>
35#include <stdio.h>
36
37/* g++ requires this to pick up PRI, etc.
38 * See http://gcc.gnu.org/ml/gcc-help/2006-10/msg00223.html
39 */
40#if !defined(__STDC_FORMAT_MACROS)
41#define __STDC_FORMAT_MACROS
42#endif
43#include <inttypes.h>
44
45typedef int (*loci_obj_show_f)(loci_writer_f writer,
46 void *cookie, of_object_t *obj);
47
48/****************************************************************
49 *
50 * Per-datatype dump macros
51 *
52 ****************************************************************/
53#define LOCI_SHOW_u8(writer, cookie, val) writer(cookie, "%u", (val))
54#define LOCI_SHOW_u16(writer, cookie, val) writer(cookie, "%u (0x%x)", (val), (val))
55#define LOCI_SHOW_u32(writer, cookie, val) writer(cookie, "%u (0x%x)", (val), (val))
56#define LOCI_SHOW_u64(writer, cookie, val) writer(cookie, "%" PRIu64 "(0x%" PRIx64 ")", (val), (val))
57
58#define LOCI_SHOW_D_INT(cookie, macro, val) writer(cookie, "%" macro , val);
59#define LOCI_SHOW_X_INT(cookie, macro, val) writer(cookie, "0x%" macro, val);
60
61#define LOCI_SHOW_x8(writer, cookie, val) LOCI_SHOW_X_INT(cookie, PRIx8, val)
62#define LOCI_SHOW_x16(writer, cookie, val) LOCI_SHOW_X_INT(cookie, PRIx16, val)
63#define LOCI_SHOW_x32(writer, cookie, val) LOCI_SHOW_X_INT(cookie, PRIx32, val)
64#define LOCI_SHOW_x64(writer, cookie, val) LOCI_SHOW_X_INT(cookie, PRIx64, val)
65#define LOCI_SHOW_d8(writer, cookie, val) LOCI_SHOW_D_INT(cookie, PRId8, val)
66#define LOCI_SHOW_d16(writer, cookie, val) LOCI_SHOW_D_INT(cookie, PRId16, val)
67#define LOCI_SHOW_d32(writer, cookie, val) LOCI_SHOW_D_INT(cookie, PRId32, val)
68#define LOCI_SHOW_d64(writer, cookie, val) LOCI_SHOW_D_INT(cookie, PRId64, val)
69
Rich Lanea06d0c32013-03-25 08:52:03 -070070/* @todo Add checks for special port numbers */
71#define LOCI_SHOW_port_no(writer, cookie, val) writer(cookie, "%d", val)
72#define LOCI_SHOW_fm_cmd(writer, cookie, val) LOCI_SHOW_u16(writer, cookie, val)
73
74/* @todo Decode wildcards */
75#define LOCI_SHOW_wc_bmap(writer, cookie, val) \
76 writer(cookie, "0x%" PRIx64, (val))
77#define LOCI_SHOW_match_bmap(writer, cookie, val) \
78 writer(cookie, "0x%" PRIx64, (val))
79
80/* @todo Dump first N bytes of data */
81#define LOCI_SHOW_octets(writer, cookie, val) \
82 writer(cookie, "%d bytes at location %p", (val).bytes, (val).data)
83
84#define LOCI_SHOW_mac(writer, cookie, val) \
85 writer(cookie, "%02x:%02x:%02x:%02x:%02x:%02x", \
86 (val).addr[0], (val).addr[1], (val).addr[2], \
87 (val).addr[3], (val).addr[4], (val).addr[5])
88
89#define LOCI_SHOW_ipv4(writer, cookie, val) \
90 writer(cookie, "%d.%d.%d.%d", val >> 24, (val >> 16) & 0xff, \
91 (val >> 8) & 0xff, val & 0xff)
92
93#define LOCI_SHOW_ipv6(writer, cookie, val) \
94 writer(cookie, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", \
95 (val).addr[0], (val).addr[1], (val).addr[2], (val).addr[3], \
96 (val).addr[4], (val).addr[5], (val).addr[6], (val).addr[7], \
97 (val).addr[8], (val).addr[9], (val).addr[10], (val).addr[11], \
98 (val).addr[12], (val).addr[13], (val).addr[14], (val).addr[15])
99
100#define LOCI_SHOW_string(writer, cookie, val) writer(cookie, "%s", val)
101
102#define LOCI_SHOW_port_name(writer, cookie, val) LOCI_SHOW_string(writer, cookie, val)
Kiran Poolaa9167ff2013-09-19 16:34:54 -0700103#define LOCI_SHOW_port_name_if_name(writer, cookie, val) LOCI_SHOW_string(writer, cookie, val)
Rich Lanea06d0c32013-03-25 08:52:03 -0700104#define LOCI_SHOW_tab_name(writer, cookie, val) LOCI_SHOW_string(writer, cookie, val)
105#define LOCI_SHOW_desc_str(writer, cookie, val) LOCI_SHOW_string(writer, cookie, val)
106#define LOCI_SHOW_ser_num(writer, cookie, val) LOCI_SHOW_string(writer, cookie, val)
Rich Lanef8a3d002014-03-19 13:33:52 -0700107#define LOCI_SHOW_str64(writer, cookie, val) LOCI_SHOW_string(writer, cookie, val)
Rich Lanea06d0c32013-03-25 08:52:03 -0700108
109int loci_show_match(loci_writer_f writer, void *cookie, of_match_t *match);
110#define LOCI_SHOW_match(writer, cookie, val) loci_show_match(writer, cookie, &val)
111
Rich Lane3b2fd832013-09-24 13:44:08 -0700112#define LOCI_SHOW_bitmap_128(writer, cookie, val) writer(cookie, "%" PRIx64 "%" PRIx64, (val).hi, (val).lo)
113
Rich Lanefab0c822013-12-30 11:46:48 -0800114#define LOCI_SHOW_checksum_128(writer, cookie, val) writer(cookie, "%016" PRIx64 "%016" PRIx64, (val).hi, (val).lo)
115
Rich Lanea06d0c32013-03-25 08:52:03 -0700116/**
117 * Generic version for any object
118 */
119int of_object_show(loci_writer_f writer, void *cookie, of_object_t *obj);
120
Rich Lanea06d0c32013-03-25 08:52:03 -0700121#endif /* _LOCI_SHOW_H_ */