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


Python Mininet.addNAT方法代码示例

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


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

示例1: myNetwork

# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addNAT [as 别名]
def myNetwork():

    net = Mininet( topo=None,
                   listenPort=6633,
                   build=False,
                   ipBase='10.0.0.0/8',
		   link=TCLink,
		   )

    info( '*** Adding controller\n' )
    c0=net.addController(name='c0',
                      controller=RemoteController,
		      protocols='OpenFlow13',
		      ip='127.0.0.1'
                     )

    info( '*** Add switches\n')
    s1 = net.addSwitch('s3', cls=OVSSwitch, mac='00:00:00:00:00:06', protocols='OpenFlow13')
    s2 = net.addSwitch('s2', cls=OVSSwitch, mac='00:00:00:00:00:05', protocols='OpenFlow13')
    s3 = net.addSwitch('s1', cls=OVSSwitch, mac='00:00:00:00:00:04', protocols='OpenFlow13')

    info( '*** Add hosts\n')
    h1 = net.addHost('h3', cls=Host, ip='10.0.0.3', mac='00:00:00:00:00:03', defaultRoute='via 10.0.0.4')
    h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', mac='00:00:00:00:00:02', defaultRoute='via 10.0.0.4')
    h3 = net.addHost('h1', cls=Host, ip='10.0.0.1', mac='00:00:00:00:00:01', defaultRoute='via 10.0.0.4')
    # La ruta por defecto de los host es la de NAT (10.0.0.4 en este caso)

    info('*** Add NAT\n')
    net.addNAT().configDefault()


    info( '*** Add links\n')
    net.addLink(s1, s2, bw=10, delay='0.2ms')
    net.addLink(s1, s3, bw=10, delay='0.2ms')
    #net.addLink(s2, s1, bw=10, delay='0.2ms') #Esta linea con este controlador provoca errores.
    net.addLink(s1, h1, bw=10, delay='0.2ms')
    net.addLink(s2, h2, bw=10, delay='0.2ms')
    net.addLink(s3, h3, bw=10, delay='0.2ms')


    info( '*** Starting network\n')
    net.build()
    net.start()
    info( '*** Starting controllers\n')
    for controller in net.controllers:
        controller.start()


    info( '*** Starting switches\n')
    net.get('s3').start([c0])
    net.get('s2').start([c0])
    net.get('s1').start([c0])

    info( '*** Post configure switches and hosts\n')

    CLI(net)
    net.stop()
开发者ID:pahharo,项目名称:dissectorapp,代码行数:59,代码来源:topo_nat.py

示例2: myNetwork

# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addNAT [as 别名]
def myNetwork():

    net = Mininet( topo=None,
                   build=False,
                   ipBase='10.0.0.0/8')

    info( '*** Adding controller\n' )
    c0=net.addController(name='c0',
                      controller=RemoteController,
                      ip='192.168.1.10',
                      protocol='tcp',
                      port=6633)

    info( '*** Add switches\n')
    #s4 = net.addSwitch('s4', cls=OVSKernelSwitch)
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch)
    s4 = net.addSwitch('s4', cls=OVSKernelSwitch)
    s3 = net.addSwitch('s3', cls=OVSKernelSwitch)
    s1 = net.addSwitch('s1', cls=OVSKernelSwitch)

    info( '*** Add hosts\n')
    h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
    h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)

    info( '*** Add links\n')
    net.addLink(h1, s1)
    net.addLink(s1, s2)
    net.addLink(s1, s3)
    net.addLink(s2, s4)
    net.addLink(s3, s4)
    net.addLink(s4, h2)

    info( '*** Starting network\n')
    net.build()
    info( '*** Starting controllers\n')
    for controller in net.controllers:
        controller.start()

    info( '*** Starting switches\n')
    net.get('s4').start([c0])
    net.get('s2').start([c0])
    net.get('s3').start([c0])
    net.get('s1').start([c0])

    info( '*** Post configure switches and hosts\n')
  
    info( '*** Add NAT connectivity\n')
    net.addNAT().configDefault()
    info( '*** Hosts are running and should have internet connectivity\n')
    net.start()
    CLI(net)
    net.stop()
开发者ID:RotemNe,项目名称:SDN-Based-Private-Interconnection,代码行数:54,代码来源:PrivateInterTopo.py

示例3: myNetwork

# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addNAT [as 别名]
def myNetwork():

    net = Mininet( topo=None,
                   build=False)


    info( '*** Adding controller\n' )
    net.addController(name='c0', controller=RemoteController, ip='127.0.0.1', port=6633)

    info( '*** Add switches\n')
    s1 = net.addSwitch('s1')
    Intf( 'eth1', node=s1 )
    net.addNAT().configDefault()
    s2 = net.addSwitch('s2')

    s3 = net.addSwitch('s3')


    info( '*** Add hosts\n')
    h1 = net.addHost('h1', ip='0.0.0.0')
    h2 = net.addHost('h2', ip='0.0.0.0')
    h3 = net.addHost('h3', ip='0.0.0.0')
    h4 = net.addHost('h4', ip='0.0.0.0')
