MoonGen 网卡多端口 自定义payload 发包 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
[root@localhost ~]# cat ~/l3_ipv4_udp_97_X2.lua
local mg = require "moongen"
local memory = require "memory"
local device = require "device"
local ts = require "timestamping"
local filter = require "filter"
local hist = require "histogram"
local stats = require "stats"
local timer = require "timer"
local arp = require "proto.arp"
local log = require "log"

-- set addresses here
local SRC_MAC = "FE:DC:BA:98:76:54"
local DST_MAC = "12:34:45:78:9A:BC"
local SRC_IP_BASE = "172.1.1.1"
local DST_IP = "192.1.1.1"
local SRC_PORT = 8080
local DST_PORT = 16285

function configure(parser)
parser:option("-r --rate", "Transmit rate in Mbit/s."):default(10000):convert(tonumber)
parser:option("-f --flows", "Number of flows (randomized source IP)."):default(4):convert(tonumber)
parser:option("-s --size", "Packet size."):default(60):convert(tonumber)
end

function master(args)
-- use port 0
txDev0 = device.config{port = 0, rxQueues = 3, txQueues = 3}
rxDev0 = device.config{port = 0, rxQueues = 3, txQueues = 3}

-- use port 1
txDev1 = device.config{port = 1, rxQueues = 3, txQueues = 3}
rxDev1 = device.config{port = 1, rxQueues = 3, txQueues = 3}

device.waitForLinks()
-- max 1kpps timestamping traffic timestamping
-- rate will be somewhat off for high-latency links at low rates
if args.rate > 0 then
txDev0:getTxQueue(0):setRate(args.rate - (args.size + 4) * 8 / 1000)
txDev1:getTxQueue(0):setRate(args.rate - (args.size + 4) * 8 / 1000)
end

mg.startTask("loadSlave", txDev0:getTxQueue(0), rxDev0, args.size, args.flows)
mg.startTask("loadSlave", txDev1:getTxQueue(0), rxDev1, args.size, args.flows)
mg.waitForTasks()
end

local function fillUdpPacket(buf, len)
buf:getUdpPacket():fill{
ethSrc = queue,
ethDst = DST_MAC,
ip4Src = SRC_IP,
ip4Dst = DST_IP,
udpSrc = SRC_PORT,
udpDst = DST_PORT,
pktLength = len
}
end

function loadSlave(queue, rxDev, size, flows)
local mempool = memory.createMemPool(function(buf)
fillUdpPacket(buf, size)
end)
local i = 0;
local acc = 0;
local bufs = mempool:bufArray()
local counter = 0
local txCtr = stats:newDevTxCounter(queue, "plain")
local rxCtr = stats:newDevRxCounter(rxDev, "plain")
local baseIP = parseIPAddress(SRC_IP_BASE)
while mg.running() do
bufs:alloc(size)
for i, buf in ipairs(bufs) do
local pkt = buf:getUdpPacket()

pkt.ip4.src:set(baseIP + counter) -- new flow by randomized ip src

pkt.udp:setDstPort(16285)
pkt.udp:setSrcPort(65535)

-- Prefix
pkt.payload.uint8[0] = 0x97
pkt.payload.uint8[1] = 0x11

-- Resv
pkt.payload.uint8[2] = 0
pkt.payload.uint8[3] = 0
pkt.payload.uint8[4] = 0
pkt.payload.uint8[5] = 0

-- Session id
pkt.payload.uint8[6] = 0xAB
pkt.payload.uint8[7] = 0xAC
pkt.payload.uint8[8] = 0xAD
pkt.payload.uint8[9] = acc % 256 -- randomized Session id

-- SEQ
pkt.payload.uint8[12] = acc / 256
pkt.payload.uint8[13] = acc % 256

acc = acc + 1
counter = incAndWrap(counter, flows)
end
-- UDP checksums are optional, so using just IPv4 checksums would be sufficient here
bufs:offloadUdpChecksums()
queue:send(bufs)
txCtr:update()
rxCtr:update()
end
txCtr:finalize()
rxCtr:finalize()
end

dpdk 配置

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
59

