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