How to run ping when STP is ready in a mininet topology

If you have a topology like a mesh or any other with redundant links, you must use Spanning tree protocol (STP) to avoid a while.
To run STP, you can use a controller app or setup your virtual switches to be compatible with STP.

To run as controller:

Run a STP controller app. In my case I use Ryu:
ryu-manager --ofp-tcp-listen-port=6633

To run as virtual switch (OVSSwitch):

You can modify your switch from your terminal (outside mininet) as follows:

ovs-vsctl set bridge s1 stp-enable=true

You can use the same sentence inside a python script like follows:

s1.cmd('ovs-vsctl set bridge s1 stp-enable=true')

Now, to avoid execute ping before STP is ready, you need to see the status port of your switch. You can use the following code to insert in your python script.

while(s1.cmdPrint('ovs-ofctl show s1 | grep -o FORWARD | head -n1') != "FORWARD\r\n"):
# Avoid initial too long delaytime.sleep(2)
info("Running ping\n")
ping=h2.cmdPrint('ping -c3 ' + h1.IP())

When the switch port changes it status to FORWARDS, means that STP finished. You can check the status every one second (or 3 in my case to avoid an overload).
After that, you can execute ping without dropped packets.
Enjoy it!


Popular posts from this blog

How to fix Android when developer options are not available for this user

from: can't read /var/mail/ in Python scripts

Fix "Set scan parameters failed: Input/output error" on Ubuntu 16.04