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


Python Mininet.hosts方法代码示例

本文整理汇总了Python中mininet.net.Mininet.hosts方法的典型用法代码示例。如果您正苦于以下问题:Python Mininet.hosts方法的具体用法?Python Mininet.hosts怎么用?Python Mininet.hosts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mininet.net.Mininet的用法示例。


在下文中一共展示了Mininet.hosts方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: pairNet

# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import hosts [as 别名]
def pairNet( pairs=1, useSwitches=False, bw=None, cpu=-1, **kwargs ):
    "Convenience function for creating pair networks"
    clients, servers = [], []
    # This is a bit ugly - a lot of work to avoid flushing
    # routes; I think we should rethink how that works.
    class MyHost( CPULimitedHost ):
        "Put clients in root namespace and DON'T flush routes"
        def __init__( self, name, **kwargs ):
            # First N (=pairs) hosts are clients, in root NS
            kwargs.pop('inNamespace', True)
            isServer = int( name[ 1: ] ) > pairs
            CPULimitedHost.__init__( self, name, inNamespace=isServer, **kwargs )
        def setDefaultRoute( self, intf ):
            "Hack of sorts: don't set or flush route"
            pass

    cpu = custom( MyHost, cpu=cpu )
    link = custom( TCLink, bw=bw )
    topo = PairTopo( pairs, useSwitches )
    net = Mininet( topo, host=MyHost, **kwargs )
    net.hosts = sorted( net.hosts, key=lambda h: natural( h.name ) )
    clients, servers = net.hosts[ :pairs ], net.hosts[ pairs: ]
    info( "*** Configuring host routes\n" )
    for client, server in zip( clients, servers ):
        client.setHostRoute( server.IP(), client.defaultIntf() )
        server.setHostRoute( client.IP(), server.defaultIntf() )
    return net, clients, servers
开发者ID:EliseuTorres,项目名称:mininet-tests,代码行数:29,代码来源:pair_intervals.py

示例2: info

# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import hosts [as 别名]
info( '* Starting Control Network\n')
cnet.build()
cnet.start()
dataControllers = cnet.hosts[ : -1 ]  # ignore 'root' node

info( '* Creating Data Network\n' )
topo = TreeTopo( depth=2, fanout=2 )
# UserSwitch so we can easily test failover
net = Mininet( topo=topo, switch=UserSwitch, build=False )
info( '* Adding Controllers to Data Network\n' )
net.controllers = dataControllers
net.build()
info( '* Starting Data Network\n')
net.start()

CLI2( net, cnet=cnet )

info( '* Stopping Data Network\n' )
net.stop()

info( '* Stopping Control Network\n' )
# dataControllers have already been stopped
cnet.hosts = list( set( cnet.hosts ) - set( dataControllers ) )
cnet.stop()






开发者ID:HaiVu,项目名称:mininet,代码行数:26,代码来源:controlnet.py


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