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


Python Topo.addLink方法代码示例

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


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

示例1: _convert_to_plain_topo

# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addLink [as 别名]
 def _convert_to_plain_topo(self, topo):
     r = Topo()
     for node in topo.nodes():
         r.addNode(node,**topo.nodeInfo(node))
     for edge in topo.links():
         r.addLink(edge[0],edge[1],**topo.linkInfo(edge[0],edge[1]))
     return r
开发者ID:lianjiecao,项目名称:mininet-hd,代码行数:9,代码来源:metisPartitioner1.py

示例2: main

# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addLink [as 别名]
def main():
    logger = MininetLogger()
    logger.setLogLevel(levelname='info')

    controller_ip = sys.argv[2]

    topo = Topo()
    n = int(sys.argv[1])

    switches = [topo.addSwitch('s%d' % (i+1), protocols='OpenFlow13') for i in range(n)]
    host1 = topo.addHost('h%d' % 1, mac="12:34:56:78:00:01")
    host2 = topo.addHost('h%d' % 2, mac="12:34:56:78:00:02")
    hosts = [host1, host2]

    for i in [0, 1]:
        topo.addLink(hosts[i], switches[i])

    for i in range(n):
        topo.addLink(switches[i], switches[(i+1) % n])

    net = Mininet(topo=topo, controller=RemoteController, link=TCLink, build=False)
    net.addController(ip=controller_ip)

    net.start()
    CLI(net)
    net.stop()
开发者ID:snlab,项目名称:vxe-onug-hackathon-2016,代码行数:28,代码来源:demonetwork.py

示例3: finalize

# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addLink [as 别名]
    def finalize(self):
        # make mininet topo
        topo = Topo()
        
        # add nodes
        for x,d in self.nodes(data=True):
            if d['isSwitch']:
                topo.addSwitch(str(x))
            else:
                topo.addHost(str(x))
                
        # add links
        for src,dst in self.edges():
            topo.addLink(str(src),str(dst))
            
        # backpatch ports into original graph
        for x in self.nodes():
            self.node[x]['ports'] = {}
            self.node[x]['port'] = {}            
            for y in self.neighbors(x):
                x_port, y_port = topo.port(str(x),str(y))
                self.node[x]['ports'][y] = x_port
                # Support indexing in by port to get neighbor switch/port                
                self.node[x]['port'][x_port] = (y, y_port)

        
        self.topo = topo        
        self.finalized = True
开发者ID:frenetic-lang,项目名称:fattire,代码行数:30,代码来源:nxtopo.py

示例4: createTopology

# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addLink [as 别名]
def createTopology(switch, hosts):
    setLogLevel('info')
    topo = Topo()
    switch = topo.addSwitch(switch)

    for (hostname, opts) in hosts:
        host = topo.addHost(hostname, **opts)
        topo.addLink(host, switch, None)

    network = Mininet(topo, controller=None)
    network.start()
    print "*** Dumping host connections"
    dumpNodeConnections(network.hosts)
    CLI(network)
    network.stop()
开发者ID:flavio-fernandes,项目名称:ovs-lab,代码行数:17,代码来源:common.py

示例5: test_from_mininet

# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addLink [as 别名]
 def test_from_mininet(self):
     from mininet.topo import Topo
     t = Topo()
     t.addHost("h1")
     t.addHost("h4")
     t.addSwitch("s2")
     t.addSwitch("s3")
     t.addLink("h1", "s2")
     t.addLink("s2", "s3")
     t.addLink("s3", "h4")
     fnss_topo = fnss.from_mininet(t)
     self.assertIsNotNone(fnss_topo)
     for h in "h1", "h4":
         self.assertEqual(fnss_topo.node[h]['type'], 'host')
     for s in "s2", "s3":
         self.assertEqual(fnss_topo.node[s]['type'], 'switch')
开发者ID:brucespang,项目名称:fnss,代码行数:18,代码来源:test_mn.py

示例6: createTopology

# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addLink [as 别名]
def createTopology(switch, hosts):
    ODL_Controller_IP='172.17.40.4'
    setLogLevel('info')
    topo = Topo()
    switch = topo.addSwitch(switch)

    for (hostname, opts) in hosts:
        host = topo.addHost(hostname, **opts)
        topo.addLink(host, switch, None)

    network = Mininet(topo, controller=None)
    #odl_ctrl = network.addController('c0', controller=RemoteController, ip=ODL_Controller_IP, port=6633)
    network.start()
    print "*** Dumping host connections"
    dumpNodeConnections(network.hosts)
    CLI(network)
    network.stop()
开发者ID:vpickard,项目名称:ovs-lab,代码行数:19,代码来源:common.py

示例7: _convert_to_plain_topo

# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addLink [as 别名]
    def _convert_to_plain_topo(self, topo):
        """Convert topo to mininet.topo.Topo instance.

        This helper function allows the user to use topologys which are not
        direct instances of mininet.topo.Topo in MaxiNet. If the topology was
        not converted to a Topo instance the transfer via pyro most likely
        fails as the original class might not be available at the pyro remote.

        Args:
            topo: Instance which fullfills the interface of mininet.topo.Topo.

        Returns:
            Instance of mininet.topo.Topo,
        """
        r = Topo()
        for node in topo.nodes():
            r.addNode(node, **topo.nodeInfo(node))
        for edge in topo.links():
            r.addLink(**topo.linkInfo(edge[0], edge[1]))
        return r
开发者ID:CN-UPB,项目名称:MaxiNet,代码行数:22,代码来源:partitioner.py

示例8: createTopo

# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addLink [as 别名]
def createTopo():
	topo=Topo()

        swCore1 = topo.addSwitch('s1')

	## Ajuste do parametro de fanout da rede
	fanout = 2

        # Switches counter
        lastSW = 2
        lastHost = 1

        # Aggregation switches loop
        for i in irange (1, fanout):
                swAggregL = topo.addSwitch('s%s' % lastSW)
                topo.addLink(swCore1, swAggregL)
                lastSW += 1

                # Edge switches loop
                for j in irange (1, fanout):
                        swEdge = topo.addSwitch('s%s' % lastSW)
                        topo.addLink(swAggregL, swEdge)
                        lastSW += 1

                        # Hosts loop
                        for k in irange (1, fanout):
                                host = topo.addHost('h%s' % lastHost)
                                topo.addLink(swEdge, host)
                                lastHost += 1
	
	return topo
开发者ID:glaucogoncalves,项目名称:sdnufrpe,代码行数:33,代码来源:pratica-2-II.py

示例9: networkx_to_mininet

# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addLink [as 别名]
def networkx_to_mininet(G, hosts, switches, mapping):
    # Conversion from NetworkX topology into FNSS topology
    fnss_topo = fnss.Topology(G)

    # G is a NetworkX Graph() and fnss_topo is a FNSS Topology(): hosts and switches are indistinguishable.
    # We exploit 'mapping' returned from parse_network_xml() for nodes role differentiation.
    # We can't use fnss.adapters.to_mininet() because we need a customized nodes relabeling.
    # TODO link capacities!! http://fnss.github.io/doc/core/_modules/fnss/adapters/mn.html

    # Conversion from FNSS topology into Mininet topology
    nodes = set(fnss_topo.nodes_iter())
    hosts = sorted(set(hosts))
    switches = sorted(set(switches))

    hosts = set(mapping[v] for v in hosts)
    switches = set(mapping[v] for v in switches)

    if not switches.isdisjoint(hosts):
        raise ValueError('Some nodes are labeled as both host and switch. '
                         'Switches and hosts node lists must be disjoint')
    if hosts.union(switches) != switches.union(hosts):
        raise ValueError('Some nodes are not labeled as either host or switch '
                         'or some nodes listed as switches or hosts do not '
                         'belong to the topology')
    
    fnss_topo = nx.relabel_nodes(fnss_topo, mapping, copy=True)

    global mn_topo
    mn_topo = Topo()
    for v in switches:
        mn_topo.addSwitch(str(v))
    for v in hosts:
        mn_topo.addHost(str(v))
    for u, v in fnss_topo.edges_iter():
            params = {}
            mn_topo.addLink(str(u), str(v), **params)
    return mn_topo
