測試環境
操作系統: Ubuntu 20.04 LTS;
處理器爲: Intel® Core™ i7-4790K CPU @ 4.00GHz。
網卡使用的是Intel的I210千兆網卡。
DPDK版本19.02。
測試拓撲:
|----------------|
| Ubuntu(DPDK) |
| |
| eth0 eth1 |
1.1.1.1 |----|------|----| 2.1.1.1
00:60:E0:6F:C8:7D | | 00:60:E0:6F:C8:7E
/ \
/ \
/ \
/ \
00:60:E0:7A:6C:78 / \ 00:60:E0:7A:6C:79
1.1.1.2 | | 2.1.1.2
|--------|------| |-------|-------|
| eth0 | | eth0 |
| | | |
| Ubuntu0 | | Ubuntu1 |
|---------------| |---------------|
環境配置
如下l3fwd_lpm.c文件中的默認路由表項,port0的網段爲:1.1.1.0/24;port1的網段爲:2.1.1.0/24。以上拓撲假定port0的IP地址爲:1.1.1.1;port1的IP地址爲:2.1.1.1,當然也可以使用其它的地址,只要是同一網段即可。
42 static struct ipv4_l3fwd_lpm_route ipv4_l3fwd_lpm_route_array[] = {
43 {IPv4(1, 1, 1, 0), 24, 0},
44 {IPv4(2, 1, 1, 0), 24, 1},
以下爲Ubuntu0的配置,其接口eth0的IP地址爲1.1.1.2,默認網關設置爲Ubuntu(DPDK)的eth0(DPDK中的port0):
/ # ip route add default via 1.1.1.1
/ #
/ # ip r
default via 1.1.1.1 dev eth0 proto zebra
1.1.1.0/24 dev eth0 proto kernel scope link src 1.1.1.2
/ #
由於DPDK的l3fwd不能處理ARP,需要在Ubuntu0上靜態指定Ubuntu(DPDK)的eth0接口IP地址對應的MAC地址:
/ # ip nei add 1.1.1.1 lladdr 00:60:E0:6F:C8:7D dev m1/1
/ #
/ # ip ne
1.1.1.1 dev m1/1 lladdr 00:60:e0:6f:c8:7d PERMANENT
以下爲Ubuntu1的配置,配置與Ubuntu0類似。其接口eth0的IP地址爲2.1.1.2,默認網關設置爲Ubuntu(DPDK)的eth1(DPDK中的port1):
/ # ip route add default via 2.1.1.1
/ #
/ # ip r
default via 2.1.1.1 dev m1/2 proto zebra
2.1.1.0/24 dev m1/2 proto kernel scope link src 2.1.1.2
/ #
由於DPDK的l3fwd不能處理ARP,需要在Ubuntu1上靜態指定Ubuntu(DPDK)的eth1接口IP地址對應的MAC地址:
/ # ip nei add 2.1.1.1 lladdr 00:60:E0:6F:C8:7E dev m1/2
/ #
/ # ip nei
2.1.1.1 dev m1/2 lladdr 00:60:e0:6f:c8:7e PERMANENT
啓動l3fwd示例
如下命令啓動l3fwd例程,eth-dest參數分別指定Ubuntu0和Ubuntu1的eth0接口的MAC地址。
./l3fwd -c 0x6 -- -p 0x3 -P --eth-dest=0,00:60:E0:7A:6C:78 --eth-dest=1,00:60:E0:7A:6C:79
如下的啓動信息,port0發送報文時,使用源MAC地址爲:00:60:E0:6F:C8:7D,目的MAC地址爲:00:60:E0:7A:6C:78。port1發送報文時,使用源MAC地址00:60:E0:6F:C8:7E,目的MAC地址爲00:60:E0:7A:6C:79。
另外,也可看到添加到LPM中的路由項。
Initializing port 0 ... Creating queues: nb_rxq=2 nb_txq=2...
Port 0 modified RSS hash function based on hardware support,requested:0xa38c configured:0x2288
Address:00:60:E0:6F:C8:7D, Destination:00:60:E0:7A:6C:78, Allocated mbuf pool on socket 0
LPM: Adding route 0x01010100 / 24 (0)
LPM: Adding route 0x02010100 / 24 (1)
Initializing port 1 ... Creating queues: nb_rxq=2 nb_txq=2...
Port 1 modified RSS hash function based on hardware support,requested:0xa38c configured:0x2288
Address:00:60:E0:6F:C8:7E, Destination:00:60:E0:7A:6C:79, txq=1,0,0
Checking link status....done
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=0 rxqueueid=1
L3FWD: entering main loop on lcore 2
L3FWD: -- lcoreid=2 portid=1 rxqueueid=0
L3FWD: -- lcoreid=2 portid=1 rxqueueid=1
在Ubuntu0上ping主機Ubuntu1的IP地址:2.1.1.2,收到回覆,鏈路是通的。