3

Given a Mininet network, I want to simulate flows, e.g. using iperf. To do this, I can run the following:

h5 iperf3 -s -p 1337 &
h6 iperf3 -s -p 1338 &
h1 iperf3 -c h5 -n 10G -b 11M -p 1337 &
h2 iperf3 -c h6 -n 10G -b 11M -p 1338 &

Within the Mininet CLI, h1, h2 ... represent hosts on the Mininet topology. If a Mininet commands begins by a host ID, the command will be run as if on that host. Any later occurrences of the IDs will be replaced by their IP addresses, for convenience.

These commands work, but I haven't found a way to automate them. I can run a python script which can call bash commands, but the above commands break because the context cannot make sense of the mininet IDs. Inputting all of these by hand is annoying, even if it's a copy-paste job.

Is there a way to send a batch of commands to the mininet CLI?

Tama Yoshi
  • 303
  • 2
  • 15
  • 1
    If the "mininet CLI" is a program you start *before* running the commands above, could you show how you invoke it? It matters whether what you're actually typing the commands into is bash itself, or is mininet. – Charles Duffy Jun 22 '17 at 18:16
  • 1
    ...if it's mininet that the above needs to be entered into, then you should probably look into [Here documents](http://wiki.bash-hackers.org/syntax/redirection#here_documents). – Charles Duffy Jun 22 '17 at 18:17
  • These commands are inputted inside the mininet CLI, yes. The CLI is invoked from a python script, as is usually the case in the examples I've found on the internet. The python function calling the CLI is `CLI({mininet object})`. So far, though, I haven't found a way to pipe anything from an exterior terminal into the CLI... – Tama Yoshi Jun 22 '17 at 18:23
  • consider editing your Q to show all the steps needed before you get to the first line of your sample code `h5 iperf3 -s -p 1337 &`. Good luck. – shellter Jun 22 '17 at 18:45
  • From `http://mininet.org/` it looks like you can skip the `python` part altogether and get the CLI with `sudo mn`. Then you should be able to use `HERE` documents as mentioned above to pass in the commands. You'll have to assign values to variables before starting, so `h5 iperf3 -s -p 1337` could be 1 variable for that line, or it could be parted out like `h${num1} iperf3 -s -p ${port1}` . Good luck. – shellter Jun 22 '17 at 18:50
  • @shellter Well, there's not much else, really. Creating a topology in mininet is really simple and quite fundamental. After that, entering the CLI is a one-line operation, as I described. I don't think it's worth integrating to the Q. Edit: Maybe that's possible. Running `sudo mn` typically boostraps a default topology, regardless of whether I'm already running one. This is not very practical. That said, there's probably a way to ask mininet to CLI into an already running instance... I'll look into that. – Tama Yoshi Jun 22 '17 at 18:51

1 Answers1

5

In the Mininet documentation it's possible to __init__ the CLI mode with a script. Each line of the script will be executed within the CLI, without stopping for user input. A cursory glance in this documentation reveals the individual methods the CLI uses to interpret and execute commands.

Here is an example:

myScript = "genTraffic.sh"
CLI(net, script=myScript) # Batch mode script execution
CLI(net) # Send user in the CLI for additional manual actions

The script I use is the same as the one posted in the question, with prepended Pings to let the network controller and Mininet some time to "see" each other.

h1 ping h5 -c 3
h2 ping h6 -c 3
h5 iperf3 -s -p 1337 &
h6 iperf3 -s -p 1338 &
h1 iperf3 -c h5 -n 10G -b 11M -p 1337 &
h2 iperf3 -c h6 -n 10G -b 11M -p 1338 &

It also happens that the Host and Switch python objects have a method called cmd. This is the method that is used when feeding commands that begin with e.g. h1 or s1 inside the Mininet CLI. I believe using a sequence of calls to cmd is equivalent to the batch-script approach.

Bonus tip: If you want to use tokens like h1 or s1 in the CLI without having it be replaced by the related IP address, you can escape the token: \h1

Tama Yoshi
  • 303
  • 2
  • 15