本文整理汇总了Python中mininet.topo.Topo.addSwitch方法的典型用法代码示例。如果您正苦于以下问题:Python Topo.addSwitch方法的具体用法?Python Topo.addSwitch怎么用?Python Topo.addSwitch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mininet.topo.Topo
的用法示例。
在下文中一共展示了Topo.addSwitch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createTopo
# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addSwitch [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
示例2: createTopo
# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addSwitch [as 别名]
def createTopo():
print "Create a topology."
topo=Topo()
print "Adding switches"
NewYork = topo.addSwitch( 's1' )
Chicago = topo.addSwitch( 's2' )
WashingtonDC = topo.addSwitch( 's3' )
Seattle = topo.addSwitch( 's4' )
Sunnyvale = topo.addSwitch( 's5' )
LosAngeles = topo.addSwitch( 's6' )
Denver = topo.addSwitch( 's7' )
KansasCity = topo.addSwitch( 's8' )
Houston = topo.addSwitch( 's9' )
Atlanta = topo.addSwitch( 's10' )
Indianapolis = topo.addSwitch( 's11' )
print "Adding hosts"
NewYork_host = topo.addHost( 'h1' )
Chicago_host = topo.addHost( 'h2' )
WashingtonDC_host = topo.addHost( 'h3' )
Seattle_host = topo.addHost( 'h4' )
Sunnyvale_host = topo.addHost( 'h5' )
LosAngeles_host = topo.addHost( 'h6' )
Denver_host = topo.addHost( 'h7' )
KansasCity_host = topo.addHost( 'h8' )
Houston_host = topo.addHost( 'h9' )
Atlanta_host = topo.addHost( 'h10' )
Indianapolis_host = topo.addHost( 'h11' )
print "Adding edges switch <-> host"
topo.addLink( NewYork , NewYork_host )
topo.addLink( Chicago , Chicago_host )
topo.addLink( WashingtonDC , WashingtonDC_host )
topo.addLink( Seattle , Seattle_host )
topo.addLink( Sunnyvale , Sunnyvale_host )
topo.addLink( LosAngeles , LosAngeles_host )
topo.addLink( Denver , Denver_host )
topo.addLink( KansasCity , KansasCity_host )
topo.addLink( Houston , Houston_host )
topo.addLink( Atlanta , Atlanta_host )
topo.addLink( Indianapolis , Indianapolis_host )
print "Adding switches <-> switches"
topo.addLink( NewYork , Chicago, bw=1000, delay='0.200ms')
topo.addLink( NewYork , WashingtonDC, bw=1000, delay='0.200ms')
topo.addLink( Chicago , Indianapolis, bw=1000, delay='0.200ms')
topo.addLink( WashingtonDC , Atlanta, bw=1000, delay='0.200ms')
topo.addLink( Seattle , Sunnyvale, bw=1000, delay='0.200ms')
topo.addLink( Seattle , Denver, bw=1000, delay='0.200ms')
topo.addLink( Sunnyvale , LosAngeles, bw=1000, delay='0.200ms')
topo.addLink( Sunnyvale , Denver, bw=1000, delay='0.200ms')
topo.addLink( LosAngeles , Houston, bw=1000, delay='0.200ms')
topo.addLink( Denver , KansasCity, bw=1000, delay='0.200ms')
topo.addLink( KansasCity , Houston, bw=1000, delay='0.200ms')
topo.addLink( KansasCity , Indianapolis, bw=1000, delay='0.200ms')
topo.addLink( Houston , Atlanta, bw=1000, delay='0.200ms')
topo.addLink( Atlanta , Indianapolis, bw=1000, delay='0.200ms')
return topo
示例3: createTopo
# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addSwitch [as 别名]
def createTopo():
topo=Topo()
#Create Nodes
topo.addHost("h1")
topo.addHost("h2")
topo.addHost("h3")
topo.addHost("h4")
topo.addHost("h5")
topo.addHost("h6")
topo.addSwitch('s1')
topo.addSwitch('s2')
topo.addSwitch('s3')
topo.addHost("r1") #router
topo.addHost("r2") #router
topo.addHost("r3") #router
#Create links
topo.addLink('h1','s1')
topo.addLink('h2','s1')
topo.addLink('s1','r1')
topo.addLink('h3','s2')
topo.addLink('h4','s2')
topo.addLink('s2','r2')
topo.addLink('h5','s3')
topo.addLink('h6','s3')
topo.addLink('s3','r3')
topo.addLink('r1','r2')
topo.addLink('r1','r3')
topo.addLink('r2','r3')
return topo
示例4: finalize
# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addSwitch [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
示例5: main
# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addSwitch [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()
示例6: test_from_mininet
# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addSwitch [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')
示例7: createTopo
# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addSwitch [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
示例8: createTopo
# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addSwitch [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')
topo.addLink('s1','s3')
topo.addLink('h1','s2')
topo.addLink('h2','s2')
topo.addLink('h3','s3')
topo.addLink('h4','h3')
return topo
示例9: networkx_to_mininet
# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addSwitch [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
示例10: createTopology
# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addSwitch [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()
示例11: MininetSimulator
# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addSwitch [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()
示例12: createTopology
# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addSwitch [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()
示例13: createTopo
# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addSwitch [as 别名]
def createTopo():
print "Create a topology."
topo=Topo()
print "Adding switch"
masterSwitch = topo.addSwitch( 's1' )
print "Adding servers"
server1 = topo.addHost( 'server1' )
server2 = topo.addHost( 'server2' )
print "Adding hosts"
host1 = topo.addHost( 'h1' )
host2 = topo.addHost( 'h2' )
host3 = topo.addHost( 'h3' )
host4 = topo.addHost( 'h4' )
host5 = topo.addHost( 'h5' )
host6 = topo.addHost( 'h6' )
host7 = topo.addHost( 'h7' )
host8 = topo.addHost( 'h8' )
host9 = topo.addHost( 'h9' )
host10 = topo.addHost( 'h10' )
print "Adding links"
topo.addLink( host1 , masterSwitch, bw=1, delay='0.200ms')
topo.addLink( host2 , masterSwitch, bw=1, delay='0.200ms')
topo.addLink( host3 , masterSwitch, bw=1, delay='0.200ms')
topo.addLink( host4 , masterSwitch, bw=1, delay='0.200ms')
topo.addLink( host5 , masterSwitch, bw=1, delay='0.200ms')
topo.addLink( host6 , masterSwitch, bw=1, delay='0.200ms')
topo.addLink( host7 , masterSwitch, bw=1, delay='0.200ms')
topo.addLink( host8 , masterSwitch, bw=1, delay='0.200ms')
topo.addLink( host9 , masterSwitch, bw=1, delay='0.200ms')
topo.addLink( host10 , masterSwitch, bw=1, delay='0.200ms')
topo.addLink( server1 , masterSwitch, bw=10, delay='0.200ms')
topo.addLink( server2 , masterSwitch, bw=10, delay='0.200ms')
return topo
示例14: to_mininet
# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addSwitch [as 别名]
def to_mininet(topology, switches=None, hosts=None, relabel_nodes=True):
"""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
relabel_nodes : bool, optional
If *True*, rename node labels according to `Mininet conventions
<https://github.com/mininet/mininet/wiki/Introduction-to-Mininet#naming-in-mininet>`_.
In Mininet all node labels are strings whose values are "h1", "h2", ...
if the node is a host or "s1", "s2", ... if the node is a switch.
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*.
It is important to point out that if the topology contains loops, it will
not work with the *ovs-controller* and *controller* provided by Mininet. It
will be necessary to use custom controllers. Further info `here
<https://github.com/mininet/mininet/wiki/Introduction-to-Mininet#multipath-routing>`_.
"""
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 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')
if relabel_nodes:
hosts = sorted(hosts)
switches = sorted(switches)
mapping = dict([(hosts[i], "h%s" % str(i+1)) for i in range(len(hosts))] +
[(switches[i], "s%s" % str(i+1)) for i in range(len(switches))])
hosts = set(mapping[v] for v in hosts)
switches = set(mapping[v] for v in switches)
nodes = hosts.union(switches)
topology = nx.relabel_nodes(topology, mapping, copy=True)
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:
capacity_conversion = float(capacity_units[capacity_unit]) \
/ capacity_units['Mbps']
if delay_unit:
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:
#.........这里部分代码省略.........
示例15: to_mininet
# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import addSwitch [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