summaryrefslogtreecommitdiffstats
path: root/src/vnet/ip/ip_format_fns.h
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2019-09-04 09:12:29 +0200
committerDave Barach <openvpp@barachs.net>2019-09-16 12:23:27 +0000
commit33a58171e5995d9e649b414bfc77f2aab26e4c58 (patch)
tree85e072422b46ef44bbefbdf49231da507ec99536 /src/vnet/ip/ip_format_fns.h
parent1292d19c79c2fd4f09ffcc43ebf39f5d9d485c35 (diff)
api: autogenerate api trace print/endian
In addition to the external vppapitrace tool, VPP itself supports dumping of API trace files. In two formats, "custom-dump" and "dump". "dump" gives a human friendly list, and "custom-dump" is meant to give a list of commands that can be fed to VAT. This patch only deals with "dump". Prior to this fix, auto-generation was only done for the basic types. This fix adds support for any type, including lists, and supports pretty-printing of enums, strings, IP addresses, MAC addresses and so on. Usage: api trace dump <api-trace-file> For example Change-Id: I4e485680e6dcfce7489299ae6cf31d835071ac40 ---------- trace 48 ----------- vl_api_sw_interface_set_flags_t: _vl_msg_id: 75 client_index: 0 context: 10 sw_if_index: 1 flags: IF_STATUS_API_FLAG_ADMIN_UP ---------- trace 49 ----------- vl_api_sw_interface_add_del_address_t: _vl_msg_id: 88 client_index: 0 context: 11 sw_if_index: 1 is_add: 1 del_all: 0 prefix: 172.16.1.1/24 ---------- trace 51 ----------- vl_api_cli_inband_t: _vl_msg_id: 819 client_index: 0 context: 13 cmd: packet-generator capture pg0 pcap /tmp/vpp-unittest-TestMAP-YhcmDX/pg0_out.pcap disable ---------- trace 58 ----------- vl_api_ip_neighbor_add_del_t: _vl_msg_id: 199 client_index: 0 context: 20 is_add: 1 neighbor: sw_if_index: 2 flags: IP_API_NEIGHBOR_FLAG_NONE mac_address: 0202.0000.ff02 ip_address: fd01:2::2 Signed-off-by: Ole Troan <ot@cisco.com> Change-Id: I5556d06008de2762e7c2d35a8b0963ae670b3db1 Type: fix Signed-off-by: Ole Troan <ot@cisco.com> Signed-off-by: Ole Troan <ot@cisco.com> Signed-off-by: Ole Troan <ot@cisco.com> Signed-off-by: Ole Troan <ot@cisco.com> Signed-off-by: Ole Troan <ot@cisco.com> Signed-off-by: Ole Troan <ot@cisco.com> Signed-off-by: Ole Troan <ot@cisco.com> Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/vnet/ip/ip_format_fns.h')
-rw-r--r--src/vnet/ip/ip_format_fns.h86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/vnet/ip/ip_format_fns.h b/src/vnet/ip/ip_format_fns.h
new file mode 100644
index 00000000000..b24c59454d4
--- /dev/null
+++ b/src/vnet/ip/ip_format_fns.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef included_ip_format_fns_h
+#define included_ip_format_fns_h
+
+static inline u8 *format_vl_api_ip6_address_t (u8 * s, va_list * args);
+static inline u8 *format_vl_api_ip4_address_t (u8 * s, va_list * args);
+
+#include <vnet/ip/format.h>
+#define vl_typedefs
+#include <vnet/ip/ip_types.api.h>
+
+static inline u8 *
+format_vl_api_ip6_address_t (u8 * s, va_list * args)
+{
+ vl_api_ip6_address_t *a = va_arg (*args, vl_api_ip6_address_t *);
+ u32 indent __attribute__((unused)) = va_arg (*args, u32);
+
+ return format (s, "%U", format_ip6_address, a);
+}
+
+static inline u8 *
+format_vl_api_ip6_prefix_t (u8 * s, va_list * args)
+{
+ vl_api_ip6_prefix_t *a = va_arg (*args, vl_api_ip6_prefix_t *);
+ u32 indent __attribute__((unused)) = va_arg (*args, u32);
+
+ return format (s, "%U/%u", format_ip6_address, &a->address, a->len);
+}
+
+static inline u8 *
+format_vl_api_ip4_address_t (u8 * s, va_list * args)
+{
+ vl_api_ip4_address_t *a = va_arg (*args, vl_api_ip4_address_t *);
+ u32 indent __attribute__((unused)) = va_arg (*args, u32);
+
+ return format (s, "%U", format_ip4_address, a);
+}
+
+static inline u8 *
+format_vl_api_ip4_prefix_t (u8 * s, va_list * args)
+{
+ vl_api_ip4_prefix_t *a = va_arg (*args, vl_api_ip4_prefix_t *);
+ u32 indent __attribute__((unused)) = va_arg (*args, u32);
+
+ return format (s, "%U/%u", format_ip4_address, &a->address, a->len);
+}
+
+static inline u8 *
+format_vl_api_address_t (u8 * s, va_list * args)
+{
+ vl_api_address_t *a = va_arg (*args, vl_api_address_t *);
+ u32 indent __attribute__((unused)) = va_arg (*args, u32);
+
+ switch (a->af) {
+ case ADDRESS_IP4:
+ return format(s, "%U", format_ip4_address, &a->un.ip4);
+ case ADDRESS_IP6:
+ return format(s, "%U", format_ip6_address, &a->un.ip6);
+ }
+ return format (s, "");
+}
+
+static inline u8 *
+format_vl_api_prefix_t (u8 * s, va_list * args)
+{
+ vl_api_prefix_t *a = va_arg (*args, vl_api_prefix_t *);
+ u32 indent __attribute__((unused)) = va_arg (*args, u32);
+
+ return format (s, "%U/%u", format_vl_api_address_t, &a->address, indent, a->len);
+}
+
+#endif