blob: 2040eeb224e0c5bc66cb14b7ee38b2d9ca67491c [file] [log] [blame]
#!/bin/bash
# install-tutorial.sh
#
# Runs as root.
#
# This script builds an ONOS tutorial VM.
function create_user {
local name=$1
local description=$2
sudo /usr/sbin/useradd -c "$description" -d /home/$name -U -m -p $(openssl passwd -1 $name) -s /bin/bash $name
echo "$name ALL=(ALL) NOPASSWD:ALL" >> $name
sudo mv $name /etc/sudoers.d
sudo chown root:root /etc/sudoers.d/$name
sudo usermod -aG wireshark $name
sudo usermod -aG mininet $name
sudo mkdir /home/$name/.ssh
sudo chown $name:$name /home/$name/.ssh
sudo cp /home/mininet/.ssh/id_rsa /home/$name/.ssh/
sudo chown $name:$name /home/$name/.ssh/id_rsa
sudo -u $name sh -c "echo \"export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64\" >> /home/$name/.bashrc"
sudo -u $name sh -c "echo \"export ONOS_ROOT=/home/mininet/onos\" >> /home/$name/.bashrc"
sudo -u $name sh -c "echo \"export KARAF_ROOT=/home/mininet/apache-karaf-3.0.3\" >> /home/$name/.bashrc"
sudo -u $name sh -c "echo \"export M2_REPO=/home/mininet/.m2/repository\" >> /home/$name/.bashrc"
sudo -u $name sh -c "echo \". /home/mininet/onos/tools/dev/bash_profile\" >> /home/$name/.bashrc"
sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.11 ls
sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.12 ls
sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.13 ls
sudo mkdir -p /home/$name/.wireshark/plugins
sudo cp /home/mininet/openflow.lua /home/$name/.wireshark/plugins
sudo chown -R $name:$name /home/$name/.wireshark
}
# -------------- Setup 3-node LXC cluster ----------------
sudo lxc-create --name onos1 -t download -- --dist ubuntu --release utopic --arch amd64
sudo sh -c "echo lxc.start.auto=1 >> /var/lib/lxc/onos1/config"
sudo sh -c "sed -i s/dhcp/static/ /var/lib/lxc/onos1/rootfs/etc/network/interfaces"
sudo sh -c "cat << EOF >> /var/lib/lxc/onos1/rootfs/etc/network/interfaces
address 10.0.3.11
netmask 255.255.255.0
gateway 10.0.3.1
dns-nameservers 10.0.3.1
EOF"
sudo lxc-start --name onos1 --daemon
sudo lxc-ls --fancy
sleep 5
sudo lxc-ls --fancy
sudo lxc-attach --name onos1 -- ip a
sudo lxc-attach --name onos1 -- useradd -m sdn -s /bin/bash
sudo lxc-attach --name onos1 -- /bin/bash -c "echo sdn:rocks | chpasswd"
sudo lxc-attach --name onos1 -- /bin/bash -c "echo \"sdn ALL=(ALL) NOPASSWD:ALL\" > /etc/sudoers.d/sdn"
sudo lxc-attach --name onos1 -- apt-get update
sudo lxc-attach --name onos1 -- apt-get install -y openssh-server openjdk-8-jre-headless
sudo mkdir -p /var/lib/lxc/onos1/rootfs/home/sdn/.ssh
sudo cp ~/.ssh/id_rsa.pub /var/lib/lxc/onos1/rootfs/home/sdn/.ssh/authorized_keys
sudo lxc-attach --name onos1 -- chown sdn:sdn /home/sdn/.ssh/authorized_keys
sudo lxc-attach --name onos1 -- chmod 600 /home/sdn/.ssh/authorized_keys
sudo lxc-attach --name onos1 -- apt-get clean
sudo lxc-stop --name onos1
# Clone the first node to create two more nodes
sudo lxc-clone onos1 onos2
sudo sh -c "sed -i s/10.0.3.11/10.0.3.12/ /var/lib/lxc/onos2/rootfs/etc/network/interfaces"
sudo lxc-clone onos1 onos3
sudo sh -c "sed -i s/10.0.3.11/10.0.3.13/ /var/lib/lxc/onos3/rootfs/etc/network/interfaces"
sudo lxc-start --name onos1
sudo lxc-start --name onos2
sudo lxc-start --name onos3
sleep 10
sudo lxc-ls --fancy
echo "adding host keys to known_hosts"
# SSH to each once to add the host key to known_hosts
for onos in 10.0.3.11 10.0.3.12 10.0.3.13
do
echo "sshing to $onos"
ssh -o "StrictHostKeyChecking no" sdn@${onos} ls
done
echo "Enabling non-root wireshark"
echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections
sudo dpkg-reconfigure -f noninteractive wireshark-common
# Get the wireshark dissector handy
wget -O /home/mininet/openflow.lua "https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.1;f=openflow.lua"
# -------------- Install ONOS ----------------
echo "Installing ONOS"
USER=mininet
USER_HOME=/home/${USER}
cd ~
# Download a local karaf so we can use the bin directory
wget http://archive.apache.org/dist/karaf/3.0.3/apache-karaf-3.0.3.tar.gz
tar -xzf apache-karaf-3.0.3.tar.gz
git clone https://gerrit.onosproject.org/onos
cd onos && git checkout 1.2.1 && cd -
mkdir -p ~/Downloads
echo "export ONOS_ROOT=${USER_HOME}/onos" >> ~/.bashrc
echo "export KARAF_ROOT=${USER_HOME}/apache-karaf-3.0.3" >> ~/.bashrc
echo ". ~/onos/tools/dev/bash_profile" >> ~/.bashrc
export ONOS_ROOT=${USER_HOME}/onos
export KARAF_ROOT=${USER_HOME}/apache-karaf-3.0.3
. ~/onos/tools/dev/bash_profile
echo $ONOS_ROOT
echo $JAVA_HOME
export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"
cd $ONOS_ROOT && mvn clean install && mvn dependency:go-offline && cd -
# Get the sample apps and build them for the right version
git clone https://gerrit.onosproject.org/onos-app-samples
cd onos-app-samples
git checkout 52da58b5991049025ce1b599c000357500b00aef
mvn versions:set -DnewVersion=1.2.1 versions:commit
mvn clean install
cd ..
cat << EOF >> onos/tools/test/cells/3node
export ONOS_NIC=10.0.3.*
export OC1="10.0.3.11"
export OC2="10.0.3.12"
export OC3="10.0.3.13"
export OCI="10.0.3.11"
export ONOS_FEATURES="webconsole,onos-rest,onos-gui,onos-api,onos-core,onos-cli,onos-openflow"
export ONOS_APPS="drivers,openflow"
export ONOS_USER="sdn"
EOF
cat << EOF >> onos/tools/test/cells/1node
export ONOS_NIC=10.0.3.*
export OC1="10.0.3.11"
export OCI="10.0.3.11"
export ONOS_FEATURES="webconsole,onos-rest,onos-gui,onos-api,onos-core,onos-cli,onos-openflow"
export ONOS_APPS="drivers,openflow"
export ONOS_USER="sdn"
EOF
cell 3node
onos-package
onos-group install -f
onos-wait-for-start $OC1
onos-wait-for-start $OC2
onos-wait-for-start $OC3
echo "ONOS install and startup complete"
sleep 1
onos-service --cell status
# Prevent ONOS services from starting automatically
sudo sh -c "echo manual >> /var/lib/lxc/onos1/rootfs/etc/init/onos.override"
sudo sh -c "echo manual >> /var/lib/lxc/onos2/rootfs/etc/init/onos.override"
sudo sh -c "echo manual >> /var/lib/lxc/onos3/rootfs/etc/init/onos.override"
# ------------- Create reset scripts -------------
cat << EOF >> ${USER_HOME}/reset-to-1.sh
#!/bin/bash
sudo rm -rf /tmp/*
export ONOS_ROOT=/home/mininet/onos
export M2_REPO=/home/mininet/.m2/repository
export KARAF_TAR=/home/mininet/apache-karaf-3.0.3.tar.gz
. ${ONOS_ROOT}/tools/dev/bash_profile
. ${ONOS_ROOT}/tools/build/envDefaults
sudo mn -c
cell 3node
onos-service --cell stop
cell 1node
if [ -n "\$1" ]; then
export ONOS_APPS=\$ONOS_APPS,\$1
fi
onos-package
onos-install -f '$OC1'
EOF
sudo chmod 777 ${USER_HOME}/reset-to-1.sh
cat << EOF >> ${USER_HOME}/reset-to-3.sh
#!/bin/bash
sudo rm -rf /tmp/*
export ONOS_ROOT=/home/mininet/onos
export M2_REPO=/home/mininet/.m2/repository
export KARAF_TAR=/home/mininet/apache-karaf-3.0.3.tar.gz
. ${ONOS_ROOT}/tools/dev/bash_profile
. ${ONOS_ROOT}/tools/build/envDefaults
sudo mn -c
cell 3node
if [ -n "\$1" ]; then
export ONOS_APPS=\$ONOS_APPS,\$1
fi
onos-service --cell stop
onos-package
onos-install -f '$OC1'
onos-install -f '$OC2'
onos-install -f '$OC3'
EOF
sudo chmod 777 ${USER_HOME}/reset-to-3.sh
sudo apt-get clean
sudo rm /etc/apt/apt.conf.d/02proxy
# ------------- Set up each tutorial -------------
create_user tutorial1 "Basic ONOS Tutorial"
URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.1;f=tutorial1-setup.sh'
wget -O tutorial1-setup.sh $URL
sudo -u tutorial1 -H sh -c 'cp tutorial1-setup.sh ~/ && cd ~/ && sh tutorial1-setup.sh'
create_user sdnip "SDN-IP Tutorial"
SDNIP_URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.1;f=sdnip-setup.sh'
wget -O sdnip-setup.sh $SDNIP_URL
sudo -u sdnip -H sh -c 'cp sdnip-setup.sh ~/ && cd ~/ && sh sdnip-setup.sh'
create_user distributed "Distributed Tutorial"
DIST_URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.1;f=dist-setup.sh'
wget -O dist-setup.sh $DIST_URL
sudo -u distributed -H sh -c 'cp dist-setup.sh ~/ && cd ~/ && sh dist-setup.sh'
create_user optical "Optical Tutorial"
OPT_URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.1;f=opt-setup.sh'
wget -O opt-setup.sh $OPT_URL
sudo -u optical -H sh -c 'cp opt-setup.sh ~/ && cd ~/ && sh opt-setup.sh'
# ------------- Zero Unused Blocks -------------
#TODO investigate zerofree
echo "Zeroing unused blocks"
sync
dd if=/dev/zero of=tmp-zeros
sync
rm tmp-zeros
sync