diff mbox series

[iproute2-next] tipc: enable printing of broadcast rcv link stats

Message ID 20200526094055.17526-1-tuong.t.lien@dektech.com.au
State Accepted
Delegated to: David Ahern
Headers show
Series [iproute2-next] tipc: enable printing of broadcast rcv link stats | expand

Commit Message

Tuong Lien May 26, 2020, 9:40 a.m. UTC
This commit allows printing the statistics of a broadcast-receiver link
using the same tipc command, but with additional 'link' options:

$ tipc link stat show --help
Usage: tipc link stat show [ link { LINK | SUBSTRING | all } ]

With:
+ 'LINK'      : print the stats of the specific link 'LINK';
+ 'SUBSTRING' : print the stats of all the links having the 'SUBSTRING'
                in name;
+ 'all'       : print all the links' stats incl. the broadcast-receiver
                ones;

Also, a link stats can be reset in the usual way by specifying the link
name in command.

For example:

$ tipc l st sh l br
Link <broadcast-link>
  Window:50 packets
  RX packets:0 fragments:0/0 bundles:0/0
  TX packets:5011125 fragments:4968774/149643 bundles:38402/307061
  RX naks:781484 defs:0 dups:0
  TX naks:0 acks:0 retrans:330259
  Congestion link:50657  Send queue max:0 avg:0

Link <broadcast-link:1001001>
  Window:50 packets
  RX packets:95146 fragments:95040/1980 bundles:1/2
  TX packets:0 fragments:0/0 bundles:0/0
  RX naks:380938 defs:83962 dups:403
  TX naks:8362 acks:0 retrans:170662
  Congestion link:0  Send queue max:0 avg:0

Link <broadcast-link:1001002>
  Window:50 packets
  RX packets:0 fragments:0/0 bundles:0/0
  TX packets:0 fragments:0/0 bundles:0/0
  RX naks:400546 defs:0 dups:0
  TX naks:0 acks:0 retrans:159597
  Congestion link:0  Send queue max:0 avg:0

$ tipc l st sh l 1001002
Link <1001003:data0-1001002:data0>
  ACTIVE  MTU:1500  Priority:10  Tolerance:1500 ms  Window:50 packets
  RX packets:99546 fragments:0/0 bundles:33/877
  TX packets:629 fragments:0/0 bundles:35/828
  TX profile sample:8 packets average:390 octets
  0-64:75% -256:0% -1024:0% -4096:25% -16384:0% -32768:0% -66000:0%
  RX states:488714 probes:7397 naks:0 defs:4 dups:5
  TX states:27734 probes:18016 naks:5 acks:2305 retrans:0
  Congestion link:0  Send queue max:0 avg:0

Link <broadcast-link:1001002>
  Window:50 packets
  RX packets:0 fragments:0/0 bundles:0/0
  TX packets:0 fragments:0/0 bundles:0/0
  RX naks:400546 defs:0 dups:0
  TX naks:0 acks:0 retrans:159597
  Congestion link:0  Send queue max:0 avg:0

$ tipc l st re l broadcast-link:1001002

$ tipc l st sh l broadcast-link:1001002
Link <broadcast-link:1001002>
  Window:50 packets
  RX packets:0 fragments:0/0 bundles:0/0
  TX packets:0 fragments:0/0 bundles:0/0
  RX naks:0 defs:0 dups:0
  TX naks:0 acks:0 retrans:0
  Congestion link:0  Send queue max:0 avg:0

Acked-by: Ying Xue <ying.xue@windriver.com>
Acked-by: Jon Maloy <jmaloy@redhat.com>
Signed-off-by: Tuong Lien <tuong.t.lien@dektech.com.au>
---
 tipc/link.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

Comments

David Ahern May 27, 2020, 2:09 a.m. UTC | #1
On 5/26/20 3:40 AM, Tuong Lien wrote:
> This commit allows printing the statistics of a broadcast-receiver link
> using the same tipc command, but with additional 'link' options:
> 
> $ tipc link stat show --help
> Usage: tipc link stat show [ link { LINK | SUBSTRING | all } ]
> 
> With:
> + 'LINK'      : print the stats of the specific link 'LINK';
> + 'SUBSTRING' : print the stats of all the links having the 'SUBSTRING'
>                 in name;
> + 'all'       : print all the links' stats incl. the broadcast-receiver
>                 ones;
> 
> Also, a link stats can be reset in the usual way by specifying the link
> name in command.
> 
> For example:
> 
> $ tipc l st sh l br
> Link <broadcast-link>
>   Window:50 packets
>   RX packets:0 fragments:0/0 bundles:0/0
>   TX packets:5011125 fragments:4968774/149643 bundles:38402/307061
>   RX naks:781484 defs:0 dups:0
>   TX naks:0 acks:0 retrans:330259
>   Congestion link:50657  Send queue max:0 avg:0
> 
> Link <broadcast-link:1001001>
>   Window:50 packets
>   RX packets:95146 fragments:95040/1980 bundles:1/2
>   TX packets:0 fragments:0/0 bundles:0/0
>   RX naks:380938 defs:83962 dups:403
>   TX naks:8362 acks:0 retrans:170662
>   Congestion link:0  Send queue max:0 avg:0
> 
> Link <broadcast-link:1001002>
>   Window:50 packets
>   RX packets:0 fragments:0/0 bundles:0/0
>   TX packets:0 fragments:0/0 bundles:0/0
>   RX naks:400546 defs:0 dups:0
>   TX naks:0 acks:0 retrans:159597
>   Congestion link:0  Send queue max:0 avg:0
> 
> $ tipc l st sh l 1001002
> Link <1001003:data0-1001002:data0>
>   ACTIVE  MTU:1500  Priority:10  Tolerance:1500 ms  Window:50 packets
>   RX packets:99546 fragments:0/0 bundles:33/877
>   TX packets:629 fragments:0/0 bundles:35/828
>   TX profile sample:8 packets average:390 octets
>   0-64:75% -256:0% -1024:0% -4096:25% -16384:0% -32768:0% -66000:0%
>   RX states:488714 probes:7397 naks:0 defs:4 dups:5
>   TX states:27734 probes:18016 naks:5 acks:2305 retrans:0
>   Congestion link:0  Send queue max:0 avg:0
> 
> Link <broadcast-link:1001002>
>   Window:50 packets
>   RX packets:0 fragments:0/0 bundles:0/0
>   TX packets:0 fragments:0/0 bundles:0/0
>   RX naks:400546 defs:0 dups:0
>   TX naks:0 acks:0 retrans:159597
>   Congestion link:0  Send queue max:0 avg:0
> 
> $ tipc l st re l broadcast-link:1001002
> 
> $ tipc l st sh l broadcast-link:1001002
> Link <broadcast-link:1001002>
>   Window:50 packets
>   RX packets:0 fragments:0/0 bundles:0/0
>   TX packets:0 fragments:0/0 bundles:0/0
>   RX naks:0 defs:0 dups:0
>   TX naks:0 acks:0 retrans:0
>   Congestion link:0  Send queue max:0 avg:0
> 
> Acked-by: Ying Xue <ying.xue@windriver.com>
> Acked-by: Jon Maloy <jmaloy@redhat.com>
> Signed-off-by: Tuong Lien <tuong.t.lien@dektech.com.au>
> ---
>  tipc/link.c | 25 +++++++++++++++++--------
>  1 file changed, 17 insertions(+), 8 deletions(-)
> 

