]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bfdd: add show bfd [vrf NAME] counters command
authorPhilippe Guibert <philippe.guibert@6wind.com>
Tue, 16 Apr 2019 12:18:12 +0000 (14:18 +0200)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Tue, 7 May 2019 14:01:47 +0000 (16:01 +0200)
that command permits to filter bfd peer counter contexts per vrf.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
bfdd/bfdd_vty.c

index 6a353085ee5d850e61255f22a93dcec4e1beb42d..96a9386d193ebab0056ab7922c5ebaeb54e5529c 100644 (file)
@@ -72,7 +72,7 @@ static struct json_object *__display_peer_counters_json(struct bfd_session *bs);
 static void _display_peer_counters_json(struct vty *vty, struct bfd_session *bs);
 static void _display_peer_counter_iter(struct hash_bucket *hb, void *arg);
 static void _display_peer_counter_json_iter(struct hash_bucket *hb, void *arg);
-static void _display_peers_counter(struct vty *vty, bool use_json);
+static void _display_peers_counter(struct vty *vty, char *vrfname, bool use_json);
 static struct bfd_session *
 _find_peer_or_error(struct vty *vty, int argc, struct cmd_token **argv,
                    const char *label, const char *peer_str,
@@ -658,16 +658,38 @@ static void _display_peer_counters_json(struct vty *vty, struct bfd_session *bs)
 
 static void _display_peer_counter_iter(struct hash_bucket *hb, void *arg)
 {
-       struct vty *vty = arg;
+       struct bfd_vrf_tuple *bvt = arg;
+       struct vty *vty;
        struct bfd_session *bs = hb->data;
 
+       if (!bvt)
+               return;
+       vty = bvt->vty;
+
+       if (bvt->vrfname) {
+               if (!bs->key.vrfname[0] ||
+                   !strmatch(bs->key.vrfname, bvt->vrfname))
+                       return;
+       }
+
        _display_peer_counter(vty, bs);
 }
 
 static void _display_peer_counter_json_iter(struct hash_bucket *hb, void *arg)
 {
-       struct json_object *jo = arg, *jon = NULL;
+       struct json_object *jo, *jon = NULL;
        struct bfd_session *bs = hb->data;
+       struct bfd_vrf_tuple *bvt = arg;
+
+       if (!bvt)
+               return;
+       jo  = bvt->jo;
+
+       if (bvt->vrfname) {
+               if (!bs->key.vrfname[0] ||
+                   !strmatch(bs->key.vrfname, bvt->vrfname))
+                       return;
+       }
 
        jon = __display_peer_counters_json(bs);
        if (jon == NULL) {
@@ -678,17 +700,22 @@ static void _display_peer_counter_json_iter(struct hash_bucket *hb, void *arg)
        json_object_array_add(jo, jon);
 }
 
-static void _display_peers_counter(struct vty *vty, bool use_json)
+static void _display_peers_counter(struct vty *vty, char *vrfname, bool use_json)
 {
        struct json_object *jo;
+       struct bfd_vrf_tuple bvt;
 
+       memset(&bvt, 0, sizeof(struct bfd_vrf_tuple));
+       bvt.vrfname = vrfname;
        if (!use_json) {
+               bvt.vty = vty;
                vty_out(vty, "BFD Peers:\n");
-               bfd_id_iterate(_display_peer_counter_iter, vty);
+               bfd_id_iterate(_display_peer_counter_iter, &bvt);
                return;
        }
 
        jo = json_object_new_array();
+       bvt.jo = jo;
        bfd_id_iterate(_display_peer_counter_json_iter, jo);
 
        vty_out(vty, "%s\n", json_object_to_json_string_ext(jo, 0));
@@ -838,14 +865,21 @@ DEFPY(bfd_show_peer_counters, bfd_show_peer_counters_cmd,
 }
 
 DEFPY(bfd_show_peers_counters, bfd_show_peers_counters_cmd,
-      "show bfd peers counters [json]",
+      "show bfd [vrf <NAME>] peers counters [json]",
       SHOW_STR
       "Bidirection Forwarding Detection\n"
+      VRF_CMD_HELP_STR
       "BFD peers status\n"
       "Show BFD peer counters information\n"
       JSON_STR)
 {
-       _display_peers_counter(vty, use_json(argc, argv));
+       char *vrf_name = NULL;
+       int idx_vrf = 0;
+
+       if (argv_find(argv, argc, "vrf", &idx_vrf))
+               vrf_name = argv[idx_vrf + 1]->arg;
+
+       _display_peers_counter(vty, vrf_name, use_json(argc, argv));
 
        return CMD_SUCCESS;
 }