JayBeams  0.1
Another project to have fun coding.
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
jb::itch5::mold_udp_pacer< clock_type > Class Template Reference

Send a sequence of raw ITCH-5.x messages as MoldUDP64 packets, trying to match the original time interval between messages. More...

#include <mold_udp_pacer.hpp>

Public Types

Type traits
typedef clock_type::time_point time_point
 The time point (specific time with respect to some epoch) type. More...
 
typedef clock_type::duration duration
 The duration (the difference between two time points) type. More...
 
typedef mold_udp_pacer_config config
 The configuration file. More...
 
typedef jb::itch5::short_string_field< mold_udp_protocol::session_id_sizesession_id_type
 The type used to represent session ids. More...
 

Public Member Functions

 mold_udp_pacer (config const &cfg=config(), session_id_type const &session_id=session_id_type())
 Initialize a MoldUDP pacer object. More...
 
template<typename message_sink_type , typename sleep_functor_type >
void handle_message (time_point ts, unknown_message const &msg, message_sink_type &sink, sleep_functor_type &sleeper)
 Process a raw ITCH-5.x message. More...
 
template<typename message_sink_type >
void flush (timestamp ts, message_sink_type &sink)
 Flush the current messages, if any. More...
 
template<typename message_sink_type >
void heartbeat (message_sink_type &sink)
 Send a heartbeat packet. More...
 

Private Member Functions

template<typename message_sink_type >
void coalesce (time_point recv_ts, unknown_message const &msg, timestamp ts, message_sink_type &sink)
 Add another message to the current queue, flushing first if necessary. More...
 
void fillup_header_fields ()
 Fill up the header for the MoldUDP64 packet. More...
 
template<typename message_sink_type >
void flush_impl (timestamp ts, message_sink_type &sink)
 Implement the flush() and hearbeat() member functions. More...
 
bool packet_full (std::uint16_t block_size) const
 Return true if the packet is too full to accept a new block of size block_size. More...
 

Private Attributes

jb::itch5::timestamp last_send_
 
duration max_delay_
 
int mtu_
 
char rawbuf [rawbufsize] = {0}
 
boost::asio::mutable_buffer packet_
 
std::size_t packet_size_
 
std::uint32_t first_block_
 
timestamp first_block_ts_
 
std::uint16_t block_count_
 

Static Private Attributes

static constexpr std::size_t rawbufsize = 65536
 

Detailed Description

template<typename clock_type = std::chrono::steady_clock>
class jb::itch5::mold_udp_pacer< clock_type >

Send a sequence of raw ITCH-5.x messages as MoldUDP64 packets, trying to match the original time interval between messages.

The MoldUDP64 protocol (see link below) allows transmission of ITCH-5.x messages over UDP. Multiple ITCH-5.x messages are packed into a single MoldUDP64 packet, which includes enough information to request retransmissions if needed.

This class receives a stream of raw ITCH-5.x messages and creates a stream of MoldUDP64 packets. It examines the original timestamps of the raw ITCH-5.x messages to pace the outgoing stream. When the original messages are sufficiently close in time they are assembled into a single large packet. If the messages are separated in time the class blocks until enough wall-clock time has elapsed.

Template Parameters
clock_typea dependency injection point to make this class testable. Normally the class is simply used with a std::chrono::steady_clock. Under test, it is convenient to be able to modify the results of the clock_type::now() function to exercise multiple scenarios.

References: http://www.nasdaqtrader.com/content/technicalsupport/specifications/dataproducts/moldudp64.pdf

Definition at line 43 of file mold_udp_pacer.hpp.

Member Typedef Documentation

◆ config

template<typename clock_type = std::chrono::steady_clock>
typedef mold_udp_pacer_config jb::itch5::mold_udp_pacer< clock_type >::config

The configuration file.

Definition at line 56 of file mold_udp_pacer.hpp.

◆ duration

template<typename clock_type = std::chrono::steady_clock>
typedef clock_type::duration jb::itch5::mold_udp_pacer< clock_type >::duration

The duration (the difference between two time points) type.

Definition at line 53 of file mold_udp_pacer.hpp.

◆ session_id_type

template<typename clock_type = std::chrono::steady_clock>
typedef jb::itch5::short_string_field<mold_udp_protocol::session_id_size> jb::itch5::mold_udp_pacer< clock_type >::session_id_type

The type used to represent session ids.

The MoldUDP64 protocol uses a 10-character identifier for the session id, different streams can be distinguished using this field in the protocol.

Definition at line 66 of file mold_udp_pacer.hpp.

◆ time_point

template<typename clock_type = std::chrono::steady_clock>
typedef clock_type::time_point jb::itch5::mold_udp_pacer< clock_type >::time_point

The time point (specific time with respect to some epoch) type.

Definition at line 50 of file mold_udp_pacer.hpp.

Constructor & Destructor Documentation

◆ mold_udp_pacer()

template<typename clock_type = std::chrono::steady_clock>
jb::itch5::mold_udp_pacer< clock_type >::mold_udp_pacer ( config const &  cfg = config(),
session_id_type const &  session_id = session_id_type() 
)
inline

Member Function Documentation

◆ coalesce()

template<typename clock_type = std::chrono::steady_clock>
template<typename message_sink_type >
void jb::itch5::mold_udp_pacer< clock_type >::coalesce ( time_point  recv_ts,
unknown_message const &  msg,
timestamp  ts,
message_sink_type &  sink 
)
inlineprivate

◆ fillup_header_fields()

template<typename clock_type = std::chrono::steady_clock>
void jb::itch5::mold_udp_pacer< clock_type >::fillup_header_fields ( )
inlineprivate

◆ flush()

