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


Python Node.setIP方法代码示例

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


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

示例1: connectToInternet

# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import setIP [as 别名]
def connectToInternet( network ):
    "Connect the network to the internet"
    switch = network.switches[ 0 ]  # switch to use
    ip = '10.0.0.254'  # our IP address on host network
    routes = [ '10.0.0.0/24' ]  # host networks to route to
    prefixLen = 24 # subnet mask length
    inetIface = "eth0" # host interface for internet connectivity

    # Create a node in root namespace and link to switch 0
    root = Node( 'root', inNamespace=False )
    intf = Link( root, switch ).intf1
    #intf = createLink( root, switch )[ 0 ]
    #root.setIP( intf, ip, prefixLen )
    root.setIP( ip, prefixLen, intf)

    # Start network that now includes link to root namespace
    network.start()

    # Start NAT and establish forwarding
    startNAT( inetIface, root )

    # Establish routes from end hosts
    for host in network.hosts:
        host.cmd( 'ip route flush root 0/0' )
        #host.cmd( 'route add -net 10.0.0.0/24 dev ' + host.intfs[0] )
        host.cmd( 'route add -net 10.0.0.0/24 dev ' + host.intfs[0].name )
        host.cmd( 'route add default gw ' + ip )
        
    return root
开发者ID:ZubairNabi,项目名称:minerva,代码行数:31,代码来源:connect_internet.py

示例2: MyTopo

# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import setIP [as 别名]
class MyTopo(object):
    def __init__(self, cname='onos', cips=['10.0.3.1']):
        # Create network with multiple controllers
        self.net = Mininet(controller=RemoteController, switch=OVSKernelSwitch,
                           build=False)
 
        # Add controllers with input IPs to the network
        ctrls = [RemoteController(cname, cip, 6633) for cip in cips]
        for ctrl in ctrls:
            print ctrl.ip
            self.net.addController(ctrl)
 
        # Add switch
        self.s2 = self.net.addSwitch('s2', dpid='00000000000000a2')
	
	# Connect root namespace to the switch
	self.root = Node('root', inNamespace=False)
	intf = self.net.addLink(self.root, self.s2).intf1
	self.root.setIP('10.0.0.1/32', intf=intf)

	# Add host
	h2 = self.net.addHost('h2', ip='10.0.0.12/24', mac='00:00:00:00:00:02')
	self.net.addLink(h2, self.s2)

    def run(self):
        self.net.build()
        self.net.start()
        self.s2.cmd('ovs-vsctl set bridge s2 protocols=OpenFlow13')
        self.s2.cmd('ovs-vsctl add-port s2 vxlan2')
        self.s2.cmd('ovs-vsctl set interface vxlan2 type=vxlan option:remote_ip=104.236.158.75 option:key=flow')
	self.root.cmd('route add -net 10.0.0.0/24 dev root-eth0')
        CLI(self.net)
        self.net.stop()
开发者ID:hyunsun,项目名称:mininet-scripts,代码行数:35,代码来源:floating-network.py

示例3: startNetwork

# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import setIP [as 别名]
def startNetwork(network, switch, ip, routes):
    root = Node('root', inNamespace=False)
    intf = Link(root, switch).intf1
    root.setIP(ip, intf=intf)
    network.start()
    for route in routes:
        root.cmd( 'route add -net ' + route + ' dev ' + str( intf ) )
开发者ID:krman,项目名称:thesis,代码行数:9,代码来源:simple.py

示例4: connectToRootNS

# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import setIP [as 别名]
def connectToRootNS(network, switch, ip, routes):
    root = Node('root', inNamespace=False)
    intf = network.addLink(root, switch).intf1
    root.setIP(ip, intf=intf)
    network.start()
    for route in routes:
        root.cmd('route add -net {} dev {} '.format(route, intf)) 
开发者ID:amwelch,项目名称:mininet-sandbox,代码行数:9,代码来源:chatty.py

示例5: start

# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import setIP [as 别名]
def start():

    global net, attacker, running

    if running:
        return '\nServer already running.\n'

    setLogLevel('info')

    topo = MixTopo()
    net = Mininet(topo=topo)

    s1 = net['s1']
    plc2 = net['plc2']
    plc3 = net['plc3']

    s2, rtu2a, scada = net.get('s2', 'rtu2a', 'scada')
    rtu2b, attacker2 = net.get('rtu2b', 'attacker2')
    s3 = net.get('s3')

    # NOTE: root-eth0 interface on the host
    root = Node('root', inNamespace=False)
    intf = net.addLink(root, s3).intf1
    print('DEBUG root intf: {}'.format(intf))
    root.setIP('10.0.0.30', intf=intf)
    # NOTE: all packet from root to the 10.0.0.0 network
    root.cmd('route add -net ' + '10.0.0.0' + ' dev ' + str(intf))


    net.start()
    info('Welcome')

    # NOTE: use for debugging
    #s1.cmd('tcpdump -i s1-eth1 -w /tmp/s1-eth1.pcap &')
    #s1.cmd('tcpdump -i s1-eth2 -w /tmp/s1-eth2.pcap &')

    SLEEP = 0.5

    # NOTE: swat challenge 1 and 2
    plc3.cmd(sys.executable + ' plc3.py &')
    sleep(SLEEP)
    plc2.cmd(sys.executable + ' plc2.py &')
    sleep(SLEEP)

    # NOTE: wadi challenge 1
    scada.cmd(sys.executable + ' scada.py &')
    sleep(SLEEP)
    rtu2a.cmd(sys.executable + ' rtu2a.py &')
    sleep(SLEEP)
    # NOTE: wadi challenge 2
    rtu2b.cmd(sys.executable + ' rtu2b.py &')
    sleep(SLEEP)


    running = True
    return '\nServer started.\n'
开发者ID:scy-phy,项目名称:minicps,代码行数:58,代码来源:run.py

示例6: sshd_connectToRootNS

# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import setIP [as 别名]
def sshd_connectToRootNS(args,network):
	
	#we create node root and attach it to a swtich
	switch = network.getNodeByName(args.names.sw_sshd[0])

	#ip of root
	ip = '172.16.255.1/32' 
	
	root = Node( 'root', inNamespace=False )
	intf = Link( root, switch ).intf1
	root.setIP( ip, intf=intf )

	return root,intf
开发者ID:Romain-Ly,项目名称:PRES,代码行数:15,代码来源:pyMPTCP_options.py

示例7: connectToRootNS

# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import setIP [as 别名]
def connectToRootNS( network, switch, ip, routes ):
    """Connect hosts to root namespace via switch. Starts network.
      network: Mininet() network object
      switch: switch to connect to root namespace
      ip: IP address for root namespace node
      routes: host networks to route to"""
    # Create a node in root namespace and link to switch 0
    root = Node( 'root', inNamespace=False )
    intf = network.addLink( root, switch ).intf1
    root.setIP( ip, intf=intf )
    # Start network that now includes link to root namespace
    network.start()
    # Add routes from root ns to hosts
    for route in routes:
        root.cmd( 'route add -net ' + route + ' dev ' + str( intf ) )
开发者ID:lctseng,项目名称:NCTU-CS-Thesis-Undegraduated,代码行数:17,代码来源:topo.py

示例8: connectToRootNS

# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import setIP [as 别名]
def connectToRootNS( network, switch, ip, prefixLen, routes ):
    "Connect hosts to root namespace via switch. Starts network."
    "network: Mininet() network object"
    "switch: switch to connect to root namespace"
    "ip: IP address for root namespace node"
    "prefixLen: IP address prefix length (e.g. 8, 16, 24)"
    "routes: host networks to route to"
    # Create a node in root namespace and link to switch 0
    root = Node( 'root', inNamespace=False )
    intf = TCLink( root, switch ).intf1
    root.setIP( ip, prefixLen, intf )
    # Start network that now includes link to root namespace
    network.start()
    # Add routes from root ns to hosts
    for route in routes:
        root.cmd( 'route add -net ' + route + ' dev ' + str( intf ) )
开发者ID:PawelBorawski,项目名称:MNScenarioGenerator,代码行数:18,代码来源:agis2.py

示例9: scratchNet

# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import setIP [as 别名]
def scratchNet( cname='controller', cargs='-v ptcp:' ):
    "Create network from scratch using Open vSwitch."

    info( "*** Creating nodes\n" )
    controller = Node( 'c0', inNamespace=False )
    switch = Node( 's0', inNamespace=False )
    h0 = Node( 'h0' )
    h1 = Node( 'h1' )

    info( "*** Creating links\n" )
    Link( h0, switch )
    Link( h1, switch )

    info( "*** Configuring hosts\n" )
    h0.setIP( '192.168.123.1/24' )
    h1.setIP( '192.168.123.2/24' )
    info( str( h0 ) + '\n' )
    info( str( h1 ) + '\n' )

    info( "*** Starting network using Open vSwitch\n" )
    controller.cmd( cname + ' ' + cargs + '&' )
    switch.cmd( 'ovs-vsctl del-br dp0' )
    switch.cmd( 'ovs-vsctl add-br dp0' )
    for intf in switch.intfs.values():
        print switch.cmd( 'ovs-vsctl add-port dp0 %s' % intf )

    # Note: controller and switch are in root namespace, and we
    # can connect via loopback interface
    switch.cmd( 'ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633' )

    info( '*** Waiting for switch to connect to controller' )
    while 'is_connected' not in quietRun( 'ovs-vsctl show' ):
        sleep( 1 )
        info( '.' )
    info( '\n' )

    info( "*** Running test\n" )
    h0.cmdPrint( 'ping -c1 ' + h1.IP() )

    info( "*** Stopping network\n" )
    controller.cmd( 'kill %' + cname )
    switch.cmd( 'ovs-vsctl del-br dp0' )
    switch.deleteIntfs()
    info( '\n' )
开发者ID:09beeihaq,项目名称:Coursera-SDN-Assignments,代码行数:46,代码来源:scratchnet.py

示例10: scratchNet

# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import setIP [as 别名]
def scratchNet(cname="controller", cargs="-v ptcp:"):
    "Create network from scratch using Open vSwitch."

    info("*** Creating nodes\n")
    controller = Node("c0", inNamespace=False)
    switch = Node("s0", inNamespace=False)
    h0 = Node("h0")
    h1 = Node("h1")

    info("*** Creating links\n")
    Link(h0, switch)
    Link(h1, switch)

    info("*** Configuring hosts\n")
    h0.setIP("192.168.123.1/24")
    h1.setIP("192.168.123.2/24")
    info(str(h0) + "\n")
    info(str(h1) + "\n")

    info("*** Starting network using Open vSwitch\n")
    controller.cmd(cname + " " + cargs + "&")
    switch.cmd("ovs-vsctl del-br dp0")
    switch.cmd("ovs-vsctl add-br dp0")
    for intf in switch.intfs.values():
        print(switch.cmd("ovs-vsctl add-port dp0 %s" % intf))

    # Note: controller and switch are in root namespace, and we
    # can connect via loopback interface
    switch.cmd("ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633")

    info("*** Waiting for switch to connect to controller")
    while "is_connected" not in quietRun("ovs-vsctl show"):
        sleep(1)
        info(".")
    info("\n")

    info("*** Running test\n")
    h0.cmdPrint("ping -c1 " + h1.IP())

    info("*** Stopping network\n")
    controller.cmd("kill %" + cname)
    switch.cmd("ovs-vsctl del-br dp0")
    switch.deleteIntfs()
    info("\n")
开发者ID:jhall11,项目名称:mininet,代码行数:46,代码来源:scratchnet.py

示例11: createAgentNet

# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import setIP [as 别名]
def createAgentNet( k, routeIP ):
    net = Mininet( controller=Controller, switch=OVSBridge )

    print "*** Creating agent network"
    sw = net.addSwitch( 's%s' % (k+1) )
    for i in range( 1, k+1 ):
        host = net.addHost( 'agent%s' % i, ip='171.0.0.%s/16' % i )
        intf = net.addLink( sw, host ).intf2
        if routeIP != '127.0.0.1':
            # host.setHostRoute( routeIP, intf ) # this api does not work!!!
            host.cmd( 'ip route add %s dev %s' % ( routeIP, str( intf ) ) )

    # c = net.addController('c1', controller=Controller, ip='127.0.0.1', port=6699)

    root = Node( 'root', inNamespace=False )
    intf = net.addLink( root, sw ).intf1
    root.setIP( '171.0.123.1/16', intf=intf )
    # root.cmd( 'route add -net 171.0.0.0/16 dev ' + str( intf ) )

    net.build()
    # c.start()
    sw.start( [] )
    return net
开发者ID:SanaNad,项目名称:SoftOffload,代码行数:25,代码来源:test.py

示例12: scratchNet

# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import setIP [as 别名]
def scratchNet( cname='controller', cargs='ptcp:' ):
    "Create network from scratch using kernel switch."

    info( "*** Creating nodes\n" )
    controller = Node( 'c0', inNamespace=False )
    switch = Node( 's0', inNamespace=False )
    h0 = Node( 'h0' )
    h1 = Node( 'h1' )

    info( "*** Creating links\n" )
    createLink( node1=h0, node2=switch, port1=0, port2=0 )
    createLink( node1=h1, node2=switch, port1=0, port2=1 )

    info( "*** Configuring hosts\n" )
    h0.setIP( h0.intfs[ 0 ], '192.168.123.1', 24 )
    h1.setIP( h1.intfs[ 0 ], '192.168.123.2', 24 )
    info( str( h0 ) + '\n' )
    info( str( h1 ) + '\n' )

    info( "*** Starting network using Open vSwitch kernel datapath\n" )
    controller.cmd( cname + ' ' + cargs + '&' )
    switch.cmd( 'ovs-dpctl del-dp dp0' )
    switch.cmd( 'ovs-dpctl add-dp dp0' )
    for intf in switch.intfs.values():
        print switch.cmd( 'ovs-dpctl add-if dp0 ' + intf )
    print switch.cmd( 'ovs-openflowd dp0 tcp:127.0.0.1 &' )

    info( "*** Running test\n" )
    h0.cmdPrint( 'ping -c1 ' + h1.IP() )

    info( "*** Stopping network\n" )
    controller.cmd( 'kill %' + cname )
    switch.cmd( 'ovs-dpctl del-dp dp0' )
    switch.cmd( 'kill %ovs-openflowd' )
    switch.deleteIntfs()
    info( '\n' )
开发者ID:09zwcbupt,项目名称:mininet,代码行数:38,代码来源:scratchnet.py

示例13: connectToRootNS

# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import setIP [as 别名]
def connectToRootNS( net, ip='10.123.123.1', mac='00123456789A', prefixLen=8, routes=['10.0.0.0/8']):
	print "*** Creating controller"
	c0 = net.addController( 'c0', ip='127.0.0.1', port=6633 )
	rootswitch = net.addSwitch('roots1',)
	rootswitch.dpid = 'FFFFFFFFFFFFFFFF'
	# Connect hosts to root namespace via switch. Starts network.
	# network: Mininet() network object
	# ip: IP address for root namespace node
	# prefixLen: IP address prefix length (e.g. 8, 16, 24)
	# routes: host networks to route to"
	# Create a node in root namespace and link to switch 0
	root = Node( 'root', inNamespace=False )
	intf = Link( root, rootswitch ).intf1
	intf.setMAC(mac)
	root.setIP( ip, prefixLen, intf )
	print "*** Added Interface", str(intf), "Connected To Root-NameSpace"
	fixNetworkManager(str(intf))
	for host in net.hosts:
	    net.addLink(host,rootswitch)
	# Add routes from root ns to hosts
	for route in routes:
         root.cmd( 'route add -net ' + route + ' dev ' + str( intf ) )
	root.cmd('service network-manager restart')
	return rootswitch
开发者ID:StefanoSalsano,项目名称:alien-ofelia-conet-ccnx,代码行数:26,代码来源:start_mininet.py

示例14: scratchNetUser

# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import setIP [as 别名]
def scratchNetUser( cname='controller', cargs='ptcp:' ):
    "Create network from scratch using user switch."

    # It's not strictly necessary for the controller and switches
    # to be in separate namespaces. For performance, they probably
    # should be in the root namespace. However, it's interesting to
    # see how they could work even if they are in separate namespaces.

    info( '*** Creating Network\n' )
    controller = Node( 'c0' )
    switch = Node( 's0')
    h0 = Node( 'h0' )
    h1 = Node( 'h1' )
    cintf, sintf = createLink( controller, switch )
    h0intf, sintf1 = createLink( h0, switch )
    h1intf, sintf2 = createLink( h1, switch )

    info( '*** Configuring control network\n' )
    controller.setIP( cintf, '10.0.123.1', 24 )
    switch.setIP( sintf, '10.0.123.2', 24 )

    info( '*** Configuring hosts\n' )
    h0.setIP( h0intf, '192.168.123.1', 24 )
    h1.setIP( h1intf, '192.168.123.2', 24 )

    info( '*** Network state:\n' )
    for node in controller, switch, h0, h1:
        info( str( node ) + '\n' )

    info( '*** Starting controller and user datapath\n' )
    controller.cmd( cname + ' ' + cargs + '&' )
    switch.cmd( 'ifconfig lo 127.0.0.1' )
    intfs = [ sintf1, sintf2 ]
    switch.cmd( 'ofdatapath -i ' + ','.join( intfs ) + ' ptcp: &' )
    switch.cmd( 'ofprotocol tcp:' + controller.IP() + ' tcp:localhost &' )

    info( '*** Running test\n' )
    h0.cmdPrint( 'ping -c1 ' + h1.IP() )

    info( '*** Stopping network\n' )
    controller.cmd( 'kill %' + cname )
    switch.cmd( 'kill %ofdatapath' )
    switch.cmd( 'kill %ofprotocol' )
    switch.deleteIntfs()
    info( '\n' )
