From 0b11b56abd258a65786c99d18412149c5963ca19 Mon Sep 17 00:00:00 2001 From: David Schweizer Date: Wed, 12 Jan 2022 12:32:33 +0100 Subject: [PATCH] ospf6d: add LSA stats to show area json output Signed-off-by: David Schweizer --- lib/json.h | 9 +++++++++ ospf6d/ospf6_area.c | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/lib/json.h b/lib/json.h index 9d33ac7ae3..fcaa84c816 100644 --- a/lib/json.h +++ b/lib/json.h @@ -42,6 +42,15 @@ extern "C" { json_object_iter_equal(&(joi), &(join)) == 0; \ json_object_iter_next(&(joi))) +#define JSON_OBJECT_NEW_ARRAY(json_func, fields, n) \ + ({ \ + struct json_object *_json_array = json_object_new_array(); \ + for (int _i = 0; _i < (n); _i++) \ + json_object_array_add(_json_array, \ + (json_func)((fields)[_i])); \ + (_json_array); \ + }) + extern bool use_json(const int argc, struct cmd_token *argv[]); extern void json_object_string_add(struct json_object *obj, const char *key, const char *s); diff --git a/ospf6d/ospf6_area.c b/ospf6d/ospf6_area.c index 417fc69694..4225b59e26 100644 --- a/ospf6d/ospf6_area.c +++ b/ospf6d/ospf6_area.c @@ -453,6 +453,11 @@ void ospf6_area_show(struct vty *vty, struct ospf6_area *oa, json_object_int_add(json_area, "numberOfAreaScopedLsa", oa->lsdb->count); + json_object_object_add( + json_area, "lsaStatistics", + JSON_OBJECT_NEW_ARRAY(json_object_new_int, + oa->lsdb->stats, + OSPF6_LSTYPE_SIZE)); /* Interfaces Attached */ array_interfaces = json_object_new_array(); -- 2.39.5