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_STATS_HH_
00023 # define WIFI_STATS_STATS_HH_
00024
00025 extern "C"
00026 {
00027 # include <stdint.h>
00028 }
00029
00030 # include <map>
00031 # include <utility>
00032
00033 # include <boost/tuple/tuple.hpp>
00034 # include <boost/tuple/tuple_comparison.hpp>
00035 # include <boost/optional.hpp>
00036 # include <boost/preprocessor/tuple/elem.hpp>
00037 # include <boost/preprocessor/seq/fold_left.hpp>
00038 # include <boost/preprocessor/list/enum.hpp>
00039
00040 # include <wipal/wifi/stats/delimiter_frames.hh>
00041 # include <wipal/wifi/stats/simple_counters.hh>
00042 # include <wipal/wifi/stats/gap_lengths.hh>
00043 # include <wipal/wifi/stats/missed_estimations.hh>
00044 # include <wipal/wifi/stats/tfi_plot.hh>
00045 # include <wipal/wifi/stats/bss_stats.hh>
00046 # include <wipal/wifi/stats/ssid_stats.hh>
00047 # include <wipal/wifi/stats/activity.hh>
00048 # include <wipal/wifi/stats/growth.hh>
00049 # include <wipal/wifi/stats/on_off_data.hh>
00050 # include <wipal/wifi/stats/sta_counters.hh>
00051 # include <wipal/wifi/stats/gaps.hh>
00052 # include <wipal/tool/microseconds.hh>
00053 # include <wipal/wifi/addr.hh>
00054 # include <wipal/wifi/essid.hh>
00055 # include <wipal/wifi/seqctl.hh>
00056 # include <wipal/wifi/dissector/default_hooks.hh>
00057 # include <wipal/wifi/mgt.hh>
00058
00059 namespace wpl
00060 {
00061
00062 namespace wifi
00063 {
00064
00065 namespace stats
00066 {
00067
00068 struct stats: public abstract_stats
00069 {
00070 template <class PhyHeader, class Frame>
00071 void
00072 account(const Frame& f);
00073
00074 template <class Module>
00075 const Module&
00076 get() const;
00077
00078 std::ostream& print(std::ostream& o) const;
00079 void restart();
00080
00081 private:
00082
00083 struct state
00084 {
00085 enum
00086 {
00087 lifetime = 60 * 1000 * 1000,
00088 min_frame_sending_time = 106
00089 };
00090
00091 state(unsigned last_frame_id,
00092 const seqctl& last_sc,
00093 const tool::microseconds& last_rx_stamp);
00094
00095 unsigned last_frame_id;
00096 seqctl last_sc;
00097 tool::microseconds last_rx_stamp;
00098 };
00099
00100 typedef std::map<seqnum_counter_id, state> state_map;
00101
00102 struct hooks: public dissector_default_hooks
00103 {
00104 hooks();
00105
00106 void invalid_type_or_subtype_hook(const void*, size_t,
00107 dissector_status::status);
00108 void addr_hook(const void*, size_t, unsigned, const addr&);
00109 void seq_ctl_hook(const void*, size_t, unsigned, unsigned);
00110 void qos_ctl_hook(const void*, size_t,
00111 unsigned, bool, unsigned, unsigned);
00112 void beacon_hook(const mgt::header*, size_t);
00113
00114 struct beacon_data
00115 {
00116 beacon_data(const mgt::header* header, size_t caplen);
00117
00118 const addr* ap;
00119 const addr* bss;
00120 bool ibss;
00121 boost::optional<std::string> ssid;
00122
00123 };
00124
00125 typedef boost::optional<beacon_data> optional_beacon_data;
00126 typedef boost::optional<seqctl> optional_seqctl;
00127 typedef boost::optional<seqnum_counter_id> optional_seq_counter_id;
00128
00129 type::frame_type type;
00130 unsigned subtype;
00131 bool retx;
00132 const addr* a1;
00133
00134
00135 const addr* a2;
00136
00137
00138 std::vector< std::pair<int, const addr*> > addrs;
00139
00140 optional_seqctl sc;
00141 optional_seq_counter_id id;
00142 optional_beacon_data beacon;
00143 };
00144
00145 enum { growths_epoch = 60 * 1000 * 1000 };
00146
00147 # define WP_stats_modules \
00148 (sta_counters)(on_off_data)(beacon_items_growth<growths_epoch>) \
00149 (addr_growth<growths_epoch>) \
00150 (activity)(ssid_stats)(bss_stats)(tfi_plot)(gap_lengths) \
00151 (simple_counters)(missed_estimations)(delimiter_frames)
00152
00153
00154
00155
00156
00157
00158 # define WP_op(U, State, Elem) \
00159 ((module_list<Elem, BOOST_PP_TUPLE_ELEM(2, 0, State)), \
00160 BOOST_PP_TUPLE_ELEM(2, 1, State)>)
00161 # define WP_tuple \
00162 BOOST_PP_SEQ_FOLD_LEFT(WP_op, ((BOOST_PP_SEQ_HEAD(WP_stats_modules), \
00163 BOOST_PP_NIL),), \
00164 BOOST_PP_SEQ_TAIL(WP_stats_modules))
00165 # define WP_module_list_type \
00166 BOOST_PP_LIST_ENUM(BOOST_PP_TUPLE_ELEM(2, 0, WP_tuple)) \
00167 BOOST_PP_TUPLE_ELEM(2, 1, WP_tuple)
00168
00169 typedef WP_module_list_type module_list_type;
00170
00171 # undef WP_module_list_type
00172 # undef WP_tuple
00173 # undef WP_op
00174 # undef WP_stats_modules
00175
00176
00177 private:
00178
00179 template <class Frame>
00180 void
00181 update_states(const Frame& f, const dissector<hooks>& d);
00182
00183 private:
00184 state_map states_;
00185 std::set<addr> aps_;
00186 module_list_type modules_;
00187 };
00188
00189 }
00190
00191 }
00192
00193 }
00194
00195 # include "stats.hxx"
00196
00197 #endif // ! WIFI_STATS_STATS_HH_