Skip to content

Commit

Permalink
[core] Renamed congestion control event handling functions
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Aug 9, 2021
1 parent 747f288 commit f0aa009
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 40 deletions.
52 changes: 31 additions & 21 deletions srtcore/congctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class LiveCC: public SrtCongestionControlBase
m_zSndAvgPayloadSize = m_zMaxPayloadSize;

m_iMinNakInterval_us = 20000; //Minimum NAK Report Period (usec)
m_iNakReportAccel = 2; //Default NAK Report Period (RTT) accelerator
m_iNakReportAccel = 2; //Default NAK Report Period (RTT) accelerator (send periodic NAK every RTT/2)

HLOGC(cclog.Debug, log << "Creating LiveCC: bw=" << m_llSndMaxBW << " avgplsize=" << m_zSndAvgPayloadSize);

Expand All @@ -92,11 +92,11 @@ class LiveCC: public SrtCongestionControlBase
// from receiving thread.
parent->ConnectSignal(TEV_SEND, SSLOT(updatePayloadSize));

/*
* Readjust the max SndPeriod onACK (and onTimeout)
*/
parent->ConnectSignal(TEV_CHECKTIMER, SSLOT(updatePktSndPeriod_onTimer));
parent->ConnectSignal(TEV_ACK, SSLOT(updatePktSndPeriod_onAck));
//
// Adjust the max SndPeriod onACK and onTimeout.
//
parent->ConnectSignal(TEV_CHECKTIMER, SSLOT(onRTO));
parent->ConnectSignal(TEV_ACK, SSLOT(onAck));
}

bool checkTransArgs(SrtCongestion::TransAPI api, SrtCongestion::TransDir dir, const char* , size_t size, int , bool ) ATR_OVERRIDE
Expand Down Expand Up @@ -153,17 +153,22 @@ class LiveCC: public SrtCongestionControlBase
HLOGC(cclog.Debug, log << "LiveCC: avg payload size updated: " << m_zSndAvgPayloadSize);
}

void updatePktSndPeriod_onTimer(ETransmissionEvent , EventVariant var)
/// @brief On RTO event update an inter-packet send interval.
/// @param arg EventVariant::STAGE to distinguish between INIT and actual RTO.
void onRTO(ETransmissionEvent , EventVariant var)
{
if ( var.get<EventVariant::STAGE>() != TEV_CHT_INIT )
if (var.get<EventVariant::STAGE>() != TEV_CHT_INIT )
updatePktSndPeriod();
}

void updatePktSndPeriod_onAck(ETransmissionEvent , EventVariant )
/// @brief Handle an incoming ACK event.
/// Mainly updates a send interval between packets relying on the maximum BW limit.
void onAck(ETransmissionEvent, EventVariant )
{
updatePktSndPeriod();
}

/// @brief Updates a send interval between packets relying on the maximum BW limit.
void updatePktSndPeriod()
{
// packet = payload + header
Expand Down Expand Up @@ -289,9 +294,9 @@ class FileCC : public SrtCongestionControlBase
m_dCWndSize = 16;
m_dPktSndPeriod = 1;

parent->ConnectSignal(TEV_ACK, SSLOT(updateSndPeriod));
parent->ConnectSignal(TEV_LOSSREPORT, SSLOT(slowdownSndPeriod));
parent->ConnectSignal(TEV_CHECKTIMER, SSLOT(speedupToWindowSize));
parent->ConnectSignal(TEV_ACK, SSLOT(onACK));
parent->ConnectSignal(TEV_LOSSREPORT, SSLOT(onLossReport));
parent->ConnectSignal(TEV_CHECKTIMER, SSLOT(onRTO));

HLOGC(cclog.Debug, log << "Creating FileCC");
}
Expand All @@ -305,10 +310,11 @@ class FileCC : public SrtCongestionControlBase
return true;
}

/// Tells if an early ACK is needed (before the next Full ACK happening every 10ms).
/// In FileCC, treat non-full-payload as an end-of-message (stream)
/// and request ACK to be sent immediately.
bool needsQuickACK(const CPacket& pkt) ATR_OVERRIDE
{
// For FileCC, treat non-full-buffer situation as an end-of-message situation;
// request ACK to be sent immediately.
if (pkt.getLength() < m_parent->maxPayloadSize())
{
// This is not a regular fixed size packet...
Expand All @@ -329,9 +335,10 @@ class FileCC : public SrtCongestionControlBase
}

private:

// SLOTS
void updateSndPeriod(ETransmissionEvent, EventVariant arg)
/// Handle icoming ACK event.
/// In slow start stage increase CWND. Leave slow start once maximum CWND is reached.
/// In congestion avoidance stage adjust inter packet send interval value to achieve maximum rate.
void onACK(ETransmissionEvent, EventVariant arg)
{
const int ack = arg.get<EventVariant::ACK>();

Expand Down Expand Up @@ -455,9 +462,10 @@ class FileCC : public SrtCongestionControlBase

}

// When a lossreport has been received, it might be due to having
// reached the available bandwidth limit. Slowdown to avoid further losses.
void slowdownSndPeriod(ETransmissionEvent, EventVariant arg)
/// When a lossreport has been received, it might be due to having
/// reached the available bandwidth limit. Slowdown to avoid further losses.
/// Leave the slow start stage if it was active.
void onLossReport(ETransmissionEvent, EventVariant arg)
{
const int32_t* losslist = arg.get_ptr();
size_t losslist_size = arg.get_len();
Expand Down Expand Up @@ -559,7 +567,9 @@ class FileCC : public SrtCongestionControlBase
}
}

