dpdk_18_05 應用筆記: l3fwd 例程
查詢網卡的 pci 地址
機器上有 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)
編譯
情況1. 編譯的時候沒有網卡的驅動。(使用,後續都是以這個爲例子)
EXTRA_CFLAGS="-O0 -g3" make
情況1. 編譯的時候加上網卡的驅動。(暫不使用)
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 */
};
命令行參數
router 命令行參數
# 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
pc_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
pc_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
測試步驟
- 測試 pc_0 可以 ping 通 pc_1。
- 測試 pc_1 可以 ping 通 pc_0。