Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bca12ef
Add install script for Avenir specifically for Ubuntu 20.04
jafingerhut Oct 18, 2022
af0d9f2
Update steps
jafingerhut Oct 18, 2022
958793a
Add 'set -x' for tracing of commands mingled with output
jafingerhut Oct 18, 2022
1f90d06
Try adding another eval $(opam env) command
jafingerhut Oct 18, 2022
55a1314
Attempt to use cstruct version 6.0.0 before pinning petr4
jafingerhut Oct 18, 2022
6e14597
Updates to install script that get it further towards completion
jafingerhut Oct 18, 2022
89ba261
Add some checks for min RAM & disk space available, and supported OS …
jafingerhut Oct 18, 2022
66dcd5c
Reduce the check for required disk space to 5 GB
jafingerhut Oct 18, 2022
93e20c6
Correct Ubuntu package name in install script
jafingerhut Oct 19, 2022
a3f6c38
Some corrections to install steps in README.md
jafingerhut Oct 19, 2022
bf1888c
Correction to a sample command in README for hello example
jafingerhut Oct 19, 2022
f4a7d82
Move and rename install script
jafingerhut Oct 19, 2022
86fb0ff
Delete old named install script
jafingerhut Oct 19, 2022
fac7e6f
Change the install script to use the copy of the repo that it is within
jafingerhut Oct 19, 2022
9a824f5
Mention the ubuntu-install.sh script in the README
jafingerhut Oct 19, 2022
9f85c8b
Update disk space required
jafingerhut Oct 19, 2022
93ba0fb
Attempt to make the instructions clearer
jafingerhut Oct 19, 2022
b3fe94b
Add debug for when output of 'opam env' changes
jafingerhut Oct 19, 2022
b912c98
Put all opam env debug output files in the same directory
jafingerhut Oct 19, 2022
536a8c4
Merge branch 'master' into add-install-script
jafingerhut Oct 19, 2022
3fef24a
Force location of _opam directory relative to avenir directory in ins…
jafingerhut Oct 19, 2022
55247fe
Simplify README description of install script
jafingerhut Oct 19, 2022
c5df50f
Change version of z3 installed by script from 4.8.10 to 4.8.8
jafingerhut Oct 20, 2022
a694f52
Add 'sudo ldconfig' just before make
jafingerhut Oct 20, 2022
1f5c349
Add g++ package installation
jafingerhut Oct 20, 2022
390ddbf
Now tested successfully with Ubuntu 20.04 and 22.04
jafingerhut Oct 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 208 additions & 0 deletions scripts/ubuntu-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
#! /bin/bash

THIS_SCRIPT_FILE_MAYBE_RELATIVE="$0"
THIS_SCRIPT_DIR_MAYBE_RELATIVE="${THIS_SCRIPT_FILE_MAYBE_RELATIVE%/*}"
THIS_SCRIPT_DIR_ABSOLUTE=`readlink -f "${THIS_SCRIPT_DIR_MAYBE_RELATIVE}"`

# Install the new directories as siblings of the avenir repo directory.
# I believe that the _opam directory created during installation must be
# in a directory that is somewhere above the avenir/synthesis directory,
# otherwise Ocaml builds will use the ~/.opam directory contents, which
# are not the desired version of the OCaml compiler.
cd ${THIS_SCRIPT_DIR_ABSOLUTE}/../..
INSTALL_DIR="${PWD}"

OPAMENV="${INSTALL_DIR}/avenir-install-details"
mkdir -p ${OPAMENV}

ubuntu_version_warning() {
1>&2 echo "This script has only been tested on these systems:"
1>&2 echo " Ubuntu 18.04"
1>&2 echo " Ubuntu 20.04"
1>&2 echo " Ubuntu 22.04"
1>&2 echo ""
1>&2 echo "Proceed installing manually at your own risk of"
1>&2 echo "significant time spent figuring out how to make it all"
1>&2 echo "work, or consider getting VirtualBox and creating an"
1>&2 echo "Ubuntu virtual machine with one of the tested versions."
}

abort_script=0

lsb_release >& /dev/null
if [ $? != 0 ]
then
1>&2 echo "No 'lsb_release' found in your command path."
ubuntu_version_warning
exit 1
fi

