本文整理匯總了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