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