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


哈哈哈哈
2025-03-11 09:20:56 (28天前)


以前我使用命令创建了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



2 条回复
  1. 0# 無口君 | 2019-08-31 10-32



    这是快速做出的。它似乎工作。我得到了一些

    topolib.py



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




    1. 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:

    2. 1. Go to directory where this fil is.
    3. 2. run: sudo -E python <file name>
    4.    In this case it is: sudo -E python Tree_Generic_Topo.py     
    5. “””

    6. class GenericTree(Topo):
      “””Simple topology example.”””

    7. def build( self, depth=1, fanout=2 ):
    8.     # Numbering:  h1..N, s1..M
    9.     self.hostNum = 1
    10.     self.switchNum = 1
    11. def build( self, depth=1, fanout=2 ):
    12.     # Numbering:  h1..N, s1..M
    13.     self.hostNum = 1
    14.     self.switchNum = 1
    15.     # Build topology
    16.     self.addTree(depth, fanout)
    17. def addTree( self, depth, fanout ):
    18.     """Add a subtree starting with node n.
    19.        returns: last node added"""
    20.     isSwitch = depth > 0
    21.     if isSwitch:
    22.         node = self.addSwitch( 's%s' % self.switchNum )
    23.         self.switchNum += 1
    24.         for _ in range( fanout ):
    25.             child = self.addTree( depth - 1, fanout )
    26.             self.addLink( node, child )
    27.     else:
    28.         node = self.addHost( 'h%s' % self.hostNum )
    29.         self.hostNum += 1
    30.     return node
    31. def run():
      c = RemoteController(‘c’, 0.0.0.0’, 6633)

    32. # Change the args of GenericTree() to your desired values. You could even get them from command line.
    33. net = Mininet(topo=GenericTree(depth=2, fanout=3), host=CPULimitedHost, controller=None)
    34. net.addController(c)
    35. net.start()
    36. # installStaticFlows( net )
    37. CLI(net)
    38. net.stop()
    39. if the script is run directly (sudo custom/optical.py):

      if name == main‘:
      setLogLevel(‘info’)
      run()

    40. </code>

登录 后才能参与评论