hfsc.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* $OpenBSD: hfsc.h,v 1.8 2015/04/12 09:58:46 dlg Exp $ */
  2. /*
  3. * Copyright (c) 2012-2013 Henning Brauer <henning@openbsd.org>
  4. * Copyright (c) 1997-1999 Carnegie Mellon University. All Rights Reserved.
  5. *
  6. * Permission to use, copy, modify, and distribute this software and
  7. * its documentation is hereby granted (including for commercial or
  8. * for-profit use), provided that both the copyright notice and this
  9. * permission notice appear in all copies of the software, derivative
  10. * works, or modified versions, and any portions thereof.
  11. *
  12. * THIS SOFTWARE IS EXPERIMENTAL AND IS KNOWN TO HAVE BUGS, SOME OF
  13. * WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON PROVIDES THIS
  14. * SOFTWARE IN ITS ``AS IS'' CONDITION, AND ANY EXPRESS OR IMPLIED
  15. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  16. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. * DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
  18. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  19. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  20. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  21. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  24. * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  25. * DAMAGE.
  26. *
  27. * Carnegie Mellon encourages (but does not require) users of this
  28. * software to return any improvements or extensions that they make,
  29. * and to grant Carnegie Mellon the rights to redistribute these
  30. * changes without encumbrance.
  31. */
  32. #ifndef _HFSC_H_
  33. #define _HFSC_H_
  34. /* hfsc class flags */
  35. #define HFSC_RED 0x0001 /* use RED */
  36. #define HFSC_ECN 0x0002 /* use RED/ECN */
  37. #define HFSC_RIO 0x0004 /* use RIO */
  38. #define HFSC_DEFAULTCLASS 0x1000 /* default class */
  39. struct hfsc_pktcntr {
  40. u_int64_t packets;
  41. u_int64_t bytes;
  42. };
  43. #define PKTCNTR_INC(cntr, len) \
  44. do { (cntr)->packets++; (cntr)->bytes += len; } while (0)
  45. struct hfsc_sc {
  46. u_int m1; /* slope of the first segment in bits/sec */
  47. u_int d; /* the x-projection of the first segment in msec */
  48. u_int m2; /* slope of the second segment in bits/sec */
  49. };
  50. /* special class handles */
  51. #define HFSC_NULLCLASS_HANDLE 0
  52. #define HFSC_DEFAULT_CLASSES 64
  53. #define HFSC_MAX_CLASSES 65535
  54. /* service curve types */
  55. #define HFSC_REALTIMESC 1
  56. #define HFSC_LINKSHARINGSC 2
  57. #define HFSC_UPPERLIMITSC 4
  58. #define HFSC_DEFAULTSC (HFSC_REALTIMESC|HFSC_LINKSHARINGSC)
  59. struct hfsc_class_stats {
  60. u_int class_id;
  61. u_int32_t class_handle;
  62. struct hfsc_sc rsc;
  63. struct hfsc_sc fsc;
  64. struct hfsc_sc usc; /* upper limit service curve */
  65. u_int64_t total; /* total work in bytes */
  66. u_int64_t cumul; /* cumulative work in bytes
  67. done by real-time criteria */
  68. u_int64_t d; /* deadline */
  69. u_int64_t e; /* eligible time */
  70. u_int64_t vt; /* virtual time */
  71. u_int64_t f; /* fit time for upper-limit */
  72. /* info helpful for debugging */
  73. u_int64_t initvt; /* init virtual time */
  74. u_int64_t vtoff; /* cl_vt_ipoff */
  75. u_int64_t cvtmax; /* cl_maxvt */
  76. u_int64_t myf; /* cl_myf */
  77. u_int64_t cfmin; /* cl_mincf */
  78. u_int64_t cvtmin; /* cl_mincvt */
  79. u_int64_t myfadj; /* cl_myfadj */
  80. u_int64_t vtadj; /* cl_vtadj */
  81. u_int64_t cur_time;
  82. u_int32_t machclk_freq;
  83. u_int qlength;
  84. u_int qlimit;
  85. struct hfsc_pktcntr xmit_cnt;
  86. struct hfsc_pktcntr drop_cnt;
  87. u_int period;
  88. u_int vtperiod; /* vt period sequence no */
  89. u_int parentperiod; /* parent's vt period seqno */
  90. int nactive; /* number of active children */
  91. /* red and rio related info */
  92. int qtype;
  93. /* struct redstats red[3]; */
  94. };
  95. #ifdef _KERNEL
  96. struct ifnet;
  97. struct ifqueue;
  98. struct pf_queuespec;
  99. struct hfsc_if;
  100. #define HFSC_ENABLED(ifq) ((ifq)->ifq_hfsc != NULL)
  101. #define HFSC_DEFAULT_QLIMIT 50
  102. void hfsc_initialize(void);
  103. int hfsc_attach(struct ifnet *);
  104. int hfsc_detach(struct ifnet *);
  105. void hfsc_purge(struct ifqueue *);
  106. int hfsc_enqueue(struct ifqueue *, struct mbuf *);
  107. struct mbuf *hfsc_dequeue(struct ifqueue *, int);
  108. u_int64_t hfsc_microuptime(void);
  109. int hfsc_addqueue(struct pf_queuespec *);
  110. int hfsc_delqueue(struct pf_queuespec *);
  111. int hfsc_qstats(struct pf_queuespec *, void *, int *);
  112. #endif /* _KERNEL */
  113. #endif /* _HFSC_H_ */