00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef WIFI_STATS_GAPS_HXX_
00023 # define WIFI_STATS_GAPS_HXX_
00024
00025 # include <cstring>
00026 # include <numeric>
00027
00028 # include <wipal/wifi/stats/gaps.hh>
00029
00030 namespace wpl
00031 {
00032
00033 namespace wifi
00034 {
00035
00036 namespace stats
00037 {
00038
00039 inline
00040 gaps::gaps(const void*): last_ (0)
00041 {
00042 memset(gaps_, 0, sizeof (gaps_));
00043 memset(misses_, 0, sizeof (misses_));
00044 }
00045
00046 template <class Frame>
00047 void
00048 gaps::account_frame(const Frame& frame,
00049 const size_t& ,
00050 const type::frame_type& ty,
00051 const unsigned& ,
00052 const bool& ,
00053 const addr* const& rx,
00054 const addr* const& tx,
00055 const bool& )
00056 {
00057 if (last_)
00058 *last_ = 0;
00059 last_ = tx and ty != type::control? &inter_frames_[*tx]: 0;
00060
00061 if (tx)
00062 inter_frames_[*tx]++;
00063 if (rx and (not tx or *tx != *rx))
00064 inter_frames_[*rx]++;
00065 }
00066
00067 inline
00068 void
00069 gaps::account_gap(const unsigned& gap_length)
00070 {
00071 assert(last_);
00072
00073 const unsigned type = *last_ > 1? obstructed : clear;
00074
00075 ++gaps_[type];
00076 misses_[type] += gap_length;
00077 }
00078
00079 inline
00080 std::ostream&
00081 gaps::print(std::ostream& o) const
00082 {
00083 const double gap_total =
00084 std::accumulate(gaps_, gaps_ + sizeof (gaps_) / sizeof (*gaps_), 0);
00085
00086 const double miss_total =
00087 std::accumulate(misses_,
00088 misses_ + sizeof (misses_) / sizeof (*misses_), 0);
00089
00090 return
00091 o << "clear gaps: " << gaps_[clear]
00092 << "\nclear gaps ratio: " << (gaps_[clear] / gap_total)
00093 << "\nobstructed gaps: " << gaps_[obstructed]
00094 << "\nobstructed gaps ratio: " << (gaps_[obstructed] / gap_total)
00095 << "\nclear miss count: " << misses_[clear]
00096 << "\nclear miss count ratio: " << (misses_[clear] / miss_total)
00097 << "\nobstructed miss count: " << misses_[obstructed]
00098 << "\nobstructed miss count ratio: "
00099 << (misses_[obstructed] / miss_total) << std::endl;
00100 }
00101
00102 }
00103
00104 }
00105
00106 }
00107
00108 #endif // ! WIFI_STATS_GAPS_HXX_