P4语言编译环境搭建Ubuntu20.04

搭建P4编译环境

现有的一些教程基本都是在Ubuntu16等旧版本上的,照着原有的教程在Ubuntu20及以后的版本中会有较多的错误,本文记录一下艰苦的搭环境过程,笔者使用的系统为Ubuntu20.04,强烈建议多参考GitHub中提供的官方文档。
https://github.com/p4lang
本文也参考了
https://github.com/10249421/p4_code_learn/blob/main/p4-user-bootstrap.sh

P4C安装

. /etc/os-release
echo "deb http://download.opensuse.org/repositories/home:/p4lang/xUbuntu_${VERSION_ID}/ /" | sudo tee /etc/apt/sources.list.d/home:p4lang.list
sudo apt install curl
curl -L "http://download.opensuse.org/repositories/home:/p4lang/xUbuntu_${VERSION_ID}/Release.key" | sudo apt-key add -
sudo apt-get update
sudo apt install p4lang-p4c

bmv2安装

sudo apt-get install -y automake cmake libgmp-dev \
    libpcap-dev libboost-dev libboost-test-dev libboost-program-options-dev \
    libboost-system-dev libboost-filesystem-dev libboost-thread-dev \
    libevent-dev libtool flex bison pkg-config g++ libssl-dev

安装thrift //安装0.11.0 - 0.13.0 安装0.15.0时报错未解决

安装nanomsg

cd behavioral-model
./autogen.sh
./configure
make
sudo make install  # if you need to install bmv2

安装mininet

//sudo apt-get install mininet
git clone https://github.com/mininet/mininet mininet
sudo ./mininet/util/install.sh -nwv

安装gmock

cd gmock-1.7.0
cd make
make
./gmock_test

安装protobuf

git clone git//github.com/protocolbuffers/protobuf.git
cd protobuf/
./autogen.sh
./configure
make
sudo make install
sudo ldconfig

之后把tutorial下载下来跑一下试试,能跑起来应该没啥问题了,之后遇到问题再说(逃)

grpc安装

sudo apt-get install build-essential autoconf libtool pkg-config cmake clang libc++-dev libssl-dev -y
git clone https://github.com/grpc/grpc.git
export LDFLAGS="-Wl,-s"
# Install gRPC and its dependencies
mkdir -p "cmake/build"
pushd "cmake/build"
cmake -DBUILD_SHARED_LIBS=ON \
  -DCMAKE_BUILD_TYPE=Release \
  -DgRPC_INSTALL=ON \
  -DgRPC_BUILD_TESTS=OFF \
  -DgRPC_SSL_PROVIDER=package \
  ../..
make -j${NUM_CORES}
sudo make check |  tee  $p4/log/grpc.log
sudo make install |  tee -a $p4/log/grpc.log
sudo ldconfig
unset LDFLAGS
popd
# Build helloworld example using cmake
mkdir -p "examples/cpp/helloworld/cmake/build"
pushd "examples/cpp/helloworld/cmake/build"
cmake ../..
make -j${NUM_CORES}
popd
cd $p4
# Install gRPC Python Package
sudo pip3 install grpcio

git submodule update --init --recursive会因为网络问题失败,解决方法是把.gitmodules中的url中的https:全改为git:然后运行
module update --init --recursive

你可能感兴趣的:(网络通信,计算机网络,ubuntu)