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


Python Host.intf方法代码示例

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


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

示例1: emptyNet

# 需要导入模块: from mininet.node import Host [as 别名]
# 或者: from mininet.node.Host import intf [as 别名]
def emptyNet():

    net = Mininet(switch=OVSSwitch, build=False)

    #c0 = net.addController('c0', controller=RemoteController, port=6633)
    #c1 = net.addController('c1', controller=RemoteController, port=6634)
    c0 = net.addController('c0', controller=Controller, port=6634)
    c1 = net.addController('c1', controller=Controller, port=6635)

    h1 = net.addHost('host1', ip='192.168.0.2/24', mac='00:1e:65:15:fc:01')
    h2 = net.addHost('host2', ip='192.168.0.3/24', mac='00:1e:65:15:fc:02')
    s1 = net.addSwitch('br0')
    net.addLink(h1, s1)
    net.addLink(h2, s1)

    h3 = net.addHost('host3', ip='172.168.0.2/24', mac='00:1e:65:15:fc:03')
    h4 = net.addHost('host4', ip='172.168.0.3/24', mac='00:1e:65:15:fc:04')
    s2 = net.addSwitch('br1')
    net.addLink(h3, s2)
    net.addLink(h4, s2)

    # hide the gatway in net
    gateway = Host('gateway')
    net.addLink(s1, gateway)
    net.addLink(s2, gateway)
    gateway.intf("gateway-eth0").setIP('192.168.0.1/24')
    gateway.intf("gateway-eth1").setIP('172.168.0.1/24')

    # show gateway in net
    #gateway = net.addHost('gateway', ip='192.168.0.1/24')
    #net.addLink(s1, gateway)
    #net.addLink(s2, gateway)
    #gateway.intf("gateway-eth1").setIP('172.168.0.1/24')

    net.build()

    print h1.cmd('ip route add default via 192.168.0.1 dev host1-eth0')
    print h2.cmd('ip route add default via 192.168.0.1 dev host2-eth0')
    print h3.cmd('ip route add default via 172.168.0.1 dev host3-eth0')
    print h4.cmd('ip route add default via 172.168.0.1 dev host4-eth0')

    c0.start()
    c1.start()
    s1.start([c0])
    s2.start([c1])

    #s1.cmd('ovs-vsctl set bridge br0 protocols=OpenFlow13')
    #s2.cmd('ovs-vsctl set bridge br1 protocols=OpenFlow13')
    CLI( net )
    net.stop()
开发者ID:exuuwen,项目名称:study,代码行数:52,代码来源:mininet_net.py


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