distributor_id=`lsb_release -si`
ubuntu_release=`lsb_release -s -r`
if [ "${distributor_id}" = "Ubuntu" -a \( "${ubuntu_release}" = "18.04" -o "${ubuntu_release}" = "20.04" -o "${ubuntu_release}" = "22.04" \) ]
then
echo "Found distributor '${distributor_id}' release '${ubuntu_release}'. Continuing with installation."
else
ubuntu_version_warning
1>&2 echo ""
1>&2 echo "Here is what command 'lsb_release -a' shows this OS to be:"
lsb_release -a
exit 1
fi

# Minimum required system memory is 2 GBytes, minus a few MBytes
# because from experiments I have run on several different Ubuntu
# Linux VMs, when you configure them with 2 Gbytes of RAM, the first
# line of /proc/meminfo shows a little less than that available, I
# believe because some memory occupied by the kernel is not shown.

min_mem_MBytes=`expr 2 \* \( 1024 - 64 \)`
memtotal_KBytes=`head -n 1 /proc/meminfo | awk '{print $2;}'`
memtotal_MBytes=`expr ${memtotal_KBytes} / 1024`

if [ "${memtotal_MBytes}" -lt "${min_mem_MBytes}" ]
then
memtotal_comment="too low"
abort_script=1
else
memtotal_comment="enough"
fi

echo "Minimum recommended memory to run this script: ${min_mem_MBytes} MBytes"
echo "Memory on this system from /proc/meminfo: ${memtotal_MBytes} MBytes -> $memtotal_comment"

min_free_disk_MBytes=`expr 8 \* 1024`
free_disk_MBytes=`df --output=avail --block-size=1M . | tail -n 1`

if [ "${free_disk_MBytes}" -lt "${min_free_disk_MBytes}" ]
then
free_disk_comment="too low"
abort_script=1
else
free_disk_comment="enough"
fi

echo "Minimum free disk space to run this script: ${min_free_disk_MBytes} MBytes"
echo "Free disk space on this system from df output: ${free_disk_MBytes} MBytes -> $free_disk_comment"

if [ "${abort_script}" == 1 ]
then
echo ""
echo "Aborting script because system has too little RAM or free disk space"
exit 1
fi

Z3_DIR_NAME="z3-4.8.8-x64-ubuntu-16.04"

1>&2 echo ""
1>&2 echo "Install directory: ${INSTALL_DIR}"
1>&2 echo ""
1>&2 echo "Inside that directory, this script will create new directories"
1>&2 echo "with these names:"
1>&2 echo " _opam"
1>&2 echo " petr4"
1>&2 echo " ${Z3_DIR_NAME}"

if [ -e "_opam" -o -e "peter4" -o -e ${Z3_DIR_NAME} ]
then
1>&2 echo ""
1>&2 echo "One or more files with those names already exist."
1>&2 echo "Remove or rename them, then try this script again."
exit 1
fi

echo "------------------------------------------------------------"
echo "Time and disk space used before installation begins:"
set -x
date
df -h .
df -BM .

# This section for installing opam is based on instructions found
# here: https://opam.ocaml.org/doc/Install.html

sudo add-apt-repository --yes ppa:avsm/ppa
sudo apt update
sudo apt-get install --yes opam
opam --version

# As of 2022-Oct-16 when I last ran this on Ubuntu 18.04 and 20.04
# systems, the commands above installed opam version 2.1.0

opam --yes init
opam env --switch=default > ${OPAMENV}/opam-env-1.txt
eval $(opam env --switch=default)
opam --yes switch create . ocaml-base-compiler.4.09.0
opam env > ${OPAMENV}/opam-env-2.txt
eval $(opam env)
sudo apt-get install --yes m4
opam --yes install merlin dune utop core ocamlformat
opam env > ${OPAMENV}/opam-env-3.txt
eval $(opam env)
opam --yes user-setup install
sudo apt-get install --yes bubblewrap
opam --yes install menhir

# I tried 'sudo apt-get install z3' on Ubuntu 20.04 on 2022-Oct-16,
# but it install version 4.8.7 according to the output of `z3
# --version`, which is older than the version 4.8.8 recommended by the
# Avenir README.

# Instead, install a pre-built version of z3 4.8.8 as distributed by
# the Z3 developers.

# Download Z3 zip file
wget https://github.com/Z3Prover/z3/releases/download/z3-4.8.8/z3-4.8.8-x64-ubuntu-16.04.zip
# unzip it
unzip -e z3-4.8.8-x64-ubuntu-16.04.zip
# create a link from /usr/bin/z3 to where it is installed
Z3_INSTALL_DIR="${INSTALL_DIR}/z3-4.8.8-x64-ubuntu-16.04"
sudo ln ${Z3_INSTALL_DIR}/bin/z3 /usr/bin/z3

