From ae19ac01545ee2429f2fcbb37b36f8471a5d1498 Mon Sep 17 00:00:00 2001 From: Cong Wang Date: Tue, 19 Nov 2013 21:10:05 -0800 Subject: [PATCH] add fq_codel cli module Cc: Thomas Graf Signed-off-by: Cong Wang Signed-off-by: Thomas Graf --- lib/Makefile.am | 2 + lib/cli/qdisc/fq_codel.c | 112 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 lib/cli/qdisc/fq_codel.c diff --git a/lib/Makefile.am b/lib/Makefile.am index f03ca00..f96fc27 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -116,6 +116,7 @@ nobase_pkglib_LTLIBRARIES = \ cli/qdisc/plug.la \ cli/qdisc/bfifo.la \ cli/qdisc/ingress.la \ + cli/qdisc/fq_codel.la \ cli/cls/basic.la \ cli/cls/cgroup.la @@ -125,6 +126,7 @@ cli_qdisc_pfifo_la_LDFLAGS = -module -avoid-version cli_qdisc_plug_la_LDFLAGS = -module -avoid-version cli_qdisc_bfifo_la_LDFLAGS = -module -avoid-version cli_qdisc_ingress_la_LDFLAGS = -module -avoid-version +cli_qdisc_fq_codel_la_LDFLAGS = -module -avoid-version cli_cls_basic_la_LDFLAGS = -module -avoid-version cli_cls_cgroup_la_LDFLAGS = -module -avoid-version endif diff --git a/lib/cli/qdisc/fq_codel.c b/lib/cli/qdisc/fq_codel.c new file mode 100644 index 0000000..1602bcb --- /dev/null +++ b/lib/cli/qdisc/fq_codel.c @@ -0,0 +1,112 @@ +/* + * lib/cli/qdisc/fq_codel.c fq_codel module for CLI lib + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * Copyright (c) 2013 Cong Wang + */ + +#include +#include +#include + +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 __init fq_codel_init(void) +{ + nl_cli_tc_register(&fq_codel_module); +} + +static void __exit fq_codel_exit(void) +{ + nl_cli_tc_unregister(&fq_codel_module); +}