网络流量控制 网络流量监控工具( 五 )

Linux4.x内核中拥塞算法扩展时参考struct,拥塞算法主要重写里面函数来实现:
struct tcp_congestion_ops {struct list_headlist;u32 key;u32 flags;/* initialize private data (optional) */void (*init)(struct sock *sk);/* cleanup private data(optional) */void (*release)(struct sock *sk);/* return slow start threshold (required) */u32 (*ssthresh)(struct sock *sk);/* do new cwnd calculation (required) */void (*cong_avoid)(struct sock *sk, u32 ack, u32 acked);/* call before changing ca_state (optional) */void (*set_state)(struct sock *sk, u8 new_state);/* call when cwnd event occurs (optional) */void (*cwnd_event)(struct sock *sk, enum tcp_ca_event ev);/* call when ack arrives (optional) */void (*in_ack_event)(struct sock *sk, u32 flags);/* new value of cwnd after loss (required) */u32(*undo_cwnd)(struct sock *sk);/* hook for packet ack accounting (optional) */void (*pkts_acked)(struct sock *sk, const struct ack_sample *sample);/* override sysctl_tcp_min_tso_segs */u32 (*min_tso_segs)(struct sock *sk);/* returns the multiplier used in tcp_sndbuf_expand (optional) */u32 (*sndbuf_expand)(struct sock *sk);/* call when packets are delivered to update cwnd and pacing rate,* after all the ca_state processing. (optional)*/void (*cong_control)(struct sock *sk, const struct rate_sample *rs);/* get info for inet_diag (optional) */size_t (*get_info)(struct sock *sk, u32 ext, int *attr,union tcp_cc_info *info);charname[TCP_CA_NAME_MAX];struct module*owner;};Linux4.x内核cubic算法重新如下函数来实现:
static struct tcp_congestion_ops cubictcp __read_mostly = {.init= bictcp_init,.ssthresh= bictcp_recalc_ssthresh,.cong_avoid = bictcp_cong_avoid,.set_state= bictcp_state,.undo_cwnd= tcp_reno_undo_cwnd,.cwnd_event = bictcp_cwnd_event,.pkts_acked= bictcp_acked,.owner= THIS_MODULE,.name= "cubic",};Linux 系统流量控制重要系统参数# 每个套接字所允许的最大缓冲区的大小net.core.optmem_max = 20480# 接收套接字缓冲区大小的缺省值(以字节为单位) 。net.core.rmem_default = 229376# 接收套接字缓冲区大小的最大值(以字节为单位) 。net.core.rmem_max = 16777216# socket监听的backlog(监听队列)上限net.core.somaxconn = 128# tcp默认拥塞算法net.ipv4.tcp_congestion_control = cubic# 是否开启tcp窗口扩大net.ipv4.tcp_window_scaling = 1# tcp内存大小区(以页为单位, 1页=4096字节), 3个数值分别为 low, pressure, high# low: tcp使用低于该值页数时不考虑释放内存, pressure: tcp使用内存大于该值则试图稳定其使用内存low以下# high: 允许tcp用排队缓存数据报文的页面量, 超过该值拒绝分配socket, 出现TCP: too many of orphaned socketsnet.ipv4.tcp_mem = 381705508942763410# tcp读缓存区(以字节为单位), 3个数值分别为 默认值 最小值 最大值net.ipv4.tcp_rmem = 102408738016777216# tcp写缓存区(以字节为单位), 3个数值分别为 默认值 最小值 最大值net.ipv4.tcp_wmem = 102408738016777216Referencehttps://tools.ietf.org/html/std7
https://datatracker.ietf.org/doc/html/rfc1122
https://datatracker.ietf.org/doc/html/rfc1323
https://datatracker.ietf.org/doc/html/rfc1379
https://datatracker.ietf.org/doc/html/rfc1948
https://datatracker.ietf.org/doc/html/rfc2018
https://datatracker.ietf.org/doc/html/rfc5681
https://datatracker.ietf.org/doc/html/rfc6247
https://datatracker.ietf.org/doc/html/rfc6298
https://datatracker.ietf.org/doc/html/rfc6824
https://datatracker.ietf.org/doc/html/rfc7323
https://datatracker.ietf.org/doc/html/rfc7414
https://en.wikipedia.org/wiki/Transmission_Control_Protocol
https://linuxgazette.net/135/pfeiffer.html
http://www.tcpipguide.com/free/t_TCPSlidingWindowDataTransferandAcknowledgementMech.htm
https://www2.tkn.tu-berlin.de/teaching/rn/animations/gbn_sr/
https://zhuanlan.zhihu.com/p/144273871
http://lxr.linux.no/linux+v3.2.8/Documentation/networking/ip-sysctl.txt#L464

推荐阅读