#    h1 = net.addHost('h1', ip='10.0.3.16')
#    h2 = net.addHost('h2', ip='10.0.3.18')
#    h3 = net.addHost('h3', ip='10.0.3.19')
#    h4 = net.addHost('h4', ip='10.0.3.20')
#    h1 = net.addHost('h1')

    

    info( '*** Add links\n')
    net.addLink(h1, s2)
    net.addLink(h2, s2)
    net.addLink(h3, s3)
    net.addLink(h4, s3)
    net.addLink(s1, s2)
    net.addLink(s2, s3)
    net.addLink(s1, s3)
#    net.addLink(h1, s1)

    info( '*** Starting network\n')
    net.start()
    h1.cmdPrint('dhclient '+h1.defaultIntf().name)
    h2.cmdPrint('dhclient '+h2.defaultIntf().name)
    h3.cmdPrint('dhclient '+h3.defaultIntf().name)
    h4.cmdPrint('dhclient '+h4.defaultIntf().name)
    CLI(net)
    net.stop()
开发者ID:helbersilva,项目名称:ryu,代码行数:51,代码来源:mytoponet.py

示例4: myNetwork

# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addNAT [as 别名]
def myNetwork():

    net = Mininet( topo=None,
                   listenPort=6633,
                   build=False,
                   ipBase='10.0.0.0/8',
		   link=TCLink,
		   )

    info( '*** Adding controller\n' )
    c0=net.addController(name='c0',
                      controller=RemoteController,
		      protocols='OpenFlow13',
		      ip='127.0.0.1'
                     )
    info( '*** Add switches\n')
    s1 = net.addSwitch('s1', cls=OVSSwitch, mac='00:00:00:00:00:10', protocols='OpenFlow13')

    info( '*** Add hosts\n')
    h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', mac='00:00:00:00:00:01', defaultRoute='via 10.0.0.2') # defaultRoute es la ip del nat

    info('*** Add NAT\n')
    net.addNAT().configDefault()

    net.addLink(s1, h1, bw=10, delay='0.2ms')

    info( '*** Starting network\n')
    net.build()
    net.start()
    info( '*** Starting controllers\n')
    for controller in net.controllers:
        controller.start()


    info( '*** Starting switches\n')
    net.get('s1').start([c0])

    info( '*** Post configure switches and hosts\n')

    CLI(net)
    net.stop()
开发者ID:pahharo,项目名称:dissectorapp,代码行数:43,代码来源:topo_s1_nat.py

示例5: Application

# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addNAT [as 别名]
class Application(Topo):
  def syn_flood(self):
    for h in self.net.hosts[:10]:
      h.cmd("python /home/fschardong/escape/other/scapy-2.3.1/syn_flood.py -d 10.0.0.17 -p 8000 -c x &")


    

  def __init__(self, **opts):
    topo = TreeTopo(depth=2,fanout=4)

    http = topo.addHost('http')
    http_switch = topo.addSwitch('s0')
    topo.addLink(http, http_switch)
    topo.addLink(topo.root, http_switch)

    self.net = Mininet(topo, controller = OVSController)
    self.net.addNAT().configDefault()
    self.net.start()

    self.net.switches[0].cmd("ifconfig s0 10.0.0.253")

    #self.net.hosts[100].cmd("cvlc -vvv small.mp4 --sout '#standard{access=http,mux=asf,dst=:8080}' --repeat >& /tmp/stream.log &")
    #self.net.hosts[100].cmd("cd other; python -m SimpleHTTPServer >& /tmp/http.log &")

    #for h in self.net.hosts[20:50]:
    #  h.cmd("python networkUser.py &")

    self.net.hosts[16].cmd("/home/fschardong/escape/other/orchestrator.sh > /tmp/orchestrator.log &")

    t = Timer(1, self.syn_flood)
    t.start()

   # t = Timer(90, self.syn_flood)
   # t.start()

    t = Timer(600, self.net.stop)
    t.start()
开发者ID:fredericoschardong,项目名称:escape,代码行数:40,代码来源:application.py

示例6: emptyNet

# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addNAT [as 别名]
def emptyNet():

    NODE2_IP='192.168.144.134'
    CONTROLLER_IP='192.168.144.126'

    net = Mininet( topo=None,
                   build=False)

    #c0 = net.addController( 'c0',controller=RemoteController,ip=CONTROLLER_IP,port=6633)
    net.addController('c0', port=6633)

    h1 = net.addHost( 'h1', ip='10.0.0.1' )
    h2 = net.addHost( 'h2', ip='10.0.0.2' )
    s1 = net.addSwitch( 's1' )
    net.addLink( h1, s1,1,1)
    net.addLink( h2, s1,1,2)
    net.build()
    net.addNAT(ip='10.0.0.5').configDefault()
    net.start()
    #net.addNAT().configDefault()
    #s1.start([c0])
    #s1.cmdPrint('ovs-vsctl set bridge s1 protocols=OpenFlow13')
    # Configure the GRE tunnel
    s1.cmdPrint('ovs-vsctl add-port s1 s1-gre1 -- set interface s1-gre1 type=gre ofport_request=5 options:remote_ip='+NODE2_IP)
    s1.cmdPrint('ovs-vsctl show')
    #s1.cmdPrint('ovs-vsctl set bridge s1 protocols=OpenFlow13')
    #os.system('ovs-ofctl add-flow s1 eth_type=2048,ip_dst=10.0.1.3,action=output:5')
    #os.system('ovs-ofctl add-flow s1 eth_type=2048,ip_dst=10.0.1.4,action=output:5')
    #os.system('ovs-ofctl add-flow s1 eth_type=2054,ip_dst=10.0.1.3,action=output:5')
    #os.system('ovs-ofctl add-flow s1 eth_type=2054,ip_dst=10.0.1.4,action=output:5')
    h1.cmdPrint('ip link set mtu 1454 dev h1-eth1')
    h2.cmdPrint('ip link set mtu 1454 dev h2-eth1')
    nat = net.get('nat0')
    nat.cmdPrint('ip link set mtu 1454 dev nat0-eth0')
    #net.addNAT().configDefault()
    CLI( net )
    net.stop()
开发者ID:john35452,项目名称:sdn-p2p,代码行数:39,代码来源:a.py

示例7: startControlNet

# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addNAT [as 别名]
 def startControlNet( cls ):
     "Start control net if necessary and return it"
     cnet = cls.cnet
     if not cnet:
         info( '### Starting control network\n' )
         cnet = Mininet( ipBase=cls.ipBase )
         cswitch = cnet.addSwitch( 'ovsbr0', cls=OVSBridge )
         # Add NAT - note this can conflict with data network NAT
         info( '### Adding NAT for control and data networks'
               ' (use --nat flush=0 for data network)\n' )
         cls.cnet = cnet
         cls.nat = cnet.addNAT( 'ovsdbnat0')
         cnet.start()
         info( '### Control network started\n' )
     return cnet
开发者ID:AntonySilvester,项目名称:OnosSystemTest,代码行数:17,代码来源:multiovs.py

示例8: multiControllerNet

# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addNAT [as 别名]
def multiControllerNet():
    "Create a network from semi-scratch with multiple controllers."

    CONTROLLER_IP='192.168.144.149'
    #CONTROLLER_IP='127.0.0.1'
    #net = Mininet( controller=Controller,host=CPULimitedHost)
    net = Mininet(controller=Controller)
    print "*** Creating (reference) controllers"
    #c1 = net.addController( 'c1', port=6633)
    c1 = net.addController('c1', controller=RemoteController,ip=CONTROLLER_IP,port=6633)
    #c2 = net.addController( 'c2', port=6634 )
    c2 = net.addController('c2', controller=RemoteController,ip=CONTROLLER_IP,port=6634)
    #c3 = net.addController( 'c3', port=6635 )
    c3 = net.addController('c3', controller=RemoteController,ip=CONTROLLER_IP,port=6635)

    layer = 5
    tmp = 1<<layer
    print "*** Creating switches"
    sdn_switch = [net.addSwitch('S%d'%(n),dpid = str(n+1).zfill(16)) for n in range(1)]
    left_switch = [net.addSwitch('L%d'%(n+1),dpid = str(n+1+100).zfill(16)) for n in range(tmp-1)]
    right_switch = [net.addSwitch('R%d'%(n+tmp),dpid = str(n+1+200).zfill(16)) for n in range(tmp-1)]
    #f = open('switch_list','w')
    switch_name = [n.name for n in sdn_switch]
    #switch_name = switch_name + [n.name for n in right_switch]
    #switch_name = switch_name + [n.name for n in sdn_switch]
    with open('switch_list','w') as f:
        f.write(' '.join(switch_name)) 
    print 'Finish writing switch_list'
       
    print "*** Creating hosts"
    hosts1 = [ net.addHost( 'h%d' % (n+1) ,ip='10.0.0.%s'%(n+1),mac='00:00:00:00:00:%s'%(hex(n+1)[2:])) for n in range(tmp) ]
    hosts2 = [ net.addHost( 'h%d' % (n+1+tmp) ,ip='10.0.0.%s'%(100+n+1),mac='00:00:00:00:01:%s'%(hex(n+1)[2:])) for n in range(tmp) ]

    print "*** Creating links"
    for i in range(len(left_switch)/2):
        net.addLink(left_switch[i],left_switch[(i+1)*2-1],2,1)
        net.addLink(left_switch[i],left_switch[(i+1)*2],3,1)
    for i in range(len(right_switch)/2):
        net.addLink(right_switch[i],right_switch[(i+1)*2-1],2,1)
        net.addLink(right_switch[i],right_switch[(i+1)*2],3,1)
    for i in range(len(sdn_switch)):
        net.addLink(sdn_switch[i],left_switch[0],2,1)
        net.addLink(sdn_switch[i],right_switch[0],3,1)
  
    ''' 
    for i in range(4): 
        for j in range(2):
            net.addLink(left_switch[i+3],hosts1[2*i+j])
            net.addLink(right_switch[i+3],hosts2[2*i+j])
    '''
    tmp >>= 1
    for i in range(tmp):
        for j in range(2):
            net.addLink(left_switch[i+tmp-1],hosts1[2*i+j],2+j,1)
            net.addLink(right_switch[i+tmp-1],hosts2[2*i+j],2+j,1)
    tmp <<= 1
    print "*** Starting network"
    net.build()
    net.addNAT(ip='10.0.0.254',mac='00:00:00:00:00:FF').configDefault()
    #net.build()
    c1.start()
    c2.start()
    c3.start()
    
    for k in left_switch:
        k.start([c3])
        k.cmd('ovs-vsctl set bridge '+k.name+' protocols=OpenFlow13')
    for k in right_switch:
        k.start([c2])
        k.cmd('ovs-vsctl set bridge '+k.name+' protocols=OpenFlow13')
    for k in sdn_switch:
        k.start([c1])
        k.cmd('ovs-vsctl set bridge '+k.name+' protocols=OpenFlow13')
    print 'Finish bridges setting'
    
    ovs_url = 'http://'+CONTROLLER_IP+':8080/v1.0/conf/switches/'+str(1).zfill(16)+'/ovsdb_addr'
    queue_url = 'http://'+CONTROLLER_IP+':8080/qos/queue/status/'+str(1).zfill(16)
    rule_url = 'http://'+CONTROLLER_IP+':8080/qos/rules/'+str(1).zfill(16)
    

    #connect ovsdb
    sdn_switch[0].cmdPrint('ovs-vsctl set-manager ptcp:6632')
    payload = "tcp:"+'192.168.144.134'+":6632"
    response = requests.put(ovs_url,data=json.dumps(payload))
    print response,response.text
    #c1.cmdPrint('curl -X PUT -d \'"tcp:127.0.0.1:6632"\' http://localhost:8080/v1.0/conf/switches/0000000000000001/ovsdb_addr') 
    
    #local queue setting
    times = tmp**2+tmp+1
    print 'Add ',times,'queues to S0-eth2 and S0-eth3'
    q1 = []
    q2 = []
    for i in range(times):
        q1.append(str(i)+'[email protected]'+str(i))
        q2.append('-- [email protected]'+str(i)+' create Queue other-config:max-rate='+str(1000*1000*8))
    q1 = ','.join(q1)
    q2 = ' '.join(q2)
    CMD = 'ovs-vsctl'
    sdn_switch[0].cmd(CMD+' -- set Port S0-eth2 [email protected] -- [email protected] create Qos type=linux-htb other-config:max-rate=1000000000 queues='+q1+' '+q2)
    sdn_switch[0].cmd(CMD+' -- set Port S0-eth3 [email protected] -- [email protected] create Qos type=linux-htb other-config:max-rate=1000000000 queues='+q1+' '+q2)
