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 ||---------------| |---------------|
$ 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
./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]
./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
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},
};
$ 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
$ 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
$ 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