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 | # |
| 6 | # Tested on Ubuntu 14.04. |
| 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 |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 29 | #FIXME the following two lines seem like they are not required, at least for 16.04 |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 30 | sudo apt install -y python-software-properties software-properties-common |
| 31 | sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test |
| 32 | sudo apt update |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 33 | #FIXME 14.04 needs special gcc, 16.04 can use apt-get default |
| 34 | sudo apt install -y --no-install-recommends \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 35 | autoconf \ |
| 36 | automake \ |
| 37 | bison \ |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 38 | build-essential \ |
| 39 | cmake \ |
| 40 | cpp \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 41 | curl \ |
| 42 | dpkg-dev \ |
| 43 | flex \ |
| 44 | g++-4.9 \ |
| 45 | gcc-4.9 \ |
| 46 | git \ |
| 47 | libboost-dev \ |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 48 | libboost-filesystem-dev \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 49 | libboost-iostreams-dev \ |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 50 | libboost-program-options-dev \ |
| 51 | libboost-system-dev \ |
| 52 | libboost-test-dev \ |
| 53 | libboost-thread-dev \ |
| 54 | libc6-dev \ |
| 55 | libevent-dev \ |
| 56 | libffi-dev \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 57 | libfl-dev \ |
| 58 | libgc-dev \ |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 59 | libgc1c2 \ |
| 60 | libgflags-dev \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 61 | libgmp-dev \ |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 62 | libgmp10 \ |
| 63 | libgmpxx4ldbl \ |
| 64 | libjudy-dev \ |
| 65 | libpcap-dev \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 66 | libreadline6 \ |
| 67 | libreadline6-dev \ |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 68 | libssl-dev \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 69 | libtool \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 70 | make \ |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 71 | mktemp \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 72 | pkg-config \ |
| 73 | python \ |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 74 | python-dev \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 75 | python-ipaddr \ |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 76 | python-pip \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 77 | python-scapy \ |
| 78 | tcpdump \ |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 79 | wget \ |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 80 | unzip |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 81 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 82 | # Needed for p4c. |
| 83 | sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 50 |
| 84 | sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 50 |
| 85 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 86 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 87 | function do_protobuf { |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 88 | cd ${BUILD_DIR} |
| 89 | if [ ! -d protobuf ]; then |
| 90 | git clone https://github.com/google/protobuf.git |
| 91 | fi |
| 92 | cd protobuf |
| 93 | git fetch |
| 94 | git checkout ${PROTOBUF_COMMIT} |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 95 | |
| 96 | export CFLAGS="-Os" |
| 97 | export CXXFLAGS="-Os" |
| 98 | export LDFLAGS="-Wl,-s" |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 99 | ./autogen.sh |
| 100 | ./configure --prefix=/usr |
| 101 | make -j${NUM_CORES} |
| 102 | sudo make install |
| 103 | sudo ldconfig |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 104 | unset CFLAGS CXXFLAGS LDFLAGS |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 105 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 106 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 107 | function do_grpc { |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 108 | cd ${BUILD_DIR} |
| 109 | if [ ! -d grpc ]; then |
| 110 | git clone https://github.com/grpc/grpc.git |
| 111 | fi |
| 112 | cd grpc |
| 113 | git fetch |
| 114 | git checkout ${GRPC_COMMIT} |
| 115 | git submodule update --init |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 116 | |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 117 | export LDFLAGS="-Wl,-s" |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 118 | make -j${NUM_CORES} |
| 119 | sudo make install |
| 120 | sudo ldconfig |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 121 | unset LDFLAGS |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 122 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 123 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 124 | function do_p4runtime { |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 125 | cd ${BUILD_DIR} |
| 126 | if [ ! -d p4runtime ]; then |
| 127 | git clone https://github.com/p4lang/PI.git p4runtime |
| 128 | fi |
| 129 | cd p4runtime |
| 130 | git fetch |
| 131 | git checkout ${PI_COMMIT} |
| 132 | git submodule update --init --recursive |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 133 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 134 | ./autogen.sh |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 135 | ./configure --with-proto --without-cli --without-internal-rpc |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 136 | make -j${NUM_CORES} |
| 137 | sudo make install |
| 138 | sudo ldconfig |
| 139 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 140 | |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 141 | function do_bmv2 { |
| 142 | cd ${BUILD_DIR} |
| 143 | if [ ! -d bmv2 ]; then |
| 144 | git clone https://github.com/p4lang/behavioral-model.git bmv2 |
| 145 | fi |
| 146 | cd bmv2 |
| 147 | git fetch |
| 148 | git checkout ${BMV2_COMMIT} |
| 149 | |
| 150 | ./autogen.sh |
| 151 | # FIXME: to build with debugger, we need to install nanomsg first (see bmv2's install_deps.sh) |
| 152 | ./configure --without-thrift --without-nanomsg --with-pi |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 153 | make -j${NUM_CORES} |
| 154 | sudo make install |
| 155 | sudo ldconfig |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 156 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 157 | # Simple_switch_grpc target |
| 158 | cd targets/simple_switch_grpc |
| 159 | ./autogen.sh |
| 160 | ./configure |
| 161 | make -j${NUM_CORES} |
| 162 | sudo make install |
| 163 | sudo ldconfig |
| 164 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 165 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 166 | function do_p4c { |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 167 | cd ${BUILD_DIR} |
| 168 | if [ ! -d p4c ]; then |
| 169 | git clone https://github.com/p4lang/p4c.git |
| 170 | fi |
| 171 | cd p4c |
| 172 | git fetch |
| 173 | git checkout ${P4C_COMMIT} |
| 174 | git submodule update --init --recursive |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 175 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 176 | ./bootstrap.sh |
| 177 | cd build |
| 178 | make -j${NUM_CORES} |
| 179 | sudo make install |
| 180 | sudo ldconfig |
| 181 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 182 | |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 183 | # FIXME: Can we deprecate this? |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 184 | function do_p4c_bm { |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 185 | # old BMv2 compiler |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 186 | cd ${BUILD_DIR} |
| 187 | if [ ! -d p4c-bmv2 ]; then |
| 188 | git clone https://github.com/p4lang/p4c-bm.git p4c-bmv2 |
| 189 | fi |
| 190 | cd p4c-bmv2 |
| 191 | git fetch |
| 192 | git checkout ${P4C_BM_COMMIT} |
| 193 | sudo pip install -r requirements.txt |
| 194 | sudo python setup.py install |
| 195 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 196 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 197 | function check_commit { |
| 198 | if [ ! -e $2 ]; then |
| 199 | return 0 # true |
| 200 | fi |
| 201 | if [[ $(< $2) != "$1" ]]; then |
| 202 | return 0 # true |
| 203 | fi |
| 204 | return 1 # false |
| 205 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 206 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 207 | MUST_DO_ALL=false |
| 208 | DID_REQUIREMENTS=false |
| 209 | function check_and_do { |
| 210 | # Check if the latest built commit is the same we are trying to build now, or if all projects |
| 211 | # must be built. If true builds this project. |
| 212 | commit_id="$1" |
| 213 | proj_dir="$2" |
| 214 | func_name="$3" |
| 215 | if ${MUST_DO_ALL} = true || check_commit ${commit_id} ${proj_dir}/.last_built_commit; then |
| 216 | echo "#" |
| 217 | echo "# Building ${proj_dir} (${commit_id})" |
| 218 | echo "#" |
| 219 | if ! ${DID_REQUIREMENTS} = true; then |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 220 | #FIXME need version check for 14.04 vs 16.04 |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 221 | do_requirements |
| 222 | DID_REQUIREMENTS=true |
| 223 | fi |
| 224 | eval ${func_name} |
| 225 | echo ${commit_id} > ${BUILD_DIR}/${proj_dir}/.last_built_commit |
| 226 | # Build all next projects as they might depend on this one. |
| 227 | MUST_DO_ALL=true |
| 228 | else |
| 229 | echo "${proj_dir} is up to date (commit ${commit_id})" |
| 230 | fi |
| 231 | } |
| 232 | |
| 233 | mkdir -p ${BUILD_DIR} |
| 234 | cd ${BUILD_DIR} |
| 235 | # In dependency order. |
| 236 | check_and_do ${PROTOBUF_COMMIT} protobuf do_protobuf |
| 237 | check_and_do ${GRPC_COMMIT} grpc do_grpc |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 238 | check_and_do ${PI_COMMIT} p4runtime do_p4runtime |
Carmelo Cascone | fb76b04 | 2017-07-17 19:42:00 -0400 | [diff] [blame] | 239 | check_and_do ${BMV2_COMMIT} bmv2 do_bmv2 |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 240 | check_and_do ${P4C_COMMIT} p4c do_p4c |
| 241 | check_and_do ${P4C_BM_COMMIT} p4c-bmv2 do_p4c_bm |
| 242 | |
| 243 | echo "Done!" |