Commit c8bbc432 authored by Robert Ricci's avatar Robert Ricci

More work on the framework for running the monitor and stub

automatically.

Now automatically determines the number of peers in the experiment.

run-monitor-libnetmon.sh automatically generates the IP mapping file
now.

Auto-create /local/logs if it doesn't exist (it doesn't on our
devbox image)

Add two new 'auto' scripts - these are intended to be run as part
of the automatic experiments. They properly wait for the stubs
to start before starting the monitors, etc. They log the outputs
of the stub and monitor to /local/logs, where loghole can pick
them up. They also kill their children if they are killed (to be
used with the program agent)

The auto-* scripts need a little more work in term of properly waiting
for their children to exit.
parent b12dad65
......@@ -38,8 +38,19 @@ HOSTSFILE="/etc/hosts"
IFCONFIG="/sbin/ifconfig"
PERL="${BIN_PATH}/perl"
PYTHON="${BIN_PATH}/python"
SH=/bin/sh
SUDO="${BIN_PATH}/sudo"
MKDIR="/bin/mkdir"
CHMOD="/bin/chmod"
SYNC="/usr/local/etc/emulab/emulab-sync"
if [ "$UNAME" == "Linux" ]; then
GREP="/bin/grep"
elif [ "$UNAME" == "FreeBSD" ]; then
BIN_PATH="/usr/bin/grep"
else
echo "Unable to determine operating system"
exit -1
fi
#
# Some 'constants' by convention.
......@@ -70,6 +81,12 @@ export STUB_DIR="${BASE}/stub/";
export NETMON_DIR="${BASE}/libnetmon/";
export MONITOR_DIR="${BASE}/monitor/";
export TMPDIR="/var/tmp/";
export LOGDIR="/local/logs/"
#
# Temproary files we use
#
export IPMAP="/var/tmp/ip-mapping.txt"
#
# Important scrips/libraries
......@@ -77,6 +94,7 @@ export TMPDIR="/var/tmp/";
export NETMOND="netmond"
export STUBD="stubd"
export MONITOR="monitor.py"
export GENIPMAP="gen-ip-mapping.pl"
export NETMON_LIB="libnetmon.so"
#
......@@ -92,6 +110,29 @@ else
export ON_ELAB="yes"
fi
#
# Make a handy variable for running as root (ie. invoke sudo if necessary)
#
if [ "$EUID" != "0" ]; then
export AS_ROOT="$SUDO"
else
export AS_ROOT=""
fi
#
# How big is this experiment? Counts the number of planetlab nodes
#
export PEER_PAIRS=`$GREP -E -c 'planet-.*-planetcontrol' /etc/hosts`
export PEERS=`expr $PEER_PAIRS \* 2`
#
# Make the logdir if it doesn't exist
#
if [ ! -d $LOGDIR ]; then
$AS_ROOT $MKDIR -p $LOGDIR
$AS_ROOT $CHMOD 777 $LOGDIR
fi
#
# IP addresses and interface names
#
......@@ -133,15 +174,6 @@ elif [ "$HOST_ROLE" == "stub" ]; then
fi
fi
#
# Make a handy variable for running as root (ie. invoke sudo if necessary)
#
if [ "$EUID" != "0" ]; then
export AS_ROOT="$SUDO"
else
export AS_ROOT=""
fi
#
# Function for waiting on a barrier sync
# I'd rather automatically determine the number of peer pairs, but that
......@@ -151,17 +183,30 @@ barrier_wait()
{
BARRIER=$1
#
# This needs to be set by the calling script
# Are we the master?
#
MASTER=$SYNC -m
if [ ! "$MASTER" ]; then
$SYNC -m
MASTER=$?
if [ "$MASTER" == "1" ]; then
# I know, this looks backwards. But it's right
$SYNC -n $BARRIER
else
WAITERS=`expr $PEERS - 1`
echo "Waiting for $WAITERS clients"
WAITERS=`expr $PEER_PAIRS \* 2 - 1`
$SYNC -n $BARRIER -i $WAITERS
fi
}
#
# Log the stdout and stderr of the given process to the logdir
# Runs the program in the background and returns its pid
#
log_output_background()
{
PROGNAME=$1
CMD=$2
$CMD 1> ${LOGDIR}/${PROGNAME}.stdout 2> ${LOGDIR}/${PROGNAME}.stderr &
echo $!
}
fi # End of header guard
#!/bin/sh
. `dirname $0`/../common-env.sh
#
# Wait for all of the stubs to start
#
echo "Waiting for stubs to become ready";
barrier_wait "stub";
#
# Start up our own monitor
#
MONPID=`log_output_background "monitor" \
"$SH ${MONITOR_DIR}/run-monitor-libnetmon.sh"`
# Kill the monitor if we get killed - TODO: harsher kill?
trap "$AS_ROOT kill $MONPID" EXIT
#
# Give it time to come up
#
sleep 1
#
# Wait for all the monitors to come up
#
echo "Waiting for monitors to become ready";
barrier_wait "monitor";
echo "Running!";
#
# Wait for our monitor to finish
#
wait
......@@ -30,5 +30,8 @@ if ! [ -x "$NETMON_DIR/$NETMOND" ]; then
exit 1;
fi
echo "Generating IP mapping file into $IPMAP";
$PERL ${MONITOR_DIR}/$GENIPMAP > $IPMAP
echo "Starting up netmond for $PROJECT/$EXPERIMENT $PELAB_IP $SIP";
exec $NETMON_DIR/$NETMOND -v 2 | $PYTHON $MONITOR_DIR/$MONITOR ip-mapping.txt $PROJECT/$EXPERIMENT $PELAB_IP $SIP
exec $NETMON_DIR/$NETMOND -v 2 | $PYTHON $MONITOR_DIR/$MONITOR $IPMAP $PROJECT/$EXPERIMENT $PELAB_IP $SIP
#!/bin/sh
. `dirname $0`/../common-env.sh
#
# Start up our own stub
#
echo $SH ${STUB_DIR}/run-stub.sh
STUBPID=`log_output_background "stub" "$SH ${STUB_DIR}/run-stub.sh"`
# Kill the stub if we get killed - TODO: harsher kill?
trap "$AS_ROOT kill $STUBPID" EXIT
#
# Give it time to come up
#
sleep 1
#
# Wait for all of the stubs to start
#
echo "Waiting for stubs to become ready";
barrier_wait "stub";
#
# Wait for all the monitors to come up
#
echo "Waiting for monitors to become ready";
barrier_wait "monitor";
echo "Running!";
#
# Wait for our stub to finish
#
wait
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment