机器上有 4 个的 I350 网卡。
现在只是使用其中01:00.0
和01:00.1
两个网卡来绑定到 DPDK 作为测试。
lspci | grep Eth
> 01:00.0 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
> 01:00.1 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
> 01:00.2 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
> 01:00.3 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
EXTRA_CFLAGS="-O0 -g3" make
I350 使用的是 librte_pmd_e1000.so
的驱动。
EXTRA_CFLAGS="-O0 -g3 -lrte_pmd_e1000" make
实验的拓扑如下。中间的router机器跑 l3fwd
例程。实现路由功能。
pc_0 和 pc_1 使用 icmp 来通信。
+---------+
| pc_0 |
+---------+
| port : eth0
| mac : 00:1f:16:08:a7:57
| ip : 192.168.111.1/24
|
|
|
| dpdk port id: 0
| mac : A0:36:9F:8A:68:14
+---------+
| router |
+---------+
| dpdk port id: 1
| mac : A0:36:9F:8A:68:15
|
|
|
| port : eth0
| mac : b8:27:eb:af:96:9b
| ip : 192.168.222.1/24
+---------+
| pc_1 |
+---------+
注意:
pc_0 和 pc_1 中,需要手动添加 router 的 mac 地址作为下一跳的邻居项。
router 的命令行参数,需要指定 pc_0 和 pc_1 的 mac 地址作为邻居项。
路由表是写死在代码中的,所以需要修改源码文件。
修改源码文件:
l3fwd_lpm.c
参照拓扑设置路由项和流出网卡。
路由项 | 流出网卡 |
---|---|
192.168.111.0/24 | port0 |
192.168.222.0/24 | port1 |
修改ipv4_l3fwd_lpm_route_array
的数值。
修改路由项:
static struct ipv4_l3fwd_lpm_route ipv4_l3fwd_lpm_route_array[] = {
{IPv4(192,168,111,0), 24, 0}, /* ipv4_address, prefix, dpdk_port_id_out */
{IPv4(192,168,222,0), 24, 1}, /* ipv4_address, prefix, dpdk_port_id_out */
};
# the description of argument list for l3fwd
# ------------------------------------------
# -d librte_pmd_e1000.so
# driver for I350.
# -w 01:00.0
# whitelist for nic 0000:01:00.0 'I350 Gigabit Network Connection 1521'.
# -w 01:00.1
# whitelist for nic 0000:01:00.1 'I350 Gigabit Network Connection 1521'.
# -c 0x3
# cpu for cpu0 and cpu1.
# -n 4
# 4 channel memory controller.
# -p 0x3
# port mask 0x3 for port0 and port1.
# --config="(0,0,0),(1,0,1)"
# port0.queue0 at cpu0.
# port1.queue0 at cpu1.
# --eth-dest=0,00:1f:16:08:a7:57
# for port0 output, the destination mac address set to 00:1f:16:08:a7:57
# --eth-dest=1,b8:27:eb:af:96:9b
# for port1 output, the destination mac address set to b8:27:eb:af:96:9b
./build/l3fwd \
-d librte_pmd_e1000.so \
-w 01:00.0 -w 01:00.1 \
-c 0x3 \
-n 4 \
-- \
-p 0x3 \
--config="(0,0,0),(1,0,1)" \
--eth-dest=0,00:1f:16:08:a7:57 --eth-dest=1,b8:27:eb:af:96:9b
> # l3fwd output message:
> Initializing port 0 ... Creating queues: nb_rxq=1 nb_txq=2...
> Address:A0:36:9F:8A:68:14, Destination:00:1F:16:08:A7:57, Allocated mbuf pool on socket 0
> # ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^
> # `-- port0's MAC `-- pc_0's MAC
>
> LPM: Adding route 0xc0a86f00 / 24 (0) # 192.168.111.0/24 port out: port0
> LPM: Adding route 0xc0a8de00 / 24 (1) # 192.168.222.0/24 port out: port1
> LPM: Adding route IPV6 / 48 (0)
> LPM: Adding route IPV6 / 48 (1)
> txq=0,0,0 txq=1,1,0
> Initializing port 1 ... Creating queues: nb_rxq=1 nb_txq=2...
> Address:A0:36:9F:8A:68:15, Destination:B8:27:EB:AF:96:9B, txq=0,0,0 txq=1,1,0
> # ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^
> # `-- port1's MAC `-- pc_1's MAC
>
> Initializing rx queues on lcore 0 ... rxq=0,0,0
> Initializing rx queues on lcore 1 ... rxq=1,0,0
# add ip address
ip a a 192.168.111.1/24 dev eth0
# add a PERMANENT neighbour
ip n a 192.168.222.1 dev eth0 lladdr A0:36:9F:8A:68:14
# set default port out
ip r a default dev eth0
# testing
ping 192.168.222.1
# add ip address
ip a a 192.168.222.1/24 dev eth0
# add a PERMANENT neighbour
ip n a 192.168.111.1 dev eth0 lladdr A0:36:9F:8A:68:15
# set default port out
ip r a default dev eth0
# testing
ping 192.168.111.1