From 86da53ab0ee845179fd80ee32267ef6295564222 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 7 Feb 2019 09:58:38 -0500 Subject: [PATCH] sharpd: Add 'sharp data nexthop' data dump Add some basic data dumping about what we have watched from the vty/vtysh cli for nexthops. Signed-off-by: Donald Sharp --- doc/user/sharp.rst | 6 ++++ sharpd/sharp_globals.h | 5 ++++ sharpd/sharp_main.c | 3 ++ sharpd/sharp_nht.c | 67 ++++++++++++++++++++++++++++++++++++++++++ sharpd/sharp_nht.h | 38 ++++++++++++++++++++++++ sharpd/sharp_vty.c | 16 ++++++++++ sharpd/sharp_zebra.c | 7 +++++ sharpd/subdir.am | 2 ++ 8 files changed, 144 insertions(+) create mode 100644 sharpd/sharp_nht.c create mode 100644 sharpd/sharp_nht.h diff --git a/doc/user/sharp.rst b/doc/user/sharp.rst index a0da6af4d..a78fac8fc 100644 --- a/doc/user/sharp.rst +++ b/doc/user/sharp.rst @@ -75,3 +75,9 @@ keyword. At present, no sharp commands will be preserved in the config. Instruct zebra to monitor and notify sharp when the specified nexthop is changed. The notification from zebra is written into the debug log. + +.. index:: sharp data nexthop +.. clicmd:: sharp data nexthop + + Allow end user to dump associated data with the nexthop tracking that + may have been turned on. diff --git a/sharpd/sharp_globals.h b/sharpd/sharp_globals.h index b0d35a91f..065fb092d 100644 --- a/sharpd/sharp_globals.h +++ b/sharpd/sharp_globals.h @@ -22,6 +22,8 @@ #ifndef __SHARP_GLOBAL_H__ #define __SHARP_GLOBAL_H__ +DECLARE_MGROUP(SHARPD) + struct sharp_routes { /* The original prefix for route installation */ struct prefix orig_prefix; @@ -44,6 +46,9 @@ struct sharp_routes { struct sharp_global { /* Global data about route install/deletions */ struct sharp_routes r; + + /* The list of nexthops that we are watching and data about them */ + struct list *nhs; }; extern struct sharp_global sg; diff --git a/sharpd/sharp_main.c b/sharpd/sharp_main.c index 79d8bf9f0..39453ee9a 100644 --- a/sharpd/sharp_main.c +++ b/sharpd/sharp_main.c @@ -48,6 +48,8 @@ #include "sharp_vty.h" #include "sharp_globals.h" +DEFINE_MGROUP(SHARPD, "sharpd") + zebra_capabilities_t _caps_p[] = { }; @@ -127,6 +129,7 @@ struct sharp_global sg; static void sharp_global_init(void) { memset(&sg, 0, sizeof(sg)); + sg.nhs = list_new(); } int main(int argc, char **argv, char **envp) diff --git a/sharpd/sharp_nht.c b/sharpd/sharp_nht.c new file mode 100644 index 000000000..174f18686 --- /dev/null +++ b/sharpd/sharp_nht.c @@ -0,0 +1,67 @@ +/* + * SHARP - code to track nexthops + * Copyright (C) Cumulus Networks, Inc. + * Donald Sharp + * + * This file is part of FRR. + * + * FRR 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, or (at your option) any + * later version. + * + * FRR 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 "memory.h" +#include "nexthop.h" +#include "nexthop_group.h" +#include "vty.h" + +#include "sharp_nht.h" +#include "sharp_globals.h" + +DEFINE_MTYPE_STATIC(SHARPD, NH_TRACKER, "Nexthop Tracker") + +struct sharp_nh_tracker *sharp_nh_tracker_get(struct prefix *p) +{ + struct listnode *node; + struct sharp_nh_tracker *nht; + + for (ALL_LIST_ELEMENTS_RO(sg.nhs, node, nht)) { + if (prefix_same(&nht->p, p)) + break; + } + + if (nht) + return nht; + + nht = XCALLOC(MTYPE_NH_TRACKER, sizeof(*nht)); + prefix_copy(&nht->p, p); + + listnode_add(sg.nhs, nht); + return nht; +} + +void sharp_nh_tracker_dump(struct vty *vty) +{ + struct listnode *node; + struct sharp_nh_tracker *nht; + + for (ALL_LIST_ELEMENTS_RO(sg.nhs, node, nht)) { + char buf[PREFIX_STRLEN]; + + vty_out(vty, "%s: Nexthops: %u Updates: %u\n", + prefix2str(&nht->p, buf, sizeof(buf)), + nht->nhop_num, + nht->updates); + } +} diff --git a/sharpd/sharp_nht.h b/sharpd/sharp_nht.h new file mode 100644 index 000000000..0b00774a8 --- /dev/null +++ b/sharpd/sharp_nht.h @@ -0,0 +1,38 @@ +/* + * SHARP - code to track nexthops + * Copyright (C) Cumulus Networks, Inc. + * Donald Sharp + * + * This file is part of FRR. + * + * FRR 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, or (at your option) any + * later version. + * + * FRR 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 __SHARP_NHT_H__ +#define __SHARP_NHT_H__ + +struct sharp_nh_tracker { + /* What are we watching */ + struct prefix p; + + /* Number of valid nexthops */ + uint32_t nhop_num; + + uint32_t updates; +}; + +extern struct sharp_nh_tracker *sharp_nh_tracker_get(struct prefix *p); + +extern void sharp_nh_tracker_dump(struct vty *vty); +#endif diff --git a/sharpd/sharp_vty.c b/sharpd/sharp_vty.c index 36455a226..0c02bd304 100644 --- a/sharpd/sharp_vty.c +++ b/sharpd/sharp_vty.c @@ -32,6 +32,7 @@ #include "sharpd/sharp_globals.h" #include "sharpd/sharp_zebra.h" +#include "sharpd/sharp_nht.h" #include "sharpd/sharp_vty.h" #ifndef VTYSH_EXTRACT_PL #include "sharpd/sharp_vty_clippy.c" @@ -53,6 +54,7 @@ DEFPY(watch_nexthop_v6, watch_nexthop_v6_cmd, memcpy(&p.u.prefix6, &nhop, 16); p.family = AF_INET6; + sharp_nh_tracker_get(&p); sharp_zebra_nexthop_watch(&p, true, !!connected); return CMD_SUCCESS; @@ -74,11 +76,24 @@ DEFPY(watch_nexthop_v4, watch_nexthop_v4_cmd, p.u.prefix4 = nhop; p.family = AF_INET; + sharp_nh_tracker_get(&p); sharp_zebra_nexthop_watch(&p, true, !!connected); return CMD_SUCCESS; } +DEFPY(sharp_nht_data_dump, + sharp_nht_data_dump_cmd, + "sharp data nexthop", + "Sharp routing Protocol\n" + "Nexthop information\n" + "Data Dump\n") +{ + sharp_nh_tracker_dump(vty); + + return CMD_SUCCESS; +} + DEFPY (install_routes_data_dump, install_routes_data_dump_cmd, "sharp data route", @@ -260,6 +275,7 @@ void sharp_vty_init(void) install_element(ENABLE_NODE, &install_routes_cmd); install_element(ENABLE_NODE, &remove_routes_cmd); install_element(ENABLE_NODE, &vrf_label_cmd); + install_element(ENABLE_NODE, &sharp_nht_data_dump_cmd); install_element(ENABLE_NODE, &watch_nexthop_v6_cmd); install_element(ENABLE_NODE, &watch_nexthop_v4_cmd); diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c index 58ace8c58..30e616a05 100644 --- a/sharpd/sharp_zebra.c +++ b/sharpd/sharp_zebra.c @@ -37,6 +37,7 @@ #include "nexthop_group.h" #include "sharp_globals.h" +#include "sharp_nht.h" #include "sharp_zebra.h" /* Zebra structure to hold current status. */ @@ -334,6 +335,7 @@ void sharp_zebra_nexthop_watch(struct prefix *p, bool watch, bool connected) static int sharp_nexthop_update(int command, struct zclient *zclient, zebra_size_t length, vrf_id_t vrf_id) { + struct sharp_nh_tracker *nht; struct zapi_route nhr; char buf[PREFIX_STRLEN]; int i; @@ -346,6 +348,11 @@ static int sharp_nexthop_update(int command, struct zclient *zclient, zlog_debug("Received update for %s", prefix2str(&nhr.prefix, buf, sizeof(buf))); + + nht = sharp_nh_tracker_get(&nhr.prefix); + nht->nhop_num = nhr.nexthop_num; + nht->updates++; + for (i = 0; i < nhr.nexthop_num; i++) { struct zapi_nexthop *znh = &nhr.nexthops[i]; diff --git a/sharpd/subdir.am b/sharpd/subdir.am index 6e8864ad7..4a9028f6f 100644 --- a/sharpd/subdir.am +++ b/sharpd/subdir.am @@ -11,11 +11,13 @@ man8 += $(MANBUILD)/sharpd.8 endif sharpd_libsharp_a_SOURCES = \ + sharpd/sharp_nht.c \ sharpd/sharp_zebra.c \ sharpd/sharp_vty.c \ # end noinst_HEADERS += \ + sharpd/sharp_nht.h \ sharpd/sharp_vty.h \ sharpd/sharp_globals.h \ sharpd/sharp_zebra.h \ -- 2.39.5