#.........这里部分代码省略.........
开发者ID:wjianwei126,项目名称:sdn-p2p,代码行数:103,代码来源:3-controller.py

示例9: multiControllerNet

# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addNAT [as 别名]
def multiControllerNet():
    "Create a network from semi-scratch with multiple controllers."

    NODE1_IP='192.168.144.126'
    NODE2_IP='192.168.144.134'
    CONTROLLER_IP='192.168.144.126'
    #net = Mininet( controller=Controller,host=CPULimitedHost)
    net = Mininet(controller=Controller)
    print "*** Creating (reference) controllers"
    c1 = net.addController( 'c1', port=6633 )
    #c1 = net.addController('c1', controller=RemoteController,ip='127.0.0.1',port=6633)
    #c2 = net.addController( 'c2', port=6634 )
    #c2 = net.addController('c2', controller=RemoteController,ip='127.0.0.1',port=6634)
    #c3 = net.addController( 'c3', port=6635 )
    #c3 = net.addController('c3', controller=RemoteController,ip='127.0.0.1',port=6635)

    layer = 3
    tmp = 1<<layer
    print "*** Creating switches"
    sdn_switch = [net.addSwitch('S%d'%(n)) for n in range(15,16)]
    left_switch = [net.addSwitch('L%d'%(n+1)) for n in range(tmp-1)]
    #right_switch = [net.addSwitch('R%d'%(n+tmp)) for n in range(tmp-1)]
    #f = open('switch_list','w')
    switch_name = [n.name for n in left_switch]
    #switch_name = switch_name + [n.name for n in right_switch]
    switch_name = switch_name + [n.name for n in sdn_switch]
    '''
    with open('switch_list','w') as f:
        f.write(' '.join(switch_name)) 
    print 'Finish writing switch_list'
    '''   
    print "*** Creating hosts"
    hosts1 = [ net.addHost( 'h%d' % (n+1) ,ip='10.0.0.%s'%(n+1)) for n in range(tmp) ]
    #hosts2 = [ net.addHost( 'h%d' % (n+1+tmp) ) for n in range(tmp) ]

    print "*** Creating links"
    for i in range(len(left_switch)/2):
        net.addLink(left_switch[i],left_switch[(i+1)*2-1])
        net.addLink(left_switch[i],left_switch[(i+1)*2])
    #for i in range(len(right_switch)/2):
    #    net.addLink(right_switch[i],right_switch[(i+1)*2-1])
    #    net.addLink(right_switch[i],right_switch[(i+1)*2])
    for i in range(len(sdn_switch)):
        #net.addLink(sdn_switch[i],right_switch[0])
        net.addLink(sdn_switch[i],left_switch[0])
    #net.addLink(sdn_switch[0],sdn_switch[1])
  
    ''' 
    for i in range(4): 
        for j in range(2):
            net.addLink(left_switch[i+3],hosts1[2*i+j])
            net.addLink(right_switch[i+3],hosts2[2*i+j])
    '''
    tmp >>= 1
    for i in range(tmp):
        for j in range(2):
            net.addLink(left_switch[i+tmp-1],hosts1[2*i+j])
            #net.addLink(right_switch[i+tmp-1],hosts2[2*i+j])

    print "*** Starting network"
    net.build()
    net.addNAT(ip='10.0.0.254').configDefault()
    #nat = net.addNAT(connect=None)
    #net.addLink(nat,sdn_switch[0])
    #nat.configDefault()
    #net.build()
    c1.start()
    #c2.start()
    #c3.start()
    for k in left_switch:
        k.start([c1])
    #for k in right_switch:
    #    k.start([c2])
    for k in sdn_switch:
        k.start([c1])
    
    sdn_switch[0].cmdPrint('ovs-vsctl add-port '+sdn_switch[0].name+' '+sdn_switch[0].name+'-gre1 -- set interface '+sdn_switch[0].name+'-gre1 type=gre options:remote_ip='+NODE2_IP)
    for k in hosts1:
        k.cmdPrint('ip link set mtu 1454 dev '+k.name+'-eth0')
    nat = net.get('nat0')
    nat.cmdPrint('ip link set mtu 1454 dev nat0-eth0')
    print "*** Testing network"
    #net.pingAll()
    out = {}
    popens = {}
    count = {}
    for i in range(tmp<<1):
        print 'activate',i
        #popens[hosts1[i]] = hosts1[i].popen('python client.py 1 1 %s user1 > %s &'%(i,'user1'+str(i)))
        popens[hosts1[i]] = hosts1[i].popen('python client.py 1 1 %s user1'%(i))
        #popens[hosts2[i]] = hosts2[i].popen('python client.py 1 2 %s user1 > %s &'%(i,'user2'+str(i)))
        #hosts1[i].cmdPrint('python client.py 1 1 %s user1 > %s &'%(i,'user1'+str(i)))
        #hosts2[i].cmd('python client.py 1 2 %s user1 > %s &'%(i,'user2'+str(i)))
        out[hosts1[i].name] = open('user1'+str(i),'w')
        count[hosts1[i].name] = 0
    
    for host,line in pmonitor(popens):
        if host:
            out[host.name].write(line.strip()+'\n')
            count[host.name] += 1
