Compare commits

..
5 Commits
Author SHA1 Message Date
Bob Lantz 9cdcc59c28 Check to make sure sudo works without password. 2012-03-13 23:54:12 -07:00
Bob Lantz 68b28201ad Pass code check. 2012-03-13 23:16:36 -07:00
Bob Lantz ebfc4d0d72 Reinstate fixLimits - complain if limits are too small. 2012-03-13 23:15:13 -07:00
Bob Lantz 67b06f3a83 Simplify reading pid from mnexec. 2012-03-13 22:42:49 -07:00
Ed Swierk f510caa0e7 Run commands with sudo so mininet can be directly imported by
an unprivileged Python process
2012-03-13 21:18:51 -07:00
6 changed files with 50 additions and 89 deletions

No files matched your search

+2 -2
View File
@@ -319,8 +319,8 @@ class CLI( Cmd ):
nodePoller = poll()
nodePoller.register( node.stdout )
bothPoller = poll()
bothPoller.register( self.stdin, POLLIN )
bothPoller.register( node.stdout, POLLIN )
bothPoller.register( self.stdin )
bothPoller.register( node.stdout )
if self.isatty():
# Buffer by character, so that interactive
# commands sort of work
+7 -7
View File
@@ -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
View File
@@ -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
View File
@@ -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' )
+13 -39
View File
@@ -146,6 +146,16 @@ function of {
make
sudo make install
# Install dissector:
sudo apt-get install -y wireshark libgtk2.0-dev
cd ~/openflow/utilities/wireshark_dissectors/openflow
make
sudo make install
# Copy coloring rules: OF is white-on-blue:
mkdir -p ~/.wireshark
cp ~/mininet/util/colorfilters ~/.wireshark
# Remove avahi-daemon, which may cause unwanted discovery packets to be
# sent during tests, near link status changes:
sudo apt-get remove -y avahi-daemon
@@ -159,39 +169,6 @@ function of {
sudo sh -c "echo 'blacklist net-pf-10\nblacklist ipv6' >> $BLACKLIST"
}
function wireshark {
echo "Installing Wireshark dissector..."
sudo apt-get install -y wireshark libgtk2.0-dev
if [ "$DIST" = "Ubuntu" ] && [ "$RELEASE" != "10.04" ]; then
# Install newer version
sudo apt-get install -y scons mercurial libglib2.0-dev
sudo apt-get install -y libwiretap-dev libwireshark-dev
cd ~
hg clone https://bitbucket.org/barnstorm/of-dissector
cd of-dissector/src
export WIRESHARK=/usr/include/wireshark
scons
# libwireshark0/ on 11.04; libwireshark1/ on later
WSDIR=`ls -d /usr/lib/wireshark/libwireshark* | head -1`
WSPLUGDIR=$WSDIR/plugins/
sudo cp openflow.so $WSPLUGDIR
echo "Copied openflow plugin to $WSPLUGDIR"
else
# Install older version from reference source
cd ~/openflow/utilities/wireshark_dissectors/openflow
make
sudo make install
fi
# Copy coloring rules: OF is white-on-blue:
mkdir -p ~/.wireshark
cp ~/mininet/util/colorfilters ~/.wireshark
}
# Install Open vSwitch
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
function ovs {
@@ -284,7 +261,7 @@ function oftest {
# Install oftest:
cd ~/
git clone git://github.com/floodlight/oftest
git clone git://openflow.org/oftest
cd oftest
cd tools/munger
sudo make install
@@ -294,7 +271,7 @@ function oftest {
function cbench {
echo "Installing cbench..."
sudo apt-get install -y libsnmp-dev libpcap-dev libconfig-dev
sudo apt-get install -y libsnmp-dev libpcap-dev
cd ~/
git clone git://openflow.org/oflops.git
cd oflops
@@ -354,7 +331,6 @@ function all {
kernel
mn_deps
of
wireshark
ovs
modprobe
nox
@@ -414,7 +390,6 @@ function usage {
printf -- ' -n: install mini(N)et dependencies + core files\n' >&2
printf -- ' -t: install o(T)her stuff\n' >&2
printf -- ' -v: install open (V)switch\n' >&2
printf -- ' -w: install OpenFlow (w)ireshark dissector\n' >&2
printf -- ' -x: install NO(X) OpenFlow controller\n' >&2
printf -- ' -y: install (A)ll packages\n' >&2
@@ -425,7 +400,7 @@ if [ $# -eq 0 ]
then
all
else
while getopts 'abcdfhkmntvwx' OPTION
while getopts 'abcdfhkmntvx' OPTION
do
case $OPTION in
a) all;;
@@ -439,7 +414,6 @@ else
n) mn_deps;;
t) other;;
v) ovs;;
w) wireshark;;
x) nox;;
?) usage;;
esac
-34
View File
@@ -1,34 +0,0 @@
#!/bin/bash
# This script is intended to install Mininet into
# a brand-new Ubuntu (10.04 or 11.10) virtual machine,
# to create a fully usable "tutorial" VM.
set -e
sudo sh -c 'cat >> /etc/sudoers' <<EOF
openflow ALL=NOPASSWD: ALL
EOF
sudo sed -i -e 's/Default/#Default/' /etc/sudoers
sudo sed -i -e 's/ubuntu/mininet-vm/' /etc/hostname
sudo sed -i -e 's/ubuntu/mininet-vm/g' /etc/hosts
sudo hostname `cat /etc/hostname`
sudo sed -i -e 's/quiet splash/text/' /etc/default/grub
sudo update-grub
sudo sed -i -e 's/us.archive.ubuntu.com/mirrors.kernel.org/' \
/etc/apt/sources.list
sudo apt-get update
sudo apt-get -y install git-core openssh-server
git clone git://github.com/mininet/mininet
cd mininet
cd
time mininet/util/install.sh
if ! grep NOX_CORE_DIR .bashrc; then
echo "export NOX_CORE_DIR=~/noxcore/build/src/" >> .bashrc
fi
echo <<EOF
You may need to reboot and then:
sudo dpkg-reconfigure openvswitch-datapath-dkms
sudo service openvswitch-switch start
EOF