构建容器
mkdir docker-p4
cd docker-p4
目录下又如下文件
tree
.
├── Dockerfile
├── pip.conf
└── sources.list
0 directories, 3 files
Dockerfile
FROM ubuntu:16.04
COPY ["sources.list", "/etc/apt/sources.list"]
RUN apt-get update
RUN apt-get install -y net-tools gdb\
traceroute inetutils-ping \
tcpdump procps iotop vim bridge-utils \
git wget curl sudo iptables-dev python-pip
RUN apt-get install -y cmake\
g++ \
git \
automake \
libtool \
libgc-dev \
bison flex \
libfl-dev libgmp-dev \
libboost-dev libboost-iostreams-dev \
libboost-graph-dev llvm pkg-config python \
python-scapy python-ipaddr python-ply tcpdump\
doxygen graphviz texlive-full
RUN mkdir ~/.pip/
COPY ["pip.conf", "~/.pip/pip.conf"]
RUN pip install --upgrade pip
RUN apt-get install -y \
automake \
cmake\
libjudy-dev\
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\
pip.conf
[global]
timeout = 60
index-url = http://pypi.douban.com/simple
trusted-host = pypi.douban.com
sources.list
deb http://mirrors.163.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ xenial-backports main restricted universe multiverse
执行命令
docker build -t p4-rt .
运行容器
#创建工作目录
mkdir p4-rt
#运行容器
docker run -it --name --privileged -v /home/admin/p4-rt:/p4-rt -w /p4-rt p4-rt bash
安装我们依赖的软件
#thrift 0.9.2
git clone https://github.com/apache/thrift.git
cd thrift/
git checkout tags/0.9.2
git submodule update --init --recursive
./bootstrap.sh
./configure
make -j4
make install
ldconfig
#nanomsg 1.0.0
git clone https://github.com/nanomsg/nanomsg.git
cd nanomsg/
git checkout tags/1.0.0
git submodule update --init --recursive
mkdir build
cd build
cmake ..
cmake --build .
ctest .
cmake --build . --target install
ldconfig
#protobuf v3.2.0:
git clone https://github.com/google/protobuf.git
cd protobuf/
git checkout tags/v3.2.0
git submodule update --init --recursive
./autogen.sh
./configure
make -j4
make install
ldconfig
grpc v1.3.2:
#安装依赖c-ares-1.14.0.tar.gz
wget https://c-ares.haxx.se/download/c-ares-1.14.0.tar.gz
tar -xzvf c-ares-1.14.0.tar.gz
./configure
make
make install
ldconfig
wget https://codeload.github.com/grpc/grpc/tar.gz/v1.3.2
tar -xzvf v1.3.2
cd grpc-1.3.2/
make -j4
make install
ldconfig
#sysrepo
apt-get install build-essential cmake libpcre3-dev libavl-dev libev-dev libprotobuf-c-dev protobuf-c-compiler
git clone https://github.com/CESNET/libyang.git
cd libyang
git checkout v0.16-r1
mkdir build
cd build
cmake ..
make -j4
make install
git clone https://github.com/sysrepo/sysrepo.git
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 -j4
make install
#bmv2
pip install nnpy
apt-get install -y \
automake \
cmake\
libjudy-dev\
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
git clone git@github.com:p4lang/behavioral-model.git
cd behavioral-model
git checkout tags/1.13.0
git submodule update --init --recursive
./autogen.sh
./configure
make
make install # if you need to install bmv2
#p4c
apt-get install cmake g++ git automake libtool libgc-dev bison flex libfl-dev libgmp-dev libboost-dev libboost-iostreams-dev libboost-graph-dev llvm pkg-config python python-scapy python-ipaddr python-ply tcpdump
apt-get install -y doxygen graphviz texlive-full
git clone --recursive https://github.com/p4lang/p4c.git
cd p4c
git submodule update --init --recursive
mkdir build
cd build
cmake ..
make -j4
make -j4 check
make install
ldconfig
#PI
git cloen https://github.com/p4lang/PI.git
cd PI
git submodule update --init --recursive
./configure --with-bmv2 --with-proto
make -j4
make install
ldconfig
#编译CLI
cd CLI
apt-get install libreadline-dev
make
make install
运行测试例
在/p4-rt/PI/目录下运行:
simple_switch tests/testdata/simple_router.json // to start the switch
./CLI/pi_CLI_bmv2 -c tests/testdata/simple_router.json // to start the CLI
PI CLI> assign_device 0 0 -- port=9090 // 0 0 : device id + config id
PI CLI> table_add ipv4_lpm 10.0.0.1/24 => set_nhop 10.0.0.1 1
PI CLI> table_dump ipv4_lpm
PI CLI> table_delete ipv4_lpm <handle returned by table_add>
使用gdb进行CLI调用栈查看:
(gdb) b bm_runtime::standard::StandardClient::bm_mt_add_entry
(gdb) bt
#0 bm_runtime::standard::StandardClient::bm_mt_add_entry (this=0x86f2e0, cxt_id=0, table_name="ipv4_lpm", match_key=std::vector of length 1, capacity 1 = {...},
action_name="set_nhop", action_data=std::vector of length 2, capacity 2 = {...}, options=...) at gen-cpp/bm/Standard.cpp:15558
#1 0x00007f5964b9e02c in (anonymous namespace)::add_entry (options=..., adata=<optimized out>, mkey=std::vector of length 1, capacity 1 = {...}, t_name="ipv4_lpm",
p4info=<optimized out>, dev_tgt=...) at pi_tables_imp.cpp:177
#2 _pi_table_entry_add (session_handle=session_handle@entry=0, dev_tgt=..., table_id=table_id@entry=33581985, match_key=<optimized out>,
table_entry=table_entry@entry=0x7ffc7f09c8a0, overwrite=0, entry_handle=0x7ffc7f09c878) at pi_tables_imp.cpp:393
#3 0x00007f5964fbe421 in pi_table_entry_add (session_handle=0, dev_tgt=..., table_id=table_id@entry=33581985, match_key=<optimized out>,
table_entry=table_entry@entry=0x7ffc7f09c8a0, overwrite=0, entry_handle=0x7ffc7f09c878) at pi_tables.c:110
#4 0x00007f59651ce701 in do_table_add (subcmd=<optimized out>) at table_add.c:82
#5 0x00007f59651ccf63 in dispatch_command (subcmd=0x86f3ea "ipv4_lpm", first_word=0x86f3e0 "table_add") at main.c:224
#6 process_one_cmd (cmd=0x86f3e0 "table_add") at main.c:249
#7 main (argc=<optimized out>, argv=<optimized out>) at main.c:422
#8 0x00007f5963f7b830 in __libc_start_main (main=0x400610 <main@plt>, argc=3, argv=0x7ffc7f09ca58, init=<optimized out>, fini=<optimized out>,
rtld_fini=<optimized out>, stack_end=0x7ffc7f09ca48) at ../csu/libc-start.c:291
#9 0x0000000000400669 in _start ()
(gdb)
(gdb) b bm_runtime::standard::StandardClient::bm_mt_get_entries
Breakpoint 5 at 0x7f596465cf10: file gen-cpp/bm/Standard.cpp, line 17426.
(gdb) c
Continuing.
Thread 1 "lt-pi_CLI_bmv2" hit Breakpoint 5, bm_runtime::standard::StandardClient::bm_mt_get_entries (this=0x86f2e0, _return=std::vector of length 0, capacity 0,
cxt_id=0, table_name="ipv4_lpm") at gen-cpp/bm/Standard.cpp:17426
17426 {
(gdb) bt
#0 bm_runtime::standard::StandardClient::bm_mt_get_entries (this=0x86f2e0, _return=std::vector of length 0, capacity 0, cxt_id=0, table_name="ipv4_lpm")
at gen-cpp/bm/Standard.cpp:17426
#1 0x00007f5964b9ca3c in _pi_table_entries_fetch (session_handle=session_handle@entry=0, dev_tgt=..., table_id=table_id@entry=33581985, res=res@entry=0x86f4c0)
at pi_tables_imp.cpp:670
#2 0x00007f5964fbe65c in pi_table_entries_fetch (session_handle=0, dev_tgt=..., table_id=table_id@entry=33581985, res=res@entry=0x7ffc7f09c820) at pi_tables.c:254
#3 0x00007f59651ceac7 in do_table_dump (subcmd=<optimized out>) at table_dump.c:180
#4 0x00007f59651ccf63 in dispatch_command (subcmd=0x86f61b "ipv4_lpm", first_word=0x86f610 "table_dump") at main.c:224
#5 process_one_cmd (cmd=0x86f610 "table_dump") at main.c:249
#6 main (argc=<optimized out>, argv=<optimized out>) at main.c:422
#7 0x00007f5963f7b830 in __libc_start_main (main=0x400610 <main@plt>, argc=3, argv=0x7ffc7f09ca58, init=<optimized out>, fini=<optimized out>,
rtld_fini=<optimized out>, stack_end=0x7ffc7f09ca48) at ../csu/libc-start.c:291
#8 0x0000000000400669 in _start ()
(gdb)
(gdb) b bm_runtime::standard::StandardClient::bm_mt_delete_entry
Breakpoint 6 at 0x7f596463e720: file gen-cpp/bm/Standard.cpp, line 15740.
(gdb) c
Continuing.
Thread 1 "lt-pi_CLI_bmv2" hit Breakpoint 6, bm_runtime::standard::StandardClient::bm_mt_delete_entry (this=0x86f2e0, cxt_id=0, table_name="ipv4_lpm", entry_handle=1)
at gen-cpp/bm/Standard.cpp:15740
15740 {
(gdb) bt
#0 bm_runtime::standard::StandardClient::bm_mt_delete_entry (this=0x86f2e0, cxt_id=0, table_name="ipv4_lpm", entry_handle=1) at gen-cpp/bm/Standard.cpp:15740
#1 0x00007f5964b9c27e in _pi_table_entry_delete (session_handle=<optimized out>, dev_id=0, table_id=table_id@entry=33581985, entry_handle=entry_handle@entry=1)
at pi_tables_imp.cpp:576
#2 0x00007f5964fbe575 in pi_table_entry_delete (session_handle=<optimized out>, dev_id=<optimized out>, table_id=table_id@entry=33581985,
entry_handle=entry_handle@entry=1) at pi_tables.c:169
#3 0x00007f59651ce852 in do_table_delete (subcmd=<optimized out>) at table_delete.c:52
#4 0x00007f59651ccf63 in dispatch_command (subcmd=0x86fced "ipv4_lpm", first_word=0x86fce0 "table_delete") at main.c:224
#5 process_one_cmd (cmd=0x86fce0 "table_delete") at main.c:249
#6 main (argc=<optimized out>, argv=<optimized out>) at main.c:422
#7 0x00007f5963f7b830 in __libc_start_main (main=0x400610 <main@plt>, argc=3, argv=0x7ffc7f09ca58, init=<optimized out>, fini=<optimized out>,
rtld_fini=<optimized out>, stack_end=0x7ffc7f09ca48) at ../csu/libc-start.c:291
#8 0x0000000000400669 in _start ()
(gdb)
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。