rippled
Loading...
Searching...
No Matches
submitters.h
1#ifndef XRPL_TEST_CSF_SUBMITTERS_H_INCLUDED
2#define XRPL_TEST_CSF_SUBMITTERS_H_INCLUDED
3
4#include <test/csf/Peer.h>
5#include <test/csf/Scheduler.h>
6#include <test/csf/SimTime.h>
7#include <test/csf/Tx.h>
8
9#include <type_traits>
10
11namespace ripple {
12namespace test {
13namespace csf {
14
15// Submitters are classes for simulating submission of transactions to the
16// network
17
19struct Rate
20{
23
24 double
25 inv() const
26 {
27 return duration.count() / double(count);
28 }
29};
30
48template <class Distribution, class Generator, class Selector>
50{
51 Distribution dist_;
56 Generator& g_;
57
58 // Convert generated durations to SimDuration
59 static SimDuration
61 {
62 return d;
63 }
64
65 template <class T>
68 {
69 return SimDuration{static_cast<SimDuration::rep>(t)};
70 }
71
72 void
74 {
75 selector_()->submit(Tx{nextID_++});
76 if (scheduler_.now() < stop_)
77 {
78 scheduler_.in(asDuration(dist_(g_)), [&]() { submit(); });
79 }
80 }
81
82public:
84 Distribution dist,
85 SimTime start,
86 SimTime end,
87 Selector& selector,
88 Scheduler& s,
89 Generator& g)
90 : dist_{dist}, stop_{end}, selector_{selector}, scheduler_{s}, g_{g}
91 {
92 scheduler_.at(start, [&]() { submit(); });
93 }
94};
95
96template <class Distribution, class Generator, class Selector>
97Submitter<Distribution, Generator, Selector>
99 Distribution dist,
100 SimTime start,
101 SimTime end,
102 Selector& sel,
103 Scheduler& s,
104 Generator& g)
105{
107 dist, start, end, sel, s, g);
108}
109
110} // namespace csf
111} // namespace test
112} // namespace ripple
113
114#endif
Simulated discrete-event scheduler.
cancel_token at(time_point const &when, Function &&f)
Schedule an event at a specific time.
time_point now() const
Return the current network time.
cancel_token in(duration const &delay, Function &&f)
Schedule an event after a specified duration passes.
Invocable that returns random samples from a range according to a discrete distribution.
Submits transactions to a specified peer.
Definition submitters.h:50
static std::enable_if_t< std::is_arithmetic< T >::value, SimDuration > asDuration(T t)
Definition submitters.h:67
Submitter(Distribution dist, SimTime start, SimTime end, Selector &selector, Scheduler &s, Generator &g)
Definition submitters.h:83
static SimDuration asDuration(SimDuration d)
Definition submitters.h:60
A single transaction.
Definition Tx.h:23
Submitter< Distribution, Generator, Selector > makeSubmitter(Distribution dist, SimTime start, SimTime end, Selector &sel, Scheduler &s, Generator &g)
Definition submitters.h:98
typename SimClock::duration SimDuration
Definition SimTime.h:17
typename SimClock::time_point SimTime
Definition SimTime.h:18
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
Represents rate as a count/duration.
Definition submitters.h:20
double inv() const
Definition submitters.h:25