Mininet - 无法ping通2台路由器

时间:2017-10-03 05:29:04

标签: python networking routing ping mininet

我的自定义拓扑出现问题 -

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

两台路由器基本上有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 

如果我删除所有与交换机和主机相关的代码并尝试ping路由器到路由器它工作正常,但与其他设备似乎当我尝试r1 ping r2时,它正试图ping相反,接口连接到交换机,不知道那里发生了什么。

修复了子网,现在路由器可以ping通,但仍然无法从每个主机ping它们

我不确定如何设置手动路由,或者甚至可以使用mininet。完整代码位于

之下
#!/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()

1 个答案:

答案 0 :(得分:0)

似乎一个子网无法到达另一个子网。所以你必须修复路由。检查路由器上的路由表,然后定义路由协议或通过静态路由定义静态路由条目。