MoonGen DEV收包 应用层收包 速率显示 lua脚本

脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
[root@localhost ~]# cat rx-pkts.lua
local mg = require "dpdk"
local memory = require "memory"
local device = require "device"
local stats = require "stats"
local histogram = require "histogram"
local log = require "log"
local timer = require "timer"

function master()
local rxDev0 = device.config{ port = 0, dropEnable = false }
local rxDev1 = device.config{ port = 1, dropEnable = false }
device.waitForLinks()
mg.launchLua("counterSlave", rxDev0:getRxQueue(0))
mg.launchLua("counterSlave", rxDev1:getRxQueue(0))
mg.waitForSlaves()
end

function counterSlave(queue)
local bufs = memory.bufArray()
local ctrs = {}
local rxCtr = stats:newDevRxCounter(queue.dev)
-- to track if we lose packets on the NIC
local pktCtr = stats:newPktRxCounter("Packets counted "..queue.dev.id, "plain")
local hist = histogram:create()
while mg.running() do
local rx = queue:tryRecv(bufs, 100)
for i = 1, rx do
local buf = bufs[i]
local size = buf:getSize()
hist:update(size)
pktCtr:countPacket(buf)
end
bufs:free(rx)
rxCtr:update()
pktCtr:update()
end
rxCtr:finalize()
pktCtr:finalize()
-- TODO: check the queue's overflow counter to detect lost packets
end

[root@localhost ~]#

运行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

[root@localhost MoonGen]# ./build/MoonGen ~/rx-pkts.lua
[INFO] Initializing DPDK. This will take a few seconds...
EAL: Detected 48 lcore(s)
EAL: Probing VFIO support...
EAL: PCI device 0000:01:00.0 on NUMA socket 0
EAL: probe driver: 8086:10f8 net_ixgbe
EAL: PCI device 0000:05:00.0 on NUMA socket 0
EAL: probe driver: 8086:10fb net_ixgbe
EAL: PCI device 0000:05:00.1 on NUMA socket 0
EAL: probe driver: 8086:10fb net_ixgbe
EAL: PCI device 0000:82:00.0 on NUMA socket 1
EAL: probe driver: 8086:10f8 net_ixgbe
EAL: PCI device 0000:83:00.0 on NUMA socket 1
EAL: probe driver: 8086:1521 net_e1000_igb
EAL: PCI device 0000:83:00.1 on NUMA socket 1
EAL: probe driver: 8086:1521 net_e1000_igb
EAL: PCI device 0000:83:00.2 on NUMA socket 1
EAL: probe driver: 8086:1521 net_e1000_igb
EAL: PCI device 0000:83:00.3 on NUMA socket 1
EAL: probe driver: 8086:1521 net_e1000_igb
[INFO] Found 2 usable devices:
Device 0: E4:95:6E:20:28:15 (Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection)
Device 1: E4:95:6E:20:28:16 (Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection)
PMD: ixgbe_dev_link_status_print(): Port 0: Link Down
PMD: ixgbe_dev_link_status_print(): Port 1: Link Down
[INFO] Waiting for devices to come up...
[INFO] Device 0 (E4:95:6E:20:28:15) is up: 10000 MBit/s
[INFO] Device 1 (E4:95:6E:20:28:16) is up: 10000 MBit/s
[INFO] 2 devices are up.
[WARN] dpdk.launchLua() is deprecated, use moongen.startTask() instead.
[WARN] dpdk.waitForSlaves() is deprecated, use moongen.waitForTasks() instead.
[WARN] dpdk.running() is deprecated, use moongen.running() instead.
[WARN] dpdk.running() is deprecated, use moongen.running() instead.
[Device: id=1] RX: 4.69 Mpps, 5780 Mbit/s (6530 Mbit/s with framing)
[Packets counted 1] RX: 4.62 Mpps, 5687 Mbit/s (6426 Mbit/s with framing)
[Device: id=0] RX: 4.69 Mpps, 5779 Mbit/s (6530 Mbit/s with framing)
[Packets counted 0] RX: 4.62 Mpps, 5686 Mbit/s (6425 Mbit/s with framing)
[Device: id=1] RX: 4.69 Mpps, 5781 Mbit/s (6531 Mbit/s with framing)
[Device: id=0] RX: 4.69 Mpps, 5780 Mbit/s (6531 Mbit/s with framing)
[Packets counted 1] RX: 4.69 Mpps, 5783 Mbit/s (6534 Mbit/s with framing)
[Packets counted 0] RX: 4.69 Mpps, 5783 Mbit/s (6534 Mbit/s with framing)
[Device: id=0] RX: 4.69 Mpps, 5781 Mbit/s (6532 Mbit/s with framing)
[Device: id=1] RX: 4.69 Mpps, 5781 Mbit/s (6532 Mbit/s with framing)
[Packets counted 1] RX: 4.69 Mpps, 5781 Mbit/s (6532 Mbit/s with framing)
[Packets counted 0] RX: 4.69 Mpps, 5781 Mbit/s (6532 Mbit/s with framing)
[Device: id=0] RX: 4.69 Mpps, 5780 Mbit/s (6531 Mbit/s with framing)
[Device: id=1] RX: 4.69 Mpps, 5781 Mbit/s (6531 Mbit/s with framing)
[Packets counted 1] RX: 4.69 Mpps, 5781 Mbit/s (6531 Mbit/s with framing)
[Packets counted 0] RX: 4.69 Mpps, 5781 Mbit/s (6531 Mbit/s with framing)
[Device: id=0] RX: 4.69 Mpps, 5779 Mbit/s (6529 Mbit/s with framing)
[Device: id=1] RX: 4.69 Mpps, 5779 Mbit/s (6530 Mbit/s with framing)
[Packets counted 1] RX: 4.69 Mpps, 5779 Mbit/s (6530 Mbit/s with framing)
[Packets counted 0] RX: 4.69 Mpps, 5779 Mbit/s (6529 Mbit/s with framing)
[Device: id=0] RX: 4.69 Mpps, 5781 Mbit/s (6532 Mbit/s with framing)
[Device: id=1] RX: 4.69 Mpps, 5780 Mbit/s (6530 Mbit/s with framing)
[Packets counted 1] RX: 4.69 Mpps, 5780 Mbit/s (6530 Mbit/s with framing)
[Packets counted 0] RX: 4.69 Mpps, 5781 Mbit/s (6532 Mbit/s with framing)

运行使用制定的 CPU