forked from nsg-ethz/p4-learning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-p4-tools.sh
377 lines (325 loc) · 8.77 KB
/
install-p4-tools.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
#!/usr/bin/env bash
set -xe
BUILD_DIR=~/p4-tools
#Install requirements (a lot of them might be redundant
sudo apt update
sudo apt-get install -y --no-install-recommends \
autoconf \
automake \
bison \
build-essential \
cmake \
cpp \
curl \
flex \
git \
libavl-dev \
libboost-dev \
libboost-program-options-dev \
libboost-system-dev \
libboost-filesystem-dev \
libboost-thread-dev \
libboost-filesystem-dev \
libboost-program-options-dev \
libboost-system-dev \
libboost-test-dev \
libboost-thread-dev \
libc6-dev \
libev-dev \
libevent-dev \
libffi-dev \
libfl-dev \
libgc-dev \
libgc1c2 \
libgflags-dev \
libgmp-dev \
libgmp10 \
libgmpxx4ldbl \
libjudy-dev \
libpcap-dev \
libpcre3-dev \
libreadline6 \
libreadline6-dev \
libssl-dev \
libtool \
make \
pkg-config \
protobuf-c-compiler \
python2.7 \
python2.7-dev \
tcpdump \
wget \
unzip \
bridge-utils
sudo -H pip install setuptools cffi ipaddr ipaddress pypcap
# Advanced Topics in Communication networks 2019 Commits
BMV2_COMMIT="b447ac4c0cfd83e5e72a3cc6120251c1e91128ab" # Aug 6 2019
P4C_COMMIT="8742052c70836a8b0855e621aad9d6cc11b1f6ee" # Sep 8 2019
PI_COMMIT="41358da0ff32c94fa13179b9cee0ab597c9ccbcc" # Aug 6 2019
PROTOBUF_COMMIT="v3.2.0"
GRPC_COMMIT="v1.3.2"
NUM_CORES=`grep -c ^processor /proc/cpuinfo`
mkdir -p ${BUILD_DIR}
# If false, build tools without debug features to improve throughput of BMv2 and
# reduce CPU/memory footprint.
DEBUG_FLAGS=true
ENABLE_P4_RUNTIME=true
#install mininet
function do_mininet {
cd $HOME
git clone git://github.com/mininet/mininet mininet
cd mininet
sudo ./util/install.sh -nwv
cd ..
}
#Install Protobuf
function do_protobuf {
cd ${BUILD_DIR}
if [ ! -d protobuf ]; then
git clone https://github.com/google/protobuf.git
fi
cd protobuf
git fetch
git checkout ${PROTOBUF_COMMIT}
export CFLAGS="-Os"
export CXXFLAGS="-Os"
export LDFLAGS="-Wl,-s"
./autogen.sh
./configure --prefix=/usr
make -j${NUM_CORES}
sudo make install
sudo ldconfig
unset CFLAGS CXXFLAGS LDFLAGS
# force install python module
cd python
sudo python setup.py install --cpp_implementation
}
#needed for PI.
function do_grpc {
cd ${BUILD_DIR}
if [ ! -d grpc ]; then
git clone https://github.com/grpc/grpc.git
fi
cd grpc
git fetch
git checkout ${GRPC_COMMIT}
git submodule update --init --recursive
export LDFLAGS="-Wl,-s"
make -j${NUM_CORES}
sudo make install
sudo ldconfig
unset LDFLAGS
# Install gRPC Python Package
sudo pip install -r requirements.txt
sudo pip install grpcio
sudo pip install .
}
#needed for PI, this is the same than install_deps.sh but without the first apt-gets
function do_bmv2_deps {
# BMv2 deps (needed by PI)
cd ${BUILD_DIR}
if [ ! -d bmv2 ]; then
git clone https://github.com/p4lang/behavioral-model.git bmv2
fi
cd bmv2
git checkout ${BMV2_COMMIT}
# From bmv2's install_deps.sh, we can skip apt-get install.
# Nanomsg is required by p4runtime, p4runtime is needed by BMv2...
tmpdir=`mktemp -d -p .`
cd ${tmpdir}
bash ../travis/install-thrift.sh
bash ../travis/install-nanomsg.sh
sudo ldconfig
bash ../travis/install-nnpy.sh
cd ..
sudo rm -rf $tmpdir
cd ..
}
#Tentative gNMI support with sysrepo
function do_sysrepo {
# Dependencies in : https://github.com/p4lang/PI/blob/master/proto/README.md
sudo apt-get --yes install build-essential cmake libpcre3-dev libavl-dev libev-dev libprotobuf-c-dev protobuf-c-compiler
cd ${BUILD_DIR}
# Install libyang
if [ ! -d libyang ]; then
git clone https://github.com/CESNET/libyang.git
fi
cd libyang
git checkout v0.16-r1
mkdir build
cd build
cmake ..
make
sudo make install
sudo ldconfig
cd ../..
# Install sysrepo
if [ ! -d sysrepo ]; then
git clone https://github.com/sysrepo/sysrepo.git
fi
cd sysrepo
git checkout v0.7.5
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=Off -DCALL_TARGET_BINS_DIRECTLY=Off ..
make
sudo make install
sudo ldconfig
cd ..
}
#only if we want P4Runtime
function do_PI {
cd ${BUILD_DIR}
if [ ! -d PI ]; then
git clone https://github.com/p4lang/PI.git
fi
cd PI
git fetch
git checkout ${PI_COMMIT}
git submodule update --init --recursive
./autogen.sh
if [ "$DEBUG_FLAGS" = true ] ; then
./configure --with-proto --with-sysrepo "CXXFLAGS=-O0 -g"
else
./configure --with-proto --with-sysrepo
fi
make -j${NUM_CORES}
sudo make install
sudo ldconfig
cd ..
}
function do_bmv2 {
if [ "$ENABLE_P4_RUNTIME" = false ] ; then
do_bmv2_deps
fi
cd ${BUILD_DIR}
if [ ! -d bmv2 ]; then
git clone https://github.com/p4lang/behavioral-model.git bmv2
fi
cd bmv2
git checkout ${BMV2_COMMIT}
./autogen.sh
#./configure 'CXXFLAGS=-O0 -g' --with-nanomsg --with-thrift --enable-debugger
if [ "$DEBUG_FLAGS" = true ] && [ "$ENABLE_P4_RUNTIME" = true ] ; then
#./configure --enable-debugger --enable-elogger --with-thrift --with-nanomsg "CXXFLAGS=-O0 -g"
./configure --with-pi --enable-debugger --with-thrift --with-nanomsg --disable-elogger "CXXFLAGS=-O0 -g"
elif [ "$DEBUG_FLAGS" = true ] && [ "$ENABLE_P4_RUNTIME" = false ] ; then
./configure --enable-debugger --enable-elogger --with-thrift --with-nanomsg "CXXFLAGS=-O0 -g"
elif [ "$DEBUG_FLAGS" = false ] && [ "$ENABLE_P4_RUNTIME" = true ] ; then
./configure --with-pi --without-nanomsg --disable-elogger --disable-logging-macros 'CFLAGS=-g -O2' 'CXXFLAGS=-g -O2'
else #both false
#Option removed until we use this commit: https://github.com/p4lang/behavioral-model/pull/673
#./configure --with-pi --disable-logging-macros --disable-elogger --without-nanomsg
./configure --disable-elogger --disable-logging-macros 'CFLAGS=-g -O2' 'CXXFLAGS=-g -O2'
fi
make -j${NUM_CORES}
sudo make install
sudo ldconfig
# Simple_switch_grpc target
if [ "$ENABLE_P4_RUNTIME" = true ] ; then
cd targets/simple_switch_grpc
./autogen.sh
if [ "$DEBUG_FLAGS" = true ] ; then
./configure --with-sysrepo --with-thrift "CXXFLAGS=-O0 -g"
else
./configure --with-sysrepo --with-thrift
fi
make -j${NUM_CORES}
sudo make install
sudo ldconfig
cd ../../..
fi
}
function do_p4c {
cd ${BUILD_DIR}
if [ ! -d p4c ]; then
git clone https://github.com/p4lang/p4c.git
fi
cd p4c
git fetch
git checkout ${P4C_COMMIT}
git submodule update --init --recursive
mkdir -p build
cd build
if [ "$DEBUG_FLAGS" = true ] ; then
cmake .. -DCMAKE_BUILD_TYPE=DEBUG $*
else
# Debug build
cmake ..
fi
make -j${NUM_CORES}
sudo make install
sudo ldconfig
cd ../..
}
function do_scapy-vxlan {
cd ${BUILD_DIR}
if [ ! -d scapy-vxlan ]; then
git clone https://github.com/p4lang/scapy-vxlan.git
fi
cd scapy-vxlan
git pull origin master
sudo python setup.py install
}
function do_scapy {
# Installs normal scapy (installs latest version 2.4.4 right now)
sudo pip install scapy
}
function do_ptf {
cd ${BUILD_DIR}
if [ ! -d ptf ]; then
git clone https://github.com/p4lang/ptf.git
fi
cd ptf
git pull origin master
sudo python setup.py install
}
function do_p4-utils {
cd ${BUILD_DIR}
if [ ! -d p4-utils ]; then
git clone https://github.com/nsg-ethz/p4-utils.git
fi
cd p4-utils
sudo ./install.sh
cd ..
}
# Update scripts
function do_install_scripts {
mkdir -p /home/p4/bin
cp /vagrant/bin/update-bmv2.sh /home/p4/bin/update-bmv2
chmod a+x /home/p4/bin/update-bmv2
cp /vagrant/bin/update-p4c.sh /home/p4/bin/update-p4c
chmod a+x /home/p4/bin/update-p4c
}
function do_p4-learning {
cd ${BUILD_DIR}
if [ ! -d p4-learning ]; then
git clone https://github.com/nsg-ethz/p4-learning.git
fi
cd ..
}
# Due to this bug: https://github.com/jafingerhut/p4-guide/tree/master/linux-veth-bug
# we need to verify if the current kernel is buggy or not
function do_verify-ubuntu-bug {
sudo pip install bs4
sudo python /vagrant/bin/test_veth_intf.py
}
do_protobuf
if [ "$ENABLE_P4_RUNTIME" = true ] ; then
do_grpc
do_bmv2_deps
do_sysrepo
do_PI
fi
do_bmv2
do_p4c
#The scapy version they use its too old
#do_scapy-vxlan
do_scapy
do_ptf
do_mininet
do_p4-utils
do_install_scripts
do_p4-learning
do_verify-ubuntu-bug
echo "Done with p4-tools install!"