plug.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * lib/route/qdisc/plug.c PLUG Qdisc
  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. /**
  12. * @ingroup qdisc
  13. * @defgroup qdisc_plug Plug/Unplug Traffic (PLUG)
  14. * @brief
  15. *
  16. * Queue traffic until an explicit release command.
  17. *
  18. * There are two ways to use this qdisc:
  19. * 1. A simple "instantaneous" plug/unplug operation, by issuing an alternating
  20. * sequence of TCQ_PLUG_BUFFER & TCQ_PLUG_RELEASE_INDEFINITE commands.
  21. *
  22. * 2. For network output buffering (a.k.a output commit) functionality.
  23. * Output commit property is commonly used by applications using checkpoint
  24. * based fault-tolerance to ensure that the checkpoint from which a system
  25. * is being restored is consistent w.r.t outside world.
  26. *
  27. * Consider for e.g. Remus - a Virtual Machine checkpointing system,
  28. * wherein a VM is checkpointed, say every 50ms. The checkpoint is replicated
  29. * asynchronously to the backup host, while the VM continues executing the
  30. * next epoch speculatively.
  31. *
  32. * The following is a typical sequence of output buffer operations:
  33. * 1.At epoch i, start_buffer(i)
  34. * 2. At end of epoch i (i.e. after 50ms):
  35. * 2.1 Stop VM and take checkpoint(i).
  36. * 2.2 start_buffer(i+1) and Resume VM
  37. * 3. While speculatively executing epoch(i+1), asynchronously replicate
  38. * checkpoint(i) to backup host.
  39. * 4. When checkpoint_ack(i) is received from backup, release_buffer(i)
  40. * Thus, this Qdisc would receive the following sequence of commands:
  41. * TCQ_PLUG_BUFFER (epoch i)
  42. * .. TCQ_PLUG_BUFFER (epoch i+1)
  43. * ....TCQ_PLUG_RELEASE_ONE (epoch i)
  44. * ......TCQ_PLUG_BUFFER (epoch i+2)
  45. * ........
  46. *
  47. *
  48. * State of the queue, when used for network output buffering:
  49. *
  50. * plug(i+1) plug(i) head
  51. * ------------------+--------------------+---------------->
  52. * | |
  53. * | |
  54. * pkts_current_epoch| pkts_last_epoch |pkts_to_release
  55. * ----------------->|<--------+--------->|+--------------->
  56. * v v
  57. *
  58. *
  59. * @{
  60. */
  61. #include <netlink-private/netlink.h>
  62. #include <netlink-private/tc.h>
  63. #include <netlink/netlink.h>
  64. #include <netlink/utils.h>
  65. #include <netlink-private/route/tc-api.h>
  66. #include <netlink/route/qdisc/plug.h>
  67. static int plug_msg_fill(struct rtnl_tc *tc, void *data, struct nl_msg *msg)
  68. {
  69. struct rtnl_plug *plug = data;
  70. struct tc_plug_qopt opts;
  71. if (!plug)
  72. return -NLE_INVAL;
  73. opts.action = plug->action;
  74. opts.limit = plug->limit;
  75. return nlmsg_append(msg, &opts, sizeof(opts), NL_DONTPAD);
  76. }
  77. /**
  78. * @name Attribute Modification
  79. * @{
  80. */
  81. /**
  82. * Insert a plug into the qdisc and buffer any incoming
  83. * network traffic.
  84. * @arg qdisc PLUG qdisc to be modified.
  85. */
  86. int rtnl_qdisc_plug_buffer(struct rtnl_qdisc *qdisc)
  87. {
  88. struct rtnl_plug *plug;
  89. if (!(plug = rtnl_tc_data(TC_CAST(qdisc))))
  90. return -NLE_NOMEM;
  91. plug->action = TCQ_PLUG_BUFFER;
  92. return 0;
  93. }
  94. /**
  95. * Unplug the qdisc, releasing packets from queue head
  96. * to the last complete buffer, while new traffic
  97. * continues to be buffered.
  98. * @arg qdisc PLUG qdisc to be modified.
  99. */
  100. int rtnl_qdisc_plug_release_one(struct rtnl_qdisc *qdisc)
  101. {
  102. struct rtnl_plug *plug;
  103. if (!(plug = rtnl_tc_data(TC_CAST(qdisc))))
  104. return -NLE_NOMEM;
  105. plug->action = TCQ_PLUG_RELEASE_ONE;
  106. return 0;
  107. }
  108. /**
  109. * Indefinitely unplug the qdisc, releasing all packets.
  110. * Network traffic will not be buffered until the next
  111. * buffer command is issued.
  112. * @arg qdisc PLUG qdisc to be modified.
  113. */
  114. int rtnl_qdisc_plug_release_indefinite(struct rtnl_qdisc *qdisc)
  115. {
  116. struct rtnl_plug *plug;
  117. if (!(plug = rtnl_tc_data(TC_CAST(qdisc))))
  118. return -NLE_NOMEM;
  119. plug->action = TCQ_PLUG_RELEASE_INDEFINITE;
  120. return 0;
  121. }
  122. /**
  123. * Set limit of PLUG qdisc.
  124. * @arg qdisc PLUG qdisc to be modified.
  125. * @arg limit New limit.
  126. * @return 0 on success or a negative error code.
  127. */
  128. int rtnl_qdisc_plug_set_limit(struct rtnl_qdisc *qdisc, int limit)
  129. {
  130. struct rtnl_plug *plug;
  131. if (!(plug = rtnl_tc_data(TC_CAST(qdisc))))
  132. return -NLE_NOMEM;
  133. plug->action = TCQ_PLUG_LIMIT;
  134. plug->limit = limit;
  135. return 0;
  136. }
  137. /** @} */
  138. static struct rtnl_tc_ops plug_ops = {
  139. .to_kind = "plug",
  140. .to_type = RTNL_TC_TYPE_QDISC,
  141. .to_size = sizeof(struct rtnl_plug),
  142. .to_msg_fill = plug_msg_fill,
  143. };
  144. static void __init plug_init(void)
  145. {
  146. rtnl_tc_register(&plug_ops);
  147. }
  148. static void __exit plug_exit(void)
  149. {
  150. rtnl_tc_unregister(&plug_ops);
  151. }
  152. /** @} */