I wrote a python module to generate a random topology using Mininet and connected OpenDayLight as the remote controller.
I would like to pass a command to the mininet CLI, but from inside the python module. After generating the hosts and switches as well as connecting them to the remote controller, the module randomly chooses 2 hosts to act as Server and Client. I am having trouble doing something similar to this, but from in-line inside the python module:
mininet> h<random_number> sudo python HTTPTraffic.py <SrcIP> <DstIP>
HTTPTraffic.py
is another module that takes arguments SrcIP
and DstIP
This is the part of the main module that elects 2 random hosts and gets their IPs. I would like the HTTPTraffic.py
to run in the host corresponding to SrcIP
Nodes = list(range(1,h))
Src = random.choice(Nodes) # randomly chooses 1 host
Nodes.remove(Src)
Dst = random.choice(Nodes) # randomly chooses another host
SrcName = 'h%s' %(Src)
DstName = 'h%s' %(Dst)
SrcNode=net.get(SrcName)
DstNode=net.get(DstName)
SrcIP = SrcNode.IP() # IP retrieval of chosen hosts
DstIP = DstNode.IP()
print ('The Souce/Client is: '+ SrcName)
print (SrcIP)
print ('The Destination/Server is: '+ DstName)
print (DstIP)
SrcName +".cmd('sudo python HTTPTraffic.py "+SrcIP+" " +DstIP+"')" # this is where I am having trouble
From the mininet API documentation (See section 'Customizing a Network'), something like that is possible but I am having so much trouble doing it. Also, I would like for this command to run in the background while the main program runs. Any feedback is appreciated.