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


Python Node.setMAC方法代码示例

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


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

示例1: myNet

# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import setMAC [as 别名]
def myNet():
   "Defines a custom topology on mininet."

   print "*** Starting MyNet ***"
   cParams = ControllerParams( '10.0.3.0', 24 )
   net = Mininet( controller=RemoteController, switch=OVSKernelSwitch, cparams=cParams )

   print "** Adding controller"
   c = net.addController( 'c0' )

   print "** Adding switches"
   s1 = net.addSwitch( 's1' )
   s2 = net.addSwitch( 's2' )
   s3 = net.addSwitch( 's3' )
   s4 = net.addSwitch( 's4' )

   print "** Adding hosts"
   h5 = net.addHost( 'h5', ip='10.0.3.5' )
   h6 = net.addHost( 'h6', ip='10.0.3.6' )
   h7 = net.addHost( 'h7', ip='10.0.3.7' )
   h8 = net.addHost( 'h8', ip='10.0.3.8' )
   h9 = net.addHost( 'h9', ip='10.0.3.9' )

   print "** Linking switches together"
   s1.linkTo( s2 )
   s2.linkTo( s3 )
   s2.linkTo( s4 )

   print "** Linking hosts to switches"
   h5.linkTo( s1 )
   h6.linkTo( s3 )
   h7.linkTo( s3 )
   h8.linkTo( s4 )
   h9.linkTo( s4 )

   #print "** Setting up IP addresses"
   #h5.setIP( h5.defaultIntf(), '10.0.3.5', 24)

   #extraPort1 = s1.newPort()
   #extraPortName1 = s1.intfName( extraPort1 )
   #print "** Adding extra port to s1 - " + extraPortName1
   #s1.addIntf( extraPortName1, extraPort1 )

   #print "** Linking xeth0 to s1 port " + extraPortName1
   #makeIntfPair( "xeth0", extraPortName1 )

   #extraPort2 = s4.newPort()
   #extraPortName2 = s4.intfName( extraPort2 )
   #print "** Adding extra port to s4 - " + extraPortName2
   #s4.addIntf( extraPortName2, extraPort2 )

   #print "** Linking xeth1 to s4 port " + extraPortName2
   #makeIntfPair( "xeth1", extraPortName2 )

   print "** Creating extra node to enable access to others"
   # Create a node in root namespace and link to switch 0
   root = Node( 'root', inNamespace=False )
   root.linkTo( s1 )
   root.setMAC( root.defaultIntf(), "00:00:00:10:00:64" )
   root.setIP( root.defaultIntf(), "10.0.3.100", 24 )

   #Configure everything
   s1.setMAC ( 's1-eth1', '00:00:00:10:01:01' )
   s1.setMAC ( 's1-eth2', '00:00:00:10:01:02' )
   s1.setMAC ( 's1-eth3', '00:00:00:10:01:03' )
   s2.setMAC ( 's2-eth1', '00:00:00:10:02:01' )
   s2.setMAC ( 's2-eth2', '00:00:00:10:02:02' )
   s2.setMAC ( 's2-eth3', '00:00:00:10:02:03' )
   s3.setMAC ( 's3-eth1', '00:00:00:10:03:01' )
   s3.setMAC ( 's3-eth2', '00:00:00:10:03:02' )
   s3.setMAC ( 's3-eth3', '00:00:00:10:03:03' )
   s4.setMAC ( 's4-eth1', '00:00:00:10:04:01' )
   s4.setMAC ( 's4-eth2', '00:00:00:10:04:02' )
   s4.setMAC ( 's4-eth3', '00:00:00:10:04:03' )
   s1.setIP ( s1.defaultIntf(), '10.0.3.1', 24 )
   s2.setIP ( s2.defaultIntf(), '10.0.3.2', 24 )
   s3.setIP ( s3.defaultIntf(), '10.0.3.3', 24 )
   s4.setIP ( s4.defaultIntf(), '10.0.3.4', 24 )

   h5.setMAC( h5.defaultIntf(), "00:00:00:10:00:05" )
   h6.setMAC( h6.defaultIntf(), "00:00:00:10:00:06" )
   h7.setMAC( h7.defaultIntf(), "00:00:00:10:00:07" )
   h8.setMAC( h8.defaultIntf(), "00:00:00:10:00:08" )
   h9.setMAC( h9.defaultIntf(), "00:00:00:10:00:09" )

   print "** Firing up the network"
   net.build()
   # Try to add eth1 into s1
   #print s1.cmd( 'ovs-dpctl add-if dp0 eth1' )
   c.start()
   s1.start( [ c ] )
   s2.start( [ c ] )
   s3.start( [ c ] )
   s4.start( [ c ] )

   print "** Starting SSH Server in every host"
   sshpids = {}
   for h in net.hosts:
      h.cmd( '/usr/sbin/sshd -D &' )
      time.sleep(2) # Whait for the daemon to come up so we can see its pid (this is not very safe)