Applied to iproute2-next. Thanks for the examples in the commit message.
diff mbox series

Patch

diff --git a/tipc/link.c b/tipc/link.c
index e123c186..ba77a201 100644
--- a/tipc/link.c
+++ b/tipc/link.c
@@ -334,7 +334,7 @@  static int _show_link_stat(const char *name, struct nlattr *attrs[],
 
 	open_json_object(NULL);
 
-	print_string(PRINT_ANY, "link", "\nLink <%s>\n", name);
+	print_string(PRINT_ANY, "link", "Link <%s>\n", name);
 	print_string(PRINT_JSON, "state", "", NULL);
 	open_json_array(PRINT_JSON, NULL);
 	if (attrs[TIPC_NLA_LINK_ACTIVE])
@@ -433,7 +433,7 @@  static int _show_link_stat(const char *name, struct nlattr *attrs[],
 			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_LINK_CONGS]));
 	print_uint(PRINT_ANY, "send queue max", "  Send queue max:%u",
 			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_MAX_QUEUE]));
-	print_uint(PRINT_ANY, "avg", " avg:%u\n",
+	print_uint(PRINT_ANY, "avg", " avg:%u\n\n",
 			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_AVG_QUEUE]));
 
 	close_json_object();
@@ -496,7 +496,7 @@  static int _show_bc_link_stat(const char *name, struct nlattr *prop[],
 			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_LINK_CONGS]));
 	print_uint(PRINT_ANY, "send queue max", "  Send queue max:%u",
 			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_MAX_QUEUE]));
-	print_uint(PRINT_ANY, "avg", " avg:%u\n",
+	print_uint(PRINT_ANY, "avg", " avg:%u\n\n",
 			   mnl_attr_get_u32(stats[TIPC_NLA_STATS_AVG_QUEUE]));
 	close_json_object();
 
@@ -527,8 +527,10 @@  static int link_stat_show_cb(const struct nlmsghdr *nlh, void *data)
 
 	name = mnl_attr_get_str(attrs[TIPC_NLA_LINK_NAME]);
 
-	/* If a link is passed, skip all but that link */
-	if (link && (strcmp(name, link) != 0))
+	/* If a link is passed, skip all but that link.
+	 * Support a substring matching as well.
+	 */
+	if (link && !strstr(name, link))
 		return MNL_CB_OK;
 
 	if (attrs[TIPC_NLA_LINK_BROADCAST]) {
@@ -540,7 +542,7 @@  static int link_stat_show_cb(const struct nlmsghdr *nlh, void *data)
 
 static void cmd_link_stat_show_help(struct cmdl *cmdl)
 {
-	fprintf(stderr, "Usage: %s link stat show [ link LINK ]\n",
+	fprintf(stderr, "Usage: %s link stat show [ link { LINK | SUBSTRING | all } ]\n",
 		cmdl->argv[0]);
 }
 
@@ -554,6 +556,7 @@  static int cmd_link_stat_show(struct nlmsghdr *nlh, const struct cmd *cmd,
 		{ "link",		OPT_KEYVAL,	NULL },
 		{ NULL }
 	};
+	struct nlattr *attrs;
 	int err = 0;
 
 	if (help_flag) {
@@ -571,8 +574,14 @@  static int cmd_link_stat_show(struct nlmsghdr *nlh, const struct cmd *cmd,
 		return -EINVAL;
 
 	opt = get_opt(opts, "link");
-	if (opt)
-		link = opt->val;
+	if (opt) {
+		if (strcmp(opt->val, "all"))
+			link = opt->val;
+		/* Set the flag to dump all bc links */
+		attrs = mnl_attr_nest_start(nlh, TIPC_NLA_LINK);
+		mnl_attr_put(nlh, TIPC_NLA_LINK_BROADCAST, 0, NULL);
+		mnl_attr_nest_end(nlh, attrs);
+	}
 
 	new_json_obj(json);
 	err = msg_dumpit(nlh, link_stat_show_cb, link);