Tama Yoshi
Tama Yoshi

Reputation: 313

Executing commands in batch inside Mininet

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?

Upvotes: 3

Views: 4025

Answers (1)

Tama Yoshi
Tama Yoshi

Reputation: 313

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

Upvotes: 5

Related Questions