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_BSS_STATS_HXX_
00023 # define WIFI_STATS_BSS_STATS_HXX_
00024
00025 # include <set>
00026
00027 # include <boost/foreach.hpp>
00028
00029 # include <wipal/wifi/stats/bss_stats.hh>
00030 # include <wipal/wifi/essid.hh>
00031 # include <wipal/tool/less.hh>
00032
00033 namespace wpl
00034 {
00035
00036 namespace wifi
00037 {
00038
00039 namespace stats
00040 {
00041
00042 inline
00043 bss_stats::bss_stats(const void*): beacon_count_ (0), ap_count_ (0)
00044 {
00045 }
00046
00047 template <class Frame>
00048 void
00049 bss_stats::account_beacon(const Frame& ,
00050 const addr* const& ap,
00051 const addr* const& bss,
00052 const optional_string& essid,
00053 const bool& ibss)
00054 {
00055 if (not ap or not bss)
00056 return;
00057
00058 single_bss_stats& b = bss_stats_[*bss];
00059 single_sta_stats& s = b.sta_stats_[*ap];
00060
00061 ++beacon_count_;
00062 ++b.total_;
00063 if (ibss)
00064 ++s.independent;
00065 else if (s.total == s.independent)
00066 ++ap_count_;
00067 ++s.total;
00068 if (essid)
00069 ++s.essids[*essid];
00070 }
00071
00072 inline
00073 std::ostream&
00074 bss_stats::print(std::ostream& o) const
00075 {
00076 typedef std::set<internal_stats::const_iterator,
00077 tool::less_using_second> sorted_type;
00078
00079 sorted_type sorted;
00080
00081 for (internal_stats::const_iterator i = bss_stats_.begin();
00082 i != bss_stats_.end();
00083 ++i)
00084 sorted.insert(i);
00085
00086 o << "begin BSS figures\n"
00087 << " total beacon count: " << beacon_count_ << '\n'
00088 << " distinct BSSIDs: " << bss_stats_.size() << '\n'
00089 << " distinct APs: " << ap_count_ << '\n';
00090
00091 BOOST_FOREACH(const internal_stats::const_iterator& i, sorted)
00092 {
00093 typedef single_bss_stats::sta_stats::value_type sta_stats;
00094 typedef single_sta_stats::essid_stats::value_type essid;
00095
00096 const single_bss_stats::sta_stats& s = i->second.sta_stats_;
00097
00098 o << '\n'
00099 << " begin BSS: " << i->first << '\n'
00100 << " beacon count: " << i->second.total_ << '\n'
00101 << " beacon ratio: "
00102 << (double (i->second.total_) / beacon_count_) << '\n'
00103 << " distinct beacon senders: " << s.size() << '\n';
00104
00105 assert(not s.empty());
00106 if (s.size() == 1 and s.begin()->first == i->first)
00107 {
00108
00109
00110
00111 const sta_stats& p = *s.begin();
00112 const unsigned& total = p.second.total;
00113 const unsigned& idpt = p.second.independent;
00114
00115 assert(total == i->second.total_);
00116
00117 o << " IBSS beacons: " << idpt << '\n'
00118 << " IBSS beacons ratio (this BSS): "
00119 << (double (idpt) / total) << '\n'
00120 << " begin ESSID list for " << p.first << '\n';
00121 BOOST_FOREACH(const essid& e, p.second.essids)
00122 o << " " << e.first.escape(65)
00123 << '\t' << e.second << '\n';
00124 o << " end ESSID list for " << p.first << '\n';
00125 }
00126 else
00127 {
00128
00129
00130
00131
00132 BOOST_FOREACH(const sta_stats& p, s)
00133 {
00134 const unsigned& total = p.second.total;
00135 const unsigned& idpt = p.second.independent;
00136
00137 o << '\n'
00138 << " begin beacon sender: (" << i->first << ") "
00139 << p.first << '\n'
00140 << " beacon count: " << total << '\n'
00141 << " beacon count ratio (total): "
00142 << (double (total) / beacon_count_) << '\n'
00143 << " beacon count ratio (this BSS): "
00144 << (double (total) / i->second.total_) << '\n'
00145 << " IBSS beacons: " << idpt << '\n'
00146 << " IBSS beacons ratio (this sender): "
00147 << (double (idpt) / total) << '\n'
00148 << " begin ESSID list for " << p.first << '\n';
00149 BOOST_FOREACH(const essid& e, p.second.essids)
00150 o << " " << e.first.escape(65)
00151 << '\t' << (double (e.second) / total)
00152 << '\t' << e.second << '\n';
00153 o << " end ESSID list for " << p.first << '\n'
00154 << " end beacon sender: (" << i->first << ") "
00155 << p.first << '\n';
00156 }
00157 }
00158 o << " end BSS: " << i->first << '\n';
00159 }
00160 return o << "end BSS figures" << std::endl;
00161 }
00162
00163 inline
00164 bss_stats::single_sta_stats::single_sta_stats(): total (0),
00165 independent (0)
00166 {
00167 }
00168
00169 inline
00170 bss_stats::single_bss_stats::single_bss_stats(): total_ (0)
00171 {
00172 }
00173
00174 inline
00175 bool
00176 bss_stats::
00177 single_bss_stats::operator < (const single_bss_stats& rhs) const
00178 {
00179 return total_ < rhs.total_;
00180 }
00181
00182 inline
00183 bool
00184 bss_stats::
00185 single_bss_stats::operator == (const single_bss_stats& rhs) const
00186 {
00187 return total_ == rhs.total_;
00188 }
00189
00190 }
00191
00192 }
00193
00194 }
00195
00196 #endif // ! WIFI_STATS_BSS_STATS_HXX_