All of lore.kernel.org
 help / color / mirror / Atom feed
* [iproute2-next v2 1/3] tipc: add link broadcast set method and ratio
@ 2019-03-22  8:47 Hoang Le
  2019-03-22  8:47 ` [iproute2-next v2 2/3] tipc: add link broadcast get Hoang Le
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Hoang Le @ 2019-03-22  8:47 UTC (permalink / raw)
  To: jon.maloy, maloy, ying.xue, netdev, tipc-discussion

The command added here makes it possible to forcibly configure the
broadcast link to use either broadcast or replicast, in addition to
the already existing auto selection algorithm.

A sample usage is shown below:
$tipc link set broadcast BROADCAST
$tipc link set broadcast AUTOSELECT ratio 25

$tipc link set broadcast -h
Usage: tipc link set broadcast PROPERTY

PROPERTIES
 BROADCAST         - Forces all multicast traffic to be
                     transmitted via broadcast only,
                     irrespective of cluster size and number
                     of destinations

 REPLICAST         - Forces all multicast traffic to be
                     transmitted via replicast only,
                     irrespective of cluster size and number
                     of destinations

 AUTOSELECT        - Auto switching to broadcast or replicast
                     depending on cluster size and destination
                     node number

 ratio SIZE        - Set the AUTOSELECT criteria, percentage of
                     destination nodes vs cluster size

Acked-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: Hoang Le <hoang.h.le@dektech.com.au>
---
 include/uapi/linux/tipc_netlink.h |  2 +
 tipc/link.c                       | 96 ++++++++++++++++++++++++++++++-
 2 files changed, 97 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/tipc_netlink.h b/include/uapi/linux/tipc_netlink.h
index 0ebe02ef1a86..efb958fd167d 100644
--- a/include/uapi/linux/tipc_netlink.h
+++ b/include/uapi/linux/tipc_netlink.h
@@ -281,6 +281,8 @@ enum {
 	TIPC_NLA_PROP_TOL,		/* u32 */
 	TIPC_NLA_PROP_WIN,		/* u32 */
 	TIPC_NLA_PROP_MTU,		/* u32 */
+	TIPC_NLA_PROP_BROADCAST,	/* u32 */
+	TIPC_NLA_PROP_BROADCAST_RATIO,	/* u32 */
 
 	__TIPC_NLA_PROP_MAX,
 	TIPC_NLA_PROP_MAX = __TIPC_NLA_PROP_MAX - 1
diff --git a/tipc/link.c b/tipc/link.c
index 43e26da3fa6b..e3b10bb7b3d4 100644
--- a/tipc/link.c
+++ b/tipc/link.c
@@ -28,6 +28,9 @@
 #define PRIORITY_STR "priority"
 #define TOLERANCE_STR "tolerance"
 #define WINDOW_STR "window"
+#define BROADCAST_STR "broadcast"
+
+static const char tipc_bclink_name[] = "broadcast-link";
 
 static int link_list_cb(const struct nlmsghdr *nlh, void *data)
 {
@@ -521,7 +524,8 @@ static void cmd_link_set_help(struct cmdl *cmdl)
 		"PROPERTIES\n"
 		" tolerance TOLERANCE   - Set link tolerance\n"
 		" priority PRIORITY     - Set link priority\n"
-		" window WINDOW         - Set link window\n",
+		" window WINDOW         - Set link window\n"
+		" broadcast BROADCAST   - Set link broadcast\n",
 		cmdl->argv[0]);
 }
 
@@ -585,6 +589,95 @@ static int cmd_link_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd,
 	return msg_doit(nlh, link_get_cb, &prop);
 }
 
+static void cmd_link_set_bcast_help(struct cmdl *cmdl)
+{
+	fprintf(stderr, "Usage: %s link set broadcast PROPERTY\n\n"
+		"PROPERTIES\n"
+		" BROADCAST         - Forces all multicast traffic to be\n"
+		"                     transmitted via broadcast only,\n"
+		"                     irrespective of cluster size and number\n"
+		"                     of destinations\n\n"
+		" REPLICAST         - Forces all multicast traffic to be\n"
+		"                     transmitted via replicast only,\n"
+		"                     irrespective of cluster size and number\n"
+		"                     of destinations\n\n"
+		" AUTOSELECT        - Auto switching to broadcast or replicast\n"
+		"                     depending on cluster size and destination\n"
+		"                     node number\n\n"
+		" ratio SIZE        - Set the AUTOSELECT criteria, percentage of\n"
+		"                     destination nodes vs cluster size\n\n",
+		cmdl->argv[0]);
+}
+
+static int cmd_link_set_bcast(struct nlmsghdr *nlh, const struct cmd *cmd,
+			     struct cmdl *cmdl, void *data)
+{
+	char buf[MNL_SOCKET_BUFFER_SIZE];
+	struct nlattr *props;
+	struct nlattr *attrs;
+	struct opt *opt;
+	struct opt opts[] = {
+		{ "BROADCAST",	OPT_KEY, NULL },
+		{ "REPLICAST",	OPT_KEY, NULL },
+		{ "AUTOSELECT",	OPT_KEY, NULL },
+		{ "ratio",	OPT_KEYVAL,	NULL },
+		{ NULL }
+	};
+	int method = 0;
+
+	if (help_flag) {
+		(cmd->help)(cmdl);
+		return -EINVAL;
+	}
+
+	if (parse_opts(opts, cmdl) < 0)
+		return -EINVAL;
+
+	for (opt = opts; opt->key; opt++)
+		if (opt->val)
+			break;
+
+	if (!opt || !opt->key) {
+		(cmd->help)(cmdl);
+		return -EINVAL;
+	}
+
+	nlh = msg_init(buf, TIPC_NL_LINK_SET);
+	if (!nlh) {
+		fprintf(stderr, "error, message initialisation failed\n");
+		return -1;
+	}
+
+	attrs = mnl_attr_nest_start(nlh, TIPC_NLA_LINK);
+	/* Direct to broadcast-link setting */
+	mnl_attr_put_strz(nlh, TIPC_NLA_LINK_NAME, tipc_bclink_name);
+	props = mnl_attr_nest_start(nlh, TIPC_NLA_LINK_PROP);
+
+	if (get_opt(opts, "BROADCAST"))
+		method = 0x1;
+	else if (get_opt(opts, "REPLICAST"))
+		method = 0x2;
+	else if (get_opt(opts, "AUTOSELECT"))
+		method = 0x4;
+
+	opt = get_opt(opts, "ratio");
+	if (!method && !opt) {
+		(cmd->help)(cmdl);
+		return -EINVAL;
+	}
+
+	if (method)
+		mnl_attr_put_u32(nlh, TIPC_NLA_PROP_BROADCAST, method);
+
+	if (opt)
+		mnl_attr_put_u32(nlh, TIPC_NLA_PROP_BROADCAST_RATIO,
+				 atoi(opt->val));
+
+	mnl_attr_nest_end(nlh, props);
+	mnl_attr_nest_end(nlh, attrs);
+	return msg_doit(nlh, NULL, NULL);
+}
+
 static int cmd_link_set(struct nlmsghdr *nlh, const struct cmd *cmd,
 			struct cmdl *cmdl, void *data)
 {
@@ -592,6 +685,7 @@ static int cmd_link_set(struct nlmsghdr *nlh, const struct cmd *cmd,
 		{ PRIORITY_STR,	cmd_link_set_prop,	cmd_link_set_help },
 		{ TOLERANCE_STR,	cmd_link_set_prop,	cmd_link_set_help },
 		{ WINDOW_STR,	cmd_link_set_prop,	cmd_link_set_help },
+		{ BROADCAST_STR, cmd_link_set_bcast, cmd_link_set_bcast_help },
 		{ NULL }
 	};
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [iproute2-next v2 2/3] tipc: add link broadcast get
  2019-03-22  8:47 [iproute2-next v2 1/3] tipc: add link broadcast set method and ratio Hoang Le
@ 2019-03-22  8:47 ` Hoang Le
  2019-03-22  8:47 ` [iproute2-next v2 3/3] tipc: add link broadcast man page Hoang Le
  2019-03-26 23:14 ` [iproute2-next v2 1/3] tipc: add link broadcast set method and ratio David Ahern
  2 siblings, 0 replies; 4+ messages in thread
