]> git.puffer.fish Git - matthieu/frr.git/commitdiff
sharpd: Add 'sharp data nexthop' data dump
authorDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 7 Feb 2019 14:58:38 +0000 (09:58 -0500)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 7 Feb 2019 15:14:17 +0000 (10:14 -0500)
Add some basic data dumping about what we have watched
from the vty/vtysh cli for nexthops.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
doc/user/sharp.rst
sharpd/sharp_globals.h
sharpd/sharp_main.c
sharpd/sharp_nht.c [new file with mode: 0644]
sharpd/sharp_nht.h [new file with mode: 0644]
sharpd/sharp_vty.c
sharpd/sharp_zebra.c
sharpd/subdir.am

index a0da6af4d463b4e98c1b0001da91c4fa17547dbc..a78fac8fc1d0ec7647dbfd49b3ef5aa559df9c8b 100644 (file)
@@ -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.
index b0d35a91f2d1e20f3d94f8067c994663118fac2d..065fb092d4e8f6dcc2e2c9d5fd7f2d45377ab521 100644 (file)
@@ -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;
index 79d8bf9f0704d10c72781eff5effdf0d6eff4fdd..39453ee9adc1d49e6a2ad1047d65878818673ab2 100644 (file)
@@ -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 (file)
index 0000000..174f186
--- /dev/null
@@ -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 <zebra.h>
+
+#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 (file)
index 0000000..0b00774
--- /dev/null
@@ -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
index 36455a226d739bf4adf7b2b3dd6e643b0709c18a..0c02bd304dcda3e100a58fa794c10c129163757d 100644 (file)
@@ -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);
 
index 58ace8c58b182f0a761df2d4cd00f5269b1e0581..30e616a05775a6b127e5f4b9254314abf47e4b03 100644 (file)
@@ -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];
 
index 6e8864ad7cda103889958fcf7bfe051e6c394557..4a9028f6feee69207c2b131fecab167bd20bf714 100644 (file)
@@ -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 \