PI源码分析以及服务注入(1)

Introduction to PI

PI 是由 Barefoot 和 Google 合力打造的针对P4生态的一个开源框架,目前,该框架主要为 P4 生态下的软件交换机 bmv2 服务。我们知道 OpenFlow 协议,一种依赖于网络协议的编程协议。 而P4提出了独立于网络协议的编程生态。在 SDN 框架下,如何控制器和交换机的交互?目前非常成熟的技术是利用 OpenFlow 协议。但是, 在P4的生态下,OpenFlow 就显得心有余而力不足了。在P4生态下, P4runtime 用来进行控制器和交换机的通信。而 PI 是一个将控制器,交换机, P4runtime 集合到一起的框架。目前,在该框架下可以完成的事情:使用 bmv2交换机, 通过 CLI 接口在runtime时对 bmv2交换机进行控制。
从PI的整体框架上来说, 控制器(CLI)<--p4runtime-->中间层PI<----->后端系统<----->特定交换机。 如果用户想要使用P4runtime 控制自己的交换机,那么用必须自己完善相应的后端系统。 目前针对交换机 bmv2的整个系统链已经完成呢。在PI框架下可以见到相关的bmv2 后端系统的实现代码。
PI 源代码见 https://github.com/p4lang/PI

Install PI

PI 的详细安装过程代码仓库中已经给出了,这里列出我在编译时遇到的几个麻烦的点:

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
ques1:
在执行configure 时的错误:
checking for python version... 2.7
checking for python platform... linux2
checking for python script directory... ${prefix}/lib/python2.7/dist-packages
checking for python extension module directory... ${exec_prefix}/lib/python2.7/dist-packages
./configure: line 16188: syntax error near unexpected token `PROTOBUF,'
./configure: line 16188: `PKG_CHECK_MODULES(PROTOBUF, protobuf >= 3.0.0)'
configure: error: ./configure failed for proto

解决方法:
sudo apt-get install pkg-config
export PROTOBUF=/usr/local
export PROTOC="$PROTOBUF/bin/protoc"
export PROTOBUF_LIBS="-L$PROTOBUF/lib -lprotobuf -D_THREAD_SAFE"
export PROTOBUF_CFLAGS="-I$PROTOBUF/include -D_THREAD_SAFE"

注意:执行完上述步骤之后重新开始执行 ./autogen.sh

ques2:
checking for boostlib >= 1.54.0... yes
checking whether the Boost::Thread library is available... yes
configure: error: Could not find a version of the library!

solved:
sudo apt-get install libboost-all-dev
./configure --with-boost-libdir=???
如果实在ARM环境下: ./configure --with-boost-libdir=/usr/lib/arm-linux-gnueabihf/

#外, PI代码仓库中有一个demo,位于 PI/proto/demo_grpc/, 如果在 configure 过程中指定 –with-bmv2, 那么该demo一定会编#; 如果不想与bmv2进行交互,如果系统中缺少 libmicrohttpd 插件,则不会进行编译并且不会报错, 如果系统中装有该插件,该demo #进行编译。