From 6a2b37260a33a4a3aaef7e65d8422ddddf96fd4e Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Tue, 13 Mar 2018 14:08:09 -0400 Subject: [PATCH] pbrd: debugging infra Signed-off-by: Quentin Young --- pbrd/pbr_debug.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ pbrd/pbr_debug.h | 41 +++++++++++++++++++++++ pbrd/pbr_main.c | 3 ++ pbrd/pbr_vty.c | 3 ++ pbrd/subdir.am | 5 +++ 5 files changed, 136 insertions(+) create mode 100644 pbrd/pbr_debug.c create mode 100644 pbrd/pbr_debug.h diff --git a/pbrd/pbr_debug.c b/pbrd/pbr_debug.c new file mode 100644 index 000000000000..66688b7d4936 --- /dev/null +++ b/pbrd/pbr_debug.c @@ -0,0 +1,84 @@ +/* + * PBR - debugging + * Copyright (C) 2018 Cumulus Networks, Inc. + * Quentin Young + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include + +#include "debug.h" +#include "command.h" +#include "vector.h" + +#ifndef VTYSH_EXTRACT_PL +#include "pbrd/pbr_debug_clippy.c" +#endif +#include "pbrd/pbr_debug.h" + +#define DEBUG_PBR_MAP 0x000001 + +/* PBR debugging records */ +struct debug pbr_dbg_map = {0, "PBR map"}; + +struct debug *pbr_debugs[] = {&pbr_dbg_map}; + +static void pbr_debug_set_all(uint32_t flags, bool set) +{ + for (unsigned int i = 0; i < array_size(pbr_debugs); i++) { + DEBUG_FLAGS_SET(pbr_debugs[i], flags, set); + + /* if all modes have been turned off, don't preserve options */ + if (!DEBUG_MODE_CHECK(pbr_debugs[i], DEBUG_MODE_ALL)) + DEBUG_CLEAR(pbr_debugs[i]); + } +} + +#if 0 +static void +pbr_debug_config_write(struct vty *vty) +{ + if (DEBUG_MODE_CHECK(&pbr_dbg_map, DEBUG_MODE_CONF)) + vty_out(vty, "debug pbr map"); +} +#endif + +/* PBR debugging CLI ------------------------------------------------------- */ + +DEFPY(debug_pbr_map, debug_pbr_map_cmd, "[no] debug pbr map [MAP]", + NO_STR DEBUG_STR + "Policy Based Routing\n" + "PBR Map Name\n") +{ + uint32_t mode = DEBUG_NODE2MODE(vty->node); + DEBUG_MODE_SET(&pbr_dbg_map, mode, !!no); + return CMD_SUCCESS; +} + +/* ------------------------------------------------------------------------- */ + + +struct debug_callbacks pbr_dbg_cbs = {.debug_set_all = pbr_debug_set_all}; + +void pbr_debug_init(void) +{ + debug_init(&pbr_dbg_cbs); +} + +void pbr_debug_init_vty(void) +{ + install_element(VIEW_NODE, &debug_pbr_map_cmd); + install_element(CONFIG_NODE, &debug_pbr_map_cmd); +} diff --git a/pbrd/pbr_debug.h b/pbrd/pbr_debug.h new file mode 100644 index 000000000000..29014959ae9e --- /dev/null +++ b/pbrd/pbr_debug.h @@ -0,0 +1,41 @@ +/* + * PBR - debugging + * Copyright (C) 2018 Cumulus Networks, Inc. + * Quentin Young + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#ifndef __PBR_DEBUG_H__ +#define __PBR_DEBUG_H__ + +#include + +#include "debug.h" + +extern struct debug pbr_dbg_map; + +/* + * Initialize PBR debugging. + * + * Installs VTY commands and registers callbacks. + */ +void pbr_debug_init(void); + +/* + * Install PBR debugging VTY commands. + */ +void pbr_debug_init_vty(void); + +#endif /* __PBR_DEBUG_H__ */ diff --git a/pbrd/pbr_main.c b/pbrd/pbr_main.c index 37b93199f229..569540fd0366 100644 --- a/pbrd/pbr_main.c +++ b/pbrd/pbr_main.c @@ -50,6 +50,7 @@ #include "pbr_zebra.h" #include "pbr_event.h" #include "pbr_vty.h" +#include "pbr_debug.h" zebra_capabilities_t _caps_p[] = { ZCAP_NET_RAW, ZCAP_BIND, ZCAP_NET_ADMIN, @@ -147,6 +148,8 @@ int main(int argc, char **argv, char **envp) master = frr_init(); + pbr_debug_init(); + vrf_init(NULL, NULL, NULL, NULL); nexthop_group_init(pbr_nhgroup_add_cb, pbr_nhgroup_add_nexthop_cb, diff --git a/pbrd/pbr_vty.c b/pbrd/pbr_vty.c index a6344cc14b62..8b77179d07e6 100644 --- a/pbrd/pbr_vty.c +++ b/pbrd/pbr_vty.c @@ -35,6 +35,7 @@ #include "pbrd/pbr_zebra.h" #include "pbrd/pbr_vty.h" #include "pbrd/pbr_event.h" +#include "pbrd/pbr_debug.h" #ifndef VTYSH_EXTRACT_PL #include "pbrd/pbr_vty_clippy.c" #endif @@ -624,5 +625,7 @@ void pbr_vty_init(void) install_element(VIEW_NODE, &show_pbr_interface_cmd); install_element(VIEW_NODE, &show_pbr_nexthop_group_cmd); + pbr_debug_init_vty(); + return; } diff --git a/pbrd/subdir.am b/pbrd/subdir.am index 2467252294b2..361e6c1fdeb1 100644 --- a/pbrd/subdir.am +++ b/pbrd/subdir.am @@ -15,6 +15,7 @@ pbrd_libpbr_a_SOURCES = \ pbrd/pbr_memory.c \ pbrd/pbr_nht.c \ pbrd/pbr_event.c \ + pbrd/pbr_debug.c \ # end noinst_HEADERS += \ @@ -24,11 +25,15 @@ noinst_HEADERS += \ pbrd/pbr_nht.h \ pbrd/pbr_vty.h \ pbrd/pbr_zebra.h \ + pbrd/pbr_debug.h \ # end pbrd/pbr_vty_clippy.c: $(CLIPPY_DEPS) pbrd/pbr_vty.$(OBJEXT): pbrd/pbr_vty_clippy.c +pbrd/pbr_debug_clippy.c: $(CLIPPY_DEPS) +pbrd/pbr_debug.$(OBJEXT): pbrd/pbr_debug_clippy.c + pbrd_pbrd_SOURCES = pbrd/pbr_main.c pbrd_pbrd_LDADD = pbrd/libpbr.a lib/libfrr.la @LIBCAP@