EmulatedInterface.cci
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 inline non-template implementation */
16 
17 #include "EmulatedInterface.ih"
18 
19 // Custom includes
20 
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::emu::detail::EmulatedInterfaceReceiveFilter
26 
27 prefix_ senf::emu::detail::EmulatedInterfaceReceiveFilter::
28 EmulatedInterfaceReceiveFilter(EmulatedReceiver & receiver)
29  : receiver_ (receiver)
30 {
31  route(input, output);
32  input.onRequest(&EmulatedInterfaceReceiveFilter::request);
33 }
34 
35 //-/////////////////////////////////////////////////////////////////////////////////////////////////
36 // senf::emu::detail::EmulatedInterfaceTransmitFilter::
37 
38 prefix_ senf::emu::detail::EmulatedInterfaceTransmitFilter::
39 EmulatedInterfaceTransmitFilter(EmulatedTransmitter & transmitter)
40  : transmitter_ (transmitter), mtu_ (0u)
41 {
42  route(input, output);
43  input.onRequest(&EmulatedInterfaceTransmitFilter::request);
44 }
45 
46 prefix_ unsigned senf::emu::detail::EmulatedInterfaceTransmitFilter::mtu()
47  const
48 {
49  return mtu_;
50 }
51 
52 prefix_ void senf::emu::detail::EmulatedInterfaceTransmitFilter::mtu(unsigned v)
53 {
54  if (v > SENF_EMU_MAXMTU)
55  throw senf::SystemException( "mtu too large: ", EINVAL)
56  << v << ", max. emulated mtu is " << SENF_EMU_MAXMTU;
57  mtu_ = v;
58 }
59 
60 //-/////////////////////////////////////////////////////////////////////////////////////////////////
61 // senf::emu::detail::DroppedPacketChecker
62 
63 prefix_ unsigned senf::emu::detail::DroppedPacketChecker::droppedPackets()
64  const
65 {
66  return droppedPackets_;
67 }
68 
69 //-/////////////////////////////////////////////////////////////////////////////////////////////////
70 // senf::emu::detail::DelayTimeChecker
71 
72 prefix_ void senf::emu::detail::DelayTimeChecker::maxDelay(ClockService::clock_type maxDelay)
73 {
74  maxDelay_ = maxDelay;
75 }
76 
77 prefix_ senf::ClockService::clock_type senf::emu::detail::DelayTimeChecker::maxDelay()
78  const
79 {
80  return maxDelay_;
81 }
82 
83 prefix_ unsigned senf::emu::detail::DelayTimeChecker::delayedPackets()
84  const
85 {
86  return delayedPackets_;
87 }
88 
89 prefix_ senf::ClockService::clock_type senf::emu::detail::DelayTimeChecker::maxPacketDelay()
90  const
91 {
92  return maxPacketDelay_;
93 }
94 
95 //-/////////////////////////////////////////////////////////////////////////////////////////////////
96 // senf::emu::detail::AdvancePacket
97 
98 prefix_ senf::emu::detail::AdvancePacket::AdvancePacket()
99 {
100  route(input, output);
101  input.onRequest(&AdvancePacket::request);
102 }
103 
104 prefix_ void senf::emu::detail::AdvancePacket::request()
105 {
106  output(input().next(senf::nothrow));
107 }
108 
109 //-/////////////////////////////////////////////////////////////////////////////////////////////////
110 // senf::emu::EmulatedInterface
111 
112 prefix_ senf::emu::EmulatedInterface::EmulatedInterface()
113  : socket_ (senf::noinit), enabled_ (false), interfaceIndex_(emuInterfaceIndex++)
114 {}
115 
116 prefix_ senf::emu::EmulatedInterface::~EmulatedInterface()
117 {}
118 
119 prefix_ std::uint32_t const & senf::emu::EmulatedInterface::interfaceIndex()
120  const
121 {
122  return interfaceIndex_;
123 }
124 
125 prefix_ bool senf::emu::EmulatedInterface::emulatedInterfaceEnabled()
126  const
127 {
128  return enabled_;
129 }
130 
131 prefix_ senf::emu::UDPClientHandle senf::emu::EmulatedInterface::emulationSocket()
132  const
133 {
134  return socket_;
135 }
136 
137 prefix_ senf::emu::UDPClientHandle::Address senf::emu::EmulatedInterface::emulationAddress()
138  const
139 {
140  return address_;
141 }
142 
143 prefix_ void senf::emu::EmulatedInterface::emulationInterface(std::string const & interface)
144 {
145  interface_ = interface;
146  emulationAddress(address_);
147 }
148 
149 prefix_ std::string const & senf::emu::EmulatedInterface::emulationInterface()
150  const
151 {
152  return interface_;
153 }
154 
155 //-/////////////////////////////////////////////////////////////////////////////////////////////////
156 // senf::emu::EmulatedReceiver
157 
158 prefix_ void
159 senf::emu::EmulatedReceiver::startStatistics(ClockService::clock_type interval)
160 {
161  dropChecker_.startStatistics(interval);
162  delayChecker_.startStatistics(interval);
163 }
164 
165 prefix_ void senf::emu::EmulatedReceiver::maxDelay(ClockService::clock_type maxDelay)
166 {
167  delayChecker_.maxDelay(maxDelay);
168 }
169 
170 prefix_ senf::ClockService::clock_type senf::emu::EmulatedReceiver::maxDelay()
171  const
172 {
173  return delayChecker_.maxDelay();
174 }
175 
176 prefix_ unsigned senf::emu::EmulatedReceiver::delayedPackets()
177  const
178 {
179  return delayChecker_.delayedPackets();
180 }
181 
182 prefix_ senf::ClockService::clock_type senf::emu::EmulatedReceiver::maxPacketDelay()
183  const
184 {
185  return delayChecker_.maxPacketDelay();
186 }
187 
188 prefix_ unsigned senf::emu::EmulatedReceiver::droppedPackets()
189  const
190 {
191  return dropChecker_.droppedPackets();
192 }
193 
194 prefix_ void senf::emu::EmulatedReceiver::deinitEmulatedReceiver()
195 {
196  source_.handle(UDPClientHandle(senf::noinit));
197 }
198 
199 prefix_ bool senf::emu::EmulatedReceiver::promiscEmulatedReceiver()
200  const
201 {
202  return promisc_;
203 }
204 
205 prefix_ void senf::emu::EmulatedReceiver::promiscEmulatedReceiver(bool v)
206 {
207  promisc_ = v;
208 }
209 
210 prefix_ bool senf::emu::EmulatedReceiver::annotationModeEmulatedReceiver()
211  const
212 {
213  return annotationMode_;
214 }
215 
216 prefix_ void senf::emu::EmulatedReceiver::annotationModeEmulatedReceiver(bool a)
217 {
218  annotationMode_ = a;
219 }
220 
221 prefix_ void senf::emu::EmulatedReceiver::mcAddEmulatedReceiver(MACAddress const & address)
222 {
223  mcSet_.insert(address);
224 }
225 
226 prefix_ void senf::emu::EmulatedReceiver::mcDropEmulatedReceiver(MACAddress const & address)
227 {
228  mcSet_.erase(address);
229 }
230 
231 prefix_ double senf::emu::EmulatedReceiver::lossRate()
232  const
233 {
234  return dropper_.lossRate();
235 }
236 
237 prefix_ void senf::emu::EmulatedReceiver::lossRate(double lossRate)
238 {
239  dropper_.lossRate(lossRate);
240 }
241 //-/////////////////////////////////////////////////////////////////////////////////////////////////
242 // senf::emu::EmulatedTransmitter
243 
244 prefix_ void senf::emu::EmulatedTransmitter::delay(ClockService::clock_type delay)
245 {
246  delayer_.delay(delay);
247 }
248 
249 prefix_ senf::ClockService::clock_type senf::emu::EmulatedTransmitter::delay()
250  const
251 {
252  return delayer_.delay();
253 }
254 
255 prefix_ void senf::emu::EmulatedTransmitter::deinitEmulatedTransmitter()
256 {
257  sink_.handle(UDPClientHandle(senf::noinit));
258 }
259 
260 prefix_ unsigned senf::emu::EmulatedTransmitter::mtuEmulatedTransmitter()
261  const
262 {
263  return filter_.mtu();
264 }
265 
266 prefix_ void senf::emu::EmulatedTransmitter::mtuEmulatedTransmitter(unsigned v)
267 {
268  filter_.mtu(v);
269 }
270 
271 //-/////////////////////////////////////////////////////////////////////////////////////////////////
272 #undef prefix_
273 
274 
275 // Local Variables:
276 // mode: c++
277 // fill-column: 100
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"
283 // End: