fq_codel.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #include <netlink/cli/utils.h>
  12. #include <netlink/cli/tc.h>
  13. #include <netlink/route/qdisc/fq_codel.h>
  14. static void print_usage(void)
  15. {
  16. printf(
  17. "Usage: nl-qdisc-add [...] fq_codel [OPTIONS]...\n"
  18. "\n"
  19. "OPTIONS\n"
  20. " --help Show this help text.\n"
  21. " --limit=LIMIT Maximum queue length in number of bytes.\n"
  22. " --quantum=SIZE Amount of bytes to serve at once.\n"
  23. " --flows=N Number of flows.\n"
  24. " --interval=N The interval in usec.\n"
  25. " --target=N The minimum delay in usec.\n"
  26. "\n"
  27. "EXAMPLE"
  28. " # Attach fq_codel with a 4096 packets limit to eth1\n"
  29. " nl-qdisc-add --dev=eth1 --parent=root fq_codel --limit=4096\n");
  30. }
  31. static void fq_codel_parse_argv(struct rtnl_tc *tc, int argc, char **argv)
  32. {
  33. struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) tc;
  34. int limit, flows;
  35. uint32_t quantum, target, interval;
  36. for (;;) {
  37. int c, optidx = 0;
  38. enum {
  39. ARG_LIMIT = 257,
  40. ARG_QUANTUM = 258,
  41. ARG_FLOWS,
  42. ARG_INTERVAL,
  43. ARG_TARGET,
  44. };
  45. static struct option long_opts[] = {
  46. { "help", 0, 0, 'h' },
  47. { "limit", 1, 0, ARG_LIMIT },
  48. { "quantum", 1, 0, ARG_QUANTUM },
  49. { "flows", 1, 0, ARG_FLOWS},
  50. { "interval", 1, 0, ARG_INTERVAL},
  51. { "target", 1, 0, ARG_TARGET},
  52. { 0, 0, 0, 0 }
  53. };
  54. c = getopt_long(argc, argv, "h", long_opts, &optidx);
  55. if (c == -1)
  56. break;
  57. switch (c) {
  58. case 'h':
  59. print_usage();
  60. return;
  61. case ARG_LIMIT:
  62. limit = nl_cli_parse_u32(optarg);
  63. rtnl_qdisc_fq_codel_set_limit(qdisc, limit);
  64. break;
  65. case ARG_QUANTUM:
  66. quantum = nl_cli_parse_u32(optarg);
  67. rtnl_qdisc_fq_codel_set_quantum(qdisc, quantum);
  68. break;
  69. case ARG_FLOWS:
  70. flows = nl_cli_parse_u32(optarg);
  71. rtnl_qdisc_fq_codel_set_flows(qdisc, flows);
  72. break;
  73. case ARG_INTERVAL:
  74. interval = nl_cli_parse_u32(optarg);
  75. rtnl_qdisc_fq_codel_set_interval(qdisc, interval);
  76. break;
  77. case ARG_TARGET:
  78. target = nl_cli_parse_u32(optarg);
  79. rtnl_qdisc_fq_codel_set_target(qdisc, target);
  80. break;
  81. }
  82. }
  83. }
  84. static struct nl_cli_tc_module fq_codel_module =
  85. {
  86. .tm_name = "fq_codel",
  87. .tm_type = RTNL_TC_TYPE_QDISC,
  88. .tm_parse_argv = fq_codel_parse_argv,
  89. };
  90. static void __init fq_codel_init(void)
  91. {
  92. nl_cli_tc_register(&fq_codel_module);
  93. }
  94. static void __exit fq_codel_exit(void)
  95. {
  96. nl_cli_tc_unregister(&fq_codel_module);
  97. }