6 #include <netlink/cli/utils.h>
7 #include <netlink/cli/tc.h>
8 #include <netlink/route/qdisc/hfsc.h>
9 #include <linux/pkt_sched.h>
11 static void print_qdisc_usage(
void)
14 "Usage: nl-qdisc-add [...] hfsc [OPTIONS]...\n"
17 " --help Show this help text.\n"
18 " --default=ID Default class for unclassified traffic.\n"
21 " # Create hfsc root qdisc 1: and direct unclassified traffic to class 1:10\n"
22 " nl-qdisc-add --dev=eth1 --parent=root --handle=1: hfsc --default=10\n");
25 static void hfsc_parse_qdisc_argv(
struct rtnl_tc *tc,
int argc,
char **argv)
27 struct rtnl_qdisc *qdisc = (
struct rtnl_qdisc *) tc;
34 static struct option long_opts[] = {
35 {
"help", 0, 0,
'h' },
36 {
"default", 1, 0, ARG_DEFAULT },
40 c = getopt_long(argc, argv,
"hv", long_opts, &optidx);
56 static void print_class_usage(
void)
59 "Usage: nl-class-add [...] hfsc [OPTIONS]...\n"
62 " --help Show this help text.\n"
63 " --ls=SC Link-sharing service curve\n"
64 " --rt=SC Real-time service curve\n"
65 " --sc=SC Specifiy both of the above\n"
66 " --ul=SC Upper limit\n"
67 " where SC := [ [ m1 bits ] d usec ] m2 bits\n"
70 " # Attach class 1:1 to hfsc qdisc 1: and use rt and ls curve\n"
71 " nl-class-add --dev=eth1 --parent=1: --classid=1:1 hfsc --sc=m1:250,d:8,m2:100\n");
75 hfsc_get_sc(
char *optarg,
struct tc_service_curve *sc)
77 unsigned int m1 = 0, d = 0, m2 = 0;
78 char *tmp = strdup(optarg);
85 p = strstr(pp,
"m1:");
95 m1 = strtoul(p, &endptr, 10);
101 p = strstr(pp,
"d:");
111 d = strtoul(p, &endptr, 10);
117 p = strstr(pp,
"m2:");
122 m2 = strtoul(p, &endptr, 10);
139 static void hfsc_parse_class_argv(
struct rtnl_tc *tc,
int argc,
char **argv)
141 struct rtnl_class *
class = (struct rtnl_class *) tc;
142 int arg_ok = 0, ret = -EINVAL;
152 static struct option long_opts[] = {
153 {
"help", 0, 0,
'h' },
154 {
"rt", 1, 0, ARG_RT },
155 {
"ls", 1, 0, ARG_LS },
156 {
"sc", 1, 0, ARG_SC },
157 {
"ul", 1, 0, ARG_UL },
160 struct tc_service_curve tsc;
162 c = getopt_long(argc, argv,
"h", long_opts, &optidx);
172 ret = hfsc_get_sc(optarg, &tsc);
175 "\"%s\": Invalid format.", optarg);
178 rtnl_class_hfsc_set_rsc(
class, &tsc);
183 ret = hfsc_get_sc(optarg, &tsc);
186 "\"%s\": Invalid format.", optarg);
189 rtnl_class_hfsc_set_fsc(
class, &tsc);
194 ret = hfsc_get_sc(optarg, &tsc);
197 "\"%s\": Invalid format.", optarg);
200 rtnl_class_hfsc_set_rsc(
class, &tsc);
201 rtnl_class_hfsc_set_fsc(
class, &tsc);
206 ret = hfsc_get_sc(optarg, &tsc);
209 "\"%s\": Invalid format.", optarg);
212 rtnl_class_hfsc_set_usc(
class, &tsc);
225 .tm_type = RTNL_TC_TYPE_QDISC,
226 .tm_parse_argv = hfsc_parse_qdisc_argv,
232 .tm_type = RTNL_TC_TYPE_CLASS,
233 .tm_parse_argv = hfsc_parse_class_argv,
236 static void __init hfsc_init(
void)
238 nl_cli_tc_register(&hfsc_qdisc_module);
239 nl_cli_tc_register(&hfsc_class_module);
242 static void __exit hfsc_exit(
void)
244 nl_cli_tc_unregister(&hfsc_class_module);
245 nl_cli_tc_unregister(&hfsc_qdisc_module);
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
uint32_t nl_cli_parse_u32(const char *arg)
Parse a text based 32 bit unsigned integer argument.
int rtnl_qdisc_hfsc_set_defcls(struct rtnl_qdisc *qdisc, uint32_t defcls)
Set default class of the hfsc qdisc to the specified value.