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
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
15 \brief EmulatedInterface inline non-template implementation */
17 #include "EmulatedInterface.ih"
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::emu::detail::EmulatedInterfaceReceiveFilter
27 prefix_ senf::emu::detail::EmulatedInterfaceReceiveFilter::
28 EmulatedInterfaceReceiveFilter(EmulatedReceiver & receiver)
29 : receiver_ (receiver)
32 input.onRequest(&EmulatedInterfaceReceiveFilter::request);
35 //-/////////////////////////////////////////////////////////////////////////////////////////////////
36 // senf::emu::detail::EmulatedInterfaceTransmitFilter::
38 prefix_ senf::emu::detail::EmulatedInterfaceTransmitFilter::
39 EmulatedInterfaceTransmitFilter(EmulatedTransmitter & transmitter)
40 : transmitter_ (transmitter), mtu_ (0u)
43 input.onRequest(&EmulatedInterfaceTransmitFilter::request);
46 prefix_ unsigned senf::emu::detail::EmulatedInterfaceTransmitFilter::mtu()
52 prefix_ void senf::emu::detail::EmulatedInterfaceTransmitFilter::mtu(unsigned v)
54 if (v > SENF_EMU_MAXMTU)
55 throw senf::SystemException( "mtu too large: ", EINVAL)
56 << v << ", max. emulated mtu is " << SENF_EMU_MAXMTU;
60 //-/////////////////////////////////////////////////////////////////////////////////////////////////
61 // senf::emu::detail::DroppedPacketChecker
63 prefix_ unsigned senf::emu::detail::DroppedPacketChecker::droppedPackets()
66 return droppedPackets_;
69 //-/////////////////////////////////////////////////////////////////////////////////////////////////
70 // senf::emu::detail::DelayTimeChecker
72 prefix_ void senf::emu::detail::DelayTimeChecker::maxDelay(ClockService::clock_type maxDelay)
77 prefix_ senf::ClockService::clock_type senf::emu::detail::DelayTimeChecker::maxDelay()
83 prefix_ unsigned senf::emu::detail::DelayTimeChecker::delayedPackets()
86 return delayedPackets_;
89 prefix_ senf::ClockService::clock_type senf::emu::detail::DelayTimeChecker::maxPacketDelay()
92 return maxPacketDelay_;
95 //-/////////////////////////////////////////////////////////////////////////////////////////////////
96 // senf::emu::detail::AdvancePacket
98 prefix_ senf::emu::detail::AdvancePacket::AdvancePacket()
100 route(input, output);
101 input.onRequest(&AdvancePacket::request);
104 prefix_ void senf::emu::detail::AdvancePacket::request()
106 output(input().next(senf::nothrow));
109 //-/////////////////////////////////////////////////////////////////////////////////////////////////
110 // senf::emu::EmulatedInterface
112 prefix_ senf::emu::EmulatedInterface::EmulatedInterface()
113 : socket_ (senf::noinit), enabled_ (false), interfaceIndex_(emuInterfaceIndex++)
116 prefix_ senf::emu::EmulatedInterface::~EmulatedInterface()
119 prefix_ std::uint32_t const & senf::emu::EmulatedInterface::interfaceIndex()
122 return interfaceIndex_;
125 prefix_ bool senf::emu::EmulatedInterface::emulatedInterfaceEnabled()
131 prefix_ senf::emu::UDPClientHandle senf::emu::EmulatedInterface::emulationSocket()
137 prefix_ senf::emu::UDPClientHandle::Address senf::emu::EmulatedInterface::emulationAddress()
143 prefix_ void senf::emu::EmulatedInterface::emulationInterface(std::string const & interface)
145 interface_ = interface;
146 emulationAddress(address_);
149 prefix_ std::string const & senf::emu::EmulatedInterface::emulationInterface()
155 //-/////////////////////////////////////////////////////////////////////////////////////////////////
156 // senf::emu::EmulatedReceiver
159 senf::emu::EmulatedReceiver::startStatistics(ClockService::clock_type interval)
161 dropChecker_.startStatistics(interval);
162 delayChecker_.startStatistics(interval);
165 prefix_ void senf::emu::EmulatedReceiver::maxDelay(ClockService::clock_type maxDelay)
167 delayChecker_.maxDelay(maxDelay);
170 prefix_ senf::ClockService::clock_type senf::emu::EmulatedReceiver::maxDelay()
173 return delayChecker_.maxDelay();
176 prefix_ unsigned senf::emu::EmulatedReceiver::delayedPackets()
179 return delayChecker_.delayedPackets();
182 prefix_ senf::ClockService::clock_type senf::emu::EmulatedReceiver::maxPacketDelay()
185 return delayChecker_.maxPacketDelay();
188 prefix_ unsigned senf::emu::EmulatedReceiver::droppedPackets()
191 return dropChecker_.droppedPackets();
194 prefix_ void senf::emu::EmulatedReceiver::deinitEmulatedReceiver()
196 source_.handle(UDPClientHandle(senf::noinit));
199 prefix_ bool senf::emu::EmulatedReceiver::promiscEmulatedReceiver()
205 prefix_ void senf::emu::EmulatedReceiver::promiscEmulatedReceiver(bool v)
210 prefix_ bool senf::emu::EmulatedReceiver::annotationModeEmulatedReceiver()
213 return annotationMode_;
216 prefix_ void senf::emu::EmulatedReceiver::annotationModeEmulatedReceiver(bool a)
221 prefix_ void senf::emu::EmulatedReceiver::mcAddEmulatedReceiver(MACAddress const & address)
223 mcSet_.insert(address);
226 prefix_ void senf::emu::EmulatedReceiver::mcDropEmulatedReceiver(MACAddress const & address)
228 mcSet_.erase(address);
231 prefix_ double senf::emu::EmulatedReceiver::lossRate()
234 return dropper_.lossRate();
237 prefix_ void senf::emu::EmulatedReceiver::lossRate(double lossRate)
239 dropper_.lossRate(lossRate);
241 //-/////////////////////////////////////////////////////////////////////////////////////////////////
242 // senf::emu::EmulatedTransmitter
244 prefix_ void senf::emu::EmulatedTransmitter::delay(ClockService::clock_type delay)
246 delayer_.delay(delay);
249 prefix_ senf::ClockService::clock_type senf::emu::EmulatedTransmitter::delay()
252 return delayer_.delay();
255 prefix_ void senf::emu::EmulatedTransmitter::deinitEmulatedTransmitter()
257 sink_.handle(UDPClientHandle(senf::noinit));
260 prefix_ unsigned senf::emu::EmulatedTransmitter::mtuEmulatedTransmitter()
263 return filter_.mtu();
266 prefix_ void senf::emu::EmulatedTransmitter::mtuEmulatedTransmitter(unsigned v)
271 //-/////////////////////////////////////////////////////////////////////////////////////////////////
278 // comment-column: 40
279 // c-file-style: "senf"
280 // indent-tabs-mode: nil
281 // ispell-local-dictionary: "american"
282 // compile-command: "scons -u test"