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_GROWTH_HXX_
00023 # define WIFI_STATS_GROWTH_HXX_
00024
00025 # include <wipal/wifi/stats/growth.hh>
00026
00027 namespace wpl
00028 {
00029
00030 namespace wifi
00031 {
00032
00033 namespace stats
00034 {
00035
00036
00037
00038
00039
00040 template <class T, unsigned EL>
00041 void
00042 growth<T, EL>::restart()
00043 {
00044 tracker_.restart();
00045 elements_.clear();
00046 current_elements_.clear();
00047 }
00048
00049 template <class T, unsigned EL>
00050 void
00051 growth<T, EL>::update(const tool::microseconds& timestamp)
00052 {
00053 if (tracker_.update(timestamp))
00054 current_elements_.clear();
00055 }
00056
00057 template <class T, unsigned EL>
00058 void
00059 growth<T, EL>::update(const T& elt)
00060 {
00061 epoch_data& d = tracker_.current();
00062
00063 if (current_elements_.insert(elt).second)
00064 ++d.current_count;
00065
00066 if (elements_.insert(elt).second)
00067 ++d.total_count;
00068 }
00069
00070 template <class T, unsigned EL>
00071 std::ostream&
00072 growth<T, EL>::print(std::ostream& o) const
00073 {
00074 unsigned total = 0;
00075
00076 BOOST_FOREACH(const epoch_data& e, tracker_.epochs())
00077 {
00078 total += e.total_count;
00079 o << '\t' << e.total_count
00080 << '\t' << total
00081 << '\t' << e.current_count << '\n';
00082 }
00083 return o << std::flush;
00084 }
00085
00086
00087
00088
00089
00090 template <class T, unsigned EL>
00091 growth<T, EL>::epoch_data::epoch_data(): total_count (0),
00092 current_count (0)
00093 {
00094 }
00095
00096
00097
00098
00099
00100 template <unsigned E, bool Tx>
00101 addr_growth<E, Tx>::addr_growth(const void*): ignore_ (true)
00102 {
00103 }
00104
00105 template <unsigned E, bool Tx>
00106 void
00107 addr_growth<E, Tx>::account_addr(unsigned i, const addr& a)
00108 {
00109 if (ignore_ or (Tx and i != 2))
00110 return;
00111
00112 growth_.update(a);
00113 }
00114
00115 template <unsigned E, bool Tx>
00116 template <class Frame>
00117 void
00118 addr_growth<E, Tx>::account_frame(const Frame& frame,
00119 const size_t& ,
00120 const type::frame_type& ,
00121 const unsigned& ,
00122 const bool& ,
00123 const addr* const& ,
00124 const addr* const& ,
00125 const bool& )
00126 {
00127 ignore_ = false;
00128 try
00129 {
00130 growth_.update(frame.microseconds());
00131 }
00132 catch (const non_increasing_timestamp&)
00133 {
00134 std::cerr << frame << ": [addr_growth] Decreasing timestamp, "
00135 << "ignoring." << std::endl;
00136 ignore_ = true;
00137 }
00138 }
00139
00140 template <unsigned E, bool Tx>
00141 std::ostream&
00142 addr_growth<E, Tx>::print(std::ostream& os) const
00143 {
00144 return os << "begin MAC addr. growth\n"
00145 << growth_
00146 << "end MAC addr. growth\n";
00147 }
00148
00149 template <unsigned E, bool Tx>
00150 void
00151 addr_growth<E, Tx>::restart()
00152 {
00153 growth_.restart();
00154 }
00155
00156
00157
00158
00159
00160 template <unsigned E>
00161 beacon_items_growth<E>::beacon_items_growth(const void*): ignore_ (true)
00162 {
00163 }
00164
00165 template <unsigned E>
00166 template <class Frame>
00167 void
00168 beacon_items_growth<E>::account_beacon(const Frame& ,
00169 const addr* const& ap,
00170 const addr* const& bss,
00171 const optional_string& ssid,
00172 const bool& ibss)
00173 {
00174 if (ignore_)
00175 return;
00176
00177 if (ap)
00178 ap_.update(*ap);
00179 if (bss)
00180 {
00181 if (ibss)
00182 ibssid_.update(*bss);
00183 else
00184 bssid_.update(*bss);
00185 }
00186 if (ssid)
00187 ssid_.update(*ssid);
00188 }
00189
00190 template <unsigned E>
00191 template <class Frame>
00192 void
00193 beacon_items_growth<E>::account_frame(const Frame& frame,
00194 const size_t& ,
00195 const type::frame_type& ,
00196 const unsigned& ,
00197 const bool& ,
00198 const addr* const& ,
00199 const addr* const& ,
00200 const bool& )
00201 {
00202 const tool::microseconds& stamp = frame.microseconds();
00203
00204 ignore_ = false;
00205 try
00206 {
00207 ap_.update(stamp);
00208 bssid_.update(stamp);
00209 ibssid_.update(stamp);
00210 ssid_.update(stamp);
00211 }
00212 catch (const non_increasing_timestamp&)
00213 {
00214 std::cerr << frame << ": [beacon_items_growth] Decreasing "
00215 << "timestamp, ignoring." << std::endl;
00216 ignore_ = true;
00217 }
00218 }
00219
00220 template <unsigned E>
00221 std::ostream&
00222 beacon_items_growth<E>::print(std::ostream& os) const
00223 {
00224 return os << "begin AP growth\n"
00225 << ap_
00226 << "end AP growth\n"
00227 << '\n'
00228 << "begin BSSID growth\n"
00229 << bssid_
00230 << "end BSSID growth\n"
00231 << '\n'
00232 << "begin IBSSID growth\n"
00233 << ibssid_
00234 << "end IBSSID growth\n"
00235 << '\n'
00236 << "begin SSID growth\n"
00237 << ssid_
00238 << "end SSID growth\n";
00239 }
00240
00241 template <unsigned E>
00242 void
00243 beacon_items_growth<E>::restart()
00244 {
00245 ap_.restart();
00246 bssid_.restart();
00247 ibssid_.restart();
00248 ssid_.restart();
00249 ignore_ = true;
00250 }
00251
00252 }
00253
00254 }
00255
00256 }
00257
00258 #endif // ! WIFI_STATS_GROWTH_HXX_