Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Builds and installs all tools needed for developing and testing P4 support in |
| 4 | # ONOS. |
| 5 | # |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 6 | # Tested on Ubuntu 14.04 and 16.04. |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 7 | # |
| 8 | # Recommended minimum system requirements: |
| 9 | # 4 GB of RAM |
| 10 | # 2 cores |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 11 | # 8 GB free hard drive space (~4 GB to build everything) |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 12 | # ----------------------------------------------------------------------------- |
| 13 | |
| 14 | # Exit on errors. |
| 15 | set -e |
| 16 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 17 | BUILD_DIR=~/p4tools |
Andrea Campanella | 8bcd586 | 2017-12-11 11:34:45 +0100 | [diff] [blame] | 18 | BMV2_COMMIT="d930fa2818d8ed71f3bf36eaf3f3687d9b68184f" |
| 19 | PI_COMMIT="13d611a9c655938676ebcde2bd5653b461f46ca7" |
Carmelo Cascone | 65cd9e3 | 2018-01-09 16:45:20 -0400 | [diff] [blame^] | 20 | P4C_COMMIT="cb8f118ed2861986cd20a3e34f18ee7ae3862233" |
Andrea Campanella | 8bcd586 | 2017-12-11 11:34:45 +0100 | [diff] [blame] | 21 | PROTOBUF_COMMIT="tags/v3.2.0" |
Carmelo Cascone | b1936bd | 2017-12-12 14:42:27 -0800 | [diff] [blame] | 22 | GRPC_COMMIT="tags/v1.3.2" |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 23 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 24 | NUM_CORES=`grep -c ^processor /proc/cpuinfo` |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 25 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 26 | function do_requirements { |
| 27 | sudo apt update |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 28 | sudo apt-get install -y --no-install-recommends \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 29 | autoconf \ |
| 30 | automake \ |
| 31 | bison \ |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 32 | build-essential \ |
| 33 | cmake \ |
| 34 | cpp \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 35 | curl \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 36 | flex \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 37 | git \ |
| 38 | libboost-dev \ |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 39 | libboost-program-options-dev \ |
| 40 | libboost-system-dev \ |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 41 | libboost-filesystem-dev \ |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 42 | libboost-thread-dev \ |
| 43 | libboost-filesystem-dev \ |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 44 | libboost-program-options-dev \ |
| 45 | libboost-system-dev \ |
| 46 | libboost-test-dev \ |
| 47 | libboost-thread-dev \ |
| 48 | libc6-dev \ |
| 49 | libevent-dev \ |
| 50 | libffi-dev \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 51 | libfl-dev \ |
| 52 | libgc-dev \ |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 53 | libgc1c2 \ |
| 54 | libgflags-dev \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 55 | libgmp-dev \ |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 56 | libjudy-dev \ |
| 57 | libpcap-dev \ |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 58 | libgmp10 \ |
| 59 | libgmpxx4ldbl \ |
| 60 | libjudy-dev \ |
| 61 | libpcap-dev \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 62 | libreadline6 \ |
| 63 | libreadline6-dev \ |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 64 | libssl-dev \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 65 | libtool \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 66 | make \ |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 67 | mktemp \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 68 | pkg-config \ |
| 69 | python \ |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 70 | python-dev \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 71 | python-ipaddr \ |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 72 | python-pip \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 73 | python-scapy \ |
Carmelo Cascone | ee09071 | 2017-12-14 23:01:03 -0800 | [diff] [blame] | 74 | python-setuptools \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 75 | tcpdump \ |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 76 | wget \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 77 | unzip |
Carmelo Cascone | 87ac737 | 2017-09-15 01:58:59 +0200 | [diff] [blame] | 78 | |
| 79 | sudo pip install setuptools cffi |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | function do_requirements_1404 { |
| 83 | sudo apt install -y python-software-properties software-properties-common |
| 84 | sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test |
Carmelo Cascone | 6e4f7eb | 2017-08-21 23:00:43 +0200 | [diff] [blame] | 85 | sudo add-apt-repository -y ppa:george-edison55/cmake-3.x |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 86 | sudo apt update |
| 87 | sudo apt install -y \ |
Carmelo Cascone | 6e4f7eb | 2017-08-21 23:00:43 +0200 | [diff] [blame] | 88 | cmake \ |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 89 | dpkg-dev \ |
| 90 | g++-4.9 \ |
| 91 | gcc-4.9 \ |
| 92 | libboost-iostreams-dev |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 93 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 94 | # Needed for p4c. |
| 95 | sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 50 |
| 96 | sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 50 |
| 97 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 98 | |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 99 | function do_requirements_1604 { |
| 100 | sudo apt-get update |
| 101 | sudo apt-get install -y --no-install-recommends \ |
| 102 | ca-certificates \ |
Carmelo Cascone | 6e4f7eb | 2017-08-21 23:00:43 +0200 | [diff] [blame] | 103 | cmake \ |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 104 | g++ \ |
| 105 | libboost-iostreams1.58-dev |
| 106 | } |
| 107 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 108 | function do_protobuf { |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 109 | cd ${BUILD_DIR} |
| 110 | if [ ! -d protobuf ]; then |
| 111 | git clone https://github.com/google/protobuf.git |
| 112 | fi |
| 113 | cd protobuf |
| 114 | git fetch |
| 115 | git checkout ${PROTOBUF_COMMIT} |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 116 | |
| 117 | export CFLAGS="-Os" |
| 118 | export CXXFLAGS="-Os" |
| 119 | export LDFLAGS="-Wl,-s" |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 120 | ./autogen.sh |
| 121 | ./configure --prefix=/usr |
| 122 | make -j${NUM_CORES} |
| 123 | sudo make install |
| 124 | sudo ldconfig |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 125 | unset CFLAGS CXXFLAGS LDFLAGS |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 126 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 127 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 128 | function do_grpc { |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 129 | cd ${BUILD_DIR} |
| 130 | if [ ! -d grpc ]; then |
| 131 | git clone https://github.com/grpc/grpc.git |
| 132 | fi |
| 133 | cd grpc |
| 134 | git fetch |
| 135 | git checkout ${GRPC_COMMIT} |
| 136 | git submodule update --init |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 137 | |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 138 | export LDFLAGS="-Wl,-s" |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 139 | make -j${NUM_CORES} |
| 140 | sudo make install |
| 141 | sudo ldconfig |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 142 | unset LDFLAGS |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 143 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 144 | |
Carmelo Cascone | 87ac737 | 2017-09-15 01:58:59 +0200 | [diff] [blame] | 145 | function checkout_bmv2 { |
| 146 | cd ${BUILD_DIR} |
| 147 | if [ ! -d bmv2 ]; then |
| 148 | git clone https://github.com/p4lang/behavioral-model.git bmv2 |
| 149 | fi |
| 150 | cd bmv2 |
| 151 | git fetch |
| 152 | git checkout ${BMV2_COMMIT} |
| 153 | } |
| 154 | |
| 155 | function do_pi_bmv2_deps { |
| 156 | checkout_bmv2 |
| 157 | # From bmv2's install_deps.sh. |
| 158 | # Nanomsg is required also by p4runtime. |
| 159 | tmpdir=`mktemp -d -p .` |
| 160 | cd ${tmpdir} |
| 161 | bash ../travis/install-thrift.sh |
| 162 | bash ../travis/install-nanomsg.sh |
| 163 | sudo ldconfig |
| 164 | bash ../travis/install-nnpy.sh |
| 165 | cd .. |
| 166 | sudo rm -rf $tmpdir |
| 167 | } |
| 168 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 169 | function do_p4runtime { |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 170 | cd ${BUILD_DIR} |
| 171 | if [ ! -d p4runtime ]; then |
| 172 | git clone https://github.com/p4lang/PI.git p4runtime |
| 173 | fi |
| 174 | cd p4runtime |
| 175 | git fetch |
| 176 | git checkout ${PI_COMMIT} |
| 177 | git submodule update --init --recursive |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 178 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 179 | ./autogen.sh |
Carmelo Cascone | 28f3778 | 2017-08-29 20:11:21 +0200 | [diff] [blame] | 180 | ./configure --with-proto 'CXXFLAGS=-O0 -g' |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 181 | make -j${NUM_CORES} |
| 182 | sudo make install |
| 183 | sudo ldconfig |
| 184 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 185 | |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 186 | function do_bmv2 { |
Carmelo Cascone | 87ac737 | 2017-09-15 01:58:59 +0200 | [diff] [blame] | 187 | checkout_bmv2 |
Carmelo Cascone | aaf6d98 | 2017-07-29 19:52:58 -0400 | [diff] [blame] | 188 | |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 189 | ./autogen.sh |
Carmelo Cascone | 28f3778 | 2017-08-29 20:11:21 +0200 | [diff] [blame] | 190 | ./configure --enable-debugger --with-pi 'CXXFLAGS=-O0 -g' |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 191 | make -j${NUM_CORES} |
| 192 | sudo make install |
| 193 | sudo ldconfig |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 194 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 195 | # Simple_switch_grpc target |
| 196 | cd targets/simple_switch_grpc |
| 197 | ./autogen.sh |
Carmelo Cascone | 28f3778 | 2017-08-29 20:11:21 +0200 | [diff] [blame] | 198 | ./configure 'CXXFLAGS=-O0 -g' |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 199 | make -j${NUM_CORES} |
| 200 | sudo make install |
| 201 | sudo ldconfig |
| 202 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 203 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 204 | function do_p4c { |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 205 | cd ${BUILD_DIR} |
| 206 | if [ ! -d p4c ]; then |
| 207 | git clone https://github.com/p4lang/p4c.git |
| 208 | fi |
| 209 | cd p4c |
| 210 | git fetch |
| 211 | git checkout ${P4C_COMMIT} |
| 212 | git submodule update --init --recursive |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 213 | |
Carmelo Cascone | 6e4f7eb | 2017-08-21 23:00:43 +0200 | [diff] [blame] | 214 | mkdir -p build |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 215 | cd build |
Carmelo Cascone | 6e4f7eb | 2017-08-21 23:00:43 +0200 | [diff] [blame] | 216 | cmake .. |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 217 | make -j${NUM_CORES} |
| 218 | sudo make install |
| 219 | sudo ldconfig |
| 220 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 221 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 222 | function check_commit { |
| 223 | if [ ! -e $2 ]; then |
| 224 | return 0 # true |
| 225 | fi |
| 226 | if [[ $(< $2) != "$1" ]]; then |
| 227 | return 0 # true |
| 228 | fi |
| 229 | return 1 # false |
| 230 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 231 | |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 232 | # The following is borrowed from Mininet's util/install.sh |
| 233 | function version_ge { |
| 234 | # sort -V sorts by *version number* |
| 235 | latest=`printf "$1\n$2" | sort -V | tail -1` |
| 236 | # If $1 is latest version, then $1 >= $2 |
| 237 | [ "$1" == "$latest" ] |
| 238 | } |
| 239 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 240 | MUST_DO_ALL=false |
| 241 | DID_REQUIREMENTS=false |
| 242 | function check_and_do { |
| 243 | # Check if the latest built commit is the same we are trying to build now, or if all projects |
| 244 | # must be built. If true builds this project. |
| 245 | commit_id="$1" |
| 246 | proj_dir="$2" |
| 247 | func_name="$3" |
Carmelo Cascone | 87ac737 | 2017-09-15 01:58:59 +0200 | [diff] [blame] | 248 | simple_name="$4" |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 249 | if ${MUST_DO_ALL} = true || check_commit ${commit_id} ${proj_dir}/.last_built_commit; then |
| 250 | echo "#" |
Carmelo Cascone | 87ac737 | 2017-09-15 01:58:59 +0200 | [diff] [blame] | 251 | echo "# Building ${simple_name} (${commit_id})" |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 252 | echo "#" |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 253 | # Print commands used to install to aid debugging |
| 254 | set -x |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 255 | if ! ${DID_REQUIREMENTS} = true; then |
| 256 | do_requirements |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 257 | #TODO consider other Linux distros; presently this script assumes that it is running on Ubuntu |
| 258 | RELEASE=`lsb_release -rs` |
| 259 | if version_ge $RELEASE 16.04; then |
| 260 | do_requirements_1604 |
| 261 | elif version_ge $RELEASE 14.04; then |
| 262 | do_requirements_1404 |
| 263 | else |
| 264 | echo "Ubuntu version $RELEASE is not supported" |
| 265 | exit 1 |
| 266 | fi |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 267 | DID_REQUIREMENTS=true |
| 268 | fi |
| 269 | eval ${func_name} |
| 270 | echo ${commit_id} > ${BUILD_DIR}/${proj_dir}/.last_built_commit |
| 271 | # Build all next projects as they might depend on this one. |
| 272 | MUST_DO_ALL=true |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 273 | # Disable printing to reduce output |
| 274 | set +x |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 275 | else |
| 276 | echo "${proj_dir} is up to date (commit ${commit_id})" |
| 277 | fi |
| 278 | } |
| 279 | |
| 280 | mkdir -p ${BUILD_DIR} |
| 281 | cd ${BUILD_DIR} |
| 282 | # In dependency order. |
Carmelo Cascone | 87ac737 | 2017-09-15 01:58:59 +0200 | [diff] [blame] | 283 | check_and_do ${PROTOBUF_COMMIT} protobuf do_protobuf protobuf |
| 284 | check_and_do ${GRPC_COMMIT} grpc do_grpc grpc |
| 285 | check_and_do ${BMV2_COMMIT} bmv2 do_pi_bmv2_deps bmv2-deps |
| 286 | check_and_do ${PI_COMMIT} p4runtime do_p4runtime p4runtime |
| 287 | check_and_do ${BMV2_COMMIT} bmv2 do_bmv2 bmv2 |
| 288 | check_and_do ${P4C_COMMIT} p4c do_p4c p4c |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 289 | |
| 290 | echo "Done!" |