官方文档查看地址:
http://doc.dpdk.org/guides/sample_app_ug/ip_pipeline.html
PDF下载地址:
https://www.intel.com/content/www/us/en/embedded/technology/packet-processing/dpdk/dpdk-sample-applications-user-guide.html?eu-cookie-notice
本篇难度系数:
翻译:☆☆☆☆☆
理解:★★☆☆☆
40.1.应用程序概述
因特网协议(IP)管道应用旨在成为在多核cpu上快速开发包处理应用程序的载体。
遵循OpenFlow和P4设计原则,可以使用该应用程序以模块化的方式从输入/输出端口、表和操作创建名为管道的功能块。多个管道可以通过包队列相互连接,从而创建完整的应用程序(超级管道)。
管道映射到应用程序线程,每个管道由一个线程执行,每个线程能够运行一个或多个管道。从端口、表和操作创建管道、将多个管道连接在一起并将管道映射到执行线程的可能性是无穷无尽的,因此这个应用程序可以看作是一个真正的应用程序生成器。
管道通过命令行接口(CLI)创建和管理:
任何标准TCP客户机(例如telnet、netcat、自定义脚本等)通常都能够连接到应用程序,通过网络发送命令,并等待响应,然后再执行下一个命令。
所有的应用对象都是通过CLI命令创建和管理的:
用于创建管道端口的“基本”对象:内存池、链接(即网络接口)、SW队列、流量管理器等。
操作概要:用于定义管道输入/输出端口和表要执行的操作。
管道组件:输入/输出端口、表、管道、管道到执行线程的映射。
40.2.运行应用程序
应用程序启动命令行为:
ip_pipeline [EAL_ARGS] -- [-s SCRIPT_FILE] [-h HOST] [-p PORT]
应用程序启动参数是:
-s SCRIPT_FILE
可选:是的
默认值:不存在
参数:应用程序启动时运行的CLI脚本文件的路径。如果不存在此参数,则不会在启动时运行CLI脚本文件。-h Host
可选:是的
默认值:0.0.0.0
参数:运行IP管道应用程序的主机的IP地址,用于基于远程TCP的客户机(telnet、netcat等)连接。-p Port
可选:是的
默认值:8086
参数:正在运行ip管道的TCP端口号。远程TCP客户机(如telnet、netcat等)应该使用这个端口号连接到主机应用程序。
有关运行应用程序和环境抽象层(EAL)选项的一般信息,请参阅DPDK入门指南(DPDK Getting Started Guide)。
下面是一个示例命令,用于运行为第2层转发配置的ip管道应用程序:
$ ./build/ip_pipeline -c 0x3 -- -s examples/route_ecmp.cli
应用程序应成功启动并显示如下:
EAL: Detected 40 lcore(s)
EAL: Detected 2 NUMA nodes
EAL: Multi-process socket /var/run/.rte_unix
EAL: Probing VFIO support...
EAL: PCI device 0000:02:00.0 on NUMA socket 0
EAL: probe driver: 8086:10fb net_ixgbe
...
运行远程客户端(例如telnet)与ip管道应用程序通信:
$ telnet 127.0.0.1 8086
当运行上述telnet客户端时,会显示命令提示符:
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Welcome to IP Pipeline!
pipeline>
一旦应用程序和telnet客户机开始运行,消息就可以从客户机发送到应用程序。在任何阶段,都可以使用quit命令终止telnet客户机。
40.3.应用程序阶段
40.3.1初始化
在此阶段,初始化EAL层并解析特定于应用程序的参数。此外,应用程序对象的数据结构(即链表)也被初始化。在任何初始化错误的情况下,将显示一条错误消息并终止应用程序。
40.3.2运行时
主线程根据CLI输入创建和管理所有应用程序对象。
每个数据平面线程运行一个或多个以前按循环顺序分配给它的管道。每个数据平面线程在分时模式下执行两项任务:
1.包处理任务:处理从管道输入端口读取的输入包的突发事件。
2.消息处理任务:数据平面线程周期性地暂停包处理任务,并轮询主线程发送的请求消息。例如:从当前数据平面线程中添加/删除管道,从当前数据平面线程拥有的特定管道的给定表中添加/删除规则,读取统计信息等。
40.4.例子
Name | Table(s) | Actions | Messages |
---|---|---|---|
L2fwd | Stub | Forward | Mempool create Link create Pipeline create Pipeline port in/out Pipeline table Pipeline port in table Pipeline enable Pipeline table rule add |
Flow classification | Exact match Key = byte array (16 bytes) Offset = 278 Table size = 64K | Forward | 1.Mempool create 2.Link create 3.Pipeline create 4.Pipeline port in/out 5.Pipeline table 6.Pipeline port in table 7.Pipeline enable 8.Pipeline table rule add default 9.Pipeline table rule add |
KNI | Stub | Forward | Mempool create Link create Pipeline create Pipeline port in/out Pipeline table Pipeline port in table Pipeline enable Pipeline table rule add |
Firewall | ACL Key = n-tuple Offset = 270 Table size = 4K | Allow/Drop | Mempool create Link create Pipeline create Pipeline port in/out Pipeline table Pipeline port in table Pipeline enable Pipeline table rule add default Pipeline table rule add |
IP routing | LPM (IPv4) Key = IP dest addr Offset = 286 Table size = 4K | Forward | Mempool Create Link create Pipeline creat Pipeline port in/out Pipeline table Pipeline port in table Pipeline enable Pipeline table rule add default Pipeline table rule add |
Equal-cost multi-path routing (ECMP) | LPM (IPv4) Key = IP dest addr Offset = 286 Table size = 4K Array Key = Array index Offset = 256 Size = 4K | Forward, load balance, encap ether | Mempool Create Link create Pipeline create Pipeline port in/out Pipeline table (LPM) Pipeline table (Array) Pipeline port in table (LPM) Pipeline enable Pipeline table rule add default Pipeline table rule add(LPM) Pipeline table rule add(Array) |
40.5.Command Line Interface (CLI)
40.5.1. Link
link配置
link <link_name>
dev <device_name>|port <port_id>
rxq <n_queues> <queue_size> <mempool_name>
txq <n_queues> <queue_size> promiscuous on | off
[rss <qid_0> ... <qid_n>]
注意:PCI设备名称必须用Domain:Bus:Device.Function格式。
40.5.2. Mempool
Mempool 创建
mempool <mempool_name> buffer <buffer_size>
pool <pool_size> cache <cache_size> cpu <cpu_id>
40.5.3. Software queue
创建软件队列
swq <swq_name> size <size> cpu <cpu_id>
40.5.4. Traffic manager(流量管理器TM)
添加流量管理器子端口配置文件
tmgr subport profile
<tb_rate> <tb_size>
<tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate>
<tc_period>
添加流量管理器管道配置文件
tmgr pipe profile
<tb_rate> <tb_size>
<tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate>
<tc_period>
<tc_ov_weight> <wrr_weight0..15>
创建流量管理器端口
tmgr <tmgr_name>
rate <rate>
spp <n_subports_per_port>
pps <n_pipes_per_subport>
qsize <qsize_tc0>
<qsize_tc1> <qsize_tc2> <qsize_tc3>
fo <frame_overhead> mtu <mtu> cpu <cpu_id>
配置流量管理器子端口
tmgr <tmgr_name>
subport <subport_id>
profile <subport_profile_id>
配置流量管理器管道
tmgr <tmgr_name>
subport <subport_id>
pipe from <pipe_id_first> to <pipe_id_last>
profile <pipe_profile_id>
40.5.5. Tap
Create tap port
tap <name>
40.5.6. Kni
创建kni端口
kni <kni_name>
link <link_name>
mempool <mempool_name>
[thread <thread_id>]
40.5.7. Cryptodev
Create cryptodev port
cryptodev <cryptodev_name>
dev <DPDK Cryptodev PMD name>
queue <n_queues> <queue_size>
40.5.8操作配置文件
为管道输入端口创建操作概要文件
port in action profile <profile_name>
[filter match | mismatch offset <key_offset> mask <key_mask> key <key_value> port <port_id>]
[balance offset <key_offset> mask <key_mask> port <port_id0> ... <port_id15>]
为pipeline表创建操作概要文件
table action profile <profile_name>
ipv4 | ipv6
offset <ip_offset>
fwd
[balance offset <key_offset> mask <key_mask> outoffset <out_offset>]
[meter srtcm | trtcm
tc <n_tc>
stats none | pkts | bytes | both]
[tm spp <n_subports_per_port> pps <n_pipes_per_subport>]
[encap ether | vlan | qinq | mpls | pppoe]
[nat src | dst
proto udp | tcp]
[ttl drop | fwd
stats none | pkts]
[stats pkts | bytes | both]
[sym_crypto cryptodev <cryptodev_name>
mempool_create <mempool_name> mempool_init <mempool_name>]
[time]
40.5.9. Pipeline
创建管道
pipeline <pipeline_name>
period <timer_period_ms>
offset_port_id <offset_port_id>
cpu <cpu_id>
创建管道输入端口
pipeline <pipeline_name> port in
bsz <burst_size>
link <link_name> rxq <queue_id>
| swq <swq_name>
| tmgr <tmgr_name>
| tap <tap_name> mempool <mempool_name> mtu <mtu>
| kni <kni_name>
| source mempool <mempool_name> file <file_name> bpp <n_bytes_per_pkt>
[action <port_in_action_profile_name>]
[disabled]
创建管道输出端口
pipeline <pipeline_name> port out
bsz <burst_size>
link <link_name> txq <txq_id>
| swq <swq_name>
| tmgr <tmgr_name>
| tap <tap_name>
| kni <kni_name>
| sink [file <file_name> pkts <max_n_pkts>]
创建管道表
pipeline <pipeline_name> table
match
acl
ipv4 | ipv6
offset <ip_header_offset>
size <n_rules>
| array
offset <key_offset>
size <n_keys>
| hash
ext | lru
key <key_size>
mask <key_mask>
offset <key_offset>
buckets <n_buckets>
size <n_keys>
| lpm
ipv4 | ipv6
offset <ip_header_offset>
size <n_rules>
| stub
[action <table_action_profile_name>]
将管道输入端口连接到表
pipeline <pipeline_name> port in <port_id> table <table_id>
显示特定管道输入端口、输出端口或表的统计信息
pipeline <pipeline_name> port in <port_id> stats read [clear]
pipeline <pipeline_name> port out <port_id> stats read [clear]
pipeline <pipeline_name> table <table_id> stats read [clear]
为特定管道实例启用给定的输入端口
pipeline <pipeline_name> port out <port_id> disable
禁用特定管道实例的给定输入端口
pipeline <pipeline_name> port out <port_id> disable
将特定管道实例的默认规则添加到表中
pipeline <pipeline_name> table <table_id> rule add
match
default
action
fwd
drop
| port <port_id>
| meta
| table <table_id>
为特定管道实例向表中添加规则
pipeline <pipeline_name> table <table_id> rule add
match
acl
priority <priority>
ipv4 | ipv6 <sa> <sa_depth> <da> <da_depth>
<sp0> <sp1> <dp0> <dp1> <proto>
| array <pos>
| hash
raw <key>
| ipv4_5tuple <sa> <da> <sp> <dp> <proto>
| ipv6_5tuple <sa> <da> <sp> <dp> <proto>
| ipv4_addr <addr>
| ipv6_addr <addr>
| qinq <svlan> <cvlan>
| lpm
ipv4 | ipv6 <addr> <depth>
action
fwd
drop
| port <port_id>
| meta
| table <table_id>
[balance <out0> ... <out7>]
[meter
tc0 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
[tc1 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
tc2 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
tc3 meter <meter_profile_id> policer g <pa> y <pa> r <pa>]]
[tm subport <subport_id> pipe <pipe_id>]
[encap
ether <da> <sa>
| vlan <da> <sa> <pcp> <dei> <vid>
| qinq <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid>
| mpls unicast | multicast
<da> <sa>
label0 <label> <tc> <ttl>
[label1 <label> <tc> <ttl>
[label2 <label> <tc> <ttl>
[label3 <label> <tc> <ttl>]]]
| pppoe <da> <sa> <session_id>]
[nat ipv4 | ipv6 <addr> <port>]
[ttl dec | keep]
[stats]
[time]
[sym_crypto
encrypt | decrypt
type
| cipher
cipher_algo <algo> cipher_key <key> cipher_iv <iv>
| cipher_auth
cipher_algo <algo> cipher_key <key> cipher_iv <iv>
auth_algo <algo> auth_key <key> digest_size <size>
| aead
aead_algo <algo> aead_key <key> aead_iv <iv> aead_aad <aad>
digest_size <size>
data_offset <data_offset>]
where:
<pa> ::= g | y | r | drop
为特定管道实例向表中添加批量规则
pipeline <pipeline_name> table <table_id> rule add bulk <file_name> <n_rules>
Where:
- file_name = path to file
- File line format = match <match> action <action>
删除特定管道实例的表规则
pipeline <pipeline_name> table <table_id> rule delete
match <match>
删除特定管道实例的默认表规则
pipeline <pipeline_name> table <table_id> rule delete
match
default
为特定管道实例向表中添加仪表配置文件
pipeline <pipeline_name> table <table_id> meter profile <meter_profile_id>
add srtcm cir <cir> cbs <cbs> ebs <ebs>
| trtcm cir <cir> pir <pir> cbs <cbs> pbs <pbs>
从表中删除特定管道实例的仪表配置文件
pipeline <pipeline_name> table <table_id>
meter profile <meter_profile_id> delete
为特定管道实例的表或流量管理器操作更新dscp表
pipeline <pipeline_name> table <table_id> dscp <file_name>
Where:
- file_name = path to file
- exactly 64 lines
- File line format = <tc_id> <tc_queue_id> <color>, with <color> as: g | y | r
40.5.10管道启用/禁用
为特定的数据平面线程启用给定的管道实例
thread <thread_id> pipeline <pipeline_name> enable
禁用特定数据平面线程的给定管道实例
thread <thread_id> pipeline <pipeline_name> disable