InterfaceAPI.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_InterfaceAPI_
18 #define HH_SENF_Ext_NetEmu_InterfaceAPI_ 1
19 
20 // Custom includes
21 #include <boost/noncopyable.hpp>
22 #include <senf/PPI/Jack.hh>
23 #include <senf/Utils/Statistics.hh>
25 #include "InterfaceDecorator.hh"
26 #include "InterfaceId.hh"
27 
28 #include "InterfaceAPI.ih"
29 //-/////////////////////////////////////////////////////////////////////////////////////////////////
30 
31 namespace senf {
32 namespace emu {
33 
181  class Receiver;
182  class Transmitter;
183 
193  class Interface
194  : public detail::CommfaceAccess<Receiver,Transmitter>,
195  private boost::noncopyable
196  {
197  public:
199 
200  using detail::CommfaceAccess<Receiver,Transmitter>::receiver;
201  using detail::CommfaceAccess<Receiver,Transmitter>::transmitter;
202 
203  virtual ~Interface();
204 
205  bool canTransmit() const;
206  bool canReceive() const;
207 
208  void enable();
209  void disable();
210  bool enabled() const;
211 
212  unsigned index() const;
213 
214  void id(MACAddress const & eui);
215  MACAddress const & id() const;
216 
217  static unsigned nodeId();
218 
219  static void nodeId(unsigned id);
220 
221  void deviceId(InterfaceDeviceId id);
222  InterfaceDeviceId deviceId() const;
223 
224  std::string const & device() const;
225 
226  boost::uint8_t linkTypeId() const;
227  std::string interfaceTypeName() const;
228 
230 
232  //\{
235 
236  template <class Stat>
237  senf::Statistics & registerStatistics(std::string name, Stat & stat);
239 
247  boost::optional<senf::Statistics &> statistic(std::string const & name);
249 
252 #ifndef DOXYGEN
253  boost::signals2::signal<void (ClockService::clock_type)> startStatistics;
254 #else
257 
265 #endif
266  //\}
267 
269  //\{
270  boost::signals2::signal<void (Interface &, MACAddress)> idChangedSignal;
271  //\}
272 
273  protected:
274  Interface();
275 
276  void init();
277 
279 #ifndef DOXYGEN
280  private:
281 #else
282  protected:
283 #endif
284  virtual void v_enable() = 0;
285  virtual void v_disable() = 0;
286  virtual bool v_enabled() const = 0;
287  virtual void v_id(MACAddress const & id) = 0;
288  virtual MACAddress v_id() const = 0;
289  virtual boost::uint8_t v_linkTypeId() const = 0;
290  virtual std::string const & v_device() const = 0;
291 
292  private:
293  typedef boost::ptr_map<std::string, senf::Statistics> Statistics;
294  Statistics statistics_;
295  console::ScopedDirectory<> consoleDir_;
296  unsigned index_;
297  mutable MACAddress id_; // id cache (therefore mutable)
298  static unsigned nodeId_;
299  InterfaceDeviceId deviceId_;
300  };
301 
302 
307  class Receiver
308  : public detail::InterfaceAccess<Interface>
309  {
310  public:
311  virtual ~Receiver();
312 
314 
315  bool annotationMode() const;
316  void annotationMode(bool a);
317  bool promisc() const;
318  void promisc(bool v);
319  void mcAdd(senf::MACAddress const & address);
320  void mcDrop(senf::MACAddress const & address);
321  void flushRxQueues();
322 
323 #ifndef DOXYGEN
324  protected:
325 #else
326  private:
327 #endif
332 
333  void init();
334 
335  virtual bool v_annotationMode() const = 0;
336  virtual void v_annotationMode(bool a) = 0;
337  virtual bool v_promisc() const = 0;
338  virtual void v_promisc(bool v) = 0;
339 
340  virtual void v_mcAdd(senf::MACAddress const & address) = 0;
341  virtual void v_mcDrop(senf::MACAddress const & address) = 0;
342 
343  virtual void v_flushRxQueues() {};
344  };
345 
351  : public detail::InterfaceAccess<Interface>
352  {
353  public:
354  virtual ~Transmitter();
355 
357 
358  unsigned mtu() const;
359  void mtu(unsigned v);
360  void flushTxQueues();
361 
362 #ifndef DOXYGEN
363  protected:
364 #else
365  private:
366 #endif
371 
372  void init();
373 
374  virtual unsigned v_mtu() const = 0;
375  virtual void v_mtu(unsigned v) = 0;
376  virtual void v_flushTxQueues() {} ;
377  };
378 
379  //-//////////////////////////////////////////////////////////////////////
380 
381  class WiredReceiver;
382  class WiredTransmitter;
383 
389  : public Interface,
390  public detail::CommfaceAccess<WiredReceiver,WiredTransmitter>
391  {
392  public:
394 
395  using detail::CommfaceAccess<WiredReceiver,WiredTransmitter>::receiver;
396  using detail::CommfaceAccess<WiredReceiver,WiredTransmitter>::transmitter;
397 
398  protected:
399  void init();
400  };
401 
402 
408  : public Receiver,
409  public detail::InterfaceAccess<WiredInterface>
410  {
411  protected:
416 
417  void init();
418 
419  private:
420  using detail::InterfaceAccess<WiredInterface>::interface;
421  };
422 
423 
429  : public Transmitter,
430  public detail::InterfaceAccess<WiredInterface>
431  {
432  protected:
437 
438  void init();
439 
440  private:
441  using detail::InterfaceAccess<WiredInterface>::interface;
442  };
443 
444  //-//////////////////////////////////////////////////////////////////////
445 
454  : public detail::InterfaceAccess<Interface>
455  {
456  protected:
457  void init();
458  };
459 
460  //-//////////////////////////////////////////////////////////////////////
461 
463 
464  boost::uint16_t perturb(boost::uint16_t value);
465 
466  void macIdSeed(boost::uint16_t seed);
467 
472  MACAddress uniqueMAC(boost::uint32_t magic);
474 
478 }}
479 
480 //-/////////////////////////////////////////////////////////////////////////////////////////////////
481 #include "InterfaceAPI.cci"
482 #include "InterfaceAPI.ct"
483 #include "InterfaceAPI.cti"
484 #endif
485 
486 
487 // Local Variables:
488 // mode: c++
489 // fill-column: 100
490 // comment-column: 40
491 // c-file-style: "senf"
492 // indent-tabs-mode: nil
493 // ispell-local-dictionary: "american"
494 // compile-command: "scons -u test"
495 // End:
boost::uint16_t perturb(boost::uint16_t value)
config::time_type clock_type
void macIdSeed(boost::uint16_t seed)
Re-seed the MACAddress address generator.
Interface API base class
InterfaceDecorator public header.
unsigned index() const
Get interface index.
virtual void v_enable()=0
Called to enable interface.
bool enabled() const
true, if interface enabled
senf::Statistics & registerStatistics(std::string name, Stat &stat)
Register statistics source.
bool canReceive() const
true, if interface is receive capable
virtual void v_disable()=0
Called to disable interface.
Wired interface base class.
boost::uint8_t linkTypeId() const
InterfaceDecorator Decorator
Interface base class specific decorator type
TypedInterfaceDecorator< WiredInterface, Interface::Decorator > Decorator
InterfaceDeviceId deviceId() const
Wired receiver base class.
virtual bool v_enabled() const =0
Return true if interface is enabled.
static unsigned nodeId()
Get unique node id.
void init()
Initialize interface.
Definition: InterfaceAPI.cc:38
console::DirectoryNode & consoleDir() const
Access interface console directory.
std::string const & device() const
InterfaceId public header.
MACAddress const & id() const
Get interface MAC Address.
Interface API base class for receive capable interfaces.
void startStatistics(ClockService::clock_type inverval)
Start statistics generation.
Interface API base class for transmit capable interfaces.
ppi::connector::PassiveInputJack< EthernetPacket > input
bool canTransmit() const
true, if interface is transmit capable
Hardware interface base class.
console::DirectoryNode & interfaceDir()
ppi::connector::ActiveOutputJack< EthernetPacket > output
virtual MACAddress v_id() const =0
Return the interface mac address.
MACAddress uniqueMAC(boost::uint32_t magic)
Get pseudo-random but unique MACAddress.
std::string interfaceTypeName() const
Specialized Interface decorator base-class.
console::DirectoryNode & statisticsDir() const
Access the interface statistics directory.
boost::signals2::signal< void(Interface &, MACAddress)> idChangedSignal
virtual std::string const & v_device() const =0
Wired transmitter base class.
Generic Interface decorator base-class.
boost::optional< senf::Statistics & > statistic(std::string const &name)
Get registered statistic.
Definition: InterfaceAPI.cc:94
void disable()
Disable interface (aka ifconfig down)
void enable()
Enable interface (aka ifconfig up)
virtual boost::uint8_t v_linkTypeId() const =0