查看系统默认的发送缓存大小:
sysctl -a|grep net.ipv4.tcp_wmem
三个数值:
- 第一个值是socket的发送缓存区分配的最少字节数;
- 第二个值是默认值,缓存区在系统负载不重的情况下可以增 长到这个值;
- 第三个值是发送缓存区空间的最大字节数。
- 单位为B
该文件路径在
/proc/sys/net/ipv4
查看系统默认的接受缓存大小:
sudo sysctl -a|grep net.ipv4.tcp_rmem
修改缓存大小可使用命令:
sysctl -w net.core.rmem_max = 1048576
1. 首先验证发送缓存
脚本如下:
#!/usr/bin/env python
from mininet.net import Mininet
from mininet.cli import CLI
from mininet.link import Link, TCLink,Intf
from subprocess import Popen, PIPE
from mininet.log import setLogLevel
if '__main__' == __name__:
setLogLevel('info')
net = Mininet(link=TCLink)
key = "net.mptcp.mptcp_enabled"
value = 1
p = Popen("sysctl -w %s=%s" % (key, value), shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate()
print "stdout=",stdout,"stderr=", stderr
h1 = net.addHost('h1')
h2 = net.addHost('h2')
r1 = net.addHost('r1')
linkopt={'bw':10,'delay':'20ms'}
linkopt1={'bw':10,'delay':'5ms'}
linkopt2={'bw':10,'delay':'100ms'}
net.addLink(r1,h1,cls=TCLink, bw=10, delay='50ms', max_queue_size=100, loss=0.01)
net.addLink(r1,h1,cls=TCLink, bw=10, delay='50ms', max_queue_size=100, loss=0.01)
net.addLink(r1,h2,cls=TCLink, bw=10, delay='10ms', max_queue_size=100, loss=0.01)
net.addLink(r1,h2,cls=TCLink, bw=10, delay='10ms', max_queue_size=100, loss=0.01)
net.build()
r1.cmd("ifconfig r1-eth0 0")
r1.cmd("ifconfig r1-eth1 0")
r1.cmd("ifconfig r1-eth2 0")
r1.cmd("ifconfig r1-eth3 0")
h1.cmd("ifconfig h1-eth0 0")
h1.cmd("ifconfig h1-eth1 0")
h2.cmd("ifconfig h2-eth0 0")
h2.cmd("ifconfig h2-eth1 0")
r1.cmd("echo 1 > /proc/sys/net/ipv4/ip_forward")
r1.cmd("ifconfig r1-eth0 10.0.0.1 netmask 255.255.255.0")
r1.cmd("ifconfig r1-eth1 10.0.1.1 netmask 255.255.255.0")
r1.cmd("ifconfig r1-eth2 10.0.2.1 netmask 255.255.255.0")
r1.cmd("ifconfig r1-eth3 10.0.3.1 netmask 255.255.255.0")
h1.cmd("ifconfig h1-eth0 10.0.0.2 netmask 255.255.255.0")
h1.cmd("ifconfig h1-eth1 10.0.1.2 netmask 255.255.255.0")
h2.cmd("ifconfig h2-eth0 10.0.2.2 netmask 255.255.255.0")
h2.cmd("ifconfig h2-eth1 10.0.3.2 netmask 255.255.255.0")
h1.cmd("ip rule add from 10.0.0.2 table 1")
h1.cmd("ip rule add from 10.0.1.2 table 2")
h1.cmd("ip route add 10.0.0.0/24 dev h1-eth0 scope link table 1")
h1.cmd("ip route add default via 10.0.0.1 dev h1-eth0 table 1")
h1.cmd("ip route add 10.0.1.0/24 dev h1-eth1 scope link table 2")
h1.cmd("ip route add default via 10.0.1.1 dev h1-eth1 table 2")
h1.cmd("ip route add default scope global nexthop via 10.0.0.1 dev h1-eth0")
h2.cmd("ip rule add from 10.0.2.2 table 1")
h2.cmd("ip rule add from 10.0.3.2 table 2")
h2.cmd("ip route add 10.0.2.0/24 dev h2-eth0 scope link table 1")
h2.cmd("ip route add default via 10.0.2.1 dev h2-eth0 table 1")
h2.cmd("ip route add 10.0.3.0/24 dev h2-eth1 scope link table 2")
h2.cmd("ip route add default via 10.0.3.1 dev h2-eth1 table 2")
h2.cmd("ip route add default scope global nexthop via 10.0.2.1 dev h2-eth0")
CLI(net)
net.stop()
想要修改网络中参数大小,只需要修改22->25行,发送缓存与接收缓存可以用上述命令查看。因为有一台主机作为路由器,可以直接查看该主机缓存,得出网络内缓存占用大小的数据。调度器为默认调度器。
主机缓存占用问题
基于以上分析,可以通过设置不同接收缓存大小、RTT数值数值,来验证该问题,结果如下:
可以通过实验来说明该问题。实验的环境设置见第五章节,详细的命令、操作、实验脚本见附录。下面是实验结果:在其他环境一定的情况下,假设已经建立起两条子流。通过改变这两条子流的RTT和接收缓存大小,使用iperf测试吞吐率,可以得出以下吞吐量数据(以下数据均为五组实验取平均):
图3-1 接收缓存受限时MPTCP吞吐率下降
如图3-1所示: 两条路径的RTT差越大,需要更多的接收缓冲区来获得MPTCP的全带宽聚合的效果。