12 #include <netlink/cli/utils.h> 13 #include <netlink/cli/tc.h> 14 #include <netlink/route/qdisc/hfsc.h> 15 #include <linux/pkt_sched.h> 17 static void print_qdisc_usage(
void)
20 "Usage: nl-qdisc-add [...] hfsc [OPTIONS]...\n" 23 " --help Show this help text.\n" 24 " --default=ID Default class for unclassified traffic.\n" 27 " # Create hfsc root qdisc 1: and direct unclassified traffic to class 1:10\n" 28 " nl-qdisc-add --dev=eth1 --parent=root --handle=1: hfsc --default=10\n");
31 static void hfsc_parse_qdisc_argv(
struct rtnl_tc *tc,
int argc,
char **argv)
33 struct rtnl_qdisc *qdisc = (
struct rtnl_qdisc *) tc;
40 static struct option long_opts[] = {
41 {
"help", 0, 0,
'h' },
42 {
"default", 1, 0, ARG_DEFAULT },
46 c = getopt_long(argc, argv,
"hv", long_opts, &optidx);
62 static void print_class_usage(
void)
65 "Usage: nl-class-add [...] hfsc [OPTIONS]...\n" 68 " --help Show this help text.\n" 69 " --ls=SC Link-sharing service curve\n" 70 " --rt=SC Real-time service curve\n" 71 " --sc=SC Specifiy both of the above\n" 72 " --ul=SC Upper limit\n" 73 " where SC := [ [ m1 bits ] d usec ] m2 bits\n" 76 " # Attach class 1:1 to hfsc qdisc 1: and use rt and ls curve\n" 77 " nl-class-add --dev=eth1 --parent=1: --classid=1:1 hfsc --sc=m1:250,d:8,m2:100\n");
81 hfsc_get_sc(
char *optarg,
struct tc_service_curve *sc)
83 unsigned int m1 = 0, d = 0, m2 = 0;
84 char *tmp = strdup(optarg);
91 p = strstr(pp,
"m1:");
101 m1 = strtoul(p, &endptr, 10);
107 p = strstr(pp,
"d:");
117 d = strtoul(p, &endptr, 10);
123 p = strstr(pp,
"m2:");
128 m2 = strtoul(p, &endptr, 10);
145 static void hfsc_parse_class_argv(
struct rtnl_tc *tc,
int argc,
char **argv)
147 struct rtnl_class *
class = (struct rtnl_class *) tc;
148 int arg_ok = 0, ret = -EINVAL;
158 static struct option long_opts[] = {
159 {
"help", 0, 0,
'h' },
160 {
"rt", 1, 0, ARG_RT },
161 {
"ls", 1, 0, ARG_LS },
162 {
"sc", 1, 0, ARG_SC },
163 {
"ul", 1, 0, ARG_UL },
166 struct tc_service_curve tsc;
168 c = getopt_long(argc, argv,
"h", long_opts, &optidx);
178 ret = hfsc_get_sc(optarg, &tsc);
181 "\"%s\": Invalid format.", optarg);
184 rtnl_class_hfsc_set_rsc(
class, &tsc);
189 ret = hfsc_get_sc(optarg, &tsc);
192 "\"%s\": Invalid format.", optarg);
195 rtnl_class_hfsc_set_fsc(
class, &tsc);
200 ret = hfsc_get_sc(optarg, &tsc);
203 "\"%s\": Invalid format.", optarg);
206 rtnl_class_hfsc_set_rsc(
class, &tsc);
207 rtnl_class_hfsc_set_fsc(
class, &tsc);
212 ret = hfsc_get_sc(optarg, &tsc);
215 "\"%s\": Invalid format.", optarg);
218 rtnl_class_hfsc_set_usc(
class, &tsc);
231 .tm_type = RTNL_TC_TYPE_QDISC,
232 .tm_parse_argv = hfsc_parse_qdisc_argv,
238 .tm_type = RTNL_TC_TYPE_CLASS,
239 .tm_parse_argv = hfsc_parse_class_argv,
242 static void __init hfsc_init(
void)
244 nl_cli_tc_register(&hfsc_qdisc_module);
245 nl_cli_tc_register(&hfsc_class_module);
248 static void __exit hfsc_exit(
void)
250 nl_cli_tc_unregister(&hfsc_class_module);
251 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.