Mininet 如何模拟多个机房点对点互联?

264 天前
 skyqqcc581

例如

现在有 5 个机房 每个机房有 3 台机器

每个机房的 IP 段是/24 相同的

要求单独点对点互联所有机房!

并且点对点时可以设置各个不同连接机房的延迟和宽带限速

例如 A => B 延迟 30ms 宽带 80ms

借助工具写了个这样的 但是不行:

from mininet.net import Mininet
from mininet.node import Node
from mininet.link import Link
from mininet.cli import CLI
from mininet.log import setLogLevel, info

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

def create_network():
    net = Mininet(topo=None, build=False)

    # Create routers for each room
    routers = [net.addHost('r%s' % i, cls=LinuxRouter, ip='10.0.%s.1/24' % i) for i in range(1, 6)]

    # Create switch and hosts for each room, and connect them
    for i in range(1, 6):
        switch = net.addSwitch('s%s' % i)
        net.addLink(switch, routers[i-1]) # Connect switch to router
        for j in range(1, 3):
            host = net.addHost('h%s%s' % (i, j), ip='10.0.%s.%s/24' % (i, 10+j), defaultRoute='via 10.0.%s.1' % i)
            net.addLink(host, switch)

    # Manually create links between routers to simulate the point-to-point connections
    for i in range(len(routers)-1):
        net.addLink(routers[i], routers[i+1])

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

if __name__ == '__main__':
    setLogLevel('debug')
    create_network()
910 次点击
所在节点    宽带症候群
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1020135

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX