ip_dummynet.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*-
  2. * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  3. *
  4. * Copyright (c) 1998-2010 Luigi Rizzo, Universita` di Pisa
  5. * Portions Copyright (c) 2000 Akamba Corp.
  6. * All rights reserved
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. *
  29. * $FreeBSD$
  30. */
  31. #ifndef _IP_DUMMYNET_H
  32. #define _IP_DUMMYNET_H
  33. #define NEW_AQM
  34. /*
  35. * Definition of the kernel-userland API for dummynet.
  36. *
  37. * Setsockopt() and getsockopt() pass a batch of objects, each
  38. * of them starting with a "struct dn_id" which should fully identify
  39. * the object and its relation with others in the sequence.
  40. * The first object in each request should have
  41. * type= DN_CMD_*, id = DN_API_VERSION.
  42. * For other objects, type and subtype specify the object, len indicates
  43. * the total length including the header, and 'id' identifies the specific
  44. * object.
  45. *
  46. * Most objects are numbered with an identifier in the range 1..65535.
  47. * DN_MAX_ID indicates the first value outside the range.
  48. */
  49. #define DN_API_VERSION 12500000
  50. #define DN_MAX_ID 0x10000
  51. struct dn_id {
  52. uint16_t len; /* total obj len including this header */
  53. uint8_t type;
  54. uint8_t subtype;
  55. uint32_t id; /* generic id */
  56. };
  57. /*
  58. * These values are in the type field of struct dn_id.
  59. * To preserve the ABI, never rearrange the list or delete
  60. * entries with the exception of DN_LAST
  61. */
  62. enum {
  63. DN_NONE = 0,
  64. DN_LINK = 1,
  65. DN_FS,
  66. DN_SCH,
  67. DN_SCH_I,
  68. DN_QUEUE,
  69. DN_DELAY_LINE,
  70. DN_PROFILE,
  71. DN_FLOW, /* struct dn_flow */
  72. DN_TEXT, /* opaque text is the object */
  73. DN_CMD_CONFIG = 0x80, /* objects follow */
  74. DN_CMD_DELETE, /* subtype + list of entries */
  75. DN_CMD_GET, /* subtype + list of entries */
  76. DN_CMD_FLUSH,
  77. /* for compatibility with FreeBSD 7.2/8 */
  78. DN_COMPAT_PIPE,
  79. DN_COMPAT_QUEUE,
  80. DN_GET_COMPAT,
  81. /* special commands for emulation of sysctl variables */
  82. DN_SYSCTL_GET,
  83. DN_SYSCTL_SET,
  84. #ifdef NEW_AQM
  85. /* subtypes used for setting/getting extra parameters.
  86. * these subtypes used with IP_DUMMYNET3 command (get)
  87. * and DN_TEXT (set). */
  88. DN_AQM_PARAMS, /* AQM extra params */
  89. DN_SCH_PARAMS, /* scheduler extra params */
  90. #endif
  91. DN_LAST,
  92. };
  93. enum { /* subtype for schedulers, flowset and the like */
  94. DN_SCHED_UNKNOWN = 0,
  95. DN_SCHED_FIFO = 1,
  96. DN_SCHED_WF2QP = 2,
  97. /* others are in individual modules */
  98. };
  99. enum { /* user flags */
  100. DN_HAVE_MASK = 0x0001, /* fs or sched has a mask */
  101. DN_NOERROR = 0x0002, /* do not report errors */
  102. DN_QHT_HASH = 0x0004, /* qht is a hash table */
  103. DN_QSIZE_BYTES = 0x0008, /* queue size is in bytes */
  104. DN_HAS_PROFILE = 0x0010, /* a link has a profile */
  105. DN_IS_RED = 0x0020,
  106. DN_IS_GENTLE_RED= 0x0040,
  107. DN_IS_ECN = 0x0080,
  108. #ifdef NEW_AQM
  109. DN_IS_AQM = 0x0100, /* AQMs: e.g Codel & PIE */
  110. #endif
  111. DN_PIPE_CMD = 0x1000, /* pipe config... */
  112. };
  113. /*
  114. * link template.
  115. */
  116. struct dn_link {
  117. struct dn_id oid;
  118. /*
  119. * Userland sets bw and delay in bits/s and milliseconds.
  120. * The kernel converts this back and forth to bits/tick and ticks.
  121. * XXX what about burst ?
  122. */
  123. int32_t link_nr;
  124. int bandwidth; /* bit/s or bits/tick. */
  125. int delay; /* ms and ticks */
  126. uint64_t burst; /* scaled. bits*Hz XXX */
  127. };
  128. /*
  129. * A flowset, which is a template for flows. Contains parameters
  130. * from the command line: id, target scheduler, queue sizes, plr,
  131. * flow masks, buckets for the flow hash, and possibly scheduler-
  132. * specific parameters (weight, quantum and so on).
  133. */
  134. struct dn_fs {
  135. struct dn_id oid;
  136. uint32_t fs_nr; /* the flowset number */
  137. uint32_t flags; /* userland flags */
  138. int qsize; /* queue size in slots or bytes */
  139. int32_t plr; /* PLR, pkt loss rate (2^31-1 means 100%) */
  140. uint32_t buckets; /* buckets used for the queue hash table */
  141. struct ipfw_flow_id flow_mask;
  142. uint32_t sched_nr; /* the scheduler we attach to */
  143. /* generic scheduler parameters. Leave them at -1 if unset.
  144. * Now we use 0: weight, 1: lmax, 2: priority
  145. */
  146. int par[4];
  147. /* RED/GRED parameters.
  148. * weight and probabilities are in the range 0..1 represented
  149. * in fixed point arithmetic with SCALE_RED decimal bits.
  150. */
  151. #define SCALE_RED 16
  152. #define SCALE(x) ( (x) << SCALE_RED )
  153. #define SCALE_VAL(x) ( (x) >> SCALE_RED )
  154. #define SCALE_MUL(x,y) ( ( (x) * (y) ) >> SCALE_RED )
  155. int w_q ; /* queue weight (scaled) */
  156. int max_th ; /* maximum threshold for queue (scaled) */
  157. int min_th ; /* minimum threshold for queue (scaled) */
  158. int max_p ; /* maximum value for p_b (scaled) */
  159. };
  160. /*
  161. * dn_flow collects flow_id and stats for queues and scheduler
  162. * instances, and is used to pass these info to userland.
  163. * oid.type/oid.subtype describe the object, oid.id is number
  164. * of the parent object.
  165. */
  166. struct dn_flow {
  167. struct dn_id oid;
  168. struct ipfw_flow_id fid;
  169. uint64_t tot_pkts; /* statistics counters */
  170. uint64_t tot_bytes;
  171. uint32_t length; /* Queue length, in packets */
  172. uint32_t len_bytes; /* Queue length, in bytes */
  173. uint32_t drops;
  174. };
  175. /*
  176. * Scheduler template, mostly indicating the name, number,
  177. * sched_mask and buckets.
  178. */
  179. struct dn_sch {
  180. struct dn_id oid;
  181. uint32_t sched_nr; /* N, scheduler number */
  182. uint32_t buckets; /* number of buckets for the instances */
  183. uint32_t flags; /* have_mask, ... */
  184. char name[16]; /* null terminated */
  185. /* mask to select the appropriate scheduler instance */
  186. struct ipfw_flow_id sched_mask; /* M */
  187. };
  188. /* A delay profile is attached to a link.
  189. * Note that a profile, as any other object, cannot be longer than 2^16
  190. */
  191. #define ED_MAX_SAMPLES_NO 1024
  192. struct dn_profile {
  193. struct dn_id oid;
  194. /* fields to simulate a delay profile */
  195. #define ED_MAX_NAME_LEN 32
  196. char name[ED_MAX_NAME_LEN];
  197. int link_nr;
  198. int loss_level;
  199. int bandwidth; // XXX use link bandwidth?
  200. int samples_no; /* actual len of samples[] */
  201. int samples[ED_MAX_SAMPLES_NO]; /* may be shorter */
  202. };
  203. #ifdef NEW_AQM
  204. /* Extra parameters for AQM and scheduler.
  205. * This struct is used to pass and retrieve parameters (configurations)
  206. * to/from AQM and Scheduler.
  207. */
  208. struct dn_extra_parms {
  209. struct dn_id oid;
  210. char name[16];
  211. uint32_t nr;
  212. #define DN_MAX_EXTRA_PARM 10
  213. int64_t par[DN_MAX_EXTRA_PARM];
  214. };
  215. #endif
  216. /*
  217. * Overall structure of dummynet
  218. In dummynet, packets are selected with the firewall rules, and passed
  219. to two different objects: PIPE or QUEUE (bad name).
  220. A QUEUE defines a classifier, which groups packets into flows
  221. according to a 'mask', puts them into independent queues (one
  222. per flow) with configurable size and queue management policy,
  223. and passes flows to a scheduler:
  224. (flow_mask|sched_mask) sched_mask
  225. +---------+ weight Wx +-------------+
  226. | |->-[flow]-->--| |-+
  227. -->--| QUEUE x | ... | | |
  228. | |->-[flow]-->--| SCHEDuler N | |
  229. +---------+ | | |
  230. ... | +--[LINK N]-->--
  231. +---------+ weight Wy | | +--[LINK N]-->--
  232. | |->-[flow]-->--| | |
  233. -->--| QUEUE y | ... | | |
  234. | |->-[flow]-->--| | |
  235. +---------+ +-------------+ |
  236. +-------------+
  237. Many QUEUE objects can connect to the same scheduler, each
  238. QUEUE object can have its own set of parameters.
  239. In turn, the SCHEDuler 'forks' multiple instances according
  240. to a 'sched_mask', each instance manages its own set of queues
  241. and transmits on a private instance of a configurable LINK.
  242. A PIPE is a simplified version of the above, where there
  243. is no flow_mask, and each scheduler instance handles a single queue.
  244. The following data structures (visible from userland) describe
  245. the objects used by dummynet:
  246. + dn_link, contains the main configuration parameters related
  247. to delay and bandwidth;
  248. + dn_profile describes a delay profile;
  249. + dn_flow describes the flow status (flow id, statistics)
  250. + dn_sch describes a scheduler
  251. + dn_fs describes a flowset (msk, weight, queue parameters)
  252. *
  253. */
  254. #endif /* _IP_DUMMYNET_H */