libnl: /data/src/libnl3/lib/cli/qdisc/fq_codel.c Source File

libnl 3.7.0

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