20#include <test/csf/BasicNetwork.h>
21#include <test/csf/Scheduler.h>
22#include <xrpl/beast/unit_test.h>
48 using namespace std::chrono_literals;
52 for (
auto const link : net.links(
this))
53 net.send(
this, link.target, [&, to = link.target] {
54 to->receive(net, this, 1);
71 for (
auto const link : net.links(
this))
72 net.send(
this, link.target, [&, mm = m, to = link.target] {
73 to->receive(net, this, mm);
82 using namespace std::chrono_literals;
89 BEAST_EXPECT(!net.
connect(&pv[0], &pv[0]));
90 BEAST_EXPECT(net.
connect(&pv[0], &pv[1], 1s));
91 BEAST_EXPECT(net.
connect(&pv[1], &pv[2], 1s));
92 BEAST_EXPECT(!net.
connect(&pv[0], &pv[1]));
94 peer.start(scheduler, net);
95 BEAST_EXPECT(scheduler.
step_for(0s));
96 BEAST_EXPECT(scheduler.
step_for(1s));
97 BEAST_EXPECT(scheduler.
step());
98 BEAST_EXPECT(!scheduler.
step());
99 BEAST_EXPECT(!scheduler.
step_for(1s));
100 net.
send(&pv[0], &pv[1], [] {});
101 net.
send(&pv[1], &pv[0], [] {});
103 BEAST_EXPECT(!net.
disconnect(&pv[0], &pv[1]));
106 auto const links = net.
links(&pv[1]);
109 BEAST_EXPECT(net.
disconnect(&pv[1], links[0].target));
119 using namespace std::chrono_literals;
122 BEAST_EXPECT(net.
connect(0, 1, 1s));
123 BEAST_EXPECT(net.
connect(0, 2, 2s));
126 net.
send(0, 1, [&]() { delivered.
insert(1); });
127 net.
send(0, 2, [&]() { delivered.
insert(2); });
129 scheduler.
in(1000ms, [&]() { BEAST_EXPECT(net.
disconnect(0, 2)); });
130 scheduler.
in(1100ms, [&]() { BEAST_EXPECT(net.
connect(0, 2)); });
147BEAST_DEFINE_TESTSUITE(BasicNetwork, test,
ripple);
void run() override
Runs the suite.
Peer to peer network simulator.
void send(Peer const &from, Peer const &to, Function &&f)
Send a message to a peer.
bool disconnect(Peer const &peer1, Peer const &peer2)
Break a link.
auto links(Peer const &from)
Return the range of active links.
bool connect(Peer const &from, Peer const &to, duration const &delay=std::chrono::seconds{0})
Connect two peers.
Simulated discrete-event scheduler.
bool step_for(std::chrono::duration< Period, Rep > const &amount)
Run the scheduler until time has elapsed.
void cancel(cancel_token const &token)
Cancel a timer.
bool step()
Run the scheduler until no events remain.
cancel_token in(duration const &delay, Function &&f)
Schedule an event after a specified duration passes.
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool set(T &target, std::string const &name, Section const §ion)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
void start(csf::Scheduler &scheduler, Net &net)
Peer(Peer const &)=default
void receive(Net &net, Peer *from, int m)