开发者ID:chenleji,项目名称:ryu-1,代码行数:39,代码来源:f_t_parser_ff.py

示例10: MininetSimulator

# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addLink [as 别名]
class MininetSimulator(object):

    def __init__(self, graph, controller_addr):
        self.graph = graph
        self.mininet_topo = Topo();
        self.controller_addr = controller_addr

    def generate_topo(self):
        nodes = self.graph["nodes"]
        edges = self.graph["edges"]
        for node in nodes:
            if node["class"] == "circleHClass":
                if (ip_re.match(node["title"])):
                    self.mininet_topo.addHost(node, ip=node["title"])
                else:
                    self.mininet_topo.addHost(node)
            elif node["class"] == "circleSClass":
                self.mininet_topo.addSwitch(node)
        for edge in edges:
            # set link properties here.
            # bw(Mbps), delay, loss, max_queue_size
            # source code is in {mininet_root}/mininet/link.py
            linkopts = dict()
            self.mininet_topo.addLink(edge[0], edge[1], **linkopts)

    def run(self):
        self.generate_topo()
        net = Mininet(topo=self.mininet_topo,
                controller=RemoteController,
                link=TCLink,
                build=False,
                autoStaticArp=True)
        net.addController(ip=self.controller_addr)
        net.start()
        CLI(net)
        net.stop()
开发者ID:whrhrr,项目名称:Maple-IDE,代码行数:38,代码来源:mininet.py

示例11: createTopo

# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addLink [as 别名]
def createTopo():
        topo=Topo()

        #Create Nodes
        topo.addHost("h1")
        topo.addHost("h2")
        topo.addHost("h3")
        topo.addHost("h4")
        topo.addSwitch('s1')
        topo.addSwitch('s2')
        topo.addSwitch('s3')

        #Create links
        topo.addLink('s1','s2',bw=100,delay='100ms',loss=10)
        topo.addLink('s1','s3')
        topo.addLink('h1','s2')
        topo.addLink('h2','s2')
        topo.addLink('h3','s3')
        topo.addLink('h4','s3')
        return topo
开发者ID:glaucogoncalves,项目名称:sdnufrpe,代码行数:22,代码来源:pratica-1-III.py

示例12: createTopo

# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addLink [as 别名]
def createTopo():
	topo=Topo()
	#Create Nodes
	topo.addHost("h1")
	topo.addHost("h2")
	topo.addHost("h3")
	topo.addHost("h4")
	topo.addSwitch('s1')
	topo.addSwitch('s2')
	topo.addHost("r1") #router
	#Create links
	topo.addLink('h1','s1')	
	topo.addLink('h2','s1')	
	topo.addLink('s1','r1')	
	topo.addLink('s2','r1')	
	topo.addLink('h3','s2')	
	topo.addLink('h4','s2')	
	return topo
开发者ID:Gustavomagalhaes,项目名称:r2d2,代码行数:20,代码来源:P4-simple-routing.py

示例13: to_mininet

# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addLink [as 别名]
def to_mininet(topology, switches=None, hosts=None):
    """Convert an FNSS topology to Mininet Topo object that can be used to
    deploy a Mininet network.
    
    If the links of the topology are labeled with delays, capacities or buffer
    sizes, the returned Mininet topology will also include those parameters.
    
    However, it should be noticed that buffer sizes are included in the
    converted topology only if they are expressed in packets. If buffer sizes
    are expressed in the form of bytes they will be discarded. This is because
    Mininet only supports buffer sizes expressed in packets.
    
    Parameters
    ----------
    topology : Topology, DirectedTopology or DatacenterTopology
        An FNSS Topology object
    switches : list, optional
        List of topology nodes acting as switches
    hosts : list, optional
        List of topology nodes acting as hosts
    
    Returns
    -------
    topology : Mininet Topo
        A Mininet topology object
    
    Notes
    -----
    It is not necessary to provide a list of switch and host nodes if the
    topology object provided are already annotated with a type attribute that
    can have values *host* or *switch*. This is the case of datacenter
    topologies generated with FNSS which already include information about
    which nodes are hosts and which are switches.
    
    If switches and hosts are passed as arguments, then the hosts and switches
    sets must be disjoint and their union must coincide to the set of all
    topology nodes. In other words, there cannot be nodes labeled as both
    *host* and *switch* and there cannot be nodes that are neither a *host* nor
    a *switch*.
    """
    try:
        from mininet.topo import Topo
    except ImportError:
        raise ImportError('Cannot import mininet.topo package. '
                          'Make sure Mininet is installed on this machine.')
    if hosts is None:
        hosts = (v for v in topology.nodes_iter()
                 if 'host' in topology.node[v]['type'])
    if switches is None:
        switches = (v for v in topology.nodes_iter()
                    if 'switch' in topology.node[v]['type'])
    nodes = set(topology.nodes_iter())
    switches = set(switches)
    hosts = set(hosts)
    if not switches.isdisjoint(hosts):
        raise ValueError('Some nodes are labeled as both host and switch. '
                         'Switches and hosts node lists must be disjoint')
    if not nodes == switches.union(hosts):
        raise ValueError('Some nodes are not labeled as either host or switch '
                         'or some nodes listed as switches or hosts do not '
                         'belong to the topology')
    topo = Topo()
    for v in switches:
        topo.addSwitch(str(v))
    for v in hosts:
        topo.addHost(str(v))
    delay_unit = topology.graph['delay_unit'] \
                 if 'delay_unit' in topology.graph else None    
    capacity_unit = topology.graph['capacity_unit'] \
                    if 'capacity_unit' in topology.graph else None
    buffer_unit = topology.graph['buffer_unit'] \
                  if 'buffer_unit' in topology.graph else None
    if capacity_unit is not None:
        capacity_conversion = float(capacity_units[capacity_unit]) \
                              / capacity_units['Mbps']
    if delay_unit is not None:
        delay_conversion = float(time_units[delay_unit]) \
                              / time_units['us']
    for u, v in topology.edges_iter():
        params = {}
        if 'capacity' in topology.edge[u][v] and capacity_unit is not None:
            params['bw'] = topology.edge[u][v]['capacity'] * capacity_conversion
            # Use Token Bucket filter to implement rate limit
            params['use_htb'] = True 
        if 'delay' in topology.edge[u][v] and delay_unit is not None:
            params['delay'] = '%sus' % str(topology.edge[u][v]['delay'] 
                                           * delay_conversion)
        if 'buffer_size' in topology.edge[u][v] and buffer_unit == 'packets':
            params['max_queue_size'] = topology.edge[u][v]['buffer_size']
        topo.addLink(str(u), str(v), **params)
    return topo
开发者ID:brucespang,项目名称:fnss,代码行数:93,代码来源:mn.py

示例14: create_topology

# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addLink [as 别名]
def create_topology(context):

    topo = Topo()
    h = ''
    sfs_per_sff = int(context.sf_number) / int(context.switch_number)

    # Add the links SFFs - SFs
    for i in range(len(context.sf_forwarders)):
        print context.sf_forwarders[i].opts
        s = topo.addSwitch(
            context.sf_forwarders[i].name,
            opts=context.sf_forwarders[i].opts)
        for j in range(sfs_per_sff):
            sf_index = (i*int(sfs_per_sff))+j

            if not context.service_functions[sf_index]:
                # Add the Loop switches instead of normal hosts
                sf_loopback_name = '%s-node%d' % (
                    context.sf_forwarders[i].name, j + 1)
                context.sf_loopbacks.append(sf_loopback_name)
                h = topo.addSwitch(sf_loopback_name, opts='')
            else:
                # Add the SFs as normal hosts
                if context.service_functions[sf_index].vlan_id_ == 0:
                    h = topo.addHost(
                        context.service_functions[sf_index].name,
                        ip=context.service_functions[sf_index].ip_,
                        mac=context.service_functions[sf_index].mac_)

                else:
                    h = topo.addHost(
                        context.service_functions[sf_index].name,
                        cls=VlanHost,
                        vlan=context.service_functions[sf_index].vlan_id_,
                        ip=context.service_functions[sf_index].ip_,
                        mac=context.service_functions[sf_index].mac_)

            # Connect the SF to the SFF
            topo.addLink(node1=h, node2=s)

    # Add the GWs
    gw1 = topo.addSwitch(
        context.gateways[0].name, opts=context.gateways[0].opts)
    gw2 = topo.addSwitch(
        context.gateways[1].name, opts=context.gateways[1].opts)

    if context.topology_tor:
        # Create the Top-of-Rack switch
        topo.addSwitch(context.tor_info.name, opts=context.tor_info.opts)

        # Connect each SFF to the ToR switch
        for i in range(len(context.sf_forwarders)):
            topo.addLink(context.tor_info.name, context.sf_forwarders[i].name)

        # Add the links between the GWs and the tor
        topo.addLink(context.gateways[0].name, context.tor_info.name)
        topo.addLink(context.gateways[1].name, context.tor_info.name)

    else:
        # Add the links between SFFs
        for i in range(len(context.sf_forwarders)-1):
            topo.addLink(
                context.sf_forwarders[i].name, context.sf_forwarders[i+1].name)

        # Add the links between SFFs and GWs
        topo.addLink(
            context.gateways[0].name, context.sf_forwarders[0].name)
        topo.addLink(
            context.gateways[1].name,
            context.sf_forwarders[len(context.sf_forwarders)-1].name)

    # Add the link between gw1 and gw2
    topo.addLink(context.gateway_client, context.gateway_server)

    # Add the clients and their links to GW1
    for i in range(int(context.clients_number)):
        h = topo.addHost(context.clients[i].name,
                         ip=context.clients[i].ip_,
                         mac=context.clients[i].mac_)
        topo.addLink(node1=h, node2=gw1)

    # Add the servers and their links to GW2
    for i in range(len(context.servers)):
        h = topo.addHost(context.servers[i].name,
                         ip=context.servers[i].ip_,
                         mac=context.servers[i].mac_)
        topo.addLink(node1=h, node2=gw2)

    return topo
开发者ID:CiscoDevNet,项目名称:iOAM,代码行数:91,代码来源:sfc-openflow-renderer_mininet.py

示例15: Topo

# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addLink [as 别名]
import subprocess

from mininet.node import OVSSwitch
from mininet.topo import Topo

from MaxiNet.Frontend import maxinet
from MaxiNet.tools import Tools

topo = Topo()

topo.addSwitch("s1")
topo.addSwitch("s2")
topo.addHost("h1", ip=Tools.makeIP(1), mac=Tools.makeMAC(1))
topo.addHost("h2", ip=Tools.makeIP(2), mac=Tools.makeMAC(2))
topo.addLink("h1", "s1")
topo.addLink("s1", "s2")
topo.addLink("h2", "s2")

cluster = maxinet.Cluster()

# we need to add the root node after the simulation has started as we do
# not know which worker id the frontend machine will get. Therefore we
# need a dynamic topology which is only supported in openvswitch
exp = maxinet.Experiment(cluster, topo, switch=OVSSwitch)
exp.setup()

# Start ssh servers
h1 = exp.get("h1")
h1.cmd("echo \"Welcome to %s at %s\n\" > /tmp/%s.banner" % (h1.name,
                                                        h1.IP(), h1.name))
开发者ID:CN-UPB,项目名称:MaxiNet,代码行数:32,代码来源:sshd.py


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