]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/rfapi/vnc_debug.c
bgpd: Adding BGP GR Global & Per Neighbour FSM changes
[mirror_frr.git] / bgpd / rfapi / vnc_debug.c
CommitLineData
d62a17ae 1/*
65efcfce
LB
2 *
3 * Copyright 2016, LabN Consulting, L.L.C.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
896014f4
DL
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
65efcfce
LB
18 */
19
f8b6f499 20#include "lib/zebra.h"
65efcfce
LB
21
22#include <lib/version.h>
f8b6f499
LB
23#include "lib/prefix.h"
24#include "lib/linklist.h"
25#include "lib/stream.h"
26#include "lib/command.h"
f8b6f499
LB
27#include "lib/log.h"
28#include "bgpd/rfapi/vnc_debug.h"
65efcfce
LB
29
30/*
31 * debug state storage
32 */
33unsigned long conf_vnc_debug;
34unsigned long term_vnc_debug;
35
36struct vnc_debug {
d62a17ae 37 unsigned long bit;
38 const char *name;
65efcfce
LB
39};
40
2b64873d 41static const struct vnc_debug vncdebug[] = {
d62a17ae 42 {VNC_DEBUG_RFAPI_QUERY, "rfapi-query"},
43 {VNC_DEBUG_IMPORT_BI_ATTACH, "import-bi-attach"},
44 {VNC_DEBUG_IMPORT_DEL_REMOTE, "import-del-remote"},
45 {VNC_DEBUG_EXPORT_BGP_GETCE, "export-bgp-getce"},
46 {VNC_DEBUG_EXPORT_BGP_DIRECT_ADD, "export-bgp-direct-add"},
47 {VNC_DEBUG_IMPORT_BGP_ADD_ROUTE, "import-bgp-add-route"},
48 {VNC_DEBUG_VERBOSE, "verbose"},
65efcfce
LB
49};
50
51#define VNC_STR "VNC information\n"
52
53/***********************************************************************
54 * debug bgp vnc <foo>
55 ***********************************************************************/
56DEFUN (debug_bgp_vnc,
57 debug_bgp_vnc_cmd,
d5bd3e0a 58 "debug bgp vnc <rfapi-query|import-bi-attach|import-del-remote|verbose>",
65efcfce
LB
59 DEBUG_STR
60 BGP_STR
61 VNC_STR
62 "rfapi query handling\n"
63 "import BI atachment\n"
a3b55c25
LB
64 "import delete remote routes\n"
65 "verbose logging\n")
65efcfce 66{
d62a17ae 67 size_t i;
68
69 for (i = 0; i < (sizeof(vncdebug) / sizeof(struct vnc_debug)); ++i) {
70 if (strmatch(argv[3]->text, vncdebug[i].name)) {
71 if (vty->node == CONFIG_NODE) {
72 conf_vnc_debug |= vncdebug[i].bit;
73 term_vnc_debug |= vncdebug[i].bit;
74 } else {
75 term_vnc_debug |= vncdebug[i].bit;
76 vty_out(vty, "BGP vnc %s debugging is on\n",
77 vncdebug[i].name);
78 }
79 return CMD_SUCCESS;
80 }
65efcfce 81 }
d62a17ae 82 vty_out(vty, "Unknown debug flag: %s\n", argv[3]->arg);
83 return CMD_WARNING_CONFIG_FAILED;
65efcfce
LB
84}
85
86DEFUN (no_debug_bgp_vnc,
87 no_debug_bgp_vnc_cmd,
ef7eec74 88 "no debug bgp vnc <rfapi-query|import-bi-attach|import-del-remote|verbose>",
65efcfce
LB
89 NO_STR
90 DEBUG_STR
91 BGP_STR
92 VNC_STR
93 "rfapi query handling\n"
94 "import BI atachment\n"
a3b55c25
LB
95 "import delete remote routes\n"
96 "verbose logging\n")
65efcfce 97{
d62a17ae 98 size_t i;
99
d62a17ae 100 for (i = 0; i < (sizeof(vncdebug) / sizeof(struct vnc_debug)); ++i) {
ef7eec74 101 if (strmatch(argv[argc - 1]->text, vncdebug[i].name)) {
d62a17ae 102 if (vty->node == CONFIG_NODE) {
103 conf_vnc_debug &= ~vncdebug[i].bit;
104 term_vnc_debug &= ~vncdebug[i].bit;
105 } else {
106 term_vnc_debug &= ~vncdebug[i].bit;
107 vty_out(vty, "BGP vnc %s debugging is off\n",
108 vncdebug[i].name);
109 }
110 return CMD_SUCCESS;
111 }
65efcfce 112 }
d62a17ae 113 vty_out(vty, "Unknown debug flag: %s\n", argv[3]->arg);
114 return CMD_WARNING_CONFIG_FAILED;
65efcfce
LB
115}
116
65efcfce
LB
117/***********************************************************************
118 * no debug bgp vnc all
119 ***********************************************************************/
120
121DEFUN (no_debug_bgp_vnc_all,
122 no_debug_bgp_vnc_all_cmd,
ef7eec74 123 "no debug all bgp vnc",
65efcfce
LB
124 NO_STR
125 DEBUG_STR
126 "Disable all VNC debugging\n"
127 BGP_STR
128 VNC_STR)
129{
d62a17ae 130 term_vnc_debug = 0;
131 vty_out(vty, "All possible VNC debugging has been turned off\n");
132
133 return CMD_SUCCESS;
65efcfce
LB
134}
135
65efcfce
LB
136/***********************************************************************
137 * show/save
138 ***********************************************************************/
139
87f6dc50
DS
140DEFUN_NOSH (show_debugging_bgp_vnc,
141 show_debugging_bgp_vnc_cmd,
142 "show debugging bgp vnc",
143 SHOW_STR
144 DEBUG_STR
145 BGP_STR
146 VNC_STR)
65efcfce 147{
d62a17ae 148 size_t i;
65efcfce 149
d62a17ae 150 vty_out(vty, "BGP VNC debugging status:\n");
65efcfce 151
d62a17ae 152 for (i = 0; i < (sizeof(vncdebug) / sizeof(struct vnc_debug)); ++i) {
153 if (term_vnc_debug & vncdebug[i].bit) {
154 vty_out(vty, " BGP VNC %s debugging is on\n",
155 vncdebug[i].name);
156 }
65efcfce 157 }
d62a17ae 158 vty_out(vty, "\n");
159 return CMD_SUCCESS;
65efcfce
LB
160}
161
d62a17ae 162static int bgp_vnc_config_write_debug(struct vty *vty)
65efcfce 163{
d62a17ae 164 int write = 0;
165 size_t i;
166
97b5d752 167 for (i = 0; i < array_size(vncdebug); ++i) {
d62a17ae 168 if (conf_vnc_debug & vncdebug[i].bit) {
169 vty_out(vty, "debug bgp vnc %s\n", vncdebug[i].name);
170 write++;
171 }
65efcfce 172 }
d62a17ae 173 return write;
65efcfce
LB
174}
175
d62a17ae 176static struct cmd_node debug_node = {DEBUG_VNC_NODE, "", 1};
65efcfce 177
d62a17ae 178void vnc_debug_init(void)
65efcfce 179{
d62a17ae 180 install_node(&debug_node, bgp_vnc_config_write_debug);
181 install_element(ENABLE_NODE, &show_debugging_bgp_vnc_cmd);
65efcfce 182
d62a17ae 183 install_element(ENABLE_NODE, &debug_bgp_vnc_cmd);
184 install_element(CONFIG_NODE, &debug_bgp_vnc_cmd);
185 install_element(ENABLE_NODE, &no_debug_bgp_vnc_cmd);
ef7eec74 186 install_element(CONFIG_NODE, &no_debug_bgp_vnc_cmd);
65efcfce 187
d62a17ae 188 install_element(ENABLE_NODE, &no_debug_bgp_vnc_all_cmd);
ef7eec74 189 install_element(CONFIG_NODE, &no_debug_bgp_vnc_all_cmd);
65efcfce 190}