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 | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 18 | BMV2_COMMIT="654e9c3794273b481284d8bafecfc74c7ffd643d" |
| 19 | PI_COMMIT="8051d54c9c3415ca800db232a226189fd17ad60a" |
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 | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 151 | ./configure --with-proto --without-cli --without-internal-rpc |
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 | |
| 166 | ./autogen.sh |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 167 | # TODO: to build with debugger, we need to install nanomsg first (see bmv2's install_deps.sh) |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 168 | ./configure --without-thrift --without-nanomsg --with-pi |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 169 | make -j${NUM_CORES} |
| 170 | sudo make install |
| 171 | sudo ldconfig |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 172 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 173 | # Simple_switch_grpc target |
| 174 | cd targets/simple_switch_grpc |
| 175 | ./autogen.sh |
| 176 | ./configure |
| 177 | make -j${NUM_CORES} |
| 178 | sudo make install |
| 179 | sudo ldconfig |
| 180 | } |
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 | function do_p4c { |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 183 | cd ${BUILD_DIR} |
| 184 | if [ ! -d p4c ]; then |
| 185 | git clone https://github.com/p4lang/p4c.git |
| 186 | fi |
| 187 | cd p4c |
| 188 | git fetch |
| 189 | git checkout ${P4C_COMMIT} |
| 190 | git submodule update --init --recursive |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 191 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 192 | ./bootstrap.sh |
| 193 | cd build |
| 194 | make -j${NUM_CORES} |
| 195 | sudo make install |
| 196 | sudo ldconfig |
| 197 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 198 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 199 | function check_commit { |
| 200 | if [ ! -e $2 ]; then |
| 201 | return 0 # true |
| 202 | fi |
| 203 | if [[ $(< $2) != "$1" ]]; then |
| 204 | return 0 # true |
| 205 | fi |
| 206 | return 1 # false |
| 207 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 208 | |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 209 | # The following is borrowed from Mininet's util/install.sh |
| 210 | function version_ge { |
| 211 | # sort -V sorts by *version number* |
| 212 | latest=`printf "$1\n$2" | sort -V | tail -1` |
| 213 | # If $1 is latest version, then $1 >= $2 |
| 214 | [ "$1" == "$latest" ] |
| 215 | } |
| 216 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 217 | MUST_DO_ALL=false |
| 218 | DID_REQUIREMENTS=false |
| 219 | function check_and_do { |
| 220 | # Check if the latest built commit is the same we are trying to build now, or if all projects |
| 221 | # must be built. If true builds this project. |
| 222 | commit_id="$1" |
| 223 | proj_dir="$2" |
| 224 | func_name="$3" |
| 225 | if ${MUST_DO_ALL} = true || check_commit ${commit_id} ${proj_dir}/.last_built_commit; then |
| 226 | echo "#" |
| 227 | echo "# Building ${proj_dir} (${commit_id})" |
| 228 | echo "#" |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 229 | # Print commands used to install to aid debugging |
| 230 | set -x |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 231 | if ! ${DID_REQUIREMENTS} = true; then |
| 232 | do_requirements |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 233 | #TODO consider other Linux distros; presently this script assumes that it is running on Ubuntu |
| 234 | RELEASE=`lsb_release -rs` |
| 235 | if version_ge $RELEASE 16.04; then |
| 236 | do_requirements_1604 |
| 237 | elif version_ge $RELEASE 14.04; then |
| 238 | do_requirements_1404 |
| 239 | else |
| 240 | echo "Ubuntu version $RELEASE is not supported" |
| 241 | exit 1 |
| 242 | fi |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 243 | DID_REQUIREMENTS=true |
| 244 | fi |
| 245 | eval ${func_name} |
| 246 | echo ${commit_id} > ${BUILD_DIR}/${proj_dir}/.last_built_commit |
| 247 | # Build all next projects as they might depend on this one. |
| 248 | MUST_DO_ALL=true |
Brian O'Connor | 73f8bd7 | 2017-06-16 15:27:49 -0700 | [diff] [blame] | 249 | # Disable printing to reduce output |
| 250 | set +x |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 251 | else |
| 252 | echo "${proj_dir} is up to date (commit ${commit_id})" |
| 253 | fi |
| 254 | } |
| 255 | |
| 256 | mkdir -p ${BUILD_DIR} |
| 257 | cd ${BUILD_DIR} |
| 258 | # In dependency order. |
| 259 | check_and_do ${PROTOBUF_COMMIT} protobuf do_protobuf |
| 260 | check_and_do ${GRPC_COMMIT} grpc do_grpc |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 261 | check_and_do ${PI_COMMIT} p4runtime do_p4runtime |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 262 | check_and_do ${BMV2_COMMIT} bmv2 do_bmv2 |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 263 | check_and_do ${P4C_COMMIT} p4c do_p4c |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 264 | |
| 265 | echo "Done!" |