[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 ' ".
Nano ***/mininet/net.py
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
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.
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"
Press "Ctrl+x" on the keyboard and the "Do I need to save" message appears below the editor.
Nano ***/mininet/mininet/cli.py
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 ')
Nano ***/mininet/bin/mn
/***/mininet/util/install.sh-n
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