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_ACTIVITY_HXX_
00023 # define WIFI_STATS_ACTIVITY_HXX_
00024
00025 # include <cstring>
00026 # include <cassert>
00027
00028 # include <boost/foreach.hpp>
00029
00030 # include <wipal/wifi/stats/activity.hh>
00031
00032 namespace wpl
00033 {
00034
00035 namespace wifi
00036 {
00037
00038 namespace stats
00039 {
00040
00041 inline
00042 activity::activity(const void*)
00043 {
00044 }
00045
00046 template <class Frame>
00047 void
00048 activity::account_frame(const Frame& frame,
00049 const size_t& len80211,
00050 const type::frame_type& type,
00051 const unsigned& subtype,
00052 const bool& ,
00053 const addr* const& ,
00054 const addr* const& ,
00055 const bool& from_ap)
00056 {
00057 try
00058 {
00059 const int k = tracker_.update(frame.microseconds());
00060
00061 if (k > 1)
00062 std::cerr << frame << ": [activity] warning: was inactive for "
00063 << (k * epoch_length / 1000000) << " seconds (i.e. "
00064 << k << " epochs)." << std::endl;
00065 }
00066 catch (const non_increasing_timestamp&)
00067 {
00068 std::cerr << frame << ": [activity] Decreasing timestamp, "
00069 << "ignoring." << std::endl;
00070 return;
00071 }
00072
00073 epoch& e = tracker_.current();
00074
00075 ++e.count;
00076 ++e.type_count[type];
00077 ++e.subtype_count[type][subtype];
00078 e.size += len80211;
00079 e.type_size[type] += len80211;
00080 e.subtype_size[type][subtype] += len80211;
00081 if (from_ap)
00082 {
00083 ++e.ap_count;
00084 e.ap_size += len80211;
00085 }
00086 }
00087
00088 inline
00089 std::ostream&
00090 activity::print(std::ostream& o) const
00091 {
00092 o << "begin activity\n";
00093
00094 BOOST_FOREACH(const epoch& e, tracker_.epochs())
00095 o << " "
00096 << e.count << ' '
00097 << e.size << ' '
00098 << e.type_size[type::management] << ' '
00099 << e.type_size[type::data] << ' '
00100 << e.ap_size << '\n';
00101 return o << "end activity" << std::endl;
00102 }
00103
00104 inline
00105 void
00106 activity::restart()
00107 {
00108 tracker_.restart();
00109 }
00110
00111 inline
00112 activity::epoch::epoch(): count (0), ap_count (0), size (0), ap_size (0)
00113 {
00114 memset(type_count, 0, sizeof (type_count));
00115 memset(type_size, 0, sizeof (type_size));
00116 memset(subtype_count, 0, sizeof (subtype_count));
00117 memset(subtype_size, 0, sizeof (subtype_size));
00118 }
00119
00120 }
00121
00122 }
00123
00124 }
00125
00126 #endif // ! WIFI_STATS_ACTIVITY_HXX_