顯示具有 虛擬機 標籤的文章。 顯示所有文章
顯示具有 虛擬機 標籤的文章。 顯示所有文章

2020年6月13日 星期六

[教學] DPDK在實體機/虛擬機上執行l3fwd

大家好啊~~

當初讓l3fwd這個範例程式可以正常轉送兩台電腦之間的封包
花了幾天的時間才成功
因為官網寫的文件太精簡了

起初一直無法兩端互相ping到對方
後來經過一番研究
發現使用l3fwd範例
除了routing table要在程式上預先設定之外
還必須需要指定static ARP
主要是因為l3fwd的範例程式
沒有針對TCP/UDP之外的封包做處理
所以從Source發出的ARP封包無法傳遞給Destination

拓譜架構:





電腦A(Windows 10,IP: 198.18.0.1,00-E0-4C-68-DD-6C,與Port0接)
電腦B(Windows 10,IP: 198.18.1.1,00-E0-4C-68-FD-E0,與Port1接)
電腦S(Ubuntu 20.04,Port0: 24-6e-96-58-69-68,Port1: 24-6e-96-58-69-69)

1. 在Windows上設定Static ARP MAC Address
參考這裡的說明
Ubuntu的設定
參考這裡的說明

以我這邊的環境Windows
電腦A要下Port0的MAC Address
netsh -c i i add neighbors 14 "198.18.1.1" "24-6e-96-58-69-68"
(雙引號可不加,純粹方便閱讀)
同理,電腦B要下Port1的MAC Address
這裡就不加贅述了

2. 在執行l3fwd範例的時候
要在命令列指定MAC address
最重要的就是要在命令列加入--eth-dest的參數
將電腦S上的port所對應的電腦A/B使用的網卡MAC Address

sudo ./l3fwd -c 0x3 -n 2 -- -p 0x3 --config="(0,0,0),(1,0,1)" --eth-dest=0,00:E0:4C:68:DD:6C --eth-dest=1,00:E0:4C:68:FD:E0

l3fwd啟動之後
ping的部分就會正常運作了






這邊在電腦A上使用iperf3來打流量過去到電腦B

執行結果
PS D:\iperf-3.1.3-win64> .\iperf3.exe -c 198.18.1.1
Connecting to host 198.18.1.1, port 5201
[  4] local 198.18.0.1 port 51374 connected to 198.18.1.1 port 5201
[ ID] Interval           Transfer     Bandwidth
[  4]   0.00-1.00   sec  99.0 MBytes   830 Mbits/sec
[  4]   1.00-2.00   sec   110 MBytes   919 Mbits/sec
[  4]   2.00-3.00   sec   110 MBytes   919 Mbits/sec
[  4]   3.00-4.00   sec   109 MBytes   916 Mbits/sec
[  4]   4.00-5.00   sec   110 MBytes   924 Mbits/sec
[  4]   5.00-6.00   sec   105 MBytes   881 Mbits/sec
[  4]   6.00-7.00   sec   110 MBytes   924 Mbits/sec
[  4]   7.00-8.00   sec   108 MBytes   904 Mbits/sec
[  4]   8.00-9.00   sec   110 MBytes   920 Mbits/sec
[  4]   9.00-10.00  sec  63.5 MBytes   533 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth
[  4]   0.00-10.00  sec  1.01 GBytes   867 Mbits/sec                  sender
[  4]   0.00-10.00  sec  1.01 GBytes   867 Mbits/sec                  receiver

iperf Done.
PS D:\iperf-3.1.3-win64>


遇過的問題
port 1 is not present on the board
多半可能是因為網卡沒有綁定到DPDK上

延伸閱讀
https://www.twblogs.net/a/5b99e1c22b71773ebacd9d9e
https://www.cnblogs.com/ZCplayground/p/9381961.html

---------------------------------------------------------------------------------------------------------------------

