P4Runtime - a control plane framework and tools for the P4 programming language
這個是P4社區目前正在開發的一個repo,根據它給的介紹,是一個控制平面的架構,提供了管理P4交換機的工具。接下來持續跟進它。git
首先要安裝相關依賴:github
sudo apt-get install libjudy-dev libreadline-dev git submodule update --init --recursive
配置:json
./autogen.sh ./configure [--with-bmv2] [--with-proto]
若是安裝了bmv2,加上--with-bmv2
;若是要使用p4runtime.proto 則須要安裝Google的protobuf。架構
使用bmv2參數配置信息以下:frontend
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:ui
simple_switch tests/testdata/simple_router.json
啓動交換機;this
Terminal B:code
./CLI/pi_CLI_bmv2 -c tests/testdata/simple_router.json
啓動CLI;orm
在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