Skip to content

Commit

Permalink
Merge branch 'hfsc-qdisc-support'
Browse files Browse the repository at this point in the history
  • Loading branch information
thom311 committed Jul 30, 2014
2 parents 000dd94 + cacc24e commit 76237f6
Show file tree
Hide file tree
Showing 9 changed files with 718 additions and 38 deletions.
1 change: 1 addition & 0 deletions include/Makefile.am
Expand Up @@ -70,6 +70,7 @@ nobase_libnlinclude_HEADERS = \
netlink/route/qdisc/tbf.h \
netlink/route/qdisc/plug.h \
netlink/route/qdisc/fq_codel.h \
netlink/route/qdisc/hfsc.h \
netlink/route/addr.h \
netlink/route/class.h \
netlink/route/classifier.h \
Expand Down
2 changes: 1 addition & 1 deletion include/netlink-private/route/tc-api.h
Expand Up @@ -116,7 +116,7 @@ extern int rtnl_tc_compare(struct nl_object *,

extern void * rtnl_tc_data(struct rtnl_tc *);
extern void * rtnl_tc_data_check(struct rtnl_tc *,
struct rtnl_tc_ops *);
struct rtnl_tc_ops *, int *);

extern struct rtnl_tc_ops * rtnl_tc_lookup_ops(enum rtnl_tc_type,
const char *);
Expand Down
14 changes: 14 additions & 0 deletions include/netlink-private/types.h
Expand Up @@ -721,6 +721,20 @@ struct rtnl_fq_codel
uint32_t fq_mask;
};

struct rtnl_hfsc_qdisc
{
uint32_t qh_defcls;
uint32_t qh_mask;
};

struct rtnl_hfsc_class
{
struct tc_service_curve ch_rsc;
struct tc_service_curve ch_fsc;
struct tc_service_curve ch_usc;
uint32_t ch_mask;
};

struct flnl_request
{
NLHDR_COMMON
Expand Down
37 changes: 37 additions & 0 deletions include/netlink/route/qdisc/hfsc.h
@@ -0,0 +1,37 @@
/*
* netlink/route/sch/hfsc.h HFSC Qdisc
*
* 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) 2014 Cong Wang <xiyou.wangcong@gmail.com>
*/

#ifndef NETLINK_HFSC_H_
#define NETLINK_HFSC_H_

#include <netlink/netlink.h>
#include <netlink/route/tc.h>
#include <netlink/route/qdisc.h>
#include <netlink/route/class.h>

#ifdef __cplusplus
extern "C" {
#endif

extern uint32_t rtnl_qdisc_hfsc_get_defcls(const struct rtnl_qdisc *);
extern int rtnl_qdisc_hfsc_set_defcls(struct rtnl_qdisc *, uint32_t);

extern int rtnl_class_hfsc_get_rsc(const struct rtnl_class *class, struct tc_service_curve *tsc);
extern int rtnl_class_hfsc_set_rsc(struct rtnl_class *class, const struct tc_service_curve *tsc);
extern int rtnl_class_hfsc_get_fsc(const struct rtnl_class *class, struct tc_service_curve *tsc);
extern int rtnl_class_hfsc_set_fsc(struct rtnl_class *class, const struct tc_service_curve *tsc);
extern int rtnl_class_hfsc_get_usc(const struct rtnl_class *class, struct tc_service_curve *tsc);
extern int rtnl_class_hfsc_set_usc(struct rtnl_class *class, const struct tc_service_curve *tsc);
#ifdef __cplusplus
}
#endif

#endif
4 changes: 3 additions & 1 deletion lib/Makefile.am
Expand Up @@ -86,7 +86,7 @@ libnl_route_3_la_SOURCES = \
route/qdisc/fifo.c route/qdisc/htb.c route/qdisc/netem.c \
route/qdisc/prio.c route/qdisc/red.c route/qdisc/sfq.c \
route/qdisc/tbf.c route/qdisc/plug.c route/qdisc/ingress.c \
route/qdisc/fq_codel.c \
route/qdisc/fq_codel.c route/qdisc/hfsc.c \
\
fib_lookup/lookup.c fib_lookup/request.c \
\
Expand Down Expand Up @@ -128,6 +128,7 @@ nobase_pkglib_LTLIBRARIES = \
cli/qdisc/bfifo.la \
cli/qdisc/ingress.la \
cli/qdisc/fq_codel.la \
cli/qdisc/hfsc.la \
cli/cls/basic.la \
cli/cls/cgroup.la

Expand All @@ -138,6 +139,7 @@ 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_qdisc_hfsc_la_LDFLAGS = -module -avoid-version
cli_cls_basic_la_LDFLAGS = -module -avoid-version
cli_cls_cgroup_la_LDFLAGS = -module -avoid-version
endif
250 changes: 250 additions & 0 deletions lib/cli/qdisc/hfsc.c
@@ -0,0 +1,250 @@
/*
* lib/cli/qdisc/hfsc.c HFSC 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) 2014 Cong Wang <xiyou.wangcong@gmail.com>
*/

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

static void print_qdisc_usage(void)
{
printf(
"Usage: nl-qdisc-add [...] hfsc [OPTIONS]...\n"
"\n"
"OPTIONS\n"
" --help Show this help text.\n"
" --default=ID Default class for unclassified traffic.\n"
"\n"
"EXAMPLE"
" # Create hfsc root qdisc 1: and direct unclassified traffic to class 1:10\n"
" nl-qdisc-add --dev=eth1 --parent=root --handle=1: hfsc --default=10\n");
}

static void hfsc_parse_qdisc_argv(struct rtnl_tc *tc, int argc, char **argv)
{
struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) tc;

for (;;) {
int c, optidx = 0;
enum {
ARG_DEFAULT = 257,
};
static struct option long_opts[] = {
{ "help", 0, 0, 'h' },
{ "default", 1, 0, ARG_DEFAULT },
{ 0, 0, 0, 0 }
};

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

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

case ARG_DEFAULT:
rtnl_qdisc_hfsc_set_defcls(qdisc, nl_cli_parse_u32(optarg));
break;
}
}
}

