本文整理汇总了Python中mininet.clean.cleanup函数的典型用法代码示例。如果您正苦于以下问题:Python cleanup函数的具体用法?Python cleanup怎么用?Python cleanup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cleanup函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runMPI
def runMPI():
# Create network
topo = TestTopo()
net = Mininet(topo=topo, controller=lambda name: RemoteController(name, ip='127.0.0.1'), link=TCLink)
# net = Mininet(topo=topo, controller=OVSController, link=TCLink)
net.start()
for host in net.hosts:
host.cmd('../../tiny-lldpd/tlldpd -d -i 1')
sleep(5)
# Launch sshd on each hosts and output host IPs to machinefile
pids = []
f = open('./machines', 'w')
for h in net.hosts:
h.cmd('/usr/sbin/sshd -D -o UseDNS=no -u0 &')
pid = int(h.cmd('echo $!'))
pids.append(pid)
f.write('%s\n' % h.IP())
f.close()
# Launch MPI application
print "Starting MPI application:"
print "----------------------------------------"
net.hosts[0].cmdPrint('mpirun --machinefile ./machines --mca coll_tuned_priority 100 --mca coll_tuned_allreduce_algorithm 3 --mca coll_tuned_use_dynamic_rules 1 --mca coll_base_verbose 1 ./mpitest');
print "----------------------------------------"
print "MPI application finished."
for pid in pids:
h.cmd('kill -9 %s' % pid)
net.hosts[0].cmd('killall -9 tlldpd')
net.stop()
cleanup()
示例2: perfTest
def perfTest():
topo = TestTopo()
net = Mininet(topo=topo, controller=lambda name: RemoteController(name, ip='127.0.0.1'), link=TCLink)
net.start()
print "Dumping connections"
dumpNodeConnections(net.hosts)
print "Launching LLDP daemons"
for host in net.hosts:
host.cmd('../../tiny-lldpd/tlldpd -d -i 1')
sleep(3)
net.pingAll()
net.get('h3').cmd('iperf -sD')
net.get('h4').cmd('iperf -sD')
net.get('h1').cmd('iperf -c %s > /tmp/h1.txt &' % net.get('h3').IP())
net.get('h2').cmd('sleep 1; iperf -c %s > /tmp/h2.txt &' % net.get('h4').IP())
net.get('h1').cmd('wait $!')
net.get('h2').cmd('wait $!')
net.get('h1').cmdPrint("awk 'NR == 7 {print $7 $8}' /tmp/h1.txt")
net.get('h2').cmdPrint("awk 'NR == 7 {print $7 $8}' /tmp/h2.txt")
net.hosts[0].cmd('killall -9 tlldpd')
net.hosts[0].cmd('killall -9 iperf')
net.stop()
cleanup()
示例3: launch_network
def launch_network(k=4, bw=10, ip_alias=True, fair_queues=False, cli=False):
signal.signal(signal.SIGTERM, signal_term_handler)
# Cleanup the network
cleanup()
sh("killall ospfd zebra getLoads.py nc")
# Remove tmp files and old namespaces
subprocess.call(['rm', '/tmp/*.log', '/tmp/*.pid', '/tmp/mice*'])
subprocess.call(['rm', '/var/run/netns/*'])
# Flush root namespace mangle table
subprocess.call(["iptables", "-t", "mangle" ,"-F"])
subprocess.call(["iptables", "-t", "mangle" ,"-X"])
# Topology
topo = FatTree(k=k, sflow=False, ovs_switches=False)
# Interfaces
if fair_queues:
print("*** Using FairQueues at the network interfaces")
intf = custom(DCTCIntf, bw=bw)
else:
print("*** Using normal pFIFO queues at the network interfaces")
intf = custom(PrioFifoIntf, bw=bw)
# Network
net = IPNet(topo=topo, debug=_lib.DEBUG_FLAG, intf=intf)
# Save the TopoDB object
TopologyDB(net=net).save(cfg.DB_path)
# Start the network
net.start()
# Setup hash seeds
setupHashSeeds(topo)
# Start intreface collectors
startCounterCollectors(topo, interval=1)
if ip_alias:
setupSecondaryIps(net)
if cli:
# Start the Fibbing CLI
FibbingCLI(net)
else:
print("*** Looping forever. Press CTRL+C to quit")
while True:
try:
time.sleep(2)
except KeyboardInterrupt:
print("*** KeyboardInterrupt catched! Shutting down")
break
net.stop()
stopCounterCollectors(topo)
示例4: stop_mininet
def stop_mininet(self):
if self.mininet_client is not None:
self.mininet_client.stop()
if self.topology:
self.topology = []
self.delay = None
cleanup()
sleep(20)
示例5: runTests
def runTests( testDir, verbosity=1 ):
"discover and run all tests in testDir"
# ensure root and cleanup before starting tests
cleanup()
# discover all tests in testDir
testSuite = defaultTestLoader.discover( testDir )
# run tests
TextTestRunner( verbosity=verbosity ).run( testSuite )
示例6: runTests
def runTests( testDir, verbosity=1 ):
"discover and run all tests in testDir"
# cleanup before starting tests
cleanup()
# discover all tests in testDir
testSuite = unittest.defaultTestLoader.discover( testDir )
# run tests
MininetTestRunner( verbosity=verbosity ).run( testSuite )
示例7: tearDown
def tearDown():
cleanup()
# make sure that all pending docker containers are killed
with open(os.devnull, 'w') as devnull:
subprocess.call(
"sudo docker rm -f $(sudo docker ps --filter 'label=com.containernet' -a -q)",
stdout=devnull,
stderr=devnull,
shell=True)
示例8: runTests
def runTests( testDir, verbosity=1 ):
"discover and run all tests in testDir"
# ensure root and cleanup before starting tests
ensureRoot()
cleanup()
# discover all tests in testDir
testSuite = unittest.defaultTestLoader.discover( testDir )
# run tests
success = MininetTestRunner( verbosity=verbosity ).run( testSuite ).wasSuccessful()
sys.exit( 0 if success else 1 )
示例9: destroy_mininet
def destroy_mininet(self):
"""shut down mininet instance"""
if self.net:
for popen in self.x11popens:
popen.terminate()
popen.communicate()
popen.wait()
self.net.stop()
# remove mininet instance and running docker container
cleanup()
self.logger.info("mininet instance terminated")
self.net = None
示例10: __init__
def __init__(self, topo=None):
cleanUpScreens()
cleanup()
if topo is None:
topo = LinearTopo(N)
self.net = Mininet(controller=partial(RemoteController, ip='101.6.30.40', port=6653),
topo=topo,
#host=CPULimitedHost,
#link=TCLink
)
示例11: httpTest
def httpTest( N=2 ):
"Run pings and monitor multiple hosts using pmonitor"
## SET LOGGING AND CLEANUP PREVIOUS MININET STATE, IF ANY
lg.setLogLevel('info')
cleanup()
## INSTEAD OF RUNNING PYRETIC HUB, UNCOMMENT LINE
## TO SEE THAT THIS WORKS FINE WHEN RUNNING REFERENCE CONTROLLER
# call('controller ptcp: &', shell=True)
## SET UP TOPOLOGY
topo = LinearTopo( N ) ## (tcp parse) warning TCP data offset too long or too short
# topo = SingleSwitchTopo( N ) ## SILENT STALL
## SET UP MININET INSTANCE AND START
net = Mininet( topo, switch=OVSKernelSwitch, host=Host, controller=RemoteController )
net.start()
print "Starting test..."
## GET THE HOST AND SERVER NAMES
hosts = net.hosts
client = hosts[ 0 ]
server = hosts[ 1 ]
## DICTS FOR USE W/ PMONITOR
spopens = {}
cpopens = {}
## WARMUP SERVER
spopens[server] = server.popen('python', '-m', 'SimpleHTTPServer', '80')
sleep(1)
## CLIENT REQUEST
cpopens[client] = client.popen('wget', '-O', '-', server.IP(), stdout=PIPE, stderr=STDOUT)
## MONITOR OUTPUT
for h, line in pmonitor( cpopens, timeoutms=5000 ):
if h and line:
print '%s: %s' % ( h.name, line ),
## TO USE THE COMMAND LINE INTERFACE, BEFORE FINISHING, UNCOMMENT
# CLI( net )
## SHUTDOWN SERVER
spopens[server].send_signal( SIGINT )
## SHUTDOWN MININET
net.stop()
示例12: runTests
def runTests(testDir, verbosity=1, dockeronly=False):
"discover and run all tests in testDir"
# ensure root and cleanup before starting tests
ensureRoot()
cleanup()
# discover all tests in testDir
testSuite = defaultTestLoader.discover(testDir)
if dockeronly:
testSuiteFiltered = [s for s in testSuite if "Docker" in str(s)]
testSuite = TestSuite()
testSuite.addTests(testSuiteFiltered)
# run tests
TextTestRunner(verbosity=verbosity).run(testSuite)
示例13: perfTest
def perfTest():
topo = TestTopo()
net = Mininet(topo=topo, controller=lambda name: RemoteController(name, ip='127.0.0.1'), link=TCLink)
net.start()
print "Dumping connections"
dumpNodeConnections(net.hosts)
for host in net.hosts:
host.cmdPrint('../../tiny-lldpd/tlldpd -d -i 1')
CLI(net)
for host in net.hosts:
host.cmdPrint('killall tlldpd')
net.stop()
cleanup()
示例14: bwtest
def bwtest( cpuLimits, period_us=100000, seconds=10 ):
"""Example/test of link and CPU bandwidth limits
cpu: cpu limit as fraction of overall CPU time"""
topo = TreeTopo( depth=1, fanout=2 )
results = {}
for sched in 'rt', 'cfs':
info( '*** Testing with', sched, 'bandwidth limiting\n' )
for cpu in cpuLimits:
# cpu is the cpu fraction for all hosts, so we divide
# it across two hosts
host = custom( CPULimitedHost, sched=sched,
period_us=period_us,
cpu=.5*cpu )
try:
net = Mininet( topo=topo, host=host )
# pylint: disable=bare-except
except:
info( '*** Skipping scheduler %s and cleaning up\n' % sched )
cleanup()
break
net.start()
net.pingAll()
hosts = [ net.getNodeByName( h ) for h in topo.hosts() ]
client, server = hosts[ 0 ], hosts[ -1 ]
info( '*** Starting iperf with %d%% of CPU allocated to hosts\n' %
( 100.0 * cpu ) )
# We measure at the server because it doesn't include
# the client's buffer fill rate
popen = server.popen( 'iperf -yc -s -p 5001' )
waitListening( client, server, 5001 )
# ignore empty result from waitListening/telnet
popen.stdout.readline()
client.cmd( 'iperf -yc -t %s -c %s' % ( seconds, server.IP() ) )
result = decode( popen.stdout.readline() ).split( ',' )
bps = float( result[ -1 ] )
popen.terminate()
net.stop()
updated = results.get( sched, [] )
updated += [ ( cpu, bps ) ]
results[ sched ] = updated
return results
示例15: cleanup
def cleanup():
"""Cleanup all possible junk that we may have started."""
log.setLogLevel('info')
# Standard mininet cleanup
mnclean.cleanup()
# Cleanup any leftover daemon
patterns = []
for d in daemons.__all__:
obj = getattr(daemons, d)
killp = getattr(obj, 'KILL_PATTERNS', None)
if not killp:
continue
if not is_container(killp):
killp = [killp]
patterns.extend(killp)
log.info('*** Cleaning up daemons:\n')
for pattern in patterns:
mnclean.killprocs('"%s"' % pattern)
log.info('\n')