8#include <linux/pkt_sched.h>
10#include <netlink/cli/utils.h>
11#include <netlink/cli/tc.h>
12#include <netlink/route/qdisc/hfsc.h>
14static void print_qdisc_usage(
void)
17"Usage: nl-qdisc-add [...] hfsc [OPTIONS]...\n"
20" --help Show this help text.\n"
21" --default=ID Default class for unclassified traffic.\n"
24" # Create hfsc root qdisc 1: and direct unclassified traffic to class 1:10\n"
25" nl-qdisc-add --dev=eth1 --parent=root --handle=1: hfsc --default=10\n");
28static void hfsc_parse_qdisc_argv(
struct rtnl_tc *tc,
int argc,
char **argv)
37 static struct option long_opts[] = {
38 {
"help", 0, 0,
'h' },
39 {
"default", 1, 0, ARG_DEFAULT },
43 c = getopt_long(argc, argv,
"hv", long_opts, &optidx);
59static void print_class_usage(
void)
62"Usage: nl-class-add [...] hfsc [OPTIONS]...\n"
65" --help Show this help text.\n"
66" --ls=SC Link-sharing service curve\n"
67" --rt=SC Real-time service curve\n"
68" --sc=SC Specifiy both of the above\n"
69" --ul=SC Upper limit\n"
70" where SC := [ [ m1 bits ] d usec ] m2 bits\n"
73" # Attach class 1:1 to hfsc qdisc 1: and use rt and ls curve\n"
74" nl-class-add --dev=eth1 --parent=1: --classid=1:1 hfsc --sc=m1:250,d:8,m2:100\n");
78hfsc_get_sc(
char *optarg,
struct tc_service_curve *sc)
80 unsigned int m1 = 0, d = 0, m2 = 0;
81 char *tmp = strdup(optarg);
88 p = strstr(pp,
"m1:");
98 m1 = strtoul(p, &endptr, 10);
104 p = strstr(pp,
"d:");
114 d = strtoul(p, &endptr, 10);
120 p = strstr(pp,
"m2:");
125 m2 = strtoul(p, &endptr, 10);
142static void hfsc_parse_class_argv(
struct rtnl_tc *tc,
int argc,
char **argv)
145 int arg_ok = 0, ret = -EINVAL;
155 static struct option long_opts[] = {
156 {
"help", 0, 0,
'h' },
157 {
"rt", 1, 0, ARG_RT },
158 {
"ls", 1, 0, ARG_LS },
159 {
"sc", 1, 0, ARG_SC },
160 {
"ul", 1, 0, ARG_UL },
163 struct tc_service_curve tsc;
165 c = getopt_long(argc, argv,
"h", long_opts, &optidx);
175 ret = hfsc_get_sc(optarg, &tsc);
178 "\"%s\": Invalid format.", optarg);
181 rtnl_class_hfsc_set_rsc(
class, &tsc);
186 ret = hfsc_get_sc(optarg, &tsc);
189 "\"%s\": Invalid format.", optarg);
192 rtnl_class_hfsc_set_fsc(
class, &tsc);
197 ret = hfsc_get_sc(optarg, &tsc);
200 "\"%s\": Invalid format.", optarg);
203 rtnl_class_hfsc_set_rsc(
class, &tsc);
204 rtnl_class_hfsc_set_fsc(
class, &tsc);
209 ret = hfsc_get_sc(optarg, &tsc);
212 "\"%s\": Invalid format.", optarg);
215 rtnl_class_hfsc_set_usc(
class, &tsc);
228 .tm_type = RTNL_TC_TYPE_QDISC,
229 .tm_parse_argv = hfsc_parse_qdisc_argv,
235 .tm_type = RTNL_TC_TYPE_CLASS,
236 .tm_parse_argv = hfsc_parse_class_argv,
239static void _nl_init hfsc_init(
void)
241 nl_cli_tc_register(&hfsc_qdisc_module);
242 nl_cli_tc_register(&hfsc_class_module);
245static void _nl_exit hfsc_exit(
void)
247 nl_cli_tc_unregister(&hfsc_class_module);
248 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.