29 m_bytes_per_time_smoothed(0),
30 m_bytes_per_time_less_smoothed(0),
31 m_bytes_this_sample(0),
33 m_no_samples_yet(true)
45 using boost::chrono::microseconds;
46 using boost::chrono::round;
47 using boost::chrono::ceil;
114 FLOW_LOG_TRACE(
"bw_est [" << sock <<
"] update: start first sample at 0 bytes.");
127 assert(since_sample_start.count() >= 0);
129 const Fine_duration& srtt = sock->m_snd_smoothed_round_trip_time;
131 if (srtt == Fine_duration::zero())
137 FLOW_LOG_WARNING(
"bw_est [" << sock <<
"] update: received acks but have no SRTT yet! This may be "
138 "a bug. Adding [" << sock->bytes_blocks_str(bytes) <<
"] to current sample "
140 "started [" << since_sample_start <<
"] ago.");
146 const Fine_duration sample_period_floor = sock->opt(sock->m_opts.m_st_snd_bandwidth_est_sample_period_floor);
147 const Fine_duration min_sample_period = max(srtt, sample_period_floor);
149 FLOW_LOG_TRACE(
"bw_est [" << sock <<
"] update: received acks; current sample "
151 "started [" << round<microseconds>(since_sample_start) <<
"] ago; "
152 "SRTT [" << round<microseconds>(srtt) <<
"]; "
153 "sample period floor [" << round<microseconds>(sample_period_floor) <<
"].");
155 if (since_sample_start > min_sample_period)
164 const n_bytes_t bytes_per_time_this_sample
175 FLOW_LOG_TRACE(
"bw_est [" << sock <<
"] update: first complete sample; bw_est = bw_est_less_smoothed "
176 "= [" << bytes_per_time_this_sample <<
"] bytes per [" <<
Time_unit(1) <<
"]"
177 "= [" << util::to_mbit_per_sec<Time_unit>(bytes_per_time_this_sample) <<
" Mbit/s]; "
178 "start new sample at 0 bytes.");
202 FLOW_LOG_TRACE(
"bw_est [" << sock <<
"] update: complete sample; "
203 "bw_est_less_smoothed "
204 "= filter[" << prev_bytes_per_time_less_smoothed <<
", " << bytes_per_time_this_sample <<
"] "
211 "units = bytes per [" <<
Time_unit(1) <<
"].");
226 FLOW_LOG_TRACE(
"bw_est [" << sock <<
"] update: received acks; sample "
228 "after increment by [" << sock->bytes_blocks_str(bytes) <<
"].");
235 return ((7 * prev_val) + new_sample_val) / 8;
Interface that the user should implement, passing the implementing Logger into logging classes (Flow'...
n_bytes_t m_bytes_this_sample
The number of bytes acknowledged by receiver since m_this_sample_start_time (the time when the curren...
n_bytes_t bandwidth_bytes_per_time() const
Returns the current estimate of the available outgoing bandwidth per unit time for the containing soc...
boost::chrono::milliseconds Time_unit
The primary time unit over which this class reports bandwidth.
static n_bytes_t apply_filter(n_bytes_t prev_val_per_time, n_bytes_t new_sample_val_per_time)
Applies the low-pass filter that takes the given previous result of the filter and blends in the give...
boost::weak_ptr< Peer_socket::Const_ptr::element_type > m_sock
The containing socket (read-only access).
uint64_t n_bytes_t
Type that represents the number of bytes, either as an absolute amount or over some time period.
Peer_socket::Const_ptr socket() const
Utility that returns a handle to the containing Peer_socket.
Fine_time_pt m_this_sample_start_time
The time at which the currently ongoing bandwidth sample began to accumulate.
bool m_no_samples_yet
true until a sample has been completed and fed into the filter; false forever thereafter.
Send_bandwidth_estimator(log::Logger *logger_ptr, Peer_socket::Const_ptr sock)
Constructs object by setting up logging and saving a pointer to the containing Peer_socket.
bool m_no_acks_yet
true until on_acks() called for the first time; false forever thereafter. Used to begin the sample se...
n_bytes_t m_bytes_per_time_less_smoothed
In the same units as m_bytes_per_time_smoothed, the less smoothed bandwidth estimate,...
n_bytes_t m_bytes_per_time_smoothed
The current smoothed bandwidth estimate, to be returned by bandwidth_bytes_per_time(),...
void on_acks(size_t bytes)
Informs the bandwidth estimator strategy that 1 or more previously sent packets whose status was In-f...
Const_target_ptr Const_ptr
Short-hand for ref-counted pointer to immutable values of type Target_type::element_type (a-la T cons...
#define FLOW_LOG_WARNING(ARG_stream_fragment)
Logs a WARNING message into flow::log::Logger *get_logger() with flow::log::Component get_log_compone...
#define FLOW_LOG_TRACE(ARG_stream_fragment)
Logs a TRACE message into flow::log::Logger *get_logger() with flow::log::Component get_log_component...
Flow module containing the API and implementation of the Flow network protocol, a TCP-inspired stream...
Flow_log_component
The flow::log::Component payload enumeration comprising various log components used by Flow's own int...
Fine_clock::duration Fine_duration
A high-res time duration as computed from two Fine_time_pts.