[Realization of stochastic flow model in environment building]mininet, 20180130

Source: Internet
Author: User

[Realization of stochastic flow model in environment building]mininet

This paper records how to Implement "Mininet topology of any host to the other host to randomly send a UDP data stream, and Iperf test results automatically saved to the file" method, in general, "for Mininet set a custom command to achieve the above function" Iperfmulti ' ".

    • 1. Adding custom functions and custom commands

    • Using the Nano Editor, open and edit the "***/mininet/net.py" file and enter the command:

Nano ***/mininet/net.py

      • Note: Because the personal mininet folder is located in a different directory, the following text is used "* * *" to indicate the part of the path.

    • Add a custom Function "Iperf_single" to the class body of the "Mininet" class:

def iperf_single (Self,hosts=none, udpbw= ' 10M ', period=60, port=5001):

"" "Run Iperf between the 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 + ' "" Set the bandwidth size sent by UDP mode ""

Print "***start server***"

Server.cmd (Iperfargs + '-s-i 1 ' + ' >/home/zg/log/' + filename + ' & ') "" "1. In this edit server-side iperf command, add the required parameters; 2. Set Iperf The output of the command is saved to the path "" "

Print "***start client***"

Client.cmd (

Iperfargs + '-t ' + str (period) + '-C ' + server. IP () + ' + Bwargs

+ ' >/home/zg/log/' + ' client ' + filename + ' & ') "" "1. In this edit client's Iperf command, add the required parameters; 2. Set the path" "" of the output of the Iperf command to be saved

    • is part of the code "Mininet" in the "***/mininet/net.py" file:

    • Add the code for the custom Function "Iperf_single" to the class code of the "Mininet" class:

One thing to note is the indentation of the Python statement, such as,

There should be 4 spaces before "Def", and the statement under "Def" should also be indented correctly.

    • Add the custom command code "Iperfmulti" to the class body of the "Mininet" class:

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 been done"

    • Still note is the indentation of the Python statement.

    • After adding the code:

    • Save the "***/mininet/net.py" File and exit the Nano editor

Press "Ctrl+x" on the keyboard and the "Do I need to save" message appears below the editor.

    • Press "Y" key once, then press "ENTER" key again to save "***/mininet/net.py" File and Exit Nano Editor.

    • 2. Registering custom commands in the CLI class

      • Modify the "***/mininet/mininet/cli.py" file

        • Using the Nano Editor, open and edit the "***/mininet/mininet/cli.py" file and enter the command:

Nano ***/mininet/mininet/cli.py

    • To add code in the Nano editor:

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

    • Note: The code needs to be added to the class body of the "CLI" class.

    • Press "Ctrl+x", "Y" Key, "enter" button on the keyboard to save the "***/mininet/mininet/cli.py" File and exit the Nano editor.

    • 3. Registering a custom command with the corresponding execution function in the mininet execution interpreter

      • Modify the "***/mininet/bin/mn" file

        • Using the Nano Editor, open and edit the "***/mininet/bin/mn" file and enter the command:

Nano ***/mininet/bin/mn

    • Find "altspelling" and Add "Iperfmulti" and "Iperfmulti" Red box sections:

    • 4. Recompile mininet

      • Enter the command:

/***/mininet/util/install.sh-n

    • 5. How to use the custom command "Iperfmulti"

      • Command format: Iperfmulti < bandwidth >

        • For example:

Iperfmulti 150M

    • After entering the command and observing the terminal output "test has done" (e.g.), you can view the test results, the code of the previous custom function "Iperf_single" shows that the test results are saved under the directory "/home/zg/log".

    • Observe what files are in the "/home/zg/log" directory, using the following 2 commands:

Cd/home/zg/log

Ls

    • By the knowledge, the output of 4 files, respectively, corresponding to the Server1,server2,client1,client2 bandwidth test output file. Output 4 files is because the author uses the mininet default network topology to do experiments, the network only two hosts, the two hosts each time the server, the client, so there are two sets of output files.

    • To view Iperf test results, use the command "Cat < file name >", for example:

Cat 1.out

The results of the output are observed:

[Realization of stochastic flow model in environment building]mininet, 20180130

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.