|
Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
|
Replays several captured multicast groups as one packet stream in capture-time order. More...
#include <md_feed/pcap_replay_source.hpp>
Classes | |
| struct | Item |
| A packet at the head of the stream. data is valid until pop(). More... | |
Public Member Functions | |
| PcapReplaySource (std::string name, std::string root, uint64_t begin_ns, uint64_t end_ns, std::vector< PcapLine > lines, size_t max_queued_batches=64) | |
| root is only used for lines without explicit paths. | |
| ~PcapReplaySource () | |
| PcapReplaySource (const PcapReplaySource &)=delete | |
| PcapReplaySource & | operator= (const PcapReplaySource &)=delete |
| void | start () |
| Starts reading. | |
| void | stop () |
| bool | positioned () const |
| True once every line has been read up to begin_ns and holds a first packet (or has none), so the replay is ready to produce. | |
| bool | reader_done () const |
| True when the reader has nothing more to add: the window is read out, or it failed (see error()). | |
| uint64_t | truncated_frames () const |
| Frames the reader skipped for being cut short or malformed (not the IGMP, ARP and other non-UDP traffic a capture always holds). | |
| std::string | error () const |
| What stopped the reader, empty when nothing did. Any thread. | |
| uint64_t | read_ts_ns () const |
| Capture time of the last packet the reader has merged, nanoseconds. Any thread. | |
| bool | peek (Item &item) |
| The next packet, without consuming it. | |
| void | pop () |
| Consumes the packet peek() returned. Consumer thread. | |
| bool | finished () |
| True when every packet has been consumed and the reader will add none. | |
Replays several captured multicast groups as one packet stream in capture-time order.
A reader thread decodes the capture files, merges the lines by timestamp, and hands batches to the exchange thread through a bounded lock-free ring (slick::spsc_queue). The reader waits when the ring is full, so a consumer that stops draining (a replay waiting for its client to start it) holds the capture where it is and loses nothing, unlike the lossy live-feed queue.
The consumer looks at the next packet with peek() before taking it with pop(), so a pacer can hold a packet back until its time. Both are for one thread, and the rest of the interface may be called from any thread.
Only packets with begin_ns <= timestamp <= end_ns are replayed. Files of consecutive days overlap, so a line's next file skips everything up to the time its previous file reached, and nothing repeats.
Definition at line 85 of file pcap_replay_source.hpp.
|
inline |
root is only used for lines without explicit paths.
Definition at line 96 of file pcap_replay_source.hpp.
Referenced by PcapReplaySource(), and operator=().
|
inline |
Definition at line 110 of file pcap_replay_source.hpp.
References stop().
|
delete |
References PcapReplaySource().
|
inlinenodiscard |
What stopped the reader, empty when nothing did. Any thread.
Definition at line 145 of file pcap_replay_source.hpp.
|
inlinenodiscard |
True when every packet has been consumed and the reader will add none.
A failed reader ends the replay too: check error(). Consumer thread.
Definition at line 175 of file pcap_replay_source.hpp.
|
delete |
References PcapReplaySource().
|
inline |
The next packet, without consuming it.
False when none is ready; that is not the end of the replay, see finished(). Consumer thread.
Definition at line 154 of file pcap_replay_source.hpp.
References slick::sim::md_feed::PcapReplaySource::Item::data, slick::sim::md_feed::PcapReplaySource::Item::line, slick::sim::md_feed::PcapReplaySource::Item::size, and slick::sim::md_feed::PcapReplaySource::Item::ts_ns.
|
inline |
Consumes the packet peek() returned. Consumer thread.
Definition at line 167 of file pcap_replay_source.hpp.
|
inlinenodiscard |
True once every line has been read up to begin_ns and holds a first packet (or has none), so the replay is ready to produce.
Any thread.
Definition at line 133 of file pcap_replay_source.hpp.
|
inlinenodiscard |
Capture time of the last packet the reader has merged, nanoseconds. Any thread.
Definition at line 150 of file pcap_replay_source.hpp.
|
inlinenodiscard |
True when the reader has nothing more to add: the window is read out, or it failed (see error()).
Packets may still be queued. Any thread.
Definition at line 137 of file pcap_replay_source.hpp.
|
inline |
Starts reading.
Opening and positioning the files is slow (a zstd stream cannot be seeked), so it happens on the reader thread; watch positioned() and error().
Definition at line 117 of file pcap_replay_source.hpp.
|
inline |
Definition at line 124 of file pcap_replay_source.hpp.
Referenced by ~PcapReplaySource().
|
inlinenodiscard |
Frames the reader skipped for being cut short or malformed (not the IGMP, ARP and other non-UDP traffic a capture always holds).
A count worth reading when the replay has gaps. Any thread.
Definition at line 142 of file pcap_replay_source.hpp.