#.........这里部分代码省略.........
开发者ID:john35452,项目名称:sdn-p2p,代码行数:103,代码来源:net.py

示例10: myNetwork

# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addNAT [as 别名]
def myNetwork():

    net = Mininet( topo=None,
                   build=False,
                   ipBase='10.0.0.0/8')

    info( '*** Adding controller\n' )
    c0=net.addController(name='c0',
                      controller=RemoteController,
                      protocol='tcp',
                      port=6633)

    info( '*** Add switches\n')
    s3 = net.addSwitch('s3', cls=OVSKernelSwitch, protocols="OpenFlow13")
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch, protocols="OpenFlow13")
    s4 = net.addSwitch('s4', cls=OVSKernelSwitch, protocols="OpenFlow13")
    s5 = net.addSwitch('s5', cls=OVSKernelSwitch, protocols="OpenFlow13")
    s1 = net.addSwitch('s1', cls=OVSKernelSwitch, protocols="OpenFlow13")
    s6 = net.addSwitch('s6', cls=OVSKernelSwitch, protocols="OpenFlow13")
    s7 = net.addSwitch('s7', cls=OVSKernelSwitch, protocols="OpenFlow13")

    info( '*** Add hosts\n')
    #Endpoints
    h1 = net.addHost('h1', cls=Host, mac='3a:20:45:92:93:fc', ip='10.0.0.1', defaultRoute=None)
    h2 = net.addHost('h2', cls=Host, mac='4e:f0:8b:08:4f:07', ip='10.0.0.2', defaultRoute=None)
    h3 = net.addHost('h3', cls=Host, mac='b2:67:ff:f4:e4:18', ip='10.0.0.3', defaultRoute=None)
    h4 = net.addHost('h4', cls=Host, mac='ba:a1:a6:16:e0:91', ip='10.0.0.4', defaultRoute=None)
    h5 = net.addHost('h5', cls=Host, mac='52:e7:7c:5c:02:66', ip='10.0.0.5', defaultRoute=None)
    h6 = net.addHost('h6', cls=Host, mac='36:35:11:54:5f:95', ip='10.0.0.6', defaultRoute=None)
    h7 = net.addHost('h7', cls=Host, mac='22:bf:70:06:90:ec', ip='10.0.0.7', defaultRoute=None)
    h8 = net.addHost('h8', cls=Host, mac='02:76:81:72:1e:16', ip='10.0.0.8', defaultRoute=None)
    
    #Switch 'Hosts'
    h9 = net.addHost('h9', cls=Host, ip='10.0.0.9', defaultRoute=None)
    h10 = net.addHost('h10', cls=Host, ip='10.0.0.10', defaultRoute=None)
    h11 = net.addHost('h11', cls=Host, ip='10.0.0.11', defaultRoute=None)
    h12 = net.addHost('h12', cls=Host, ip='10.0.0.12', defaultRoute=None)
    h13 = net.addHost('h13', cls=Host, ip='10.0.0.13', defaultRoute=None)
    h14 = net.addHost('h14', cls=Host, ip='10.0.0.14', defaultRoute=None)
    h15 = net.addHost('h15', cls=Host, ip='10.0.0.15', defaultRoute=None)
    
    #External
    h16 = net.addHost('h16', cls=Host, mac='f6:52:56:1a:37:1f', ip='10.0.0.16', defaultRoute=None)

    info( '*** Add links\n')
    net.addLink(s1, h16)
    net.addLink(s1, h15)
    net.addLink(s1, s2)
    net.addLink(s1, s3)
    net.addLink(s3, s7)
    net.addLink(s3, s6)
    net.addLink(s6, h5)
    net.addLink(s6, h6)
    net.addLink(s7, h7)
    net.addLink(s7, h8)
    net.addLink(s5, h4)
    net.addLink(s5, h3)
    net.addLink(s4, h2)
    net.addLink(s4, h1)
    net.addLink(s5, h13)
    net.addLink(s5, s2)
    net.addLink(s2, s4)
    net.addLink(s2, h12)
    net.addLink(s3, h11)
    net.addLink(s7, h9)
    net.addLink(s4, h14)
    net.addLink(s6, h10)

    info( '*** Starting network\n')
    net.addNAT().configDefault()
    net.build()
    info( '*** Starting controllers\n')
    for controller in net.controllers:
        controller.start()

    info( '*** Starting switches\n')
    net.get('s3').start([c0])
    net.get('s2').start([c0])
    net.get('s4').start([c0])
    net.get('s5').start([c0])
    net.get('s1').start([c0])
    net.get('s6').start([c0])
    net.get('s7').start([c0])

    info( '*** Post configure switches and hosts\n')

    CLI(net)
    
    net.stop()
