Skip to content

Commit

Permalink
zebra: Add show fpm status [json] command
Browse files Browse the repository at this point in the history
Add a command to get the status of the dplane_fpm_nl
module.

Signed-off-by: Donald Sharp <[email protected]>
  • Loading branch information
donaldsharp committed Feb 15, 2024
1 parent 006baa2 commit 90fa030
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
72 changes: 72 additions & 0 deletions zebra/dplane_fpm_nl.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "lib/network.h"
#include "lib/ns.h"
#include "lib/frr_pthread.h"
#include "lib/termtable.h"
#include "zebra/debug.h"
#include "zebra/interface.h"
#include "zebra/zebra_dplane.h"
Expand All @@ -44,6 +45,8 @@
#include "zebra/debug.h"
#include "fpm/fpm.h"

#include "zebra/dplane_fpm_nl_clippy.c"

#define SOUTHBOUND_DEFAULT_ADDR INADDR_LOOPBACK

/*
Expand Down Expand Up @@ -322,6 +325,74 @@ DEFUN(fpm_reset_counters, fpm_reset_counters_cmd,
return CMD_SUCCESS;
}

DEFPY(fpm_show_status,
fpm_show_status_cmd,
"show fpm status [json]$json",
SHOW_STR FPM_STR "FPM status\n" JSON_STR)
{
struct json_object *j;
bool connected;
uint16_t port;
struct sockaddr_in *sin;
struct sockaddr_in6 *sin6;
char buf[BUFSIZ];

connected = gfnc->socket > 0 ? true : false;

switch (gfnc->addr.ss_family) {
case AF_INET:
sin = (struct sockaddr_in *)&gfnc->addr;
snprintfrr(buf, sizeof(buf), "%pI4", &sin->sin_addr);
port = ntohs(sin->sin_port);
break;
case AF_INET6:
sin6 = (struct sockaddr_in6 *)&gfnc->addr;
snprintfrr(buf, sizeof(buf), "%pI6", &sin6->sin6_addr);
port = ntohs(sin6->sin6_port);
break;
default:
strlcpy(buf, "Unknown", sizeof(buf));
port = FPM_DEFAULT_PORT;
break;
}

if (json) {
j = json_object_new_object();

json_object_boolean_add(j, "connected", connected);
json_object_boolean_add(j, "useNHG", gfnc->use_nhg);
json_object_boolean_add(j, "useRouteReplace",
gfnc->use_route_replace);
json_object_boolean_add(j, "disabled", gfnc->disabled);
json_object_string_add(j, "address", buf);
json_object_int_add(j, "port", port);

vty_json(vty, j);
} else {
struct ttable *table = ttable_new(&ttable_styles[TTSTYLE_BLANK]);
char *out;

ttable_rowseps(table, 0, BOTTOM, true, '-');
ttable_add_row(table, "Address to connect to|%s", buf);
ttable_add_row(table, "Port|%u", port);
ttable_add_row(table, "Connected|%s", connected ? "Yes" : "No");
ttable_add_row(table, "Use Nexthop Groups|%s",
gfnc->use_nhg ? "Yes" : "No");
ttable_add_row(table, "Use Route Replace Semantics|%s",
gfnc->use_route_replace ? "Yes" : "No");
ttable_add_row(table, "Disabled|%s",
gfnc->disabled ? "Yes" : "No");

out = ttable_dump(table, "\n");
vty_out(vty, "%s\n", out);
XFREE(MTYPE_TMP, out);

ttable_del(table);
}

return CMD_SUCCESS;
}

DEFUN(fpm_show_counters, fpm_show_counters_cmd,
"show fpm counters",
SHOW_STR
Expand Down Expand Up @@ -1665,6 +1736,7 @@ static int fpm_nl_new(struct event_loop *tm)
zlog_debug("%s register status: %d", prov_name, rv);

install_node(&fpm_node);
install_element(ENABLE_NODE, &fpm_show_status_cmd);
install_element(ENABLE_NODE, &fpm_show_counters_cmd);
install_element(ENABLE_NODE, &fpm_show_counters_json_cmd);
install_element(ENABLE_NODE, &fpm_reset_counters_cmd);
Expand Down
1 change: 1 addition & 0 deletions zebra/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ zebra_zebra_SOURCES = \

clippy_scan += \
zebra/debug.c \
zebra/dplane_fpm_nl.c \
zebra/interface.c \
zebra/rtadv.c \
zebra/zebra_mlag_vty.c \
Expand Down

0 comments on commit 90fa030

Please sign in to comment.