repo:Github PI
P4Runtime - a control plane framework and tools for the P4 programming language
这个是P4社区目前正在开发的一个repo,根据它给的介绍,是一个控制平面的架构,提供了管理P4交换机的工具。接下来持续跟进它。
首先要安装相关依赖:
sudo apt-get install libjudy-dev libreadline-dev
git submodule update --init --recursive
配置:
./autogen.sh
./configure [--with-bmv2] [--with-proto]
如果安装了bmv2,加上--with-bmv2
;如果要使用p4runtime.proto 则需要安装Google的protobuf。
使用bmv2参数配置信息如下:
Features recap ......................................
Compile for bmv2 ............................. : yes
simple_switch found ........................ : yes
Compile C++ frontend ......................... : no
Compile p4runtime.proto and associated fe .... : no
Compile internal RPC ......................... : yes
Compile PI C CLI ............................. : yes
make
make不报错则证明安装成功了。
实验
Terminal A:
simple_switch tests/testdata/simple_router.json
启动交换机;
Terminal B:
./CLI/pi_CLI_bmv2 -c tests/testdata/simple_router.json
启动CLI;
在CLI中可以对交换机进行相关配置:
PI CLI> assign_device 0 -- port=9090
Device assigned successfully.
Selecting device.
PI CLI> table_add ipv4_lpm 10.0.0.1/24 => set_nhop 10.0.0.1 1
Entry was successfully added with handle 0.
PI CLI> table_dump ipv4_lpm
Successfully retrieved 1 entrie(s).
==========
TABLE ENTRIES
**********
Dumping entry 0
Match key:
* ipv4.dstAddr : LPM 0a000001/24
Action entry: set_nhop - 0a000001, 0001
==========
Dumping default entry
EMPTY
==========
PI CLI> table_delete ipv4_lpm 0
Entry with handle 0 was successfully removed.
PI CLI>
PI CLI> help
commands description
quit Exits CLI
help Print this message
add_p4 Add a P4 configuration and receive an ID for it, default config type is bmv2: add_p4 <path_to_config> [bmv2|native]*
assign_device Assign a specific device, if no device selected currently, it will select the newly device: assign_device <device_id> [p4_config_id] [-- [key=v;]*]
select_device Select a specific device by id, the device must have been assigned previously: select_device <device_id>
remove_device Remove a specific device: remove_device <device_id>
show_devices Show known devices, with available information: show_devices
update_device_start Update the P4 config on the selected device, update_device_start <p4_config_id> <device_data_path>
update_device_end End the P4 config update sequence on the selected device, update_device_start
table_add Add entry to a match table: table_add <table name> <match fields> [priority] => [<action name> <action parameters> | <indirect handle>]
table_delete Delete entry from a match table: table_delete <table name> <entry handle>
table_delete_wkey Delete entry from a match table using the match key: table_delete_wkey <table name> <match fields> [priority]
table_modify Modify entry in a match table: table_modify <table name> <entry_handle> => [<action name> <action parameters> | <indirect handle>]
table_modify_wkey Modify entry in a match table using the match key: table_modify_wkey <table name> <match fields> [priority] => [<action name> <action parameters> | <indirect handle>]
table_set_default Set default entry in a match table: table_set_default <table name> [<action name> <action parameters> | <indirect handle>]
table_dump Dump all entries in a match table: table_dump <table name>
act_prof_create_member Add a member to an action profile: act_prof_create_member <act_prof_name> <action_name> [action parameters]
act_prof_create_group Add group to an action profile: act_prof_create_group <act_prof_name> [grp_size = 120]
act_prof_add_member_to_group Add member to a group in an action profile: act_prof_add_member_to_group <act_prof_name> <mbr_h> <grp_h>
act_prof_dump Dump entries of action profile: act_prof_dump <act_prof_name>
counter_read Read value(s) from counter: counter_read <counter name> <index | entry handle>
counter_write Write value(s) to counter: counter_write <counter name> <index | entry handle> [packets=<N>] [bytes=<N>]
counter_reset Reset values for counter to 0: counter_reset <counter name> <index | entry handle>
meter_read_spec Read meter spec: meter_read_spec <meter name> <index | entry handle>
meter_set Set meter spec: meter_set <meter name> <index | entry handle> <rate_1>:<burst_1> <rate_2>:<burst_2>
direct_res_reset Remove direct resource configs which are kept ready for next table_add: direct_res_reset
2017.4.5