本文整理汇总了Python中mininet.net.Mininet.configHosts方法的典型用法代码示例。如果您正苦于以下问题:Python Mininet.configHosts方法的具体用法?Python Mininet.configHosts怎么用?Python Mininet.configHosts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mininet.net.Mininet
的用法示例。
在下文中一共展示了Mininet.configHosts方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: topo_init
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import configHosts [as 别名]
def topo_init():
myTopo = TreeTopo( depth=3, fanout=3 )
global net
net = Mininet( topo=myTopo, switch=OVSSwitch, build=False )
"Creating Controller"
c0 = net.addController( 'c0', controller=InbandController, ip='10.0.0.100' )
net.start()
"Adding a host for changing to controller"
server = net.addHost( 'server', ip='10.0.0.100')
s1 = net.get('s1')
link = net.addLink( server, s1 )
s1.attach( link.intf2 )
net.configHosts()
"Hosts list and the total # of hosts"
global hosts_list
hosts_list = net.hosts
global num_hosts
num_hosts = len( hosts_list )
"Assigning IP addresses to switches in the network"
switch_list = net.switches
n = len(switch_list)
ip = hosts_list[-2].IP()
for i in range(1,n+1):
ip2int = lambda ipstr: struct.unpack( '!I', socket.inet_aton(ipstr))[0]
int_ip = ip2int(ip)
int_ip+=1
int2ip = lambda n: socket.inet_ntoa(struct.pack('!I', n))
ip = int2ip(int_ip)
s = net.get('s%d' % i)
s.cmd( 'ifconfig s%d %s ' % (i, ip) )
"Start the controller in 'server' host"
global controller_host
controller_host = hosts_list[-1]
"Fetch the listener host in the network"
global server_host
server_host = hosts_list[-2]
"Start the listener script in the listener host"
#info( server_host.cmd( './listener.sh &' ) )
#server_host.cmd( 'while true; do nc -l -p 2222; done > /home/mininet/mininet/custom/dump.txt &' )
"Start the sender script in the remaining hosts"
示例2: failover_test
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import configHosts [as 别名]
def failover_test():
"""Example/test of fast failover"""
myTopo = Diamond()
net = Mininet( topo=myTopo, autoStaticArp=True, \
switch=UserSwitch, \
controller=RemoteController )
#controller=PatheticController )
net.configHosts()
net.start()
#net.controllers[0].real_start()
print "* Sleep a few seconds while pathetic installs rules"
sleep(10)
#CLI(net)
testFailover( net )
net.stop()
示例3: configHosts
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import configHosts [as 别名]
def configHosts(self):
"Configure the networks hosts."
# Let Mininet handle the baseline initialization
Mininet.configHosts(self)
info('*** Starting host services\n')
for host in self.hosts:
returnCodes = host.autoStartServices()
if returnCodes:
# print detailed information on the started services
statusStr = "%s: " % (host)
for service, returnCode in returnCodes.iteritems():
if returnCode['ret'] == 0:
result = 'OK'
else:
result = 'FAIL'
statusStr += "%s (%s) " % (service, result)
info(statusStr + '\n')
示例4: limit
# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import configHosts [as 别名]
def limit( traffic, numEdgeSwitches=20, bw=100 ):
"""Example/test of link and CPU bandwidth limits
traffic: traffic matrix (src,dst,load)
bw: interface bandwidth limit in Mbps
cpu: cpu limit as fraction of overall CPU time"""
# intf = custom( TCIntf, bw=bw, use_tbf=True )
# host = custom( Host, intf=intf )
myTopo = FattreeTopology( numEdgeSwitches=numEdgeSwitches )
net = Mininet( topo=myTopo.mininet_topo(), autoStaticArp=True, \
switch=UserSwitch, \
controller=RemoteController )
switch = net.switches[ 0 ]
routes = [ '10.0.0.0/8' ] # host networks to route to
net.configHosts()
# connectToRootNS( net, switch, routes )
net.start()
start_sshd( net )
CLI(net)
testThroughput( net, traffic )
stop_sshd( net )
net.stop()