JayBeams  0.1
Another project to have fun coding.
mold_udp_pacer_config.cpp
Go to the documentation of this file.
2 
4 
5 #include <chrono>
6 #include <sstream>
7 #include <stdexcept>
8 
9 namespace jb {
10 namespace itch5 {
11 /// Default the default values for ITCH-5.x configuation.
12 namespace defaults {
13 
14 #ifndef JB_ITCH5_DEFAULTS_maximum_delay_microseconds
15 #define JB_ITCH5_DEFAULTS_maximum_delay_microseconds 100
16 #endif // JB_ITCH5_DEFAULTS_maximum_delay_microseconds
17 
18 /*
19  * Getting a good default for the MTU is hard. Most Ethernet networks
20  * can tolerate MTUs of 1500 octets. Including the minimum IPv4
21  * header (20 octets, 40 for IPv6), and the minimum UDP header (8) the
22  * usual recommendation is 1500 - 20 - 8 = 1472. But this is easily
23  * wrong as the UDP header can be as large as 60 octets, and the MTU
24  * may be significantly smaller (or larger!).
25  *
26  * The only guarantee is that all hosts should be prepared to accept
27  * datagrams of up to 576 octets:
28  * https://tools.ietf.org/html/rfc791
29  * effectively, 576 is the "minimum" value for the MTU.
30  *
31  * So the most conservative approach would be to limit our payload to
32  * 576 minus the largest headers that could exist. For IPv4 the
33  * maximum header is 60 bytes, so the limit would be:
34  *
35  * ConservativeMTU(IPv4) = 576 - 60 - 8 = 508
36  *
37  * for IPv6 the situation is a lot more complicated, as far as I can
38  * tell there is no limit for the IPv6 header.
39  */
40 #ifndef JB_ITCH5_DEFAULTS_maximum_transmission_unit
41 #define JB_ITCH5_DEFAULTS_maximum_transmission_unit 508
42 #endif // JB_ITCH5_DEFAULTS_maximum_transmission_unit
43 
46 
47 } // namespace defaults
48 
51  desc("maximum-delay-microseconds")
52  .help("Maximum time a MoldUDP packet is "
53  "delayed before sending it."),
56  desc("maximum-transmission-unit")
57  .help(
58  "Maximum MoldUDP message to be sent in a single UDP message. "
59  "The default value is extremely conservative. "
60  "If your Ethernet network is configured for an MTU of 1500, "
61  "use 1432 for this value. Beware of VLANs and other details "
62  "that may consume your available bytes."),
64 }
65 
67  // The UDP payload length is encoded in a 16-bit number, so no
68  // matter how clever your network the payload cannot exceed 1<<16 -
69  // 1. Well, with jumbograms you could go as big as 1<<32 - 1, but
70  // that is completely wrong for the type of data that MoldUDP64
71  // carries ...
72  int const max_udp_payload = (1 << 16) - 1;
74  static_cast<int>(mold_udp_protocol::header_size) or
75  maximum_transmission_unit() >= max_udp_payload) {
76  std::ostringstream os;
77  os << "--maximum-transimission-unit must be in the ["
78  << mold_udp_protocol::header_size << "," << max_udp_payload
79  << "] range, value=" << maximum_transmission_unit();
80  throw jb::usage{os.str(), 1};
81  }
82 
83  // ... a delay for more than 5 minutes makes no sense for this type
84  // of data ...
85  using namespace std::chrono;
86  auto const day_in_usecs = duration_cast<microseconds>(minutes(5));
87  if (maximum_delay_microseconds() <= 0 or
88  maximum_delay_microseconds() >= day_in_usecs.count()) {
89  std::ostringstream os;
90  os << "--maximum-delay-microseconds must be in the [0,"
91  << day_in_usecs.count()
92  << " (24 hours)] range, value=" << maximum_delay_microseconds();
93  throw jb::usage{os.str(), 1};
94  }
95 }
96 
97 } // namespace itch5
98 } // namespace jb
jb::config_attribute< mold_udp_pacer_config, int > maximum_delay_microseconds
Define defaults for program parameters.
#define JB_ITCH5_DEFAULTS_maximum_transmission_unit
void validate() const override
Validate the settings.
A simple class to communicate the result of parsing the options.
Definition: usage.hpp:11
#define JB_ITCH5_DEFAULTS_maximum_delay_microseconds
constexpr std::size_t header_size
The total size of the MoldUDP64 header.
jb::config_attribute< mold_udp_pacer_config, int > maximum_transmission_unit
The top-level namespace for the JayBeams library.
Definition: as_hhmmss.hpp:7