Reputation: 193
I am new to mininet. I want to run the mininet commands to run from the python scripts like "nodes","dump". I can create the topology but cannot use these commands through my script. I am using Ubuntu 14.04.
import subprocess as sb
import os
print "Single Switch and 4 Hosts per switch topology"
print "Creation of topology"
os.system(" sudo mn --topo = single,4",shell=True)
os.system("nodes")
Error:
sh: 1: nodes: not found
32512
I do not want to create a topology through python script, I only want to use the mininet commands.
Upvotes: 3
Views: 8768
Reputation: 79
Glad I found this question. I have a sub-question of a very similar nature. I understand that you can execute a command into the mininet CLI from python using e.g. h1.cmd('ifconfig')
, but is there a way to do the same from python to the mininet>
prompt ? i.e. not pointing it to a specific host in the topology (I am simulating faults so some hosts are disconnected). Something like net.cmd('python module.py')
? @Abhimanyu singh @nir0s
Upvotes: 2
Reputation: 417
As nirOs suggested , you should use the Mininet Python Library . Read Through https://github.com/mininet/mininet/wiki/Introduction-to-Mininet to get a better idea on how to create Topologies . Once Created you can use hostObject.cmd('your command goes here') . Each host in mininet is created with its own namespace . This "cmd" executes the given command in the host's namespace. For Example : host1.cmd("ifconfig") #this returns the IP information of the host
Upvotes: 3
Reputation: 1181
The problem is that mininet is an interactive CLI. You can't simply call it and then pass another command as an interactive CLI is blocking.
There are ways to solve that. Look here: Wrapping an interactive CLI in python
and check pexpect to more comfortably interact with interactive CLI's.
Upvotes: 1