DPDK — L3 Forwarding 与 PLM IP 地址匹配算法
创始人
2025-05-31 15:36:01
0

目录

文章目录

  • 目录
  • L3 Forwarding Application
  • 安装部署
    • 部署拓扑
    • 编译运行 L3fwd
    • 测试 L3 转发功能
    • 性能参数
  • 实现分析

L3 Forwarding Application

L3 Forwarding Application 是一个实现了 LPM(Longest prefix match,最长前缀匹配)路由选择算法的 IP 数据包转发应用程序。此外,它还实现了负载均衡和多路径转发等功能,以提高网络的吞吐量和性能。

rte_lpm 库提供了高效的 LPM 算法,可以在大规模路由表上快速查找路由。

安装部署

部署拓扑

                      |----------------||     l3fwd      ||                ||  eth1   eth2   |1.1.1.1 |----|------|----|  2.1.1.152:54:00:5E:8C:DF      |      |       52:54:00:A7:A7:F6/        \/          \/            \/              \52:54:00:4a:1f:6d   /                \   52:54:00:53:5a:d21.1.1.2   |                  |  2.1.1.2|--------|------|   |-------|-------||      eth1     |   |     eth2      ||               |   |               ||    server0    |   |    server1    ||---------------|   |---------------|

编译运行 L3fwd

  • 编译
$ cat dpdk.rc
export RTE_SDK=/opt/dpdk-18.08
export RTE_TARGET=x86_64-native-linuxapp-gcc
export DPDK_BUILD=${DPDK_DIR}/${RTE_TARGET}
export LD_LIBRARY_PATH=${RTE_SDK}/${RTE_TARGET}/lib:/usr/local/lib:/usr/lib:$ source dpdk.rc$ cd ${RTE_SDK}/examples/l3fwd
$ make
$ ll build/l3fwd
  • 指令行格式
    • -p PORTMASK:指定要使用的 Ports 的十六进制位掩码(Bitmap)。
    • -P:将所有 Ports 都设置为混杂模式,使得无论 Frame 的 dstMAC 是不是本地网卡都可以接收。
    • -E:启用精确匹配算法(Exact match)。
    • -L:启动最长前缀匹配算法(Longest prefix match)。
    • –config:指示 port、queue、lcore 的映射关系。
    • –eth dest:指示 PortX 的 dstMAC 地址。
    • –enable-jumbo:启用 Jumbo 数据帧。
    • –max-pkt-len:在启用 Jumbo 的前提下,以十进制表示最大的数据包长度。
    • –no-numa:禁用 NUMA 亲和。
    • –hash-entry-num:指示十六进制 HASH Entry 的数量。
./l3fwd [EAL options] -- -p PORTMASK[-P][-E][-L]--config(port,queue,lcore)[,(port,queue,lcore)][--eth-dest=X,MM:MM:MM:MM:MM:MM][--enable-jumbo [--max-pkt-len PKTLEN]][--no-numa][--hash-entry-num][--ipv6][--parse-ptype]
  • 运行
    • -l 1:只使用一个 lcore,因为测试机的网卡不支持多队列,而 l3fwd 会为每个 lcore 分配一个 Tx queue,所以只能使用 1 个 lcore,否则会在 rte_eth_dev_configure() 的时候失败。
    • 52:54:00:4a:1f:6d - server0 eth1 发出的 Frame 的 dstMAC 地址。因为 l3fwd 没有 ARP 协议,所以需要手动指定每个 Ports 的 dstMAC。
    • 52:54:00:53:5a:d2- server1 eth2 发出的 Frame 的 dstMAC 地址。
./build/l3fwd -l 1 -- -p 0x3 -P --config="(0,0,1),(1,0,1)" --parse-ptype --eth-dest=0,52:54:00:4a:1f:6d --eth-dest=1,52:54:00:53:5a:d2soft parse-ptype is enabled
LPM or EM none selected, default LPM onInitializing port 0 ... Creating queues: nb_rxq=1 nb_txq=1... Port 0 modified RSS hash function based on hardware support,requested:0xa38c configured:0Address:52:54:00:5E:8C:DF, Destination:52:54:00:4A:1F:6D, Allocated mbuf pool on socket 0LPM: Adding route 0x01010100 / 24 (0)
LPM: Adding route 0x02010100 / 24 (1)
LPM: Adding route IPV6 / 48 (0)
LPM: Adding route IPV6 / 48 (1)
txq=1,0,0Initializing port 1 ... Creating queues: nb_rxq=1 nb_txq=1... Port 1 modified RSS hash function based on hardware support,requested:0xa38c configured:0Address:52:54:00:A7:A7:F6, Destination:52:54:00:53:5A:D2, txq=1,0,0Skipping disabled port 2Initializing rx queues on lcore 1 ... rxq=0,0,0 rxq=1,0,0Port 0: softly parse packet type info
Port 1: softly parse packet type infoChecking link statusdone
Port0 Link Up. Speed 10000 Mbps -full-duplex
Port1 Link Up. Speed 10000 Mbps -full-duplex
L3FWD: entering main loop on lcore 1
L3FWD:  -- lcoreid=1 portid=0 rxqueueid=0
L3FWD:  -- lcoreid=1 portid=1 rxqueueid=0

