本文整理汇总了Python中mininet.topo.Topo方法的典型用法代码示例。如果您正苦于以下问题:Python topo.Topo方法的具体用法?Python topo.Topo怎么用?Python topo.Topo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mininet.topo
的用法示例。
在下文中一共展示了topo.Topo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: networkx_to_mininet
# 需要导入模块: from mininet import topo [as 别名]
# 或者: from mininet.topo import Topo [as 别名]
def networkx_to_mininet(G, hosts, switches, mapping):
# Conversion from NetworkX topology into FNSS topology
fnss_topo = fnss.Topology(G)
# G is a NetworkX Graph() and fnss_topo is a FNSS Topology(): hosts and switches are indistinguishable.
# We exploit 'mapping' returned from parse_network_xml() for nodes role differentiation.
# We can't use fnss.adapters.to_mininet() because we need a customized nodes relabeling.
# TODO link capacities!! http://fnss.github.io/doc/core/_modules/fnss/adapters/mn.html
# Conversion from FNSS topology into Mininet topology
nodes = set(fnss_topo.nodes_iter())
hosts = sorted(set(hosts))
switches = sorted(set(switches))
hosts = set(mapping[v] for v in hosts)
switches = set(mapping[v] for v in switches)
if not switches.isdisjoint(hosts):
raise ValueError('Some nodes are labeled as both host and switch. '
'Switches and hosts node lists must be disjoint')
if hosts.union(switches) != switches.union(hosts):
raise ValueError('Some nodes are not labeled as either host or switch '
'or some nodes listed as switches or hosts do not '
'belong to the topology')
fnss_topo = nx.relabel_nodes(fnss_topo, mapping, copy=True)
global mn_topo
mn_topo = Topo()
for v in switches:
mn_topo.addSwitch(str(v))
for v in hosts:
mn_topo.addHost(str(v))
for u, v in fnss_topo.edges_iter():
params = {}
mn_topo.addLink(str(u), str(v), **params)
return mn_topo