root/net80211/ieee80211_amrr.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ieee80211_amrr_node_init
  2. ieee80211_amrr_choose

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

/* [<][>][^][v][top][bottom][index][help] */