static void print_class_usage(void)
{
printf(
"Usage: nl-class-add [...] hfsc [OPTIONS]...\n"
"\n"
"OPTIONS\n"
" --help Show this help text.\n"
" --ls=SC Link-sharing service curve\n"
" --rt=SC Real-time service curve\n"
" --sc=SC Specifiy both of the above\n"
" --ul=SC Upper limit\n"
" where SC := [ [ m1 bits ] d usec ] m2 bits\n"
"\n"
"EXAMPLE"
" # Attach class 1:1 to hfsc qdisc 1: and use rt and ls curve\n"
" nl-class-add --dev=eth1 --parent=1: --classid=1:1 hfsc --sc=m1:250,d:8,m2:100\n");
}

static int
hfsc_get_sc(char *optarg, struct tc_service_curve *sc)
{
unsigned int m1 = 0, d = 0, m2 = 0;
char *tmp = strdup(optarg);
char *p = tmp, *endptr;

if (!tmp)
return -ENOMEM;

p = strstr(p, "m1:");
if (p) {
char *q;
p += 3;
if (*p == 0)
goto err;
q = strchr(p, ',');
if (!q)
goto err;
*q = 0;
m1 = strtoul(p, &endptr, 10);
if (endptr == p)
goto err;
p = q + 1;
}

p = strstr(p, "d:");
if (p) {
char *q;
p += 2;
if (*p == 0)
goto err;
q = strchr(p, ',');
if (!q)
goto err;
*q = 0;
d = strtoul(p, &endptr, 10);
if (endptr == p)
goto err;
p = q + 1;
}

p = strstr(p, "m2:");
if (p) {
p += 3;
if (*p == 0)
goto err;
m2 = strtoul(p, &endptr, 10);
if (endptr == p)
goto err;
} else
goto err;

free(tmp);
sc->m1 = m1;
sc->d = d;
sc->m2 = m2;
return 0;

err:
free(tmp);
return -EINVAL;
}

static void hfsc_parse_class_argv(struct rtnl_tc *tc, int argc, char **argv)
{
struct rtnl_class *class = (struct rtnl_class *) tc;
int arg_ok = 0, ret = -EINVAL;

for (;;) {
int c, optidx = 0;
enum {
ARG_RT = 257,
ARG_LS = 258,
ARG_SC,
ARG_UL,
};
static struct option long_opts[] = {
{ "help", 0, 0, 'h' },
{ "rt", 1, 0, ARG_RT },
{ "ls", 1, 0, ARG_LS },
{ "sc", 1, 0, ARG_SC },
{ "ul", 1, 0, ARG_UL },
{ 0, 0, 0, 0 }
};
struct tc_service_curve tsc;

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

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

case ARG_RT:
ret = hfsc_get_sc(optarg, &tsc);
if (ret < 0) {
nl_cli_fatal(ret, "Unable to parse sc "
"\"%s\": Invalid format.", optarg);
}

rtnl_class_hfsc_set_rsc(class, &tsc);
arg_ok++;
break;

case ARG_LS:
ret = hfsc_get_sc(optarg, &tsc);
if (ret < 0) {
nl_cli_fatal(ret, "Unable to parse sc "
"\"%s\": Invalid format.", optarg);
}

rtnl_class_hfsc_set_fsc(class, &tsc);
arg_ok++;
break;

case ARG_SC:
ret = hfsc_get_sc(optarg, &tsc);
if (ret < 0) {
nl_cli_fatal(ret, "Unable to parse sc "
"\"%s\": Invalid format.", optarg);
}

rtnl_class_hfsc_set_rsc(class, &tsc);
rtnl_class_hfsc_set_fsc(class, &tsc);
arg_ok++;
break;

case ARG_UL:
ret = hfsc_get_sc(optarg, &tsc);
if (ret < 0) {
nl_cli_fatal(ret, "Unable to parse sc "
"\"%s\": Invalid format.", optarg);
}

rtnl_class_hfsc_set_usc(class, &tsc);
arg_ok++;
break;
}
}

if (!arg_ok)
nl_cli_fatal(ret, "Invalid arguments");
}

static struct nl_cli_tc_module hfsc_qdisc_module =
{
.tm_name = "hfsc",
.tm_type = RTNL_TC_TYPE_QDISC,
.tm_parse_argv = hfsc_parse_qdisc_argv,
};

static struct nl_cli_tc_module hfsc_class_module =
{
.tm_name = "hfsc",
.tm_type = RTNL_TC_TYPE_CLASS,
.tm_parse_argv = hfsc_parse_class_argv,
};

static void __init hfsc_init(void)
{
nl_cli_tc_register(&hfsc_qdisc_module);
nl_cli_tc_register(&hfsc_class_module);
}

static void __exit hfsc_exit(void)
{
nl_cli_tc_unregister(&hfsc_class_module);
nl_cli_tc_unregister(&hfsc_qdisc_module);
}

0 comments on commit 76237f6

Please sign in to comment.