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