Thread (3 messages) flat view 3 messages, 2 authors, 2021-04-17

Re: [RFC iproute2-next v2] seg6: add counters support for SRv6 Behaviors

From: Paolo Lungaroni <hidden>
Date: 2021-04-17 23:36:45

Quoting Stephen Hemminger [off-list ref]:
On Thu, 15 Apr 2021 20:06:43 +0200
Paolo Lungaroni [off-list ref] wrote:
quoted
+	if (is_json_context())
+		open_json_object("stats64");
+
+	if (tb[SEG6_LOCAL_CNT_PACKETS]) {
+		packets = rta_getattr_u64(tb[SEG6_LOCAL_CNT_PACKETS]);
+		if (is_json_context()) {
+			print_u64(PRINT_JSON, "packets", NULL, packets);
+		} else {
+			print_string(PRINT_FP, NULL, "%s ", "packets");
+			print_num(fp, 1, packets);
+		}
+	}
+
+	if (tb[SEG6_LOCAL_CNT_BYTES]) {
+		bytes = rta_getattr_u64(tb[SEG6_LOCAL_CNT_BYTES]);
+		if (is_json_context()) {
+			print_u64(PRINT_JSON, "bytes", NULL, bytes);
+		} else {
+			print_string(PRINT_FP, NULL, "%s ", "bytes");
+			print_num(fp, 1, bytes);
+		}
+	}
+
+	if (tb[SEG6_LOCAL_CNT_ERRORS]) {
+		errors = rta_getattr_u64(tb[SEG6_LOCAL_CNT_ERRORS]);
+		if (is_json_context()) {
+			print_u64(PRINT_JSON, "errors", NULL, errors);
+		} else {
+			print_string(PRINT_FP, NULL, "%s ", "errors");
+			print_num(fp, 1, errors);
+		}
+	}
+
+	if (is_json_context())
+		close_json_object();

The code would be cleaner with doing if (is_json_context()) once at  
outer loop.
See print_vf_stats64.
Hi Stephen,

thank you for your suggestion. We will change the code as you suggest.

Paolo.


Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help