Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
Loading...
Searching...
No Matches
slick::sim::md_feed::PcapReplaySource Class Reference

Replays several captured multicast groups as one packet stream in capture-time order. More...

#include <md_feed/pcap_replay_source.hpp>

Collaboration diagram for slick::sim::md_feed::PcapReplaySource:

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.

Detailed Description

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.

Constructor & Destructor Documentation

◆ PcapReplaySource() [1/2]

slick::sim::md_feed::PcapReplaySource::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 )
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=().

◆ ~PcapReplaySource()

slick::sim::md_feed::PcapReplaySource::~PcapReplaySource ( )
inline

Definition at line 110 of file pcap_replay_source.hpp.

References stop().

◆ PcapReplaySource() [2/2]

slick::sim::md_feed::PcapReplaySource::PcapReplaySource ( const PcapReplaySource & )
delete

References PcapReplaySource().

Member Function Documentation

◆ error()

std::string slick::sim::md_feed::PcapReplaySource::error ( ) const
inlinenodiscard

What stopped the reader, empty when nothing did. Any thread.

Definition at line 145 of file pcap_replay_source.hpp.

◆ finished()

bool slick::sim::md_feed::PcapReplaySource::finished ( )
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.

◆ operator=()

PcapReplaySource & slick::sim::md_feed::PcapReplaySource::operator= ( const PcapReplaySource & )
delete

References PcapReplaySource().

◆ peek()

bool slick::sim::md_feed::PcapReplaySource::peek ( Item & item)
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.

◆ pop()

void slick::sim::md_feed::PcapReplaySource::pop ( )
inline

Consumes the packet peek() returned. Consumer thread.

Definition at line 167 of file pcap_replay_source.hpp.

◆ positioned()

bool slick::sim::md_feed::PcapReplaySource::positioned ( ) const
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.

◆ read_ts_ns()

uint64_t slick::sim::md_feed::PcapReplaySource::read_ts_ns ( ) const
inlinenodiscard

Capture time of the last packet the reader has merged, nanoseconds. Any thread.

Definition at line 150 of file pcap_replay_source.hpp.

◆ reader_done()

bool slick::sim::md_feed::PcapReplaySource::reader_done ( ) const
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.

◆ start()

void slick::sim::md_feed::PcapReplaySource::start ( )
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.

◆ stop()

void slick::sim::md_feed::PcapReplaySource::stop ( )
inline

Definition at line 124 of file pcap_replay_source.hpp.

Referenced by ~PcapReplaySource().

◆ truncated_frames()

uint64_t slick::sim::md_feed::PcapReplaySource::truncated_frames ( ) const
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.


The documentation for this class was generated from the following file: