28#include <boost/endian.hpp>
169 private boost::noncopyable
238 static_assert(std::numeric_limits<flow_port_t>::is_integer
239 && (!std::numeric_limits<flow_port_t>::is_signed),
240 "Ports are non-negative integers.");
274 template<
typename Low_lvl_packet_sub>
285 template<
typename Low_lvl_packet_sub>
368 static const std::string&
type_id_to_str(
const std::type_index& type_id);
415 virtual std::ostream&
to_ostream(std::ostream& os,
bool verbose =
false)
const;
439 private boost::noncopyable
533 bool prefer_no_move,
util::Blob* raw_packet) = 0;
605 static_assert(std::numeric_limits<Sequence_number::seq_num_t>::is_integer
606 && (!std::numeric_limits<Sequence_number::seq_num_t>::is_signed),
607 "Raw sequence numbers are non-negative integers.");
628 friend boost::shared_ptr<Syn_packet> Low_lvl_packet::create_uninit_packet<Syn_packet>(
log::Logger*);
651 std::ostream&
to_ostream(std::ostream& os,
bool verbose)
const override;
665 bool prefer_no_move,
util::Blob* raw_packet)
override;
715 static_assert(std::numeric_limits<Sequence_number::seq_num_t>::is_integer
716 && (!std::numeric_limits<Sequence_number::seq_num_t>::is_signed),
717 "Raw sequence numbers are non-negative integers.");
718 static_assert(std::numeric_limits<security_token_t>::is_integer
719 && (!std::numeric_limits<security_token_t>::is_signed),
720 "Security tokens are non-negative integers.");
721 static_assert(std::numeric_limits<rcv_wnd_t>::is_integer
722 && (!std::numeric_limits<rcv_wnd_t>::is_signed),
723 "rcv_wnd values are non-negative integers.");
744 friend boost::shared_ptr<Syn_ack_packet> Low_lvl_packet::create_uninit_packet<Syn_ack_packet>(
log::Logger*);
767 std::ostream&
to_ostream(std::ostream& os,
bool verbose)
const override;
781 bool prefer_no_move,
util::Blob* raw_packet)
override;
814 static_assert(std::numeric_limits<security_token_t>::is_integer
815 && (!std::numeric_limits<security_token_t>::is_signed),
816 "Security tokens are non-negative integers.");
817 static_assert(std::numeric_limits<rcv_wnd_t>::is_integer
818 && (!std::numeric_limits<rcv_wnd_t>::is_signed),
819 "rcv_wnd values are non-negative integers.");
840 friend boost::shared_ptr<Syn_ack_ack_packet> Low_lvl_packet::create_uninit_packet<Syn_ack_ack_packet>(
log::Logger*);
863 std::ostream&
to_ostream(std::ostream& os,
bool verbose)
const override;
877 bool prefer_no_move,
util::Blob* raw_packet)
override;
936 static_assert(std::numeric_limits<Sequence_number::seq_num_t>::is_integer
937 && (!std::numeric_limits<Sequence_number::seq_num_t>::is_signed),
938 "Raw sequence numbers are non-negative integers.");
939 static_assert(std::numeric_limits<rexmit_id_t>::is_integer
940 && (!std::numeric_limits<rexmit_id_t>::is_signed),
941 "Retransmission IDs are non-negative integers.");
962 friend boost::shared_ptr<Data_packet> Low_lvl_packet::create_uninit_packet<Data_packet>(
log::Logger*);
985 std::ostream&
to_ostream(std::ostream& os,
bool verbose)
const override;
999 bool prefer_no_move,
util::Blob* raw_packet)
override;
1065 static_assert(std::numeric_limits<rcv_wnd_t>::is_integer
1066 && (!std::numeric_limits<rcv_wnd_t>::is_signed),
1067 "rcv_wnd values are non-negative integers.");
1149 friend boost::shared_ptr<Ack_packet> Low_lvl_packet::create_uninit_packet<Ack_packet>(
log::Logger*);
1172 std::ostream&
to_ostream(std::ostream& os,
bool verbose)
const override;
1186 bool prefer_no_move,
util::Blob* raw_packet)
override;
1200 using Ptr = boost::shared_ptr<Individual_ack>;
1237#pragma pack(push, 1)
1264 static_assert(std::numeric_limits<Sequence_number::seq_num_t>::is_integer
1265 && (!std::numeric_limits<Sequence_number::seq_num_t>::is_signed),
1266 "Raw sequence numbers are non-negative integers.");
1267 static_assert(std::numeric_limits<ack_delay_t>::is_integer
1268 && (!std::numeric_limits<ack_delay_t>::is_signed),
1269 "Time periods are non-negative integers.");
1296 static_assert(std::numeric_limits<rexmit_id_t>::is_integer
1297 && (!std::numeric_limits<rexmit_id_t>::is_signed),
1298 "Retransmission IDs are non-negative integers.");
1356 friend boost::shared_ptr<Rst_packet> Low_lvl_packet::create_uninit_packet<Rst_packet>(
log::Logger*);
1382 bool prefer_no_move,
util::Blob* raw_packet)
override;
1387template<
typename Low_lvl_packet_sub>
1390 using boost::shared_ptr;
1395 return shared_ptr<Low_lvl_packet_sub>(
new Low_lvl_packet_sub(logger));
1398template<
typename Low_lvl_packet_sub>
1406 using boost::endian::native_to_big;
1408 constexpr uint16_t TEST_VAL = 0x0102;
1409 return native_to_big(TEST_VAL) == TEST_VAL;
Convenience class that simply stores a Logger and/or Component passed into a constructor; and returns...
Interface that the user should implement, passing the implementing Logger into logging classes (Flow'...
An internal net_flow sequence number identifying a piece of data.
uint64_t seq_num_t
Raw sequence number type.
An empty interface, consisting of nothing but a default virtual destructor, intended as a boiler-plat...
Convenience class template that endows the given subclass T with nested aliases Ptr and Const_ptr ali...
static Ptr ptr_cast(const From_ptr &ptr_to_cast)
Provides syntactic-sugary way to perform a static_pointer_cast<> from a compatible smart pointer type...
boost::shared_ptr< Low_lvl_packet > Ptr
Short-hand for ref-counted pointer to mutable values of type Target_type::element_type (a-la T*).
Flow module containing the API and implementation of the Flow network protocol, a TCP-inspired stream...
uint16_t flow_port_t
Logical Flow port type (analogous to a UDP/TCP port in spirit but in no way relevant to UDP/TCP).
Blob_with_log_context<> Blob
A concrete Blob_with_log_context that compile-time-disables Basic_blob::share() and the sharing API d...
Fine_clock::duration Fine_duration
A high-res time duration as computed from two Fine_time_pts.
unsigned char uint8_t
Byte. Best way to represent a byte of binary data. This is 8 bits on all modern systems.
Specifies the outgoing (pre-serialization) acknowledgment of a single received Data_packet,...
const Sequence_number::seq_num_t m_seq_num_raw
See Individual_ack::m_seq_num and Sequence_number::raw_num_ref().
const ack_delay_t m_delay
See Individual_ack::m_delay; this is in Ack_delay_time_unit(1) multiples.
Individual_ack_rexmit_off(const Sequence_number &seq_num, ack_delay_t delay)
Constructs object.
Equivalent of Individual_ack_rexmit_off but for sockets with retransmission enabled.
Data_packet::rexmit_id_t m_rexmit_id
See Individual_ack::m_rexmit_id but note the type difference.
Individual_ack_rexmit_off m_basic_ack
Stores the values applicable to both Individual_ack_rexmit_off and Individual_ack_rexmit_on.
Individual_ack_rexmit_on(const Sequence_number &seq_num, unsigned int rexmit_id, ack_delay_t delay)
Constructs object.
Specifies the incoming (post-deserialization) acknowledgment of a single received Data_packet.
Individual_ack()=delete
Force direct member initialization even if no member is const.
Sequence_number m_seq_num
Sequence number of first datum in packet that we acknowledge.
void operator=(const Individual_ack &)=delete
Forbid copy assignment.
boost::shared_ptr< const Individual_ack > Const_ptr
Short-hand for ref-counted pointer to immutable objects of this class.
const Fine_duration m_delay
The delay between when we received the acknowledged packet and when decided to send this ack.
boost::shared_ptr< Individual_ack > Ptr
Short-hand for ref-counted pointer to mutable objects of this class.
const unsigned int m_rexmit_id
Retransmit counter of the acknowledged Data_packet.
Individual_ack(const Individual_ack &)=delete
Forbid copy construction.
Internal net_flow struct that encapsulates the Flow-protocol low-level ACK packet.
std::vector< boost::shared_ptr< Individual_ack > > m_rcv_acked_packets
List of incoming (post-deserialization of ACK) acknowledgments of DATA packets, each identified by it...
uint64_t ack_delay_t
Type used to store the ACK delay for a given individual acknowledged packet.
std::ostream & to_ostream(std::ostream &os, bool verbose) const override
Implements Low_lvl_packet API.
rcv_wnd_t m_rcv_wnd
Current receive window (remaining Receive buffer size) of the ACK sender.
bool deserialize_type_specific_data_from_raw_data_packet(Const_buffer *raw_buf, bool prefer_no_move, util::Blob *raw_packet) override
Implements Low_lvl_packet API.
size_t serialize_to_raw_data(Const_buffer_sequence *raw_bufs) const override
Implements Low_lvl_packet API.
static const uint8_t S_RAW_TYPE_ID
In serialized packet, the type ID byte identifying this as an ACK packet. Must not equal any other pa...
uint16_t m_rcv_acked_packets_rexmit_out_size
This is the serialized version of m_rcv_acked_packets_rexmit_{on|off}_out.size() and m_rcv_acked_pack...
Fine_duration Ack_delay_time_unit
Ack_delay_time_unit(1) is the duration corresponding to the ack_delay_t value 1; and proportionally f...
std::vector< Individual_ack_rexmit_on > m_rcv_acked_packets_rexmit_on_out
Equivalent of m_rcv_acked_packets_rexmit_off_out but for retransmission enabled.
Ack_packet(log::Logger *logger_ptr)
The implementation of Low_lvl_packet::create_uninit_packet() for this sub-type of Low_lvl_packet.
std::vector< Individual_ack_rexmit_off > m_rcv_acked_packets_rexmit_off_out
Equivalent of m_rcv_acked_packets but used for outgoing (pre-serialization of ACK) acknowledgments an...
Internal net_flow struct that encapsulates the Flow-protocol low-level DATA packet.
uint16_t m_data_size_raw
This is the serialized version of m_data.size() (see m_data).
std::ostream & to_ostream(std::ostream &os, bool verbose) const override
Implements Low_lvl_packet API.
Data_packet(log::Logger *logger_ptr)
The implementation of Low_lvl_packet::create_uninit_packet() for this sub-type of Low_lvl_packet.
static const uint8_t S_RAW_TYPE_ID
In serialized packet, the type ID byte identifying this as a DATA packet. Must not equal any other pa...
Sequence_number m_seq_num
The sequence number of the first byte in the payload; i.e., of m_data.front(), a/k/a m_data[0].
uint8_t rexmit_id_t
Type used to store the retransmission count in DATA and ACK packets.
rexmit_id_t m_rexmit_id
Retransmit counter of the DATA packet being sent.
bool deserialize_type_specific_data_from_raw_data_packet(Const_buffer *raw_buf, bool prefer_no_move, util::Blob *raw_packet) override
Implements Low_lvl_packet API.
util::Blob m_data
The payload.
size_t serialize_to_raw_data(Const_buffer_sequence *raw_bufs) const override
Implements Low_lvl_packet API.
Helper data store type for storing binary data needed by serialize_to_raw_data(), when certains bits ...
uint8_t m_opt_rexmit_on_raw
This is the serialized version of the multi-byte bool Low_lvl_packet::m_opt_rexmit_on.
const uint16_t m_reserved2
Unused space reserved for future use, ensuring correct alignment of other fields and headers.
Aux_raw_data()
Constructs a mostly-uninitialized object, except for the const member(s), if any.
A simple, unmodifiable data store that contains the properties unique to each packet type a/k/a concr...
const uint8_t m_raw_type_id
The type ID value, in serialized order, to be used in each serialization of all packets of this type.
const std::string m_type_id_str
The brief string representation of this packet type, suitable for Low_lvl_packet::type_id_to_str().
Internal net_flow struct that encapsulates the Flow-protocol low-level packet structure and serves as...
uint32_t rcv_wnd_t
Type used to store the size of m_rcv_wnd member in a couple of different packet types.
static boost::shared_ptr< Low_lvl_packet_sub > create_uninit_packet(log::Logger *logger_ptr)
Constructs packet with uninitialized (essentially random) values, of the Low_lvl_packet sub-type spec...
uint8_t rexmit_id_t
Type used to store the retransmission count in DATA and ACK packets.
Aux_raw_data m_aux_raw_data
Auxilliary data area necessary for serialize_to_raw_data() to work.
static Ptr create_from_raw_data_packet(log::Logger *logger_ptr, util::Blob *raw_packet, bool prefer_no_move)
Constructs packet on the heap with values determined by the given raw binary data as presumably recei...
static const std::string & type_id_to_str(const std::type_index &type_id)
Returns a brief (a few characters) string description of the given packet type given as type_index(ty...
struct flow::net_flow::Low_lvl_packet::@7 m_packed
Packed group affected by #pragma pack.
virtual std::ostream & to_ostream(std::ostream &os, bool verbose=false) const
Writes a multi-line representation of *this to an output stream.
Low_lvl_packet(log::Logger *logger_ptr)
Constructs packet with uninitialized (essentially random) values.
static const boost::unordered_map< std::type_index, Packet_type_info > S_NATIVE_TYPE_ID_TO_PACKET_TYPE_INFO
Mapping from native typeid(), a/k/a packet type (for all possible packet types), to the set of proper...
static constexpr bool native_is_big_endian()
Returns true, at compile time, if and only if the native memory representation is big-endian,...
size_t serialize_to_raw_data_and_log(Const_buffer_sequence *raw_bufs) const
Identical to serialize_to_raw_data() but adds log-level-appropriate logging after the operation.
virtual bool deserialize_type_specific_data_from_raw_data_packet(Const_buffer *raw_buf, bool prefer_no_move, util::Blob *raw_packet)=0
virtual helper for create_from_raw_data_packet() that fills out the fields of *this that are not in L...
static Ptr create_uninit_packet_base(log::Logger *logger_ptr)
A simple convenience method that casts the result of create_uninit_packet() from shared_ptr<T>,...
static const uint8_t & type_id_native_to_raw(const std::type_info &type_id)
Helper that looks up the Packet_type_info::m_raw_type_id value for the given typeid(p),...
std::vector< Const_buffer > Const_buffer_sequence
Short-hand for sequence of immutable buffers; i.e., a sequence of 1 or more scattered areas in memory...
std::ostream & type_to_ostream(std::ostream &os) const
Writes a brief representation of typeid(*this) – i.e., the packet type (ACK, RST, etc....
flow_port_t m_dst_port
Flow-protocol port # of socket in receiving Node.
const Function< std::ostream &(std::ostream &)> m_type_ostream_manip
ostream manipulator (argument to ostream <<) that will output packet's type ("ACK",...
uint64_t security_token_t
Type used for m_security_token member of a couple different packet types.
const Function< std::ostream &(std::ostream &)> m_concise_ostream_manip
ostream manipulator (argument to ostream <<) that will output packet info suitable for TRACE log leve...
virtual size_t serialize_to_raw_data(Const_buffer_sequence *raw_bufs) const =0
Serializes the current logical packet data from *this into the given Const_buffer_sequence,...
boost::asio::const_buffer Const_buffer
Short-hand for boost.asio immutable buffer, which essentially is a pointer to and length of a memory ...
size_t serialize_common_header_to_raw_data(Const_buffer_sequence *raw_bufs) const
Helper for serialize_to_raw_data() implementations in sub-types that encodes the header common to all...
bool m_opt_rexmit_on
Option indicating whether this connection is using retransmission or not.
const Function< std::ostream &(std::ostream &)> m_verbose_ostream_manip
ostream manipulator (argument to ostream <<) that will output packet info suitable for DATA log level...
flow_port_t m_src_port
Flow-protocol port # of socket in sending Node.
Internal net_flow struct that encapsulates the Flow-protocol low-level RST packet.
size_t serialize_to_raw_data(Const_buffer_sequence *raw_bufs) const override
Implements Low_lvl_packet API.
Rst_packet(log::Logger *logger_ptr)
The implementation of Low_lvl_packet::create_uninit_packet() for this sub-type of Low_lvl_packet.
static const uint8_t S_RAW_TYPE_ID
In serialized packet, the type ID byte identifying this as an RST packet. Must not equal any other pa...
bool deserialize_type_specific_data_from_raw_data_packet(Const_buffer *raw_buf, bool prefer_no_move, util::Blob *raw_packet) override
Implements Low_lvl_packet API.
Internal net_flow struct that encapsulates the Flow-protocol low-level SYN_ACK_ACK packet.
std::ostream & to_ostream(std::ostream &os, bool verbose) const override
Implements Low_lvl_packet API.
bool deserialize_type_specific_data_from_raw_data_packet(Const_buffer *raw_buf, bool prefer_no_move, util::Blob *raw_packet) override
Implements Low_lvl_packet API.
struct flow::net_flow::Syn_ack_ack_packet::@9 m_packed
Packed group affected by #pragma pack.
rcv_wnd_t m_rcv_wnd
Same meaning as in Syn_ack_packet but applied to the essentially independent opposite traffic directi...
size_t serialize_to_raw_data(Const_buffer_sequence *raw_bufs) const override
Implements Low_lvl_packet API.
Syn_ack_ack_packet(log::Logger *logger_ptr)
The implementation of Low_lvl_packet::create_uninit_packet() for this sub-type of Low_lvl_packet.
security_token_t m_security_token
This must equal Syn_ack_packet m_security_token received in the packet to which *this is replying.
static const uint8_t S_RAW_TYPE_ID
In serialized packet, the type ID byte identifying this as a SYN_ACK_ACK. Must not equal any other pa...
Internal net_flow struct that encapsulates the Flow-protocol low-level SYN_ACK packet.
Sequence_number m_init_seq_num
Same meaning as Syn_packet::m_init_seq_num but applied to the essentially independent opposite traffi...
bool deserialize_type_specific_data_from_raw_data_packet(Const_buffer *raw_buf, bool prefer_no_move, util::Blob *raw_packet) override
Implements Low_lvl_packet API.
rcv_wnd_t m_rcv_wnd
Number of DATA payload bytes the sender of this packet would accept into its Receive buffer,...
Syn_ack_packet(log::Logger *logger_ptr)
The implementation of Low_lvl_packet::create_uninit_packet() for this sub-type of Low_lvl_packet.
security_token_t m_security_token
Random security token used during SYN_ACK-SYN_ACK_ACK.
size_t serialize_to_raw_data(Const_buffer_sequence *raw_bufs) const override
Implements Low_lvl_packet API.
std::ostream & to_ostream(std::ostream &os, bool verbose) const override
Implements Low_lvl_packet API.
struct flow::net_flow::Syn_ack_packet::@8 m_packed
Packed group affected by #pragma pack.
static const uint8_t S_RAW_TYPE_ID
In serialized packet, the type ID byte identifying this as a SYN_ACK. Must not equal any other packet...
Internal net_flow struct that encapsulates the Flow-protocol low-level SYN packet.
std::ostream & to_ostream(std::ostream &os, bool verbose) const override
Implements Low_lvl_packet API.
static const uint8_t S_RAW_TYPE_ID
In serialized packet, the type ID byte identifying this as a SYN packet. Must not equal any other pac...
Syn_packet(log::Logger *logger_ptr)
The implementation of Low_lvl_packet::create_uninit_packet() for this sub-type of Low_lvl_packet.
util::Blob m_serialized_metadata
Arbitrary serialized user-supplied metadata to send in SYN, where it can be deserialized by the user ...
bool deserialize_type_specific_data_from_raw_data_packet(Const_buffer *raw_buf, bool prefer_no_move, util::Blob *raw_packet) override
Implements Low_lvl_packet API.
Sequence_number m_init_seq_num
The Initial Sequence Number (ISN) of the sequence number line that the sender of this SYN will be usi...
size_t serialize_to_raw_data(Const_buffer_sequence *raw_bufs) const override
Implements Low_lvl_packet API.