1 /* $OpenBSD: ieee80211_amrr.c,v 1.1 2006/06/17 19:07:19 damien Exp $ */
2 /* $NetBSD: ieee80211_amrr.c,v 1.1 2006/10/31 21:53:41 joerg Exp $ */
3
4 /*-
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/param.h>
22 #include <sys/kernel.h>
23 #include <sys/socket.h>
24 #include <sys/sysctl.h>
25
26 #include <net/if.h>
27 #include <net/if_media.h>
28
29 #ifdef INET
30 #include <netinet/in.h>
31 #include <netinet/if_ether.h>
32 #endif
33
34 #include <net80211/ieee80211.h>
35 #include <net80211/ieee80211_var.h>
36 #include <net80211/ieee80211_amrr.h>
37
38 #define is_success(amn) \
39 ((amn)->amn_retrycnt < (amn)->amn_txcnt / 10)
40 #define is_failure(amn) \
41 ((amn)->amn_retrycnt > (amn)->amn_txcnt / 3)
42 #define is_enough(amn) \
43 ((amn)->amn_txcnt > 10)
44 #define is_min_rate(ni) \
45 ((ni)->ni_txrate == 0)
46 #define is_max_rate(ni) \
47 ((ni)->ni_txrate == (ni)->ni_rates.rs_nrates - 1)
48 #define increase_rate(ni) \
49 ((ni)->ni_txrate++)
50 #define decrease_rate(ni) \
51 ((ni)->ni_txrate--)
52 #define reset_cnt(amn) \
53 do { (amn)->amn_txcnt = (amn)->amn_retrycnt = 0; } while (0)
54
55 void
56 ieee80211_amrr_node_init(struct ieee80211_amrr *amrr,
57 struct ieee80211_amrr_node *amn)
58 {
59 amn->amn_success = 0;
60 amn->amn_recovery = 0;
61 amn->amn_txcnt = amn->amn_retrycnt = 0;
62 amn->amn_success_threshold = amrr->amrr_min_success_threshold;
63 }
64
65 /*
66 * Update ni->ni_txrate.
67 */
68 void
69 ieee80211_amrr_choose(struct ieee80211_amrr *amrr, struct ieee80211_node *ni,
70 struct ieee80211_amrr_node *amn)
71 {
72 int need_change = 0;
73
74 if (is_success(amn) && is_enough(amn)) {
75 amn->amn_success++;
76 if (amn->amn_success >= amn->amn_success_threshold &&
77 !is_max_rate(ni)) {
78 amn->amn_recovery = 1;
79 amn->amn_success = 0;
80 increase_rate(ni);
81 IEEE80211_DPRINTF(ni->ni_ic, IEEE80211_MSG_DEBUG,
82 "AMRR increasing rate %d (txcnt=%d retrycnt=%d)\n",
83 ni->ni_rates.rs_rates[ni->ni_txrate] &
84 IEEE80211_RATE_VAL,
85 amn->amn_txcnt, amn->amn_retrycnt);
86 need_change = 1;
87 } else {
88 amn->amn_recovery = 0;
89 }
90 } else if (is_failure(amn)) {
91 amn->amn_success = 0;
92 if (!is_min_rate(ni)) {
93 if (amn->amn_recovery) {
94 amn->amn_success_threshold *= 2;
95 if (amn->amn_success_threshold >
96 amrr->amrr_max_success_threshold)
97 amn->amn_success_threshold =
98 amrr->amrr_max_success_threshold;
99 } else {
100 amn->amn_success_threshold =
101 amrr->amrr_min_success_threshold;
102 }
103 decrease_rate(ni);
104 IEEE80211_DPRINTF(ni->ni_ic, IEEE80211_MSG_DEBUG,
105 "AMRR decreasing rate %d (txcnt=%d retrycnt=%d)\n",
106 ni->ni_rates.rs_rates[ni->ni_txrate] &
107 IEEE80211_RATE_VAL,
108 amn->amn_txcnt, amn->amn_retrycnt);
109 need_change = 1;
110 }
111 amn->amn_recovery = 0;
112 }
113
114 if (is_enough(amn) || need_change)
115 reset_cnt(amn);
116 }
Cache object: e2f78e6e6b960a540dfbfa341deddff1
|