1

As a part of an experiment, my network has the following topology for two host machines connected to two routers in mininet(on Ubuntu 22.04.02 Virtual Machine)

     h1 - r1 - r2 - h2      

I have written the following script in mininet API to set up my network topology and routing:

    from mininet.net import Mininet
    from mininet.node import Controller, RemoteController, OVSController
    from mininet.node import CPULimitedHost, Host, Node
    from mininet.node import OVSKernelSwitch, UserSwitch
    from mininet.node import IVSSwitch
    from mininet.cli import CLI
    from mininet.log import setLogLevel, info
    from mininet.link import TCLink, Intf
    from subprocess import call


    def myNetwork():
        net = Mininet( topo=None,
                       build=False,
                       ipBase='192.168.0.0/16')
        info( '* Adding controller\n' )
        info( '* Add switches\n')
        r1 = net.addHost('r1', cls=Node, ip='0.0.0.0')
        r1.cmd('sysctl -w net.ipv4.ip_forward=1')
        r2 = net.addHost('r2', cls=Node, ip='0.0.0.0')
        r2.cmd('sysctl -w net.ipv4.ip_forward=1')

        info( '* Add hosts\n')
        h1 = net.addHost('h1', cls=Host, ip='192.168.0.103/24', defaultRoute='via 192.168.0.1')
        h2 = net.addHost('h2', cls=Host, ip='192.168.1.2/24', defaultRoute='via 192.168.1.1')

        info( '* Add links\n')
        net.addLink(h1, r1, intfName2='r1-eth0', params2={'ip':'192.168.0.1/24'})
        net.addLink(r1, r2, intfName1='r1-eth1', intfName2='r2-eth0', params1=   {'ip':'192.168.2.1/24'}, params2={'ip':'192.168.2.2/24'})
        net.addLink(r2, h2, intfName1='r2-eth1', params1={'ip':'192.168.1.1/24'})


        info( '* Starting network\n')
        net.build()
    
        info( '* Post configure switches and hosts\n')
    # Setting up IP addresses and routing tables
        r1.cmd('ifconfig r1-eth0 192.168.0.1 netmask 255.255.255.0')
        r1.cmd('ip route add 192.168.1.0/24 via 192.168.2.2')
        r1.cmd('ip route add 192.168.2.0/24 via 192.168.0.1')

        r2.cmd('ifconfig r2-eth0 192.168.2.1 netmask 255.255.255.0')
        r2.cmd('ip route add 192.168.0.0/24 via 192.168.2.2')
        r2.cmd('ip route add 192.168.1.0/24 via 192.168.2.2')

        h1.cmd('ip route add default via 192.168.0.1')
        h2.cmd('ip route add default via 192.168.1.1')

    
        CLI(net)
        net.stop()


    if __name__ == '__main__':
        setLogLevel( 'info' )
        myNetwork()

The problem is I cant get the hosts to ping each other, nor I can get the host to reach the router on the other end. The following is the ping reachability matrix:

mininet> pingall
*** Ping: testing ping reachability
r1 -> r2 h1 X 
r2 -> r1 X h2 
h1 -> r1 r2 X 
h2 -> r1 r2 X 
*** Results: 33% dropped (8/12 received)

It can be interpreted as :

Through pinging,

  1. r1 can reach r2 and h1 but not h2.
  2. r2 can reach r1 but cant reach h1 nor h2.
  3. h1 can reach r1 and r2 but not h2.
  4. h2 can reach r1 and r2 but not h1.

Oddly, I got someone else to run the program with same routing setup in gns3 and it worked for them. Is there something I have missed? Any step? Any Configuration? Any leads are appreciated.

0 Answers0