开发者ID:mirceaIordache,项目名称:DistributedNAD,代码行数:91,代码来源:finalTopo.py

示例11: ONOSCluster

# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addNAT [as 别名]
class ONOSCluster( Controller ):
    "ONOS Cluster"
    def __init__( self, *args, **kwargs ):
        """name: (first parameter)
           *args: topology class parameters
           ipBase: IP range for ONOS nodes
           forward: default port forwarding list,
           topo: topology class or instance
           nodeOpts: ONOSNode options
           **kwargs: additional topology parameters"""
        args = list( args )
        name = args.pop( 0 )
        topo = kwargs.pop( 'topo', None )
        self.nat = kwargs.pop( 'nat', 'nat0' )
        nodeOpts = kwargs.pop( 'nodeOpts', {} )
        # Default: single switch with 1 ONOS node
        if not topo:
            topo = SingleSwitchTopo
            if not args:
                args = ( 1, )
        if not isinstance( topo, Topo ):
            topo = RenamedTopo( topo, *args, hnew='onos', **kwargs )
        self.ipBase = kwargs.pop( 'ipBase', '192.168.123.0/24' )
        self.forward = kwargs.pop( 'forward',
                                   [ KarafPort, GUIPort, OpenFlowPort ] )
        super( ONOSCluster, self ).__init__( name, inNamespace=False )
        fixIPTables()
        self.env = initONOSEnv()
        self.net = Mininet( topo=topo, ipBase=self.ipBase,
                            host=partial( ONOSNode, **nodeOpts ),
                            switch=LinuxBridge,
                            controller=None )
        if self.nat:
            self.net.addNAT( self.nat ).configDefault()
        updateNodeIPs( self.env, self.nodes() )
        self._remoteControllers = []

    def start( self ):
        "Start up ONOS cluster"
        info( '*** ONOS_APPS = %s\n' % ONOS_APPS )
        self.net.start()
        for node in self.nodes():
            node.start( self.env, self.nodes() )
        info( '\n' )
        self.configPortForwarding( ports=self.forward, action='A' )
        self.waitStarted()
        return

    def waitStarted( self ):
        "Wait until all nodes have started"
        startTime = time.time()
        for node in self.nodes():
            info( node )
            node.waitStarted()
        info( '*** Waited %.2f seconds for ONOS startup' %
              ( time.time() - startTime ) )

    def stop( self ):
        "Shut down ONOS cluster"
        self.configPortForwarding( ports=self.forward, action='D' )
        for node in self.nodes():
            node.stop()
        self.net.stop()

    def nodes( self ):
        "Return list of ONOS nodes"
        return [ h for h in self.net.hosts if isinstance( h, ONOSNode ) ]

    def configPortForwarding( self, ports=[], action='A' ):
        """Start or stop port forwarding (any intf) for all nodes
           ports: list of ports to forward
           action: A=add/start, D=delete/stop (default: A)"""
        self.cmd( 'iptables -' + action, 'FORWARD -d', self.ipBase,
                  '-j ACCEPT' )
        for port in ports:
            for index, node in enumerate( self.nodes() ):
                ip, inport = node.IP(), port + index
                # Configure a destination NAT rule
                self.cmd( 'iptables -t nat -' + action,
                          'PREROUTING -t nat -p tcp --dport', inport,
                          '-j DNAT --to-destination %s:%s' % ( ip, port ) )
