简体   繁体   English

Mininet 不 ping 跨路由器

[英]Mininet doesn't ping accross routers

I want to implement this topology using mininet api but the two hosts can't ping accross the routers.我想使用 mininet api 实现此拓扑,但两台主机无法通过路由器 ping。 Topology: h1<----->s1<----->r1<--------->s2<--------->h2 my code:拓扑:h1<----->s1<----->r1<--------->s2<--------->h2 我的代码:

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):

    def build(self, **_opts):

        defaultIP = '10.0.1.4/24'  # IP address for r1-eth1
        router = self.addNode('r1', cls=LinuxRouter, ip=defaultIP)

        s1, s2 = [self.addSwitch(s) for s in ('s1', 's2')]

        self.addLink(s1, router, intfName2='r1-eth1', params2={'ip':       defaultIP})  # for clarity
        self.addLink(s2, router, intfName2='r1-eth2',
                 params2={'ip': '10.0.2.4/12'})

        h1 = self.addHost('h1', ip='10.0.1.1/24', defaultRoute='via 10.0.1.4')
        h2 = self.addHost('h2', ip='10.0.2.1/12', defaultRoute='via 10.0.2.4')

        for h, s in [(h1, s1), (h2, s2)]:
            self.addLink(h, s)


def run():
    topo = NetworkTopo()
    net = Mininet(topo=topo)  # controller is used by s1-s3
    net.start()
    info('*** Routing Table on Router:\n')
    info(net['r1'].cmd('route'))
    CLI(net)
    net.stop()


if __name__ == '__main__':
    setLogLevel('info')
    run()

and here is pingall results: *** Ping: testing ping reachability这是 pingall 结果:*** Ping:测试 ping 可达性
h1 -> X r1 h1 -> X r1
h2 -> X r1 h2 -> X r1
r1 -> h1 h2 r1 -> h1 h2

The address 10.0.1.1/24 overlaps with 10.0.2.1/12.地址 10.0.1.1/24 与 10.0.2.1/12 重叠。 Setting both /24 should work.设置两个 /24 应该可以工作。

This works for me.这对我有用。

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):

    def build(self, **_opts):

        defaultIP = '10.0.1.4/24'  # IP address for r1-eth1
        router = self.addNode('r1', cls=LinuxRouter, ip=defaultIP)

        s1, s2 = [self.addSwitch(s) for s in ('s1', 's2')]

        self.addLink(s1, router, intfName2='r1-eth1', params2={'ip':       defaultIP})  # for clarity
        self.addLink(s2, router, intfName2='r1-eth2',
                 params2={'ip': '10.0.2.4/24'})

        h1 = self.addHost('h1', ip='10.0.1.1/24', defaultRoute='via 10.0.1.4')
        h2 = self.addHost('h2', ip='10.0.2.1/24', defaultRoute='via 10.0.2.4')

        for h, s in [(h1, s1), (h2, s2)]:
            self.addLink(h, s)


def run():
    topo = NetworkTopo()
    net = Mininet(topo=topo)  # controller is used by s1-s3
    net.start()
    info('*** Routing Table on Router:\n')
    info(net['r1'].cmd('route'))
    CLI(net)
    net.stop()


if __name__ == '__main__':
    setLogLevel('info')
    run()

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

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