有人可以给我看一个 python 脚本,它在 Mininet 中创建一个简单的自定义拓扑,它使用深度和扇出为 2 的树形拓扑?这将不胜感激。
问问题
996 次
2 回答
0
例子:
from mininet.topo import Topo
class CustomTopo(Topo):
def __init__(self, linkopts1, linkopts2, linkopts3, fanout=2, **opts):
Topo.__init__(self, **opts)
self.fanout = fanout
self.linkopts1 = linkopts1
self.linkopts2 = linkopts2
self.linkopts3 = linkopts3
self.coreNumbering = 1
self.aggNumbering = 1
self.edgNumbering = 1
self.hosNumbering = 1
depth = 3
self.createTreeTopo(depth, fanout)
def createTreeTopo(self, depth, fanout):
thisCore = depth == 3
thisAggregation = depth == 2
thisEdge = depth == 1
if depth > 0:
linkopts = dict()
if thisCore:
node = self.addSwitch('c%s' % self.coreNumbering)
self.coreNumbering += 1
linkopts = self.linkopts1
if thisAggregation:
node = self.addSwitch('a%s' % self.aggNumbering)
self.aggNumbering += 1
linkopts = self.linkopts2
if thisEdge:
node = self.addSwitch('e%s' % self.edgNumbering)
self.edgNumbering += 1
linkopts = self.linkopts3
for _ in range(fanout):
child = self.createTreeTopo(depth - 1, fanout)
self.addLink(node, child, **linkopts)
else:
node = self.addHost('h%s' % self.hosNumbering)
self.hosNumbering += 1
return node
topos = { 'custom': ( lambda: CustomTopo() ) }
于 2015-06-17T00:45:57.037 回答
0
如果你想使用TreeNet
来自的类mininet.topolib
:
from mininet.cli import CLI
from mininet.log import setLogLevel
from mininet.node import OVSKernelSwitch
from mininet.topolib import TreeNet
from mininet.net import Mininet
from mininet.node import RemoteController
if __name__ == '__main__':
setLogLevel( 'info' )
print "Input Depth :"
_depth = int(raw_input())
print "Input fanout :"
_fanout = int(raw_input())
network = TreeNet( depth= _depth, fanout= _fanout, controller= RemoteController, autoSetMacs = True, cleanup = True, switch=OVSKernelSwitch)
print network.topo.links()
# network.startTerms()
network.run(CLI, network)
于 2015-06-23T18:17:14.953 回答