plug.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * src/lib/cli/qdisc/plug.c plug 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) 2012 Shriram Rajagopalan <rshriram@cs.ubc.ca>
  10. */
  11. #include <netlink/cli/utils.h>
  12. #include <netlink/cli/tc.h>
  13. #include <netlink/route/qdisc/plug.h>
  14. static void print_usage(void)
  15. {
  16. printf(
  17. "Usage: nl-qdisc-add [...] plug [OPTIONS]...\n"
  18. "\n"
  19. "OPTIONS\n"
  20. " --help Show this help text.\n"
  21. " --limit Maximum queue length in bytes.\n"
  22. " --buffer create a new buffer(plug) and queue incoming traffic into it.\n"
  23. " --release-one release traffic from previous buffer.\n"
  24. " --release-indefinite stop buffering and release all (buffered and new) packets.\n"
  25. "\n"
  26. "EXAMPLE"
  27. " # Attach plug qdisc with 32KB queue size to ifb0\n"
  28. " nl-qdisc-add --dev=ifb0 --parent=root plug --limit=32768\n"
  29. " # Plug network traffic arriving at ifb0\n"
  30. " nl-qdisc-add --dev=ifb0 --parent=root --update plug --buffer\n"
  31. " # Unplug traffic arriving at ifb0 indefinitely\n"
  32. " nl-qdisc-add --dev=ifb0 --parent=root --update plug --release-indefinite\n\n"
  33. " # If operating in output buffering mode:\n"
  34. " # at time t=t0, create a new output buffer b0 to hold network output\n"
  35. " nl-qdisc-add --dev=ifb0 --parent=root --update plug --buffer\n\n"
  36. " # at time t=t1, take a checkpoint c0, create a new output buffer b1\n"
  37. " nl-qdisc-add --dev=ifb0 --parent=root --update plug --buffer\n"
  38. " # at time t=t1+r, after c0 is committed, release b0\n"
  39. " nl-qdisc-add --dev=ifb0 --parent=root --update plug --release-one\n\n"
  40. " # at time t=t2, take a checkpoint c1, create a new output buffer b2\n"
  41. " nl-qdisc-add --dev=ifb0 --parent=root --update plug --buffer\n"
  42. " # at time t=t2+r, after c1 is committed, release b1\n"
  43. " nl-qdisc-add --dev=ifb0 --parent=root --update plug --release-one\n");
  44. }
  45. static void plug_parse_argv(struct rtnl_tc *tc, int argc, char **argv)
  46. {
  47. struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) tc;
  48. for (;;) {
  49. int c, optidx = 0;
  50. enum {
  51. ARG_LIMIT = 257,
  52. ARG_BUFFER = 258,
  53. ARG_RELEASE_ONE = 259,
  54. ARG_RELEASE_INDEFINITE = 260,
  55. };
  56. static struct option long_opts[] = {
  57. { "help", 0, 0, 'h' },
  58. { "limit", 1, 0, ARG_LIMIT },
  59. { "buffer", 0, 0, ARG_BUFFER },
  60. { "release-one", 0, 0, ARG_RELEASE_ONE },
  61. { "release-indefinite", 0, 0, ARG_RELEASE_INDEFINITE },
  62. { 0, 0, 0, 0 }
  63. };
  64. c = getopt_long(argc, argv, "h", long_opts, &optidx);
  65. if (c == -1)
  66. break;
  67. switch (c) {
  68. case 'h':
  69. print_usage();
  70. return;
  71. case ARG_LIMIT:
  72. rtnl_qdisc_plug_set_limit(qdisc, nl_cli_parse_u32(optarg));
  73. break;
  74. case ARG_BUFFER:
  75. rtnl_qdisc_plug_buffer(qdisc);
  76. break;
  77. case ARG_RELEASE_ONE:
  78. rtnl_qdisc_plug_release_one(qdisc);
  79. break;
  80. case ARG_RELEASE_INDEFINITE:
  81. rtnl_qdisc_plug_release_indefinite(qdisc);
  82. break;
  83. }
  84. }
  85. }
  86. static struct nl_cli_tc_module plug_module =
  87. {
  88. .tm_name = "plug",
  89. .tm_type = RTNL_TC_TYPE_QDISC,
  90. .tm_parse_argv = plug_parse_argv,
  91. };
  92. static void __init plug_init(void)
  93. {
  94. nl_cli_tc_register(&plug_module);
  95. }
  96. static void __exit plug_exit(void)
  97. {
  98. nl_cli_tc_unregister(&plug_module);
  99. }