WirelessInterfaceAPI.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #ifndef HH_SENF_Ext_NetEmu_WirelessInterfaceAPI_
18 #define HH_SENF_Ext_NetEmu_WirelessInterfaceAPI_ 1
19 
20 // Custom includes
21 #include <boost/ptr_container/ptr_unordered_map.hpp>
22 #include "InterfaceAPI.hh"
23 
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 
26 namespace senf {
27 namespace emu {
28 
29  class WirelessReceiver;
30  class WirelessTransmitter;
31  class EmulatedWirelessInterface;
32  class EmulatedWirelessReceiver;
33  class EmulatedWirelessTransmitter;
34  class ModulationParameterRegistry;
35 
36 
46  : public boost::equality_comparable<ModulationParameter>,
47  public boost::less_than_comparable<ModulationParameter>
48  {
49  typedef boost::uint32_t id_t;
50  id_t id;
51  std::string coding;
52  short minRssi;
53  unsigned rate;
54  unsigned bandwidth;
55  boost::uint8_t linkTypeId;
56  std::string info;
57 
58  ModulationParameter(std::string const & _coding, short _minRssi, unsigned _rate, unsigned _bandwidth, boost::uint8_t _linkTypeId, std::string const & _info = "");
59  virtual ~ModulationParameter() {}
60 
61  void dump(std::ostream & os) const;
62  void dumpTableHeader(std::ostream & os) const;
63  void dumpTableRow(std::ostream & os, bool is_current_modulation) const;
64 
65  struct Error : public senf::Exception {
66  Error();
67  };
68 
69  bool operator<(ModulationParameter const & other) const {
70  return id < other.id;
71  };
72 
73  bool operator==(ModulationParameter const & other) const {
74  return id == other.id;
75  };
76 
77  private:
78  friend class ModulationParameterRegistry;
79  virtual boost::uint16_t v_modulationId() const = 0;
80  virtual ModulationParameter * v_clone() const = 0;
81  virtual void v_dump(std::ostream & os) const = 0;
82  virtual void v_dumpTableHeader(std::ostream & os) const = 0;
83  virtual void v_dumpTableRow(std::ostream & os) const = 0;
84  };
85 
87  : private boost::noncopyable
88  {
89  public:
91  static ModulationParameterRegistry _instance;
92  return _instance;
93  }
94 
95  unsigned registerModulation(ModulationParameter & parameter);
96  ModulationParameter const & findModulationById(ModulationParameter::id_t id) const;
97 
98  private:
99  typedef boost::ptr_unordered_map<ModulationParameter::id_t, ModulationParameter> Modulations;
100  Modulations modulations_;
101  };
102 
103 
125  : public Interface,
126  public detail::CommfaceAccess<WirelessReceiver, WirelessTransmitter>
127  {
128  public:
129  //-////////////////////////////////////////////////////////////////////////
130  // Types
131 
134 
143  struct Frequency {
144  unsigned frequencyLower;
145  unsigned frequencyUpper;
146  unsigned bandwidthLower;
147  unsigned bandwidthUpper;
148 
149  Frequency(unsigned frequencyLower_, unsigned frequencyUpper_, unsigned bandwidthLower_, unsigned bandwidthUpper_);
151  Frequency(unsigned frequency_, unsigned bandwidth_);
153  };
154 
155  private:
156  struct ByLower {};
157  struct ByUpper {};
158 
159  // This greatly shortens the type name and thus error messages ...
160  struct FrequenciesIndexes
161  : public boost::multi_index::indexed_by<
162  boost::multi_index::ordered_non_unique<
163  boost::multi_index::tag<ByLower>,
164  boost::multi_index::composite_key<
165  Frequency,
166  boost::multi_index::member<Frequency, unsigned, &Frequency::bandwidthLower>,
167  boost::multi_index::member<Frequency, unsigned, &Frequency::frequencyLower> > >,
168  boost::multi_index::ordered_non_unique<
169  boost::multi_index::tag<ByUpper>,
170  boost::multi_index::composite_key<
171  Frequency,
172  boost::multi_index::member<Frequency, unsigned, &Frequency::bandwidthUpper>,
173  boost::multi_index::member<Frequency, unsigned, &Frequency::frequencyUpper> > > >
174  {};
175 
176  typedef boost::multi_index_container<Frequency, FrequenciesIndexes> Frequencies;
177 
178  typedef std::pair<unsigned, unsigned> FrequencyInterval; // Frequency interval lower & upper bound
179  typedef std::set<FrequencyInterval> FrequencyIntervals;
180 
181  struct frequency_is_whitelisted
182  {
183  FrequencyIntervals const & whitelistedFrequencies_;
184  frequency_is_whitelisted(FrequencyIntervals const & whitelistedFrequencies);
185  bool operator()(unsigned frequencyLower, unsigned frequencyUpper);
186  bool operator()(Frequency const & frequency);
187  };
188 
189  typedef std::set<ModulationParameter::id_t> ModulationParameterIds;
190 
191  public:
192  typedef boost::filter_iterator<frequency_is_whitelisted, Frequencies::const_iterator> FrequencyIterator;
193  typedef boost::iterator_range<FrequencyIterator> FrequenciesRange;
195 
196  //-////////////////////////////////////////////////////////////////////////
197  // Methods
198 
199  using detail::CommfaceAccess<WirelessReceiver,WirelessTransmitter>::receiver;
200  using detail::CommfaceAccess<WirelessReceiver,WirelessTransmitter>::transmitter;
201 
203  //\{
204  ModulationParameterIds const & modulationParameterIds() const;
205  unsigned maxNSS() const;
206  //\}
207 
209  //\{
210  unsigned frequency() const;
211  unsigned bandwidth() const;
212  void frequency(unsigned freq);
213  void frequency(unsigned freq, unsigned bw);
214 
215  FrequenciesRange frequencies() const;
216 
217  void whitelistedFrequencyRange(unsigned frequencyLower, unsigned frequencyUpper);
218  void whitelistedChannel(unsigned frequency, unsigned bandwidth);
219  void clearWhitelistedFrequencies();
220 
221  void coverageRange(unsigned distance);
222  //\}
223 
224  protected:
226 
227  void init();
228 
229  void clearRegisteredFrequencies();
230  void clearRegisteredModulations();
231 
232  void registerFrequency(unsigned frequency, unsigned bandwidth);
234  void registerFrequency(unsigned frequencyLower, unsigned frequencyUpper,
235  unsigned bandwidthLower, unsigned bandwidthUpper);
237  void registerModulation(ModulationParameter::id_t id);
239 
240 #ifndef DOXYGEN
241  private:
242 #else
243  protected:
244 #endif
245  virtual void v_coverageRange(unsigned distance) = 0;
246  // channel frequency
247  virtual unsigned v_frequency() const = 0;
248  virtual unsigned v_bandwidth() const = 0;
249  virtual void v_frequency(unsigned freq, unsigned bw) = 0;
251 
252  private:
253  void listModulations(std::ostream & os) const;
254  void listFrequencies(std::ostream & os) const;
255 
256  void lookupFrequency(unsigned freq, unsigned bw) const;
257 
258  ModulationParameterIds modulationIds_;
259  Frequencies frequencies_;
260  FrequencyIntervals whitelistedFrequencies_;
261 
262  friend class WirelessTransmitter;
264  };
265 
266 
272  : public Receiver,
273  public detail::InterfaceAccess<WirelessInterface>
274  {
275  protected:
280 
281  void init();
282 
283  private:
284  using detail::InterfaceAccess<WirelessInterface>::interface;
285  };
286 
287 
297  : public Transmitter,
298  public detail::InterfaceAccess<WirelessInterface>
299  {
300  public:
301  //-////////////////////////////////////////////////////////////////////////
302  // Types
303 
305  struct TxPower {
306  const int lower;
307  const int upper;
308 
309  TxPower(int _lower, int _upper);
310  };
311 
312  private:
313  struct TxPowersIndices
314  : public boost::multi_index::indexed_by<
315  boost::multi_index::ordered_unique<
316  boost::multi_index::member<TxPower, const int, &TxPower::upper> > >
317  {};
318 
319  typedef boost::multi_index_container<TxPower, TxPowersIndices> TxPowers;
320 
321  public:
322  typedef boost::iterator_range<TxPowers::const_iterator> TxPowersRange;
323 
324  //-////////////////////////////////////////////////////////////////////////
325  // Methods
326 
328  //\{
329  ModulationParameter::id_t modulation() const;
331  void modulation(ModulationParameter::id_t id);
332  //\}
333 
335  //\{
336  int txPower() const;
337  void txPower(int power);
338  TxPowersRange txPowers() const;
339  //\}
340 
341  protected:
346 
347  void init();
348 
349  void registerTxPower(int power);
350  void registerTxPower(int powerLower, int powerUpper);
351 
352 #ifndef DOXYGEN
353  private:
354 #else
355  protected:
356 #endif
357  virtual ModulationParameter::id_t v_modulationId() const = 0;
359  virtual void v_modulationId(ModulationParameter::id_t id) = 0;
361  virtual int v_txPower() const = 0;
363  virtual void v_txPower(int power) = 0;
365 
366  private:
367  using detail::InterfaceAccess<WirelessInterface>::interface;
368 
369  void listTxpowers(std::ostream & os) const;
370 
371  TxPowers txPowers_;
372 
374  };
375 
376 }}
377 
378 //-/////////////////////////////////////////////////////////////////////////////////////////////////
379 #include "WirelessInterfaceAPI.cci"
380 //#include "WirelessInterfaceAPI.ct"
381 //#include "WirelessInterfaceAPI.cti"
382 #endif
383 
384 
385 // Local Variables:
386 // mode: c++
387 // fill-column: 100
388 // comment-column: 40
389 // c-file-style: "senf"
390 // indent-tabs-mode: nil
391 // ispell-local-dictionary: "american"
392 // compile-command: "scons -u test"
393 // End:
Interface API base class
void init()
std::string info
Arbitrary additional information.
unsigned bandwidth
Bandwidth in KHz.
Emulated wireless transmitter base-class.
const int upper
Transmit power interval upper bound.
bool operator==(ModulationParameter const &other) const
boost::iterator_range< FrequencyIterator > FrequenciesRange
Range of frequency entries.
short minRssi
Minimum RSSI value.
Wireless modulation parameter.
Interface API base class specialization for wireless interfaces.
unsigned rate
Bitrate in kbit/s.
boost::filter_iterator< frequency_is_whitelisted, Frequencies::const_iterator > FrequencyIterator
TypedInterfaceDecorator< WirelessInterface, Interface::Decorator > Decorator
WirelessInterface base class specific decorator type.
Receive capable wireless interface base class.
void dump(std::ostream &os) const
boost::iterator_range< TxPowers::const_iterator > TxPowersRange
unsigned bandwidthLower
Bandwidth interval lower bound.
InterfaceAPI public header.
Interface API base class for receive capable interfaces.
const int lower
Transmit power interval lower bound.
Emulated wireless interface base-class.
bool operator<(ModulationParameter const &other) const
Interface API base class for transmit capable interfaces.
void dumpTableHeader(std::ostream &os) const
static ModulationParameterRegistry & instance()
void dumpTableRow(std::ostream &os, bool is_current_modulation) const
Specialized Interface decorator base-class.
Transmit capable wireless interface base class.
unsigned frequencyLower
Frequency interval lower bound.
ModulationParameter(std::string const &_coding, short _minRssi, unsigned _rate, unsigned _bandwidth, boost::uint8_t _linkTypeId, std::string const &_info="")
unsigned bandwidthUpper
Bandwidth interval upper bound.
unsigned frequencyUpper
Frequency interval upper bound.
__be16 freq