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_SIMPLE_COUNTERS_HXX_
00023 # define WIFI_STATS_SIMPLE_COUNTERS_HXX_
00024
00025 # include <cstring>
00026 # include <cassert>
00027
00028 # include <wipal/wifi/stats/simple_counters.hh>
00029 # include <wipal/tool/si.hh>
00030 # include <wipal/wifi/frame.hh>
00031
00032 namespace wpl
00033 {
00034
00035 namespace wifi
00036 {
00037
00038 namespace stats
00039 {
00040
00041 inline
00042 simple_counters::simple_counters(const void*): total_ (0),
00043 size_ (0),
00044 ap_total_ (0),
00045 ap_size_ (0),
00046 retransmitted_ (0),
00047 expired_ (0),
00048 out_of_order_ (0),
00049 duplicate_ (0),
00050 gap_ (0),
00051 seq_anomaly_ (0)
00052 {
00053 memset(type_count_, 0, sizeof (type_count_));
00054 memset(type_size_, 0, sizeof (type_size_));
00055 memset(subtype_count_, 0, sizeof (subtype_count_));
00056 memset(subtype_size_, 0, sizeof (subtype_size_));
00057 }
00058
00059 inline
00060 void
00061 simple_counters::account_duplicate()
00062 {
00063 ++duplicate_;
00064 }
00065
00066 inline
00067 void
00068 simple_counters::account_expired()
00069 {
00070 ++expired_;
00071 }
00072
00073 template <class Frame>
00074 void
00075 simple_counters::
00076 account_frame(const Frame& ,
00077 const size_t& len80211,
00078 const type::frame_type& type,
00079 const unsigned& subtype,
00080 const bool& retx,
00081 const addr* const& ,
00082 const addr* const& ,
00083 const bool& from_ap)
00084 {
00085 assert(type < 4);
00086 assert(subtype < 16);
00087
00088 ++total_;
00089 size_ += len80211;
00090
00091 if (from_ap)
00092 {
00093 ++ap_total_;
00094 ap_size_ += len80211;
00095 }
00096
00097 if (retx)
00098 ++retransmitted_;
00099
00100 ++type_count_[type];
00101 type_size_[type] += len80211;
00102
00103 ++subtype_count_[type][subtype];
00104 subtype_size_[type][subtype] += len80211;
00105 }
00106
00107 inline
00108 void
00109 simple_counters::account_gap(const unsigned&)
00110 {
00111 ++gap_;
00112 }
00113
00114 inline
00115 void
00116 simple_counters::account_out_of_order()
00117 {
00118 ++out_of_order_;
00119 }
00120
00121 inline
00122 void
00123 simple_counters::account_seq_anomaly()
00124 {
00125 ++seq_anomaly_;
00126 }
00127
00128 inline
00129 std::ostream&
00130 simple_counters::print(std::ostream& o) const
00131 {
00132 o << "frame count: " << total_ << '\n'
00133 << "traffic size (B): " << size_ << '\n'
00134 << "traffic size (MiB): " << tool::MiB (tool::B (size_)) << '\n'
00135 << "AP frame count: " << ap_total_ << '\n'
00136 << "AP traffic size: " << tool::MiB (tool::B (ap_size_)) << '\n'
00137 << "AP traffic ratio:" << (double (ap_size_) / size_) << '\n'
00138 << "non-AP frame count: " << (total_ - ap_total_) << '\n'
00139 << "non-AP traffic size: "
00140 << tool::MiB (tool::B (size_ - ap_size_)) << '\n'
00141 << "non-AP traffic ratio:"
00142 << (double (size_ - ap_size_) / size_) << '\n'
00143 << "mean frame length: " << (double (size_) / total_) << '\n'
00144 << "retransmissions: " << retransmitted_ << '\n'
00145 << "retransmissions ratio: "
00146 << (double (retransmitted_) / total_) << '\n'
00147 << "frames from expired senders: " << expired_ << '\n'
00148 << "frames from expired senders ratio: "
00149 << (double (expired_) / total_) << '\n'
00150 << "out-of-order frames: " << out_of_order_ << '\n'
00151 << "out-of-order frames ratio: "
00152 << (double (out_of_order_) / total_) << '\n'
00153 << "duplicate frames w.r.t. sequence numbers: " << duplicate_ << '\n'
00154 << "duplicate frames w.r.t. sequence numbers ratio: "
00155 << (double (duplicate_) / total_) << '\n'
00156 << "sequence gap too large to make sense: " << seq_anomaly_ << '\n'
00157 << "sequence gap too large to make sense ratio (wrt. frame count): "
00158 << (double (seq_anomaly_) / total_) << '\n'
00159 << "sequence gap too large to make sense ratio (wrt. gap count): "
00160 << (double (seq_anomaly_) / (seq_anomaly_ + gap_)) << '\n'
00161 << '\n'
00162 << "begin frame types/subtypes\n";
00163 for (unsigned t = 0; t < 4; ++t)
00164 {
00165 const unsigned tc = type_count_[t];
00166 const uint64_t ts = type_size_[t];
00167
00168 if (not tc)
00169 continue;
00170
00171 o << '\n'
00172 << " begin type: " << type::names[t] << '\n'
00173 << " count: " << tc << '\n'
00174 << " size (B): " << ts << '\n'
00175 << " size (MiB): " << tool::MiB (tool::B (ts)) << '\n'
00176 << " mean frame length: " << (double (ts) / tc) << '\n'
00177 << " count ratio: " << (double (tc) / total_) << '\n'
00178 << " traffic ratio: " << (double (ts) / size_) << '\n';
00179 for (unsigned st = 0; st < 16; ++st)
00180 {
00181 const unsigned stc = subtype_count_[t][st];
00182 const uint64_t sts = subtype_size_[t][st];
00183
00184 if (not stc)
00185 continue;
00186
00187 o << '\n'
00188 << " begin subtype: "
00189 << type::names[t] << '/'
00190 << subtype::names[t][st] << '\n'
00191 << " count: " << stc << '\n'
00192 << " size (B): " << sts << '\n'
00193 << " size (MiB): " << tool::MiB (tool::B (sts)) << '\n'
00194 << " mean frame length: " << (double (sts) / stc) << '\n'
00195 << " count ratio (overall): "
00196 << (double (stc) / total_) << '\n'
00197 << " count ratio (this type): "
00198 << (double (stc) / tc) << '\n'
00199 << " traffic ratio (overall): "
00200 << (double (sts) / size_) << '\n'
00201 << " traffic ratio (this type): "
00202 << (double (sts) / ts) << '\n'
00203 << " end subtype: " << type::names[t] << '/'
00204 << subtype::names[t][st] << '\n';
00205 }
00206 o << "\n end type: " << type::names[t] << '\n';
00207 }
00208 o << "\nend frame types/subtypes" << std::endl;
00209 return o;
00210 }
00211
00212 inline
00213 unsigned
00214 simple_counters::total() const
00215 {
00216 return total_;
00217 }
00218
00219 inline
00220 unsigned
00221 simple_counters::type_count(unsigned type) const
00222 {
00223 return type_count_[type];
00224 }
00225
00226 inline
00227 unsigned
00228 simple_counters::subtype_count(unsigned type, unsigned subtype) const
00229 {
00230 return subtype_count_[type][subtype];
00231 }
00232
00233 }
00234
00235 }
00236
00237 }
00238
00239 #endif // ! WIFI_STATS_SIMPLE_COUNTERS_HXX_