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