]> git.puffer.fish Git - matthieu/frr.git/commitdiff
isisd. Add json to show summary command.
authorJavier Garcia <javier.martin.garcia@ibm.com>
Wed, 23 Feb 2022 11:41:04 +0000 (12:41 +0100)
committerJavier Garcia <javier.martin.garcia@ibm.com>
Fri, 25 Feb 2022 11:36:11 +0000 (12:36 +0100)
Signed-off-by: Javier Garcia <javier.martin.garcia@ibm.com>
doc/user/isisd.rst
isisd/isis_spf.c
isisd/isis_spf.h
isisd/isisd.c

index 5d53f60f93c33be62912c25f32719256a6f05705..2bb45a37f3e28f31bf6e603dc9e34082c170b6e0 100644 (file)
@@ -272,7 +272,7 @@ ISIS interface
 Showing ISIS information
 ========================
 
-.. clicmd:: show isis summary
+.. clicmd:: show isis [vrf <NAME|all>] summary [json]
 
    Show summary information about ISIS.
 
index 5718b48b9d42c23d4d9d6ebd1f10c808e28823c8..f44e2afeeb166c4c26de617f644131cc40682dd3 100644 (file)
@@ -2685,3 +2685,15 @@ void isis_spf_print(struct isis_spftree *spftree, struct vty *vty)
 
        vty_out(vty, "      run count         : %u\n", spftree->runcount);
 }
+void isis_spf_print_json(struct isis_spftree *spftree, struct json_object *json)
+{
+       char uptime[MONOTIME_STRLEN];
+       time_t cur;
+       cur = time(NULL);
+       cur -= spftree->last_run_timestamp;
+       frrtime_to_interval(cur, uptime, sizeof(uptime));
+       json_object_string_add(json, "last-run-elapsed", uptime);
+       json_object_int_add(json, "last-run-duration-usec",
+                           spftree->last_run_duration);
+       json_object_int_add(json, "last-run-count", spftree->runcount);
+}
index 5b3aa593799bf347d609dd471bf96d82fc681f73..815db7b226a8e1297d7e9e5a13eec75e547a5736 100644 (file)
@@ -75,6 +75,8 @@ void isis_print_routes(struct vty *vty, struct isis_spftree *spftree,
                       bool prefix_sid, bool backup);
 void isis_spf_init(void);
 void isis_spf_print(struct isis_spftree *spftree, struct vty *vty);
