简体   繁体   English

Mininet - 无法跨 2 个路由器 ping

[英]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-基本上跨 2 个路由器的 2 个子网,但是当我尝试 ping 跨它们时,我什么也没得到,pingall 结果是-

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. 如果我删除与交换机和主机有关的所有代码并尝试 ping 路由器到路由器,它可以正常工作,但是对于其他设备,似乎当我尝试 r1 ping r2 时,它正在尝试 ping 连接到交换机的接口相反,不确定那里发生了什么。

Fixed the subnetting and now the routers can ping, but still unable to ping across them from each host修复了子网划分,现在路由器可以 ping,但仍然无法从每个主机跨它们 ping

I'm not sure how to set up manual routing or if that's even possible with mininet.我不确定如何设置手动路由,或者是否可以使用 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.检查路由器上的路由表,然后定义路由协议或通过静态路由定义静态路由项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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