libnl 3.9.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 "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
12static 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
30static 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);
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);
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
93static 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
100static void _nl_init fq_codel_init(void)
101{
102 nl_cli_tc_register(&fq_codel_module);
103}
104
105static void _nl_exit fq_codel_exit(void)
106{
107 nl_cli_tc_unregister(&fq_codel_module);
108}
uint32_t nl_cli_parse_u32(const char *arg)
Parse a text based 32 bit unsigned integer argument.
Definition utils.c:36
int rtnl_qdisc_fq_codel_set_target(struct rtnl_qdisc *qdisc, uint32_t target)
Set target of fq_codel qdisc.
Definition fq_codel.c:190
int rtnl_qdisc_fq_codel_set_interval(struct rtnl_qdisc *qdisc, uint32_t interval)
Set interval of fq_codel qdisc.
Definition fq_codel.c:225
int rtnl_qdisc_fq_codel_set_flows(struct rtnl_qdisc *qdisc, int flows)
Set flows of fq_codel qdisc.
Definition fq_codel.c:295
int rtnl_qdisc_fq_codel_set_quantum(struct rtnl_qdisc *qdisc, uint32_t quantum)
Set quantum of fq_codel qdisc.
Definition fq_codel.c:260
int rtnl_qdisc_fq_codel_set_limit(struct rtnl_qdisc *qdisc, int limit)
Set limit of fq_codel qdisc.
Definition fq_codel.c:153