+void isis_spf_print_json(struct isis_spftree *spftree,
+                        struct json_object *json);
 void isis_run_spf(struct isis_spftree *spftree);
 struct isis_spftree *isis_run_hopcount_spf(struct isis_area *area,
                                           uint8_t *sysid,
index 3fa2b7cc20f0a0d3f98d0123ba257c2cfa1cdaab..99bf7674a8dcd03e075f6afbb9d7d50e59df4520 100644 (file)
@@ -2056,7 +2056,152 @@ DEFUN(show_isis_spf_ietf, show_isis_spf_ietf_cmd,
        return CMD_SUCCESS;
 }
 
-static void common_isis_summary(struct vty *vty, struct isis *isis)
+
+static const char *pdu_counter_index_to_name_json(enum pdu_counter_index index)
+{
+       switch (index) {
+       case L1_LAN_HELLO_INDEX:
+               return "l1-iih";
+       case L2_LAN_HELLO_INDEX:
+               return "l2-iih";
+       case P2P_HELLO_INDEX:
+               return "p2p-iih";
+       case L1_LINK_STATE_INDEX:
+               return "l1-lsp";
+       case L2_LINK_STATE_INDEX:
+               return "l2-lsp";
+       case FS_LINK_STATE_INDEX:
+               return "fs-lsp";
+       case L1_COMPLETE_SEQ_NUM_INDEX:
+               return "l1-csnp";
+       case L2_COMPLETE_SEQ_NUM_INDEX:
+               return "l2-csnp";
+       case L1_PARTIAL_SEQ_NUM_INDEX:
+               return "l1-psnp";
+       case L2_PARTIAL_SEQ_NUM_INDEX:
+               return "l2-psnp";
+       default:
+               return "???????";
+       }
+}
+
+static void common_isis_summary_json(struct json_object *json,
+                                    struct isis *isis)
+{
+       int level;
+       json_object *areas_json, *area_json, *tx_pdu_json, *rx_pdu_json,
+               *levels_json, *level_json;
+       struct listnode *node, *node2;
+       struct isis_area *area;
+       time_t cur;
+       char uptime[MONOTIME_STRLEN];
+       char stier[5];
+       json_object_string_add(json, "vrf", isis->name);
+       json_object_int_add(json, "process-id", isis->process_id);
+       if (isis->sysid_set)
+               json_object_string_add(json, "system-id",
+                                      sysid_print(isis->sysid));
+
+       cur = time(NULL);
+       cur -= isis->uptime;
+       frrtime_to_interval(cur, uptime, sizeof(uptime));
+       json_object_string_add(json, "up-time", uptime);
+       if (isis->area_list)
+               json_object_int_add(json, "number-areas",
+                                   isis->area_list->count);
+       areas_json = json_object_new_array();
+       json_object_object_add(json, "areas", areas_json);
+       for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
+               area_json = json_object_new_object();
+               json_object_string_add(area_json, "area",
+                                      area->area_tag ? area->area_tag
+                                                     : "null");
+
+
+               if (fabricd) {
+                       uint8_t tier = fabricd_tier(area);
+                       snprintfrr(stier, sizeof(stier), "%s", &tier);
+                       json_object_string_add(area_json, "tier",
+                                              tier == ISIS_TIER_UNDEFINED
+                                                      ? "undefined"
+                                                      : stier);
+               }
+
+               if (listcount(area->area_addrs) > 0) {
+                       struct area_addr *area_addr;
+                       for (ALL_LIST_ELEMENTS_RO(area->area_addrs, node2,
+                                                 area_addr)) {
+                               json_object_string_add(
+                                       area_json, "net",
+                                       isonet_print(area_addr->area_addr,
+                                                    area_addr->addr_len +
+                                                            ISIS_SYS_ID_LEN +
+                                                            1));
+                       }
+               }
+
+               tx_pdu_json = json_object_new_object();
+               json_object_object_add(area_json, "tx-pdu-type", tx_pdu_json);
+               for (int i = 0; i < PDU_COUNTER_SIZE; i++) {
+                       if (!area->pdu_tx_counters[i])
+                               continue;
+                       json_object_int_add(tx_pdu_json,
+                                           pdu_counter_index_to_name_json(i),
+                                           area->pdu_tx_counters[i]);
+               }
+               json_object_int_add(tx_pdu_json, "lsp-rxmt",
+                                   area->lsp_rxmt_count);
+
+               rx_pdu_json = json_object_new_object();
+               json_object_object_add(area_json, "rx-pdu-type", rx_pdu_json);
+               for (int i = 0; i < PDU_COUNTER_SIZE; i++) {
+                       if (!area->pdu_rx_counters[i])
+                               continue;
+                       json_object_int_add(rx_pdu_json,
+                                           pdu_counter_index_to_name_json(i),
+                                           area->pdu_rx_counters[i]);
+               }
+
+               levels_json = json_object_new_array();
+               json_object_object_add(area_json, "levels", levels_json);
+               for (level = ISIS_LEVEL1; level <= ISIS_LEVELS; level++) {
+                       if ((area->is_type & level) == 0)
+                               continue;
+                       level_json = json_object_new_object();
+                       json_object_int_add(level_json, "id", level);
+                       json_object_int_add(level_json, "lsp0-regenerated",
+                                           area->lsp_gen_count[level - 1]);
+                       json_object_int_add(level_json, "lsp-purged",
+                                           area->lsp_purge_count[level - 1]);
+                       if (area->spf_timer[level - 1])
+                               json_object_string_add(level_json, "spf",
+                                                      "pending");
+                       else
+                               json_object_string_add(level_json, "spf",
+                                                      "no pending");
+                       json_object_int_add(level_json, "minimum-interval",
+                                           area->min_spf_interval[level - 1]);
+                       if (area->spf_delay_ietf[level - 1])
+                               json_object_string_add(
+                                       level_json, "ietf-spf-delay-activated",
+                                       "not used");
+                       if (area->ip_circuits) {
+                               isis_spf_print_json(
+                                       area->spftree[SPFTREE_IPV4][level - 1],
+                                       level_json);
+                       }
+                       if (area->ipv6_circuits) {
+                               isis_spf_print_json(
+                                       area->spftree[SPFTREE_IPV6][level - 1],
+                                       level_json);
+                       }
+                       json_object_array_add(levels_json, level_json);
+               }
+               json_object_array_add(areas_json, area_json);
+       }
+}
+
+static void common_isis_summary_vty(struct vty *vty, struct isis *isis)
 {
        struct listnode *node, *node2;
        struct isis_area *area;
@@ -2156,10 +2301,21 @@ static void common_isis_summary(struct vty *vty, struct isis *isis)
        }
 }
 
+static void common_isis_summary(struct vty *vty, struct json_object *json,
+                               struct isis *isis)
+{
+       if (json) {
+               common_isis_summary_json(json, isis);
+       } else {
+               common_isis_summary_vty(vty, isis);
+       }
+}
+
 DEFUN(show_isis_summary, show_isis_summary_cmd,
-      "show " PROTO_NAME " [vrf <NAME|all>] summary",
+      "show " PROTO_NAME " [vrf <NAME|all>] summary [json]",
       SHOW_STR PROTO_HELP VRF_CMD_HELP_STR
       "All VRFs\n"
+       "json output\n"
       "summary\n")
 {
        struct listnode *node;
@@ -2167,25 +2323,30 @@ DEFUN(show_isis_summary, show_isis_summary_cmd,
        struct isis *isis;
        const char *vrf_name = VRF_DEFAULT_NAME;
        bool all_vrf = false;
+       bool uj = use_json(argc, argv);
+       json_object *json = NULL;
 
        ISIS_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf)
        if (!im) {
                vty_out(vty, PROTO_NAME " is not running\n");
                return CMD_SUCCESS;
        }
+       if (uj)
+               json = json_object_new_object();
        if (vrf_name) {
                if (all_vrf) {
                        for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis))
-                               common_isis_summary(vty, isis);
+                               common_isis_summary(vty, json, isis);
 
                        return CMD_SUCCESS;
                }
                isis = isis_lookup_by_vrfname(vrf_name);
                if (isis != NULL)
-                       common_isis_summary(vty, isis);
+                       common_isis_summary(vty, json, isis);
        }
 
-       vty_out(vty, "\n");
+       if (uj)
+               vty_json(vty, json);
 
        return CMD_SUCCESS;
 }