當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。