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 | :: |
| 28 | /* Copyright 2012, Big Switch Networks, Inc. */ |
| 29 | |
| 30 | #if !defined(_LOCI_DUMP_H_) |
| 31 | #define _LOCI_DUMP_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 | |
| 45 | typedef int (*loci_obj_dump_f)(loci_writer_f writer, void *cookie, of_object_t *obj); |
| 46 | |
| 47 | /**************************************************************** |
| 48 | * |
| 49 | * Per-datatype dump macros |
| 50 | * |
| 51 | ****************************************************************/ |
| 52 | #define LOCI_DUMP_u8(writer, cookie, val) writer(cookie, "%u", (val)) |
| 53 | #define LOCI_DUMP_u16(writer, cookie, val) writer(cookie, "%u (0x%x)", (val), (val)) |
| 54 | #define LOCI_DUMP_u32(writer, cookie, val) writer(cookie, "%u (0x%x)", (val), (val)) |
| 55 | #define LOCI_DUMP_u64(writer, cookie, val) writer(cookie, "%" PRIu64 "(0x%" PRIx64 ")", (val), (val)) |
| 56 | |
| 57 | /* @todo Add checks for special port numbers */ |
| 58 | #define LOCI_DUMP_port_no(writer, cookie, val) LOCI_DUMP_u32(writer, cookie, val) |
| 59 | #define LOCI_DUMP_fm_cmd(writer, cookie, val) LOCI_DUMP_u16(writer, cookie, val) |
| 60 | |
| 61 | /* @todo Decode wildcards */ |
| 62 | #define LOCI_DUMP_wc_bmap(writer, cookie, val) \ |
| 63 | writer(cookie, "0x%" PRIx64, (val)) |
| 64 | #define LOCI_DUMP_match_bmap(writer, cookie, val) \ |
| 65 | writer(cookie, "0x%" PRIx64, (val)) |
| 66 | |
| 67 | /* @todo Dump first N bytes of data */ |
| 68 | #define LOCI_DUMP_octets(writer, cookie, val) \ |
| 69 | writer(cookie, "%d bytes at location %p", (val).bytes, (val).data) |
| 70 | |
| 71 | #define LOCI_DUMP_mac(writer, cookie, val) \ |
| 72 | writer(cookie, "%02x:%02x:%02x:%02x:%02x:%02x", \ |
| 73 | (val).addr[0], (val).addr[1], (val).addr[2], \ |
| 74 | (val).addr[3], (val).addr[4], (val).addr[5]) |
| 75 | |
| 76 | #define LOCI_DUMP_ipv4(writer, cookie, val) \ |
| 77 | writer(cookie, "%d.%d.%d.%d", val >> 24, (val >> 16) & 0xff, \ |
| 78 | (val >> 8) & 0xff, val & 0xff) |
| 79 | |
| 80 | #define LOCI_DUMP_ipv6(writer, cookie, val) \ |
| 81 | writer(cookie, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", \ |
| 82 | (val).addr[0], (val).addr[1], (val).addr[2], (val).addr[3], \ |
| 83 | (val).addr[4], (val).addr[5], (val).addr[6], (val).addr[7], \ |
| 84 | (val).addr[8], (val).addr[9], (val).addr[10], (val).addr[11], \ |
| 85 | (val).addr[12], (val).addr[13], (val).addr[14], (val).addr[15]) |
| 86 | |
| 87 | #define LOCI_DUMP_string(writer, cookie, val) writer(cookie, "%s", val) |
| 88 | |
| 89 | #define LOCI_DUMP_port_name(writer, cookie, val) LOCI_DUMP_string(writer, cookie, val) |
| 90 | #define LOCI_DUMP_tab_name(writer, cookie, val) LOCI_DUMP_string(writer, cookie, val) |
| 91 | #define LOCI_DUMP_desc_str(writer, cookie, val) LOCI_DUMP_string(writer, cookie, val) |
| 92 | #define LOCI_DUMP_ser_num(writer, cookie, val) LOCI_DUMP_string(writer, cookie, val) |
| 93 | |
| 94 | int loci_dump_match(loci_writer_f writer, void* cookie, of_match_t *match); |
| 95 | #define LOCI_DUMP_match(writer, cookie, val) loci_dump_match(writer, cookie, &val) |
| 96 | |
| 97 | /** |
| 98 | * Generic version for any object |
| 99 | */ |
| 100 | int of_object_dump(loci_writer_f writer, void *cookie, of_object_t *obj); |
| 101 | #endif /* _LOCI_DUMP_H_ */ |