EmulatedInterface.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_EmulatedInterface_
18 #define HH_SENF_Ext_NetEmu_EmulatedInterface_ 1
19 
20 // Custom includes
22 #include <senf/PPI/SocketSink.hh>
23 #include <senf/PPI/SocketSource.hh>
24 #include "Modules/PacketDelayer.hh"
25 #include "Modules/PacketDropper.hh"
26 #include "InterfaceAPI.hh"
27 #include "config.hh"
28 
29 //#include "EmulatedInterface.mpp"
30 //-/////////////////////////////////////////////////////////////////////////////////////////////////
31 
32 namespace senf {
33 namespace emu {
34 
53  // Change this to UDPv6ClientSocketHandle to use IPv6
55 
56 }}
57 
58 #include "EmulatedInterface.ih"
59 
60 namespace senf {
61 namespace emu {
62 
63  class EmulatedReceiver;
64  class EmulatedTransmitter;
65 
66  //-////////////////////////////////////////////////////////////////////////
67  // Interface
68 
77  : public detail::InterfaceAccess<Interface>,
78  public detail::CommfaceAccess<EmulatedReceiver, EmulatedTransmitter>
79  {
80  public:
81  using detail::CommfaceAccess<EmulatedReceiver, EmulatedTransmitter>::receiver;
82  using detail::CommfaceAccess<EmulatedReceiver, EmulatedTransmitter>::transmitter;
83 
84  virtual ~EmulatedInterface();
85 
86  UDPClientHandle emulationSocket() const;
87 
90  UDPClientHandle::Address emulationAddress() const;
92 
93  void emulationInterface(std::string const & interface);
95  std::string const & emulationInterface() const;
97 
98  std::uint32_t const & interfaceIndex() const;
99 
100  protected:
102  void init();
103 
104  void emulationAddress(UDPClientHandle::Address const & address);
106 
111  void enableEmulatedInterface();
112 
114  void disableEmulatedInterface();
115 
117  bool emulatedInterfaceEnabled() const;
118 
121 #ifndef DOXYGEN
122  private:
123 #else
124  protected:
125 #endif
126  virtual void v_initEmulationInterface() = 0;
127  virtual void v_deinitEmulationInterface() = 0;
128 
129  private:
130  void openSocket();
131  void closeSocket();
132 
133  UDPClientHandle::Address address_;
134  UDPClientHandle socket_;
135  bool enabled_;
136  std::string interface_;
137  std::uint32_t interfaceIndex_;
138  // this is a static counter, which is increamented in the ctor whenever an interface is created
139  // This can be used to uniquely identify an interface across multiple runs of the same emulated scenario (actually: same config a node)
140  static std::uint32_t emuInterfaceIndex;
141  };
142 
143 
148  : public detail::InterfaceAccess<EmulatedInterface>,
149  public detail::InterfaceAccess<Interface>
150  {
152  detail::EmulatedInterfaceReceiveFilter filter_;
153  detail::DroppedPacketChecker dropChecker_;
154  detail::DelayTimeChecker delayChecker_;
155  emu::PacketDropper dropper_;
156  detail::AdvancePacket advance_;
157 
158  public:
159  void startStatistics(ClockService::clock_type pollInterval);
161 
162  void maxDelay(ClockService::clock_type maxDelay);
164  ClockService::clock_type maxDelay() const;
166 
167  unsigned delayedPackets() const;
168  ClockService::clock_type maxPacketDelay() const;
170  unsigned droppedPackets() const;
171 
172  double lossRate() const;
173  void lossRate(double lossRate);
174 
175  protected:
177 
179  void init();
180 
181  void initEmulatedReceiver();
182 
184  void deinitEmulatedReceiver();
185 
187  bool promiscEmulatedReceiver() const;
188 
190  void promiscEmulatedReceiver(bool v);
191 
193  void annotationModeEmulatedReceiver(bool a);
194 
196  bool annotationModeEmulatedReceiver() const;
197 
199  void mcAddEmulatedReceiver(MACAddress const & address);
200 
202  void mcDropEmulatedReceiver(MACAddress const & address);
203 
206  private:
207  typedef detail::InterfaceAccess<EmulatedInterface> emui;
208  typedef detail::InterfaceAccess<Interface> basei;
209 
210  bool promisc_;
211  bool annotationMode_;
212  std::set<MACAddress> mcSet_;
213 
214  friend class detail::EmulatedInterfaceReceiveFilter;
215  };
216 
217 
222  : public detail::InterfaceAccess<EmulatedInterface>,
223  public detail::InterfaceAccess<Interface>
224  {
225  public:
226  void delay(ClockService::clock_type delay);
227  ClockService::clock_type delay() const;
228 
229  protected:
231 
233  void init();
234 
235  void initEmulatedTransmitter();
236 
238  void deinitEmulatedTransmitter();
239 
242  unsigned mtuEmulatedTransmitter() const;
243 
245  void mtuEmulatedTransmitter(unsigned v);
246 
249  virtual Packet::size_type v_emulatedPayloadSize(Packet packet);
250 
256  private:
257  typedef detail::InterfaceAccess<EmulatedInterface> emui;
258  typedef detail::InterfaceAccess<Interface> basei;
259 
260  detail::EmulatedInterfaceTransmitFilter filter_;
261  PacketDelayer delayer_;
263 
264  friend class detail::EmulatedInterfaceTransmitFilter;
265  };
266 
267 
268  class EmulatedWiredReceiver;
270 
275  : public EmulatedInterface,
276  public detail::InterfaceAccess<WiredInterface>,
277  public detail::CommfaceAccess<EmulatedWiredReceiver, EmulatedWiredTransmitter>
278  {
279  public:
280  using detail::InterfaceAccess<WiredInterface>::interface;
281  using detail::CommfaceAccess<EmulatedWiredReceiver, EmulatedWiredTransmitter>::receiver;
282  using detail::CommfaceAccess<EmulatedWiredReceiver, EmulatedWiredTransmitter>::transmitter;
283 
285 
286  protected:
287  void init();
288  };
289 
290 
295  : public EmulatedReceiver,
296  public detail::InterfaceAccess<WiredInterface>
297  {
298  protected:
299  void init();
300 
301  private:
302  using detail::InterfaceAccess<EmulatedInterface>::interface;
303  };
304 
309  : public EmulatedTransmitter,
310  public detail::InterfaceAccess<WiredInterface>
311  {
312  protected:
313  void init();
314 
315  private:
316  using detail::InterfaceAccess<EmulatedInterface>::interface;
317  };
318 
319 }}
320 
321 //-/////////////////////////////////////////////////////////////////////////////////////////////////
322 #include "EmulatedInterface.cci"
323 //#include "EmulatedInterface.ct"
324 //#include "EmulatedInterface.cti"
325 #endif
326 
327 
328 // Local Variables:
329 // mode: c++
330 // fill-column: 100
331 // comment-column: 40
332 // c-file-style: "senf"
333 // indent-tabs-mode: nil
334 // ispell-local-dictionary: "american"
335 // compile-command: "scons -u test"
336 // End:
config::time_type clock_type
void init()
Emulated interface base-class for transmit capable interfaces.
Emulated interface base-class for receive capable wired interfaces.
PacketDropper public header.
PacketDelayer public header.
ppi::connector::ActiveOutputJack receiverJack
Emulated interface base-class.
senf::detail::packet::size_type size_type
Emulated interface base-class for receive capable interfaces.
InterfaceAPI public header.
senf::UDPv4ClientSocketHandle UDPClientHandle
Emulated interface base-class for wired interfaces.
UDPClientHandle::Address emulationAddress() const
Get current emulated traffic multicast address.
ProtocolClientSocketHandle< UDPv4SocketProtocol > UDPv4ClientSocketHandle
ppi::connector::PassiveInputJack transmitterJack
Emulated interface base-class for transmit capable wired interfaces.