Skip to content Skip to sidebar Skip to footer

Errno 111 Connection Refused - Python Mininet Api Hosts Client/server No Connection?

I am new to Mininet and I am trying to find a way to use a script in python to execute a few tests using Mininet. More precisely I want to build topology and send a few xmlrpc re

Solution 1:

Why not use mininet's python interface to achieve this? From your question it seems like you want to get the names of the nodes that sudo mn creates by default.

In that case why not just add the following to your python:

from mininet.topo import SingleSwitchTopo
from mininet.net import Mininet
from mininet.node import CPULimitedHost
from mininet.link import TCLink

if __name__ == '__main__':
    topo = SingleSwitchTopo()
    net = Mininet(topo=topo, host=CPULimitedHost, link=TCLink)

    net.start()

    nodes = net.items()
    node_names, _ = zip(*nodes)

    print(node_names)
    net.stop()

SingleSwitchTopo is the one that mn uses by default (two hosts connected to a single switch). net.items() gives you a tuple of the node's names and ids see here. Perhaps I misunderstand your question, but seems like trying to access it via subprocess when there is an API is overcomplicating an otherwise simple task.

Solution 2:

Finally, I found what caused the [Errno 111] : connection refused when the client trying to connect to the server. It was something "crazy" in a good way ;).

I just realized that server wasn't ready and running when the client post a request, simply because both execution commands start simultaneously. So, I add a delay between calling/execution cmd lines like this:

host1.sendCmd("python3 server.py")
sleep(5)
host2.cmdPrint("python3 client.py")

Extra comments:

Important to mention that the sendCmd() gives an assertion await error when net.stop() runs. The documentations says to use host1.monitor() after sendCmd() and before net.stop() but it didn't work. So, I replaced the sendCmd() with popen() and then used the terminate() and everything is fine now!

Post a Comment for "Errno 111 Connection Refused - Python Mininet Api Hosts Client/server No Connection?"