TCP拥塞控制算法内核实现剖析Word文档下载推荐.docx
- 文档编号:21707596
- 上传时间:2023-01-31
- 格式:DOCX
- 页数:42
- 大小:43.56KB
TCP拥塞控制算法内核实现剖析Word文档下载推荐.docx
《TCP拥塞控制算法内核实现剖析Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《TCP拥塞控制算法内核实现剖析Word文档下载推荐.docx(42页珍藏版)》请在冰豆网上搜索。
Maximal
window
to
advertise
*/
5.
rcv_ssthresh
Current
clamp
rcv_wnd
receiver
7.
8.
snd_wll
记录发送窗口更新时,造成窗口更新的那个数据报的第一个序号。
9.
*
它主要用于在下一次判断是否需要更新发送窗口。
10.
11.
Sequence
for
update
12.
snd_wnd
发送窗口的大小,直接取值于来自对方的数据报的TCP首部
13.
ever
seen
from
peer
记录来自对方通告的窗口的最大值
14.
First
byte
we
want
an
ack
发送窗口的左边沿
15.
max_window
snd_una
16.
17.
18.
Slow
start
and
congestion
control
19.
20.
snd_ssthresh
size
threshold
21.
snd_cwnd
Sending
22.
/*表示在当前的拥塞控制窗口中已经发送的数据段的个数*/
23.
snd_cwnd_cnt
Linear
increase
counter
24.
snd_cwnd_clamp
Do
not
allow
grow
above
this
25.
26.
mss_cache
cached
effective
mss
including
SACKS
27.
bytes_acked
Appropriate
Byte
Counting
-
RFC3465
28.
29.}
拥塞避免算法关键部分
1./*
In
theory
is
tp->
+=
1
/
(
or
alternative
w
)
2.void
tcp_cong_avoid_ai(struct
w)
if
>
{
<
snd_cwnd_clamp)
snd_cwnd++
0
}
else
++
11.}
12.EXPORT_SYMBOL_GPL(tcp_cong_avoid_ai)
慢启动算法
tcp_max_ssthresh参数的含义
tcp_max_ssthresh参数是实现RFC3742时引入的,离现在已经有4年的时间了。
07年5月内核实现了这个RFC。
但是,tcp的这个参数在内核文档(ip-sysctl.txt)中找不到任何的说明。
慢启动阶段,就是当前拥塞窗口值比慢启动阈值(snd_ssthresh)小的时候,所处的阶段就叫做慢启动阶段。
当我们收到一个新的ACK时,则会调用tcp_slow_start()这个函数,并且为拥塞窗口增加1.
(Linux中拥塞窗口的值代表数据包的个数,而不是实际的发送字节数目。
实际可以发送的字节数等于可以发送的数据包个数*MSS。
)
直到慢启动阶段出现数据包的丢失。
而引入了tcp_max_ssthresh
这个参数后,则可以控制在慢启动阶段拥塞窗口增加的频度。
默认这个参数不打开,如果这个参数的值设置为1000,则当拥塞窗口值大于1000时,
则没收到一个ACK,并不再增加拥塞窗口一个单位了,而是约收到2个ACK才增加一个窗口单位。
注意:
收到2ACK并不是决定值!
!
需要根据当前的拥塞窗口值,tcp_max_ssthresh值进行判断。
参见tcp.txt(documentation/networking)
Thefollowingvariablesareusedinthetcp_sockforcongestioncontrol:
snd_cwndThesizeofthecongestionwindow
snd_ssthreshSlowstartthreshold.Weareinslowstartifsnd_cwndislessthanthis.
snd_cwnd_cntAcounterusedtoslowdowntherateofincreaseonceweexceedslowstartthreshold.
snd_cwnd_clampThisisthemaximumsizethatsnd_cwndcangrowto.
snd_cwnd_stampTimestampforwhencongestionwindowlastvalidated.
snd_cwnd_usedUsedasahighwatermarkforhowmuchofthecongestionwindowisinuse.Itisusedtoadjustsnd_cwnddownwhenthelinkislimitedbytheapplicationratherthanthenetwork.
1.void
tcp_slow_start(
int
cnt
in
packets
5./*
:
ABC
slow
Increase
only
after
a
full
MSS
of
bytes
acked
TCP
sender
SHOULD
cwnd
by
the
number
previously
unacknowledged
ACKed
each
incoming
acknowledgment
provided
more
than
L
ack的数据少于MSS,tcp_abc默认关闭
sysctl_tcp_abc
&
mss_cached
16./*
当前拥塞窗口值大于sysctl_tcp_max_ssthresh.限制拥塞窗口增长值*/
sysctl_tcp_max_ssthresh
tcp->
sysctl_tcp_max_ssthresh)
limited
exponential
22./*
We
MAY
2
discovered
delayed
25./*
如果接收方启用了延时确认,此时收到的确认代表两个MSS数据报*/
26.if
2*tp->
29.tp->
30.tp->
此时snd_cwnd_cnt等于snd_cwnd或2*snd_cwnd
31.
32./*最多增加1/2sysctl_tcp_max_ssthresh字节。
也就是说,至少2个ACK才能让拥塞窗口增加1.*/
33.
while(
34.
-=
35.
if(
36.
37.
38.}
39.EXPORT_SYMBOL_GPL(
tcp_slow_start
1.2拥塞控制算法基础
1.2.1代表拥塞算法的结构体
1.#define
TCP_CA_NAME_MAX
16
2.struct
tcp_congestion_ops
list_head
list
unsigned
long
flags
initialize
private
data
(optional)
void
(*init)
cleanup
(*release)
(required)
(*ssthresh)
lower
bound
(*min_cwnd)
(const
do
new
calculation
(*cong_avoid)
*sk
in_flight
call
before
changing
ca_state
(*set_state)
u8
new_state)
when
event
occurs
(*cwnd_event)
enum
tcp_ca_event
ev)
value
loss
(*undo_cwnd)
hook
packet
accounting
(*pkts_acked)
num_acked
s32
rtt_us)
get
info
inet_diag
(*get_info)
ext
sk_buff
*skb)
char
name[TCP_CA_NAME_MAX]
module
*owner
27.}
在Tcp_cong.c中,有全局变量:
intsysctl_tcp_max_ssthresh=0;
/*defineDEFINE_SPINLOCK(x)spinlock_tx=__SPIN_LOCK_UNLOCKED(x)*/
staticDEFINE_SPINLOCK(tcp_cong_list_lock);
staticLIST_HEAD(tcp_cong_list);
//tcp拥塞控制算法链表,其元素为tcp_congestion_ops
/*
BUG_ON();
如果BUG_ON中的条件为真就调用BUG,它输出一些信息,然后调用panic函数挂起系统。
char*strncpy(char*dest,char*src,size_tn);
它与strcpy不同之处在于复制n个字符,而不是把所有的字符拷贝(包括结尾'
\0'
)。
当src的长度小于n时,dst内的未复制空间用'
填充。
否则,复制n个字符到dst,没有加'
。
这里就要注意在字符串dst结尾处理加'
的情况了。
rcu_read_lock()//读者在读取由RCU保护的共享数据时使用该函数标记它进入读端临界区。
rcu_read_unlock()//该函数与rcu_read_lock配对使用,用以标记读者退出读端临界区。
*/
1.2.2对拥塞控制算法的一些操作(读写增减注册等)
Get
current
default
tcp_get_default_congestion_control(
*name
*ca
will
always
have
reno
BUG_ON(
list_empty(
tcp_cong_list)
rcu_read_lock(
ca
list_entry(
tcp_cong_list
.
next
strncpy(
name
ca->
rcu_read_unlock(
12.}
structsock——representationofsockets
structinet_sock——representationofINETsockets
structinet_connection_sock——INETconnectionorientedsockets
structtcp_sock——tcpsockets
以上几种socket越分越细,比如inet_connection_sock是在inet_sock上的扩展,具有自己特有的属性。
tcp_sock是TCP协议专用的一个socket表示,它是在structinet_connection_sock基础进行扩展,主要是增加了滑动窗口协议,避免拥塞算法等一些TCP专有属性。
inet_connection_sock
2.
//
Pluggable
const
*icsk_ca_ops
icsk_ca_priv[16]
8.#define
ICSK_CA_PRIV_SIZE
(16*sizeof(u32))
9.}
举例:
//有一个初始化了得structsock*sk
structinet_connection_sock*icsk=inet_csk(sk);
printk(KERN_INFO"
%s"
icsk->
icsk_ca_ops->
name);
//当前连接拥塞控制算法名称
inet_sock
Socket
demultiplex
comparisons
on
__be32
inet_daddr
__be16
inet_dport
inet_saddr
inet_sport
inet_num
local
port
inet_rcv_saddr
Bound
IPv4
addr
Built
non-restricted
values*/
tcp_get_allowed_congestion_control(
*buf
size_t
maxlen)
offs
'
//有必要?
rcu_read_lock()
list_for_each_entry(
!
TCP_CONG_NON_RESTRICTED))
//排除有限制的。
限制和非限制区别?
continue;
snprintf(
buf+offs
maxlen-offs
"
%s%s"
==
0?
name)
rcu_read_unlock()
14.}
Simple
linear
search
don'
t
expect
many
entries!
tcp_congestion_ops*tcp_ca_find(
*name)
*e
list_for_each_entry_rcu(
e
strcmp(e->
name)==0)
NULL
10.}
Attach
algorith
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- TCP 拥塞 控制 算法 内核 实现 剖析
![提示](https://static.bdocx.com/images/bang_tan.gif)