template<typename clock_type = std::chrono::steady_clock>
template<typename message_sink_type >
void jb::itch5::mold_udp_pacer< clock_type >::flush ( timestamp  ts,
message_sink_type &  sink 
)
inline

Flush the current messages, if any.

Parameters
tsthe wall clock time when the message was received
sinkthe destination for the MoldUDP64 packets
Template Parameters
message_sink_typeplease see handle_message() for details

Definition at line 140 of file mold_udp_pacer.hpp.

References jb::itch5::mold_udp_pacer< clock_type >::block_count_, and jb::itch5::mold_udp_pacer< clock_type >::flush_impl().

Referenced by BOOST_AUTO_TEST_CASE(), jb::itch5::mold_udp_pacer< clock_type >::coalesce(), and jb::itch5::mold_udp_pacer< clock_type >::handle_message().

◆ flush_impl()

template<typename clock_type = std::chrono::steady_clock>
template<typename message_sink_type >
void jb::itch5::mold_udp_pacer< clock_type >::flush_impl ( timestamp  ts,
message_sink_type &  sink 
)
inlineprivate

◆ handle_message()

template<typename clock_type = std::chrono::steady_clock>
template<typename message_sink_type , typename sleep_functor_type >
void jb::itch5::mold_udp_pacer< clock_type >::handle_message ( time_point  ts,
unknown_message const &  msg,
message_sink_type &  sink,
sleep_functor_type &  sleeper 
)
inline

Process a raw ITCH-5.x message.

Parameters
tsthe wall-clock when the message was received, as defined by clock_type
msgthe message received, the timestamp in the message is used to pace the outgoing MoldUDP64 packets
sinka functor to send the MoldUDP64 packets
sleepera functor to sleep and effectively pace the messages
Template Parameters
message_sink_typethe type of the sink functor. The signature must be compatible with void(auto buffers) where buffers meets the requirements of a Boost.Asio ConstBufferSequence.
sleep_functor_typethe type of the sleeper function, the signature must be compatible with void(clock_type::duration const&)

Definition at line 105 of file mold_udp_pacer.hpp.

References jb::itch5::mold_udp_pacer< clock_type >::coalesce(), jb::itch5::unknown_message::count(), jb::itch5::unknown_message::decode_header(), jb::itch5::mold_udp_pacer< clock_type >::flush(), jb::itch5::mold_udp_pacer< clock_type >::last_send_, jb::itch5::mold_udp_pacer< clock_type >::max_delay_, jb::itch5::message_header::timestamp, and jb::itch5::timestamp::ts.

Referenced by BOOST_AUTO_TEST_CASE().

◆ heartbeat()

template<typename clock_type = std::chrono::steady_clock>
template<typename message_sink_type >
void jb::itch5::mold_udp_pacer< clock_type >::heartbeat ( message_sink_type &  sink)
inline

Send a heartbeat packet.

If there are any pending messages those messages are flushed and the resulting packet constitutes the heartbeat.

Parameters
sinkthe destination for the MoldUDP64 packets
Template Parameters
message_sink_typeplease see handle_message() for details

Definition at line 158 of file mold_udp_pacer.hpp.

References jb::itch5::mold_udp_pacer< clock_type >::first_block_ts_, and jb::itch5::mold_udp_pacer< clock_type >::flush_impl().

Referenced by BOOST_AUTO_TEST_CASE().

◆ packet_full()

template<typename clock_type = std::chrono::steady_clock>
bool jb::itch5::mold_udp_pacer< clock_type >::packet_full ( std::uint16_t  block_size) const
inlineprivate

Return true if the packet is too full to accept a new block of size block_size.

Parameters
block_sizethe size of the next block that we intend to add to the packet

Definition at line 246 of file mold_udp_pacer.hpp.

References jb::itch5::mold_udp_pacer< clock_type >::block_count_, jb::itch5::mold_udp_pacer< clock_type >::mtu_, and jb::itch5::mold_udp_pacer< clock_type >::packet_size_.

Referenced by jb::itch5::mold_udp_pacer< clock_type >::coalesce().

Member Data Documentation

◆ block_count_

template<typename clock_type = std::chrono::steady_clock>
std::uint16_t jb::itch5::mold_udp_pacer< clock_type >::block_count_
private

◆ first_block_

template<typename clock_type = std::chrono::steady_clock>
std::uint32_t jb::itch5::mold_udp_pacer< clock_type >::first_block_
private

◆ first_block_ts_

template<typename clock_type = std::chrono::steady_clock>
timestamp jb::itch5::mold_udp_pacer< clock_type >::first_block_ts_
private

◆ last_send_

template<typename clock_type = std::chrono::steady_clock>
jb::itch5::timestamp jb::itch5::mold_udp_pacer< clock_type >::last_send_
private

◆ max_delay_

template<typename clock_type = std::chrono::steady_clock>
duration jb::itch5::mold_udp_pacer< clock_type >::max_delay_
private

◆ mtu_

template<typename clock_type = std::chrono::steady_clock>
int jb::itch5::mold_udp_pacer< clock_type >::mtu_
private

◆ packet_

template<typename clock_type = std::chrono::steady_clock>
boost::asio::mutable_buffer jb::itch5::mold_udp_pacer< clock_type >::packet_
private

◆ packet_size_

template<typename clock_type = std::chrono::steady_clock>
std::size_t jb::itch5::mold_udp_pacer< clock_type >::packet_size_
private

◆ rawbuf

template<typename clock_type = std::chrono::steady_clock>
char jb::itch5::mold_udp_pacer< clock_type >::rawbuf[rawbufsize] = {0}
private

◆ rawbufsize

template<typename clock_type = std::chrono::steady_clock>
constexpr std::size_t jb::itch5::mold_udp_pacer< clock_type >::rawbufsize = 65536
staticprivate

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