00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef WIFI_FRAME_STATS_MISSED_ESTIMATIONS_HXX_
00023 # define WIFI_FRAME_STATS_MISSED_ESTIMATIONS_HXX_
00024
00025 # include <wipal/wifi/frame/stats/missed_estimations.hh>
00026 # include <wipal/wifi/frame/frame.hh>
00027 # include <wipal/wifi/frame/mgt.hh>
00028
00029 namespace wifi
00030 {
00031
00032 namespace frame
00033 {
00034
00035 namespace stats
00036 {
00037
00038
00039 inline
00040 missed_estimations::missed_estimations(const simple_counters& c):
00041 missed_beacons_ (0),
00042 missed_ (0),
00043 c_ (&c)
00044 {
00045 }
00046
00047 inline
00048 void
00049 missed_estimations::account_beacon(const tool::microseconds& tstamp,
00050 const addr& src)
00051 {
00052 beacons_map::iterator i = beacons_.find(src);
00053
00054 if (i == beacons_.end())
00055 {
00056 beacons_.insert(std::make_pair(src, tstamp));
00057 return;
00058 }
00059
00060 const tool::microseconds dt = tstamp - i->second;
00061
00062 if (dt < 0)
00063 std::cerr << "WARNING: Time-travelling beacon!" << std::endl;
00064 else
00065 {
00066 const unsigned delta = dt.get_div_by(beacon_interval);
00067
00068
00069
00070
00071
00072
00073 if (1 < delta)
00074 missed_beacons_ += delta - 1;
00075 }
00076
00077 i->second = tstamp;
00078 }
00079
00080 inline
00081 void
00082 missed_estimations::account_miss()
00083 {
00084 ++missed_;
00085 }
00086
00087 inline
00088 void
00089 missed_estimations::account_gap(unsigned gap_length)
00090 {
00091 missed_ += gap_length;
00092 }
00093
00094 inline
00095 std::ostream&
00096 missed_estimations::print(std::ostream& o) const
00097 {
00098 const unsigned stc = c_->subtype_count(type::management,
00099 mgt::subtype::beacon);
00100
00101 o << "estimated missed beacons: " << missed_beacons_ << '\n'
00102 << "estimated missed beacons ratio: "
00103 << (double (missed_beacons_) / (missed_beacons_ + stc)) << '\n'
00104 << "estimated missed frames: " << missed_ << '\n'
00105 << "estimated missed frames ratio: "
00106 << (double (missed_) / (missed_ + c_->total())) << std::endl;
00107 return o;
00108 }
00109
00110 }
00111
00112 }
00113
00114 }
00115
00116 #endif // ! WIFI_FRAME_STATS_MISSED_ESTIMATIONS_HXX_