[root@localhost ~]# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 48
On-line CPU(s) list: 0-47
Thread(s) per core: 2
Core(s) per socket: 12
Socket(s): 2
NUMA node(s): 2
Vendor ID: GenuineIntel
CPU family: 6
Model: 79
Model name: Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz
Stepping: 1
CPU MHz: 1202.179
CPU max MHz: 2900.0000
CPU min MHz: 1200.0000
BogoMIPS: 4399.86
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 30720K
NUMA node0 CPU(s): 0-11,24-35
NUMA node1 CPU(s): 12-23,36-47
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 cdp_l3 intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts
[root@localhost ~]#


[root@localhost MoonGen]# cat libmoon/dpdk-conf.lua
-- Configuration for all DPDK command line parameters.
-- See DPDK documentation at http://dpdk.org/doc/guides/testpmd_app_ug/run_app.html for details.
-- libmoon tries to choose reasonable defaults, so this config file can almost always be empty.
-- Be careful when running libmoon in a VM that also uses another virtio NIC, e.g., for internet access.
-- In this case it may be necessary to use the blacklist or whitelist features in some configurations.
DPDKConfig {
-- configure the CPU cores to use, default: all cores
--cores = {0, 1, 2, 3, 4, 5},

-- max number of shared tasks running on core 0
--sharedCores = 8,

-- black or whitelist devices to limit which PCI devs are used by DPDK
-- only one of the following examples can be used
--pciBlacklist = {"0000:81:00.3","0000:81:00.1"},
--pciWhitelist = {"0000:81:00.3","0000:81:00.1"},

-- arbitrary DPDK command line options
-- the following configuration allows multiple DPDK instances (use together with pciWhitelist)
-- cf. http://dpdk.org/doc/guides/prog_guide/multi_proc_support.html#running-multiple-independent-dpdk-applications
--cli = {
-- "--file-prefix", "m1",
-- "--socket-mem", "512,512",
--}

}
[root@localhost MoonGen]#

运行

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
[root@localhost MoonGen]# ./build/MoonGen ~/l3_ipv4_udp_97_X2.lua -f 400 -s 150 -r 5800
[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:27:3D (Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection)
Device 1: E4:95:6E:20:27:3E (Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection)
PMD: ixgbe_dev_link_status_print(): Port 0: Link Down
[WARN] Device 0 already configured, skipping initilization
PMD: ixgbe_dev_link_status_print(): Port 1: Link Down
[WARN] Device 1 already configured, skipping initilization
[INFO] Waiting for devices to come up...
[INFO] Device 0 (E4:95:6E:20:27:3D) is up: 10000 MBit/s
[INFO] Device 1 (E4:95:6E:20:27:3E) is up: 10000 MBit/s
[INFO] 2 devices are up.
[Device: id=0] TX: 4.70 Mpps, 5796 Mbit/s (6549 Mbit/s with framing)
[Device: id=0] RX: 0.00 Mpps, 0 Mbit/s (0 Mbit/s with framing)
[Device: id=1] TX: 4.70 Mpps, 5794 Mbit/s (6547 Mbit/s with framing)
[Device: id=1] RX: 0.00 Mpps, 0 Mbit/s (0 Mbit/s with framing)
[Device: id=0] TX: 4.59 Mpps, 5658 Mbit/s (6393 Mbit/s with framing)
[Device: id=1] TX: 4.61 Mpps, 5684 Mbit/s (6422 Mbit/s with framing)
[Device: id=0] RX: 0.00 Mpps, 0 Mbit/s (0 Mbit/s with framing)
[Device: id=1] RX: 0.00 Mpps, 0 Mbit/s (0 Mbit/s with framing)
[Device: id=0] TX: 4.69 Mpps, 5779 Mbit/s (6530 Mbit/s with framing)
[Device: id=1] TX: 4.69 Mpps, 5781 Mbit/s (6531 Mbit/s with framing)
[Device: id=0] RX: 0.00 Mpps, 0 Mbit/s (0 Mbit/s with framing)
[Device: id=1] RX: 0.00 Mpps, 0 Mbit/s (0 Mbit/s with framing)


[root@localhost ~]#