EmulatedInterface.ih
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 
14 /** \file
15  \brief EmulatedInterface internal header */
16 
17 #ifndef IH_SENF_Ext_NetEmu_EmulatedInterface_
18 #define IH_SENF_Ext_NetEmu_EmulatedInterface_ 1
19 
20 // Custom includes
21 #include <senf/PPI/MonitorModule.hh>
22 #include <senf/PPI/IntervalTimer.hh>
23 #include "Packets.hh"
24 
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 
27 namespace senf {
28 namespace emu {
29 
30  class EmulatedReceiver;
31  class EmulatedTransmitter;
32  class ChannelGroupTable;
33 
34 namespace detail {
35 
36  /** \brief Internal: Emulated interface receive filter */
37  class EmulatedInterfaceReceiveFilter
38  : public ppi::module::Module
39  {
40  SENF_PPI_MODULE(EmulatedInterfaceReceiveFilter);
41  public:
42  ppi::connector::PassiveInput<PacketHeader> input;
43  ppi::connector::ActiveOutput<> output;
44 
45  explicit EmulatedInterfaceReceiveFilter(EmulatedReceiver & receiver);
46 
47  private:
48  void request();
49 
50  EmulatedReceiver & receiver_;
51  };
52 
53  /** \brief Internal: Emulated interface transmit filter */
54  class EmulatedInterfaceTransmitFilter
55  : public ppi::module::Module
56  {
57  SENF_PPI_MODULE(EmulatedInterfaceTransmitFilter);
58  public:
59  ppi::connector::PassiveInput<> input;
60  ppi::connector::ActiveOutput<PacketHeader> output;
61 
62  explicit EmulatedInterfaceTransmitFilter(EmulatedTransmitter & transmitter);
63 
64  unsigned mtu() const;
65  void mtu(unsigned v);
66 
67  private:
68  void request();
69 
70  EmulatedTransmitter & transmitter_;
71  unsigned seqNr_;
72  unsigned mtu_;
73  };
74 
75  /** \brief Sequence number validation
76 
77  This module will validate the sequence number of all packets. The sequence number is
78  monitored for each peer. If sequence numbers are reversed or missing the module generates an
79  appropriate message.
80  */
81  class DroppedPacketChecker
82  : public ppi::module::MonitorModule<PacketHeader>
83  {
84  SENF_PPI_MODULE(DroppedPacketChecker);
85  SENF_LOG_CLASS_AREA();
86  public:
87  DroppedPacketChecker();
88 
89  unsigned droppedPackets() const; ///< Number of dropped packets
90 
91  /** \brief DroppedPacketChecker statistics
92  \see DroppedPacketChecker */
93  struct Statistics {
94  boost::signals2::signal<void (float)> droppedPacketsPerSecond;
95  boost::signals2::signal<void (unsigned)> numPeers;
96  } signals;
97 
98  void startStatistics(ClockService::clock_type pollInterval);
99  ///< Start statistics generation or change interval
100 
101  private:
102  virtual void v_handlePacket(PacketHeader const & p) override;
103  void statisticsUpdate();
104 
105  typedef std::map<std::pair<unsigned,unsigned>, boost::uint32_t> SeqNoMap;
106  SeqNoMap seqNos_;
107  unsigned droppedPackets_;
108  ppi::IntervalTimer statisticsTimer_;
109  unsigned lastDroppedPackets_;
110  float factor_;
111  };
112 
113  /** \brief Check raw packet transmit time
114 
115  This module will check the time each packet takes from the time it is sent until it is
116  received against a maximum value. Excessively delayed packets will be logged.
117  */
118  class DelayTimeChecker
119  : public ppi::module::MonitorModule<PacketHeader>
120  {
121  SENF_PPI_MODULE(DelayTimeChecker);
122  SENF_LOG_CLASS_AREA();
123  public:
124  DelayTimeChecker(
125  ClockService::clock_type maxDelay = ClockService::milliseconds(10));
126 
127  void maxDelay(ClockService::clock_type maxDelay);
128  ///< Set maximum allowed packet delay
129  ClockService::clock_type maxDelay() const;
130  ///< Get current maxDelay() value
131 
132  unsigned delayedPackets() const; ///< Number of packets with delay > maxDelay()
133  ClockService::clock_type maxPacketDelay() const;
134  ///< Maximum packet delay encountered
135 
136  /** \brief DelayTimeChecker statistics
137  \see DelayTimeChecker */
138  struct Statistics {
139  boost::signals2::signal<void (float,float,float)> packetDelay;
140  } signals;
141 
142  void startStatistics(ClockService::clock_type pollInterval);
143 
144  private:
145  virtual void v_handlePacket(PacketHeader const & p) override;
146  void statisticsUpdate();
147 
148  ClockService::clock_type maxDelay_;
149  unsigned delayedPackets_;
150  ClockService::clock_type maxPacketDelay_;
151  ppi::IntervalTimer statisticsTimer_;
152  ClockService::clock_type minDelayStat_, totalDelayStat_, maxDelayStat_;
153  unsigned nPackets_;
154  };
155 
156  class AdvancePacket
157  : public ppi::module::Module
158  {
159  SENF_PPI_MODULE(AdvancePacket);
160  public:
161  ppi::connector::PassiveInput<PacketHeader> input;
162  ppi::connector::ActiveOutput<> output;
163 
164  AdvancePacket();
165 
166  private:
167  void request();
168  };
169 
170 }}}
171 
172 //-/////////////////////////////////////////////////////////////////////////////////////////////////
173 #endif
174 
175 
176 // Local Variables:
177 // mode: c++
178 // fill-column: 100
179 // comment-column: 40
180 // c-file-style: "senf"
181 // indent-tabs-mode: nil
182 // ispell-local-dictionary: "american"
183 // compile-command: "scons -u test"
184 // End: