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