开发者ID:09zwcbupt,项目名称:mininet,代码行数:47,代码来源:scratchnetuser.py

示例15: OpenstackManage

# 需要导入模块: from mininet.node import Node [as 别名]
# 或者: from mininet.node.Node import setIP [as 别名]
class OpenstackManage(object):
    """
    OpenstackManage is a singleton and management component for the emulator.
    It is the brain of the Openstack component and manages everything that is not datacenter specific like
    network chains or load balancers.
    """
    __instance = None

    def __new__(cls):
        if OpenstackManage.__instance is None:
            OpenstackManage.__instance = object.__new__(cls)
        return OpenstackManage.__instance

    def __init__(self, ip="0.0.0.0", port=4000):
        # we are a singleton, only initialize once!
        self.lock = threading.Lock()
        with self.lock:
            if hasattr(self, "init"):
                return
            self.init = True

        self.endpoints = dict()
        self.cookies = set()
        self.cookies.add(0)
        self.ip = ip
        self.port = port
        self._net = None
        # to keep track which src_vnf(input port on the switch) handles a load balancer
        self.lb_flow_cookies = dict()
        self.chain_flow_cookies = dict()

        # for the visualization also store the complete chain data incl. paths
        self.full_chain_data = dict()
        self.full_lb_data = dict()

        # flow groups could be handled for each switch separately, but this global group counter should be easier to
        # debug and to maintain
        self.flow_groups = dict()

        # we want one global chain api. this should not be datacenter dependent!
        self.chain = chain_api.ChainApi(ip, port, self)
        self.thread = threading.Thread(target=self.chain._start_flask, args=())
        self.thread.daemon = True
        self.thread.name = self.chain.__class__
        self.thread.start()

        # floating ip network setup
        self.floating_switch = None
        self.floating_network = None
        self.floating_netmask = "192.168.100.0/24"
        self.floating_nodes = dict()
        self.floating_cookies = dict()
        self.floating_intf = None
        self.floating_links = dict()

    @property
    def net(self):
        return self._net

    @net.setter
    def net(self, value):
        if self._net is None:
            self._net = value
            self.init_floating_network()
        self._net = value

    def init_floating_network(self):
        """
        Initialize the floating network component for the emulator.
        Will not do anything if already initialized.
        """
        if self.net is not None and self.floating_switch is None:
            # create a floating network
            fn = self.floating_network = Net("default")
            fn.id = str(uuid.uuid4())
            fn.set_cidr(self.floating_netmask)

            # create a subnet
            fn.subnet_id = str(uuid.uuid4())
            fn.subnet_name = fn.name + "-sub"

            # create a port for the host
            port = Port("root-port")
            #port.id = str(uuid.uuid4())
            port.net_name = fn.name

            # get next free ip
            root_ip = fn.get_new_ip_address(port.name)
            port.ip_address = root_ip
            # floating ip network setup
            # wierd way of getting a datacenter object
            first_dc = self.net.dcs.values()[0]
            # set a dpid for the switch. for this we have to get the id of the next possible dc
            self.floating_switch = self.net.addSwitch("fs1", dpid=hex(first_dc._get_next_dc_dpid())[2:])
            # this is the interface appearing on the physical host
            self.floating_root = Node('root', inNamespace=False)
            self.net.hosts.append(self.floating_root)
            self.net.nameToNode['root'] = self.floating_root
            self.floating_intf = self.net.addLink(self.floating_root, self.floating_switch).intf1
            self.floating_root.setIP(root_ip, intf=self.floating_intf)
#.........这里部分代码省略.........
开发者ID:stevenvanrossem,项目名称:son-emu,代码行数:103,代码来源:manage.py


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