]> git.puffer.fish Git - mirror/frr.git/commitdiff
pathd: rework debug pathd pcep command 14728/head
authorFarid Mihoub <farid.mihoub@6wind.com>
Fri, 3 Nov 2023 12:53:43 +0000 (13:53 +0100)
committerFarid Mihoub <farid.mihoub@6wind.com>
Fri, 3 Nov 2023 16:09:11 +0000 (17:09 +0100)
Rework "debug pathd pcep [...]" command to support the following
configurations:
  - configure one debugging log type at a time.
  - deconfigure one debugging log type at a time.
  - configure all debugging logs in one shot.
  - deconfigure all debugging logs in one shot.

Signed-off-by: Farid Mihoub <farid.mihoub@6wind.com>
pathd/path_pcep.h
pathd/path_pcep_cli.c

index 5c6a02372f236c6f38818ed60f2b7e3b6b5ff490..d6dbcb5c08c9a6206d773882d7729f98cb050a60 100644 (file)
@@ -25,6 +25,7 @@ DECLARE_MTYPE(PCEP);
 #define PCEP_DEBUG_MODE_PATH 0x02
 #define PCEP_DEBUG_MODE_PCEP 0x04
 #define PCEP_DEBUG_MODE_PCEPLIB 0x08
+#define PCEP_DEBUG_MODE_ALL 0x0F
 #define PCEP_DEBUG(fmt, ...)                                                   \
        do {                                                                   \
                if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_BASIC))    \
index c46649b0db04eafef070139283519f41b0e64a2d..ab61abc02d23047992058f33b9e80f9d17aedfd6 100644 (file)
@@ -458,28 +458,32 @@ static void pcep_cli_remove_pce_connection(struct pce_opts *pce_opts)
  * VTY command implementations
  */
 
-static int path_pcep_cli_debug(struct vty *vty, const char *no_str,
-                              const char *basic_str, const char *path_str,
-                              const char *message_str, const char *pceplib_str)
+static int path_pcep_cli_debug(struct vty *vty, const char *debug_type, bool set)
 {
        uint32_t mode = DEBUG_NODE2MODE(vty->node);
-       bool no = (no_str != NULL);
 
-       DEBUG_MODE_SET(&pcep_g->dbg, mode, !no);
-
-       if (basic_str != NULL) {
-               DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_BASIC, !no);
-       }
-       if (path_str != NULL) {
-               DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_PATH, !no);
-       }
-       if (message_str != NULL) {
-               DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEP, !no);
-       }
-       if (pceplib_str != NULL) {
-               DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEPLIB, !no);
+       /* Global Set */
+       if (debug_type == NULL) {
+               DEBUG_MODE_SET(&pcep_g->dbg, mode, set);
+               DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_ALL, set);
+               return CMD_SUCCESS;
        }
 
+       DEBUG_MODE_SET(&pcep_g->dbg, mode, true);
+
+       if (strcmp(debug_type, "basic") == 0)
+               DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_BASIC, set);
+       else if (strcmp(debug_type, "path") == 0)
+               DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_PATH, set);
+       else if (strcmp(debug_type, "message") == 0)
+               DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEP, set);
+       else if (strcmp(debug_type, "pceplib") == 0)
+               DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEPLIB, set);
+
+       /* Unset the pcep debug mode if there is no flag at least set*/
+       if (!DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_ALL))
+               DEBUG_MODE_SET(&pcep_g->dbg, mode, false);
+
        return CMD_SUCCESS;
 }
 
@@ -1788,7 +1792,7 @@ DEFPY(show_debugging_pathd_pcep,
 
 DEFPY(pcep_cli_debug,
       pcep_cli_debug_cmd,
-      "[no] debug pathd pcep [basic]$basic_str [path]$path_str [message]$message_str [pceplib]$pceplib_str",
+      "[no] debug pathd pcep [<basic|path|message|pceplib>$debug_type]",
       NO_STR DEBUG_STR
       "pathd debugging\n"
       "pcep module debugging\n"
@@ -1797,8 +1801,7 @@ DEFPY(pcep_cli_debug,
       "pcep message debugging\n"
       "pceplib debugging\n")
 {
-       return path_pcep_cli_debug(vty, no, basic_str, path_str, message_str,
-                                  pceplib_str);
+       return path_pcep_cli_debug(vty, debug_type, !no);
 }
 
 DEFPY(pcep_cli_show_srte_pcep_counters,