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