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 | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 18 | BMV2_COMMIT="487ee8f907153d93d4806f3e9e209ed9cb668c2b" |
| 19 | PI_COMMIT="d7418b386e2301f82c1330a1d2dca131ef7b4fe3" |
| 20 | P4C_COMMIT="80db63762314494b313f39c40067b3d3416007d3" |
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 |
| 29 | sudo apt install -y python-software-properties software-properties-common |
| 30 | sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test |
| 31 | sudo apt update |
| 32 | sudo apt install -y \ |
| 33 | autoconf \ |
| 34 | automake \ |
| 35 | bison \ |
| 36 | curl \ |
| 37 | dpkg-dev \ |
| 38 | flex \ |
| 39 | g++-4.9 \ |
| 40 | gcc-4.9 \ |
| 41 | git \ |
| 42 | libboost-dev \ |
| 43 | libboost-iostreams-dev \ |
| 44 | libfl-dev \ |
| 45 | libgc-dev \ |
| 46 | libgmp-dev \ |
| 47 | libreadline6 \ |
| 48 | libreadline6-dev \ |
| 49 | libtool \ |
| 50 | libc6-dev \ |
| 51 | make \ |
| 52 | pkg-config \ |
| 53 | python \ |
| 54 | python-ipaddr \ |
| 55 | python-scapy \ |
| 56 | tcpdump \ |
| 57 | unzip |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 58 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 59 | # Needed for p4c. |
| 60 | sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 50 |
| 61 | sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 50 |
| 62 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 63 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 64 | function do_protobuf { |
| 65 | # Protobuf |
| 66 | cd ${BUILD_DIR} |
| 67 | if [ ! -d protobuf ]; then |
| 68 | git clone https://github.com/google/protobuf.git |
| 69 | fi |
| 70 | cd protobuf |
| 71 | git fetch |
| 72 | git checkout ${PROTOBUF_COMMIT} |
| 73 | ./autogen.sh |
| 74 | ./configure --prefix=/usr |
| 75 | make -j${NUM_CORES} |
| 76 | sudo make install |
| 77 | sudo ldconfig |
| 78 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 79 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 80 | function do_grpc { |
| 81 | # gRPC |
| 82 | cd ${BUILD_DIR} |
| 83 | if [ ! -d grpc ]; then |
| 84 | git clone https://github.com/grpc/grpc.git |
| 85 | fi |
| 86 | cd grpc |
| 87 | git fetch |
| 88 | git checkout ${GRPC_COMMIT} |
| 89 | git submodule update --init |
| 90 | make -j${NUM_CORES} |
| 91 | sudo make install |
| 92 | sudo ldconfig |
| 93 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 94 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 95 | function do_bmv2 { |
| 96 | # BMv2 part 1 (without PI) |
| 97 | cd ${BUILD_DIR} |
| 98 | if [ ! -d bmv2 ]; then |
| 99 | git clone https://github.com/p4lang/behavioral-model.git bmv2 |
| 100 | fi |
| 101 | cd bmv2 |
| 102 | git fetch |
| 103 | git checkout ${BMV2_COMMIT} |
| 104 | ./install_deps.sh |
| 105 | ./autogen.sh |
| 106 | ./configure --enable-debugger |
| 107 | make -j${NUM_CORES} |
| 108 | sudo make install |
| 109 | sudo ldconfig |
| 110 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 111 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 112 | function do_p4runtime { |
| 113 | # P4Runtime (PI) |
| 114 | cd ${BUILD_DIR} |
| 115 | if [ ! -d p4runtime ]; then |
| 116 | git clone https://github.com/p4lang/PI.git p4runtime |
| 117 | fi |
| 118 | cd p4runtime |
| 119 | git fetch |
| 120 | git checkout ${PI_COMMIT} |
| 121 | git submodule update --init --recursive |
| 122 | ./autogen.sh |
| 123 | ./configure --with-bmv2 --with-proto |
| 124 | make -j${NUM_CORES} |
| 125 | sudo make install |
| 126 | sudo ldconfig |
| 127 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 128 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 129 | function do_bmv2_with_pi { |
| 130 | # BMv2 part 2 (with PI) |
| 131 | cd ${BUILD_DIR}/bmv2 |
| 132 | ./configure --enable-debugger --with-pi |
| 133 | make -j${NUM_CORES} |
| 134 | sudo make install |
| 135 | sudo ldconfig |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 136 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 137 | # Simple_switch_grpc target |
| 138 | cd targets/simple_switch_grpc |
| 139 | ./autogen.sh |
| 140 | ./configure |
| 141 | make -j${NUM_CORES} |
| 142 | sudo make install |
| 143 | sudo ldconfig |
| 144 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 145 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 146 | function do_p4c { |
| 147 | # p4c |
| 148 | cd ${BUILD_DIR} |
| 149 | if [ ! -d p4c ]; then |
| 150 | git clone https://github.com/p4lang/p4c.git |
| 151 | fi |
| 152 | cd p4c |
| 153 | git fetch |
| 154 | git checkout ${P4C_COMMIT} |
| 155 | git submodule update --init --recursive |
| 156 | ./bootstrap.sh |
| 157 | cd build |
| 158 | make -j${NUM_CORES} |
| 159 | sudo make install |
| 160 | sudo ldconfig |
| 161 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 162 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 163 | function do_p4c_bm { |
| 164 | # p4c-bmv2 (old BMv2 compiler) |
| 165 | cd ${BUILD_DIR} |
| 166 | if [ ! -d p4c-bmv2 ]; then |
| 167 | git clone https://github.com/p4lang/p4c-bm.git p4c-bmv2 |
| 168 | fi |
| 169 | cd p4c-bmv2 |
| 170 | git fetch |
| 171 | git checkout ${P4C_BM_COMMIT} |
| 172 | sudo pip install -r requirements.txt |
| 173 | sudo python setup.py install |
| 174 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 175 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 176 | function check_commit { |
| 177 | if [ ! -e $2 ]; then |
| 178 | return 0 # true |
| 179 | fi |
| 180 | if [[ $(< $2) != "$1" ]]; then |
| 181 | return 0 # true |
| 182 | fi |
| 183 | return 1 # false |
| 184 | } |
Carmelo Cascone | acf1225 | 2017-06-05 01:05:43 -0400 | [diff] [blame] | 185 | |
Carmelo Cascone | 7e8f832 | 2017-06-05 13:31:47 -0400 | [diff] [blame] | 186 | MUST_DO_ALL=false |
| 187 | DID_REQUIREMENTS=false |
| 188 | function check_and_do { |
| 189 | # Check if the latest built commit is the same we are trying to build now, or if all projects |
| 190 | # must be built. If true builds this project. |
| 191 | commit_id="$1" |
| 192 | proj_dir="$2" |
| 193 | func_name="$3" |
| 194 | if ${MUST_DO_ALL} = true || check_commit ${commit_id} ${proj_dir}/.last_built_commit; then |
| 195 | echo "#" |
| 196 | echo "# Building ${proj_dir} (${commit_id})" |
| 197 | echo "#" |
| 198 | if ! ${DID_REQUIREMENTS} = true; then |
| 199 | do_requirements |
| 200 | DID_REQUIREMENTS=true |
| 201 | fi |
| 202 | eval ${func_name} |
| 203 | echo ${commit_id} > ${BUILD_DIR}/${proj_dir}/.last_built_commit |
| 204 | # Build all next projects as they might depend on this one. |
| 205 | MUST_DO_ALL=true |
| 206 | else |
| 207 | echo "${proj_dir} is up to date (commit ${commit_id})" |
| 208 | fi |
| 209 | } |
| 210 | |
| 211 | mkdir -p ${BUILD_DIR} |
| 212 | cd ${BUILD_DIR} |
| 213 | # In dependency order. |
| 214 | check_and_do ${PROTOBUF_COMMIT} protobuf do_protobuf |
| 215 | check_and_do ${GRPC_COMMIT} grpc do_grpc |
| 216 | check_and_do ${BMV2_COMMIT} bmv2 do_bmv2 |
| 217 | check_and_do ${PI_COMMIT} p4runtime do_p4runtime |
| 218 | check_and_do ${BMV2_COMMIT} bmv2 do_bmv2_with_pi |
| 219 | check_and_do ${P4C_COMMIT} p4c do_p4c |
| 220 | check_and_do ${P4C_BM_COMMIT} p4c-bmv2 do_p4c_bm |
| 221 | |
| 222 | echo "Done!" |