2 * Copyright (C) 2016 Centre for Advanced Internet Architectures,
3 * Swinburne University of Technology, Melbourne, Australia.
4 * Portions of this code were made possible in part by a gift from
5 * The Comcast Innovation Fund.
6 * Implemented by Rasool Al-Saadi <ralsaadi@swin.edu.au>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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
31 * API for writing an Active Queue Management algorithm for Dummynet
40 /* NOW is the current time in millisecond*/
41 #define NOW ((dn_cfg.curr_time * tick) / 1000)
43 #define AQM_UNOW (dn_cfg.curr_time * tick)
44 #define AQM_TIME_1US ((aqm_time_t)(1))
45 #define AQM_TIME_1MS ((aqm_time_t)(1000))
46 #define AQM_TIME_1S ((aqm_time_t)(AQM_TIME_1MS * 1000))
48 /* aqm time allows to store up to 4294 seconds */
49 typedef uint32_t aqm_time_t;
50 typedef int32_t aqm_stime_t;
52 #define DN_AQM_MTAG_TS 55345
54 /* Macro for variable bounding */
55 #define BOUND_VAR(x,l,h) ((x) > (h)? (h) : ((x) > (l)? (x) : (l)))
57 /* sysctl variable to count number of dropped packets */
58 extern unsigned long io_pkt_drop;
61 * Structure for holding data and function pointers that together represent a
65 #define DN_AQM_NAME_MAX 50
66 char name[DN_AQM_NAME_MAX]; /* name of AQM algorithm */
67 uint32_t type; /* AQM type number */
69 /* Methods implemented by AQM algorithm:
71 * enqueue enqueue packet 'm' on queue 'q'.
72 * Return 0 on success, 1 on drop.
74 * dequeue dequeue a packet from queue 'q'.
75 * Return a packet, NULL if no packet available.
77 * config configure AQM algorithm
78 * If required, this function should allocate space to store
79 * the configurations and set 'fs->aqmcfg' to point to this space.
80 * 'dn_extra_parms' includes array of parameters send
81 * from ipfw userland command.
82 * Return 0 on success, non-zero otherwise.
84 * deconfig deconfigure AQM algorithm.
85 * The allocated configuration memory space should be freed here.
86 * Return 0 on success, non-zero otherwise.
88 * init initialise AQM status variables of queue 'q'
89 * This function is used to allocate space and init AQM status for a
90 * queue and q->aqm_status to point to this space.
91 * Return 0 on success, non-zero otherwise.
93 * cleanup cleanup AQM status variables of queue 'q'
94 * The allocated memory space for AQM status should be freed here.
95 * Return 0 on success, non-zero otherwise.
97 * getconfig retrieve AQM configurations
98 * This function is used to return AQM parameters to userland
99 * command. The function should fill 'dn_extra_parms' struct with
100 * the AQM configurations using 'par' array.
104 int (*enqueue)(struct dn_queue *, struct mbuf *);
105 struct mbuf * (*dequeue)(struct dn_queue *);
106 int (*config)(struct dn_fsk *, struct dn_extra_parms *ep, int);
107 int (*deconfig)(struct dn_fsk *);
108 int (*init)(struct dn_queue *);
109 int (*cleanup)(struct dn_queue *);
110 int (*getconfig)(struct dn_fsk *, struct dn_extra_parms *);
112 int ref_count; /*Number of queues instances in the system */
113 int cfg_ref_count; /*Number of AQM instances in the system */
114 SLIST_ENTRY (dn_aqm) next; /* Next AQM in the list */
117 /* Helper function to update queue and scheduler statistics.
118 * negative len + drop -> drop
119 * negative len -> dequeue
120 * positive len -> enqueue
121 * positive len + drop -> drop during enqueue
124 update_stats(struct dn_queue *q, int len, int drop)
143 /*update queue stats */
145 qni->len_bytes += len;
147 /*update scheduler instance stats */
149 sni->len_bytes += len;
151 /* tot_pkts is updated in dn_enqueue function */
155 /* kernel module related function */
157 dn_aqm_modevent(module_t mod, int cmd, void *arg);
159 #define DECLARE_DNAQM_MODULE(name, dnaqm) \
160 static moduledata_t name##_mod = { \
161 #name, dn_aqm_modevent, dnaqm \
163 DECLARE_MODULE(name, name##_mod, \
164 SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY); \
165 MODULE_DEPEND(name, dummynet, 3, 3, 3)