开发者ID:Shashikanth-Huawei,项目名称:bmp,代码行数:83,代码来源:onos.py

示例12: setLogLevel

# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addNAT [as 别名]
    setLogLevel( 'info')
    net = Mininet( controller=RemoteController )
   
    info( '*** Adding controller\n' ) 
  
    net.addController( 'c1',controller=RemoteController,ip="10.161.68.127",port=6653 )

    info( '*** Adding hosts\n' )
    h1 = net.addHost( 'h1', ip="12.0.0.1" )
    h2 = net.addHost( 'h2', ip="12.0.0.2" )

    info( '*** Adding switch\n' )
    s1 = net.addSwitch( 's1', mac="00:00:00:00:00:01" )

    info( '*** Creating links\n' )
   

    net.addLink( h1, s1 )
    net.addLink( h2, s1 )
    net.addNAT().configDefault()

    info( '*** Starting network\n')
    net.start()

   
    info( '*** Running CLI\n' )
    CLI( net )

    info( '*** Stopping network' )
    net.stop()
开发者ID:khantee,项目名称:Customtopo,代码行数:32,代码来源:Group1_nat.py

示例13: Mininet

# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addNAT [as 别名]
    """
    net = Mininet(controller=RemoteController)

    c0 = net.addController('c0')

    s1 = net.addSwitch('s1')
    s2 = net.addSwitch('s2')
    s3 = net.addSwitch('s3')

    h1 = net.addHost('h1', mac='00:00:00:00:00:01')
    h2 = net.addHost('h2', mac='00:00:00:00:00:02')
    h3 = net.addHost('h3', mac='00:00:00:00:00:03')
    h4 = net.addHost('h4', mac='00:00:00:00:00:04')
    h5 = net.addHost('h5', mac='00:00:00:00:00:05')

    nat0 = net.addNAT(name='nat0', connect=False)

    print "Links: ",
    links = [(s1, h1), (s1, h2), (s2, h3), (s3, h4), (s3, h5), (s1, s2),
             (s2, s3), (nat0, s2)]
    for node1, node2 in links:
        print '({0}, {1})'.format(node1.name, node2.name),
        Link(node1, node2)
    print

    net.build()
    c0.start()
    s1.start([c0])
    s2.start([c0])
    s3.start([c0])
    #print "Setting protocols..."
开发者ID:cubarco,项目名称:SDN-2015,代码行数:33,代码来源:setup_network.py

示例14: ONOSCluster

# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addNAT [as 别名]
class ONOSCluster( Controller ):
    "ONOS Cluster"
    def __init__( self, *args, **kwargs ):
        """name: (first parameter)
           *args: topology class parameters
           ipBase: IP range for ONOS nodes
           forward: default port forwarding list,
           topo: topology class or instance
           **kwargs: additional topology parameters"""
        args = list( args )
        name = args.pop( 0 )
        topo = kwargs.pop( 'topo', None )
        # Default: single switch with 1 ONOS node
        if not topo:
            topo = SingleSwitchTopo
            if not args:
                args = ( 1, )
        if not isinstance( topo, Topo ):
            topo = RenamedTopo( topo, *args, hnew='onos', **kwargs )
        self.ipBase = kwargs.pop( 'ipBase', '192.168.123.0/24' )
        self.forward = kwargs.pop( 'forward',
                                   [ KarafPort, GUIPort, OpenFlowPort ] )
        super( ONOSCluster, self ).__init__( name, inNamespace=False )
        fixIPTables()
        self.env = initONOSEnv()
        self.net = Mininet( topo=topo, ipBase=self.ipBase,
                            host=ONOSNode, switch=LinuxBridge,
                            controller=None )
        self.net.addNAT().configDefault()
        updateNodeIPs( self.env, self.nodes() )
        self._remoteControllers = []

    def start( self ):
        "Start up ONOS cluster"
        killprocs( 'karaf.jar' )
        info( '*** ONOS_APPS = %s\n' % ONOS_APPS )
        self.net.start()
        for node in self.nodes():
            node.start( self.env )
        info( '\n' )
        self.configPortForwarding( ports=self.forward, action='A' )
        self.waitStarted()
        return

    def waitStarted( self ):
        "Wait until all nodes have started"
        startTime = time.time()
        for node in self.nodes():
            info( node )
            node.waitStarted()
        info( '*** Waited %.2f seconds for ONOS startup' %
              ( time.time() - startTime ) )

    def stop( self ):
        "Shut down ONOS cluster"
        self.configPortForwarding( ports=self.forward, action='D' )
        for node in self.nodes():
            node.stop()
        self.net.stop()

    def nodes( self ):
        "Return list of ONOS nodes"
        return [ h for h in self.net.hosts if isinstance( h, ONOSNode ) ]

    def configPortForwarding( self, ports=[], intf='eth0', action='A' ):
        """Start or stop ports on intf to all nodes
           action: A=add/start, D=delete/stop (default: A)"""
        for port in ports:
            for index, node in enumerate( self.nodes() ):
                ip, inport = node.IP(), port + index
                # Configure a destination NAT rule
                cmd = ( 'iptables -t nat -{action} PREROUTING -t nat '
                        '-i {intf} -p tcp --dport {inport} '
                        '-j DNAT --to-destination {ip}:{port}' )
                self.cmd( cmd.format( **locals() ) )
开发者ID:Luckylau,项目名称:onos,代码行数:77,代码来源:onos.py

示例15: ONOSCluster

# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import addNAT [as 别名]
class ONOSCluster( Controller ):
    "ONOS Cluster"
    def __init__( self, *args, **kwargs ):
        """name: (first parameter)
           *args: topology class parameters
           ipBase: IP range for ONOS nodes
           forward: default port forwarding list,
           topo: topology class or instance
           nodeOpts: ONOSNode options
           **kwargs: additional topology parameters"""
        args = list( args )
        name = args.pop( 0 )
        topo = kwargs.pop( 'topo', None )
        nat = kwargs.pop( 'nat', 'nat0' )
        nodeOpts = kwargs.pop( 'nodeOpts', {} )
        # Default: single switch with 1 ONOS node
        if not topo:
            topo = SingleSwitchTopo
            if not args:
                args = ( 1, )
        if not isinstance( topo, Topo ):
            topo = RenamedTopo( topo, *args, hnew='onos', **kwargs )
        self.ipBase = kwargs.pop( 'ipBase', '192.168.123.0/24' )
        self.forward = kwargs.pop( 'forward',
                                   [ KarafPort, GUIPort, OpenFlowPort ] )
        super( ONOSCluster, self ).__init__( name, inNamespace=False )
        fixIPTables()
        self.env = initONOSEnv()
        self.net = Mininet( topo=topo, ipBase=self.ipBase,
                            host=partial( ONOSNode, **nodeOpts ),
                            switch=LinuxBridge,
                            controller=None )
        if nat:
            self.net.addNAT( nat ).configDefault()
        updateNodeIPs( self.env, self.nodes() )
        self._remoteControllers = []

    def start( self ):
        "Start up ONOS cluster"
        info( '*** ONOS_APPS = %s\n' % ONOS_APPS )
        self.net.start()
        for node in self.nodes():
            node.start( self.env, self.nodes() )
        info( '\n' )
        self.configPortForwarding( ports=self.forward, action='A' )
        self.waitStarted()
        return

    def waitStarted( self ):
        "Wait until all nodes have started"
        startTime = time.time()
        for node in self.nodes():
            info( node )
            node.waitStarted()
        info( '*** Waited %.2f seconds for ONOS startup' %
              ( time.time() - startTime ) )

    def stop( self ):
        "Shut down ONOS cluster"
        self.configPortForwarding( ports=self.forward, action='D' )
        for node in self.nodes():
            node.stop()
        self.net.stop()

    def nodes( self ):
        "Return list of ONOS nodes"
        return [ h for h in self.net.hosts if isinstance( h, ONOSNode ) ]

    def defaultIntf( self ):
        "Call ip route to determine default interface"
        result = quietRun( 'ip route | grep default', shell=True ).strip()
        match = search( r'dev\s+([^\s]+)', result )
        if match:
            intf = match.group( 1 )
        else:
            warn( "Can't find default network interface - using eth0\n" )
            intf = 'eth0'
        return intf

    def configPortForwarding( self, ports=[], intf='', action='A' ):
        """Start or stop forwarding on intf to all nodes
           action: A=add/start, D=delete/stop (default: A)"""
        if not intf:
            intf = self.defaultIntf()
        for port in ports:
            for index, node in enumerate( self.nodes() ):
                ip, inport = node.IP(), port + index
                # Configure a destination NAT rule
                cmd = ( 'iptables -t nat -{action} PREROUTING -t nat '
                        '-i {intf} -p tcp --dport {inport} '
                        '-j DNAT --to-destination {ip}:{port}' )
                self.cmd( cmd.format( **locals() ) )
开发者ID:Priyankab-Huawei,项目名称:onos,代码行数:94,代码来源:onos.py


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