Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 185 lines (155 sloc) 5.74 KB
#!/bin/bash
if [ "$EUID" != "0" ]; then
echo "You must be root to run this script."
exit 1
fi
SCRIPT_NAME="rftest2"
LXCDIR=/var/lib/lxc
MONGODB_CONF=/etc/mongodb.conf
MONGODB_PORT=27017
CONTROLLER_PORT=6633
RF_HOME=..
export PATH=$PATH:/usr/local/bin:/usr/local/sbin
export PYTHONPATH=$PYTHONPATH:$RF_HOME
cd $RF_HOME
wait_port_listen() {
port=$1
while ! `nc -z localhost $port` ; do
echo -n .
sleep 1
done
}
echo_bold() {
echo -e "\033[1m${1}\033[0m"
}
kill_process_tree() {
top=$1
pid=$2
children=`ps -o pid --no-headers --ppid ${pid}`
for child in $children
do
kill_process_tree 0 $child
done
if [ $top -eq 0 ]; then
kill -9 $pid &> /dev/null
fi
}
reset() {
init=$1;
if [ $init -eq 1 ]; then
echo_bold "-> Starting $SCRIPT_NAME";
else
echo_bold "-> Stopping child processes...";
kill_process_tree 1 $$
fi
ovs-vsctl del-br dp0 &> /dev/null;
ovs-vsctl emer-reset &> /dev/null;
echo_bold "-> Stopping and resetting LXC VMs...";
for vm in "rfvmA" "rfvmB" "rfvmC" "rfvmD"
do
lxc-shutdown -n "$vm";
while true
do
if lxc-info -q -n "$vm" | grep -q "STOPPED"; then
break;
fi
echo -n .
sleep 1
done
done
echo_bold "-> Deleting (previous) run data...";
mongo db --eval "
db.getCollection('rftable').drop();
db.getCollection('rfconfig').drop();
db.getCollection('rfstats').drop();
db.getCollection('rfclient<->rfserver').drop();
db.getCollection('rfserver<->rfproxy').drop();
"
rm -rf /var/lib/lxc/rfvmA/rootfs/opt/rfclient;
rm -rf /var/lib/lxc/rfvmB/rootfs/opt/rfclient;
rm -rf /var/lib/lxc/rfvmC/rootfs/opt/rfclient;
rm -rf /var/lib/lxc/rfvmD/rootfs/opt/rfclient;
}
reset 1
trap "reset 0; exit 0" INT
echo_bold "-> Setting up the management bridge (lxcbr0)..."
ifconfig lxcbr0 192.169.1.1 up
echo_bold "-> Setting up MongoDB..."
sed -i "/bind_ip/c\bind_ip = 127.0.0.1,192.169.1.1" $MONGODB_CONF
service mongodb restart
wait_port_listen $MONGODB_PORT
echo_bold "-> Configuring the virtual machines..."
# Create the rfclient dir
mkdir /var/lib/lxc/rfvmA/rootfs/opt/rfclient
mkdir /var/lib/lxc/rfvmB/rootfs/opt/rfclient
mkdir /var/lib/lxc/rfvmC/rootfs/opt/rfclient
mkdir /var/lib/lxc/rfvmD/rootfs/opt/rfclient
# Copy the rfclient executable
cp build/rfclient /var/lib/lxc/rfvmA/rootfs/opt/rfclient/rfclient
cp build/rfclient /var/lib/lxc/rfvmB/rootfs/opt/rfclient/rfclient
cp build/rfclient /var/lib/lxc/rfvmC/rootfs/opt/rfclient/rfclient
cp build/rfclient /var/lib/lxc/rfvmD/rootfs/opt/rfclient/rfclient
# We sleep for a few seconds to wait for the interfaces to go up
echo "#!/bin/sh" > /var/lib/lxc/rfvmA/rootfs/root/run_rfclient.sh
echo "sleep 3" >> /var/lib/lxc/rfvmA/rootfs/root/run_rfclient.sh
echo "/etc/init.d/quagga start" >> /var/lib/lxc/rfvmA/rootfs/root/run_rfclient.sh
echo "/opt/rfclient/rfclient > /var/log/rfclient.log" >> /var/lib/lxc/rfvmA/rootfs/root/run_rfclient.sh
echo "#!/bin/sh" > /var/lib/lxc/rfvmB/rootfs/root/run_rfclient.sh
echo "sleep 3" >> /var/lib/lxc/rfvmB/rootfs/root/run_rfclient.sh
echo "/etc/init.d/quagga start" >> /var/lib/lxc/rfvmB/rootfs/root/run_rfclient.sh
echo "/opt/rfclient/rfclient > /var/log/rfclient.log" >> /var/lib/lxc/rfvmB/rootfs/root/run_rfclient.sh
echo "#!/bin/sh" > /var/lib/lxc/rfvmC/rootfs/root/run_rfclient.sh
echo "sleep 3" >> /var/lib/lxc/rfvmC/rootfs/root/run_rfclient.sh
echo "/etc/init.d/quagga start" >> /var/lib/lxc/rfvmC/rootfs/root/run_rfclient.sh
echo "/opt/rfclient/rfclient > /var/log/rfclient.log" >> /var/lib/lxc/rfvmC/rootfs/root/run_rfclient.sh
echo "#!/bin/sh" > /var/lib/lxc/rfvmD/rootfs/root/run_rfclient.sh
echo "sleep 3" >> /var/lib/lxc/rfvmD/rootfs/root/run_rfclient.sh
echo "/etc/init.d/quagga start" >> /var/lib/lxc/rfvmD/rootfs/root/run_rfclient.sh
echo "/opt/rfclient/rfclient > /var/log/rfclient.log" >> /var/lib/lxc/rfvmD/rootfs/root/run_rfclient.sh
chmod +x /var/lib/lxc/rfvmA/rootfs/root/run_rfclient.sh
chmod +x /var/lib/lxc/rfvmB/rootfs/root/run_rfclient.sh
chmod +x /var/lib/lxc/rfvmC/rootfs/root/run_rfclient.sh
chmod +x /var/lib/lxc/rfvmD/rootfs/root/run_rfclient.sh
echo_bold "-> Starting the virtual machines..."
lxc-start -n rfvmA -d
lxc-start -n rfvmB -d
lxc-start -n rfvmC -d
lxc-start -n rfvmD -d
echo_bold "-> Starting the controller and RFPRoxy..."
cd pox
./pox.py log.level --=INFO topology openflow.topology openflow.discovery rfproxy rfstats &
cd -
wait_port_listen $CONTROLLER_PORT
echo_bold "-> Starting RFServer..."
./rfserver/rfserver.py rftest/rftest2config.csv &
echo_bold "-> Starting the control plane network (dp0 VS)..."
ovs-vsctl add-br dp0
ovs-vsctl add-port dp0 rfvmA.1
ovs-vsctl add-port dp0 rfvmA.2
ovs-vsctl add-port dp0 rfvmA.3
ovs-vsctl add-port dp0 rfvmA.4
ovs-vsctl add-port dp0 rfvmB.1
ovs-vsctl add-port dp0 rfvmB.2
ovs-vsctl add-port dp0 rfvmB.3
ovs-vsctl add-port dp0 rfvmC.1
ovs-vsctl add-port dp0 rfvmC.2
ovs-vsctl add-port dp0 rfvmC.3
ovs-vsctl add-port dp0 rfvmD.1
ovs-vsctl add-port dp0 rfvmD.2
ovs-vsctl add-port dp0 rfvmD.3
ovs-vsctl add-port dp0 rfvmD.4
ovs-vsctl set Bridge dp0 other-config:datapath-id=7266767372667673
ovs-vsctl set-controller dp0 tcp:127.0.0.1:$CONTROLLER_PORT
echo_bold "---"
echo_bold "This test is up and running."
echo_bold "Start Mininet:"
echo_bold " $ sudo mn --custom mininet/custom/topo-4sw-4host.py --topo=rftest2"
echo_bold " --controller=remote,ip=[host address],port=6633 --pre=ipconf"
echo_bold "Replace [host address] with the address of this host's interface "
echo_bold "connected to the Mininet VM."
echo_bold "Then try pinging everything:"
echo_bold " mininet> pingall"
echo_bold "You can stop this test by pressing CTRL+C."
echo_bold "---"
wait
exit 0
Something went wrong with that request. Please try again.