具有自定义带宽链接的通用树拓扑的 Mininet 脚本

Mininet script for generic Tree topology with custom bandwidth links

之前我使用以下命令创建了 mininet 拓扑:

sudo mn --topo tree,depth=2,fanout=5 --controller=remote,ip=10.0.0.1,port=6633 --switch ovsk,protocols=OpenFlow13, --link tc,bw=1,delay=10ms

我需要为不同的链接指定自定义 bw 值。

如何以通用方式制作树,指定 depthfanout 值,如 TreeNet 提到的 here?我需要 setLink(int value, src, dest) 来修改创建的树的链接。

直到现在我有这个:

#!/usr/bin/python

from functools import partial
from mininet.cli import CLI
from mininet.link import TCLink
from mininet.log import setLogLevel
from mininet.net import Mininet
from mininet.node import OVSKernelSwitch
from mininet.node import RemoteController
from mininet.topo import Topo
from mininet.util import dumpNodeConnections


class MyNet( Topo ):    
    def __init__( self ):
        "Create custom topo."

        # Initialize topology
        Topo.__init__( self )

        # Add hosts
        h1 = self.addHost( 'h1' )
        h2 = self.addHost( 'h2' )
        ...
        h25 = self.addHost( 'h25' )

    # Add switches
        s1 = self.addSwitch( 's1' )
        ...
        s6 = self.addSwitch( 's6' )

        # Add links
        self.addLink( s2, s1 ,bw=10)
        self.addLink( s3, s1 ,bw=10)
        self.addLink( s4, s1 ,bw=10)
        self.addLink( s5, s1 ,bw=10)
        self.addLink( s6, s1 ,bw=10)

        self.addLink( h1, s2 ,bw=10)
        self.addLink( h2, s2 ,bw=10)
        self.addLink( h3, s2 ,bw=10)
        self.addLink( h4, s2 ,bw=10)
        self.addLink( h5, s2 ,bw=10)

        self.addLink( h6, s3 ,bw=10)
        self.addLink( h7, s3 ,bw=10)
        self.addLink( h8, s3 ,bw=10)
        self.addLink( h9, s3 ,bw=10)
        self.addLink( h10, s3 ,bw=10)

        self.addLink( h11, s4 ,bw=10)
        ...
        self.addLink( h25, s6 ,bw=10)

topos = { 'MyNet': ( lambda: MyNet() ) }

我正在使用:

#sudo mn --custom MyNet.py --topo MyNet --controller=remote,ip=10.0.0.1,port=6633 --switch ovsk,protocols=OpenFlow13 --link tc

这是快速制作的内容。它似乎在工作。我从 topolib.py

得到了一点

代码使用递归。函数 addTree() 在其自身内部被调用。

__author__ = 'Ehsan'
from mininet.node import CPULimitedHost
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.log import setLogLevel, info
from mininet.node import RemoteController
from mininet.cli import CLI
from mininet.link import TCLink
"""
Instructions to run the topo:
    1. Go to directory where this fil is.
    2. run: sudo -E python <file name>
       In this case it is: sudo -E python Tree_Generic_Topo.py     
"""


class GenericTree(Topo):
    """Simple topology example."""

    def build( self, depth=1, fanout=2 ):
        # Numbering:  h1..N, s1..M
        self.hostNum = 1
        self.switchNum = 1

    def build( self, depth=1, fanout=2 ):
        # Numbering:  h1..N, s1..M
        self.hostNum = 1
        self.switchNum = 1
        # Build topology
        self.addTree(depth, fanout)

    def addTree( self, depth, fanout ):
        """Add a subtree starting with node n.
           returns: last node added"""
        isSwitch = depth > 0
        if isSwitch:
            node = self.addSwitch( 's%s' % self.switchNum )
            self.switchNum += 1
            for _ in range( fanout ):
                child = self.addTree( depth - 1, fanout )
                self.addLink( node, child )
        else:
            node = self.addHost( 'h%s' % self.hostNum )
            self.hostNum += 1
        return node


def run():
    c = RemoteController('c', '0.0.0.0', 6633)
    # Change the args of GenericTree() to your desired values. You could even get them from command line.
    net = Mininet(topo=GenericTree(depth=2, fanout=3), host=CPULimitedHost, controller=None)
    net.addController(c)
    net.start()

    # installStaticFlows( net )
    CLI(net)
    net.stop()

# if the script is run directly (sudo custom/optical.py):
if __name__ == '__main__':
    setLogLevel('info')
    run()