下面另外亂入附上
在虛擬機上執行l3fwd的結果
因為沒有實際的網卡所以沒辦法產生封包互打
推測可能要在虛擬機之間設定LAN Segment之類的東西
((有誰試試可以告訴我結果XD

如果要在虛擬機上執行
需要多加一個--parse-ptype的參數

john@ubuntu:~/dpdk-stable-18.11.6/myinstall/share/dpdk/examples/l3fwd/build/app$ sudo ./l3fwd -c 1 -n 2 -- -p 0x3 -P --config="(0,0,0),(1,0,0)" --parse-ptype
EAL: Detected 4 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: No free hugepages reported in hugepages-1048576kB
EAL: Probing VFIO support...
EAL: PCI device 0000:02:01.0 on NUMA socket -1
EAL:   Invalid NUMA socket, default to 0
EAL:   probe driver: 8086:100f net_e1000_em
EAL: PCI device 0000:02:06.0 on NUMA socket -1
EAL:   Invalid NUMA socket, default to 0
EAL:   probe driver: 8086:100f net_e1000_em
EAL: PCI device 0000:02:07.0 on NUMA socket -1
EAL:   Invalid NUMA socket, default to 0
EAL:   probe driver: 8086:100f net_e1000_em
soft parse-ptype is enabled
LPM or EM none selected, default LPM on
Initializing port 0 ... Creating queues: nb_rxq=1 nb_txq=1... Port 0 modified RSS hash function based on hardware support,requested:0xa38c configured:0
portid = 0, nb_rx_queue = 1
 Address:00:0C:29:DC:F9:16, Destination:02:00:00:00:00:00, Allocated mbuf pool on socket 0
LPM: Adding route 0x01010100 / 24 (0)
LPM: Adding route 0x02010100 / 24 (1)
LPM: Adding route IPV6 / 48 (0)
LPM: Adding route IPV6 / 48 (1)
txq=0,0,0
Initializing port 1 ... Creating queues: nb_rxq=1 nb_txq=1... Port 1 modified RSS hash function based on hardware support,requested:0xa38c configured:0
portid = 1, nb_rx_queue = 1
 Address:00:0C:29:DC:F9:20, Destination:02:00:00:00:00:01, txq=0,0,0

Initializing rx queues on lcore 0 ... rxq=0,0,0 rxq=1,0,0

Port 0: softly parse packet type info
Port 1: softly parse packet type info

Checking link statusdone
Port0 Link Up. Speed 1000 Mbps -full-duplex
Port1 Link Up. Speed 1000 Mbps -full-duplex
L3FWD: entering main loop on lcore 0
L3FWD:  -- lcoreid=0 portid=0 rxqueueid=0
L3FWD:  -- lcoreid=0 portid=1 rxqueueid=0


2020年5月25日 星期一

[教學] DPDK在Ubuntu虛擬機上編譯方式

大家好啊~~
最近在研究DPDK的套件
想了解這些範例程式跑起來的樣子是什麼
但手邊沒有支援DPDK的實體網卡
後來看到網路上說
可以使用虛擬機模擬出支援的網卡!!!
於是手刀部建虛擬機&編譯環境了

以下是整理過的筆記
以DPDK-18.11.6版本+Ubuntu 16.04.3 with 4.4.0-87-generic+VMware Workstation 15當作範例

撰寫日期:2020.05.20

1. 首先建立好虛擬機並安裝好作業系統

2. 把虛擬機關機,再去設定檔這邊添加2張網卡(mode設NAT即可)

3. 修改.vmx,把你要設定網卡的"virtualDev"的值,設定為"e1000"
(否則網卡會無法給DPDK使用)

4. 開機後去官網下載dpdk的原始碼,並解壓縮出來後,進入該資料夾

5. 使用指令
sudo apt-get install make gcc python libpcap-dev libnuma-dev pkg-config -y
安裝這幾個dpdk編譯會用到的套件
./usertools/dpdk-devbind.py --status
去看網卡類型是否變為
drv=e1000
有的話就成功模擬出支援的網卡囉

6. 環境變數DESTDIR指定程式build出來的位置(名字位置任意,本範例會在dpdk目錄底下的myinstall資料夾內,建立所有範例的binary)
還有DPDK編譯相關的環境變數
export DESTDIR=myinstall
export RTE_SDK=/home/john/dpdk-stable-18.11.6/ export RTE_TARGET=x86_64-native-linuxapp-gcc

7. 執行官方設置腳本,包含載入igb_uio模組以及綁定網卡給DPDK使用
./usertools/dpdk-setup.sh
依序選擇
[15] x86_64-native-linuxapp-gcc(根據作業系統、使用的編譯器決定)
[18] Insert IGB UIO module
[24] Bind Ethernet/Crypto device to IGB UIO module(綁定指定網卡給DPDK)
[21/22] Setup hugepage mappings for (non-)NUMA systems(設定Hugeopage給DPDK使用)

8. 手動編譯範例make test,發現ImportError: No module named pexpect
補上解法
sudo apt-get install python-setuptools
sudo easy_install pip
sudo -E pip install pexpect
9. 因為在虛擬機上面執行程式,虛擬出來的網卡會有一些問題
如圖所示

要去修改library的程式碼解決問題
vim kernel/linux/igb_uio/igb_uio.c : 259
修改完畢後要重新編譯DPDK,並且重新載入igb_uio模組

10. 再去執行範例程式,以Helloworld來說存在於myinstall/share/dpdk/examples/helloworld/build/app底下

我的虛擬機有4顆Core,3張網卡(後兩張有綁給DPDK)
使用sudo ./helloworld執行範例
執行結果如下
-------------------------------------------------------------------------
john@ubuntu:~/dpdk-stable-18.11.6/myinstall/share/dpdk/examples/helloworld/build/app$ sudo ./helloworld
EAL: Detected 4 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: No free hugepages reported in hugepages-1048576kB
EAL: Probing VFIO support...
EAL: PCI device 0000:02:01.0 on NUMA socket -1
EAL:   Invalid NUMA socket, default to 0
EAL:   probe driver: 8086:100f net_e1000_em
EAL: PCI device 0000:02:06.0 on NUMA socket -1
EAL:   Invalid NUMA socket, default to 0
EAL:   probe driver: 8086:100f net_e1000_em
EAL: PCI device 0000:02:07.0 on NUMA socket -1
EAL:   Invalid NUMA socket, default to 0
EAL:   probe driver: 8086:100f net_e1000_em
hello from core 1
hello from core 2
hello from core 3
hello from core 0
john@ubuntu:~/dpdk-stable-18.11.6/myinstall/share/dpdk/examples/helloworld/build/app$
-------------------------------------------------------------------------

以上!
有問題歡迎留言討論
後續再來寫命令列參數的使用