6个版本
0.1.5 | 2021年11月26日 |
---|---|
0.1.4 | 2021年2月21日 |
#16 in #fd
每月55次下载
35KB
871 代码行
vpp-api-transport
这是一个用于与VPP API交互的Rust库。
警告:接口很可能会有所改变。这个版本(至少到0.2.0)是为了测试并鼓励反馈。
想法是拥有一个实现Read和Write特质的实体,以及最终实现AsRawFd。这应该允许你在代码中使用常规套接字的地方使用它。
先决条件
Rust和操作系统依赖项
Rust
请按照https://www.rust-lang.net.cn/tools/install进行安装
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
操作系统依赖项
在Ubuntu上
sudo apt-get install build-essential libclang-10-dev
VPP客户端库
选项1 - 你的本地开发VPP树在任意位置
定义环境变量VPP_LIB_DIR,使其指向文件libvppapiclient.so所在的文件夹。你可能还需要将LD_LIBRARY_PATH设置到相同的位置。
选项2 - 从packagecloud.io的VPP客户端
按照说明设置来自https://packagecloud.io/fdio/master或分支特定的存储库,然后安装包python3-vpp-api,cargo build将在那里找到库。
用法
请参阅src/vpp-api-transport-test.rs,随着我们继续,将会有更多和更好的文档。在这里详细说明没有什么意义,因为接口将会改变。
运行cargo test
sudo apt-get install vpp vpp-plugin-core python3-vpp-api
运行示例
与运行cargo test相同的先决条件,然后
$ cargo run --release --example vpp-api-transport-test -- -h
...
Finished release [optimized] target(s) in 0.04s
Running `target/release/examples/vpp-api-transport-test -h`
vpp-api-transport version heads/main-0-gaca41b6
Andrew Yourtchenko <[email protected]>
This program is a minimum test of vpp-api-transport crate To make it somewhat useful, it can also
bench the cli_inband API execution time for various commands
USAGE:
vpp-api-transport-test [FLAGS] [OPTIONS]
FLAGS:
-h, --help Prints help information
-n, --nonblocking set non-blocking mode for the connection
-v, --verbose A level of verbosity, and can be used multiple times
-V, --version Prints version information
OPTIONS:
-c, --command <command>
Run the bench using this CLI, else use "show version"
-o, --options-override <options-override> Override options from this yaml/json file
-r, --repeat-count <repeat-count> repeat count for the command [default: 100000]
-s, --socket-path <socket-path>
Use AF_UNIX socket if this path is mentioned, else use shared memory transport
$
$ cargo run --release --example vpp-api-transport-test -- -s /run/vpp/api.sock -r 1000000
...
Finished release [optimized] target(s) in 0.04s
Running `target/release/examples/vpp-api-transport-test -s /run/vpp/api.sock -r 1000000`
Open success!
Table: MsgSockClntCreateReplyHdr { _vl_msg_id: 16, client_index: 0, context: 124, response: 0, index: 2147483649, count: 1563 }
Connect result: 0
Starting 1000000 requests of 'show version'
Still running... 270492 iterations in 5.000010229s: 54098.2893257197 per second
Still running... 539286 iterations in 10.000028579s: 53928.445877894526 per second
Still running... 854847 iterations in 15.0000489s: 56989.61421385766 per second
Ran 1000000 operations in 17.455633583s : 57288.09528712252 per second
$
$ ./target/release/examples/vpp-api-transport-test -s /run/vpp/api.sock -c "show clock" -v -v -v -r 3
Open success!
Table: MsgSockClntCreateReplyHdr { _vl_msg_id: 16, client_index: 0, context: 124, response: 0, index: 2147483649, count: 1563 }
Connect result: 0
Starting 3 requests of 'show clock'
Result:
Time now 45666.272925, Sun, 21 Feb 2021 22:20:42 GMT
Result:
Time now 45666.272982, Sun, 21 Feb 2021 22:20:42 GMT
Result:
Time now 45666.273032, Sun, 21 Feb 2021 22:20:42 GMT
Ran 3 operations in 173.171µs : 17323.9168221007 per second
$
依赖关系
~0.6–3MB
~63K SLoC