1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3 * Copyright (c) 2013 Cong Wang <[email protected]>
4 */
5
6 #include "nl-default.h"
7
8 #include <netlink/cli/utils.h>
9 #include <netlink/cli/tc.h>
10 #include <netlink/route/qdisc/fq_codel.h>
11
print_usage(void)12 static void print_usage(void)
13 {
14 printf(
15 "Usage: nl-qdisc-add [...] fq_codel [OPTIONS]...\n"
16 "\n"
17 "OPTIONS\n"
18 " --help Show this help text.\n"
19 " --limit=LIMIT Maximum queue length in number of bytes.\n"
20 " --quantum=SIZE Amount of bytes to serve at once.\n"
21 " --flows=N Number of flows.\n"
22 " --interval=N The interval in usec.\n"
23 " --target=N The minimum delay in usec.\n"
24 "\n"
25 "EXAMPLE"
26 " # Attach fq_codel with a 4096 packets limit to eth1\n"
27 " nl-qdisc-add --dev=eth1 --parent=root fq_codel --limit=4096\n");
28 }
29
fq_codel_parse_argv(struct rtnl_tc * tc,int argc,char ** argv)30 static void fq_codel_parse_argv(struct rtnl_tc *tc, int argc, char **argv)
31 {
32 struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) tc;
33 int limit, flows;
34 uint32_t quantum, target, interval;
35
36 for (;;) {
37 int c, optidx = 0;
38 enum {
39 ARG_LIMIT = 257,
40 ARG_QUANTUM = 258,
41 ARG_FLOWS,
42 ARG_INTERVAL,
43 ARG_TARGET,
44 };
45 static struct option long_opts[] = {
46 { "help", 0, 0, 'h' },
47 { "limit", 1, 0, ARG_LIMIT },
48 { "quantum", 1, 0, ARG_QUANTUM },
49 { "flows", 1, 0, ARG_FLOWS},
50 { "interval", 1, 0, ARG_INTERVAL},
51 { "target", 1, 0, ARG_TARGET},
52 { 0, 0, 0, 0 }
53 };
54
55 c = getopt_long(argc, argv, "h", long_opts, &optidx);
56 if (c == -1)
57 break;
58
59 switch (c) {
60 case 'h':
61 print_usage();
62 return;
63
64 case ARG_LIMIT:
65 limit = nl_cli_parse_u32(optarg);
66 rtnl_qdisc_fq_codel_set_limit(qdisc, limit);
67 break;
68
69 case ARG_QUANTUM:
70 quantum = nl_cli_parse_u32(optarg);
71 rtnl_qdisc_fq_codel_set_quantum(qdisc, quantum);
72 break;
73
74 case ARG_FLOWS:
75 flows = nl_cli_parse_u32(optarg);
76 rtnl_qdisc_fq_codel_set_flows(qdisc, flows);
77 break;
78
79 case ARG_INTERVAL:
80 interval = nl_cli_parse_u32(optarg);
81 rtnl_qdisc_fq_codel_set_interval(qdisc, interval);
82 break;
83
84 case ARG_TARGET:
85 target = nl_cli_parse_u32(optarg);
86 rtnl_qdisc_fq_codel_set_target(qdisc, target);
87 break;
88
89 }
90 }
91 }
92
93 static struct nl_cli_tc_module fq_codel_module =
94 {
95 .tm_name = "fq_codel",
96 .tm_type = RTNL_TC_TYPE_QDISC,
97 .tm_parse_argv = fq_codel_parse_argv,
98 };
99
fq_codel_init(void)100 static void _nl_init fq_codel_init(void)
101 {
102 nl_cli_tc_register(&fq_codel_module);
103 }
104
fq_codel_exit(void)105 static void _nl_exit fq_codel_exit(void)
106 {
107 nl_cli_tc_unregister(&fq_codel_module);
108 }
109