Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9cdcc59c28 | |||
| 68b28201ad | |||
| ebfc4d0d72 | |||
| 67b06f3a83 | |||
| f510caa0e7 |
@@ -1,2 +0,0 @@
|
||||
include mnexec.c
|
||||
exclude bin/mnexec
|
||||
@@ -21,12 +21,10 @@ test: $(MININET) $(TEST)
|
||||
-echo "Running tests"
|
||||
mininet/test/test_nets.py
|
||||
|
||||
install:
|
||||
install: mnexec
|
||||
cp mnexec bin/
|
||||
python setup.py install
|
||||
|
||||
develop:
|
||||
python setup.py develop
|
||||
|
||||
doc:
|
||||
doxygen doxygen.cfg
|
||||
|
||||
|
||||
+7
-7
@@ -91,6 +91,7 @@ import re
|
||||
import select
|
||||
import signal
|
||||
from time import sleep
|
||||
from subprocess import check_output
|
||||
|
||||
from mininet.cli import CLI
|
||||
from mininet.log import info, error, debug, output
|
||||
@@ -561,13 +562,12 @@ def init():
|
||||
"Initialize Mininet."
|
||||
if init.inited:
|
||||
return
|
||||
if os.getuid() != 0:
|
||||
# Note: this script must be run as root
|
||||
# Perhaps we should do so automatically!
|
||||
print "*** Mininet must run as root."
|
||||
exit( 1 )
|
||||
# If which produces no output, then mnexec is not in the path.
|
||||
# May want to loosen this to handle mnexec in the current dir.
|
||||
# Make sure we can sudo without a password
|
||||
try:
|
||||
check_output( [ 'sudo', '-n', 'echo' ] )
|
||||
except:
|
||||
raise Exception( "Could not run sudo -n echo - check /etc/sudoers" )
|
||||
# Make sure mnexec is in our path
|
||||
if not quietRun( 'which mnexec' ):
|
||||
raise Exception( "Could not find mnexec - check $PATH" )
|
||||
fixLimits()
|
||||
|
||||
+5
-3
@@ -76,12 +76,12 @@ class Node( object ):
|
||||
opts = '-cdp'
|
||||
if self.inNamespace:
|
||||
opts += 'n'
|
||||
cmd = [ 'mnexec', opts, 'bash', '-m' ]
|
||||
cmd = [ 'sudo', '-E', 'env', 'PATH=%s' % os.environ['PATH'],
|
||||
'mnexec', opts, 'bash', '-m', '-p' ]
|
||||
self.shell = Popen( cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT,
|
||||
close_fds=False )
|
||||
self.stdin = self.shell.stdin
|
||||
self.stdout = self.shell.stdout
|
||||
self.pid = self.shell.pid
|
||||
self.pollOut = select.poll()
|
||||
self.pollOut.register( self.stdout )
|
||||
# Maintain mapping between file descriptors and nodes
|
||||
@@ -102,6 +102,8 @@ class Node( object ):
|
||||
self.waiting = False
|
||||
# Stash additional information as desired
|
||||
self.args = kwargs
|
||||
# Read pid from mnexec
|
||||
self.pid = int( self.readline()[ 1: ] )
|
||||
|
||||
@classmethod
|
||||
def fdToNode( cls, fd ):
|
||||
@@ -149,7 +151,7 @@ class Node( object ):
|
||||
|
||||
def terminate( self ):
|
||||
"Send kill signal to Node and clean up after it."
|
||||
os.kill( self.pid, signal.SIGKILL )
|
||||
quietRun( 'kill ' + str( self.pid ) )
|
||||
self.cleanup()
|
||||
|
||||
def stop( self ):
|
||||
|
||||
+23
-4
@@ -1,11 +1,12 @@
|
||||
"Utility functions for Mininet."
|
||||
|
||||
from time import sleep
|
||||
from resource import setrlimit, RLIMIT_NPROC, RLIMIT_NOFILE
|
||||
from resource import setrlimit, getrlimit, RLIMIT_NPROC, RLIMIT_NOFILE
|
||||
import select
|
||||
from subprocess import call, check_call, Popen, PIPE, STDOUT
|
||||
import os
|
||||
|
||||
from mininet.log import error
|
||||
from mininet.log import error, warn
|
||||
|
||||
# Command execution support
|
||||
|
||||
@@ -29,6 +30,7 @@ def quietRun( *cmd ):
|
||||
cmd = cmd[ 0 ]
|
||||
if isinstance( cmd, str ):
|
||||
cmd = cmd.split( ' ' )
|
||||
cmd = ["sudo", "-E", "env", "PATH=%s" % os.environ["PATH"]] + cmd
|
||||
popen = Popen( cmd, stdout=PIPE, stderr=STDOUT )
|
||||
# We can't use Popen.communicate() because it uses
|
||||
# select(), which can't handle
|
||||
@@ -205,5 +207,22 @@ def makeNumeric( s ):
|
||||
|
||||
def fixLimits():
|
||||
"Fix ridiculously small resource limits."
|
||||
setrlimit( RLIMIT_NPROC, ( 4096, 8192 ) )
|
||||
setrlimit( RLIMIT_NOFILE, ( 16384, 32768 ) )
|
||||
manyprocs = 8192
|
||||
manyfiles = 32768
|
||||
minprocs, maxprocs = getrlimit( RLIMIT_NPROC )
|
||||
minfiles, maxfiles = getrlimit( RLIMIT_NOFILE )
|
||||
# Root can raise limits
|
||||
if os.getuid() == 0:
|
||||
maxprocs = max( maxprocs, manyprocs )
|
||||
maxfiles = max( maxfiles, manyfiles )
|
||||
minprocs = min( manyprocs, maxprocs )
|
||||
minfiles = min( manyfiles, maxfiles )
|
||||
setrlimit( RLIMIT_NPROC, ( minprocs, maxprocs ) )
|
||||
setrlimit( RLIMIT_NOFILE, ( minfiles, maxfiles ) )
|
||||
nprocs = max( getrlimit( RLIMIT_NPROC ) )
|
||||
nfiles = max( getrlimit( RLIMIT_NOFILE ) )
|
||||
# Complain if limits are too low
|
||||
if nprocs < manyprocs:
|
||||
warn( '*** Warning: process limit is low:', nprocs, 'procs\n' )
|
||||
if nfiles < manyfiles:
|
||||
warn( '*** Warning: open file limit is low:', nfiles, 'files \n' )
|
||||
|
||||
@@ -2,33 +2,26 @@
|
||||
|
||||
"Setuptools params"
|
||||
|
||||
import os, setuptools
|
||||
import distutils.command.build_scripts
|
||||
import distutils.command.clean
|
||||
import distutils.ccompiler
|
||||
from setuptools import setup, find_packages
|
||||
from os.path import join
|
||||
|
||||
scripts = [ join( 'bin', filename ) for filename in [
|
||||
'mn', 'mnexec' ] ]
|
||||
|
||||
modname = distname = 'mininet'
|
||||
|
||||
class build_scripts(distutils.command.build_scripts.build_scripts):
|
||||
def run(self):
|
||||
distutils.ccompiler.new_compiler().link_executable(["mnexec.c"], "bin/mnexec")
|
||||
distutils.command.build_scripts.build_scripts.run(self)
|
||||
|
||||
class clean(distutils.command.clean.clean):
|
||||
def run(self):
|
||||
if os.path.exists("bin/mnexec"):
|
||||
os.unlink("bin/mnexec")
|
||||
distutils.command.clean.clean.run(self)
|
||||
|
||||
setuptools.setup(
|
||||
setup(
|
||||
name=distname,
|
||||
version='0.0.0',
|
||||
description='Process-based OpenFlow emulator',
|
||||
author='Bob Lantz',
|
||||
author_email='rlantz@cs.stanford.edu',
|
||||
packages=setuptools.find_packages(exclude='test'),
|
||||
packages=find_packages(exclude='test'),
|
||||
long_description="""
|
||||
Insert longer description here.
|
||||
""",
|
||||
classifiers=[
|
||||
"License :: OSI Approved :: BSD",
|
||||
"License :: OSI Approved :: GNU General Public License (GPL)",
|
||||
"Programming Language :: Python",
|
||||
"Development Status :: 4 - Beta",
|
||||
"Intended Audience :: Developers",
|
||||
@@ -40,10 +33,5 @@ setuptools.setup(
|
||||
'setuptools',
|
||||
'networkx'
|
||||
],
|
||||
scripts=[
|
||||
'bin/mn',
|
||||
'bin/mnexec'
|
||||
],
|
||||
cmdclass={"build_scripts": build_scripts,
|
||||
"clean": clean}
|
||||
scripts=scripts,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user