Mininet multi-data center network topology traffic bandwidth experiment

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

Full text reference: SDNLAB experiment

You can directly use the platform to do experiments. I operate on my own virtual machine. The advantage is that when you do it yourself, there are often unexpected mistakes, and you have more experience

1. Realize the iperfmulti function to generate multiple clients and randomly generate UDP traffic

Step 1 Define the iperf_single() function and add the custom command iperfmulti() function in the mininet/net.py file in the Mininet directory

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:
It is worth noting here/home/tian01/logIf you want to have it in advance, you can choose an existing directory yourself

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数据流

Step 2 Register the iperfmulti command in mininet/cli.py in the Mininet directory

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')

Step 3: Add iperfmulti executable command to /usr/local/bin/mn

First use the whereis mn command to view the location of the command

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

vim can be opened and modified as follows

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'}

Step 4 Enter the mininet/util directory to recompile mininet

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

Step 5 verification

Insert picture description here

	输入iperf 按TAB补全就能看到

2. Multi-data center topology script code

The code file of the custom topo should be in the /mininet/custom directory, and also in this directory when starting

#!/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() ) }

Three, data center topology script execution

Tips: Open the ryu controller in one window, and perform the mininet experiment in one window!

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:

4. Data center topology network test-TCP bandwidth test

	没有演示,自行实验

5. Data center topology network test-iperfmulti UDP test

	这里我也设置带宽参数为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

Six, view records

请自行查看,我放在/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# 

Guess you like

Origin blog.csdn.net/weixin_46239293/article/details/113394544