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_HH_
00023 # define WIFI_STATS_HH_
00024
00025 # include <ostream>
00026 # include <vector>
00027 # include <map>
00028
00029 # include <boost/date_time/posix_time/posix_time.hpp>
00030
00031 # include <wipal/phy/prism_header.hh>
00032 # include <wipal/wifi/frame.hh>
00033 # include <wipal/wifi/addr.hh>
00034 # include <wipal/pcap/stream.hh>
00035
00036 namespace stats
00037 {
00038
00039
00040
00041
00042
00043 struct distribution
00044 {
00045 distribution(float min, float max, float granularity);
00046
00047 void insert(float);
00048 std::ostream& dump(std::ostream&) const;
00049
00050 private:
00051 float min_;
00052 float max_;
00053 float gran_;
00054 std::vector<unsigned> dist_;
00055 unsigned total_;
00056 };
00057
00058 std::ostream&
00059 operator << (std::ostream&, const distribution&);
00060
00061
00062
00063
00064
00065 struct timed_events
00066 {
00067 typedef boost::posix_time::ptime ptime;
00068 typedef boost::posix_time::time_duration time_duration;
00069
00070 time_duration insert(const ptime&);
00071 const std::vector<ptime>& evs() const;
00072
00073 private:
00074 std::vector<ptime> evs_;
00075 };
00076
00077 template <class C>
00078 std::vector<boost::posix_time::time_duration>
00079 its(const C&);
00080
00081 template <class C>
00082 boost::posix_time::time_duration
00083 mean(const C&);
00084
00085 template <class C>
00086 boost::posix_time::time_duration
00087 stddev(const C& its,
00088 const boost::posix_time::time_duration* mean = 0);
00089
00090 template <class C>
00091 boost::posix_time::time_duration
00092 median(const std::vector<boost::posix_time::time_duration>&);
00093
00094 template <class C>
00095 distribution
00096 make_distribution(float min,
00097 float max,
00098 float granularity,
00099 const C& container);
00100
00101
00102
00103
00104
00105 struct addr_state
00106 {
00107 typedef boost::posix_time::ptime ptime;
00108
00109 struct presp_attr
00110 {
00111 presp_attr();
00112
00113 ptime arrival;
00114 ptime ack_expected_arrival;
00115 ptime ack_arrival;
00116 unsigned retries;
00117 unsigned acks;
00118 };
00119
00120 typedef std::map<wpl::wifi::addr, presp_attr> preq_answer_set;
00121 typedef std::vector<preq_answer_set> pr_answers_t;
00122
00123 addr_state();
00124
00125 timed_events pr_stats[3];
00126 pr_answers_t pr_answers;
00127 presp_attr* last_presp;
00128 unsigned heard_as_tmiter;
00129 unsigned mentioned_as_ap;
00130 };
00131
00132 typedef std::map<wpl::wifi::addr, addr_state> addr_state_map;
00133
00134
00135
00136
00137
00138 struct probe_requests
00139 {
00140 typedef boost::posix_time::ptime ptime;
00141
00142 probe_requests(addr_state_map&);
00143
00144 void update(const wpl::wifi::mgt::header *frame,
00145 const ptime& toa);
00146
00147 std::ostream& dump(std::ostream& ,
00148 unsigned successful_frames,
00149 unsigned distinct_transmitters,
00150 const ptime& first) const;
00151
00152 protected:
00153 std::ostream& dump_header(std::ostream& ,
00154 unsigned successful_frames)
00155 const;
00156 std::ostream& dump_footer(std::ostream&) const;
00157 std::ostream& dump_addr_stats(std::ostream& ,
00158 unsigned index,
00159 unsigned distinct_transmitters)
00160 const;
00161 std::ostream& dump_pr_events(std::ostream& ,
00162 unsigned index,
00163 const ptime& ref) const;
00164 static
00165 std::ostream& dump_it_dist(std::ostream&, const distribution&);
00166
00167 private:
00168 unsigned count;
00169 addr_state_map* addrs;
00170 distribution it_dist;
00171
00172
00173 static const float unit;
00174 static const float min;
00175 static const float max;
00176 static const float gran;
00177 static const unsigned tic;
00178 };
00179
00180
00181
00182
00183
00184 struct frames
00185 {
00186 frames();
00187
00188 std::ostream& dump(std::ostream&) const;
00189
00190 void update(const wpl::pkt::metadata& pcap_header,
00191 const void* ieee80211_frame);
00192
00193 void update(const wpl::pkt::metadata& pcap_header,
00194 const wpl::prism::header* prism_header);
00195
00196 private:
00197 typedef boost::posix_time::ptime ptime;
00198
00199 std::ostream& dump_pr_answers(std::ostream&,
00200 const addr_state_map::const_iterator&)
00201 const;
00202 void dump_all_pr_answers(const std::string& prefix,
00203 const std::string& suffix) const;
00204
00205 ptime update_counters(const wpl::pkt::metadata&);
00206
00207
00208 unsigned frame_count;
00209 unsigned total_len;
00210
00211
00212 unsigned total_caplen;
00213 unsigned phy_error_count;
00214
00215
00216
00217 probe_requests pr;
00218 addr_state_map addrs;
00219 ptime first;
00220 ptime last;
00221 };
00222
00223 std::ostream&
00224 operator << (std::ostream&, const frames&);
00225
00226 }
00227
00228 # include "wifi_stats.hxx"
00229
00230 #endif // ! WIFI_STATS_HH_