(mininet) 在一台主机上配置多个接口 [英] (mininet) Configure multiple interfaces on a host

查看:72
本文介绍了(mininet) 在一台主机上配置多个接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个场景,其中有一台带有两个接口的服务器机器.这些接口中的每一个都有自己的 IP 地址.服务器机器托管一个 HTTP 服务器,它应该可以通过两个接口访问.

I have a scenario in which there is a server machine with two interfaces. Each of these interfaces has its own IP address. The server machine hosts an HTTP server, which should be accessible via both of the interfaces.

完整的python脚本来重现这种情况:

Full python script to reproduce this situation:

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

class TestTopology(Topo):
    def __init__(self):
        Topo.__init__(self)
        host1_id = self.addHost('h1')
        host2_id = self.addHost('h2')
        server_id = self.addHost('server')
        self.addLink(server_id, host1_id)
        self.addLink(server_id, host2_id)

def configure_network(network):
    server = network.get('server')
    server.setIP('10.0.0.10', intf='server-eth0')
    server.setMAC('00:00:00:00:00:10', intf='server-eth0')
    server.setIP('10.0.0.11', intf='server-eth1')
    server.setMAC('00:00:00:00:00:11', intf='server-eth1')
    server.cmd("python -m SimpleHTTPServer 8080 &")

# Run 'sudo python *path_to_this_script*' in mininet VM.
if __name__ == '__main__':
    setLogLevel('info')
    net = Mininet(topo=TestTopology())
    configure_network(net)
    net.pingAll()
    CLI(net)

SimpleHTTPServer 默认监听 0.0.0.0.

The SimpleHTTPServer is listening on 0.0.0.0 as default.

'pingAll' 测试表明 h1 可以访问服务器(反之亦然),但对于 h2 则不是这种情况.当然,我也不能从 h2 中 wget.

The 'pingAll' test shows that the server is accessible by h1 (and vice versa), but it's not the case for h2. Of course, I can't wget from h2 either.

如何配置服务器接口,以便服务器通过这两个接口响应 pingwget 命令?

How to configure the server interfaces so that the server responds both to ping and wget commands via both of these interfaces?

/etc/network/interfaces 包含一些配置,但它是关于不存在的 eth0 接口,所以我假设它没有被使用.

/etc/network/interfaces on the server contains some configuration, but it is regarding a non-existent eth0 interface, so I assumed it is not used.

注意:我已经了解到对于 linux,一个特定的 IP != 网络接口.服务器从 h1 响应对 10.0.0.10 和 10.0.0.11 的 ping,但我希望它在两个物理接口上都响应.

NOTE: I've already learned that for linux, a particular IP != network interface. The server responds for pings to both 10.0.0.10 and 10.0.0.11 from h1, but I would like for it to respond on both physical interfaces.

推荐答案

您可以尝试从 mininet.util 导入自定义

You can try importing custom from mininet.util

就我而言,重新排序代码有效.

In my case, reordering the code worked.

这是我的代码:

#!/usr/bin/python

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, Link
from mininet.util import makeNumeric, custom
from subprocess import call

def myNetwork():
    link = custom(TCLink, bw=10)
    net = Mininet( topo=None,
                   build=False,
                   ipBase='10.0.0.0/8')

    info( '*** Adding controller\n' )
    info( '*** Add switches\n')



    s5 = net.addSwitch('s5', cls=OVSKernelSwitch, failMode='standalone')
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch, failMode='standalone')
    s7 = net.addSwitch('s7', cls=OVSKernelSwitch, failMode='standalone')
    s4 = net.addSwitch('s4', cls=OVSKernelSwitch, failMode='standalone')

    r8 = net.addHost('r8', cls=Node, ip='0.0.0.0')
    r8.cmd('sysctl -w net.ipv4.ip_forward=1')
    r9 = net.addHost('r9', cls=Node, ip='0.0.0.0')
    r9.cmd('sysctl -w net.ipv4.ip_forward=1')
    r10 = net.addHost('r10', cls=Node, ip='0.0.0.0')
    r10.cmd('sysctl -w net.ipv4.ip_forward=1')

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

    info( '*** Add links\n')
    net.addLink(s2, r9)
    net.addLink(s4, r10)
    net.addLink(r9, s5)
    net.addLink(s7, r8)
    net.addLink(r8, h2)
    net.addLink(s5, h2)
    net.addLink(s2, h1)
    net.addLink(s4, h1)
    net.addLink(r10, s7)

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

    info( '*** Starting switches\n')
    net.get('s5').start([])
    net.get('s2').start([])
    net.get('s7').start([])
    net.get('s4').start([])

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

    CLI(net)
    net.stop()

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

这篇关于(mininet) 在一台主机上配置多个接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