无法在mininet中使用ping6

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

我正在 mininet(虚拟机)上运行 Python 脚本,如下所示:

def main():
    setLogLevel('info')
    net = Mininet(switch=LinuxBridge, controller=None)
    h1 = net.addHost('h1', ip=None)
    h2 = net.addHost('h2', ip=None)
    s0 = net.addSwitch('s0')
    s1 = net.addSwitch('s1')
    s2 = net.addSwitch('s2')
    r1 = net.addHost('r1', ip=None)
    r1.cmd('sysctl -w net.ipv6.conf.all.forwarding=1')
    r2 = net.addHost('r2', ip=None)
    r2.cmd('sysctl -w net.ipv6.conf.all.forwarding=1')

    net.addLink(h1, s1)
    net.addLink(r1, s1)
    net.addLink(r1, s0)
    net.addLink(r2, s0)
    net.addLink(r2, s2)
    net.addLink(h2, s2)

    h1.cmd("ip -6 addr add 2001:638:709:a::1/64 dev h1-eth0")
    h2.cmd("ip -6 addr add 2001:638:709:b::1/64 dev h2-eth0")
    r1.cmd("ip -6 addr add 2001:638:709:a::f/64 dev r1-eth0")
    r1.cmd("ip -6 addr add 2001:638:709:f::1/64 dev r1-eth1")
    r2.cmd("ip -6 addr add 2001:638:709:f::2/64 dev r2-eth0")
    r2.cmd("ip -6 addr add 2001:638:709:b::f/64 dev r2-eth1")

    h1.cmd("ip -6 route add 2001:638:709::/48 via 2001:638:709:a::f dev h1-eth0")
    r1.cmd("ip -6 route add 2001:638:709:b::/64 via 2001:638:709:f::2 dev r1-eth1")
    r2.cmd("ip -6 route add 2001:638:709:a::/64 via 2001:638:709:f::1 dev r2-eth0")
    h2.cmd("ip -6 route add 2001:638:709::/48 via 2001:638:709:b::f dev h2-eth0")

    net.start()
    CLI(net)
    net.stop()

运行后,当我执行

h1 ping6 2001:638:709:b::1
时,我收到一个错误

Address family not supported by protocol

如果我尝试

h1 ping6 2001:638:709:b::f/64
,我会得到
unknown host

验证网络的正确方法是什么?

python networking ping mininet topology
1个回答
0
投票

你的例子也不适合我。但我能够让 IPv6 像这样工作:

from mininet.cli import CLI
from mininet.log import setLogLevel
from mininet.net import Mininet
from mininet.topo import Topo
from mininet.nodelib import LinuxBridge

class MyTopo(Topo):
    def build(self):
        h1 = self.addHost('h1', ip=None)
        h2 = self.addHost('h2', ip=None)
        r1 = self.addHost('r1', ip=None)
        r2 = self.addHost('r2', ip=None)
        s0 = self.addSwitch('s0')
        s1 = self.addSwitch('s1')
        s2 = self.addSwitch('s2')

        self.addLink(h1, s1)
        self.addLink(r1, s1)
        self.addLink(r1, s0)
        self.addLink(r2, s0)
        self.addLink(r2, s2)
        self.addLink(h2, s2)


def main():
    setLogLevel('info')
    topo = MyTopo()
    net = Mininet(topo, switch=LinuxBridge)

    h1, h2, r1, r2 = [ net.hosts[x] for x in range(4) ]
    h1.cmd("ip -6 addr add 2001:638:709:a::1/64 dev h1-eth0")
    h2.cmd("ip -6 addr add 2001:638:709:b::1/64 dev h2-eth0")
    r1.cmd("ip -6 addr add 2001:638:709:a::f/64 dev r1-eth0")
    r1.cmd("ip -6 addr add 2001:638:709:f::1/64 dev r1-eth1")
    r2.cmd("ip -6 addr add 2001:638:709:f::2/64 dev r2-eth0")
    r2.cmd("ip -6 addr add 2001:638:709:b::f/64 dev r2-eth1")
    r1.cmd('sysctl -w net.ipv6.conf.all.forwarding=1')
    r2.cmd('sysctl -w net.ipv6.conf.all.forwarding=1')
    h1.cmd("ip -6 route add 2001:638:709::/48 via 2001:638:709:a::f dev h1-eth0")
    r1.cmd("ip -6 route add 2001:638:709:b::/64 via 2001:638:709:f::2 dev r1-eth1")
    r2.cmd("ip -6 route add 2001:638:709:a::/64 via 2001:638:709:f::1 dev r2-eth0")
    h2.cmd("ip -6 route add 2001:638:709::/48 via 2001:638:709:b::f dev h2-eth0")

    net.start()
    CLI(net)
    net.stop()

main()

与您的代码的主要区别在于拓扑是在

build()
方法中构建的。

在我的系统上,我还必须禁用网桥上的 netfilter:

sysctl net.bridge.bridge-nf-call-iptables=0
sysctl net.bridge.bridge-nf-call-ip6tables=0
sysctl net.bridge.bridge-nf-call-arptables=0
© www.soinside.com 2019 - 2024. All rights reserved.