Mininet - 无法 ping 通 2 个路由器
Mininet - Can't ping across 2 routers
我的自定义拓扑有问题,看起来像-
h1 h3
> s1 - r1 - r2 - s2 <
h2 h4
本质上,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
如果我删除所有与交换机和主机相关的代码并尝试 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()
似乎一个子网无法到达另一个子网。所以你必须修复路由。查看路由器上的路由表,然后定义路由协议或通过静态路由定义静态路由条目。
我的自定义拓扑有问题,看起来像-
h1 h3
> s1 - r1 - r2 - s2 <
h2 h4
本质上,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
如果我删除所有与交换机和主机相关的代码并尝试 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()
似乎一个子网无法到达另一个子网。所以你必须修复路由。查看路由器上的路由表,然后定义路由协议或通过静态路由定义静态路由条目。