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 |
Yi Tseng | 3e7f145 | 2017-10-20 10:31:53 -0700 | [diff] [blame] | 18 | BMV2_COMMIT="44ac9c21636b00fed660ae8590889d85b5d4df4c" |
| 19 | PI_COMMIT="a8814a8ac40838a9df83fe47a17a025b69026fcf" |
Carmelo Cascone | ca94bcf | 2017-10-27 14:16:59 -0700 | [diff] [blame] | 20 | P4C_COMMIT="040b931fbfcb7912e3a14cd05df950fbdd49b038" |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 21 | PROTOBUF_COMMIT="tags/v3.0.2" |
| 22 | GRPC_COMMIT="tags/v1.3.0" |
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 \ |
| 74 | tcpdump \ |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 75 | wget \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 76 | unzip |
Carmelo Cascone | 87ac737 | 2017-09-15 01:58:59 +0200 | [diff] [blame] | 77 | |
| 78 | sudo pip install setuptools cffi |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | function do_requirements_1404 { |
| 82 | sudo apt install -y python-software-properties software-properties-common |
| 83 | sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test |
Carmelo Cascone | 6e4f7eb | 2017-08-21 23:00:43 +0200 | [diff] [blame] | 84 | sudo add-apt-repository -y ppa:george-edison55/cmake-3.x |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 85 | sudo apt update |
| 86 | sudo apt install -y \ |
Carmelo Cascone | 6e4f7eb | 2017-08-21 23:00:43 +0200 | [diff] [blame] | 87 | cmake \ |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 88 | dpkg-dev \ |
| 89 | g++-4.9 \ |
| 90 | gcc-4.9 \ |
| 91 | libboost-iostreams-dev |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 92 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 93 | # Needed for p4c. |
| 94 | sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 50 |
| 95 | sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 50 |
| 96 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 97 | |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 98 | function do_requirements_1604 { |
| 99 | sudo apt-get update |
| 100 | sudo apt-get install -y --no-install-recommends \ |
| 101 | ca-certificates \ |
Carmelo Cascone | 6e4f7eb | 2017-08-21 23:00:43 +0200 | [diff] [blame] | 102 | cmake \ |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 103 | g++ \ |
| 104 | libboost-iostreams1.58-dev |
| 105 | } |
| 106 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 107 | function do_protobuf { |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 108 | cd ${BUILD_DIR} |
| 109 | if [ ! -d protobuf ]; then |
| 110 | git clone https://github.com/google/protobuf.git |
| 111 | fi |
| 112 | cd protobuf |
| 113 | git fetch |
| 114 | git checkout ${PROTOBUF_COMMIT} |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 115 | |
| 116 | export CFLAGS="-Os" |
| 117 | export CXXFLAGS="-Os" |
| 118 | export LDFLAGS="-Wl,-s" |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 119 | ./autogen.sh |
| 120 | ./configure --prefix=/usr |
| 121 | make -j${NUM_CORES} |
| 122 | sudo make install |
| 123 | sudo ldconfig |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 124 | unset CFLAGS CXXFLAGS LDFLAGS |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 125 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 126 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 127 | function do_grpc { |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 128 | cd ${BUILD_DIR} |
| 129 | if [ ! -d grpc ]; then |
| 130 | git clone https://github.com/grpc/grpc.git |
| 131 | fi |
| 132 | cd grpc |
| 133 | git fetch |
| 134 | git checkout ${GRPC_COMMIT} |
| 135 | git submodule update --init |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 136 | |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 137 | export LDFLAGS="-Wl,-s" |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 138 | make -j${NUM_CORES} |
| 139 | sudo make install |
| 140 | sudo ldconfig |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 141 | unset LDFLAGS |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 142 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 143 | |
Carmelo Cascone | 87ac737 | 2017-09-15 01:58:59 +0200 | [diff] [blame] | 144 | function checkout_bmv2 { |
| 145 | cd ${BUILD_DIR} |
| 146 | if [ ! -d bmv2 ]; then |
| 147 | git clone https://github.com/p4lang/behavioral-model.git bmv2 |
| 148 | fi |
| 149 | cd bmv2 |
| 150 | git fetch |
| 151 | git checkout ${BMV2_COMMIT} |
| 152 | } |
| 153 | |
| 154 | function do_pi_bmv2_deps { |
| 155 | checkout_bmv2 |
| 156 | # From bmv2's install_deps.sh. |
| 157 | # Nanomsg is required also by p4runtime. |
| 158 | tmpdir=`mktemp -d -p .` |
| 159 | cd ${tmpdir} |
| 160 | bash ../travis/install-thrift.sh |
| 161 | bash ../travis/install-nanomsg.sh |
| 162 | sudo ldconfig |
| 163 | bash ../travis/install-nnpy.sh |
| 164 | cd .. |
| 165 | sudo rm -rf $tmpdir |
| 166 | } |
| 167 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 168 | function do_p4runtime { |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 169 | cd ${BUILD_DIR} |
| 170 | if [ ! -d p4runtime ]; then |
| 171 | git clone https://github.com/p4lang/PI.git p4runtime |
| 172 | fi |
| 173 | cd p4runtime |
| 174 | git fetch |
| 175 | git checkout ${PI_COMMIT} |
| 176 | git submodule update --init --recursive |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 177 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 178 | ./autogen.sh |
Carmelo Cascone | 28f3778 | 2017-08-29 20:11:21 +0200 | [diff] [blame] | 179 | ./configure --with-proto 'CXXFLAGS=-O0 -g' |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 180 | make -j${NUM_CORES} |
| 181 | sudo make install |
| 182 | sudo ldconfig |
| 183 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 184 | |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 185 | function do_bmv2 { |
Carmelo Cascone | 87ac737 | 2017-09-15 01:58:59 +0200 | [diff] [blame] | 186 | checkout_bmv2 |
Carmelo Cascone | aaf6d98 | 2017-07-29 19:52:58 -0400 | [diff] [blame] | 187 | |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 188 | ./autogen.sh |
Carmelo Cascone | 28f3778 | 2017-08-29 20:11:21 +0200 | [diff] [blame] | 189 | ./configure --enable-debugger --with-pi 'CXXFLAGS=-O0 -g' |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 190 | make -j${NUM_CORES} |
| 191 | sudo make install |
| 192 | sudo ldconfig |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 193 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 194 | # Simple_switch_grpc target |
| 195 | cd targets/simple_switch_grpc |
| 196 | ./autogen.sh |
Carmelo Cascone | 28f3778 | 2017-08-29 20:11:21 +0200 | [diff] [blame] | 197 | ./configure 'CXXFLAGS=-O0 -g' |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 198 | make -j${NUM_CORES} |
| 199 | sudo make install |
| 200 | sudo ldconfig |
| 201 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 202 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 203 | function do_p4c { |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 204 | cd ${BUILD_DIR} |
| 205 | if [ ! -d p4c ]; then |
| 206 | git clone https://github.com/p4lang/p4c.git |
| 207 | fi |
| 208 | cd p4c |
| 209 | git fetch |
| 210 | git checkout ${P4C_COMMIT} |
| 211 | git submodule update --init --recursive |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 212 | |
Carmelo Cascone | 6e4f7eb | 2017-08-21 23:00:43 +0200 | [diff] [blame] | 213 | mkdir -p build |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 214 | cd build |
Carmelo Cascone | 6e4f7eb | 2017-08-21 23:00:43 +0200 | [diff] [blame] | 215 | cmake .. |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 216 | make -j${NUM_CORES} |
| 217 | sudo make install |
| 218 | sudo ldconfig |
| 219 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 220 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 221 | function check_commit { |
| 222 | if [ ! -e $2 ]; then |
| 223 | return 0 # true |
| 224 | fi |
| 225 | if [[ $(< $2) != "$1" ]]; then |
| 226 | return 0 # true |
| 227 | fi |
| 228 | return 1 # false |
| 229 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 230 | |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 231 | # The following is borrowed from Mininet's util/install.sh |
| 232 | function version_ge { |
| 233 | # sort -V sorts by *version number* |
| 234 | latest=`printf "$1\n$2" | sort -V | tail -1` |
| 235 | # If $1 is latest version, then $1 >= $2 |
| 236 | [ "$1" == "$latest" ] |
| 237 | } |
| 238 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 239 | MUST_DO_ALL=false |
| 240 | DID_REQUIREMENTS=false |
| 241 | function check_and_do { |
| 242 | # Check if the latest built commit is the same we are trying to build now, or if all projects |
| 243 | # must be built. If true builds this project. |
| 244 | commit_id="$1" |
| 245 | proj_dir="$2" |
| 246 | func_name="$3" |
Carmelo Cascone | 87ac737 | 2017-09-15 01:58:59 +0200 | [diff] [blame] | 247 | simple_name="$4" |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 248 | if ${MUST_DO_ALL} = true || check_commit ${commit_id} ${proj_dir}/.last_built_commit; then |
| 249 | echo "#" |
Carmelo Cascone | 87ac737 | 2017-09-15 01:58:59 +0200 | [diff] [blame] | 250 | echo "# Building ${simple_name} (${commit_id})" |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 251 | echo "#" |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 252 | # Print commands used to install to aid debugging |
| 253 | set -x |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 254 | if ! ${DID_REQUIREMENTS} = true; then |
| 255 | do_requirements |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 256 | #TODO consider other Linux distros; presently this script assumes that it is running on Ubuntu |
| 257 | RELEASE=`lsb_release -rs` |
| 258 | if version_ge $RELEASE 16.04; then |
| 259 | do_requirements_1604 |
| 260 | elif version_ge $RELEASE 14.04; then |
| 261 | do_requirements_1404 |
| 262 | else |
| 263 | echo "Ubuntu version $RELEASE is not supported" |
| 264 | exit 1 |
| 265 | fi |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 266 | DID_REQUIREMENTS=true |
| 267 | fi |
| 268 | eval ${func_name} |
| 269 | echo ${commit_id} > ${BUILD_DIR}/${proj_dir}/.last_built_commit |
| 270 | # Build all next projects as they might depend on this one. |
| 271 | MUST_DO_ALL=true |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 272 | # Disable printing to reduce output |
| 273 | set +x |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 274 | else |
| 275 | echo "${proj_dir} is up to date (commit ${commit_id})" |
| 276 | fi |
| 277 | } |
| 278 | |
| 279 | mkdir -p ${BUILD_DIR} |
| 280 | cd ${BUILD_DIR} |
| 281 | # In dependency order. |
Carmelo Cascone | 87ac737 | 2017-09-15 01:58:59 +0200 | [diff] [blame] | 282 | check_and_do ${PROTOBUF_COMMIT} protobuf do_protobuf protobuf |
| 283 | check_and_do ${GRPC_COMMIT} grpc do_grpc grpc |
| 284 | check_and_do ${BMV2_COMMIT} bmv2 do_pi_bmv2_deps bmv2-deps |
| 285 | check_and_do ${PI_COMMIT} p4runtime do_p4runtime p4runtime |
| 286 | check_and_do ${BMV2_COMMIT} bmv2 do_bmv2 bmv2 |
| 287 | check_and_do ${P4C_COMMIT} p4c do_p4c p4c |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 288 | |
| 289 | echo "Done!" |