Home | History | Annotate | Line # | Download | only in net80211
ieee80211_amrr.c revision 1.1.2.2
      1  1.1.2.2  ad /*	$OpenBSD: ieee80211_amrr.c,v 1.1 2006/06/17 19:07:19 damien Exp $	*/
      2  1.1.2.2  ad /*	$NetBSD: ieee80211_amrr.c,v 1.1.2.2 2006/11/18 21:39:32 ad Exp $	*/
      3  1.1.2.2  ad 
      4  1.1.2.2  ad /*-
      5  1.1.2.2  ad  * Copyright (c) 2006
      6  1.1.2.2  ad  *	Damien Bergamini <damien.bergamini (at) free.fr>
      7  1.1.2.2  ad  *
      8  1.1.2.2  ad  * Permission to use, copy, modify, and distribute this software for any
      9  1.1.2.2  ad  * purpose with or without fee is hereby granted, provided that the above
     10  1.1.2.2  ad  * copyright notice and this permission notice appear in all copies.
     11  1.1.2.2  ad  *
     12  1.1.2.2  ad  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     13  1.1.2.2  ad  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     14  1.1.2.2  ad  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     15  1.1.2.2  ad  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     16  1.1.2.2  ad  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     17  1.1.2.2  ad  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     18  1.1.2.2  ad  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     19  1.1.2.2  ad  */
     20  1.1.2.2  ad 
     21  1.1.2.2  ad #include <sys/param.h>
     22  1.1.2.2  ad #include <sys/kernel.h>
     23  1.1.2.2  ad #include <sys/socket.h>
     24  1.1.2.2  ad #include <sys/sysctl.h>
     25  1.1.2.2  ad 
     26  1.1.2.2  ad #include <net/if.h>
     27  1.1.2.2  ad #include <net/if_media.h>
     28  1.1.2.2  ad 
     29  1.1.2.2  ad #ifdef INET
     30  1.1.2.2  ad #include <netinet/in.h>
     31  1.1.2.2  ad #include <netinet/if_ether.h>
     32  1.1.2.2  ad #endif
     33  1.1.2.2  ad 
     34  1.1.2.2  ad #include <net80211/ieee80211.h>
     35  1.1.2.2  ad #include <net80211/ieee80211_var.h>
     36  1.1.2.2  ad #include <net80211/ieee80211_amrr.h>
     37  1.1.2.2  ad 
     38  1.1.2.2  ad #define is_success(amn)	\
     39  1.1.2.2  ad 	((amn)->amn_retrycnt < (amn)->amn_txcnt / 10)
     40  1.1.2.2  ad #define is_failure(amn)	\
     41  1.1.2.2  ad 	((amn)->amn_retrycnt > (amn)->amn_txcnt / 3)
     42  1.1.2.2  ad #define is_enough(amn)		\
     43  1.1.2.2  ad 	((amn)->amn_txcnt > 10)
     44  1.1.2.2  ad #define is_min_rate(ni)		\
     45  1.1.2.2  ad 	((ni)->ni_txrate == 0)
     46  1.1.2.2  ad #define is_max_rate(ni)		\
     47  1.1.2.2  ad 	((ni)->ni_txrate == (ni)->ni_rates.rs_nrates - 1)
     48  1.1.2.2  ad #define increase_rate(ni)	\
     49  1.1.2.2  ad 	((ni)->ni_txrate++)
     50  1.1.2.2  ad #define decrease_rate(ni)	\
     51  1.1.2.2  ad 	((ni)->ni_txrate--)
     52  1.1.2.2  ad #define reset_cnt(amn)		\
     53  1.1.2.2  ad 	do { (amn)->amn_txcnt = (amn)->amn_retrycnt = 0; } while (0)
     54  1.1.2.2  ad 
     55  1.1.2.2  ad void
     56  1.1.2.2  ad ieee80211_amrr_node_init(struct ieee80211_amrr *amrr,
     57  1.1.2.2  ad     struct ieee80211_amrr_node *amn)
     58  1.1.2.2  ad {
     59  1.1.2.2  ad 	amn->amn_success = 0;
     60  1.1.2.2  ad 	amn->amn_recovery = 0;
     61  1.1.2.2  ad 	amn->amn_txcnt = amn->amn_retrycnt = 0;
     62  1.1.2.2  ad 	amn->amn_success_threshold = amrr->amrr_min_success_threshold;
     63  1.1.2.2  ad }
     64  1.1.2.2  ad 
     65  1.1.2.2  ad /*
     66  1.1.2.2  ad  * Update ni->ni_txrate.
     67  1.1.2.2  ad  */
     68  1.1.2.2  ad void
     69  1.1.2.2  ad ieee80211_amrr_choose(struct ieee80211_amrr *amrr, struct ieee80211_node *ni,
     70  1.1.2.2  ad     struct ieee80211_amrr_node *amn)
     71  1.1.2.2  ad {
     72  1.1.2.2  ad 	int need_change = 0;
     73  1.1.2.2  ad 
     74  1.1.2.2  ad 	if (is_success(amn) && is_enough(amn)) {
     75  1.1.2.2  ad 		amn->amn_success++;
     76  1.1.2.2  ad 		if (amn->amn_success >= amn->amn_success_threshold &&
     77  1.1.2.2  ad 		    !is_max_rate(ni)) {
     78  1.1.2.2  ad 			amn->amn_recovery = 1;
     79  1.1.2.2  ad 			amn->amn_success = 0;
     80  1.1.2.2  ad 			increase_rate(ni);
     81  1.1.2.2  ad 			IEEE80211_DPRINTF(ni->ni_ic, IEEE80211_MSG_DEBUG,
     82  1.1.2.2  ad 			    "AMRR increasing rate %d (txcnt=%d retrycnt=%d)\n",
     83  1.1.2.2  ad 			    ni->ni_rates.rs_rates[ni->ni_txrate] &
     84  1.1.2.2  ad 				IEEE80211_RATE_VAL,
     85  1.1.2.2  ad 			    amn->amn_txcnt, amn->amn_retrycnt);
     86  1.1.2.2  ad 			need_change = 1;
     87  1.1.2.2  ad 		} else {
     88  1.1.2.2  ad 			amn->amn_recovery = 0;
     89  1.1.2.2  ad 		}
     90  1.1.2.2  ad 	} else if (is_failure(amn)) {
     91  1.1.2.2  ad 		amn->amn_success = 0;
     92  1.1.2.2  ad 		if (!is_min_rate(ni)) {
     93  1.1.2.2  ad 			if (amn->amn_recovery) {
     94  1.1.2.2  ad 				amn->amn_success_threshold *= 2;
     95  1.1.2.2  ad 				if (amn->amn_success_threshold >
     96  1.1.2.2  ad 				    amrr->amrr_max_success_threshold)
     97  1.1.2.2  ad 					amn->amn_success_threshold =
     98  1.1.2.2  ad 					    amrr->amrr_max_success_threshold;
     99  1.1.2.2  ad 			} else {
    100  1.1.2.2  ad 				amn->amn_success_threshold =
    101  1.1.2.2  ad 				    amrr->amrr_min_success_threshold;
    102  1.1.2.2  ad 			}
    103  1.1.2.2  ad 			decrease_rate(ni);
    104  1.1.2.2  ad 			IEEE80211_DPRINTF(ni->ni_ic, IEEE80211_MSG_DEBUG,
    105  1.1.2.2  ad 			    "AMRR decreasing rate %d (txcnt=%d retrycnt=%d)\n",
    106  1.1.2.2  ad 			    ni->ni_rates.rs_rates[ni->ni_txrate] &
    107  1.1.2.2  ad 				IEEE80211_RATE_VAL,
    108  1.1.2.2  ad 			    amn->amn_txcnt, amn->amn_retrycnt);
    109  1.1.2.2  ad 			need_change = 1;
    110  1.1.2.2  ad 		}
    111  1.1.2.2  ad 		amn->amn_recovery = 0;
    112  1.1.2.2  ad 	}
    113  1.1.2.2  ad 
    114  1.1.2.2  ad 	if (is_enough(amn) || need_change)
    115  1.1.2.2  ad 		reset_cnt(amn);
    116  1.1.2.2  ad }
    117