* First draft of Ubuntu 20.04 Vagrantfile and scripts to install 2021-Mar version of open source P4 development tools. * Add more tracing output of what files have been installed at each step * Don't do behavioral-model install_deps.sh before installing PI This is an experiment to see if the end result will be able to run tutorials basic exercise using Python3 only on an Ubuntu 20.04 system. Just before this commit, `vagrant up` resulted in a system that failed to run the basic exercise, because python3 failed to import google.grpc (if I recall correctly -- it may have been a different google.<something> Python3 module name). * Add missing patch file * Fix copy and paste mistake * Add missing patch file * Change how protobuf Python3 module files are installed * Correct a few desktop icon file names, and add clean.sh script * Enhance clean.sh script, and add README for manual steps in creating a VM * Changes to try to always use Python3, never Python2, in tutorials * Update README steps for preparing a VM * More additions to README on steps to create a single file VM image * Add empty-disk-block zeroing to clean.sh script * Also install PTF * Update versions of P4 dev tool source code to 2021-Apr-05 This includes a change to p4lang/PI that allows P4Runtime API clients to send the shortest byte sequences necessary to encode integer values, which I want for a PTF test that I have recently created. * Update README for 2021-Apr-05 version of VM image * Resolve Python 3 compatibility issues Most of the Python 2 to 3 code translation changes were automated with the 2to3 tool. Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org> * Update commit SHAs for 4 p4lang repos to latest as of 2021-May-04 * Update Ubuntu 20.04 README.md for how I created 2021-May-04 version of VM * mycontroller: Use Python 3 shebang line Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org> * Update Ubuntu 20.04 README.md for how I created 2021-Jun-01 version of VM * Update commit SHAs for 4 p4lang repos to latest as of 2021-Jul-07 * Update Ubuntu 20.04 README.md for how I created 2021-Jul-07 version of VM * Update commit SHAs for 4 p4lang repos to latest as of 2021-Aug-01 * Update Ubuntu 20.04 README.md for how I created 2021-Aug-01 version of VM * Update commit SHAs for 4 p4lang repos to latest as of 2021-Sep-07 * Update Ubuntu 20.04 README.md for how I created 2021-Sep-07 version of VM Co-authored-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
308 lines
9.5 KiB
Bash
Executable File
308 lines
9.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Print script commands and exit on errors.
|
|
set -xe
|
|
|
|
#Src
|
|
BMV2_COMMIT="b0fb01ecacbf3a7d7f0c01e2f149b0c6a957f779" # 2021-Sep-07
|
|
PI_COMMIT="a5fd855d4b3293e23816ef6154e83dc6621aed6a" # 2021-Sep-07
|
|
P4C_COMMIT="149634bbe4842fb7c1e80d1b7c9d1e0ec91b0051" # 2021-Sep-07
|
|
PTF_COMMIT="8f260571036b2684f16366962edd0193ef61e9eb" # 2021-Sep-07
|
|
PROTOBUF_COMMIT="v3.6.1"
|
|
GRPC_COMMIT="tags/v1.17.2"
|
|
|
|
#Get the number of cores to speed up the compilation process
|
|
NUM_CORES=`grep -c ^processor /proc/cpuinfo`
|
|
|
|
|
|
# The install steps for p4lang/PI and p4lang/behavioral-model end
|
|
# up installing Python module code in the site-packages directory
|
|
# mentioned below in this function. That is were GNU autoconf's
|
|
# 'configure' script seems to find as the place to put them.
|
|
|
|
# On Ubuntu systems when you run the versions of Python that are
|
|
# installed via Debian/Ubuntu packages, they only look in a
|
|
# sibling dist-packages directory, never the site-packages one.
|
|
|
|
# If I could find a way to change the part of the install script
|
|
# so that p4lang/PI and p4lang/behavioral-model install their
|
|
# Python modules in the dist-packages directory, that sounds
|
|
# useful, but I have not found a way.
|
|
|
|
# As a workaround, after finishing the part of the install script
|
|
# for those packages, I will invoke this function to move them all
|
|
# into the dist-packages directory.
|
|
|
|
# Some articles with questions and answers related to this.
|
|
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=765022
|
|
# https://bugs.launchpad.net/ubuntu/+source/automake/+bug/1250877
|
|
# https://unix.stackexchange.com/questions/351394/makefile-installing-python-module-out-of-of-pythonpath
|
|
|
|
PY3LOCALPATH=`${HOME}/py3localpath.py`
|
|
|
|
move_usr_local_lib_python3_from_site_packages_to_dist_packages() {
|
|
local SRC_DIR
|
|
local DST_DIR
|
|
local j
|
|
local k
|
|
|
|
SRC_DIR="${PY3LOCALPATH}/site-packages"
|
|
DST_DIR="${PY3LOCALPATH}/dist-packages"
|
|
|
|
# When I tested this script on Ubunt 16.04, there was no
|
|
# site-packages directory. Return without doing anything else if
|
|
# this is the case.
|
|
if [ ! -d ${SRC_DIR} ]
|
|
then
|
|
return 0
|
|
fi
|
|
|
|
# Do not move any __pycache__ directory that might be present.
|
|
sudo rm -fr ${SRC_DIR}/__pycache__
|
|
|
|
echo "Source dir contents before moving: ${SRC_DIR}"
|
|
ls -lrt ${SRC_DIR}
|
|
echo "Dest dir contents before moving: ${DST_DIR}"
|
|
ls -lrt ${DST_DIR}
|
|
for j in ${SRC_DIR}/*
|
|
do
|
|
echo $j
|
|
k=`basename $j`
|
|
# At least sometimes (perhaps always?) there is a directory
|
|
# 'p4' or 'google' in both the surce and dest directory. I
|
|
# think I want to merge their contents. List them both so I
|
|
# can see in the log what was in both at the time:
|
|
if [ -d ${SRC_DIR}/$k -a -d ${DST_DIR}/$k ]
|
|
then
|
|
echo "Both source and dest dir contain a directory: $k"
|
|
echo "Source dir $k directory contents:"
|
|
ls -l ${SRC_DIR}/$k
|
|
echo "Dest dir $k directory contents:"
|
|
ls -l ${DST_DIR}/$k
|
|
sudo mv ${SRC_DIR}/$k/* ${DST_DIR}/$k/
|
|
sudo rmdir ${SRC_DIR}/$k
|
|
else
|
|
echo "Not a conflicting directory: $k"
|
|
sudo mv ${SRC_DIR}/$k ${DST_DIR}/$k
|
|
fi
|
|
done
|
|
|
|
echo "Source dir contents after moving: ${SRC_DIR}"
|
|
ls -lrt ${SRC_DIR}
|
|
echo "Dest dir contents after moving: ${DST_DIR}"
|
|
ls -lrt ${DST_DIR}
|
|
}
|
|
|
|
find /usr/lib /usr/local $HOME/.local | sort > $HOME/usr-local-1-before-protobuf.txt
|
|
|
|
# --- Protobuf --- #
|
|
git clone https://github.com/google/protobuf.git
|
|
cd protobuf
|
|
git checkout ${PROTOBUF_COMMIT}
|
|
./autogen.sh
|
|
# install-p4dev-v4.sh script doesn't have --prefix=/usr option here.
|
|
./configure --prefix=/usr
|
|
make -j${NUM_CORES}
|
|
sudo make install
|
|
sudo ldconfig
|
|
# Force install python module
|
|
#cd python
|
|
#sudo python3 setup.py install
|
|
#cd ../..
|
|
cd ..
|
|
|
|
find /usr/lib /usr/local $HOME/.local | sort > $HOME/usr-local-2-after-protobuf.txt
|
|
|
|
# --- gRPC --- #
|
|
git clone https://github.com/grpc/grpc.git
|
|
cd grpc
|
|
git checkout ${GRPC_COMMIT}
|
|
git submodule update --init --recursive
|
|
# Apply patch that seems to be necessary in order for grpc v1.17.2 to
|
|
# compile and install successfully on an Ubuntu 19.10 and later
|
|
# system.
|
|
PATCH_DIR="${HOME}/patches"
|
|
patch -p1 < "${PATCH_DIR}/disable-Wno-error-and-other-small-changes.diff" || echo "Errors while attempting to patch grpc, but continuing anyway ..."
|
|
make -j${NUM_CORES}
|
|
sudo make install
|
|
# I believe the following 2 commands, adapted from similar commands in
|
|
# src/python/grpcio/README.rst, should install the Python3 module
|
|
# grpc.
|
|
find /usr/lib /usr/local $HOME/.local | sort > $HOME/usr-local-2b-before-grpc-pip3.txt
|
|
pip3 list | tee $HOME/pip3-list-2b-before-grpc-pip3.txt
|
|
sudo pip3 install -rrequirements.txt
|
|
GRPC_PYTHON_BUILD_WITH_CYTHON=1 sudo pip3 install .
|
|
sudo ldconfig
|
|
cd ..
|
|
|
|
find /usr/lib /usr/local $HOME/.local | sort > $HOME/usr-local-3-after-grpc.txt
|
|
|
|
# Note: This is a noticeable difference between how an earlier
|
|
# user-bootstrap.sh version worked, where it effectively ran
|
|
# behavioral-model's install_deps.sh script, then installed PI, then
|
|
# went back and compiled the behavioral-model code. Building PI code
|
|
# first, without first running behavioral-model's install_deps.sh
|
|
# script, might result in less PI project features being compiled into
|
|
# its binaries.
|
|
|
|
# --- PI/P4Runtime --- #
|
|
git clone https://github.com/p4lang/PI.git
|
|
cd PI
|
|
git checkout ${PI_COMMIT}
|
|
git submodule update --init --recursive
|
|
./autogen.sh
|
|
# install-p4dev-v4.sh adds more --without-* options to the configure
|
|
# script here. I suppose without those, this script will cause
|
|
# building PI code to include more features?
|
|
./configure --with-proto
|
|
make -j${NUM_CORES}
|
|
sudo make install
|
|
# install-p4dev-v4.sh at this point does these things, which might be
|
|
# useful in this script, too:
|
|
# Save about 0.25G of storage by cleaning up PI build
|
|
make clean
|
|
move_usr_local_lib_python3_from_site_packages_to_dist_packages
|
|
sudo ldconfig
|
|
cd ..
|
|
|
|
find /usr/lib /usr/local $HOME/.local | sort > $HOME/usr-local-4-after-PI.txt
|
|
|
|
# --- Bmv2 --- #
|
|
git clone https://github.com/p4lang/behavioral-model.git
|
|
cd behavioral-model
|
|
git checkout ${BMV2_COMMIT}
|
|
PATCH_DIR="${HOME}/patches"
|
|
patch -p1 < "${PATCH_DIR}/behavioral-model-use-correct-libssl-pkg.patch" || echo "Errors while attempting to patch behavioral-model, but continuing anyway ..."
|
|
./install_deps.sh
|
|
./autogen.sh
|
|
./configure --enable-debugger --with-pi
|
|
make -j${NUM_CORES}
|
|
sudo make install
|
|
sudo ldconfig
|
|
# Simple_switch_grpc target
|
|
cd targets/simple_switch_grpc
|
|
./autogen.sh
|
|
./configure --with-thrift
|
|
make -j${NUM_CORES}
|
|
sudo make install
|
|
sudo ldconfig
|
|
# install-p4dev-v4.sh script does this here:
|
|
move_usr_local_lib_python3_from_site_packages_to_dist_packages
|
|
cd ../../..
|
|
|
|
find /usr/lib /usr/local $HOME/.local | sort > $HOME/usr-local-5-after-behavioral-model.txt
|
|
|
|
# --- P4C --- #
|
|
git clone https://github.com/p4lang/p4c
|
|
cd p4c
|
|
git checkout ${P4C_COMMIT}
|
|
git submodule update --init --recursive
|
|
mkdir -p build
|
|
cd build
|
|
cmake ..
|
|
# The command 'make -j${NUM_CORES}' works fine for the others, but
|
|
# with 2 GB of RAM for the VM, there are parts of the p4c build where
|
|
# running 2 simultaneous C++ compiler runs requires more than that
|
|
# much memory. Things work better by running at most one C++ compilation
|
|
# process at a time.
|
|
make -j1
|
|
sudo make install
|
|
sudo ldconfig
|
|
cd ../..
|
|
|
|
find /usr/lib /usr/local $HOME/.local | sort > $HOME/usr-local-6-after-p4c.txt
|
|
|
|
# --- Mininet --- #
|
|
git clone git://github.com/mininet/mininet mininet
|
|
cd mininet
|
|
PATCH_DIR="${HOME}/patches"
|
|
patch -p1 < "${PATCH_DIR}/mininet-dont-install-python2.patch" || echo "Errors while attempting to patch mininet, but continuing anyway ..."
|
|
cd ..
|
|
# TBD: Try without installing openvswitch, i.e. no '-v' option, to see
|
|
# if everything still works well without it.
|
|
sudo ./mininet/util/install.sh -nw
|
|
|
|
find /usr/lib /usr/local $HOME/.local | sort > $HOME/usr-local-7-after-mininet-install.txt
|
|
|
|
# --- PTF --- #
|
|
git clone git://github.com/p4lang/ptf
|
|
cd ptf
|
|
git checkout ${PTF_COMMIT}
|
|
sudo python3 setup.py install
|
|
cd ..
|
|
|
|
find /usr/lib /usr/local $HOME/.local | sort > $HOME/usr-local-8-after-ptf-install.txt
|
|
|
|
# --- Tutorials --- #
|
|
git clone https://github.com/p4lang/tutorials
|
|
sudo mv tutorials /home/p4
|
|
sudo chown -R p4:p4 /home/p4/tutorials
|
|
|
|
# --- Emacs --- #
|
|
sudo cp p4_16-mode.el /usr/share/emacs/site-lisp/
|
|
sudo mkdir /home/p4/.emacs.d/
|
|
echo "(autoload 'p4_16-mode' \"p4_16-mode.el\" \"P4 Syntax.\" t)" > init.el
|
|
echo "(add-to-list 'auto-mode-alist '(\"\\.p4\\'\" . p4_16-mode))" | tee -a init.el
|
|
sudo mv init.el /home/p4/.emacs.d/
|
|
sudo ln -s /usr/share/emacs/site-lisp/p4_16-mode.el /home/p4/.emacs.d/p4_16-mode.el
|
|
sudo chown -R p4:p4 /home/p4/.emacs.d/
|
|
|
|
# --- Vim --- #
|
|
cd ~
|
|
mkdir .vim
|
|
cd .vim
|
|
mkdir ftdetect
|
|
mkdir syntax
|
|
echo "au BufRead,BufNewFile *.p4 set filetype=p4" >> ftdetect/p4.vim
|
|
echo "set bg=dark" >> ~/.vimrc
|
|
sudo mv ~/.vimrc /home/p4/.vimrc
|
|
cp ~/p4.vim syntax/p4.vim
|
|
cd ~
|
|
sudo mv .vim /home/p4/.vim
|
|
sudo chown -R p4:p4 /home/p4/.vim
|
|
sudo chown p4:p4 /home/p4/.vimrc
|
|
|
|
# --- Adding Desktop icons --- #
|
|
DESKTOP=/home/${USER}/Desktop
|
|
mkdir -p ${DESKTOP}
|
|
|
|
cat > ${DESKTOP}/Terminal.desktop << EOF
|
|
[Desktop Entry]
|
|
Encoding=UTF-8
|
|
Type=Application
|
|
Name=Terminal
|
|
Name[en_US]=Terminal
|
|
Icon=konsole
|
|
Exec=/usr/bin/x-terminal-emulator
|
|
Comment[en_US]=
|
|
EOF
|
|
|
|
cat > ${DESKTOP}/Wireshark.desktop << EOF
|
|
[Desktop Entry]
|
|
Encoding=UTF-8
|
|
Type=Application
|
|
Name=Wireshark
|
|
Name[en_US]=Wireshark
|
|
Icon=wireshark
|
|
Exec=/usr/bin/wireshark
|
|
Comment[en_US]=
|
|
EOF
|
|
|
|
cat > ${DESKTOP}/Sublime\ Text.desktop << EOF
|
|
[Desktop Entry]
|
|
Encoding=UTF-8
|
|
Type=Application
|
|
Name=Sublime Text
|
|
Name[en_US]=Sublime Text
|
|
Icon=sublime-text
|
|
Exec=/opt/sublime_text/sublime_text
|
|
Comment[en_US]=
|
|
EOF
|
|
|
|
sudo mkdir -p /home/p4/Desktop
|
|
sudo mv /home/${USER}/Desktop/* /home/p4/Desktop
|
|
sudo chown -R p4:p4 /home/p4/Desktop/
|
|
|
|
# Do this last!
|
|
sudo reboot
|