有人可以给我看一个python脚本,它在Mininet中创建一个简单的自定义拓扑,它使用深度和扇出为2的树形拓扑吗?非常感谢。
答案 0 :(得分: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() ) }
答案 1 :(得分: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)