Commit c1611cd9 authored by Mike Hibler's avatar Mike Hibler

Slightly modified version of Jon's Xen vif script for control net setup.

parent 5fef1c70
#!/bin/sh
#
# Invoked by xmcreate script to configure the control network for a vnode.
# Usage:
# emulab-cnet vmid host_ip vnode_name vnode_ip (online | offline)
#
# NOTE: vmid should be an integer ID.
#
#boss=@BOSSNODE_IP@
#ops=@USERNODE_IP@
#fs=@FSNODE_IP@
boss=155.98.32.70
ops=155.98.33.74
fs=155.98.33.74
# XXX should be configed
tmcd_port=7777
slothd_port=8509
evproxy_port=16505
LOGDIR=/var/emulab/logs
if [ $# < 3 ]; then
echo "usage: $0 vmid host_ip vnode_name vnode_ip [ other_args ]"
exit 1
fi
# $vif comes from the environment
vmid=$1; shift
host_ip=$1; shift
vhost_id=$1; shift
vif_ip=$1; shift
local_tmcd_port=`expr $tmcd_port \+ $vmid`
#echo "(vif=$vif), vmid=$vmid, host_ip=$host_ip, vnode_name=$vhost_id, vnode_ip=$vif_ip, other=$*" > /tmp/args
# xen's configuration for a vif
sh /etc/xen/scripts/vif-bridge $*
cleanup="/tmp/cleanup-$vhost_id"
do_offline() {
sh $cleanup
rm -f $cleanup
}
do_online() {
echo "# Cleanup script for $vif in vhost $vhost_id" >> $cleanup
echo "# created `date`" >> $cleanup
# prevent dhcp requests from reaching eth0
/sbin/iptables -A OUTPUT -j DROP -o $vif -m pkttype --pkt-type broadcast -m physdev --physdev-out $vif
echo "/sbin/iptables -D OUTPUT -j DROP -o $vif -m pkttype --pkt-type broadcast -m physdev --physdev-out $vif" >> $cleanup
# reroute tmcd calls to the proxy on the physical host
/sbin/iptables -t nat -A PREROUTING -j DNAT -p tcp --dport $tmcd_port -d $boss -s $vif_ip --to-destination $host_ip:$local_tmcd_port
/sbin/iptables -t nat -A PREROUTING -j DNAT -p udp --dport $tmcd_port -d $boss -s $vif_ip --to-destination $host_ip:$local_tmcd_port
echo "/sbin/iptables -t nat -D PREROUTING -j DNAT -p tcp --dport $tmcd_port -d $boss -s $vif_ip --to-destination $host_ip:$local_tmcd_port" >> $cleanup
echo "/sbin/iptables -t nat -D PREROUTING -j DNAT -p udp --dport $tmcd_port -d $boss -s $vif_ip --to-destination $host_ip:$local_tmcd_port" >> $cleanup
# start a tmcc proxy (handles both TCP and UDP)
/usr/local/etc/emulab/tmcc.bin -d -n $vhost_id -X $host_ip:$local_tmcd_port -s $boss -p $tmcd_port -o $LOGDIR/tmccproxy.$vhost_id.log &
echo "kill $!" >> $cleanup
# slothd
/sbin/iptables -t nat -A POSTROUTING -j SNAT -p udp --dport $slothd_port --to-source $host_ip -s $vif_ip --destination $boss -o eth0
echo "/sbin/iptables -t nat -D POSTROUTING -j SNAT -p udp --dport $slothd_port --to-source $host_ip -s $vif_ip --destination $boss -o eth0" >> $cleanup
# route mount points and evproxy server
# todo: only forward ports the mount server needs (use rpcinfo on fs node)
# todo: also only route back to the vif ip
/sbin/iptables -t nat -A POSTROUTING -j SNAT --to-source $host_ip -s $vif_ip --destination $fs -o eth0
echo "/sbin/iptables -t nat -D POSTROUTING -j SNAT --to-source $host_ip -s $vif_ip --destination $fs -o eth0" >> $cleanup
# reroute evproxy packets
/sbin/iptables -t nat -A PREROUTING -j DNAT -p tcp --dport $evproxy_port -d $ops -s $vif_ip --to-destination $host_ip:$evproxy_port
echo "/sbin/iptables -t nat -D PREROUTING -j DNAT -p tcp --dport $evproxy_port -d $ops -s $vif_ip --to-destination $host_ip:$evproxy_port" >> $cleanup
}
case "$1" in
'online')
do_online
;;
'offline')
do_offline
;;
esac
exit 0
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