Commit c2e39e38 authored by Robert Ricci's avatar Robert Ricci

New and improved common-env.sh that now finds things like interface

names and IP addresses for you.

Updated run-monitor-libnetmon.sh to use better information from
common-env.sh

New run-stub.sh to automatically get the interface name for you
parent a65f04ea
...@@ -4,10 +4,35 @@ ...@@ -4,10 +4,35 @@
# shell scripts # shell scripts
# #
#
# 'Header guard'
#
if [ "$COMMON_ENV_LOADED" != "yes" ]; then
COMMON_ENV_LOADED="yes"
#
# Locations of some Emulab-specific files
#
EMUVAR="/var/emulab"
EMUBOOT="$EMUVAR/boot"
NICKFILE="$EMUBOOT/nickname"
RCPLAB="$EMUBOOT/rc.plab"
HOSTSFILE="/etc/hosts"
IFCONFIG="/sbin/ifconfig"
PERL="/usr/bin/perl"
PYTHON="/usr/bin/python"
SUDO="/usr/bin/sudo"
#
# Some 'constants' by convention.
#
export PELAB_LAN=elabc
export EPLAB_LAN=planetc
# #
# Node/experiment info # Node/experiment info
# #
export NICKNAME=`cat /var/emulab/boot/nickname`; export NICKNAME=`cat $NICKFILE`
export HOSTNAME=`echo $NICKNAME | cut -d. -f1`; export HOSTNAME=`echo $NICKNAME | cut -d. -f1`;
export EXPERIMENT=`echo $NICKNAME | cut -d. -f2`; export EXPERIMENT=`echo $NICKNAME | cut -d. -f2`;
export PROJECT=`echo $NICKNAME | cut -d. -f3`; export PROJECT=`echo $NICKNAME | cut -d. -f3`;
...@@ -22,3 +47,78 @@ export STUB_DIR="${BASE}/stub/"; ...@@ -22,3 +47,78 @@ export STUB_DIR="${BASE}/stub/";
export NETMON_DIR="${BASE}/libnetmon/"; export NETMON_DIR="${BASE}/libnetmon/";
export MONITOR_DIR="${BASE}/monitor/"; export MONITOR_DIR="${BASE}/monitor/";
export TMPDIR="/var/tmp/"; export TMPDIR="/var/tmp/";
#
# Important scrips/libraries
#
export NETMOND="netmond"
export STUBD="stubd"
export MONITOR="monitor.py"
export NETMON_LIB="libnetmon.so"
#
# Where are we running?
#
if [ -e "$RCPLAB" ]; then
export RUNNING_ON="plab"
export ON_PLAB="yes"
export ON_ELAB=""
else
export RUNNING_ON="elab"
export ON_PLAB=""
export ON_ELAB="yes"
fi
#
# IP addresses and interface names
#
ifacename() {
IPADDR=$1
LINKIP=`lookup_ip_host $1`
IFACENAME=`$IFCONFIG -a | $PERL -e "while(<>) { if (/^(eth\d+)/) { \\\$if = \\\$1; } if (/$LINKIP/) { print \"\\\$if\n\"; exit 0; }} exit 1;"`
echo $IFACENAME
}
lookup_ip_host()
{
HOST=$1
LINK=$2
IPADDR=`grep "$HOST-$LINK" $HOSTSFILE | cut -f1`
echo $IPADDR
}
get_iface_addr() {
IFACE=$1
IFACEADDR=`$IFCONFIG -a | $PERL -e "while(<>) { if (/^$IFACE/) { \\\$found = 1; } if (\\\$found && /addr:(\d+\.\d+\.\d+\.\d+)/) { print \"\\\$1\n\"; exit 0; }} exit 1;"`
echo $IFACEADDR
}
#
# $HOST_ROLE should be set by the calling script
#
if [ "$HOST_ROLE" == "monitor" ]; then
export PELAB_IP=`lookup_ip_host $HOSTNAME $PELAB_LAN`
export PELAB_IFACE=`ifacename $PELAB_IP`
elif [ "$HOST_ROLE" == "stub" ]; then
if [ "$ON_ELAB" == "yes" ]; then
export PLAB_IP=`lookup_ip_host $HOSTNAME $EPLAB_LAN`
export PLAB_IFACE=`ifacename $PLAB_IP`
else
# On real planetlab
export PLAB_IFACE="vnet"
export PLAB_IP=`get_iface_addr $PLAB_IFACE`
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
fi # End of header guard
...@@ -3,24 +3,24 @@ ...@@ -3,24 +3,24 @@
# Script to run the monitor, collecting data from libnetmon # Script to run the monitor, collecting data from libnetmon
# #
#
# Let common-env know what role we're playing
#
export HOST_ROLE="monitor"
# #
# Grab common environment variables # Grab common environment variables
# #
. `dirname $0`/../common-env.sh . `dirname $0`/../common-env.sh
if [ $# != 1 ]; then if [ $# != 0 ]; then
if [ $# != 2 ]; then if [ $# != 1 ]; then
echo "Usage: $0 <my-ip> [stub-ip]" echo "Usage: $0 [stub-ip]"
exit 1; exit 1;
fi fi
SIP=$2 SIP=$1
fi fi
PID=$PROJECT
EID=$EXPERIMENT
MIP=$1
NETMOND=netmond
if ! [ -x "$NETMON_DIR/$NETMOND" ]; then if ! [ -x "$NETMON_DIR/$NETMOND" ]; then
gmake -C $NETMON_DIR $NETMOND gmake -C $NETMON_DIR $NETMOND
fi fi
...@@ -30,5 +30,5 @@ if ! [ -x "$NETMON_DIR/$NETMOND" ]; then ...@@ -30,5 +30,5 @@ if ! [ -x "$NETMON_DIR/$NETMOND" ]; then
exit 1; exit 1;
fi fi
echo "Starting up netmond for $PID/$EID $MIP $SIP"; echo "Starting up netmond for $PROJECT/$EXPERIMENT $PELAB_IP $SIP";
$NETMON_DIR/$NETMOND | python $MONITOR_DIR/monitor.py ip-mapping.txt $PID/$EID $MIP $SIP exec $NETMON_DIR/$NETMOND | $PYTHON $MONITOR_DIR/$MONITOR ip-mapping.txt $PROJECT/$EXPERIMENT $PELAB_IP $SIP
#!/bin/sh
#
# Script to run the stub
#
#
# Let common-env know what role we're playing
#
export HOST_ROLE="stub"
#
# Grab common environment variables
#
. `dirname $0`/../common-env.sh
#
# Just run the stub!
# TODO: Allow other command line args
#
echo "Starting stubd on $PLAB_IFACE"
exec $AS_ROOT $STUB_DIR/$STUBD $PLAB_IFACE
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