12 #include <netlink/cli/utils.h> 13 #include <netlink/cli/tc.h> 14 #include <netlink/route/qdisc/hfsc.h> 16 static void print_qdisc_usage(
void)
19 "Usage: nl-qdisc-add [...] hfsc [OPTIONS]...\n" 22 " --help Show this help text.\n" 23 " --default=ID Default class for unclassified traffic.\n" 26 " # Create hfsc root qdisc 1: and direct unclassified traffic to class 1:10\n" 27 " nl-qdisc-add --dev=eth1 --parent=root --handle=1: hfsc --default=10\n");
30 static void hfsc_parse_qdisc_argv(
struct rtnl_tc *tc,
int argc,
char **argv)
32 struct rtnl_qdisc *qdisc = (
struct rtnl_qdisc *) tc;
39 static struct option long_opts[] = {
40 {
"help", 0, 0,
'h' },
41 {
"default", 1, 0, ARG_DEFAULT },
45 c = getopt_long(argc, argv,
"hv", long_opts, &optidx);
61 static void print_class_usage(
void)
64 "Usage: nl-class-add [...] hfsc [OPTIONS]...\n" 67 " --help Show this help text.\n" 68 " --ls=SC Link-sharing service curve\n" 69 " --rt=SC Real-time service curve\n" 70 " --sc=SC Specifiy both of the above\n" 71 " --ul=SC Upper limit\n" 72 " where SC := [ [ m1 bits ] d usec ] m2 bits\n" 75 " # Attach class 1:1 to hfsc qdisc 1: and use rt and ls curve\n" 76 " nl-class-add --dev=eth1 --parent=1: --classid=1:1 hfsc --sc=m1:250,d:8,m2:100\n");
80 hfsc_get_sc(
char *optarg,
struct tc_service_curve *sc)
82 unsigned int m1 = 0, d = 0, m2 = 0;
83 char *tmp = strdup(optarg);
90 p = strstr(pp,
"m1:");
100 m1 = strtoul(p, &endptr, 10);
106 p = strstr(pp,
"d:");
116 d = strtoul(p, &endptr, 10);
122 p = strstr(pp,
"m2:");
127 m2 = strtoul(p, &endptr, 10);
144 static void hfsc_parse_class_argv(
struct rtnl_tc *tc,
int argc,
char **argv)
146 struct rtnl_class *
class = (struct rtnl_class *) tc;
147 int arg_ok = 0, ret = -EINVAL;
157 static struct option long_opts[] = {
158 {
"help", 0, 0,
'h' },
159 {
"rt", 1, 0, ARG_RT },
160 {
"ls", 1, 0, ARG_LS },
161 {
"sc", 1, 0, ARG_SC },
162 {
"ul", 1, 0, ARG_UL },
165 struct tc_service_curve tsc;
167 c = getopt_long(argc, argv,
"h", long_opts, &optidx);
177 ret = hfsc_get_sc(optarg, &tsc);
180 "\"%s\": Invalid format.", optarg);
183 rtnl_class_hfsc_set_rsc(
class, &tsc);
188 ret = hfsc_get_sc(optarg, &tsc);
191 "\"%s\": Invalid format.", optarg);
194 rtnl_class_hfsc_set_fsc(
class, &tsc);
199 ret = hfsc_get_sc(optarg, &tsc);
202 "\"%s\": Invalid format.", optarg);
205 rtnl_class_hfsc_set_rsc(
class, &tsc);
206 rtnl_class_hfsc_set_fsc(
class, &tsc);
211 ret = hfsc_get_sc(optarg, &tsc);
214 "\"%s\": Invalid format.", optarg);
217 rtnl_class_hfsc_set_usc(
class, &tsc);
230 .tm_type = RTNL_TC_TYPE_QDISC,
231 .tm_parse_argv = hfsc_parse_qdisc_argv,
237 .tm_type = RTNL_TC_TYPE_CLASS,
238 .tm_parse_argv = hfsc_parse_class_argv,
241 static void __init hfsc_init(
void)
243 nl_cli_tc_register(&hfsc_qdisc_module);
244 nl_cli_tc_register(&hfsc_class_module);
247 static void __exit hfsc_exit(
void)
249 nl_cli_tc_unregister(&hfsc_class_module);
250 nl_cli_tc_unregister(&hfsc_qdisc_module);
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.
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.