在這篇文章中,我將帶您了解 FRR DOCA 數據平面插件 的創建過程,并向您展示如何使用全新的 DOCA?flow 庫卸載 PBR 規則。在上一篇文章中,您了解了使用 DPDK rte_flow
庫創建 FRR 數據平面插件,以加速 BlueField 上的 PBR 規則。有關內容,請參見 使用 NVIDIA BlueField DPU 和 DPDK 開發應用程序 .
向 Zebra 添加 DOCA 數據平面插件
我仍然使用 DPDK API 進行硬件初始化,但隨后使用 DOCA?flow API 來設置數據平面流管道。為此,我必須將 DPDK (libdpdk.pc
)和 DOCA?flow(doca-flow.pc
)共享庫鏈接到 DOCA 數據平面插件。
root@dpu-arm:~# export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/opt/mellanox/dpdk/lib/aarch
64-linux-gnu/pkgconfig
root@dpu-arm:~# pkg-config --libs doca-flow
-ldoca_flow
root@dpu-arm:~# pkg-config --cflags doca-flow
-DALLOW_EXPERIMENTAL_API -include rte_config.h -mcpu=cortex-a72 -DALLOW_EXPERIMENTAL_API -I/opt/mellanox/dpdk/include/dpdk -I/opt/mellanox/dpdk/include/dpdk/../aarch64-linux-gnu/dpdk -I/opt/mellanox/dpdk/include/dpdk -I/usr/include/libnl3
root@dpu-arm:~#
我在 FRR makefile (configure.ac
)中為 DPDK 和 DOCA?flow添加了pkg check-and-define
宏。
if test "$enable_dp_doca" = "yes"; then
PKG_CHECK_MODULES([DOCA], [libdpdk doca-flow], [
AC_DEFINE([HAVE_DOCA], [1], [Enable DOCA backend])
DOCA=true
], [
AC_MSG_ERROR([configuration specifies --enable-dp-doca but DOCA libs were not found])
])
fi
我將 DPDK 和 DOCA flow
庫?及 cflags
都包含在zebra-dp-doca make
宏(zebra/subdir.am
)中。
zebra_zebra_dplane_doca_la_CFLAGS = $(DOCA_CFLAGS)
zebra_zebra_dplane_doca_la_LIBADD = $(DOCA_LIBS)
使用/etc/frr/daemons
啟動 FRR 服務時,可以啟用 DOCA 數據平面插件。
zebra_options= " -M dplane_doca -A 127.0.0.1"
硬件初始化和端口映射
使用 DPDK API 、rte_eal_init
和rte_eth_dev_info_get
初始化硬件,并設置 Zebra 接口到 DPDK 端口映射。此工作流與上一節中的 DPDK 數據平面插件相同。
root@dpu-arm:~# vtysh -c "show dplane doca port"
Total ports: 6 cores: 8
Port Device IfName IfIndex sw,domain,port
0 0000:03:00.0 p0 4 0000:03:00.0,0,65535
1 0000:03:00.0 pf0hpf 6 0000:03:00.0,0,4095
2 0000:03:00.0 pf0vf0 15 0000:03:00.0,0,4096
3 0000:03:00.0 pf0vf1 16 0000:03:00.0,0,4097
4 0000:03:00.1 p1 5 0000:03:00.1,1,65535
5 0000:03:00.1 pf1hpf 7 0000:03:00.1,1,20479
root@dpu-arm:~#
DOCA?flow初始化
為了使用doca-flow
編寫 PBR 規則,我必須初始化doca-flow
和doca-flow-port
數據庫。此初始化是在使用rte_eal_init
初始化硬件后完成的。
我使用 doca_flow_init 通過配置流和隊列計數來初始化doca-flow
庫。
struct doca_flow_cfg flow_cfg; memset(&flow_cfg, 0, sizeof(flow_cfg)); flow_cfg.total_sessions = ZD_DOCA_FLOW_MAX; flow_cfg.queues = doca_ctx->nb_cores; doca_flow_init (&flow_cfg, &err);
當我使用 DPDK 設置硬件端口時,我必須使用dpdk_port-id
將它們安裝到doca-flow-port
數據庫中。
struct doca_flow_port_cfg port_cfg;
memset(&port_cfg, 0, sizeof(port_cfg));
port_cfg.port_id = dpdk_port_id;
port_cfg.type = DOCA_FLOW_PORT_DPDK_BY_ID;
snprintf(port_id_str, ZD_PORT_STR_MAX, "%u", port_cfg.port_id);
port_cfg.devargs = port_id_str;
doca_port = doca_flow_port_start (&port_cfg, &err);
使用 doca-flow API 編寫 PBR 規則
通過一系列用于匹配、動作、轉發和監控屬性的數據結構來對 DOCA 流進行編程。
struct doca_flow_match match, match_mask;
struct doca_flow_actions actions;
struct doca_flow_fwd fwd;
struct doca_flow_monitor monitor;
流匹配
這被指定為匹配和匹配掩碼。匹配掩碼是可選的,如果未指定,則由doca-flow
庫自動填充。
memset(&match, 0, sizeof(match));
memset(&match_mask, 0, sizeof(match_mask));
match.out_src_ip.type = DOCA_FLOW_IP4_ADDR;
match.out_src_ip.ipv4_addr = src_ip;
match_mask.out_src_ip.ipv4_addr = src_ip_mask;
match.out_dst_ip.type = DOCA_FLOW_IP4_ADDR;
match.out_dst_ip.ipv4_addr = dst_ip;
match_mask.out_src_ip.ipv4_addr = dst_ip_mask;
match.out_l4_type = ip_proto;
match.out_src_port = RTE_BE16 (l4_src_port);
match_mask.out_src_port = UINT16_MAX;
match.out_dst_port = RTE_BE16 (l4_dst_port);
match_mask.out_dst_port = UINT16_MAX;
我跳過了填充eth
或eth-mask
等字段。這是因為doca-flow
庫可以基于其他匹配字段dst_ip
或src_ip
自動將此類字段填充到RTE_ETHER_TYPE_IPV4
或RTE_ETHER_TYPE_IPV6
。
流動作
為了路由數據包,我必須將目標 MAC 地址更改為網關( leaf2 ) MAC ,減少 TTL ,并更改源 MAC 地址。這一點最初在上一篇文章中討論, 使用 NVIDIA BlueField DPU 和 DPDK 開發應用程序 .
memset(&actions, 0, sizeof(actions)); actions.dec_ttl = true; memcpy(actions.mod_src_mac, uplink_mac, DOCA_ETHER_ADDR_LEN); memcpy(actions.mod_dst_mac, gw_mac, DOCA_ETHER_ADDR_LEN);
流轉發
然后,我將輸出端口設置為上行鏈路。
memset(&fwd, 0, sizeof(fwd));
fwd.type = DOCA_FLOW_FWD_PORT;
fwd.port_id = out_port_id;
流監控
我設置了流量計數器進行故障排除。
memset(&monitor, 0, sizeof(monitor)); monitor.flags |= DOCA_FLOW_MONITOR_COUNT;
DOCA?流管道和入口
流程創建分為兩步:
- 創建流管道.
- 將流條目添加到流管道。
第一步是為查找階段創建軟件模板。第二步使用模板在硬件中的流進行編程。
當您必須對許多類似的流進行編程時,管道非常有用。對于這種情況,可以設置單個匹配模板(管道),并指示在創建流條目時必須更新哪個匹配字段(例如,第 4 層目標端口)。后續的流條目只需要 填充與管道(第 4 層目標端口)不同的匹配字段。
對于 PBR ,每個流模式都是唯一的,所以我使用已經填充的流屬性為每個 PBR 規則創建了一個單獨的管道和條目。
struct doca_flow_pipe_cfg pipe_cfg;
pipe_cfg.name = "pbr";
pipe_cfg.port = in_dport->doca_port;
pipe_cfg.match = &match;
pipe_cfg.match_mask = &match_mask;
pipe_cfg.actions = &actions;
pipe_cfg.monitor = &monitor;
pipe_cfg.is_root = true;
flow_pipe = doca_flow_create_pipe (&pipe_cfg, &fwd, NULL, &err);
flow_entry = doca_flow_pipe_add_entry (0, flow_pipe, &match, &actions, &monitor, &fwd, &err);
流刪除
流管道和條目創建 API 返回管道和流指針,這些指針必須被緩存以供后續刪除。
doca_flow_pipe_rm_entry( 0, flow_entry);
doca_flow_destroy_pipe (port_id, flow_pipe);
流統計
在創建流時,我設置了DOCA_FLOW_MONITOR_COUNT
標志。我使用doca_flow_query
查詢了流統計數據。
struct doca_flow_query query ;
// hit counters – query.total_pkts and query.total_bytes
memset(&query, 0, sizeof(query));
doca_flow_query (flow_entry, &query);
驗證硬件加速
FRR-PBR 規則配置和流量生成與dpdk-plugin
相同。流量按預期由 DPU 硬件轉發,并可使用流計數器進行驗證。
root@dpu-arm:~# vtysh -c "show dplane doca pbr flow" Rules if pf0vf0 Seq 1 pri 300 SRC IP Match: 172.20.0.8/32 DST IP Match: 172.30.0.8/32 IP protocol Match: 17 DST Port Match: 53 Tableid: 10000 Action: nh: 192.168.20.250 intf: p0 Action: mac: 00:00:5e:00:01:fa DOCA flow: installed 0xffff28005150 DOCA stats: packets 202 bytes 24644 root@dpu-arm:~#
還可以使用硬件條目進行驗證:
root@dpu-arm:~# ~/mlx_steering_dump/mlx_steering_dump_parser.py -p `pidof zebra` -
f /tmp/dpdkDump
domain 0xe294002, table 0xaaab07648b10, matcher 0xffff28012c30, rule 0xffff28014040
match: outer_l3_type: 0x1, outer_ip_dst_addr: 172.30.0.8, outer_l4_type: 0x2, metadata_reg_c_0: 0x00030000, outer_l4_dport: 0x0035, outer_ip_src_addr: 172.20.0.8
action: MODIFY_HDR(hdr(dec_ip4_ttl)), rewrite index 0x0 & VPORT, num 0xffff & CTR(hits(352), bytes(42944)), index 0x806200
通過使用 doca-flow
,FRR 現在具有了第二個數據平面插件,可用于 PBR 規則的硬件加速。
應用程序開發要點
在本系列文章中,您了解了如何使用rte_flow
或doca_flow
通過四個步驟對 DPU 網絡應用程序進行硬件加速:
- 將 DOCA / DPDK 庫鏈接到應用程序。
- 初始化硬件。
- 設置應用程序到硬件端口的映射。
- 用于引導流量的流編程。
隨著越來越多的元素卸載到DPU 上,及源代碼行( SLOC )的增加,開發過程可能會變得復雜。而這正是 DOCA 抽象庫可以幫助解決的:
- DOCA 附帶了幾個內置庫,如
doca-dpi
、 gRPC 、 Firefly 時間同步等。這些庫支持應用程序的快速即插即用。 - DOCA 構建(如
doca_pipe
)使您能夠模板化管道,消除樣板代碼并優化流插入。 - 即將推出的 DOCA 庫,如硬件加速的 LPM (最長前綴匹配),使構建交換機管道變得更容易。這與您在本系列文章中看到的示例應用程序 FRR 尤其相關, FRR 通常用于使用 BGP 構建 LPM 路由表(或 RIB )。
- 借助 DOCA ,您還可以在融合加速器上的 GPU 和 DPU?上實現令人激動的開發體驗。
你準備好讓你的應用程序開發達到令人敬仰的高度了嗎?報名參加 DOCA 提前進入 開發商計劃今天開始建設.
有關更多信息,請參閱以下參考資料:
- NVIDIA 推出 BlueField DPU 作為 DOCA 1.2 的零信任安全平臺
- 用 NVIDIA DOCA 1.2 / A]構建零信任安全基礎
- DOCA BlueField NVIDIA DOCA 簡介 DLI 課程
- 基于 DPU 的硬件加速:軟件視角
?