PacketDropper.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_Modules_PacketDropper_
18 #define HH_SENF_Ext_NetEmu_Modules_PacketDropper_ 1
19 
20 // Custom includes
21 #include <senf/PPI/Module.hh>
22 #include <senf/PPI/Connectors.hh>
23 #include <boost/random.hpp>
24 
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 
27 namespace senf {
28 namespace emu {
29 
31  : public ppi::module::Module
32  {
34 
35  public:
38 
39  PacketDropper(double rate);
40  double lossRate() const;
41  void lossRate(double lossRate);
42 
43  private:
44  typedef boost::mt19937 RandomEngine; // Mersenne twister
45  typedef boost::bernoulli_distribution<> RandomDistribution;
46  typedef boost::variate_generator<RandomEngine, RandomDistribution> RandomGenerator;
47 
48  RandomEngine randomEngine_;
49  boost::scoped_ptr<RandomDistribution> randomDistribution_;
50  boost::scoped_ptr<RandomGenerator> randomGenerator_;
51  double lossRate_;
52 
53  void onRequest_forwardAll();
54  void onRequest_discardAll();
55  void onRequest_random();
56  };
57 
58 }}
59 
60 //-/////////////////////////////////////////////////////////////////////////////////////////////////
61 #include "PacketDropper.cci"
62 //#include "PacketDropper.ct"
63 //#include "PacketDropper.cti"
64 #endif
65 
66 
67 // Local Variables:
68 // mode: c++
69 // fill-column: 100
70 // c-file-style: "senf"
71 // indent-tabs-mode: nil
72 // ispell-local-dictionary: "american"
73 // compile-command: "scons -u test"
74 // comment-column: 40
75 // End:
#define SENF_PPI_MODULE(name)
ppi::connector::ActiveOutput output
ppi::connector::PassiveInput input