Deleted Added
full compact
ieee80211_amrr.c (178354) ieee80211_amrr.c (206358)
1/* $OpenBSD: ieee80211_amrr.c,v 1.1 2006/06/17 19:07:19 damien Exp $ */
2
3/*-
1/* $OpenBSD: ieee80211_amrr.c,v 1.1 2006/06/17 19:07:19 damien Exp $ */
2
3/*-
4 * Copyright (c) 2010 Rui Paulo <rpaulo@FreeBSD.org>
4 * Copyright (c) 2006
5 * Damien Bergamini <damien.bergamini@free.fr>
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#include <sys/cdefs.h>
5 * Copyright (c) 2006
6 * Damien Bergamini <damien.bergamini@free.fr>
7 *
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
21#include <sys/cdefs.h>
21__FBSDID("$FreeBSD: head/sys/net80211/ieee80211_amrr.c 178354 2008-04-20 20:35:46Z sam $");
22__FBSDID("$FreeBSD: head/sys/net80211/ieee80211_amrr.c 206358 2010-04-07 15:29:13Z rpaulo $");
22
23/*-
24 * Naive implementation of the Adaptive Multi Rate Retry algorithm:
25 *
26 * "IEEE 802.11 Rate Adaptation: A Practical Approach"
27 * Mathieu Lacage, Hossein Manshaei, Thierry Turletti
28 * INRIA Sophia - Projet Planete
29 * http://www-sop.inria.fr/rapports/sophia/RR-5208.html

--- 11 unchanged lines hidden (view full) ---

41
42#ifdef INET
43#include <netinet/in.h>
44#include <netinet/if_ether.h>
45#endif
46
47#include <net80211/ieee80211_var.h>
48#include <net80211/ieee80211_amrr.h>
23
24/*-
25 * Naive implementation of the Adaptive Multi Rate Retry algorithm:
26 *
27 * "IEEE 802.11 Rate Adaptation: A Practical Approach"
28 * Mathieu Lacage, Hossein Manshaei, Thierry Turletti
29 * INRIA Sophia - Projet Planete
30 * http://www-sop.inria.fr/rapports/sophia/RR-5208.html

--- 11 unchanged lines hidden (view full) ---

42
43#ifdef INET
44#include <netinet/in.h>
45#include <netinet/if_ether.h>
46#endif
47
48#include <net80211/ieee80211_var.h>
49#include <net80211/ieee80211_amrr.h>
50#include <net80211/ieee80211_ratectl.h>
49
50#define is_success(amn) \
51 ((amn)->amn_retrycnt < (amn)->amn_txcnt / 10)
52#define is_failure(amn) \
53 ((amn)->amn_retrycnt > (amn)->amn_txcnt / 3)
54#define is_enough(amn) \
55 ((amn)->amn_txcnt > 10)
56
51
52#define is_success(amn) \
53 ((amn)->amn_retrycnt < (amn)->amn_txcnt / 10)
54#define is_failure(amn) \
55 ((amn)->amn_retrycnt > (amn)->amn_txcnt / 3)
56#define is_enough(amn) \
57 ((amn)->amn_txcnt > 10)
58
57static void amrr_sysctlattach(struct ieee80211_amrr *amrr,
58 struct sysctl_ctx_list *ctx, struct sysctl_oid *tree);
59static void amrr_setinterval(const struct ieee80211vap *, int);
60static void amrr_init(struct ieee80211vap *);
61static void amrr_deinit(struct ieee80211vap *);
62static void amrr_node_init(struct ieee80211_node *);
63static void amrr_node_deinit(struct ieee80211_node *);
64static int amrr_update(struct ieee80211_amrr *,
65 struct ieee80211_amrr_node *, struct ieee80211_node *);
66static int amrr_rate(struct ieee80211_node *, void *, uint32_t);
67static void amrr_tx_complete(const struct ieee80211vap *,
68 const struct ieee80211_node *, int,
69 void *, void *);
70static void amrr_tx_update(const struct ieee80211vap *vap,
71 const struct ieee80211_node *, void *, void *, void *);
72static void amrr_sysctlattach(struct ieee80211vap *,
73 struct sysctl_ctx_list *, struct sysctl_oid *);
59
60/* number of references from net80211 layer */
61static int nrefs = 0;
62
74
75/* number of references from net80211 layer */
76static int nrefs = 0;
77
63void
64ieee80211_amrr_setinterval(struct ieee80211_amrr *amrr, int msecs)
78static const struct ieee80211_ratectl amrr = {
79 .ir_name = "amrr",
80 .ir_attach = NULL,
81 .ir_detach = NULL,
82 .ir_init = amrr_init,
83 .ir_deinit = amrr_deinit,
84 .ir_node_init = amrr_node_init,
85 .ir_node_deinit = amrr_node_deinit,
86 .ir_rate = amrr_rate,
87 .ir_tx_complete = amrr_tx_complete,
88 .ir_tx_update = amrr_tx_update,
89 .ir_setinterval = amrr_setinterval,
90};
91IEEE80211_RATECTL_MODULE(amrr, 1);
92IEEE80211_RATECTL_ALG(amrr, IEEE80211_RATECTL_AMRR, amrr);
93
94static void
95amrr_setinterval(const struct ieee80211vap *vap, int msecs)
65{
96{
97 struct ieee80211_amrr *amrr = vap->iv_rs;
66 int t;
67
68 if (msecs < 100)
69 msecs = 100;
70 t = msecs_to_ticks(msecs);
71 amrr->amrr_interval = (t < 1) ? 1 : t;
72}
73
98 int t;
99
100 if (msecs < 100)
101 msecs = 100;
102 t = msecs_to_ticks(msecs);
103 amrr->amrr_interval = (t < 1) ? 1 : t;
104}
105
74void
75ieee80211_amrr_init(struct ieee80211_amrr *amrr,
76 struct ieee80211vap *vap, int amin, int amax, int interval)
106static void
107amrr_init(struct ieee80211vap *vap)
77{
108{
78 /* XXX bounds check? */
79 amrr->amrr_min_success_threshold = amin;
80 amrr->amrr_max_success_threshold = amax;
81 ieee80211_amrr_setinterval(amrr, interval);
109 struct ieee80211_amrr *amrr;
82
110
83 amrr_sysctlattach(amrr, vap->iv_sysctl, vap->iv_oid);
111 KASSERT(vap->iv_rs == NULL, ("%s called multiple times", __func__));
112
113 vap->iv_rs = malloc(sizeof(struct ieee80211_amrr), M_80211_RATECTL,
114 M_WAITOK|M_ZERO);
115 amrr = vap->iv_rs;
116 amrr->amrr_min_success_threshold = IEEE80211_AMRR_MIN_SUCCESS_THRESHOLD;
117 amrr->amrr_max_success_threshold = IEEE80211_AMRR_MAX_SUCCESS_THRESHOLD;
118 amrr_setinterval(vap, 500 /* ms */);
119 amrr_sysctlattach(vap, vap->iv_sysctl, vap->iv_oid);
84}
85
120}
121
86void
87ieee80211_amrr_cleanup(struct ieee80211_amrr *amrr)
122static void
123amrr_deinit(struct ieee80211vap *vap)
88{
124{
125 free(vap->iv_rs, M_80211_RATECTL);
89}
90
126}
127
91void
92ieee80211_amrr_node_init(struct ieee80211_amrr *amrr,
93 struct ieee80211_amrr_node *amn, struct ieee80211_node *ni)
128static void
129amrr_node_init(struct ieee80211_node *ni)
94{
95 const struct ieee80211_rateset *rs = &ni->ni_rates;
130{
131 const struct ieee80211_rateset *rs = &ni->ni_rates;
132 struct ieee80211vap *vap = ni->ni_vap;
133 struct ieee80211_amrr *amrr = vap->iv_rs;
134 struct ieee80211_amrr_node *amn;
96
135
136 KASSERT(ni->ni_rctls == NULL, ("%s: ni_rctls already initialized",
137 __func__));
138
139 ni->ni_rctls = malloc(sizeof(struct ieee80211_amrr_node),
140 M_80211_RATECTL, M_WAITOK|M_ZERO);
141 amn = ni->ni_rctls;
97 amn->amn_amrr = amrr;
98 amn->amn_success = 0;
99 amn->amn_recovery = 0;
100 amn->amn_txcnt = amn->amn_retrycnt = 0;
101 amn->amn_success_threshold = amrr->amrr_min_success_threshold;
102
103 /* pick initial rate */
104 for (amn->amn_rix = rs->rs_nrates - 1;
105 amn->amn_rix > 0 && (rs->rs_rates[amn->amn_rix] & IEEE80211_RATE_VAL) > 72;
106 amn->amn_rix--)
107 ;
108 ni->ni_txrate = rs->rs_rates[amn->amn_rix] & IEEE80211_RATE_VAL;
109 amn->amn_ticks = ticks;
110
111 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni,
112 "AMRR initial rate %d", ni->ni_txrate);
113}
114
142 amn->amn_amrr = amrr;
143 amn->amn_success = 0;
144 amn->amn_recovery = 0;
145 amn->amn_txcnt = amn->amn_retrycnt = 0;
146 amn->amn_success_threshold = amrr->amrr_min_success_threshold;
147
148 /* pick initial rate */
149 for (amn->amn_rix = rs->rs_nrates - 1;
150 amn->amn_rix > 0 && (rs->rs_rates[amn->amn_rix] & IEEE80211_RATE_VAL) > 72;
151 amn->amn_rix--)
152 ;
153 ni->ni_txrate = rs->rs_rates[amn->amn_rix] & IEEE80211_RATE_VAL;
154 amn->amn_ticks = ticks;
155
156 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni,
157 "AMRR initial rate %d", ni->ni_txrate);
158}
159
160static void
161amrr_node_deinit(struct ieee80211_node *ni)
162{
163 free(ni->ni_rctls, M_80211_RATECTL);
164}
165
115static int
116amrr_update(struct ieee80211_amrr *amrr, struct ieee80211_amrr_node *amn,
117 struct ieee80211_node *ni)
118{
119 int rix = amn->amn_rix;
120
121 KASSERT(is_enough(amn), ("txcnt %d", amn->amn_txcnt));
122

--- 40 unchanged lines hidden (view full) ---

163 return rix;
164}
165
166/*
167 * Return the rate index to use in sending a data frame.
168 * Update our internal state if it's been long enough.
169 * If the rate changes we also update ni_txrate to match.
170 */
166static int
167amrr_update(struct ieee80211_amrr *amrr, struct ieee80211_amrr_node *amn,
168 struct ieee80211_node *ni)
169{
170 int rix = amn->amn_rix;
171
172 KASSERT(is_enough(amn), ("txcnt %d", amn->amn_txcnt));
173

--- 40 unchanged lines hidden (view full) ---

214 return rix;
215}
216
217/*
218 * Return the rate index to use in sending a data frame.
219 * Update our internal state if it's been long enough.
220 * If the rate changes we also update ni_txrate to match.
221 */
171int
172ieee80211_amrr_choose(struct ieee80211_node *ni,
173 struct ieee80211_amrr_node *amn)
222static int
223amrr_rate(struct ieee80211_node *ni, void *arg __unused, uint32_t iarg __unused)
174{
224{
225 struct ieee80211_amrr_node *amn = ni->ni_rctls;
175 struct ieee80211_amrr *amrr = amn->amn_amrr;
176 int rix;
177
178 if (is_enough(amn) && (ticks - amn->amn_ticks) > amrr->amrr_interval) {
179 rix = amrr_update(amrr, amn, ni);
180 if (rix != amn->amn_rix) {
181 /* update public rate */
182 ni->ni_txrate =
183 ni->ni_rates.rs_rates[rix] & IEEE80211_RATE_VAL;
184 amn->amn_rix = rix;
185 }
186 amn->amn_ticks = ticks;
187 } else
188 rix = amn->amn_rix;
189 return rix;
190}
191
226 struct ieee80211_amrr *amrr = amn->amn_amrr;
227 int rix;
228
229 if (is_enough(amn) && (ticks - amn->amn_ticks) > amrr->amrr_interval) {
230 rix = amrr_update(amrr, amn, ni);
231 if (rix != amn->amn_rix) {
232 /* update public rate */
233 ni->ni_txrate =
234 ni->ni_rates.rs_rates[rix] & IEEE80211_RATE_VAL;
235 amn->amn_rix = rix;
236 }
237 amn->amn_ticks = ticks;
238 } else
239 rix = amn->amn_rix;
240 return rix;
241}
242
243/*
244 * Update statistics with tx complete status. Ok is non-zero
245 * if the packet is known to be ACK'd. Retries has the number
246 * retransmissions (i.e. xmit attempts - 1).
247 */
248static void
249amrr_tx_complete(const struct ieee80211vap *vap,
250 const struct ieee80211_node *ni, int ok,
251 void *arg1, void *arg2 __unused)
252{
253 struct ieee80211_amrr_node *amn = ni->ni_rctls;
254 int retries = *(int *)arg1;
255
256 amn->amn_txcnt++;
257 if (ok)
258 amn->amn_success++;
259 amn->amn_retrycnt += retries;
260}
261
262/*
263 * Set tx count/retry statistics explicitly. Intended for
264 * drivers that poll the device for statistics maintained
265 * in the device.
266 */
267static void
268amrr_tx_update(const struct ieee80211vap *vap, const struct ieee80211_node *ni,
269 void *arg1, void *arg2, void *arg3)
270{
271 struct ieee80211_amrr_node *amn = ni->ni_rctls;
272 int txcnt = *(int *)arg1, success = *(int *)arg2, retrycnt = *(int *)arg3;
273
274 amn->amn_txcnt = txcnt;
275 amn->amn_success = success;
276 amn->amn_retrycnt = retrycnt;
277}
278
192static int
193amrr_sysctl_interval(SYSCTL_HANDLER_ARGS)
194{
279static int
280amrr_sysctl_interval(SYSCTL_HANDLER_ARGS)
281{
195 struct ieee80211_amrr *amrr = arg1;
282 struct ieee80211vap *vap = arg1;
283 struct ieee80211_amrr *amrr = vap->iv_rs;
196 int msecs = ticks_to_msecs(amrr->amrr_interval);
197 int error;
198
199 error = sysctl_handle_int(oidp, &msecs, 0, req);
200 if (error || !req->newptr)
201 return error;
284 int msecs = ticks_to_msecs(amrr->amrr_interval);
285 int error;
286
287 error = sysctl_handle_int(oidp, &msecs, 0, req);
288 if (error || !req->newptr)
289 return error;
202 ieee80211_amrr_setinterval(amrr, msecs);
290 amrr_setinterval(vap, msecs);
203 return 0;
204}
205
206static void
291 return 0;
292}
293
294static void
207amrr_sysctlattach(struct ieee80211_amrr *amrr,
295amrr_sysctlattach(struct ieee80211vap *vap,
208 struct sysctl_ctx_list *ctx, struct sysctl_oid *tree)
209{
296 struct sysctl_ctx_list *ctx, struct sysctl_oid *tree)
297{
298 struct ieee80211_amrr *amrr = vap->iv_rs;
210
211 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
299
300 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
212 "amrr_rate_interval", CTLTYPE_INT | CTLFLAG_RW, amrr,
301 "amrr_rate_interval", CTLTYPE_INT | CTLFLAG_RW, vap,
213 0, amrr_sysctl_interval, "I", "amrr operation interval (ms)");
214 /* XXX bounds check values */
215 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
216 "amrr_max_sucess_threshold", CTLFLAG_RW,
217 &amrr->amrr_max_success_threshold, 0, "");
218 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
219 "amrr_min_sucess_threshold", CTLFLAG_RW,
220 &amrr->amrr_min_success_threshold, 0, "");
221}
302 0, amrr_sysctl_interval, "I", "amrr operation interval (ms)");
303 /* XXX bounds check values */
304 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
305 "amrr_max_sucess_threshold", CTLFLAG_RW,
306 &amrr->amrr_max_success_threshold, 0, "");
307 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
308 "amrr_min_sucess_threshold", CTLFLAG_RW,
309 &amrr->amrr_min_success_threshold, 0, "");
310}
222
223/*
224 * Module glue.
225 */
226IEEE80211_RATE_MODULE(amrr, 1);