当前位置: 首页>>代码示例>>Python>>正文


Python topo.Topo方法代码示例

本文整理汇总了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 
开发者ID:OpenState-SDN,项目名称:ryu,代码行数:39,代码来源:f_t_parser_ff.py


注:本文中的mininet.topo.Topo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。