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_MISSED_ESTIMATIONS_HXX_
00023 # define WIFI_STATS_MISSED_ESTIMATIONS_HXX_
00024
00025 # include <wipal/wifi/stats/missed_estimations.hh>
00026 # include <wipal/wifi/frame.hh>
00027 # include <wipal/wifi/mgt.hh>
00028
00029 namespace wpl
00030 {
00031
00032 namespace wifi
00033 {
00034
00035 namespace stats
00036 {
00037
00038 template <class H, class T>
00039 missed_estimations::missed_estimations(const module_list<H, T>* ml):
00040 missed_beacons_ (0),
00041 missed_ (0),
00042 sc_ (&ml->template get<simple_counters>())
00043 {
00044 }
00045
00046 template <class Frame>
00047 void
00048 missed_estimations::
00049 account_beacon(const Frame& frame,
00050 const addr* const& ap,
00051 const addr* const& ,
00052 const optional_string& ,
00053 const bool& )
00054 {
00055 if (not ap)
00056 return;
00057
00058 const tool::microseconds& stamp = frame.microseconds();
00059 beacons_map::iterator i = beacons_.find(*ap);
00060
00061 if (i == beacons_.end())
00062 {
00063 beacons_.insert(std::make_pair(*ap, stamp));
00064 return;
00065 }
00066
00067 const tool::microseconds dt = stamp - i->second;
00068
00069 if (dt < 0)
00070 std::cerr << frame << ": Time-travelling beacon!" << std::endl;
00071 else
00072 {
00073 const unsigned delta = dt.get_div_by(beacon_interval);
00074
00075
00076
00077
00078
00079
00080 if (1 < delta)
00081 missed_beacons_ += delta - 1;
00082 }
00083
00084 i->second = stamp;
00085 }
00086
00087 inline
00088 void
00089 missed_estimations::account_gap(const unsigned& gap_length)
00090 {
00091 missed_ += gap_length;
00092 }
00093
00094 inline
00095 void
00096 missed_estimations::account_miss()
00097 {
00098 ++missed_;
00099 }
00100
00101 inline
00102 std::ostream&
00103 missed_estimations::print(std::ostream& o) const
00104 {
00105 const unsigned stc = sc_->subtype_count(type::management,
00106 mgt::subtype::beacon);
00107
00108 o << "estimated missed beacons: " << missed_beacons_ << '\n'
00109 << "estimated missed beacons ratio: "
00110 << (double (missed_beacons_) / (missed_beacons_ + stc)) << '\n'
00111 << "estimated missed frames: " << missed_ << '\n'
00112 << "estimated missed frames ratio: "
00113 << (double (missed_) / (missed_ + sc_->total())) << std::endl;
00114 return o;
00115 }
00116
00117 }
00118
00119 }
00120
00121 }
00122
00123 #endif // ! WIFI_STATS_MISSED_ESTIMATIONS_HXX_