mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
General cleanup of the NewReno CC module (no functional changes):
- Remove superfluous includes and unhelpful comments. - Alphabetically order functions. - Make functions static. Sponsored by: FreeBSD Foundation MFC after: 9 weeks X-MFC with: r215166
This commit is contained in:
parent
e66a677b27
commit
74a5a1949e
1 changed files with 64 additions and 76 deletions
|
|
@ -52,41 +52,35 @@ __FBSDID("$FreeBSD$");
|
|||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/socketvar.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/systm.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_var.h>
|
||||
#include <net/vnet.h>
|
||||
|
||||
#include <netinet/cc.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_pcb.h>
|
||||
#include <netinet/tcp_seq.h>
|
||||
#include <netinet/tcp_var.h>
|
||||
|
||||
#include <netinet/cc/cc_module.h>
|
||||
|
||||
void newreno_ack_received(struct cc_var *ccv, uint16_t type);
|
||||
void newreno_cong_signal(struct cc_var *ccv, uint32_t type);
|
||||
void newreno_post_recovery(struct cc_var *ccv);
|
||||
void newreno_after_idle(struct cc_var *ccv);
|
||||
static void newreno_ack_received(struct cc_var *ccv, uint16_t type);
|
||||
static void newreno_after_idle(struct cc_var *ccv);
|
||||
static void newreno_cong_signal(struct cc_var *ccv, uint32_t type);
|
||||
static void newreno_post_recovery(struct cc_var *ccv);
|
||||
|
||||
struct cc_algo newreno_cc_algo = {
|
||||
.name = "newreno",
|
||||
.ack_received = newreno_ack_received,
|
||||
.after_idle = newreno_after_idle,
|
||||
.cong_signal = newreno_cong_signal,
|
||||
.post_recovery = newreno_post_recovery,
|
||||
.after_idle = newreno_after_idle
|
||||
};
|
||||
|
||||
/*
|
||||
* Increase cwnd on receipt of a successful ACK:
|
||||
* if cwnd <= ssthresh, increases by 1 MSS per ACK
|
||||
* if cwnd > ssthresh, increase by ~1 MSS per RTT
|
||||
*/
|
||||
void
|
||||
static void
|
||||
newreno_ack_received(struct cc_var *ccv, uint16_t type)
|
||||
{
|
||||
if (type == CC_ACK && !IN_RECOVERY(CCV(ccv, t_flags)) &&
|
||||
|
|
@ -153,67 +147,7 @@ newreno_ack_received(struct cc_var *ccv, uint16_t type)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* manage congestion signals
|
||||
*/
|
||||
void
|
||||
newreno_cong_signal(struct cc_var *ccv, uint32_t type)
|
||||
{
|
||||
u_int win;
|
||||
|
||||
win = max(CCV(ccv, snd_cwnd) / 2 / CCV(ccv, t_maxseg), 2) *
|
||||
CCV(ccv, t_maxseg);
|
||||
|
||||
switch (type) {
|
||||
case CC_NDUPACK:
|
||||
if (!IN_FASTRECOVERY(CCV(ccv, t_flags))) {
|
||||
if (!IN_CONGRECOVERY(CCV(ccv, t_flags)))
|
||||
CCV(ccv, snd_ssthresh) = win;
|
||||
ENTER_RECOVERY(CCV(ccv, t_flags));
|
||||
}
|
||||
break;
|
||||
case CC_ECN:
|
||||
if (!IN_CONGRECOVERY(CCV(ccv, t_flags))) {
|
||||
CCV(ccv, snd_ssthresh) = win;
|
||||
CCV(ccv, snd_cwnd) = win;
|
||||
ENTER_CONGRECOVERY(CCV(ccv, t_flags));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* decrease the cwnd in response to packet loss or a transmit timeout.
|
||||
* th can be null, in which case cwnd will be set according to reno instead
|
||||
* of new reno.
|
||||
*/
|
||||
void
|
||||
newreno_post_recovery(struct cc_var *ccv)
|
||||
{
|
||||
if (IN_FASTRECOVERY(CCV(ccv, t_flags))) {
|
||||
/*
|
||||
* Fast recovery will conclude after returning from this
|
||||
* function. Window inflation should have left us with
|
||||
* approximately snd_ssthresh outstanding data. But in case we
|
||||
* would be inclined to send a burst, better to do it via the
|
||||
* slow start mechanism.
|
||||
*
|
||||
* XXXLAS: Find a way to do this without needing curack
|
||||
*/
|
||||
if (SEQ_GT(ccv->curack + CCV(ccv, snd_ssthresh),
|
||||
CCV(ccv, snd_max)))
|
||||
CCV(ccv, snd_cwnd) = CCV(ccv, snd_max) -
|
||||
ccv->curack + CCV(ccv, t_maxseg);
|
||||
else
|
||||
CCV(ccv, snd_cwnd) = CCV(ccv, snd_ssthresh);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* if a connection has been idle for a while and more data is ready to be sent,
|
||||
* reset cwnd
|
||||
*/
|
||||
void
|
||||
static void
|
||||
newreno_after_idle(struct cc_var *ccv)
|
||||
{
|
||||
int rw;
|
||||
|
|
@ -240,5 +174,59 @@ newreno_after_idle(struct cc_var *ccv)
|
|||
CCV(ccv, snd_cwnd) = min(rw, CCV(ccv, snd_cwnd));
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform any necessary tasks before we enter congestion recovery.
|
||||
*/
|
||||
static void
|
||||
newreno_cong_signal(struct cc_var *ccv, uint32_t type)
|
||||
{
|
||||
u_int win;
|
||||
|
||||
win = max(CCV(ccv, snd_cwnd) / 2 / CCV(ccv, t_maxseg), 2) *
|
||||
CCV(ccv, t_maxseg);
|
||||
|
||||
switch (type) {
|
||||
case CC_NDUPACK:
|
||||
if (!IN_FASTRECOVERY(CCV(ccv, t_flags))) {
|
||||
if (!IN_CONGRECOVERY(CCV(ccv, t_flags)))
|
||||
CCV(ccv, snd_ssthresh) = win;
|
||||
ENTER_RECOVERY(CCV(ccv, t_flags));
|
||||
}
|
||||
break;
|
||||
case CC_ECN:
|
||||
if (!IN_CONGRECOVERY(CCV(ccv, t_flags))) {
|
||||
CCV(ccv, snd_ssthresh) = win;
|
||||
CCV(ccv, snd_cwnd) = win;
|
||||
ENTER_CONGRECOVERY(CCV(ccv, t_flags));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform any necessary tasks before we exit congestion recovery.
|
||||
*/
|
||||
static void
|
||||
newreno_post_recovery(struct cc_var *ccv)
|
||||
{
|
||||
if (IN_FASTRECOVERY(CCV(ccv, t_flags))) {
|
||||
/*
|
||||
* Fast recovery will conclude after returning from this
|
||||
* function. Window inflation should have left us with
|
||||
* approximately snd_ssthresh outstanding data. But in case we
|
||||
* would be inclined to send a burst, better to do it via the
|
||||
* slow start mechanism.
|
||||
*
|
||||
* XXXLAS: Find a way to do this without needing curack
|
||||
*/
|
||||
if (SEQ_GT(ccv->curack + CCV(ccv, snd_ssthresh),
|
||||
CCV(ccv, snd_max)))
|
||||
CCV(ccv, snd_cwnd) = CCV(ccv, snd_max) -
|
||||
ccv->curack + CCV(ccv, t_maxseg);
|
||||
else
|
||||
CCV(ccv, snd_cwnd) = CCV(ccv, snd_ssthresh);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DECLARE_CC_MODULE(newreno, &newreno_cc_algo);
|
||||
|
|
|
|||
Loading…
Reference in a new issue