V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
skyqqcc581
V2EX  ›  宽带症候群

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

  •  
  •   skyqqcc581 · 259 天前 · 903 次点击
    这是一个创建于 259 天前的主题,其中的信息可能已经有所发展或是发生改变。

    例如

    现在有 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()
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1011 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 20:03 · PVG 04:03 · LAX 12:03 · JFK 15:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.