本文整理汇总了Python中mininet.util.irange函数的典型用法代码示例。如果您正苦于以下问题:Python irange函数的具体用法?Python irange怎么用?Python irange使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了irange函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__( self, N, M, **params ):
# Initialize topology
Topo.__init__( self, **params )
print ""
# Create switches and hosts
switches = []
hosts = []
for s in irange(1, N):
print 's%s' % s
switch = self.addSwitch('s%s' % s)
switches.append(switch)
for h in irange(1, M):
print 's%sh%s' % (s, h)
host = self.addHost('s%sh%s' % (s, h))
hosts.append(host)
print 's%sh%s-s%s' % (s, h, s)
# Wire up hosts
self.addLink(switch, host)
print switches
print hosts
# Wire up switches
last = None
for switch in switches:
if last:
self.addLink( last, switch )
self.addLink( last, switch )
print last + "-" + switch
last = switch
示例2: __init__
def __init__(self, k, l, **opts):
"""Init.
k: number of switches (and hosts)
hconf: host configuration options
lconf: link configuration options"""
super(dcSpineLeafTopo, self).__init__(**opts)
self.k = k
self.l = l
for i in irange(0, k-1):
spineSwitch = self.addSwitch('s%s%s' % (1,i+1))
spineList.append(spineSwitch)
for i in irange(0, l-1):
leafSwitch = self.addSwitch('l%s%s' % (2, i+1))
leafList.append(leafSwitch)
host1 = self.addHost('h%s' % (i+1))
#host12 = self.addHost('h%s' % (i+1))
#hosts1 = [ net.addHost( 'h%d' % n ) for n in 3, 4 ]
"connection of the hosts to the left tor switch "
self.addLink(host1, leafSwitch, **link_host_leaf)
#self.addLink(host12, leafSwitch)
for i in irange(0, k-1):
for j in irange(0, l-1): #this is to go through the leaf switches
self.addLink(spineList[i], leafList[j], **link_spine_leaf)
示例3: build
def build( self, k=2, n=1,delay=None, **_opts):
"""k: number of switches
n: number of hosts per switch"""
self.k = k
self.n = n
if n == 1:
genHostName = lambda i, j: 'h%s' % i
else:
genHostName = lambda i, j: 'h%ss%d' % ( j, i )
lastSwitch = None
for i in irange( 1, k ):
# Add switch
switch = self.addSwitch( 's%s' % i )
# Add hosts to switch
for j in irange( 1, n ):
host = self.addHost( genHostName( i, j ) )
if delay != None:
self.addLink( host, switch, delay=delay, use_htb=True)
else:
self.addLink( host, switch)
# Connect switch to previous
if lastSwitch:
if delay != None:
self.addLink( switch, lastSwitch, delay=delay, use_htb=True )
else:
self.addLink( switch, lastSwitch )
lastSwitch = switch
示例4: __init__
def __init__( self, N, **params ):
Topo.__init__( self, **params )
hosts1 = [ self.addHost( 'h%d' % n )
for n in irange( 1, 2 ) ]
hosts2 = [ self.addHost( 'h%d' % n )
for n in irange( 3, 4 ) ]
hosts3 = [ self.addHost( 'h%d' % n )
for n in irange( 5, 6 ) ]
hosts4 = [ self.addHost( 'h%d' % n )
for n in irange( 7, 8 ) ]
switches = [ self.addSwitch( 's%s' % s )
for s in irange( 1, 6 ) ]
for h in hosts1:
self.addLink( s2, h )
for h in hosts2:
self.addLink( s3, h )
for h in hosts3:
self.addLink( s5, h )
for h in hosts4:
net.addLink( s6, h )
self.addLink( s1, s2 )
self.addLink( s1, s4 )
self.addLink( s1, s3 )
self.addLink( s4, s5 )
self.addLink( s4, s6 )
示例5: __init__
def __init__( self, N, bw, **params ):
# Initialize topology
Topo.__init__( self, **params )
# Create switches and hosts
hosts = [ self.addHost( 'h%s' % h )
for h in irange( 1, N ) ]
switches = [ self.addSwitch( 's%s' % s )
for s in irange( 1, N - 1 ) ]
# Wire up switches
last = None
for switch in switches:
if last:
self.addLink( last, switch,
bw=bw, delay='1ns', loss=0, use_htb=True)
last = switch
# Wire up hosts
self.addLink( hosts[ 0 ], switches[ 0 ],
bw=bw, delay='1ms', loss=0, use_htb=True)
for host, switch in zip( hosts[ 1: ], switches ):
self.addLink( host, switch,
bw=bw, delay='1ms', loss=0, use_htb=True)
示例6: __init__
def __init__(self, linkopts1, linkopts2, linkopts3, fanout=2, **opts):
# Initialize topology and default options
Topo.__init__(self, **opts)
# Add your logic here ...
sw_list_access = []
sw_list_edge = []
core_switch = self.addSwitch('c1')
sw_id = 0
for i in irange (1, fanout):
sw_id = sw_id + 1
access_switch = self.addSwitch('a%s' %sw_id)
self.addLink(core_switch, access_switch, **linkopts1)
sw_list_access.append(access_switch)
sw_id = 0
for sw in sw_list_access:
for i in irange (1, fanout):
sw_id = sw_id + 1
edge_switch = self.addSwitch('e%s' %sw_id)
self.addLink(edge_switch, sw, **linkopts2)
sw_list_edge.append(edge_switch)
h_id = 0
for sw in sw_list_edge:
for i in irange (1, fanout):
h_id = h_id + 1
host = self.addHost('h%s' %h_id)
self.addLink(host, sw, **linkopts3)
示例7: __init__
def __init__(self, linkopts1={}, linkopts2={}, linkopts3={}, fanout=2, **opts):
# Initialize topology and default options
Topo.__init__(self, **opts)
# Add your logic here ...
# Add CORE
core = self.addSwitch('c1')
# Aux variables to count switches and hosts used to assign names
acount = 1
ecount = 1
hcount = 1
# Add Agreggation
for i in irange(1, fanout):
#name = str(acount + int(i))
AggSwitch = self.addSwitch('a%s' % acount)
self.addLink( core, AggSwitch, **linkopts1)
acount += 1
# Add Edge
for j in irange(1,fanout):
#name = str(ecount + int(j))
EdgeSwitch = self.addSwitch('e%s' % ecount)
self.addLink( AggSwitch, EdgeSwitch, **linkopts2)
ecount += 1
# Add hosts
for k in irange(1, fanout):
#name = str(hcount + int(k))
host = self.addHost('h%s' % hcount)
self.addLink( EdgeSwitch, host, **linkopts3)
hcount += 1
示例8: __init__
def __init__(self, linkopts1, linkopts2, linkopts3, fanout=2, **opts):
# Initialize topology and default options
Topo.__init__(self, **opts)
# Create switches and hosts
c_switch = self.addSwitch('cs1')
a_switches = [ self.addSwitch('as%s' % s) for s in irange(1,fanout) ]
e_switches = [ self.addSwitch('es%s' % s) for s in irange(1,fanout ** 2)]
hosts = [ self.addHost('h%s' % h) for h in irange( 1, fanout ** 3)]
# Connect between c_switch and a_switches
for a_switch in a_switches:
self.addLink(c_switch,a_switch,**linkopts1)
# Connect between a_switches and e_switches
count = 0
for e_switch in e_switches:
selector = count / fanout
self.addLink(e_switch,a_switches[selector],**linkopts2)
count = count + 1
# Connect between e_switches and hosts
count = 0
for host in hosts:
selector = count / fanout
self.addLink(host,e_switches[selector],**linkopts3)
count = count + 1
示例9: __init__
def __init__(self, linkopts1, linkopts2, linkopts3, fanout=2, **opts):
# Initialize topology and default options
Topo.__init__(self, **opts)
# Add your logic here ...
# changed LinearTopo to TreeTopo, not sure what difference this makes)
super(CustomTopo, self).__init__(**opts)
self.fanout = fanout
switchFanOut = fanout
edgeSwitchFanOut = fanout
hostFanOut = fanout
#lastSwitch = None
# create core switch
coreSwitch = self.addSwitch('c1')
#now start logic of creating tree under the root (i.e. core switch)
for asfo in irange(1, switchFanOut):
aggSwitch = self.addSwitch('a%s' % asfo)
for esfo in irange(1+fanout*(asfo-1), edgeSwitchFanOut+fanout*(asfo-1)):
edgeSwitch = self.addSwitch('e%s' % esfo)
for hfo in irange(1+fanout*(esfo-1), hostFanOut+fanout*(esfo-1)):
host = self.addHost('h%s' % hfo)
self.addLink(host, edgeSwitch, **linkopts3)
self.addLink(edgeSwitch, aggSwitch, **linkopts2)
self.addLink(coreSwitch, aggSwitch, **linkopts1)
示例10: __init__
def __init__(self, linkopts1, linkopts2, linkopts3, fanout=2, **opts):
#def __init__(self, fanout=3, **opts):
# Initialize topology and default options
Topo.__init__(self, **opts)
jj = 1
kk = 1
coreSwitch = self.addSwitch('c1')
for i in irange(1, fanout):
aggSwitch = self.addSwitch('a%s' % i)
self.addLink(aggSwitch,coreSwitch,**linkopts1)
link_ae = 1
for j in irange(jj, fanout * fanout):
edgeSwitch = self.addSwitch('e%s' % j)
if link_ae <= fanout:
self.addLink(edgeSwitch,aggSwitch,**linkopts2)
link_ae += 1
else:
break
link_eh = 1
for k in irange(kk, fanout * fanout * fanout):
host = self.addHost('h%s' % k)
if link_eh <= fanout:
self.addLink(host,edgeSwitch,**linkopts3)
link_eh += 1
else:
break
kk = kk + fanout
jj = jj + fanout
示例11: createTopo
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
示例12: __init__
def __init__(self, linkopts1, linkopts2, linkopts3, fanout=2, **opts):
# Initialize topology and default options
Topo.__init__(self, **opts)
# Add your logic here ...
self.fanout = fanout
currentHost = 1
currentEdge = 1
currentAgg = 1
# Core Layer
coreSW = self.addSwitch('c1', cpu=.5/fanout)
for a in irange(1, fanout):
# Aggregation Layer
aggSW = self.addSwitch('a%s' % currentAgg)
self.addLink(aggSW, coreSW, bw=linkopts1['bw'], delay=linkopts1['delay'], loss=1, max_queue_size=1000, use_htb=True)
currentAgg += 1
for e in irange(1, fanout):
# Edge Layer
edgeSW = self.addSwitch('e%s' % currentEdge)
self.addLink(edgeSW, aggSW, bw=linkopts2['bw'], delay=linkopts2['delay'], loss=1, max_queue_size=1000, use_htb=True)
currentEdge += 1
for h in irange(1, fanout):
# Host Layer
host = self.addHost('h%s' % currentHost, cpu=.5/fanout)
self.addLink(host, edgeSW, bw=linkopts3['bw'], delay=linkopts3['delay'], loss=1, max_queue_size=1000, use_htb=True)
currentHost += 1
示例13: __init__
def __init__(self, linkopts1, linkopts2, linkopts3, fanout=2, **opts):
# Initialize topology and default options
Topo.__init__(self, **opts)
aggregation = []
edge = []
host = []
self.linkopts = [ linkopts1, linkopts2, linkopts3 ]
# Create core switch
core = self.addSwitch('c1')
# Aggregation switches
for i in irange(1, fanout):
aggregation.append(self.addSwitch('a%s' % (len(aggregation) + 1)))
self.addLink(core, aggregation[-1], **linkopts1)
# Edge switches
for j in irange(1, fanout):
edge.append(self.addSwitch('e%s' % (len(edge) + 1)))
self.addLink(aggregation[-1], edge[-1], **linkopts2)
# Hosts
for k in irange(1, fanout):
host.append(self.addHost('h%s' % (len(host) + 1)))
self.addLink(host[-1], edge[-1], **linkopts3)
示例14: __init__
def __init__(self, linkopts1, linkopts2,linkopts3,fanout, **opts):
Topo.__init__(self, **opts)
self.linkopts1 = linkopts1
self.linkopts2 = linkopts2
self.linkopts3 = linkopts3
self.fanout = fanout
s=[]
h=[]
l=[1]
a=0
c=0
for i in irange(1,1+fanout+fanout**2):
switch = self.addSwitch('s%s' % i)
s.append(switch)
for i in irange(1,fanout**3):
host = self.addHost('h%s' % i)
h.append(host)
for i in range(fanout-1):
a=a+fanout+1
l.append(a+1)
for i in l:
link = self.addLink(s[0], s[i],**linkopts1)
for i in l:
b=0
for j in irange(1,fanout):
link = self.addLink(s[i],s[b+i+1],**linkopts2)
for k in irange(1,fanout):
link = self.addLink(h[c],s[b+i+1],**linkopts3)
c=c+1
b=b+1
示例15: __init__
def __init__(self, k=2, n=1, **opts):
"""Init.
k: number of switches
n: number of hosts per switch
hconf: host configuration options
lconf: link configuration options"""
super(LinearTopo, self).__init__(**opts)
self.k = k
self.n = n
lastSwitch = None
for i in irange(1, k):
# Add switch
switch = self.addSwitch('s%s' % i)
# Add hosts to switch
for j in irange(1, n):
hostNum = (i-1)*n + j
host = self.addHost('h%s' % hostNum)
self.addLink(host, switch)
# Connect switch to previous
if lastSwitch:
self.addLink(switch, lastSwitch)
lastSwitch = switch