summaryrefslogtreecommitdiffstats
path: root/src/vnet/interface_format.c
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2019-09-11 21:35:48 -0400
committerDave Barach <dave@barachs.net>2019-09-16 16:18:10 -0400
commit5554c56a65cff3ef90844eb5e63d89283fae74df (patch)
treea4f299ec718601f2929c7003e9ab141b6e70cdfb /src/vnet/interface_format.c
parentda9513af296b54ac0299206862e9654ae2431bf7 (diff)
http_static: add dynamic GET / POST method hooks
Add .json output to format_vnet_sw_interface_cntrs(...) Type: feature Signed-off-by: Dave Barach <dave@barachs.net> Change-Id: Ied036ebfaaafbf1dfc2a4e396c00f09f40659400
Diffstat (limited to 'src/vnet/interface_format.c')
-rw-r--r--src/vnet/interface_format.c43
1 files changed, 40 insertions, 3 deletions
diff --git a/src/vnet/interface_format.c b/src/vnet/interface_format.c
index 47546c57f93..347dd4940d4 100644
--- a/src/vnet/interface_format.c
+++ b/src/vnet/interface_format.c
@@ -214,12 +214,21 @@ format_vnet_hw_if_index_name (u8 * s, va_list * args)
u8 *
format_vnet_sw_interface_cntrs (u8 * s, vnet_interface_main_t * im,
- vnet_sw_interface_t * si)
+ vnet_sw_interface_t * si, int json)
{
u32 indent, n_printed;
int j, n_counters;
+ char *x = "";
+ int json_need_comma_nl = 0;
u8 *n = 0;
+ /*
+ * to output a json snippet, stick quotes in lots of places
+ * definitely deserves a one-character variable name.
+ */
+ if (json)
+ x = "\"";
+
indent = format_get_indent (s);
n_printed = 0;
@@ -242,6 +251,21 @@ format_vnet_sw_interface_cntrs (u8 * s, vnet_interface_main_t * im,
if (vtotal.packets == 0)
continue;
+ if (json)
+ {
+ if (json_need_comma_nl)
+ {
+ vec_add1 (s, ',');
+ vec_add1 (s, '\n');
+ }
+ s = format (s, "%s%s_packets%s: %s%Ld%s,\n", x, cm->name, x, x,
+ vtotal.packets, x);
+ s = format (s, "%s%s_bytes%s: %s%Ld%s", x, cm->name, x, x,
+ vtotal.bytes, x);
+ json_need_comma_nl = 1;
+ continue;
+ }
+
if (n_printed > 0)
s = format (s, "\n%U", format_white_space, indent);
n_printed += 2;
@@ -277,6 +301,19 @@ format_vnet_sw_interface_cntrs (u8 * s, vnet_interface_main_t * im,
if (vtotal == 0)
continue;
+ if (json)
+ {
+ if (json_need_comma_nl)
+ {
+ vec_add1 (s, ',');
+ vec_add1 (s, '\n');
+ }
+ s = format (s, "%s%s%s: %s%Ld%s", x, cm->name, x, x, vtotal, x);
+ json_need_comma_nl = 1;
+ continue;
+ }
+
+
if (n_printed > 0)
s = format (s, "\n%U", format_white_space, indent);
n_printed += 1;
@@ -315,7 +352,7 @@ format_vnet_sw_interface (u8 * s, va_list * args)
format_vnet_sw_interface_flags, si->flags,
format_vnet_sw_interface_mtu, si);
- s = format_vnet_sw_interface_cntrs (s, im, si);
+ s = format_vnet_sw_interface_cntrs (s, im, si, 0 /* want json */ );
return s;
}
@@ -338,7 +375,7 @@ format_vnet_sw_interface_name_override (u8 * s, va_list * args)
name, si->sw_if_index,
format_vnet_sw_interface_flags, si->flags);
- s = format_vnet_sw_interface_cntrs (s, im, si);
+ s = format_vnet_sw_interface_cntrs (s, im, si, 0 /* want json */ );
return s;
}