1 /* $OpenBSD: ieee80211_amrr.c,v 1.1 2006/06/17 19:07:19 damien Exp $ */
5 * Damien Bergamini <damien.bergamini@free.fr>
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.
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.
20 #include <sys/cdefs.h>
21 __FBSDID("$FreeBSD$");
24 * Naive implementation of the Adaptive Multi Rate Retry algorithm:
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
31 #include <sys/param.h>
32 #include <sys/kernel.h>
33 #include <sys/module.h>
34 #include <sys/socket.h>
35 #include <sys/sysctl.h>
38 #include <net/if_media.h>
41 #include <netinet/in.h>
42 #include <netinet/if_ether.h>
45 #include <net80211/ieee80211_var.h>
46 #include <net80211/ieee80211_amrr.h>
48 #define is_success(amn) \
49 ((amn)->amn_retrycnt < (amn)->amn_txcnt / 10)
50 #define is_failure(amn) \
51 ((amn)->amn_retrycnt > (amn)->amn_txcnt / 3)
52 #define is_enough(amn) \
53 ((amn)->amn_txcnt > 10)
54 #define is_min_rate(ni) \
55 ((ni)->ni_txrate == 0)
56 #define is_max_rate(ni) \
57 ((ni)->ni_txrate == (ni)->ni_rates.rs_nrates - 1)
58 #define increase_rate(ni) \
60 #define decrease_rate(ni) \
62 #define reset_cnt(amn) \
63 do { (amn)->amn_txcnt = (amn)->amn_retrycnt = 0; } while (0)
66 ieee80211_amrr_init(struct ieee80211_amrr *amrr,
67 struct ieee80211com *ic, int amin, int amax)
69 /* XXX bounds check? */
70 amrr->amrr_min_success_threshold = amin;
71 amrr->amrr_max_success_threshold = amax;
76 ieee80211_amrr_node_init(struct ieee80211_amrr *amrr,
77 struct ieee80211_amrr_node *amn)
80 amn->amn_recovery = 0;
81 amn->amn_txcnt = amn->amn_retrycnt = 0;
82 amn->amn_success_threshold = amrr->amrr_min_success_threshold;
86 * Update ni->ni_txrate.
89 ieee80211_amrr_choose(struct ieee80211_amrr *amrr, struct ieee80211_node *ni,
90 struct ieee80211_amrr_node *amn)
94 if (is_success(amn) && is_enough(amn)) {
96 if (amn->amn_success >= amn->amn_success_threshold &&
98 amn->amn_recovery = 1;
101 IEEE80211_DPRINTF(amrr->amrr_ic, IEEE80211_MSG_RATECTL,
102 "AMRR increasing rate %d (txcnt=%d "
104 ni->ni_rates.rs_rates[ni->ni_txrate] &
106 amn->amn_txcnt, amn->amn_retrycnt);
109 amn->amn_recovery = 0;
111 } else if (is_failure(amn)) {
112 amn->amn_success = 0;
113 if (!is_min_rate(ni)) {
114 if (amn->amn_recovery) {
115 amn->amn_success_threshold *= 2;
116 if (amn->amn_success_threshold >
117 amrr->amrr_max_success_threshold)
118 amn->amn_success_threshold =
119 amrr->amrr_max_success_threshold;
121 amn->amn_success_threshold =
122 amrr->amrr_min_success_threshold;
125 IEEE80211_DPRINTF(amrr->amrr_ic, IEEE80211_MSG_RATECTL,
126 "AMRR decreasing rate %d (txcnt=%d "
128 ni->ni_rates.rs_rates[ni->ni_txrate] &
130 amn->amn_txcnt, amn->amn_retrycnt);
133 amn->amn_recovery = 0;
136 if (is_enough(amn) || need_change)
144 amrr_modevent(module_t mod, int type, void *unused)
149 printf("wlan_amrr: <AMRR Transmit Rate Control Algorithm>\n");
157 static moduledata_t amrr_mod = {
162 DECLARE_MODULE(wlan_amrr, amrr_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
163 MODULE_VERSION(wlan_amrr, 1);
164 MODULE_DEPEND(wlan_amrr, wlan, 1, 1, 1);