summaryrefslogtreecommitdiffstats
path: root/lib/cli/qdisc
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2010-10-20 12:57:39 (GMT)
committerThomas Graf <tgraf@suug.ch>2010-10-20 12:57:39 (GMT)
commit27883b0f9b0da6bb33ccc185107a2870df25d030 (patch)
treefbda57a6026fbc6653648ecb9d588d2d9e938b5e /lib/cli/qdisc
parent18848090f99cae37ac1a3052369ab4d26ed9ada0 (diff)
downloadlibnl-27883b0f9b0da6bb33ccc185107a2870df25d030.zip
libnl-27883b0f9b0da6bb33ccc185107a2870df25d030.tar.gz
libnl-27883b0f9b0da6bb33ccc185107a2870df25d030.tar.bz2
nl-class-add tool
Adds a cli based tool to add/update traffic classes. This tool requires each class to be supported via the respetive qdisc module in pkglibdir/cli/qdisc/$name.so. Syntax: nl-class-add --dev eth2 --parent 1: --id 1:1 htb --rate 100mbit nl-class-add --update --dev eth2 --id 1:1 htb --rate 200mbit
Diffstat (limited to 'lib/cli/qdisc')
-rw-r--r--lib/cli/qdisc/bfifo.c4
-rw-r--r--lib/cli/qdisc/blackhole.c4
-rw-r--r--lib/cli/qdisc/htb.c143
-rw-r--r--lib/cli/qdisc/pfifo.c4
4 files changed, 144 insertions, 11 deletions
diff --git a/lib/cli/qdisc/bfifo.c b/lib/cli/qdisc/bfifo.c
index 7354728..2f74659 100644
--- a/lib/cli/qdisc/bfifo.c
+++ b/lib/cli/qdisc/bfifo.c
@@ -66,8 +66,8 @@ static void bfifo_parse_argv(struct rtnl_qdisc *qdisc, int argc, char **argv)
static struct nl_cli_qdisc_module bfifo_module =
{
- .qm_name = "bfifo",
- .qm_parse_argv = bfifo_parse_argv,
+ .qm_name = "bfifo",
+ .qm_parse_qdisc_argv = bfifo_parse_argv,
};
static void __init bfifo_init(void)
diff --git a/lib/cli/qdisc/blackhole.c b/lib/cli/qdisc/blackhole.c
index 176f463..1eebb32 100644
--- a/lib/cli/qdisc/blackhole.c
+++ b/lib/cli/qdisc/blackhole.c
@@ -48,8 +48,8 @@ static void blackhole_parse_argv(struct rtnl_qdisc *qdisc, int argc, char **argv
static struct nl_cli_qdisc_module blackhole_module =
{
- .qm_name = "blackhole",
- .qm_parse_argv = blackhole_parse_argv,
+ .qm_name = "blackhole",
+ .qm_parse_qdisc_argv = blackhole_parse_argv,
};
static void __init blackhole_init(void)
diff --git a/lib/cli/qdisc/htb.c b/lib/cli/qdisc/htb.c
index 9ce8e25..6b913a8 100644
--- a/lib/cli/qdisc/htb.c
+++ b/lib/cli/qdisc/htb.c
@@ -11,8 +11,9 @@
#include <netlink/cli/utils.h>
#include <netlink/cli/qdisc.h>
+#include <netlink/route/sch/htb.h>
-static void print_usage(void)
+static void print_qdisc_usage(void)
{
printf(
"Usage: nl-qdisc-add [...] htb [OPTIONS]...\n"
@@ -27,7 +28,7 @@ static void print_usage(void)
" nl-qdisc-add --dev=eth1 --parent=root --handle=1: htb --default=10\n");
}
-static void htb_parse_argv(struct rtnl_qdisc *qdisc, int argc, char **argv)
+static void htb_parse_qdisc_argv(struct rtnl_qdisc *qdisc, int argc, char **argv)
{
for (;;) {
int c, optidx = 0;
@@ -48,7 +49,7 @@ static void htb_parse_argv(struct rtnl_qdisc *qdisc, int argc, char **argv)
switch (c) {
case 'h':
- print_usage();
+ print_qdisc_usage();
return;
case ARG_R2Q:
@@ -62,10 +63,142 @@ static void htb_parse_argv(struct rtnl_qdisc *qdisc, int argc, char **argv)
}
}
+static void print_class_usage(void)
+{
+ printf(
+"Usage: nl-class-add [...] htb [OPTIONS]...\n"
+"\n"
+"OPTIONS\n"
+" --help Show this help text.\n"
+" --rate=RATE Rate limit.\n"
+" --ceil=RATE Rate limit while borrowing (default: equal to --rate).\n"
+" --prio=PRIO Priority, lower is served first (default: 0).\n"
+" --mtu=MTU Maximum packet size on the link (default: 1600).\n"
+" --mpu=MPU Minimum packet size on the link (default: 0).\n"
+" --overhead=OVERHEAD Overhead in bytes per packet (default: 0).\n"
+" --quantum=SIZE Amount of bytes to serve at once (default: rate/r2q).\n"
+" --burst=SIZE Max charge size of rate burst buffer (default: auto).\n"
+" --cburst=SIZE Max charge size of ceil rate burst buffer (default: auto)\n"
+"\n"
+"EXAMPLE"
+" # Attach class 1:1 to htb qdisc 1: and rate limit it to 20mbit\n"
+" nl-class-add --dev=eth1 --parent=1: --classid=1:1 htb --rate=20mbit\n");
+}
+
+static void htb_parse_class_argv(struct rtnl_class *class, int argc, char **argv)
+{
+ long rate;
+
+ for (;;) {
+ int c, optidx = 0;
+ enum {
+ ARG_RATE = 257,
+ ARG_QUANTUM = 258,
+ ARG_CEIL,
+ ARG_PRIO,
+ ARG_MTU,
+ ARG_MPU,
+ ARG_OVERHEAD,
+ ARG_BURST,
+ ARG_CBURST,
+ };
+ static struct option long_opts[] = {
+ { "help", 0, 0, 'h' },
+ { "rate", 1, 0, ARG_RATE },
+ { "quantum", 1, 0, ARG_QUANTUM },
+ { "ceil", 1, 0, ARG_CEIL },
+ { "prio", 1, 0, ARG_PRIO },
+ { "mtu", 1, 0, ARG_MTU },
+ { "mpu", 1, 0, ARG_MPU },
+ { "overhead", 1, 0, ARG_OVERHEAD },
+ { "burst", 1, 0, ARG_BURST },
+ { "cburst", 1, 0, ARG_CBURST },
+ { 0, 0, 0, 0 }
+ };
+
+ c = getopt_long(argc, argv, "h", long_opts, &optidx);
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'h':
+ print_class_usage();
+ return;
+
+ case ARG_RATE:
+ rate = nl_size2int(optarg);
+ if (rate < 0) {
+ nl_cli_fatal(rate, "Unable to parse htb rate "
+ "\"%s\": Invalid format.", optarg);
+ }
+
+ rtnl_htb_set_rate(class, rate);
+ break;
+
+ case ARG_CEIL:
+ rate = nl_size2int(optarg);
+ if (rate < 0) {
+ nl_cli_fatal(rate, "Unable to parse htb ceil rate "
+ "\"%s\": Invalid format.", optarg);
+ }
+
+ rtnl_htb_set_ceil(class, rate);
+ break;
+
+ case ARG_MTU:
+ rtnl_htb_set_mtu(class, nl_cli_parse_u32(optarg));
+ break;
+
+ case ARG_MPU:
+ rtnl_htb_set_mpu(class, nl_cli_parse_u32(optarg));
+ break;
+
+ case ARG_OVERHEAD:
+ rtnl_htb_set_overhead(class, nl_cli_parse_u32(optarg));
+ break;
+
+ case ARG_PRIO:
+ rtnl_htb_set_prio(class, nl_cli_parse_u32(optarg));
+ break;
+
+ case ARG_QUANTUM:
+ rate = nl_size2int(optarg);
+ if (rate < 0) {
+ nl_cli_fatal(rate, "Unable to parse quantum "
+ "\"%s\": Invalid format.", optarg);
+ }
+
+ rtnl_htb_set_quantum(class, rate);
+ break;
+
+ case ARG_BURST:
+ rate = nl_size2int(optarg);
+ if (rate < 0) {
+ nl_cli_fatal(rate, "Unable to parse burst "
+ "\"%s\": Invalid format.", optarg);
+ }
+
+ rtnl_htb_set_rbuffer(class, rate);
+ break;
+
+ case ARG_CBURST:
+ rate = nl_size2int(optarg);
+ if (rate < 0) {
+ nl_cli_fatal(rate, "Unable to parse cburst "
+ "\"%s\": Invalid format.", optarg);
+ }
+
+ rtnl_htb_set_cbuffer(class, rate);
+ break;
+ }
+ }
+}
+
static struct nl_cli_qdisc_module htb_module =
{
- .qm_name = "htb",
- .qm_parse_argv = htb_parse_argv,
+ .qm_name = "htb",
+ .qm_parse_qdisc_argv = htb_parse_qdisc_argv,
+ .qm_parse_class_argv = htb_parse_class_argv,
};
static void __init htb_init(void)
diff --git a/lib/cli/qdisc/pfifo.c b/lib/cli/qdisc/pfifo.c
index 4d900d8..38cc97a 100644
--- a/lib/cli/qdisc/pfifo.c
+++ b/lib/cli/qdisc/pfifo.c
@@ -59,8 +59,8 @@ static void pfifo_parse_argv(struct rtnl_qdisc *qdisc, int argc, char **argv)
static struct nl_cli_qdisc_module pfifo_module =
{
- .qm_name = "pfifo",
- .qm_parse_argv = pfifo_parse_argv,
+ .qm_name = "pfifo",
+ .qm_parse_qdisc_argv = pfifo_parse_argv,
};
static void __init pfifo_init(void)