简体   繁体   中英

Mininet - Can't ping across 2 routers

I'm having an issue with my custom topology that looks like-

h1                       h3
   > s1 - r1 - r2 - s2 <
h2                       h4

Essentially 2 subnets across the 2 routers but when I try to ping across them I get nothing, the pingall results are-

h1 -> h2 X X r1 X 
h2 -> h1 X X r1 X 
h3 -> X X h4 X r2 
h4 -> X X h3 X r2 
r1 -> h1 h2 X X r2 
r2 -> X X h3 h4 r1 

If I remove all the code pertaining to the switches and hosts and attempt to ping router to router it works fine, but with the other devices it seems that when I try to r1 ping r2, it's trying to ping out the interface attached to the switch instead, not sure what is happening there.

Fixed the subnetting and now the routers can ping, but still unable to ping across them from each host

I'm not sure how to set up manual routing or if that's even possible with mininet. The full code is below

#!/usr/bin/python

from mininet.topo import Topo
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.log import setLogLevel, info
from mininet.link import TCLink, Intf
from mininet.cli import CLI

class LinuxRouter( Node ):
    "A Node with IP forwarding enabled."

    def config( self, **params ):
        super( LinuxRouter, self).config( **params )
        # Enable forwarding on the router
        self.cmd( 'sysctl net.ipv4.ip_forward=1' )

    def terminate( self ):
        self.cmd( 'sysctl net.ipv4.ip_forward=0' )
        super( LinuxRouter, self ).terminate()

class NetworkTopo( Topo ):

    def build( self, **_opts ):

        r1 = self.addHost('r1', cls=LinuxRouter, ip='10.0.0.1/24')
        r2 = self.addHost('r2', cls=LinuxRouter, ip='10.0.0.2/24')
        self.addLink(r1, r2, intfName1='r1-eth0', intfName2='r2-eth0')

        s1 = self.addSwitch('s1', cls=OVSKernelSwitch, failMode='standalone')
        s2 = self.addSwitch('s2', cls=OVSKernelSwitch, failMode='standalone')
        self.addLink(s1, r1, intfName2='r1-eth1', params2={'ip':'10.0.1.1/24'})
        self.addLink(s2, r2, intfName2='r2-eth1', params2={'ip':'10.0.2.1/24'})

        h1 = self.addHost('h1', ip='10.0.1.2/24', defaultRoute='via 10.0.1.1')
        h2 = self.addHost('h2', ip='10.0.1.3/24', defaultRoute='via 10.0.1.1')
        h3 = self.addHost('h3', ip='10.0.2.2/24', defaultRoute='via 10.0.2.1')
        h4 = self.addHost('h4', ip='10.0.2.3/24', defaultRoute='via 10.0.2.1')

        for h, s in [(h1, s1), (h2, s1), (h3, s2), (h4, s2)]:
        self.addLink (h, s)

def run():
    topo = NetworkTopo()
    net = Mininet(topo = topo)
    net.start()
    info('*** Routing Table on Router:\nR1:\n')
    info(net['r1'].cmd('route'))
    info('\nR2:\n')
    info(net['r2'].cmd('route'))
    CLI(net)
    net.stop()

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

it seems that the one subnets cannot reach the other. So you have to fix routing. Check the routing tables on routers, and then define routing protocol or define the static routing entries via static routing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM