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_FILTER_UNIQUELY_IDENTIFIABLE_HXX_
00023 # define WIFI_FRAME_FILTER_UNIQUELY_IDENTIFIABLE_HXX_
00024
00025 # include <wipal/wifi/frame/dissector/dissector.hh>
00026 # include <wipal/wifi/frame/unique_id/unique_id.hh>
00027 # include <wipal/wifi/frame/filter/non_noisy_prism.hh>
00028
00029 namespace wifi
00030 {
00031 namespace frame
00032 {
00033 namespace filter
00034 {
00035
00036 namespace internals
00037 {
00038
00039 template <class U, class I, class H, class B1, class B2>
00040 uniquely_identifiable_iterator<U, I, H, B1, B2>::
00041 uniquely_identifiable_iterator(const iterable_type& uif,
00042 bool end):
00043 iterable_ (&uif),
00044 next_ (end ? uif.end_ : uif.begin_),
00045 mactime_ (uif.pcap_tstamps_),
00046 frame_count_ (0),
00047 uframe_count_ (0)
00048 {
00049 if (not end)
00050 increment();
00051 }
00052
00053 template <class U, class I, class H, class B1, class B2>
00054 bool
00055 uniquely_identifiable_iterator<U, I, H, B1, B2>::
00056 equal(const uniquely_identifiable_iterator& rhs) const
00057 {
00058 if (not rhs.value())
00059 return not this->value();
00060 return next_ == rhs.next_;
00061 }
00062
00063 template <class U, class I, class H, class B1, class B2>
00064 void
00065 uniquely_identifiable_iterator<U, I, H, B1, B2>::increment()
00066 {
00067 unique_id_factory<U> factory;
00068 boost::optional<U> id;
00069
00070 while (next_ != iterable_->end_ and not id)
00071 {
00072 mactime_.tick<H>(*next_, iterable_->phy_end_);
00073 id = factory.template build<H>(*next_, *iterable_->mapping_);
00074 ++next_;
00075 ++frame_count_;
00076 }
00077 if (id)
00078 {
00079 this->value() = value_type (mactime_.microseconds(), id.get());
00080 ++uframe_count_;
00081 }
00082 else
00083 this->value() = boost::none_t ();
00084 }
00085
00086 template <class U, class I, class H, class B1, class B2>
00087 unsigned
00088 uniquely_identifiable_iterator<U, I, H, B1, B2>::frame_count() const
00089 {
00090 return frame_count_;
00091 }
00092
00093 template <class U, class I, class H, class B1, class B2>
00094 unsigned
00095 uniquely_identifiable_iterator<U, I, H, B1, B2>::
00096 unique_frame_count() const
00097 {
00098 return uframe_count_;
00099 }
00100
00101 }
00102
00103 template <class U, class I, class H, class B>
00104 uniquely_identifiable<U, I, H, B>::
00105 uniquely_identifiable(const I& begin,
00106 const I& end,
00107 addr_mapping& mapping,
00108 tool::endian::endianness phy_end,
00109 bool pcap_tstamps):
00110 begin_ (begin),
00111 end_ (end),
00112 mapping_ (&mapping),
00113 phy_end_ (phy_end),
00114 pcap_tstamps_ (pcap_tstamps)
00115 {
00116 }
00117
00118 template <class U, class HT, class I, class F>
00119 void
00120 for_each_uniquely_identifiable(const I& first,
00121 const I& last,
00122 tool::opt::list& opts,
00123 F& func)
00124 {
00125 typedef tool::endian::endianness endianness;
00126
00127 const endianness& end = opts["endianness"].get<endianness>();
00128 addr_mapping& map = opts["mapping"].get<addr_mapping>();
00129 const bool pcapts = not opts["phy_tstamps"].get<bool>();
00130
00131 if (opts["ignore_noisy_prism"].get<bool>())
00132 {
00133 typedef non_noisy_prism<I> filter_type;
00134 typedef typename filter_type::iterator iterator;
00135 typedef uniquely_identifiable<U, iterator, HT> unique_type;
00136
00137 filter_type f (first, last);
00138 unique_type u (f.begin(), f.end(), map, end, pcapts);
00139
00140 u.for_each(func);
00141 }
00142 else
00143 {
00144 typedef uniquely_identifiable<U, I, HT> unique_type;
00145
00146 unique_type u (first, last, map, end, pcapts);
00147
00148 u.for_each(func);
00149 }
00150 }
00151
00152
00153 template <class U, class HT, class I, class F>
00154 void
00155 for_each_uniquely_identifiable(const I& first,
00156 const I& last,
00157 const tool::opt::list& opts,
00158 const F& func)
00159 {
00160 typedef tool::endian::endianness endianness;
00161
00162 const endianness& end = opts["endianness"].get<endianness>();
00163 addr_mapping& map = opts["mapping"].get<addr_mapping>();
00164 const bool pcapts = not opts["phy_tstamps"].get<bool>();
00165
00166 if (opts["ignore_noisy_prism"].get<bool>())
00167 {
00168 typedef non_noisy_prism<I> filter_type;
00169 typedef typename filter_type::iterator iterator;
00170 typedef uniquely_identifiable<U, iterator, HT> unique_type;
00171
00172 filter_type f (first, last);
00173 unique_type u (f.begin(), f.end(), map, end, pcapts);
00174
00175 u.for_each(func);
00176 }
00177 else
00178 {
00179 typedef uniquely_identifiable<U, I, HT> unique_type;
00180
00181 unique_type u (first, last, map, end, pcapts);
00182
00183 u.for_each(func);
00184 }
00185 }
00186
00187 }
00188
00189 }
00190
00191 }
00192
00193 #endif // ! WIFI_FRAME_FILTER_UNIQUELY_IDENTIFIABLE_HXX_