测试 L3 转发功能

  • l3fwd_lpm.c 中定义的默认路由表,port0 为 1.1.1.0/24,port1 为 2.1.1.0/24。
static struct ipv4_l3fwd_lpm_route ipv4_l3fwd_lpm_route_array[] = {{IPv4(1, 1, 1, 0), 24, 0},{IPv4(2, 1, 1, 0), 24, 1},{IPv4(3, 1, 1, 0), 24, 2},{IPv4(4, 1, 1, 0), 24, 3},{IPv4(5, 1, 1, 0), 24, 4},{IPv4(6, 1, 1, 0), 24, 5},{IPv4(7, 1, 1, 0), 24, 6},{IPv4(8, 1, 1, 0), 24, 7},
};
  • server01:因为 l3fwd 不能处理 ARP 协议,所以需要手动添加 l3fwd port0 的静态 MAC 地址表。
$ ip addr add dev eth1 1.1.1.2/24
$ ip route add 2.1.1.2 via 1.1.1.1 dev eth1
$ ip nei add 1.1.1.1 lladdr 52:54:00:5E:8C:DF dev eth1
  • server02
$ ip addr add dev eth2 2.1.1.2/24
$ ip route add 1.1.1.2 via 2.1.1.1 dev eth2
$ ip nei add 2.1.1.1 lladdr 52:54:00:A7:A7:F6 dev eth2
  • server01 ping server02
$ ping 2.1.1.2
PING 2.1.1.2 (2.1.1.2) 56(84) bytes of data.
64 bytes from 2.1.1.2: icmp_seq=30 ttl=63 time=0.659 ms

性能参数

  • 10GbE、Intel x710、2NUMA、4ports

在这里插入图片描述

实现分析

相关内容

热门资讯

躺平后,老干妈赚了快54亿 「核心提示」当众多品牌深陷流量与价格内卷时,不运营社交媒体,几乎零直播投放的老干妈怎么躺着把钱赚了?...
超级逆转?黑马有望逆袭美联储主... 2025.12.16本文字数:1890,阅读时长大约3分钟作者 |第一财经 樊志菁近期华尔街关注度最...
青海春天,保壳生死时速 斑马消费 陈晓京*ST春天走到退市边缘,并不让人意外。自极草5X神话落幕后,公司一直走在转型路上,最...
虐宠、欠薪、巨亏?海洋公园怎么... 12月6日,杭州野生动物世界在进行黑熊表演时,发生了黑熊将驯养员扑倒争抢食物的事件。该事件最后以全部...
埃基蒂克9分!利物浦战胜布莱顿... 在刚刚结束的英超第16轮比赛中,利物浦在安菲尔德球场以2-0战胜了布莱顿。这场比赛不仅仅是比分的胜利...
全球首个!马斯克身价超6000... 2025.12.16本文字数:2295,阅读时长大约4分钟作者 |第一财经 樊志菁经历了年初接近50...
恒兴股份:核心技术人员入职次年... 《金证研》南方资本中心 云起/作者 易溪 南江 映蔚/风控在申报北交所上市过程中,湖南恒兴新材料科技...
马云为什么要去卢旺达? 随着00后开始步入职场,星空君和00后打交道越来越多。作为集团专家库成员,在工作中星空君对00后同事...
超级逆转?黑马有望逆袭美联储主... 近期华尔街关注度最高的热门话题于周一出现突发转折。前美联储理事沃什(Kevin Walsh)取代哈塞...
中国平安:是否到了可以乐观的时... 本文系基于公开资料撰写,仅作为信息交流之用,不构成任何投资建议“请珍惜XX元以下的平安”,这一曾流传...