sudo apt-get install --yes libgmp-dev
opam --yes pin add z3 https://github.com/priyasrikumar/ocaml-z3.git

# Install recommended version of petr4
cd ${INSTALL_DIR}
git clone https://github.com/cornell-netlab/petr4
cd petr4
git checkout cd556c1e2c20ccbd5b959f385cecebc43f5cfd72
PETR4_INSTALL_DIR=`pwd`

cd ${THIS_SCRIPT_DIR_ABSOLUTE}/../synthesis
opam --yes install p4pp=0.1.4
opam env > ${OPAMENV}/opam-env-4.txt
eval $(opam env)
opam --yes pin add cstruct 6.0.0
opam env > ${OPAMENV}/opam-env-5.txt
eval $(opam env)
opam --yes pin add petr4 ${PETR4_INSTALL_DIR}
opam env > ${OPAMENV}/opam-env-6.txt
eval $(opam env)

# I got the following error message attempting the next command:
# dune external-lib-deps: This subcommand is no longer implemented.

# This error occured whiel running dune version 3.4.1. Apparently
# this 'extern-lib-deps' sub-command was removed in some version of
# dune since the Avenir install instructions were written, so skip
# this command.
# dune external-lib-deps --missing @all

# These should be the packages that need to be installed, according to
# the Avenir developers.
sudo apt-get install --yes pkg-config g++
opam --yes install async cohttp-async ipaddr shell
opam env > ${OPAMENV}/opam-env-7.txt
eval $(opam env)
sudo ldconfig

make

set +x
echo "------------------------------------------------------------"
echo "Time and disk space used when installation was complete:"
set -x
date
df -h .
df -BM .
18 changes: 9 additions & 9 deletions synthesis/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Getting Started

If you wish to automate these install steps on a freshly installed Ubuntu 18.04 or 20.04 system, run the script `avenir/scripts/ubuntu-install.sh`. After the install script completes, you may then skip down to the section [Verification](#verification).

+ First, [install](https://opam.ocaml.org/doc/Install.html) OPAM version >2.0.4. If you already have OPAM >2.0.4 installed you can skip this step. If you have an earlier version of OPAM, upgrade it.

+ In the `synthesis` directory, run
Expand Down Expand Up @@ -27,7 +29,7 @@ opam user-setup install
+ Install Menhir

```bash
apt install bubblewrap
sudo apt-get install bubblewrap
opam install menhir
```

Expand All @@ -48,25 +50,23 @@ opam pin add z3 https://github.com/priyasrikumar/ocaml-z3.git
cd <petr4 fp>
git checkout cd556c1e2c20ccbd5b959f385cecebc43f5cfd72
```
Then change back to the `hybrid/synthesis` directory. Install the version of the p4 preprocessor `p4pp` that works with this specific commit:
Then change back to the `avenir/synthesis` directory. Install the version of the p4 preprocessor `p4pp` that works with this specific commit:
``` bash
opam install p4pp=0.1.4
opam pin add cstruct 6.0.0
```
Then, pin the petr4 package to the local state.
```
opam pin add petr4 <petr4 fp>
```

+ Install any remaining dependencies (e.g. `async`) using `opam install` (e.g.
`opam install async`) that show up when you run the following command:
+ Install the remaining dependencies with the commands below:

```
dune external-lib-deps --missing @all
sudo apt-get install pkg-config
opam install async cohttp-async ipaddr shell
```

The list of packages should be `async cohttp-async ipaddr shell`. If `z3`,
`petr4`, or `p4pp` show up here, repeat the previous steps untill they no longer appear when you run this command. If `menhir` appears in this list even when `opam` declares that it has been correctly installed, you may proceed.

+ Run `make` to verify that `avenir` builds.

+ The makefile is currently a bit wonky, so for subsequent compilations, you may need to run `make rebuild` instead of `make build`.
Expand Down Expand Up @@ -136,7 +136,7 @@ the retargeting experiment and the BMV2 simple-switch demonstration.

## Prerequisite software

The following packaged are required to run these evaluations:
The following packages are required to run these evaluations:
- python2.7
- python-tk (via `apt`)
- matplotlib (via `pip`)
Expand Down