libnl  3.2.24-rc1
fq_codel.c
1 /*
2  * lib/cli/qdisc/fq_codel.c fq_codel module for CLI lib
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation version 2.1
7  * of the License.
8  *
9  * Copyright (c) 2013 Cong Wang <xiyou.wangcong@gmail.com>
10  */
11 
12 #include <netlink/cli/utils.h>
13 #include <netlink/cli/tc.h>
14 #include <netlink/route/qdisc/fq_codel.h>
15 
16 static void print_usage(void)
17 {
18  printf(
19 "Usage: nl-qdisc-add [...] fq_codel [OPTIONS]...\n"
20 "\n"
21 "OPTIONS\n"
22 " --help Show this help text.\n"
23 " --limit=LIMIT Maximum queue length in number of bytes.\n"
24 " --quantum=SIZE Amount of bytes to serve at once.\n"
25 " --flows=N Number of flows.\n"
26 " --interval=N The interval in usec.\n"
27 " --target=N The minimum delay in usec.\n"
28 "\n"
29 "EXAMPLE"
30 " # Attach fq_codel with a 4096 packets limit to eth1\n"
31 " nl-qdisc-add --dev=eth1 --parent=root fq_codel --limit=4096\n");
32 }
33 
34 static void fq_codel_parse_argv(struct rtnl_tc *tc, int argc, char **argv)
35 {
36  struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) tc;
37  int limit, flows;
38  uint32_t quantum, target, interval;
39 
40  for (;;) {
41  int c, optidx = 0;
42  enum {
43  ARG_LIMIT = 257,
44  ARG_QUANTUM = 258,
45  ARG_FLOWS,
46  ARG_INTERVAL,
47  ARG_TARGET,
48  };
49  static struct option long_opts[] = {
50  { "help", 0, 0, 'h' },
51  { "limit", 1, 0, ARG_LIMIT },
52  { "quantum", 1, 0, ARG_QUANTUM },
53  { "flows", 1, 0, ARG_FLOWS},
54  { "interval", 1, 0, ARG_INTERVAL},
55  { "target", 1, 0, ARG_TARGET},
56  { 0, 0, 0, 0 }
57  };
58 
59  c = getopt_long(argc, argv, "h", long_opts, &optidx);
60  if (c == -1)
61  break;
62 
63  switch (c) {
64  case 'h':
65  print_usage();
66  return;
67 
68  case ARG_LIMIT:
69  limit = nl_cli_parse_u32(optarg);
70  rtnl_qdisc_fq_codel_set_limit(qdisc, limit);
71  break;
72 
73  case ARG_QUANTUM:
74  quantum = nl_cli_parse_u32(optarg);
75  rtnl_qdisc_fq_codel_set_quantum(qdisc, quantum);
76  break;
77 
78  case ARG_FLOWS:
79  flows = nl_cli_parse_u32(optarg);
80  rtnl_qdisc_fq_codel_set_flows(qdisc, flows);
81  break;
82 
83  case ARG_INTERVAL:
84  interval = nl_cli_parse_u32(optarg);
85  rtnl_qdisc_fq_codel_set_interval(qdisc, interval);
86  break;
87 
88  case ARG_TARGET:
89  target = nl_cli_parse_u32(optarg);
90  rtnl_qdisc_fq_codel_set_target(qdisc, target);
91  break;
92 
93  }
94  }
95 }
96 
97 static struct nl_cli_tc_module fq_codel_module =
98 {
99  .tm_name = "fq_codel",
100  .tm_type = RTNL_TC_TYPE_QDISC,
101  .tm_parse_argv = fq_codel_parse_argv,
102 };
103 
104 static void __init fq_codel_init(void)
105 {
106  nl_cli_tc_register(&fq_codel_module);
107 }
108 
109 static void __exit fq_codel_exit(void)
110 {
111  nl_cli_tc_unregister(&fq_codel_module);
112 }