(一)流量模拟:
为什么进行流量模拟
网络性能评估中一个巨大的挑战就是如何生成真实的网络流量,可以通过程序来创造人工的网络流量,通过建立测试化境来模拟真是的状况。
流量随机模型再Mininet的应用
流量随机模型:主机向在网络中的另一任意主机以等概率发送数据包。
使用mininet中的iperf工具在网络中生成UDP流量,iperf客户端传送数据流到iperf的服务端,由服务端接收并记录相关信息。我们需要实现的是将批处理流的自定义命令添加到mininet中,在mininet中使用此自定义命令,实现上述功能。
(二)自定义命令实现:
在Mininet中拓展自定义命令主要有4个步骤:
- 修改/mininet/net.py
- 修改/mininet/cli.py
- 修改/bin/mn
- 重新编译mininet核心文件:~/mininet/util/install.sh -n
1:修改net.py,添加到iperf方法后面,其中,iperf_single方法主要实现了两个主机之间的UDP带宽测试,并将测试结果存储在‘home/Desktop/result/’目录下。
iperfMulti则从H1开始,随机选取UDP数据流的发送对象,持续测试period时长,设置为60s。
net.py修改部分如下:
def iperf_single( self, hosts=None, udpBw='10M', period=60, port=5001):
""" Run iperf between two hosts using UDP and record communications.
hosts: list of hosts; if None, uses opposite hosts
returns: results two-element array of server and client speeds
"""
if not hosts:
return
else:
assert len( hosts ) == 2
client, server = hosts
filename = client.name[1:]+'.out'
output( '*** Iperf: testing bandwidth between ' )
output( "%s and %s\n" % ( client.name, server.name ) )
iperfArgs = 'iperf -u '
bwArgs = '-b ' + udpBw + ' '
print( "***start server***" )
server.cmd( iperfArgs + '-s -i 1' + ' > /home/Desktop/result/' + filename + '&')
print( "***start client***" )
client.cmd( iperfArgs + '-t ' + str(period) + ' -c ' +server.IP() + ' ' + bwArgs +\
'> /home/Desktop/result/' + 'client' + filename + '&')
def iperfMulti( self, bw, period=60 ):
base_port = 5001
server_list = []
host_list = [h for h in self.hosts]
_len = len(host_list)
for i in range(0, _len):
client = host_list[i]
server = client
while( server == client ):
server = random.choice(host_list)
server_list.append(server)
self.iperf_single(hosts=[client,server],udpBw=bw,period=period,port=base_port)
sleep(.05)
base_port += 1
sleep(period)
print("test has done")
2:修改cli.py,添加到do_iperfudp方法后面
def do_iperfmulti( self, line ):
"""
Multi iperf UDP test between nodes
"""
args = line.split()
if len(args) == 1:
udpBw = args[0]
self.mn.iperfMulti(udpBw)
elif len(args) == 2:
udpBw = args[0]
period = args[1]
self.mn.iperfMulti(udpBw,float(period))
else:
error( 'invalid number of args: iperfMulti udpBw period\n '+
'udpBw examples:1M 120\n' )
3:修改mn,进入mininet/mn目录下,修改mn文件,将iperfmulti加入TEST和ALTSPELLING列表中。(mn中已经存在了TEST和ALTSPLLING,我们要做的是把自定义的命令添加进去)
# TESTS dict can contain functions and/or Mininet() method names
# XXX: it would be nice if we could specify a default test, but
# this may be tricky
TESTS = { name: True
for name in ( 'pingall', 'pingpair', 'iperf', 'iperfudp', 'iperfmulti' ) }
# Map to alternate spellings of Mininet() methods
ALTSPELLING = { 'pingall': 'pingAll', 'pingpair': 'pingPair',
'iperfudp': 'iperfUdp', 'iperfmulti': 'iperfMulti' }
4:重新编译只需要把编译的模式设置为 -n (只重新编译mininet的配置文件,不用重新编译其他的文件)
~/mininet/util/install.sh -n
编译完成之后就可以使用iperfmulti命令进行流量模拟!
(三)网络测试
1:运行RYU控制器和网络拓扑
ryu-manager simple_switch_stp_13.py
python final.py
2:使用iperfmulti进行流量模拟
iperfmulti 0.025M
3:生成的结果在/home/Desktop/result目录下
即可查看流量日志!
参考:
[1] 山上有风景:https://www.cnblogs.com/ssyfj/
[2] Ryubook:http://osrg.github.io/ryu-book/en/html/
[3] Ryu官方文档:https://ryu.readthedocs.io/en/latest/
[4] 未来网络学院:https://www.bilibili.com/video/BV1ft4y1a7ip/?spm_id_from=333.337.search-card.all.click&vd_source=f8206d9b2ac93039311dbe9fdd0bcc87
[5]SDN实验(五)——Mininet多数据中心流量带宽实验_mininet 交换机实验-CSDN博客