summaryrefslogtreecommitdiff
path: root/ospf6d
diff options
context:
space:
mode:
Diffstat (limited to 'ospf6d')
-rw-r--r--ospf6d/ospf6_abr.c55
-rw-r--r--ospf6d/ospf6_asbr.c77
-rw-r--r--ospf6d/ospf6_intra.c174
-rw-r--r--ospf6d/ospf6_lsa.c238
-rw-r--r--ospf6d/ospf6_lsa.h20
-rw-r--r--ospf6d/ospf6_lsdb.c49
-rw-r--r--ospf6d/ospf6_lsdb.h3
-rw-r--r--ospf6d/ospf6d.c766
8 files changed, 751 insertions, 631 deletions
diff --git a/ospf6d/ospf6_abr.c b/ospf6d/ospf6_abr.c
index 8cfdf2642c..eee98275ec 100644
--- a/ospf6d/ospf6_abr.c
+++ b/ospf6d/ospf6_abr.c
@@ -1296,7 +1296,9 @@ static char *ospf6_inter_area_prefix_lsa_get_prefix_str(struct ospf6_lsa *lsa,
}
static int ospf6_inter_area_prefix_lsa_show(struct vty *vty,
- struct ospf6_lsa *lsa)
+ struct ospf6_lsa *lsa,
+ json_object *json_obj,
+ bool use_json)
{
struct ospf6_inter_prefix_lsa *prefix_lsa;
char buf[INET6_ADDRSTRLEN];
@@ -1304,16 +1306,29 @@ static int ospf6_inter_area_prefix_lsa_show(struct vty *vty,
prefix_lsa = (struct ospf6_inter_prefix_lsa *)OSPF6_LSA_HEADER_END(
lsa->header);
- vty_out(vty, " Metric: %lu\n",
- (unsigned long)OSPF6_ABR_SUMMARY_METRIC(prefix_lsa));
+ if (use_json) {
+ json_object_int_add(
+ json_obj, "metric",
+ (unsigned long)OSPF6_ABR_SUMMARY_METRIC(prefix_lsa));
+ ospf6_prefix_options_printbuf(prefix_lsa->prefix.prefix_options,
+ buf, sizeof(buf));
+ json_object_string_add(json_obj, "prefixOptions", buf);
+ json_object_string_add(
+ json_obj, "prefix",
+ ospf6_inter_area_prefix_lsa_get_prefix_str(
+ lsa, buf, sizeof(buf), 0));
+ } else {
+ vty_out(vty, " Metric: %lu\n",
+ (unsigned long)OSPF6_ABR_SUMMARY_METRIC(prefix_lsa));
- ospf6_prefix_options_printbuf(prefix_lsa->prefix.prefix_options, buf,
- sizeof(buf));
- vty_out(vty, " Prefix Options: %s\n", buf);
+ ospf6_prefix_options_printbuf(prefix_lsa->prefix.prefix_options,
+ buf, sizeof(buf));
+ vty_out(vty, " Prefix Options: %s\n", buf);
- vty_out(vty, " Prefix: %s\n",
- ospf6_inter_area_prefix_lsa_get_prefix_str(lsa, buf,
- sizeof(buf), 0));
+ vty_out(vty, " Prefix: %s\n",
+ ospf6_inter_area_prefix_lsa_get_prefix_str(
+ lsa, buf, sizeof(buf), 0));
+ }
return 0;
}
@@ -1338,7 +1353,9 @@ static char *ospf6_inter_area_router_lsa_get_prefix_str(struct ospf6_lsa *lsa,
}
static int ospf6_inter_area_router_lsa_show(struct vty *vty,
- struct ospf6_lsa *lsa)
+ struct ospf6_lsa *lsa,
+ json_object *json_obj,
+ bool use_json)
{
struct ospf6_inter_router_lsa *router_lsa;
char buf[64];
@@ -1347,12 +1364,22 @@ static int ospf6_inter_area_router_lsa_show(struct vty *vty,
lsa->header);
ospf6_options_printbuf(router_lsa->options, buf, sizeof(buf));
- vty_out(vty, " Options: %s\n", buf);
- vty_out(vty, " Metric: %lu\n",
- (unsigned long)OSPF6_ABR_SUMMARY_METRIC(router_lsa));
+ if (use_json) {
+ json_object_string_add(json_obj, "options", buf);
+ json_object_int_add(
+ json_obj, "metric",
+ (unsigned long)OSPF6_ABR_SUMMARY_METRIC(router_lsa));
+ } else {
+ vty_out(vty, " Options: %s\n", buf);
+ vty_out(vty, " Metric: %lu\n",
+ (unsigned long)OSPF6_ABR_SUMMARY_METRIC(router_lsa));
+ }
inet_ntop(AF_INET, &router_lsa->router_id, buf, sizeof(buf));
- vty_out(vty, " Destination Router ID: %s\n", buf);
+ if (use_json)
+ json_object_string_add(json_obj, "destinationRouterId", buf);
+ else
+ vty_out(vty, " Destination Router ID: %s\n", buf);
return 0;
}
diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c
index 0e419cbff6..af99bc0c88 100644
--- a/ospf6d/ospf6_asbr.c
+++ b/ospf6d/ospf6_asbr.c
@@ -1890,7 +1890,8 @@ static char *ospf6_as_external_lsa_get_prefix_str(struct ospf6_lsa *lsa,
return (buf);
}
-static int ospf6_as_external_lsa_show(struct vty *vty, struct ospf6_lsa *lsa)
+static int ospf6_as_external_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
+ json_object *json_obj, bool use_json)
{
struct ospf6_as_external_lsa *external;
char buf[64];
@@ -1908,31 +1909,65 @@ static int ospf6_as_external_lsa_show(struct vty *vty, struct ospf6_lsa *lsa)
(CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_T) ? 'T'
: '-'));
- vty_out(vty, " Bits: %s\n", buf);
- vty_out(vty, " Metric: %5lu\n",
- (unsigned long)OSPF6_ASBR_METRIC(external));
-
- ospf6_prefix_options_printbuf(external->prefix.prefix_options, buf,
- sizeof(buf));
- vty_out(vty, " Prefix Options: %s\n", buf);
+ if (use_json) {
+ json_object_string_add(json_obj, "bits", buf);
+ json_object_int_add(json_obj, "metric",
+ (unsigned long)OSPF6_ASBR_METRIC(external));
+ ospf6_prefix_options_printbuf(external->prefix.prefix_options,
+ buf, sizeof(buf));
+ json_object_string_add(json_obj, "prefixOptions", buf);
+ json_object_int_add(
+ json_obj, "referenceLsType",
+ ntohs(external->prefix.prefix_refer_lstype));
+ json_object_string_add(json_obj, "prefix",
+ ospf6_as_external_lsa_get_prefix_str(
+ lsa, buf, sizeof(buf), 0));
+
+ /* Forwarding-Address */
+ json_object_boolean_add(
+ json_obj, "forwardingAddressPresent",
+ CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_F));
+ if (CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_F))
+ json_object_string_add(
+ json_obj, "forwardingAddress",
+ ospf6_as_external_lsa_get_prefix_str(
+ lsa, buf, sizeof(buf), 1));
+
+ /* Tag */
+ json_object_boolean_add(
+ json_obj, "tagPresent",
+ CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_T));
+ if (CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_T))
+ json_object_int_add(json_obj, "tag",
+ ospf6_as_external_lsa_get_tag(lsa));
+ } else {
+ vty_out(vty, " Bits: %s\n", buf);
+ vty_out(vty, " Metric: %5lu\n",
+ (unsigned long)OSPF6_ASBR_METRIC(external));
- vty_out(vty, " Referenced LSType: %d\n",
- ntohs(external->prefix.prefix_refer_lstype));
+ ospf6_prefix_options_printbuf(external->prefix.prefix_options,
+ buf, sizeof(buf));
+ vty_out(vty, " Prefix Options: %s\n", buf);
- vty_out(vty, " Prefix: %s\n",
- ospf6_as_external_lsa_get_prefix_str(lsa, buf, sizeof(buf), 0));
+ vty_out(vty, " Referenced LSType: %d\n",
+ ntohs(external->prefix.prefix_refer_lstype));
- /* Forwarding-Address */
- if (CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_F)) {
- vty_out(vty, " Forwarding-Address: %s\n",
+ vty_out(vty, " Prefix: %s\n",
ospf6_as_external_lsa_get_prefix_str(lsa, buf,
- sizeof(buf), 1));
- }
+ sizeof(buf), 0));
+
+ /* Forwarding-Address */
+ if (CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_F)) {
+ vty_out(vty, " Forwarding-Address: %s\n",
+ ospf6_as_external_lsa_get_prefix_str(
+ lsa, buf, sizeof(buf), 1));
+ }
- /* Tag */
- if (CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_T)) {
- vty_out(vty, " Tag: %" ROUTE_TAG_PRI "\n",
- ospf6_as_external_lsa_get_tag(lsa));
+ /* Tag */
+ if (CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_T)) {
+ vty_out(vty, " Tag: %" ROUTE_TAG_PRI "\n",
+ ospf6_as_external_lsa_get_tag(lsa));
+ }
}
return 0;
diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c
index 17538c466a..01e4b31c4e 100644
--- a/ospf6d/ospf6_intra.c
+++ b/ospf6d/ospf6_intra.c
@@ -92,12 +92,15 @@ static char *ospf6_router_lsa_get_nbr_id(struct ospf6_lsa *lsa, char *buf,
return buf;
}
-static int ospf6_router_lsa_show(struct vty *vty, struct ospf6_lsa *lsa)
+static int ospf6_router_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
+ json_object *json_obj, bool use_json)
{
char *start, *end, *current;
char buf[32], name[32], bits[16], options[32];
struct ospf6_router_lsa *router_lsa;
struct ospf6_router_lsdesc *lsdesc;
+ json_object *json_arr;
+ json_object *json_loop;
router_lsa =
(struct ospf6_router_lsa *)((char *)lsa->header
@@ -105,7 +108,12 @@ static int ospf6_router_lsa_show(struct vty *vty, struct ospf6_lsa *lsa)
ospf6_capability_printbuf(router_lsa->bits, bits, sizeof(bits));
ospf6_options_printbuf(router_lsa->options, options, sizeof(options));
- vty_out(vty, " Bits: %s Options: %s\n", bits, options);
+ if (use_json) {
+ json_object_string_add(json_obj, "bits", bits);
+ json_object_string_add(json_obj, "options", options);
+ json_arr = json_object_new_array();
+ } else
+ vty_out(vty, " Bits: %s Options: %s\n", bits, options);
start = (char *)router_lsa + sizeof(struct ospf6_router_lsa);
end = (char *)lsa->header + ntohs(lsa->header->length);
@@ -126,18 +134,43 @@ static int ospf6_router_lsa_show(struct vty *vty, struct ospf6_lsa *lsa)
snprintf(name, sizeof(name), "Unknown (%#x)",
lsdesc->type);
- vty_out(vty, " Type: %s Metric: %d\n", name,
- ntohs(lsdesc->metric));
- vty_out(vty, " Interface ID: %s\n",
- inet_ntop(AF_INET, &lsdesc->interface_id, buf,
- sizeof(buf)));
- vty_out(vty, " Neighbor Interface ID: %s\n",
- inet_ntop(AF_INET, &lsdesc->neighbor_interface_id, buf,
- sizeof(buf)));
- vty_out(vty, " Neighbor Router ID: %s\n",
- inet_ntop(AF_INET, &lsdesc->neighbor_router_id, buf,
- sizeof(buf)));
+ if (use_json) {
+ json_loop = json_object_new_object();
+ json_object_string_add(json_loop, "type", name);
+ json_object_int_add(json_loop, "metric",
+ ntohs(lsdesc->metric));
+ json_object_string_add(json_loop, "interfaceId",
+ inet_ntop(AF_INET,
+ &lsdesc->interface_id,
+ buf, sizeof(buf)));
+ json_object_string_add(
+ json_loop, "neighborInterfaceId",
+ inet_ntop(AF_INET,
+ &lsdesc->neighbor_interface_id, buf,
+ sizeof(buf)));
+ json_object_string_add(
+ json_loop, "neighborRouterId",
+ inet_ntop(AF_INET, &lsdesc->neighbor_router_id,
+ buf, sizeof(buf)));
+ json_object_array_add(json_arr, json_loop);
+ } else {
+ vty_out(vty, " Type: %s Metric: %d\n", name,
+ ntohs(lsdesc->metric));
+ vty_out(vty, " Interface ID: %s\n",
+ inet_ntop(AF_INET, &lsdesc->interface_id, buf,
+ sizeof(buf)));
+ vty_out(vty, " Neighbor Interface ID: %s\n",
+ inet_ntop(AF_INET,
+ &lsdesc->neighbor_interface_id, buf,
+ sizeof(buf)));
+ vty_out(vty, " Neighbor Router ID: %s\n",
+ inet_ntop(AF_INET, &lsdesc->neighbor_router_id,
+ buf, sizeof(buf)));
+ }
}
+ if (use_json)
+ json_object_object_add(json_obj, "lsaDescription", json_arr);
+
return 0;
}
@@ -421,29 +454,44 @@ static char *ospf6_network_lsa_get_ar_id(struct ospf6_lsa *lsa, char *buf,
return (buf);
}
-static int ospf6_network_lsa_show(struct vty *vty, struct ospf6_lsa *lsa)
+static int ospf6_network_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
+ json_object *json_obj, bool use_json)
{
char *start, *end, *current;
struct ospf6_network_lsa *network_lsa;
struct ospf6_network_lsdesc *lsdesc;
char buf[128], options[32];
+ json_object *json_arr;
network_lsa =
(struct ospf6_network_lsa *)((caddr_t)lsa->header
+ sizeof(struct ospf6_lsa_header));
ospf6_options_printbuf(network_lsa->options, options, sizeof(options));
- vty_out(vty, " Options: %s\n", options);
+ if (use_json)
+ json_object_string_add(json_obj, "options", options);
+ else
+ vty_out(vty, " Options: %s\n", options);
start = (char *)network_lsa + sizeof(struct ospf6_network_lsa);
end = (char *)lsa->header + ntohs(lsa->header->length);
+ if (use_json)
+ json_arr = json_object_new_array();
+
for (current = start;
current + sizeof(struct ospf6_network_lsdesc) <= end;
current += sizeof(struct ospf6_network_lsdesc)) {
lsdesc = (struct ospf6_network_lsdesc *)current;
inet_ntop(AF_INET, &lsdesc->router_id, buf, sizeof(buf));
- vty_out(vty, " Attached Router: %s\n", buf);
+ if (use_json)
+ json_object_array_add(json_arr,
+ json_object_new_string(buf));
+ else
+ vty_out(vty, " Attached Router: %s\n", buf);
}
+ if (use_json)
+ json_object_object_add(json_obj, "attachedRouter", json_arr);
+
return 0;
}
@@ -625,7 +673,8 @@ static char *ospf6_link_lsa_get_prefix_str(struct ospf6_lsa *lsa, char *buf,
return NULL;
}
-static int ospf6_link_lsa_show(struct vty *vty, struct ospf6_lsa *lsa)
+static int ospf6_link_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
+ json_object *json_obj, bool use_json)
{
char *start, *end, *current;
struct ospf6_link_lsa *link_lsa;
@@ -634,6 +683,10 @@ static int ospf6_link_lsa_show(struct vty *vty, struct ospf6_lsa *lsa)
struct ospf6_prefix *prefix;
const char *p, *mc, *la, *nu;
struct in6_addr in6;
+ json_object *json_loop;
+ json_object *json_arr = NULL;
+ char str[15];
+ char prefix_string[133];
link_lsa = (struct ospf6_link_lsa *)((caddr_t)lsa->header
+ sizeof(struct ospf6_lsa_header));
@@ -642,10 +695,18 @@ static int ospf6_link_lsa_show(struct vty *vty, struct ospf6_lsa *lsa)
inet_ntop(AF_INET6, &link_lsa->linklocal_addr, buf, sizeof(buf));
prefixnum = ntohl(link_lsa->prefix_num);
- vty_out(vty, " Priority: %d Options: %s\n", link_lsa->priority,
- options);
- vty_out(vty, " LinkLocal Address: %s\n", buf);
- vty_out(vty, " Number of Prefix: %d\n", prefixnum);
+ if (use_json) {
+ json_arr = json_object_new_array();
+ json_object_int_add(json_obj, "priority", link_lsa->priority);
+ json_object_string_add(json_obj, "options", options);
+ json_object_string_add(json_obj, "linkLocalAddress", buf);
+ json_object_int_add(json_obj, "numberOfPrefix", prefixnum);
+ } else {
+ vty_out(vty, " Priority: %d Options: %s\n",
+ link_lsa->priority, options);
+ vty_out(vty, " LinkLocal Address: %s\n", buf);
+ vty_out(vty, " Number of Prefix: %d\n", prefixnum);
+ }
start = (char *)link_lsa + sizeof(struct ospf6_link_lsa);
end = (char *)lsa->header + ntohs(lsa->header->length);
@@ -668,16 +729,31 @@ static int ospf6_link_lsa_show(struct vty *vty, struct ospf6_lsa *lsa)
nu = (CHECK_FLAG(prefix->prefix_options, OSPF6_PREFIX_OPTION_NU)
? "NU"
: "--");
- vty_out(vty, " Prefix Options: %s|%s|%s|%s\n", p, mc, la,
- nu);
+ if (use_json) {
+ json_loop = json_object_new_object();
+ snprintf(str, sizeof(str), "%s|%s|%s|%s", p, mc, la,
+ nu);
+ json_object_string_add(json_loop, "prefixOption", str);
+ } else
+ vty_out(vty, " Prefix Options: %s|%s|%s|%s\n", p,
+ mc, la, nu);
memset(&in6, 0, sizeof(in6));
memcpy(&in6, OSPF6_PREFIX_BODY(prefix),
OSPF6_PREFIX_SPACE(prefix->prefix_length));
inet_ntop(AF_INET6, &in6, buf, sizeof(buf));
- vty_out(vty, " Prefix: %s/%d\n", buf,
- prefix->prefix_length);
+ if (use_json) {
+ snprintf(prefix_string, sizeof(prefix_string), "%s/%d",
+ buf, prefix->prefix_length);
+ json_object_string_add(json_loop, "prefix",
+ prefix_string);
+ json_object_array_add(json_arr, json_loop);
+ } else
+ vty_out(vty, " Prefix: %s/%d\n", buf,
+ prefix->prefix_length);
}
+ if (use_json)
+ json_object_object_add(json_obj, "prefix", json_arr);
return 0;
}
@@ -828,7 +904,8 @@ static char *ospf6_intra_prefix_lsa_get_prefix_str(struct ospf6_lsa *lsa,
return (buf);
}
-static int ospf6_intra_prefix_lsa_show(struct vty *vty, struct ospf6_lsa *lsa)
+static int ospf6_intra_prefix_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
+ json_object *json_obj, bool use_json)
{
char *start, *end, *current;
struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
@@ -838,6 +915,10 @@ static int ospf6_intra_prefix_lsa_show(struct vty *vty, struct ospf6_lsa *lsa)
char id[16], adv_router[16];
const char *p, *mc, *la, *nu;
struct in6_addr in6;
+ json_object *json_loop;
+ json_object *json_arr = NULL;
+ char str[15];
+ char prefix_string[133];
intra_prefix_lsa = (struct ospf6_intra_prefix_lsa
*)((caddr_t)lsa->header
@@ -845,13 +926,25 @@ static int ospf6_intra_prefix_lsa_show(struct vty *vty, struct ospf6_lsa *lsa)
prefixnum = ntohs(intra_prefix_lsa->prefix_num);
- vty_out(vty, " Number of Prefix: %d\n", prefixnum);
+ if (use_json) {
+ json_arr = json_object_new_array();
+ json_object_int_add(json_obj, "numberOfPrefix", prefixnum);
+ } else
+ vty_out(vty, " Number of Prefix: %d\n", prefixnum);
inet_ntop(AF_INET, &intra_prefix_lsa->ref_id, id, sizeof(id));
inet_ntop(AF_INET, &intra_prefix_lsa->ref_adv_router, adv_router,
sizeof(adv_router));
- vty_out(vty, " Reference: %s Id: %s Adv: %s\n",
- ospf6_lstype_name(intra_prefix_lsa->ref_type), id, adv_router);
+ if (use_json) {
+ json_object_string_add(
+ json_obj, "reference",
+ ospf6_lstype_name(intra_prefix_lsa->ref_type));
+ json_object_string_add(json_obj, "referenceId", id);
+ json_object_string_add(json_obj, "referenceAdv", adv_router);
+ } else
+ vty_out(vty, " Reference: %s Id: %s Adv: %s\n",
+ ospf6_lstype_name(intra_prefix_lsa->ref_type), id,
+ adv_router);
start = (char *)intra_prefix_lsa
+ sizeof(struct ospf6_intra_prefix_lsa);
@@ -875,16 +968,31 @@ static int ospf6_intra_prefix_lsa_show(struct vty *vty, struct ospf6_lsa *lsa)
nu = (CHECK_FLAG(prefix->prefix_options, OSPF6_PREFIX_OPTION_NU)
? "NU"
: "--");
- vty_out(vty, " Prefix Options: %s|%s|%s|%s\n", p, mc, la,
- nu);
+ if (use_json) {
+ json_loop = json_object_new_object();
+ snprintf(str, sizeof(str), "%s|%s|%s|%s", p, mc, la,
+ nu);
+ json_object_string_add(json_loop, "prefixOption", str);
+ } else
+ vty_out(vty, " Prefix Options: %s|%s|%s|%s\n", p,
+ mc, la, nu);
memset(&in6, 0, sizeof(in6));
memcpy(&in6, OSPF6_PREFIX_BODY(prefix),
OSPF6_PREFIX_SPACE(prefix->prefix_length));
inet_ntop(AF_INET6, &in6, buf, sizeof(buf));
- vty_out(vty, " Prefix: %s/%d\n", buf,
- prefix->prefix_length);
+ if (use_json) {
+ snprintf(prefix_string, sizeof(prefix_string), "%s/%d",
+ buf, prefix->prefix_length);
+ json_object_string_add(json_loop, "prefix",
+ prefix_string);
+ json_object_array_add(json_arr, json_loop);
+ } else
+ vty_out(vty, " Prefix: %s/%d\n", buf,
+ prefix->prefix_length);
}
+ if (use_json)
+ json_object_object_add(json_obj, "prefix", json_arr);
return 0;
}
diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c
index 29141ee7f8..f1b04c9bec 100644
--- a/ospf6d/ospf6_lsa.c
+++ b/ospf6d/ospf6_lsa.c
@@ -66,7 +66,8 @@ struct ospf6 *ospf6_get_by_lsdb(struct ospf6_lsa *lsa)
return ospf6;
}
-static int ospf6_unknown_lsa_show(struct vty *vty, struct ospf6_lsa *lsa)
+static int ospf6_unknown_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
+ json_object *json_obj, bool use_json)
{
uint8_t *start, *end, *current;
char byte[4];
@@ -74,18 +75,22 @@ static int ospf6_unknown_lsa_show(struct vty *vty, struct ospf6_lsa *lsa)
start = (uint8_t *)lsa->header + sizeof(struct ospf6_lsa_header);
end = (uint8_t *)lsa->header + ntohs(lsa->header->length);
- vty_out(vty, " Unknown contents:\n");
- for (current = start; current < end; current++) {
- if ((current - start) % 16 == 0)
- vty_out(vty, "\n ");
- else if ((current - start) % 4 == 0)
- vty_out(vty, " ");
+ if (use_json)
+ json_object_string_add(json_obj, "LsaType", "unknown");
+ else {
+ vty_out(vty, " Unknown contents:\n");
+ for (current = start; current < end; current++) {
+ if ((current - start) % 16 == 0)
+ vty_out(vty, "\n ");
+ else if ((current - start) % 4 == 0)
+ vty_out(vty, " ");
+
+ snprintf(byte, sizeof(byte), "%02x", *current);
+ vty_out(vty, "%s", byte);
+ }
- snprintf(byte, sizeof(byte), "%02x", *current);
- vty_out(vty, "%s", byte);
+ vty_out(vty, "\n\n");
}
-
- vty_out(vty, "\n\n");
return 0;
}
@@ -392,13 +397,15 @@ void ospf6_lsa_show_summary_header(struct vty *vty)
"AdvRouter", "Age", "SeqNum", "Payload");
}
-void ospf6_lsa_show_summary(struct vty *vty, struct ospf6_lsa *lsa)
+void ospf6_lsa_show_summary(struct vty *vty, struct ospf6_lsa *lsa,
+ json_object *json_array, bool use_json)
{
char adv_router[16], id[16];
int type;
const struct ospf6_lsa_handler *handler;
- char buf[64], tmpbuf[80];
+ char buf[64];
int cnt = 0;
+ json_object *json_obj = NULL;
assert(lsa);
assert(lsa->header);
@@ -409,34 +416,95 @@ void ospf6_lsa_show_summary(struct vty *vty, struct ospf6_lsa *lsa)
type = ntohs(lsa->header->type);
handler = ospf6_get_lsa_handler(lsa->header->type);
+
+ if (use_json)
+ json_obj = json_object_new_object();
+
if ((type == OSPF6_LSTYPE_INTER_PREFIX)
|| (type == OSPF6_LSTYPE_INTER_ROUTER)
|| (type == OSPF6_LSTYPE_AS_EXTERNAL)) {
- vty_out(vty, "%-4s %-15s%-15s%4hu %8lx %30s\n",
- ospf6_lstype_short_name(lsa->header->type), id,
- adv_router, ospf6_lsa_age_current(lsa),
- (unsigned long)ntohl(lsa->header->seqnum),
- handler->lh_get_prefix_str(lsa, buf, sizeof(buf), 0));
+ if (use_json) {
+ json_object_string_add(
+ json_obj, "type",
+ ospf6_lstype_short_name(lsa->header->type));
+ json_object_string_add(json_obj, "lsId", id);
+ json_object_string_add(json_obj, "advRouter",
+ adv_router);
+ json_object_int_add(json_obj, "age",
+ ospf6_lsa_age_current(lsa));
+ json_object_int_add(
+ json_obj, "seqNum",
+ (unsigned long)ntohl(lsa->header->seqnum));
+ json_object_string_add(
+ json_obj, "payload",
+ handler->lh_get_prefix_str(lsa, buf,
+ sizeof(buf), 0));
+ json_object_array_add(json_array, json_obj);
+ } else
+ vty_out(vty, "%-4s %-15s%-15s%4hu %8lx %30s\n",
+ ospf6_lstype_short_name(lsa->header->type), id,
+ adv_router, ospf6_lsa_age_current(lsa),
+ (unsigned long)ntohl(lsa->header->seqnum),
+ handler->lh_get_prefix_str(lsa, buf,
+ sizeof(buf), 0));
} else if (type != OSPF6_LSTYPE_UNKNOWN) {
- snprintf(tmpbuf, sizeof(tmpbuf), "%-4s %-15s%-15s%4hu %8lx",
- ospf6_lstype_short_name(lsa->header->type), id,
- adv_router, ospf6_lsa_age_current(lsa),
- (unsigned long)ntohl(lsa->header->seqnum));
-
while (handler->lh_get_prefix_str(lsa, buf, sizeof(buf), cnt)
!= NULL) {
- vty_out(vty, "%s %30s\n", tmpbuf, buf);
+ if (use_json) {
+ json_object_string_add(
+ json_obj, "type",
+ ospf6_lstype_short_name(
+ lsa->header->type));
+ json_object_string_add(json_obj, "lsId", id);
+ json_object_string_add(json_obj, "advRouter",
+ adv_router);
+ json_object_int_add(json_obj, "age",
+ ospf6_lsa_age_current(lsa));
+ json_object_int_add(
+ json_obj, "seqNum",
+ (unsigned long)ntohl(
+ lsa->header->seqnum));
+ json_object_string_add(json_obj, "payload",
+ buf);
+ json_object_array_add(json_array, json_obj);
+ json_obj = json_object_new_object();
+ } else
+ vty_out(vty, "%-4s %-15s%-15s%4hu %8lx %30s\n",
+ ospf6_lstype_short_name(
+ lsa->header->type),
+ id, adv_router,
+ ospf6_lsa_age_current(lsa),
+ (unsigned long)ntohl(
+ lsa->header->seqnum),
+ buf);
cnt++;
}
+ if (use_json)
+ json_object_free(json_obj);
} else {
- vty_out(vty, "%-4s %-15s%-15s%4hu %8lx\n",
- ospf6_lstype_short_name(lsa->header->type), id,
- adv_router, ospf6_lsa_age_current(lsa),
- (unsigned long)ntohl(lsa->header->seqnum));
+ if (use_json) {
+ json_object_string_add(
+ json_obj, "type",
+ ospf6_lstype_short_name(lsa->header->type));
+ json_object_string_add(json_obj, "lsId", id);
+ json_object_string_add(json_obj, "advRouter",
+ adv_router);
+ json_object_int_add(json_obj, "age",
+ ospf6_lsa_age_current(lsa));
+ json_object_int_add(
+ json_obj, "seqNum",
+ (unsigned long)ntohl(lsa->header->seqnum));
+ json_object_array_add(json_array, json_obj);
+ } else
+ vty_out(vty, "%-4s %-15s%-15s%4hu %8lx\n",
+ ospf6_lstype_short_name(lsa->header->type), id,
+ adv_router, ospf6_lsa_age_current(lsa),
+ (unsigned long)ntohl(lsa->header->seqnum));
}
}
-void ospf6_lsa_show_dump(struct vty *vty, struct ospf6_lsa *lsa)
+void ospf6_lsa_show_dump(struct vty *vty, struct ospf6_lsa *lsa,
+ json_object *json_array, bool use_json)
{
uint8_t *start, *end, *current;
char byte[4];
@@ -444,6 +512,9 @@ void ospf6_lsa_show_dump(struct vty *vty, struct ospf6_lsa *lsa)
start = (uint8_t *)lsa->header;
end = (uint8_t *)lsa->header + ntohs(lsa->header->length);
+ if (use_json)
+ return;
+
vty_out(vty, "\n");
vty_out(vty, "%s:\n", lsa->name);
@@ -458,12 +529,15 @@ void ospf6_lsa_show_dump(struct vty *vty, struct ospf6_lsa *lsa)
}
vty_out(vty, "\n\n");
+
return;
}
-void ospf6_lsa_show_internal(struct vty *vty, struct ospf6_lsa *lsa)
+void ospf6_lsa_show_internal(struct vty *vty, struct ospf6_lsa *lsa,
+ json_object *json_array, bool use_json)
{
char adv_router[64], id[64];
+ json_object *json_obj;
assert(lsa && lsa->header);
@@ -471,30 +545,56 @@ void ospf6_lsa_show_internal(struct vty *vty, struct ospf6_lsa *lsa)
inet_ntop(AF_INET, &lsa->header->adv_router, adv_router,
sizeof(adv_router));
- vty_out(vty, "\n");
- vty_out(vty, "Age: %4hu Type: %s\n", ospf6_lsa_age_current(lsa),
- ospf6_lstype_name(lsa->header->type));
- vty_out(vty, "Link State ID: %s\n", id);
- vty_out(vty, "Advertising Router: %s\n", adv_router);
- vty_out(vty, "LS Sequence Number: %#010lx\n",
- (unsigned long)ntohl(lsa->header->seqnum));
- vty_out(vty, "CheckSum: %#06hx Length: %hu\n",
- ntohs(lsa->header->checksum), ntohs(lsa->header->length));
- vty_out(vty, "Flag: %x \n", lsa->flag);
- vty_out(vty, "Lock: %d \n", lsa->lock);
- vty_out(vty, "ReTx Count: %d\n", lsa->retrans_count);
- vty_out(vty, "Threads: Expire: 0x%p, Refresh: 0x%p \n",
- (void *)lsa->expire, (void *)lsa->refresh);
- vty_out(vty, "\n");
+ if (use_json) {
+ json_obj = json_object_new_object();
+ json_object_int_add(json_obj, "age",
+ ospf6_lsa_age_current(lsa));
+ json_object_string_add(json_obj, "type",
+ ospf6_lstype_name(lsa->header->type));
+ json_object_string_add(json_obj, "linkStateId", id);
+ json_object_string_add(json_obj, "advertisingRouter",
+ adv_router);
+ json_object_int_add(json_obj, "lsSequenceNumber",
+ (unsigned long)ntohl(lsa->header->seqnum));
+ json_object_int_add(json_obj, "checksum",
+ ntohs(lsa->header->checksum));
+ json_object_int_add(json_obj, "length",
+ ntohs(lsa->header->length));
+ json_object_int_add(json_obj, "flag", lsa->flag);
+ json_object_int_add(json_obj, "lock", lsa->lock);
+ json_object_int_add(json_obj, "reTxCount", lsa->retrans_count);
+
+ /* Threads Data not added */
+ json_object_array_add(json_array, json_obj);
+ } else {
+ vty_out(vty, "\n");
+ vty_out(vty, "Age: %4hu Type: %s\n", ospf6_lsa_age_current(lsa),
+ ospf6_lstype_name(lsa->header->type));
+ vty_out(vty, "Link State ID: %s\n", id);
+ vty_out(vty, "Advertising Router: %s\n", adv_router);
+ vty_out(vty, "LS Sequence Number: %#010lx\n",
+ (unsigned long)ntohl(lsa->header->seqnum));
+ vty_out(vty, "CheckSum: %#06hx Length: %hu\n",
+ ntohs(lsa->header->checksum),
+ ntohs(lsa->header->length));
+ vty_out(vty, "Flag: %x \n", lsa->flag);
+ vty_out(vty, "Lock: %d \n", lsa->lock);
+ vty_out(vty, "ReTx Count: %d\n", lsa->retrans_count);
+ vty_out(vty, "Threads: Expire: 0x%p, Refresh: 0x%p \n",
+ (void *)lsa->expire, (void *)lsa->refresh);
+ vty_out(vty, "\n");
+ }
return;
}
-void ospf6_lsa_show(struct vty *vty, struct ospf6_lsa *lsa)
+void ospf6_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
+ json_object *json_array, bool use_json)
{
char adv_router[64], id[64];
const struct ospf6_lsa_handler *handler;
struct timeval now, res;
char duration[64];
+ json_object *json_obj = NULL;
assert(lsa && lsa->header);
@@ -505,27 +605,47 @@ void ospf6_lsa_show(struct vty *vty, struct ospf6_lsa *lsa)
monotime(&now);
timersub(&now, &lsa->installed, &res);
timerstring(&res, duration, sizeof(duration));
-
- vty_out(vty, "Age: %4hu Type: %s\n", ospf6_lsa_age_current(lsa),
- ospf6_lstype_name(lsa->header->type));
- vty_out(vty, "Link State ID: %s\n", id);
- vty_out(vty, "Advertising Router: %s\n", adv_router);
- vty_out(vty, "LS Sequence Number: %#010lx\n",
- (unsigned long)ntohl(lsa->header->seqnum));
- vty_out(vty, "CheckSum: %#06hx Length: %hu\n",
- ntohs(lsa->header->checksum), ntohs(lsa->header->length));
- vty_out(vty, "Duration: %s\n", duration);
+ if (use_json) {
+ json_obj = json_object_new_object();
+ json_object_int_add(json_obj, "age",
+ ospf6_lsa_age_current(lsa));
+ json_object_string_add(json_obj, "type",
+ ospf6_lstype_name(lsa->header->type));
+ json_object_string_add(json_obj, "advertisingRouter",
+ adv_router);
+ json_object_int_add(json_obj, "lsSequenceNumber",
+ (unsigned long)ntohl(lsa->header->seqnum));
+ json_object_int_add(json_obj, "checkSum",
+ ntohs(lsa->header->checksum));
+ json_object_int_add(json_obj, "length",
+ ntohs(lsa->header->length));
+ json_object_string_add(json_obj, "duration", duration);
+ } else {
+ vty_out(vty, "Age: %4hu Type: %s\n", ospf6_lsa_age_current(lsa),
+ ospf6_lstype_name(lsa->header->type));
+ vty_out(vty, "Link State ID: %s\n", id);
+ vty_out(vty, "Advertising Router: %s\n", adv_router);
+ vty_out(vty, "LS Sequence Number: %#010lx\n",
+ (unsigned long)ntohl(lsa->header->seqnum));
+ vty_out(vty, "CheckSum: %#06hx Length: %hu\n",
+ ntohs(lsa->header->checksum),
+ ntohs(lsa->header->length));
+ vty_out(vty, "Duration: %s\n", duration);
+ }
handler = ospf6_get_lsa_handler(lsa->header->type);
if (handler->lh_show != NULL)
- handler->lh_show(vty, lsa);
+ handler->lh_show(vty, lsa, json_obj, use_json);
else {
assert(unknown_handler.lh_show != NULL);
- unknown_handler.lh_show(vty, lsa);
+ unknown_handler.lh_show(vty, lsa, json_obj, use_json);
}
- vty_out(vty, "\n");
+ if (use_json)
+ json_object_array_add(json_array, json_obj);
+ else
+ vty_out(vty, "\n");
}
/* OSPFv3 LSA creation/deletion function */
diff --git a/ospf6d/ospf6_lsa.h b/ospf6d/ospf6_lsa.h
index 814e276796..7fa9c5fe40 100644
--- a/ospf6d/ospf6_lsa.h
+++ b/ospf6d/ospf6_lsa.h
@@ -21,6 +21,7 @@
#ifndef OSPF6_LSA_H
#define OSPF6_LSA_H
#include "ospf6_top.h"
+#include "lib/json.h"
/* Debug option */
#define OSPF6_LSA_DEBUG 0x01
@@ -141,9 +142,10 @@ struct ospf6_lsa_handler {
uint16_t lh_type; /* host byte order */
const char *lh_name;
const char *lh_short_name;
- int (*lh_show)(struct vty *, struct ospf6_lsa *);
- char *(*lh_get_prefix_str)(struct ospf6_lsa *, char *buf,
- int buflen, int pos);
+ int (*lh_show)(struct vty *, struct ospf6_lsa *, json_object *json_obj,
+ bool use_json);
+ char *(*lh_get_prefix_str)(struct ospf6_lsa *, char *buf, int buflen,
+ int pos);
uint8_t lh_debug;
};
@@ -206,10 +208,14 @@ extern char *ospf6_lsa_printbuf(struct ospf6_lsa *lsa, char *buf, int size);
extern void ospf6_lsa_header_print_raw(struct ospf6_lsa_header *header);
extern void ospf6_lsa_header_print(struct ospf6_lsa *lsa);
extern void ospf6_lsa_show_summary_header(struct vty *vty);
-extern void ospf6_lsa_show_summary(struct vty *vty, struct ospf6_lsa *lsa);
-extern void ospf6_lsa_show_dump(struct vty *vty, struct ospf6_lsa *lsa);
-extern void ospf6_lsa_show_internal(struct vty *vty, struct ospf6_lsa *lsa);
-extern void ospf6_lsa_show(struct vty *vty, struct ospf6_lsa *lsa);
+extern void ospf6_lsa_show_summary(struct vty *vty, struct ospf6_lsa *lsa,
+ json_object *json, bool use_json);
+extern void ospf6_lsa_show_dump(struct vty *vty, struct ospf6_lsa *lsa,
+ json_object *json, bool use_json);
+extern void ospf6_lsa_show_internal(struct vty *vty, struct ospf6_lsa *lsa,
+ json_object *json, bool use_json);
+extern void ospf6_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
+ json_object *json, bool use_json);
extern struct ospf6_lsa *ospf6_lsa_create(struct ospf6_lsa_header *header);
extern struct ospf6_lsa *
diff --git a/ospf6d/ospf6_lsdb.c b/ospf6d/ospf6_lsdb.c
index c136c558cb..9636e1a230 100644
--- a/ospf6d/ospf6_lsdb.c
+++ b/ospf6d/ospf6_lsdb.c
@@ -346,55 +346,6 @@ int ospf6_lsdb_maxage_remover(struct ospf6_lsdb *lsdb)
return (reschedule);
}
-void ospf6_lsdb_show(struct vty *vty, enum ospf_lsdb_show_level level,
- uint16_t *type, uint32_t *id, uint32_t *adv_router,
- struct ospf6_lsdb *lsdb)
-{
- struct ospf6_lsa *lsa;
- const struct route_node *end = NULL;
- void (*showfunc)(struct vty *, struct ospf6_lsa *) = NULL;
-
- switch (level) {
- case OSPF6_LSDB_SHOW_LEVEL_DETAIL:
- showfunc = ospf6_lsa_show;
- break;
- case OSPF6_LSDB_SHOW_LEVEL_INTERNAL:
- showfunc = ospf6_lsa_show_internal;
- break;
- case OSPF6_LSDB_SHOW_LEVEL_DUMP:
- showfunc = ospf6_lsa_show_dump;
- break;
- case OSPF6_LSDB_SHOW_LEVEL_NORMAL:
- default:
- showfunc = ospf6_lsa_show_summary;
- }
-
- if (type && id && adv_router) {
- lsa = ospf6_lsdb_lookup(*type, *id, *adv_router, lsdb);
- if (lsa) {
- if (level == OSPF6_LSDB_SHOW_LEVEL_NORMAL)
- ospf6_lsa_show(vty, lsa);
- else
- (*showfunc)(vty, lsa);
- }
- return;
- }
-
- if (level == OSPF6_LSDB_SHOW_LEVEL_NORMAL)
- ospf6_lsa_show_summary_header(vty);
-
- end = ospf6_lsdb_head(lsdb, !!type + !!(type && adv_router),
- type ? *type : 0, adv_router ? *adv_router : 0,
- &lsa);
- while (lsa) {
- if ((!adv_router || lsa->header->adv_router == *adv_router)
- && (!id || lsa->header->id == *id))
- (*showfunc)(vty, lsa);
-
- lsa = ospf6_lsdb_next(end, lsa);
- }
-}
-
uint32_t ospf6_new_ls_id(uint16_t type, uint32_t adv_router,
struct ospf6_lsdb *lsdb)
{
diff --git a/ospf6d/ospf6_lsdb.h b/ospf6d/ospf6_lsdb.h
index 457e3dc4e4..7a62c46b02 100644
--- a/ospf6d/ospf6_lsdb.h
+++ b/ospf6d/ospf6_lsdb.h
@@ -92,7 +92,8 @@ enum ospf_lsdb_show_level {
extern void ospf6_lsdb_show(struct vty *vty, enum ospf_lsdb_show_level level,
uint16_t *type, uint32_t *id, uint32_t *adv_router,
- struct ospf6_lsdb *lsdb);
+ struct ospf6_lsdb *lsdb, json_object *json,
+ bool use_json);
extern uint32_t ospf6_new_ls_id(uint16_t type, uint32_t adv_router,
struct ospf6_lsdb *lsdb);
diff --git a/ospf6d/ospf6d.c b/ospf6d/ospf6d.c
index 4b958e550f..02eb4baf8d 100644
--- a/ospf6d/ospf6d.c
+++ b/ospf6d/ospf6d.c
@@ -44,6 +44,7 @@
#include "ospf6_flood.h"
#include "ospf6d.h"
#include "ospf6_bfd.h"
+#include "lib/json.h"
struct route_node *route_prev(struct route_node *node)
{
@@ -154,53 +155,264 @@ static uint16_t parse_type_spec(int idx_lsa, int argc, struct cmd_token **argv)
return type;
}
+void ospf6_lsdb_show(struct vty *vty, enum ospf_lsdb_show_level level,
+ uint16_t *type, uint32_t *id, uint32_t *adv_router,
+ struct ospf6_lsdb *lsdb, json_object *json_obj,
+ bool use_json)
+{
+ struct ospf6_lsa *lsa;
+ const struct route_node *end = NULL;
+ void (*showfunc)(struct vty *, struct ospf6_lsa *, json_object *,
+ bool) = NULL;
+ json_object *json_array = NULL;
+
+ switch (level) {
+ case OSPF6_LSDB_SHOW_LEVEL_DETAIL:
+ showfunc = ospf6_lsa_show;
+ break;
+ case OSPF6_LSDB_SHOW_LEVEL_INTERNAL:
+ showfunc = ospf6_lsa_show_internal;
+ break;
+ case OSPF6_LSDB_SHOW_LEVEL_DUMP:
+ showfunc = ospf6_lsa_show_dump;
+ break;
+ case OSPF6_LSDB_SHOW_LEVEL_NORMAL:
+ default:
+ showfunc = ospf6_lsa_show_summary;
+ }
+
+ if (use_json)
+ json_array = json_object_new_array();
+
+ if (type && id && adv_router) {
+ lsa = ospf6_lsdb_lookup(*type, *id, *adv_router, lsdb);
+ if (lsa) {
+ if (level == OSPF6_LSDB_SHOW_LEVEL_NORMAL)
+ ospf6_lsa_show(vty, lsa, json_array, use_json);
+ else
+ (*showfunc)(vty, lsa, json_array, use_json);
+ }
+
+ if (use_json)
+ json_object_object_add(json_obj, "lsa", json_array);
+ return;
+ }
+
+ if ((level == OSPF6_LSDB_SHOW_LEVEL_NORMAL) && !use_json)
+ ospf6_lsa_show_summary_header(vty);
+
+ end = ospf6_lsdb_head(lsdb, !!type + !!(type && adv_router),
+ type ? *type : 0, adv_router ? *adv_router : 0,
+ &lsa);
+ while (lsa) {
+ if ((!adv_router || lsa->header->adv_router == *adv_router)
+ && (!id || lsa->header->id == *id))
+ (*showfunc)(vty, lsa, json_array, use_json);
+ lsa = ospf6_lsdb_next(end, lsa);
+ }
+
+ if (use_json)
+ json_object_object_add(json_obj, "lsa", json_array);
+}
+
+static void ospf6_lsdb_show_wrapper(struct vty *vty,
+ enum ospf_lsdb_show_level level,
+ uint16_t *type, uint32_t *id,
+ uint32_t *adv_router, bool uj,
+ struct ospf6 *ospf6)
+{
+ struct listnode *i, *j;
+ struct ospf6 *o = ospf6;
+ struct ospf6_area *oa;
+ struct ospf6_interface *oi;
+ json_object *json = NULL;
+ json_object *json_array = NULL;
+ json_object *json_obj = NULL;
+
+ if (uj) {
+ json = json_object_new_object();
+ json_array = json_object_new_array();
+ }
+ for (ALL_LIST_ELEMENTS_RO(o->area_list, i, oa)) {
+ if (uj) {
+ json_obj = json_object_new_object();
+ json_object_string_add(json_obj, "areaId", oa->name);
+ } else
+ vty_out(vty, AREA_LSDB_TITLE_FORMAT, oa->name);
+ ospf6_lsdb_show(vty, level, type, id, adv_router, oa->lsdb,
+ json_obj, uj);
+ if (uj)
+ json_object_array_add(json_array, json_obj);
+ }
+ if (uj)
+ json_object_object_add(json, "areaScopedLinkStateDb",
+ json_array);
+
+ if (uj)
+ json_array = json_object_new_array();
+ for (ALL_LIST_ELEMENTS_RO(o->area_list, i, oa)) {
+ for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi)) {
+ if (uj) {
+ json_obj = json_object_new_object();
+ json_object_string_add(json_obj, "areaId",
+ oa->name);
+ json_object_string_add(json_obj, "interface",
+ oi->interface->name);
+ } else
+ vty_out(vty, IF_LSDB_TITLE_FORMAT,
+ oi->interface->name, oa->name);
+ ospf6_lsdb_show(vty, level, type, id, adv_router,
+ oi->lsdb, json_obj, uj);
+ if (uj)
+ json_object_array_add(json_array, json_obj);
+ }
+ }
+ if (uj)
+ json_object_object_add(json, "interfaceScopedLinkStateDb",
+ json_array);
+ if (uj) {
+ json_array = json_object_new_array();
+ json_obj = json_object_new_object();
+ } else
+ vty_out(vty, AS_LSDB_TITLE_FORMAT);
+
+ ospf6_lsdb_show(vty, level, type, id, adv_router, o->lsdb, json_obj,
+ uj);
+
+ if (uj) {
+ json_object_array_add(json_array, json_obj);
+ json_object_object_add(json, "asScopedLinkStateDb", json_array);
+
+ vty_out(vty, "%s\n",
+ json_object_to_json_string_ext(
+ json, JSON_C_TO_STRING_PRETTY));
+ json_object_free(json);
+ } else
+ vty_out(vty, "\n");
+}
+
+static void ospf6_lsdb_type_show_wrapper(struct vty *vty,
+ enum ospf_lsdb_show_level level,
+ uint16_t *type, uint32_t *id,
+ uint32_t *adv_router, bool uj,
+ struct ospf6 *ospf6)
+{
+ struct listnode *i, *j;
+ struct ospf6 *o = ospf6;
+ struct ospf6_area *oa;
+ struct ospf6_interface *oi;
+ json_object *json = NULL;
+ json_object *json_array = NULL;
+ json_object *json_obj = NULL;
+
+ if (uj) {
+ json = json_object_new_object();
+ json_array = json_object_new_array();
+ }
+
+ switch (OSPF6_LSA_SCOPE(*type)) {
+ case OSPF6_SCOPE_AREA:
+ for (ALL_LIST_ELEMENTS_RO(o->area_list, i, oa)) {
+ if (uj) {
+ json_obj = json_object_new_object();
+ json_object_string_add(json_obj, "areaId",
+ oa->name);
+ } else
+ vty_out(vty, AREA_LSDB_TITLE_FORMAT, oa->name);
+
+ ospf6_lsdb_show(vty, level, type, id, adv_router,
+ oa->lsdb, json_obj, uj);
+ if (uj)
+ json_object_array_add(json_array, json_obj);
+ }
+ if (uj)
+ json_object_object_add(json, "areaScopedLinkStateDb",
+ json_array);
+ break;
+
+ case OSPF6_SCOPE_LINKLOCAL:
+ for (ALL_LIST_ELEMENTS_RO(o->area_list, i, oa)) {
+ for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi)) {
+ if (uj) {
+ json_obj = json_object_new_object();
+ json_object_string_add(
+ json_obj, "areaId", oa->name);
+ json_object_string_add(
+ json_obj, "interface",
+ oi->interface->name);
+ } else
+ vty_out(vty, IF_LSDB_TITLE_FORMAT,
+ oi->interface->name, oa->name);
+
+ ospf6_lsdb_show(vty, level, type, id,
+ adv_router, oi->lsdb, json_obj,
+ uj);
+
+ if (uj)
+ json_object_array_add(json_array,
+ json_obj);
+ }
+ }
+ if (uj)
+ json_object_object_add(
+ json, "interfaceScopedLinkStateDb", json_array);
+ break;
+
+ case OSPF6_SCOPE_AS:
+ if (uj)
+ json_obj = json_object_new_object();
+ else
+ vty_out(vty, AS_LSDB_TITLE_FORMAT);
+
+ ospf6_lsdb_show(vty, level, type, id, adv_router, o->lsdb,
+ json_obj, uj);
+ if (uj) {
+ json_object_array_add(json_array, json_obj);
+ json_object_object_add(json, "asScopedLinkStateDb",
+ json_array);
+ }
+ break;
+
+ default:
+ assert(0);
+ break;
+ }
+ if (uj) {
+ vty_out(vty, "%s\n",
+ json_object_to_json_string_ext(
+ json, JSON_C_TO_STRING_PRETTY));
+ json_object_free(json);
+ } else
+ vty_out(vty, "\n");
+}
+
DEFUN (show_ipv6_ospf6_database,
show_ipv6_ospf6_database_cmd,
- "show ipv6 ospf6 database [<detail|dump|internal>]",
+ "show ipv6 ospf6 database [<detail|dump|internal>] [json]",
SHOW_STR
IPV6_STR
OSPF6_STR
"Display Link state database\n"
"Display details of LSAs\n"
"Dump LSAs\n"
- "Display LSA's internal information\n")
+ "Display LSA's internal information\n"
+ JSON_STR)
{
int idx_level = 4;
int level;
- struct listnode *i, *j;
+ bool uj = use_json(argc, argv);
struct ospf6 *ospf6;
- struct ospf6_area *oa;
- struct ospf6_interface *oi;
-
ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
OSPF6_CMD_CHECK_RUNNING(ospf6);
level = parse_show_level(idx_level, argc, argv);
-
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- vty_out(vty, AREA_LSDB_TITLE_FORMAT, oa->name);
- ospf6_lsdb_show(vty, level, NULL, NULL, NULL, oa->lsdb);
- }
-
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi)) {
- vty_out(vty, IF_LSDB_TITLE_FORMAT, oi->interface->name,
- oa->name);
- ospf6_lsdb_show(vty, level, NULL, NULL, NULL, oi->lsdb);
- }
- }
-
- vty_out(vty, AS_LSDB_TITLE_FORMAT);
- ospf6_lsdb_show(vty, level, NULL, NULL, NULL, ospf6->lsdb);
-
- vty_out(vty, "\n");
+ ospf6_lsdb_show_wrapper(vty, level, NULL, NULL, NULL, uj, ospf6);
return CMD_SUCCESS;
}
-DEFUN (show_ipv6_ospf6_database_type,
- show_ipv6_ospf6_database_type_cmd,
- "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> [<detail|dump|internal>]",
+DEFUN (show_ipv6_ospf6_database_type, show_ipv6_ospf6_database_type_cmd,
+ "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> [<detail|dump|internal>] [json]",
SHOW_STR
IPV6_STR
OSPF6_STR
@@ -217,16 +429,14 @@ DEFUN (show_ipv6_ospf6_database_type,
"Display details of LSAs\n"
"Dump LSAs\n"
"Display LSA's internal information\n"
- )
+ JSON_STR)
{
int idx_lsa = 4;
int idx_level = 5;
int level;
- struct listnode *i, *j;
- struct ospf6 *ospf6;
- struct ospf6_area *oa;
- struct ospf6_interface *oi;
uint16_t type = 0;
+ bool uj = use_json(argc, argv);
+ struct ospf6 *ospf6;
ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
@@ -235,43 +445,13 @@ DEFUN (show_ipv6_ospf6_database_type,
type = parse_type_spec(idx_lsa, argc, argv);
level = parse_show_level(idx_level, argc, argv);
- switch (OSPF6_LSA_SCOPE(type)) {
- case OSPF6_SCOPE_AREA:
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- vty_out(vty, AREA_LSDB_TITLE_FORMAT, oa->name);
- ospf6_lsdb_show(vty, level, &type, NULL, NULL,
- oa->lsdb);
- }
- break;
-
- case OSPF6_SCOPE_LINKLOCAL:
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi)) {
- vty_out(vty, IF_LSDB_TITLE_FORMAT,
- oi->interface->name, oa->name);
- ospf6_lsdb_show(vty, level, &type, NULL, NULL,
- oi->lsdb);
- }
- }
- break;
-
- case OSPF6_SCOPE_AS:
- vty_out(vty, AS_LSDB_TITLE_FORMAT);
- ospf6_lsdb_show(vty, level, &type, NULL, NULL, ospf6->lsdb);
- break;
-
- default:
- assert(0);
- break;
- }
-
- vty_out(vty, "\n");
+ ospf6_lsdb_type_show_wrapper(vty, level, &type, NULL, NULL, uj, ospf6);
return CMD_SUCCESS;
}
DEFUN (show_ipv6_ospf6_database_id,
show_ipv6_ospf6_database_id_cmd,
- "show ipv6 ospf6 database <*|linkstate-id> A.B.C.D [<detail|dump|internal>]",
+ "show ipv6 ospf6 database <*|linkstate-id> A.B.C.D [<detail|dump|internal>] [json]",
SHOW_STR
IPV6_STR
OSPF6_STR
@@ -281,16 +461,15 @@ DEFUN (show_ipv6_ospf6_database_id,
"Specify Link state ID as IPv4 address notation\n"
"Display details of LSAs\n"
"Dump LSAs\n"
- "Display LSA's internal information\n")
+ "Display LSA's internal information\n"
+ JSON_STR)
{
int idx_ipv4 = 5;
int idx_level = 6;
int level;
- struct listnode *i, *j;
- struct ospf6 *ospf6;
- struct ospf6_area *oa;
- struct ospf6_interface *oi;
uint32_t id = 0;
+ bool uj = use_json(argc, argv);
+ struct ospf6 *ospf6;
ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
@@ -300,30 +479,14 @@ DEFUN (show_ipv6_ospf6_database_id,
inet_pton(AF_INET, argv[idx_ipv4]->arg, &id);
level = parse_show_level(idx_level, argc, argv);
+ ospf6_lsdb_show_wrapper(vty, level, NULL, &id, NULL, uj, ospf6);
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- vty_out(vty, AREA_LSDB_TITLE_FORMAT, oa->name);
- ospf6_lsdb_show(vty, level, NULL, &id, NULL, oa->lsdb);
- }
-
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi)) {
- vty_out(vty, IF_LSDB_TITLE_FORMAT, oi->interface->name,
- oa->name);
- ospf6_lsdb_show(vty, level, NULL, &id, NULL, oi->lsdb);
- }
- }
-
- vty_out(vty, AS_LSDB_TITLE_FORMAT);
- ospf6_lsdb_show(vty, level, NULL, &id, NULL, ospf6->lsdb);
-
- vty_out(vty, "\n");
return CMD_SUCCESS;
}
DEFUN (show_ipv6_ospf6_database_router,
show_ipv6_ospf6_database_router_cmd,
- "show ipv6 ospf6 database <*|adv-router> * A.B.C.D <detail|dump|internal>",
+ "show ipv6 ospf6 database <*|adv-router> * A.B.C.D <detail|dump|internal> [json]",
SHOW_STR
IPV6_STR
OSPF6_STR
@@ -334,16 +497,15 @@ DEFUN (show_ipv6_ospf6_database_router,
"Specify Advertising Router as IPv4 address notation\n"
"Display details of LSAs\n"
"Dump LSAs\n"
- "Display LSA's internal information\n")
+ "Display LSA's internal information\n"
+ JSON_STR)
{
int idx_ipv4 = 6;
int idx_level = 7;
int level;
- struct listnode *i, *j;
- struct ospf6 *ospf6;
- struct ospf6_area *oa;
- struct ospf6_interface *oi;
uint32_t adv_router = 0;
+ bool uj = use_json(argc, argv);
+ struct ospf6 *ospf6;
ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
@@ -351,24 +513,7 @@ DEFUN (show_ipv6_ospf6_database_router,
inet_pton(AF_INET, argv[idx_ipv4]->arg, &adv_router);
level = parse_show_level(idx_level, argc, argv);
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- vty_out(vty, AREA_LSDB_TITLE_FORMAT, oa->name);
- ospf6_lsdb_show(vty, level, NULL, NULL, &adv_router, oa->lsdb);
- }
-
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi)) {
- vty_out(vty, IF_LSDB_TITLE_FORMAT, oi->interface->name,
- oa->name);
- ospf6_lsdb_show(vty, level, NULL, NULL, &adv_router,
- oi->lsdb);
- }
- }
-
- vty_out(vty, AS_LSDB_TITLE_FORMAT);
- ospf6_lsdb_show(vty, level, NULL, NULL, &adv_router, ospf6->lsdb);
-
- vty_out(vty, "\n");
+ ospf6_lsdb_show_wrapper(vty, level, NULL, NULL, &adv_router, uj, ospf6);
return CMD_SUCCESS;
}
@@ -408,7 +553,7 @@ DEFUN_HIDDEN (show_ipv6_ospf6_database_aggr_router,
return CMD_SUCCESS;
}
ospf6_lsdb_show(vty, level, &type, NULL, NULL,
- oa->temp_router_lsa_lsdb);
+ oa->temp_router_lsa_lsdb, NULL, false);
/* Remove the temp cache */
ospf6_remove_temp_router_lsa(oa);
}
@@ -420,7 +565,7 @@ DEFUN_HIDDEN (show_ipv6_ospf6_database_aggr_router,
DEFUN (show_ipv6_ospf6_database_type_id,
show_ipv6_ospf6_database_type_id_cmd,
- "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> linkstate-id A.B.C.D [<detail|dump|internal>]",
+ "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> linkstate-id A.B.C.D [<detail|dump|internal>] [json]",
SHOW_STR
IPV6_STR
OSPF6_STR
@@ -439,18 +584,16 @@ DEFUN (show_ipv6_ospf6_database_type_id,
"Display details of LSAs\n"
"Dump LSAs\n"
"Display LSA's internal information\n"
- )
+ JSON_STR)
{
int idx_lsa = 4;
int idx_ipv4 = 6;
int idx_level = 7;
int level;
- struct listnode *i, *j;
- struct ospf6 *ospf6;
- struct ospf6_area *oa;
- struct ospf6_interface *oi;
uint16_t type = 0;
uint32_t id = 0;
+ bool uj = use_json(argc, argv);
+ struct ospf6 *ospf6;
ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
@@ -460,42 +603,13 @@ DEFUN (show_ipv6_ospf6_database_type_id,
inet_pton(AF_INET, argv[idx_ipv4]->arg, &id);
level = parse_show_level(idx_level, argc, argv);
- switch (OSPF6_LSA_SCOPE(type)) {
- case OSPF6_SCOPE_AREA:
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- vty_out(vty, AREA_LSDB_TITLE_FORMAT, oa->name);
- ospf6_lsdb_show(vty, level, &type, &id, NULL, oa->lsdb);
- }
- break;
-
- case OSPF6_SCOPE_LINKLOCAL:
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi)) {
- vty_out(vty, IF_LSDB_TITLE_FORMAT,
- oi->interface->name, oa->name);
- ospf6_lsdb_show(vty, level, &type, &id, NULL,
- oi->lsdb);
- }
- }
- break;
-
- case OSPF6_SCOPE_AS:
- vty_out(vty, AS_LSDB_TITLE_FORMAT);
- ospf6_lsdb_show(vty, level, &type, &id, NULL, ospf6->lsdb);
- break;
-
- default:
- assert(0);
- break;
- }
-
- vty_out(vty, "\n");
+ ospf6_lsdb_type_show_wrapper(vty, level, &type, &id, NULL, uj, ospf6);
return CMD_SUCCESS;
}
DEFUN (show_ipv6_ospf6_database_type_router,
show_ipv6_ospf6_database_type_router_cmd,
- "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> <*|adv-router> A.B.C.D [<detail|dump|internal>]",
+ "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> <*|adv-router> A.B.C.D [<detail|dump|internal>] [json]",
SHOW_STR
IPV6_STR
OSPF6_STR
@@ -515,18 +629,16 @@ DEFUN (show_ipv6_ospf6_database_type_router,
"Display details of LSAs\n"
"Dump LSAs\n"
"Display LSA's internal information\n"
- )
+ JSON_STR)
{
int idx_lsa = 4;
int idx_ipv4 = 6;
int idx_level = 7;
int level;
- struct listnode *i, *j;
- struct ospf6 *ospf6;
- struct ospf6_area *oa;
- struct ospf6_interface *oi;
uint16_t type = 0;
uint32_t adv_router = 0;
+ bool uj = use_json(argc, argv);
+ struct ospf6 *ospf6;
ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
@@ -535,45 +647,15 @@ DEFUN (show_ipv6_ospf6_database_type_router,
inet_pton(AF_INET, argv[idx_ipv4]->arg, &adv_router);
level = parse_show_level(idx_level, argc, argv);
- switch (OSPF6_LSA_SCOPE(type)) {
- case OSPF6_SCOPE_AREA:
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- vty_out(vty, AREA_LSDB_TITLE_FORMAT, oa->name);
- ospf6_lsdb_show(vty, level, &type, NULL, &adv_router,
- oa->lsdb);
- }
- break;
-
- case OSPF6_SCOPE_LINKLOCAL:
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi)) {
- vty_out(vty, IF_LSDB_TITLE_FORMAT,
- oi->interface->name, oa->name);
- ospf6_lsdb_show(vty, level, &type, NULL,
- &adv_router, oi->lsdb);
- }
- }
- break;
-
- case OSPF6_SCOPE_AS:
- vty_out(vty, AS_LSDB_TITLE_FORMAT);
- ospf6_lsdb_show(vty, level, &type, NULL, &adv_router,
- ospf6->lsdb);
- break;
-
- default:
- assert(0);
- break;
- }
-
- vty_out(vty, "\n");
+ ospf6_lsdb_type_show_wrapper(vty, level, &type, NULL, &adv_router, uj,
+ ospf6);
return CMD_SUCCESS;
}
DEFUN (show_ipv6_ospf6_database_id_router,
show_ipv6_ospf6_database_id_router_cmd,
- "show ipv6 ospf6 database * A.B.C.D A.B.C.D [<detail|dump|internal>]",
+ "show ipv6 ospf6 database * A.B.C.D A.B.C.D [<detail|dump|internal>] [json]",
SHOW_STR
IPV6_STR
OSPF6_STR
@@ -584,18 +666,16 @@ DEFUN (show_ipv6_ospf6_database_id_router,
"Display details of LSAs\n"
"Dump LSAs\n"
"Display LSA's internal information\n"
- )
+ JSON_STR)
{
int idx_ls_id = 5;
int idx_adv_rtr = 6;
int idx_level = 7;
int level;
- struct listnode *i, *j;
- struct ospf6 *ospf6;
- struct ospf6_area *oa;
- struct ospf6_interface *oi;
uint32_t id = 0;
uint32_t adv_router = 0;
+ bool uj = use_json(argc, argv);
+ struct ospf6 *ospf6;
ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
OSPF6_CMD_CHECK_RUNNING(ospf6);
@@ -603,31 +683,14 @@ DEFUN (show_ipv6_ospf6_database_id_router,
inet_pton(AF_INET, argv[idx_adv_rtr]->arg, &adv_router);
level = parse_show_level(idx_level, argc, argv);
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- vty_out(vty, AREA_LSDB_TITLE_FORMAT, oa->name);
- ospf6_lsdb_show(vty, level, NULL, &id, &adv_router, oa->lsdb);
- }
-
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi)) {
- vty_out(vty, IF_LSDB_TITLE_FORMAT, oi->interface->name,
- oa->name);
- ospf6_lsdb_show(vty, level, NULL, &id, &adv_router,
- oi->lsdb);
- }
- }
-
- vty_out(vty, AS_LSDB_TITLE_FORMAT);
- ospf6_lsdb_show(vty, level, NULL, &id, &adv_router, ospf6->lsdb);
-
- vty_out(vty, "\n");
+ ospf6_lsdb_show_wrapper(vty, level, NULL, &id, &adv_router, uj, ospf6);
return CMD_SUCCESS;
}
DEFUN (show_ipv6_ospf6_database_adv_router_linkstate_id,
show_ipv6_ospf6_database_adv_router_linkstate_id_cmd,
- "show ipv6 ospf6 database adv-router A.B.C.D linkstate-id A.B.C.D [<detail|dump|internal>]",
+ "show ipv6 ospf6 database adv-router A.B.C.D linkstate-id A.B.C.D [<detail|dump|internal>] [json]",
SHOW_STR
IPV6_STR
OSPF6_STR
@@ -638,18 +701,17 @@ DEFUN (show_ipv6_ospf6_database_adv_router_linkstate_id,
"Specify Link state ID as IPv4 address notation\n"
"Display details of LSAs\n"
"Dump LSAs\n"
- "Display LSA's internal information\n")
+ "Display LSA's internal information\n"
+ JSON_STR)
{
int idx_adv_rtr = 5;
int idx_ls_id = 7;
int idx_level = 8;
int level;
- struct listnode *i, *j;
- struct ospf6 *ospf6;
- struct ospf6_area *oa;
- struct ospf6_interface *oi;
uint32_t id = 0;
uint32_t adv_router = 0;
+ bool uj = use_json(argc, argv);
+ struct ospf6 *ospf6;
ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
@@ -658,30 +720,13 @@ DEFUN (show_ipv6_ospf6_database_adv_router_linkstate_id,
inet_pton(AF_INET, argv[idx_ls_id]->arg, &id);
level = parse_show_level(idx_level, argc, argv);
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- vty_out(vty, AREA_LSDB_TITLE_FORMAT, oa->name);
- ospf6_lsdb_show(vty, level, NULL, &id, &adv_router, oa->lsdb);
- }
-
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi)) {
- vty_out(vty, IF_LSDB_TITLE_FORMAT, oi->interface->name,
- oa->name);
- ospf6_lsdb_show(vty, level, NULL, &id, &adv_router,
- oi->lsdb);
- }
- }
-
- vty_out(vty, AS_LSDB_TITLE_FORMAT);
- ospf6_lsdb_show(vty, level, NULL, &id, &adv_router, ospf6->lsdb);
-
- vty_out(vty, "\n");
+ ospf6_lsdb_show_wrapper(vty, level, NULL, &id, &adv_router, uj, ospf6);
return CMD_SUCCESS;
}
DEFUN (show_ipv6_ospf6_database_type_id_router,
show_ipv6_ospf6_database_type_id_router_cmd,
- "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> A.B.C.D A.B.C.D [<dump|internal>]",
+ "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> A.B.C.D A.B.C.D [<dump|internal>] [json]",
SHOW_STR
IPV6_STR
OSPF6_STR
@@ -698,20 +743,19 @@ DEFUN (show_ipv6_ospf6_database_type_id_router,
"Specify Link state ID as IPv4 address notation\n"
"Specify Advertising Router as IPv4 address notation\n"
"Dump LSAs\n"
- "Display LSA's internal information\n")
+ "Display LSA's internal information\n"
+ JSON_STR)
{
int idx_lsa = 4;
int idx_ls_id = 5;
int idx_adv_rtr = 6;
int idx_level = 7;
int level;
- struct listnode *i, *j;
- struct ospf6 *ospf6;
- struct ospf6_area *oa;
- struct ospf6_interface *oi;
uint16_t type = 0;
uint32_t id = 0;
uint32_t adv_router = 0;
+ bool uj = use_json(argc, argv);
+ struct ospf6 *ospf6;
ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
@@ -722,45 +766,15 @@ DEFUN (show_ipv6_ospf6_database_type_id_router,
inet_pton(AF_INET, argv[idx_adv_rtr]->arg, &adv_router);
level = parse_show_level(idx_level, argc, argv);
- switch (OSPF6_LSA_SCOPE(type)) {
- case OSPF6_SCOPE_AREA:
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- vty_out(vty, AREA_LSDB_TITLE_FORMAT, oa->name);
- ospf6_lsdb_show(vty, level, &type, &id, &adv_router,
- oa->lsdb);
- }
- break;
-
- case OSPF6_SCOPE_LINKLOCAL:
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi)) {
- vty_out(vty, IF_LSDB_TITLE_FORMAT,
- oi->interface->name, oa->name);
- ospf6_lsdb_show(vty, level, &type, &id,
- &adv_router, oi->lsdb);
- }
- }
- break;
-
- case OSPF6_SCOPE_AS:
- vty_out(vty, AS_LSDB_TITLE_FORMAT);
- ospf6_lsdb_show(vty, level, &type, &id, &adv_router,
- ospf6->lsdb);
- break;
-
- default:
- assert(0);
- break;
- }
-
- vty_out(vty, "\n");
+ ospf6_lsdb_type_show_wrapper(vty, level, &type, &id, &adv_router, uj,
+ ospf6);
return CMD_SUCCESS;
}
DEFUN (show_ipv6_ospf6_database_type_adv_router_linkstate_id,
show_ipv6_ospf6_database_type_adv_router_linkstate_id_cmd,
- "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> adv-router A.B.C.D linkstate-id A.B.C.D [<dump|internal>]",
+ "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> adv-router A.B.C.D linkstate-id A.B.C.D [<dump|internal>] [json]",
SHOW_STR
IPV6_STR
OSPF6_STR
@@ -779,20 +793,19 @@ DEFUN (show_ipv6_ospf6_database_type_adv_router_linkstate_id,
"Search by Link state ID\n"
"Specify Link state ID as IPv4 address notation\n"
"Dump LSAs\n"
- "Display LSA's internal information\n")
+ "Display LSA's internal information\n"
+ JSON_STR)
{
int idx_lsa = 4;
int idx_adv_rtr = 6;
int idx_ls_id = 8;
int idx_level = 9;
int level;
- struct listnode *i, *j;
- struct ospf6 *ospf6;
- struct ospf6_area *oa;
- struct ospf6_interface *oi;
uint16_t type = 0;
uint32_t id = 0;
uint32_t adv_router = 0;
+ bool uj = use_json(argc, argv);
+ struct ospf6 *ospf6;
ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
@@ -803,44 +816,14 @@ DEFUN (show_ipv6_ospf6_database_type_adv_router_linkstate_id,
inet_pton(AF_INET, argv[idx_ls_id]->arg, &id);
level = parse_show_level(idx_level, argc, argv);
- switch (OSPF6_LSA_SCOPE(type)) {
- case OSPF6_SCOPE_AREA:
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- vty_out(vty, AREA_LSDB_TITLE_FORMAT, oa->name);
- ospf6_lsdb_show(vty, level, &type, &id, &adv_router,
- oa->lsdb);
- }
- break;
-
- case OSPF6_SCOPE_LINKLOCAL:
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi)) {
- vty_out(vty, IF_LSDB_TITLE_FORMAT,
- oi->interface->name, oa->name);
- ospf6_lsdb_show(vty, level, &type, &id,
- &adv_router, oi->lsdb);
- }
- }
- break;
-
- case OSPF6_SCOPE_AS:
- vty_out(vty, AS_LSDB_TITLE_FORMAT);
- ospf6_lsdb_show(vty, level, &type, &id, &adv_router,
- ospf6->lsdb);
- break;
-
- default:
- assert(0);
- break;
- }
-
- vty_out(vty, "\n");
+ ospf6_lsdb_type_show_wrapper(vty, level, &type, &id, &adv_router, uj,
+ ospf6);
return CMD_SUCCESS;
}
DEFUN (show_ipv6_ospf6_database_self_originated,
show_ipv6_ospf6_database_self_originated_cmd,
- "show ipv6 ospf6 database self-originated [<detail|dump|internal>]",
+ "show ipv6 ospf6 database self-originated [<detail|dump|internal>] [json]",
SHOW_STR
IPV6_STR
OSPF6_STR
@@ -848,46 +831,28 @@ DEFUN (show_ipv6_ospf6_database_self_originated,
"Display Self-originated LSAs\n"
"Display details of LSAs\n"
"Dump LSAs\n"
- "Display LSA's internal information\n")
+ "Display LSA's internal information\n"
+ JSON_STR)
{
int idx_level = 5;
int level;
- struct listnode *i, *j;
- struct ospf6 *ospf6;
- struct ospf6_area *oa;
- struct ospf6_interface *oi;
uint32_t adv_router = 0;
+ bool uj = use_json(argc, argv);
+ struct ospf6 *ospf6;
ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
OSPF6_CMD_CHECK_RUNNING(ospf6);
level = parse_show_level(idx_level, argc, argv);
adv_router = ospf6->router_id;
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- vty_out(vty, AREA_LSDB_TITLE_FORMAT, oa->name);
- ospf6_lsdb_show(vty, level, NULL, NULL, &adv_router, oa->lsdb);
- }
-
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi)) {
- vty_out(vty, IF_LSDB_TITLE_FORMAT, oi->interface->name,
- oa->name);
- ospf6_lsdb_show(vty, level, NULL, NULL, &adv_router,
- oi->lsdb);
- }
- }
-
- vty_out(vty, AS_LSDB_TITLE_FORMAT);
- ospf6_lsdb_show(vty, level, NULL, NULL, &adv_router, ospf6->lsdb);
-
- vty_out(vty, "\n");
+ ospf6_lsdb_show_wrapper(vty, level, NULL, NULL, &adv_router, uj, ospf6);
return CMD_SUCCESS;
}
DEFUN (show_ipv6_ospf6_database_type_self_originated,
show_ipv6_ospf6_database_type_self_originated_cmd,
- "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> self-originated [<detail|dump|internal>]",
+ "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> self-originated [<detail|dump|internal>] [json]",
SHOW_STR
IPV6_STR
OSPF6_STR
@@ -904,17 +869,16 @@ DEFUN (show_ipv6_ospf6_database_type_self_originated,
"Display Self-originated LSAs\n"
"Display details of LSAs\n"
"Dump LSAs\n"
- "Display LSA's internal information\n")
+ "Display LSA's internal information\n"
+ JSON_STR)
{
int idx_lsa = 4;
int idx_level = 6;
int level;
- struct listnode *i, *j;
- struct ospf6 *ospf6;
- struct ospf6_area *oa;
- struct ospf6_interface *oi;
uint16_t type = 0;
uint32_t adv_router = 0;
+ bool uj = use_json(argc, argv);
+ struct ospf6 *ospf6;
ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
OSPF6_CMD_CHECK_RUNNING(ospf6);
@@ -923,44 +887,14 @@ DEFUN (show_ipv6_ospf6_database_type_self_originated,
adv_router = ospf6->router_id;
- switch (OSPF6_LSA_SCOPE(type)) {
- case OSPF6_SCOPE_AREA:
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- vty_out(vty, AREA_LSDB_TITLE_FORMAT, oa->name);
- ospf6_lsdb_show(vty, level, &type, NULL, &adv_router,
- oa->lsdb);
- }
- break;
-
- case OSPF6_SCOPE_LINKLOCAL:
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi)) {
- vty_out(vty, IF_LSDB_TITLE_FORMAT,
- oi->interface->name, oa->name);
- ospf6_lsdb_show(vty, level, &type, NULL,
- &adv_router, oi->lsdb);
- }
- }
- break;
-
- case OSPF6_SCOPE_AS:
- vty_out(vty, AS_LSDB_TITLE_FORMAT);
- ospf6_lsdb_show(vty, level, &type, NULL, &adv_router,
- ospf6->lsdb);
- break;
-
- default:
- assert(0);
- break;
- }
-
- vty_out(vty, "\n");
+ ospf6_lsdb_type_show_wrapper(vty, level, &type, NULL, &adv_router, uj,
+ ospf6);
return CMD_SUCCESS;
}
DEFUN (show_ipv6_ospf6_database_type_self_originated_linkstate_id,
show_ipv6_ospf6_database_type_self_originated_linkstate_id_cmd,
- "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> self-originated linkstate-id A.B.C.D [<detail|dump|internal>]",
+ "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> self-originated linkstate-id A.B.C.D [<detail|dump|internal>] [json]",
SHOW_STR
IPV6_STR
OSPF6_STR
@@ -979,19 +913,18 @@ DEFUN (show_ipv6_ospf6_database_type_self_originated_linkstate_id,
"Specify Link state ID as IPv4 address notation\n"
"Display details of LSAs\n"
"Dump LSAs\n"
- "Display LSA's internal information\n")
+ "Display LSA's internal information\n"
+ JSON_STR)
{
int idx_lsa = 4;
int idx_ls_id = 7;
int idx_level = 8;
int level;
- struct listnode *i, *j;
- struct ospf6 *ospf6;
- struct ospf6_area *oa;
- struct ospf6_interface *oi;
uint16_t type = 0;
uint32_t adv_router = 0;
uint32_t id = 0;
+ bool uj = use_json(argc, argv);
+ struct ospf6 *ospf6;
ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
OSPF6_CMD_CHECK_RUNNING(ospf6);
@@ -1000,44 +933,14 @@ DEFUN (show_ipv6_ospf6_database_type_self_originated_linkstate_id,
level = parse_show_level(idx_level, argc, argv);
adv_router = ospf6->router_id;
- switch (OSPF6_LSA_SCOPE(type)) {
- case OSPF6_SCOPE_AREA:
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- vty_out(vty, AREA_LSDB_TITLE_FORMAT, oa->name);
- ospf6_lsdb_show(vty, level, &type, &id, &adv_router,
- oa->lsdb);
- }
- break;
-
- case OSPF6_SCOPE_LINKLOCAL:
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi)) {
- vty_out(vty, IF_LSDB_TITLE_FORMAT,
- oi->interface->name, oa->name);
- ospf6_lsdb_show(vty, level, &type, &id,
- &adv_router, oi->lsdb);
- }
- }
- break;
-
- case OSPF6_SCOPE_AS:
- vty_out(vty, AS_LSDB_TITLE_FORMAT);
- ospf6_lsdb_show(vty, level, &type, &id, &adv_router,
- ospf6->lsdb);
- break;
-
- default:
- assert(0);
- break;
- }
-
- vty_out(vty, "\n");
+ ospf6_lsdb_type_show_wrapper(vty, level, &type, &id, &adv_router, uj,
+ ospf6);
return CMD_SUCCESS;
}
DEFUN (show_ipv6_ospf6_database_type_id_self_originated,
show_ipv6_ospf6_database_type_id_self_originated_cmd,
- "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> A.B.C.D self-originated [<detail|dump|internal>]",
+ "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> A.B.C.D self-originated [<detail|dump|internal>] [json]",
SHOW_STR
IPV6_STR
OSPF6_STR
@@ -1055,19 +958,18 @@ DEFUN (show_ipv6_ospf6_database_type_id_self_originated,
"Display Self-originated LSAs\n"
"Display details of LSAs\n"
"Dump LSAs\n"
- "Display LSA's internal information\n")
+ "Display LSA's internal information\n"
+ JSON_STR)
{
int idx_lsa = 4;
int idx_ls_id = 5;
int idx_level = 7;
int level;
- struct listnode *i, *j;
- struct ospf6 *ospf6;
- struct ospf6_area *oa;
- struct ospf6_interface *oi;
uint16_t type = 0;
uint32_t adv_router = 0;
uint32_t id = 0;
+ bool uj = use_json(argc, argv);
+ struct ospf6 *ospf6;
ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
OSPF6_CMD_CHECK_RUNNING(ospf6);
@@ -1076,38 +978,8 @@ DEFUN (show_ipv6_ospf6_database_type_id_self_originated,
level = parse_show_level(idx_level, argc, argv);
adv_router = ospf6->router_id;
- switch (OSPF6_LSA_SCOPE(type)) {
- case OSPF6_SCOPE_AREA:
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- vty_out(vty, AREA_LSDB_TITLE_FORMAT, oa->name);
- ospf6_lsdb_show(vty, level, &type, &id, &adv_router,
- oa->lsdb);
- }
- break;
-
- case OSPF6_SCOPE_LINKLOCAL:
- for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
- for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi)) {
- vty_out(vty, IF_LSDB_TITLE_FORMAT,
- oi->interface->name, oa->name);
- ospf6_lsdb_show(vty, level, &type, &id,
- &adv_router, oi->lsdb);
- }
- }
- break;
-
- case OSPF6_SCOPE_AS:
- vty_out(vty, AS_LSDB_TITLE_FORMAT);
- ospf6_lsdb_show(vty, level, &type, &id, &adv_router,
- ospf6->lsdb);
- break;
-
- default:
- assert(0);
- break;
- }
-
- vty_out(vty, "\n");
+ ospf6_lsdb_type_show_wrapper(vty, level, &type, &id, &adv_router, uj,
+ ospf6);
return CMD_SUCCESS;
}