Luca Prete | 8137ffc | 2016-08-16 11:53:45 -0700 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # install-tutorial.sh |
| 3 | # |
| 4 | # Runs as root. |
| 5 | # |
| 6 | # This script builds an ONOS tutorial VM. |
| 7 | |
| 8 | function create_user { |
| 9 | local name=$1 |
| 10 | local description=$2 |
| 11 | |
| 12 | sudo /usr/sbin/useradd -c "$description" -d /home/$name -U -m -p $(openssl passwd -1 $name) -s /bin/bash $name |
| 13 | echo "$name ALL=(ALL) NOPASSWD:ALL" >> $name |
| 14 | sudo mv $name /etc/sudoers.d |
| 15 | sudo chown root:root /etc/sudoers.d/$name |
| 16 | sudo usermod -aG wireshark $name |
| 17 | |
| 18 | sudo usermod -aG mininet $name |
| 19 | |
| 20 | sudo mkdir /home/$name/.ssh |
| 21 | sudo chown $name:$name /home/$name/.ssh |
| 22 | sudo cp /home/mininet/.ssh/id_rsa /home/$name/.ssh/ |
| 23 | sudo chown $name:$name /home/$name/.ssh/id_rsa |
| 24 | |
| 25 | sudo -u $name sh -c "echo \"export ONOS_ROOT=/home/mininet/onos\" >> /home/$name/.bashrc" |
| 26 | sudo -u $name sh -c "echo \"export KARAF_ROOT=/home/mininet/apache-karaf-3.0.3\" >> /home/$name/.bashrc" |
| 27 | sudo -u $name sh -c "echo \"export M2_REPO=/home/mininet/.m2/repository\" >> /home/$name/.bashrc" |
| 28 | sudo -u $name sh -c "echo \". /home/mininet/onos/tools/dev/bash_profile\" >> /home/$name/.bashrc" |
| 29 | |
| 30 | sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.11 ls |
| 31 | sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.12 ls |
| 32 | sudo -u $name ssh -o "StrictHostKeyChecking no" sdn@10.0.3.13 ls |
| 33 | |
| 34 | sudo mkdir -p /home/$name/.wireshark/plugins |
| 35 | sudo cp /home/mininet/openflow.lua /home/$name/.wireshark/plugins |
| 36 | sudo chown -R $name:$name /home/$name/.wireshark |
| 37 | } |
| 38 | |
| 39 | # -------------- Setup 3-node LXC cluster ---------------- |
| 40 | |
| 41 | sudo lxc-create --name onos1 -t download -- --dist ubuntu --release utopic --arch amd64 |
| 42 | |
| 43 | sudo sh -c "echo lxc.start.auto=1 >> /var/lib/lxc/onos1/config" |
| 44 | |
| 45 | sudo sh -c "sed -i s/dhcp/static/ /var/lib/lxc/onos1/rootfs/etc/network/interfaces" |
| 46 | sudo sh -c "cat << EOF >> /var/lib/lxc/onos1/rootfs/etc/network/interfaces |
| 47 | address 10.0.3.11 |
| 48 | netmask 255.255.255.0 |
| 49 | gateway 10.0.3.1 |
| 50 | dns-nameservers 10.0.3.1 |
| 51 | EOF" |
| 52 | |
| 53 | sudo lxc-start --name onos1 --daemon |
| 54 | |
| 55 | sudo lxc-ls --fancy |
| 56 | sleep 5 |
| 57 | sudo lxc-ls --fancy |
| 58 | sudo lxc-attach --name onos1 -- ip a |
| 59 | |
| 60 | sudo lxc-attach --name onos1 -- useradd -m sdn -s /bin/bash |
| 61 | sudo lxc-attach --name onos1 -- /bin/bash -c "echo sdn:rocks | chpasswd" |
| 62 | sudo lxc-attach --name onos1 -- /bin/bash -c "echo \"sdn ALL=(ALL) NOPASSWD:ALL\" > /etc/sudoers.d/sdn" |
| 63 | sudo lxc-attach --name onos1 -- oracle-java8-installer shared/accepted-oracle-license-v1-1 select true |
| 64 | sudo lxc-attach --name onos1 -- oracle-java8-installer shared/accepted-oracle-license-v1-1 seen true |
| 65 | sudo lxc-attach --name onos1 -- add-apt-repository -y ppa:webupd8team/java |
| 66 | sudo lxc-attach --name onos1 -- apt-get update |
| 67 | sudo lxc-attach --name onos1 -- apt-get install -y openssh-server oracle-java8-installer oracle-java8-set-default |
| 68 | |
| 69 | sudo mkdir -p /var/lib/lxc/onos1/rootfs/home/sdn/.ssh |
| 70 | sudo cp ~/.ssh/id_rsa.pub /var/lib/lxc/onos1/rootfs/home/sdn/.ssh/authorized_keys |
| 71 | sudo lxc-attach --name onos1 -- chown sdn:sdn /home/sdn/.ssh/authorized_keys |
| 72 | sudo lxc-attach --name onos1 -- chmod 600 /home/sdn/.ssh/authorized_keys |
| 73 | |
| 74 | sudo lxc-attach --name onos1 -- apt-get clean |
| 75 | |
| 76 | sudo lxc-stop --name onos1 |
| 77 | |
| 78 | # Clone the first node to create two more nodes |
| 79 | sudo lxc-clone onos1 onos2 |
| 80 | sudo sh -c "sed -i s/10.0.3.11/10.0.3.12/ /var/lib/lxc/onos2/rootfs/etc/network/interfaces" |
| 81 | |
| 82 | sudo lxc-clone onos1 onos3 |
| 83 | sudo sh -c "sed -i s/10.0.3.11/10.0.3.13/ /var/lib/lxc/onos3/rootfs/etc/network/interfaces" |
| 84 | |
| 85 | sudo lxc-start --name onos1 |
| 86 | sudo lxc-start --name onos2 |
| 87 | sudo lxc-start --name onos3 |
| 88 | |
| 89 | sleep 10 |
| 90 | |
| 91 | sudo lxc-ls --fancy |
| 92 | |
| 93 | echo "adding host keys to known_hosts" |
| 94 | # SSH to each once to add the host key to known_hosts |
| 95 | for onos in 10.0.3.11 10.0.3.12 10.0.3.13 |
| 96 | do |
| 97 | echo "sshing to $onos" |
| 98 | ssh -o "StrictHostKeyChecking no" sdn@${onos} ls |
| 99 | done |
| 100 | |
| 101 | |
| 102 | echo "Enabling non-root wireshark" |
| 103 | echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections |
| 104 | sudo dpkg-reconfigure -f noninteractive wireshark-common |
| 105 | |
| 106 | # Get the wireshark dissector handy |
| 107 | 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" |
| 108 | |
| 109 | # -------------- Install ONOS ---------------- |
| 110 | |
| 111 | echo "Installing ONOS" |
| 112 | |
| 113 | USER=mininet |
| 114 | USER_HOME=/home/${USER} |
| 115 | |
| 116 | cd ~ |
| 117 | |
| 118 | # Download a local karaf so we can use the bin directory |
| 119 | wget http://archive.apache.org/dist/karaf/3.0.5/apache-karaf-3.0.5.tar.gz |
| 120 | tar -xzf apache-karaf-3.0.5.tar.gz |
| 121 | |
| 122 | |
| 123 | git clone https://gerrit.onosproject.org/onos |
| 124 | cd onos && git checkout 1.6.0 && cd - |
| 125 | |
| 126 | mkdir -p ~/Downloads |
| 127 | |
| 128 | |
| 129 | echo "export ONOS_ROOT=${USER_HOME}/onos" >> ~/.bashrc |
| 130 | echo "export KARAF_ROOT=${USER_HOME}/apache-karaf-3.0.5" >> ~/.bashrc |
| 131 | echo ". ~/onos/tools/dev/bash_profile" >> ~/.bashrc |
| 132 | |
| 133 | export ONOS_ROOT=${USER_HOME}/onos |
| 134 | export KARAF_ROOT=${USER_HOME}/apache-karaf-3.0.5 |
| 135 | . ~/onos/tools/dev/bash_profile |
| 136 | |
| 137 | |
| 138 | echo $ONOS_ROOT |
| 139 | |
| 140 | cd $ONOS_ROOT && mvn clean install && mvn dependency:go-offline && cd - |
| 141 | |
| 142 | # Get the sample apps and build them for the right version |
| 143 | git clone https://gerrit.onosproject.org/onos-app-samples |
| 144 | cd onos-app-samples |
| 145 | git checkout 52da58b5991049025ce1b599c000357500b00aef |
| 146 | mvn versions:set -DnewVersion=1.2.1 versions:commit |
| 147 | mvn clean install |
| 148 | cd .. |
| 149 | |
| 150 | |
| 151 | cat << EOF >> onos/tools/test/cells/3node |
| 152 | export ONOS_NIC=10.0.3.* |
| 153 | export OC1="10.0.3.11" |
| 154 | export OC2="10.0.3.12" |
| 155 | export OC3="10.0.3.13" |
| 156 | export OCI="10.0.3.11" |
| 157 | export ONOS_APPS="drivers,openflow" |
| 158 | export ONOS_USER="sdn" |
| 159 | EOF |
| 160 | |
| 161 | cat << EOF >> onos/tools/test/cells/1node |
| 162 | export ONOS_NIC=10.0.3.* |
| 163 | export OC1="10.0.3.11" |
| 164 | export OCI="10.0.3.11" |
| 165 | export ONOS_APPS="drivers,openflow" |
| 166 | export ONOS_USER="sdn" |
| 167 | EOF |
| 168 | |
| 169 | cell 3node |
| 170 | |
| 171 | |
| 172 | onos-package |
| 173 | onos-group install -f |
| 174 | onos-wait-for-start $OC1 |
| 175 | onos-wait-for-start $OC2 |
| 176 | onos-wait-for-start $OC3 |
| 177 | |
| 178 | echo "ONOS install and startup complete" |
| 179 | |
| 180 | sleep 1 |
| 181 | onos-service --cell status |
| 182 | |
| 183 | # Prevent ONOS services from starting automatically |
| 184 | sudo sh -c "echo manual >> /var/lib/lxc/onos1/rootfs/etc/init/onos.override" |
| 185 | sudo sh -c "echo manual >> /var/lib/lxc/onos2/rootfs/etc/init/onos.override" |
| 186 | sudo sh -c "echo manual >> /var/lib/lxc/onos3/rootfs/etc/init/onos.override" |
| 187 | |
| 188 | # ------------- Create reset scripts ------------- |
| 189 | |
| 190 | cat << EOF >> ${USER_HOME}/reset-to-1.sh |
| 191 | #!/bin/bash |
| 192 | sudo rm -rf /tmp/* |
| 193 | export ONOS_ROOT=/home/mininet/onos |
| 194 | export M2_REPO=/home/mininet/.m2/repository |
| 195 | export KARAF_TAR=/home/mininet/apache-karaf-3.0.5.tar.gz |
| 196 | . ${ONOS_ROOT}/tools/dev/bash_profile |
| 197 | . ${ONOS_ROOT}/tools/build/envDefaults |
| 198 | |
| 199 | sudo mn -c |
| 200 | |
| 201 | cell 3node |
| 202 | onos-service --cell stop |
| 203 | cell 1node |
| 204 | |
| 205 | if [ -n "\$1" ]; then |
| 206 | export ONOS_APPS=\$ONOS_APPS,\$1 |
| 207 | fi |
| 208 | |
| 209 | onos-package |
| 210 | onos-install -f '$OC1' |
| 211 | EOF |
| 212 | |
| 213 | sudo chmod 777 ${USER_HOME}/reset-to-1.sh |
| 214 | |
| 215 | cat << EOF >> ${USER_HOME}/reset-to-3.sh |
| 216 | #!/bin/bash |
| 217 | sudo rm -rf /tmp/* |
| 218 | export ONOS_ROOT=/home/mininet/onos |
| 219 | export M2_REPO=/home/mininet/.m2/repository |
| 220 | export KARAF_TAR=/home/mininet/apache-karaf-3.0.5.tar.gz |
| 221 | . ${ONOS_ROOT}/tools/dev/bash_profile |
| 222 | . ${ONOS_ROOT}/tools/build/envDefaults |
| 223 | |
| 224 | sudo mn -c |
| 225 | |
| 226 | cell 3node |
| 227 | |
| 228 | if [ -n "\$1" ]; then |
| 229 | export ONOS_APPS=\$ONOS_APPS,\$1 |
| 230 | fi |
| 231 | |
| 232 | onos-service --cell stop |
| 233 | onos-package |
| 234 | onos-install -f '$OC1' |
| 235 | onos-install -f '$OC2' |
| 236 | onos-install -f '$OC3' |
| 237 | EOF |
| 238 | |
| 239 | sudo chmod 777 ${USER_HOME}/reset-to-3.sh |
| 240 | |
| 241 | sudo apt-get clean |
| 242 | sudo rm /etc/apt/apt.conf.d/02proxy |
| 243 | |
| 244 | # ------------- Set up each tutorial ------------- |
| 245 | |
| 246 | create_user tutorial1 "Basic ONOS Tutorial" |
| 247 | |
| 248 | URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.6;f=tutorial1-setup.sh' |
| 249 | wget -O tutorial1-setup.sh $URL |
| 250 | sudo -u tutorial1 -H sh -c 'cp tutorial1-setup.sh ~/ && cd ~/ && sh tutorial1-setup.sh' |
| 251 | |
| 252 | create_user sdnip "SDN-IP Tutorial" |
| 253 | |
| 254 | SDNIP_URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.6;f=sdnip-setup.sh' |
| 255 | wget -O sdnip-setup.sh $SDNIP_URL |
| 256 | sudo -u sdnip -H sh -c 'cp sdnip-setup.sh ~/ && cd ~/ && sh sdnip-setup.sh' |
| 257 | |
| 258 | create_user distributed "Distributed Tutorial" |
| 259 | |
| 260 | DIST_URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.6;f=dist-setup.sh' |
| 261 | wget -O dist-setup.sh $DIST_URL |
| 262 | sudo -u distributed -H sh -c 'cp dist-setup.sh ~/ && cd ~/ && sh dist-setup.sh' |
| 263 | |
| 264 | create_user optical "Optical Tutorial" |
| 265 | |
| 266 | OPT_URL='https://gerrit.onosproject.org/gitweb?p=onos-vm.git;a=blob_plain;hb=refs/heads/onos-tutorial-1.6;f=opt-setup.sh' |
| 267 | wget -O opt-setup.sh $OPT_URL |
| 268 | sudo -u optical -H sh -c 'cp opt-setup.sh ~/ && cd ~/ && sh opt-setup.sh' |
| 269 | |
| 270 | # ------------- Zero Unused Blocks ------------- |
| 271 | #TODO investigate zerofree |
| 272 | echo "Zeroing unused blocks" |
| 273 | sync |
| 274 | dd if=/dev/zero of=tmp-zeros |
| 275 | sync |
| 276 | rm tmp-zeros |
| 277 | sync |