Mininet 中的主机与使用 Root 命名空间的主机通信

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

我尝试在 Mininet 中的主机和主机之间建立连接(通过 Mininet 中的交换机):(主机 ---> 交换机)--> 主机 ---> Internet)。

详细信息:

我尝试将主机(在 Mininet 中)连接到主机。我正在使用根命名空间方法(NAT、根命名空间、OVS)。我可以将交换机(在 Mininet 中)连接到主机,但不能从主机(在 Mininet 中)连接。

  做不到

mininet> h1 ping -c 5 www.google.com

错误信息:
“ping:www.google.com:名称解析暂时失败”

   如果我尝试连接内部网络中的其他计算机,例如

mininet> h1 ping -c 5 192.168.3.23

错误信息:
“连接:网络无法访问”

这是我的网络:

此修改图来自2

这是我的代码片段(“code.py”):

#!/usr/bin/python
#
# Reference:
#    code: https://stackoverflow.com/a/62060980/5595995
#    root namespace: https://forum.p4.org/t/connect-mininet-hosts-to-root-namespace/91 

import argparse, os, pdb, sys
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.cli import CLI
from mininet.log import setLogLevel, info
from mininet.link import TCLink, Intf
from subprocess import call
from mininet.topo import Topo


# ----- ----- ----- -----
def main(args):

    if (args.selection == "original"):
        treeNetwork()
    else:
        print ("Please, choose among choices.")


def treeNetwork():

    net = Mininet(topo=None,
                  build=False,
                  ipBase='10.0.0.0/8')

    info( '*** Adding controller\n' )
    # If error at the port 6653 holding by another contorller
    #     $ sudo fuser -k 6653/tcp
    #     ref: https://github.com/intrig-unicamp/mininet-wifi/issues/96#issuecomment-968238622
    c0=net.addController(name='c0',
                      controller=OVSController,
                      ip='127.0.0.1',
                      protocol='tcp',
                      port=6653)

    info( '*** Add switches\n')
    s1 = net.addSwitch('s1', cls=OVSKernelSwitch)

    info( '*** Add hosts\n')
    h1 = net.addHost('h1', cls=Host, ip='10.0.223.1', defaultRoute=None)
    h2 = net.addHost('h2', cls=Host, ip='10.0.223.3', defaultRoute=None)

    info( '*** Add links\n')
    s1h1 = {'bw':120,'loss':5}  # 0 (zero) not accepted
    net.addLink(s1, h1, cls=TCLink , **s1h1)

    s1h2 = {'bw':400,'loss':20}
    net.addLink(s1, h2, cls=TCLink , **s1h2)

    # from https://forum.p4.org/t/connect-mininet-hosts-to-root-namespace/91
    # To host, h1, can reachable from Terminal in host machine
    s1_node = net.getNodeByName("s1")
    root = Node('root', inNamespace=False)
    intf = net.addLink(root, s1_node).intf1
    # IP address should be under same subnet with host.
    #    Details: https://forum.p4.org/t/connect-mininet-hosts-to-root-namespace/91/6
    ip='10.0.223.0/32'  # If you need an IP address 
    root.setIP(ip, intf=intf)
    
    info( '*** Starting network\n')
    net.build()

    info( '*** Starting controllers\n')
    for controller in net.controllers:
        controller.start()

    info( '*** Starting switches\n')
    net.get('s1').start([c0])

    info( '*** Post configure switches and hosts\n')

    CLI(net)

    net.stop()


def input_para():

    parser = argparse.ArgumentParser()
    parser.add_argument('-s', action='store', dest='selection',
        help='Store a simple value')
    results = parser.parse_args()

    return results


if __name__ == '__main__':

    setLogLevel( 'info' )
    args = input_para()
    main(args)

(我通过

$ sudo python2 code.py -s original
运行这个,我不使用虚拟机或虚拟环境。)

这是我在 Mininet 上执行

dump
的时候:

mininet> dump
<Host h1: h1-eth0:10.0.223.1 pid=17601>
<Host h2: h2-eth0:10.0.223.3 pid=17603>
<OVSSwitch s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None,s1-eth3:None pid=17596>
<OVSController c0: 127.0.0.1:6653 pid=17588>

主机中

$ ifconfig
的这部分输出:


root-eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.223.0  netmask 0.0.0.0  broadcast 255.255.255.255
        inet6 fe80::ccd4:2bff:fea8:6b80  prefixlen 64  scopeid 0x20<link>
        ether ce:d4:2b:a8:6b:80  txqueuelen 1000  (Ethernet)
        RX packets 31  bytes 4173 (4.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 60  bytes 11703 (11.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

使用此代码:
我可以从 Mininet 中的“s1” ping “www.google.com”:

mininet> s1 ping -c 5 www.google.com
(在 Mininet 中切换 --> 主机 --> Internet)

我还可以从主机 ping “10.0.223.0”(到 Mininet 中“s1”处的“root-eth0”端口)
$ ping -c 5 10.0.223.0
(上面的
ifconfig
)(在 Mininet 中切换 <--- host machine)

问题是: 我无法从 Mininet 中的“h1” ping “www.google.com”:

mininet> h1 ping -c 5 www.google.com

第一次尝试

根据Eder在P4 switch论坛的建议3,我必须做:

  1. 执行路由命令,以便主机知道将数据包路由到 Mininet 内的主机的何处 (如果“root-eth0”IP是同一子网,则不需要)
  2. 在“s1”中制定规则,告诉交换机通过“s1-eth5”端口将数据包转发到主机(在我的代码中为“s1-eth3”)
  3. 在 Mininet 主机中添加关于“root-eth0”的 ARP 规则,反之亦然在主机中

我猜我做了第 1 项:
第 1 项:我将“h1”放在 10.0.223.1,将“s1”放在 10.0.223.0。

如何在 Mininet(和主机)中执行第 2 项和第 3 项?
对于第 3 项,我实际上尝试了

net.staticArp()
但主机(在 Mininet 中)仍然无法访问互联网。

我的代码有错误吗?

我完全没抓住重点吗?

第二次尝试

我将交换机类型从“OVSKernelSwitch”更改为“OVSSwitch”再更改为“OVSBridge”。还是没有解决问题。

第三次尝试

一些检查错误消息“ping:www.google.com:名称解析暂时失败”

 我遵循了“询问Ubuntu”中类似帖子中的建议,我的路由可能有问题。我运行了这个命令,这是输出

mininet> h1 route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.0.0.0        0.0.0.0         255.0.0.0       U     0      0        0 h1-eth0

我应该修改路线吗?

谢谢你。


参考:
运行时环境
迷你网 2.2.2
Python 2.7
操作系统:Ubuntu 18.04

python-2.7 networking network-programming ping mininet
© www.soinside.com 2019 - 2024. All rights reserved.