3

I am experimenting a bit to gain a better understanding of Mininet and Openflow. I have built a topology with n hosts in a line and no switches. Strangely, host 1 and host 2 can ping each other but the remaining hosts can't. Could somebody explain why this is and possibly if it is possible to get all nodes to be able to ping their neighbors without introducing switches into the network?

Here is my current code:

#!/usr/bin/python
from mininet.net import Mininet
from utils.FloodlightController import FloodlightController
from mininet.log import setLogLevel
import os,time

if __name__ == '__main__':
    #setLogLevel( 'info' )
    net = Mininet(controller=FloodlightController)
    #net.addController("controller1")

    num_nodes = 8
    for i in range(1,num_nodes):
        net.addHost("h%d"%i)
    for i in range(2,num_nodes):
        net.addLink("h%d"%i, "h%d"%(i-1))

    net.start()
    net.pingAll()
    net.stop()

This is the output:

*** Ping: testing ping reachability
h1 -> h2 X X X X X 
h2 -> h1 X X X X X 
h3 -> X X X X X X 
h4 -> X X X X X X 
h5 -> X X X X X X 
h6 -> X X X X X X 
h7 -> X X X X X X 
*** Results: 95% dropped (2/42 received)
  • Did any answer help you? If so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you could provide and accept your own answer. – Ron Maupin Aug 14 '17 at 21:04
1

Perhaps the first two hosts get an IP assigned in the same subnet. Hence, they may be communicating over traditional network. Since, you didn't add a switch, the question of loops shouldn't arise.

You have a misconfigured code. The Controller object needs to be 'built' and only Switches have to be 'started'. Use net.build() instead of net.start(). The start() function is for switches.

1

There are 2 problems here based on the fact that Mininet considers one interface in a host as the "default" interface for the node.

  1. In a host with many interfaces, mininet assigns an IP only to the default interface, so you have to assign the IP with a coherent IP plan. See here for details.

    You can see in the following code that you can have a different result changing only the order in which you add the links (when you add a link, the interfaces are also created and if the new interface is the first in the host, it will be the "default", thus with an IP):

    #!/usr/bin/python
    
    from mininet.net import Mininet
    from mininet.log import setLogLevel
    import os,time
    
    if __name__ == '__main__':
        #setLogLevel( 'info' )
        net = Mininet()
    
        num_nodes = 8
        hosts=[None] * num_nodes
    
        for i in range(1,num_nodes):
            hosts[i]=net.addHost("h%d"%i)
        for i in range(2,num_nodes,2):
            net.addLink(hosts[i], hosts[i-1])
        for i in range(3,num_nodes,2):
            net.addLink(hosts[i], hosts[i-1])
    
        net.start()
        net.pingAll()
        net.stop()
    

This is the output:

    h1 -> h2 X X X X X 
    h2 -> h1 X X X X X 
    h3 -> X X h4 X X X 
    h4 -> X X h3 X X X 
    h5 -> X X X X h6 X 
    h6 -> X X X X h5 X 
    h7 -> X X X X X X 
  1. pingAll() tries to ping from each host to the IP of the default interface of any other host. This can work only if you enable the ip forwarding in every host in this way:

    host.cmd('sysctl -w net.ipv4.ip_forward=1')
    

    otherwise you have to ping the neighbors of each host giving the right IP.

Here you can find the code that can assign the IPs to the interfaces and ping all the neighbors for each node.

#!/usr/bin/python

from mininet.net import Mininet
from mininet.log import output

if __name__ == '__main__':

    net = Mininet()

    num_nodes = 8 

    # from 1 to num_nodes
    for i in range(1,num_nodes+1): 
        net.addHost('h%d'%i,ip=None)

    # from 1 to num_nodes-1 because the index starts from zero
    for i in range(1,num_nodes): 

        h1 = net.hosts[i-1]
        h2 = net.hosts[i]

        net.addLink(h2, h1, intfName1 = '%s-eth0'%h2.name, intfName2 = '%s-eth1'%h1.name)
        h2.intf('%s-eth0'%h2.name).setIP('10.0.%d.1'%i, 24) 
        h1.intf('%s-eth1'%h1.name).setIP('10.0.%d.2'%i, 24) 

    net.start()

    # Ping forward and backward nodes
    for i in range(0,num_nodes):
        node = net.hosts[i]

        fwdNode, bwNode = None, None

        output('%s -> '%node.name)

        if i!=0:
            bwNode = net.hosts[i-1]
            bwIP = bwNode.IP('%s-eth1'%bwNode.name)
            result = node.cmd('ping -c1 %s'%bwIP)
            sent, received = net._parsePing(result)

            output(('%s '%bwNode.name) if received else 'X ')

        if i!=7:
            fwdNode = net.hosts[i+1]
            fwdIP = fwdNode.IP('%s-eth0'%fwdNode.name)
            result = node.cmd('ping -c1 %s'%fwdIP)
            sent, received = net._parsePing(result)

            output(('%s '%fwdNode.name) if received else 'X ')

        output('\n')

    net.stop()

and this is the output:

h1 -> h2 
h2 -> h1 h3 
h3 -> h2 h4 
h4 -> h3 h5 
h5 -> h4 h6 
h6 -> h5 h7 
h7 -> h6 h8 
h8 -> h7 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.