Mininet - 不能跨路由器ping

问题描述 投票:0回答:1

我正在研究mininet中的多路径TCP协议。

我正试图做这样的事情。

h1 === r1 --- r2 === h2

r1和h1之间有两条链路 r2和h2之间有两条链路 r1和r2之间有一条链路。

我在转发子网时遇到了问题,我试图在子网之间进行ping,但没有成功。例如,我可以从r1ping到r2,从h1ping到r1,但无法从h1ping到r2。h2到r2和h2到r1之间的情况也一样。

这是我的测试脚本。

#!/usr/bin/env python

from mininet.net import Mininet
from mininet.cli import CLI
from mininet.link import Link, TCLink,Intf
from subprocess import Popen, PIPE
from mininet.log import setLogLevel

if '__main__' == __name__:

  setLogLevel('info')
  net = Mininet(link=TCLink)
  key = "net.mptcp.mptcp_enabled"
  value = 1
  p = Popen("sysctl -w %s=%s" % (key, value), shell=True, stdout=PIPE, stderr=PIPE)
  stdout, stderr = p.communicate()
  print "stdout=",stdout,"stderr=", stderr


  h1 = net.addHost('h1')
  h2 = net.addHost('h2')

  r1 = net.addHost('r1')
  r2 = net.addHost('r2')

  linkopt={'bw':10}
  linkoptbetween={'bw':100}

  net.addLink(r1,h1,cls=TCLink, **linkopt)
  net.addLink(r1,h1,cls=TCLink, **linkopt)
  net.addLink(r2,h2,cls=TCLink, **linkopt)
  net.addLink(r2,h2,cls=TCLink, **linkopt)
  net.addLink(r1,r2,cls=TCLink, **linkoptbetween)

  net.build()

  r1.cmd("ifconfig r1-eth0 0")
  r1.cmd("ifconfig r1-eth1 0")
  r1.cmd("ifconfig r1-eth2 0")

  r2.cmd("ifconfig r2-eth0 0")
  r2.cmd("ifconfig r2-eth1 0")
  r2.cmd("ifconfig r2-eth2 0")

  h1.cmd("ifconfig h1-eth0 0")
  h1.cmd("ifconfig h1-eth1 0")

  h2.cmd("ifconfig h2-eth0 0")
  h2.cmd("ifconfig h2-eth1 0")

  r1.cmd('sysctl net.ipv4.ip_forward=1')
  r1.cmd("ifconfig r1-eth0 10.1.0.1 netmask 255.255.255.0")
  r1.cmd("ifconfig r1-eth1 10.1.1.1 netmask 255.255.255.0")
  r1.cmd("ifconfig r1-eth2 10.7.2.1 netmask 255.255.255.0")

  r2.cmd('sysctl net.ipv4.ip_forward=1')
  r2.cmd("ifconfig r2-eth0 10.2.0.1 netmask 255.255.255.0")
  r2.cmd("ifconfig r2-eth1 10.2.1.1 netmask 255.255.255.0")
  r2.cmd("ifconfig r2-eth2 10.7.2.2 netmask 255.255.255.0")

  r2.cmd("ip route add default via 10.2.0.1 dev r2-eth0")
  r2.cmd("ip route add default via 10.2.1.1 dev r2-eth1")
  r2.cmd("ip route add default via 10.7.2.2 dev r2-eth2")
  r1.cmd("ip route add default via 10.7.2.1 dev r1-eth2")
  r1.cmd("ip route add default via 10.1.1.1 dev r1-eth1")
  r1.cmd("ip route add default via 10.1.0.1 dev r1-eth0")

  h1.cmd("ifconfig h1-eth0 10.1.0.2 netmask 255.255.255.0")
  h1.cmd("ifconfig h1-eth1 10.1.1.2 netmask 255.255.255.0")

  h2.cmd("ifconfig h2-eth0 10.2.0.2 netmask 255.255.255.0")
  h2.cmd("ifconfig h2-eth1 10.2.1.2 netmask 255.255.255.0")

  h1.cmd("ip rule add from 10.1.0.2 table 1")
  h1.cmd("ip rule add from 10.1.1.2 table 2")

  h1.cmd("ip route add 10.1.0.0/24 dev h1-eth0 scope link table 1")
  h1.cmd("ip route add default via 10.1.0.1 dev h1-eth0 table 1")
  h1.cmd("ip route add 10.1.1.0/24 dev h1-eth1 scope link table 2")
  h1.cmd("ip route add default via 10.1.1.1 dev h1-eth1 table 2")

  h1.cmd("ip route add default scope global nexthop via 10.1.0.1 dev h1-eth0")

  h2.cmd("ip rule add from 10.2.0.2 table 1")
  h2.cmd("ip rule add from 10.2.1.2 table 2")

  h2.cmd("ip route add 10.2.0.0/24 dev h2-eth0 scope link table 1")
  h2.cmd("ip route add default via 10.2.0.1 dev h2-eth0 table 1")
  h2.cmd("ip route add 10.2.1.0/24 dev h2-eth1 scope link table 2")
  h2.cmd("ip route add default via 10.2.1.1 dev h2-eth1 table 2")

  h2.cmd("ip route add default scope global nexthop via 10.2.0.1 dev h2-eth0")


  CLI(net)

  net.stop()

先谢谢你 :)

EDIT:

刷新。谁有什么办法?

networking routes ping mininet mptcp
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.