DOCA Switch 应用指南
本指南提供了一个基于 NVIDIA® BlueField® DPU 之上交换机实现的示例。
DOCA Switch 是一个网络应用,它利用 DPU 的硬件能力,用于 DPU 上表示端口之间的内部交换。
DOCA Switch 基于 DOCA Flow 库。因此,它公开了一个命令行界面,该界面接收类似 DOCA Flow 的命令,以允许实时添加规则。
DOCA Switch 被设计为在 DPU 上作为独立应用运行(所有网络流量都直接通过它)。
主机上两个虚拟机之间的流量流

从物理端口到主机上虚拟机的流量流

DOCA Switch 基于 3 个模块
命令行界面 – 接收预定义的类似 DOCA Flow 的命令并解析它们
流管道管理器 – 为每个创建的 DOCA Flow 结构生成唯一的标识号
交换核心 – 将所有模块组合在一起,并调用必要的 DOCA Flow API

端口初始化不能动态进行。所有端口都必须在使用标准 DPDK 标志运行应用程序时定义。
当添加管道或条目时,用户必须运行命令来预先创建相关的结构
可选参数必须由用户在命令行中指定;否则,将使用
NULL
成功创建管道或条目后,将打印相关 ID 以供将来使用
有关如何安装 BlueField 相关软件的详细信息,请参阅 DOCA Linux 安装指南。
DOCA 参考应用程序的安装包包含应用程序的源代码以及匹配的编译说明。这允许“按原样”编译应用程序,并提供修改源代码然后编译应用程序新版本的能力。
有关应用程序以及开发和编译技巧的更多信息,请参阅 DOCA 参考应用程序页面。
应用程序的源代码可以在应用程序的目录下找到:/opt/mellanox/doca/applications/switch/
。
编译所有应用
所有 DOCA 应用程序都在一个 meson 项目下定义。因此,默认情况下,编译包括所有应用程序。
要一起构建所有应用程序,请运行
cd /opt/mellanox/doca/applications/
meson /tmp/build
ninja -C /tmp/build
doca_switch
在 /tmp/build/switch/
下创建。
仅重新编译当前应用
要直接仅构建交换机应用程序
cd /opt/mellanox/doca/applications/
meson /tmp/build -Denable_all_applications=false
-Denable_switch=true
ninja -C /tmp/build
doca_switch
在 /tmp/build/switch/
下创建。
或者,可以在 meson_options.txt
文件中设置所需的标志,而不是在编译命令行中提供它们
编辑
/opt/mellanox/doca/applications/meson_options.txt
中的以下标志将
enable_all_applications
设置为false
将
enable_switch
设置为true
运行以下编译命令
cd /opt/mellanox/doca/applications/ meson /tmp/build ninja -C /tmp/build
信息doca_switch
在/tmp/build/switch/
下创建。
故障排除
有关应用程序编译遇到的任何问题,请参阅 DOCA 故障排除。
前提条件
交换机应用程序基于 DOCA Flow。因此,用户需要分配巨页。
$ echo '1024'
| sudo tee -a /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
$ sudo mkdir /mnt/huge
$ sudo mount -t hugetlbfs -o pagesize=2M nodev /mnt/huge
应用执行
交换机应用程序以源代码形式提供。因此,在执行应用程序之前,需要进行编译。
应用程序使用说明
Usage: doca_switch -- [DOCA Flags] DOCA Flags: -h, --help Print a help synopsis -v, --version Print program version information -l, --log-level Set the (numeric) log level
for
the program <10
=DISABLE,20
=CRITICAL,30
=ERROR,40
=WARNING,50
=INFO,60
=DEBUG,70
=TRACE> --sdk-log-level Set the SDK (numeric) log levelfor
the program <10
=DISABLE,20
=CRITICAL,30
=ERROR,40
=WARNING,50
=INFO,60
=DEBUG,70
=TRACE> -j, --json <path> Parse all command flags from an input json file Program Flags: -p, --pci Device PCI address -r, --rep Device representor -exp, --expert-mode Set expert mode信息此用法打印输出可以使用
-h
(或--help
)选项打印到命令行./doca_switch -- -h
信息有关更多信息,请参阅 “命令行标志” 部分。
在 BlueField 上运行应用程序的 CLI 示例
./doca_switch -- -p
03
:00.0
-r vf[0
-1
] -l60
注意PCIe 地址 (
03:00.0
) 应与所需 PCIe 设备的地址匹配。
命令行标志
标志类型 | 短标志 | 长标志 | 描述 | JSON 内容 |
通用标志 |
|
| 打印帮助概要 | N/A |
|
| 打印程序版本信息 | N/A | |
|
| 设置应用程序的日志级别
|
| |
N/A |
| 设置程序的日志级别
|
| |
|
| 从输入 JSON 文件解析所有命令标志 | N/A | |
程序标志 |
|
| PCI 地址 |
|
|
| 表示端口索引 |
| |
exp | expert-mode | 在专家模式下运行交换机 |
有关支持的标志和执行模式的更多信息,请参阅 DOCA Arg Parser。
支持的命令
create pipe port_id=[port_id][,<optional_parameters>]
可用可选参数name=<pipe-name>
root_enable=[1|0]
monitor=[1|0]
match_mask=[1|0]
fwd=[1|0]
fwd_miss=[1|0]
type=[basic|control]
add entry pipe_id=<pipe_id>,pipe_queue=<pipe_queue>[,<optional_parameters>]
可用可选参数monitor=[1|0]
fwd=[1|0]
add control_pipe entry priority=<priority>,pipe_id=<pipe_id>,pipe_queue=<pipe_queue>[,<optional_parameters>]
可用可选参数match_mask=[1|0]
fwd=[1|0]
destroy pipe pipe_id=<pipe_id>
rm entry pipe_queue=<pipe_queue>,entry_id=[entry_id]
port pipes flush port_id=[port_id]
port pipes dump port_id=[port_id],file=[file_name]
query entry_id=[entry_id]
create [struct] [field=value,…]
结构选项:
pipe_match
、entry_match
、match_mask
、actions
、monitor
、fwd
、fwd_miss
匹配结构字段
字段
字段选项
flags
port_meta
outer.eth.src_mac
outer.eth.dst_mac
outer.eth.type
outer.vlan_tci
outer.l3_type
ipv4
、ipv6
outer.src_ip_addr
outer.dst_ip_addr
outer.l4_type_ext
tcp
、udp
、gre
outer.tcp.flags
FIN
、SYN
、RST
、PSH
、ACK
、URG
、ECE
、CWR
outer.tcp_src_port
outer.tcp_dst_port
outer.udp_src_port
outer.udp_dst_port
tun_type
vxlan_tun_id
gre_key
gtp_teid
inner.eth.src_mac
inner.eth.dst_mac
inner.eth.type
inner.vlan_tci
inner.l3_type
ipv4
、ipv6
inner.src_ip_addr
inner.dst_ip_addr
inner.l4_type_ext
tcp
、udp
inner.tcp.flags
FIN
、SYN
、RST
、PSH
、ACK
、URG
、ECE
、CWR
inner.tcp_src_port
inner.tcp_dst_port
inner.udp_src_port
inner.udp_dst_port
动作结构字段
字段
字段选项
decap
true
、false
mod_src_mac
mod_dst_mac
mod_src_ip_type
ipv4
、ipv6
mod_src_ip_addr
mod_dst_ip_type
ipv4
、ipv6
mod_dst_ip_addr
mod_src_port
mod_dst_port
ttl
has_encap
true
、false
encap_src_mac
encap_dst_mac
encap_src_ip_type
ipv4
、ipv6
encap_src_ip_addr
encap_dst_ip_type
ipv4
、ipv6
encap_dst_ip_addr
encap_tup_type
vxlan
、gtpu
、gre
encap_vxlan-tun_id
encap_gre_key
encap_gtp_teid
FWD 结构字段
字段
字段选项
type
rss
、port
、pipe
、drop
rss_flags
rss_queues
num_of_queues
port_id
next_pipe_id
Monitor 结构字段
flags
cir
cbs
aging
物理端口号(仅支持一个物理端口)始终为 0,所有表示端口的编号从 1 到 N,其中 N 是正在使用的表示端口的数量。例如
物理端口 ID:0
VF0 表示端口 ID:1
VF1 表示端口 ID:2
VF2 表示端口 ID:3
以下是创建管道并在其中添加一个条目的示例
create fwd type=port,port_id=0xffff
create pipe port_id=0
,name=p0_to_vf1,root_enable=1
,fwd=1
create fwd type=port,port_id=1
add entry pipe_queue=0
,fwd=1
,pipe_id=1012
....
rm entry pipe_queue=0
,entry_id=447
管道在端口 ID 0(物理端口)上配置。
条目配置为将所有流量直接转发到端口 ID 1 (VF0)。
当不再需要转发规则时,将删除该条目。
最终,两个条目都将被删除,每个条目都根据其被赋予的唯一随机 ID 删除
故障排除
有关 DOCA 应用程序的安装或执行遇到的任何问题,请参阅 DOCA 故障排除。
解析应用程序参数。
初始化参数解析器资源并注册 DOCA 通用参数。
doca_argp_init();
注册 DOCA Flow 交换机模式应用程序参数。
register_doca_flow_switch_param();
解析应用程序参数。
doca_argp_start();
启动 DOCA Flow 交换机模式应用程序参数。
init_doca_flow_switch_common();
初始化 DPDK 端口和队列。
dpdk_queues_and_ports_init();
初始化 DOCA Switch。
switch_init();
初始化 DOCA Flow。
创建端口对。
创建 Flow Pipes Manger 模块。
为每个相关的 CLI 命令注册一个动作。
初始化 Flow Parser。
flow_parser_init();
重置所有内部 Flow Parser 结构。
启动命令行界面。
接收用户命令,解析它们,并调用所需的 DOCA Flow API 命令。
一旦输入 “quit” 命令,关闭交互式 shell。
清理 Flow Parser 资源。
flow_parser_cleanup();
销毁 Switch 资源。
switch_destroy();
销毁 Flow Pipes Manager 资源。
销毁 DOCA Flow。
switch_destroy();
销毁 DPDK 端口和队列。
dpdk_queues_and_ports_fini();
DPDK 结束。
dpdk_fini();
调用
rte_eal_destroy()
以销毁初始化的 EAL 资源。
参数解析器销毁。
doca_argp_destroy();
/opt/mellanox/doca/applications/switch/