From: Hoang Le @ 2019-03-22  8:47 UTC (permalink / raw)
  To: jon.maloy, maloy, ying.xue, netdev, tipc-discussion

The command prints the actually method that multicast
is running in the system.
Also 'ratio' value for AUTOSELECT method.

A sample usage is shown below:
$tipc link get broadcast
BROADCAST

$tipc link get broadcast
AUTOSELECT ratio:30%

$tipc link get broadcast -j -p
[ {
        "method": "AUTOSELECT"
    },{
        "ratio": 30
    } ]

Acked-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: Hoang Le <hoang.h.le@dektech.com.au>
---
 tipc/link.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 84 insertions(+), 1 deletion(-)

diff --git a/tipc/link.c b/tipc/link.c
index e3b10bb7b3d4..e123c1863575 100644
--- a/tipc/link.c
+++ b/tipc/link.c
@@ -175,10 +175,92 @@ static void cmd_link_get_help(struct cmdl *cmdl)
 		"PROPERTIES\n"
 		" tolerance             - Get link tolerance\n"
 		" priority              - Get link priority\n"
-		" window                - Get link window\n",
+		" window                - Get link window\n"
+		" broadcast             - Get link broadcast\n",
 		cmdl->argv[0]);
 }
 
+static int cmd_link_get_bcast_cb(const struct nlmsghdr *nlh, void *data)
+{
+	int *prop = data;
+	int prop_ratio = TIPC_NLA_PROP_BROADCAST_RATIO;
+	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
+	struct nlattr *info[TIPC_NLA_MAX + 1] = {};
+	struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1] = {};
+	struct nlattr *props[TIPC_NLA_PROP_MAX + 1] = {};
+	int bc_mode;
+
+	mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info);
+	if (!info[TIPC_NLA_LINK])
+		return MNL_CB_ERROR;
+
+	mnl_attr_parse_nested(info[TIPC_NLA_LINK], parse_attrs, attrs);
+	if (!attrs[TIPC_NLA_LINK_PROP])
+		return MNL_CB_ERROR;
+
+	mnl_attr_parse_nested(attrs[TIPC_NLA_LINK_PROP], parse_attrs, props);
+	if (!props[*prop])
+		return MNL_CB_ERROR;
+
+	bc_mode = mnl_attr_get_u32(props[*prop]);
+
+	new_json_obj(json);
+	open_json_object(NULL);
+	switch (bc_mode) {
+	case 0x1:
+		print_string(PRINT_ANY, "method", "%s\n", "BROADCAST");
+		break;
+	case 0x2:
+		print_string(PRINT_ANY, "method", "%s\n", "REPLICAST");
+		break;
+	case 0x4:
+		print_string(PRINT_ANY, "method", "%s", "AUTOSELECT");
+		close_json_object();
+		open_json_object(NULL);
+		print_uint(PRINT_ANY, "ratio", " ratio:%u%\n",
+			   mnl_attr_get_u32(props[prop_ratio]));
+		break;
+	default:
+		print_string(PRINT_ANY, NULL, "UNKNOWN\n", NULL);
+		break;
+	}
+	close_json_object();
+	delete_json_obj();
+	return MNL_CB_OK;
+}
+
+static void cmd_link_get_bcast_help(struct cmdl *cmdl)
+{
+	fprintf(stderr, "Usage: %s link get PPROPERTY\n\n"
+		"PROPERTIES\n"
+		" broadcast             - Get link broadcast\n",
+		cmdl->argv[0]);
+}
+
+static int cmd_link_get_bcast(struct nlmsghdr *nlh, const struct cmd *cmd,
+			     struct cmdl *cmdl, void *data)
+{
+	int prop = TIPC_NLA_PROP_BROADCAST;
+	char buf[MNL_SOCKET_BUFFER_SIZE];
+	struct nlattr *attrs;
+
+	if (help_flag) {
+		(cmd->help)(cmdl);
+		return -EINVAL;
+	}
+
+	nlh = msg_init(buf, TIPC_NL_LINK_GET);
+	if (!nlh) {
+		fprintf(stderr, "error, message initialisation failed\n");
+		return -1;
+	}
+	attrs = mnl_attr_nest_start(nlh, TIPC_NLA_LINK);
+	/* Direct to broadcast-link setting */
+	mnl_attr_put_strz(nlh, TIPC_NLA_LINK_NAME, tipc_bclink_name);
+	mnl_attr_nest_end(nlh, attrs);
+	return msg_doit(nlh, cmd_link_get_bcast_cb, &prop);
+}
+
 static int cmd_link_get(struct nlmsghdr *nlh, const struct cmd *cmd,
 			struct cmdl *cmdl, void *data)
 {
@@ -186,6 +268,7 @@ static int cmd_link_get(struct nlmsghdr *nlh, const struct cmd *cmd,
 		{ PRIORITY_STR,	cmd_link_get_prop,	cmd_link_get_help },
 		{ TOLERANCE_STR,	cmd_link_get_prop,	cmd_link_get_help },
 		{ WINDOW_STR,	cmd_link_get_prop,	cmd_link_get_help },
+		{ BROADCAST_STR, cmd_link_get_bcast, cmd_link_get_bcast_help },
 		{ NULL }
 	};
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [iproute2-next v2 3/3] tipc: add link broadcast man page
  2019-03-22  8:47 [iproute2-next v2 1/3] tipc: add link broadcast set method and ratio Hoang Le
  2019-03-22  8:47 ` [iproute2-next v2 2/3] tipc: add link broadcast get Hoang Le
@ 2019-03-22  8:47 ` Hoang Le
  2019-03-26 23:14 ` [iproute2-next v2 1/3] tipc: add link broadcast set method and ratio David Ahern
  2 siblings, 0 replies; 4+ messages in thread
From: Hoang Le @ 2019-03-22  8:47 UTC (permalink / raw)
  To: jon.maloy, maloy, ying.xue, netdev, tipc-discussion

Add a man page describing tipc link broadcast command get and set

Signed-off-by: Hoang Le <hoang.h.le@dektech.com.au>
---
 man/man8/tipc-link.8 | 53 +++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 48 insertions(+), 5 deletions(-)

diff --git a/man/man8/tipc-link.8 b/man/man8/tipc-link.8
index 01afa1c3ad9f..47dae25d3626 100644
--- a/man/man8/tipc-link.8
+++ b/man/man8/tipc-link.8
@@ -1,4 +1,4 @@
-.TH TIPC-LINK 8 "02 Jun 2015" "iproute2" "Linux"
+.TH TIPC-LINK 8 "22 Mar 2019" "iproute2" "Linux"
 
 .\" For consistency, please keep padding right aligned.
 .\" For example '.B "foo " bar' and not '.B foo " bar"'
@@ -14,18 +14,36 @@ tipc-link \- show links or modify link properties
 
 .ti -8
 .B tipc link set
-.RB "{ " "priority "
+.br
+.RB "[ " "{ " "priority "
 .IR PRIORITY
 .RB "| " tolerance
 .IR TOLERANCE
 .RB "| " window
 .IR "WINDOW " }
-.BI "link " LINK
+.BI "link " LINK " ]"
+.RB "|"
+.br
+.RB "[ "
+.RB "{ " broadcast " [ "
+.IR BROADCAST
+.RB " | "
+.IR REPLICAST
+.RB " | "
+.IR AUTOSELECT
+.RB "[ " ratio
+.IR SIZE
+.RB "] " ] " } " "]"
 
 .ti -8
 .B tipc link get
-.RB "{ " "priority" " | " tolerance " | " window " } " link
-.I LINK
+.br
+.RB "[ " "{ " "priority" " | " tolerance " | " window " } " link
+.IR LINK " ] "
+.RB "|"
+.br
+.RB "[ " { " broadcast " } " ]"
+.br
 
 .ti -8
 .B tipc link statistics
@@ -306,6 +324,31 @@ They are usually transient and occur during the cluster startup phase
 or network reconfiguration.
 Possible status are: U or D. The status U implies up and D down.
 
+.SS Broadcast properties
+.TP
+.B  BROADCAST
+.br
+Forces all multicast traffic to be transmitted via broadcast only,
+irrespective of cluster size and number of destinations.
+
+.TP
+.B REPLICAST
+.br
+Forces all multicast traffic to be transmitted via replicast only,
+irrespective of cluster size and number of destinations.
+
+.TP
+.B AUTOSELECT
+.br
+Auto switching to broadcast or replicast depending on cluster size and
+destination node number.
+
+.TP
+.B ratio SIZE
+.br
+Set the AUTOSELECT criteria, percentage of destination nodes vs cluster
+size.
+
 .SH EXAMPLES
 .PP
 tipc link monitor list
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [iproute2-next v2 1/3] tipc: add link broadcast set method and ratio
  2019-03-22  8:47 [iproute2-next v2 1/3] tipc: add link broadcast set method and ratio Hoang Le
  2019-03-22  8:47 ` [iproute2-next v2 2/3] tipc: add link broadcast get Hoang Le
  2019-03-22  8:47 ` [iproute2-next v2 3/3] tipc: add link broadcast man page Hoang Le
@ 2019-03-26 23:14 ` David Ahern
  2 siblings, 0 replies; 4+ messages in thread
From: David Ahern @ 2019-03-26 23:14 UTC (permalink / raw)
  To: Hoang Le, jon.maloy, maloy, ying.xue, netdev, tipc-discussion

On 3/22/19 2:47 AM, Hoang Le wrote:
> The command added here makes it possible to forcibly configure the
> broadcast link to use either broadcast or replicast, in addition to
> the already existing auto selection algorithm.
> 
> A sample usage is shown below:
> $tipc link set broadcast BROADCAST
> $tipc link set broadcast AUTOSELECT ratio 25
> 
> $tipc link set broadcast -h
> Usage: tipc link set broadcast PROPERTY
> 
> PROPERTIES
>  BROADCAST         - Forces all multicast traffic to be
>                      transmitted via broadcast only,
>                      irrespective of cluster size and number
>                      of destinations
> 
>  REPLICAST         - Forces all multicast traffic to be
>                      transmitted via replicast only,
>                      irrespective of cluster size and number
>                      of destinations
> 
>  AUTOSELECT        - Auto switching to broadcast or replicast
>                      depending on cluster size and destination
>                      node number
> 
>  ratio SIZE        - Set the AUTOSELECT criteria, percentage of
>                      destination nodes vs cluster size
> 
> Acked-by: Jon Maloy <jon.maloy@ericsson.com>
> Signed-off-by: Hoang Le <hoang.h.le@dektech.com.au>
> ---
>  include/uapi/linux/tipc_netlink.h |  2 +
>  tipc/link.c                       | 96 ++++++++++++++++++++++++++++++-
>  2 files changed, 97 insertions(+), 1 deletion(-)
> 

applied all 3 to iproute2-next. Thanks



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-03-26 23:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-22  8:47 [iproute2-next v2 1/3] tipc: add link broadcast set method and ratio Hoang Le
2019-03-22  8:47 ` [iproute2-next v2 2/3] tipc: add link broadcast get Hoang Le
2019-03-22  8:47 ` [iproute2-next v2 3/3] tipc: add link broadcast man page Hoang Le
2019-03-26 23:14 ` [iproute2-next v2 1/3] tipc: add link broadcast set method and ratio David Ahern

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.