void speedupToWindowSize(ETransmissionEvent, EventVariant arg)
/// @brief On retransmission timeout leave slow start stage if it was active.
/// @param arg EventVariant::STAGE to distinguish between INIT and actual RTO.
void onRTO(ETransmissionEvent, EventVariant arg)
{
ECheckTimerStage stg = arg.get<EventVariant::STAGE>();

Expand Down
38 changes: 19 additions & 19 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10899,21 +10899,21 @@ bool srt::CUDT::checkExpTimer(const steady_clock::time_point& currtime, int chec

void srt::CUDT::checkRexmitTimer(const steady_clock::time_point& currtime)
{
/* There are two algorithms of blind packet retransmission: LATEREXMIT and FASTREXMIT.
*
* LATEREXMIT is only used with FileCC.
* The mode is triggered when some time has passed since the last ACK from
* the receiver, while there is still some unacknowledged data in the sender's buffer,
* and the loss list is empty.
*
* FASTREXMIT is only used with LiveCC.
* The mode is triggered if the receiver does not send periodic NAK reports,
* when some time has passed since the last ACK from the receiver,
* while there is still some unacknowledged data in the sender's buffer.
*
* In case the above conditions are met, the unacknowledged packets
* in the sender's buffer will be added to loss list and retransmitted.
*/
// There are two algorithms of blind packet retransmission: LATEREXMIT and FASTREXMIT.
//
// LATEREXMIT is only used with FileCC.
// The RTO is triggered when some time has passed since the last ACK from
// the receiver, while there is still some unacknowledged data in the sender's buffer,
// and the loss list is empty at the moment of RTO (nothing to retransmit yet).
//
// FASTREXMIT is only used with LiveCC.
// The RTO is triggered if the receiver is not configured to send periodic NAK reports,
// when some time has passed since the last ACK from the receiver,
// while there is still some unacknowledged data in the sender's buffer.
//
// In case the above conditions are met, the unacknowledged packets
// in the sender's buffer will be added to the SND loss list and retransmitted.
//

const uint64_t rtt_syn = (m_iSRTT + 4 * m_iRTTVar + 2 * COMM_SYN_INTERVAL_US);
const uint64_t exp_int_us = (m_iReXmitCount * rtt_syn + COMM_SYN_INTERVAL_US);
Expand All @@ -10926,19 +10926,19 @@ void srt::CUDT::checkRexmitTimer(const steady_clock::time_point& currtime)
if (m_pSndBuffer->getCurrBufSize() <= 0)
return;

const bool is_laterexmit = m_CongCtl->rexmitMethod() == SrtCongestion::SRM_LATEREXMIT;
const bool is_fastrexmit = m_CongCtl->rexmitMethod() == SrtCongestion::SRM_FASTREXMIT;
const bool is_laterexmit = m_CongCtl->rexmitMethod() == SrtCongestion::SRM_LATEREXMIT; // FileCC
const bool is_fastrexmit = m_CongCtl->rexmitMethod() == SrtCongestion::SRM_FASTREXMIT; // LiveCC

// If the receiver will send periodic NAK reports, then FASTREXMIT (live) is inactive.
// TODO: Probably some method of "blind rexmit" MUST BE DONE, when TLPKTDROP is off.
if (is_fastrexmit && m_bPeerNakReport)
return;

// Schedule for retransmission IF:
// Schedule a retransmission IF:
// - there are packets in flight (getFlightSpan() > 0);
// - in case of LATEREXMIT (File Mode): the sender loss list is empty
// (the receiver didn't send any LOSSREPORT, or LOSSREPORT was lost on track).
// - in case of FASTREXMIT (Live Mode): there is the latency constraint, therefore
// - in case of FASTREXMIT (Live Mode): the RTO (rtt_syn) was triggered, therefore
// schedule unacknowledged packets for retransmission regardless of the loss list emptiness.
if (getFlightSpan() > 0 && (!is_laterexmit || m_pSndLossList->getLossLength() == 0))
{
Expand Down

0 comments on commit f0aa009

Please sign in to comment.