#.........这里部分代码省略.........
开发者ID:ComputerNetworks-UFRGS,项目名称:Aurora,代码行数:103,代码来源:topology_im2013.py

示例2: myNet

# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import setMAC [as 别名]
def myNet():
    "Defines a custom topology on mininet."

    print "*** Starting MyNet ***"
    cParams = ControllerParams( '10.0.3.0', 24 )
    net = Mininet( controller=RemoteController, switch=OVSKernelSwitch, cparams=cParams )

    print "** Adding controller"
    c = net.addController( 'c0' )

    print "** Adding switches"
    s1 = net.addSwitch( 's1' )
    s2 = net.addSwitch( 's2' )
    s3 = net.addSwitch( 's3' )
    s4 = net.addSwitch( 's4' )
    s5 = net.addSwitch( 's5' )
    s6 = net.addSwitch( 's6' )
    s7 = net.addSwitch( 's7' )
    s8 = net.addSwitch( 's8' )
    s9 = net.addSwitch( 's9' )
    s10 = net.addSwitch( 's10' )

    print "** Adding hosts"
    h1 = net.addHost( 'h1', ip='10.0.3.1' )
    h2 = net.addHost( 'h2', ip='10.0.3.2' )
    h3 = net.addHost( 'h3', ip='10.0.3.3' )
    h4 = net.addHost( 'h4', ip='10.0.3.4' )
    h5 = net.addHost( 'h5', ip='10.0.3.5' )
    h6 = net.addHost( 'h6', ip='10.0.3.6' )
    h7 = net.addHost( 'h7', ip='10.0.3.7' )
    h8 = net.addHost( 'h8', ip='10.0.3.8' )
    h9 = net.addHost( 'h9', ip='10.0.3.9' )
    h10 = net.addHost( 'h10', ip='10.0.3.10' )
    h11 = net.addHost( 'h11', ip='10.0.3.11' )
    h12 = net.addHost( 'h12', ip='10.0.3.12' )
    h13 = net.addHost( 'h13', ip='10.0.3.13' )
    h14 = net.addHost( 'h14', ip='10.0.3.14' )
    h15 = net.addHost( 'h15', ip='10.0.3.15' )
    h16 = net.addHost( 'h16', ip='10.0.3.16' )
    h17 = net.addHost( 'h17', ip='10.0.3.17' )
    h18 = net.addHost( 'h18', ip='10.0.3.18' )
    h19 = net.addHost( 'h19', ip='10.0.3.19' )
    h20 = net.addHost( 'h20', ip='10.0.3.20' )

    print "** Linking switches and hosts"
    # S1
    s1.linkTo( s2 )
    s1.linkTo( h1 )
    s1.linkTo( h2 )
    s1.linkTo( h3 )
    # S2
    s2.linkTo( s3 )
    s2.linkTo( s4 )
    s2.linkTo( s5 )
    # S3
    s3.linkTo( s6 )
    s3.linkTo( h4 )
    s3.linkTo( h5 )
    # S4
    s4.linkTo( s8 )
    s4.linkTo( h6 )
    s4.linkTo( h7 )
    s4.linkTo( h8 )
    # S5
    s5.linkTo( s9 )
    s5.linkTo( s10 )
    s5.linkTo( h9 )
    s5.linkTo( h10 )
    # S6
    s6.linkTo( s7 )
    s6.linkTo( h11 )
    s6.linkTo( h12 )
    s6.linkTo( h13 )
    # S7
    s7.linkTo( h14 )
    s7.linkTo( h15 )
    s7.linkTo( h16 )
    # S8
    s8.linkTo( h17 )
    s8.linkTo( h18 )
    # S9
    s9.linkTo( h19 )
    # S10
    s10.linkTo( h20 )

    print "** Creating extra node to enable access to others"
    # Create a node in root namespace and link to switch 0
    root = Node( 'root', inNamespace=False )
    root.linkTo( s1 )
    root.setMAC( root.defaultIntf(), "00:00:00:11:00:64" )
    root.setIP( root.defaultIntf(), "10.0.3.100", 24 )

    # Configure everything
    s1.setMAC ( 's1-eth1', '00:00:00:10:01:01' )
    s1.setMAC ( 's1-eth2', '00:00:00:10:01:02' )
    s1.setMAC ( 's1-eth3', '00:00:00:10:01:03' )
    s1.setMAC ( 's1-eth4', '00:00:00:10:01:04' )
    s1.setMAC ( 's1-eth5', '00:00:00:10:01:05' ) # Extra for the root

    s2.setMAC ( 's2-eth1', '00:00:00:10:02:01' )
#.........这里部分代码省略.........
开发者ID:ComputerNetworks-UFRGS,项目名称:Aurora,代码行数:103,代码来源:topology_complex.py


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