Mininet多数据中心网络拓扑流量带宽实验

设备名称 软件环境
host1 mininet
host1 ryu controller
前提:
由于节省设备资源,vm我就开了一个利用host,系统ubuntu16.04,然后xshell远程
连接开两个窗口,一个窗口运行mininet,一个窗口运行ryu controller。

全文参考:SDNLAB 实验

可以直接用该平台做实验,我是在自己的虚拟机上操作,好处就是你自己做的时候经常会有意想不到出错的地方,更有体会

一、 实现iperfmulti功能生成多客户端随机产生UDP流量

步骤1 在Mininet目录下mininet/net.py文件中定义iperf_single()函数、添加自定义命令iperfmulti() 函数

iperf_single函数目的:是为两个主机之间进行iperf udp测试,并且在server端记录
def iperf_single( self,hosts=None, udpBw='10M', period=60, port=5001):
        """Run iperf between two hosts using UDP.
           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/tian01/log/' + filename + '&')
        print "***start client***"
        client.cmd(
            iperfArgs + '-t '+ str(period) + ' -c ' + server.IP() + ' ' + bwArgs
            +' > /home/tian01/log/' + 'client' + filename +'&')

tips:
值得注意的是这里的 /home/tian01/log提前要有的,你自己可以选一个已经存在的目录

def iperfMulti(self, bw, period=60):
    base_port = 5001
    server_list = []
    client_list = [h for h in self.hosts]
    host_list = []
    host_list = [h for h in self.hosts]

    cli_outs = []
    ser_outs = []

    _len = len(host_list)
    for i in xrange(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"
为mininet添加自定义命令iperfmulti,依次为每一台主机随机选择另一台主机作为iperf
的服务器端,通过调用iperf_single,自身以客户端身份按照指定参数发送UDP流,服务器生
成的报告以重定向的方式输出到文件中(就是刚刚/home/tian01/log),使用iperfmulti命
令,主机随机地向另一台主机发起一条恒定带宽的UDP数据流

步骤2 在Mininet目录下mininet/cli.py中注册iperfmulti命令

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 ]
        err = False
        self.mn.iperfMulti(udpBw, float(period))
    else:
        error('invalid number of args: iperfmulti udpBw period\n' +
               'udpBw examples: 1M 120\n')

步骤3 /usr/local/bin/mn加入iperfmulti可执行命令

先用whereis mn 命令查看命令所在位置

root@tian01-virtual-machine:/home/tian01/mininet/mininet# whereis mn
mn: /usr/local/bin/mn /usr/share/man/man1/mn.1

vim 打开修改如下即可

root@tian01-virtual-machine:/home/tian01/mininet/mininet# vim /usr/local/bin/mn
#Map to alternate spellings of Mininet() methods
ALTSPELLING = {
    
     'pingall': 'pingAll', 'pingpair': 'pingPair',
                'iperfudp': 'iperfUdp','iperfmulti':'iperfMulti'}

步骤4 进入mininet/util目录下重新编译mininet

root@tian01-virtual-machine:/home/tian01/mininet#./mininet/util/install.sh -n

步骤5 验证

在这里插入图片描述

	输入iperf 按TAB补全就能看到

二、多数据中心拓扑脚本代码

自定义topo的code文件要在/mininet/custom目录下,启动时也在该目录下

#!/usr/bin/python
"""Custom topology example
Adding the 'topos' dict with a key/value pair to generate our newly defined
topology enables one to pass in '--topo=mytopo' from the command line.
"""
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import RemoteController,CPULimitedHost
from mininet.link import TCLink
from mininet.util import dumpNodeConnections

class MyTopo( Topo ):
    "Simple topology example."

    def __init__( self ):
        "Create custom topo."

        # Initialize topology
        Topo.__init__( self )
        L1 = 2
        L2 = L1 * 2 
        L3 = L2
        c = []
        a = []
        e = []

        # add core ovs  
        for i in range( L1 ):
                sw = self.addSwitch( 'c{}'.format( i + 1 ) )
                c.append( sw )

        # add aggregation ovs
        for i in range( L2 ):
                sw = self.addSwitch( 'a{}'.format( L1 + i + 1 ) )
                a.append( sw )

        # add edge ovs
        for i in range( L3 ):
                sw = self.addSwitch( 'e{}'.format( L1 + L2 + i + 1 ) )
                e.append( sw )

        # add links between core and aggregation ovs
        for i in range( L1 ):
                sw1 = c[i]
                for sw2 in a[i/2::L1/2]:
                # self.addLink(sw2, sw1, bw=10, delay='5ms', loss=10, max_queue_size=1000, use_htb=True)
                        self.addLink( sw2, sw1 )

        # add links between aggregation and edge ovs
        for i in range( 0, L2, 2 ):
                for sw1 in a[i:i+2]:
                    for sw2 in e[i:i+2]:
                        self.addLink( sw2, sw1 )

        #add hosts and its links with edge ovs
        count = 1
        for sw1 in e:
                for i in range(2):
                    host = self.addHost( 'h{}'.format( count ) )
                    self.addLink( sw1, host )
                    count += 1
topos = {
    
     'mytopo': ( lambda: MyTopo() ) }

三、数据中心拓扑脚本执行

tips:一个窗口吧ryu controller 开启,一个窗口进行mininet的这个实验哦!

root@tian01-virtual-machine:/home/tian01/mininet/custom# mn --custom fattree.py --topo mytopo --controller=remote,ip=127.0.0.1,port=6633
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2 h3 h4 h5 h6 h7 h8 
*** Adding switches:
a3 a4 a5 a6 c1 c2 e7 e8 e9 e10 
*** Adding links:
(a3, c1) (a3, c2) (a4, c1) (a4, c2) (a5, c1) (a5, c2) (a6, c1) (a6, c2) (e7, a3) (e7, a4) (e7, h1) (e7, h2) (e8, a3) (e8, a4) (e8, h3) (e8, h4) (e9, a5) (e9, a6) (e9, h5) (e9, h6) (e10, a5) (e10, a6) (e10, h7) (e10, h8) 
*** Configuring hosts
h1 h2 h3 h4 h5 h6 h7 h8 
*** Starting controller
c0 
*** Starting 10 switches
a3 a4 a5 a6 c1 c2 e7 e8 e9 e10 ...
*** Starting CLI:

四、数据中心拓扑网络测试—TCP带宽测试

	没有演示,自行实验

五、数据中心拓扑网络测试—iperfmulti UDP测试

	这里我也设置带宽参数为0.025M
mininet> pingall
*** Ping: testing ping reachability
h1 -> X X X X X X X 
h2 -> X X h4 h5 h6 h7 h8 
h3 -> h1 h2 h4 h5 h6 h7 h8 
h4 -> h1 h2 h3 h5 h6 h7 h8 
h5 -> h1 h2 h3 h4 h6 h7 h8 
h6 -> h1 h2 h3 h4 h5 h7 h8 
h7 -> h1 h2 h3 h4 h5 h6 h8 
h8 -> h1 h2 h3 h4 h5 h6 h7 
*** Results: 16% dropped (47/56 received)
mininet> pingall
*** Ping: testing ping reachability
h1 -> h2 h3 h4 h5 h6 h7 h8 
h2 -> h1 h3 h4 h5 h6 h7 h8 
h3 -> h1 h2 h4 h5 h6 h7 h8 
h4 -> h1 h2 h3 h5 h6 h7 h8 
h5 -> h1 h2 h3 h4 h6 h7 h8 
h6 -> h1 h2 h3 h4 h5 h7 h8 
h7 -> h1 h2 h3 h4 h5 h6 h8 
h8 -> h1 h2 h3 h4 h5 h6 h7 
*** Results: 0% dropped (56/56 received)
mininet> iperfmulti 0.025M
*** Iperf: testing bandwidth between h1 and h6
***start server***
***start client***
*** Iperf: testing bandwidth between h2 and h1
***start server***
***start client***
*** Iperf: testing bandwidth between h3 and h5
***start server***
***start client***
*** Iperf: testing bandwidth between h4 and h5
***start server***
***start client***
*** Iperf: testing bandwidth between h5 and h4
***start server***
***start client***
*** Iperf: testing bandwidth between h6 and h2
***start server***
***start client***
*** Iperf: testing bandwidth between h7 and h2
***start server***
***start client***
*** Iperf: testing bandwidth between h8 and h3
***start server***
***start client***
test has done

六、查看记录

请自行查看,我放在/home/tian01/log下
root@tian01-virtual-machine:/home/tian01/mininet/custom# cd /home/tian01/log/
root@tian01-virtual-machine:/home/tian01/log# ls
1.out  3.out  5.out  7.out  client1.out  client3.out  client5.out  client7.out
2.out  4.out  6.out  8.out  client2.out  client4.out  client6.out  client8.out
root@tian01-virtual-machine:/home/tian01/log# 

猜你喜欢

转载自blog.csdn.net/weixin_46239293/article/details/113394544
今日推荐