我正在尝试建立一个网络,其中3个主机(h1,h2,h3,在不同的网络上)可以通过分离它们的2个路由器(r1,r2)相互ping通。
h1 - > r1 - > h2 - > r2 - > h3 - > r3 - >互联网
我找到了this,引导我通过2台主机和1台路由器但是当我在h2的另一侧添加r2时,r2没有响应任何东西,并且它无法ping任何东西或者我可以获得以下双向对: (h1,r1)(h2,r2)
此代码为我提供了无响应/静音的r2:
#!/usr/bin/python
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import Node
from mininet.log import setLogLevel, info
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 ):
"A LinuxRouter connecting three IP subnets"
def build( self, **_opts ):
robIP = '10.1.1.14/24' # IP address for r0-eth1
richIP = '10.4.4.46/24'
robert = self.addNode( 'r0', cls=LinuxRouter, ip=robIP, defaultRoute='via 10.4.4.14' )
richard = self.addNode( 'r1', cls=LinuxRouter, ip=richIP, defaultRoute='via 10.6.6.46' )
alice = self.addHost( 'h1', ip='10.1.1.17/24', defaultRoute='via 10.1.1.14' )
bob = self.addHost( 'h2', ip='10.4.4.48/24', defaultRoute='via 10.4.4.14' )
self.addLink( alice, robert, intfName2='r0-eth1', params2={ 'ip' : '10.1.1.14/24' } )
self.addLink( bob, robert, intfName2='r1-eth1', params2={ 'ip' : '10.4.4.14/24' } )
self.addLink( bob, richard, intfName2='r0-eth2', params2={ 'ip' : '10.4.4.46/24' } )
def run():
"Test linux router"
topo = NetworkTopo()
net = Mininet( topo=topo ) # controller is used by s1-s3
net.start()
info( '*** Routing Table on Router:\n' )
print net[ 'r0' ].cmd( 'route' )
CLI( net )
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
run()
如果我转换这2行,我会获得2对双向。
self.addLink( bob, richard, intfName2='r1-eth1', params2={ 'ip' : '10.4.4.46/24' } )
self.addLink( bob, robert, intfName2='r0-eth2', params2={ 'ip' : '10.4.4.14/24' } )
我甚至不知道这个问题是不是我的错误代码,或者它是否是我在导致它的路由器上没有完成的配置。
我只需要能够毫无损失地ping通。