summaryrefslogtreecommitdiff
path: root/lib/cli/qdisc/fq_codel.c
blob: 83e409a45ce3847d74c27075bd2e1293b4e0cc42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* SPDX-License-Identifier: LGPL-2.1-only */
/*
 * Copyright (c) 2013 Cong Wang <xiyou.wangcong@gmail.com>
 */

#include "nl-default.h"

#include <netlink/cli/utils.h>
#include <netlink/cli/tc.h>
#include <netlink/route/qdisc/fq_codel.h>

static void print_usage(void)
{
	printf(
"Usage: nl-qdisc-add [...] fq_codel [OPTIONS]...\n"
"\n"
"OPTIONS\n"
"     --help                Show this help text.\n"
"     --limit=LIMIT         Maximum queue length in number of bytes.\n"
"     --quantum=SIZE        Amount of bytes to serve at once.\n"
"     --flows=N             Number of flows.\n"
"     --interval=N          The interval in usec.\n"
"     --target=N            The minimum delay in usec.\n"
"\n"
"EXAMPLE"
"    # Attach fq_codel with a 4096 packets limit to eth1\n"
"    nl-qdisc-add --dev=eth1 --parent=root fq_codel --limit=4096\n");
}

static void fq_codel_parse_argv(struct rtnl_tc *tc, int argc, char **argv)
{
	struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) tc;
	int limit, flows;
	uint32_t quantum, target, interval;

	for (;;) {
		int c, optidx = 0;
		enum {
			ARG_LIMIT = 257,
			ARG_QUANTUM = 258,
			ARG_FLOWS,
			ARG_INTERVAL,
			ARG_TARGET,
		};
		static struct option long_opts[] = {
			{ "help", 0, 0, 'h' },
			{ "limit", 1, 0, ARG_LIMIT },
			{ "quantum", 1, 0, ARG_QUANTUM },
			{ "flows", 1, 0, ARG_FLOWS},
			{ "interval", 1, 0, ARG_INTERVAL},
			{ "target", 1, 0, ARG_TARGET},
			{ 0, 0, 0, 0 }
		};

		c = getopt_long(argc, argv, "h", long_opts, &optidx);
		if (c == -1)
			break;

		switch (c) {
		case 'h':
			print_usage();
			return;

		case ARG_LIMIT:
			limit = nl_cli_parse_u32(optarg);
			rtnl_qdisc_fq_codel_set_limit(qdisc, limit);
			break;

		case ARG_QUANTUM:
			quantum = nl_cli_parse_u32(optarg);
			rtnl_qdisc_fq_codel_set_quantum(qdisc, quantum);
			break;

		case ARG_FLOWS:
			flows = nl_cli_parse_u32(optarg);
			rtnl_qdisc_fq_codel_set_flows(qdisc, flows);
			break;

		case ARG_INTERVAL:
			interval = nl_cli_parse_u32(optarg);
			rtnl_qdisc_fq_codel_set_interval(qdisc, interval);
			break;

		case ARG_TARGET:
			target = nl_cli_parse_u32(optarg);
			rtnl_qdisc_fq_codel_set_target(qdisc, target);
			break;

		}
	}
}

static struct nl_cli_tc_module fq_codel_module =
{
	.tm_name		= "fq_codel",
	.tm_type		= RTNL_TC_TYPE_QDISC,
	.tm_parse_argv		= fq_codel_parse_argv,
};

static void _nl_init fq_codel_init(void)
{
	nl_cli_tc_register(&fq_codel_module);
}

static void _nl_exit fq_codel_exit(void)
{
	nl_cli_tc_unregister(&fq_codel_module);
}